adnbn 0.11.0 → 0.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (378) hide show
  1. package/README.md +3 -0
  2. package/dist/cli/builders/manifest/ManifestBase.js +1 -1
  3. package/dist/cli/bundler/index.d.ts +1 -0
  4. package/dist/cli/bundler/index.js +1 -0
  5. package/dist/cli/bundler/index.js.map +1 -1
  6. package/dist/cli/bundler/layers.d.ts +5 -0
  7. package/dist/cli/bundler/layers.js +11 -0
  8. package/dist/cli/bundler/layers.js.map +1 -0
  9. package/dist/cli/bundler/plugins/build-assets-map/BuildAssetsMapPlugin.js +44 -15
  10. package/dist/cli/bundler/plugins/build-assets-map/BuildAssetsMapPlugin.js.map +1 -1
  11. package/dist/cli/bundler/plugins/build-assets-map/index.d.ts +1 -2
  12. package/dist/cli/bundler/plugins/build-assets-map/index.js +0 -3
  13. package/dist/cli/bundler/plugins/build-assets-map/index.js.map +1 -1
  14. package/dist/cli/bundler/plugins/build-assets-map/normalize.d.ts +3 -0
  15. package/dist/cli/bundler/plugins/build-assets-map/normalize.js +24 -0
  16. package/dist/cli/bundler/plugins/build-assets-map/normalize.js.map +1 -0
  17. package/dist/cli/bundler/plugins/build-assets-map/templates/runtime.template.d.ts +2 -0
  18. package/dist/cli/bundler/plugins/build-assets-map/templates.d.ts +9 -0
  19. package/dist/cli/bundler/plugins/build-assets-map/templates.js +32 -0
  20. package/dist/cli/bundler/plugins/build-assets-map/usage.d.ts +3 -6
  21. package/dist/cli/bundler/plugins/build-assets-map/usage.js +6 -3
  22. package/dist/cli/bundler/plugins/build-assets-map/usage.js.map +1 -1
  23. package/dist/cli/bundler/plugins/entrypoint/EntrypointPlugin.js +11 -0
  24. package/dist/cli/bundler/plugins/entrypoint/EntrypointPlugin.js.map +1 -1
  25. package/dist/cli/bundler/plugins/index.d.ts +2 -2
  26. package/dist/cli/bundler/plugins/index.js +2 -6
  27. package/dist/cli/bundler/plugins/index.js.map +1 -1
  28. package/dist/cli/bundler/plugins/isolated-styles/IsolatedStylesPlugin.d.ts +1 -1
  29. package/dist/cli/bundler/plugins/isolated-styles/IsolatedStylesPlugin.js +38 -13
  30. package/dist/cli/bundler/plugins/isolated-styles/IsolatedStylesPlugin.js.map +1 -1
  31. package/dist/cli/bundler/plugins/isolated-styles/chunks.d.ts +7 -0
  32. package/dist/cli/bundler/plugins/isolated-styles/chunks.js +33 -0
  33. package/dist/cli/bundler/plugins/isolated-styles/chunks.js.map +1 -0
  34. package/dist/cli/bundler/plugins/isolated-styles/split-chunks.d.ts +4 -0
  35. package/dist/cli/bundler/plugins/isolated-styles/split-chunks.js +51 -0
  36. package/dist/cli/bundler/plugins/isolated-styles/split-chunks.js.map +1 -0
  37. package/dist/cli/bundler/plugins/isolated-styles/templates.js +36 -6
  38. package/dist/cli/bundler/plugins/manifest/ManifestPlugin.js +1 -2
  39. package/dist/cli/bundler/plugins/manifest/ManifestPlugin.js.map +1 -1
  40. package/dist/cli/bundler/plugins/types.d.ts +4 -0
  41. package/dist/cli/bundler/plugins/utils/compilation-assets.d.ts +4 -0
  42. package/dist/cli/bundler/plugins/utils/compilation-assets.js +12 -0
  43. package/dist/cli/bundler/plugins/utils/compilation-assets.js.map +1 -0
  44. package/dist/cli/bundler/plugins/utils/index.d.ts +2 -0
  45. package/dist/cli/bundler/plugins/utils/index.js +5 -0
  46. package/dist/cli/bundler/plugins/utils/index.js.map +1 -1
  47. package/dist/cli/bundler/plugins/utils/runtime-module.d.ts +3 -0
  48. package/dist/cli/bundler/plugins/utils/runtime-module.js +11 -0
  49. package/dist/cli/bundler/plugins/utils/runtime-module.js.map +1 -0
  50. package/dist/cli/bundler/utils/app-filename.d.ts +2 -0
  51. package/dist/cli/bundler/utils/app-filename.js +19 -0
  52. package/dist/cli/bundler/utils/app-filename.js.map +1 -0
  53. package/dist/cli/bundler/utils/assets.d.ts +3 -0
  54. package/dist/cli/bundler/utils/{output.js → assets.js} +22 -33
  55. package/dist/cli/bundler/utils/assets.js.map +1 -0
  56. package/dist/cli/bundler/utils/index.d.ts +2 -3
  57. package/dist/cli/bundler/utils/index.js +2 -3
  58. package/dist/cli/bundler/utils/index.js.map +1 -1
  59. package/dist/cli/entrypoint/file/injectors/core.js +1 -1
  60. package/dist/cli/entrypoint/finder/ContentFinder.d.ts +1 -1
  61. package/dist/cli/entrypoint/parser/ContentParser.d.ts +2 -2
  62. package/dist/cli/entrypoint/parser/ContentParser.js +6 -22
  63. package/dist/cli/entrypoint/parser/ContentParser.js.map +1 -1
  64. package/dist/cli/entrypoint/parser/RelayParser.js +1 -1
  65. package/dist/cli/entrypoint/parser/utils/content/default-render.d.ts +3 -0
  66. package/dist/cli/entrypoint/parser/utils/content/default-render.js +21 -0
  67. package/dist/cli/entrypoint/parser/utils/content/default-render.js.map +1 -0
  68. package/dist/cli/plugins/content/Content.d.ts +1 -1
  69. package/dist/cli/plugins/content/ContentDriver.d.ts +1 -1
  70. package/dist/cli/plugins/content/ContentManager.d.ts +1 -1
  71. package/dist/cli/plugins/content/ContentManager.js +1 -1
  72. package/dist/cli/plugins/content/ContentName.d.ts +1 -1
  73. package/dist/cli/plugins/content/ContentName.js +1 -1
  74. package/dist/cli/plugins/content/Relay.d.ts +1 -1
  75. package/dist/cli/plugins/content/RelayDriver.d.ts +1 -1
  76. package/dist/cli/plugins/content/RelayDriver.js +1 -1
  77. package/dist/cli/plugins/content/bundler.d.ts +1 -4
  78. package/dist/cli/plugins/content/bundler.js +5 -21
  79. package/dist/cli/plugins/content/bundler.js.map +1 -1
  80. package/dist/cli/plugins/content/index.js +4 -5
  81. package/dist/cli/plugins/content/index.js.map +1 -1
  82. package/dist/cli/plugins/content/types.d.ts +1 -1
  83. package/dist/cli/plugins/content/utils.d.ts +1 -1
  84. package/dist/cli/plugins/content/utils.js +1 -1
  85. package/dist/cli/plugins/index.d.ts +1 -1
  86. package/dist/cli/plugins/index.js +1 -1
  87. package/dist/cli/plugins/locale/Locale.js +5 -2
  88. package/dist/cli/plugins/locale/Locale.js.map +1 -1
  89. package/dist/cli/plugins/locale/index.js +2 -2
  90. package/dist/cli/plugins/locale/index.js.map +1 -1
  91. package/dist/cli/plugins/output/index.d.ts +2 -0
  92. package/dist/cli/plugins/{output.js → output/index.js} +11 -13
  93. package/dist/cli/plugins/output/index.js.map +1 -0
  94. package/dist/cli/plugins/output/runtime.d.ts +26 -0
  95. package/dist/cli/plugins/output/runtime.js +19 -0
  96. package/dist/cli/plugins/output/runtime.js.map +1 -0
  97. package/dist/cli/plugins/style/index.d.ts +1 -2
  98. package/dist/cli/plugins/style/index.js +19 -30
  99. package/dist/cli/plugins/style/index.js.map +1 -1
  100. package/dist/cli/resolvers/config.js +1 -2
  101. package/dist/cli/resolvers/config.js.map +1 -1
  102. package/dist/cli/virtual/index.js +4 -4
  103. package/dist/cli/virtual/virtual.d.ts +8 -3
  104. package/dist/content/index.d.ts +3 -0
  105. package/dist/content/index.js +8 -0
  106. package/dist/content/index.js.map +1 -0
  107. package/dist/entry/content/adapters/react/Builder.d.ts +7 -6
  108. package/dist/entry/content/adapters/react/Builder.js +12 -19
  109. package/dist/entry/content/adapters/react/Builder.js.map +1 -1
  110. package/dist/entry/content/adapters/react/Node.d.ts +6 -14
  111. package/dist/entry/content/adapters/react/Node.js +11 -35
  112. package/dist/entry/content/adapters/react/Node.js.map +1 -1
  113. package/dist/entry/content/adapters/react/definition.d.ts +2 -0
  114. package/dist/entry/content/adapters/react/definition.js +12 -0
  115. package/dist/entry/content/adapters/react/definition.js.map +1 -0
  116. package/dist/entry/content/adapters/react/index.d.ts +2 -1
  117. package/dist/entry/content/adapters/react/index.js +3 -1
  118. package/dist/entry/content/adapters/react/index.js.map +1 -1
  119. package/dist/entry/content/adapters/vanilla/Builder.d.ts +7 -5
  120. package/dist/entry/content/adapters/vanilla/Builder.js +17 -14
  121. package/dist/entry/content/adapters/vanilla/Builder.js.map +1 -1
  122. package/dist/entry/content/adapters/vanilla/Node.d.ts +5 -11
  123. package/dist/entry/content/adapters/vanilla/Node.js +11 -37
  124. package/dist/entry/content/adapters/vanilla/Node.js.map +1 -1
  125. package/dist/entry/content/adapters/vanilla/definition.d.ts +2 -0
  126. package/dist/entry/content/adapters/vanilla/definition.js +9 -0
  127. package/dist/entry/content/adapters/vanilla/definition.js.map +1 -0
  128. package/dist/entry/content/adapters/vanilla/index.d.ts +2 -1
  129. package/dist/entry/content/adapters/vanilla/index.js +3 -1
  130. package/dist/entry/content/adapters/vanilla/index.js.map +1 -1
  131. package/dist/entry/content/adapters/vanilla/utils.d.ts +1 -0
  132. package/dist/entry/content/adapters/vanilla/utils.js +7 -0
  133. package/dist/entry/content/adapters/vanilla/utils.js.map +1 -0
  134. package/dist/entry/content/index.d.ts +5 -1
  135. package/dist/entry/content/index.js +8 -1
  136. package/dist/entry/content/index.js.map +1 -1
  137. package/dist/entry/content/lifecycle/Builder.d.ts +32 -0
  138. package/dist/entry/content/lifecycle/Builder.js +254 -0
  139. package/dist/entry/content/lifecycle/Builder.js.map +1 -0
  140. package/dist/entry/content/lifecycle/IsolationSetup.d.ts +16 -0
  141. package/dist/entry/content/lifecycle/IsolationSetup.js +37 -0
  142. package/dist/entry/content/lifecycle/IsolationSetup.js.map +1 -0
  143. package/dist/entry/content/lifecycle/MountBuilder.d.ts +11 -0
  144. package/dist/entry/content/lifecycle/MountBuilder.js +73 -0
  145. package/dist/entry/content/lifecycle/MountBuilder.js.map +1 -0
  146. package/dist/entry/content/lifecycle/context/ContainerRegistry.d.ts +7 -0
  147. package/dist/entry/content/lifecycle/context/ContainerRegistry.js +45 -0
  148. package/dist/entry/content/lifecycle/context/ContainerRegistry.js.map +1 -0
  149. package/dist/entry/content/lifecycle/context/Context.d.ts +17 -0
  150. package/dist/entry/content/lifecycle/context/Context.js +88 -0
  151. package/dist/entry/content/lifecycle/context/Context.js.map +1 -0
  152. package/dist/entry/content/{core → lifecycle}/context/EventEmitter.d.ts +2 -2
  153. package/dist/entry/content/{core → lifecycle}/context/EventEmitter.js +3 -3
  154. package/dist/entry/content/lifecycle/context/EventEmitter.js.map +1 -0
  155. package/dist/entry/content/lifecycle/context/ManagedContext.d.ts +8 -0
  156. package/dist/entry/content/lifecycle/context/ManagedContext.js +19 -0
  157. package/dist/entry/content/lifecycle/context/ManagedContext.js.map +1 -0
  158. package/dist/entry/content/{core → lifecycle}/context/index.d.ts +1 -0
  159. package/dist/entry/content/lifecycle/context/index.js +11 -0
  160. package/dist/entry/content/lifecycle/context/index.js.map +1 -0
  161. package/dist/entry/content/{core → lifecycle}/markers/AbstractMarker.d.ts +2 -2
  162. package/dist/entry/content/{core → lifecycle}/markers/AbstractMarker.js +3 -3
  163. package/dist/entry/content/lifecycle/markers/AbstractMarker.js.map +1 -0
  164. package/dist/entry/content/{core → lifecycle}/markers/AttributeMarker.d.ts +2 -2
  165. package/dist/entry/content/{core → lifecycle}/markers/AttributeMarker.js +5 -3
  166. package/dist/entry/content/lifecycle/markers/AttributeMarker.js.map +1 -0
  167. package/dist/entry/content/{core → lifecycle}/markers/WeakMarker.d.ts +2 -2
  168. package/dist/entry/content/{core → lifecycle}/markers/WeakMarker.js +2 -2
  169. package/dist/entry/content/lifecycle/markers/WeakMarker.js.map +1 -0
  170. package/dist/entry/content/lifecycle/markers/index.js.map +1 -0
  171. package/dist/entry/content/lifecycle/nodes/EventNode.d.ts +15 -0
  172. package/dist/entry/content/lifecycle/nodes/EventNode.js +49 -0
  173. package/dist/entry/content/lifecycle/nodes/EventNode.js.map +1 -0
  174. package/dist/entry/content/lifecycle/nodes/FrameNode.d.ts +30 -0
  175. package/dist/entry/content/lifecycle/nodes/FrameNode.js +190 -0
  176. package/dist/entry/content/lifecycle/nodes/FrameNode.js.map +1 -0
  177. package/dist/entry/content/{core → lifecycle}/nodes/MarkerNode.d.ts +3 -2
  178. package/dist/entry/content/{core → lifecycle}/nodes/MarkerNode.js +5 -2
  179. package/dist/entry/content/lifecycle/nodes/MarkerNode.js.map +1 -0
  180. package/dist/entry/content/lifecycle/nodes/MountNode.d.ts +17 -0
  181. package/dist/entry/content/lifecycle/nodes/MountNode.js +80 -0
  182. package/dist/entry/content/lifecycle/nodes/MountNode.js.map +1 -0
  183. package/dist/entry/content/{core → lifecycle}/nodes/Node.d.ts +2 -2
  184. package/dist/entry/content/{core → lifecycle}/nodes/Node.js +2 -2
  185. package/dist/entry/content/lifecycle/nodes/Node.js.map +1 -0
  186. package/dist/entry/content/lifecycle/nodes/RenderNode.d.ts +28 -0
  187. package/dist/entry/content/lifecycle/nodes/RenderNode.js +140 -0
  188. package/dist/entry/content/lifecycle/nodes/RenderNode.js.map +1 -0
  189. package/dist/entry/content/lifecycle/nodes/ShadowNode.d.ts +22 -0
  190. package/dist/entry/content/lifecycle/nodes/ShadowNode.js +124 -0
  191. package/dist/entry/content/lifecycle/nodes/ShadowNode.js.map +1 -0
  192. package/dist/entry/content/{core → lifecycle}/nodes/index.d.ts +1 -0
  193. package/dist/entry/content/lifecycle/nodes/index.js +17 -0
  194. package/dist/entry/content/lifecycle/nodes/index.js.map +1 -0
  195. package/dist/entry/content/{core → lifecycle}/nodes/isolated-styles.d.ts +1 -1
  196. package/dist/entry/content/{core → lifecycle}/nodes/isolated-styles.js +2 -2
  197. package/dist/entry/content/lifecycle/nodes/isolated-styles.js.map +1 -0
  198. package/dist/entry/content/lifecycle/types.d.ts +28 -0
  199. package/dist/entry/content/resolvers/anchor.d.ts +2 -0
  200. package/dist/entry/content/{core/resolvers → resolvers}/anchor.js +2 -2
  201. package/dist/entry/content/resolvers/anchor.js.map +1 -0
  202. package/dist/entry/content/resolvers/container.d.ts +2 -0
  203. package/dist/entry/content/{core/resolvers → resolvers}/container.js +2 -2
  204. package/dist/entry/content/resolvers/container.js.map +1 -0
  205. package/dist/entry/content/resolvers/definition.d.ts +5 -0
  206. package/dist/entry/content/resolvers/definition.js +24 -0
  207. package/dist/entry/content/resolvers/definition.js.map +1 -0
  208. package/dist/entry/content/{core/resolvers → resolvers}/index.d.ts +1 -1
  209. package/dist/entry/content/{core/resolvers → resolvers}/index.js +1 -1
  210. package/dist/entry/content/resolvers/index.js.map +1 -0
  211. package/dist/entry/content/resolvers/mount.d.ts +2 -0
  212. package/dist/entry/content/{core/resolvers → resolvers}/mount.js +3 -3
  213. package/dist/entry/content/resolvers/mount.js.map +1 -0
  214. package/dist/entry/content/resolvers/target.d.ts +3 -0
  215. package/dist/entry/content/resolvers/target.js +34 -0
  216. package/dist/entry/content/resolvers/target.js.map +1 -0
  217. package/dist/entry/content/resolvers/watch.d.ts +6 -0
  218. package/dist/entry/content/resolvers/watch.js +81 -0
  219. package/dist/entry/content/resolvers/watch.js.map +1 -0
  220. package/dist/entry/relay/Builder.d.ts +8 -8
  221. package/dist/entry/relay/Builder.js +28 -19
  222. package/dist/entry/relay/Builder.js.map +1 -1
  223. package/dist/entry/relay/TransportBuilder.d.ts +3 -2
  224. package/dist/entry/relay/TransportBuilder.js +3 -3
  225. package/dist/entry/relay/TransportBuilder.js.map +1 -1
  226. package/dist/entry/relay/index.d.ts +5 -2
  227. package/dist/entry/relay/index.js +8 -2
  228. package/dist/entry/relay/index.js.map +1 -1
  229. package/dist/entry/relay/resolvers/definition.d.ts +4 -0
  230. package/dist/entry/relay/resolvers/definition.js +16 -0
  231. package/dist/entry/relay/resolvers/definition.js.map +1 -0
  232. package/dist/main/content.d.ts +4 -6
  233. package/dist/main/content.js +3 -16
  234. package/dist/main/content.js.map +1 -1
  235. package/dist/main/entrypoint.js +1 -1
  236. package/dist/main/entrypoint.js.map +1 -1
  237. package/dist/main/relay.d.ts +2 -1
  238. package/dist/main/relay.js.map +1 -1
  239. package/dist/relay/RelayPermission.js +1 -1
  240. package/dist/shared/content/isolation.d.ts +1 -1
  241. package/dist/shared/content/isolation.js +13 -20
  242. package/dist/shared/content/isolation.js.map +1 -1
  243. package/dist/shared/locale/index.d.ts +1 -1
  244. package/dist/shared/locale/index.js +3 -1
  245. package/dist/shared/locale/index.js.map +1 -1
  246. package/dist/shared/locale/messages.d.ts +4 -0
  247. package/dist/shared/locale/messages.js +12 -0
  248. package/dist/shared/locale/messages.js.map +1 -1
  249. package/dist/types/content/adapters/index.d.ts +2 -0
  250. package/dist/types/content/adapters/index.js +1 -0
  251. package/dist/types/content/adapters/index.js.map +1 -0
  252. package/dist/types/content/adapters/react.d.ts +4 -0
  253. package/dist/types/content/adapters/react.js +1 -0
  254. package/dist/types/content/adapters/react.js.map +1 -0
  255. package/dist/types/content/adapters/vanilla.d.ts +1 -0
  256. package/dist/types/content/adapters/vanilla.js +1 -0
  257. package/dist/types/content/adapters/vanilla.js.map +1 -0
  258. package/dist/types/content/boundary.d.ts +17 -0
  259. package/dist/types/content/boundary.js +1 -0
  260. package/dist/types/content/boundary.js.map +1 -0
  261. package/dist/types/{content.d.ts → content/common.d.ts} +32 -53
  262. package/dist/types/{content.js → content/common.js} +1 -1
  263. package/dist/types/content/common.js.map +1 -0
  264. package/dist/types/content/definition.d.ts +66 -0
  265. package/dist/types/content/definition.js +1 -0
  266. package/dist/types/content/definition.js.map +1 -0
  267. package/dist/types/content/index.d.ts +7 -0
  268. package/dist/types/content/index.js +2 -0
  269. package/dist/types/content/index.js.map +1 -0
  270. package/dist/types/content/prepare.d.ts +9 -0
  271. package/dist/types/content/prepare.js +1 -0
  272. package/dist/types/content/prepare.js.map +1 -0
  273. package/dist/types/content/render.d.ts +6 -0
  274. package/dist/types/content/render.js +1 -0
  275. package/dist/types/content/render.js.map +1 -0
  276. package/dist/types/content/target.d.ts +13 -0
  277. package/dist/types/content/target.js +1 -0
  278. package/dist/types/content/target.js.map +1 -0
  279. package/dist/types/locale.d.ts +3 -0
  280. package/dist/types/locale.js.map +1 -1
  281. package/dist/types/manifest.d.ts +1 -1
  282. package/dist/types/relay.d.ts +3 -4
  283. package/dist/types/relay.js.map +1 -1
  284. package/dist/virtual/modules.d.ts +4 -3
  285. package/dist/virtual/{entrypoint.d.ts → runtime.d.ts} +3 -0
  286. package/dist/virtual/runtime.js +9 -0
  287. package/dist/virtual/runtime.js.map +1 -0
  288. package/package.json +32 -25
  289. package/scripts/merge-coverage.mjs +12 -0
  290. package/scripts/pre-commit.mjs +22 -0
  291. package/scripts/test-inventory.mjs +38 -0
  292. package/scripts/test-run.mjs +25 -0
  293. package/types/client.d.ts +3 -3
  294. package/dist/cli/bundler/plugins/build-assets-map/entrypoint-module.d.ts +0 -13
  295. package/dist/cli/bundler/plugins/build-assets-map/entrypoint-module.js +0 -16
  296. package/dist/cli/bundler/plugins/build-assets-map/entrypoint-module.js.map +0 -1
  297. package/dist/cli/bundler/utils/layers.d.ts +0 -4
  298. package/dist/cli/bundler/utils/layers.js +0 -10
  299. package/dist/cli/bundler/utils/layers.js.map +0 -1
  300. package/dist/cli/bundler/utils/output.d.ts +0 -6
  301. package/dist/cli/bundler/utils/output.js.map +0 -1
  302. package/dist/cli/bundler/utils/styles.d.ts +0 -5
  303. package/dist/cli/bundler/utils/styles.js +0 -30
  304. package/dist/cli/bundler/utils/styles.js.map +0 -1
  305. package/dist/cli/plugins/output.d.ts +0 -2
  306. package/dist/cli/plugins/output.js.map +0 -1
  307. package/dist/cli/plugins/style/types.d.ts +0 -5
  308. package/dist/entry/content/adapters/react/resolvers/index.d.ts +0 -1
  309. package/dist/entry/content/adapters/react/resolvers/index.js +0 -2
  310. package/dist/entry/content/adapters/react/resolvers/index.js.map +0 -1
  311. package/dist/entry/content/adapters/react/resolvers/render.d.ts +0 -2
  312. package/dist/entry/content/adapters/react/resolvers/render.js +0 -11
  313. package/dist/entry/content/adapters/react/resolvers/render.js.map +0 -1
  314. package/dist/entry/content/core/Builder.d.ts +0 -26
  315. package/dist/entry/content/core/Builder.js +0 -128
  316. package/dist/entry/content/core/Builder.js.map +0 -1
  317. package/dist/entry/content/core/MountBuilder.d.ts +0 -10
  318. package/dist/entry/content/core/MountBuilder.js +0 -48
  319. package/dist/entry/content/core/MountBuilder.js.map +0 -1
  320. package/dist/entry/content/core/context/Context.d.ts +0 -12
  321. package/dist/entry/content/core/context/Context.js +0 -50
  322. package/dist/entry/content/core/context/Context.js.map +0 -1
  323. package/dist/entry/content/core/context/EventEmitter.js.map +0 -1
  324. package/dist/entry/content/core/context/ManagedContext.d.ts +0 -5
  325. package/dist/entry/content/core/context/ManagedContext.js +0 -12
  326. package/dist/entry/content/core/context/ManagedContext.js.map +0 -1
  327. package/dist/entry/content/core/context/index.js +0 -9
  328. package/dist/entry/content/core/context/index.js.map +0 -1
  329. package/dist/entry/content/core/markers/AbstractMarker.js.map +0 -1
  330. package/dist/entry/content/core/markers/AttributeMarker.js.map +0 -1
  331. package/dist/entry/content/core/markers/WeakMarker.js.map +0 -1
  332. package/dist/entry/content/core/markers/index.js.map +0 -1
  333. package/dist/entry/content/core/nodes/EventNode.d.ts +0 -11
  334. package/dist/entry/content/core/nodes/EventNode.js +0 -35
  335. package/dist/entry/content/core/nodes/EventNode.js.map +0 -1
  336. package/dist/entry/content/core/nodes/FrameNode.d.ts +0 -23
  337. package/dist/entry/content/core/nodes/FrameNode.js +0 -125
  338. package/dist/entry/content/core/nodes/FrameNode.js.map +0 -1
  339. package/dist/entry/content/core/nodes/MarkerNode.js.map +0 -1
  340. package/dist/entry/content/core/nodes/MountNode.d.ts +0 -12
  341. package/dist/entry/content/core/nodes/MountNode.js +0 -42
  342. package/dist/entry/content/core/nodes/MountNode.js.map +0 -1
  343. package/dist/entry/content/core/nodes/Node.js.map +0 -1
  344. package/dist/entry/content/core/nodes/ShadowNode.d.ts +0 -14
  345. package/dist/entry/content/core/nodes/ShadowNode.js +0 -67
  346. package/dist/entry/content/core/nodes/ShadowNode.js.map +0 -1
  347. package/dist/entry/content/core/nodes/index.js +0 -15
  348. package/dist/entry/content/core/nodes/index.js.map +0 -1
  349. package/dist/entry/content/core/nodes/isolated-styles.js.map +0 -1
  350. package/dist/entry/content/core/resolvers/anchor.d.ts +0 -2
  351. package/dist/entry/content/core/resolvers/anchor.js.map +0 -1
  352. package/dist/entry/content/core/resolvers/container.d.ts +0 -2
  353. package/dist/entry/content/core/resolvers/container.js.map +0 -1
  354. package/dist/entry/content/core/resolvers/definition.d.ts +0 -3
  355. package/dist/entry/content/core/resolvers/definition.js +0 -12
  356. package/dist/entry/content/core/resolvers/definition.js.map +0 -1
  357. package/dist/entry/content/core/resolvers/index.js.map +0 -1
  358. package/dist/entry/content/core/resolvers/mount.d.ts +0 -2
  359. package/dist/entry/content/core/resolvers/mount.js.map +0 -1
  360. package/dist/entry/content/core/resolvers/render.d.ts +0 -3
  361. package/dist/entry/content/core/resolvers/render.js +0 -18
  362. package/dist/entry/content/core/resolvers/render.js.map +0 -1
  363. package/dist/entry/content/core/resolvers/watch.d.ts +0 -4
  364. package/dist/entry/content/core/resolvers/watch.js +0 -62
  365. package/dist/entry/content/core/resolvers/watch.js.map +0 -1
  366. package/dist/entry/content/frame/Builder.d.ts +0 -7
  367. package/dist/entry/content/frame/Builder.js +0 -14
  368. package/dist/entry/content/frame/Builder.js.map +0 -1
  369. package/dist/entry/content/frame/index.d.ts +0 -4
  370. package/dist/entry/content/frame/index.js +0 -7
  371. package/dist/entry/content/frame/index.js.map +0 -1
  372. package/dist/types/content.js.map +0 -1
  373. package/dist/virtual/entrypoint.js +0 -7
  374. package/dist/virtual/entrypoint.js.map +0 -1
  375. /package/dist/entry/content/{core → lifecycle}/markers/index.d.ts +0 -0
  376. /package/dist/entry/content/{core → lifecycle}/markers/index.js +0 -0
  377. /package/dist/{cli/plugins/style → entry/content/lifecycle}/types.js +0 -0
  378. /package/dist/{cli/plugins/style → entry/content/lifecycle}/types.js.map +0 -0
