Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 83 additions & 4 deletions apps/tauri/src/App.vue
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
<script setup lang="ts">
import { onMounted, ref } from "vue";
import { computed, onMounted, ref } from "vue";
import { invoke } from "@tauri-apps/api/core";
import { useShellStore } from "./stores/shell";
import {
applyTheme,
initTheme,
type QueryaThemeMode,
} from "./theme/queryaTheme";
import {
provideQueryaMotion,
type QueryaMotionLevel,
} from "./motion";

const shell = useShellStore();
const motion = provideQueryaMotion();
const { level: motionLevel, springsOn } = motion;
const backend = ref<string>("…");
const theme = ref<QueryaThemeMode>("system");
const panelOpen = ref(false);

const swatches = [
{ name: "bg", varName: "--q-background" },
Expand All @@ -21,6 +28,11 @@ const swatches = [
{ name: "destructive", varName: "--q-destructive" },
] as const;

const panelStyle = computed(() => ({
transitionDuration: `${motion.duration("standard")}ms`,
transitionTimingFunction: motion.easing("enter"),
}));

onMounted(async () => {
theme.value = initTheme();
try {
Expand All @@ -39,13 +51,20 @@ function setTheme(mode: QueryaThemeMode) {
theme.value = mode;
applyTheme(mode);
}

function setMotion(level: QueryaMotionLevel) {
motion.setLevel(level);
}
</script>

<template>
<div class="shell">
<header class="brand">Querya</header>
<p class="tagline">Tauri 2 + Vue 3 — Querya tokens (no shadcn)</p>
<p class="tagline">Tauri 2 + Vue 3 — tokens + Fluid Motion</p>
<p class="meta" data-testid="backend-info">{{ backend }}</p>
<p class="meta">
springs: {{ springsOn ? "on" : "off" }} · level: {{ motionLevel }}
</p>

<div class="swatches" aria-label="Querya token swatches">
<div v-for="s in swatches" :key="s.name" class="swatch">
Expand Down Expand Up @@ -80,6 +99,43 @@ function setTheme(mode: QueryaThemeMode) {
Dark
</button>
</div>

<div class="theme-row" role="group" aria-label="Motion">
<button
type="button"
class="btn"
:class="{ active: motionLevel === 'full' }"
@click="setMotion('full')"
>
Full
</button>
<button
type="button"
class="btn"
:class="{ active: motionLevel === 'reduced' }"
@click="setMotion('reduced')"
>
Reduced
</button>
<button
type="button"
class="btn"
:class="{ active: motionLevel === 'off' }"
@click="setMotion('off')"
>
Off
</button>
</div>

<button type="button" class="btn demo-toggle" @click="panelOpen = !panelOpen">
Toggle demo panel
</button>
<div
class="demo-panel"
:class="{ open: panelOpen }"
:style="panelStyle"
data-testid="motion-demo-panel"
/>
</div>
</template>

Expand All @@ -88,6 +144,7 @@ function setTheme(mode: QueryaThemeMode) {
min-height: 100%;
display: grid;
place-content: center;
justify-items: center;
gap: var(--q-space-2);
padding: var(--q-space-8);
text-align: center;
Expand All @@ -107,7 +164,7 @@ function setTheme(mode: QueryaThemeMode) {
}

.meta {
margin: var(--q-space-3) 0 0;
margin: var(--q-space-1) 0 0;
font-size: var(--q-text-sm);
color: var(--q-muted-foreground);
font-variant-numeric: tabular-nums;
Expand Down Expand Up @@ -144,7 +201,7 @@ function setTheme(mode: QueryaThemeMode) {
.theme-row {
display: inline-flex;
gap: var(--q-space-2);
margin-top: var(--q-space-6);
margin-top: var(--q-space-4);
padding: var(--q-space-1);
border-radius: var(--q-radius-lg);
background: var(--q-card);
Expand Down Expand Up @@ -172,4 +229,26 @@ function setTheme(mode: QueryaThemeMode) {
color: var(--q-primary-foreground);
background: var(--q-primary);
}

.demo-toggle {
margin-top: var(--q-space-4);
background: var(--q-secondary);
color: var(--q-secondary-foreground);
border: 1px solid var(--q-border);
}

.demo-panel {
width: 12rem;
height: 0;
margin-top: var(--q-space-3);
border-radius: var(--q-radius-md);
background: var(--q-primary);
opacity: 0.35;
transition-property: height, opacity;
}

.demo-panel.open {
height: 3rem;
opacity: 1;
}
</style>
10 changes: 10 additions & 0 deletions apps/tauri/src/motion/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export type { QueryaMotionLevel, SpringDescription } from "./types";
export {
QueryaMotionEasing,
QueryaMotionMs,
QueryaSpring,
effectiveDurationMs,
effectiveEasing,
springsEnabled,
} from "./tokens";
export { provideQueryaMotion, useQueryaMotion } from "./useQueryaMotion";
59 changes: 59 additions & 0 deletions apps/tauri/src/motion/tokens.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import type { QueryaMotionLevel, SpringDescription } from "./types";

/** Duration tokens — Flutter `QueryaMotion` (ms). */
export const QueryaMotionMs = {
instant: 0,
fast: 120,
standard: 200,
slow: 320,
treeExpand: 200,
sidebarCubic: 160,
} as const;

export type QueryaMotionToken = keyof typeof QueryaMotionMs;

/** CSS easing — Flutter curve counterparts. */
export const QueryaMotionEasing = {
enter: "cubic-bezier(0.33, 1, 0.68, 1)",
exit: "cubic-bezier(0.32, 0, 0.67, 0)",
standard: "cubic-bezier(0.65, 0, 0.35, 1)",
emphasized: "cubic-bezier(0.2, 0, 0, 1)",
linear: "linear",
} as const;

/** Spring presets — Flutter `QueryaSpring`. */
export const QueryaSpring: Record<"snappy" | "gentle" | "bouncy", SpringDescription> =
{
snappy: { mass: 1, stiffness: 400, damping: 40 },
gentle: { mass: 1, stiffness: 180, damping: 26.83 },
bouncy: { mass: 1, stiffness: 300, damping: 20 },
};

export function effectiveDurationMs(
level: QueryaMotionLevel,
tokenMs: number,
): number {
if (tokenMs <= 0) return 0;
switch (level) {
case "off":
return 0;
case "reduced": {
const halved = Math.floor(tokenMs / 2);
return halved <= 0 ? QueryaMotionMs.fast : halved;
}
case "full":
return tokenMs;
}
}

export function effectiveEasing(
level: QueryaMotionLevel,
easing: string = QueryaMotionEasing.standard,
): string {
return level === "off" ? QueryaMotionEasing.linear : easing;
}

/** Springs only in Full (Flutter `QueryaSpring.springsEnabled`). */
export function springsEnabled(level: QueryaMotionLevel): boolean {
return level === "full";
}
8 changes: 8 additions & 0 deletions apps/tauri/src/motion/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/** Matches Flutter `QueryaMotionLevel`. */
export type QueryaMotionLevel = "full" | "reduced" | "off";

export type SpringDescription = {
mass: number;
stiffness: number;
damping: number;
};
71 changes: 71 additions & 0 deletions apps/tauri/src/motion/useQueryaMotion.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import { computed, inject, provide, ref, type InjectionKey, type Ref } from "vue";
import {
effectiveDurationMs,
effectiveEasing,
QueryaMotionEasing,
QueryaMotionMs,
springsEnabled,
type QueryaMotionToken,
} from "./tokens";
import type { QueryaMotionLevel } from "./types";

const STORAGE_KEY = "querya.motion";

type MotionApi = {
level: Ref<QueryaMotionLevel>;
setLevel: (level: QueryaMotionLevel) => void;
duration: (token?: QueryaMotionToken | number) => number;
easing: (name?: keyof typeof QueryaMotionEasing) => string;
springsOn: Ref<boolean>;
};

const MotionKey: InjectionKey<MotionApi> = Symbol("querya-motion");

function readStoredLevel(): QueryaMotionLevel {
const raw = localStorage.getItem(STORAGE_KEY);
if (raw === "full" || raw === "reduced" || raw === "off") return raw;
return "full";
}

export function provideQueryaMotion(
initial: QueryaMotionLevel = readStoredLevel(),
): MotionApi {
const level = ref<QueryaMotionLevel>(initial);

function applyDom(next: QueryaMotionLevel) {
document.documentElement.dataset.motion = next;
localStorage.setItem(STORAGE_KEY, next);
}

applyDom(level.value);

function setLevel(next: QueryaMotionLevel) {
level.value = next;
applyDom(next);
}

function duration(token: QueryaMotionToken | number = "standard"): number {
const ms = typeof token === "number" ? token : QueryaMotionMs[token];
return effectiveDurationMs(level.value, ms);
}

function easing(name: keyof typeof QueryaMotionEasing = "standard"): string {
return effectiveEasing(level.value, QueryaMotionEasing[name]);
}

const springsOn = computed(() => springsEnabled(level.value));

const api: MotionApi = { level, setLevel, duration, easing, springsOn };
provide(MotionKey, api);
return api;
}

export function useQueryaMotion(): MotionApi {
const api = inject(MotionKey);
if (!api) {
throw new Error(
"useQueryaMotion() requires provideQueryaMotion() in an ancestor",
);
}
return api;
}
1 change: 1 addition & 0 deletions apps/tauri/src/styles/base.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
@import "./tokens.css";
@import "./motion.css";

*,
*::before,
Expand Down
32 changes: 32 additions & 0 deletions apps/tauri/src/styles/motion.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/**
* Fluid Motion CSS hooks. `data-motion` on <html> is set by provideQueryaMotion.
* Components should prefer the composable for JS; use these vars for CSS transitions.
*/

:root,
:root[data-motion="full"] {
--q-motion-fast: 120ms;
--q-motion-standard: 200ms;
--q-motion-slow: 320ms;
--q-motion-sidebar: 160ms;
--q-motion-ease: cubic-bezier(0.65, 0, 0.35, 1);
--q-motion-ease-enter: cubic-bezier(0.33, 1, 0.68, 1);
--q-motion-ease-exit: cubic-bezier(0.32, 0, 0.67, 0);
}

:root[data-motion="reduced"] {
--q-motion-fast: 60ms;
--q-motion-standard: 100ms;
--q-motion-slow: 160ms;
--q-motion-sidebar: 80ms;
}

:root[data-motion="off"] {
--q-motion-fast: 0ms;
--q-motion-standard: 0ms;
--q-motion-slow: 0ms;
--q-motion-sidebar: 0ms;
--q-motion-ease: linear;
--q-motion-ease-enter: linear;
--q-motion-ease-exit: linear;
}
Loading