Skip to content

Commit

Permalink
cards scroll
Browse files Browse the repository at this point in the history
  • Loading branch information
lenincompres committed Oct 23, 2024
1 parent e90ab48 commit b5201d8
Show file tree
Hide file tree
Showing 6 changed files with 147 additions and 86 deletions.
8 changes: 6 additions & 2 deletions DOM.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* Creates DOM structures from a JS object (structure)
* @author Lenin Compres <lenincompres@gmail.com>
* @version 1.1.3
* @version 1.1.4
* @repository https://github.com/lenincompres/DOM.js
*/

Expand Down Expand Up @@ -85,7 +85,7 @@ Element.prototype.set = function (model, ...args) {
}
if (model._bonds) model = model.bind();
if (model.binders) {
if(DOM.tags.includes(STATION) && !DOM.attributes.includes(STATION)) return this.set({
if (DOM.tags.includes(STATION) && !DOM.attributes.includes(STATION)) return this.set({
content: model,
}, STATION);
model.binders.forEach(binder => binder.bind(this, STATION, model.onvalue, model.listener, ["attribute", "attributes"].includes(station) ? station : undefined));
Expand All @@ -110,6 +110,10 @@ Element.prototype.set = function (model, ...args) {
this.innerText = model;
return this;
}
if (["markdown", "md"].includes(station)) {
this.innerHTML = model.replace(/^###### (.*$)/gim, '<h6>$1</h6>').replace(/^##### (.*$)/gim, '<h5>$1</h5>').replace(/^#### (.*$)/gim, '<h4>$1</h4>').replace(/^### (.*$)/gim, '<h3>$1</h3>').replace(/^## (.*$)/gim, '<h2>$1</h2>').replace(/^# (.*$)/gim, '<h1>$1</h1>').replace(/\*\*(.*?)\*\*/g, '<b>$1</b>').replace(/__(.*?)__/g, '<b>$1</b>').replace(/\*(.*?)\*/g, '<i>$1</i>').replace(/_(.*?)_/g, '<i>$1</i>').replace(/\[(.*?)\]\((.*?)\)/g, '<a href="$2" target="_blank">$1</a>').replace(/^\> (.*$)/gim, '<blockquote>$1</blockquote>').replace(/^\* (.*$)/gim, '<ul><li>$1</li></ul>').replace(/^\d+\. (.*$)/gim, '<ol><li>$1</li></ol>').replace(/^\s*([^\n]+)\s*$/gim, '<p>$1</p>').replace(/\n{2,}/g, '<br>').trim();
return this;
}
if (["html", "innerhtml"].includes(station)) {
this.innerHTML = model;
return this;
Expand Down
110 changes: 110 additions & 0 deletions src/CardScroll.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
import {
COLOR
} from "./style.js";

class CardScroll extends HTMLElement {
constructor(items = [], SPEED = 500) {
if(!Array.isArray(items)) items = [items];
super();
this._ITEMS = new Binder([]);
this._SELECTED = new Binder(-1);
this.set({
content: this._ITEMS.as(items => ({
margin: "6em auto",
position: "relative",
width: "20em",
height: "30em",
section: items.map((item, i) => {
const diff = val => i - val;
const dist = val => items.length - Math.abs(diff(val));
const shade = val => Math.abs(diff(val)) / (items.length + 2);
return {
position: 'absolute',
width: "20em",
height: "30em",
backgroundColor: "white",
borderRadius: "2em",
boxShadow: "1px 1px 3px black",
overflow: "hidden",
border: "solid 1em white",
transition: SPEED + "ms",
borderColor: this._SELECTED.as(val => val === i ? 'white' : `rgba(34,64,64,${shade(val)})`),
cursor: this._SELECTED.as(val => val === i ? 'auto' : 'pointer'),
zIndex: this._SELECTED.as(dist),
transform: this._SELECTED.as(val => `rotate(${ 30 * items.length * (1-shade(val)) * diff(val)/items.length}deg)`),
left: this._SELECTED.as(val => val === i ? 0 : val > i ? '-20em' : '33.3em'),
top: this._SELECTED.as(val => val === i ? 0 : '25%'),
fontSize: this._SELECTED.as(val => val === i ? '1em' : `0.6em`),
main: {
pointerEvents: this._SELECTED.as(val => val === i ? 'auto' : 'none'),
content: item,
},
div: {
top: 0,
left: 0,
position: 'absolute',
opacity: this._SELECTED.as(val => val === i ? 0 : shade(val)),
backgroundColor: COLOR.LINK_DARK,
transition: SPEED + "ms",
width: "100%",
height: "100%",
pointerEvents: "none",
},
onclick: e => this._SELECTED.value != i ? this.selected += i > this.selected ? 1 : -1 : null,
}
}),
b: {
color: "black",
backgroundColor: "white",
borderRadius: "1.5em",
lineHeight: "1em",
width: "3em",
height: "3em",
padding: "1em",
textAlign: "center",
position: "absolute",
top: "50%",
zIndex: items.length,
pointerEvents: "none",
transition: SPEED + "ms",
content: [{
left: "-20%",
text: "◀",
opacity: this._SELECTED.as(val => val > 0 ? 1 : 0),
}, {
text: "▶",
right: "-20%",
opacity: this._SELECTED.as(val => val > -1 && items.length > 1 && val < items.length - 1 ? 1 : 0),
}],
onready: me => setTimeout(() => this.selected = 0, 2 * SPEED),
},
}))
});
this.items = items;
}

get selected() {
return this._SELECTED.value;
}

set selected(n) {
this._SELECTED.value = n;
}

get items() {
return this._ITEMS.value;
}

set items(items) {
if(!Array.isArray(items)) items = [items];
this._ITEMS.value = items;
}

clear() {
this.selected = -1;
}

}

customElements.define('card-scroll', CardScroll);
export default CardScroll;
2 changes: 1 addition & 1 deletion src/Copy.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ class Copy {
return Copy.copy.next();
}

static pick(map){
static text(map){
return map[Copy.lang];
}

Expand Down
104 changes: 25 additions & 79 deletions src/news.js
Original file line number Diff line number Diff line change
@@ -1,84 +1,30 @@
import Copy from "./Copy.js";
import {
COLOR
} from "./style.js";

const _SELECTED_NEWS = new Binder(-1);

const news = [{
title: Copy.pick({
es: "¡Noticias!",
en: "News!",
}),
img: "assets/poster.jpg",
desc: Copy.pick({
es: 'Es Octubre y Lenino sale de su madriguera a cantarle cuentos a las brujas, ogros, duendes y hadas que se manifiesten la noche del 3 de Noviembre en ',
en: `It is October and Lenino comes out of his burrow to sing stories to the witches, ogres, goblins and fairies that appear on the night of November 3 at `,
}),
link: {
target: "_blank",
href: "https://www.google.com/maps/place/Ca%C3%B1ave/@40.8644495,-73.9289111,15z/data=!4m6!3m5!1s0x89c2f559184229cb:0x994c7ec6855fdb5!8m2!3d40.8644495!4d-73.9289111!16s%2Fg%2F11g0hldvl4?entry=ttu&g_ep=EgoyMDI0MTAyMC4xIKXMDSoASAFQAw%3D%3D",
text: "Cañave",
let news = [{
href: "https://www.google.com/maps/place/Ca%C3%B1ave/@40.8644495,-73.9289111,15z/data=!4m6!3m5!1s0x89c2f559184229cb:0x994c7ec6855fdb5!8m2!3d40.8644495!4d-73.9289111!16s%2Fg%2F11g0hldvl4?entry=ttu&g_ep=EgoyMDI0MTAyMC4xIKXMDSoASAFQAw%3D%3D",
get a() {
return ({
href: this.href,
target: "_blank",
img: {
width: "100%",
alt: Copy.text({
es: "desCONCIERTO de Jalogüín",
en: "A Halloween disCONCERT",
}),
src: "assets/poster.jpg",
},
})
},
}];

const newsSection = DOM.element({
margin: "6em auto",
position: "relative",
width: "20em",
section: news.map((n, i) => ({
position: 'absolute',
width: "20em",
left: _SELECTED_NEWS.as(val => val === i ? 0 : val > i ? '-20em' : '20em'),
right: 0,
backgroundColor: "white",
borderRadius: "1.5em",
boxShadow: "1px 1px 3px black",
padding: "1em",
transform: _SELECTED_NEWS.as(val => val === i ? `rotate(${-5+i}deg)` : val > i ? "rotate(-45deg)" : "rotate(40deg)"),
transition: "1000ms",
opacity: _SELECTED_NEWS.as(val => val === i ? 1 : 0),
h2: {
textAlign: "center",
text: n.title,
},
img: {
width: "100%",
src: n.img,
},
p: {
text: n.desc,
a: n.link,
span: '.',
},
onready: me => setTimeout(() => i === 0 ? _SELECTED_NEWS.value = i : null, 1000),
})),
a: {
hover: {
backgroundColor: COLOR.LINK + "! important",
color: "white",
},
backgroundColor: "white",
padding: "1em",
borderRadius: "1.5em",
lineHeight: "1em",
width: "3em",
textAlign: "center",
boxShadow: "1px 1px 3px black",
position: "absolute",
top: "10em",
content: [{
left: "-4em",
text: "◀",
display: _SELECTED_NEWS.as(val => val > 0 ? "block" : "none"),
click: () => _SELECTED_NEWS.value = _SELECTED_NEWS.value - 1,
}, {
text: "▶",
right: "-4em",
display: _SELECTED_NEWS.as(val => news.length > 1 && val < news.length - 1 ? "block" : "none"),
click: () => _SELECTED_NEWS.value = _SELECTED_NEWS.value + 1,
}],
get div() {
return ({
marginBottom: "1em",
markdown: Copy.text({
es: `Es Octubre y Lenino sale de su madriguera a cantarle cuentos a las brujas, ogros, duendes y hadas que se manifiesten la noche del **3 de Noviembre** en [Cañave](${this.href}).`,
en: `It is October and Lenino comes out of his burrow to sing stories to the witches, ogres, goblins and fairies that appear on the night of **November 3** at [Cañave](${this.href}).`,
}),
})
}
}, 'aside');
}];

export default newsSection;
export default news;
7 changes: 4 additions & 3 deletions src/pages.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import allProjects from "./projects.js"
import * as STYLE from "./style.js";
import SOCIAL_LINKS from "./social.js";
import Copy from "./Copy.js";
import newsSection from "./news.js";
import CardScroll from "./CardScroll.js";
import news from "./news.js";

const projects = allProjects.filter(p => !p.hidden);
const activeProject = new Binder();
Expand Down Expand Up @@ -34,14 +35,14 @@ Copy.add({

export const PAGES = {
[Copy.KEY.home]: {
section: newsSection,
section: new CardScroll(news),
},
[Copy.KEY.bio]: {
section: {
style: STYLE.PAGE,
lineHeight: "1.5em",
content: {
p: Copy.pick({
p: Copy.text({
es: `Lenin Comprés (también conocido como Prof. Lenino) es un profesional en medios interactivos, ciencias de la educación y artes escénicas. Se desempeña como profesor y tecnólogo creativo en la <a href="https://itp.nyu.edu/itp/people/?tab=staff"> Escuela de Artes TISCH de la Universidad de Nueva York</a> y es graduado de Teachers College de la Universidad de Columbia. Lenin es coautor del guion galardonado de <a href="https://www.imdb.com/title/tt7552938/">Mis 500 locos</a>, que representó a la República Dominicana en los Óscares de 2021. También es el creador de <a href="http://jackrabbits.lenino.net">Lenino’s JACK RABBITS</a>, el primer juego de mesa original escrito por un dominicano, que cuenta con un manual de instrucciones completamente en verso y rima. Como artista, se presenta bajo su seudónimo Lenino como un cuentacuentos musicómico.`,
en: `Lenin Comprés (also known as Prof. Lenino) is a professional in interactive media, educational sciences, and performing arts. He serves as a professor and creative technologist at <a href="https://itp.nyu.edu/itp/people/?tab=staff">New York University's TISCH School of the Arts</a> and holds a degree from Columbia University's Teachers College. Lenin is the co-writer of the award-winning script for <a href="https://www.imdb.com/title/tt7552938/">A State of Madness</a>, which represented the Dominican Republic at the 2021 Oscars. He is also the creator of <a href="http://jackrabbits.lenino.net">Lenino’s JACK RABBITS</a>, the first original Dominican-authored board game featuring an instructional booklet written entirely in verse and rhyme. As an artist, he performs as a quirky musical storyteller under his Lenino moniker.`
}),
Expand Down
2 changes: 1 addition & 1 deletion src/style.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export const COLOR = {
LINK: '#055',
LINK_DARK: '#033',
LINK_DARK: '#003333',
BACKGROUND: 'rgb(68, 85, 51)',
HIGHLIGHT: 'rgb(0, 180, 180)',
PAGE: '#F5DC9A',
Expand Down

0 comments on commit b5201d8

Please sign in to comment.