From cac85db02ff00732cf75d473dc3411332f33d845 Mon Sep 17 00:00:00 2001 From: Ruben Beltran del Rio Date: Sun, 1 May 2022 01:02:58 +0200 Subject: Apply formatting --- src/lib/animations/blink.test.ts | 176 ++-- src/lib/animations/blink.ts | 36 +- src/lib/components/actions/topic.svelte | 8 +- src/lib/components/actions/topic.test.ts | 30 +- src/lib/components/error_block/error_block.test.ts | 28 +- src/lib/components/forum/forum.test.ts | 107 ++- src/lib/components/forum_list/forum_list.svelte | 22 +- src/lib/components/forum_list/forum_list.test.ts | 148 ++-- src/lib/components/glyph/glyph.test.ts | 36 +- src/lib/components/header/header.svelte | 2 +- src/lib/components/header/header.test.ts | 23 +- .../language_selector/language_selector.svelte | 14 +- .../language_selector/language_selector.test.ts | 51 +- src/lib/components/post/post.svelte | 10 +- src/lib/components/post/post.test.ts | 215 +++-- src/lib/components/tag/tag.test.ts | 90 +- src/lib/components/topic/topic.svelte | 23 +- src/lib/components/topic/topic.test.ts | 282 +++---- .../components/topic_summary/topic_summary.svelte | 16 +- .../components/topic_summary/topic_summary.test.ts | 59 +- src/lib/config/__mocks__/config.ts | 22 +- src/lib/config/apollo.ts | 12 +- src/lib/config/config.ts | 8 +- src/lib/i18n.ts | 4 +- src/lib/stores/actions.test.ts | 49 +- src/lib/stores/actions.ts | 33 +- src/lib/stores/apollo.ts | 90 +- src/lib/stores/forums.test.ts | 902 ++++++++++----------- src/lib/stores/forums.ts | 3 +- src/lib/stores/posts.test.ts | 492 ++++++----- src/lib/stores/tags.test.ts | 478 ++++++----- src/lib/stores/topics.test.ts | 540 ++++++------ src/lib/stores/topics.ts | 3 +- src/lib/utils/glyph_hash.test.ts | 108 ++- src/lib/utils/glyph_hash.ts | 60 +- src/lib/utils/readable_time.test.ts | 104 ++- src/lib/utils/readable_time.ts | 67 +- src/lib/utils/resolve_after.test.ts | 59 +- src/lib/utils/resolve_after.ts | 39 +- 39 files changed, 2117 insertions(+), 2332 deletions(-) (limited to 'src/lib') diff --git a/src/lib/animations/blink.test.ts b/src/lib/animations/blink.test.ts index 32dc872..b4d9f33 100644 --- a/src/lib/animations/blink.test.ts +++ b/src/lib/animations/blink.test.ts @@ -6,102 +6,88 @@ import { blink } from './blink'; import { sineOut } from 'svelte/easing'; const internals = { - response: null + response: null }; describe('blink', () => { - - test('it has a default delay of 0ms', () => { - - const response = blink(document.createElement('div'), {}); - - expect(response.delay).toBe(0); - }); - - test('it allows delay to be overridden', () => { - - const response = blink(document.createElement('div'), { - delay: 300 - }); - - expect(response.delay).toBe(300); - }); - - test('it has a default duration of 400ms', () => { - - const response = blink(document.createElement('div'), {}); - - expect(response.duration).toBe(400); - }); - - test('it allows delay to be overridden', () => { - - const response = blink(document.createElement('div'), { - duration: 999 - }); - - expect(response.duration).toBe(999); - }); - - test('it uses sineOut as the default easing function', () => { - - const response = blink(document.createElement('div'), {}); - - expect(response.easing).toBe(sineOut); - }); - - test('it allows easing function to be overridden', () => { - - const response = blink(document.createElement('div'), { - easing: () => 666 - }); - - expect(response.easing(0)).toBe(666); - }); - - describe('css animation function', () => { - - beforeEach(() => { - - const div = document.createElement('div'); - div.style.width = '100px'; - div.style.height = '200px'; - internals.response = blink(div, {}); - }); - - test('It starts with with zeroed width and height', () => { - - const css = internals.response.css(0, 1); - expect(css).toContain('width: 0px'); - expect(css).toContain('height: 0px'); - }); - - test('It grows to full height and 0 width in first 20%', () => { - - const css = internals.response.css(0.2, 0.8); - expect(css).toContain('width: 0px'); - expect(css).toContain('height: 200px'); - }); - - test('It expands to full height by the end', () => { - - const css = internals.response.css(1, 0); - expect(css).toContain('width: 100px'); - expect(css).toContain('height: 200px'); - }); - - test('It keeps element vertically centered by adjusting the margin', () => { - - const css = internals.response.css(0.1, 0.9); - expect(css).toContain('margin: 50px 50px'); - expect(css).toContain('height: 100px'); - }); - - test('It keeps element horizontally centered by adjusting the margin', () => { - - const css = internals.response.css(0.6, 0.4); - expect(css).toContain('margin: 0px 25px'); - expect(css).toContain('width: 50px'); - }); - }); + test('it has a default delay of 0ms', () => { + const response = blink(document.createElement('div'), {}); + + expect(response.delay).toBe(0); + }); + + test('it allows delay to be overridden', () => { + const response = blink(document.createElement('div'), { + delay: 300 + }); + + expect(response.delay).toBe(300); + }); + + test('it has a default duration of 400ms', () => { + const response = blink(document.createElement('div'), {}); + + expect(response.duration).toBe(400); + }); + + test('it allows delay to be overridden', () => { + const response = blink(document.createElement('div'), { + duration: 999 + }); + + expect(response.duration).toBe(999); + }); + + test('it uses sineOut as the default easing function', () => { + const response = blink(document.createElement('div'), {}); + + expect(response.easing).toBe(sineOut); + }); + + test('it allows easing function to be overridden', () => { + const response = blink(document.createElement('div'), { + easing: () => 666 + }); + + expect(response.easing(0)).toBe(666); + }); + + describe('css animation function', () => { + beforeEach(() => { + const div = document.createElement('div'); + div.style.width = '100px'; + div.style.height = '200px'; + internals.response = blink(div, {}); + }); + + test('It starts with with zeroed width and height', () => { + const css = internals.response.css(0, 1); + expect(css).toContain('width: 0px'); + expect(css).toContain('height: 0px'); + }); + + test('It grows to full height and 0 width in first 20%', () => { + const css = internals.response.css(0.2, 0.8); + expect(css).toContain('width: 0px'); + expect(css).toContain('height: 200px'); + }); + + test('It expands to full height by the end', () => { + const css = internals.response.css(1, 0); + expect(css).toContain('width: 100px'); + expect(css).toContain('height: 200px'); + }); + + test('It keeps element vertically centered by adjusting the margin', () => { + const css = internals.response.css(0.1, 0.9); + expect(css).toContain('margin: 50px 50px'); + expect(css).toContain('height: 100px'); + }); + + test('It keeps element horizontally centered by adjusting the margin', () => { + const css = internals.response.css(0.6, 0.4); + expect(css).toContain('margin: 0px 25px'); + expect(css).toContain('width: 50px'); + }); + }); }); diff --git a/src/lib/animations/blink.ts b/src/lib/animations/blink.ts index c291b06..623489a 100644 --- a/src/lib/animations/blink.ts +++ b/src/lib/animations/blink.ts @@ -1,25 +1,23 @@ import { sineOut } from 'svelte/easing'; import type { AnimationConfig } from 'svelte/animate'; -export const blink = function blink(node: HTMLElement, params: AnimationConfig): AnimationConfig{ +export const blink = function blink(node: HTMLElement, params: AnimationConfig): AnimationConfig { + const originalWidth = parseFloat(getComputedStyle(node).width); + const originalHeight = parseFloat(getComputedStyle(node).height); - const originalWidth = parseFloat(getComputedStyle(node).width); - const originalHeight = parseFloat(getComputedStyle(node).height); + return { + delay: params.delay || 0, + duration: params.duration || 400, + easing: params.easing || sineOut, + css: (t: number): string => { + const halfWidth = originalWidth / 2; + const halfHeight = originalHeight / 2; + const height = Math.round(t <= 0.2 ? (originalHeight * t) / 0.2 : originalHeight); + const marginY = Math.round(t <= 0.2 ? halfHeight * (1 - t / 0.2) : 0); + const width = Math.round(t > 0.2 ? ((t - 0.2) / 0.8) * originalWidth : 0); + const marginX = Math.round(t > 0.2 ? (1 - (t - 0.2) / 0.8) * halfWidth : halfWidth); - return { - delay: params.delay || 0, - duration: params.duration || 400, - easing: params.easing || sineOut, - css: (t: number): string => { - - const halfWidth = originalWidth / 2; - const halfHeight = originalHeight / 2; - const height = Math.round(t <= 0.2 ? (originalHeight * t) / 0.2 : originalHeight); - const marginY = Math.round(t <= 0.2 ? halfHeight * (1 - t / 0.2) : 0); - const width = Math.round(t > 0.2 ? ((t - 0.2) / 0.8) * originalWidth : 0); - const marginX = Math.round(t > 0.2 ? (1 - (t - 0.2) / 0.8) * halfWidth : halfWidth); - - return `width: ${width}px; height: ${height}px; margin: ${marginY}px ${marginX}px`; - } - }; + return `width: ${width}px; height: ${height}px; margin: ${marginY}px ${marginX}px`; + } + }; }; diff --git a/src/lib/components/actions/topic.svelte b/src/lib/components/actions/topic.svelte index 1311d06..a3cba3b 100644 --- a/src/lib/components/actions/topic.svelte +++ b/src/lib/components/actions/topic.svelte @@ -1,14 +1,14 @@
  • - - {@html $_('header.action.reply.display')} - + + {@html $_('header.action.reply.display')} +