Initial commit

This commit is contained in:
a 2020-09-06 14:34:28 +02:00
commit ad0a7fe22a
14 changed files with 5154 additions and 0 deletions

23
.eslintrc.js Normal file
View File

@ -0,0 +1,23 @@
module.exports = {
env: {
browser: true,
es6: true,
},
extends: [
"eslint:recommended",
"plugin:@typescript-eslint/eslint-recommended",
"prettier",
"prettier/@typescript-eslint",
],
globals: {
Atomics: "readonly",
SharedArrayBuffer: "readonly",
},
parser: "@typescript-eslint/parser",
parserOptions: {
ecmaVersion: 2018,
sourceType: "module",
},
plugins: ["@typescript-eslint"],
rules: {},
};

116
.gitignore vendored Normal file
View File

@ -0,0 +1,116 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
# Runtime data
pids
*.pid
*.seed
*.pid.lock
# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov
# Coverage directory used by tools like istanbul
coverage
*.lcov
# nyc test coverage
.nyc_output
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt
# Bower dependency directory (https://bower.io/)
bower_components
# node-waf configuration
.lock-wscript
# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release
# Dependency directories
node_modules/
jspm_packages/
# Snowpack dependency directory (https://snowpack.dev/)
web_modules/
# TypeScript cache
*.tsbuildinfo
# Optional npm cache directory
.npm
# Optional eslint cache
.eslintcache
# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/
# Optional REPL history
.node_repl_history
# Output of 'npm pack'
*.tgz
# Yarn Integrity file
.yarn-integrity
# dotenv environment variables file
.env
.env.test
# parcel-bundler cache (https://parceljs.org/)
.cache
.parcel-cache
# Next.js build output
.next
out
# Nuxt.js build / generate output
.nuxt
dist
# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and not Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public
# vuepress build output
.vuepress/dist
# Serverless directories
.serverless/
# FuseBox cache
.fusebox/
# DynamoDB Local files
.dynamodb/
# TernJS port file
.tern-port
# Stores VSCode versions used for testing VSCode extensions
.vscode-test
# yarn v2
.yarn/cache
.yarn/unplugged
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*

4
.prettierrc.json Normal file
View File

@ -0,0 +1,4 @@
{
"useTabs": true,
"semi": true
}

33
package.json Normal file
View File

@ -0,0 +1,33 @@
{
"name": "projekt-sklep",
"version": "1.0.0",
"scripts": {
"build": "webpack",
"watch": "webpack --watch",
"server": "live-server dist/"
},
"main": "index.js",
"license": "MIT",
"devDependencies": {
"@typescript-eslint/eslint-plugin": "^4.0.1",
"@typescript-eslint/parser": "^4.0.1",
"css-loader": "^4.2.2",
"eslint": "^7.8.1",
"eslint-config-prettier": "^6.11.0",
"file-loader": "^6.1.0",
"html-loader": "^1.3.0",
"html-webpack-plugin": "^4.4.1",
"live-server": "^1.2.1",
"posthtml-extend": "^0.5.0",
"posthtml-loader": "^2.0.1",
"prettier": "^2.1.1",
"raw-loader": "^4.0.1",
"sass": "^1.26.10",
"sass-loader": "^10.0.2",
"style-loader": "^1.2.1",
"ts-loader": "^8.0.3",
"typescript": "^4.0.2",
"webpack": "^4.44.1",
"webpack-cli": "^3.3.12"
}
}

41
src/base.html Normal file
View File

@ -0,0 +1,41 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="base.scss">
<block name="head"></block>
<head>
<body>
<div class="container">
<header>
<div class="contact-login-cart-bar">
<div class="contact">
<span> Tel: +600 700 200</span>
<span> Email: hello@sklep.com </span>
</div>
<div class="login-cart">
<a href=#> Zaloguj się </a>
<a href="#"> Koszyk </a>
</div>
</div>
<nav>
<a> Kategorie </a>
<a> Blog </a>
<a> Kontakt </a>
<a> Praca </a>
</nav>
</header>
<div class="main-footer-container">
<main>
<block name="content"></block>
</main>
<footer>
Footer!
</footer>
</div>
</div>
</body>
</html>

111
src/base.scss Normal file
View File

