qarpeo 0.4.12 → 0.4.14
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.
- package/README.md +12 -6
- package/dist/apps/cms.d.ts +1 -1
- package/dist/apps/comments.d.ts +1 -1
- package/dist/apps/payments.d.ts +1 -1
- package/dist/apps/store.d.ts +1 -1
- package/dist/chunks/{manifest.get.mjs → tools.mjs} +445 -430
- package/dist/cli/index.mjs +756 -746
- package/dist/core/aliases.d.ts +1 -1
- package/dist/core/context.d.ts +1 -1
- package/dist/core/d1-migrate.d.ts +1 -1
- package/dist/core/devtools.d.ts +1 -1
- package/dist/core/nitro.d.ts +1 -1
- package/dist/core/schema.d.ts +1 -1
- package/dist/core/server-utils.d.ts +1 -1
- package/dist/core/wrangler.d.ts +1 -1
- package/dist/fate/index.d.ts +8 -8
- package/dist/fate/index.mjs +3 -1
- package/dist/features/agents.d.ts +1 -1
- package/dist/features/auth.d.ts +1 -1
- package/dist/features/bots.d.ts +1 -1
- package/dist/features/console.d.ts +1 -1
- package/dist/features/fate.d.ts +1 -1
- package/dist/features/mail.d.ts +1 -1
- package/dist/features/mcp.d.ts +1 -1
- package/dist/features/multitenant.d.ts +1 -1
- package/dist/features/notifications.d.ts +1 -1
- package/dist/features/realtime.d.ts +1 -1
- package/dist/features/studio.d.ts +4 -0
- package/dist/module.d.ts +1 -1
- package/dist/module.mjs +5293 -5232
- package/dist/primitives/ai.d.ts +1 -1
- package/dist/primitives/analytics.d.ts +1 -1
- package/dist/primitives/blob.d.ts +1 -1
- package/dist/primitives/browser.d.ts +1 -1
- package/dist/primitives/cache.d.ts +1 -1
- package/dist/primitives/d1.d.ts +1 -1
- package/dist/primitives/do.d.ts +1 -1
- package/dist/primitives/email.d.ts +1 -1
- package/dist/primitives/hyperdrive.d.ts +1 -1
- package/dist/primitives/kv.d.ts +1 -1
- package/dist/primitives/queue.d.ts +1 -1
- package/dist/primitives/ratelimit.d.ts +1 -1
- package/dist/primitives/vectorize.d.ts +1 -1
- package/dist/primitives/workflows.d.ts +1 -1
- package/dist/runtime/ai.mjs +4 -1
- package/dist/runtime/app/components/CMSEditor.vue +439 -0
- package/dist/runtime/app/components/CMSEditorImageNode.vue +90 -0
- package/dist/runtime/app/components/CMSEditorLinkPopover.vue +120 -0
- package/dist/runtime/app/components/QDropZone.vue +327 -0
- package/dist/runtime/app/components/QImageCropper.vue +658 -0
- package/dist/runtime/app/components/QImageStudio.vue +300 -0
- package/dist/runtime/app/components/QImg.vue +7 -4
- package/dist/runtime/app/composables/analytics.d.ts +8 -8
- package/dist/runtime/app/composables/api-tokens.d.ts +5 -5
- package/dist/runtime/app/composables/auth.d.ts +23 -19
- package/dist/runtime/app/composables/chat.d.ts +7 -6
- package/dist/runtime/app/composables/cms-preview.d.ts +7 -8
- package/dist/runtime/app/composables/cms.d.ts +6 -6
- package/dist/runtime/app/composables/comments.d.ts +5 -5
- package/dist/runtime/app/composables/comments.mjs +7 -4
- package/dist/runtime/app/composables/console.d.ts +6 -14
- package/dist/runtime/app/composables/docs-version.d.ts +8 -8
- package/dist/runtime/app/composables/impersonation.d.ts +5 -5
- package/dist/runtime/app/composables/organization.d.ts +5 -5
- package/dist/runtime/app/composables/passkey.d.ts +5 -5
- package/dist/runtime/app/composables/passwordless.d.ts +5 -5
- package/dist/runtime/app/composables/payments.d.ts +5 -5
- package/dist/runtime/app/composables/rbac.d.ts +5 -5
- package/dist/runtime/app/composables/site.d.ts +2 -2
- package/dist/runtime/app/composables/sse.d.ts +20 -33
- package/dist/runtime/app/composables/sse.mjs +6 -3
- package/dist/runtime/app/composables/storage.d.ts +6 -8
- package/dist/runtime/app/composables/store.d.ts +37 -36
- package/dist/runtime/app/composables/store.mjs +7 -6
- package/dist/runtime/app/composables/studio.d.ts +59 -0
- package/dist/runtime/app/composables/studio.mjs +129 -0
- package/dist/runtime/app/composables/tenant.d.ts +7 -7
- package/dist/runtime/app/composables/turnstile.d.ts +5 -5
- package/dist/runtime/app/composables/two-factor.d.ts +5 -5
- package/dist/runtime/app/pages/devtools/notifications.vue +1 -6
- package/dist/runtime/app/plugins/pwa.mjs +1 -3
- package/dist/runtime/app/utils/cms-editor.d.ts +25 -0
- package/dist/runtime/app/utils/cms-editor.mjs +43 -0
- package/dist/runtime/auth.d.ts +9 -9
- package/dist/runtime/blob.d.ts +1 -3
- package/dist/runtime/blob.mjs +3 -1
- package/dist/runtime/cache.d.ts +8 -6
- package/dist/runtime/cache.mjs +8 -11
- package/dist/runtime/db.d.ts +4 -3
- package/dist/runtime/drizzle.d.ts +2 -1
- package/dist/runtime/drizzle.mjs +2 -2
- package/dist/runtime/queue.d.ts +1 -0
- package/dist/runtime/replica.d.ts +6 -10
- package/dist/runtime/replica.mjs +3 -1
- package/dist/runtime/schema-mysql.d.ts +16 -32
- package/dist/runtime/schema-pg.d.ts +15 -31
- package/dist/runtime/schema-shared.d.ts +20 -17
- package/dist/runtime/schema.d.ts +21 -33
- package/dist/runtime/server/durable-objects/agent.mjs +4 -1
- package/dist/runtime/server/durable-objects/room.d.ts +4 -6
- package/dist/runtime/server/durable-objects/room.mjs +18 -8
- package/dist/runtime/server/plugins/comments.d.ts +2 -3
- package/dist/runtime/server/plugins/email-inbound.d.ts +1 -3
- package/dist/runtime/server/plugins/store.d.ts +2 -3
- package/dist/runtime/server/routes/__qarpeo/cloud/agents/run.post.d.ts +2 -2
- package/dist/runtime/server/routes/__qarpeo/cloud/cms/entry.get.mjs +10 -2
- package/dist/runtime/server/routes/__qarpeo/cloud/cms/entry.post.d.ts +2 -2
- package/dist/runtime/server/routes/__qarpeo/cloud/cms/entry.post.mjs +10 -2
- package/dist/runtime/server/routes/__qarpeo/cloud/cms.get.d.ts +2 -2
- package/dist/runtime/server/routes/__qarpeo/cloud/cms.get.mjs +7 -1
- package/dist/runtime/server/routes/__qarpeo/cloud/comments/moderate.post.d.ts +2 -2
- package/dist/runtime/server/routes/__qarpeo/cloud/comments/moderate.post.mjs +5 -1
- package/dist/runtime/server/routes/__qarpeo/cloud/comments.get.d.ts +1 -3
- package/dist/runtime/server/routes/__qarpeo/cloud/extras.get.d.ts +2 -2
- package/dist/runtime/server/routes/__qarpeo/cloud/extras.get.mjs +15 -4
- package/dist/runtime/server/routes/__qarpeo/cloud/mail/unsuppress.post.d.ts +2 -2
- package/dist/runtime/server/routes/__qarpeo/cloud/migrate/cms.post.mjs +13 -4
- package/dist/runtime/server/routes/__qarpeo/cloud/migrate/products.post.mjs +1 -1
- package/dist/runtime/server/routes/__qarpeo/cloud/migrate.post.d.ts +3 -3
- package/dist/runtime/server/routes/__qarpeo/cloud/migrate.post.mjs +22 -6
- package/dist/runtime/server/routes/__qarpeo/cloud/notifications/test.post.d.ts +2 -2
- package/dist/runtime/server/routes/__qarpeo/cloud/operations.get.d.ts +6 -5
- package/dist/runtime/server/routes/__qarpeo/cloud/store/order-status.post.d.ts +1 -3
- package/dist/runtime/server/routes/__qarpeo/cloud/store/order-status.post.mjs +14 -2
- package/dist/runtime/server/routes/__qarpeo/cloud/store/orders.get.d.ts +1 -3
- package/dist/runtime/server/routes/__qarpeo/cloud/store/orders.get.mjs +7 -1
- package/dist/runtime/server/routes/__qarpeo/cloud/store/products.get.d.ts +1 -3
- package/dist/runtime/server/routes/__qarpeo/cloud/tasks/run.post.d.ts +2 -2
- package/dist/runtime/server/routes/__qarpeo/cloud/users/action.post.d.ts +2 -2
- package/dist/runtime/server/routes/__qarpeo/cloud/users/action.post.mjs +5 -1
- package/dist/runtime/server/routes/__qarpeo/cloud/users.get.d.ts +6 -5
- package/dist/runtime/server/routes/__qarpeo/cloud/users.get.mjs +1 -3
- package/dist/runtime/server/routes/__qarpeo/mail/track/click/[id].get.mjs +2 -2
- package/dist/runtime/server/routes/__qarpeo/manifest.get.d.ts +2 -2
- package/dist/runtime/server/routes/__qarpeo/og.get.d.ts +2 -2
- package/dist/runtime/server/routes/__qarpeo/rbac/me.get.d.ts +2 -2
- package/dist/runtime/server/routes/__qarpeo/rbac/roles.delete.d.ts +2 -2
- package/dist/runtime/server/routes/__qarpeo/rbac/roles.delete.mjs +5 -1
- package/dist/runtime/server/routes/__qarpeo/rbac/roles.get.d.ts +2 -2
- package/dist/runtime/server/routes/__qarpeo/rbac/roles.get.mjs +1 -5
- package/dist/runtime/server/routes/__qarpeo/rbac/roles.post.d.ts +2 -2
- package/dist/runtime/server/routes/__qarpeo/rbac/roles.post.mjs +5 -1
- package/dist/runtime/server/routes/__qarpeo/rbac/users.post.d.ts +2 -2
- package/dist/runtime/server/routes/agents/[agent]/chat.post.mjs +1 -6
- package/dist/runtime/server/routes/agents/[agent]/clear.post.mjs +1 -6
- package/dist/runtime/server/routes/agents/[agent]/history.get.mjs +1 -6
- package/dist/runtime/server/routes/auth/2fa/disable.post.mjs +5 -1
- package/dist/runtime/server/routes/auth/2fa/verify.post.mjs +7 -1
- package/dist/runtime/server/routes/auth/magic-link/send.post.mjs +1 -1
- package/dist/runtime/server/routes/auth/otp/send.post.mjs +1 -1
- package/dist/runtime/server/routes/cms/search.get.mjs +2 -6
- package/dist/runtime/server/routes/comments/[id]/report.post.mjs +1 -4
- package/dist/runtime/server/routes/comments/[id].patch.mjs +1 -4
- package/dist/runtime/server/routes/comments/batch.post.mjs +1 -3
- package/dist/runtime/server/routes/comments/index.post.mjs +1 -5
- package/dist/runtime/server/routes/fate.mjs +1 -1
- package/dist/runtime/server/routes/mail/webhooks.post.mjs +1 -1
- package/dist/runtime/server/routes/sitemap.xml.get.mjs +2 -1
- package/dist/runtime/server/routes/storage/presigned-r2.post.d.ts +5 -6
- package/dist/runtime/server/routes/storage/presigned-r2.post.mjs +1 -1
- package/dist/runtime/server/routes/store/cart/items/[id].delete.mjs +1 -1
- package/dist/runtime/server/routes/store/cart/items/[id].patch.mjs +1 -1
- package/dist/runtime/server/routes/store/currencies.get.mjs +1 -4
- package/dist/runtime/server/routes/store/orders/[id].get.mjs +1 -1
- package/dist/runtime/server/routes/store/orders/download/[token].get.mjs +13 -4
- package/dist/runtime/server/routes/store/orders/index.get.mjs +1 -1
- package/dist/runtime/server/routes/store/tax/calculate.post.d.ts +2 -1
- package/dist/runtime/server/routes/store/tax/calculate.post.mjs +12 -3
- package/dist/runtime/server/routes/tenants/[tenant]/domains/[domain]/index.delete.mjs +4 -1
- package/dist/runtime/server/routes/tenants/[tenant]/domains/[domain]/verify.post.mjs +4 -1
- package/dist/runtime/server/utils/ai.d.ts +38 -35
- package/dist/runtime/server/utils/ai.mjs +7 -11
- package/dist/runtime/server/utils/analytics-query.d.ts +4 -4
- package/dist/runtime/server/utils/auth.d.ts +25 -25
- package/dist/runtime/server/utils/auth.mjs +22 -8
- package/dist/runtime/server/utils/bots.d.ts +7 -7
- package/dist/runtime/server/utils/browser-utils.d.ts +26 -27
- package/dist/runtime/server/utils/cache.d.ts +20 -20
- package/dist/runtime/server/utils/cms/collections.mjs +1 -6
- package/dist/runtime/server/utils/cms/common.mjs +1 -0
- package/dist/runtime/server/utils/cms/markdown.d.ts +2 -2
- package/dist/runtime/server/utils/cms/markdown.mjs +5 -5
- package/dist/runtime/server/utils/cms/mutations.mjs +8 -23
- package/dist/runtime/server/utils/cms/navigation.mjs +4 -4
- package/dist/runtime/server/utils/cms/path.d.ts +1 -0
- package/dist/runtime/server/utils/cms/path.mjs +8 -2
- package/dist/runtime/server/utils/cms/references.mjs +1 -7
- package/dist/runtime/server/utils/cms/search.d.ts +2 -2
- package/dist/runtime/server/utils/cms/sync.mjs +4 -2
- package/dist/runtime/server/utils/cms/taxonomy.d.ts +2 -2
- package/dist/runtime/server/utils/cms.d.ts +1 -1
- package/dist/runtime/server/utils/cms.mjs +1 -5
- package/dist/runtime/server/utils/comments-filter.d.ts +9 -7
- package/dist/runtime/server/utils/comments.d.ts +68 -55
- package/dist/runtime/server/utils/comments.mjs +21 -9
- package/dist/runtime/server/utils/config.d.ts +2 -2
- package/dist/runtime/server/utils/console.d.ts +3 -5
- package/dist/runtime/server/utils/context.d.ts +10 -10
- package/dist/runtime/server/utils/crypto.d.ts +20 -20
- package/dist/runtime/server/utils/domains.mjs +3 -1
- package/dist/runtime/server/utils/drizzle.d.ts +24 -25
- package/dist/runtime/server/utils/drizzle.mjs +17 -17
- package/dist/runtime/server/utils/durable-object.d.ts +27 -25
- package/dist/runtime/server/utils/durable-object.mjs +3 -10
- package/dist/runtime/server/utils/email-inbound.d.ts +10 -10
- package/dist/runtime/server/utils/impersonation.d.ts +18 -18
- package/dist/runtime/server/utils/legacy-hash.d.ts +23 -27
- package/dist/runtime/server/utils/lock.d.ts +20 -23
- package/dist/runtime/server/utils/mail.d.ts +19 -19
- package/dist/runtime/server/utils/mail.mjs +4 -2
- package/dist/runtime/server/utils/mcp.d.ts +20 -20
- package/dist/runtime/server/utils/mcp.mjs +22 -38
- package/dist/runtime/server/utils/notifications.d.ts +49 -38
- package/dist/runtime/server/utils/oauth.d.ts +3 -9
- package/dist/runtime/server/utils/organization.d.ts +28 -28
- package/dist/runtime/server/utils/organization.mjs +15 -5
- package/dist/runtime/server/utils/passwordless.d.ts +24 -24
- package/dist/runtime/server/utils/payments/checkout.d.ts +12 -12
- package/dist/runtime/server/utils/payments/checkout.mjs +1 -3
- package/dist/runtime/server/utils/payments/common.d.ts +3 -3
- package/dist/runtime/server/utils/payments/paddle.d.ts +4 -1
- package/dist/runtime/server/utils/payments/polar.d.ts +4 -1
- package/dist/runtime/server/utils/payments/stripe.mjs +5 -7
- package/dist/runtime/server/utils/payments/subscriptions.d.ts +14 -14
- package/dist/runtime/server/utils/payments/subscriptions.mjs +2 -6
- package/dist/runtime/server/utils/payments/usage.mjs +1 -3
- package/dist/runtime/server/utils/payments/webhooks.mjs +2 -2
- package/dist/runtime/server/utils/queue.d.ts +54 -58
- package/dist/runtime/server/utils/queue.mjs +2 -6
- package/dist/runtime/server/utils/rag.d.ts +23 -23
- package/dist/runtime/server/utils/rag.mjs +10 -5
- package/dist/runtime/server/utils/ratelimit.d.ts +21 -18
- package/dist/runtime/server/utils/rbac.d.ts +13 -15
- package/dist/runtime/server/utils/rbac.mjs +44 -10
- package/dist/runtime/server/utils/realtime.d.ts +53 -52
- package/dist/runtime/server/utils/role-env.d.ts +5 -4
- package/dist/runtime/server/utils/scheduled-task.d.ts +14 -15
- package/dist/runtime/server/utils/session.d.ts +40 -40
- package/dist/runtime/server/utils/sse.d.ts +23 -33
- package/dist/runtime/server/utils/sse.mjs +5 -14
- package/dist/runtime/server/utils/sso.mjs +3 -1
- package/dist/runtime/server/utils/storage.d.ts +20 -22
- package/dist/runtime/server/utils/storage.mjs +2 -2
- package/dist/runtime/server/utils/store/cart.d.ts +5 -3
- package/dist/runtime/server/utils/store/cart.mjs +14 -10
- package/dist/runtime/server/utils/store/checkout.mjs +4 -1
- package/dist/runtime/server/utils/store/common.d.ts +1 -1
- package/dist/runtime/server/utils/store/common.mjs +36 -12
- package/dist/runtime/server/utils/store/inventory.mjs +3 -1
- package/dist/runtime/server/utils/store/orders.mjs +32 -24
- package/dist/runtime/server/utils/store-localization.d.ts +9 -27
- package/dist/runtime/server/utils/store-localization.mjs +3 -3
- package/dist/runtime/server/utils/table-names.d.ts +15 -15
- package/dist/runtime/server/utils/table-names.mjs +1 -1
- package/dist/runtime/server/utils/tenant.d.ts +12 -12
- package/dist/runtime/server/utils/tenant.mjs +7 -4
- package/dist/runtime/server/utils/totp.d.ts +18 -18
- package/dist/runtime/server/utils/tracker.d.ts +5 -5
- package/dist/runtime/server/utils/turnstile.d.ts +9 -9
- package/dist/runtime/server/utils/urn.d.ts +5 -8
- package/dist/runtime/server/utils/workflows.d.ts +30 -31
- package/dist/runtime/server/utils/workflows.mjs +2 -4
- package/dist/runtime/server.d.ts +2 -2
- package/dist/runtime/service.d.ts +10 -10
- package/dist/runtime/test-utils.d.ts +10 -10
- package/dist/runtime/test-utils.mjs +9 -2
- package/dist/runtime/types/ai.d.ts +14 -14
- package/dist/runtime/types/d1.d.ts +6 -11
- package/dist/runtime/types/durable-object.d.ts +4 -8
- package/dist/runtime/types/email.d.ts +3 -9
- package/dist/runtime/types/index.d.ts +15 -21
- package/dist/runtime/types/r2.d.ts +5 -5
- package/dist/runtime/types/workflows.d.ts +5 -6
- package/dist/runtime/workflows.d.ts +1 -3
- package/dist/types/ai.d.ts +10 -17
- package/dist/types/auth.d.ts +5 -3
- package/dist/types/cache.d.ts +7 -7
- package/dist/types/cms.d.ts +30 -5
- package/dist/types/comments.d.ts +23 -21
- package/dist/types/console.d.ts +1 -3
- package/dist/types/db.d.ts +7 -7
- package/dist/types/index.d.ts +1 -0
- package/dist/types/options.d.ts +36 -24
- package/dist/types/site.d.ts +8 -2
- package/dist/types/storage.d.ts +2 -1
- package/dist/types/store-options.d.ts +10 -26
- package/dist/types/studio.d.ts +79 -0
- package/dist/utils/bots.d.ts +7 -3
- package/dist/utils/cms-table-names.d.ts +1 -1
- package/dist/utils/drizzle.d.ts +13 -14
- package/dist/utils/email-inbound.d.ts +4 -4
- package/dist/utils/features.d.ts +19 -5
- package/dist/utils/mcp.d.ts +1 -0
- package/dist/utils/migration-lock.d.ts +15 -29
- package/dist/utils/pkg.d.ts +6 -7
- package/dist/utils/schema-diff.d.ts +7 -11
- package/dist/utils/store-schema.d.ts +4 -6
- package/dist/utils/tools.d.ts +3 -3
- 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>
|