-
Notifications
You must be signed in to change notification settings - Fork 2
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
10 changed files
with
330 additions
and
9 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
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,83 @@ | ||
<script lang="ts"> | ||
import SvelteMarkdown from 'svelte-markdown' | ||
import {getContext, onDestroy, onMount} from "svelte"; | ||
import type {Writable} from "svelte/store"; | ||
import {popups, type PopupState} from "$state/popup.svelte"; | ||
import { _ } from 'svelte-i18n' | ||
interface Props { | ||
explanation: Promise<string> | ||
} | ||
let { explanation }: Props = $props(); | ||
const popupState = getContext<Writable<PopupState>>("state"); | ||
let element: HTMLDivElement | ||
function click(event: MouseEvent) { | ||
if (element.contains(event.target as HTMLElement)) return | ||
popups.close($popupState.id); | ||
} | ||
onMount(() => { | ||
document.body.addEventListener('click', click) | ||
}) | ||
onDestroy(() => { | ||
document.body.removeEventListener('click', click) | ||
}) | ||
</script> | ||
|
||
<div class="content" bind:this={element}> | ||
<h2>{$_("EXPLANATION")}</h2> | ||
{#await explanation} | ||
<div class="container"> | ||
<div class="loading"></div> | ||
<div class="loading"></div> | ||
<div class="loading"></div> | ||
<div class="loading"></div> | ||
</div> | ||
{:then explanation} | ||
<SvelteMarkdown source="{explanation}" /> | ||
{/await} | ||
<div class="footer">{$_("META_ATTRIBUTION")}</div> | ||
</div> | ||
|
||
<style> | ||
.content { | ||
width: 400px; | ||
padding: 20px; | ||
} | ||
.footer { | ||
color: var(--on-secondary-muted); | ||
} | ||
.container { | ||
display: flex; | ||
flex-direction: column; | ||
gap: 5px; | ||
margin: 16px 0; | ||
} | ||
.loading { | ||
background: linear-gradient( | ||
100deg, | ||
rgba(255, 255, 255, 0) 40%, | ||
rgba(255, 255, 255, .5) 50%, | ||
rgba(255, 255, 255, 0) 60% | ||
) #a5a5a550; | ||
background-size: 200% 100%; | ||
background-position-x: 180%; | ||
animation: 1s loading ease-in-out infinite; | ||
height: 14px; | ||
width: 100%; | ||
} | ||
@keyframes loading { | ||
to { | ||
background-position-x: -20%; | ||
} | ||
} | ||
</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 |
---|---|---|
@@ -0,0 +1,94 @@ | ||
<script lang="ts"> | ||
import Fa from "svelte-fa"; | ||
import { | ||
faMagicWandSparkles, | ||
} from "@fortawesome/free-solid-svg-icons"; | ||
import * as Blockly from "blockly"; | ||
import {get} from "svelte/store"; | ||
import {workspace} from "$state/blockly.svelte"; | ||
import type {WorkspaceSvg} from "blockly"; | ||
import {onDestroy, onMount} from "svelte"; | ||
import {explain} from "$domain/blockly/blockly"; | ||
function getBlockForPosition(event: PointerEvent) { | ||
const space = get(workspace) as WorkspaceSvg | ||
if (!space) return | ||
return space.getAllBlocks(true).reverse().find(block => { | ||
const bounding = block.pathObject.svgPath.getBoundingClientRect() | ||
if (bounding.x > event.clientX || bounding.y > event.clientY) return false | ||
return !(bounding.x + bounding.width < event.clientX || bounding.y + bounding.height < event.clientY) | ||
}) | ||
} | ||
let previous: Blockly.BlockSvg = null | ||
let selecting = false | ||
function pointerMove(event: PointerEvent) { | ||
if (!selecting) return | ||
const block =getBlockForPosition(event) | ||
previous?.setHighlighted(false) | ||
block?.setHighlighted(true) | ||
previous = block | ||
} | ||
async function select(event: PointerEvent) { | ||
if (!selecting) return | ||
previous?.setHighlighted(false) | ||
selecting = false | ||
const block = getBlockForPosition(event) | ||
if (!block) return | ||
await explain(block) | ||
} | ||
function onclick() { | ||
selecting = true | ||
} | ||
onMount(() => { | ||
document.body.addEventListener('pointermove', pointerMove) | ||
document.body.addEventListener('pointerup', select) | ||
}) | ||
onDestroy(() => { | ||
document.body.removeEventListener('pointermove', pointerMove) | ||
document.body.removeEventListener('pointerup', select) | ||
}) | ||
</script> | ||
|
||
<button class="dropper" class:selecting {onclick}> | ||
<Fa icon="{faMagicWandSparkles}" /> | ||
</button> | ||
{#if selecting} | ||
<div class="noInteract"></div> | ||
{/if} | ||
|
||
<style> | ||
.dropper { | ||
all: unset; | ||
position: fixed; | ||
bottom: 35px; | ||
right: 116px; | ||
color: rgba(136, 136, 136, 0.5); | ||
font-size: 45px; | ||
cursor: pointer; | ||
} | ||
.selecting { | ||
color: rgba(84, 93, 149, 0.5); | ||
} | ||
.noInteract { | ||
position: fixed; | ||
left: 0; | ||
top: 0; | ||
width: 100vw; | ||
height: 100vh; | ||
z-index: 9999999999; | ||
cursor: crosshair; | ||
} | ||
</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
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.