@outbook/webcomponents-player-artwork 1.0.0 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -0,0 +1,102 @@
1
+ # @outbook/webcomponents-player-artwork
2
+
3
+ This package provides a web component for displaying player artwork. It supports responsive images via `srcset`, multiple sources for `<picture>` elements, and a customizable fallback icon when no image is provided.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @outbook/webcomponents-player-artwork
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ### As a Lit Element (using wrapper function)
14
+
15
+ The `PlayerArtwork` wrapper function simplifies usage within Lit templates.
16
+
17
+ ```javascript
18
+ import { html } from 'lit';
19
+ import { PlayerArtwork } from '@outbook/webcomponents-player-artwork';
20
+ import { music_note } from '@outbook/icons';
21
+
22
+ function render() {
23
+ return html`
24
+ ${PlayerArtwork({
25
+ src1x: 'path/to/image.jpg',
26
+ src2x: 'path/to/image@2x.jpg',
27
+ icon: music_note
28
+ })}
29
+ `;
30
+ }
31
+ ```
32
+
33
+ ### Direct HTML Usage (using component tag)
34
+
35
+ You can use the custom element directly in your HTML. Note that complex properties like `icon` must be set via JavaScript, while `sources` can be passed as a JSON string.
36
+
37
+ ```javascript
38
+ import '@outbook/webcomponents-player-artwork';
39
+ ```
40
+
41
+ ```html
42
+ <!-- Simple usage -->
43
+ <outbook-player-artwork
44
+ src1x="path/to/image.jpg"
45
+ src2x="path/to/image@2x.jpg"
46
+ ></outbook-player-artwork>
47
+
48
+ <!-- With sources for <picture> element -->
49
+ <outbook-player-artwork
50
+ sources='[{"media": "(min-width: 600px)", "src1x": "large.jpg"}]'
51
+ ></outbook-player-artwork>
52
+
53
+ <!-- With fallback icon (default is music_note) -->
54
+ <outbook-player-artwork></outbook-player-artwork>
55
+ ```
56
+
57
+ ## Component Usage
58
+
59
+ The component is best used via its wrapper function `PlayerArtwork`.
60
+
61
+ ### Properties
62
+
63
+ The properties listed below are used by the `PlayerArtwork` wrapper function.
64
+
65
+ | Attribute | Property | Type | Default | Description |
66
+ |---|---|---|---|---|
67
+ | `class` | `extraClasses` | `String` | `undefined` | CSS classes to apply to the host element. |
68
+ | `src1x` | `src1x` | `String` | `undefined` | The source URL for the 1x resolution image. |
69
+ | `src2x` | `src2x` | `String` | `undefined` | The source URL for the 2x resolution image. |
70
+ | `sources` | `sources` | `Array` | `[]` | An array of source objects for `<picture>` usage. Each object should have `media`, `src1x`, and optionally `src2x`. |
71
+ | - | `icon` | `Object` | `music_note` | The SVG icon object to display as a fallback. Must be passed as a property. |
72
+
73
+ ### Sources Object Structure
74
+
75
+ The `sources` array expects objects with the following structure:
76
+
77
+ ```javascript
78
+ {
79
+ media: '(min-width: 600px)',
80
+ src1x: 'path/to/large-image.jpg',
81
+ src2x: 'path/to/large-image@2x.jpg'
82
+ }
83
+ ```
84
+
85
+ ## Styling
86
+
87
+ This component uses Shadow DOM, and its styles are self-contained. The component's styles are automatically applied and encapsulated.
88
+
89
+ ### Custom Properties
90
+
91
+ You can customize the appearance using the following CSS custom properties:
92
+
93
+ | Custom Property | Description |
94
+ |---|---|
95
+ | `--outbook-player-artwork--background-color` | Background color of the artwork container. |
96
+ | `--outbook-player-artwork--text-color` | Color of the fallback icon. |
97
+ | `--outbook-player-artwork--crystal-background` | Background styling for the crystal effect (fallback mode). |
98
+ | `--outbook-player-artwork--crystal-border` | Border styling for the crystal effect (fallback mode). |
99
+
100
+ ## License
101
+
102
+ This component is licensed under the Apache-2.0 License.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@outbook/webcomponents-player-artwork",
3
- "version": "1.0.0",
3
+ "version": "1.1.0",
4
4
  "main": "player-artwork.js",
5
5
  "type": "module",
6
6
  "private": false,
package/player-artwork.js CHANGED
@@ -16,31 +16,56 @@ function renderCoverFallback({ icon = music_note }) {
16
16
  `;
17
17
  }
18
18
 
19
+ function buildSrcSet(src1x, src2x) {
20
+ return src2x ? `${src1x} 1x, ${src2x} 2x` : `${src1x} 1x`;
21
+ }
22
+
19
23
  class ComponentPlayerArtwork extends LitElement {
20
24
  static properties = {
21
25
  src1x: { type: String },
22
26
  src2x: { type: String },
27
+ sources: {
28
+ converter: {
29
+ fromAttribute: value => (value ? JSON.parse(value) : []),
30
+ toAttribute: value => (value?.length ? JSON.stringify(value) : null)
31
+ }
32
+ },
23
33
  icon: { type: Object }
24
34
  };
25
35
 
26
36
  constructor() {
27
37
  super();
28
38
  this.icon = music_note;
39
+ this.sources = [];
29
40
  }
30
41
 
31
42
  static styles = styleComponent;
32
43
 
44
+ get resolvedSources() {
45
+ if (this.sources?.length) return this.sources;
46
+ if (this.src1x) return [{ src1x: this.src1x, src2x: this.src2x }];
47
+ return [];
48
+ }
49
+
33
50
  render() {
34
- if (this.src1x) {
35
- const srcSet = this.src2x
36
- ? `${this.src1x} 1x, ${this.src2x} 2x`
37
- : `${this.src1x} 1x`;
51
+ const [fallback] = this.resolvedSources;
38
52
 
53
+ if (fallback) {
39
54
  return html`
40
55
  <picture class="player-artwork player-artwork--image">
56
+ ${this.resolvedSources.length > 1
57
+ ? this.resolvedSources.map(
58
+ ({ media, src1x, src2x }) => html`
59
+ <source
60
+ media="${ifDefined(media)}"
61
+ srcset="${buildSrcSet(src1x, src2x)}"
62
+ />
63
+ `
64
+ )
65
+ : ''}
41
66
  <img
42
- srcset="${srcSet}"
43
- src="${this.src1x}"
67
+ srcset="${buildSrcSet(fallback.src1x, fallback.src2x)}"
68
+ src="${fallback.src1x}"
44
69
  alt=""
45
70
  aria-hidden="true"
46
71
  loading="lazy"
@@ -57,14 +82,13 @@ if (!customElements.get('outbook-player-artwork')) {
57
82
  customElements.define('outbook-player-artwork', ComponentPlayerArtwork);
58
83
  }
59
84
 
60
- export function PlayerArtwork(props) {
61
- const { extraClasses, src1x, src2x, icon } = props;
62
-
85
+ export function PlayerArtwork({ extraClasses, src1x, src2x, sources, icon }) {
63
86
  return html`
64
87
  <outbook-player-artwork
65
88
  class="${ifDefined(extraClasses)}"
66
89
  src1x="${ifDefined(src1x)}"
67
90
  src2x="${ifDefined(src2x)}"
91
+ .sources="${sources ?? []}"
68
92
  .icon="${icon}"
69
93
  ></outbook-player-artwork>
70
94
  `;