enhance: improve avatar decoration
This commit is contained in:
		| @@ -34,6 +34,7 @@ const props = withDefaults(defineProps<{ | ||||
| 	textConverter?: (value: number) => string, | ||||
| 	showTicks?: boolean; | ||||
| 	easing?: boolean; | ||||
| 	continuousUpdate?: boolean; | ||||
| }>(), { | ||||
| 	step: 1, | ||||
| 	textConverter: (v) => v.toString(), | ||||
| @@ -123,6 +124,10 @@ const onMousedown = (ev: MouseEvent | TouchEvent) => { | ||||
| 		const pointerX = ev.touches && ev.touches.length > 0 ? ev.touches[0].clientX : ev.clientX; | ||||
| 		const pointerPositionOnContainer = pointerX - (containerRect.left + (thumbWidth / 2)); | ||||
| 		rawValue.value = Math.min(1, Math.max(0, pointerPositionOnContainer / (containerEl.value!.offsetWidth - thumbWidth))); | ||||
|  | ||||
| 		if (props.continuousUpdate) { | ||||
| 			emit('update:modelValue', finalValue.value); | ||||
| 		} | ||||
| 	}; | ||||
|  | ||||
| 	let beforeValue = finalValue.value; | ||||
|   | ||||
| @@ -23,7 +23,16 @@ SPDX-License-Identifier: AGPL-3.0-only | ||||
| 			</div> | ||||
| 		</div> | ||||
| 	</div> | ||||
| 	<img v-if="decoration || user.avatarDecorations.length > 0" :class="[$style.decoration]" :src="decoration ?? user.avatarDecorations[0].url" alt=""> | ||||
| 	<img | ||||
| 		v-if="decoration || user.avatarDecorations.length > 0" | ||||
| 		:class="[$style.decoration]" | ||||
| 		:src="decoration?.url ?? user.avatarDecorations[0].url" | ||||
| 		:style="{ | ||||
| 			rotate: getDecorationAngle(), | ||||
| 			scale: getDecorationScale(), | ||||
| 		}" | ||||
| 		alt="" | ||||
| 	> | ||||
| </component> | ||||
| </template> | ||||
|  | ||||
| @@ -48,12 +57,18 @@ const props = withDefaults(defineProps<{ | ||||
| 	link?: boolean; | ||||
| 	preview?: boolean; | ||||
| 	indicator?: boolean; | ||||
| 	decoration?: string; | ||||
| 	decoration?: { | ||||
| 		url: string; | ||||
| 		angle?: number; | ||||
| 		flipH?: boolean; | ||||
| 		flipV?: boolean; | ||||
| 	}; | ||||
| }>(), { | ||||
| 	target: null, | ||||
| 	link: false, | ||||
| 	preview: false, | ||||
| 	indicator: false, | ||||
| 	decoration: undefined, | ||||
| }); | ||||
|  | ||||
| const emit = defineEmits<{ | ||||
| @@ -73,6 +88,30 @@ function onClick(ev: MouseEvent): void { | ||||
| 	emit('click', ev); | ||||
| } | ||||
|  | ||||
| function getDecorationAngle() { | ||||
| 	let angle; | ||||
| 	if (props.decoration) { | ||||
| 		angle = props.decoration.angle ?? 0; | ||||
| 	} else if (props.user.avatarDecorations.length > 0) { | ||||
| 		angle = props.user.avatarDecorations[0].angle ?? 0; | ||||
| 	} else { | ||||
| 		angle = 0; | ||||
| 	} | ||||
| 	return angle === 0 ? undefined : `${angle * 360}deg`; | ||||
| } | ||||
|  | ||||
| function getDecorationScale() { | ||||
| 	let scaleX; | ||||
| 	if (props.decoration) { | ||||
| 		scaleX = props.decoration.flipH ? -1 : 1; | ||||
| 	} else if (props.user.avatarDecorations.length > 0) { | ||||
| 		scaleX = props.user.avatarDecorations[0].flipH ? -1 : 1; | ||||
| 	} else { | ||||
| 		scaleX = 1; | ||||
| 	} | ||||
| 	return scaleX === 1 ? undefined : `${scaleX} 1`; | ||||
| } | ||||
|  | ||||
| let color = $ref<string | undefined>(); | ||||
|  | ||||
| watch(() => props.user.avatarBlurhash, () => { | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 syuilo
					syuilo