@voidzero-dev/vitepress-theme 0.0.2 → 0.0.3

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 (42) hide show
  1. package/dist/_virtual/_/plugin-vue/export-helper.js +11 -0
  2. package/{style.css → dist/index.css} +7 -7
  3. package/dist/index.d.ts +2 -0
  4. package/dist/index.js +3 -0
  5. package/dist/vitepress/components/Eyebrow.js +18 -0
  6. package/dist/vitepress/components/Footer.js +58 -0
  7. package/dist/vitepress/components/Header.js +34 -0
  8. package/dist/vitepress/components/RiveAnimation.js +117 -0
  9. package/dist/vitepress/components/Terminal.js +161 -0
  10. package/dist/vitepress/components/icons/VZIconBluesky.js +21 -0
  11. package/dist/vitepress/components/icons/VZIconGitHub.js +21 -0
  12. package/dist/vitepress/components/icons/VZIconLogo.js +24 -0
  13. package/dist/vitepress/components/icons/VZIconTwitter.js +21 -0
  14. package/dist/vitepress/components/terminal-animations/TerminalAnimation1.js +37 -0
  15. package/dist/vitepress/components/terminal-animations/TerminalAnimation2.js +44 -0
  16. package/dist/vitepress/components/terminal-animations/TerminalAnimation3.js +37 -0
  17. package/dist/vitepress/components/terminal-animations/TerminalAnimation4.js +37 -0
  18. package/dist/vitepress/components/terminal-animations/TerminalAnimation5.js +37 -0
  19. package/dist/vitepress/components/terminal-animations/TerminalAnimation6.js +37 -0
  20. package/dist/vitepress/index.d.ts +34 -0
  21. package/dist/vitepress/index.js +21 -0
  22. package/package.json +20 -18
  23. package/assets/checkmark.svg +0 -1
  24. package/assets/primary-button-background.jpg +0 -0
  25. package/assets/terminal-background.jpg +0 -0
  26. package/components/Eyebrow.vue +0 -11
  27. package/components/Footer.vue +0 -44
  28. package/components/Header.vue +0 -38
  29. package/components/RiveAnimation.vue +0 -144
  30. package/components/Terminal.vue +0 -165
  31. package/components/terminal-animations/TerminalAnimation1.vue +0 -53
  32. package/components/terminal-animations/TerminalAnimation2.vue +0 -58
  33. package/components/terminal-animations/TerminalAnimation3.vue +0 -45
  34. package/components/terminal-animations/TerminalAnimation4.vue +0 -49
  35. package/components/terminal-animations/TerminalAnimation5.vue +0 -50
  36. package/components/terminal-animations/TerminalAnimation6.vue +0 -54
  37. package/fonts/APK-Protocol-Medium.woff2 +0 -0
  38. package/fonts/KHTeka-Medium.woff2 +0 -0
  39. package/fonts/KHTeka-Regular.woff2 +0 -0
  40. package/fonts/KHTekaMono-Medium.woff2 +0 -0
  41. package/fonts/KHTekaMono-Regular.woff2 +0 -0
  42. package/index.ts +0 -44
