Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add matrix background with info box transparency effects #77

Merged
merged 23 commits into from
May 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
3d30938
Initial implementation of matrix background with text from DDJ
amosjyng Apr 26, 2024
9412661
Display matrix background in Storybook
amosjyng Apr 26, 2024
8d94e72
Lower infobox opacity to make background effect more visible
amosjyng Apr 26, 2024
9195c49
Add background blur effect to info boxes
amosjyng Apr 28, 2024
059c3d8
Apply fade-in to entire InfoBox story
amosjyng Apr 28, 2024
009e5b1
Avoid having the background canvas overwrite the rounded corners of t…
amosjyng Apr 28, 2024
c9826d2
Fix blurred clip path background on Windows
amosjyng Apr 28, 2024
2e87fe5
Fix errant scrollable height calculation
amosjyng Apr 28, 2024
8d70ee5
Reintroduce support for background animation toggle
amosjyng Apr 30, 2024
ed59a33
Respect animation speed in background
amosjyng Apr 30, 2024
7e71bdb
Add non-persistent transparency toggle
amosjyng Apr 30, 2024
d0f0b71
Make it possible for null Settings JSON fields to be omitted entirely
amosjyng Apr 30, 2024
c4faa27
Persist transparency preference
amosjyng Apr 30, 2024
2d4c137
Make FS test failures more obvious
amosjyng Apr 30, 2024
b9a822e
Default transparency to on for Windows
amosjyng May 1, 2024
3d11cc8
Fix mutability lint on Linux
amosjyng May 1, 2024
5545906
Apply background animation to fewer storybook stories
amosjyng May 1, 2024
aba7bf4
Add custom Chinese font for background
amosjyng May 1, 2024
b9d9522
Position scrollbars at right side of entire window
amosjyng May 1, 2024
90cabc1
Try to wait for Chinese font to load before animating background
amosjyng May 1, 2024
d07d6b3
Try a different way of ensuring the font is loaded before animating t…
amosjyng May 1, 2024
77737e8
Update screenshots
amosjyng May 1, 2024
c5b5ac1
Fix AppLayout test by mocking document.fonts
amosjyng May 1, 2024
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
1 change: 1 addition & 0 deletions src-svelte/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
"@neodrag/svelte": "file:../forks/neodrag/packages/svelte",
"autosize": "^6.0.1",
"nanoid": "^3.3.6",
"pure-rand": "^6.1.0",
"svelte-highlight": "^7.6.0",
"svelte-markdown": "^0.4.1"
}
Expand Down
Binary file modified src-svelte/screenshots/baseline/layout/app/static.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src-svelte/screenshots/baseline/layout/background/static.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src-svelte/screenshots/baseline/screens/llm-call/list/full.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src-svelte/screenshots/baseline/screens/settings/tablet.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
73 changes: 52 additions & 21 deletions src-svelte/src/lib/InfoBox.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@
import getComponentId from "./label-id";
import RoundDef from "./RoundDef.svelte";
import { cubicInOut, cubicOut, linear } from "svelte/easing";
import { animationSpeed, animationsOn } from "./preferences";
import { animationSpeed, animationsOn, transparencyOn } from "./preferences";
import { fade, type TransitionConfig } from "svelte/transition";
import { firstAppLoad, firstPageLoad } from "./firstPageLoad";
import { SubAnimation, PropertyAnimation } from "$lib/animation-timing";
Expand Down Expand Up @@ -514,7 +514,14 @@
<RoundDef />

<div class="border-container">
<div class="border-box" in:revealOutline|global={timing.borderBox}></div>
<div
class="border-box"
class:transparent={$transparencyOn}
in:revealOutline|global={timing.borderBox}
>
<div class="blur"></div>
<div class="background"></div>
</div>
<div class="info-box">
<h2
in:revealTitle|global={timing.title}
Expand Down Expand Up @@ -549,32 +556,56 @@
flex-direction: column;
}