@ -0,0 +1,111 @@
@use "./color_scheme";
html {
border: 0px;
margin: 0px;
padding: 0px;
}
body {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
background-color: var(--background-primary-1);
color: var(--text-color-1);
min-height: 100vh;
margin: 0px;
padding: 0px;
}
.container {
display: flex;
flex-direction: column;
width: 1200px;
max-width: 100vw;
background-color: var(--background-secondary-1);
box-shadow: 0px 0px 5px 0px var(--background-opposite-1);
flex-grow: 1;
}
header {
display: flex;
flex-direction: column;
border-bottom: 1px solid var(--border-color-1);
}
.contact-login-cart-bar {
background-color: var(--background-opposite-2);
color: var(--text-opposite-4);
width: 100%;
height: 1.5em;
display: flex;
justify-content: space-between;
align-items: center;
a {
padding: 0px 2px;
&:link,&:visited {
color: var(--text-opposite-4);
}
&:hover {
color: var(--text-opposite-3);
}
}
}
.contact span {
padding-right: 0.5em;
}
.logo-nav {
display: flex;
justify-content: space-between;
align-items: center;
img {
max-width: 100%;
max-height: 100%;
padding: 1em;
}
}
nav {
display: flex;
justify-content: space-around;
height: 4em;
align-items: center;
color: var(--text-opposite-1);
background-color: var(--green-1);
a {
border-left: 1px solid var(--text-color-1);
&:first-child {
border-left: 0px;
}
height: 100%;
display: flex;
align-items: center;
width: 100%;
justify-content: center;
cursor: pointer;
&:hover {
background-color: var(--green-3);
}
}
flex-grow: 1;
}
.main-footer-container {
display: flex;
flex-direction: column;
flex-grow: 1;
justify-content: space-between;
}
footer {
display: flex;
background-color: var(--background-opposite-3);
color: var(--text-opposite-1);
height: 3em;
align-items: center;
}

71
src/color_scheme.scss Normal file
View File

@ -0,0 +1,71 @@
@use "sass:list";
@use "sass:color";
/*
$background-color-light: hsla(250, 32%, 97%, 1);
$text-color-light: rgba(7, 59, 58, 1);
$green-light: hsla(145, 63%, 50%, 1);
$red-light: hsla(0, 100%, 48%, 1);
$border-color-light: color.invert($background-color-light, $weight: 100%);
$background-color-dark: hsla(222, 19%, 50%, 1);
$text-color-dark: hsla(60, 15%, 95%, 1);
$green-dark: color.scale($green-light, $lightness: -20%);
$red-dark: color.scale($red-light, $lightness: -20%);
$border-color-dark: color.invert($background-color-dark, $weight: 100%);
$light-theme: (
"background-color" $background-color-light -8%,
"green" $green-light -5%,
"red" $red-light -4%,
"text-color" $text-color-light 5%,
"border-color" $border-color-light -5%
);
$dark-theme: (
"background-color" $background-color-dark -13%,
"green" $green-dark -5%,
"red" $red-dark -5%,
"text-color" $text-color-dark -5%,
"border-color" $border-color-dark -5%
);
*/
$background-primary: hsla(0, 0%, 92%, 1);
$background-secondary: hsla(0, 0%, 96%, 1);
$text-color-light: rgba(7, 59, 58, 1);
$green-light: hsla(145, 63%, 50%, 1);
$red-light: hsla(0, 100%, 48%, 1);
$background-opposite: color.invert($background-primary);
$text-opposite: #fff;
$light-theme: (
"background-primary" $background-primary -8%,
"background-secondary" $background-secondary -8%,
"background-opposite" $background-opposite 4%,
"text-opposite" $text-opposite -10%,
"green" $green-light -5%,
"red" $red-light -4%,
"text-color" $text-color-light 5%,
);
//Takes a list of three values(name, color and lightness step) and emits 4 css(not sass) variables for each step
@mixin theme($theme) {
@for $i from 0 to 4 {
@each $value in $theme {
$name: list.nth($value, 1);
$color: list.nth($value, 2);
$step: list.nth($value, 3);
--#{$name}-#{$i+1}: #{color.scale($color, $lightness: $i * $step)};
}
}
}
:root {
@include theme($light-theme);
@media (prefers-color-scheme: dark) {
// @include theme($dark-theme);
}
}

18
src/index.html Normal file
View File