@@ -0,0 +1,37 @@
1
+ import { createElementBlock, createElementVNode, defineComponent, onMounted, onUnmounted, openBlock } from "vue";
2
+ import Typewriter from "typewriter-effect/dist/core";
3
+
4
+ //#region src/vitepress/components/terminal-animations/TerminalAnimation3.vue
5
+ const _hoisted_1 = { class: "font-mono text-sm text-white leading-[1.5rem]" };
6
+ const _sfc_main = /* @__PURE__ */ defineComponent({
7
+ __name: "TerminalAnimation3",
8
+ props: { onAnimationComplete: { type: Function } },
9
+ setup(__props) {
10
+ const props = __props;
11
+ let typewriter;
12
+ onMounted(() => {
13
+ const target = document.getElementById("terminal-code");
14
+ typewriter = new Typewriter(target, {
15
+ loop: false,
16
+ delay: 1
17
+ });
18
+ typewriter.typeString(`<span>$ vite lint</span>`).pauseFor(200).pasteString(`<span class="block w-full h-[1rem]"></span>`).pasteString(`<div class="block text-grey"><span class="text-vite">VITE+ v1.0.0</span> <span class="text-aqua">lint</span></div>`).pauseFor(500).pasteString(`<div class="block text-grey">Found <span class="text-white">0 warnings</span> and <span class="text-white">0 errors</span>.</div>`).pasteString(`<div class="block text-grey"><span class="text-zest">✓</span> Finished in <span class="text-white">1ms</span> on <span class="text-white">3 files</span> with <span class="text-white">88 rules</span> using <span class="text-white">10 threads</span>.</div>`).pasteString(`<span class="block w-full h-[1rem]"></span>`).callFunction(() => {
19
+ if (props.onAnimationComplete) {
20
+ props.onAnimationComplete();
21
+ }
22
+ }).start();
23
+ });
24
+ onUnmounted(() => {
25
+ if (typewriter) {
26
+ typewriter.stop();
27
+ }
28
+ });
29
+ return (_ctx, _cache) => {
30
+ return openBlock(), createElementBlock("p", _hoisted_1, [..._cache[0] || (_cache[0] = [createElementVNode("span", { id: "terminal-code" }, null, -1)])]);
31
+ };
32
+ }
33
+ });
34
+ var TerminalAnimation3_default = _sfc_main;
35
+
36
+ //#endregion
37
+ export { TerminalAnimation3_default as default };
@@ -0,0 +1,37 @@
1
+ import { createElementBlock, createElementVNode, defineComponent, onMounted, onUnmounted, openBlock } from "vue";
2
+ import Typewriter from "typewriter-effect/dist/core";
3
+
4
+ //#region src/vitepress/components/terminal-animations/TerminalAnimation4.vue
5
+ const _hoisted_1 = { class: "font-mono text-sm text-white leading-[1.5rem]" };
6
+ const _sfc_main = /* @__PURE__ */ defineComponent({
7
+ __name: "TerminalAnimation4",
8
+ props: { onAnimationComplete: { type: Function } },
9
+ setup(__props) {
10
+ const props = __props;
11
+ let typewriter;
12
+ onMounted(() => {
13
+ const target = document.getElementById("terminal-code");
14
+ typewriter = new Typewriter(target, {
15
+ loop: false,
16
+ delay: 1
17
+ });
18
+ typewriter.typeString(`<span>$ vite fmt</span>`).pauseFor(200).pasteString(`<span class="block w-full h-[1rem]"></span>`).pasteString(`<div class="block text-grey"><span class="text-vite">VITE+ v1.0.0</span> <span class="text-aqua">fmt</span></div>`).pauseFor(500).pasteString(`<div class="block">src/App.css <span class="text-aqua">0ms</span> <span class="text-grey">(unchanged)</span></div>`).pasteString(`<div class="block">src/App.tsx <span class="text-aqua">1ms</span></div>`).pasteString(`<div class="block">src/index.css <span class="text-aqua">0ms</span> <span class="text-grey">(unchanged)</span></div>`).pasteString(`<div class="block">src/main.tsx <span class="text-aqua">1ms</span></div>`).pasteString(`<div class="block">src/vite-env.d.ts <span class="text-aqua">0ms</span> <span class="text-grey">(unchanged)</span></div>`).pasteString(`<div class="block"><span class="text-zest">✓</span> Formatted <span class="text-aqua">2 files</span> in <span class="text-aqua">2ms</span>.</div>`).pasteString(`<span class="block w-full h-[1rem]"></span>`).callFunction(() => {
19
+ if (props.onAnimationComplete) {
20
+ props.onAnimationComplete();
21
+ }
22
+ }).start();
23
+ });
24
+ onUnmounted(() => {
25
+ if (typewriter) {
26
+ typewriter.stop();
27
+ }
28
+ });
29
+ return (_ctx, _cache) => {
30
+ return openBlock(), createElementBlock("p", _hoisted_1, [..._cache[0] || (_cache[0] = [createElementVNode("span", { id: "terminal-code" }, null, -1)])]);
31
+ };
32
+ }
33
+ });
34
+ var TerminalAnimation4_default = _sfc_main;
35
+
36
+ //#endregion
37
+ export { TerminalAnimation4_default as default };
@@ -0,0 +1,37 @@
1
+ import { createElementBlock, createElementVNode, defineComponent, onMounted, onUnmounted, openBlock } from "vue";
2
+ import Typewriter from "typewriter-effect/dist/core";
3
+
4
+ //#region src/vitepress/components/terminal-animations/TerminalAnimation5.vue
5
+ const _hoisted_1 = { class: "font-mono text-sm text-white leading-[1.5rem]" };
6
+ const _sfc_main = /* @__PURE__ */ defineComponent({
7
+ __name: "TerminalAnimation5",
8
+ props: { onAnimationComplete: { type: Function } },
9
+ setup(__props) {
10
+ const props = __props;
11
+ let typewriter;
12
+ onMounted(() => {
13
+ const target = document.getElementById("terminal-code");
14
+ typewriter = new Typewriter(target, {
15
+ loop: false,
16
+ delay: 1
17
+ });
18
+ typewriter.typeString(`<span>$ vite test</span>`).pauseFor(200).pasteString(`<span class="block w-full h-[1rem]"></span>`).pasteString(`<div class="block"><span class="text-vite">VITE+ v1.0.0</span> <span class="text-aqua">test</span> RUN ~/vite-plus-demo</div>`).pasteString(`<span class="block w-full h-[1rem]"></span>`).pauseFor(300).pasteString(`<div class="block"><span class="text-zest">✓</span> test/hello.spec.ts <span class="text-grey">(1 test)</span> <span class="text-zest">1ms</span></div>`).pasteString(`<span class="block w-full h-[1rem]"></span>`).pasteString(`<div class="block text-grey">Test Files <span class="text-zest">1 passed</span> <span class="text-grey">(1)</span></div>`).pasteString(`<div class="block text-grey">Tests <span class="text-zest">1 passed</span> <span class="text-grey">(1)</span></div>`).pasteString(`<div class="block text-grey">Start at <span class="text-white">00:13:44</span></div>`).pasteString(`<div class="block text-grey">Duration <span class="text-white">199ms</span> <span class="text-grey">(transform 13ms, setup 0ms, collect 8ms, tests 1ms, environment 0ms, prepare 33ms)</span></div>`).pasteString(`<span class="block w-full h-[1rem]"></span>`).callFunction(() => {
19
+ if (props.onAnimationComplete) {
20
+ props.onAnimationComplete();
21
+ }
22
+ }).start();
23
+ });
24
+ onUnmounted(() => {
25
+ if (typewriter) {
26
+ typewriter.stop();
27
+ }
28
+ });
29
+ return (_ctx, _cache) => {
30
+ return openBlock(), createElementBlock("p", _hoisted_1, [..._cache[0] || (_cache[0] = [createElementVNode("span", { id: "terminal-code" }, null, -1)])]);
31
+ };
32
+ }
33
+ });
34
+ var TerminalAnimation5_default = _sfc_main;
35
+
36
+ //#endregion
37
+ export { TerminalAnimation5_default as default };
@@ -0,0 +1,37 @@
1
+ import { createElementBlock, createElementVNode, defineComponent, onMounted, onUnmounted, openBlock } from "vue";
2
+ import Typewriter from "typewriter-effect/dist/core";
3
+
4
+ //#region src/vitepress/components/terminal-animations/TerminalAnimation6.vue
5
+ const _hoisted_1 = { class: "font-mono text-sm text-white leading-[1.5rem]" };
6
+ const _sfc_main = /* @__PURE__ */ defineComponent({
7
+ __name: "TerminalAnimation6",
8
+ props: { onAnimationComplete: { type: Function } },
9
+ setup(__props) {
10
+ const props = __props;
11
+ let typewriter;
12
+ onMounted(() => {
13
+ const target = document.getElementById("terminal-code");
14
+ typewriter = new Typewriter(target, {
15
+ loop: false,
16
+ delay: 1
17
+ });
18
+ typewriter.typeString(`<span>$ vite build</span>`).pauseFor(200).pasteString(`<span class="block w-full h-[1rem]"></span>`).pasteString(`<div class="block"><span class="text-vite">VITE+ v1.0.0</span> <span class="text-aqua">building for production</span></div>`).pauseFor(100).pasteString(`<div class="block">transforming...</div>`).pauseFor(400).pasteString(`<div class="block"><span class="text-zest">✓</span> <span class="text-grey">32 modules transformed...</span></div>`).pauseFor(300).pasteString(`<div class="block">rendering chunks...</div>`).pasteString(`<div class="block">computing gzip size...</div>`).pasteString(`<div class="block text-grey"><span class="w-72 inline-block">dist/<span class="text-white">index.html</span></span>&nbsp;&nbsp;0.46 kB | gzip: 0.30 kB</div>`).pasteString(`<div class="block text-grey"><span class="w-72 inline-block">dist/assets/<span class="text-vite">react-CHdo91hT.svg</span></span>&nbsp;&nbsp;4.13 kB | gzip: 2.05 kB</div>`).pasteString(`<div class="block text-grey"><span class="w-72 inline-block">dist/assets/<span class="text-electric">index-D8b4DHJx.css</span></span>&nbsp;&nbsp;1.39 kB | gzip: 0.71 kB</div>`).pasteString(`<div class="block text-grey"><span class="w-72 inline-block">dist/assets/<span class="text-aqua">index-CAl1KfkQ.js</span></span>188.06 kB | gzip: 59.21 kB</div>`).pasteString(`<div class="block"><span class="text-zest">✓ built in 308ms</span></div>`).pasteString(`<span class="block w-full h-[1rem]"></span>`).callFunction(() => {
19
+ if (props.onAnimationComplete) {
20
+ props.onAnimationComplete();
21
+ }
22
+ }).start();
23
+ });
24
+ onUnmounted(() => {
25
+ if (typewriter) {
26
+ typewriter.stop();
27
+ }
28
+ });
29
+ return (_ctx, _cache) => {
30
+ return openBlock(), createElementBlock("p", _hoisted_1, [..._cache[0] || (_cache[0] = [createElementVNode("span", { id: "terminal-code" }, null, -1)])]);
31
+ };
32
+ }
33
+ });
34
+ var TerminalAnimation6_default = _sfc_main;
35
+
36
+ //#endregion
37
+ export { TerminalAnimation6_default as default };
@@ -0,0 +1,34 @@
1
+ import * as vitepress0 from "vitepress";
2
+
3
+ //#region src/vitepress/index.d.ts
4
+
5
+ /**
6
+ * @voidzerodev/vitepress-theme
7
+ *
8
+ * Shared VitePress theme providing base styles, fonts, and design tokens
9
+ * for VoidZero projects.
10
+ *
11
+ * Usage:
12
+ * Extend this theme in your project's VitePress theme.
13
+ *
14
+ * @example
15
+ * ```ts
16
+ * // In your-project/.vitepress/theme/index.ts
17
+ * import Theme from '@voidzero-dev/vitepress-theme'
18
+ * import './overrides.css' // Your project-specific styles
19
+ *
20
+ * export default {
21
+ * extends: Theme,
22
+ * Layout: YourLayout
23
+ * }
24
+ * ```
25
+ *
26
+ */
27
+ declare const VPTheme: {
28
+ Layout: () => null;
29
+ enhanceApp({
30
+ app
31
+ }: vitepress0.EnhanceAppContext): void;
32
+ };
33
+ //#endregion
34
+ export { VPTheme };
@@ -0,0 +1,21 @@
1
+ import Footer_default from "./components/Footer.js";
2
+ import Header_default from "./components/Header.js";
3
+ import Terminal_default from "./components/Terminal.js";
4
+ import Eyebrow_default from "./components/Eyebrow.js";
5
+ import RiveAnimation_default from "./components/RiveAnimation.js";
6
+
7
+ //#region src/vitepress/index.ts
8
+ const VPTheme = {
9
+ Layout: () => null,
10
+ enhanceApp({ app }) {
11
+ app.component("Footer", Footer_default);
12
+ app.component("Header", Header_default);
13
+ app.component("Terminal", Terminal_default);
14
+ app.component("Eyebrow", Eyebrow_default);
15
+ app.component("RiveAnimation", RiveAnimation_default);
16
+ }
17
+ };
18
+ var vitepress_default = VPTheme;
19
+
20
+ //#endregion
21
+ export { VPTheme, vitepress_default as default };
package/package.json CHANGED
@@ -1,22 +1,25 @@
1
1
  {
2
2
  "name": "@voidzero-dev/vitepress-theme",
3
- "version": "0.0.2",
3
+ "version": "0.0.3",
4
4
  "description": "Shared VitePress theme for VoidZero projects",
5
5
  "type": "module",
6
- "main": "./index.ts",
6
+ "license": "MIT",
7
+ "main": "./dist/index.js",
8
+ "types": "./dist/index.d.ts",
7
9
  "exports": {
8
10
  ".": {
9
- "style": "./style.css",
10
- "import": "./index.ts"
11
- }
11
+ "styles": "./dist/index.css",
12
+ "types": "./dist/index.d.ts",
13
+ "import": "./dist/index.js"
14
+ },
15
+ "./index.css": "./dist/index.css"
12
16
  },