.border-box {
.border-box,
.border-box div,
.border-box div::before {
width: 100%;
height: 100%;
position: absolute;
filter: url(#round) drop-shadow(0px 1px 4px rgba(26, 58, 58, 0.4));
}

.border-box {
z-index: 1;
--cut-depth: calc(2 * var(--cut) * cos(45deg));
--poly: polygon(
0% var(--cut-depth),
var(--cut-depth) 0%,
100% 0%,
100% calc(100% - var(--cut-depth)),
calc(100% - var(--cut-depth)) 100%,
0% 100%
);
}

.border-box .blur {
display: none;
}

.border-box.transparent .blur {
display: block;
}

.border-box::before {
.border-box .blur::before {
backdrop-filter: blur(9px);
-webkit-clip-path: var(--poly);
clip-path: var(--poly);
content: "";
}

.border-box .background {
filter: url(#round) drop-shadow(0px 1px 4px rgba(26, 58, 58, 0.4));
}

.border-box.transparent .background {
filter: url(#round) drop-shadow(0px 1px 4px rgba(26, 58, 58, 0.8));
opacity: 0.5;
}

.border-box .background::before {
background: #fff;
-webkit-clip-path: var(--poly);
clip-path: var(--poly);
content: "";
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
background: var(--color-foreground);
-webkit-mask:
linear-gradient(-45deg, transparent 0 var(--cut), #fff 0) bottom right,
linear-gradient(135deg, transparent 0 var(--cut), #fff 0) top left;
-webkit-mask-size: 51% 100%;
-webkit-mask-repeat: no-repeat;
mask:
linear-gradient(-45deg, transparent 0 var(--cut), #fff 0) bottom right,
linear-gradient(135deg, transparent 0 var(--cut), #fff 0) top left;
mask-size: 51% 100%;
mask-repeat: no-repeat;
}

.info-box {
Expand Down
2 changes: 1 addition & 1 deletion src-svelte/src/lib/InfoBoxView.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

<div style="--base-animation-speed: {$animationSpeed};">
<InfoBox {...$$restProps}>
<p>
<p class="atomic-reveal">
How do we know that even the realest of realities wouldn't be subjective,
in the final analysis? Nobody can prove his existence, can he? &mdash; <em
>Simulacron 3</em
Expand Down
3 changes: 2 additions & 1 deletion src-svelte/src/lib/Scrollable.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
return;
}

scrollableHeight = `${container.clientHeight}px`;
const newHeight = Math.floor(container.getBoundingClientRect().height);
scrollableHeight = `${newHeight}px`;
dispatchResizeEvent("resize", scrollable.getDimensions());
});
}
Expand Down
22 changes: 21 additions & 1 deletion src-svelte/src/lib/__mocks__/MockPageTransitions.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,26 @@
import MockFullPageLayout from "./MockFullPageLayout.svelte";
import PageTransition from "../../routes/PageTransition.svelte";
import { firstAppLoad, firstPageLoad } from "$lib/firstPageLoad";
import { animationSpeed } from "$lib/preferences";
import {
animationSpeed,
transparencyOn,
backgroundAnimation,
} from "$lib/preferences";
import Background from "../../routes/Background.svelte";

firstAppLoad.set(true);
firstPageLoad.set(true);
animationSpeed.set(0.1);
transparencyOn.set(true);
backgroundAnimation.set(true);
</script>

<div id="mock-transitions">
<MockFullPageLayout>
<div class="bg">
<Background />
</div>

<PageTransition currentRoute="/storybook-demo">
<slot />
</PageTransition>
Expand All @@ -21,4 +32,13 @@
#mock-transitions {
margin: -1rem;
}

.bg {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
z-index: -1;
}
</style>
2 changes: 1 addition & 1 deletion src-svelte/src/lib/bindings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export type Llm = { name: string; requested: string; provider: Service }
export type Service = "OpenAI"
export type EntityId = { uuid: string }
export type Response = { completion: ChatMessage }
export type Preferences = { animations_on: boolean | null; background_animation: boolean | null; animation_speed: number | null; sound_on: boolean | null; volume: number | null }
export type Preferences = { animations_on?: boolean | null; background_animation?: boolean | null; animation_speed?: number | null; transparency_on?: boolean | null; sound_on?: boolean | null; volume?: number | null }
export type ApiKeys = { openai: string | null }
export type OS = "Mac" | "Linux" | "Windows"
export type Shell = "Bash" | "Zsh" | "PowerShell"
Expand Down
10 changes: 1 addition & 9 deletions src-svelte/src/lib/preferences.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { writable, derived } from "svelte/store";
import type { Preferences } from "./bindings";

export const animationsOn = writable(true);
export const transparencyOn = writable(false);
export const backgroundAnimation = writable(false);
export const animationSpeed = writable(1);
export const soundOn = writable(true);
Expand All @@ -12,11 +12,3 @@ export const standardDuration = derived(
([$animationsOn, $animationSpeed]) =>
$animationsOn ? 100 / $animationSpeed : 0,
);

export const NullPreferences: Preferences = {
animations_on: null,
background_animation: null,
animation_speed: null,
sound_on: null,
volume: null,
};
45 changes: 27 additions & 18 deletions src-svelte/src/routes/AppLayout.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
soundOn,
backgroundAnimation,
animationSpeed,
transparencyOn,
volume,
animationsOn,
} from "$lib/preferences";
Expand All @@ -20,28 +21,32 @@

onMount(async () => {
const prefs = await getPreferences();
if (prefs.sound_on !== null) {
if (prefs.sound_on != null) {
soundOn.set(prefs.sound_on);
}

if (prefs.volume !== null) {
if (prefs.volume != null) {
volume.set(prefs.volume);
}

if (prefs.animations_on !== null) {
if (prefs.animations_on != null) {
animationsOn.set(prefs.animations_on);
}

if (prefs.background_animation === null) {
if (prefs.background_animation == null) {
backgroundAnimation.set(true);
} else {
backgroundAnimation.set(prefs.background_animation);
}

if (prefs.animation_speed !== null) {
if (prefs.animation_speed != null) {
animationSpeed.set(prefs.animation_speed);
}

if (prefs.transparency_on != null) {
transparencyOn.set(prefs.transparency_on);
}

ready = true;
});
</script>
Expand All @@ -56,13 +61,15 @@
</div>
<Snackbar />

<main>
{#if ready}
<PageTransition {currentRoute}>
<slot />
</PageTransition>
{/if}
</main>
<div class="content-container">
<main>
{#if ready}
<PageTransition {currentRoute}>
<slot />
</PageTransition>
{/if}
</main>
</div>
</div>
</AnimationControl>
</div>
Expand All @@ -84,13 +91,9 @@
height: 100vh;
box-sizing: border-box;
margin-left: var(--sidebar-space);
overflow-x: hidden;
overflow-y: scroll;
border-radius: var(--main-corners);
background-color: var(--color-offwhite);
box-shadow: calc(-1 * var(--shadow-offset)) 0 var(--shadow-blur) 0 #ccc;
overflow-y: auto;
overflow-x: hidden;
}

.background-layout {
Expand All @@ -103,11 +106,17 @@
right: 0;
}

.content-container {
width: 100%;
height: 100%;
position: relative;
overflow-y: auto;
overflow-x: hidden;
}

main {
position: relative;
z-index: 1;
max-width: 70rem;
margin: 0 auto;
height: 100%;
}
</style>
27 changes: 27 additions & 0 deletions src-svelte/src/routes/AppLayout.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,25 @@ import {
volume,
animationsOn,
animationSpeed,
transparencyOn,
} from "$lib/preferences";
import { TauriInvokePlayback } from "$lib/sample-call-testing";
import { tickFor } from "$lib/test-helpers";

const tauriInvokeMock = vi.fn();

vi.stubGlobal("__TAURI_INVOKE__", tauriInvokeMock);
vi.stubGlobal("FontFace", function () {
return {
load: () => Promise.resolve(),
};
});
Object.defineProperty(document, "fonts", {
value: {
add: vi.fn(),
load: vi.fn(),
},
});

describe("AppLayout", () => {
let tauriInvokeMock: Mock;
Expand Down Expand Up @@ -103,4 +115,19 @@ describe("AppLayout", () => {
});
expect(tauriInvokeMock).toHaveReturnedTimes(1);
});

test("will set transparency if transparency preference overridden", async () => {
expect(get(transparencyOn)).toBe(false);
expect(tauriInvokeMock).not.toHaveBeenCalled();

playback.addSamples(
"../src-tauri/api/sample-calls/get_preferences-transparency-on.yaml",
);

render(AppLayout, { currentRoute: "/" });
await waitFor(() => {
expect(get(transparencyOn)).toBe(true);
});
expect(tauriInvokeMock).toHaveReturnedTimes(1);
});
});
Loading
Loading