Skip to content

Commit

Permalink
Update Tweeq library
Browse files Browse the repository at this point in the history
  • Loading branch information
baku89 committed Oct 2, 2023
1 parent 0fed88a commit 14496f5
Show file tree
Hide file tree
Showing 51 changed files with 1,790 additions and 1,490 deletions.
15 changes: 12 additions & 3 deletions src/components/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ const testNumber = ref(Math.PI)
const testBoolean = ref(false)
const testAlign = ref<'left' | 'center' | 'right'>('left')
const colorSpace = ref<'r|g|b' | 'svh' | 'hsv' | 'hvs' | 'hsvr'>('hsv')
const cubicBezier = ref([0, 0.5, 0.5, 1] as const)
const testColor = ref('skyblue')
// interface PaperDesc {
// id?: string
Expand Down Expand Up @@ -401,6 +403,7 @@ window.addEventListener('drop', async e => {
</Tq.Tab>
</Tq.Tabs>
</Tq.FloatingPane>

<Tq.FloatingPane
name="timeline"
icon="timeline"
Expand All @@ -411,7 +414,7 @@ window.addEventListener('drop', async e => {
<Tq.InputString v-model="testString" />
</Tq.Parameter>
<Tq.Parameter label="Grow">
<Tq.InputNumber v-model="testNumber" :min="0" :max="Math.PI * 2" />
<Tq.InputNumber v-model="testNumber" />
</Tq.Parameter>
<Tq.Parameter label="Degrees">
<Tq.InputRotery v-model="testNumber" />
Expand All @@ -425,19 +428,25 @@ window.addEventListener('drop', async e => {
<Tq.Parameter label="Radio">
<Tq.InputRadio
v-model="testAlign"
:items="['left', 'center', 'right']"
:options="['left', 'center', 'right']"
/>
</Tq.Parameter>
<Tq.Parameter label="Radio">
<Tq.InputDropdown
v-model="colorSpace"
:items="['r|g|b', 'svh', 'hsv', 'hvs', 'hsvr']"
:options="['r|g|b', 'svh', 'hsv', 'hvs', 'hsvr']"
:labels="['RGB', 'SVH', 'HSV', 'HVS', 'Radial']"
/>
</Tq.Parameter>
<Tq.Parameter label="Button">
<Tq.InputButton label="Hey" />
</Tq.Parameter>
<Tq.Parameter label="Easing">
<Tq.InputCubicBezier v-model="cubicBezier" />
</Tq.Parameter>
<Tq.Parameter label="Stroke">
<Tq.InputColor v-model="testColor" :presets="['brown']" />
</Tq.Parameter>
</Tq.ParameterGrid>
</Tq.FloatingPane>
</div>
Expand Down
2 changes: 0 additions & 2 deletions src/tweeq/FloatingPane/FloatingPane.vue
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,6 @@ onMounted(() => {
.left
display none
.resize
position absolute
hover-transition()
Expand Down Expand Up @@ -380,4 +379,3 @@ onMounted(() => {
height 100%
hover-transition(opacity)
</style>
@/tweaq/useAppStorage
151 changes: 84 additions & 67 deletions src/tweeq/GlslCanvas.vue
Original file line number Diff line number Diff line change
@@ -1,87 +1,104 @@
<script lang="ts">
import _ from 'lodash'
import Regl from 'regl'
<script lang="ts" setup>
import {isEqual, mapValues} from 'lodash'
import Regl, {DrawConfig} from 'regl'
import REGL from 'regl'
import {
computed,
defineComponent,
onMounted,
onUnmounted,
PropType,
ref,
watch,
} from 'vue'
import {REGL_QUAD_DEFAULT} from './util'
interface UniformsProp {
[name: string]: number[] | string
}
import {computed, onMounted, onUnmounted, ref, watch} from 'vue'
export default defineComponent({
name: 'GlslCnavas',
props: {
fragmentString: {
type: String,
default: `
precision mediump float;
varying vec2 uv;
void main() { gl_FragColor = vec4(uv, 0, 1); }`,
},
uniforms: {
type: Object as PropType<UniformsProp>,
default: () => ({}),
},
const REGL_QUAD_DEFAULT: DrawConfig = {
vert: `
precision mediump float;
attribute vec2 position;
varying vec2 uv;
void main() {
uv = position / 2.0 + 0.5;
gl_Position = vec4(position, 0, 1);
}`,
attributes: {
position: [-1, -1, 1, -1, -1, 1, 1, 1],
},
depth: {
enable: false,
},
setup(props) {
const canvas = ref<null | HTMLCanvasElement>(null)
count: 4,
primitive: 'triangle strip',
}
interface Props {
fragmentString: string
uniforms: Record<
string,
number | number[] | readonly [number, number, number, number]
>
}
const regl = ref<null | REGL.Regl>(null)
const props = withDefaults(defineProps<Props>(), {
fragmentString: `
precision mediump float;
varying vec2 uv;
void main() { gl_FragColor = vec4(uv, 0, 1); }`,
uniforms: () => ({}),
})
onMounted(() => {
if (!canvas.value) {
return
}
const $canvas = ref<null | HTMLCanvasElement>(null)
regl.value = Regl({
attributes: {
depth: false,
premultipliedAlpha: false,
},
canvas: canvas.value,
})
})
const regl = ref<null | REGL.Regl>(null)
onUnmounted(() => regl.value?.destroy())
onMounted(() => {
if (!$canvas.value) return
const uniformKeys = ref(_.keys(props.uniforms))
regl.value = Regl({
attributes: {
depth: false,
premultipliedAlpha: false,
},
canvas: $canvas.value,
})
})
const drawCommand = computed(() => {
if (!regl.value) return null
onUnmounted(() => regl.value?.destroy())
const prop = regl.value.prop as any
const reglUniforms = ref<Record<string, any>>({})
const uniforms = _.fromPairs(uniformKeys.value.map(k => [k, prop(k)]))
watch(
() => [props.uniforms, regl.value] as const,
([uniforms, regl]) => {
const keys = Object.keys(uniforms)
const oldKeys = Object.keys(reglUniforms.value)
return regl.value({
...REGL_QUAD_DEFAULT,
frag: props.fragmentString,
uniforms,
})
})
if (isEqual(keys, oldKeys)) return
if (!regl) return
watch(
() => [regl.value, drawCommand.value, props.uniforms],
() => {
drawCommand.value && drawCommand.value(props.uniforms)
}
)
const prop = regl.prop as any
return {canvas}
reglUniforms.value = mapValues(props.uniforms, (_, key) => prop(key))
},
{immediate: true}
)
const drawCommand = computed(() => {
if (!regl.value) return null
return regl.value({
...REGL_QUAD_DEFAULT,
frag: props.fragmentString,
uniforms: reglUniforms.value,
})
})
watch(
() => [drawCommand.value, props.uniforms] as const,
([draw, uniforms]) => {
// TODO: Fix this
try {
draw && draw(uniforms)
} catch {
return
}
},
{immediate: true}
)
</script>

<template>
<canvas ref="canvas" />
<canvas ref="$canvas" />
</template>
7 changes: 5 additions & 2 deletions src/tweeq/InputButton.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,12 @@ withDefaults(defineProps<Props>(), {label: ''})
background var(--tq-color-primary-container)
color var(--md-sys-color-on-primary-container)
font-size inherit
hover-transition(background, collor)
hover-transition(background, color)
&:hover, &:focus-visible
&:focus-visible
background var(--tq-color-tinted-input-active)
&:hover
color var(--tq-color-on-primary)
background var(--tq-color-primary)
</style>
3 changes: 2 additions & 1 deletion src/tweeq/InputCheckbox/InputCheckbox.vue
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ function onInput(e: InputEvent) {
color var(--tq-color-primary)
line-height 1em
pointer-events none
hover-transition(box-shadow)
&__checkmark
position relative
Expand All @@ -100,7 +101,7 @@ function onInput(e: InputEvent) {
// Hover and Focus
&:hover &__frame,
&:focus-within &__frame
box-shadow inset 0 0 0 1px var(--tq-color-primary)
box-shadow 0 0 0 1px var(--tq-color-primary)
color var(--tq-color-primary)
// Label
Expand Down

0 comments on commit 14496f5

Please sign in to comment.