13
17
  "files": [
14
- "index.ts",
15
- "style.css",
16
- "fonts",
17
- "assets",
18
- "components"
18
+ "dist"
19
19
  ],
20
+ "scripts": {
21
+ "build": "tsdown"
22
+ },
20
23
  "peerDependencies": {
21
24
  "vitepress": "^2.0.0-alpha.12",
22
25
  "vue": "^3.5.0"
@@ -25,15 +28,14 @@
25
28
  "@rive-app/canvas": "^2.31.6",
26
29
  "@tailwindcss/typography": "^0.5.19",
27
30
  "@tailwindcss/vite": "^4.1.13",
28
- "tailwindcss": "^4.1.13",
29
31
  "reka-ui": "^2.5.1",
32
+ "tailwindcss": "^4.1.13",
30
33
  "typewriter-effect": "^2.22.0"
31
34
  },
32
- "keywords": [
33
- "vitepress",
34
- "theme",
35
- "voidzero",
36
- "tailwind"
37
- ],
38
- "license": "MIT"
35
+ "devDependencies": {
36
+ "tsdown": "^0.15.11",
37
+ "typescript": "^5.9.3",
38
+ "unplugin-vue": "^7.0.4",
39
+ "vue-tsc": "^3.1.2"
40
+ }
39
41
  }
