Skip to content

Commit

Permalink
chore (rewrite): viewerpage applications
Browse files Browse the repository at this point in the history
  • Loading branch information
mickael-kerjean committed Dec 18, 2023
1 parent 6d18fcd commit f007472
Show file tree
Hide file tree
Showing 12 changed files with 397 additions and 93 deletions.
12 changes: 6 additions & 6 deletions public/assets/css/designsystem_utils.css
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
}

.hidden{
position:absolute;
left:-10000px;
top:auto;
width:1px;
height:1px;
overflow:hidden;
position:absolute!important;
left:-10000px!important;
top:auto!important;
width:1px!important;
height:1px!important;
overflow:hidden!important;
}

.no-select {
Expand Down
4 changes: 2 additions & 2 deletions public/assets/lib/animate.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export function transition($node, opts = {}) {
}

export function animate($node, opts = {}) {
const { time = 250, keyframes = opacityIn(), fill = "forwards" } = opts;
const { time = 250, keyframes = opacityIn(), fill = "forwards", easing = "ease" } = opts;

if (!$node) return Promise.resolve();
else if (typeof $node.animate !== "function") return Promise.resolve();
Expand All @@ -20,7 +20,7 @@ export function animate($node, opts = {}) {
return new Promise((done) => {
$node.animate(keyframes, {
duration: time,
fill,
fill, easing,
}).onfinish = done;
});
}
Expand Down
9 changes: 9 additions & 0 deletions public/assets/lib/assert.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,13 @@ export default class assert {
if (object instanceof type) return;
throw new Error(`assertion failed - unexpected type for ${object.toString()}`);
}

static truthy(object) {
if (object) return;
throw new Error(`assertion failed - object is not truthy`);
}

static fail(object) {
throw new Error(`assertion failed - ${object}`);
}
}
12 changes: 11 additions & 1 deletion public/assets/pages/viewerpage/application_audio.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,17 @@ import { createElement } from "../../lib/skeleton/index.js";
import { onDestroy } from "../../lib/skeleton/lifecycle.js";
import rxjs, { effect } from "../../lib/rx.js";
import WaveSurfer from "../../lib/vendor/wavesurfer.js";
import { loadCSS } from "../../helpers/loader.js";

import { getDownloadUrl } from "./common.js";

import "../../components/menubar.js";

export default function(render) {
const $page = createElement(`
<div class="component_formviewer">
<component-menubar></component-menubar>
<div id="waveform">AUDIO</div>
<div id="waveform"></div>
</div>
`);
render($page);
Expand All @@ -23,5 +28,10 @@ export default function(render) {
height: 200,
barWidth: 1,
});
wavesurfer.load(getDownloadUrl());
onDestroy(() => wavesurfer.destroy());
}

