@teipublisher/pb-components 2.11.0 → 2.12.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@teipublisher/pb-components",
3
- "version": "2.11.0",
3
+ "version": "2.12.0",
4
4
  "description": "Collection of webcomponents underlying TEI Publisher",
5
5
  "repository": "https://github.com/eeditiones/tei-publisher-components.git",
6
6
  "main": "index.html",
@@ -28,7 +28,7 @@
28
28
  "lint": "npm run lint:eslint && npm run lint:prettier",
29
29
  "format": "npm run format:eslint && npm run format:prettier",
30
30
  "clean": "npm run clean-lib && rimraf dist css images/leaflet demo/build docs",
31
- "clean-lib": "rimraf -g lib/leaflet* lib/paged*",
31
+ "clean-lib": "rimraf -g lib/leaflet* lib/paged* lib/web-midi-player.js lib/openseadragon*",
32
32
  "prepare": "npm run docs && npm run build:production",
33
33
  "semantic-release": "semantic-release",
34
34
  "gh-pages": "node gh-pages.js"
@@ -90,7 +90,9 @@
90
90
  "tippy.js": "^6.3.7",
91
91
  "tom-select": "^2.2.2",
92
92
  "uniqolor": "^1.1.0",
93
- "web-animations-js": "^2.3.2"
93
+ "verovio": "^3.16.0",
94
+ "web-animations-js": "^2.3.2",
95
+ "web-midi-player": "^1.4.1"
94
96
  },