@ -0,0 +1,18 @@
<extends src="base.html">
<block name="head">
<title>Sklep AAAA </title>
<link rel="stylesheet" href="index.scss">
</block>
<block name="content">
<div class="gallery">
<x-carousel></x-carousel>
</div>
<p>
Lorem ipsum dolor sit, amet consectetur adipisicing elit. Nulla quos animi alias porro modi doloremque numquam quaerat, pariatur doloribus sit quo, repellendus consequatur esse omnis repudiandae accusantium sint facere cupiditate? Lorem ipsum dolor sit amet, consectetur adipisicing elit. Consectetur autem expedita inventore magnam, eos aspernatur. Eveniet, laudantium doloribus veritatis sapiente eos illo, debitis non obcaecati numquam ab nam enim unde!
Lorem ipsum dolor sit, amet consectetur adipisicing elit. Nulla quos animi alias porro modi doloremque numquam quaerat, pariatur doloribus sit quo, repellendus consequatur esse omnis repudiandae accusantium sint facere cupiditate? Lorem ipsum dolor sit amet, consectetur adipisicing elit. Consectetur autem expedita inventore magnam, eos aspernatur. Eveniet, laudantium doloribus veritatis sapiente eos illo, debitis non obcaecati numquam ab nam enim unde!
Lorem ipsum dolor sit, amet consectetur adipisicing elit. Nulla quos animi alias porro modi doloremque numquam quaerat, pariatur doloribus sit quo, repellendus consequatur esse omnis repudiandae accusantium sint facere cupiditate? Lorem ipsum dolor sit amet, consectetur adipisicing elit. Consectetur autem expedita inventore magnam, eos aspernatur. Eveniet, laudantium doloribus veritatis sapiente eos illo, debitis non obcaecati numquam ab nam enim unde!
Lorem ipsum dolor sit, amet consectetur adipisicing elit. Nulla quos animi alias porro modi doloremque numquam quaerat, pariatur doloribus sit quo, repellendus consequatur esse omnis repudiandae accusantium sint facere cupiditate? Lorem ipsum dolor sit amet, consectetur adipisicing elit. Consectetur autem expedita inventore magnam, eos aspernatur. Eveniet, laudantium doloribus veritatis sapiente eos illo, debitis non obcaecati numquam ab nam enim unde!
Lorem ipsum dolor sit, amet consectetur adipisicing elit. Nulla quos animi alias porro modi doloremque numquam quaerat, pariatur doloribus sit quo, repellendus consequatur esse omnis repudiandae accusantium sint facere cupiditate? Lorem ipsum dolor sit amet, consectetur adipisicing elit. Consectetur autem expedita inventore magnam, eos aspernatur. Eveniet, laudantium doloribus veritatis sapiente eos illo, debitis non obcaecati numquam ab nam enim unde!
</p>
</block>
</extends>

4
src/index.scss Normal file
View File

@ -0,0 +1,4 @@
.gallery {
width: 100%;
height: 10em;
}

153
src/index.ts Normal file
View File

