2021-09-04 10:54:24 +02:00
|
|
|
<template>
|
2023-01-15 12:55:09 +01:00
|
|
|
<MkContainer :naked="widgetProps.transparent" :show-header="false" class="mkw-aichan data-cy-mkw-aichan">
|
2021-11-19 11:36:12 +01:00
|
|
|
<iframe ref="live2d" class="dedjhjmo" src="https://misskey-dev.github.io/mascot-web/?scale=1.5&y=1.1&eyeY=100" @click="touched"></iframe>
|
2021-09-04 10:54:24 +02:00
|
|
|
</MkContainer>
|
|
|
|
</template>
|
|
|
|
|
2022-01-08 12:30:01 +01:00
|
|
|
<script lang="ts" setup>
|
2023-02-16 15:09:41 +01:00
|
|
|
import { onMounted, onUnmounted, shallowRef } from 'vue';
|
|
|
|
import { useWidgetPropsManager, Widget, WidgetComponentExpose } from './widget';
|
2022-06-25 20:12:58 +02:00
|
|
|
import { GetFormResultType } from '@/scripts/form';
|
2021-09-04 10:54:24 +02:00
|
|
|
|
2022-01-08 12:30:01 +01:00
|
|
|
const name = 'ai';
|
|
|
|
|
|
|
|
const widgetPropsDef = {
|
|
|
|
transparent: {
|
|
|
|
type: 'boolean' as const,
|
|
|
|
default: false,
|
2021-09-04 10:54:24 +02:00
|
|
|
},
|
2022-01-08 12:30:01 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
type WidgetProps = GetFormResultType<typeof widgetPropsDef>;
|
|
|
|
|
|
|
|
// 現時点ではvueの制限によりimportしたtypeをジェネリックに渡せない
|
|
|
|
//const props = defineProps<WidgetComponentProps<WidgetProps>>();
|
|
|
|
//const emit = defineEmits<WidgetComponentEmits<WidgetProps>>();
|
|
|
|
const props = defineProps<{ widget?: Widget<WidgetProps>; }>();
|
2022-05-25 09:43:12 +02:00
|
|
|
const emit = defineEmits<{ (ev: 'updateProps', props: WidgetProps); }>();
|
2022-01-08 12:30:01 +01:00
|
|
|
|
|
|
|
const { widgetProps, configure } = useWidgetPropsManager(name,
|
|
|
|
widgetPropsDef,
|
|
|
|
props,
|
|
|
|
emit,
|
|
|
|
);
|
|
|
|
|
2023-01-03 02:12:37 +01:00
|
|
|
const live2d = shallowRef<HTMLIFrameElement>();
|
2022-01-08 12:30:01 +01:00
|
|
|
|
|
|
|
const touched = () => {
|
|
|
|
//if (this.live2d) this.live2d.changeExpression('gurugurume');
|
|
|
|
};
|
|
|
|
|
2022-06-25 20:12:58 +02:00
|
|
|
const onMousemove = (ev: MouseEvent) => {
|
|
|
|
const iframeRect = live2d.value.getBoundingClientRect();
|
|
|
|
live2d.value.contentWindow.postMessage({
|
|
|
|
type: 'moveCursor',
|
|
|
|
body: {
|
|
|
|
x: ev.clientX - iframeRect.left,
|
|
|
|
y: ev.clientY - iframeRect.top,
|
|
|
|
},
|
|
|
|
}, '*');
|
|
|
|
};
|
2022-01-08 12:30:01 +01:00
|
|
|
|
2022-06-25 20:12:58 +02:00
|
|
|
onMounted(() => {
|
2022-01-08 12:30:01 +01:00
|
|
|
window.addEventListener('mousemove', onMousemove, { passive: true });
|
2022-06-25 20:12:58 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
onUnmounted(() => {
|
|
|
|
window.removeEventListener('mousemove', onMousemove);
|
2022-01-08 12:30:01 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
defineExpose<WidgetComponentExpose>({
|
|
|
|
name,
|
|
|
|
configure,
|
|
|
|
id: props.widget ? props.widget.id : null,
|
2021-09-04 10:54:24 +02:00
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
2022-12-27 10:29:39 +01:00
|
|
|
<style lang="scss" scoped>
|
2021-09-04 10:54:24 +02:00
|
|
|
.dedjhjmo {
|
|
|
|
width: 100%;
|
|
|
|
height: 350px;
|
|
|
|
border: none;
|
|
|
|
pointer-events: none;
|
|
|
|
}
|
|
|
|
</style>
|