Skip to content
Draft
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
20 changes: 19 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ jobs:
- name: GQL checks
run: |
vpx gql-tada generate output
vpx gql-tada generate output -c packages/plugin-7tv/tsconfig.json
vpx gql-tada check
vpx gql-tada check -c packages/plugin-7tv/tsconfig.json
- name: Type check
run: vpr check

Expand All @@ -37,10 +39,26 @@ jobs:
node-version: 24
cache: true
- name: Generate GQL types
run: vpx gql-tada generate output
run: |
vpx gql-tada generate output
vpx gql-tada generate output -c packages/plugin-7tv/tsconfig.json
- name: Check
run: vp check

test:
name: Test
runs-on: blacksmith-2vcpu-ubuntu-2404
steps:
- name: Checkout
uses: actions/checkout@v7
- name: Setup Vite+
uses: voidzero-dev/setup-vp@v1.22.0
with:
node-version: lts
cache: true
- name: Test
run: vp test

build:
name: Build
runs-on: blacksmith-2vcpu-ubuntu-2404
Expand Down
9 changes: 7 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"dev": "vp dev",
"build": "vp build",
"preview": "vp preview",
"sync": "svelte-kit sync && gql-tada generate-output && gql-tada turbo",
"sync": "svelte-kit sync && gql-tada generate-output && gql-tada turbo && gql-tada generate-output -c packages/plugin-7tv/tsconfig.json && gql-tada turbo -c packages/plugin-7tv/tsconfig.json",
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
"tauri": "tauri",
Expand Down Expand Up @@ -39,7 +39,12 @@
"@tauri-store/svelte": "^3.2.1",
"@ui-sdk/core": "0.1.0-beta.24",
"@ui-sdk/svelte": "0.1.0-beta.24",
"colord": "^2.14.1",
"@usehyperion/plugin": "workspace:^",
"@usehyperion/plugin-7tv": "workspace:^",
"@usehyperion/plugin-bttv": "workspace:^",
"@usehyperion/plugin-ffz": "workspace:^",
"@usehyperion/types": "workspace:^",
"colord": "^2.14.0",
"dayjs": "^1.11.23",
"gql.tada": "^1.11.6",
"graphql-web-lite": "16.6.0-4",
Expand Down
1 change: 1 addition & 0 deletions packages/plugin-7tv/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
gql-*.d.ts
27 changes: 27 additions & 0 deletions packages/plugin-7tv/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"name": "@usehyperion/plugin-7tv",
"version": "0.1.0",
"private": true,
"type": "module",
"exports": {
".": "./src/index.ts",
"./package.json": "./package.json"
},
"dependencies": {
"gql.tada": "^1.11.4",
"graphql-web-lite": "16.6.0-4"
},
"devDependencies": {
"@usehyperion/plugin": "workspace:^",
"svelte": "^5.57.3",
"vite": "catalog:"
},
"peerDependencies": {
"svelte": "^5.57.3"
},
"hyperion": {
"id": "7tv",
"name": "7TV",
"description": "Emotes, badges, and paints from [7TV](https://7tv.app/)."
}
}
58 changes: 58 additions & 0 deletions packages/plugin-7tv/src/components/EmoteEmbed.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<script lang="ts">
import type { EmbedProps } from "@usehyperion/plugin";

import type { EmoteEmbedData } from "../types";

import HiddenIcon from "./HiddenIcon.svelte";

const { url, data, ui }: EmbedProps<EmoteEmbedData> = $props();

let blurred = $state(true);
</script>

