Initial commit.

develop
Tomáš Mládek 2024-01-31 20:17:33 +01:00
commit ebc3d06da0
25 changed files with 2822 additions and 0 deletions

13
.eslintignore Normal file
View File

@ -0,0 +1,13 @@
.DS_Store
node_modules
/build
/.svelte-kit
/package
.env
.env.*
!.env.example
# Ignore files for PNPM, NPM and YARN
pnpm-lock.yaml
package-lock.json
yarn.lock

31
.eslintrc.cjs Normal file
View File

@ -0,0 +1,31 @@
/** @type { import("eslint").Linter.Config } */
module.exports = {
root: true,
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/recommended',
'plugin:svelte/recommended',
'prettier'
],
parser: '@typescript-eslint/parser',
plugins: ['@typescript-eslint'],
parserOptions: {
sourceType: 'module',
ecmaVersion: 2020,
extraFileExtensions: ['.svelte']
},
env: {
browser: true,
es2017: true,
node: true
},
overrides: [
{
files: ['*.svelte'],
parser: 'svelte-eslint-parser',
parserOptions: {
parser: '@typescript-eslint/parser'
}
}
]
};

10
.gitignore vendored Normal file
View File

@ -0,0 +1,10 @@
.DS_Store
node_modules
/build
/.svelte-kit
/package
.env
.env.*
!.env.example
vite.config.js.timestamp-*
vite.config.ts.timestamp-*

1
.npmrc Normal file
View File

@ -0,0 +1 @@
engine-strict=true

4
.prettierignore Normal file
View File

@ -0,0 +1,4 @@
# Ignore files for PNPM, NPM and YARN
pnpm-lock.yaml
package-lock.json
yarn.lock

8
.prettierrc Normal file
View File

@ -0,0 +1,8 @@
{
"useTabs": true,
"singleQuote": true,
"trailingComma": "none",
"printWidth": 100,
"plugins": ["prettier-plugin-svelte"],
"overrides": [{ "files": "*.svelte", "options": { "parser": "svelte" } }]
}

12
index.html Normal file
View File

@ -0,0 +1,12 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Expanded Modern Test Card</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
</body>
</html>

39
package.json Normal file
View File

@ -0,0 +1,39 @@
{
"name": "testcard",
"version": "0.0.1",
"private": true,
"scripts": {
"dev": "vite dev",
"build": "vite build",
"preview": "vite preview",
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
"lint": "prettier --check . && eslint .",
"format": "prettier --write ."
},
"devDependencies": {
"@sveltejs/adapter-auto": "^3.0.0",
"@sveltejs/kit": "^2.0.0",
"@sveltejs/vite-plugin-svelte": "^3.0.0",
"@types/eslint": "8.56.0",
"@types/lodash": "^4.14.202",
"@typescript-eslint/eslint-plugin": "^6.0.0",
"@typescript-eslint/parser": "^6.0.0",
"eslint": "^8.56.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-svelte": "^2.35.1",
"prettier": "^3.1.1",
"prettier-plugin-svelte": "^3.1.2",
"svelte": "^4.2.7",
"svelte-check": "^3.6.0",
"tslib": "^2.4.1",
"typescript": "^5.0.0",
"vite": "^5.0.3"
},
"type": "module",
"dependencies": {
"@ibm/plex": "^6.4.0",
"lodash": "^4.17.21",
"normalize.css": "^8.0.1"
}
}

2109
pnpm-lock.yaml Normal file

File diff suppressed because it is too large Load Diff

13
src/app.d.ts vendored Normal file
View File

@ -0,0 +1,13 @@
// See https://kit.svelte.dev/docs/types#app
// for information about these interfaces
declare global {
namespace App {
// interface Error {}
// interface Locals {}
// interface PageData {}
// interface PageState {}
// interface Platform {}
}
}
export {};

12
src/app.html Normal file
View File

@ -0,0 +1,12 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="icon" href="%sveltekit.assets%/favicon.png" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
%sveltekit.head%
</head>
<body data-sveltekit-preload-data="hover">
<div style="display: contents">%sveltekit.body%</div>
</body>
</html>

17
src/index.css Normal file
View File

@ -0,0 +1,17 @@
body, html {
height: 100%;
margin: 0;
display: flex;
justify-content: center;
align-items: center;
color: white;
background-color: black;
font-family: 'IBM Plex Sans', 'Helvetica Neue', Arial, sans-serif;
font-size: 1.5vw;
}
* {
box-sizing: border-box;
}

65
src/lib/Axes.svelte Normal file
View File