@ -0,0 +1,153 @@
import { cyclicArray, rotateArray } from "./utils";
const items = [
{
img:
"https://a.allegroimg.com/original/110ef3/20ea48304d19b18e409748a8fdc1/KOMIN-NA-TWARZ-ZAMIAST-MASECZKI-BAWELNA",
name: "lorem ip sum! 1 ",
},
{
img: "https://i.ytimg.com/vi/ggrm3Sn1HGw/maxresdefault.jpg",
name: "lorem ip sum! 2 ",
},
{
img:
"https://www.freetutorialshub.com/wp-content/uploads/2020/04/learn-css-transition-and-animation_5e919fd2f0264.jpeg",
name: "lorem ip sum! 3 ",
},
{
img:
"https://a.allegroimg.com/original/110ef3/20ea48304d19b18e409748a8fdc1/KOMIN-NA-TWARZ-ZAMIAST-MASECZKI-BAWELNA",
name: "lorem ip sum! 4",
},
];
class Item extends HTMLElement {
shadow: ShadowRoot = this.attachShadow({ mode: "open" });
private _item!: { img: string; name: string };
public get item(): { img: string; name: string } {
return this._item;
}
public set item(value: { img: string; name: string }) {
this._item = value;
this.img.src = value.img;
this.p.innerText = value.name;
}
img;
p;
constructor() {
super();
this.img = document.createElement("img") as HTMLImageElement;
this.p = document.createElement("p") as HTMLParagraphElement;
}
connectedCallback() {
this.shadow.appendChild(this.img);
this.shadow.appendChild(this.p);
const style = document.createElement("style");
style.innerHTML = `
:host {
margin: 0.3em;
}
img {
height: 100%;
max-width: 100%;
object-fit: scale-down;
}
`;
this.shadow.appendChild(style);
}
}
customElements.define("x-item", Item);
class Carousel extends HTMLElement {
items: Item[] = [];
shadow: ShadowRoot = this.attachShadow({ mode: "open" });
forSale = cyclicArray(items);
leftButton!: HTMLButtonElement;
rightButton!: HTMLButtonElement;
constructor() {
super();
const style = document.createElement("style");
style.innerHTML = `
:host {
display: flex;
align-items: center;
height: 100%;
}
button {
z-index: 2;
}
div {
display: flex;
height: 100%;
margin: 0 -10%;
}
x-item {
max-height: 100%;
width: 33%;
transition: 3s ease;
flex-grow: 1;
}
.item-1, .item-3 {
transform: scale(0.8, 0.8);
opacity: 0.7;
}
.item-1 {
order: 1;
}
.item-2 {
order: 2;
margin: 0 -10em;
z-index: 1;
}
.item-3 {
order: 3;
}
`;
this.shadow.appendChild(style);
}
connectedCallback() {
this.leftButton = document.createElement("button") as HTMLButtonElement;
this.leftButton.innerHTML = "Next";
this.leftButton.addEventListener("click", () => this.rotate());
this.shadow.appendChild(this.leftButton);
const container = document.createElement("div") as HTMLDivElement;
this.shadow.appendChild(container);
for (let i = 0; i < 3; i++) {
const elm = document.createElement("x-item") as Item;
elm.classList.add(`item-${i + 1}`);
elm.item = items[i];
container.appendChild(elm);
this.items.push(elm);
}
this.rightButton = document.createElement("button") as HTMLButtonElement;
this.rightButton.innerHTML = "Prev";
this.rightButton.addEventListener("click", () => this.rotate(true));
this.shadow.appendChild(this.rightButton);
}
rotate(backwards = false) {
this.items.forEach((item) => item.classList.remove(`item-1`));
this.items.forEach((item) => item.classList.remove(`item-2`));
this.items.forEach((item) => item.classList.remove(`item-3`));
this.items = rotateArray(this.items, backwards);
this.items.forEach((item, i) => item.classList.add(`item-${i + 1}`));
const val = this.forSale.next(backwards).value;
if (val) {
if (backwards) this.items[0].item = val;
else this.items[2].item = val;
}
}
}
customElements.define("x-carousel", Carousel);

18
src/utils.ts Normal file
View File

@ -0,0 +1,18 @@
/// A generator that infinitely loops around an array
export function* cyclicArray<T>(array: T[]) {
let index = 0;
while (true) {
const reverse = yield array[index];
if (reverse) index--;
else index++;
if (index < 0) index = array.length - 1;
else if (index >= array.length) index = 0;
}
}
export const rotateArray = <T>(arr: T[], reverse = false): T[] => {
if (reverse) arr.unshift(arr.pop()!);
else arr.push(arr.shift()!);
return arr;
};

12
tsconfig.json Normal file
View File

@ -0,0 +1,12 @@
{
"compilerOptions": {
"outDir": "./dist/",
"sourceMap": true,
"strict": true,
"noImplicitAny": true,
"module": "commonjs",
"target": "ES2018",
"allowJs": true
}
}

62
webpack.config.js Normal file
View File

@ -0,0 +1,62 @@
const path = require("path");
const process = require("process");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const mode = process.env.NODE_ENV || "development";
const src = path.resolve(__dirname, "src");
module.exports = {
entry: {
index: path.join(src, "index.ts"),
},
mode: mode,
devtool: "inline-source-map",
module: {
rules: [
{
test: /\.tsx?$/,
use: "ts-loader",
exclude: /node_modules/,
},
{
test: /\.(c|s[ac])ss$/i,
use: [
{
loader: "file-loader",
options: { name: "[name].css" },
},
"sass-loader",
],
},
{
test: /\.html$/,
use: [
"html-loader",
{
loader: "posthtml-loader",
options: {
plugins: [
/* PostHTML Plugins */
require("posthtml-extend")({ root: src }),
],
},
},
],
},
],
},
resolve: {
extensions: [".tsx", ".ts", ".js"],
},
output: {
filename: "bundle.js",
path: path.resolve(__dirname, "dist"),
},
plugins: [
new HtmlWebpackPlugin({
filename: "index.html",
template: path.resolve(src, "index.html"),
chunks: ["index"],
}),
],
};

4488
yarn.lock Normal file

File diff suppressed because it is too large Load Diff