@tokenoftrust/storefront-runner 7.3.2 → 7.5.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 (415) hide show
  1. package/agency-kit/tools/lib/catalog-model/files.mjs +11 -4
  2. package/agency-kit/tools/lib/catalog-model/model.mjs +5 -1
  3. package/agency-kit/tools/lib/redirect-shadows.mjs +261 -0
  4. package/apps/storefront/astro.config.mjs +8 -2
  5. package/apps/storefront/package.json +1 -2
  6. package/apps/storefront/src/components/catalog/storefront/ProductCard.astro +20 -6
  7. package/apps/storefront/src/components/catalog/storefront/islands/ImageGallery.tsx +17 -6
  8. package/apps/storefront/src/components/compliance/storefront/islands/CheckoutComplianceGate.tsx +1 -32
  9. package/apps/storefront/src/config/compliance/rulesets.ts +1 -1
  10. package/apps/storefront/src/layouts/Layout.astro +17 -0
  11. package/apps/storefront/src/lib/access/auth/agentRoles.ts +20 -0
  12. package/apps/storefront/src/lib/access/auth/agentSessionGate.ts +32 -8
  13. package/apps/storefront/src/lib/access/auth/brokerAssertion.ts +16 -2
  14. package/apps/storefront/src/lib/access/auth/contactReaderAuthority.ts +39 -0
  15. package/apps/storefront/src/lib/access/auth/loginGate.ts +15 -17
  16. package/apps/storefront/src/lib/access/dashboard/staffAdmission.ts +5 -0
  17. package/apps/storefront/src/lib/access/dashboard/tenantSelection.ts +2 -0
  18. package/apps/storefront/src/lib/access/shared/capability.ts +14 -6
  19. package/apps/storefront/src/lib/access/shared/generated/capabilityCatalog.generated.ts +161 -0
  20. package/apps/storefront/src/lib/activity/activityScope.ts +36 -0
  21. package/apps/storefront/src/lib/activity/recordActivity.ts +23 -1
  22. package/apps/storefront/src/lib/activity/serverFanOut.ts +31 -0
  23. package/apps/storefront/src/lib/activity/store.ts +9 -3
  24. package/apps/storefront/src/lib/checkout/commerce/cardCartForm.ts +2 -0
  25. package/apps/storefront/src/lib/checkout/commerce/cartSession.ts +109 -12
  26. package/apps/storefront/src/lib/checkout/commerce/checkoutHandoffRoute.ts +53 -25
  27. package/apps/storefront/src/lib/checkout/commerce/finalCartAuthorization.ts +48 -6
  28. package/apps/storefront/src/lib/checkout/proposal/cartProposal.ts +388 -0
  29. package/apps/storefront/src/lib/checkout/proposal/listMatcher.ts +149 -0
  30. package/apps/storefront/src/lib/checkout/proposal/proposalRoutes.ts +447 -0
  31. package/apps/storefront/src/lib/checkout/proposal/reviewHtml.ts +100 -0
  32. package/apps/storefront/src/lib/compliance/browser/checkoutVerificationFlow.ts +26 -2
  33. package/apps/storefront/src/lib/content/shared/redirects.ts +21 -4
  34. package/apps/storefront/src/lib/publication/shared/edgeCache.ts +5 -2
  35. package/apps/storefront/src/lib/publication/shared/previewAnnotations/renderDecorator.ts +15 -8
  36. package/apps/storefront/src/lib/publication/shared/runtimeEnv.ts +1 -1
  37. package/apps/storefront/src/middleware/controlPlane.ts +15 -1
  38. package/apps/storefront/src/middleware/index.ts +7 -3
  39. package/apps/storefront/src/middleware/renderChain.ts +46 -33
  40. package/apps/storefront/src/pages/api/cart-proposal/confirm.ts +12 -0
  41. package/apps/storefront/src/pages/api/cart-proposal/review.ts +26 -0
  42. package/apps/storefront/src/pages/api/commerce/final-cart-authorization.ts +29 -6
  43. package/apps/storefront/src/pages/api/compliance/preflight.ts +25 -1
  44. package/apps/storefront/src/pages/products/[handle].astro +2 -15
  45. package/apps/storefront/tsconfig.astro.json +11 -0
  46. package/package.json +1 -1
  47. package/packages/public-runtime/src/activity/README.md +12 -0
  48. package/packages/public-runtime/src/activity/catalog.ts +7 -0
  49. package/packages/public-runtime/src/activity/event.ts +19 -0
  50. package/packages/public-runtime/src/activity/redaction.ts +31 -2
  51. package/packages/public-runtime/src/catalog-files.ts +3 -2
  52. package/packages/public-runtime/src/checkout-orders.ts +18 -19
  53. package/packages/public-runtime/src/checkout.ts +70 -0
  54. package/packages/public-runtime/src/compliance/evaluate.ts +60 -1
  55. package/packages/public-runtime/src/compliance/index.ts +1 -1
  56. package/packages/public-runtime/src/compliance/pact-report.ts +184 -3
  57. package/packages/public-runtime/src/compliance/profile.ts +268 -20
  58. package/packages/public-runtime/src/compliance/ruleset.ts +42 -0
  59. package/packages/public-runtime/src/customization-runtime.ts +1 -1
  60. package/packages/public-runtime/src/product.ts +9 -1
  61. package/packages/public-runtime/src/publication-content-redirects.ts +16 -3
  62. package/packages/public-runtime/tests/fixtures/compliance-decisions.golden.json +252 -52
  63. package/pnpm-lock.runner.yaml +0 -15
  64. package/scripts/tenant/materialize-tenant-content.mjs +3 -0
  65. package/scripts/tenant/validate.mjs +128 -0
  66. package/apps/storefront/dev-plugins/dev-publish.mjs +0 -55
  67. package/apps/storefront/drizzle.config.apps.ts +0 -13
  68. package/apps/storefront/integrations/preview-annotations-client-bundle.mjs +0 -80
  69. package/apps/storefront/migrations-apps/0000_fast_millenium_guard.sql +0 -129
  70. package/apps/storefront/migrations-apps/0001_woozy_lyja.sql +0 -22
  71. package/apps/storefront/migrations-apps/0002_good_switch.sql +0 -26
  72. package/apps/storefront/migrations-apps/0003_mute_marauders.sql +0 -12
  73. package/apps/storefront/migrations-apps/0004_deep_morph.sql +0 -36
  74. package/apps/storefront/migrations-apps/0005_common_mystique.sql +0 -23
  75. package/apps/storefront/migrations-apps/0006_broad_microchip.sql +0 -16
  76. package/apps/storefront/migrations-apps/0007_brave_outlaw_kid.sql +0 -15
  77. package/apps/storefront/migrations-apps/0008_blue_dazzler.sql +0 -11
  78. package/apps/storefront/migrations-apps/0009_bored_shinobi_shaw.sql +0 -15
  79. package/apps/storefront/migrations-apps/0010_ws4_verified_provider_measurement.sql +0 -35
  80. package/apps/storefront/migrations-apps/0011_dt_tracking_tenant_databases.sql +0 -23
  81. package/apps/storefront/migrations-apps/0012_test_destinations.sql +0 -29
  82. package/apps/storefront/migrations-apps/0013_publication_space_editorial.sql +0 -64
  83. package/apps/storefront/migrations-apps/0014_retire_candidate_ledger.sql +0 -12
  84. package/apps/storefront/migrations-apps/0015_merchant_calculation_settings.sql +0 -31
  85. package/apps/storefront/migrations-apps/0016_scrappy_commerce_contract.sql +0 -166
  86. package/apps/storefront/migrations-apps/0017_commerce_durable_projection.sql +0 -28
  87. package/apps/storefront/migrations-apps/0018_commerce_provider_cart_identity.sql +0 -13
  88. package/apps/storefront/migrations-apps/0019_commerce_source_authority.sql +0 -23
  89. package/apps/storefront/migrations-apps/0020_contact_messages.sql +0 -18
  90. package/apps/storefront/migrations-apps/0021_contact_vault.sql +0 -166
  91. package/apps/storefront/migrations-apps/0022_contact_vault_fields.sql +0 -342
  92. package/apps/storefront/migrations-apps/0023_principal_grant_contacts.sql +0 -15
  93. package/apps/storefront/migrations-apps/0024_order_contact_erasure_state.sql +0 -22
  94. package/apps/storefront/migrations-apps/0025_shipment_audit_order_lookup.sql +0 -2
  95. package/apps/storefront/migrations-apps/0026_fulfillment_assignment.sql +0 -44
  96. package/apps/storefront/migrations-apps/0027_app_contact_authority.sql +0 -70
  97. package/apps/storefront/migrations-apps/0028_app_jwk_and_candidates.sql +0 -133
  98. package/apps/storefront/migrations-apps/0029_inventory_locations_wms.sql +0 -38
  99. package/apps/storefront/migrations-apps/0030_assignment_split_shipments.sql +0 -149
  100. package/apps/storefront/migrations-apps/meta/0000_snapshot.json +0 -843
  101. package/apps/storefront/migrations-apps/meta/0001_snapshot.json +0 -990
  102. package/apps/storefront/migrations-apps/meta/0002_snapshot.json +0 -1160
  103. package/apps/storefront/migrations-apps/meta/0003_snapshot.json +0 -1235
  104. package/apps/storefront/migrations-apps/meta/0004_snapshot.json +0 -1474
  105. package/apps/storefront/migrations-apps/meta/0005_snapshot.json +0 -1617
  106. package/apps/storefront/migrations-apps/meta/0006_snapshot.json +0 -1716
  107. package/apps/storefront/migrations-apps/meta/0007_snapshot.json +0 -1812
  108. package/apps/storefront/migrations-apps/meta/0008_snapshot.json +0 -1881
  109. package/apps/storefront/migrations-apps/meta/0009_snapshot.json +0 -1979
  110. package/apps/storefront/migrations-apps/meta/_journal.json +0 -76
  111. package/apps/storefront/perf/README.md +0 -64
  112. package/apps/storefront/perf/assert-budgets.ts +0 -159
  113. package/apps/storefront/platform-reconcile-tenants.json +0 -3
  114. package/apps/storefront/playwright.config.ts +0 -23
  115. package/apps/storefront/public/js/dashboard-access-banner.js +0 -53
  116. package/apps/storefront/public/js/dashboard-apps.js +0 -183
  117. package/apps/storefront/public/js/dashboard-contact-capture.js +0 -52
  118. package/apps/storefront/public/js/dashboard-delegate.js +0 -167
  119. package/apps/storefront/public/js/dashboard-team.js +0 -356
  120. package/apps/storefront/public/js/dashboard-vendor-search.js +0 -115
  121. package/apps/storefront/src/components/content/storefront/AsyncStylesheet.astro +0 -26
  122. package/apps/storefront/src/components/integrations/storefront/WidgetFrame.astro +0 -34
  123. package/apps/storefront/src/config/adminTenantLookup.ts +0 -35
  124. package/apps/storefront/src/config/evidenceTenantRoster.ts +0 -25
  125. package/apps/storefront/src/config/staffProvisionProjection.ts +0 -24
  126. package/apps/storefront/src/config/storeName.ts +0 -34
  127. package/apps/storefront/src/lib/access/admin/README.md +0 -122
  128. package/apps/storefront/src/lib/access/admin/adminShell.ts +0 -281
  129. package/apps/storefront/src/lib/access/admin/envelope.ts +0 -9
  130. package/apps/storefront/src/lib/access/admin/viewmodels/settings.ts +0 -64
  131. package/apps/storefront/src/lib/access/auth/adminApiGuard.ts +0 -66
  132. package/apps/storefront/src/lib/access/auth/adminEntry.ts +0 -126
  133. package/apps/storefront/src/lib/access/auth/mcpClientAssertion.ts +0 -217
  134. package/apps/storefront/src/lib/access/auth/operatorSession.ts +0 -120
  135. package/apps/storefront/src/lib/access/dashboard/agentStoreEntry.ts +0 -253
  136. package/apps/storefront/src/lib/access/dashboard/delegateGate.ts +0 -130
  137. package/apps/storefront/src/lib/access/dashboard/staffStoreEntry.ts +0 -153
  138. package/apps/storefront/src/lib/access/dashboard/staffVendorAccess.ts +0 -474
  139. package/apps/storefront/src/lib/access/dashboard/vendorQuery.ts +0 -61
  140. package/apps/storefront/src/lib/access/fixtures/settings.ts +0 -67
  141. package/apps/storefront/src/lib/access/fixtures/tenants.ts +0 -29
  142. package/apps/storefront/src/lib/access/notifications/magicLinkInviteEmail.ts +0 -62
  143. package/apps/storefront/src/lib/access/shared/grantContactLookup.ts +0 -97
  144. package/apps/storefront/src/lib/access/shared/principalGrants.ts +0 -775
  145. package/apps/storefront/src/lib/activity/alerts.ts +0 -426
  146. package/apps/storefront/src/lib/activity/candidateSubmitLease.ts +0 -87
  147. package/apps/storefront/src/lib/activity/changeActorAttribution.ts +0 -181
  148. package/apps/storefront/src/lib/activity/evidence/evidenceReference.ts +0 -32
  149. package/apps/storefront/src/lib/activity/fixtures/evidence.ts +0 -99
  150. package/apps/storefront/src/lib/activity/query.ts +0 -403
  151. package/apps/storefront/src/lib/activity/uiActor.ts +0 -152
  152. package/apps/storefront/src/lib/admin/services/mock/index.ts +0 -12
  153. package/apps/storefront/src/lib/assets/addons/catalog.ts +0 -60
  154. package/apps/storefront/src/lib/assets/addons/storeEntitlements.ts +0 -260
  155. package/apps/storefront/src/lib/assets/durableAssetsRoute.ts +0 -65
  156. package/apps/storefront/src/lib/assets/durableR2.ts +0 -473
  157. package/apps/storefront/src/lib/assets/durableR2Bindings.ts +0 -33
  158. package/apps/storefront/src/lib/automation/admin/viewmodels/aiWorkflows.ts +0 -65
  159. package/apps/storefront/src/lib/automation/ai/approvalMode.ts +0 -20
  160. package/apps/storefront/src/lib/automation/ai/askEnvelope.ts +0 -47
  161. package/apps/storefront/src/lib/automation/ai/audit.ts +0 -12
  162. package/apps/storefront/src/lib/automation/ai/operationalRuns.ts +0 -155
  163. package/apps/storefront/src/lib/automation/ai/recommendation.ts +0 -20
  164. package/apps/storefront/src/lib/automation/fixtures/aiWorkflows.ts +0 -59
  165. package/apps/storefront/src/lib/catalog/admin/catalogSettingsClient.ts +0 -250
  166. package/apps/storefront/src/lib/catalog/admin/catalogSettingsFields.ts +0 -134
  167. package/apps/storefront/src/lib/catalog/admin/catalogSettingsPreview.ts +0 -37
  168. package/apps/storefront/src/lib/catalog/admin/catalogSettingsPricingView.ts +0 -39
  169. package/apps/storefront/src/lib/catalog/admin/catalogSettingsRuleView.ts +0 -44
  170. package/apps/storefront/src/lib/catalog/admin/catalogSettingsSkuView.ts +0 -21
  171. package/apps/storefront/src/lib/catalog/admin/catalogSettingsState.ts +0 -132
  172. package/apps/storefront/src/lib/catalog/admin/productSetupPhoto.ts +0 -23
  173. package/apps/storefront/src/lib/catalog/admin/productsTabClient.ts +0 -193
  174. package/apps/storefront/src/lib/catalog/admin/services/catalogProducts.ts +0 -32
  175. package/apps/storefront/src/lib/catalog/admin/viewmodels/catalogProducts.ts +0 -164
  176. package/apps/storefront/src/lib/catalog/admin/viewmodels/products.ts +0 -267
  177. package/apps/storefront/src/lib/catalog/fixtures/products.ts +0 -105
  178. package/apps/storefront/src/lib/catalog/tot/syncState.ts +0 -111
  179. package/apps/storefront/src/lib/checkout/admin/checkoutStyleInput.ts +0 -172
  180. package/apps/storefront/src/lib/checkout/admin/checkoutStyleTarget.ts +0 -65
  181. package/apps/storefront/src/lib/checkout/browser/checkoutExciseForm.ts +0 -152
  182. package/apps/storefront/src/lib/checkout/browser/checkoutRequirementsForm.ts +0 -72
  183. package/apps/storefront/src/lib/checkout/browser/checkoutStyleForm.ts +0 -110
  184. package/apps/storefront/src/lib/checkout/browser/settingDraftActions.ts +0 -367
  185. package/apps/storefront/src/lib/checkout/commerce/checkoutSettings.ts +0 -246
  186. package/apps/storefront/src/lib/checkout/fixtures/checkoutSettings.ts +0 -77
  187. package/apps/storefront/src/lib/content/blog/markdown.ts +0 -174
  188. package/apps/storefront/src/lib/content/chrome/examples/tokenoftrust.chrome-assignments.example.json +0 -6
  189. package/apps/storefront/src/lib/content/chrome/examples/tokenoftrust.chrome.example.json +0 -79
  190. package/apps/storefront/src/lib/content/index.ts +0 -27
  191. package/apps/storefront/src/lib/content/the-build/readingTime.ts +0 -35
  192. package/apps/storefront/src/lib/content/the-build/toc.ts +0 -95
  193. package/apps/storefront/src/lib/customers/admin/viewmodels/customers.ts +0 -56
  194. package/apps/storefront/src/lib/customers/contactVault/blindIndex.ts +0 -28
  195. package/apps/storefront/src/lib/customers/contactVault/contactAudit.ts +0 -149
  196. package/apps/storefront/src/lib/customers/contactVault/dataKeys.ts +0 -283
  197. package/apps/storefront/src/lib/customers/contactVault/fieldEnvelope.ts +0 -88
  198. package/apps/storefront/src/lib/customers/contactVault/isolateMetrics.ts +0 -37
  199. package/apps/storefront/src/lib/customers/contactVault/kms.ts +0 -292
  200. package/apps/storefront/src/lib/customers/contactVault/retention.ts +0 -302
  201. package/apps/storefront/src/lib/customers/contactVault/retentionPolicy.ts +0 -290
  202. package/apps/storefront/src/lib/customers/contactVault/zip3.ts +0 -24
  203. package/apps/storefront/src/lib/customers/fixtures/customers.ts +0 -86
  204. package/apps/storefront/src/lib/developer-experience/admin/memoizeByEnvelope.ts +0 -27
  205. package/apps/storefront/src/lib/developer-experience/admin/seed.ts +0 -54
  206. package/apps/storefront/src/lib/developer-experience/dev/activityIngestToken.ts +0 -85
  207. package/apps/storefront/src/lib/developer-experience/dev/activityStore.ts +0 -82
  208. package/apps/storefront/src/lib/developer-experience/dev/agentGrantAttestation.ts +0 -74
  209. package/apps/storefront/src/lib/developer-experience/dev/ai-widget-client.js +0 -308
  210. package/apps/storefront/src/lib/developer-experience/dev/apiBase.ts +0 -17
  211. package/apps/storefront/src/lib/developer-experience/dev/cliSignInCode.ts +0 -124
  212. package/apps/storefront/src/lib/developer-experience/dev/cockpit/ask.ts +0 -49
  213. package/apps/storefront/src/lib/developer-experience/dev/cockpit/clickToSource.ts +0 -71
  214. package/apps/storefront/src/lib/developer-experience/dev/cockpit/copyCommand.ts +0 -227
  215. package/apps/storefront/src/lib/developer-experience/dev/cockpit/files.ts +0 -249
  216. package/apps/storefront/src/lib/developer-experience/dev/cockpit/hostedActivity.ts +0 -500
  217. package/apps/storefront/src/lib/developer-experience/dev/cockpit/infoPopover.ts +0 -12
  218. package/apps/storefront/src/lib/developer-experience/dev/cockpit/mcpCopy.ts +0 -34
  219. package/apps/storefront/src/lib/developer-experience/dev/cockpit/monitor.ts +0 -107
  220. package/apps/storefront/src/lib/developer-experience/dev/cockpit/stepper.ts +0 -116
  221. package/apps/storefront/src/lib/developer-experience/dev/cockpit/themeToggle.ts +0 -23
  222. package/apps/storefront/src/lib/developer-experience/dev/livePreview.ts +0 -77
  223. package/apps/storefront/src/lib/developer-experience/dev/obstacleStore.ts +0 -214
  224. package/apps/storefront/src/lib/developer-experience/dev/previewStatus.ts +0 -87
  225. package/apps/storefront/src/lib/developer-experience/dev/rendezvousBroker.ts +0 -226
  226. package/apps/storefront/src/lib/developer-experience/dev/runtimeStore.ts +0 -291
  227. package/apps/storefront/src/lib/developer-experience/dev/storeStatus.ts +0 -142
  228. package/apps/storefront/src/lib/developer-experience/dev/subjectReissue.ts +0 -67
  229. package/apps/storefront/src/lib/developer-experience/fixtures/regulated-commerce-truth/index.ts +0 -540
  230. package/apps/storefront/src/lib/developer-experience/fixtures/ws3-readonly-clone-preflight/index.ts +0 -495
  231. package/apps/storefront/src/lib/engagement/contact/contactMessages.ts +0 -671
  232. package/apps/storefront/src/lib/engagement/contact/messagesTabClient.ts +0 -175
  233. package/apps/storefront/src/lib/engagement/contact/submission.ts +0 -112
  234. package/apps/storefront/src/lib/engagement/messaging/messagesClient.ts +0 -149
  235. package/apps/storefront/src/lib/engagement/newsletter/digest.ts +0 -117
  236. package/apps/storefront/src/lib/engagement/newsletter/resendClient.ts +0 -79
  237. package/apps/storefront/src/lib/engagement/newsletter/send.ts +0 -265
  238. package/apps/storefront/src/lib/engagement/social/golive.ts +0 -212
  239. package/apps/storefront/src/lib/engagement/social/notify.ts +0 -32
  240. package/apps/storefront/src/lib/engagement/social/tokenStore.ts +0 -171
  241. package/apps/storefront/src/lib/fulfillment/admin/commerceDesk.ts +0 -180
  242. package/apps/storefront/src/lib/fulfillment/admin/commerceDeskRouting.ts +0 -45
  243. package/apps/storefront/src/lib/fulfillment/admin/viewmodels/fulfillment.ts +0 -1071
  244. package/apps/storefront/src/lib/fulfillment/appShipmentEvidence.ts +0 -271
  245. package/apps/storefront/src/lib/fulfillment/carrierEvidence.ts +0 -105
  246. package/apps/storefront/src/lib/fulfillment/commerceProjection.ts +0 -157
  247. package/apps/storefront/src/lib/fulfillment/commerceReadback.ts +0 -60
  248. package/apps/storefront/src/lib/fulfillment/commerceRecovery.ts +0 -84
  249. package/apps/storefront/src/lib/fulfillment/commerceRuntime.ts +0 -41
  250. package/apps/storefront/src/lib/fulfillment/fulfillmentService.ts +0 -2842
  251. package/apps/storefront/src/lib/fulfillment/readiness.ts +0 -217
  252. package/apps/storefront/src/lib/fulfillment/splitShipments.ts +0 -388
  253. package/apps/storefront/src/lib/fulfillment/syntheticPreviewOrders.ts +0 -292
  254. package/apps/storefront/src/lib/integrations/apps/appContactAuthority.ts +0 -27
  255. package/apps/storefront/src/lib/integrations/apps/appContactConsents.ts +0 -118
  256. package/apps/storefront/src/lib/integrations/apps/appInstallEnv.ts +0 -28
  257. package/apps/storefront/src/lib/integrations/apps/gtmMigrationDraft.ts +0 -103
  258. package/apps/storefront/src/lib/integrations/apps/inventoryWrite.ts +0 -906
  259. package/apps/storefront/src/lib/integrations/apps/orders/customerHash.ts +0 -28
  260. package/apps/storefront/src/lib/integrations/apps/orders/idempotency.ts +0 -100
  261. package/apps/storefront/src/lib/integrations/apps/reports/salesVelocityReport.ts +0 -96
  262. package/apps/storefront/src/lib/integrations/apps/routeParams.ts +0 -45
  263. package/apps/storefront/src/lib/integrations/webhooks/cloudflareQueueDispatcher.ts +0 -82
  264. package/apps/storefront/src/lib/integrations/webhooks/commercePayloads.ts +0 -159
  265. package/apps/storefront/src/lib/integrations/webhooks/deliveryEngine.ts +0 -379
  266. package/apps/storefront/src/lib/integrations/webhooks/deliveryMapper.ts +0 -34
  267. package/apps/storefront/src/lib/integrations/webhooks/deliveryStore.ts +0 -903
  268. package/apps/storefront/src/lib/integrations/webhooks/dispatcher.ts +0 -168
  269. package/apps/storefront/src/lib/integrations/webhooks/emit.ts +0 -245
  270. package/apps/storefront/src/lib/integrations/webhooks/events.ts +0 -105
  271. package/apps/storefront/src/lib/integrations/webhooks/getDispatcher.ts +0 -77
  272. package/apps/storefront/src/lib/integrations/webhooks/orderFulfilledClaim.ts +0 -75
  273. package/apps/storefront/src/lib/measurement/admin/analyticsRegionPolicy.ts +0 -151
  274. package/apps/storefront/src/lib/measurement/admin/analyticsRegionsClient.ts +0 -84
  275. package/apps/storefront/src/lib/measurement/admin/consentSettingsClient.ts +0 -113
  276. package/apps/storefront/src/lib/measurement/analytics/index.ts +0 -44
  277. package/apps/storefront/src/lib/measurement/attribution/attributionService.ts +0 -206
  278. package/apps/storefront/src/lib/measurement/attribution/orderConversionD1.ts +0 -150
  279. package/apps/storefront/src/lib/measurement/attribution/verifiedProviderMeasurement.ts +0 -118
  280. package/apps/storefront/src/lib/measurement/tracking/interactionCollector.ts +0 -205
  281. package/apps/storefront/src/lib/measurement/tracking/pruneRollup.ts +0 -260
  282. package/apps/storefront/src/lib/measurement/tracking/tenantReadAccess.ts +0 -138
  283. package/apps/storefront/src/lib/measurement/tracking-writeback/rewriteTrackingIds.ts +0 -175
  284. package/apps/storefront/src/lib/measurement/tracking-writeback/writebackCandidate.ts +0 -110
  285. package/apps/storefront/src/lib/observability/diag/capture.ts +0 -162
  286. package/apps/storefront/src/lib/observability/diag/consoleLine.ts +0 -76
  287. package/apps/storefront/src/lib/observability/diag/debugConsole.ts +0 -118
  288. package/apps/storefront/src/lib/observability/diag/debugMode.ts +0 -163
  289. package/apps/storefront/src/lib/observability/diag/debugWindow.ts +0 -111
  290. package/apps/storefront/src/lib/observability/diag/redact.ts +0 -17
  291. package/apps/storefront/src/lib/observability/diag/reference.ts +0 -148
  292. package/apps/storefront/src/lib/observability/diag/referenceStore.ts +0 -113
  293. package/apps/storefront/src/lib/observability/diag/report.ts +0 -110
  294. package/apps/storefront/src/lib/observability/diag/serverResponseTime.ts +0 -91
  295. package/apps/storefront/src/lib/observability/diag/session.ts +0 -93
  296. package/apps/storefront/src/lib/observability/monitoring/manifest.ts +0 -301
  297. package/apps/storefront/src/lib/observability/performance/lighthouseReport.ts +0 -109
  298. package/apps/storefront/src/lib/observability/performance/rumAlert.ts +0 -179
  299. package/apps/storefront/src/lib/orders/admin/orderActions.ts +0 -556
  300. package/apps/storefront/src/lib/orders/admin/orderClient.ts +0 -248
  301. package/apps/storefront/src/lib/orders/admin/orderSource.ts +0 -410
  302. package/apps/storefront/src/lib/orders/admin/services/orders.ts +0 -922
  303. package/apps/storefront/src/lib/orders/admin/viewmodels/orders.ts +0 -135
  304. package/apps/storefront/src/lib/orders/data/commerceCallerConfig.ts +0 -37
  305. package/apps/storefront/src/lib/orders/data/ledgerContractOrders.ts +0 -148
  306. package/apps/storefront/src/lib/orders/data/orderForwardReceiver.ts +0 -532
  307. package/apps/storefront/src/lib/orders/data/orderMapper.ts +0 -454
  308. package/apps/storefront/src/lib/orders/data/ordersStore.ts +0 -623
  309. package/apps/storefront/src/lib/orders/data/sourceAuthorityContract.ts +0 -380
  310. package/apps/storefront/src/lib/orders/data/sourceAuthorityStore.ts +0 -830
  311. package/apps/storefront/src/lib/orders/fixtures/orders.ts +0 -186
  312. package/apps/storefront/src/lib/orders/providers/foxyOrderClient.ts +0 -207
  313. package/apps/storefront/src/lib/orders/vault/appRecipientRead.ts +0 -222
  314. package/apps/storefront/src/lib/orders/vault/contactIntake.ts +0 -63
  315. package/apps/storefront/src/lib/orders/vault/contactRoutes.ts +0 -110
  316. package/apps/storefront/src/lib/orders/vault/kmsEnv.ts +0 -11
  317. package/apps/storefront/src/lib/orders/vault/orderContact.ts +0 -96
  318. package/apps/storefront/src/lib/orders/vault/orderContactVault.ts +0 -1427
  319. package/apps/storefront/src/lib/orders/vault/vault-test-support.ts +0 -258
  320. package/apps/storefront/src/lib/publication/d1/schema-apps.ts +0 -808
  321. package/apps/storefront/src/lib/publication/notifications/candidateConflictEmail.ts +0 -80
  322. package/apps/storefront/src/lib/publication/servingMode.ts +0 -52
  323. package/apps/storefront/src/lib/publication/shared/previewAnnotations/moduleAsset.ts +0 -65
  324. package/apps/storefront/src/lib/publication/shared/routedApiParam.ts +0 -38
  325. package/apps/storefront/src/lib/reporting/admin/viewmodels/reporting.ts +0 -34
  326. package/apps/storefront/src/lib/reporting/fixtures/reporting.ts +0 -51
  327. package/apps/storefront/src/lib/subscriptions/admin/viewmodels/subscriptions.ts +0 -106
  328. package/apps/storefront/src/lib/subscriptions/fixtures/subscriptions.ts +0 -398
  329. package/apps/storefront/src/pages/api/admin/activity-alerts.ts +0 -58
  330. package/apps/storefront/src/pages/api/admin/commerce-readiness.ts +0 -172
  331. package/apps/storefront/src/pages/api/admin/fulfillment/batches.ts +0 -59
  332. package/apps/storefront/src/pages/api/admin/fulfillment/orders/[id]/address.ts +0 -66
  333. package/apps/storefront/src/pages/api/admin/fulfillment/orders/[id].ts +0 -118
  334. package/apps/storefront/src/pages/api/admin/fulfillment/orders/contact-search.ts +0 -26
  335. package/apps/storefront/src/pages/api/admin/fulfillment/orders/contacts.ts +0 -22
  336. package/apps/storefront/src/pages/api/admin/interaction-insights.ts +0 -101
  337. package/apps/storefront/src/pages/api/admin/orders/[id].ts +0 -63
  338. package/apps/storefront/src/pages/api/admin/orders.ts +0 -65
  339. package/apps/storefront/src/pages/api/contact.ts +0 -144
  340. package/apps/storefront/src/scheduled/contactVaultSweep.ts +0 -113
  341. package/apps/storefront/src/styles/admin.css +0 -1161
  342. package/apps/storefront/test/pipeline/fake-preview-services.ts +0 -288
  343. package/apps/storefront/test/pipeline/harness.ts +0 -209
  344. package/apps/storefront/test/pipeline/intake-worker.mjs +0 -14
  345. package/apps/storefront/test/pipeline/matrix-faults.ts +0 -366
  346. package/apps/storefront/test/pipeline/pipeline-host.ts +0 -418
  347. package/apps/storefront/test/pipeline/pool-config.cjs +0 -85
  348. package/apps/storefront/test/pipeline/publish-kinds.ts +0 -279
  349. package/apps/storefront/test/pipeline/synthetic-job.ts +0 -303
  350. package/apps/storefront/test/pipeline-faults/matrix-lib.ts +0 -696
  351. package/apps/storefront/vitest.config.cts +0 -44
  352. package/apps/storefront/vitest.faults.config.cts +0 -13
  353. package/apps/storefront/vitest.workers.config.cts +0 -7
  354. package/packages/feedback/fixtures/v1/expected-findings.json +0 -16
  355. package/packages/feedback/fixtures/v1/feedback-action/invalid/carries-transport-credential.json +0 -14
  356. package/packages/feedback/fixtures/v1/feedback-action/invalid/control-char-in-description.json +0 -13
  357. package/packages/feedback/fixtures/v1/feedback-action/invalid/legacy-schema-version.json +0 -13
  358. package/packages/feedback/fixtures/v1/feedback-action/invalid/page-path-with-query.json +0 -14
  359. package/packages/feedback/fixtures/v1/feedback-action/invalid/title-too-short.json +0 -13
  360. package/packages/feedback/fixtures/v1/feedback-action/valid/element-problem.json +0 -33
  361. package/packages/feedback/fixtures/v1/feedback-action/valid/page-comment.json +0 -20
  362. package/packages/feedback/fixtures/v1/feedback-action/valid/region-improvement.json +0 -24
  363. package/packages/feedback/fixtures/v1/feedback-action/valid/text-selection-feature.json +0 -30
  364. package/packages/feedback/fixtures/v1/submission-receipt/invalid/accepted-at-not-utc.json +0 -9
  365. package/packages/feedback/fixtures/v1/submission-receipt/invalid/bad-feedback-id.json +0 -9
  366. package/packages/feedback/fixtures/v1/submission-receipt/invalid/legacy-contract-version.json +0 -9
  367. package/packages/feedback/fixtures/v1/submission-receipt/invalid/missing-replayed.json +0 -8
  368. package/packages/feedback/fixtures/v1/submission-receipt/valid/accepted.json +0 -9
  369. package/packages/feedback/fixtures/v1/submission-receipt/valid/fractional-seconds.json +0 -9
  370. package/packages/feedback/fixtures/v1/submission-receipt/valid/replayed.json +0 -9
  371. package/packages/feedback/fixtures/v1/target-evidence/invalid/page-kind-claims-structure.json +0 -6
  372. package/packages/feedback/fixtures/v1/target-evidence/invalid/path-too-deep.json +0 -17
  373. package/packages/feedback/fixtures/v1/target-evidence/invalid/relative-region-out-of-range.json +0 -11
  374. package/packages/feedback/fixtures/v1/target-evidence/invalid/selector-uses-class.json +0 -7
  375. package/packages/feedback/fixtures/v1/target-evidence/invalid/source-precision-without-anchor.json +0 -6
  376. package/packages/feedback/fixtures/v1/target-evidence/valid/element-structure.json +0 -21
  377. package/packages/feedback/fixtures/v1/target-evidence/valid/host-iframe.json +0 -14
  378. package/packages/feedback/fixtures/v1/target-evidence/valid/source-anchor.json +0 -12
  379. package/packages/feedback/fixtures/v1/target-evidence/valid/text-selection.json +0 -26
  380. package/packages/feedback/package.json +0 -35
  381. package/packages/feedback/scripts/build-player.mjs +0 -28
  382. package/packages/feedback/src/index.ts +0 -1
  383. package/packages/feedback/src/primitives/composer.ts +0 -639
  384. package/packages/feedback/src/primitives/dialog.ts +0 -263
  385. package/packages/feedback/src/primitives/hostAdapter.ts +0 -116
  386. package/packages/feedback/src/primitives/index.ts +0 -10
  387. package/packages/feedback/src/primitives/launcher.ts +0 -200
  388. package/packages/feedback/src/primitives/picker.ts +0 -663
  389. package/packages/feedback/src/primitives/redaction.ts +0 -204
  390. package/packages/feedback/src/primitives/selection.ts +0 -49
  391. package/packages/feedback/src/primitives/shiftAccelerator.ts +0 -160
  392. package/packages/feedback/src/primitives/styles.ts +0 -77
  393. package/packages/feedback/src/primitives/surface.ts +0 -124
  394. package/packages/feedback/src/primitives/target.ts +0 -293
  395. package/packages/feedback/src/tour/canonical.ts +0 -27
  396. package/packages/feedback/src/tour/index.ts +0 -3
  397. package/packages/feedback/src/tour/player/browser.ts +0 -5
  398. package/packages/feedback/src/tour/player/host.ts +0 -12
  399. package/packages/feedback/src/tour/player/index.ts +0 -205
  400. package/packages/feedback/src/tour/player/manifest.ts +0 -76
  401. package/packages/feedback/src/tour/player/player.css +0 -130
  402. package/packages/feedback/src/tour/player/resolver.ts +0 -12
  403. package/packages/feedback/src/tour/player/surface.ts +0 -295
  404. package/packages/feedback/src/tour/player/types.ts +0 -8
  405. package/packages/feedback/src/tour/resolve/core.ts +0 -267
  406. package/packages/feedback/src/tour/resolve/dom.ts +0 -115
  407. package/packages/feedback/src/tour/resolve/index.ts +0 -29
  408. package/packages/feedback/src/tour/sanitize.ts +0 -76
  409. package/packages/feedback/src/tour/schema.ts +0 -362
  410. package/packages/feedback/src/v1/guards.ts +0 -335
  411. package/packages/feedback/src/v1/index.ts +0 -3
  412. package/packages/feedback/src/v1/protectedSurfaces.ts +0 -32
  413. package/packages/feedback/src/v1/types.ts +0 -177
  414. package/packages/feedback/tsconfig.json +0 -9
  415. package/packages/feedback/vitest.config.cts +0 -21
