qarpeo 0.4.13 → 0.4.15

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 (304) hide show
  1. package/README.md +197 -191
  2. package/dist/apps/cms.d.ts +1 -1
  3. package/dist/apps/comments.d.ts +1 -1
  4. package/dist/apps/payments.d.ts +1 -1
  5. package/dist/apps/store.d.ts +1 -1
  6. package/dist/chunks/{manifest.get.mjs → tools.mjs} +445 -430
  7. package/dist/cli/index.mjs +756 -746
  8. package/dist/core/aliases.d.ts +1 -1
  9. package/dist/core/context.d.ts +1 -1
  10. package/dist/core/d1-migrate.d.ts +1 -1
  11. package/dist/core/devtools.d.ts +1 -1
  12. package/dist/core/nitro.d.ts +1 -1
  13. package/dist/core/schema.d.ts +1 -1
  14. package/dist/core/server-utils.d.ts +1 -1
  15. package/dist/core/wrangler.d.ts +1 -1
  16. package/dist/fate/index.d.ts +8 -8
  17. package/dist/fate/index.mjs +3 -1
  18. package/dist/features/agents.d.ts +1 -1
  19. package/dist/features/auth.d.ts +1 -1
  20. package/dist/features/bots.d.ts +1 -1
  21. package/dist/features/console.d.ts +1 -1
  22. package/dist/features/fate.d.ts +1 -1
  23. package/dist/features/mail.d.ts +1 -1
  24. package/dist/features/mcp.d.ts +1 -1
  25. package/dist/features/multitenant.d.ts +1 -1
  26. package/dist/features/notifications.d.ts +1 -1
  27. package/dist/features/realtime.d.ts +1 -1
  28. package/dist/features/studio.d.ts +4 -0
  29. package/dist/module.d.ts +1 -1
  30. package/dist/module.mjs +5451 -5249
  31. package/dist/primitives/ai.d.ts +1 -1
  32. package/dist/primitives/analytics.d.ts +1 -1
  33. package/dist/primitives/blob.d.ts +1 -1
  34. package/dist/primitives/browser.d.ts +1 -1
  35. package/dist/primitives/cache.d.ts +1 -1
  36. package/dist/primitives/d1.d.ts +1 -1
  37. package/dist/primitives/do.d.ts +1 -1
  38. package/dist/primitives/email.d.ts +1 -1
  39. package/dist/primitives/hyperdrive.d.ts +1 -1
  40. package/dist/primitives/kv.d.ts +1 -1
  41. package/dist/primitives/queue.d.ts +1 -1
  42. package/dist/primitives/ratelimit.d.ts +1 -1
  43. package/dist/primitives/vectorize.d.ts +1 -1
  44. package/dist/primitives/workflows.d.ts +1 -1
  45. package/dist/runtime/ai.mjs +4 -1
  46. package/dist/runtime/app/components/CMSEditor.vue +439 -0
  47. package/dist/runtime/app/components/CMSEditorImageNode.vue +90 -0
  48. package/dist/runtime/app/components/CMSEditorLinkPopover.vue +120 -0
  49. package/dist/runtime/app/components/QDropZone.vue +327 -0
  50. package/dist/runtime/app/components/QImageCropper.vue +658 -0
  51. package/dist/runtime/app/components/QImageStudio.vue +300 -0
  52. package/dist/runtime/app/components/QImg.vue +7 -4
  53. package/dist/runtime/app/composables/analytics.d.ts +8 -8
  54. package/dist/runtime/app/composables/api-tokens.d.ts +5 -5
  55. package/dist/runtime/app/composables/auth.d.ts +23 -19
  56. package/dist/runtime/app/composables/chat.d.ts +7 -6
  57. package/dist/runtime/app/composables/cms-preview.d.ts +7 -8
  58. package/dist/runtime/app/composables/cms.d.ts +6 -6
  59. package/dist/runtime/app/composables/comments.d.ts +5 -5
  60. package/dist/runtime/app/composables/comments.mjs +7 -4
  61. package/dist/runtime/app/composables/console.d.ts +6 -14
  62. package/dist/runtime/app/composables/docs-version.d.ts +8 -8
  63. package/dist/runtime/app/composables/impersonation.d.ts +5 -5
  64. package/dist/runtime/app/composables/organization.d.ts +5 -5
  65. package/dist/runtime/app/composables/passkey.d.ts +5 -5
  66. package/dist/runtime/app/composables/passwordless.d.ts +5 -5
  67. package/dist/runtime/app/composables/payments.d.ts +5 -5
  68. package/dist/runtime/app/composables/rbac.d.ts +5 -5
  69. package/dist/runtime/app/composables/site.d.ts +2 -2
  70. package/dist/runtime/app/composables/sse.d.ts +20 -33
  71. package/dist/runtime/app/composables/sse.mjs +6 -3
  72. package/dist/runtime/app/composables/storage.d.ts +6 -8
  73. package/dist/runtime/app/composables/store.d.ts +52 -36
  74. package/dist/runtime/app/composables/store.mjs +70 -11
  75. package/dist/runtime/app/composables/studio.d.ts +59 -0
  76. package/dist/runtime/app/composables/studio.mjs +129 -0
  77. package/dist/runtime/app/composables/tenant.d.ts +7 -7
  78. package/dist/runtime/app/composables/turnstile.d.ts +5 -5
  79. package/dist/runtime/app/composables/two-factor.d.ts +5 -5
  80. package/dist/runtime/app/pages/devtools/notifications.vue +1 -6
  81. package/dist/runtime/app/plugins/pwa.mjs +1 -3
  82. package/dist/runtime/app/utils/cms-editor.d.ts +25 -0
  83. package/dist/runtime/app/utils/cms-editor.mjs +43 -0
  84. package/dist/runtime/auth.d.ts +9 -9
  85. package/dist/runtime/blob.d.ts +1 -3
  86. package/dist/runtime/blob.mjs +3 -1
  87. package/dist/runtime/cache.d.ts +8 -6
  88. package/dist/runtime/cache.mjs +8 -11
  89. package/dist/runtime/db.d.ts +4 -3
  90. package/dist/runtime/drizzle.d.ts +2 -1
  91. package/dist/runtime/drizzle.mjs +2 -2
  92. package/dist/runtime/queue.d.ts +1 -0
  93. package/dist/runtime/replica.d.ts +6 -10
  94. package/dist/runtime/replica.mjs +3 -1
  95. package/dist/runtime/schema-mysql.d.ts +16 -32
  96. package/dist/runtime/schema-pg.d.ts +15 -31
  97. package/dist/runtime/schema-shared.d.ts +20 -17
  98. package/dist/runtime/schema.d.ts +21 -33
  99. package/dist/runtime/server/durable-objects/agent.mjs +4 -1
  100. package/dist/runtime/server/durable-objects/room.d.ts +4 -6
  101. package/dist/runtime/server/durable-objects/room.mjs +18 -8
  102. package/dist/runtime/server/plugins/comments.d.ts +2 -3
  103. package/dist/runtime/server/plugins/email-inbound.d.ts +1 -3
  104. package/dist/runtime/server/plugins/store.d.ts +2 -3
  105. package/dist/runtime/server/routes/__qarpeo/cloud/agents/run.post.d.ts +2 -2
  106. package/dist/runtime/server/routes/__qarpeo/cloud/cms/entry.get.mjs +10 -2
  107. package/dist/runtime/server/routes/__qarpeo/cloud/cms/entry.post.d.ts +2 -2
  108. package/dist/runtime/server/routes/__qarpeo/cloud/cms/entry.post.mjs +10 -2
  109. package/dist/runtime/server/routes/__qarpeo/cloud/cms.get.d.ts +2 -2
  110. package/dist/runtime/server/routes/__qarpeo/cloud/cms.get.mjs +7 -1
  111. package/dist/runtime/server/routes/__qarpeo/cloud/comments/moderate.post.d.ts +2 -2
  112. package/dist/runtime/server/routes/__qarpeo/cloud/comments/moderate.post.mjs +5 -1
  113. package/dist/runtime/server/routes/__qarpeo/cloud/comments.get.d.ts +1 -3
  114. package/dist/runtime/server/routes/__qarpeo/cloud/extras.get.d.ts +2 -2
  115. package/dist/runtime/server/routes/__qarpeo/cloud/extras.get.mjs +15 -4
  116. package/dist/runtime/server/routes/__qarpeo/cloud/mail/unsuppress.post.d.ts +2 -2
  117. package/dist/runtime/server/routes/__qarpeo/cloud/migrate/cms.post.mjs +13 -4
  118. package/dist/runtime/server/routes/__qarpeo/cloud/migrate/products.post.mjs +1 -1
  119. package/dist/runtime/server/routes/__qarpeo/cloud/migrate.post.d.ts +3 -3
  120. package/dist/runtime/server/routes/__qarpeo/cloud/migrate.post.mjs +22 -6
  121. package/dist/runtime/server/routes/__qarpeo/cloud/notifications/test.post.d.ts +2 -2
  122. package/dist/runtime/server/routes/__qarpeo/cloud/operations.get.d.ts +6 -5
  123. package/dist/runtime/server/routes/__qarpeo/cloud/store/order-status.post.d.ts +1 -3
  124. package/dist/runtime/server/routes/__qarpeo/cloud/store/order-status.post.mjs +14 -2
  125. package/dist/runtime/server/routes/__qarpeo/cloud/store/orders.get.d.ts +1 -3
  126. package/dist/runtime/server/routes/__qarpeo/cloud/store/orders.get.mjs +7 -1
  127. package/dist/runtime/server/routes/__qarpeo/cloud/store/products.get.d.ts +1 -3
  128. package/dist/runtime/server/routes/__qarpeo/cloud/tasks/run.post.d.ts +2 -2
  129. package/dist/runtime/server/routes/__qarpeo/cloud/users/action.post.d.ts +2 -2
  130. package/dist/runtime/server/routes/__qarpeo/cloud/users/action.post.mjs +5 -1
  131. package/dist/runtime/server/routes/__qarpeo/cloud/users.get.d.ts +6 -5
  132. package/dist/runtime/server/routes/__qarpeo/cloud/users.get.mjs +1 -3
  133. package/dist/runtime/server/routes/__qarpeo/mail/track/click/[id].get.mjs +2 -2
  134. package/dist/runtime/server/routes/__qarpeo/manifest.get.d.ts +2 -2
  135. package/dist/runtime/server/routes/__qarpeo/og.get.d.ts +2 -2
  136. package/dist/runtime/server/routes/__qarpeo/rbac/me.get.d.ts +2 -2
  137. package/dist/runtime/server/routes/__qarpeo/rbac/roles.delete.d.ts +2 -2
  138. package/dist/runtime/server/routes/__qarpeo/rbac/roles.delete.mjs +5 -1
  139. package/dist/runtime/server/routes/__qarpeo/rbac/roles.get.d.ts +2 -2
  140. package/dist/runtime/server/routes/__qarpeo/rbac/roles.get.mjs +1 -5
  141. package/dist/runtime/server/routes/__qarpeo/rbac/roles.post.d.ts +2 -2
  142. package/dist/runtime/server/routes/__qarpeo/rbac/roles.post.mjs +5 -1
  143. package/dist/runtime/server/routes/__qarpeo/rbac/users.post.d.ts +2 -2
  144. package/dist/runtime/server/routes/agents/[agent]/chat.post.mjs +1 -6
  145. package/dist/runtime/server/routes/agents/[agent]/clear.post.mjs +1 -6
  146. package/dist/runtime/server/routes/agents/[agent]/history.get.mjs +1 -6
  147. package/dist/runtime/server/routes/auth/2fa/disable.post.mjs +5 -1
  148. package/dist/runtime/server/routes/auth/2fa/verify.post.mjs +7 -1
  149. package/dist/runtime/server/routes/auth/magic-link/send.post.mjs +1 -1
  150. package/dist/runtime/server/routes/auth/otp/send.post.mjs +1 -1
  151. package/dist/runtime/server/routes/cms/search.get.mjs +2 -6
  152. package/dist/runtime/server/routes/comments/[id]/report.post.mjs +1 -4
  153. package/dist/runtime/server/routes/comments/[id].patch.mjs +1 -4
  154. package/dist/runtime/server/routes/comments/batch.post.mjs +1 -3
  155. package/dist/runtime/server/routes/comments/index.post.mjs +1 -5
  156. package/dist/runtime/server/routes/fate.mjs +1 -1
  157. package/dist/runtime/server/routes/mail/webhooks.post.mjs +1 -1
  158. package/dist/runtime/server/routes/sitemap.xml.get.mjs +2 -1
  159. package/dist/runtime/server/routes/storage/presigned-r2.post.d.ts +5 -6
  160. package/dist/runtime/server/routes/storage/presigned-r2.post.mjs +1 -1
  161. package/dist/runtime/server/routes/store/cart/items/[id].delete.mjs +1 -1
  162. package/dist/runtime/server/routes/store/cart/items/[id].patch.mjs +1 -1
  163. package/dist/runtime/server/routes/store/currencies.get.mjs +1 -4
  164. package/dist/runtime/server/routes/store/orders/[id].get.mjs +1 -1
  165. package/dist/runtime/server/routes/store/orders/download/[token].get.mjs +13 -4
  166. package/dist/runtime/server/routes/store/orders/index.get.mjs +1 -1
  167. package/dist/runtime/server/routes/store/products/index.get.mjs +2 -0
  168. package/dist/runtime/server/routes/store/tax/calculate.post.d.ts +2 -1
  169. package/dist/runtime/server/routes/store/tax/calculate.post.mjs +12 -3
  170. package/dist/runtime/server/routes/tenants/[tenant]/domains/[domain]/index.delete.mjs +4 -1
  171. package/dist/runtime/server/routes/tenants/[tenant]/domains/[domain]/verify.post.mjs +4 -1
  172. package/dist/runtime/server/utils/ai.d.ts +38 -35
  173. package/dist/runtime/server/utils/ai.mjs +7 -11
  174. package/dist/runtime/server/utils/analytics-query.d.ts +4 -4
  175. package/dist/runtime/server/utils/auth.d.ts +25 -25
  176. package/dist/runtime/server/utils/auth.mjs +22 -8
  177. package/dist/runtime/server/utils/bots.d.ts +7 -7
  178. package/dist/runtime/server/utils/browser-utils.d.ts +26 -27
  179. package/dist/runtime/server/utils/cache.d.ts +20 -20
  180. package/dist/runtime/server/utils/cms/collections.mjs +1 -6
  181. package/dist/runtime/server/utils/cms/common.mjs +1 -0
  182. package/dist/runtime/server/utils/cms/markdown.d.ts +2 -2
  183. package/dist/runtime/server/utils/cms/markdown.mjs +5 -5
  184. package/dist/runtime/server/utils/cms/mutations.mjs +8 -23
  185. package/dist/runtime/server/utils/cms/navigation.mjs +4 -4
  186. package/dist/runtime/server/utils/cms/path.d.ts +1 -0
  187. package/dist/runtime/server/utils/cms/path.mjs +8 -2
  188. package/dist/runtime/server/utils/cms/references.mjs +1 -7
  189. package/dist/runtime/server/utils/cms/search.d.ts +2 -2
  190. package/dist/runtime/server/utils/cms/sync.mjs +4 -2
  191. package/dist/runtime/server/utils/cms/taxonomy.d.ts +2 -2
  192. package/dist/runtime/server/utils/cms.d.ts +1 -1
  193. package/dist/runtime/server/utils/cms.mjs +1 -5
  194. package/dist/runtime/server/utils/comments-filter.d.ts +9 -7
  195. package/dist/runtime/server/utils/comments.d.ts +68 -55
  196. package/dist/runtime/server/utils/comments.mjs +21 -9
  197. package/dist/runtime/server/utils/config.d.ts +2 -2
  198. package/dist/runtime/server/utils/console.d.ts +3 -5
  199. package/dist/runtime/server/utils/context.d.ts +10 -10
  200. package/dist/runtime/server/utils/crypto.d.ts +20 -20
  201. package/dist/runtime/server/utils/domains.mjs +3 -1
  202. package/dist/runtime/server/utils/drizzle.d.ts +24 -25
  203. package/dist/runtime/server/utils/drizzle.mjs +17 -17
  204. package/dist/runtime/server/utils/durable-object.d.ts +27 -25
  205. package/dist/runtime/server/utils/durable-object.mjs +3 -10
  206. package/dist/runtime/server/utils/email-inbound.d.ts +10 -10
  207. package/dist/runtime/server/utils/impersonation.d.ts +18 -18
  208. package/dist/runtime/server/utils/legacy-hash.d.ts +23 -27
  209. package/dist/runtime/server/utils/lock.d.ts +20 -23
  210. package/dist/runtime/server/utils/mail.d.ts +19 -19
  211. package/dist/runtime/server/utils/mail.mjs +4 -2
  212. package/dist/runtime/server/utils/mcp.d.ts +20 -20
  213. package/dist/runtime/server/utils/mcp.mjs +22 -38
  214. package/dist/runtime/server/utils/notifications.d.ts +49 -38
  215. package/dist/runtime/server/utils/oauth.d.ts +3 -9
  216. package/dist/runtime/server/utils/organization.d.ts +28 -28
  217. package/dist/runtime/server/utils/organization.mjs +15 -5
  218. package/dist/runtime/server/utils/passwordless.d.ts +24 -24
  219. package/dist/runtime/server/utils/payments/checkout.d.ts +12 -12
  220. package/dist/runtime/server/utils/payments/checkout.mjs +1 -3
  221. package/dist/runtime/server/utils/payments/common.d.ts +3 -3
  222. package/dist/runtime/server/utils/payments/paddle.d.ts +4 -1
  223. package/dist/runtime/server/utils/payments/polar.d.ts +4 -1
  224. package/dist/runtime/server/utils/payments/stripe.mjs +5 -7
  225. package/dist/runtime/server/utils/payments/subscriptions.d.ts +14 -14
  226. package/dist/runtime/server/utils/payments/subscriptions.mjs +2 -6
  227. package/dist/runtime/server/utils/payments/usage.mjs +1 -3
  228. package/dist/runtime/server/utils/payments/webhooks.mjs +2 -2
  229. package/dist/runtime/server/utils/queue.d.ts +54 -58
  230. package/dist/runtime/server/utils/queue.mjs +2 -6
  231. package/dist/runtime/server/utils/rag.d.ts +23 -23
  232. package/dist/runtime/server/utils/rag.mjs +10 -5
  233. package/dist/runtime/server/utils/ratelimit.d.ts +21 -18
  234. package/dist/runtime/server/utils/rbac.d.ts +13 -15
  235. package/dist/runtime/server/utils/rbac.mjs +44 -10
  236. package/dist/runtime/server/utils/realtime.d.ts +53 -52
  237. package/dist/runtime/server/utils/role-env.d.ts +5 -4
  238. package/dist/runtime/server/utils/scheduled-task.d.ts +14 -15
  239. package/dist/runtime/server/utils/session.d.ts +40 -40
  240. package/dist/runtime/server/utils/sse.d.ts +23 -33
  241. package/dist/runtime/server/utils/sse.mjs +5 -14
  242. package/dist/runtime/server/utils/sso.mjs +3 -1
  243. package/dist/runtime/server/utils/storage.d.ts +20 -22
  244. package/dist/runtime/server/utils/storage.mjs +2 -2
  245. package/dist/runtime/server/utils/store/cart.d.ts +5 -3
  246. package/dist/runtime/server/utils/store/cart.mjs +14 -10
  247. package/dist/runtime/server/utils/store/checkout.mjs +4 -1
  248. package/dist/runtime/server/utils/store/common.d.ts +1 -1
  249. package/dist/runtime/server/utils/store/common.mjs +36 -12
  250. package/dist/runtime/server/utils/store/inventory.mjs +3 -1
  251. package/dist/runtime/server/utils/store/orders.mjs +32 -24
  252. package/dist/runtime/server/utils/store/vendor.d.ts +11 -1
  253. package/dist/runtime/server/utils/store/vendor.mjs +47 -0
  254. package/dist/runtime/server/utils/store-localization.d.ts +9 -27
  255. package/dist/runtime/server/utils/store-localization.mjs +3 -3
  256. package/dist/runtime/server/utils/table-names.d.ts +15 -15
  257. package/dist/runtime/server/utils/table-names.mjs +1 -1
  258. package/dist/runtime/server/utils/tenant.d.ts +12 -12
  259. package/dist/runtime/server/utils/tenant.mjs +7 -4
  260. package/dist/runtime/server/utils/totp.d.ts +18 -18
  261. package/dist/runtime/server/utils/tracker.d.ts +5 -5
  262. package/dist/runtime/server/utils/turnstile.d.ts +9 -9
  263. package/dist/runtime/server/utils/urn.d.ts +5 -8
  264. package/dist/runtime/server/utils/workflows.d.ts +30 -31
  265. package/dist/runtime/server/utils/workflows.mjs +2 -4
  266. package/dist/runtime/server.d.ts +2 -2
  267. package/dist/runtime/service.d.ts +10 -10
  268. package/dist/runtime/test-utils.d.ts +10 -10
  269. package/dist/runtime/test-utils.mjs +9 -2
  270. package/dist/runtime/types/ai.d.ts +14 -14
  271. package/dist/runtime/types/d1.d.ts +6 -11
  272. package/dist/runtime/types/durable-object.d.ts +4 -8
  273. package/dist/runtime/types/email.d.ts +3 -9
  274. package/dist/runtime/types/index.d.ts +15 -21
  275. package/dist/runtime/types/r2.d.ts +5 -5
  276. package/dist/runtime/types/store.d.ts +7 -0
  277. package/dist/runtime/types/workflows.d.ts +5 -6
  278. package/dist/runtime/workflows.d.ts +1 -3
  279. package/dist/types/ai.d.ts +10 -17
  280. package/dist/types/auth.d.ts +5 -3
  281. package/dist/types/cache.d.ts +7 -7
  282. package/dist/types/cms.d.ts +30 -5
  283. package/dist/types/comments.d.ts +23 -21
  284. package/dist/types/console.d.ts +1 -3
  285. package/dist/types/db.d.ts +7 -7
  286. package/dist/types/index.d.ts +1 -0
  287. package/dist/types/options.d.ts +36 -24
  288. package/dist/types/site.d.ts +8 -2
  289. package/dist/types/storage.d.ts +2 -1
  290. package/dist/types/store-options.d.ts +31 -26
  291. package/dist/types/studio.d.ts +79 -0
  292. package/dist/utils/bots.d.ts +7 -3
  293. package/dist/utils/cms-table-names.d.ts +1 -1
  294. package/dist/utils/drizzle.d.ts +13 -14
  295. package/dist/utils/email-inbound.d.ts +4 -4
  296. package/dist/utils/features.d.ts +19 -5
  297. package/dist/utils/mcp.d.ts +1 -0
  298. package/dist/utils/migration-lock.d.ts +15 -29
  299. package/dist/utils/overridable-routes.d.ts +12 -0
  300. package/dist/utils/pkg.d.ts +6 -7
  301. package/dist/utils/schema-diff.d.ts +7 -11
  302. package/dist/utils/store-schema.d.ts +4 -6
  303. package/dist/utils/tools.d.ts +3 -3
  304. package/package.json +55 -5