@@ -0,0 +1,32 @@
1
+ import EntrypointBuilder from "../../core/Builder.js";
2
+ import { ManagedContext, EventEmitter } from "./context/index.js";
3
+ import type { ContentScriptNodeAssembly } from "./types.js";
4
+ import { ContentScriptAnchor, ContentScriptAnchorGetter, ContentScriptBuilder, ContentScriptContainerCreator, ContentScriptContainerFactory, ContentScriptContainerOptions, ContentScriptContainerTag, ContentScriptContext, ContentScriptDefinition, ContentScriptIsolation, ContentScriptIsolationOptions, ContentScriptMarkerContract, ContentScriptMarkerGetter, ContentScriptMarkerResolver, ContentScriptMarkerType, ContentScriptMountFunction, ContentScriptPrepareProps, ContentScriptPrepareResult, ContentScriptRenderHandler, ContentScriptRenderValue, ContentScriptResolvedDefinition, ContentScriptTarget, ContentScriptTargetCreator, ContentScriptWatchStrategy } from "../../../types/content/index.js";
5
+ export default abstract class Builder<Data = unknown, Isolation extends `${ContentScriptIsolation}` = `${ContentScriptIsolation}`> extends EntrypointBuilder implements ContentScriptBuilder {
6
+ private cycle?;
7
+ protected generation: number;
8
+ protected readonly definition: ContentScriptResolvedDefinition<Data>;
9
+ protected readonly emitter: EventEmitter;
10
+ protected readonly context: ManagedContext;
11
+ protected marker: ContentScriptMarkerContract;
12
+ protected unwatch?: () => void;
13
+ protected abstract createNode(anchor: Element, result: ContentScriptPrepareResult<Data> | undefined): Promise<ContentScriptNodeAssembly>;
14
+ protected constructor(input: ContentScriptDefinition<Data, Isolation>);
15
+ protected resolveMarker(marker: ContentScriptMarkerType | ContentScriptMarkerGetter): ContentScriptMarkerResolver;
16
+ protected resolveAnchor(anchor?: ContentScriptAnchor | ContentScriptAnchorGetter): ContentScriptAnchorGetter;
17
+ protected resolveMount(mount?: ContentScriptMountFunction): ContentScriptMountFunction;
18
+ protected resolveContainer(container?: ContentScriptContainerTag | ContentScriptContainerOptions | ContentScriptContainerFactory<Data>): ContentScriptContainerCreator<Data>;
19
+ protected resolveTarget(target?: ContentScriptTarget<Data>): ContentScriptTargetCreator<Data>;
20
+ protected resolveIsolation(definition: ContentScriptDefinition<Data>): ContentScriptIsolationOptions;
21
+ protected resolveRender(render?: ContentScriptRenderValue<Data> | ContentScriptRenderHandler<Data>): true | ContentScriptRenderHandler<Data> | undefined;
22
+ protected resolveWatch(watch?: true | ContentScriptWatchStrategy): ContentScriptWatchStrategy;
23
+ getContext(): ContentScriptContext;
24
+ build(): Promise<void>;
25
+ destroy(): Promise<void>;
26
+ protected getPrepareProps(anchor: Element): ContentScriptPrepareProps;
27
+ private requestProcessing;
28
+ private drainProcessing;
29
+ protected processing(generation: number): Promise<void>;
30
+ protected processAnchor(anchor: Element, generation: number): Promise<void>;
31
+ private handleRenderError;
32
+ }
@@ -0,0 +1,254 @@
1
+ import { isContentScriptFrameNavigation, resolveContentScriptIsolation } from "./../../../shared/content/index.js";
2
+ import EntrypointBuilder from "./../../../entry/core/Builder.js";
3
+ import {
4
+ createAnchorResolver,
5
+ createAwaitFirstStrategy,
6
+ createContainerResolver,
7
+ createTargetResolver,
8
+ withLocationTracking,
9
+ createAppendMountHandler,
10
+ createMutationObserverStrategy
11
+ } from "../resolvers/index.js";
12
+ import { ManagedContext, EventEmitter } from "./context/index.js";
13
+ import { AttributeMarker, WeakMarker } from "./markers/index.js";
14
+ import { EventNode } from "./nodes/index.js";
15
+ import {
16
+ ContentScriptMarker
17
+ } from "./../../../types/content/index.js";
18
+ class Builder extends EntrypointBuilder {
19
+ cycle;
20
+ generation = 0;
21
+ definition;
22
+ emitter = new EventEmitter();
23
+ context = new ManagedContext(this.emitter);
24
+ marker = new AttributeMarker();
25
+ unwatch;
26
+ constructor(input) {
27
+ super();
28
+ const definition = input;
29
+ this.definition = {
30
+ ...definition,
31
+ marker: this.resolveMarker(definition.marker),
32
+ anchor: this.resolveAnchor(definition.anchor),
33
+ mount: this.resolveMount(definition.mount),
34
+ container: this.resolveContainer(definition.container),
35
+ target: this.resolveTarget(definition.target),
36
+ isolation: this.resolveIsolation(definition),
37
+ render: this.resolveRender(definition.render),
38
+ watch: this.resolveWatch(definition.watch)
39
+ };
40
+ }
41
+ resolveMarker(marker) {
42
+ return async (options) => {
43
+ if (typeof marker === "function") {
44
+ marker = await marker(options);
45
+ }
46
+ if (!marker) {
47
+ marker = ContentScriptMarker.Attribute;
48
+ }
49
+ if (typeof marker === "string") {
50
+ switch (marker) {
51
+ case ContentScriptMarker.Weak:
52
+ return new WeakMarker();
53
+ case ContentScriptMarker.Attribute:
54
+ default:
55
+ return new AttributeMarker();
56
+ }
57
+ }
58
+ return marker;
59
+ };
60
+ }
61
+ resolveAnchor(anchor) {
62
+ return createAnchorResolver(anchor);
63
+ }
64
+ resolveMount(mount) {
65
+ return mount || createAppendMountHandler();
66
+ }
67
+ resolveContainer(container) {
68
+ return createContainerResolver(container);
69
+ }
70
+ resolveTarget(target) {
71
+ return createTargetResolver(target);
72
+ }
73
+ resolveIsolation(definition) {
74
+ const isolation = resolveContentScriptIsolation(definition.isolation, "render" in definition);
75
+ if (definition.boundary !== void 0) {
76
+ if (typeof definition.boundary !== "function") {
77
+ throw new Error("Content script boundary must be a synchronous setup handler");
78
+ }
79
+ if (isolation.type === "none") {
80
+ throw new Error("Content script boundary requires Shadow DOM or an iframe");
81
+ }
82
+ }
83
+ if (definition.target !== void 0 && (isolation.type === "none" || isContentScriptFrameNavigation(isolation))) {
84
+ throw new Error("Content script target requires Shadow DOM or an iframe with local rendering");
85
+ }
86
+ return isolation;
87
+ }
88
+ resolveRender(render) {
89
+ if (render === true || render === void 0) {
90
+ return render;
91
+ }
92
+ throw new Error("Content script rendering requires a renderer adapter");
93
+ }
94
+ resolveWatch(watch) {
95
+ if (watch === void 0) {
96
+ watch = createAwaitFirstStrategy();
97
+ } else if (watch === true) {
98
+ watch = createMutationObserverStrategy();
99
+ }
100
+ return withLocationTracking(watch);
101
+ }
102
+ getContext() {
103
+ return this.context;
104
+ }
105
+ async build() {
106
+ const destroying = this.destroy();
107
+ const generation = this.generation;
108
+ await destroying;
109
+ if (generation !== this.generation) {
110
+ return;
111
+ }
112
+ const { render, prepare, main, anchor, marker, container, boundary, target, watch, mount, ...options } = this.definition;
113
+ await (main == null ? void 0 : main(this.context, options));
114
+ if (generation !== this.generation) {
115
+ return;
116
+ }
117
+ if (render !== void 0 || prepare !== void 0 || isContentScriptFrameNavigation(this.definition.isolation)) {
118
+ const resolvedMarker = await marker(options);
119
+ if (generation !== this.generation) {
120
+ return;
121
+ }
122
+ this.marker = resolvedMarker;
123
+ await this.requestProcessing(generation);
124
+ if (generation !== this.generation) {
125
+ return;
126
+ }
127
+ const onError = (error) => {
128
+ console.error("Content script processing on watch error", error);
129
+ };
130
+ this.unwatch = watch(() => this.requestProcessing(generation, onError), this.context);
131
+ }
132
+ }
133
+ async destroy() {
134
+ var _a;
135
+ this.generation++;
136
+ this.cycle = void 0;
137
+ (_a = this.unwatch) == null ? void 0 : _a.call(this);
138
+ this.unwatch = void 0;
139
+ try {
140
+ this.context.clear();
141
+ } finally {
142
+ this.context.unwatch();
143
+ this.marker.reset();
144
+ }
145
+ }
146
+ getPrepareProps(anchor) {
147
+ const {
148
+ anchor: _,
149
+ marker,
150
+ mount,
151
+ watch,
152
+ prepare,
153
+ render,
154
+ container,
155
+ boundary,
156
+ target,
157
+ main,
158
+ ...options
159
+ } = this.definition;
160
+ return { ...options, anchor };
161
+ }
162
+ requestProcessing(generation, onError) {
163
+ var _a;
164
+ if (generation !== this.generation) {
165
+ return Promise.resolve();
166
+ }
167
+ if (((_a = this.cycle) == null ? void 0 : _a.generation) === generation) {
168
+ this.cycle.pending = true;
169
+ return this.cycle.promise;
170
+ }
171
+ const cycle = {
172
+ generation,
173
+ pending: true,
174
+ promise: Promise.resolve().then(() => this.drainProcessing(cycle))
175
+ };
176
+ if (onError) {
177
+ cycle.promise = cycle.promise.catch(onError);
178
+ }
179
+ this.cycle = cycle;
180
+ return cycle.promise;
181
+ }
182
+ async drainProcessing(cycle) {
183
+ try {
184
+ while (cycle.pending && cycle.generation === this.generation) {
185
+ cycle.pending = false;
186
+ this.context.mount();
187
+ if (cycle.generation !== this.generation) {
188
+ return;
189
+ }
190
+ await this.processing(cycle.generation);
191
+ }
192
+ } finally {
193
+ if (this.cycle === cycle) {
194
+ this.cycle = void 0;
195
+ }
196
+ }
197
+ }
198
+ async processing(generation) {
199
+ const anchor = await this.definition.anchor();
200
+ if (generation !== this.generation) {
201
+ return;
202
+ }
203
+ const anchors = this.marker.for(anchor).unmarked().filter((anchor2) => anchor2.isConnected);
204
+ const results = await Promise.allSettled(anchors.map((anchor2) => this.processAnchor(anchor2, generation)));
205
+ const errors = results.flatMap((result) => result.status === "rejected" ? [result.reason] : []);
206
+ if (errors.length && generation === this.generation) {
207
+ console.error(new AggregateError(errors, "Content script anchor processing failed"));
208
+ }
209
+ }
210
+ async processAnchor(anchor, generation) {
211
+ var _a, _b, _c, _d;
212
+ const current = () => generation === this.generation && anchor.isConnected;
213
+ const data = await ((_b = (_a = this.definition).prepare) == null ? void 0 : _b.call(_a, this.getPrepareProps(anchor)));
214
+ if (!current()) {
215
+ return;
216
+ }
217
+ const assembly = await this.createNode(anchor, data);
218
+ const node = new EventNode(assembly.node, this.emitter, assembly.renderer);
219
+ if (!current()) {
220
+ node.unmount();
221
+ return;
222
+ }
223
+ (_c = assembly.renderer) == null ? void 0 : _c.setErrorHandler((error) => this.handleRenderError(node, error, generation));
224
+ this.context.add(node);
225
+ if (generation !== this.generation) {
226
+ return;
227
+ }
228
+ try {
229
+ node.mount();
230
+ if (!current() && !((_d = node.container) == null ? void 0 : _d.isConnected)) {
231
+ this.context.remove(node);
232
+ }
233
+ } catch (error) {
234
+ this.context.remove(node);
235
+ throw error;
236
+ }
237
+ }
238
+ handleRenderError(node, error, generation) {
239
+ if (generation !== this.generation) {
240
+ return;
241
+ }
242
+ const errors = [error];
243
+ try {
244
+ this.context.remove(node);
245
+ } catch (cause) {
246
+ errors.push(cause);
247
+ }
248
+ console.error(new AggregateError(errors, "Content script deferred mount failed"));
249
+ }
250
+ }
251
+ export {
252
+ Builder as default
253
+ };
254
+ //# sourceMappingURL=Builder.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/entry/content/lifecycle/Builder.ts"],"sourcesContent":["import {isContentScriptFrameNavigation, resolveContentScriptIsolation} from \"@shared/content\";\n\nimport EntrypointBuilder from \"@entry/core/Builder\";\n\nimport {\n createAnchorResolver,\n createAwaitFirstStrategy,\n createContainerResolver,\n createTargetResolver,\n withLocationTracking,\n createAppendMountHandler,\n createMutationObserverStrategy,\n} from \"../resolvers\";\n\nimport {ManagedContext, EventEmitter} from \"./context\";\nimport {AttributeMarker, WeakMarker} from \"./markers\";\nimport {EventNode} from \"./nodes\";\n\nimport type {ContentScriptNodeAssembly, ContentScriptCycle} from \"./types\";\n\nimport {\n ContentScriptNode,\n ContentScriptAnchor,\n ContentScriptAnchorGetter,\n ContentScriptBuilder,\n ContentScriptContainerCreator,\n ContentScriptContainerFactory,\n ContentScriptContainerOptions,\n ContentScriptContainerTag,\n ContentScriptContext,\n ContentScriptDefinition,\n ContentScriptIsolation,\n ContentScriptIsolationOptions,\n ContentScriptMarker,\n ContentScriptMarkerContract,\n ContentScriptMarkerGetter,\n ContentScriptMarkerResolver,\n ContentScriptMarkerType,\n ContentScriptMountFunction,\n ContentScriptPrepareProps,\n ContentScriptPrepareResult,\n ContentScriptOptions,\n ContentScriptRenderHandler,\n ContentScriptRenderValue,\n ContentScriptResolvedDefinition,\n ContentScriptTarget,\n ContentScriptTargetCreator,\n ContentScriptWatchStrategy,\n} from \"@typing/content\";\n\nexport default abstract class Builder<\n Data = unknown,\n Isolation extends `${ContentScriptIsolation}` = `${ContentScriptIsolation}`,\n>\n extends EntrypointBuilder\n implements ContentScriptBuilder\n{\n private cycle?: ContentScriptCycle;\n\n protected generation = 0;\n\n protected readonly definition: ContentScriptResolvedDefinition<Data>;\n\n protected readonly emitter = new EventEmitter();\n\n protected readonly context = new ManagedContext(this.emitter);\n\n protected marker: ContentScriptMarkerContract = new AttributeMarker();\n\n protected unwatch?: () => void;\n\n protected abstract createNode(\n anchor: Element,\n result: ContentScriptPrepareResult<Data> | undefined\n ): Promise<ContentScriptNodeAssembly>;\n\n protected constructor(input: ContentScriptDefinition<Data, Isolation>) {\n super();\n\n // Normalization selects the isolation at runtime; its node supplies the matching callback props.\n const definition = input as ContentScriptDefinition<Data>;\n\n this.definition = {\n ...definition,\n marker: this.resolveMarker(definition.marker),\n anchor: this.resolveAnchor(definition.anchor),\n mount: this.resolveMount(definition.mount),\n container: this.resolveContainer(definition.container),\n target: this.resolveTarget(definition.target),\n isolation: this.resolveIsolation(definition),\n render: this.resolveRender(definition.render),\n watch: this.resolveWatch(definition.watch),\n };\n }\n\n protected resolveMarker(marker: ContentScriptMarkerType | ContentScriptMarkerGetter): ContentScriptMarkerResolver {\n return async (options: ContentScriptOptions) => {\n if (typeof marker === \"function\") {\n marker = await marker(options);\n }\n\n if (!marker) {\n marker = ContentScriptMarker.Attribute;\n }\n\n if (typeof marker === \"string\") {\n switch (marker) {\n case ContentScriptMarker.Weak:\n return new WeakMarker();\n\n case ContentScriptMarker.Attribute:\n default:\n return new AttributeMarker();\n }\n }\n\n return marker;\n };\n }\n\n protected resolveAnchor(anchor?: ContentScriptAnchor | ContentScriptAnchorGetter): ContentScriptAnchorGetter {\n return createAnchorResolver(anchor);\n }\n\n protected resolveMount(mount?: ContentScriptMountFunction): ContentScriptMountFunction {\n return mount || createAppendMountHandler();\n }\n\n protected resolveContainer(\n container?: ContentScriptContainerTag | ContentScriptContainerOptions | ContentScriptContainerFactory<Data>\n ): ContentScriptContainerCreator<Data> {\n return createContainerResolver(container);\n }\n\n protected resolveTarget(target?: ContentScriptTarget<Data>): ContentScriptTargetCreator<Data> {\n return createTargetResolver(target);\n }\n\n protected resolveIsolation(definition: ContentScriptDefinition<Data>): ContentScriptIsolationOptions {\n const isolation = resolveContentScriptIsolation(definition.isolation, \"render\" in definition);\n\n if (definition.boundary !== undefined) {\n if (typeof definition.boundary !== \"function\") {\n throw new Error(\"Content script boundary must be a synchronous setup handler\");\n }\n\n if (isolation.type === \"none\") {\n throw new Error(\"Content script boundary requires Shadow DOM or an iframe\");\n }\n }\n\n if (\n definition.target !== undefined &&\n (isolation.type === \"none\" || isContentScriptFrameNavigation(isolation))\n ) {\n throw new Error(\"Content script target requires Shadow DOM or an iframe with local rendering\");\n }\n\n return isolation;\n }\n\n protected resolveRender(\n render?: ContentScriptRenderValue<Data> | ContentScriptRenderHandler<Data>\n ): true | ContentScriptRenderHandler<Data> | undefined {\n if (render === true || render === undefined) {\n return render;\n }\n\n throw new Error(\"Content script rendering requires a renderer adapter\");\n }\n\n protected resolveWatch(watch?: true | ContentScriptWatchStrategy): ContentScriptWatchStrategy {\n if (watch === undefined) {\n watch = createAwaitFirstStrategy();\n } else if (watch === true) {\n watch = createMutationObserverStrategy();\n }\n\n return withLocationTracking(watch);\n }\n\n public getContext(): ContentScriptContext {\n return this.context;\n }\n\n public async build(): Promise<void> {\n const destroying = this.destroy();\n const generation = this.generation;\n await destroying;\n\n if (generation !== this.generation) {\n return;\n }\n\n const {render, prepare, main, anchor, marker, container, boundary, target, watch, mount, ...options} =\n this.definition;\n\n await main?.(this.context, options);\n\n if (generation !== this.generation) {\n return;\n }\n\n if (\n render !== undefined ||\n prepare !== undefined ||\n isContentScriptFrameNavigation(this.definition.isolation)\n ) {\n const resolvedMarker = await marker(options);\n\n if (generation !== this.generation) {\n return;\n }\n\n this.marker = resolvedMarker;\n\n await this.requestProcessing(generation);\n\n if (generation !== this.generation) {\n return;\n }\n\n const onError = (error: unknown): void => {\n console.error(\"Content script processing on watch error\", error);\n };\n\n this.unwatch = watch(() => this.requestProcessing(generation, onError), this.context);\n }\n }\n\n public async destroy(): Promise<void> {\n this.generation++;\n this.cycle = undefined;\n\n this.unwatch?.();\n this.unwatch = undefined;\n\n try {\n this.context.clear();\n } finally {\n this.context.unwatch();\n this.marker.reset();\n }\n }\n\n protected getPrepareProps(anchor: Element): ContentScriptPrepareProps {\n const {\n anchor: _,\n marker,\n mount,\n watch,\n prepare,\n render,\n container,\n boundary,\n target,\n main,\n ...options\n } = this.definition;\n\n return {...options, anchor};\n }\n\n private requestProcessing(generation: number, onError?: (error: unknown) => void): Promise<void> {\n if (generation !== this.generation) {\n return Promise.resolve();\n }\n\n if (this.cycle?.generation === generation) {\n this.cycle.pending = true;\n\n return this.cycle.promise;\n }\n\n const cycle: ContentScriptCycle = {\n generation,\n pending: true,\n promise: Promise.resolve().then(() => this.drainProcessing(cycle)),\n };\n\n if (onError) {\n // One handler per cycle, not one suspended async callback per watch notification.\n cycle.promise = cycle.promise.catch(onError);\n }\n\n this.cycle = cycle;\n\n return cycle.promise;\n }\n\n private async drainProcessing(cycle: ContentScriptCycle): Promise<void> {\n try {\n while (cycle.pending && cycle.generation === this.generation) {\n cycle.pending = false;\n this.context.mount();\n\n if (cycle.generation !== this.generation) {\n return;\n }\n\n await this.processing(cycle.generation);\n }\n } finally {\n if (this.cycle === cycle) {\n this.cycle = undefined;\n }\n }\n }\n\n protected async processing(generation: number): Promise<void> {\n const anchor = await this.definition.anchor();\n\n if (generation !== this.generation) {\n return;\n }\n\n const anchors = this.marker\n .for(anchor)\n .unmarked()\n .filter(anchor => anchor.isConnected);\n\n const results = await Promise.allSettled(anchors.map(anchor => this.processAnchor(anchor, generation)));\n const errors = results.flatMap(result => (result.status === \"rejected\" ? [result.reason] : []));\n\n if (errors.length && generation === this.generation) {\n console.error(new AggregateError(errors, \"Content script anchor processing failed\"));\n }\n }\n\n protected async processAnchor(anchor: Element, generation: number): Promise<void> {\n const current = () => generation === this.generation && anchor.isConnected;\n const data = await this.definition.prepare?.(this.getPrepareProps(anchor));\n\n if (!current()) {\n return;\n }\n\n const assembly = await this.createNode(anchor, data);\n const node = new EventNode(assembly.node, this.emitter, assembly.renderer);\n\n if (!current()) {\n node.unmount();\n\n return;\n }\n\n // Add listeners can mount immediately, so connect the renderer before publishing the node.\n assembly.renderer?.setErrorHandler(error => this.handleRenderError(node, error, generation));\n this.context.add(node);\n\n if (generation !== this.generation) {\n return;\n }\n\n try {\n node.mount();\n\n if (!current() && !node.container?.isConnected) {\n this.context.remove(node);\n }\n } catch (error) {\n this.context.remove(node);\n throw error;\n }\n }\n\n private handleRenderError(node: ContentScriptNode, error: unknown, generation: number): void {\n if (generation !== this.generation) {\n return;\n }\n\n const errors = [error];\n\n try {\n this.context.remove(node);\n } catch (cause) {\n errors.push(cause);\n }\n\n console.error(new AggregateError(errors, \"Content script deferred mount failed\"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ScriptTargetProps } from "../../../types/content/index.js";
2
+ interface IsolationSetupOptions<Data, Isolation extends "shadow" | "iframe"> {
3
+ props: () => ContentScriptContainerProps<Data>;
4
+ container: () => Element | undefined;
5
+ boundary?: ContentScriptBoundaryHandler<Data, Isolation>;
6
+ target: (props: ContentScriptTargetProps<Data, Isolation>) => Element;
7
+ }
8
+ /** Applies user configuration; isolation nodes own DOM, cleanup timing, and recovery. */
9
+ export default class IsolationSetup<Data = unknown, Isolation extends "shadow" | "iframe" = "shadow" | "iframe"> {
10
+ private readonly options;
11
+ constructor(options: IsolationSetupOptions<Data, Isolation>);
12
+ setup(boundary: Exclude<ContentScriptBoundary<Isolation>, undefined>): ContentScriptBoundaryCleanup | undefined;
13
+ createTarget(boundary: Exclude<ContentScriptBoundary<Isolation>, undefined>, document: Document): Element;
14
+ private getProps;
15
+ }
16
+ export {};
@@ -0,0 +1,37 @@
1
+ class IsolationSetup {
2
+ constructor(options) {
3
+ this.options = options;
4
+ }
5
+ options;
6
+ setup(boundary) {
7
+ var _a, _b;
8
+ const props = this.getProps("boundary");
9
+ const cleanup = (_b = (_a = this.options).boundary) == null ? void 0 : _b.call(_a, { ...props, boundary });
10
+ if (cleanup !== void 0 && typeof cleanup !== "function") {
11
+ throw new Error("Content script boundary must return synchronously with a cleanup function or undefined");
12
+ }
13
+ if (cleanup) {
14
+ return () => {
15
+ try {
16
+ cleanup();
17
+ } catch (error) {
18
+ console.error("Content script boundary cleanup failed", error);
19
+ }
20
+ };
21
+ }
22
+ }
23
+ createTarget(boundary, document) {
24
+ return this.options.target({ ...this.getProps("target"), boundary, document });
25
+ }
26
+ getProps(stage) {
27
+ const container = this.options.container();
28
+ if (!container) {
29
+ throw new Error(`Content script ${stage} requires a mounted container`);
30
+ }
31
+ return { ...this.options.props(), container };
32
+ }
33
+ }
34
+ export {
35
+ IsolationSetup as default
36
+ };
37
+ //# sourceMappingURL=IsolationSetup.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/entry/content/lifecycle/IsolationSetup.ts"],"sourcesContent":["import type {\n ContentScriptBoundary,\n ContentScriptBoundaryCleanup,\n ContentScriptBoundaryHandler,\n ContentScriptContainerProps,\n ContentScriptTargetProps,\n} from \"@typing/content\";\n\ninterface IsolationSetupOptions<Data, Isolation extends \"shadow\" | \"iframe\"> {\n props: () => ContentScriptContainerProps<Data>;\n container: () => Element | undefined;\n boundary?: ContentScriptBoundaryHandler<Data, Isolation>;\n target: (props: ContentScriptTargetProps<Data, Isolation>) => Element;\n}\n\n/** Applies user configuration; isolation nodes own DOM, cleanup timing, and recovery. */\nexport default class IsolationSetup<Data = unknown, Isolation extends \"shadow\" | \"iframe\" = \"shadow\" | \"iframe\"> {\n public constructor(private readonly options: IsolationSetupOptions<Data, Isolation>) {}\n\n public setup(\n boundary: Exclude<ContentScriptBoundary<Isolation>, undefined>\n ): ContentScriptBoundaryCleanup | undefined {\n const props = this.getProps(\"boundary\");\n const cleanup = this.options.boundary?.({...props, boundary});\n\n if (cleanup !== undefined && typeof cleanup !== \"function\") {\n throw new Error(\"Content script boundary must return synchronously with a cleanup function or undefined\");\n }\n\n if (cleanup) {\n return () => {\n try {\n cleanup();\n } catch (error) {\n console.error(\"Content script boundary cleanup failed\", error);\n }\n };\n }\n }\n\n public createTarget(boundary: Exclude<ContentScriptBoundary<Isolation>, undefined>, document: Document): Element {\n return this.options.target({...this.getProps(\"target\"), boundary, document});\n }\n\n private getProps(stage: \"boundary\" | \"target\"): ContentScriptContainerProps<Data> & {container: Element} {\n const container = this.options.container();\n\n if (!container) {\n throw new Error(`Content script ${stage} requires a mounted container`);\n }\n\n return {...this.options.props(), container};\n }\n}\n"],"mappings":"AAgBA,MAAO,eAA0G;AAAA,EACtG,YAA6B,SAAiD;AAAjD;AAAA,EAAkD;AAAA,EAAlD;AAAA,EAE7B,MACH,UACwC;AArBhD;AAsBQ,UAAM,QAAQ,KAAK,SAAS,UAAU;AACtC,UAAM,WAAU,gBAAK,SAAQ,aAAb,4BAAwB,EAAC,GAAG,OAAO,SAAQ;AAE3D,QAAI,YAAY,UAAa,OAAO,YAAY,YAAY;AACxD,YAAM,IAAI,MAAM,wFAAwF;AAAA,IAC5G;AAEA,QAAI,SAAS;AACT,aAAO,MAAM;AACT,YAAI;AACA,kBAAQ;AAAA,QACZ,SAAS,OAAO;AACZ,kBAAQ,MAAM,0CAA0C,KAAK;AAAA,QACjE;AAAA,MACJ;AAAA,IACJ;AAAA,EACJ;AAAA,EAEO,aAAa,UAAgE,UAA6B;AAC7G,WAAO,KAAK,QAAQ,OAAO,EAAC,GAAG,KAAK,SAAS,QAAQ,GAAG,UAAU,SAAQ,CAAC;AAAA,EAC/E;AAAA,EAEQ,SAAS,OAAwF;AACrG,UAAM,YAAY,KAAK,QAAQ,UAAU;AAEzC,QAAI,CAAC,WAAW;AACZ,YAAM,IAAI,MAAM,kBAAkB,KAAK,+BAA+B;AAAA,IAC1E;AAEA,WAAO,EAAC,GAAG,KAAK,QAAQ,MAAM,GAAG,UAAS;AAAA,EAC9C;AACJ;","names":[]}
@@ -0,0 +1,11 @@
1
+ import Builder from "./Builder.js";
2
+ import type { ContentScriptIsolationAssembly, ContentScriptNodeAssembly, ContentScriptRenderLifecycle, ContentScriptRenderOptions } from "./types.js";
3
+ import { ContentScriptDefinition, ContentScriptIsolation, ContentScriptNode, ContentScriptPrepareResult, ContentScriptProps, ContentScriptRenderHandler } from "../../../types/content/index.js";
4
+ export default class MountBuilder<Data = unknown, Isolation extends `${ContentScriptIsolation}` = `${ContentScriptIsolation}`> extends Builder<Data, Isolation> {
5
+ constructor(definition: ContentScriptDefinition<Data, Isolation>);
6
+ protected getProps(node: ContentScriptNode, data: Data): ContentScriptProps<Data>;
7
+ protected createNode(anchor: Element, result: ContentScriptPrepareResult<Data> | undefined): Promise<ContentScriptNodeAssembly>;
8
+ protected createMountNode(anchor: Element, data: Data): Promise<ContentScriptNode>;
9
+ protected createIsolation(node: ContentScriptNode, data: Data): ContentScriptIsolationAssembly;
10
+ protected createRenderer(node: ContentScriptNode, render: ContentScriptRenderHandler<Data>, props: () => ContentScriptProps<Data>, options: ContentScriptRenderOptions): ContentScriptNode & ContentScriptRenderLifecycle;
11
+ }
@@ -0,0 +1,73 @@
1
+ import Builder from "./Builder.js";
2
+ import IsolationSetup from "./IsolationSetup.js";
3
+ import { FrameNode, MountNode, MarkerNode, ShadowNode, Node } from "./nodes/index.js";
4
+ import { isContentScriptFrameNavigation } from "./../../../shared/content/index.js";
5
+ import {
6
+ ContentScriptIsolation
7
+ } from "./../../../types/content/index.js";
8
+ class MountBuilder extends Builder {
9
+ constructor(definition) {
10
+ super(definition);
11
+ }
12
+ getProps(node, data) {
13
+ if (!node.container || !node.target) {
14
+ throw new Error("Content script render requires a container and target");
15
+ }
16
+ return {
17
+ ...this.getPrepareProps(node.anchor),
18
+ data,
19
+ container: node.container,
20
+ target: node.target,
21
+ boundary: node.boundary
22
+ };
23
+ }
24
+ async createNode(anchor, result) {
25
+ const navigation = isContentScriptFrameNavigation(this.definition.isolation);
26
+ const render = this.definition.render;
27
+ if (result === false || !navigation && (render === void 0 || render === true)) {
28
+ return { node: new MarkerNode(new Node(anchor), this.marker) };
29
+ }
30
+ const data = result;
31
+ const mountedNode = await this.createMountNode(anchor, data);
32
+ const { node, ready } = this.createIsolation(mountedNode, data);
33
+ if (navigation || typeof render !== "function") {
34
+ return { node };
35
+ }
36
+ const renderer = this.createRenderer(node, render, () => this.getProps(node, data), { ready });
37
+ return { node: renderer, renderer };
38
+ }
39
+ async createMountNode(anchor, data) {
40
+ const marker = this.marker;
41
+ const container = await this.definition.container({ ...this.getPrepareProps(anchor), data });
42
+ return new MountNode(
43
+ new MarkerNode(new Node(anchor, container), marker),
44
+ this.context.containers,
45
+ this.definition.mount
46
+ );
47
+ }
48
+ createIsolation(node, data) {
49
+ const options = this.definition.isolation;
50
+ if (options.type === ContentScriptIsolation.None) {
51
+ return { node };
52
+ }
53
+ const setup = new IsolationSetup({
54
+ props: () => ({ ...this.getPrepareProps(node.anchor), data }),
55
+ container: () => node.container,
56
+ boundary: this.definition.boundary,
57
+ target: this.definition.target
58
+ });
59
+ if (options.type === ContentScriptIsolation.Shadow) {
60
+ const shadow = new ShadowNode(node, options, setup);
61
+ return { node: shadow, ready: () => shadow.ready() };
62
+ }
63
+ const frame = new FrameNode(node, options, () => this.context.mount(), setup);
64
+ return { node: frame, ready: () => frame.ready() };
65
+ }
66
+ createRenderer(node, render, props, options) {
67
+ throw new Error("Content script rendering requires a renderer adapter");
68
+ }
69
+ }
70
+ export {
71
+ MountBuilder as default
72
+ };
73
+ //# sourceMappingURL=MountBuilder.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/entry/content/lifecycle/MountBuilder.ts"],"sourcesContent":["import Builder from \"./Builder\";\nimport IsolationSetup from \"./IsolationSetup\";\nimport {FrameNode, MountNode, MarkerNode, ShadowNode, Node} from \"./nodes\";\n\nimport {isContentScriptFrameNavigation} from \"@shared/content\";\n\nimport type {\n ContentScriptIsolationAssembly,\n ContentScriptNodeAssembly,\n ContentScriptRenderLifecycle,\n ContentScriptRenderOptions,\n} from \"./types\";\n\nimport {\n ContentScriptDefinition,\n ContentScriptIsolation,\n ContentScriptNode,\n ContentScriptPrepareResult,\n ContentScriptProps,\n ContentScriptRenderHandler,\n} from \"@typing/content\";\n\nexport default class MountBuilder<\n Data = unknown,\n Isolation extends `${ContentScriptIsolation}` = `${ContentScriptIsolation}`,\n> extends Builder<Data, Isolation> {\n public constructor(definition: ContentScriptDefinition<Data, Isolation>) {\n super(definition);\n }\n\n protected getProps(node: ContentScriptNode, data: Data): ContentScriptProps<Data> {\n if (!node.container || !node.target) {\n throw new Error(\"Content script render requires a container and target\");\n }\n\n return {\n ...this.getPrepareProps(node.anchor),\n data,\n container: node.container,\n target: node.target,\n boundary: node.boundary,\n };\n }\n\n protected async createNode(\n anchor: Element,\n result: ContentScriptPrepareResult<Data> | undefined\n ): Promise<ContentScriptNodeAssembly> {\n const navigation = isContentScriptFrameNavigation(this.definition.isolation);\n const render = this.definition.render;\n\n if (result === false || (!navigation && (render === undefined || render === true))) {\n return {node: new MarkerNode(new Node(anchor), this.marker)};\n }\n\n const data = result as Data;\n const mountedNode = await this.createMountNode(anchor, data);\n const {node, ready} = this.createIsolation(mountedNode, data);\n\n if (navigation || typeof render !== \"function\") {\n return {node};\n }\n\n const renderer = this.createRenderer(node, render, () => this.getProps(node, data), {ready});\n\n return {node: renderer, renderer};\n }\n\n protected async createMountNode(anchor: Element, data: Data): Promise<ContentScriptNode> {\n const marker = this.marker;\n const container = await this.definition.container({...this.getPrepareProps(anchor), data});\n\n return new MountNode(\n new MarkerNode(new Node(anchor, container), marker),\n this.context.containers,\n this.definition.mount\n );\n }\n\n protected createIsolation(node: ContentScriptNode, data: Data): ContentScriptIsolationAssembly {\n const options = this.definition.isolation;\n\n if (options.type === ContentScriptIsolation.None) {\n return {node};\n }\n\n const setup = new IsolationSetup({\n props: () => ({...this.getPrepareProps(node.anchor), data}),\n container: () => node.container,\n boundary: this.definition.boundary,\n target: this.definition.target,\n });\n\n if (options.type === ContentScriptIsolation.Shadow) {\n const shadow = new ShadowNode(node, options, setup);\n\n return {node: shadow, ready: () => shadow.ready()};\n }\n\n const frame = new FrameNode(node, options, () => this.context.mount(), setup);\n\n return {node: frame, ready: () => frame.ready()};\n }\n\n protected createRenderer(\n node: ContentScriptNode,\n render: ContentScriptRenderHandler<Data>,\n props: () => ContentScriptProps<Data>,\n options: ContentScriptRenderOptions\n ): ContentScriptNode & ContentScriptRenderLifecycle {\n throw new Error(\"Content script rendering requires a renderer adapter\");\n }\n}\n"],"mappings":"AAAA,OAAO,aAAa;AACpB,OAAO,oBAAoB;AAC3B,SAAQ,WAAW,WAAW,YAAY,YAAY,YAAW;AAEjE,SAAQ,sCAAqC;AAS7C;AAAA,EAEI;AAAA,OAKG;AAEP,MAAO,qBAGG,QAAyB;AAAA,EACxB,YAAY,YAAsD;AACrE,UAAM,UAAU;AAAA,EACpB;AAA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BAAgB,MAAyB,MAA4C;AAC3F,UAAM,UAAU,KAAK,WAAW;AAEhC,QAAI,QAAQ,SAAS,uBAAuB,MAAM;AAC9C,aAAO,EAAC,KAAI;AAAA,IAChB;AAEA,UAAM,QAAQ,IAAI,eAAe;AAAA,MAC7B,OAAO,OAAO,EAAC,GAAG,KAAK,gBAAgB,KAAK,MAAM,GAAG,KAAI;AAAA,MACzD,WAAW,MAAM,KAAK;AAAA,MACtB,UAAU,KAAK,WAAW;AAAA,MAC1B,QAAQ,KAAK,WAAW;AAAA,IAC5B,CAAC;AAED,QAAI,QAAQ,SAAS,uBAAuB,QAAQ;AAChD,YAAM,SAAS,IAAI,WAAW,MAAM,SAAS,KAAK;AAElD,aAAO,EAAC,MAAM,QAAQ,OAAO,MAAM,OAAO,MAAM,EAAC;AAAA,IACrD;AAEA,UAAM,QAAQ,IAAI,UAAU,MAAM,SAAS,MAAM,KAAK,QAAQ,MAAM,GAAG,KAAK;AAE5E,WAAO,EAAC,MAAM,OAAO,OAAO,MAAM,MAAM,MAAM,EAAC;AAAA,EACnD;AAAA,EAEU,eACN,MACA,QACA,OACA,SACgD;AAChD,UAAM,IAAI,MAAM,sDAAsD;AAAA,EAC1E;AACJ;","names":[]}
@@ -0,0 +1,7 @@
1
+ /** Tracks independent mount registrations without adding ownership to lifecycle nodes. */
2
+ export default class ContainerRegistry {
3
+ private readonly registrations;
4
+ register(container: Element, anchor: Element): () => void;
5
+ owns(target: Node): boolean;
6
+ clear(): void;
7
+ }
@@ -0,0 +1,45 @@
1
+ class ContainerRegistry {
2
+ registrations = /* @__PURE__ */ new Map();
3
+ register(container, anchor) {
4
+ let registrations = this.registrations.get(container);
5
+ if (!registrations) {
6
+ registrations = /* @__PURE__ */ new Set();
7
+ this.registrations.set(container, registrations);
8
+ }
9
+ const registration = { anchor };
10
+ const current = registrations;
11
+ current.add(registration);
12
+ return () => {
13
+ if (!current.delete(registration)) {
14
+ return;
15
+ }
16
+ if (current.size === 0 && this.registrations.get(container) === current) {
17
+ this.registrations.delete(container);
18
+ }
19
+ };
20
+ }
21
+ owns(target) {
22
+ var _a, _b;
23
+ if (this.registrations.size === 0) {
24
+ return false;
25
+ }
26
+ let current = target;
27
+ while (current) {
28
+ const registrations = this.registrations.get(current);
29
+ const container = current;
30
+ if (registrations && !Array.from(registrations).some(({ anchor }) => container.contains(anchor))) {
31
+ return true;
32
+ }
33
+ const shadowRoot = ((_b = (_a = current.ownerDocument) == null ? void 0 : _a.defaultView) == null ? void 0 : _b.ShadowRoot) ?? ShadowRoot;
34
+ current = current.parentNode ?? (current instanceof shadowRoot ? current.host : null);
35
+ }
36
+ return false;
37
+ }
38
+ clear() {
39
+ this.registrations.clear();
40
+ }
41
+ }
42
+ export {
43
+ ContainerRegistry as default
44
+ };
45
+ //# sourceMappingURL=ContainerRegistry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../src/entry/content/lifecycle/context/ContainerRegistry.ts"],"sourcesContent":["/** Tracks independent mount registrations without adding ownership to lifecycle nodes. */\nexport default class ContainerRegistry {\n private readonly registrations = new Map<Node, Set<{anchor: Element}>>();\n\n public register(container: Element, anchor: Element): () => void {\n let registrations = this.registrations.get(container);\n\n if (!registrations) {\n registrations = new Set();\n this.registrations.set(container, registrations);\n }\n\n const registration = {anchor};\n const current = registrations;\n current.add(registration);\n\n return () => {\n if (!current.delete(registration)) {\n return;\n }\n\n if (current.size === 0 && this.registrations.get(container) === current) {\n this.registrations.delete(container);\n }\n };\n }\n\n public owns(target: Node): boolean {\n if (this.registrations.size === 0) {\n return false;\n }\n\n let current: Node | null = target;\n\n while (current) {\n const registrations = this.registrations.get(current);\n const container = current;\n\n if (registrations && !Array.from(registrations).some(({anchor}) => container.contains(anchor))) {\n return true;\n }\n\n const shadowRoot: typeof ShadowRoot = current.ownerDocument?.defaultView?.ShadowRoot ?? ShadowRoot;\n current = current.parentNode ?? (current instanceof shadowRoot ? current.host : null);\n }\n\n return false;\n }\n\n public clear(): void {\n this.registrations.clear();\n }\n}\n"],"mappings":"AACA,MAAO,kBAAgC;AAAA,EAClB,gBAAgB,oBAAI,IAAkC;AAAA,EAEhE,SAAS,WAAoB,QAA6B;AAC7D,QAAI,gBAAgB,KAAK,cAAc,IAAI,SAAS;AAEpD,QAAI,CAAC,eAAe;AAChB,sBAAgB,oBAAI,IAAI;AACxB,WAAK,cAAc,IAAI,WAAW,aAAa;AAAA,IACnD;AAEA,UAAM,eAAe,EAAC,OAAM;AAC5B,UAAM,UAAU;AAChB,YAAQ,IAAI,YAAY;AAExB,WAAO,MAAM;AACT,UAAI,CAAC,QAAQ,OAAO,YAAY,GAAG;AAC/B;AAAA,MACJ;AAEA,UAAI,QAAQ,SAAS,KAAK,KAAK,cAAc,IAAI,SAAS,MAAM,SAAS;AACrE,aAAK,cAAc,OAAO,SAAS;AAAA,MACvC;AAAA,IACJ;AAAA,EACJ;AAAA,EAEO,KAAK,QAAuB;AA3BvC;AA4BQ,QAAI,KAAK,cAAc,SAAS,GAAG;AAC/B,aAAO;AAAA,IACX;AAEA,QAAI,UAAuB;AAE3B,WAAO,SAAS;AACZ,YAAM,gBAAgB,KAAK,cAAc,IAAI,OAAO;AACpD,YAAM,YAAY;AAElB,UAAI,iBAAiB,CAAC,MAAM,KAAK,aAAa,EAAE,KAAK,CAAC,EAAC,OAAM,MAAM,UAAU,SAAS,MAAM,CAAC,GAAG;AAC5F,eAAO;AAAA,MACX;AAEA,YAAM,eAAgC,mBAAQ,kBAAR,mBAAuB,gBAAvB,mBAAoC,eAAc;AACxF,gBAAU,QAAQ,eAAe,mBAAmB,aAAa,QAAQ,OAAO;AAAA,IACpF;AAEA,WAAO;AAAA,EACX;AAAA,EAEO,QAAc;AACjB,SAAK,cAAc,MAAM;AAAA,EAC7B;AACJ;","names":[]}
@@ -0,0 +1,17 @@
1
+ import type ContainerRegistry from "./ContainerRegistry.js";
2
+ import { ContentScriptNode, ContentScriptContext, ContentScriptEventCallback, ContentScriptEventEmitter } from "../../../../types/content/index.js";
3
+ export default class Context implements ContentScriptContext {
4
+ protected readonly emitter: ContentScriptEventEmitter;
5
+ private readonly registry;
6
+ protected readonly collection: Set<ContentScriptNode>;
7
+ private unmounting;
8
+ constructor(emitter: ContentScriptEventEmitter, registry: ContainerRegistry);
9
+ get nodes(): ReadonlySet<ContentScriptNode>;
10
+ owns(target: Node): boolean;
11
+ mount(): void;
12
+ unmount(): void;
13
+ remove(node: ContentScriptNode): void;
14
+ clear(): void;
15
+ watch(callback: ContentScriptEventCallback): () => void;
16
+ unwatch(): void;
17
+ }
@@ -0,0 +1,88 @@
1
+ class Context {
2
+ constructor(emitter, registry) {
3
+ this.emitter = emitter;
4
+ this.registry = registry;
5
+ }
6
+ emitter;
7
+ registry;
8
+ collection = /* @__PURE__ */ new Set();
9
+ unmounting = false;
10
+ get nodes() {
11
+ return this.collection;
12
+ }
13
+ owns(target) {
14
+ return this.registry.owns(target);
15
+ }
16
+ mount() {
17
+ if (this.unmounting) {
18
+ return;
19
+ }
20
+ for (const node of this.collection) {
21
+ if (!node.anchor.isConnected) {
22
+ node.unmount();
23
+ this.collection.delete(node);
24
+ this.emitter.emitRemove(node);
25
+ continue;
26
+ }
27
+ node.mount();
28
+ }
29
+ }
30
+ unmount() {
31
+ const unmounting = this.unmounting;
32
+ this.unmounting = true;
33
+ try {
34
+ for (const node of this.collection) {
35
+ node.unmount();
36
+ if (!node.anchor.isConnected) {
37
+ this.collection.delete(node);
38
+ this.emitter.emitRemove(node);
39
+ }
40
+ }
41
+ } finally {
42
+ this.unmounting = unmounting;
43
+ }
44
+ }
45
+ remove(node) {
46
+ if (!this.collection.delete(node)) {
47
+ return;
48
+ }
49
+ try {
50
+ node.unmount();
51
+ } finally {
52
+ this.emitter.emitRemove(node);
53
+ }
54
+ }
55
+ clear() {
56
+ const unmounting = this.unmounting;
57
+ this.unmounting = true;
58
+ const errors = [];
59
+ try {
60
+ for (const node of this.collection) {
61
+ try {
62
+ this.remove(node);
63
+ } catch (error) {
64
+ errors.push(error);
65
+ }
66
+ }
67
+ } finally {
68
+ this.registry.clear();
69
+ this.unmounting = unmounting;
70
+ }
71
+ if (errors.length > 0) {
72
+ throw new AggregateError(errors, "Content script context cleanup failed");
73
+ }
74
+ }
75
+ watch(callback) {
76
+ this.emitter.on(callback);
77
+ return () => {
78
+ this.emitter.off(callback);
79
+ };
80
+ }
81
+ unwatch() {
82
+ this.emitter.removeAllListeners();
83
+ }
84
+ }
85
+ export {
86
+ Context as default
87
+ };
88
+ //# sourceMappingURL=Context.js.map