-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
137 additions
and
144 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,107 +1,103 @@ | ||
<template> | ||
<div class="InputCubicBezierPicker"> | ||
<svg ref="editor" viewBox="0 0 1 1" class="InputCubicBezierPicker__editor"> | ||
<g> | ||
<line :x1="0" :y1="0" :x2="x1" :y2="y1" /> | ||
<line :x1="1" :y1="1" :x2="x2" :y2="y2" /> | ||
<path :d="easingPath" /> | ||
<circle :cx="x1" :cy="y1" r=".035" @mousedown="draggingPoint = 0" /> | ||
<circle :cx="x2" :cy="y2" r=".035" @mousedown="draggingPoint = 1" /> | ||
</g> | ||
</svg> | ||
</div> | ||
</template> | ||
|
||
<script lang="ts"> | ||
<script lang="ts" setup> | ||
import {templateRef} from '@vueuse/core' | ||
import {clamp} from 'lodash' | ||
import {computed, defineComponent, PropType, ref} from 'vue-demi' | ||
import {CubicBezierPoints} from '@vueuse/core' | ||
import {vec2} from 'linearly' | ||
import {computed, ref} from 'vue-demi' | ||
import useDrag from '@/tweeq/useDragV1' | ||
export default defineComponent({ | ||
name: 'InputCubicBezierPicker', | ||
props: { | ||
modelValue: { | ||
type: Array as PropType<number[]>, | ||
required: true, | ||
}, | ||
}, | ||
emit: ['update:modelValue'], | ||
setup(props, context) { | ||
const editorEl = templateRef<HTMLElement>('editor') | ||
useDrag(editorEl, { | ||
onDrag({pos, left, right, top, bottom}) { | ||
if (draggingPoint.value === null) return | ||
import {CubicBezierValue} from './util' | ||
let x = (pos[0] - left) / (right - left) | ||
let y = 1 - (pos[1] - top) / (bottom - top) | ||
interface Props { | ||
modelValue: CubicBezierValue | ||
} | ||
x = clamp(x, 0, 1) | ||
y = clamp(y, 0, 1) | ||
const props = defineProps<Props>() | ||
const newValue = [...props.modelValue] | ||
const emit = defineEmits<{ | ||
'update:modelValue': [CubicBezierValue] | ||
}>() | ||
newValue[draggingPoint.value * 2 + 0] = x | ||
newValue[draggingPoint.value * 2 + 1] = y | ||
const $editor = templateRef<HTMLElement>('$editor') | ||
context.emit('update:modelValue', newValue) | ||
}, | ||
onDragEnd() { | ||
draggingPoint.value = null | ||
}, | ||
}) | ||
useDrag($editor, { | ||
onDrag({pos, left, right, top, bottom}) { | ||
if (draggingPoint.value === null) return | ||
const easingPath = computed(() => { | ||
const [x1, y1, x2, y2] = props.modelValue | ||
return `M 0,0 C ${x1},${y1} ${x2},${y2} 1,1` | ||
}) | ||
const uv = vec2.invlerp([left, bottom], [right, top], pos) | ||
const [x, y] = vec2.clamp(uv, [0, 0], [1, 1]) | ||
const x1 = computed(() => props.modelValue[0]) | ||
const y1 = computed(() => props.modelValue[1]) | ||
const x2 = computed(() => props.modelValue[2]) | ||
const y2 = computed(() => props.modelValue[3]) | ||
const newValue: CubicBezierPoints = [...props.modelValue] | ||
const draggingPoint = ref<number | null>(null) | ||
newValue[draggingPoint.value * 2 + 0] = x | ||
newValue[draggingPoint.value * 2 + 1] = y | ||
return {easingPath, x1, y1, x2, y2, draggingPoint} | ||
emit('update:modelValue', newValue) | ||
}, | ||
onDragEnd() { | ||
draggingPoint.value = null | ||
}, | ||
}) | ||
const easingPath = computed(() => { | ||
const [x1, y1, x2, y2] = props.modelValue | ||
return `M 0,0 C ${x1},${y1} ${x2},${y2} 1,1` | ||
}) | ||
const x1 = computed(() => props.modelValue[0]) | ||
const y1 = computed(() => props.modelValue[1]) | ||
const x2 = computed(() => props.modelValue[2]) | ||
const y2 = computed(() => props.modelValue[3]) | ||
const draggingPoint = ref<number | null>(null) | ||
</script> | ||
|
||
<template> | ||
<div class="InputCubicBezierPicker"> | ||
<svg ref="$editor" viewBox="0 0 1 1" class="pad"> | ||
<g> | ||
<line :x1="0" :y1="0" :x2="x1" :y2="y1" /> | ||
<line :x1="1" :y1="1" :x2="x2" :y2="y2" /> | ||
<path :d="easingPath" /> | ||
<circle :cx="x1" :cy="y1" r=".035" @mousedown="draggingPoint = 0" /> | ||
<circle :cx="x2" :cy="y2" r=".035" @mousedown="draggingPoint = 1" /> | ||
</g> | ||
</svg> | ||
</div> | ||
</template> | ||
|
||
<style lang="stylus"> | ||
@import '../common.styl' | ||
.InputCubicBezierPicker | ||
&__editor | ||
overflow visible | ||
margin 0.8em | ||
width calc(100% - 1.6em) | ||
.pad | ||
overflow visible | ||
margin 0.8em | ||
width calc(100% - 1.6em) | ||
* | ||
vector-effect non-scaling-stroke | ||
* | ||
vector-effect non-scaling-stroke | ||
g | ||
transform scaleY(-1) | ||
transform-origin 50% 50% | ||
g | ||
transform scaleY(-1) | ||
transform-origin 50% 50% | ||
path, line, circle | ||
fill none | ||
stroke-linecap round | ||
path, line, circle | ||
fill none | ||
stroke-linecap round | ||
path, circle | ||
stroke-width 2 | ||
stroke base16('05') | ||
path, circle | ||
stroke-width 2 | ||
stroke var(--tq-color-primary) | ||
line | ||
stroke-width 1 | ||
stroke base16('03') | ||
line | ||
stroke-width 1 | ||
stroke var(--md-sys-color-outline) | ||
circle | ||
fill var(--tq-color-text) | ||
circle | ||
fill var(--tq-color-bg) | ||
hover-transition(fill, stroke) | ||
&:hover | ||
fill var(--tq-color-primary) | ||
stroke var(--tq-color-primary) | ||
&:hover | ||
fill var(--tq-color-primary) | ||
stroke var(--tq-color-primary) | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
import InputCubicBezier from './InputCubicBezier.vue' | ||
import InputCubicBezierPicker from './InputCubicBezierPicker.vue' | ||
|
||
export default InputCubicBezier | ||
export {InputCubicBezier, InputCubicBezierPicker} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export type CubicBezierValue = readonly [number, number, number, number] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.