@@ -0,0 +1,658 @@
1
+ <script lang="ts" setup>
2
+ import { computed, onBeforeUnmount, onMounted, reactive, ref, watch } from "vue"
3
+
4
+ import type { StudioCropConfig, StudioCropResult, StudioZoomConfig } from "../../../types/studio"
5
+ import { parseAspectRatio } from "../composables/studio"
6
+
7
+ const props = defineProps<{
8
+ src: string
9
+ crop?: StudioCropConfig
10
+ zoom?: StudioZoomConfig | boolean
11
+ hideActions?: boolean
12
+ }>()
13
+
14
+ const emit = defineEmits<{
15
+ apply: [result: StudioCropResult]
16
+ cancel: []
17
+ ready: []
18
+ }>()
19
+
20
+ const config = computed(() => ({
21
+ aspect: props.crop?.aspect ?? null,
22
+ presets: props.crop?.presets ?? [],
23
+ shape: props.crop?.shape ?? "rect",
24
+ fixed: props.crop?.fixed ?? false,
25
+ naked: props.crop?.naked ?? false,
26
+ zoom: props.zoom === false ? false : typeof props.zoom === "object" ? props.zoom : {},
27
+ size: props.crop?.size,
28
+ width: props.crop?.width,
29
+ height: props.crop?.height,
30
+ format: props.crop?.format ?? (props.crop?.shape === "round" ? "image/png" : "image/webp"),
31
+ quality: props.crop?.quality ?? 0.9,
32
+ }))
33
+
34
+ const activeAspect = ref<number | null>(
35
+ config.value.shape === "round"
36
+ ? 1
37
+ : (parseAspectRatio(config.value.aspect) ??
38
+ (config.value.width && config.value.height
39
+ ? config.value.width / config.value.height
40
+ : null)),
41
+ )
42
+
43
+ const rotation = ref(0)
44
+ const containerRef = ref<HTMLElement>()
45
+ const canvasRef = ref<HTMLCanvasElement>()
46
+ const imgRef = ref<HTMLImageElement>()
47
+ const hoverCursor = ref("default")
48
+
49
+ let ctx: CanvasRenderingContext2D | null = null
50
+ let resizeObserver: ResizeObserver | null = null
51
+ let dragAction = ""
52
+ let startMouseX = 0
53
+ let startMouseY = 0
54
+ let lastBaseScale = 0
55
+ let startCrop = { x: 0, y: 0, w: 0, h: 0 }
56
+ let startImg = { x: 0, y: 0, w: 0, h: 0 }
57
+
58
+ const imgState = reactive({ x: 0, y: 0, w: 0, h: 0, scale: 0 })
59
+ const cropState = reactive({ x: 0, y: 0, w: 0, h: 0 })
60
+
61
+ const HANDLE_SIZE = 12
62
+
63
+ function getRotatedDimensions() {
64
+ const img = imgRef.value
65
+ if (!img) return { w: 0, h: 0 }
66
+ const swapped = rotation.value % 180 !== 0
67
+ return {
68
+ w: swapped ? img.naturalHeight : img.naturalWidth,
69
+ h: swapped ? img.naturalWidth : img.naturalHeight,
70
+ }
71
+ }
72
+
73
+ function getBounds() {
74
+ if (!canvasRef.value) return { left: 0, top: 0, right: 0, bottom: 0, w: 0, h: 0 }
75
+ const cw = canvasRef.value.width
76
+ const ch = canvasRef.value.height
77
+ if (config.value.naked) {
78
+ return { left: 0, top: 0, right: cw, bottom: ch, w: cw, h: ch }
79
+ }
80
+ const pad = 20
81
+ return {
82
+ left: Math.max(pad, imgState.x),
83
+ top: Math.max(pad, imgState.y),
84
+ right: Math.min(cw - pad, imgState.x + imgState.w),
85
+ bottom: Math.min(ch - pad, imgState.y + imgState.h),
86
+ w: Math.min(cw - pad * 2, imgState.w),
87
+ h: Math.min(ch - pad * 2, imgState.h),
88
+ }
89
+ }
90
+
91
+ function applyAspect() {
92
+ const aspect = activeAspect.value
93
+ if (!aspect || !canvasRef.value) return
94
+ const bounds = getBounds()
95
+ const maxW = bounds.w
96
+ const maxH = bounds.h
97
+ if (maxW <= 0 || maxH <= 0) return
98
+
99
+ let w = cropState.w
100
+ let h = w / aspect
101
+ if (h > maxH) {
102
+ h = maxH
103
+ w = h * aspect
104
+ }
105
+ if (w > maxW) {
106
+ w = maxW
107
+ h = w / aspect
108
+ }
109
+ const cx = cropState.x + cropState.w / 2
110
+ const cy = cropState.y + cropState.h / 2
111
+ cropState.w = Math.max(40, w)
112
+ cropState.h = Math.max(40, h)
113
+ cropState.x = Math.max(bounds.left, Math.min(cx - cropState.w / 2, bounds.right - cropState.w))
114
+ cropState.y = Math.max(bounds.top, Math.min(cy - cropState.h / 2, bounds.bottom - cropState.h))
115
+ draw()
116
+ }
117
+
118
+ function initLayout(resetCrop = true) {
119
+ const container = containerRef.value
120
+ const canvas = canvasRef.value
121
+ const img = imgRef.value
122
+ if (!container || !canvas || !img || !img.naturalWidth) return
123
+
124
+ const cw = container.clientWidth
125
+ const ch = container.clientHeight
126
+ if (cw <= 0 || ch <= 0) return
127
+
128
+ canvas.width = cw
129
+ canvas.height = ch
130
+
131
+ const { w: natW, h: natH } = getRotatedDimensions()
132
+ const pad = config.value.naked ? 0 : 24
133
+ const availW = Math.max(40, cw - pad * 2)
134
+ const availH = Math.max(40, ch - pad * 2)
135
+
136
+ const baseScale = Math.min(availW / natW, availH / natH)
137
+ lastBaseScale = baseScale
138
+
139
+ if (resetCrop || imgState.scale === 0) {
140
+ imgState.scale = baseScale
141
+ imgState.w = natW * baseScale
142
+ imgState.h = natH * baseScale
143
+ imgState.x = (cw - imgState.w) / 2
144
+ imgState.y = (ch - imgState.h) / 2
145
+
146
+ const bounds = getBounds()
147
+ const targetAspect = activeAspect.value
148
+ if (targetAspect) {
149
+ let cwBox = bounds.w * 0.85
150
+ let chBox = cwBox / targetAspect
151
+ if (chBox > bounds.h * 0.85) {
152
+ chBox = bounds.h * 0.85
153
+ cwBox = chBox * targetAspect
154
+ }
155
+ cropState.w = cwBox
156
+ cropState.h = chBox
157
+ } else {
158
+ cropState.w = bounds.w * 0.85
159
+ cropState.h = bounds.h * 0.85
160
+ }
161
+ cropState.x = (cw - cropState.w) / 2
162
+ cropState.y = (ch - cropState.h) / 2
163
+ } else {
164
+ imgState.w = natW * imgState.scale
165
+ imgState.h = natH * imgState.scale
166
+ imgState.x = (cw - imgState.w) / 2
167
+ imgState.y = (ch - imgState.h) / 2
168
+ }
169
+
170
+ draw()
171
+ }
172
+
173
+ function draw() {
174
+ const canvas = canvasRef.value
175
+ const img = imgRef.value
176
+ if (!ctx || !canvas || !img) return
177
+
178
+ const cw = canvas.width
179
+ const ch = canvas.height
180
+ ctx.clearRect(0, 0, cw, ch)
181
+
182
+ // Draw rotated image
183
+ ctx.save()
184
+ const centerX = imgState.x + imgState.w / 2
185
+ const centerY = imgState.y + imgState.h / 2
186
+ ctx.translate(centerX, centerY)
187
+ ctx.rotate((rotation.value * Math.PI) / 180)
188
+ const drawW = rotation.value % 180 !== 0 ? imgState.h : imgState.w
189
+ const drawH = rotation.value % 180 !== 0 ? imgState.w : imgState.h
190
+ ctx.drawImage(img, -drawW / 2, -drawH / 2, drawW, drawH)
191
+ ctx.restore()
192
+
193
+ // Darken outside crop box
194
+ ctx.save()
195
+ ctx.fillStyle = "rgba(0, 0, 0, 0.55)"
196
+ ctx.beginPath()
197
+ ctx.rect(0, 0, cw, ch)
198
+ if (config.value.shape === "round") {
199
+ const rx = cropState.w / 2
200
+ const ry = cropState.h / 2
201
+ ctx.ellipse(cropState.x + rx, cropState.y + ry, rx, ry, 0, 0, Math.PI * 2, true)
202
+ } else {
203
+ ctx.rect(cropState.x, cropState.y, cropState.w, cropState.h)
204
+ }
205
+ ctx.fill("evenodd")
206
+ ctx.restore()
207
+
208
+ // Crop border & rule-of-thirds grid
209
+ ctx.save()
210
+ ctx.strokeStyle = "#ffffff"
211
+ ctx.lineWidth = 1.5
212
+ if (config.value.shape === "round") {
213
+ const rx = cropState.w / 2
214
+ const ry = cropState.h / 2
215
+ ctx.beginPath()
216
+ ctx.ellipse(cropState.x + rx, cropState.y + ry, rx, ry, 0, 0, Math.PI * 2)
217
+ ctx.stroke()
218
+ } else {
219
+ ctx.strokeRect(cropState.x, cropState.y, cropState.w, cropState.h)
220
+ ctx.strokeStyle = "rgba(255, 255, 255, 0.25)"
221
+ ctx.lineWidth = 1
222
+ ctx.beginPath()
223
+ for (let i = 1; i <= 2; i++) {
224
+ const gx = cropState.x + (cropState.w / 3) * i
225
+ const gy = cropState.y + (cropState.h / 3) * i
226
+ ctx.moveTo(gx, cropState.y)
227
+ ctx.lineTo(gx, cropState.y + cropState.h)
228
+ ctx.moveTo(cropState.x, gy)
229
+ ctx.lineTo(cropState.x + cropState.w, gy)
230
+ }
231
+ ctx.stroke()
232
+ }
233
+
234
+ // Corner handles (when not fixed)
235
+ if (!config.value.fixed) {
236
+ ctx.fillStyle = "#ffffff"
237
+ const hs = 8
238
+ const corners = [
239
+ [cropState.x, cropState.y],
240
+ [cropState.x + cropState.w, cropState.y],
241
+ [cropState.x, cropState.y + cropState.h],
242
+ [cropState.x + cropState.w, cropState.y + cropState.h],
243
+ ]
244
+ for (const [cx, cy] of corners) {
245
+ ctx.fillRect(cx - hs / 2, cy - hs / 2, hs, hs)
246
+ }
247
+ }
248
+ ctx.restore()
249
+ }
250
+
251
+ function getHandleAt(mx: number, my: number): string {
252
+ if (!config.value.fixed) {
253
+ const hs = HANDLE_SIZE
254
+ const { x, y, w, h } = cropState
255
+ if (Math.abs(mx - x) <= hs && Math.abs(my - y) <= hs) return "nw"
256
+ if (Math.abs(mx - (x + w)) <= hs && Math.abs(my - y) <= hs) return "ne"
257
+ if (Math.abs(mx - x) <= hs && Math.abs(my - (y + h)) <= hs) return "sw"
258
+ if (Math.abs(mx - (x + w)) <= hs && Math.abs(my - (y + h)) <= hs) return "se"
259
+ }
260
+ if (
261
+ mx >= cropState.x &&
262
+ mx <= cropState.x + cropState.w &&
263
+ my >= cropState.y &&
264
+ my <= cropState.y + cropState.h
265
+ ) {
266
+ return config.value.fixed ? "pan" : "move"
267
+ }
268
+ return config.value.zoom ? "pan" : ""
269
+ }
270
+
271
+ function cursorForAction(action: string): string {
272
+ if (action === "nw" || action === "se") return "nwse-resize"
273
+ if (action === "ne" || action === "sw") return "nesw-resize"
274
+ if (action === "move" || action === "pan") return "grab"
275
+ return "default"
276
+ }
277
+
278
+ function onPointerDown(e: PointerEvent) {
279
+ const canvas = canvasRef.value
280
+ if (!canvas) return
281
+ const rect = canvas.getBoundingClientRect()
282
+ const mx = e.clientX - rect.left
283
+ const my = e.clientY - rect.top
284
+
285
+ dragAction = getHandleAt(mx, my)
286
+ if (!dragAction) return
287
+ canvas.setPointerCapture(e.pointerId)
288
+ startMouseX = mx
289
+ startMouseY = my
290
+ startCrop = { ...cropState }
291
+ startImg = { ...imgState }
292
+ }
293
+
294
+ function onPointerMove(e: PointerEvent) {
295
+ const canvas = canvasRef.value
296
+ if (!canvas) return
297
+ const rect = canvas.getBoundingClientRect()
298
+ const mx = e.clientX - rect.left
299
+ const my = e.clientY - rect.top
300
+
301
+ if (!dragAction) {
302
+ hoverCursor.value = cursorForAction(getHandleAt(mx, my))
303
+ return
304
+ }
305
+
306
+ const dx = mx - startMouseX
307
+ const dy = my - startMouseY
308
+ const bounds = getBounds()
309
+
310
+ if (dragAction === "move") {
311
+ cropState.x = Math.max(bounds.left, Math.min(startCrop.x + dx, bounds.right - startCrop.w))
312
+ cropState.y = Math.max(bounds.top, Math.min(startCrop.y + dy, bounds.bottom - startCrop.h))
313
+ } else if (dragAction === "pan") {
314
+ imgState.x = startImg.x + dx
315
+ imgState.y = startImg.y + dy
316
+ } else {
317
+ const aspect = activeAspect.value
318
+ let nx = startCrop.x
319
+ let ny = startCrop.y
320
+ let nw = startCrop.w
321
+ let nh = startCrop.h
322
+ const minSize = 40
323
+
324
+ if (dragAction.includes("e"))
325
+ nw = Math.max(minSize, Math.min(startCrop.w + dx, bounds.right - startCrop.x))
326
+ if (dragAction.includes("s"))
327
+ nh = Math.max(minSize, Math.min(startCrop.h + dy, bounds.bottom - startCrop.y))
328
+ if (dragAction.includes("w")) {
329
+ const maxDx = startCrop.w - minSize
330
+ const clampedDx = Math.max(bounds.left - startCrop.x, Math.min(dx, maxDx))
331
+ nx = startCrop.x + clampedDx
332
+ nw = startCrop.w - clampedDx
333
+ }
334
+ if (dragAction.includes("n")) {
335
+ const maxDy = startCrop.h - minSize
336
+ const clampedDy = Math.max(bounds.top - startCrop.y, Math.min(dy, maxDy))
337
+ ny = startCrop.y + clampedDy
338
+ nh = startCrop.h - clampedDy
339
+ }
340
+
341
+ if (aspect) {
342
+ nh = nw / aspect
343
+ if (ny + nh > bounds.bottom) {
344
+ nh = bounds.bottom - ny
345
+ nw = nh * aspect
346
+ }
347
+ if (nx + nw > bounds.right) {
348
+ nw = bounds.right - nx
349
+ nh = nw / aspect
350
+ }
351
+ }
352
+
353
+ cropState.x = nx
354
+ cropState.y = ny
355
+ cropState.w = Math.max(minSize, nw)
356
+ cropState.h = Math.max(minSize, nh)
357
+ }
358
+
359
+ draw()
360
+ }
361
+
362
+ function onPointerUp(e: PointerEvent) {
363
+ if (!dragAction) return
364
+ canvasRef.value?.releasePointerCapture(e.pointerId)
365
+ dragAction = ""
366
+ }
367
+
368
+ function onWheel(e: WheelEvent) {
369
+ if (!config.value.zoom) return
370
+ e.preventDefault()
371
+ const step = (typeof config.value.zoom === "object" ? config.value.zoom.step : undefined) ?? 0.08
372
+ const factor = e.deltaY < 0 ? 1 + step : 1 - step
373
+ zoomBy(factor, e)
374
+ }
375
+
376
+ function zoomBy(factor: number, e?: WheelEvent) {
377
+ if (!canvasRef.value || !imgRef.value) return
378
+ const minZoom =
379
+ (typeof config.value.zoom === "object" ? config.value.zoom.min : undefined) ??
380
+ lastBaseScale * 0.5
381
+ const maxZoom =
382
+ (typeof config.value.zoom === "object" ? config.value.zoom.max : undefined) ??
383
+ lastBaseScale * 10
384
+
385
+ const nextScale = Math.max(minZoom, Math.min(maxZoom, imgState.scale * factor))
386
+ const ratio = nextScale / imgState.scale
387
+ const rect = canvasRef.value.getBoundingClientRect()
388
+ const pivotX = e ? e.clientX - rect.left : canvasRef.value.width / 2
389
+ const pivotY = e ? e.clientY - rect.top : canvasRef.value.height / 2
390
+
391
+ const { w: natW, h: natH } = getRotatedDimensions()
392
+ imgState.scale = nextScale
393
+ imgState.w = natW * nextScale
394
+ imgState.h = natH * nextScale
395
+ imgState.x = pivotX - (pivotX - imgState.x) * ratio
396
+ imgState.y = pivotY - (pivotY - imgState.y) * ratio
397
+ draw()
398
+ }
399
+
400
+ function rotateLeft() {
401
+ rotation.value = (rotation.value - 90 + 360) % 360
402
+ initLayout(true)
403
+ }
404
+
405
+ function rotateRight() {
406
+ rotation.value = (rotation.value + 90) % 360
407
+ initLayout(true)
408
+ }
409
+
410
+ function reset() {
411
+ rotation.value = 0
412
+ initLayout(true)
413
+ }
414
+
415
+ function setAspect(val: string | number | null) {
416
+ if (config.value.shape === "round") return
417
+ activeAspect.value = parseAspectRatio(val)
418
+ applyAspect()
419
+ }
420
+
421
+ function apply() {
422
+ const img = imgRef.value
423
+ if (!img || imgState.scale <= 0) return
424
+
425
+ const relX = (cropState.x - imgState.x) / imgState.scale
426
+ const relY = (cropState.y - imgState.y) / imgState.scale
427
+ const relW = cropState.w / imgState.scale
428
+ const relH = cropState.h / imgState.scale
429
+
430
+ const outW = config.value.width ?? config.value.size ?? Math.max(1, Math.round(relW))
431
+ const outH = config.value.height ?? config.value.size ?? Math.max(1, Math.round(relH))
432
+
433
+ const outCanvas = document.createElement("canvas")
434
+ outCanvas.width = outW
435
+ outCanvas.height = outH
436
+ const outCtx = outCanvas.getContext("2d")
437
+ if (!outCtx) return
438
+
439
+ if (config.value.shape === "round") {
440
+ outCtx.beginPath()
441
+ outCtx.arc(outW / 2, outH / 2, Math.min(outW, outH) / 2, 0, Math.PI * 2)
442
+ outCtx.closePath()
443
+ outCtx.clip()
444
+ }
445
+
446
+ // Render rotated source onto an intermediate canvas so crop coordinates map 1:1
447
+ const { w: rotW, h: rotH } = getRotatedDimensions()
448
+ const tmpCanvas = document.createElement("canvas")
449
+ tmpCanvas.width = rotW
450
+ tmpCanvas.height = rotH
451
+ const tmpCtx = tmpCanvas.getContext("2d")
452
+ if (!tmpCtx) return
453
+
454
+ tmpCtx.translate(rotW / 2, rotH / 2)
455
+ tmpCtx.rotate((rotation.value * Math.PI) / 180)
456
+ tmpCtx.drawImage(img, -img.naturalWidth / 2, -img.naturalHeight / 2)
457
+
458
+ outCtx.drawImage(tmpCanvas, relX, relY, relW, relH, 0, 0, outW, outH)
459
+
460
+ const dataUrl = outCanvas.toDataURL(config.value.format, config.value.quality)
461
+ emit("apply", {
462
+ x: Math.round(relX),
463
+ y: Math.round(relY),
464
+ width: Math.round(relW),
465
+ height: Math.round(relH),
466
+ outWidth: outW,
467
+ outHeight: outH,
468
+ dataUrl,
469
+ })
470
+ }
471
+
472
+ async function loadImage() {
473
+ if (!props.src) return
474
+ const img = new Image()
475
+ img.crossOrigin = "anonymous"
476
+ img.onload = () => {
477
+ imgRef.value = img
478
+ initLayout(true)
479
+ emit("ready")
480
+ }
481
+ img.src = props.src
482
+ }
483
+
484
+ watch(
485
+ () => props.src,
486
+ () => {
487
+ rotation.value = 0
488
+ loadImage()
489
+ },
490
+ )
491
+
492
+ watch(
493
+ () => config.value.aspect,
494
+ (val) => {
495
+ if (config.value.shape === "round") return
496
+ activeAspect.value = parseAspectRatio(val)
497
+ applyAspect()
498
+ },
499
+ )
500
+
501
+ onMounted(() => {
502
+ if (canvasRef.value) {
503
+ ctx = canvasRef.value.getContext("2d")
504
+ }
505
+ if (containerRef.value && typeof ResizeObserver !== "undefined") {
506
+ resizeObserver = new ResizeObserver(() => initLayout(false))
507
+ resizeObserver.observe(containerRef.value)
508
+ }
509
+ loadImage()
510
+ })
511
+
512
+ onBeforeUnmount(() => {
513
+ resizeObserver?.disconnect()
514
+ })
515
+
516
+ defineExpose({
517
+ apply,
518
+ reset,
519
+ rotateLeft,
520
+ rotateRight,
521
+ zoomIn: () => zoomBy(1.15),
522
+ zoomOut: () => zoomBy(0.85),
523
+ })
524
+ </script>
525
+
526
+ <template>
527
+ <div class="q-cropper">
528
+ <div v-if="config.presets.length > 0 && config.shape !== 'round'" class="q-cropper-presets">
529
+ <UButton
530
+ v-for="preset in config.presets"
531
+ :key="preset.label"
532
+ :label="preset.label"
533
+ size="xs"
534
+ :color="activeAspect === parseAspectRatio(preset.value) ? 'primary' : 'neutral'"
535
+ :variant="activeAspect === parseAspectRatio(preset.value) ? 'solid' : 'outline'"
536
+ @click="setAspect(preset.value)"
537
+ />
538
+ </div>
539
+
540
+ <div ref="containerRef" class="q-cropper-stage">
541
+ <canvas
542
+ ref="canvasRef"
543
+ class="q-cropper-canvas"
544
+ :style="{ cursor: hoverCursor }"
545
+ @pointerdown="onPointerDown"
546
+ @pointermove="onPointerMove"
547
+ @pointerup="onPointerUp"
548
+ @pointercancel="onPointerUp"
549
+ @wheel="onWheel"
550
+ />
551
+ </div>
552
+
553
+ <div v-if="!hideActions" class="q-cropper-actions">
554
+ <div class="q-cropper-tools">
555
+ <UButton
556
+ icon="i-lucide-rotate-ccw"
557
+ label="90°"
558
+ size="xs"
559
+ color="neutral"
560
+ variant="outline"
561
+ title="Rotate Left"
562
+ @click="rotateLeft"
563
+ />
564
+ <UButton
565
+ icon="i-lucide-rotate-cw"
566
+ label="90°"
567
+ size="xs"
568
+ color="neutral"
569
+ variant="outline"
570
+ title="Rotate Right"
571
+ @click="rotateRight"
572
+ />
573
+ <UButton label="Reset" size="xs" color="neutral" variant="ghost" @click="reset" />
574
+ </div>
575
+ <div class="q-cropper-tools">
576
+ <UButton label="Cancel" size="xs" color="neutral" variant="ghost" @click="emit('cancel')" />
577
+ <UButton
578
+ icon="i-lucide-check"
579
+ label="Apply Crop"
580
+ size="xs"
581
+ color="primary"
582
+ variant="solid"
583
+ @click="apply"
584
+ />
585
+ </div>
586
+ </div>
587
+ </div>
588
+ </template>
589
+
590
+ <style scoped>
591
+ .q-cropper {
592
+ display: flex;
593
+ flex-direction: column;
594
+ width: 100%;
595
+ height: 100%;
596
+ min-height: 280px;
597
+ gap: 0.75rem;
598
+ }
599
+ .q-cropper-presets {
600
+ display: flex;
601
+ flex-wrap: wrap;
602
+ gap: 0.375rem;
603
+ }
604
+ .q-cropper-preset-btn {
605
+ padding: 0.25rem 0.625rem;
606
+ font-size: 0.75rem;
607
+ border-radius: 0.375rem;
608
+ border: 1px solid var(--ui-border, #cbd5e1);
609
+ background: transparent;
610
+ color: inherit;
611
+ cursor: pointer;
612
+ }
613
+ .q-cropper-preset-btn.is-active {
614
+ border-color: var(--ui-primary, #3b82f6);
615
+ background: color-mix(in srgb, var(--ui-primary, #3b82f6) 14%, transparent);
616
+ color: var(--ui-primary, #3b82f6);
617
+ }
618
+ .q-cropper-stage {
619
+ position: relative;
620
+ flex: 1;
621
+ min-height: 240px;
622
+ background: #0f172a;
623
+ border-radius: 0.5rem;
624
+ overflow: hidden;
625
+ }
626
+ .q-cropper-canvas {
627
+ display: block;
628
+ width: 100%;
629
+ height: 100%;
630
+ touch-action: none;
631
+ }
632
+ .q-cropper-actions {
633
+ display: flex;
634
+ align-items: center;
635
+ justify-content: space-between;
636
+ gap: 0.5rem;
637
+ flex-wrap: wrap;
638
+ }
639
+ .q-cropper-tools {
640
+ display: flex;
641
+ gap: 0.5rem;
642
+ }
643
+ .q-cropper-btn {
644
+ padding: 0.4375rem 0.875rem;
645
+ border-radius: 0.5rem;
646
+ border: 1px solid var(--ui-border, #cbd5e1);
647
+ background: var(--ui-bg, transparent);
648
+ color: inherit;
649
+ font-size: 0.8125rem;
650
+ font-weight: 500;
651
+ cursor: pointer;
652
+ }
653
+ .q-cropper-btn-primary {
654
+ border-color: var(--ui-primary, #3b82f6);
655
+ background: var(--ui-primary, #3b82f6);
656
+ color: #ffffff;
657
+ }
658
+ </style>