@ -0,0 +1,65 @@
<script>
import { onMount } from 'svelte';
let heightOdd = false;
let widthOdd = false;
function updateOdd() {
heightOdd = window.innerHeight % 2 === 1;
widthOdd = window.innerWidth % 2 === 1;
}
onMount(() => {
updateOdd();
window.addEventListener('resize', updateOdd);
});
</script>
<div class="axes" class:heightOdd class:widthOdd>
<div class="horizontal"></div>
<div class="vertical"></div>
</div>
<style>
.axes {
position: absolute;
top: 0;
left: 0;
width: 100vw;
height: 100vh;
--size: 3px;
}
.axes .horizontal,
.axes .vertical {
position: absolute;
background-color: red;
z-index: 5;
opacity: 0.66;
}
.axes .horizontal {
top: 50%;
left: 0;
width: 100%;
height: var(--size);
transform: translateY(-50%);
}
.axes .vertical {
top: 0;
left: 50%;
width: var(--size);
height: 100%;
transform: translateX(-50%);
}
/*.axes.heightOdd .horizontal {*/
/* top: calc(50% + 1px);*/
/*}*/
/*.axes.widthOdd .vertical {*/
/* left: calc(50% + 1px);*/
/*}*/
</style>

View File

@ -0,0 +1,230 @@
<script lang="ts">
import _ from 'lodash';
import { createEventDispatcher, onMount } from 'svelte';
const dispatch = createEventDispatcher();
const START_COUNT = 27;
const MAX_COUNT = 33;
const MARGIN_SIZE = 16;
let horizontalCount = START_COUNT;
let verticalCount = START_COUNT;
let blockSize = 64;
let cornerBlocks = 2;
let horizontalMargin = 0;
let verticalMargin = 0;
$: updateCounts();
function updateCounts() {
const gridWidth = window.innerWidth - MARGIN_SIZE;
const gridHeight = window.innerHeight - MARGIN_SIZE;
const [longerSide, shorterSide] =
gridWidth > gridHeight ? [gridWidth, gridHeight] : [gridHeight, gridWidth];
function discrepancy(count: number) {
const blockSize = longerSide / count;
return shorterSide / blockSize - Math.floor(shorterSide / blockSize);
}
let finalCount = START_COUNT;
let count = START_COUNT;
let bestDiscrepancy = discrepancy(count);
while (count < MAX_COUNT) {
count += 2;
const currentDiscrepancy = discrepancy(count);
if (currentDiscrepancy < bestDiscrepancy) {
bestDiscrepancy = currentDiscrepancy;
finalCount = count;
}
}
const longerCount = finalCount;
const shorterCount = Math.round(longerCount * (shorterSide / longerSide));
[horizontalCount, verticalCount] =
gridWidth > gridHeight ? [longerCount, shorterCount] : [shorterCount, longerCount];
blockSize = longerSide / finalCount;
horizontalMargin = (window.innerWidth - blockSize * horizontalCount) / 2;
verticalMargin = (window.innerHeight - blockSize * verticalCount) / 2;
cornerBlocks = shorterCount > 8 ? 3 : Math.max(1, Math.floor(shorterCount / 4));
dispatch('change', {
horizontalCount,
verticalCount,
blockSize,
horizontalMargin,
verticalMargin
});
}
const updateCountsOnResize = _.throttle(updateCounts, 200);
onMount(() => {
window.addEventListener('resize', updateCountsOnResize);
updateCounts();
});
</script>
<div
class="background"
class:even-vertical={verticalCount % 2 === 0}
style="--horizontal-count: {horizontalCount};
--vertical-count: {verticalCount};
--block-size: {blockSize}px;
--corner-blocks: {cornerBlocks};
--horizontal-margin: {horizontalMargin}px;
--vertical-margin: {verticalMargin}px;"
>
<div class="corners">
<div class="corner top left"></div>
<div class="corner top right"></div>
<div class="corner bottom left"></div>
<div class="corner bottom right"></div>
</div>
<div class="edges">
{#each ['top', 'bottom'] as edge}
<div class="edge {edge}">
{#each [...Array(horizontalCount - cornerBlocks * 2).keys()] as _}
<div class="block"></div>
{/each}
</div>
{/each}
{#each ['left', 'right'] as edge}
<div class="edge {edge}">
{#each [...Array(verticalCount - cornerBlocks * 2).keys()] as _}
<div class="block"></div>
{/each}
</div>
{/each}
</div>
<div class="grid">
{#each [...Array(verticalCount).keys()] as x}
<div class="row">
{#each [...Array(horizontalCount).keys()] as y}
<div class="block"></div>
{/each}
</div>
{/each}
</div>
</div>
<style>
.background {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
pointer-events: none;
--corner-color: white;
--corner-height: calc(var(--vertical-margin) + var(--corner-blocks) * var(--block-size));
--corner-width: calc(var(--horizontal-margin) + var(--corner-blocks) * var(--block-size));
}
.corner {
background-color: var(--corner-color);
position: absolute;
&.top {
top: 0;
height: var(--corner-height);
}
&.bottom {
bottom: 0;
height: var(--corner-height);
}
&.left {
left: 0;
width: var(--corner-width);
}
&.right {
right: 0;
width: var(--corner-width);
}
}
.edges {
& .edge {
position: absolute;
display: flex;
}
& .top {
top: 0;
}
& .bottom {
bottom: 0;
}
& .top,
& .bottom {
width: calc(100vw - var(--corner-width) * 2);
height: calc(var(--margin-size) * 2);
left: var(--corner-width);
}
& .left {
left: 0;
}
& .right {
right: 0;
}
& .left,
& .right {
flex-direction: column;
height: calc(100vh - var(--corner-height) * 2);
width: calc(var(--margin-size) * 2);
top: var(--corner-height);
}
& .block {
display: inline-block;
height: var(--block-size);
width: var(--block-size);
background: white;
&:nth-child(odd) {
background: black;
}
}
}
.background.even-vertical .edges .right .block {
background: black;
&:nth-child(odd) {
background: white;
}
}
.grid {
display: grid;
grid-template-columns: repeat(var(--horizontal-count), var(--block-size));
grid-template-rows: repeat(var(--vertical-count), var(--block-size));
position: absolute;
top: var(--vertical-margin);
left: var(--horizontal-margin);
& .row {
display: contents;
}
& .block {
background: black;
border-right: 1px solid gray;
border-bottom: 1px solid gray;
}
& .row:first-child .block {
border-top: 1px solid gray;
}
& .block:first-child {
border-left: 1px solid gray;
}
}
</style>

View File

@ -0,0 +1,10 @@
<div class="gradient"></div>
<style>
.gradient {
width: 100%;
height: 100%;
background: linear-gradient(0deg, white, black);
}
</style>

View File

@ -0,0 +1,19 @@
<div class="gradient"></div>
<style>
.gradient {
width: 100%;
height: 100%;
background: linear-gradient(
180deg,
#ff0000,
#ff7f00,
#ffff00,
#00ff00,
#0000ff,
#4b0082,
#9400d3
);
}
</style>

51
src/lib/ScreenInfo.svelte Normal file
View File

@ -0,0 +1,51 @@
<script lang="ts">
import { onMount } from 'svelte';
import { fade } from 'svelte/transition';
let screenResolution = '';
let windowResolution = '';
function updateResolution() {
const realWidth = Math.round(screen.width * window.devicePixelRatio);
const realHeight = Math.round(screen.height * window.devicePixelRatio);
const windowWidth = Math.round(window.innerWidth * window.devicePixelRatio);
const windowHeight = Math.round(window.innerHeight * window.devicePixelRatio);
screenResolution = `${realWidth} x ${realHeight}`;
windowResolution = `${windowWidth} x ${windowHeight}`;
}
onMount(() => {
window.addEventListener('resize', () => {
updateResolution();
});
updateResolution();
});
</script>
<div class="info">
<div class="resolution">
<div class="title">Screen Resolution</div>
<div class="value">{screenResolution}</div>
{#if windowResolution !== screenResolution}
<div class="window" transition:fade>
<div class="title">Window Resolution</div>
<div class="value">{windowResolution}</div>
</div>
{/if}
</div>
</div>
<style>
.info {
text-align: center;
}
.title {
font-weight: bold;
}
.window {
margin-top: 1em;
font-size: 0.8em;
}
</style>

126
src/lib/TestCard.svelte Normal file
View File

@ -0,0 +1,126 @@
<script lang="ts">
import BackgroundGrid from '$lib/BackgroundGrid.svelte';
import ScreenInfo from '$lib/ScreenInfo.svelte';
import Axes from '$lib/Axes.svelte';
import ColorGradient from '$lib/ColorGradient.svelte';
import BrightnessGradient from '$lib/BrightnessGradient.svelte';
let sizes = {
blockSize: 64,
horizontalCount: 8,
verticalCount: 8,
horizontalMargin: 0,
verticalMargin: 0
};
$: columnWidth = sizes.horizontalCount % 2 === 0 ? 3 : 4;
$: columnHeight = 2 * Math.floor((sizes.verticalCount * 0.75) / 2) + (sizes.verticalCount % 2);
$: columnTop = (sizes.verticalCount - columnHeight) / 2;
$: leftColumn = sizes.horizontalCount / 4 - columnWidth / 2;
$: circleBlocks =
2 * Math.floor((Math.min(sizes.horizontalCount, sizes.verticalCount) * 0.66) / 2) +
(sizes.horizontalCount % 2);
</script>
<div
class="test-card"
style="--block-size: {sizes.blockSize}px;
--horizontal-margin: {sizes.horizontalMargin}px;
--vertical-margin: {sizes.verticalMargin}px;
--circle-blocks: {circleBlocks};
--column-width: {columnWidth};
--column-height: {columnHeight};
--column-top: {columnTop};
--left-column: {leftColumn};"
>
<BackgroundGrid on:change={(ev) => (sizes = ev.detail)} />
<Axes />
<div class="inner">
<ScreenInfo />
</div>
<div class="outer"></div>
<div class="column left">
<div class="gradient">
<ColorGradient />
</div>
<div class="gradient">
<BrightnessGradient />
</div>
</div>
<div class="column right">
<div class="gradient">
<ColorGradient />
</div>
<div class="gradient">
<BrightnessGradient />
</div>
</div>
</div>
<style>
.test-card {
position: absolute;
top: 0;
left: 0;
width: 100vw;
height: 100vh;
overflow: hidden;
}
.inner {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
width: calc(var(--block-size) * var(--circle-blocks));
height: calc(var(--block-size) * var(--circle-blocks));
display: flex;
justify-content: center;
align-items: center;
border: 1px solid white;
background: rgba(0, 0, 0, 0.66);
border-radius: 50%;
}
.outer {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
width: calc(min(100vw, 100vh) - max(var(--horizontal-margin), var(--vertical-margin)) * 2);
height: calc(min(100vw, 100vh) - max(var(--horizontal-margin), var(--vertical-margin)) * 2);
border: 2px dashed white;
border-radius: 50%;
opacity: 0.5;
}
.column {
position: absolute;
top: calc(var(--vertical-margin) + var(--block-size) * var(--column-top));
width: calc(var(--block-size) * var(--column-width));
height: calc(var(--block-size) * var(--column-height));
z-index: 9;
display: flex;
&.left {
left: calc(var(--horizontal-margin) + var(--block-size) * 3);
}
&.right {
right: calc(var(--horizontal-margin) + var(--block-size) * 3);
transform: rotate(180deg);
}
& .gradient {
flex-grow: 1;
}
}
</style>

1
src/lib/index.ts Normal file
View File

@ -0,0 +1 @@
// place files you want to import through the `$lib` alias in this folder.

1
src/routes/+layout.ts Normal file
View File

@ -0,0 +1 @@
export const ssr = false;

8
src/routes/+page.svelte Normal file
View File

@ -0,0 +1,8 @@
<script>
import 'normalize.css/normalize.css';
import '@ibm/plex/css/ibm-plex.css';
import '../index.css';
import TestCard from '$lib/TestCard.svelte';
</script>
<TestCard />

0
style.css Normal file
View File

18
svelte.config.js Normal file
View File

@ -0,0 +1,18 @@
import adapter from '@sveltejs/adapter-auto';
import { vitePreprocess } from '@sveltejs/vite-plugin-svelte';
/** @type {import('@sveltejs/kit').Config} */
const config = {
// Consult https://kit.svelte.dev/docs/integrations#preprocessors
// for more information about preprocessors
preprocess: vitePreprocess(),
kit: {
// adapter-auto only supports some environments, see https://kit.svelte.dev/docs/adapter-auto for a list.
// If your environment is not supported or you settled on a specific environment, switch out the adapter.
// See https://kit.svelte.dev/docs/adapters for more information about adapters.
adapter: adapter()
}
};
export default config;

18
tsconfig.json Normal file
View File

@ -0,0 +1,18 @@
{
"extends": "./.svelte-kit/tsconfig.json",
"compilerOptions": {
"allowJs": true,
"checkJs": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"resolveJsonModule": true,
"skipLibCheck": true,
"sourceMap": true,
"strict": true,
"moduleResolution": "bundler"
}
// Path aliases are handled by https://kit.svelte.dev/docs/configuration#alias
//
// If you want to overwrite includes/excludes, make sure to copy over the relevant includes/excludes
// from the referenced tsconfig.json - TypeScript does not merge them in
}

6
vite.config.ts Normal file
View File

@ -0,0 +1,6 @@
import { sveltekit } from '@sveltejs/kit/vite';
import { defineConfig } from 'vite';
export default defineConfig({
plugins: [sveltekit()]
});