From 21e28a720c62c07dd95ff9792befc40dfecf0f41 Mon Sep 17 00:00:00 2001 From: tree Date: Thu, 16 Feb 2023 13:26:53 +0100 Subject: [PATCH] Speaker anim --- package-lock.json | 7 +++++++ package.json | 1 + src/lib/components/PeopleList.svelte | 12 +++++++++--- src/lib/helpers.js | 9 ++++++--- 4 files changed, 23 insertions(+), 6 deletions(-) diff --git a/package-lock.json b/package-lock.json index 6196ce9..bbe1732 100644 --- a/package-lock.json +++ b/package-lock.json @@ -21,6 +21,7 @@ "postcss": "^8.4.21", "prettier": "^2.8.0", "prettier-plugin-svelte": "^2.8.1", + "remove-markdown": "^0.5.0", "svelte": "^3.54.0", "svelte-markdown": "^0.2.3", "tailwindcss": "^3.2.6", @@ -2307,6 +2308,12 @@ "url": "https://github.com/sponsors/mysticatea" } }, + "node_modules/remove-markdown": { + "version": "0.5.0", + "resolved": "https://registry.npmjs.org/remove-markdown/-/remove-markdown-0.5.0.tgz", + "integrity": "sha512-x917M80K97K5IN1L8lUvFehsfhR8cYjGQ/yAMRI9E7JIKivtl5Emo5iD13DhMr+VojzMCiYk8V2byNPwT/oapg==", + "dev": true + }, "node_modules/resolve": { "version": "1.22.1", "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.22.1.tgz", diff --git a/package.json b/package.json index ec74b3c..6084dc5 100644 --- a/package.json +++ b/package.json @@ -24,6 +24,7 @@ "postcss": "^8.4.21", "prettier": "^2.8.0", "prettier-plugin-svelte": "^2.8.1", + "remove-markdown": "^0.5.0", "svelte": "^3.54.0", "svelte-markdown": "^0.2.3", "tailwindcss": "^3.2.6", diff --git a/src/lib/components/PeopleList.svelte b/src/lib/components/PeopleList.svelte index 186f14c..1512345 100644 --- a/src/lib/components/PeopleList.svelte +++ b/src/lib/components/PeopleList.svelte @@ -12,18 +12,24 @@ function twitterLink(handle) { return `https://twitter.com/${handle}`; } + + function animateSpeaker (el) { + for(const e of el.target.getElementsByClassName('animate-speaker')) { + animateText({ target: e }) + } + } {#each items.map(getPerson) as item} -
+
-
{item.name}
+
{item.name}
{#if item.caption}
diff --git a/src/lib/helpers.js b/src/lib/helpers.js index 6b903f6..5044fa7 100644 --- a/src/lib/helpers.js +++ b/src/lib/helpers.js @@ -1,11 +1,14 @@ + +import removeMd from 'remove-markdown' + export function rand(length) { let result = ''; const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; const charactersLength = characters.length; let counter = 0; while (counter < length) { - result += characters.charAt(Math.floor(Math.random() * charactersLength)); - counter += 1; + result += characters.charAt(Math.floor(Math.random() * charactersLength)); + counter += 1; } return result; } @@ -18,7 +21,7 @@ export function animateText (ev) { return; } ev.target.setAttribute('data-animate', "1") - const orig = ev.target.getAttribute('data-text') + const orig = removeMd(ev.target.getAttribute('data-text')) const steps = orig.length const genRand = (pos = 0, len = null) => orig.substring(pos, len).split(' ').map(x => rand(x.length)).join(' ')