{#await data.fetch(data.id) then emote}
{#if emote}
<ui.EmbedCard href={url.href} label={emote.displayName} type="emote">
{#snippet media()}
<div class="flex h-full w-19 items-center justify-center bg-tint p-1.5">
<img
class="max-h-full w-auto"
srcset={emote.srcset.join(", ")}
alt={emote.displayName}
decoding="async"
/>
</div>

{#if !emote.listed && blurred}
<button
class="absolute inset-0 z-20 grid place-items-center backdrop-blur-lg
transition-colors hover:bg-tint"
aria-label="Click to reveal unlisted emote"
onclick={() => (blurred = false)}
>
<HiddenIcon class="size-5 text-fg-muted" />
</button>
{/if}
{/snippet}

<div class="flex min-w-0 items-center gap-1.5">
<span class="truncate font-medium" title={emote.displayName}>
{emote.displayName}
</span>

{#if !emote.listed}
<span
class="shrink-0 rounded-sm bg-danger/12 px-1 py-px text-caption
font-medium tracking-wide text-danger uppercase"
>
unlisted
</span>
{/if}
</div>

<div class="flex items-center gap-1.5 text-detail text-fg-muted">
<span class="truncate">by {emote.owner ?? "Unknown"}</span>
</div>
</ui.EmbedCard>
{/if}
{/await}
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
<script lang="ts">
import type { Viewer } from "#lib/models/viewer.svelte.js";

import Username from "#lib/components/user/Username.svelte";
import type { PluginUi, User } from "@usehyperion/plugin";

interface Props {
name?: string;
actor: Viewer;
actor: User;
ui: PluginUi;
}

const { name, actor }: Props = $props();
const { name, actor, ui }: Props = $props();
</script>

<Username user={actor.user} />
<ui.Username user={actor} />

{#if name}
changed the active emote set to
Expand Down
25 changes: 25 additions & 0 deletions packages/plugin-7tv/src/components/EmoteSetUpdate.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<script lang="ts">
import type { Emote, PluginUi, User } from "@usehyperion/plugin";

interface Props {
action: "added" | "removed" | "renamed";
oldName?: string;
emote: Emote;
actor: User;
ui: PluginUi;
}

const { action, oldName, emote, actor, ui }: Props = $props();
</script>

<ui.Username user={actor} />

{#if action === "renamed"}
renamed <span class="font-medium text-fg">{oldName}</span> to
<span class="font-medium text-fg">{emote.displayName}</span>
{:else}
{action} an emote:
<span class="font-medium text-fg">{emote.displayName}</span>
{/if}

<ui.Emote {emote} />
16 changes: 16 additions & 0 deletions packages/plugin-7tv/src/components/HiddenIcon.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<script lang="ts">
import type { SVGAttributes } from "svelte/elements";

const props: SVGAttributes<SVGSVGElement> = $props();
</script>

<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 24 24" {...props}>
<g fill="none" stroke="currentColor" stroke-linecap="round" stroke-width="1.5">
<path
stroke-linejoin="round"
d="M19.439 15.439a19.5 19.5 0 0 0 2.105-2.484c.304-.426.456-.64.456-.955c0-.316-.152-.529-.456-.955C20.178 9.129 16.689 5 12 5c-.908 0-1.77.155-2.582.418m-2.67 1.33c-2.017 1.36-3.506 3.195-4.292 4.297c-.304.426-.456.64-.456.955c0 .316.152.529.456.955C3.822 14.871 7.311 19 12 19c1.99 0 3.765-.744 5.253-1.747"
/>
<path d="M9.858 10A2.929 2.929 0 1 0 14 14.142" />
<path stroke-linejoin="round" d="m3 3l18 18" />
</g>
</svg>
19 changes: 19 additions & 0 deletions packages/plugin-7tv/src/components/Icon.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<script lang="ts">
import type { SVGAttributes } from "svelte/elements";

const props: SVGAttributes<SVGSVGElement> = $props();
</script>

<svg
width="20"
height="20"
fill="white"
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 33 23.551"
{...props}
>
<path
d="M2.383,0,0,4.127,1.473,6.676H11.7L3.426,21,4.9,23.551H9.66Q14.532,15.113,19.4,6.676L15.549,0ZM18.492,0l3.856,6.676h2.945l2.381-4.125L26.2,0Zm2.383,9.225L17.021,15.9l4.417,7.649H26.2L33,11.775l-1.473-2.55H26.764l-2.944,5.1Z"
>
</path>
</svg>
101 changes: 101 additions & 0 deletions packages/plugin-7tv/src/cosmetics.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
import type { EmoteData } from "@usehyperion/plugin";
import { SvelteMap } from "svelte/reactivity";

import type { PaintObject } from "./types";

export interface Paint {
name: string;
css: string;
}

/**
* Paints and personal emotes, learned from live events.
*/
export class Cosmetics {
/**
* Paints keyed by their id.
*/
public readonly paints = new Map<string, Paint>();

/**
* The emotes of personal emote sets keyed by set id.
*/
public readonly personalSets = new SvelteMap<string, EmoteData[]>();

/**
* The paint each user has equipped keyed by Twitch user id.
*/
public readonly userPaints = new SvelteMap<string, Paint | undefined>();

/**
* The personal emote set each user has keyed by Twitch user id.
*/
public readonly userPersonalSets = new SvelteMap<string, string>();

/**
* The emote with the given name in the user's personal emote set.
*/
public personalEmote(userId: string, name: string) {
const setId = this.userPersonalSets.get(userId);

return setId
? this.personalSets.get(setId)?.find((emote) => emote.displayName === name)
: undefined;
}
}

function toRgb(decimal: number) {
const r = (decimal >>> 24) & 255;
const g = (decimal >>> 16) & 255;
const b = (decimal >>> 8) & 255;
const a = (decimal & 255) / 255;

return `rgb(${r} ${g} ${b} / ${a.toFixed(2)})`;
}

/**
* The CSS that paints text with the given paint.
*/
export function paintCss(paint: PaintObject) {
const args: string[] = [];

switch (paint.function) {
case "LINEAR_GRADIENT": {
args.push(`${paint.angle}deg`);
break;
}

case "RADIAL_GRADIENT": {
args.push(paint.shape);
break;
}

case "URL": {
args.push(paint.image_url);
break;
}
}

if (paint.function !== "URL") {
for (const stop of paint.stops) {
args.push(`${toRgb(stop.color)} ${stop.at * 100}%`);
}
}

const cssFunction =
(paint.repeat ? "repeating-" : "") + paint.function.toLowerCase().replace(/_/g, "-");

const shadows = paint.shadows.map(
(shadow) =>
`drop-shadow(${shadow.x_offset}px ${shadow.y_offset}px ${shadow.radius}px ${toRgb(shadow.color)})`,
);

return [
`background-color: currentcolor`,
`background-image: ${cssFunction}(${args.join(", ")})`,
`background-size: 100% 100%`,
`background-clip: text`,
`filter: ${shadows.join(" ")}`,
`-webkit-text-fill-color: transparent`,
].join(";");
}
Loading