export function init() {
return loadCSS(import.meta.url, "./application_audio.css");
}
10 changes: 1 addition & 9 deletions public/assets/pages/viewerpage/application_ebook.css
Original file line number Diff line number Diff line change
@@ -1,18 +1,10 @@
.component_ebookviewer {
display: flex;
flex-direction: column;
flex: 1;
width: 100%;
flex-grow: 1;
}
.component_ebookviewer .ebookviewer_container {
display: flex;
flex-grow: 1;
min-height: 0;
}
.component_ebookviewer .ebookviewer_container .epub-container {
background: var(--super-light);
padding-top: 50px;
padding-top: 20px;
padding-bottom: 50px;
box-sizing: border-box;
overflow-x: hidden !important;
Expand Down
3 changes: 1 addition & 2 deletions public/assets/pages/viewerpage/application_ebook.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export default function(render) {
replacements: "blobUrl",
});
const rendition = book.renderTo($epub, {
width: "100%", height: "100%",
height: "100%", width: "100%",
flow: "scrolled-doc",
method: "continuous",
allowScriptedContent: false,
Expand Down Expand Up @@ -58,7 +58,6 @@ export default function(render) {
rxjs.fromEvent(document, "keydown"),
rendition$.pipe(rxjs.mergeMap(() => rxjs.fromEvent(qs(document, "iframe").contentDocument.body, "keydown"))),
)),
rxjs.tap((a) => console.log(a.code)),
rxjs.map((e) => {
switch(e.code) {
case "Space": return (r) => r.next();
Expand Down
2 changes: 1 addition & 1 deletion public/assets/pages/viewerpage/application_editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export default async function(render) {
const $page = createElement(`
<div class="component_ide">
<component-menubar class="hidden"></component-menubar>
<div class="component_editor scroll-y"></div>
<div class="component_editor"></div>
</div>
`);
render($page);
Expand Down
20 changes: 20 additions & 0 deletions public/assets/pages/viewerpage/application_iframe.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
body:not(.dark-mode) .component_appframe {
background: #525659;
}

.component_appframe {
text-align: center;
width: 100%;
}

.component_appframe iframe {
width: 100%;
height: 100%;
border: none;
}
.component_appframe .error {
color: white;
font-size: 17px;
margin-top: 10px;
font-family: monospace;
}
9 changes: 6 additions & 3 deletions public/assets/pages/viewerpage/application_iframe.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import { createElement } from "../../lib/skeleton/index.js";
import assert from "../../lib/assert.js";

export default function(render, opts) {
console.log("OPTIONS", opts);
export default function(render, opts = {}) {
const { endpoint = null } = opts;

assert.truthy(endpoint);
const $page = createElement(`
<div class="component_formviewer">
<div class="component_appframe">
<component-menubar></component-menubar>
<div>
IFRAME
Expand Down
44 changes: 7 additions & 37 deletions public/assets/pages/viewerpage/application_image.css
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,11 @@ body:not(.dark-mode) .component_imageviewer .component_image_container, body:not
.component_imageviewer .component_image_container img[srcset].idle {
transition: 0.2s ease transform;
}
.component_imageviewer .component_image_container img.error {
filter: contrast(0.8);
width: 160px;
margin: 0 auto;
}

.component_imageviewer .loader, .component_imageviewer .loader > span {
height: 100%;
Expand All @@ -191,42 +196,7 @@ body:not(.dark-mode) .component_imageviewer .component_image_container, body:not
}

.component_imageviewer .error {
display: flex;
height: 100%;
color: var(--dark);
font-size: 1.5em;
font-style: italic;
}
.component_imageviewer .error .label {
text-shadow: 1px 1px 5px rgba(255, 255, 255, 0.1);
display: block;
margin: auto;
}

.image-enter, .image-appear {
opacity: 0;
}

.image-enter.image-enter-active, .image-appear.image-appear-active {
transition: top .3s,right .3s,bottom .3s,left .3s,max-width .3s,max-height .3s;
-webkit-animation-name: zoomIn;
animation-name: zoomIn;
animation-duration: .3s;
-webkit-animation-timing-function: cubic-bezier(0.51, 0.92, 0.24, 1.15);
animation-timing-function: cubic-bezier(0.51, 0.92, 0.24, 1.15);
opacity: 1;
}

@keyframes zoomIn {
0% {
opacity: 0;
transform: scale(0.97);
}
1% {
opacity: 1;
}
100% {
opacity: 1;
transform: scale(1);
}
font-size: 1.3em;
margin-top: 10px;
}
50 changes: 46 additions & 4 deletions public/assets/pages/viewerpage/application_image.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import { createElement, createRender } from "../../lib/skeleton/index.js";
import rxjs, { effect, onLoad } from "../../lib/rx.js";
import { animate } from "../../lib/animate.js";
import { loadCSS } from "../../helpers/loader.js";
import { qs } from "../../lib/dom.js";
import { createLoader } from "../../components/loader.js";
import ctrlError from "../ctrl_error.js";

import { getDownloadUrl } from "./common.js";
import { transition, getDownloadUrl } from "./common.js";

import componentMetadata from "./application_image_metadata.js";
import componentPager, { init as initPager} from "./component_pager.js";
Expand All @@ -15,17 +19,55 @@ export default function(render) {
<component-menubar></component-menubar>
<div class="component_image_container">
<div class="images_wrapper">
<img class="photo idle" draggable="true" srcset="${getDownloadUrl()}">
<img class="photo idle hidden" draggable="true" src="${getDownloadUrl()}">
</div>
<div class="images_aside scroll-y"></div>
<div class="component_pager"></div>
</div>
</div>
`);
render($page);
transition(qs($page, ".component_image_container"));

componentMetadata(createRender(qs($page, ".images_aside")));
componentPager(createRender(qs($page, ".component_pager")));
const removeLoader = createLoader(qs($page, ".images_wrapper"));
const $photo = qs($page, "img.photo");
effect(onLoad($photo).pipe(
removeLoader,
rxjs.tap(($node) => {
$node.classList.remove("hidden");
animate($node, {
time: 300, easing: "cubic-bezier(.51,.92,.24,1.15)",
keyframes: [
{ opacity: 0, transform: "scale(.97)" },
{ opacity: 1 },
{ opacity: 1, transform: "scale(1)" },
],
})
}),
rxjs.catchError((err) => {
if (err.target instanceof window.HTMLElement && err.type === "error") {
return rxjs.of($photo).pipe(
removeLoader,
rxjs.tap(($img) => {
$img.setAttribute("src", "data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iV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select">
This file format is not supported
</div>
`));
}),
rxjs.catchError(ctrlError()),
);
}
console.log(err)
return ctrlError()(err);
}),
));

// componentMetadata(createRender(qs($page, ".images_aside")));
// componentPager(createRender(qs($page, ".component_pager")));
}

export function init() {
Expand Down
Loading

0 comments on commit f007472

Please sign in to comment.