@@ -1 +0,0 @@
1
- <svg xmlns="http://www.w3.org/2000/svg" width="20" height="19" fill="none" viewBox="0 0 20 19"><circle cx="10" cy="9.5" r="9" stroke="#3b3440" stroke-width=".5"/><path stroke="#fff" stroke-width="1.2" d="M17.794 14a9 9 0 0 0 0-9M2.206 14a9 9 0 0 1 0-9"/><path stroke="#fff" stroke-linejoin="bevel" stroke-width="1.2" d="m6.249 9.788 2.308 2.309 5.195-5.195"/></svg>
Binary file
@@ -1,11 +0,0 @@
1
- <script setup lang="ts">
2
- defineProps<{
3
- title: string
4
- }>()
5
- </script>
6
-
7
- <template>
8
- <section class="wrapper wrapper--ticks border-t p-5 pl-10">
9
- <span class="text-nickel dark:text-white text-xs font-medium font-mono uppercase tracking-wide">{{ title }}</span>
10
- </section>
11
- </template>
@@ -1,44 +0,0 @@
1
- <template>
2
- <footer class="bg-primary" data-theme="dark">
3
- <section class="wrapper">
4
- <div class="bg-wine bg-[url(/cta-background.jpg)] bg-cover py-16 md:py-30 px-5 md:px-0 overflow-clip flex flex-col items-center justify-center gap-8 md:gap-12">
5
- <h2 class="text-white w-full md:w-2xl text-center text-balance">Take your team's productivity to the next level with Vite+</h2>
6
- <div class="flex items-center gap-5">
7
- <a href="https://tally.so/r/nGWebL" target="_blank" rel="noopener noreferrer" class="button">Register your interest</a>
8
- <a href="https://voidzero.dev/posts/announcing-vite-plus?utm_source=viteplusdev&utm_content=bottom_learn_more" target="_blank" rel="noopener noreferrer" class="button">
9
- Learn more
10
- </a>
11
- </div>
12
- </div>
13
- <div class="px-5 md:px-24 pt-10 md:pt-16 pb-16 md:pb-30 flex flex-col md:flex-row gap-10 md:gap-0 md:justify-between">
14
- <div>
15
- <p class="text-grey text-xs font-mono uppercase tracking-wide mb-8">Company</p>
16
- <ul class="flex flex-col gap-3">
17
- <li><a href="https://voidzero.dev/" target="_blank" rel="noopener noreferrer" class="text-white text-base">VoidZero</a></li>
18
- <li><a href="https://vite.dev/" target="_blank" rel="noopener noreferrer" class="text-white text-base">Vite</a></li>
19
- <li><a href="https://rolldown.rs/" target="_blank" rel="noopener noreferrer" class="text-white text-base">Rolldown</a></li>
20
- <li><a href="https://vitest.dev/" target="_blank" rel="noopener noreferrer" class="text-white text-base">Vitest</a></li>
21
- <li><a href="https://oxc.rs/" target="_blank" rel="noopener noreferrer" class="text-white text-base">Oxc</a></li>
22
- </ul>
23
- </div>
24
- <div>
25
- <p class="text-grey text-xs font-mono uppercase tracking-wide mb-8">Social</p>
26
- <ul class="flex flex-col gap-3">
27
- <li><a href="https://github.com/voidzero-dev" target="_blank" rel="noopener noreferrer" class="text-white text-base flex gap-3 items-center"><img loading="lazy" src="/github.svg" alt="GitHub" class="size-5">GitHub</a></li>
28
- <li><a href="https://web-cdn.bsky.app/profile/voidzero.dev" target="_blank" rel="noopener noreferrer" class="text-white text-base flex gap-3 items-center"><img loading="lazy" src="/bluesky.svg" alt="Bluesky" class="size-5">Bluesky</a></li>
29
- <li><a href="https://x.com/voidzerodev" target="_blank" rel="noopener noreferrer" class="text-white text-base flex gap-3 items-center"><img loading="lazy" src="/twitter.svg" alt="Twitter" class="size-5">X.com</a></li>
30
- </ul>
31
- </div>
32
- </div>
33
- </section>
34
- <section class="wrapper wrapper--ticks border-t py-5 px-5 md:px-24">
35
- <p class="text-sm">© {{ new Date().getFullYear() }} VoidZero Inc. <span class="hidden sm:inline ">All Rights Reserved.</span></p>
36
- </section>
37
- </footer>
38
- </template>
39
-
40
- <style scoped>
41
-
42
- </style>
43
- <script setup lang="ts">
44
- </script>
@@ -1,38 +0,0 @@
1
- <script setup lang="ts">
2
- import {useData, useRoute} from 'vitepress'
3
-
4
- const {site, theme} = useData()
5
- const nav = theme.value.nav
6
-
7
- const route = useRoute()
8
- </script>
9
-
10
- <template>
11
- <header class="wrapper px-6 py-7 flex items-center justify-between">
12
- <div class="flex items-center gap-10">
13
- <a href="/">
14
- <img class="h-4" src="/logo.svg" :alt="site.title"/>
15
- </a>
16
- <ul class="nav">
17
- <li v-for="navItem in nav" :key="navItem.link">
18
- <a
19
- :class="{ active: route.path === navItem.link }"
20
- :href="navItem.link"
21
- >
22
- {{ navItem.text }}
23
- </a>
24
- </li>
25
- </ul>
26
- </div>
27
-
28
- <div class="flex items-center gap-6">
29
- <slot name="right-side">
30
- <!-- Right-aligned links / calls-to-action -->
31
- </slot>
32
- </div>
33
- </header>
34
- </template>
35
-
36
- <style scoped>
37
-
38
- </style>
@@ -1,144 +0,0 @@
1
- <script setup lang="ts">
2
- import * as rive from "@rive-app/canvas"
3
- import { ref, onMounted, onUnmounted, computed } from "vue"
4
-
5
- interface Props {
6
- desktopSrc: string
7
- mobileSrc?: string
8
- breakpoint?: number
9
- stateMachines?: string
10
- canvasClass?: string
11
- desktopWidth?: number
12
- desktopHeight?: number
13
- mobileWidth?: number
14
- mobileHeight?: number
15
- }
16
-
17
- const props = withDefaults(defineProps<Props>(), {
18
- breakpoint: 768, // md breakpoint
19
- stateMachines: "State Machine 1",
20
- canvasClass: "w-full"
21
- })
22
-
23
- const canvasRef = ref<HTMLCanvasElement | null>(null)
24
- const containerRef = ref<HTMLElement | null>(null)
25
- let riveInstance: rive.Rive | null = null
26
- let hasStarted = ref(false)
27
- let observer: IntersectionObserver | null = null
28
-
29
- const isMobile = ref(false)
30
-
31
- const checkMobile = () => {
32
- isMobile.value = window.innerWidth < props.breakpoint
33
- }
34
-
35
- const getCurrentSrc = () => {
36
- return isMobile.value && props.mobileSrc ? props.mobileSrc : props.desktopSrc
37
- }
38
-
39
- const currentWidth = computed(() => {
40
- return isMobile.value && props.mobileWidth ? props.mobileWidth : props.desktopWidth
41
- })
42
-
43
- const currentHeight = computed(() => {
44
- return isMobile.value && props.mobileHeight ? props.mobileHeight : props.desktopHeight
45
- })
46
-
47
- const loadAnimation = () => {
48
- if (!canvasRef.value || riveInstance) return
49
-
50
- const src = getCurrentSrc()
51
-
52
- riveInstance = new rive.Rive({
53
- src,
54
- canvas: canvasRef.value,
55
- autoplay: false,
56
- stateMachines: props.stateMachines,
57
- onLoad: () => {
58
- riveInstance?.resizeDrawingSurfaceToCanvas()
59
- }
60
- })
61
- }
62
-
63
- const playAnimation = () => {
64
- if (riveInstance) {
65
- riveInstance.play()
66
- }
67
- }
68
-
69
- const cleanupAnimation = () => {
70
- if (riveInstance) {
71
- riveInstance.cleanup()
72
- riveInstance = null
73
- }
74
- }
75
-
76
- const handleResize = () => {
77
- const wasMobile = isMobile.value
78
- checkMobile()
79
-
80
- // If mobile state changed, reload with correct source
81
- if (wasMobile !== isMobile.value) {
82
- const wasPlaying = hasStarted.value
83
- cleanupAnimation()
84
- loadAnimation()
85
- if (wasPlaying) {
86
- playAnimation()
87
- }
88
- }
89
- }
90
-
91
- onMounted(() => {
92
- checkMobile()
93
-
94
- // Load animation immediately
95
- loadAnimation()
96
-
97
- // Set up intersection observer to play animation when in viewport
98
- observer = new IntersectionObserver(
99
- (entries) => {
100
- entries.forEach((entry) => {
101
- if (entry.isIntersecting && !hasStarted.value) {
102
- hasStarted.value = true
103
- playAnimation()
104
- }
105
- })
106
- },
107
- {
108
- threshold: 0.1 // Start when 10% visible
109
- }
110
- )
111
-
112
- if (containerRef.value) {
113
- observer.observe(containerRef.value)
114
- }
115
-
116
- // Listen for window resize to handle breakpoint changes
117
- window.addEventListener('resize', handleResize)
118
- })
119
-
120
- onUnmounted(() => {
121
- cleanupAnimation()
122
-
123
- if (observer && containerRef.value) {
124
- observer.unobserve(containerRef.value)
125
- observer.disconnect()
126
- }
127
-
128
- window.removeEventListener('resize', handleResize)
129
- })
130
- </script>
131
-
132
- <template>
133
- <div ref="containerRef" class="pointer-events-none touch-none select-none">
134
- <canvas
135
- ref="canvasRef"
136
- :width="currentWidth"
137
- :height="currentHeight"
138
- :class="canvasClass"
139
- />
140
- </div>
141
- </template>
142
-
143
- <style scoped>
144
- </style>