qarpeo 0.1.6 → 0.1.8
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/LICENSE +21 -21
- package/README.md +102 -102
- package/dist/module.mjs +1 -1
- package/dist/runtime/app/components/BlobImage.vue +100 -100
- package/dist/runtime/app/components/CMSBlocks.vue +93 -93
- package/dist/runtime/app/components/CMSContent.vue +23 -23
- package/dist/runtime/app/components/CMSImage.vue +49 -49
- package/dist/runtime/app/components/CMSLocaleSwitcher.vue +110 -110
- package/dist/runtime/app/components/CMSPreviewBanner.vue +79 -79
- package/dist/runtime/app/components/CMSVersionBanner.vue +49 -49
- package/dist/runtime/app/components/CMSVersionSwitcher.vue +140 -140
- package/dist/runtime/app/components/ContentRenderer.vue +80 -80
- package/dist/runtime/app/components/FileUpload.vue +196 -196
- package/dist/runtime/app/components/ImpersonationBanner.vue +57 -57
- package/dist/runtime/app/components/SignedIn.vue +13 -13
- package/dist/runtime/app/components/SignedOut.vue +13 -13
- package/dist/runtime/app/components/shiki.css +34 -34
- package/dist/runtime/app/pages/cms.vue +2249 -2249
- package/dist/runtime/app/pages/devtools/overview.vue +390 -390
- package/dist/runtime/app/pages/devtools/settings.vue +560 -560
- package/dist/runtime/app/pages/devtools.vue +165 -165
- package/dist/runtime/app/public/sw-notifications.mjs +52 -52
- package/dist/runtime/server/utils/cms.mjs +102 -18
- package/dist/runtime/types/auth-globals.d.ts +14 -14
- package/dist/runtime/types/imports.d.ts +58 -58
- package/package.json +3 -3
package/LICENSE
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2026 Qarpeo (https://qarpeo.com)
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Qarpeo (https://qarpeo.com)
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,102 +1,102 @@
|
|
|
1
|
-
# Qarpeo
|
|
2
|
-
|
|
3
|
-
> The Zero-Config Edge Platform for Nuxt & Cloudflare.
|
|
4
|
-
|
|
5
|
-
[](https://www.npmjs.com/package/qarpeo)
|
|
6
|
-
[](https://opensource.org/licenses/MIT)
|
|
7
|
-
|
|
8
|
-
**Qarpeo** bridges Nuxt and Cloudflare Workers into a seamless, high-velocity developer experience. One package, zero manual wrangler configuration, type-safe auto-imports, and global edge persistence across all 12 Cloudflare primitives.
|
|
9
|
-
|
|
10
|
-
Documentation: [https://qarpeo.com](https://qarpeo.com)
|
|
11
|
-
|
|
12
|
-
---
|
|
13
|
-
|
|
14
|
-
## Features
|
|
15
|
-
|
|
16
|
-
- ⚡ **Zero-Config Wrangler**: Auto-generates local and production `wrangler.json` from your Nuxt config.
|
|
17
|
-
- 🗄️ **Database Ready**: Native Cloudflare D1 with automatic Drizzle ORM.
|
|
18
|
-
- 📦 **Key-Value & Storage**: Cloudflare KV and R2 Blob storage with typed auto-imported clients.
|
|
19
|
-
- 🤖 **Edge AI & Vector Search**: Cloudflare Workers AI LLMs and Vectorize embeddings out of the box.
|
|
20
|
-
- 📨 **Queues & Background Tasks**: Cloudflare Queues producer with `defineQueueHandler` consumers.
|
|
21
|
-
- 🌐 **Browser Rendering**: Headless Chromium automation, screenshots, and PDFs via Cloudflare Browser Rendering.
|
|
22
|
-
- 📊 **Telemetry & Rate Limiting**: Cloudflare Analytics Engine and edge rate limiting with zero external Redis.
|
|
23
|
-
- 🚀 **Hyperdrive**: Pooled connections and query acceleration to external PostgreSQL and MySQL databases.
|
|
24
|
-
|
|
25
|
-
---
|
|
26
|
-
|
|
27
|
-
## Quick Start
|
|
28
|
-
|
|
29
|
-
### 1. Install
|
|
30
|
-
|
|
31
|
-
```bash
|
|
32
|
-
# Using Vite+
|
|
33
|
-
vp add qarpeo
|
|
34
|
-
|
|
35
|
-
# Using pnpm
|
|
36
|
-
pnpm add qarpeo
|
|
37
|
-
|
|
38
|
-
# Using npm
|
|
39
|
-
npm install qarpeo
|
|
40
|
-
```
|
|
41
|
-
|
|
42
|
-
### 2. Configure
|
|
43
|
-
|
|
44
|
-
Enable the Cloudflare primitives you need in `nuxt.config.ts`:
|
|
45
|
-
|
|
46
|
-
```ts [nuxt.config.ts]
|
|
47
|
-
export default defineNuxtConfig({
|
|
48
|
-
modules: ["qarpeo"],
|
|
49
|
-
|
|
50
|
-
qarpeo: {
|
|
51
|
-
db: true,
|
|
52
|
-
blob: true,
|
|
53
|
-
kv: true,
|
|
54
|
-
ai: true,
|
|
55
|
-
browser: true,
|
|
56
|
-
},
|
|
57
|
-
})
|
|
58
|
-
```
|
|
59
|
-
|
|
60
|
-
### 3. Use Anywhere in Server Routes
|
|
61
|
-
|
|
62
|
-
All bindings are auto-imported and typed:
|
|
63
|
-
|
|
64
|
-
```ts [server/api/example.get.ts]
|
|
65
|
-
export default defineEventHandler(async () => {
|
|
66
|
-
// Cloudflare KV
|
|
67
|
-
await kv.set("hello", "world")
|
|
68
|
-
|
|
69
|
-
// Cloudflare D1 + Drizzle
|
|
70
|
-
const allUsers = await db.select().from(schema.users)
|
|
71
|
-
|
|
72
|
-
// Cloudflare Workers AI
|
|
73
|
-
const aiResult = await ai.run("@cf/meta/llama-3.1-8b-instruct", {
|
|
74
|
-
prompt: "Summarize edge computing in 5 words",
|
|
75
|
-
})
|
|
76
|
-
|
|
77
|
-
return { kv: await kv.get("hello"), allUsers, aiResult }
|
|
78
|
-
})
|
|
79
|
-
```
|
|
80
|
-
|
|
81
|
-
### 4. CLI Tools (`qp` / `qarpeo`)
|
|
82
|
-
|
|
83
|
-
Qarpeo includes an integrated CLI for health diagnostics, database migrations, and schema management:
|
|
84
|
-
|
|
85
|
-
```bash
|
|
86
|
-
# Validate Cloudflare bindings, migrations, and secrets
|
|
87
|
-
pnpm qp doctor
|
|
88
|
-
|
|
89
|
-
# Validate against production/remote deployment criteria
|
|
90
|
-
pnpm qp doctor --remote
|
|
91
|
-
|
|
92
|
-
# Generate and apply D1 migrations
|
|
93
|
-
pnpm qp generate
|
|
94
|
-
pnpm qp migrate
|
|
95
|
-
pnpm qp migrate --remote
|
|
96
|
-
```
|
|
97
|
-
|
|
98
|
-
---
|
|
99
|
-
|
|
100
|
-
## License
|
|
101
|
-
|
|
102
|
-
[MIT](./LICENSE)
|
|
1
|
+
# Qarpeo
|
|
2
|
+
|
|
3
|
+
> The Zero-Config Edge Platform for Nuxt & Cloudflare.
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/qarpeo)
|
|
6
|
+
[](https://opensource.org/licenses/MIT)
|
|
7
|
+
|
|
8
|
+
**Qarpeo** bridges Nuxt and Cloudflare Workers into a seamless, high-velocity developer experience. One package, zero manual wrangler configuration, type-safe auto-imports, and global edge persistence across all 12 Cloudflare primitives.
|
|
9
|
+
|
|
10
|
+
Documentation: [https://qarpeo.com](https://qarpeo.com)
|
|
11
|
+
|
|
12
|
+
---
|
|
13
|
+
|
|
14
|
+
## Features
|
|
15
|
+
|
|
16
|
+
- ⚡ **Zero-Config Wrangler**: Auto-generates local and production `wrangler.json` from your Nuxt config.
|
|
17
|
+
- 🗄️ **Database Ready**: Native Cloudflare D1 with automatic Drizzle ORM.
|
|
18
|
+
- 📦 **Key-Value & Storage**: Cloudflare KV and R2 Blob storage with typed auto-imported clients.
|
|
19
|
+
- 🤖 **Edge AI & Vector Search**: Cloudflare Workers AI LLMs and Vectorize embeddings out of the box.
|
|
20
|
+
- 📨 **Queues & Background Tasks**: Cloudflare Queues producer with `defineQueueHandler` consumers.
|
|
21
|
+
- 🌐 **Browser Rendering**: Headless Chromium automation, screenshots, and PDFs via Cloudflare Browser Rendering.
|
|
22
|
+
- 📊 **Telemetry & Rate Limiting**: Cloudflare Analytics Engine and edge rate limiting with zero external Redis.
|
|
23
|
+
- 🚀 **Hyperdrive**: Pooled connections and query acceleration to external PostgreSQL and MySQL databases.
|
|
24
|
+
|
|
25
|
+
---
|
|
26
|
+
|
|
27
|
+
## Quick Start
|
|
28
|
+
|
|
29
|
+
### 1. Install
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
# Using Vite+
|
|
33
|
+
vp add qarpeo
|
|
34
|
+
|
|
35
|
+
# Using pnpm
|
|
36
|
+
pnpm add qarpeo
|
|
37
|
+
|
|
38
|
+
# Using npm
|
|
39
|
+
npm install qarpeo
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
### 2. Configure
|
|
43
|
+
|
|
44
|
+
Enable the Cloudflare primitives you need in `nuxt.config.ts`:
|
|
45
|
+
|
|
46
|
+
```ts [nuxt.config.ts]
|
|
47
|
+
export default defineNuxtConfig({
|
|
48
|
+
modules: ["qarpeo"],
|
|
49
|
+
|
|
50
|
+
qarpeo: {
|
|
51
|
+
db: true,
|
|
52
|
+
blob: true,
|
|
53
|
+
kv: true,
|
|
54
|
+
ai: true,
|
|
55
|
+
browser: true,
|
|
56
|
+
},
|
|
57
|
+
})
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
### 3. Use Anywhere in Server Routes
|
|
61
|
+
|
|
62
|
+
All bindings are auto-imported and typed:
|
|
63
|
+
|
|
64
|
+
```ts [server/api/example.get.ts]
|
|
65
|
+
export default defineEventHandler(async () => {
|
|
66
|
+
// Cloudflare KV
|
|
67
|
+
await kv.set("hello", "world")
|
|
68
|
+
|
|
69
|
+
// Cloudflare D1 + Drizzle
|
|
70
|
+
const allUsers = await db.select().from(schema.users)
|
|
71
|
+
|
|
72
|
+
// Cloudflare Workers AI
|
|
73
|
+
const aiResult = await ai.run("@cf/meta/llama-3.1-8b-instruct", {
|
|
74
|
+
prompt: "Summarize edge computing in 5 words",
|
|
75
|
+
})
|
|
76
|
+
|
|
77
|
+
return { kv: await kv.get("hello"), allUsers, aiResult }
|
|
78
|
+
})
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
### 4. CLI Tools (`qp` / `qarpeo`)
|
|
82
|
+
|
|
83
|
+
Qarpeo includes an integrated CLI for health diagnostics, database migrations, and schema management:
|
|
84
|
+
|
|
85
|
+
```bash
|
|
86
|
+
# Validate Cloudflare bindings, migrations, and secrets
|
|
87
|
+
pnpm qp doctor
|
|
88
|
+
|
|
89
|
+
# Validate against production/remote deployment criteria
|
|
90
|
+
pnpm qp doctor --remote
|
|
91
|
+
|
|
92
|
+
# Generate and apply D1 migrations
|
|
93
|
+
pnpm qp generate
|
|
94
|
+
pnpm qp migrate
|
|
95
|
+
pnpm qp migrate --remote
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
---
|
|
99
|
+
|
|
100
|
+
## License
|
|
101
|
+
|
|
102
|
+
[MIT](./LICENSE)
|
package/dist/module.mjs
CHANGED
|
@@ -1,100 +1,100 @@
|
|
|
1
|
-
<script lang="ts" setup>
|
|
2
|
-
import { computed } from "vue"
|
|
3
|
-
import { useStorage } from "../composables/storage"
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* `<BlobImage>` — Renders an optimized image stored in Qarpeo R2 blob storage.
|
|
7
|
-
* Supports named presets, on-the-fly resizing, format conversion, and responsive srcset generation.
|
|
8
|
-
*/
|
|
9
|
-
const props = withDefaults(defineProps<{
|
|
10
|
-
/** Storage key or pathname (e.g. "avatars/user-1.jpg") or absolute URL. */
|
|
11
|
-
src: string
|
|
12
|
-
/** Named transformation preset configured in `qarpeo.storage.presets`. */
|
|
13
|
-
preset?: string
|
|
14
|
-
/** Output image width in pixels. */
|
|
15
|
-
width?: number | string
|
|
16
|
-
/** Output image height in pixels. */
|
|
17
|
-
height?: number | string
|
|
18
|
-
/** Compression quality (1-100). */
|
|
19
|
-
quality?: number | string
|
|
20
|
-
/** Output format. */
|
|
21
|
-
format?: "webp" | "avif" | "jpeg" | "png"
|
|
22
|
-
/** Fit mode for resizing. */
|
|
23
|
-
fit?: "cover" | "contain" | "scale-down" | "crop" | "pad"
|
|
24
|
-
/** Image alternative text for accessibility. */
|
|
25
|
-
alt?: string
|
|
26
|
-
/** Image loading strategy. */
|
|
27
|
-
loading?: "lazy" | "eager"
|
|
28
|
-
/** Auto-generate responsive srcset (true) or provide a custom srcset string. */
|
|
29
|
-
srcset?: boolean | string
|
|
30
|
-
/** HTML sizes attribute for responsive layouts. */
|
|
31
|
-
sizes?: string
|
|
32
|
-
}>(), {
|
|
33
|
-
alt: "",
|
|
34
|
-
loading: "lazy",
|
|
35
|
-
srcset: false,
|
|
36
|
-
})
|
|
37
|
-
|
|
38
|
-
const { getOptimizedImageUrl } = useStorage()
|
|
39
|
-
|
|
40
|
-
const resolvedSrc = computed(() => {
|
|
41
|
-
if (!props.src) return ""
|
|
42
|
-
if ((props.src.startsWith("http://") || props.src.startsWith("https://")) && !props.preset) {
|
|
43
|
-
return props.src
|
|
44
|
-
}
|
|
45
|
-
return getOptimizedImageUrl(props.src, {
|
|
46
|
-
preset: props.preset,
|
|
47
|
-
width: props.width ? Number(props.width) : undefined,
|
|
48
|
-
height: props.height ? Number(props.height) : undefined,
|
|
49
|
-
quality: props.quality ? Number(props.quality) : undefined,
|
|
50
|
-
format: props.format,
|
|
51
|
-
fit: props.fit,
|
|
52
|
-
})
|
|
53
|
-
})
|
|
54
|
-
|
|
55
|
-
const resolvedSrcset = computed(() => {
|
|
56
|
-
if (!props.src || !props.srcset) return undefined
|
|
57
|
-
if (typeof props.srcset === "string") return props.srcset
|
|
58
|
-
|
|
59
|
-
const numWidth = props.width ? Number(props.width) : undefined
|
|
60
|
-
if (numWidth) {
|
|
61
|
-
const src1x = resolvedSrc.value
|
|
62
|
-
const src2x = getOptimizedImageUrl(props.src, {
|
|
63
|
-
preset: props.preset,
|
|
64
|
-
width: numWidth * 2,
|
|
65
|
-
height: props.height ? Number(props.height) * 2 : undefined,
|
|
66
|
-
quality: props.quality ? Number(props.quality) : undefined,
|
|
67
|
-
format: props.format,
|
|
68
|
-
fit: props.fit,
|
|
69
|
-
})
|
|
70
|
-
return `${src1x} 1x, ${src2x} 2x`
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
// Default responsive breakpoints
|
|
74
|
-
return [320, 640, 960, 1280]
|
|
75
|
-
.map((w) => {
|
|
76
|
-
const url = getOptimizedImageUrl(props.src, {
|
|
77
|
-
preset: props.preset,
|
|
78
|
-
width: w,
|
|
79
|
-
quality: props.quality ? Number(props.quality) : undefined,
|
|
80
|
-
format: props.format,
|
|
81
|
-
fit: props.fit,
|
|
82
|
-
})
|
|
83
|
-
return `${url} ${w}w`
|
|
84
|
-
})
|
|
85
|
-
.join(", ")
|
|
86
|
-
})
|
|
87
|
-
</script>
|
|
88
|
-
|
|
89
|
-
<template>
|
|
90
|
-
<img
|
|
91
|
-
:src="resolvedSrc"
|
|
92
|
-
:srcset="resolvedSrcset"
|
|
93
|
-
:sizes="sizes"
|
|
94
|
-
:width="width"
|
|
95
|
-
:height="height"
|
|
96
|
-
:alt="alt"
|
|
97
|
-
:loading="loading"
|
|
98
|
-
decoding="async"
|
|
99
|
-
/>
|
|
100
|
-
</template>
|
|
1
|
+
<script lang="ts" setup>
|
|
2
|
+
import { computed } from "vue"
|
|
3
|
+
import { useStorage } from "../composables/storage"
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* `<BlobImage>` — Renders an optimized image stored in Qarpeo R2 blob storage.
|
|
7
|
+
* Supports named presets, on-the-fly resizing, format conversion, and responsive srcset generation.
|
|
8
|
+
*/
|
|
9
|
+
const props = withDefaults(defineProps<{
|
|
10
|
+
/** Storage key or pathname (e.g. "avatars/user-1.jpg") or absolute URL. */
|
|
11
|
+
src: string
|
|
12
|
+
/** Named transformation preset configured in `qarpeo.storage.presets`. */
|
|
13
|
+
preset?: string
|
|
14
|
+
/** Output image width in pixels. */
|
|
15
|
+
width?: number | string
|
|
16
|
+
/** Output image height in pixels. */
|
|
17
|
+
height?: number | string
|
|
18
|
+
/** Compression quality (1-100). */
|
|
19
|
+
quality?: number | string
|
|
20
|
+
/** Output format. */
|
|
21
|
+
format?: "webp" | "avif" | "jpeg" | "png"
|
|
22
|
+
/** Fit mode for resizing. */
|
|
23
|
+
fit?: "cover" | "contain" | "scale-down" | "crop" | "pad"
|
|
24
|
+
/** Image alternative text for accessibility. */
|
|
25
|
+
alt?: string
|
|
26
|
+
/** Image loading strategy. */
|
|
27
|
+
loading?: "lazy" | "eager"
|
|
28
|
+
/** Auto-generate responsive srcset (true) or provide a custom srcset string. */
|
|
29
|
+
srcset?: boolean | string
|
|
30
|
+
/** HTML sizes attribute for responsive layouts. */
|
|
31
|
+
sizes?: string
|
|
32
|
+
}>(), {
|
|
33
|
+
alt: "",
|
|
34
|
+
loading: "lazy",
|
|
35
|
+
srcset: false,
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
const { getOptimizedImageUrl } = useStorage()
|
|
39
|
+
|
|
40
|
+
const resolvedSrc = computed(() => {
|
|
41
|
+
if (!props.src) return ""
|
|
42
|
+
if ((props.src.startsWith("http://") || props.src.startsWith("https://")) && !props.preset) {
|
|
43
|
+
return props.src
|
|
44
|
+
}
|
|
45
|
+
return getOptimizedImageUrl(props.src, {
|
|
46
|
+
preset: props.preset,
|
|
47
|
+
width: props.width ? Number(props.width) : undefined,
|
|
48
|
+
height: props.height ? Number(props.height) : undefined,
|
|
49
|
+
quality: props.quality ? Number(props.quality) : undefined,
|
|
50
|
+
format: props.format,
|
|
51
|
+
fit: props.fit,
|
|
52
|
+
})
|
|
53
|
+
})
|
|
54
|
+
|
|
55
|
+
const resolvedSrcset = computed(() => {
|
|
56
|
+
if (!props.src || !props.srcset) return undefined
|
|
57
|
+
if (typeof props.srcset === "string") return props.srcset
|
|
58
|
+
|
|
59
|
+
const numWidth = props.width ? Number(props.width) : undefined
|
|
60
|
+
if (numWidth) {
|
|
61
|
+
const src1x = resolvedSrc.value
|
|
62
|
+
const src2x = getOptimizedImageUrl(props.src, {
|
|
63
|
+
preset: props.preset,
|
|
64
|
+
width: numWidth * 2,
|
|
65
|
+
height: props.height ? Number(props.height) * 2 : undefined,
|
|
66
|
+
quality: props.quality ? Number(props.quality) : undefined,
|
|
67
|
+
format: props.format,
|
|
68
|
+
fit: props.fit,
|
|
69
|
+
})
|
|
70
|
+
return `${src1x} 1x, ${src2x} 2x`
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// Default responsive breakpoints
|
|
74
|
+
return [320, 640, 960, 1280]
|
|
75
|
+
.map((w) => {
|
|
76
|
+
const url = getOptimizedImageUrl(props.src, {
|
|
77
|
+
preset: props.preset,
|
|
78
|
+
width: w,
|
|
79
|
+
quality: props.quality ? Number(props.quality) : undefined,
|
|
80
|
+
format: props.format,
|
|
81
|
+
fit: props.fit,
|
|
82
|
+
})
|
|
83
|
+
return `${url} ${w}w`
|
|
84
|
+
})
|
|
85
|
+
.join(", ")
|
|
86
|
+
})
|
|
87
|
+
</script>
|
|
88
|
+
|
|
89
|
+
<template>
|
|
90
|
+
<img
|
|
91
|
+
:src="resolvedSrc"
|
|
92
|
+
:srcset="resolvedSrcset"
|
|
93
|
+
:sizes="sizes"
|
|
94
|
+
:width="width"
|
|
95
|
+
:height="height"
|
|
96
|
+
:alt="alt"
|
|
97
|
+
:loading="loading"
|
|
98
|
+
decoding="async"
|
|
99
|
+
/>
|
|
100
|
+
</template>
|
|
@@ -1,93 +1,93 @@
|
|
|
1
|
-
<script lang="ts" setup>
|
|
2
|
-
import { resolveDynamicComponent, h } from "vue"
|
|
3
|
-
import type { CMSBlockData } from "../../../types"
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* `<CMSBlocks>` / `<CMSPageBuilder>` — Renders an array of typed CMS block objects.
|
|
7
|
-
* Resolves each block to a matching Vue component (`<BlockHero>`, `<Hero>`, etc.),
|
|
8
|
-
* falls back to scoped slots (`#hero="{ block, index }"`), or a generic `#default` slot.
|
|
9
|
-
*/
|
|
10
|
-
const props = withDefaults(defineProps<{
|
|
11
|
-
blocks?: CMSBlockData[]
|
|
12
|
-
prefix?: string
|
|
13
|
-
as?: string
|
|
14
|
-
}>(), {
|
|
15
|
-
blocks: () => [],
|
|
16
|
-
prefix: "Block",
|
|
17
|
-
as: "div",
|
|
18
|
-
})
|
|
19
|
-
|
|
20
|
-
const slots = defineSlots<{
|
|
21
|
-
default?(props: { block: CMSBlockData; index: number }): any
|
|
22
|
-
[key: string]: ((props: { block: CMSBlockData; index: number }) => any) | undefined
|
|
23
|
-
}>()
|
|
24
|
-
|
|
25
|
-
function toPascalCase(str: string): string {
|
|
26
|
-
return str
|
|
27
|
-
.replace(/[-_](\w)/g, (_, c) => c.toUpperCase())
|
|
28
|
-
.replace(/^\w/, (c) => c.toUpperCase())
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
function renderBlock(block: CMSBlockData, index: number) {
|
|
32
|
-
const type = block._type || "unknown"
|
|
33
|
-
const key = block._id || `${type}-${index}`
|
|
34
|
-
|
|
35
|
-
// 1. Scoped slot for this exact block type
|
|
36
|
-
if (slots[type]) {
|
|
37
|
-
return h("div", { key, class: `qarpeo-block qarpeo-block-${type}` }, slots[type]!({ block, index }))
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
// 2. Generic default slot
|
|
41
|
-
if (slots.default) {
|
|
42
|
-
return h("div", { key, class: `qarpeo-block qarpeo-block-${type}` }, slots.default({ block, index }))
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
// 3. Dynamic component resolution: <BlockHero /> or <Hero />
|
|
46
|
-
const pascalType = toPascalCase(type)
|
|
47
|
-
const prefixedName = props.prefix ? `${props.prefix}${pascalType}` : pascalType
|
|
48
|
-
|
|
49
|
-
let component: any = null
|
|
50
|
-
try {
|
|
51
|
-
component = resolveDynamicComponent(prefixedName)
|
|
52
|
-
if (typeof component === "string" && component === prefixedName) {
|
|
53
|
-
if (props.prefix) {
|
|
54
|
-
const fallback = resolveDynamicComponent(pascalType)
|
|
55
|
-
component = typeof fallback !== "string" || fallback !== pascalType ? fallback : null
|
|
56
|
-
} else {
|
|
57
|
-
component = null
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
} catch {
|
|
61
|
-
component = null
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
if (component) {
|
|
65
|
-
return h(component, { key, ...block, block, index, class: `qarpeo-block qarpeo-block-${type}` })
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
// 4. Dev fallback warning
|
|
69
|
-
if (import.meta.dev) {
|
|
70
|
-
return h(
|
|
71
|
-
"div",
|
|
72
|
-
{
|
|
73
|
-
key,
|
|
74
|
-
class: "rounded-lg border border-dashed border-amber-400 bg-amber-50/50 p-4 my-2 font-mono text-xs text-amber-700",
|
|
75
|
-
},
|
|
76
|
-
[
|
|
77
|
-
h("strong", `[CMSBlocks] Missing component for block "_type: ${type}"`),
|
|
78
|
-
h("p", { class: "mt-1 opacity-80" }, `Create <${prefixedName} /> or use slot #${type}`),
|
|
79
|
-
],
|
|
80
|
-
)
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
return null
|
|
84
|
-
}
|
|
85
|
-
</script>
|
|
86
|
-
|
|
87
|
-
<template>
|
|
88
|
-
<component :is="as" class="qarpeo-cms-blocks">
|
|
89
|
-
<template v-for="(block, index) in blocks" :key="block._id || `${block._type}-${index}`">
|
|
90
|
-
<component :is="() => renderBlock(block, index)" />
|
|
91
|
-
</template>
|
|
92
|
-
</component>
|
|
93
|
-
</template>
|
|
1
|
+
<script lang="ts" setup>
|
|
2
|
+
import { resolveDynamicComponent, h } from "vue"
|
|
3
|
+
import type { CMSBlockData } from "../../../types"
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* `<CMSBlocks>` / `<CMSPageBuilder>` — Renders an array of typed CMS block objects.
|
|
7
|
+
* Resolves each block to a matching Vue component (`<BlockHero>`, `<Hero>`, etc.),
|
|
8
|
+
* falls back to scoped slots (`#hero="{ block, index }"`), or a generic `#default` slot.
|
|
9
|
+
*/
|
|
10
|
+
const props = withDefaults(defineProps<{
|
|
11
|
+
blocks?: CMSBlockData[]
|
|
12
|
+
prefix?: string
|
|
13
|
+
as?: string
|
|
14
|
+
}>(), {
|
|
15
|
+
blocks: () => [],
|
|
16
|
+
prefix: "Block",
|
|
17
|
+
as: "div",
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
const slots = defineSlots<{
|
|
21
|
+
default?(props: { block: CMSBlockData; index: number }): any
|
|
22
|
+
[key: string]: ((props: { block: CMSBlockData; index: number }) => any) | undefined
|
|
23
|
+
}>()
|
|
24
|
+
|
|
25
|
+
function toPascalCase(str: string): string {
|
|
26
|
+
return str
|
|
27
|
+
.replace(/[-_](\w)/g, (_, c) => c.toUpperCase())
|
|
28
|
+
.replace(/^\w/, (c) => c.toUpperCase())
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function renderBlock(block: CMSBlockData, index: number) {
|
|
32
|
+
const type = block._type || "unknown"
|
|
33
|
+
const key = block._id || `${type}-${index}`
|
|
34
|
+
|
|
35
|
+
// 1. Scoped slot for this exact block type
|
|
36
|
+
if (slots[type]) {
|
|
37
|
+
return h("div", { key, class: `qarpeo-block qarpeo-block-${type}` }, slots[type]!({ block, index }))
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// 2. Generic default slot
|
|
41
|
+
if (slots.default) {
|
|
42
|
+
return h("div", { key, class: `qarpeo-block qarpeo-block-${type}` }, slots.default({ block, index }))
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// 3. Dynamic component resolution: <BlockHero /> or <Hero />
|
|
46
|
+
const pascalType = toPascalCase(type)
|
|
47
|
+
const prefixedName = props.prefix ? `${props.prefix}${pascalType}` : pascalType
|
|
48
|
+
|
|
49
|
+
let component: any = null
|
|
50
|
+
try {
|
|
51
|
+
component = resolveDynamicComponent(prefixedName)
|
|
52
|
+
if (typeof component === "string" && component === prefixedName) {
|
|
53
|
+
if (props.prefix) {
|
|
54
|
+
const fallback = resolveDynamicComponent(pascalType)
|
|
55
|
+
component = typeof fallback !== "string" || fallback !== pascalType ? fallback : null
|
|
56
|
+
} else {
|
|
57
|
+
component = null
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
} catch {
|
|
61
|
+
component = null
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
if (component) {
|
|
65
|
+
return h(component, { key, ...block, block, index, class: `qarpeo-block qarpeo-block-${type}` })
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// 4. Dev fallback warning
|
|
69
|
+
if (import.meta.dev) {
|
|
70
|
+
return h(
|
|
71
|
+
"div",
|
|
72
|
+
{
|
|
73
|
+
key,
|
|
74
|
+
class: "rounded-lg border border-dashed border-amber-400 bg-amber-50/50 p-4 my-2 font-mono text-xs text-amber-700",
|
|
75
|
+
},
|
|
76
|
+
[
|
|
77
|
+
h("strong", `[CMSBlocks] Missing component for block "_type: ${type}"`),
|
|
78
|
+
h("p", { class: "mt-1 opacity-80" }, `Create <${prefixedName} /> or use slot #${type}`),
|
|
79
|
+
],
|
|
80
|
+
)
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
return null
|
|
84
|
+
}
|
|
85
|
+
</script>
|
|
86
|
+
|
|
87
|
+
<template>
|
|
88
|
+
<component :is="as" class="qarpeo-cms-blocks">
|
|
89
|
+
<template v-for="(block, index) in blocks" :key="block._id || `${block._type}-${index}`">
|
|
90
|
+
<component :is="() => renderBlock(block, index)" />
|
|
91
|
+
</template>
|
|
92
|
+
</component>
|
|
93
|
+
</template>
|