2021-09-04 11:54:24 +03:00
|
|
|
<template>
|
2022-01-08 13:30:01 +02:00
|
|
|
<MkContainer :naked="widgetProps.transparent" :show-header="false">
|
2021-11-19 12:36:12 +02: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 11:54:24 +03:00
|
|
|
</MkContainer>
|
|
|
|
</template>
|
|
|
|
|
2022-01-08 13:30:01 +02:00
|
|
|
<script lang="ts" setup>
|
|
|
|
import { onMounted, onUnmounted, reactive, ref } from 'vue';
|
|
|
|
import { GetFormResultType } from '@/scripts/form';
|
|
|
|
import { useWidgetPropsManager, Widget, WidgetComponentEmits, WidgetComponentExpose, WidgetComponentProps } from './widget';
|
2021-09-04 11:54:24 +03:00
|
|
|
|
2022-01-08 13:30:01 +02:00
|
|
|
const name = 'ai';
|
|
|
|
|
|
|
|
const widgetPropsDef = {
|
|
|
|
transparent: {
|
|
|
|
type: 'boolean' as const,
|
|
|
|
default: false,
|
2021-09-04 11:54:24 +03:00
|
|
|
},
|
2022-01-08 13:30:01 +02: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>; }>();
|
|
|
|
const emit = defineEmits<{ (e: 'updateProps', props: WidgetProps); }>();
|
|
|
|
|
|
|
|
const { widgetProps, configure } = useWidgetPropsManager(name,
|
|
|
|
widgetPropsDef,
|
|
|
|
props,
|
|
|
|
emit,
|
|
|
|
);
|
|
|
|
|
|
|
|
const live2d = ref<HTMLIFrameElement>();
|
|
|
|
|
|
|
|
const touched = () => {
|
|
|
|
//if (this.live2d) this.live2d.changeExpression('gurugurume');
|
|
|
|
};
|
|
|
|
|
|
|
|
onMounted(() => {
|
|
|
|
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,
|
|
|
|
}
|
|
|
|
}, '*');
|
|
|
|
};
|
|
|
|
|
|
|
|
window.addEventListener('mousemove', onMousemove, { passive: true });
|
|
|
|
onUnmounted(() => {
|
|
|
|
window.removeEventListener('mousemove', onMousemove);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
defineExpose<WidgetComponentExpose>({
|
|
|
|
name,
|
|
|
|
configure,
|
|
|
|
id: props.widget ? props.widget.id : null,
|
2021-09-04 11:54:24 +03:00
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
.dedjhjmo {
|
|
|
|
width: 100%;
|
|
|
|
height: 350px;
|
|
|
|
border: none;
|
|
|
|
pointer-events: none;
|
|
|
|
}
|
|
|
|
</style>
|