Skip to content

Commit

Permalink
feat: allow media source swapping
Browse files Browse the repository at this point in the history
Resolved #7 by adding a new toggle pane button containing an input field for changing
the current media of the player. Only URNs are accepted.

Other chnages:
- Disabled tracking for the preview player.
  • Loading branch information
jboix committed Apr 11, 2024
1 parent 1dd81ad commit f667be6
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 35 deletions.
9 changes: 7 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ <h1><img src="/pillarbox-logo.webp" class="logo" alt="Pillarbox logo"/> Pillarbo
<main>
<resizable-split-view>
<section slot="left">
<div class="craft-title-container">
<div class="section-title-container">
<h2>Craft your theme</h2>
<toggle-pane-button title="Select a file to edit" id="navigation-button">
<tree-view id="navigation"></tree-view>
Expand All @@ -31,7 +31,12 @@ <h2>Craft your theme</h2>
<css-editor id="editor"></css-editor>
</section>
<section slot="right">
<h2>Live Canvas Preview</h2>
<div class="section-title-container">
<h2>Live Canvas Preview</h2>
<toggle-pane-button title="Change the media" label="Change the media" id="load-media-button">
<input id="src-input" type="text" placeholder="Enter a URN..." />
</toggle-pane-button>
</div>
<preview-box id="preview"></preview-box>
</section>
</resizable-split-view>
Expand Down
22 changes: 17 additions & 5 deletions scss/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,22 @@
}

:root {
color: rgb(255 255 255 / 87%);
color: var(--app-color);
font-weight: 400;
font-family: Inter, system-ui, Avenir, Helvetica, Arial, sans-serif;
line-height: 1.5;
background-color: #242424;
background-color: var(--app-background-color);
font-synthesis: none;
text-rendering: optimizelegibility;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;

--button-background: #40729d;
--button-hover-background: #305273;
--button-color: #fff;
--button-color: var(--app-color);
--button-border-radius: 0.5em;
--app-background-color: #242424;
--app-color: rgb(255 255 255 / 87%);
}

html,
Expand Down Expand Up @@ -54,7 +56,7 @@ header p {
margin-left: 0.5em;
padding-left: 0.5em;
text-align: justify;
border-left: 3px solid rgb(255 255 255 / 87%);
border-left: 3px solid var(--app-color)
}

main {
Expand Down Expand Up @@ -86,7 +88,7 @@ footer {
}
}

.craft-title-container {
.section-title-container {
display: flex;
gap: 1em;
align-items: center;
Expand Down Expand Up @@ -118,3 +120,13 @@ footer {
#download:hover {
background-color: var(--button-hover-background);
}

input {
margin: 0;
padding: 0.5em 0.2em;
color: var(--app-color);
font-size: var(--size-3);
background-color: var(--app-background-color);
border: none;
outline: none;
}
48 changes: 26 additions & 22 deletions src/components/preview-box.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { html, LitElement } from 'lit';
import { createRef, ref } from 'lit/directives/ref.js';
import pillarbox from '@srgssr/pillarbox-web';

/**
Expand All @@ -10,49 +9,54 @@ import pillarbox from '@srgssr/pillarbox-web';
* @element preview-box
*
* @property {String} appliedCss CSS styles that can be applied to the video player.
* @property {String} [src='urn:rts:video:14318206'] The media to be loaded by the player,
* @property {String} [type='srgssr/urn'] The type of media to be loaded.
*
* @example
* <preview-box></preview-box>
*/
class PreviewBox extends LitElement {
static properties = {
appliedCss: { type: String }
appliedCss: { type: String },
src: { type: String },
type: { type: String }
};

constructor() {
super();
this.pillarboxRef = createRef();
this.src = 'urn:rts:video:14318206';
this.type = 'srgssr/urn';
}

/**
* Renders the video player with applied custom CSS and the pillarbox library functionalities.
*
* @returns {TemplateResult} The LitElement `html` template result.
*/
render() {
return html`
<style>${this.appliedCss}</style>
<video id="main-player"
<video id="preview-player"
class="pillarbox-js"
controls crossOrigin="anonymous"
${ref(this.pillarboxRef)}>
controls crossOrigin="anonymous">
</video>
`;
}

/**
* Lifecycle callback that is called after the component's first render.
* It initializes the pillarbox player with a specific video source.
*/
firstUpdated(_changedProperties) {
updated(_changedProperties) {
super.firstUpdated(_changedProperties);

// Initializes pillarbox with the video element and sets the video source.
this.player = pillarbox(this.pillarboxRef.value, { muted: true });
this.player.src({
src: 'urn:rts:video:14318206',
type: 'srgssr/urn'
});
if (['src', 'type'].some(property => _changedProperties.has(property))) {
this.player?.dispose();

const el = this.shadowRoot.getElementById('preview-player');

this.player = pillarbox(el, {
muted: true,
restoreEl: true
});

this.player.src({
src: this.src,
type: this.type,
disableTrackers: true
});
}
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/components/toggle-pane-button.scss
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
:host {
--button-background: #40729d;
--button-hover-background: #305273;
--button-color: #fff;
--button-color: rgb(255 255 255 / 87%);
--button-border-radius: 0.5em;
--popup-background: #333;
--popup-background: #242424;
--popup-border: 1px solid #666;
--popup-border-radius: 0.5em;
--popup-z-index: 1;
Expand Down
4 changes: 2 additions & 2 deletions src/components/tree-view.scss
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
:host {
--tree-background-color: #333;
--tree-item-hover-color: #555;
--tree-background-color: #242424;
--tree-item-hover-color: #444;
--tree-item-selected-color: #666;
--tree-folder-icon: '📁';
--tree-file-icon: '📄';
Expand Down
9 changes: 9 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const navigationButton = document.getElementById('navigation-button');
const editor = document.getElementById('editor');
const preview = document.getElementById('preview');
const downloadButton = document.getElementById('download');
const sourceInput = document.getElementById('src-input');

navigation.items = sassCompiler.workspace;
navigationButton.label = currentItem.name;
Expand All @@ -31,3 +32,11 @@ editor.addEventListener('value-changed', (event) => {
});

downloadButton.addEventListener('click', () => sassCompiler.download());

sourceInput.addEventListener('keyup', (event) => {
const src = event.target.value;

if (event.key === 'Enter' && src) {
preview.src = src;
}
});
7 changes: 5 additions & 2 deletions test/components/preview-box.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,12 @@ describe('PreviewBox Component', () => {
it('initializes pillarbox with correct parameters', () => {
const pillarboxMock = vi.mocked(pillarbox);

expect(pillarboxMock)
.toHaveBeenCalledWith(expect.anything(), { muted: true });
expect(pillarboxMock).toHaveBeenCalledWith(expect.anything(), {
muted: true,
restoreEl: true
});
expect(pillarboxMock.mock.instances[0].srcSpy).toHaveBeenCalledWith({
disableTrackers: true,
src: 'urn:rts:video:14318206',
type: 'srgssr/urn'
});
Expand Down

0 comments on commit f667be6

Please sign in to comment.