extension-develop 2.0.0 → 2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (260) hide show
  1. package/README.md +204 -0
  2. package/dist/add-content-script-wrapper.js +1777 -0
  3. package/dist/add-hmr-accept-code.js +95 -3
  4. package/dist/build.d.ts +2 -0
  5. package/dist/cleanup.d.ts +1 -0
  6. package/dist/deprecated-shadow-root.js +115 -14
  7. package/dist/dev.d.ts +2 -0
  8. package/dist/develop-lib/config-types.d.ts +85 -0
  9. package/dist/develop-lib/extract-from-zip.d.ts +1 -0
  10. package/dist/develop-lib/find-nearest-package.d.ts +2 -0
  11. package/dist/develop-lib/generate-extension-types.d.ts +1 -0
  12. package/dist/develop-lib/generate-zip.d.ts +2 -0
  13. package/dist/develop-lib/get-extension-config.d.ts +6 -0
  14. package/dist/develop-lib/get-project-path.d.ts +6 -0
  15. package/dist/develop-lib/install-dependencies.d.ts +2 -0
  16. package/dist/develop-lib/messages.d.ts +35 -0
  17. package/dist/develop-lib/validate-user-dependencies.d.ts +1 -0
  18. package/dist/ensure-hmr-for-scripts.js +74 -3
  19. package/dist/extensions/chrome-manager-extension/background.js +1 -1
  20. package/dist/extensions/chrome-manager-extension/images/logo.png +0 -0
  21. package/dist/extensions/chrome-manager-extension/manifest.json +3 -3
  22. package/dist/extensions/chrome-manager-extension/pages/welcome.html +3 -6
  23. package/dist/extensions/chrome-manager-extension/reload-service.js +214 -62
  24. package/dist/extensions/chromium-based-manager-extension/background.js +1 -1
  25. package/dist/extensions/chromium-based-manager-extension/images/logo.png +0 -0
  26. package/dist/extensions/chromium-based-manager-extension/manifest.json +3 -3
  27. package/dist/extensions/chromium-based-manager-extension/pages/welcome.html +3 -6
  28. package/dist/extensions/chromium-based-manager-extension/reload-service.js +185 -28
  29. package/dist/extensions/edge-manager-extension/background.js +1 -1
  30. package/dist/extensions/edge-manager-extension/images/logo.png +0 -0
  31. package/dist/extensions/edge-manager-extension/manifest.json +3 -3
  32. package/dist/extensions/edge-manager-extension/pages/welcome.html +3 -6
  33. package/dist/extensions/edge-manager-extension/reload-service.js +223 -69
  34. package/dist/extensions/firefox-manager-extension/background.js +40 -12
  35. package/dist/extensions/firefox-manager-extension/define-initial-tab.js +10 -12
  36. package/dist/extensions/firefox-manager-extension/images/logo.png +0 -0
  37. package/dist/extensions/firefox-manager-extension/manifest.json +4 -5
  38. package/dist/extensions/firefox-manager-extension/pages/welcome.html +3 -6
  39. package/dist/extensions/firefox-manager-extension/reload-service.js +113 -75
  40. package/dist/extensions/gecko-based-manager-extension/background.js +1 -1
  41. package/dist/extensions/gecko-based-manager-extension/define-initial-tab.js +7 -4
  42. package/dist/extensions/gecko-based-manager-extension/images/logo.png +0 -0
  43. package/dist/extensions/gecko-based-manager-extension/manifest.json +3 -3
  44. package/dist/extensions/gecko-based-manager-extension/pages/welcome.html +3 -6
  45. package/dist/extensions/gecko-based-manager-extension/reload-service.js +54 -26
  46. package/dist/inject-chromium-client-loader.js +144 -22
  47. package/dist/inject-firefox-client-loader.js +164 -47
  48. package/dist/minimum-chromium-file.js +25 -0
  49. package/dist/minimum-content-file.js +5 -0
  50. package/dist/minimum-firefox-file.js +17 -0
  51. package/dist/minimum-script-file.js +5 -0
  52. package/dist/module.d.ts +8 -95
  53. package/dist/module.js +10543 -128
  54. package/dist/preview.d.ts +2 -0
  55. package/dist/rslib.config.d.ts +3 -0
  56. package/dist/start.d.ts +2 -0
  57. package/dist/types.d.ts +11 -0
  58. package/dist/vitest.config.d.mts +2 -0
  59. package/dist/webpack/dev-server.d.ts +3 -0
  60. package/dist/webpack/plugin-browsers/browsers-lib/add-progress-bar.d.ts +1 -0
  61. package/dist/webpack/plugin-browsers/browsers-lib/constants.d.ts +5 -0
  62. package/dist/webpack/plugin-browsers/browsers-lib/dynamic-extension-manager.d.ts +35 -0
  63. package/dist/webpack/plugin-browsers/browsers-lib/html-merge.d.ts +1 -0
  64. package/dist/webpack/plugin-browsers/browsers-lib/instance-manager.d.ts +71 -0
  65. package/dist/webpack/plugin-browsers/browsers-lib/messages.d.ts +161 -0
  66. package/dist/webpack/plugin-browsers/browsers-lib/rdp-wire.d.ts +7 -0
  67. package/dist/webpack/plugin-browsers/browsers-lib/shared-utils.d.ts +16 -0
  68. package/dist/webpack/plugin-browsers/browsers-types.d.ts +131 -0
  69. package/dist/webpack/plugin-browsers/index.d.ts +41 -0
  70. package/dist/webpack/plugin-browsers/run-chromium/browser-config.d.ts +3 -0
  71. package/dist/webpack/plugin-browsers/run-chromium/create-profile.d.ts +10 -0
  72. package/dist/webpack/plugin-browsers/run-chromium/index.d.ts +28 -0
  73. package/dist/webpack/plugin-browsers/run-chromium/master-preferences.d.ts +161 -0
  74. package/dist/webpack/plugin-browsers/run-chromium/setup-chrome-inspection/cdp-client.d.ts +29 -0
  75. package/dist/webpack/plugin-browsers/run-chromium/setup-chrome-inspection/index.d.ts +25 -0
  76. package/dist/webpack/plugin-browsers/run-firefox/firefox/binary-detector.d.ts +15 -0
  77. package/dist/webpack/plugin-browsers/run-firefox/firefox/browser-config.d.ts +7 -0
  78. package/dist/webpack/plugin-browsers/run-firefox/firefox/create-profile.d.ts +13 -0
  79. package/dist/webpack/plugin-browsers/run-firefox/firefox/master-preferences.d.ts +95 -0
  80. package/dist/webpack/plugin-browsers/run-firefox/index.d.ts +26 -0
  81. package/dist/webpack/plugin-browsers/run-firefox/remote-firefox/index.d.ts +13 -0
  82. package/dist/webpack/plugin-browsers/run-firefox/remote-firefox/message-utils.d.ts +2 -0
  83. package/dist/webpack/plugin-browsers/run-firefox/remote-firefox/messaging-client.d.ts +42 -0
  84. package/dist/webpack/plugin-browsers/run-firefox/remote-firefox/setup-firefox-inspection.d.ts +31 -0
  85. package/dist/webpack/plugin-compatibility/feature-browser-specific-fields.d.ts +9 -0
  86. package/dist/webpack/plugin-compatibility/feature-polyfill.d.ts +12 -0
  87. package/dist/webpack/plugin-compatibility/index.d.ts +13 -0
  88. package/dist/webpack/plugin-compilation/clean-dist.d.ts +8 -0
  89. package/dist/webpack/plugin-compilation/env.d.ts +9 -0
  90. package/dist/webpack/plugin-compilation/index.d.ts +12 -0
  91. package/dist/webpack/plugin-css/common-style-loaders.d.ts +8 -0
  92. package/dist/webpack/plugin-css/css-in-content-script-loader.d.ts +11 -0
  93. package/dist/webpack/plugin-css/css-in-html-loader.d.ts +8 -0
  94. package/dist/webpack/plugin-css/css-tools/less.d.ts +4 -0
  95. package/dist/webpack/plugin-css/css-tools/postcss.d.ts +3 -0
  96. package/dist/webpack/plugin-css/css-tools/sass.d.ts +4 -0
  97. package/dist/webpack/plugin-css/css-tools/stylelint.d.ts +4 -0
  98. package/dist/webpack/plugin-css/css-tools/tailwind.d.ts +2 -0
  99. package/dist/webpack/plugin-css/index.d.ts +9 -0
  100. package/dist/webpack/plugin-css/is-content-script.d.ts +1 -0
  101. package/dist/webpack/plugin-extension/data/manifest-fields/html-fields/action.d.ts +2 -0
  102. package/dist/webpack/plugin-extension/data/manifest-fields/html-fields/background.d.ts +2 -0
  103. package/dist/webpack/plugin-extension/data/manifest-fields/html-fields/browser_action.d.ts +2 -0
  104. package/dist/webpack/plugin-extension/data/manifest-fields/html-fields/chrome_url_overrides.d.ts +2 -0
  105. package/dist/webpack/plugin-extension/data/manifest-fields/html-fields/devtools_page.d.ts +2 -0
  106. package/dist/webpack/plugin-extension/data/manifest-fields/html-fields/index.d.ts +2 -0
  107. package/dist/webpack/plugin-extension/data/manifest-fields/html-fields/options_ui.d.ts +2 -0
  108. package/dist/webpack/plugin-extension/data/manifest-fields/html-fields/page_action.d.ts +2 -0
  109. package/dist/webpack/plugin-extension/data/manifest-fields/html-fields/sandbox.d.ts +2 -0
  110. package/dist/webpack/plugin-extension/data/manifest-fields/html-fields/side_panel.d.ts +2 -0
  111. package/dist/webpack/plugin-extension/data/manifest-fields/html-fields/sidebar_action.d.ts +2 -0
  112. package/dist/webpack/plugin-extension/data/manifest-fields/icons-fields/action.d.ts +2 -0
  113. package/dist/webpack/plugin-extension/data/manifest-fields/icons-fields/browser_action.d.ts +2 -0
  114. package/dist/webpack/plugin-extension/data/manifest-fields/icons-fields/browser_action.theme_icons.d.ts +2 -0
  115. package/dist/webpack/plugin-extension/data/manifest-fields/icons-fields/icons.d.ts +2 -0
  116. package/dist/webpack/plugin-extension/data/manifest-fields/icons-fields/index.d.ts +2 -0
  117. package/dist/webpack/plugin-extension/data/manifest-fields/icons-fields/normalize.d.ts +6 -0
  118. package/dist/webpack/plugin-extension/data/manifest-fields/icons-fields/page_action.d.ts +2 -0
  119. package/dist/webpack/plugin-extension/data/manifest-fields/icons-fields/sidebar_action.d.ts +2 -0
  120. package/dist/webpack/plugin-extension/data/manifest-fields/index.d.ts +19 -0
  121. package/dist/webpack/plugin-extension/data/manifest-fields/json-fields/declarative_net_request.d.ts +2 -0
  122. package/dist/webpack/plugin-extension/data/manifest-fields/json-fields/index.d.ts +2 -0
  123. package/dist/webpack/plugin-extension/data/manifest-fields/json-fields/storage.d.ts +2 -0
  124. package/dist/webpack/plugin-extension/data/manifest-fields/locales-fields/index.d.ts +1 -0
  125. package/dist/webpack/plugin-extension/data/manifest-fields/normalize.d.ts +10 -0
  126. package/dist/webpack/plugin-extension/data/manifest-fields/scripts-fields/background.d.ts +2 -0
  127. package/dist/webpack/plugin-extension/data/manifest-fields/scripts-fields/content_scripts.d.ts +2 -0
  128. package/dist/webpack/plugin-extension/data/manifest-fields/scripts-fields/index.d.ts +2 -0
  129. package/dist/webpack/plugin-extension/data/manifest-fields/scripts-fields/service_worker.d.ts +2 -0
  130. package/dist/webpack/plugin-extension/data/manifest-fields/scripts-fields/user_scripts.d.ts +2 -0
  131. package/dist/webpack/plugin-extension/data/manifest-fields/web-resources-fields/index.d.ts +2 -0
  132. package/dist/webpack/plugin-extension/data/special-folders/generate-entries.d.ts +4 -0
  133. package/dist/webpack/plugin-extension/data/special-folders/index.d.ts +12 -0
  134. package/dist/webpack/plugin-extension/feature-html/__spec__/html-lib/test-utils.d.ts +18 -0
  135. package/dist/webpack/plugin-extension/feature-html/html-lib/parse-html.d.ts +8 -0
  136. package/dist/webpack/plugin-extension/feature-html/html-lib/patch-html.d.ts +8 -0
  137. package/dist/webpack/plugin-extension/feature-html/html-lib/utils.d.ts +18 -0
  138. package/dist/webpack/plugin-extension/feature-html/index.d.ts +37 -0
  139. package/dist/webpack/plugin-extension/feature-html/steps/add-assets-to-compilation.d.ts +11 -0
  140. package/dist/webpack/plugin-extension/feature-html/steps/add-scripts-and-styles-to-compilation.d.ts +10 -0
  141. package/dist/webpack/plugin-extension/feature-html/steps/add-to-file-dependencies.d.ts +10 -0
  142. package/dist/webpack/plugin-extension/feature-html/steps/emit-html-file.d.ts +9 -0
  143. package/dist/webpack/plugin-extension/feature-html/steps/ensure-hmr-for-scripts.d.ts +2 -0
  144. package/dist/webpack/plugin-extension/feature-html/steps/handle-common-errors.d.ts +10 -0
  145. package/dist/webpack/plugin-extension/feature-html/steps/minimum-script-file.d.ts +1 -0
  146. package/dist/webpack/plugin-extension/feature-html/steps/throw-if-recompile-is-needed.d.ts +13 -0
  147. package/dist/webpack/plugin-extension/feature-html/steps/update-html-file.d.ts +10 -0
  148. package/dist/webpack/plugin-extension/feature-icons/index.d.ts +25 -0
  149. package/dist/webpack/plugin-extension/feature-icons/steps/add-to-file-dependencies.d.ts +9 -0
  150. package/dist/webpack/plugin-extension/feature-icons/steps/emit-file.d.ts +9 -0
  151. package/dist/webpack/plugin-extension/feature-json/index.d.ts +18 -0
  152. package/dist/webpack/plugin-extension/feature-locales/get-locales.d.ts +1 -0
  153. package/dist/webpack/plugin-extension/feature-locales/index.d.ts +13 -0
  154. package/dist/webpack/plugin-extension/feature-manifest/index.d.ts +23 -0
  155. package/dist/webpack/plugin-extension/feature-manifest/manifest-overrides/common/background.d.ts +10 -0
  156. package/dist/webpack/plugin-extension/feature-manifest/manifest-overrides/common/chrome_url_overrides.d.ts +8 -0
  157. package/dist/webpack/plugin-extension/feature-manifest/manifest-overrides/common/commands.d.ts +16 -0
  158. package/dist/webpack/plugin-extension/feature-manifest/manifest-overrides/common/content_scripts.d.ts +7 -0
  159. package/dist/webpack/plugin-extension/feature-manifest/manifest-overrides/common/content_security_policy.d.ts +4 -0
  160. package/dist/webpack/plugin-extension/feature-manifest/manifest-overrides/common/devtools_page.d.ts +4 -0
  161. package/dist/webpack/plugin-extension/feature-manifest/manifest-overrides/common/icons.d.ts +6 -0
  162. package/dist/webpack/plugin-extension/feature-manifest/manifest-overrides/common/index.d.ts +2 -0
  163. package/dist/webpack/plugin-extension/feature-manifest/manifest-overrides/common/omnibox.d.ts +2 -0
  164. package/dist/webpack/plugin-extension/feature-manifest/manifest-overrides/common/options_page.d.ts +4 -0
  165. package/dist/webpack/plugin-extension/feature-manifest/manifest-overrides/common/options_ui.d.ts +8 -0
  166. package/dist/webpack/plugin-extension/feature-manifest/manifest-overrides/common/page_action.d.ts +8 -0
  167. package/dist/webpack/plugin-extension/feature-manifest/manifest-overrides/common/permissions.d.ts +4 -0
  168. package/dist/webpack/plugin-extension/feature-manifest/manifest-overrides/common/sandbox.d.ts +7 -0
  169. package/dist/webpack/plugin-extension/feature-manifest/manifest-overrides/common/sidebar_action.d.ts +2 -0
  170. package/dist/webpack/plugin-extension/feature-manifest/manifest-overrides/common/storage.d.ts +6 -0
  171. package/dist/webpack/plugin-extension/feature-manifest/manifest-overrides/common/theme.d.ts +2 -0
  172. package/dist/webpack/plugin-extension/feature-manifest/manifest-overrides/common/user_scripts.d.ts +2 -0
  173. package/dist/webpack/plugin-extension/feature-manifest/manifest-overrides/common/web_accessible_resources.d.ts +9 -0
  174. package/dist/webpack/plugin-extension/feature-manifest/manifest-overrides/index.d.ts +2 -0
  175. package/dist/webpack/plugin-extension/feature-manifest/manifest-overrides/mv2/background.d.ts +10 -0
  176. package/dist/webpack/plugin-extension/feature-manifest/manifest-overrides/mv2/browser_action.d.ts +12 -0
  177. package/dist/webpack/plugin-extension/feature-manifest/manifest-overrides/mv2/chrome_settings_overrides.d.ts +24 -0
  178. package/dist/webpack/plugin-extension/feature-manifest/manifest-overrides/mv2/index.d.ts +2 -0
  179. package/dist/webpack/plugin-extension/feature-manifest/manifest-overrides/mv2/page_action.d.ts +1 -0
  180. package/dist/webpack/plugin-extension/feature-manifest/manifest-overrides/mv2/sidebar_action.d.ts +1 -0
  181. package/dist/webpack/plugin-extension/feature-manifest/manifest-overrides/mv2/theme_experiment.d.ts +2 -0
  182. package/dist/webpack/plugin-extension/feature-manifest/manifest-overrides/mv3/action.d.ts +8 -0
  183. package/dist/webpack/plugin-extension/feature-manifest/manifest-overrides/mv3/background.d.ts +10 -0
  184. package/dist/webpack/plugin-extension/feature-manifest/manifest-overrides/mv3/declarative_net_request.d.ts +2 -0
  185. package/dist/webpack/plugin-extension/feature-manifest/manifest-overrides/mv3/host_permissions.d.ts +2 -0
  186. package/dist/webpack/plugin-extension/feature-manifest/manifest-overrides/mv3/index.d.ts +2 -0
  187. package/dist/webpack/plugin-extension/feature-manifest/manifest-overrides/mv3/side_panel.d.ts +2 -0
  188. package/dist/webpack/plugin-extension/feature-manifest/steps/add-dependencies.d.ts +6 -0
  189. package/dist/webpack/plugin-extension/feature-manifest/steps/check-manifest-files.d.ts +17 -0
  190. package/dist/webpack/plugin-extension/feature-manifest/steps/emit-manifest.d.ts +7 -0
  191. package/dist/webpack/plugin-extension/feature-manifest/steps/throw-if-recompile.d.ts +11 -0
  192. package/dist/webpack/plugin-extension/feature-manifest/steps/update-manifest.d.ts +9 -0
  193. package/dist/webpack/plugin-extension/feature-scripts/index.d.ts +27 -0
  194. package/dist/webpack/plugin-extension/feature-scripts/scripts-lib/utils.d.ts +3 -0
  195. package/dist/webpack/plugin-extension/feature-scripts/steps/add-content-script-wrapper.d.ts +2 -0
  196. package/dist/webpack/plugin-extension/feature-scripts/steps/add-hmr-accept-code.d.ts +2 -0
  197. package/dist/webpack/plugin-extension/feature-scripts/steps/add-public-path-for-main-world.d.ts +11 -0
  198. package/dist/webpack/plugin-extension/feature-scripts/steps/add-public-path-runtime-module.d.ts +4 -0
  199. package/dist/webpack/plugin-extension/feature-scripts/steps/add-scripts.d.ts +9 -0
  200. package/dist/webpack/plugin-extension/feature-scripts/steps/deprecated-shadow-root.d.ts +2 -0
  201. package/dist/webpack/plugin-extension/feature-scripts/steps/javascript-content-script-wrapper.d.ts +1 -0
  202. package/dist/webpack/plugin-extension/feature-scripts/steps/preact-content-script-wrapper.d.ts +1 -0
  203. package/dist/webpack/plugin-extension/feature-scripts/steps/react-content-script-wrapper.d.ts +1 -0
  204. package/dist/webpack/plugin-extension/feature-scripts/steps/svelte-content-script-wrapper.d.ts +1 -0
  205. package/dist/webpack/plugin-extension/feature-scripts/steps/typescript-content-script-wrapper.d.ts +1 -0
  206. package/dist/webpack/plugin-extension/feature-scripts/steps/vue-content-script-wrapper.d.ts +1 -0
  207. package/dist/webpack/plugin-extension/feature-special-folders/copy-public-folder.d.ts +14 -0
  208. package/dist/webpack/plugin-extension/feature-special-folders/index.d.ts +19 -0
  209. package/dist/webpack/plugin-extension/feature-special-folders/warn-upon-folder-changes.d.ts +7 -0
  210. package/dist/webpack/plugin-extension/feature-web-resources/clean-matches.d.ts +7 -0
  211. package/dist/webpack/plugin-extension/feature-web-resources/index.d.ts +18 -0
  212. package/dist/webpack/plugin-extension/index.d.ts +10 -0
  213. package/dist/webpack/plugin-js-frameworks/index.d.ts +13 -0
  214. package/dist/webpack/plugin-js-frameworks/js-tools/babel.d.ts +16 -0
  215. package/dist/webpack/plugin-js-frameworks/js-tools/preact.d.ts +3 -0
  216. package/dist/webpack/plugin-js-frameworks/js-tools/react.d.ts +3 -0
  217. package/dist/webpack/plugin-js-frameworks/js-tools/svelte.d.ts +3 -0
  218. package/dist/webpack/plugin-js-frameworks/js-tools/typescript.d.ts +36 -0
  219. package/dist/webpack/plugin-js-frameworks/js-tools/vue.d.ts +3 -0
  220. package/dist/webpack/plugin-js-frameworks/load-loader-options.d.ts +1 -0
  221. package/dist/webpack/plugin-reload/index.d.ts +13 -0
  222. package/dist/webpack/plugin-reload/reload-lib/messages.d.ts +106 -0
  223. package/dist/webpack/plugin-reload/reload-types.d.ts +14 -0
  224. package/dist/webpack/plugin-reload/start-server.d.ts +4 -0
  225. package/dist/webpack/plugin-reload/steps/create-web-socket-server/index.d.ts +14 -0
  226. package/dist/webpack/plugin-reload/steps/create-web-socket-server/web-socket-server/broadcast-message.d.ts +2 -0
  227. package/dist/webpack/plugin-reload/steps/create-web-socket-server/web-socket-server/message-dispatcher.d.ts +2 -0
  228. package/dist/webpack/plugin-reload/steps/create-web-socket-server/web-socket-server/servers.d.ts +2 -0
  229. package/dist/webpack/plugin-reload/steps/setup-chromium-reload-client/index.d.ts +3 -0
  230. package/dist/webpack/plugin-reload/steps/setup-chromium-reload-client/inject-chromium-client-loader.d.ts +9 -0
  231. package/dist/webpack/plugin-reload/steps/setup-chromium-reload-client/minimum-chromium-file.d.ts +0 -0
  232. package/dist/webpack/plugin-reload/steps/setup-firefox-reload-client/index.d.ts +3 -0
  233. package/dist/webpack/plugin-reload/steps/setup-firefox-reload-client/inject-firefox-client-loader.d.ts +9 -0
  234. package/dist/webpack/plugin-reload/steps/setup-firefox-reload-client/minimum-firefox-file.d.ts +0 -0
  235. package/dist/webpack/plugin-reload/steps/setup-reload-strategy/apply-manifest-dev-defaults/index.d.ts +9 -0
  236. package/dist/webpack/plugin-reload/steps/setup-reload-strategy/apply-manifest-dev-defaults/patch-background.d.ts +15 -0
  237. package/dist/webpack/plugin-reload/steps/setup-reload-strategy/apply-manifest-dev-defaults/patch-csp.d.ts +5 -0
  238. package/dist/webpack/plugin-reload/steps/setup-reload-strategy/apply-manifest-dev-defaults/patch-externally-connectable.d.ts +10 -0
  239. package/dist/webpack/plugin-reload/steps/setup-reload-strategy/apply-manifest-dev-defaults/patch-web-resources.d.ts +10 -0
  240. package/dist/webpack/plugin-reload/steps/setup-reload-strategy/generate-manager-extension.d.ts +15 -0
  241. package/dist/webpack/plugin-reload/steps/setup-reload-strategy/index.d.ts +10 -0
  242. package/dist/webpack/plugin-reload/steps/setup-reload-strategy/target-web-extension-plugin/index.d.ts +13 -0
  243. package/dist/webpack/plugin-static-assets/index.d.ts +12 -0
  244. package/dist/webpack/webpack-config.d.ts +14 -0
  245. package/dist/webpack/webpack-lib/auto-exit.d.ts +1 -0
  246. package/dist/webpack/webpack-lib/constants.d.ts +4 -0
  247. package/dist/webpack/webpack-lib/messages.d.ts +121 -0
  248. package/dist/webpack/webpack-lib/port-manager.d.ts +27 -0
  249. package/dist/webpack/webpack-lib/utils.d.ts +20 -0
  250. package/dist/webpack/webpack-types.d.ts +49 -0
  251. package/package.json +64 -29
  252. package/dist/depreacated-shadow-root.js +0 -34
  253. package/dist/inject-content-css-during-dev.js +0 -10
  254. package/dist/minimum-chromium-file.mjs +0 -1
  255. package/dist/minimum-content-file.mjs +0 -1
  256. package/dist/minimum-firefox-file.mjs +0 -1
  257. package/dist/resolver-loader.js +0 -1
  258. package/dist/resolver-module.mjs +0 -1
  259. package/dist/tailwind.config.js +0 -25
  260. /package/dist/{minimum-script-file.mjs → webpack/plugin-extension/feature-scripts/steps/minimum-content-file.d.ts} +0 -0