95
97
  "devDependencies": {
96
98
  "@babel/plugin-proposal-object-rest-spread": "^7.11.0",
package/pb-elements.json CHANGED
@@ -6808,11 +6808,16 @@
6808
6808
  {
6809
6809
  "name": "pb-mei",
6810
6810
  "path": "./src/pb-mei.js",
6811
- "description": "A viewer and player for MEI musical notation based on [Verovio](https://www.verovio.org/).\nSupports optional MIDI playback using [web-midi-player](https://midi.yvesgurcan.com/).\nBoth libraries are loaded dynamically when the component is used the first time.\n\nViewing options to be selected by the user can be defined via nested `pb-option` elements:\n\n```html\n<pb-mei id=\"viewer\" player url=\"http://www.marenzio.org/mei/M-06-5/M_06_5_01_S_io_parto_i_moro_e_pur_partir_conviene.mei\" \n footer=\"none\">\n <pb-option name=\"appXPath\" on=\"./rdg[contains(@label, 'original')]\" off=\"\">Original Clefs</pb-option>\n </pb-mei>",
6811
+ "description": "A viewer and player for MEI musical notation based on [Verovio](https://www.verovio.org/).\nSupports optional MIDI playback using [web-midi-player](https://midi.yvesgurcan.com/).\nBoth libraries are loaded dynamically when the component is used the first time.\n\nViewing options to be selected by the user can be defined via nested `pb-option` elements:\n\n```html\n<pb-mei id=\"viewer\" player url=\"http://www.marenzio.org/mei/M-06-5/M_06_5_01_S_io_parto_i_moro_e_pur_partir_conviene.mei\" \n footer=\"none\">\n <pb-option name=\"appXPath\" on=\"./rdg[contains(@label, 'original')]\" off=\"\">Original Clefs</pb-option>\n</pb-mei>\n```\n\nThe MEI document to display can either be given directly in the `data` property or loaded from an URL\nspecified in `url`.",
6812
6812
  "attributes": [
6813
+ {
6814
+ "name": "data",
6815
+ "description": "MEI data to display specified as a string. This should represent a complete\nMEI document.",
6816
+ "type": "string"
6817
+ },
6813
6818
  {
6814
6819
  "name": "url",
6815
- "description": "URL of the MEI file to load. A relative URL would be resolved\nrelative to the TEI Publisher endpoint.",
6820
+ "description": "URL of the MEI file to load. Will be used if no `data` property is present. \nA relative URL would be resolved relative to the TEI Publisher endpoint.",
6816
6821
  "type": "string"
6817
6822
  },
6818
6823
  {
@@ -6891,10 +6896,16 @@
6891
6896
  }
6892
6897
  ],
6893
6898
  "properties": [
6899
+ {
6900
+ "name": "data",
6901
+ "attribute": "data",
6902
+ "description": "MEI data to display specified as a string. This should represent a complete\nMEI document.",
6903
+ "type": "string"
6904
+ },
6894
6905
  {
6895
6906
  "name": "url",
6896
6907
  "attribute": "url",
6897
- "description": "URL of the MEI file to load. A relative URL would be resolved\nrelative to the TEI Publisher endpoint.",
6908
+ "description": "URL of the MEI file to load. Will be used if no `data` property is present. \nA relative URL would be resolved relative to the TEI Publisher endpoint.",
6898
6909
  "type": "string"
6899
6910
  },
6900
6911
  {
@@ -6985,6 +6996,22 @@
6985
6996
  "type": "boolean",
6986
6997
  "default": "false"
6987
6998
  }
6999
+ ],
7000
+ "cssProperties": [
7001
+ {
7002
+ "name": "--pb-mei-min-width",
7003
+ "description": "minimal width"
7004
+ }
7005
+ ],
7006
+ "cssParts": [
7007
+ {
7008
+ "name": "toolbar",
7009
+ "description": "toolbar with pagination and midi player controls"
7010
+ },
7011
+ {
7012
+ "name": "music",
7013
+ "description": "the music output area"
7014
+ }
6988
7015
  ]
6989
7016
  },
6990
7017
  {
@@ -48,7 +48,6 @@ import './dts-client.js';
48
48
  import './pb-codepen.js';
49
49
  import './pb-markdown.js';
50
50
  import './pb-observable.js';
51
- import './pb-mei.js';
52
51
  import './pb-autocomplete.js';
53
52
  import './pb-select.js';
54
53
  import './pb-clipboard.js';
@@ -52,10 +52,6 @@ export class PbManageOdds extends pbMixin(LitElement) {
52
52
  connectedCallback() {
53
53
  super.connectedCallback();
54
54
 
55
- this.subscribeTo('pb-login', () => {
56
- this._refresh();
57
- }, []);
58
-
59
55
  this.subscribeTo('pb-refresh-odds', (ev) => {
60
56
  this._refresh();
61
57
 
package/src/pb-mei.js CHANGED
@@ -1,13 +1,18 @@
1
1
  import { LitElement, html, css } from 'lit-element';
2
2
  import { unsafeHTML } from 'lit-html/directives/unsafe-html.js';
3
3
  import "@lrnwebcomponents/es-global-bridge";
4
+ import createVerovioModule from 'verovio/dist/verovio-module.mjs';
5
+ import { VerovioToolkit } from 'verovio/dist/verovio.mjs';
4
6
  import { pbMixin, waitOnce } from './pb-mixin.js';
5
7
  import { translate } from './pb-i18n.js';
8
+ import { resolveURL } from './utils.js';
6
9
  import '@polymer/paper-icon-button';
7
10
  import '@polymer/paper-checkbox';
8
11
  import '@polymer/iron-icons';
9
12
  import '@polymer/iron-icons/av-icons';
10
13
 
14
+ let _verovio = null;
15
+
11
16
  /** Import external script dynamically */
12
17
  function _import(name, location) {
13
18
  window.ESGlobalBridge.requestAvailability();
@@ -32,19 +37,33 @@ function _import(name, location) {
32
37
  * <pb-mei id="viewer" player url="http://www.marenzio.org/mei/M-06-5/M_06_5_01_S_io_parto_i_moro_e_pur_partir_conviene.mei"
33
38
  * footer="none">
34
39
  * <pb-option name="appXPath" on="./rdg[contains(@label, 'original')]" off="">Original Clefs</pb-option>
35
- * </pb-mei>
40
+ * </pb-mei>
41
+ * ```
42
+ *
43
+ * The MEI document to display can either be given directly in the `data` property or loaded from an URL
44
+ * specified in `url`.
36
45
  *
37
46
  * @prop {"auto" | "encoded" | "none" | "always"} footer - Control footer layout
38
47
  * @prop {"auto" | "encoded" | "none"} header - Control footer layout
39
48
  * @prop {"auto" | "none" | "line" | "encoded" | "smart"} breaks - Define page and system breaks layout (default: "auto")
49
+ * @cssprop --pb-mei-min-width - minimal width
50
+ * @csspart toolbar - toolbar with pagination and midi player controls
51
+ * @csspart music - the music output area
40
52
  */
41
53
  export class PbMei extends pbMixin(LitElement) {
42
54
 
43
55
  static get properties() {
44
56
  return {
57
+ /**
58
+ * MEI data to display specified as a string. This should represent a complete
59
+ * MEI document.
60
+ */
61
+ data: {
62
+ type: String
63
+ },
45
64
  /**
46
- * URL of the MEI file to load. A relative URL would be resolved
47
- * relative to the TEI Publisher endpoint.
65
+ * URL of the MEI file to load. Will be used if no `data` property is present.
66
+ * A relative URL would be resolved relative to the TEI Publisher endpoint.
48
67
  */
49
68
  url: {
50
69
  type: String,
@@ -107,7 +126,6 @@ export class PbMei extends pbMixin(LitElement) {
107
126
  this._pages = 0;
108
127
  this._page = 0;
109
128
  this._midiPlayer = null;
110
- this._verovio = null;
111
129
  this.footer = 'auto';
112
130
  this.header = 'auto';
113
131
  this.breaks = 'auto';
@@ -120,6 +138,7 @@ export class PbMei extends pbMixin(LitElement) {
120
138
 
121
139
  connectedCallback() {
122
140
  super.connectedCallback();
141
+
123
142
  this.querySelectorAll('pb-option').forEach((option) => {
124
143
  this._options.push({
125
144
  name: option.getAttribute('name'),
@@ -134,58 +153,72 @@ export class PbMei extends pbMixin(LitElement) {
134
153
  super.firstUpdated();
135
154
 
136
155
  if (this.player) {
137
- _import("midiPlayer", 'https://cdn.jsdelivr.net/npm/web-midi-player@latest/index.js')
156
+ _import("midiPlayer", resolveURL('../lib/web-midi-player/index.js'))
138
157
  .then(() => {
139
158
  const { 'web-midi-player': { default: MidiPlayer } } = window;
140
159
  this._midiPlayer = new MidiPlayer();
141
160
  });
142
161
  }
143
162
 
144
- _import("verovio", 'https://www.verovio.org/javascript/latest/verovio-toolkit.js')
145
- .then(() => {
146
- this._verovio = new window.verovio.toolkit();
147
-
163
+ if (!_verovio) {
164
+ createVerovioModule().then(VerovioModule => {
165
+ _verovio = new VerovioToolkit(VerovioModule);
166
+
148
167
  waitOnce('pb-page-ready', () => {
149
- this.load();
168
+ this.load();
150
169
  });
151
170
  });
171
+ } else {
172
+ waitOnce('pb-page-ready', () => {
173
+ this.load();
174
+ });
175
+ }
152
176
  }
153
177
 
154
178
  update(changedProps) {
155
179
  super.update(changedProps);
156
- if (changedProps.get('url')) {
180
+ if (changedProps.get('url') || changedProps.get('data')) {
157
181
  this.load();
158
182
  } else if (
159
183
  (changedProps.has('appXPath') ||
160
184
  changedProps.has('choiceXPath') ||
161
185
  changedProps.has('mdivXPath') ||
162
186
  changedProps.has('substXPath')) &&
163
- this._verovio
187
+ _verovio
164
188
  ) {
165
- this._verovio.setOptions(this._getOptions());
166
- this._verovio.loadData(this._data);
189
+ _verovio.setOptions(this._getOptions());
190
+ _verovio.loadData(this._data);
167
191
  this.showPage();
168
192
  }
169
193
  }
170
194
 
171
195
  load() {
172
- const link = this.toAbsoluteURL(this.url);
196
+ if (this.data) {
197
+ console.log('<pb-mei> Rendering data');
198
+ this.show(this.data);
199
+ } else if (this.url) {
200
+ const link = this.toAbsoluteURL(this.url);
173
201
 
174
- fetch(link)
175
- .then(response => response.text())
176
- .then(async data => {
177
- this._data = data;
178
- this._verovio.setOptions(this._getOptions());
179
- this._verovio.loadData(this._data);
180
- this._pages = this._verovio.getPageCount();
181
- this._page = 1;
182
- console.log('<pb-mei> Loaded %d pages', this._pages);
183
- this.showPage();
184
- });
202
+ fetch(link)
203
+ .then(response => response.text())
204
+ .then(async str => {
205
+ this.show(str);
206
+ });
207
+ }
208
+ }
209
+
210
+ show(str) {
211
+ this._data = str;
212
+ _verovio.setOptions(this._getOptions());
213
+ _verovio.loadData(this._data);
214
+ this._pages = _verovio.getPageCount();
215
+ this._page = 1;
216
+ console.log('<pb-mei> Loaded %d pages', this._pages);
217
+ this.showPage();
185
218
  }
186
219
 
187
220
  showPage() {
188
- this._svg = this._verovio.renderToSVG(this._page, {});
221
+ this._svg = _verovio.renderToSVG(this._page, {});
189
222
  }
190
223
 
191
224
  async play() {
@@ -199,8 +232,8 @@ export class PbMei extends pbMixin(LitElement) {
199
232
  this._midiPaused = false;
200
233
  this._midiPlayer.resume();
201
234
  } else {
202
- this._verovio.loadData(this._data);
203
- const mdata = this._verovio.renderToMIDI();
235
+ _verovio.loadData(this._data);
236
+ const mdata = _verovio.renderToMIDI();
204
237
  const raw = window.atob(mdata);
205
238
  const rawLength = raw.length;
206
239
  const array = new Uint8Array(new ArrayBuffer(rawLength));
@@ -226,7 +259,7 @@ export class PbMei extends pbMixin(LitElement) {
226
259
 
227
260
  render() {
228
261
  return html`
229
- <div id="toolbar">
262
+ <div id="toolbar" part="toolbar">
230
263
  <div class="${this._pages === 1 ? 'hidden' : ''}">
231
264
  <paper-icon-button id="pageLeft" icon="icons:chevron-left" @click="${this._previousPage}"
232
265
  ?disabled="${this._page === 1}"></paper-icon-button>
@@ -237,8 +270,8 @@ export class PbMei extends pbMixin(LitElement) {
237
270
  <div>${ this._renderOptions() }</div>
238
271
  </div>
239
272
  ${ this._svg ?
240
- html`<div id="output">${unsafeHTML(this._svg)}</div>` :
241
- html`<div id="output">${translate('dialogs.loading')}</div>`
273
+ html`<div id="output" part="music">${unsafeHTML(this._svg)}</div>` :
274
+ html`<div id="output" part="music">${translate('dialogs.loading')}</div>`
242
275
  }
243
276
  `;
244
277
  }
@@ -310,6 +343,7 @@ export class PbMei extends pbMixin(LitElement) {
310
343
  :host {
311
344
  display: grid;
312
345
  grid-template-rows: auto 1fr;
346
+ min-width: var(--pb-mei-min-width, auto);
313
347
  }
314
348
 
315
349
  #toolbar {
@@ -318,7 +352,7 @@ export class PbMei extends pbMixin(LitElement) {
318
352
  }
319
353
 
320
354
  #toolbar div {
321
- margin-right: 30px;
355
+ margin-right: 1rem;
322
356
  }
323
357
 
324
358
  #toolbar div:last-child {