Skip to content

Commit 60a31f3

Browse files
committed
feat(packages/vue): improve vue wrapper
1 parent e514d69 commit 60a31f3

File tree

5 files changed

+478
-222
lines changed

5 files changed

+478
-222
lines changed

examples/with-vue/src/App.vue

Lines changed: 41 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
<template>
2-
<button
3-
@click="enabled = !enabled"
4-
:style="{ position: 'absolute', zIndex: 1 }"
5-
>
6-
{{ enabled ? 'Enabled' : 'Disabled' }}
7-
</button>
2+
<div class="buttons">
3+
<button @click="mounted = !mounted">
4+
{{ mounted ? 'Mounted' : 'Unmounted' }}
5+
</button>
6+
<button @click="startFireworks">Start</button>
7+
</div>
88
<Fireworks
9-
v-if="enabled"
9+
ref="fw"
10+
v-if="mounted"
1011
:options="options"
1112
:style="{
1213
top: 0,
@@ -20,10 +21,41 @@
2021
</template>
2122

2223
<script lang="ts" setup>
23-
import { ref } from 'vue'
24+
import { onMounted, ref, watch } from 'vue'
2425
import { Fireworks } from '@fireworks-js/vue'
2526
import type { FireworksOptions } from '@fireworks-js/vue'
2627
28+
const fw = ref<InstanceType<typeof Fireworks>>()
2729
const options = ref<FireworksOptions>({ opacity: 0.5 })
28-
const enabled = ref(true)
30+
const mounted = ref(true)
31+
32+
async function startFireworks() {
33+
const { fireworks } = fw.value!
34+
fireworks?.start()
35+
await new Promise((resolve) => setTimeout(resolve, 1000))
36+
await fireworks?.waitStop()
37+
}
38+
39+
onMounted(() => {
40+
startFireworks()
41+
})
42+
43+
watch(fw, () => {
44+
if (fw.value) {
45+
startFireworks()
46+
}
47+
})
2948
</script>
49+
50+
<style>
51+
body {
52+
background-color: #000;
53+
}
54+
55+
.buttons {
56+
z-index: 1;
57+
position: absolute;
58+
display: flex;
59+
gap: 4px;
60+
}
61+
</style>

packages/vue/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@
4444
"fireworks-js": "workspace:2.6.0"
4545
},
4646
"devDependencies": {
47-
"@vitejs/plugin-vue": "3.0.0",
48-
"vue": "3.2.27",
49-
"vue-tsc": "0.33.9"
47+
"@vitejs/plugin-vue": "3.2.0",
48+
"vue": "3.2.41",
49+
"vue-tsc": "1.0.9"
5050
},
5151
"peerDependencies": {
5252
"vue": ">=2.7.0"

packages/vue/src/fireworks.vue

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
1-
<template>
2-
<div ref="container"></div>
3-
</template>
4-
51
<script lang="ts" setup>
62
import { Fireworks } from 'fireworks-js'
73
import type { FireworksOptions } from 'fireworks-js'
8-
import { PropType, onMounted, onUnmounted, ref } from 'vue'
4+
import { PropType, defineExpose, onMounted, onUnmounted, ref } from 'vue'
95
106
const props = defineProps({
117
options: {
@@ -25,4 +21,13 @@ onMounted(() => {
2521
onUnmounted(() => {
2622
fireworks.value!.stop()
2723
})
24+
25+
defineExpose({
26+
fireworks,
27+
container
28+
})
2829
</script>
30+
31+
<template>
32+
<div ref="container"></div>
33+
</template>

packages/vue/tsconfig.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
"extends": "@crashmax/tsconfig",
33
"compilerOptions": {
44
"jsx": "preserve",
5-
"outDir": "dist"
5+
"outDir": "dist",
6+
"noEmitOnError": false
67
},
78
"include": [
89
"src"

0 commit comments

Comments
 (0)