@@ -1,663 +0,0 @@
1
- /**
2
- * Selection: hover glow, click-to-select, Larger/Smaller area, region drag, two-corner taps, a
3
- * keyboard target navigator, and text-selection picking.
4
- *
5
- * While picking an element or region, a full-viewport shield inside the primitive's shadow root
6
- * receives every pointer event, and capture-phase window listeners swallow any
7
- * click/pointer/touch/submit event aimed at the page, so links, buttons, forms, cart and checkout
8
- * controls never activate during selection. When the picker is inactive none of these listeners
9
- * exist. Text mode needs the page's own selection gesture, so it installs no shield and no
10
- * swallowing; the reviewer confirms with "Use selection".
11
- *
12
- * Hit testing uses `document.elementsFromPoint` with the picker host filtered out. A point over an
13
- * iframe, canvas or shadow host resolves to that host element (see target.ts).
14
- */
15
- import type { FeedbackTarget, Rect, TargetEvidenceV1, TextSelection } from "../v1/types.js";
16
- import { isSurfacePermitted, type HostAdapter } from "./hostAdapter.js";
17
- import { readTextSelection } from "./selection.js";
18
- import { createSurface, eventFromHost, h } from "./surface.js";
19
- import {
20
- buildTargetEvidence,
21
- describeTarget,
22
- elementTarget,
23
- isHostBoundary,
24
- pageTarget,
25
- rectFromCorners,
26
- regionTarget,
27
- safeLabel,
28
- } from "./target.js";
29
-
30
- export type PickMode = "element" | "region";
31
-
32
- export interface PickResult {
33
- kind: "element" | "region";
34
- element: Element | null;
35
- rect?: Rect;
36
- }
37
-
38
- export interface PickerCallbacks {
39
- onHover(el: Element | null, label: string | null): void;
40
- onRegionDraft(rect: Rect | null): void;
41
- onPick(result: PickResult): void;
42
- onInstruction(text: string): void;
43
- }
44
-
45
- const SWALLOW = [
46
- "click",
47
- "dblclick",
48
- "auxclick",
49
- "contextmenu",
50
- "pointerdown",
51
- "pointerup",
52
- "mousedown",
53
- "mouseup",
54
- "touchstart",
55
- "touchend",
56
- "submit",
57
- ] as const;
58
-
59
- const TAP_SLOP = 6;
60
- /**
61
- * After a pick, the browser still synthesizes the tap's compatibility mouse events and click — at the
62
- * page element now under the point, because the shield is gone. Keep swallowing for this long.
63
- */
64
- const GHOST_CLICK_GRACE_MS = 500;
65
-
66
- export class Picker {
67
- private active = false;
68
- private mode: PickMode = "element";
69
- private hovered: Element | null = null;
70
- /** Element stack for Larger/Smaller: [original, parent, grandparent, ...]. */
71
- private stack: Element[] = [];
72
- private stackIndex = 0;
73
- private dragStart: { x: number; y: number } | null = null;
74
- private firstCorner: { x: number; y: number } | null = null;
75
- private attached = false;
76
- private graceUntil = 0;
77
- /** A keyboard or toolbar pick synthesizes no click, so it has no ghost click to swallow. */
78
- private pickWithoutGhostClick = false;
79
- private detachTimer: ReturnType<typeof setTimeout> | null = null;
80
- private readonly swallow = (e: Event) => {
81
- if (!this.active && performance.now() > this.graceUntil) return;
82
- if (this.isOwn(e)) return;
83
- // After the pick the ghost click lands on the page; the package's own dialog and launcher are never its target.
84
- if (!this.active && e.composedPath().some((n) => n instanceof Element && n.localName.startsWith("feedback-"))) return;
85
- e.preventDefault();
86
- e.stopImmediatePropagation();
87
- };
88
-
89
- constructor(
90
- private readonly win: Window,
91
- private readonly doc: Document,
92
- private readonly host: Element,
93
- private readonly shield: HTMLElement,
94
- private readonly cb: PickerCallbacks,
95
- ) {
96
- shield.addEventListener("pointermove", (e) => this.onMove(e));
97
- shield.addEventListener("pointerdown", (e) => this.onDown(e));
98
- shield.addEventListener("pointerup", (e) => this.onUp(e));
99
- shield.addEventListener("click", (e) => {
100
- e.preventDefault();
101
- e.stopPropagation();
102
- });
103
- }
104
-
105
- get isActive(): boolean {
106
- return this.active;
107
- }
108
-
109
- get currentMode(): PickMode {
110
- return this.mode;
111
- }
112
-
113
- get current(): Element | null {
114
- return this.stack[this.stackIndex] ?? this.hovered;
115
- }
116
-
117
- /**
118
- * @param seed the page element the keyboard navigator starts on (the element that had focus when
119
- * selection began); falls back to the element at the viewport centre, then the first visible
120
- * element of the page.
121
- */
122
- start(mode: PickMode, seed: Element | null = null): void {
123
- this.mode = mode;
124
- this.firstCorner = null;
125
- this.dragStart = null;
126
- this.cb.onRegionDraft(null);
127
- if (this.detachTimer) {
128
- clearTimeout(this.detachTimer);
129
- this.detachTimer = null;
130
- }
131
- this.active = true;
132
- this.pickWithoutGhostClick = false;
133
- if (!this.attached) {
134
- this.attached = true;
135
- for (const type of SWALLOW) this.win.addEventListener(type, this.swallow, { capture: true });
136
- }
137
- this.shield.hidden = false;
138
- this.shield.dataset.mode = mode;
139
- if (!this.current) {
140
- const usableSeed = seed && seed.isConnected && seed !== this.doc.body && seed !== this.doc.documentElement && !this.host.contains(seed) ? seed : null;
141
- this.setStackFrom(
142
- usableSeed ??
143
- this.hit(this.win.innerWidth / 2, this.win.innerHeight / 2) ??
144
- (this.doc.body ? this.firstVisible(Array.from(this.doc.body.children)) : null),
145
- );
146
- }
147
- this.cb.onInstruction(
148
- mode === "element"
149
- ? "Select something to comment on. Esc to cancel."
150
- : "Drag to draw a region, or tap two corners. Esc to cancel.",
151
- );
152
- this.emitHover();
153
- }
154
-
155
- stop(): void {
156
- const ghostClick = !this.pickWithoutGhostClick;
157
- this.pickWithoutGhostClick = false;
158
- if (this.active && this.attached && !ghostClick) this.detach();
159
- else if (this.active && this.attached) {
160
- this.graceUntil = performance.now() + GHOST_CLICK_GRACE_MS;
161
- if (this.detachTimer) clearTimeout(this.detachTimer);
162
- this.detachTimer = setTimeout(() => this.detach(), GHOST_CLICK_GRACE_MS + 50);
163
- }
164
- this.active = false;
165
- this.shield.hidden = true;
166
- this.dragStart = null;
167
- this.firstCorner = null;
168
- this.hovered = null;
169
- this.stack = [];
170
- this.stackIndex = 0;
171
- this.cb.onHover(null, null);
172
- this.cb.onRegionDraft(null);
173
- }
174
-
175
- /** The next stop() follows a pick that came from a control, not a pointer tap, so no click is synthesized. */
176
- pickedByControl(): void {
177
- this.pickWithoutGhostClick = true;
178
- }
179
-
180
- /** Remove every page listener now (teardown, or when the ghost-click grace has elapsed). */
181
- detach(): void {
182
- if (this.detachTimer) {
183
- clearTimeout(this.detachTimer);
184
- this.detachTimer = null;
185
- }
186
- if (this.attached) {
187
- for (const type of SWALLOW) this.win.removeEventListener(type, this.swallow, { capture: true });
188
- this.attached = false;
189
- }
190
- this.graceUntil = 0;
191
- }
192
-
193
- /** Larger area: promote to the containing element. */
194
- larger(): void {
195
- const cur = this.current;
196
- if (!cur) return;
197
- if (this.stackIndex < this.stack.length - 1) this.stackIndex += 1;
198
- else {
199
- const parent = cur.parentElement;
200
- if (parent && parent !== this.doc.documentElement) {
201
- this.stack.push(parent);
202
- this.stackIndex = this.stack.length - 1;
203
- }
204
- }
205
- this.emitHover();
206
- }
207
-
208
- /** Smaller area: step back toward the originally hovered element, or into the first child. */
209
- smaller(): void {
210
- if (this.stackIndex > 0) {
211
- this.stackIndex -= 1;
212
- this.emitHover();
213
- return;
214
- }
215
- this.child();
216
- }
217
-
218
- parent(): void {
219
- this.larger();
220
- }
221
-
222
- child(): void {
223
- const cur = this.current;
224
- if (!cur || isHostBoundary(cur)) return;
225
- const next = this.firstVisible(Array.from(cur.children));
226
- if (next) this.setStackFrom(next);
227
- }
228
-
229
- next(): void {
230
- this.sibling(1);
231
- }
232
-
233
- previous(): void {
234
- this.sibling(-1);
235
- }
236
-
237
- /** Select the navigator's current element (keyboard path). */
238
- selectCurrent(): void {
239
- const el = this.current;
240
- if (!el) return;
241
- this.pickWithoutGhostClick = true;
242
- if (this.mode === "region") {
243
- const r = el.getBoundingClientRect();
244
- const rect = rectFromCorners(
245
- { x: r.left, y: r.top },
246
- { x: r.right, y: r.bottom },
247
- { width: this.win.innerWidth, height: this.win.innerHeight },
248
- );
249
- this.cb.onPick({ kind: "region", element: el.parentElement ?? el, rect });
250
- return;
251
- }
252
- this.cb.onPick({ kind: "element", element: el });
253
- }
254
-
255
- private sibling(step: 1 | -1): void {
256
- const cur = this.current;
257
- const parent = cur?.parentElement;
258
- if (!cur || !parent) return;
259
- const siblings = Array.from(parent.children).filter((c) => c !== this.host && this.visible(c));
260
- const i = siblings.indexOf(cur);
261
- const next = siblings[(i + step + siblings.length) % siblings.length];
262
- if (next) this.setStackFrom(next);
263
- }
264
-
265
- private setStackFrom(el: Element | null): void {
266
- this.stack = el ? [el] : [];
267
- this.stackIndex = 0;
268
- this.hovered = el;
269
- this.emitHover();
270
- }
271
-
272
- private emitHover(): void {
273
- const el = this.current;
274
- this.cb.onHover(el, el ? safeLabel(el) : null);
275
- }
276
-
277
- private isOwn(e: Event): boolean {
278
- const path = typeof e.composedPath === "function" ? e.composedPath() : [];
279
- return path.includes(this.host);
280
- }
281
-
282
- private visible(el: Element): boolean {
283
- const r = el.getBoundingClientRect();
284
- return r.width > 0 || r.height > 0;
285
- }
286
-
287
- private firstVisible(list: Element[]): Element | null {
288
- return list.find((c) => c !== this.host && this.visible(c)) ?? list.find((c) => c !== this.host) ?? null;
289
- }
290
-
291
- /** Topmost page element at a viewport point, skipping the annotation host. */
292
- hit(x: number, y: number): Element | null {
293
- const list =
294
- typeof this.doc.elementsFromPoint === "function"
295
- ? this.doc.elementsFromPoint(x, y)
296
- : [this.doc.elementFromPoint(x, y)].filter((e): e is Element => !!e);
297
- for (const el of list) {
298
- if (el === this.host || this.host.contains(el)) continue;
299
- if (el === this.doc.documentElement) continue;
300
- return el;
301
- }
302
- return null;
303
- }
304
-
305
- private onMove(e: PointerEvent): void {
306
- if (!this.active) return;
307
- if (this.mode === "region") {
308
- if (this.dragStart) {
309
- this.cb.onRegionDraft(this.rect(this.dragStart, { x: e.clientX, y: e.clientY }));
310
- } else if (this.firstCorner) {
311
- this.cb.onRegionDraft(this.rect(this.firstCorner, { x: e.clientX, y: e.clientY }));
312
- }
313
- return;
314
- }
315
- const el = this.hit(e.clientX, e.clientY);
316
- if (el !== this.hovered) this.setStackFrom(el);
317
- }
318
-
319
- private onDown(e: PointerEvent): void {
320
- if (!this.active) return;
321
- e.preventDefault();
322
- e.stopPropagation();
323
- if (this.mode === "region") this.dragStart = { x: e.clientX, y: e.clientY };
324
- }
325
-
326
- private onUp(e: PointerEvent): void {
327
- if (!this.active) return;
328
- e.preventDefault();
329
- e.stopPropagation();
330
- const point = { x: e.clientX, y: e.clientY };
331
- if (this.mode === "element") {
332
- const el = this.hit(point.x, point.y);
333
- if (el) {
334
- if (el !== this.hovered) this.setStackFrom(el);
335
- this.cb.onPick({ kind: "element", element: this.current });
336
- }
337
- return;
338
- }
339
- const start = this.dragStart;
340
- this.dragStart = null;
341
- if (start && (Math.abs(start.x - point.x) > TAP_SLOP || Math.abs(start.y - point.y) > TAP_SLOP)) {
342
- this.finishRegion(start, point);
343
- return;
344
- }
345
- // A tap: two separate taps choose two corners.
346
- if (!this.firstCorner) {
347
- this.firstCorner = point;
348
- this.cb.onInstruction("First corner set. Tap the opposite corner. Esc to cancel.");
349
- this.cb.onRegionDraft(this.rect(point, point));
350
- return;
351
- }
352
- const first = this.firstCorner;
353
- this.firstCorner = null;
354
- this.finishRegion(first, point);
355
- }
356
-
357
- private rect(a: { x: number; y: number }, b: { x: number; y: number }): Rect {
358
- return rectFromCorners(a, b, { width: this.win.innerWidth, height: this.win.innerHeight });
359
- }
360
-
361
- private finishRegion(a: { x: number; y: number }, b: { x: number; y: number }): void {
362
- const rect = this.rect(a, b);
363
- if (rect.width < 4 || rect.height < 4) {
364
- this.cb.onInstruction("That region is too small. Drag a larger area or tap two corners.");
365
- this.cb.onRegionDraft(null);
366
- return;
367
- }
368
- const container = this.containerFor(rect);
369
- this.cb.onRegionDraft(rect);
370
- this.cb.onPick({ kind: "region", element: container, rect });
371
- }
372
-
373
- /** Deepest page element at the region centre whose box contains the whole region. */
374
- private containerFor(rect: Rect): Element | null {
375
- let el = this.hit(rect.x + rect.width / 2, rect.y + rect.height / 2);
376
- while (el && el !== this.doc.body) {
377
- const r = el.getBoundingClientRect();
378
- if (r.left <= rect.x && r.top <= rect.y && r.right >= rect.x + rect.width && r.bottom >= rect.y + rect.height) {
379
- return el;
380
- }
381
- el = el.parentElement;
382
- }
383
- return this.doc.body;
384
- }
385
- }
386
-
387
- // ---------------------------------------------------------------------------------------------
388
- // Picker surface: shield, highlight, region box and toolbar around the Picker engine.
389
-
390
- export type PickerSurfaceMode = PickMode | "text";
391
-
392
- /** What a finished pick produces: the evidence, plus a safe label for the UI. */
393
- export interface PickOutcome {
394
- kind: "element" | "region" | "page" | "text";
395
- /** The picked element, kept only so the UI can highlight it; never serialize it. */
396
- element: Element | null;
397
- /** Orientation label: a tag/role word, "Whole page", "Region WxH", or "Selected text". Never page text. */
398
- label: string;
399
- target: FeedbackTarget;
400
- selection?: TextSelection;
401
- evidence: TargetEvidenceV1;
402
- }
403
-
404
- export interface PickerSurfaceOptions {
405
- win: Window;
406
- doc: Document;
407
- adapter?: HostAdapter;
408
- /** Pick modes the toolbar offers. Default: element, region and text. A host whose intake cannot carry a text selection omits `text`. */
409
- modes?: readonly PickerSurfaceMode[];
410
- onPick(outcome: PickOutcome): void;
411
- /** Called after the reviewer cancels (Esc or the Cancel button). */
412
- onCancel?(): void;
413
- }
414
-
415
- export interface PickerSurface {
416
- mount(): boolean;
417
- /** Stops any active pick, then removes the surface. Idempotent. */
418
- unmount(): void;
419
- /** Begin picking. `seed` is the page element the keyboard navigator starts on. Returns false when not permitted. */
420
- start(mode?: PickerSurfaceMode, seed?: Element | null): boolean;
421
- /** End picking without reporting a result. */
422
- stop(): void;
423
- /**
424
- * The outcome a pick of `element` would report, without starting a pick or calling `onPick`. For a
425
- * host that re-targets a draft (for example, widening it to the containing element). Null for an
426
- * element the picker never offers (the document element, or one of the package's own surfaces).
427
- */
428
- outcomeFor(element: Element): PickOutcome | null;
429
- readonly isActive: boolean;
430
- readonly mode: PickerSurfaceMode;
431
- readonly host: HTMLElement;
432
- /** Diagnostic access to the shadow root (a closed root hides it from page script). */
433
- readonly root: ShadowRoot;
434
- }
435
-
436
- export function createPicker(options: PickerSurfaceOptions): PickerSurface {
437
- const { win, doc, adapter } = options;
438
- const surface = createSurface({ win, doc, adapter, tag: "feedback-picker" });
439
- const live = h(doc, "div", { class: "sr", role: "status", "aria-live": "polite" });
440
- const shield = h(doc, "div", { class: "shield", hidden: true, "aria-hidden": "true" });
441
- const highlight = h(doc, "div", { class: "highlight", hidden: true, "aria-hidden": "true" });
442
- const highlightTag = h(doc, "span", { class: "tag" });
443
- highlight.append(highlightTag);
444
- const regionBox = h(doc, "div", { class: "region", hidden: true, "aria-hidden": "true" });
445
- const toolbar = h(doc, "div", { class: "toolbar", role: "toolbar", "aria-label": "Feedback selection", hidden: true });
446
- const instr = h(doc, "span", { class: "instr" });
447
- surface.root.append(shield, highlight, regionBox, toolbar, live);
448
-
449
- let active = false;
450
- let mode: PickerSurfaceMode = "element";
451
-
452
- const announce = (text: string) => {
453
- instr.textContent = text;
454
- live.textContent = text;
455
- };
456
- const place = (el: HTMLElement, r: { left: number; top: number; width: number; height: number }) => {
457
- el.style.setProperty("left", `${r.left}px`);
458
- el.style.setProperty("top", `${r.top}px`);
459
- el.style.setProperty("width", `${Math.max(0, r.width)}px`);
460
- el.style.setProperty("height", `${Math.max(0, r.height)}px`);
461
- };
462
-
463
- const engine = new Picker(win, doc, surface.host, shield, {
464
- onHover(el, label) {
465
- if (!el) {
466
- highlight.hidden = true;
467
- return;
468
- }
469
- place(highlight, el.getBoundingClientRect());
470
- highlightTag.textContent = label ?? "";
471
- highlight.hidden = false;
472
- },
473
- onRegionDraft(rect) {
474
- if (!rect) {
475
- regionBox.hidden = true;
476
- return;
477
- }
478
- place(regionBox, { left: rect.x, top: rect.y, width: rect.width, height: rect.height });
479
- regionBox.hidden = false;
480
- },
481
- onPick(result) {
482
- finish(result.kind, result.element, result.rect);
483
- },
484
- onInstruction: announce,
485
- });
486
-
487
- const evidenceFor = (target: FeedbackTarget, selection?: TextSelection) => {
488
- const page = adapter?.context?.();
489
- return buildTargetEvidence({
490
- win,
491
- target,
492
- ...(page ? { page } : {}),
493
- ...(selection ? { selection } : {}),
494
- });
495
- };
496
-
497
- function finish(kind: PickOutcome["kind"], element: Element | null, rect?: Rect, selection?: TextSelection) {
498
- let target: FeedbackTarget;
499
- let label: string;
500
- if (kind === "page") {
501
- target = pageTarget();
502
- label = "Whole page";
503
- } else if (kind === "region" && rect) {
504
- target = regionTarget(rect, element);
505
- label = describeTarget(target);
506
- } else if (kind === "text") {
507
- target = element ? elementTarget(element) : pageTarget();
508
- label = "Selected text";
509
- } else if (element) {
510
- target = elementTarget(element);
511
- label = safeLabel(element);
512
- } else return;
513
- const outcome: PickOutcome = {
514
- kind,
515
- element: kind === "page" || kind === "region" ? null : element,
516
- label,
517
- target,
518
- evidence: evidenceFor(target, selection),
519
- ...(selection ? { selection } : {}),
520
- };
521
- stop();
522
- options.onPick(outcome);
523
- }
524
-
525
- const button = (label: string, onClick: () => void, extra: Record<string, string> = {}) => {
526
- const b = h(doc, "button", { type: "button", text: label, ...extra });
527
- b.addEventListener("click", (e) => {
528
- e.preventDefault();
529
- onClick();
530
- });
531
- return b;
532
- };
533
- const modeButtons: Record<PickerSurfaceMode, HTMLButtonElement> = {
534
- element: button("Element", () => begin("element"), { "aria-pressed": "true" }),
535
- region: button("Region", () => begin("region"), { "aria-pressed": "false" }),
536
- text: button("Text", () => begin("text"), { "aria-pressed": "false" }),
537
- };
538
- const useSelection = button("Use selection", () => {
539
- const pick = readTextSelection(win, surface.host);
540
- if (!pick) {
541
- announce("Select some text on the page first.");
542
- return;
543
- }
544
- finish("text", pick.container, undefined, pick.selection);
545
- }, { class: "primary" });
546
- const keyed = (fn: () => void) => () => {
547
- if (mode !== "text") fn();
548
- };
549
- const offered = new Set<PickerSurfaceMode>(options.modes ?? ["element", "region", "text"]);
550
- toolbar.append(
551
- instr,
552
- ...(["element", "region", "text"] as const).filter((m) => offered.has(m)).map((m) => modeButtons[m]),
553
- button("Whole page", () => {
554
- engine.pickedByControl();
555
- finish("page", null);
556
- }),
557
- button("Larger area", keyed(() => engine.larger())),
558
- button("Smaller area", keyed(() => engine.smaller())),
559
- button("Previous", keyed(() => engine.previous())),
560
- button("Next", keyed(() => engine.next())),
561
- button("Parent", keyed(() => engine.parent())),
562
- button("Child", keyed(() => engine.child())),
563
- button("Select highlighted", keyed(() => engine.selectCurrent()), { class: "primary" }),
564
- useSelection,
565
- button("Cancel", () => cancel()),
566
- );
567
-
568
- /** Keep the toolbar off what the pointer is aiming at: it docks at the edge farther from the pointer. */
569
- const dockAwayFrom = (y: number) => {
570
- const clearance = (toolbar.offsetHeight || 64) + 12 + 16;
571
- const docked = toolbar.classList.contains("bottom");
572
- if (!docked && y < clearance) toolbar.classList.add("bottom");
573
- else if (docked && y > win.innerHeight - clearance) toolbar.classList.remove("bottom");
574
- };
575
- shield.addEventListener("pointermove", (e) => dockAwayFrom((e as PointerEvent).clientY));
576
- shield.addEventListener("pointerdown", (e) => dockAwayFrom((e as PointerEvent).clientY));
577
- const touchFirst = () => !!win.matchMedia?.("(pointer: coarse)").matches || (win.navigator?.maxTouchPoints ?? 0) > 0;
578
-
579
- let seedEl: Element | null = null;
580
- function begin(next: PickerSurfaceMode) {
581
- mode = next;
582
- active = true;
583
- for (const [m, b] of Object.entries(modeButtons)) b.setAttribute("aria-pressed", String(m === next));
584
- toolbar.hidden = false;
585
- toolbar.classList.toggle("bottom", touchFirst());
586
- useSelection.hidden = next !== "text";
587
- if (next === "text") {
588
- engine.stop();
589
- shield.hidden = true;
590
- announce("Select text on the page, then press Use selection. Esc to cancel.");
591
- } else {
592
- engine.start(next, seedEl);
593
- }
594
- }
595
-
596
- function stop() {
597
- if (!active) return;
598
- active = false;
599
- engine.stop();
600
- toolbar.hidden = true;
601
- highlight.hidden = true;
602
- regionBox.hidden = true;
603
- win.removeEventListener("keydown", onKey, true);
604
- }
605
-
606
- function cancel() {
607
- if (!active) return;
608
- stop();
609
- options.onCancel?.();
610
- }
611
-
612
- const onKey = (e: Event) => {
613
- const ke = e as KeyboardEvent;
614
- if (!active) return;
615
- if (ke.key === "Escape") {
616
- ke.preventDefault();
617
- ke.stopImmediatePropagation();
618
- cancel();
619
- return;
620
- }
621
- // Keep keyboard activation of page controls from firing while picking.
622
- if (mode !== "text" && !eventFromHost(ke, surface.host) && (ke.key === "Enter" || ke.key === " ")) {
623
- ke.preventDefault();
624
- ke.stopImmediatePropagation();
625
- }
626
- };
627
-
628
- return {
629
- mount() {
630
- if (!isSurfacePermitted(adapter, "picker")) return false;
631
- surface.attach();
632
- return true;
633
- },
634
- unmount() {
635
- stop();
636
- engine.detach();
637
- surface.detach();
638
- },
639
- start(next = "element", seed = null) {
640
- if (!isSurfacePermitted(adapter, "picker") || !offered.has(next)) return false;
641
- surface.attach();
642
- seedEl = seed;
643
- win.removeEventListener("keydown", onKey, true);
644
- win.addEventListener("keydown", onKey, true);
645
- begin(next);
646
- return true;
647
- },
648
- stop,
649
- outcomeFor(element) {
650
- if (element === doc.documentElement || element === surface.host || surface.host.contains(element)) return null;
651
- const target = elementTarget(element);
652
- return { kind: "element", element, label: safeLabel(element), target, evidence: evidenceFor(target) };
653
- },
654
- get isActive() {
655
- return active;
656
- },
657
- get mode() {
658
- return mode;
659
- },
660
- host: surface.host,
661
- root: surface.shadow,
662
- };
663
- }