@maas/vue-equipment 1.1.0 → 1.3.0
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/dist/nuxt/module.json +1 -1
- package/dist/nuxt/module.mjs +4 -3
- package/dist/plugins/MagicCarousel/src/utils/defaultOptions.mjs +1 -1
- package/dist/plugins/MagicDotMatrix/index.d.ts +14 -0
- package/dist/plugins/MagicDotMatrix/index.mjs +20 -0
- package/dist/plugins/MagicDotMatrix/nuxt.d.ts +0 -0
- package/dist/plugins/MagicDotMatrix/nuxt.mjs +29 -0
- package/dist/plugins/MagicDotMatrix/src/components/MagicDotMatrix.d.vue.ts +10 -0
- package/dist/plugins/MagicDotMatrix/src/components/MagicDotMatrix.vue +103 -0
- package/dist/plugins/MagicDotMatrix/src/components/MagicDotMatrix.vue.d.ts +10 -0
- package/dist/plugins/MagicDotMatrix/src/composables/private/useDotMatrixApi.d.ts +10 -0
- package/dist/plugins/MagicDotMatrix/src/composables/private/useDotMatrixApi.mjs +82 -0
- package/dist/plugins/MagicDotMatrix/src/composables/private/useDotMatrixState.d.ts +6 -0
- package/dist/plugins/MagicDotMatrix/src/composables/private/useDotMatrixState.mjs +71 -0
- package/dist/plugins/MagicDotMatrix/src/composables/useMagicDotMatrix.d.ts +10 -0
- package/dist/plugins/MagicDotMatrix/src/composables/useMagicDotMatrix.mjs +27 -0
- package/dist/plugins/MagicDotMatrix/src/composables/useMagicDotMatrixEmoji.d.ts +19 -0
- package/dist/plugins/MagicDotMatrix/src/composables/useMagicDotMatrixEmoji.mjs +50 -0
- package/dist/plugins/MagicDotMatrix/src/types/index.d.ts +40 -0
- package/dist/plugins/MagicDotMatrix/src/types/index.mjs +0 -0
- package/dist/plugins/MagicDotMatrix/src/utils/defaultOptions.d.ts +4 -0
- package/dist/plugins/MagicDotMatrix/src/utils/defaultOptions.mjs +14 -0
- package/dist/plugins/MagicDotMatrix/src/utils/emoji/animateEmoji.d.ts +5 -0
- package/dist/plugins/MagicDotMatrix/src/utils/emoji/animateEmoji.mjs +296 -0
- package/dist/plugins/MagicDotMatrix/src/utils/emoji/motions.d.ts +382 -0
- package/dist/plugins/MagicDotMatrix/src/utils/emoji/motions.mjs +420 -0
- package/dist/plugins/MagicDotMatrix/src/utils/emoji/pickMotion.d.ts +7 -0
- package/dist/plugins/MagicDotMatrix/src/utils/emoji/pickMotion.mjs +153 -0
- package/dist/plugins/MagicDotMatrix/src/utils/presets/bounce.d.ts +2 -0
- package/dist/plugins/MagicDotMatrix/src/utils/presets/bounce.mjs +8 -0
- package/dist/plugins/MagicDotMatrix/src/utils/presets/checkerboard.d.ts +2 -0
- package/dist/plugins/MagicDotMatrix/src/utils/presets/checkerboard.mjs +18 -0
- package/dist/plugins/MagicDotMatrix/src/utils/presets/comet.d.ts +2 -0
- package/dist/plugins/MagicDotMatrix/src/utils/presets/comet.mjs +5 -0
- package/dist/plugins/MagicDotMatrix/src/utils/presets/drift.d.ts +2 -0
- package/dist/plugins/MagicDotMatrix/src/utils/presets/drift.mjs +38 -0
- package/dist/plugins/MagicDotMatrix/src/utils/presets/equalizer.d.ts +2 -0
- package/dist/plugins/MagicDotMatrix/src/utils/presets/equalizer.mjs +14 -0
- package/dist/plugins/MagicDotMatrix/src/utils/presets/fill.d.ts +2 -0
- package/dist/plugins/MagicDotMatrix/src/utils/presets/fill.mjs +10 -0
- package/dist/plugins/MagicDotMatrix/src/utils/presets/focus.d.ts +2 -0
- package/dist/plugins/MagicDotMatrix/src/utils/presets/focus.mjs +5 -0
- package/dist/plugins/MagicDotMatrix/src/utils/presets/index.d.ts +12 -0
- package/dist/plugins/MagicDotMatrix/src/utils/presets/index.mjs +12 -0
- package/dist/plugins/MagicDotMatrix/src/utils/presets/orbit.d.ts +2 -0
- package/dist/plugins/MagicDotMatrix/src/utils/presets/orbit.mjs +8 -0
- package/dist/plugins/MagicDotMatrix/src/utils/presets/pulse.d.ts +2 -0
- package/dist/plugins/MagicDotMatrix/src/utils/presets/pulse.mjs +7 -0
- package/dist/plugins/MagicDotMatrix/src/utils/presets/ripple.d.ts +2 -0
- package/dist/plugins/MagicDotMatrix/src/utils/presets/ripple.mjs +5 -0
- package/dist/plugins/MagicDotMatrix/src/utils/presets/scan.d.ts +2 -0
- package/dist/plugins/MagicDotMatrix/src/utils/presets/scan.mjs +6 -0
- package/dist/plugins/MagicDotMatrix/src/utils/presets/spiral.d.ts +2 -0
- package/dist/plugins/MagicDotMatrix/src/utils/presets/spiral.mjs +34 -0
- package/dist/plugins/MagicDotMatrix/src/utils/sequence/equalizerFrame.d.ts +7 -0
- package/dist/plugins/MagicDotMatrix/src/utils/sequence/equalizerFrame.mjs +12 -0
- package/dist/plugins/MagicDotMatrix/src/utils/sequence/getRings.d.ts +2 -0
- package/dist/plugins/MagicDotMatrix/src/utils/sequence/getRings.mjs +24 -0
- package/dist/plugins/MagicDotMatrix/src/utils/sequence/ringPath.d.ts +7 -0
- package/dist/plugins/MagicDotMatrix/src/utils/sequence/ringPath.mjs +35 -0
- package/dist/plugins/MagicDotMatrix/src/utils/sequence/toIndex.d.ts +6 -0
- package/dist/plugins/MagicDotMatrix/src/utils/sequence/toIndex.mjs +3 -0
- package/dist/plugins/MagicDotMatrix/src/utils/sequence/withTrail.d.ts +6 -0
- package/dist/plugins/MagicDotMatrix/src/utils/sequence/withTrail.mjs +17 -0
- package/dist/plugins/MagicDraggable/src/utils/defaultOptions.mjs +1 -1
- package/dist/plugins/MagicDrawer/src/components/MagicDrawerContent.vue +4 -0
- package/dist/plugins/MagicDrawer/src/components/MagicDrawerTrigger.d.vue.ts +1 -1
- package/dist/plugins/MagicDrawer/src/components/MagicDrawerTrigger.vue +5 -1
- package/dist/plugins/MagicDrawer/src/components/MagicDrawerTrigger.vue.d.ts +1 -1
- package/dist/plugins/MagicDrawer/src/composables/private/useDrawerDrag.mjs +1 -2
- package/dist/plugins/MagicDrawer/src/composables/private/useDrawerProgress.mjs +57 -77
- package/dist/plugins/MagicDrawer/src/composables/private/useDrawerSnap.mjs +2 -5
- package/dist/plugins/MagicDrawer/src/utils/defaultOptions.mjs +1 -1
- package/dist/plugins/MagicEmitter/src/types/index.d.ts +2 -0
- package/dist/plugins/MagicMenu/src/components/MagicMenuTrigger.vue +13 -3
- package/dist/plugins/MagicTray/index.d.ts +2 -1
- package/dist/plugins/MagicTray/index.mjs +3 -0
- package/dist/plugins/MagicTray/src/components/MagicTrayContent.d.vue.ts +2 -2
- package/dist/plugins/MagicTray/src/components/MagicTrayContent.vue +17 -16
- package/dist/plugins/MagicTray/src/components/MagicTrayContent.vue.d.ts +2 -2
- package/dist/plugins/MagicTray/src/components/MagicTrayTrigger.d.vue.ts +25 -0
- package/dist/plugins/MagicTray/src/components/MagicTrayTrigger.vue +96 -0
- package/dist/plugins/MagicTray/src/components/MagicTrayTrigger.vue.d.ts +25 -0
- package/dist/plugins/MagicTray/src/composables/private/useTrayDrag.d.ts +0 -4
- package/dist/plugins/MagicTray/src/composables/private/useTrayDrag.mjs +9 -415
- package/dist/plugins/MagicTray/src/composables/private/useTrayGesture.d.ts +16 -0
- package/dist/plugins/MagicTray/src/composables/private/useTrayGesture.mjs +426 -0
- package/dist/plugins/MagicTray/src/composables/private/useTrayMagnetism.mjs +9 -37
- package/dist/plugins/MagicTray/src/composables/private/useTrayProgress.mjs +1 -1
- package/dist/plugins/MagicTray/src/composables/private/useTraySnap.mjs +2 -4
- package/dist/plugins/MagicTray/src/composables/private/useTrayUtils.d.ts +8 -1
- package/dist/plugins/MagicTray/src/composables/private/useTrayUtils.mjs +7 -1
- package/dist/plugins/MagicTray/src/utils/defaultOptions.mjs +1 -1
- package/package.json +3 -4
package/dist/nuxt/module.json
CHANGED
package/dist/nuxt/module.mjs
CHANGED
|
@@ -32,8 +32,9 @@ const functions$1 = [
|
|
|
32
32
|
{
|
|
33
33
|
name: "MagicDotMatrix",
|
|
34
34
|
"package": "plugins",
|
|
35
|
-
lastUpdated:
|
|
36
|
-
|
|
35
|
+
lastUpdated: 1793291276000,
|
|
36
|
+
docs: "https://vue.equipment/plugins/MagicDotMatrix",
|
|
37
|
+
description: "MagicDotMatrix is a dot matrix display for playing frame based animations on a grid of dots"
|
|
37
38
|
},
|
|
38
39
|
{
|
|
39
40
|
name: "MagicDraggable",
|
|
@@ -122,7 +123,7 @@ const functions$1 = [
|
|
|
122
123
|
{
|
|
123
124
|
name: "MagicTray",
|
|
124
125
|
"package": "plugins",
|
|
125
|
-
lastUpdated:
|
|
126
|
+
lastUpdated: 1793032883000,
|
|
126
127
|
docs: "https://vue.equipment/plugins/MagicTray",
|
|
127
128
|
description: "MagicTray is a flexible"
|
|
128
129
|
},
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import MagicDotMatrix from './src/components/MagicDotMatrix.vue.js';
|
|
2
|
+
import { useMagicDotMatrix } from './src/composables/useMagicDotMatrix.js';
|
|
3
|
+
import { useMagicDotMatrixEmoji } from './src/composables/useMagicDotMatrixEmoji.js';
|
|
4
|
+
import type { Plugin } from 'vue';
|
|
5
|
+
import type { DotMatrixEmojiMotion, DotMatrixEvents, DotMatrixFrame, DotMatrixGrid, DotMatrixLayeredFrame, DotMatrixSequence, MagicDotMatrixEmojiOptions, MagicDotMatrixOptions } from './src/types/index.js';
|
|
6
|
+
declare const MagicDotMatrixPlugin: Plugin;
|
|
7
|
+
export * from './src/utils/presets/index.js';
|
|
8
|
+
export { equalizerFrame } from './src/utils/sequence/equalizerFrame.js';
|
|
9
|
+
export { getRings } from './src/utils/sequence/getRings.js';
|
|
10
|
+
export { ringPath } from './src/utils/sequence/ringPath.js';
|
|
11
|
+
export { toIndex } from './src/utils/sequence/toIndex.js';
|
|
12
|
+
export { withTrail } from './src/utils/sequence/withTrail.js';
|
|
13
|
+
export { MagicDotMatrixPlugin, MagicDotMatrix, useMagicDotMatrix, useMagicDotMatrixEmoji, };
|
|
14
|
+
export type { DotMatrixEmojiMotion, DotMatrixEvents, DotMatrixFrame, DotMatrixGrid, DotMatrixLayeredFrame, DotMatrixSequence, MagicDotMatrixEmojiOptions, MagicDotMatrixOptions, };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import MagicDotMatrix from "./src/components/MagicDotMatrix.vue";
|
|
2
|
+
import { useMagicDotMatrix } from "./src/composables/useMagicDotMatrix.mjs";
|
|
3
|
+
import { useMagicDotMatrixEmoji } from "./src/composables/useMagicDotMatrixEmoji.mjs";
|
|
4
|
+
const MagicDotMatrixPlugin = {
|
|
5
|
+
install: (app) => {
|
|
6
|
+
app.component("MagicDotMatrix", MagicDotMatrix);
|
|
7
|
+
}
|
|
8
|
+
};
|
|
9
|
+
export * from "./src/utils/presets/index.mjs";
|
|
10
|
+
export { equalizerFrame } from "./src/utils/sequence/equalizerFrame.mjs";
|
|
11
|
+
export { getRings } from "./src/utils/sequence/getRings.mjs";
|
|
12
|
+
export { ringPath } from "./src/utils/sequence/ringPath.mjs";
|
|
13
|
+
export { toIndex } from "./src/utils/sequence/toIndex.mjs";
|
|
14
|
+
export { withTrail } from "./src/utils/sequence/withTrail.mjs";
|
|
15
|
+
export {
|
|
16
|
+
MagicDotMatrixPlugin,
|
|
17
|
+
MagicDotMatrix,
|
|
18
|
+
useMagicDotMatrix,
|
|
19
|
+
useMagicDotMatrixEmoji
|
|
20
|
+
};
|
|
File without changes
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import {
|
|
2
|
+
defineNuxtModule,
|
|
3
|
+
createResolver,
|
|
4
|
+
addComponent,
|
|
5
|
+
addImports
|
|
6
|
+
} from "@nuxt/kit";
|
|
7
|
+
export default defineNuxtModule({
|
|
8
|
+
meta: {
|
|
9
|
+
name: "@maas/vue-equipment/nuxt/MagicDotMatrix"
|
|
10
|
+
},
|
|
11
|
+
setup() {
|
|
12
|
+
const resolver = createResolver(import.meta.url);
|
|
13
|
+
addComponent({
|
|
14
|
+
filePath: resolver.resolve("src/components/MagicDotMatrix.vue"),
|
|
15
|
+
name: "MagicDotMatrix",
|
|
16
|
+
global: true
|
|
17
|
+
});
|
|
18
|
+
addImports([
|
|
19
|
+
{
|
|
20
|
+
from: "@maas/vue-equipment/plugins/MagicDotMatrix",
|
|
21
|
+
name: "useMagicDotMatrix"
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
from: "@maas/vue-equipment/plugins/MagicDotMatrix",
|
|
25
|
+
name: "useMagicDotMatrixEmoji"
|
|
26
|
+
}
|
|
27
|
+
]);
|
|
28
|
+
}
|
|
29
|
+
});
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { MaybeRef } from 'vue';
|
|
2
|
+
import type { DotMatrixSequence, MagicDotMatrixOptions } from '../types/index.js';
|
|
3
|
+
interface MagicDotMatrixProps {
|
|
4
|
+
id: MaybeRef<string>;
|
|
5
|
+
sequence: DotMatrixSequence;
|
|
6
|
+
options?: MagicDotMatrixOptions;
|
|
7
|
+
}
|
|
8
|
+
declare const __VLS_export: import("vue").DefineComponent<MagicDotMatrixProps, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<MagicDotMatrixProps> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
9
|
+
declare const _default: typeof __VLS_export;
|
|
10
|
+
export default _default;
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div
|
|
3
|
+
class="magic-dot-matrix"
|
|
4
|
+
:data-id="toValue(id)"
|
|
5
|
+
:data-playing="state.playing"
|
|
6
|
+
:style="{ '--mdm-cols': mappedCols, '--mdm-rows': mappedRows }"
|
|
7
|
+
>
|
|
8
|
+
<svg xmlns="http://www.w3.org/2000/svg">
|
|
9
|
+
<rect
|
|
10
|
+
v-for="dot in dots"
|
|
11
|
+
:key="dot"
|
|
12
|
+
class="magic-dot-matrix__dot"
|
|
13
|
+
:data-active="tones.has(dot) || null"
|
|
14
|
+
:style="dotStyle(dot)"
|
|
15
|
+
/>
|
|
16
|
+
</svg>
|
|
17
|
+
</div>
|
|
18
|
+
</template>
|
|
19
|
+
|
|
20
|
+
<script setup>
|
|
21
|
+
import { computed, onMounted, toValue, watch } from "vue";
|
|
22
|
+
import { useDotMatrixState } from "../composables/private/useDotMatrixState";
|
|
23
|
+
import { useDotMatrixApi } from "../composables/private/useDotMatrixApi";
|
|
24
|
+
import { defaultOptions } from "../utils/defaultOptions";
|
|
25
|
+
const { id, sequence, options } = defineProps({
|
|
26
|
+
id: { type: null, required: true },
|
|
27
|
+
sequence: { type: Array, required: true },
|
|
28
|
+
options: { type: Object, required: false }
|
|
29
|
+
});
|
|
30
|
+
const { initializeState } = useDotMatrixState(id);
|
|
31
|
+
const state = initializeState(options);
|
|
32
|
+
watch(
|
|
33
|
+
() => options,
|
|
34
|
+
(value) => {
|
|
35
|
+
initializeState(value);
|
|
36
|
+
},
|
|
37
|
+
{ deep: true }
|
|
38
|
+
);
|
|
39
|
+
const { tones, initialize } = useDotMatrixApi({
|
|
40
|
+
instanceId: id,
|
|
41
|
+
sequence: () => sequence
|
|
42
|
+
});
|
|
43
|
+
const mappedCols = computed(() => state.options.cols ?? defaultOptions.cols);
|
|
44
|
+
const mappedRows = computed(() => state.options.rows ?? defaultOptions.rows);
|
|
45
|
+
const dots = computed(
|
|
46
|
+
() => Array.from(
|
|
47
|
+
{ length: mappedCols.value * mappedRows.value },
|
|
48
|
+
(_, index) => index
|
|
49
|
+
)
|
|
50
|
+
);
|
|
51
|
+
function dotStyle(index) {
|
|
52
|
+
const tone = tones.value.get(index);
|
|
53
|
+
return {
|
|
54
|
+
"--mdm-col": index % mappedCols.value,
|
|
55
|
+
"--mdm-row": Math.floor(index / mappedCols.value),
|
|
56
|
+
"--mdm-tone-color": tone ? `var(--magic-dot-matrix-color-${tone})` : void 0
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
onMounted(() => {
|
|
60
|
+
initialize();
|
|
61
|
+
});
|
|
62
|
+
</script>
|
|
63
|
+
|
|
64
|
+
<style>
|
|
65
|
+
.magic-dot-matrix {
|
|
66
|
+
display: block;
|
|
67
|
+
container-type: inline-size;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
.magic-dot-matrix svg {
|
|
71
|
+
--mdm-gap: var(
|
|
72
|
+
--magic-dot-matrix-gap,
|
|
73
|
+
calc(100cqi / (4 * var(--mdm-cols) - 1))
|
|
74
|
+
);
|
|
75
|
+
--mdm-dot-size: calc(
|
|
76
|
+
(100cqi - (var(--mdm-cols) - 1) * var(--mdm-gap)) / var(--mdm-cols)
|
|
77
|
+
);
|
|
78
|
+
display: block;
|
|
79
|
+
width: 100cqi;
|
|
80
|
+
height: calc(
|
|
81
|
+
var(--mdm-rows) * var(--mdm-dot-size) + (var(--mdm-rows) - 1) *
|
|
82
|
+
var(--mdm-gap)
|
|
83
|
+
);
|
|
84
|
+
background: var(--magic-dot-matrix-background, transparent);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
.magic-dot-matrix__dot {
|
|
88
|
+
x: calc(var(--mdm-col) * (var(--mdm-dot-size) + var(--mdm-gap)));
|
|
89
|
+
y: calc(var(--mdm-row) * (var(--mdm-dot-size) + var(--mdm-gap)));
|
|
90
|
+
width: var(--mdm-dot-size);
|
|
91
|
+
height: var(--mdm-dot-size);
|
|
92
|
+
rx: calc(var(--magic-dot-matrix-radius, 0.33) * var(--mdm-dot-size));
|
|
93
|
+
fill: var(
|
|
94
|
+
--magic-dot-matrix-inactive-color,
|
|
95
|
+
color-mix(in srgb, currentColor 15%, transparent)
|
|
96
|
+
);
|
|
97
|
+
transition: var(--magic-dot-matrix-transition, none);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
.magic-dot-matrix__dot[data-active='true'] {
|
|
101
|
+
fill: var(--mdm-tone-color, var(--magic-dot-matrix-color, currentColor));
|
|
102
|
+
}
|
|
103
|
+
</style>
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { MaybeRef } from 'vue';
|
|
2
|
+
import type { DotMatrixSequence, MagicDotMatrixOptions } from '../types/index.js';
|
|
3
|
+
interface MagicDotMatrixProps {
|
|
4
|
+
id: MaybeRef<string>;
|
|
5
|
+
sequence: DotMatrixSequence;
|
|
6
|
+
options?: MagicDotMatrixOptions;
|
|
7
|
+
}
|
|
8
|
+
declare const __VLS_export: import("vue").DefineComponent<MagicDotMatrixProps, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<MagicDotMatrixProps> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
9
|
+
declare const _default: typeof __VLS_export;
|
|
10
|
+
export default _default;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { MaybeRef, MaybeRefOrGetter } from 'vue';
|
|
2
|
+
import type { DotMatrixSequence } from '../../types/index.js';
|
|
3
|
+
export type UseDotMatrixApiParams = {
|
|
4
|
+
instanceId: MaybeRef<string>;
|
|
5
|
+
sequence: MaybeRefOrGetter<DotMatrixSequence>;
|
|
6
|
+
};
|
|
7
|
+
export declare function useDotMatrixApi({ instanceId, sequence, }: UseDotMatrixApiParams): {
|
|
8
|
+
tones: import("vue").ComputedRef<Map<number, number>>;
|
|
9
|
+
initialize: () => void;
|
|
10
|
+
};
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { computed, toValue, watch } from "vue";
|
|
2
|
+
import { useIntervalFn } from "@vueuse/core";
|
|
3
|
+
import { useMagicEmitter } from "@maas/vue-equipment/plugins/MagicEmitter";
|
|
4
|
+
import { useDotMatrixState } from "./useDotMatrixState.mjs";
|
|
5
|
+
import { defaultOptions } from "../../utils/defaultOptions.mjs";
|
|
6
|
+
export function useDotMatrixApi({
|
|
7
|
+
instanceId,
|
|
8
|
+
sequence
|
|
9
|
+
}) {
|
|
10
|
+
const { initializeState } = useDotMatrixState(instanceId);
|
|
11
|
+
const state = initializeState();
|
|
12
|
+
const emitter = useMagicEmitter();
|
|
13
|
+
const maxLoops = computed(() => {
|
|
14
|
+
switch (state.options.loop) {
|
|
15
|
+
case true:
|
|
16
|
+
case void 0:
|
|
17
|
+
return Infinity;
|
|
18
|
+
case false:
|
|
19
|
+
return 1;
|
|
20
|
+
default:
|
|
21
|
+
return Math.max(1, state.options.loop);
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
const tones = computed(() => {
|
|
25
|
+
const frame = toValue(sequence)[state.frame] ?? [];
|
|
26
|
+
const layers = isLayered(frame) ? frame : [frame];
|
|
27
|
+
const mapped = /* @__PURE__ */ new Map();
|
|
28
|
+
layers.forEach((layer, index) => {
|
|
29
|
+
layer.forEach((dot) => mapped.set(dot, index + 1));
|
|
30
|
+
});
|
|
31
|
+
return mapped;
|
|
32
|
+
});
|
|
33
|
+
function isLayered(frame) {
|
|
34
|
+
return frame.some((entry) => Array.isArray(entry));
|
|
35
|
+
}
|
|
36
|
+
function advance() {
|
|
37
|
+
const length = toValue(sequence).length;
|
|
38
|
+
if (length === 0) {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
const next = (state.frame + 1) % length;
|
|
42
|
+
if (next === 0) {
|
|
43
|
+
state.loops++;
|
|
44
|
+
if (state.loops >= maxLoops.value) {
|
|
45
|
+
state.playing = false;
|
|
46
|
+
emitter.emit("finish", { id: toValue(instanceId) });
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
state.frame = next;
|
|
51
|
+
}
|
|
52
|
+
const { pause, resume } = useIntervalFn(
|
|
53
|
+
advance,
|
|
54
|
+
() => state.options.interval ?? defaultOptions.interval,
|
|
55
|
+
{ immediate: false }
|
|
56
|
+
);
|
|
57
|
+
function sync() {
|
|
58
|
+
pause();
|
|
59
|
+
if (state.playing && toValue(sequence).length > 0) {
|
|
60
|
+
resume();
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
function initialize() {
|
|
64
|
+
if (!(state.options.autoplay ?? defaultOptions.autoplay)) {
|
|
65
|
+
state.playing = false;
|
|
66
|
+
}
|
|
67
|
+
sync();
|
|
68
|
+
}
|
|
69
|
+
watch(
|
|
70
|
+
() => toValue(sequence),
|
|
71
|
+
() => {
|
|
72
|
+
state.frame = 0;
|
|
73
|
+
state.loops = 0;
|
|
74
|
+
sync();
|
|
75
|
+
}
|
|
76
|
+
);
|
|
77
|
+
watch(() => state.playing, sync);
|
|
78
|
+
return {
|
|
79
|
+
tones,
|
|
80
|
+
initialize
|
|
81
|
+
};
|
|
82
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { MaybeRef } from 'vue';
|
|
2
|
+
import type { MagicDotMatrixOptions } from '../../types/index.js';
|
|
3
|
+
export declare function useDotMatrixState(instanceId: MaybeRef<string>): {
|
|
4
|
+
initializeState: (options?: MagicDotMatrixOptions) => any;
|
|
5
|
+
dotMatrixStateStore: any;
|
|
6
|
+
};
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { reactive, toValue, onScopeDispose } from "vue";
|
|
2
|
+
import { defu } from "defu";
|
|
3
|
+
import { createStateStore } from "@maas/vue-equipment/utils";
|
|
4
|
+
import { defaultOptions } from "../../utils/defaultOptions.mjs";
|
|
5
|
+
const getDotMatrixStateStore = createStateStore(
|
|
6
|
+
"MagicDotMatrix",
|
|
7
|
+
() => []
|
|
8
|
+
);
|
|
9
|
+
export function useDotMatrixState(instanceId) {
|
|
10
|
+
const dotMatrixStateStore = getDotMatrixStateStore();
|
|
11
|
+
let scopeCounted = false;
|
|
12
|
+
function createState(id) {
|
|
13
|
+
const state = {
|
|
14
|
+
id,
|
|
15
|
+
refCount: 0,
|
|
16
|
+
options: { ...defaultOptions },
|
|
17
|
+
playing: true,
|
|
18
|
+
frame: 0,
|
|
19
|
+
loops: 0
|
|
20
|
+
};
|
|
21
|
+
return reactive(state);
|
|
22
|
+
}
|
|
23
|
+
function addState(id) {
|
|
24
|
+
const state = createState(id);
|
|
25
|
+
dotMatrixStateStore.value = [...dotMatrixStateStore.value, state];
|
|
26
|
+
return state;
|
|
27
|
+
}
|
|
28
|
+
function deleteState() {
|
|
29
|
+
const currentId = toValue(instanceId);
|
|
30
|
+
dotMatrixStateStore.value = dotMatrixStateStore.value.filter(
|
|
31
|
+
(x) => x.id !== currentId
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
function initializeState(options) {
|
|
35
|
+
const currentId = toValue(instanceId);
|
|
36
|
+
let state = dotMatrixStateStore.value.find(
|
|
37
|
+
(entry) => entry.id === currentId
|
|
38
|
+
);
|
|
39
|
+
if (!state) {
|
|
40
|
+
state = addState(currentId);
|
|
41
|
+
}
|
|
42
|
+
if (!scopeCounted) {
|
|
43
|
+
state.refCount++;
|
|
44
|
+
scopeCounted = true;
|
|
45
|
+
}
|
|
46
|
+
if (options) {
|
|
47
|
+
const mappedOptions = defu(options, defaultOptions);
|
|
48
|
+
state.options = mappedOptions;
|
|
49
|
+
}
|
|
50
|
+
return state;
|
|
51
|
+
}
|
|
52
|
+
onScopeDispose(() => {
|
|
53
|
+
if (!scopeCounted) {
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
const currentId = toValue(instanceId);
|
|
57
|
+
const state = dotMatrixStateStore.value.find(
|
|
58
|
+
(entry) => entry.id === currentId
|
|
59
|
+
);
|
|
60
|
+
if (state) {
|
|
61
|
+
state.refCount--;
|
|
62
|
+
if (state.refCount <= 0) {
|
|
63
|
+
deleteState();
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}, true);
|
|
67
|
+
return {
|
|
68
|
+
initializeState,
|
|
69
|
+
dotMatrixStateStore
|
|
70
|
+
};
|
|
71
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { MaybeRef } from 'vue';
|
|
2
|
+
export declare function useMagicDotMatrix(id: MaybeRef<string>): {
|
|
3
|
+
state: any;
|
|
4
|
+
isPlaying: import("vue").ComputedRef<any>;
|
|
5
|
+
currentFrame: import("vue").ComputedRef<any>;
|
|
6
|
+
play: () => void;
|
|
7
|
+
pause: () => void;
|
|
8
|
+
restart: () => void;
|
|
9
|
+
};
|
|
10
|
+
export type UseMagicDotMatrixReturn = ReturnType<typeof useMagicDotMatrix>;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { computed } from "vue";
|
|
2
|
+
import { useDotMatrixState } from "./private/useDotMatrixState.mjs";
|
|
3
|
+
export function useMagicDotMatrix(id) {
|
|
4
|
+
const { initializeState } = useDotMatrixState(id);
|
|
5
|
+
const state = initializeState();
|
|
6
|
+
const isPlaying = computed(() => state.playing);
|
|
7
|
+
const currentFrame = computed(() => state.frame);
|
|
8
|
+
function play() {
|
|
9
|
+
state.playing = true;
|
|
10
|
+
}
|
|
11
|
+
function pause() {
|
|
12
|
+
state.playing = false;
|
|
13
|
+
}
|
|
14
|
+
function restart() {
|
|
15
|
+
state.frame = 0;
|
|
16
|
+
state.loops = 0;
|
|
17
|
+
state.playing = true;
|
|
18
|
+
}
|
|
19
|
+
return {
|
|
20
|
+
state,
|
|
21
|
+
isPlaying,
|
|
22
|
+
currentFrame,
|
|
23
|
+
play,
|
|
24
|
+
pause,
|
|
25
|
+
restart
|
|
26
|
+
};
|
|
27
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { MaybeRefOrGetter } from 'vue';
|
|
2
|
+
import type { MagicDotMatrixEmojiOptions } from '../types/index.js';
|
|
3
|
+
/**
|
|
4
|
+
* @experimental Options, return values and motions may change, and the
|
|
5
|
+
* composable may be removed again in a future release.
|
|
6
|
+
*/
|
|
7
|
+
export declare function useMagicDotMatrixEmoji(emoji: MaybeRefOrGetter<string>, options?: MaybeRefOrGetter<MagicDotMatrixEmojiOptions>): {
|
|
8
|
+
sequence: import("vue").ComputedRef<import("../types/index.js").DotMatrixLayeredFrame[]>;
|
|
9
|
+
options: import("vue").ComputedRef<{
|
|
10
|
+
cols: number;
|
|
11
|
+
rows: number;
|
|
12
|
+
interval: number;
|
|
13
|
+
}>;
|
|
14
|
+
style: import("vue").ComputedRef<{
|
|
15
|
+
'--magic-dot-matrix-inactive-color'?: string | undefined;
|
|
16
|
+
}>;
|
|
17
|
+
motion: import("vue").ComputedRef<import("../types/index.js").DotMatrixEmojiMotion>;
|
|
18
|
+
};
|
|
19
|
+
export type UseMagicDotMatrixEmojiReturn = ReturnType<typeof useMagicDotMatrixEmoji>;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { computed, shallowRef, toValue, watch } from "vue";
|
|
2
|
+
import { tryOnMounted } from "@vueuse/core";
|
|
3
|
+
import { defu } from "defu";
|
|
4
|
+
import { animateEmoji } from "../utils/emoji/animateEmoji.mjs";
|
|
5
|
+
import { motions } from "../utils/emoji/motions.mjs";
|
|
6
|
+
import { pickMotion } from "../utils/emoji/pickMotion.mjs";
|
|
7
|
+
import { defaultEmojiOptions } from "../utils/defaultOptions.mjs";
|
|
8
|
+
export function useMagicDotMatrixEmoji(emoji, options) {
|
|
9
|
+
const mappedOptions = computed(
|
|
10
|
+
() => defu(toValue(options) ?? {}, defaultEmojiOptions)
|
|
11
|
+
);
|
|
12
|
+
const animation = shallowRef({ sequence: [], colors: [] });
|
|
13
|
+
const motion = computed(() => pickMotion(toValue(emoji)).name);
|
|
14
|
+
const sequence = computed(() => animation.value.sequence);
|
|
15
|
+
const matrixOptions = computed(() => ({
|
|
16
|
+
cols: mappedOptions.value.cols,
|
|
17
|
+
rows: mappedOptions.value.rows,
|
|
18
|
+
interval: motions[motion.value].interval
|
|
19
|
+
}));
|
|
20
|
+
const style = computed(() => {
|
|
21
|
+
const { colors } = animation.value;
|
|
22
|
+
return {
|
|
23
|
+
...Object.fromEntries(
|
|
24
|
+
colors.map((color, index) => [
|
|
25
|
+
`--magic-dot-matrix-color-${index + 1}`,
|
|
26
|
+
color
|
|
27
|
+
])
|
|
28
|
+
),
|
|
29
|
+
...colors[0] && {
|
|
30
|
+
"--magic-dot-matrix-inactive-color": `color-mix(in srgb, ${colors[0]} 15%, transparent)`
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
});
|
|
34
|
+
function update() {
|
|
35
|
+
const { sequence: sequence2, colors } = animateEmoji({
|
|
36
|
+
emoji: toValue(emoji),
|
|
37
|
+
...mappedOptions.value
|
|
38
|
+
});
|
|
39
|
+
animation.value = { sequence: sequence2, colors };
|
|
40
|
+
}
|
|
41
|
+
tryOnMounted(() => {
|
|
42
|
+
watch([() => toValue(emoji), mappedOptions], update, { immediate: true });
|
|
43
|
+
});
|
|
44
|
+
return {
|
|
45
|
+
sequence,
|
|
46
|
+
options: matrixOptions,
|
|
47
|
+
style,
|
|
48
|
+
motion
|
|
49
|
+
};
|
|
50
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
export type DotMatrixFrame = Array<number>;
|
|
2
|
+
export type DotMatrixLayeredFrame = Array<DotMatrixFrame>;
|
|
3
|
+
export type DotMatrixSequence = Array<DotMatrixFrame | DotMatrixLayeredFrame>;
|
|
4
|
+
export interface DotMatrixGrid {
|
|
5
|
+
cols: number;
|
|
6
|
+
rows: number;
|
|
7
|
+
}
|
|
8
|
+
export interface MagicDotMatrixOptions {
|
|
9
|
+
cols?: number;
|
|
10
|
+
rows?: number;
|
|
11
|
+
interval?: number;
|
|
12
|
+
loop?: boolean | number;
|
|
13
|
+
autoplay?: boolean;
|
|
14
|
+
}
|
|
15
|
+
export interface DotMatrixState {
|
|
16
|
+
id: string;
|
|
17
|
+
refCount: number;
|
|
18
|
+
options: MagicDotMatrixOptions;
|
|
19
|
+
playing: boolean;
|
|
20
|
+
frame: number;
|
|
21
|
+
loops: number;
|
|
22
|
+
}
|
|
23
|
+
export interface DotMatrixEvents {
|
|
24
|
+
finish: {
|
|
25
|
+
id: string;
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
export type DotMatrixEmojiMotion = 'beat' | 'flicker' | 'swing' | 'wave' | 'fly' | 'drive' | 'bounce' | 'hop' | 'spin' | 'flip' | 'float' | 'twinkle' | 'shake' | 'rain' | 'snow' | 'sleep' | 'rock' | 'burst' | 'stamp' | 'gleam' | 'flag' | 'sway' | 'love' | 'steam' | 'look' | 'nod' | 'tilt' | 'swim' | 'flap' | 'clap' | 'bob' | 'pop';
|
|
29
|
+
export interface MagicDotMatrixEmojiOptions {
|
|
30
|
+
cols?: number;
|
|
31
|
+
rows?: number;
|
|
32
|
+
colors?: number;
|
|
33
|
+
threshold?: number;
|
|
34
|
+
}
|
|
35
|
+
export interface DotMatrixEmojiAnimation {
|
|
36
|
+
motion: DotMatrixEmojiMotion;
|
|
37
|
+
interval: number;
|
|
38
|
+
sequence: Array<DotMatrixLayeredFrame>;
|
|
39
|
+
colors: Array<string>;
|
|
40
|
+
}
|
|
File without changes
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { MagicDotMatrixEmojiOptions, MagicDotMatrixOptions } from '../types/index.js';
|
|
2
|
+
declare const defaultOptions: Required<MagicDotMatrixOptions>;
|
|
3
|
+
declare const defaultEmojiOptions: Required<MagicDotMatrixEmojiOptions>;
|
|
4
|
+
export { defaultOptions, defaultEmojiOptions };
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { DotMatrixEmojiAnimation, MagicDotMatrixEmojiOptions } from '../../types/index.js';
|
|
2
|
+
export type AnimateEmojiArgs = Required<MagicDotMatrixEmojiOptions> & {
|
|
3
|
+
emoji: string;
|
|
4
|
+
};
|
|
5
|
+
export declare function animateEmoji({ emoji, cols, rows, colors: colorCount, threshold, }: AnimateEmojiArgs): DotMatrixEmojiAnimation;
|