diff --git a/src/app/ui.ts b/src/app/ui.ts index 3923c6e3..4dc1f2f6 100644 --- a/src/app/ui.ts +++ b/src/app/ui.ts @@ -140,13 +140,11 @@ const prefersDark = window.matchMedia("(prefers-color-scheme: dark)").matches export const theme = synced("ui/theme", prefersDark ? "dark" : "light") -export const getThemeVariables = $theme => { - const colors = switcher($theme, { - light: THEME_LIGHT, - dark: THEME_DARK, - }) +export const getThemeColors = $theme => switcher($theme, {light: THEME_LIGHT, dark: THEME_DARK}) - return Object.entries(colors) +export const getThemeColor = ($theme, k) => prop(k, getThemeColors($theme)) + +export const getThemeVariables = $theme => + Object.entries(getThemeColors($theme)) .map(([k, v]) => `--${k}: ${v};`) .join("\n") -} diff --git a/src/partials/Anchor.svelte b/src/partials/Anchor.svelte index 71ad8d9c..dd33900f 100644 --- a/src/partials/Anchor.svelte +++ b/src/partials/Anchor.svelte @@ -15,10 +15,11 @@ {"opacity-50": loading}, switcher(type, { anchor: "underline", - button: "py-2 px-4 rounded bg-gray-3 text-accent whitespace-nowrap", + button: "py-2 px-4 rounded bg-input text-accent whitespace-nowrap", "button-circle": - "w-10 h-10 flex justify-center items-center rounded-full bg-gray-3 text-accent whitespace-nowrap", - "button-accent": "py-2 px-4 rounded bg-accent text-white whitespace-nowrap", + "w-10 h-10 flex justify-center items-center rounded-full bg-input text-accent whitespace-nowrap border border-solid border-gray-5", + "button-accent": + "py-2 px-4 rounded bg-accent text-white whitespace-nowrap border border-solid border-gray-5", }) ) diff --git a/src/routes/PersonDetail.svelte b/src/routes/PersonDetail.svelte index 41abc76c..04557428 100644 --- a/src/routes/PersonDetail.svelte +++ b/src/routes/PersonDetail.svelte @@ -5,7 +5,7 @@ import {fly, fade} from "svelte/transition" import {navigate} from "svelte-routing" import {log} from "src/util/logger" - import {renderContent} from "src/util/html" + import {renderContent, parseHex} from "src/util/html" import {displayPerson, Tags, toHex} from "src/util/nostr" import Tabs from "src/partials/Tabs.svelte" import Content from "src/partials/Content.svelte" @@ -19,7 +19,7 @@ import {sampleRelays, getPubkeyWriteRelays} from "src/agent/relays" import network from "src/agent/network" import {getPersonWithFallback, people} from "src/agent/tables" - import {routes, modal} from "src/app/ui" + import {routes, modal, theme, getThemeColor} from "src/app/ui" import PersonCircle from "src/partials/PersonCircle.svelte" export let npub @@ -39,6 +39,14 @@ let loading = true let showActions = false let actions = [] + let rgb, rgba + + $: { + const color = parseHex(getThemeColor($theme, "gray-8")) + + rgba = `rgba(${color.join(", ")}, 0.4)` + rgb = `rgba(${color.join(", ")})` + } $: following = $petnamePubkeys.includes(pubkey) $: muted = find(m => m[1] === pubkey, $mutes) @@ -168,11 +176,11 @@ style="z-index: -1; background-size: cover; background-image: - linear-gradient(to bottom, rgba(0, 0, 0, 0.3), #0f0f0e), + linear-gradient(to bottom, {rgba}, {rgb}), url('{person.kind0?.banner}')" /> -
+
diff --git a/src/util/html.ts b/src/util/html.ts index 5919b3d9..d710bbe0 100644 --- a/src/util/html.ts +++ b/src/util/html.ts @@ -1,5 +1,5 @@ -import {uniq} from 'ramda' -import {ellipsize, bytes} from 'hurdak/lib/hurdak' +import {uniq} from "ramda" +import {ellipsize, bytes} from "hurdak/lib/hurdak" export const copyToClipboard = text => { const {activeElement} = document @@ -34,7 +34,7 @@ export const stripExifData = async (file, opts = {}) => { new Compressor(file, { maxWidth: 1024, maxHeight: 1024, - convertSize: bytes(1, 'mb'), + convertSize: bytes(1, "mb"), ...opts, success: resolve, error: e => { @@ -50,7 +50,7 @@ export const stripExifData = async (file, opts = {}) => { } export const listenForFile = (input, onChange) => { - input.addEventListener('change', async e => { + input.addEventListener("change", async e => { const target = e.target as HTMLInputElement const [file] = target.files @@ -71,8 +71,7 @@ export const blobToString = async blob => reader.readAsDataURL(blob) }) -export const blobToFile = blob => - new File([blob], blob.name, {type: blob.type}) +export const blobToFile = blob => new File([blob], blob.name, {type: blob.type}) export const escapeHtml = html => { const div = document.createElement("div") @@ -112,9 +111,11 @@ export const extractUrls = content => { const regex = /(https?:\/\/)?[-a-z0-9@:%._\+~#=\.]+\.[a-z]{1,6}[-a-z0-9@:%_\+.~#?!&//=;]*/gi const urls = content.match(regex) - return (urls || []) - // Skip decimals like 3.5 and ellipses which have more than one dot in a row - .filter(url => !url.match(/^[\d\.]+$/) && !url.match(/\.{2}/)) + return ( + (urls || []) + // Skip decimals like 3.5 and ellipses which have more than one dot in a row + .filter(url => !url.match(/^[\d\.]+$/) && !url.match(/\.{2}/)) + ) } export const renderContent = content => { @@ -126,16 +127,16 @@ export const renderContent = content => { // Extract urls for (let url of uniq(extractUrls(content))) { // It's common for a period to end a url, trim it off - if (url.endsWith('.')) { + if (url.endsWith(".")) { url = url.slice(0, -1) } - const href = url.includes('://') ? url : 'https://' + url - const display = url.replace(/https?:\/\/(www\.)?/, '') - const escaped = url.replace(/([.*+?^${}()|[\]\\])/g, '\\$1') - const regex = new RegExp(`([^"]*)(${escaped})([^"]*)`, 'g') + const href = url.includes("://") ? url : "https://" + url + const display = url.replace(/https?:\/\/(www\.)?/, "") + const escaped = url.replace(/([.*+?^${}()|[\]\\])/g, "\\$1") + const regex = new RegExp(`([^"]*)(${escaped})([^"]*)`, "g") - const $a = document.createElement('a') + const $a = document.createElement("a") $a.href = href $a.target = "_blank" @@ -149,3 +150,9 @@ export const renderContent = content => { } export const isMobile = localStorage.mobile || window.navigator.maxTouchPoints > 1 + +export const parseHex = hex => { + const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex) + + return [parseInt(result[1], 16), parseInt(result[2], 16), parseInt(result[3], 16)] +} diff --git a/src/views/notifications/Notification.svelte b/src/views/notifications/Notification.svelte index 02277704..a1ceb7b8 100644 --- a/src/views/notifications/Notification.svelte +++ b/src/views/notifications/Notification.svelte @@ -69,7 +69,7 @@ {/if}

{formatTimestamp(timestamp)}

-
+
{ellipsize(note.content, 120)}