@@ -0,0 +1,1777 @@
1
+ "use strict";
2
+ var __webpack_require__ = {};
3
+ (()=>{
4
+ __webpack_require__.d = (exports1, definition)=>{
5
+ for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
6
+ enumerable: true,
7
+ get: definition[key]
8
+ });
9
+ };
10
+ })();
11
+ (()=>{
12
+ __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
13
+ })();
14
+ (()=>{
15
+ __webpack_require__.r = (exports1)=>{
16
+ if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
17
+ value: 'Module'
18
+ });
19
+ Object.defineProperty(exports1, '__esModule', {
20
+ value: true
21
+ });
22
+ };
23
+ })();
24
+ var __webpack_exports__ = {};
25
+ __webpack_require__.r(__webpack_exports__);
26
+ __webpack_require__.d(__webpack_exports__, {
27
+ default: ()=>add_content_script_wrapper
28
+ });
29
+ const external_path_namespaceObject = require("path");
30
+ const external_fs_namespaceObject = require("fs");
31
+ const external_loader_utils_namespaceObject = require("loader-utils");
32
+ const external_schema_utils_namespaceObject = require("schema-utils");
33
+ function extractCSSImports(source) {
34
+ const cssImports = [];
35
+ const lines = source.split('\n');
36
+ const cssImportPatterns = [
37
+ /^\s*import\s+['"]([^'"]*\.(?:css|scss|sass|less|module\.css))['"]/,
38
+ /^\s*import\s+['"]([^'"]*\.(?:css|scss|sass|less|module\.css))['"]\s*;?\s*$/,
39
+ /^\s*import\s+['"]([^'"]*\.(?:css|scss|sass|less|module\.css))['"]\s*from\s+['"][^'"]*['"]/
40
+ ];
41
+ for (const line of lines){
42
+ const trimmedLine = line.trim();
43
+ if (!(trimmedLine.startsWith('//') || trimmedLine.startsWith('/*'))) for (const pattern of cssImportPatterns){
44
+ const match = pattern.exec(line);
45
+ if (match) {
46
+ const cssPath = match[1];
47
+ if (cssPath && !cssImports.includes(cssPath)) cssImports.push(cssPath);
48
+ }
49
+ }
50
+ }
51
+ return cssImports;
52
+ }
53
+ function generateReactWrapperCode(source, resourcePath) {
54
+ external_path_namespaceObject.basename(resourcePath, external_path_namespaceObject.extname(resourcePath));
55
+ const cssImports = extractCSSImports(source);
56
+ const resourceDir = external_path_namespaceObject.dirname(resourcePath);
57
+ if ('development' === process.env.EXTENSION_ENV) console.log("[Extension.js] Detected React framework with CSS imports:", cssImports);
58
+ const cssContentMap = {};
59
+ for (const cssImport of cssImports)try {
60
+ const cssPath = external_path_namespaceObject.resolve(resourceDir, cssImport);
61
+ if (external_fs_namespaceObject.existsSync(cssPath)) {
62
+ const cssContent = external_fs_namespaceObject.readFileSync(cssPath, 'utf-8');
63
+ const escapedCSS = cssContent.replace(/\\/g, '\\\\').replace(/`/g, '\\`').replace(/\${/g, '\\${').replace(/\n/g, ' ').replace(/\s+/g, ' ').trim();
64
+ cssContentMap[cssImport] = escapedCSS;
65
+ if ('development' === process.env.EXTENSION_ENV) console.log(`[Extension.js] Read CSS content for ${cssImport}, length: ${cssContent.length}`);
66
+ } else if ('development' === process.env.EXTENSION_ENV) console.warn(`[Extension.js] CSS file not found: ${cssPath}`);
67
+ } catch (error) {
68
+ if ('development' === process.env.EXTENSION_ENV) console.warn(`[Extension.js] Failed to read CSS file ${cssImport}:`, error);
69
+ }
70
+ const wrapperCode = `
71
+ // React Content Script Wrapper - Auto-generated by Extension.js
72
+ // This wrapper provides Shadow DOM isolation and CSS injection for React content scripts
73
+
74
+ // Original React content script source (directive processed)
75
+ ${source.replace(/'use shadow-dom'/g, "// 'use shadow-dom'").replace(/"use shadow-dom"/g, '// "use shadow-dom"')}
76
+
77
+ // Content script options interface
78
+ export interface ContentScriptOptions {
79
+ rootElement?: string
80
+ rootClassName?: string
81
+ stylesheets?: string[]
82
+ }
83
+
84
+ // Content script instance interface
85
+ export interface ContentScriptInstance {
86
+ mount: (container: HTMLElement) => void
87
+ unmount: () => void
88
+ }
89
+
90
+ // React Content script wrapper class
91
+ class ReactContentScriptWrapper {
92
+ private rootElement: HTMLElement | null = null
93
+ private shadowRoot: ShadowRoot | null = null
94
+ private styleElement: HTMLStyleElement | null = null
95
+ private renderFunction: (container: HTMLElement) => (() => void) | void
96
+ private unmountFunction: (() => void) | null = null
97
+ private options: ContentScriptOptions
98
+
99
+ constructor(renderFunction: (container: HTMLElement) => (() => void) | void, options: ContentScriptOptions = {}) {
100
+ this.renderFunction = renderFunction
101
+ this.options = {
102
+ rootElement: 'extension-root',
103
+ rootClassName: undefined, // React handles its own styling
104
+ stylesheets: ${JSON.stringify(cssImports.length > 0 ? cssImports : [
105
+ './styles.css'
106
+ ])},
107
+ ...options
108
+ }
109
+ }
110
+
111
+ async mount(container?: HTMLElement): Promise<void> {
112
+ console.log('[Extension.js] React wrapper mount called')
113
+ if (this.rootElement) {
114
+ this.unmount()
115
+ }
116
+
117
+ // Create root element - React handles its own container styling
118
+ this.rootElement = container || document.createElement('div')
119
+ this.rootElement.id = this.options.rootElement!
120
+ if (this.options.rootClassName) {
121
+ this.rootElement.className = this.options.rootClassName
122
+ }
123
+ // React component handles its own styling
124
+
125
+ // Create shadow root for style isolation
126
+ this.shadowRoot = this.rootElement.attachShadow({ mode: 'open' })
127
+
128
+ // Inject styles FIRST
129
+ console.log('[Extension.js] About to inject styles')
130
+ await this.injectStyles()
131
+
132
+ // Render React content
133
+ console.log('[Extension.js] About to render React content')
134
+ const result = this.renderFunction(this.shadowRoot as any)
135
+ if (typeof result === 'function') {
136
+ this.unmountFunction = result
137
+ }
138
+
139
+ // Append to document if no container provided
140
+ if (!container) {
141
+ document.body.appendChild(this.rootElement)
142
+ }
143
+
144
+ console.log('[Extension.js] React wrapper mount complete')
145
+ }
146
+
147
+ unmount() {
148
+ if (this.unmountFunction) {
149
+ this.unmountFunction()
150
+ this.unmountFunction = null
151
+ }
152
+
153
+ if (this.rootElement && this.rootElement.parentNode) {
154
+ this.rootElement.parentNode.removeChild(this.rootElement)
155
+ }
156
+
157
+ this.rootElement = null
158
+ this.shadowRoot = null
159
+ this.styleElement = null
160
+ }
161
+
162
+ // Inject styles with hardcoded CSS content for React templates
163
+ private async injectStyles(): Promise<void> {
164
+ console.log('[Extension.js] React injectStyles called')
165
+ const targetRoot = this.shadowRoot || this.rootElement!
166
+
167
+ // Create style element
168
+ this.styleElement = document.createElement('style')
169
+ targetRoot.appendChild(this.styleElement)
170
+
171
+ // Fetch CSS content
172
+ try {
173
+ console.log('[Extension.js] About to fetch CSS')
174
+ const cssContent = await this.fetchCSS()
175
+ console.log('[Extension.js] CSS fetched, length:', cssContent.length)
176
+ this.styleElement.textContent = cssContent
177
+ console.log('[Extension.js] React CSS injected successfully')
178
+ } catch (error) {
179
+ console.error('[Extension.js] Failed to inject React CSS:', error)
180
+ }
181
+
182
+ // Setup HMR for CSS files
183
+ this.setupCSSHMR()
184
+ }
185
+
186
+ // Fetch CSS with hardcoded content for React templates
187
+ private async fetchCSS(): Promise<string> {
188
+ let allCSS = ''
189
+
190
+ console.log('[Extension.js] Processing React stylesheets:', this.options.stylesheets)
191
+
192
+ // CSS content map is injected at build time
193
+ const cssContentMap: Record<string, string> = ${JSON.stringify(cssContentMap)}
194
+
195
+ for (const stylesheet of this.options.stylesheets) {
196
+ try {
197
+ console.log('[Extension.js] Processing React stylesheet:', stylesheet)
198
+ // Check if we have hardcoded content for this stylesheet
199
+ if (cssContentMap[stylesheet]) {
200
+ const cssContent = cssContentMap[stylesheet]
201
+ allCSS += cssContent + '\\n'
202
+ console.log(\`[Extension.js] Successfully injected React \${stylesheet} content\`)
203
+ continue
204
+ }
205
+
206
+ // For stylesheets without hardcoded content, try to fetch them
207
+ const cssUrl = new URL(stylesheet, import.meta.url)
208
+ const response = await fetch(cssUrl)
209
+ const text = await response.text()
210
+ if (response.ok) {
211
+ allCSS += text + '\\n'
212
+ console.log('[Extension.js] Successfully fetched stylesheet:', stylesheet)
213
+ } else {
214
+ console.warn('[Extension.js] Failed to fetch CSS:', stylesheet)
215
+ }
216
+ } catch (error) {
217
+ console.warn('[Extension.js] Failed to fetch React CSS:', stylesheet, error)
218
+ }
219
+ }
220
+
221
+ const result = allCSS || '/* No CSS loaded */'
222
+ console.log('[Extension.js] Final CSS result length:', result.length)
223
+ return result
224
+ }
225
+
226
+ // Setup CSS HMR for React templates
227
+ private setupCSSHMR() {
228
+ if (!import.meta.webpackHot) return
229
+
230
+ // Setup HMR for each CSS file
231
+ for (const stylesheet of this.options.stylesheets) {
232
+ import.meta.webpackHot?.accept(stylesheet, async () => {
233
+ try {
234
+ const cssContent = await this.fetchCSS()
235
+ if (this.styleElement) {
236
+ this.styleElement.textContent = cssContent
237
+ console.log('[Extension.js] React CSS updated via HMR:', stylesheet)
238
+ }
239
+ } catch (error) {
240
+ console.error('[Extension.js] Failed to update React CSS via HMR:', stylesheet, error)
241
+ }
242
+ })
243
+ }
244
+ }
245
+ }
246
+
247
+ // Initialize React content script with wrapper
248
+ function initializeReactContentScript(
249
+ options: ContentScriptOptions,
250
+ renderFunction: (container: HTMLElement) => (() => void) | void
251
+ ): ContentScriptInstance {
252
+ const wrapper = new ReactContentScriptWrapper(renderFunction, options)
253
+
254
+ return {
255
+ mount: (container?: HTMLElement) => wrapper.mount(container),
256
+ unmount: () => wrapper.unmount()
257
+ }
258
+ }
259
+
260
+ // Auto-initialize the React content script with the wrapper
261
+ export function autoInitializeReactContentScript(
262
+ options: ContentScriptOptions = {}
263
+ ): ContentScriptInstance {
264
+ // Get the render function from the imported contentScript
265
+ const renderFunction = contentScript(options)
266
+
267
+ // Initialize with the wrapper using the detected CSS imports
268
+ return initializeReactContentScript(options, renderFunction)
269
+ }
270
+
271
+ // Simple initialization for React
272
+ let unmount: (() => void) | undefined
273
+
274
+ async function initialize() {
275
+ console.log('[Extension.js] React wrapper initialize called')
276
+ if (unmount) {
277
+ console.log('[Extension.js] Unmounting previous React instance')
278
+ unmount()
279
+ }
280
+
281
+ // Get the render function from the contentScript function
282
+ const renderFunction = contentScript({})
283
+ const wrapper = new ReactContentScriptWrapper(renderFunction, {})
284
+ await wrapper.mount()
285
+ unmount = () => wrapper.unmount()
286
+ console.log('[Extension.js] React wrapper initialization complete')
287
+ }
288
+
289
+ if (import.meta.webpackHot) {
290
+ import.meta.webpackHot?.accept()
291
+ import.meta.webpackHot?.dispose(() => unmount?.())
292
+
293
+ // Accept changes to this file
294
+ import.meta.webpackHot?.accept(() => {
295
+ initialize()
296
+ })
297
+ }
298
+
299
+ if (document.readyState === 'complete') {
300
+ initialize()
301
+ } else {
302
+ document.addEventListener('readystatechange', () => {
303
+ if (document.readyState === 'complete') {
304
+ initialize()
305
+ }
306
+ })
307
+ }
308
+
309
+ export default ReactContentScriptWrapper
310
+ `;
311
+ return wrapperCode;
312
+ }
313
+ function vue_content_script_wrapper_extractCSSImports(source) {
314
+ const cssImports = [];
315
+ const lines = source.split('\n');
316
+ const cssImportPatterns = [
317
+ /^\s*import\s+['"]([^'"]*\.(?:css|scss|sass|less|module\.css))['"]/,
318
+ /^\s*import\s+['"]([^'"]*\.(?:css|scss|sass|less|module\.css))['"]\s*;?\s*$/,
319
+ /^\s*import\s+['"]([^'"]*\.(?:css|scss|sass|less|module\.css))['"]\s*from\s+['"][^'"]*['"]/
320
+ ];
321
+ for (const line of lines){
322
+ const trimmedLine = line.trim();
323
+ if (!(trimmedLine.startsWith('//') || trimmedLine.startsWith('/*'))) for (const pattern of cssImportPatterns){
324
+ const match = pattern.exec(line);
325
+ if (match) {
326
+ const cssPath = match[1];
327
+ if (cssPath && !cssImports.includes(cssPath)) cssImports.push(cssPath);
328
+ }
329
+ }
330
+ }
331
+ return cssImports;
332
+ }
333
+ function generateVueWrapperCode(source, resourcePath) {
334
+ external_path_namespaceObject.basename(resourcePath, external_path_namespaceObject.extname(resourcePath));
335
+ const cssImports = vue_content_script_wrapper_extractCSSImports(source);
336
+ const resourceDir = external_path_namespaceObject.dirname(resourcePath);
337
+ if ('development' === process.env.EXTENSION_ENV) console.log("[Extension.js] Detected Vue framework with CSS imports:", cssImports);
338
+ const cssContentMap = {};
339
+ for (const cssImport of cssImports)try {
340
+ const cssPath = external_path_namespaceObject.resolve(resourceDir, cssImport);
341
+ if (external_fs_namespaceObject.existsSync(cssPath)) {
342
+ const cssContent = external_fs_namespaceObject.readFileSync(cssPath, 'utf-8');
343
+ const escapedCSS = cssContent.replace(/\\/g, '\\\\').replace(/`/g, '\\`').replace(/\${/g, '\\${').replace(/\n/g, ' ').replace(/\s+/g, ' ').trim();
344
+ cssContentMap[cssImport] = escapedCSS;
345
+ if ('development' === process.env.EXTENSION_ENV) console.log(`[Extension.js] Read CSS content for ${cssImport}, length: ${cssContent.length}`);
346
+ } else if ('development' === process.env.EXTENSION_ENV) console.warn(`[Extension.js] CSS file not found: ${cssPath}`);
347
+ } catch (error) {
348
+ if ('development' === process.env.EXTENSION_ENV) console.warn(`[Extension.js] Failed to read CSS file ${cssImport}:`, error);
349
+ }
350
+ const wrapperCode = `
351
+ // Vue Content Script Wrapper - Auto-generated by Extension.js
352
+ // This wrapper provides Shadow DOM isolation and CSS injection for Vue content scripts
353
+
354
+ // Original Vue content script source (directive processed)
355
+ ${source.replace(/'use shadow-dom'/g, "// 'use shadow-dom'").replace(/"use shadow-dom"/g, '// "use shadow-dom"')}
356
+
357
+ // Content script options interface
358
+ export interface ContentScriptOptions {
359
+ rootElement?: string
360
+ rootClassName?: string
361
+ stylesheets?: string[]
362
+ }
363
+
364
+ // Content script instance interface
365
+ export interface ContentScriptInstance {
366
+ mount: (container: HTMLElement) => void
367
+ unmount: () => void
368
+ }
369
+
370
+ // Vue Content script wrapper class
371
+ class VueContentScriptWrapper {
372
+ private rootElement: HTMLElement | null = null
373
+ private shadowRoot: ShadowRoot | null = null
374
+ private styleElement: HTMLStyleElement | null = null
375
+ private renderFunction: (container: HTMLElement) => (() => void) | void
376
+ private unmountFunction: (() => void) | null = null
377
+ private options: ContentScriptOptions
378
+
379
+ constructor(renderFunction: (container: HTMLElement) => (() => void) | void, options: ContentScriptOptions = {}) {
380
+ this.renderFunction = renderFunction
381
+ this.options = {
382
+ rootElement: 'extension-root',
383
+ rootClassName: undefined, // Vue handles its own styling
384
+ stylesheets: ${JSON.stringify(cssImports.length > 0 ? cssImports : [
385
+ './styles.css'
386
+ ])},
387
+ ...options
388
+ }
389
+ }
390
+
391
+ async mount(container?: HTMLElement): Promise<void> {
392
+ console.log('[Extension.js] Vue wrapper mount called')
393
+ if (this.rootElement) {
394
+ this.unmount()
395
+ }
396
+
397
+ // Create root element - Vue handles its own container styling
398
+ this.rootElement = container || document.createElement('div')
399
+ this.rootElement.id = this.options.rootElement!
400
+ if (this.options.rootClassName) {
401
+ this.rootElement.className = this.options.rootClassName
402
+ }
403
+ // Vue component handles its own styling
404
+
405
+ // Create shadow root for style isolation
406
+ this.shadowRoot = this.rootElement.attachShadow({ mode: 'open' })
407
+
408
+ // Inject styles FIRST
409
+ console.log('[Extension.js] About to inject styles')
410
+ await this.injectStyles()
411
+
412
+ // Render Vue content
413
+ console.log('[Extension.js] About to render Vue content')
414
+ const result = this.renderFunction(this.shadowRoot as any)
415
+ if (typeof result === 'function') {
416
+ this.unmountFunction = result
417
+ }
418
+
419
+ // Append to document if no container provided
420
+ if (!container) {
421
+ document.body.appendChild(this.rootElement)
422
+ }
423
+
424
+ console.log('[Extension.js] Vue wrapper mount complete')
425
+ }
426
+
427
+ unmount() {
428
+ if (this.unmountFunction) {
429
+ this.unmountFunction()
430
+ this.unmountFunction = null
431
+ }
432
+
433
+ if (this.rootElement && this.rootElement.parentNode) {
434
+ this.rootElement.parentNode.removeChild(this.rootElement)
435
+ }
436
+
437
+ this.rootElement = null
438
+ this.shadowRoot = null
439
+ this.styleElement = null
440
+ }
441
+
442
+ // Inject styles with hardcoded CSS content for Vue templates
443
+ private async injectStyles(): Promise<void> {
444
+ console.log('[Extension.js] Vue injectStyles called')
445
+ const targetRoot = this.shadowRoot || this.rootElement!
446
+
447
+ // Create style element
448
+ this.styleElement = document.createElement('style')
449
+ targetRoot.appendChild(this.styleElement)
450
+
451
+ // Fetch CSS content
452
+ try {
453
+ console.log('[Extension.js] About to fetch CSS')
454
+ const cssContent = await this.fetchCSS()
455
+ console.log('[Extension.js] CSS fetched, length:', cssContent.length)
456
+ this.styleElement.textContent = cssContent
457
+ console.log('[Extension.js] Vue CSS injected successfully')
458
+ } catch (error) {
459
+ console.error('[Extension.js] Failed to inject Vue CSS:', error)
460
+ }
461
+
462
+ // Setup HMR for CSS files
463
+ this.setupCSSHMR()
464
+ }
465
+
466
+ // Fetch CSS with hardcoded content for Vue templates
467
+ private async fetchCSS(): Promise<string> {
468
+ let allCSS = ''
469
+
470
+ console.log('[Extension.js] Processing Vue stylesheets:', this.options.stylesheets)
471
+
472
+ // CSS content map is injected at build time
473
+ const cssContentMap: Record<string, string> = ${JSON.stringify(cssContentMap)}
474
+
475
+ for (const stylesheet of this.options.stylesheets) {
476
+ try {
477
+ console.log('[Extension.js] Processing Vue stylesheet:', stylesheet)
478
+ // Check if we have hardcoded content for this stylesheet
479
+ if (cssContentMap[stylesheet]) {
480
+ const cssContent = cssContentMap[stylesheet]
481
+ allCSS += cssContent + '\\n'
482
+ console.log(\`[Extension.js] Successfully injected Vue \${stylesheet} content\`)
483
+ continue
484
+ }
485
+
486
+ // For stylesheets without hardcoded content, try to fetch them
487
+ const cssUrl = new URL(stylesheet, import.meta.url)
488
+ const response = await fetch(cssUrl)
489
+ const text = await response.text()
490
+ if (response.ok) {
491
+ allCSS += text + '\\n'
492
+ console.log('[Extension.js] Successfully fetched stylesheet:', stylesheet)
493
+ } else {
494
+ console.warn('[Extension.js] Failed to fetch CSS:', stylesheet)
495
+ }
496
+ } catch (error) {
497
+ console.warn('[Extension.js] Failed to fetch Vue CSS:', stylesheet, error)
498
+ }
499
+ }
500
+
501
+ return allCSS
502
+ }
503
+
504
+ // Setup CSS HMR for Vue templates
505
+ private setupCSSHMR() {
506
+ if (!import.meta.webpackHot) return
507
+
508
+ // Setup HMR for each CSS file
509
+ for (const stylesheet of this.options.stylesheets) {
510
+ import.meta.webpackHot?.accept(stylesheet, async () => {
511
+ try {
512
+ const cssContent = await this.fetchCSS()
513
+ if (this.styleElement) {
514
+ this.styleElement.textContent = cssContent
515
+ console.log('[Extension.js] Vue CSS updated via HMR:', stylesheet)
516
+ }
517
+ } catch (error) {
518
+ console.error('[Extension.js] Failed to update Vue CSS via HMR:', stylesheet, error)
519
+ }
520
+ })
521
+ }
522
+ }
523
+ }
524
+
525
+ // Initialize Vue content script with wrapper
526
+ function initializeVueContentScript(
527
+ options: ContentScriptOptions,
528
+ renderFunction: (container: HTMLElement) => (() => void) | void
529
+ ): ContentScriptInstance {
530
+ const wrapper = new VueContentScriptWrapper(renderFunction, options)
531
+
532
+ return {
533
+ mount: (container?: HTMLElement) => wrapper.mount(container),
534
+ unmount: () => wrapper.unmount()
535
+ }
536
+ }
537
+
538
+ // Auto-initialize the Vue content script with the wrapper
539
+ export function autoInitializeVueContentScript(
540
+ options: ContentScriptOptions = {}
541
+ ): ContentScriptInstance {
542
+ // Get the render function from the imported contentScript
543
+ const renderFunction = contentScript(options)
544
+
545
+ // Initialize with the wrapper using the detected CSS imports
546
+ return initializeVueContentScript(options, renderFunction)
547
+ }
548
+
549
+ // Simple initialization for Vue
550
+ let unmount: (() => void) | undefined
551
+
552
+ async function initialize() {
553
+ console.log('[Extension.js] Vue wrapper initialize called')
554
+ if (unmount) {
555
+ console.log('[Extension.js] Unmounting previous Vue instance')
556
+ unmount()
557
+ }
558
+
559
+ // Get the render function from the contentScript function
560
+ const renderFunction = contentScript({})
561
+ const wrapper = new VueContentScriptWrapper(renderFunction, {})
562
+ await wrapper.mount()
563
+ unmount = () => wrapper.unmount()
564
+ console.log('[Extension.js] Vue wrapper initialization complete')
565
+ }
566
+
567
+ if (import.meta.webpackHot) {
568
+ import.meta.webpackHot?.accept()
569
+ import.meta.webpackHot?.dispose(() => unmount?.())
570
+
571
+ // Accept changes to this file
572
+ import.meta.webpackHot?.accept(() => {
573
+ initialize()
574
+ })
575
+ }
576
+
577
+ if (document.readyState === 'complete') {
578
+ initialize()
579
+ } else {
580
+ document.addEventListener('readystatechange', () => {
581
+ if (document.readyState === 'complete') {
582
+ initialize()
583
+ }
584
+ })
585
+ }
586
+
587
+ export default VueContentScriptWrapper
588
+ `;
589
+ return wrapperCode;
590
+ }
591
+ function svelte_content_script_wrapper_extractCSSImports(source) {
592
+ const cssImports = [];
593
+ const lines = source.split('\n');
594
+ const cssImportPatterns = [
595
+ /^\s*import\s+['"]([^'"]*\.(?:css|scss|sass|less|module\.css))['"]/,
596
+ /^\s*import\s+['"]([^'"]*\.(?:css|scss|sass|less|module\.css))['"]\s*;?\s*$/,
597
+ /^\s*import\s+['"]([^'"]*\.(?:css|scss|sass|less|module\.css))['"]\s*from\s+['"][^'"]*['"]/
598
+ ];
599
+ for (const line of lines){
600
+ const trimmedLine = line.trim();
601
+ if (!(trimmedLine.startsWith('//') || trimmedLine.startsWith('/*'))) for (const pattern of cssImportPatterns){
602
+ const match = pattern.exec(line);
603
+ if (match) {
604
+ const cssPath = match[1];
605
+ if (cssPath && !cssImports.includes(cssPath)) cssImports.push(cssPath);
606
+ }
607
+ }
608
+ }
609
+ return cssImports;
610
+ }
611
+ function generateSvelteWrapperCode(source, resourcePath) {
612
+ external_path_namespaceObject.basename(resourcePath, external_path_namespaceObject.extname(resourcePath));
613
+ const cssImports = svelte_content_script_wrapper_extractCSSImports(source);
614
+ const resourceDir = external_path_namespaceObject.dirname(resourcePath);
615
+ if ('development' === process.env.EXTENSION_ENV) console.log("[Extension.js] Detected Svelte framework with CSS imports:", cssImports);
616
+ const cssContentMap = {};
617
+ for (const cssImport of cssImports)try {
618
+ const cssPath = external_path_namespaceObject.resolve(resourceDir, cssImport);
619
+ if (external_fs_namespaceObject.existsSync(cssPath)) {
620
+ const cssContent = external_fs_namespaceObject.readFileSync(cssPath, 'utf-8');
621
+ const escapedCSS = cssContent.replace(/\\/g, '\\\\').replace(/`/g, '\\`').replace(/\${/g, '\\${').replace(/\n/g, ' ').replace(/\s+/g, ' ').trim();
622
+ cssContentMap[cssImport] = escapedCSS;
623
+ if ('development' === process.env.EXTENSION_ENV) console.log(`[Extension.js] Read CSS content for ${cssImport}, length: ${cssContent.length}`);
624
+ } else if ('development' === process.env.EXTENSION_ENV) console.warn(`[Extension.js] CSS file not found: ${cssPath}`);
625
+ } catch (error) {
626
+ if ('development' === process.env.EXTENSION_ENV) console.warn(`[Extension.js] Failed to read CSS file ${cssImport}:`, error);
627
+ }
628
+ const wrapperCode = `
629
+ // Svelte Content Script Wrapper - Auto-generated by Extension.js
630
+ // This wrapper provides Shadow DOM isolation and CSS injection for Svelte content scripts
631
+
632
+ // Original Svelte content script source (directive processed)
633
+ ${source.replace(/'use shadow-dom'/g, "// 'use shadow-dom'").replace(/"use shadow-dom"/g, '// "use shadow-dom"')}
634
+
635
+ // Content script options interface
636
+ export interface ContentScriptOptions {
637
+ rootElement?: string
638
+ rootClassName?: string
639
+ stylesheets?: string[]
640
+ }
641
+
642
+ // Content script instance interface
643
+ export interface ContentScriptInstance {
644
+ mount: (container: HTMLElement) => void
645
+ unmount: () => void
646
+ }
647
+
648
+ // Svelte Content script wrapper class
649
+ class SvelteContentScriptWrapper {
650
+ private rootElement: HTMLElement | null = null
651
+ private shadowRoot: ShadowRoot | null = null
652
+ private styleElement: HTMLStyleElement | null = null
653
+ private renderFunction: (container: HTMLElement) => (() => void) | void
654
+ private unmountFunction: (() => void) | null = null
655
+ private options: ContentScriptOptions
656
+
657
+ constructor(renderFunction: (container: HTMLElement) => (() => void) | void, options: ContentScriptOptions = {}) {
658
+ this.renderFunction = renderFunction
659
+ this.options = {
660
+ rootElement: 'extension-root',
661
+ rootClassName: undefined, // Svelte handles its own styling
662
+ stylesheets: ${JSON.stringify(cssImports.length > 0 ? cssImports : [
663
+ './styles.css'
664
+ ])},
665
+ ...options
666
+ }
667
+ }
668
+
669
+ async mount(container?: HTMLElement): Promise<void> {
670
+ console.log('[Extension.js] Svelte wrapper mount called')
671
+ if (this.rootElement) {
672
+ this.unmount()
673
+ }
674
+
675
+ // Create root element - Svelte handles its own container styling
676
+ this.rootElement = container || document.createElement('div')
677
+ this.rootElement.id = this.options.rootElement!
678
+ if (this.options.rootClassName) {
679
+ this.rootElement.className = this.options.rootClassName
680
+ }
681
+ // Svelte component handles its own styling
682
+
683
+ // Create shadow root for style isolation
684
+ this.shadowRoot = this.rootElement.attachShadow({ mode: 'open' })
685
+
686
+ // Inject styles FIRST
687
+ console.log('[Extension.js] About to inject styles')
688
+ await this.injectStyles()
689
+
690
+ // Render Svelte content
691
+ console.log('[Extension.js] About to render Svelte content')
692
+ const result = this.renderFunction(this.shadowRoot as any)
693
+ if (typeof result === 'function') {
694
+ this.unmountFunction = result
695
+ }
696
+
697
+ // Append to document if no container provided
698
+ if (!container) {
699
+ document.body.appendChild(this.rootElement)
700
+ }
701
+
702
+ console.log('[Extension.js] Svelte wrapper mount complete')
703
+ }
704
+
705
+ unmount() {
706
+ if (this.unmountFunction) {
707
+ this.unmountFunction()
708
+ this.unmountFunction = null
709
+ }
710
+
711
+ if (this.rootElement && this.rootElement.parentNode) {
712
+ this.rootElement.parentNode.removeChild(this.rootElement)
713
+ }
714
+
715
+ this.rootElement = null
716
+ this.shadowRoot = null
717
+ this.styleElement = null
718
+ }
719
+
720
+ // Inject styles with hardcoded CSS content for Svelte templates
721
+ private async injectStyles(): Promise<void> {
722
+ console.log('[Extension.js] Svelte injectStyles called')
723
+ const targetRoot = this.shadowRoot || this.rootElement!
724
+
725
+ // Create style element
726
+ this.styleElement = document.createElement('style')
727
+ targetRoot.appendChild(this.styleElement)
728
+
729
+ // Fetch CSS content
730
+ try {
731
+ console.log('[Extension.js] About to fetch CSS')
732
+ const cssContent = await this.fetchCSS()
733
+ console.log('[Extension.js] CSS fetched, length:', cssContent.length)
734
+ this.styleElement.textContent = cssContent
735
+ console.log('[Extension.js] Svelte CSS injected successfully')
736
+ } catch (error) {
737
+ console.error('[Extension.js] Failed to inject Svelte CSS:', error)
738
+ }
739
+
740
+ // Setup HMR for CSS files
741
+ this.setupCSSHMR()
742
+ }
743
+
744
+ // Fetch CSS with hardcoded content for Svelte templates
745
+ private async fetchCSS(): Promise<string> {
746
+ let allCSS = ''
747
+
748
+ console.log('[Extension.js] Processing Svelte stylesheets:', this.options.stylesheets)
749
+
750
+ // CSS content map is injected at build time
751
+ const cssContentMap: Record<string, string> = ${JSON.stringify(cssContentMap)}
752
+
753
+ for (const stylesheet of this.options.stylesheets) {
754
+ try {
755
+ console.log('[Extension.js] Processing Svelte stylesheet:', stylesheet)
756
+ // Check if we have hardcoded content for this stylesheet
757
+ if (cssContentMap[stylesheet]) {
758
+ const cssContent = cssContentMap[stylesheet]
759
+ allCSS += cssContent + '\\n'
760
+ console.log(\`[Extension.js] Successfully injected Svelte \${stylesheet} content\`)
761
+ continue
762
+ }
763
+
764
+ // For stylesheets without hardcoded content, try to fetch them
765
+ const cssUrl = new URL(stylesheet, import.meta.url)
766
+ const response = await fetch(cssUrl)
767
+ const text = await response.text()
768
+ if (response.ok) {
769
+ allCSS += text + '\\n'
770
+ console.log('[Extension.js] Successfully fetched stylesheet:', stylesheet)
771
+ } else {
772
+ console.warn('[Extension.js] Failed to fetch CSS:', stylesheet)
773
+ }
774
+ } catch (error) {
775
+ console.warn('[Extension.js] Failed to fetch Svelte CSS:', stylesheet, error)
776
+ }
777
+ }
778
+
779
+ return allCSS
780
+ }
781
+
782
+ // Setup CSS HMR for Svelte templates
783
+ private setupCSSHMR() {
784
+ if (!import.meta.webpackHot) return
785
+
786
+ // Setup HMR for each CSS file
787
+ for (const stylesheet of this.options.stylesheets) {
788
+ import.meta.webpackHot?.accept(stylesheet, async () => {
789
+ try {
790
+ const cssContent = await this.fetchCSS()
791
+ if (this.styleElement) {
792
+ this.styleElement.textContent = cssContent
793
+ console.log('[Extension.js] Svelte CSS updated via HMR:', stylesheet)
794
+ }
795
+ } catch (error) {
796
+ console.error('[Extension.js] Failed to update Svelte CSS via HMR:', stylesheet, error)
797
+ }
798
+ })
799
+ }
800
+ }
801
+ }
802
+
803
+ // Initialize Svelte content script with wrapper
804
+ function initializeSvelteContentScript(
805
+ options: ContentScriptOptions,
806
+ renderFunction: (container: HTMLElement) => (() => void) | void
807
+ ): ContentScriptInstance {
808
+ const wrapper = new SvelteContentScriptWrapper(renderFunction, options)
809
+
810
+ return {
811
+ mount: (container?: HTMLElement) => wrapper.mount(container),
812
+ unmount: () => wrapper.unmount()
813
+ }
814
+ }
815
+
816
+ // Auto-initialize the Svelte content script with the wrapper
817
+ export function autoInitializeSvelteContentScript(
818
+ options: ContentScriptOptions = {}
819
+ ): ContentScriptInstance {
820
+ // Get the render function from the imported contentScript
821
+ const renderFunction = contentScript(options)
822
+
823
+ // Initialize with the wrapper using the detected CSS imports
824
+ return initializeSvelteContentScript(options, renderFunction)
825
+ }
826
+
827
+ // Simple initialization for Svelte
828
+ let unmount: (() => void) | undefined
829
+
830
+ async function initialize() {
831
+ console.log('[Extension.js] Svelte wrapper initialize called')
832
+ if (unmount) {
833
+ console.log('[Extension.js] Unmounting previous Svelte instance')
834
+ unmount()
835
+ }
836
+
837
+ // Get the render function from the contentScript function
838
+ const renderFunction = contentScript({})
839
+ const wrapper = new SvelteContentScriptWrapper(renderFunction, {})
840
+ await wrapper.mount()
841
+ unmount = () => wrapper.unmount()
842
+ console.log('[Extension.js] Svelte wrapper initialization complete')
843
+ }
844
+
845
+ if (import.meta.webpackHot) {
846
+ import.meta.webpackHot?.accept()
847
+ import.meta.webpackHot?.dispose(() => unmount?.())
848
+
849
+ // Accept changes to this file
850
+ import.meta.webpackHot?.accept(() => {
851
+ initialize()
852
+ })
853
+ }
854
+
855
+ if (document.readyState === 'complete') {
856
+ initialize()
857
+ } else {
858
+ document.addEventListener('readystatechange', () => {
859
+ if (document.readyState === 'complete') {
860
+ initialize()
861
+ }
862
+ })
863
+ }
864
+
865
+ export default SvelteContentScriptWrapper
866
+ `;
867
+ return wrapperCode;
868
+ }
869
+ function preact_content_script_wrapper_extractCSSImports(source) {
870
+ const cssImports = [];
871
+ const lines = source.split('\n');
872
+ const cssImportPatterns = [
873
+ /^\s*import\s+['"]([^'"]*\.(?:css|scss|sass|less|module\.css))['"]/,
874
+ /^\s*import\s+['"]([^'"]*\.(?:css|scss|sass|less|module\.css))['"]\s*;?\s*$/,
875
+ /^\s*import\s+['"]([^'"]*\.(?:css|scss|sass|less|module\.css))['"]\s*from\s+['"][^'"]*['"]/
876
+ ];
877
+ for (const line of lines){
878
+ const trimmedLine = line.trim();
879
+ if (!(trimmedLine.startsWith('//') || trimmedLine.startsWith('/*'))) for (const pattern of cssImportPatterns){
880
+ const match = pattern.exec(line);
881
+ if (match) {
882
+ const cssPath = match[1];
883
+ if (cssPath && !cssImports.includes(cssPath)) cssImports.push(cssPath);
884
+ }
885
+ }
886
+ }
887
+ return cssImports;
888
+ }
889
+ function generatePreactWrapperCode(source, resourcePath) {
890
+ external_path_namespaceObject.basename(resourcePath, external_path_namespaceObject.extname(resourcePath));
891
+ const cssImports = preact_content_script_wrapper_extractCSSImports(source);
892
+ const resourceDir = external_path_namespaceObject.dirname(resourcePath);
893
+ if ('development' === process.env.EXTENSION_ENV) console.log("[Extension.js] Detected Preact framework with CSS imports:", cssImports);
894
+ const cssContentMap = {};
895
+ for (const cssImport of cssImports)try {
896
+ const cssPath = external_path_namespaceObject.resolve(resourceDir, cssImport);
897
+ if (external_fs_namespaceObject.existsSync(cssPath)) {
898
+ const cssContent = external_fs_namespaceObject.readFileSync(cssPath, 'utf-8');
899
+ const escapedCSS = cssContent.replace(/\\/g, '\\\\').replace(/`/g, '\\`').replace(/\${/g, '\\${').replace(/\n/g, ' ').replace(/\s+/g, ' ').trim();
900
+ cssContentMap[cssImport] = escapedCSS;
901
+ if ('development' === process.env.EXTENSION_ENV) console.log(`[Extension.js] Read CSS content for ${cssImport}, length: ${cssContent.length}`);
902
+ } else if ('development' === process.env.EXTENSION_ENV) console.warn(`[Extension.js] CSS file not found: ${cssPath}`);
903
+ } catch (error) {
904
+ if ('development' === process.env.EXTENSION_ENV) console.warn(`[Extension.js] Failed to read CSS file ${cssImport}:`, error);
905
+ }
906
+ const wrapperCode = `
907
+ // Preact Content Script Wrapper - Auto-generated by Extension.js
908
+ // This wrapper provides Shadow DOM isolation and CSS injection for Preact content scripts
909
+
910
+ // Original Preact content script source (directive processed)
911
+ ${source.replace(/'use shadow-dom'/g, "// 'use shadow-dom'").replace(/"use shadow-dom"/g, '// "use shadow-dom"')}
912
+
913
+ // Content script options interface
914
+ export interface ContentScriptOptions {
915
+ rootElement?: string
916
+ rootClassName?: string
917
+ stylesheets?: string[]
918
+ }
919
+
920
+ // Content script instance interface
921
+ export interface ContentScriptInstance {
922
+ mount: (container: HTMLElement) => void
923
+ unmount: () => void
924
+ }
925
+
926
+ // Preact Content script wrapper class
927
+ class PreactContentScriptWrapper {
928
+ private rootElement: HTMLElement | null = null
929
+ private shadowRoot: ShadowRoot | null = null
930
+ private styleElement: HTMLStyleElement | null = null
931
+ private renderFunction: (container: HTMLElement) => (() => void) | void
932
+ private unmountFunction: (() => void) | null = null
933
+ private options: ContentScriptOptions
934
+
935
+ constructor(renderFunction: (container: HTMLElement) => (() => void) | void, options: ContentScriptOptions = {}) {
936
+ this.renderFunction = renderFunction
937
+ this.options = {
938
+ rootElement: 'extension-root',
939
+ rootClassName: undefined, // Preact handles its own styling
940
+ stylesheets: ${JSON.stringify(cssImports.length > 0 ? cssImports : [
941
+ './styles.css'
942
+ ])},
943
+ ...options
944
+ }
945
+ }
946
+
947
+ async mount(container?: HTMLElement): Promise<void> {
948
+ console.log('[Extension.js] Preact wrapper mount called')
949
+ if (this.rootElement) {
950
+ this.unmount()
951
+ }
952
+
953
+ // Create root element - Preact handles its own container styling
954
+ this.rootElement = container || document.createElement('div')
955
+ this.rootElement.id = this.options.rootElement!
956
+ if (this.options.rootClassName) {
957
+ this.rootElement.className = this.options.rootClassName
958
+ }
959
+ // Preact component handles its own styling
960
+
961
+ // Create shadow root for style isolation
962
+ this.shadowRoot = this.rootElement.attachShadow({ mode: 'open' })
963
+
964
+ // Inject styles FIRST
965
+ console.log('[Extension.js] About to inject styles')
966
+ await this.injectStyles()
967
+
968
+ // Render Preact content
969
+ console.log('[Extension.js] About to render Preact content')
970
+ const result = this.renderFunction(this.shadowRoot as any)
971
+ if (typeof result === 'function') {
972
+ this.unmountFunction = result
973
+ }
974
+
975
+ // Append to document if no container provided
976
+ if (!container) {
977
+ document.body.appendChild(this.rootElement)
978
+ }
979
+
980
+ console.log('[Extension.js] Preact wrapper mount complete')
981
+ }
982
+
983
+ unmount() {
984
+ if (this.unmountFunction) {
985
+ this.unmountFunction()
986
+ this.unmountFunction = null
987
+ }
988
+
989
+ if (this.rootElement && this.rootElement.parentNode) {
990
+ this.rootElement.parentNode.removeChild(this.rootElement)
991
+ }
992
+
993
+ this.rootElement = null
994
+ this.shadowRoot = null
995
+ this.styleElement = null
996
+ }
997
+
998
+ // Inject styles with hardcoded CSS content for Preact templates
999
+ private async injectStyles(): Promise<void> {
1000
+ console.log('[Extension.js] Preact injectStyles called')
1001
+ const targetRoot = this.shadowRoot || this.rootElement!
1002
+
1003
+ // Create style element
1004
+ this.styleElement = document.createElement('style')
1005
+ targetRoot.appendChild(this.styleElement)
1006
+
1007
+ // Fetch CSS content
1008
+ try {
1009
+ console.log('[Extension.js] About to fetch CSS')
1010
+ const cssContent = await this.fetchCSS()
1011
+ console.log('[Extension.js] CSS fetched, length:', cssContent.length)
1012
+ this.styleElement.textContent = cssContent
1013
+ console.log('[Extension.js] Preact CSS injected successfully')
1014
+ } catch (error) {
1015
+ console.error('[Extension.js] Failed to inject Preact CSS:', error)
1016
+ }
1017
+
1018
+ // Setup HMR for CSS files
1019
+ this.setupCSSHMR()
1020
+ }
1021
+
1022
+ // Fetch CSS with hardcoded content for Preact templates
1023
+ private async fetchCSS(): Promise<string> {
1024
+ let allCSS = ''
1025
+
1026
+ console.log('[Extension.js] Processing Preact stylesheets:', this.options.stylesheets)
1027
+
1028
+ // CSS content map is injected at build time
1029
+ const cssContentMap: Record<string, string> = ${JSON.stringify(cssContentMap)}
1030
+
1031
+ for (const stylesheet of this.options.stylesheets) {
1032
+ try {
1033
+ console.log('[Extension.js] Processing Preact stylesheet:', stylesheet)
1034
+ // Check if we have hardcoded content for this stylesheet
1035
+ if (cssContentMap[stylesheet]) {
1036
+ const cssContent = cssContentMap[stylesheet]
1037
+ allCSS += cssContent + '\\n'
1038
+ console.log(\`[Extension.js] Successfully injected Preact \${stylesheet} content\`)
1039
+ continue
1040
+ }
1041
+
1042
+ // For stylesheets without hardcoded content, try to fetch them
1043
+ const cssUrl = new URL(stylesheet, import.meta.url)
1044
+ const response = await fetch(cssUrl)
1045
+ const text = await response.text()
1046
+ if (response.ok) {
1047
+ allCSS += text + '\\n'
1048
+ console.log('[Extension.js] Successfully fetched stylesheet:', stylesheet)
1049
+ } else {
1050
+ console.warn('[Extension.js] Failed to fetch CSS:', stylesheet)
1051
+ }
1052
+ } catch (error) {
1053
+ console.warn('[Extension.js] Failed to fetch Preact CSS:', stylesheet, error)
1054
+ }
1055
+ }
1056
+
1057
+ return allCSS
1058
+ }
1059
+
1060
+ // Setup CSS HMR for Preact templates
1061
+ private setupCSSHMR() {
1062
+ if (!import.meta.webpackHot) return
1063
+
1064
+ // Setup HMR for each CSS file
1065
+ for (const stylesheet of this.options.stylesheets) {
1066
+ import.meta.webpackHot?.accept(stylesheet, async () => {
1067
+ try {
1068
+ const cssContent = await this.fetchCSS()
1069
+ if (this.styleElement) {
1070
+ this.styleElement.textContent = cssContent
1071
+ console.log('[Extension.js] Preact CSS updated via HMR:', stylesheet)
1072
+ }
1073
+ } catch (error) {
1074
+ console.error('[Extension.js] Failed to update Preact CSS via HMR:', stylesheet, error)
1075
+ }
1076
+ })
1077
+ }
1078
+ }
1079
+ }
1080
+
1081
+ // Initialize Preact content script with wrapper
1082
+ function initializePreactContentScript(
1083
+ options: ContentScriptOptions,
1084
+ renderFunction: (container: HTMLElement) => (() => void) | void
1085
+ ): ContentScriptInstance {
1086
+ const wrapper = new PreactContentScriptWrapper(renderFunction, options)
1087
+
1088
+ return {
1089
+ mount: (container?: HTMLElement) => wrapper.mount(container),
1090
+ unmount: () => wrapper.unmount()
1091
+ }
1092
+ }
1093
+
1094
+ // Auto-initialize the Preact content script with the wrapper
1095
+ export function autoInitializePreactContentScript(
1096
+ options: ContentScriptOptions = {}
1097
+ ): ContentScriptInstance {
1098
+ // Get the render function from the imported contentScript
1099
+ const renderFunction = contentScript(options)
1100
+
1101
+ // Initialize with the wrapper using the detected CSS imports
1102
+ return initializePreactContentScript(options, renderFunction)
1103
+ }
1104
+
1105
+ // Simple initialization for Preact
1106
+ let unmount: (() => void) | undefined
1107
+
1108
+ async function initialize() {
1109
+ console.log('[Extension.js] Preact wrapper initialize called')
1110
+ if (unmount) {
1111
+ console.log('[Extension.js] Unmounting previous Preact instance')
1112
+ unmount()
1113
+ }
1114
+
1115
+ // Get the render function from the contentScript function
1116
+ const renderFunction = contentScript({})
1117
+ const wrapper = new PreactContentScriptWrapper(renderFunction, {})
1118
+ await wrapper.mount()
1119
+ unmount = () => wrapper.unmount()
1120
+ console.log('[Extension.js] Preact wrapper initialization complete')
1121
+ }
1122
+
1123
+ if (import.meta.webpackHot) {
1124
+ import.meta.webpackHot?.accept()
1125
+ import.meta.webpackHot?.dispose(() => unmount?.())
1126
+
1127
+ // Accept changes to this file
1128
+ import.meta.webpackHot?.accept(() => {
1129
+ initialize()
1130
+ })
1131
+ }
1132
+
1133
+ if (document.readyState === 'complete') {
1134
+ initialize()
1135
+ } else {
1136
+ document.addEventListener('readystatechange', () => {
1137
+ if (document.readyState === 'complete') {
1138
+ initialize()
1139
+ }
1140
+ })
1141
+ }
1142
+
1143
+ export default PreactContentScriptWrapper
1144
+ `;
1145
+ return wrapperCode;
1146
+ }
1147
+ function typescript_content_script_wrapper_extractCSSImports(source) {
1148
+ const cssImports = [];
1149
+ const lines = source.split('\n');
1150
+ const cssImportPatterns = [
1151
+ /^\s*import\s+['"]([^'"]*\.(?:css|scss|sass|less|module\.css))['"]/,
1152
+ /^\s*import\s+['"]([^'"]*\.(?:css|scss|sass|less|module\.css))['"]\s*;?\s*$/,
1153
+ /^\s*import\s+['"]([^'"]*\.(?:css|scss|sass|less|module\.css))['"]\s*from\s+['"][^'"]*['"]/
1154
+ ];
1155
+ for (const line of lines){
1156
+ const trimmedLine = line.trim();
1157
+ if (!(trimmedLine.startsWith('//') || trimmedLine.startsWith('/*'))) for (const pattern of cssImportPatterns){
1158
+ const match = pattern.exec(line);
1159
+ if (match) {
1160
+ const cssPath = match[1];
1161
+ if (cssPath && !cssImports.includes(cssPath)) cssImports.push(cssPath);
1162
+ }
1163
+ }
1164
+ }
1165
+ return cssImports;
1166
+ }
1167
+ function generateTypeScriptWrapperCode(source, resourcePath) {
1168
+ external_path_namespaceObject.basename(resourcePath, external_path_namespaceObject.extname(resourcePath));
1169
+ const cssImports = typescript_content_script_wrapper_extractCSSImports(source);
1170
+ const resourceDir = external_path_namespaceObject.dirname(resourcePath);
1171
+ if ('development' === process.env.EXTENSION_ENV) console.log("[Extension.js] Detected TypeScript framework with CSS imports:", cssImports);
1172
+ const cssContentMap = {};
1173
+ for (const cssImport of cssImports)try {
1174
+ const cssPath = external_path_namespaceObject.resolve(resourceDir, cssImport);
1175
+ if (external_fs_namespaceObject.existsSync(cssPath)) {
1176
+ const cssContent = external_fs_namespaceObject.readFileSync(cssPath, 'utf-8');
1177
+ const escapedCSS = cssContent.replace(/\\/g, '\\\\').replace(/`/g, '\\`').replace(/\${/g, '\\${').replace(/\n/g, ' ').replace(/\s+/g, ' ').trim();
1178
+ cssContentMap[cssImport] = escapedCSS;
1179
+ if ('development' === process.env.EXTENSION_ENV) console.log(`[Extension.js] Read CSS content for ${cssImport}, length: ${cssContent.length}`);
1180
+ } else if ('development' === process.env.EXTENSION_ENV) console.warn(`[Extension.js] CSS file not found: ${cssPath}`);
1181
+ } catch (error) {
1182
+ if ('development' === process.env.EXTENSION_ENV) console.warn(`[Extension.js] Failed to read CSS file ${cssImport}:`, error);
1183
+ }
1184
+ const wrapperCode = `
1185
+ // TypeScript Content Script Wrapper - Auto-generated by Extension.js
1186
+ // This wrapper provides Shadow DOM isolation and CSS injection for TypeScript content scripts
1187
+
1188
+ // Original TypeScript content script source (directive processed)
1189
+ ${source.replace(/'use shadow-dom'/g, "// 'use shadow-dom'").replace(/"use shadow-dom"/g, '// "use shadow-dom"')}
1190
+
1191
+ // Content script options interface
1192
+ export interface ContentScriptOptions {
1193
+ rootElement?: string
1194
+ rootClassName?: string
1195
+ stylesheets?: string[]
1196
+ }
1197
+
1198
+ // Content script instance interface
1199
+ export interface ContentScriptInstance {
1200
+ mount: (container: HTMLElement) => void
1201
+ unmount: () => void
1202
+ }
1203
+
1204
+ // TypeScript Content script wrapper class
1205
+ class TypeScriptContentScriptWrapper {
1206
+ private rootElement: HTMLElement | null = null
1207
+ private shadowRoot: ShadowRoot | null = null
1208
+ private styleElement: HTMLStyleElement | null = null
1209
+ private renderFunction: (container: HTMLElement) => (() => void) | void
1210
+ private unmountFunction: (() => void) | null = null
1211
+ private options: ContentScriptOptions
1212
+
1213
+ constructor(renderFunction: (container: HTMLElement) => (() => void) | void, options: ContentScriptOptions = {}) {
1214
+ this.renderFunction = renderFunction
1215
+ this.options = {
1216
+ rootElement: 'extension-root',
1217
+ rootClassName: undefined, // TypeScript handles its own styling
1218
+ stylesheets: ${JSON.stringify(cssImports)},
1219
+ ...options
1220
+ }
1221
+ }
1222
+
1223
+ async mount(container?: HTMLElement): Promise<void> {
1224
+ console.log('[Extension.js] TypeScript wrapper mount called')
1225
+ if (this.rootElement) {
1226
+ this.unmount()
1227
+ }
1228
+
1229
+ // Create root element - TypeScript handles its own container styling
1230
+ this.rootElement = container || document.createElement('div')
1231
+ this.rootElement.id = this.options.rootElement!
1232
+ if (this.options.rootClassName) {
1233
+ this.rootElement.className = this.options.rootClassName
1234
+ }
1235
+
1236
+ // Create shadow root for style isolation
1237
+ this.shadowRoot = this.rootElement.attachShadow({ mode: 'open' })
1238
+
1239
+ // Inject styles FIRST
1240
+ console.log('[Extension.js] About to inject styles')
1241
+ await this.injectStyles()
1242
+
1243
+ // Render TypeScript content
1244
+ console.log('[Extension.js] About to render TypeScript content')
1245
+ const result = this.renderFunction(this.shadowRoot as any)
1246
+ if (typeof result === 'function') {
1247
+ this.unmountFunction = result
1248
+ }
1249
+
1250
+ // Append to document if no container provided
1251
+ if (!container) {
1252
+ document.body.appendChild(this.rootElement)
1253
+ }
1254
+
1255
+ console.log('[Extension.js] TypeScript wrapper mount complete')
1256
+ }
1257
+
1258
+ unmount() {
1259
+ if (this.unmountFunction) {
1260
+ this.unmountFunction()
1261
+ this.unmountFunction = null
1262
+ }
1263
+
1264
+ if (this.rootElement && this.rootElement.parentNode) {
1265
+ this.rootElement.parentNode.removeChild(this.rootElement)
1266
+ }
1267
+
1268
+ this.rootElement = null
1269
+ this.shadowRoot = null
1270
+ this.styleElement = null
1271
+ }
1272
+
1273
+ // Inject styles with hardcoded CSS content for TypeScript templates
1274
+ private async injectStyles(): Promise<void> {
1275
+ console.log('[Extension.js] TypeScript injectStyles called')
1276
+ const targetRoot = this.shadowRoot || this.rootElement!
1277
+
1278
+ // Create style element
1279
+ this.styleElement = document.createElement('style')
1280
+ targetRoot.appendChild(this.styleElement)
1281
+
1282
+ // Fetch CSS content
1283
+ try {
1284
+ console.log('[Extension.js] About to fetch CSS')
1285
+ const cssContent = await this.fetchCSS()
1286
+ console.log('[Extension.js] CSS fetched, length:', cssContent.length)
1287
+ this.styleElement.textContent = cssContent
1288
+ console.log('[Extension.js] TypeScript CSS injected successfully')
1289
+ } catch (error) {
1290
+ console.error('[Extension.js] Failed to inject TypeScript CSS:', error)
1291
+ }
1292
+
1293
+ // Setup HMR for CSS files
1294
+ this.setupCSSHMR()
1295
+ }
1296
+
1297
+ // Fetch CSS with hardcoded content for TypeScript templates
1298
+ private async fetchCSS(): Promise<string> {
1299
+ let allCSS = ''
1300
+
1301
+ console.log('[Extension.js] Processing TypeScript stylesheets:', this.options.stylesheets)
1302
+
1303
+ // CSS content map is injected at build time
1304
+ const cssContentMap: Record<string, string> = ${JSON.stringify(cssContentMap)}
1305
+
1306
+ for (const stylesheet of this.options.stylesheets) {
1307
+ try {
1308
+ console.log('[Extension.js] Processing TypeScript stylesheet:', stylesheet)
1309
+ // Check if we have hardcoded content for this stylesheet
1310
+ if (cssContentMap[stylesheet]) {
1311
+ const cssContent = cssContentMap[stylesheet]
1312
+ allCSS += cssContent + '\\n'
1313
+ console.log(\`[Extension.js] Successfully injected TypeScript \${stylesheet} content\`)
1314
+ continue
1315
+ }
1316
+
1317
+ // For stylesheets without hardcoded content, try to fetch them
1318
+ const cssUrl = new URL(stylesheet, import.meta.url)
1319
+ const response = await fetch(cssUrl)
1320
+ const text = await response.text()
1321
+ if (response.ok) {
1322
+ allCSS += text + '\\n'
1323
+ console.log('[Extension.js] Successfully fetched stylesheet:', stylesheet)
1324
+ } else {
1325
+ console.warn('[Extension.js] Failed to fetch CSS:', stylesheet)
1326
+ }
1327
+ } catch (error) {
1328
+ console.warn('[Extension.js] Failed to fetch TypeScript CSS:', stylesheet, error)
1329
+ }
1330
+ }
1331
+
1332
+ return allCSS
1333
+ }
1334
+
1335
+ // Setup CSS HMR for TypeScript templates
1336
+ private setupCSSHMR() {
1337
+ if (!import.meta.webpackHot) return
1338
+
1339
+ // Setup HMR for each CSS file
1340
+ for (const stylesheet of this.options.stylesheets) {
1341
+ import.meta.webpackHot?.accept(stylesheet, async () => {
1342
+ try {
1343
+ const cssContent = await this.fetchCSS()
1344
+ if (this.styleElement) {
1345
+ this.styleElement.textContent = cssContent
1346
+ console.log('[Extension.js] TypeScript CSS updated via HMR:', stylesheet)
1347
+ }
1348
+ } catch (error) {
1349
+ console.error('[Extension.js] Failed to update TypeScript CSS via HMR:', stylesheet, error)
1350
+ }
1351
+ })
1352
+ }
1353
+ }
1354
+ }
1355
+
1356
+ // Initialize TypeScript content script with wrapper
1357
+ function initializeTypeScriptContentScript(
1358
+ options: ContentScriptOptions,
1359
+ renderFunction: (container: HTMLElement) => (() => void) | void
1360
+ ): ContentScriptInstance {
1361
+ const wrapper = new TypeScriptContentScriptWrapper(renderFunction, options)
1362
+
1363
+ return {
1364
+ mount: (container?: HTMLElement) => wrapper.mount(container),
1365
+ unmount: () => wrapper.unmount()
1366
+ }
1367
+ }
1368
+
1369
+ // Auto-initialize the TypeScript content script with the wrapper
1370
+ export function autoInitializeTypeScriptContentScript(
1371
+ options: ContentScriptOptions = {}
1372
+ ): ContentScriptInstance {
1373
+ // Get the render function from the imported contentScript
1374
+ const renderFunction = contentScript(options)
1375
+
1376
+ // Initialize with the wrapper using the detected CSS imports
1377
+ return initializeTypeScriptContentScript(options, renderFunction)
1378
+ }
1379
+
1380
+ // Simple initialization for TypeScript
1381
+ let unmount: (() => void) | undefined
1382
+
1383
+ async function initialize() {
1384
+ console.log('[Extension.js] TypeScript wrapper initialize called')
1385
+ if (unmount) {
1386
+ console.log('[Extension.js] Unmounting previous TypeScript instance')
1387
+ unmount()
1388
+ }
1389
+
1390
+ // Get the render function from the contentScript function
1391
+ const renderFunction = contentScript({})
1392
+ const wrapper = new TypeScriptContentScriptWrapper(renderFunction, {})
1393
+ await wrapper.mount()
1394
+ unmount = () => wrapper.unmount()
1395
+ console.log('[Extension.js] TypeScript wrapper initialization complete')
1396
+ }
1397
+
1398
+ if (import.meta.webpackHot) {
1399
+ import.meta.webpackHot?.accept()
1400
+ import.meta.webpackHot?.dispose(() => unmount?.())
1401
+
1402
+ // Accept changes to this file
1403
+ import.meta.webpackHot?.accept(() => {
1404
+ initialize()
1405
+ })
1406
+ }
1407
+
1408
+ if (document.readyState === 'complete') {
1409
+ initialize()
1410
+ } else {
1411
+ document.addEventListener('readystatechange', () => {
1412
+ if (document.readyState === 'complete') {
1413
+ initialize()
1414
+ }
1415
+ })
1416
+ }
1417
+
1418
+ export default TypeScriptContentScriptWrapper
1419
+ `;
1420
+ return wrapperCode;
1421
+ }
1422
+ function javascript_content_script_wrapper_extractCSSImports(source) {
1423
+ const cssImports = [];
1424
+ const lines = source.split('\n');
1425
+ const cssImportPatterns = [
1426
+ /^\s*import\s+['"]([^'"]*\.(?:css|scss|sass|less|module\.css))['"]/,
1427
+ /^\s*import\s+['"]([^'"]*\.(?:css|scss|sass|less|module\.css))['"]\s*;?\s*$/,
1428
+ /^\s*import\s+['"]([^'"]*\.(?:css|scss|sass|less|module\.css))['"]\s*from\s+['"][^'"]*['"]/
1429
+ ];
1430
+ for (const line of lines){
1431
+ const trimmedLine = line.trim();
1432
+ if (!(trimmedLine.startsWith('//') || trimmedLine.startsWith('/*'))) for (const pattern of cssImportPatterns){
1433
+ const match = pattern.exec(line);
1434
+ if (match) {
1435
+ const cssPath = match[1];
1436
+ if (cssPath && !cssImports.includes(cssPath)) cssImports.push(cssPath);
1437
+ }
1438
+ }
1439
+ }
1440
+ return cssImports;
1441
+ }
1442
+ function generateJavaScriptWrapperCode(source, resourcePath) {
1443
+ external_path_namespaceObject.basename(resourcePath, external_path_namespaceObject.extname(resourcePath));
1444
+ const cssImports = javascript_content_script_wrapper_extractCSSImports(source);
1445
+ const resourceDir = external_path_namespaceObject.dirname(resourcePath);
1446
+ if ('development' === process.env.EXTENSION_ENV) console.log("[Extension.js] Detected JavaScript framework with CSS imports:", cssImports);
1447
+ const cssContentMap = {};
1448
+ for (const cssImport of cssImports)try {
1449
+ const cssPath = external_path_namespaceObject.resolve(resourceDir, cssImport);
1450
+ if (external_fs_namespaceObject.existsSync(cssPath)) {
1451
+ const cssContent = external_fs_namespaceObject.readFileSync(cssPath, 'utf-8');
1452
+ const escapedCSS = cssContent.replace(/\\/g, '\\\\').replace(/`/g, '\\`').replace(/\${/g, '\\${').replace(/\n/g, ' ').replace(/\s+/g, ' ').trim();
1453
+ cssContentMap[cssImport] = escapedCSS;
1454
+ if ('development' === process.env.EXTENSION_ENV) console.log(`[Extension.js] Read CSS content for ${cssImport}, length: ${cssContent.length}`);
1455
+ } else if ('development' === process.env.EXTENSION_ENV) console.warn(`[Extension.js] CSS file not found: ${cssPath}`);
1456
+ } catch (error) {
1457
+ if ('development' === process.env.EXTENSION_ENV) console.warn(`[Extension.js] Failed to read CSS file ${cssImport}:`, error);
1458
+ }
1459
+ const wrapperCode = `
1460
+ // JavaScript Content Script Wrapper - Auto-generated by Extension.js
1461
+ // This wrapper provides Shadow DOM isolation and CSS injection for JavaScript content scripts
1462
+
1463
+ // Original JavaScript content script source (directive processed)
1464
+ ${source.replace(/'use shadow-dom'/g, "// 'use shadow-dom'").replace(/"use shadow-dom"/g, '// "use shadow-dom"')}
1465
+
1466
+ // Content script wrapper class
1467
+ class JavaScriptContentScriptWrapper {
1468
+ constructor(renderFunction, options = {}) {
1469
+ this.renderFunction = renderFunction
1470
+ this.options = {
1471
+ rootElement: 'extension-root',
1472
+ rootClassName: undefined,
1473
+ stylesheets: ${JSON.stringify(cssImports.length > 0 ? cssImports : [
1474
+ './styles.css'
1475
+ ])},
1476
+ ...options
1477
+ }
1478
+ this.rootElement = null
1479
+ this.shadowRoot = null
1480
+ this.styleElement = null
1481
+ this.unmountFunction = null
1482
+ }
1483
+
1484
+ async mount(container) {
1485
+ console.log('[Extension.js] JavaScript wrapper mount called')
1486
+ if (this.rootElement) {
1487
+ this.unmount()
1488
+ }
1489
+
1490
+ // Create root element
1491
+ this.rootElement = container || document.createElement('div')
1492
+ this.rootElement.id = this.options.rootElement
1493
+ if (this.options.rootClassName) {
1494
+ this.rootElement.className = this.options.rootClassName
1495
+ }
1496
+
1497
+ // Create shadow root for style isolation
1498
+ this.shadowRoot = this.rootElement.attachShadow({ mode: 'open' })
1499
+
1500
+ // Inject styles FIRST
1501
+ console.log('[Extension.js] About to inject styles')
1502
+ await this.injectStyles()
1503
+
1504
+ // Render content using the original contentScript function
1505
+ console.log('[Extension.js] About to render JavaScript content')
1506
+ const result = this.renderFunction(this.shadowRoot)
1507
+ if (typeof result === 'function') {
1508
+ this.unmountFunction = result
1509
+ }
1510
+
1511
+ // Append to document if no container provided
1512
+ if (!container) {
1513
+ document.body.appendChild(this.rootElement)
1514
+ }
1515
+
1516
+ console.log('[Extension.js] JavaScript wrapper mount complete')
1517
+ }
1518
+
1519
+ unmount() {
1520
+ if (this.unmountFunction) {
1521
+ this.unmountFunction()
1522
+ this.unmountFunction = null
1523
+ }
1524
+
1525
+ if (this.rootElement && this.rootElement.parentNode) {
1526
+ this.rootElement.parentNode.removeChild(this.rootElement)
1527
+ }
1528
+
1529
+ this.rootElement = null
1530
+ this.shadowRoot = null
1531
+ this.styleElement = null
1532
+ }
1533
+
1534
+ async injectStyles() {
1535
+ console.log('[Extension.js] JavaScript injectStyles called')
1536
+ const targetRoot = this.shadowRoot || this.rootElement
1537
+
1538
+ // Create style element
1539
+ this.styleElement = document.createElement('style')
1540
+ targetRoot.appendChild(this.styleElement)
1541
+
1542
+ // Fetch CSS content
1543
+ try {
1544
+ console.log('[Extension.js] About to fetch CSS')
1545
+ const cssContent = await this.fetchCSS()
1546
+ console.log('[Extension.js] CSS fetched, length:', cssContent.length)
1547
+ this.styleElement.textContent = cssContent
1548
+ console.log('[Extension.js] JavaScript CSS injected successfully')
1549
+ } catch (error) {
1550
+ console.error('[Extension.js] Failed to inject JavaScript CSS:', error)
1551
+ }
1552
+
1553
+ // Setup HMR for CSS files
1554
+ this.setupCSSHMR()
1555
+ }
1556
+
1557
+ async fetchCSS() {
1558
+ let allCSS = ''
1559
+
1560
+ console.log('[Extension.js] Processing JavaScript stylesheets:', this.options.stylesheets)
1561
+
1562
+ // CSS content map is injected at build time
1563
+ const cssContentMap = ${JSON.stringify(cssContentMap)}
1564
+
1565
+ for (const stylesheet of this.options.stylesheets) {
1566
+ try {
1567
+ console.log('[Extension.js] Processing JavaScript stylesheet:', stylesheet)
1568
+ // Check if we have hardcoded content for this stylesheet
1569
+ if (cssContentMap[stylesheet]) {
1570
+ const cssContent = cssContentMap[stylesheet]
1571
+ allCSS += cssContent + '\\n'
1572
+ console.log(\`[Extension.js] Successfully injected JavaScript \${stylesheet} content\`)
1573
+ continue
1574
+ }
1575
+
1576
+ // For stylesheets without hardcoded content, try to fetch them
1577
+ const cssUrl = new URL(stylesheet, import.meta.url)
1578
+ const response = await fetch(cssUrl)
1579
+ const text = await response.text()
1580
+ if (response.ok) {
1581
+ allCSS += text + '\\n'
1582
+ console.log('[Extension.js] Successfully fetched stylesheet:', stylesheet)
1583
+ } else {
1584
+ console.warn('[Extension.js] Failed to fetch CSS:', stylesheet)
1585
+ }
1586
+ } catch (error) {
1587
+ console.warn('[Extension.js] Failed to fetch JavaScript CSS:', stylesheet, error)
1588
+ }
1589
+ }
1590
+
1591
+ return allCSS
1592
+ }
1593
+
1594
+ setupCSSHMR() {
1595
+ if (!import.meta.webpackHot) return
1596
+
1597
+ // Setup HMR for each CSS file
1598
+ for (const stylesheet of this.options.stylesheets) {
1599
+ import.meta.webpackHot?.accept(stylesheet, async () => {
1600
+ try {
1601
+ const cssContent = await this.fetchCSS()
1602
+ if (this.styleElement) {
1603
+ this.styleElement.textContent = cssContent
1604
+ console.log('[Extension.js] JavaScript CSS updated via HMR:', stylesheet)
1605
+ }
1606
+ } catch (error) {
1607
+ console.error('[Extension.js] Failed to update JavaScript CSS via HMR:', stylesheet, error)
1608
+ }
1609
+ })
1610
+ }
1611
+ }
1612
+ }
1613
+
1614
+ // Initialize JavaScript content script with wrapper
1615
+ function initializeJavaScriptContentScript(options, renderFunction) {
1616
+ const wrapper = new JavaScriptContentScriptWrapper(renderFunction, options)
1617
+
1618
+ return {
1619
+ mount: (container) => wrapper.mount(container),
1620
+ unmount: () => wrapper.unmount()
1621
+ }
1622
+ }
1623
+
1624
+ // Simple initialization for JavaScript
1625
+ let unmount
1626
+
1627
+ async function initialize() {
1628
+ console.log('[Extension.js] JavaScript wrapper initialize called')
1629
+ if (unmount) {
1630
+ console.log('[Extension.js] Unmounting previous JavaScript instance')
1631
+ unmount()
1632
+ }
1633
+
1634
+ // Get the render function from the contentScript function
1635
+ const renderFunction = contentScript({})
1636
+ const wrapper = new JavaScriptContentScriptWrapper(renderFunction, {})
1637
+ await wrapper.mount()
1638
+ unmount = () => wrapper.unmount()
1639
+ console.log('[Extension.js] JavaScript wrapper initialization complete')
1640
+ }
1641
+
1642
+ if (import.meta.webpackHot) {
1643
+ import.meta.webpackHot?.accept()
1644
+ import.meta.webpackHot?.dispose(() => unmount?.())
1645
+
1646
+ // Accept changes to this file
1647
+ import.meta.webpackHot?.accept(() => {
1648
+ initialize()
1649
+ })
1650
+ }
1651
+
1652
+ if (document.readyState === 'complete') {
1653
+ initialize()
1654
+ } else {
1655
+ document.addEventListener('readystatechange', () => {
1656
+ if (document.readyState === 'complete') {
1657
+ initialize()
1658
+ }
1659
+ })
1660
+ }
1661
+
1662
+ export default JavaScriptContentScriptWrapper
1663
+ `;
1664
+ return wrapperCode;
1665
+ }
1666
+ const schema = {
1667
+ type: 'object',
1668
+ properties: {
1669
+ test: {
1670
+ type: 'string'
1671
+ },
1672
+ manifestPath: {
1673
+ type: 'string'
1674
+ },
1675
+ mode: {
1676
+ type: 'string'
1677
+ },
1678
+ includeList: {
1679
+ type: 'object'
1680
+ },
1681
+ excludeList: {
1682
+ type: 'object'
1683
+ }
1684
+ }
1685
+ };
1686
+ function add_content_script_wrapper_extractCSSImports(source) {
1687
+ const cssImports = [];
1688
+ const lines = source.split('\n');
1689
+ const cssImportPatterns = [
1690
+ /^\s*import\s+['"]([^'"]*\.(?:css|scss|sass|less|module\.css))['"]/,
1691
+ /^\s*import\s+['"]([^'"]*\.(?:css|scss|sass|less|module\.css))['"]\s*;?\s*$/,
1692
+ /^\s*import\s+['"]([^'"]*\.(?:css|scss|sass|less|module\.css))['"]\s*from\s+['"][^'"]*['"]/
1693
+ ];
1694
+ for (const line of lines){
1695
+ const trimmedLine = line.trim();
1696
+ if (!(trimmedLine.startsWith('//') || trimmedLine.startsWith('/*'))) for (const pattern of cssImportPatterns){
1697
+ const match = pattern.exec(line);
1698
+ if (match) {
1699
+ const cssPath = match[1];
1700
+ if (cssPath && !cssImports.includes(cssPath)) cssImports.push(cssPath);
1701
+ }
1702
+ }
1703
+ }
1704
+ return cssImports;
1705
+ }
1706
+ function detectFramework(resourcePath, projectPath) {
1707
+ try {
1708
+ const packageJsonPath = external_path_namespaceObject.join(projectPath, 'package.json');
1709
+ if (!external_fs_namespaceObject.existsSync(packageJsonPath)) {
1710
+ if (resourcePath.endsWith('.ts') && !resourcePath.endsWith('.d.ts')) return "typescript";
1711
+ return "javascript";
1712
+ }
1713
+ const packageJson = JSON.parse(external_fs_namespaceObject.readFileSync(packageJsonPath, 'utf-8'));
1714
+ const dependencies = packageJson.dependencies || {};
1715
+ const devDependencies = packageJson.devDependencies || {};
1716
+ const allDeps = {
1717
+ ...dependencies,
1718
+ ...devDependencies
1719
+ };
1720
+ if (allDeps['react'] || allDeps['@types/react']) return 'react';
1721
+ if (allDeps['vue'] || allDeps['@vue/runtime-core']) return 'vue';
1722
+ if (allDeps['svelte'] || allDeps['@svelte/runtime']) return 'svelte';
1723
+ if (allDeps['preact'] || allDeps['@preact/preset-vite']) return 'preact';
1724
+ if (allDeps["typescript"] || allDeps['@types/node'] || resourcePath.endsWith('.ts') || resourcePath.endsWith('.tsx')) return "typescript";
1725
+ return "javascript";
1726
+ } catch (error) {
1727
+ if ('development' === process.env.EXTENSION_ENV) console.warn('[Extension.js] Error detecting framework from package.json:', error);
1728
+ if (resourcePath.endsWith('.ts') && !resourcePath.endsWith('.d.ts')) return "typescript";
1729
+ return "javascript";
1730
+ }
1731
+ }
1732
+ function generateFrameworkWrapperCode(source, framework, resourcePath) {
1733
+ external_path_namespaceObject.basename(resourcePath, external_path_namespaceObject.extname(resourcePath));
1734
+ const cssImports = add_content_script_wrapper_extractCSSImports(source);
1735
+ if ('development' === process.env.EXTENSION_ENV) console.log(`\u{1F50D} Detected ${framework} framework with CSS imports:`, cssImports);
1736
+ if ('react' === framework) return generateReactWrapperCode(source, resourcePath);
1737
+ if ('vue' === framework) return generateVueWrapperCode(source, resourcePath);
1738
+ if ('svelte' === framework) return generateSvelteWrapperCode(source, resourcePath);
1739
+ if ('preact' === framework) return generatePreactWrapperCode(source, resourcePath);
1740
+ if ("typescript" === framework) return generateTypeScriptWrapperCode(source, resourcePath);
1741
+ if ("javascript" === framework) return generateJavaScriptWrapperCode(source, resourcePath);
1742
+ return generateTypeScriptWrapperCode(source, resourcePath);
1743
+ }
1744
+ function shouldUseWrapper(source, manifest, projectPath, url) {
1745
+ const hasShadowDomDirective = source.includes("'use shadow-dom'") || source.includes('"use shadow-dom"');
1746
+ if (!manifest.content_scripts) return false;
1747
+ for (const contentScript of manifest.content_scripts)if (contentScript.js) for (const js of contentScript.js){
1748
+ const absoluteUrl = external_path_namespaceObject.resolve(projectPath, js);
1749
+ if (url.includes(absoluteUrl)) return hasShadowDomDirective;
1750
+ }
1751
+ return false;
1752
+ }
1753
+ function add_content_script_wrapper(source) {
1754
+ const options = this.getOptions();
1755
+ const manifestPath = options.manifestPath;
1756
+ const projectPath = external_path_namespaceObject.dirname(manifestPath);
1757
+ const manifest = JSON.parse(external_fs_namespaceObject.readFileSync(manifestPath, 'utf-8'));
1758
+ (0, external_schema_utils_namespaceObject.validate)(schema, options, {
1759
+ name: "scripts:add-content-script-wrapper",
1760
+ baseDataPath: 'options'
1761
+ });
1762
+ const url = (0, external_loader_utils_namespaceObject.urlToRequest)(this.resourcePath);
1763
+ if (!shouldUseWrapper(source, manifest, projectPath, url)) return source;
1764
+ const framework = detectFramework(this.resourcePath, projectPath);
1765
+ if (framework) {
1766
+ const wrapperCode = generateFrameworkWrapperCode(source, framework, this.resourcePath);
1767
+ return wrapperCode;
1768
+ }
1769
+ return source;
1770
+ }
1771
+ exports["default"] = __webpack_exports__["default"];
1772
+ for(var __webpack_i__ in __webpack_exports__)if (-1 === [
1773
+ "default"
1774
+ ].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
1775
+ Object.defineProperty(exports, '__esModule', {
1776
+ value: true
1777
+ });