@teipublisher/pb-components 2.26.1-next.3 → 3.0.0-next-4.2

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.
Files changed (262) hide show
  1. package/.github/workflows/docker-cypress.yml +53 -0
  2. package/.github/workflows/node.js.yml +70 -21
  3. package/.releaserc.json +7 -2
  4. package/CHANGELOG.md +363 -11
  5. package/Dockerfile +78 -70
  6. package/README.md +112 -4
  7. package/css/components.css +5 -5
  8. package/css/gridjs/mermaid.min.css +1 -1
  9. package/css/leaflet/Control.Geocoder.css +1 -126
  10. package/css/leaflet/images/layers.png +0 -0
  11. package/css/tify/tify.css +6 -5
  12. package/css/tom-select/tom-select.bootstrap4.min.css +1 -1
  13. package/css/tom-select/tom-select.bootstrap5.min.css +1 -1
  14. package/css/tom-select/tom-select.default.min.css +1 -1
  15. package/css/tom-select/tom-select.default.min.css.map +1 -0
  16. package/css/tom-select/tom-select.min.css +1 -1
  17. package/cypress.config.js +84 -0
  18. package/dist/api.html +1 -1
  19. package/dist/css/design-system.css +607 -0
  20. package/dist/demo/bundle-test.html +4 -3
  21. package/dist/demo/components.css +46 -1
  22. package/dist/demo/design-system.html +710 -0
  23. package/dist/demo/dts-client.html +2 -2
  24. package/dist/demo/pb-autocomplete.html +23 -11
  25. package/dist/demo/pb-autocomplete2.html +66 -55
  26. package/dist/demo/pb-autocomplete3.html +17 -8
  27. package/dist/demo/pb-blacklab-highlight.html +28 -11
  28. package/dist/demo/pb-blacklab-results.html +3 -2
  29. package/dist/demo/pb-browse-docs.html +24 -24
  30. package/dist/demo/pb-browse-docs2.html +3 -3
  31. package/dist/demo/pb-clipboard.html +32 -28
  32. package/dist/demo/pb-code-editor.html +6 -6
  33. package/dist/demo/pb-code-highlight.html +63 -63
  34. package/dist/demo/pb-codepen.html +1 -1
  35. package/dist/demo/pb-collapse.html +1 -1
  36. package/dist/demo/pb-collapse2.html +2 -2
  37. package/dist/demo/pb-combo-box.html +135 -130
  38. package/dist/demo/pb-custom-form.html +64 -55
  39. package/dist/demo/pb-dialog.html +12 -6
  40. package/dist/demo/pb-document.html +1 -1
  41. package/dist/demo/pb-download.html +68 -59
  42. package/dist/demo/pb-drawer.html +67 -46
  43. package/dist/demo/pb-drawer2.html +65 -58
  44. package/dist/demo/pb-edit-app.html +2 -2
  45. package/dist/demo/pb-edit-xml.html +1 -1
  46. package/dist/demo/pb-facsimile-2.html +26 -11
  47. package/dist/demo/pb-facsimile-3.html +25 -10
  48. package/dist/demo/pb-facsimile-dedup-test-2.html +48 -0
  49. package/dist/demo/pb-facsimile-dedup-test.html +48 -0
  50. package/dist/demo/pb-facsimile.html +4 -4
  51. package/dist/demo/pb-formula.html +1 -1
  52. package/dist/demo/pb-grid.html +22 -8
  53. package/dist/demo/pb-highlight.html +2 -2
  54. package/dist/demo/pb-i18n-simple.html +1 -0
  55. package/dist/demo/pb-i18n.html +15 -5
  56. package/dist/demo/pb-image-strip-standalone.html +2 -2
  57. package/dist/demo/pb-image-strip-view.html +2 -2
  58. package/dist/demo/pb-leaflet-map.html +3 -3
  59. package/dist/demo/pb-leaflet-map2.html +2 -2
  60. package/dist/demo/pb-leaflet-map3.html +3 -3
  61. package/dist/demo/pb-link.html +1 -1
  62. package/dist/demo/pb-load.html +2 -6
  63. package/dist/demo/pb-login.html +1 -3
  64. package/dist/demo/pb-manage-odds.html +9 -4
  65. package/dist/demo/pb-markdown.html +1 -1
  66. package/dist/demo/pb-media-query.html +2 -2
  67. package/dist/demo/pb-mei.html +2 -2
  68. package/dist/demo/pb-mei2.html +2 -2
  69. package/dist/demo/pb-message.html +2 -3
  70. package/dist/demo/pb-odd-editor.html +54 -52
  71. package/dist/demo/pb-page-header.html +27 -0
  72. package/dist/demo/pb-popover.html +1 -1
  73. package/dist/demo/pb-print-preview.html +2 -2
  74. package/dist/demo/pb-progress.html +4 -4
  75. package/dist/demo/pb-repeat.html +32 -36
  76. package/dist/demo/pb-search.html +16 -5
  77. package/dist/demo/pb-search2.html +4 -4
  78. package/dist/demo/pb-search3.html +3 -3
  79. package/dist/demo/pb-search4.html +3 -3
  80. package/dist/demo/pb-select-feature.html +4 -4
  81. package/dist/demo/pb-select-feature2.html +4 -4
  82. package/dist/demo/pb-select-feature3.html +2 -2
  83. package/dist/demo/pb-select-i18n.html +58 -53
  84. package/dist/demo/pb-select-odd.html +1 -1
  85. package/dist/demo/pb-select.html +190 -75
  86. package/dist/demo/pb-select2.html +91 -37
  87. package/dist/demo/pb-select3.html +109 -41
  88. package/dist/demo/pb-svg.html +1 -1
  89. package/dist/demo/pb-table-grid.html +26 -15
  90. package/dist/demo/pb-tabs.html +15 -7
  91. package/dist/demo/pb-tify.html +7 -7
  92. package/dist/demo/pb-timeline.html +1 -1
  93. package/dist/demo/pb-timeline2.html +1 -1
  94. package/dist/demo/pb-toggle-feature.html +26 -23
  95. package/dist/demo/pb-toggle-feature2.html +4 -4
  96. package/dist/demo/pb-toggle-feature3.html +2 -2
  97. package/dist/demo/pb-toggle-feature4.html +56 -54
  98. package/dist/demo/pb-version.html +2 -2
  99. package/dist/demo/pb-view.html +78 -40
  100. package/dist/demo/pb-view2.html +69 -46
  101. package/dist/demo/pb-view3.html +53 -48
  102. package/dist/demo/pb-view4.html +70 -49
  103. package/dist/demo/pb-zoom.html +2 -2
  104. package/dist/{es-global-bridge-d8ce175d.js → es-global-bridge-D8ZcUcx_.js} +0 -4
  105. package/dist/focus-mixin-VCsFap6b.js +768 -0
  106. package/dist/images/icons.svg +217 -0
  107. package/dist/jinn-codemirror-DETLdm08.js +1 -0
  108. package/dist/lib/openseadragon.min.js +80 -0
  109. package/dist/lib/openseadragon.min.js.map +1 -0
  110. package/dist/pb-code-editor.js +25 -20
  111. package/dist/pb-component-docs.js +414 -3225
  112. package/dist/pb-components-bundle.js +3046 -4402
  113. package/dist/pb-dialog-tklYGWfc.js +121 -0
  114. package/dist/pb-edit-app.js +208 -107
  115. package/dist/pb-elements.json +716 -249
  116. package/dist/pb-facsimile.js +46 -0
  117. package/dist/pb-i18n-C0NDma4h.js +1 -0
  118. package/dist/pb-leaflet-map.js +23 -23
  119. package/dist/pb-mei.js +152 -134
  120. package/dist/pb-mixin-DHoWQheB.js +1 -0
  121. package/dist/pb-odd-editor.js +1671 -1231
  122. package/dist/pb-tify.js +1 -27
  123. package/dist/unsafe-html-D5VGo9Oq.js +1 -0
  124. package/dist/urls-BEONu_g4.js +1 -0
  125. package/eslint.config.mjs +92 -0
  126. package/gh-pages.js +5 -3
  127. package/i18n/common/en.json +6 -0
  128. package/i18n/common/pl.json +2 -2
  129. package/images/icons.svg +217 -0
  130. package/index.html +0 -5
  131. package/lib/leaflet-src.js.map +1 -0
  132. package/lib/leaflet.markercluster-src.js.map +1 -0
  133. package/lib/openseadragon.min.js +6 -6
  134. package/package.json +56 -81
  135. package/pb-elements.json +716 -249
  136. package/rollup.config.mjs +312 -0
  137. package/src/assets/components.css +5 -5
  138. package/src/assets/design-system.css +607 -0
  139. package/src/authority/airtable.js +20 -21
  140. package/src/authority/anton.js +129 -129
  141. package/src/authority/custom.js +70 -27
  142. package/src/authority/geonames.js +38 -32
  143. package/src/authority/gnd.js +50 -42
  144. package/src/authority/kbga.js +136 -134
  145. package/src/authority/metagrid.js +44 -46
  146. package/src/authority/reconciliation.js +66 -68
  147. package/src/authority/registry.js +4 -4
  148. package/src/docs/demo-utils.js +91 -0
  149. package/src/docs/pb-component-docs.js +287 -147
  150. package/src/docs/pb-component-view.js +380 -273
  151. package/src/docs/pb-components-list.js +115 -51
  152. package/src/docs/pb-demo-snippet.js +199 -174
  153. package/src/dts-client.js +306 -303
  154. package/src/dts-select-endpoint.js +125 -85
  155. package/src/parse-date-service.js +184 -135
  156. package/src/pb-ajax.js +175 -173
  157. package/src/pb-authority-lookup.js +198 -158
  158. package/src/pb-autocomplete.js +731 -313
  159. package/src/pb-blacklab-highlight.js +266 -260
  160. package/src/pb-blacklab-results.js +230 -225
  161. package/src/pb-browse-docs.js +601 -484
  162. package/src/pb-browse.js +68 -65
  163. package/src/pb-clipboard.js +97 -76
  164. package/src/pb-code-editor.js +111 -103
  165. package/src/pb-code-highlight.js +234 -204
  166. package/src/pb-codepen.js +81 -73
  167. package/src/pb-collapse.js +265 -152
  168. package/src/pb-combo-box.js +191 -191
  169. package/src/pb-components-bundle.js +1 -7
  170. package/src/pb-components.js +2 -6
  171. package/src/pb-custom-form.js +230 -141
  172. package/src/pb-dialog.js +99 -63
  173. package/src/pb-document.js +118 -91
  174. package/src/pb-download.js +214 -198
  175. package/src/pb-drawer.js +146 -149
  176. package/src/pb-edit-app.js +471 -240
  177. package/src/pb-edit-xml.js +101 -98
  178. package/src/pb-events.js +126 -107
  179. package/src/pb-facs-link.js +130 -101
  180. package/src/pb-facsimile.js +494 -410
  181. package/src/pb-fetch.js +389 -0
  182. package/src/pb-formula.js +152 -154
  183. package/src/pb-geolocation.js +130 -132
  184. package/src/pb-grid-action.js +59 -56
  185. package/src/pb-grid.js +388 -228
  186. package/src/pb-highlight.js +142 -142
  187. package/src/pb-hotkeys.js +40 -42
  188. package/src/pb-i18n.js +115 -127
  189. package/src/pb-icon-button.js +108 -0
  190. package/src/pb-icon.js +283 -0
  191. package/src/pb-image-strip.js +85 -79
  192. package/src/pb-lang.js +142 -57
  193. package/src/pb-leaflet-map.js +551 -483
  194. package/src/pb-link.js +132 -126
  195. package/src/pb-load.js +495 -428
  196. package/src/pb-login.js +303 -248
  197. package/src/pb-manage-odds.js +384 -338
  198. package/src/pb-map-icon.js +90 -90
  199. package/src/pb-map-layer.js +86 -86
  200. package/src/pb-markdown.js +107 -110
  201. package/src/pb-media-query.js +75 -73
  202. package/src/pb-mei.js +523 -303
  203. package/src/pb-message.js +144 -98
  204. package/src/pb-mixin.js +268 -265
  205. package/src/pb-navigation.js +83 -96
  206. package/src/pb-observable.js +39 -39
  207. package/src/pb-odd-editor.js +1209 -948
  208. package/src/pb-odd-elementspec-editor.js +375 -310
  209. package/src/pb-odd-model-editor.js +1189 -941
  210. package/src/pb-odd-parameter-editor.js +269 -170
  211. package/src/pb-odd-rendition-editor.js +184 -131
  212. package/src/pb-page.js +451 -422
  213. package/src/pb-paginate.js +260 -178
  214. package/src/pb-panel.js +217 -183
  215. package/src/pb-popover-themes.js +16 -9
  216. package/src/pb-popover.js +297 -288
  217. package/src/pb-print-preview.js +128 -128
  218. package/src/pb-progress.js +52 -52
  219. package/src/pb-repeat.js +141 -108
  220. package/src/pb-restricted.js +85 -78
  221. package/src/pb-search.js +258 -230
  222. package/src/pb-select-feature.js +210 -126
  223. package/src/pb-select-odd.js +184 -118
  224. package/src/pb-select-template.js +113 -78
  225. package/src/pb-select.js +330 -229
  226. package/src/pb-split-list.js +181 -176
  227. package/src/pb-svg.js +81 -80
  228. package/src/pb-table-column.js +55 -55
  229. package/src/pb-table-grid.js +334 -205
  230. package/src/pb-tabs.js +238 -61
  231. package/src/pb-tify.js +3331 -126
  232. package/src/pb-timeline.js +394 -255
  233. package/src/pb-toggle-feature.js +196 -188
  234. package/src/pb-upload.js +201 -176
  235. package/src/pb-version.js +22 -34
  236. package/src/pb-view-annotate.js +138 -102
  237. package/src/pb-view.js +1722 -1272
  238. package/src/pb-zoom.js +144 -46
  239. package/src/search-result-service.js +256 -223
  240. package/src/seed-element.js +14 -22
  241. package/src/settings.js +4 -4
  242. package/src/theming.js +98 -91
  243. package/src/urls.js +403 -289
  244. package/src/utils.js +53 -51
  245. package/vite.config.js +86 -0
  246. package/.github/workflows/main.yml +0 -24
  247. package/.github/workflows/release.js.yml +0 -34
  248. package/css/pb-styles.css +0 -51
  249. package/dist/iron-form-3b8dcaa7.js +0 -210
  250. package/dist/jinn-codemirror-da0e2d1f.js +0 -1
  251. package/dist/paper-checkbox-515a5284.js +0 -1597
  252. package/dist/paper-icon-button-b1d31571.js +0 -398
  253. package/dist/paper-listbox-a3b7175c.js +0 -1265
  254. package/dist/pb-i18n-0611135a.js +0 -1
  255. package/dist/pb-mixin-b1caa22e.js +0 -158
  256. package/dist/polymer-hack.js +0 -1
  257. package/dist/vaadin-element-mixin-fe4a4883.js +0 -527
  258. package/lib/Control.Geocoder.min.js +0 -2
  259. package/lib/Control.Geocoder.min.js.map +0 -1
  260. package/src/assets/pb-styles.css +0 -51
  261. package/src/pb-light-dom.js +0 -41
  262. package/src/polymer-hack.js +0 -6
package/src/pb-mei.js CHANGED
@@ -1,48 +1,41 @@
1
- import { LitElement, html, css } from 'lit-element';
2
- import { unsafeHTML } from 'lit-html/directives/unsafe-html.js';
3
- import "@lrnwebcomponents/es-global-bridge";
4
- import createVerovioModule from 'verovio/dist/verovio-module.mjs';
5
- import { VerovioToolkit } from 'verovio/dist/verovio.mjs';
1
+ import { LitElement, html, css } from 'lit';
2
+ import { unsafeHTML } from 'lit/directives/unsafe-html.js';
3
+ import '@lrnwebcomponents/es-global-bridge';
4
+ // Use package export maps supported by verovio 3.x
5
+ import createVerovioModule from 'verovio/wasm';
6
+ import { VerovioToolkit } from 'verovio/esm';
6
7
  import { pbMixin, waitOnce } from './pb-mixin.js';
7
8
  import { translate } from './pb-i18n.js';
8
9
  import { resolveURL } from './utils.js';
9
- import '@polymer/paper-icon-button';
10
- import '@polymer/paper-checkbox';
11
- import '@polymer/iron-icons';
12
- import '@polymer/iron-icons/av-icons';
13
10
 
14
11
  let _verovio = null;
15
12
 
16
13
  /** Import external script dynamically */
17
14
  function _import(name, location) {
18
- window.ESGlobalBridge.requestAvailability();
19
- return new Promise(resolve => {
20
- window.ESGlobalBridge.instance.load(name, location);
21
- window.addEventListener(
22
- `es-bridge-${name}-loaded`,
23
- () => resolve(),
24
- { once: true }
25
- );
26
- });
15
+ window.ESGlobalBridge.requestAvailability();
16
+ return new Promise(resolve => {
17
+ window.ESGlobalBridge.instance.load(name, location);
18
+ window.addEventListener(`es-bridge-${name}-loaded`, () => resolve(), { once: true });
19
+ });
27
20
  }
28
21
 
29
22
  /**
30
23
  * A viewer and player for MEI musical notation based on [Verovio](https://www.verovio.org/).
31
24
  * Supports optional MIDI playback using [web-midi-player](https://midi.yvesgurcan.com/).
32
25
  * Both libraries are loaded dynamically when the component is used the first time.
33
- *
26
+ *
34
27
  * Viewing options to be selected by the user can be defined via nested `pb-option` elements:
35
- *
28
+ *
36
29
  * ```html
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"
30
+ * <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"
38
31
  * footer="none">
39
32
  * <pb-option name="appXPath" on="./rdg[contains(@label, 'original')]" off="">Original Clefs</pb-option>
40
33
  * </pb-mei>
41
34
  * ```
42
- *
35
+ *
43
36
  * The MEI document to display can either be given directly in the `data` property or loaded from an URL
44
37
  * specified in `url`.
45
- *
38
+ *
46
39
  * @prop {"auto" | "encoded" | "none" | "always"} footer - Control footer layout
47
40
  * @prop {"auto" | "encoded" | "none"} header - Control footer layout
48
41
  * @prop {"auto" | "none" | "line" | "encoded" | "smart"} breaks - Define page and system breaks layout (default: "auto")
@@ -51,323 +44,550 @@ function _import(name, location) {
51
44
  * @csspart music - the music output area
52
45
  */
53
46
  export class PbMei extends pbMixin(LitElement) {
47
+ static get properties() {
48
+ return {
49
+ /**
50
+ * MEI data to display specified as a string. This should represent a complete
51
+ * MEI document.
52
+ */
53
+ data: {
54
+ type: String,
55
+ },
56
+ /**
57
+ * URL of the MEI file to load. Will be used if no `data` property is present.
58
+ * A relative URL would be resolved relative to the TEI Publisher endpoint.
59
+ */
60
+ url: {
61
+ type: String,
62
+ },
63
+ /**
64
+ * Set to enable MIDI player
65
+ */
66
+ player: {
67
+ type: Boolean,
68
+ },
69
+ header: {
70
+ type: String,
71
+ },
72
+ footer: {
73
+ type: String,
74
+ },
75
+ breaks: {
76
+ type: String,
77
+ },
78
+ /**
79
+ * Set the XPath query for selecting <app> child elements, for example: "./rdg[contains(@source, 'source-id')]";
80
+ * by default the <lem> or the first <rdg> is selected
81
+ */
82
+ appXPath: {
83
+ type: String,
84
+ attribute: 'app-xpath',
85
+ },
86
+ /**
87
+ * Set the xPath query for selecting <choice> child elements, for example: "./orig"; by default the first child is selected
88
+ */
89
+ choiceXPath: {
90
+ type: String,
91
+ attribute: 'choice-xpath',
92
+ },
93
+ /**
94
+ * Set the xPath query for selecting the <mdiv> to be rendered; only one <mdiv> can be rendered (default: "")
95
+ */
96
+ mdivXPath: {
97
+ type: String,
98
+ attribute: 'mdiv-xpath',
99
+ },
100
+ /**
101
+ * Set the xPath query for selecting <subst> child elements, for example: "./del"; by default the first child is selected
102
+ */
103
+ substXPath: {
104
+ type: String,
105
+ attribute: 'subst-xpath',
106
+ },
107
+ _isPlaying: {
108
+ type: Boolean,
109
+ },
110
+ _svg: {
111
+ type: String,
112
+ },
113
+ ...super.properties,
114
+ };
115
+ }
54
116
 
55
- static get properties() {
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
- },
64
- /**
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.
67
- */
68
- url: {
69
- type: String,
70
- },
71
- /**
72
- * Set to enable MIDI player
73
- */
74
- player: {
75
- type: Boolean,
76
- },
77
- header: {
78
- type: String,
79
- },
80
- footer: {
81
- type: String,
82
- },
83
- breaks: {
84
- type: String,
85
- },
86
- /**
87
- * Set the XPath query for selecting <app> child elements, for example: "./rdg[contains(@source, 'source-id')]";
88
- * by default the <lem> or the first <rdg> is selected
89
- */
90
- appXPath: {
91
- type: String,
92
- attribute: 'app-xpath',
93
- },
94
- /**
95
- * Set the xPath query for selecting <choice> child elements, for example: "./orig"; by default the first child is selected
96
- */
97
- choiceXPath: {
98
- type: String,
99
- attribute: 'choice-xpath',
100
- },
101
- /**
102
- * Set the xPath query for selecting the <mdiv> to be rendered; only one <mdiv> can be rendered (default: "")
103
- */
104
- mdivXPath: {
105
- type: String,
106
- attribute: 'mdiv-xpath',
107
- },
108
- /**
109
- * Set the xPath query for selecting <subst> child elements, for example: "./del"; by default the first child is selected
110
- */
111
- substXPath: {
112
- type: String,
113
- attribute: 'subst-xpath',
114
- },
115
- _svg: {
116
- type: String,
117
- },
118
- ...super.properties,
119
- };
120
- }
117
+ constructor() {
118
+ super();
119
+ this._data = null;
120
+ this._svg = null;
121
+ this._pages = 0;
122
+ this._page = 0;
123
+ this._midiPlayer = null;
124
+ this.footer = 'auto';
125
+ this.header = 'auto';
126
+ this.breaks = 'auto';
127
+ this.appXPath = null;
128
+ this.choiceXPath = null;
129
+ this.mdivXPath = null;
130
+ this.substXPath = null;
131
+ this._options = [];
132
+ this._isPlaying = false;
133
+ this._midiPaused = false;
134
+ }
121
135
 
122
- constructor() {
123
- super();
124
- this._data = null;
125
- this._svg = null;
126
- this._pages = 0;
127
- this._page = 0;
128
- this._midiPlayer = null;
129
- this.footer = 'auto';
130
- this.header = 'auto';
131
- this.breaks = 'auto';
132
- this.appXPath = null;
133
- this.choiceXPath = null;
134
- this.mdivXPath = null;
135
- this.substXPath = null;
136
- this._options = [];
136
+ connectedCallback() {
137
+ super.connectedCallback();
138
+
139
+ this.querySelectorAll('pb-option').forEach(option => {
140
+ this._options.push({
141
+ name: option.getAttribute('name'),
142
+ on: option.getAttribute('on'),
143
+ off: option.getAttribute('off'),
144
+ label: option.innerHTML,
145
+ });
146
+ });
147
+ }
148
+
149
+ firstUpdated() {
150
+ super.firstUpdated();
151
+
152
+ if (this.player) {
153
+ _import('midiPlayer', resolveURL('../lib/web-midi-player/index.js')).then(() => {
154
+ const {
155
+ 'web-midi-player': { default: MidiPlayer },
156
+ } = window;
157
+ this._midiPlayer = new MidiPlayer();
158
+ });
137
159
  }
138
160
 
139
- connectedCallback() {
140
- super.connectedCallback();
161
+ if (!_verovio) {
162
+ createVerovioModule().then(VerovioModule => {
163
+ _verovio = new VerovioToolkit(VerovioModule);
141
164
 
142
- this.querySelectorAll('pb-option').forEach((option) => {
143
- this._options.push({
144
- name: option.getAttribute('name'),
145
- on: option.getAttribute('on'),
146
- off: option.getAttribute('off'),
147
- label: option.innerHTML
148
- })
165
+ waitOnce('pb-page-ready', () => {
166
+ this.load();
149
167
  });
168
+ });
169
+ } else {
170
+ waitOnce('pb-page-ready', () => {
171
+ this.load();
172
+ });
150
173
  }
174
+ }
151
175
 
152
- firstUpdated() {
153
- super.firstUpdated();
176
+ update(changedProps) {
177
+ super.update(changedProps);
178
+ if (changedProps.get('url') || changedProps.get('data')) {
179
+ this.load();
180
+ } else if (
181
+ (changedProps.has('appXPath') ||
182
+ changedProps.has('choiceXPath') ||
183
+ changedProps.has('mdivXPath') ||
184
+ changedProps.has('substXPath')) &&
185
+ _verovio
186
+ ) {
187
+ _verovio.setOptions(this._getOptions());
188
+ try {
189
+ _verovio.loadData(this._data);
190
+ this.showPage();
191
+ } catch (error) {
192
+ console.error('<pb-mei> Failed to reload MEI data:', error);
193
+ this._handleError(error);
194
+ }
195
+ }
196
+ }
154
197
 
155
- if (this.player) {
156
- _import("midiPlayer", resolveURL('../lib/web-midi-player/index.js'))
157
- .then(() => {
158
- const { 'web-midi-player': { default: MidiPlayer } } = window;
159
- this._midiPlayer = new MidiPlayer();
160
- });
161
- }
198
+ load() {
199
+ if (this.data) {
200
+ console.log('<pb-mei> Rendering data');
201
+ this.show(this.data);
202
+ } else if (this.url) {
203
+ const link = this.toAbsoluteURL(this.url);
162
204
 
163
- if (!_verovio) {
164
- createVerovioModule().then(VerovioModule => {
165
- _verovio = new VerovioToolkit(VerovioModule);
166
-
167
- waitOnce('pb-page-ready', () => {
168
- this.load();
169
- });
170
- });
171
- } else {
172
- waitOnce('pb-page-ready', () => {
173
- this.load();
174
- });
175
- }
205
+ fetch(link)
206
+ .then(response => response.text())
207
+ .then(async str => {
208
+ this.show(str);
209
+ });
176
210
  }
211
+ }
177
212
 
178
- update(changedProps) {
179
- super.update(changedProps);
180
- if (changedProps.get('url') || changedProps.get('data')) {
181
- this.load();
182
- } else if (
183
- (changedProps.has('appXPath') ||
184
- changedProps.has('choiceXPath') ||
185
- changedProps.has('mdivXPath') ||
186
- changedProps.has('substXPath')) &&
187
- _verovio
188
- ) {
189
- _verovio.setOptions(this._getOptions());
190
- _verovio.loadData(this._data);
191
- this.showPage();
192
- }
193
- }
213
+ show(str) {
214
+ this._data = str;
215
+ _verovio.setOptions(this._getOptions());
194
216
 
195
- load() {
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);
201
-
202
- fetch(link)
203
- .then(response => response.text())
204
- .then(async str => {
205
- this.show(str);
206
- });
207
- }
217
+ try {
218
+ _verovio.loadData(this._data);
219
+ this._pages = _verovio.getPageCount();
220
+ this._page = 1;
221
+ console.log('<pb-mei> Loaded %d pages', this._pages);
222
+ this.showPage();
223
+ } catch (error) {
224
+ console.error('<pb-mei> Failed to load MEI data:', error);
225
+ this._handleError(error);
208
226
  }
227
+ }
209
228
 
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();
229
+ showPage() {
230
+ this._svg = _verovio.renderToSVG(this._page, {});
231
+ }
232
+
233
+ _handleError(error) {
234
+ // Clear any existing error
235
+ this._clearError();
236
+
237
+ // Create error message element
238
+ const errorDiv = document.createElement('div');
239
+ errorDiv.className = 'pb-mei-error';
240
+ errorDiv.style.cssText = `
241
+ padding: 1rem;
242
+ margin: 1rem;
243
+ background-color: #fee;
244
+ border: 1px solid #fcc;
245
+ border-radius: 4px;
246
+ color: #c33;
247
+ font-family: sans-serif;
248
+ font-size: 14px;
249
+ `;
250
+
251
+ let errorMessage = 'Failed to load MEI data';
252
+ const errorText = error.message || error.toString() || '';
253
+
254
+ if (
255
+ errorText.includes('function or function signature mismatch') ||
256
+ errorText.includes('null function')
257
+ ) {
258
+ errorMessage = 'Invalid MEI data format';
259
+ } else if (errorText.includes('parse') || errorText.includes('XML')) {
260
+ errorMessage = 'Invalid XML/MEI syntax';
261
+ } else if (errorText.includes('WASM') || errorText.includes('module')) {
262
+ errorMessage = 'MEI rendering engine error';
218
263
  }
219
264
 
220
- showPage() {
221
- this._svg = _verovio.renderToSVG(this._page, {});
265
+ errorDiv.textContent = errorMessage;
266
+
267
+ // Insert error message into the component
268
+ if (this.shadowRoot) {
269
+ const output = this.shadowRoot.querySelector('#output');
270
+ if (output) {
271
+ output.innerHTML = '';
272
+ output.appendChild(errorDiv);
273
+ }
222
274
  }
223
275
 
224
- async play() {
225
- const button = this.shadowRoot.getElementById('play');
226
- if (!button.active) {
227
- this._midiPlayer.stop();
228
- button.icon = 'av:play-arrow';
229
- } else {
230
- button.icon = 'av:stop';
231
- if (this._midiPaused) {
232
- this._midiPaused = false;
233
- this._midiPlayer.resume();
234
- } else {
235
- _verovio.loadData(this._data);
236
- const mdata = _verovio.renderToMIDI();
237
- const raw = window.atob(mdata);
238
- const rawLength = raw.length;
239
- const array = new Uint8Array(new ArrayBuffer(rawLength));
240
-
241
- for (let i = 0; i < rawLength; i += 1) {
242
- array[i] = raw.charCodeAt(i);
243
- }
244
- this._midiPlayer.play({ arrayBuffer: array });
245
- }
276
+ // Emit error event
277
+ this.dispatchEvent(
278
+ new CustomEvent('pb-mei-error', {
279
+ detail: {
280
+ error: error.message || 'Unknown error',
281
+ data: this._data,
282
+ },
283
+ }),
284
+ );
285
+ }
286
+
287
+ _clearError() {
288
+ if (this.shadowRoot) {
289
+ const output = this.shadowRoot.querySelector('#output');
290
+ if (output) {
291
+ const existingError = output.querySelector('.pb-mei-error');
292
+ if (existingError) {
293
+ existingError.remove();
246
294
  }
295
+ }
247
296
  }
297
+ }
248
298
 
249
- pause() {
250
- const button = this.shadowRoot.getElementById('play');
251
- if (button.active) {
252
- this._midiPaused = this._midiPlayer.pause();
253
- if (this._midiPaused) {
254
- button.icon = 'av:play-arrow';
255
- button.active = false;
256
- }
257
- }
299
+ async play() {
300
+ if (!this.player || !this._midiPlayer) {
301
+ return;
258
302
  }
259
303
 
260
- render() {
261
- return html`
262
- <div id="toolbar" part="toolbar">
263
- <div class="${this._pages === 1 ? 'hidden' : ''}">
264
- <paper-icon-button id="pageLeft" icon="icons:chevron-left" @click="${this._previousPage}"
265
- ?disabled="${this._page === 1}"></paper-icon-button>
266
- <paper-icon-button id="pageRight" icon="icons:chevron-right" @click="${this._nextPage}"
267
- ?disabled="${this._page === this._pages}"></paper-icon-button>
268
- </div>
269
- ${ this._renderPlayer() }
270
- <div>${ this._renderOptions() }</div>
271
- </div>
272
- ${ this._svg ?
273
- html`<div id="output" part="music">${unsafeHTML(this._svg)}</div>` :
274
- html`<div id="output" part="music">${translate('dialogs.loading')}</div>`
275
- }
276
- `;
304
+ this._isPlaying = !this._isPlaying;
305
+ if (!this._isPlaying) {
306
+ this._midiPlayer.stop();
307
+ this._midiPaused = false;
308
+ this.requestUpdate('_isPlaying');
309
+ return;
277
310
  }
278
311
 
279
- _renderPlayer() {
280
- if (this.player) {
281
- return html`
282
- <div id="player">
283
- <paper-icon-button id="play" icon="av:play-arrow" toggles @click="${this.play}"></paper-icon-button>
284
- <paper-icon-button icon="av:pause" @click="${this.pause}"></paper-icon-button>
285
- </div>
286
- `;
287
- }
288
- return null;
312
+ if (this._midiPaused) {
313
+ this._midiPaused = false;
314
+ this._midiPlayer.resume();
315
+ this.requestUpdate('_isPlaying');
316
+ return;
317
+ }
318
+
319
+ try {
320
+ _verovio.loadData(this._data);
321
+ const mdata = _verovio.renderToMIDI();
322
+ const raw = window.atob(mdata);
323
+ const rawLength = raw.length;
324
+ const array = new Uint8Array(new ArrayBuffer(rawLength));
325
+
326
+ for (let i = 0; i < rawLength; i += 1) {
327
+ array[i] = raw.charCodeAt(i);
328
+ }
329
+ this._midiPlayer.play({ arrayBuffer: array });
330
+ this.requestUpdate('_isPlaying');
331
+ } catch (error) {
332
+ console.error('<pb-mei> Failed to play MIDI:', error);
333
+ this._isPlaying = false;
334
+ this.requestUpdate('_isPlaying');
335
+ this._handleError(error);
289
336
  }
337
+ }
290
338
 
291
- _renderOptions() {
292
- return this._options.map(option =>
293
- html`<paper-checkbox @change="${(ev) => this._setOption(option, ev.target.checked)}">${option.label}</paper-checkbox>`
294
- );
339
+ pause() {
340
+ if (!this.player || !this._midiPlayer || !this._isPlaying) {
341
+ return;
295
342
  }
296
343
 
297
- _setOption(option, checked) {
298
- let value;
299
- if (checked) {
300
- value = option.on && option.on.length > 0 ? option.on : null;
301
- } else {
302
- value = option.off && option.off.length > 0 ? option.off : null;
303
- }
304
- this[option.name] = value;
344
+ this._midiPaused = this._midiPlayer.pause();
345
+ this._isPlaying = false;
346
+ this.requestUpdate('_isPlaying');
347
+ }
348
+
349
+ render() {
350
+ return html`
351
+ <div id="toolbar" part="toolbar">
352
+ <div class="${this._pages === 1 ? 'hidden' : ''}">
353
+ <button
354
+ id="pageLeft"
355
+ class="pb-button pb-button--icon"
356
+ type="button"
357
+ aria-label="Previous page"
358
+ title="Previous page"
359
+ @click="${this._previousPage}"
360
+ ?disabled="${this._page === 1}"
361
+ >
362
+ ${this._renderChevron('left')}
363
+ </button>
364
+ <button
365
+ id="pageRight"
366
+ class="pb-button pb-button--icon"
367
+ type="button"
368
+ aria-label="Next page"
369
+ title="Next page"
370
+ @click="${this._nextPage}"
371
+ ?disabled="${this._page === this._pages}"
372
+ >
373
+ ${this._renderChevron('right')}
374
+ </button>
375
+ </div>
376
+ ${this._renderPlayer()}
377
+ <div>${this._renderOptions()}</div>
378
+ </div>
379
+ ${this._svg
380
+ ? html`<div id="output" part="music">${unsafeHTML(this._svg)}</div>`
381
+ : html`<div id="output" part="music">${translate('dialogs.loading')}</div>`}
382
+ `;
383
+ }
384
+
385
+ _renderPlayer() {
386
+ if (this.player) {
387
+ return html`
388
+ <div id="player">
389
+ <button
390
+ id="play"
391
+ class="pb-button pb-button--icon ${this._isPlaying ? 'is-active' : ''}"
392
+ type="button"
393
+ aria-label="${this._isPlaying ? 'Stop playback' : 'Start playback'}"
394
+ aria-pressed="${this._isPlaying ? 'true' : 'false'}"
395
+ title="${this._isPlaying ? 'Stop playback' : 'Start playback'}"
396
+ @click="${this.play}"
397
+ >
398
+ ${this._isPlaying ? this._renderStopIcon() : this._renderPlayIcon()}
399
+ </button>
400
+ <button
401
+ class="pb-button pb-button--icon"
402
+ type="button"
403
+ aria-label="Pause playback"
404
+ title="Pause playback"
405
+ @click="${this.pause}"
406
+ >
407
+ ${this._renderPauseIcon()}
408
+ </button>
409
+ </div>
410
+ `;
305
411
  }
412
+ return null;
413
+ }
306
414
 
307
- _nextPage(ev) {
308
- ev.preventDefault();
309
- if (this._page < this._pages) {
310
- this._page += 1;
311
- this.showPage();
312
- }
415
+ _renderOptions() {
416
+ return this._options.map(
417
+ option =>
418
+ html`<label class="option-toggle">
419
+ <input
420
+ type="checkbox"
421
+ class="option-toggle__control"
422
+ @change="${ev => this._setOption(option, ev.target.checked)}"
423
+ .checked=${Boolean(this[option.name])}
424
+ />
425
+ <span class="option-toggle__label">${option.label}</span>
426
+ </label>`,
427
+ );
428
+ }
429
+
430
+ _renderChevron(direction) {
431
+ const path =
432
+ direction === 'left'
433
+ ? 'M15.41 7.41L14 6l-6 6 6 6 1.41-1.41L10.83 12z'
434
+ : 'M8.59 16.59L13.17 12 8.59 7.41 10 6l6 6-6 6z';
435
+ return html`<svg
436
+ width="20"
437
+ height="20"
438
+ viewBox="0 0 24 24"
439
+ aria-hidden="true"
440
+ focusable="false"
441
+ >
442
+ <path d="${path}"></path>
443
+ </svg>`;
444
+ }
445
+
446
+ _renderPlayIcon() {
447
+ return html`<svg
448
+ width="20"
449
+ height="20"
450
+ viewBox="0 0 24 24"
451
+ aria-hidden="true"
452
+ focusable="false"
453
+ >
454
+ <path d="M8 5v14l11-7z"></path>
455
+ </svg>`;
456
+ }
457
+
458
+ _renderStopIcon() {
459
+ return html`<svg
460
+ width="20"
461
+ height="20"
462
+ viewBox="0 0 24 24"
463
+ aria-hidden="true"
464
+ focusable="false"
465
+ >
466
+ <path d="M6 6h12v12H6z"></path>
467
+ </svg>`;
468
+ }
469
+
470
+ _renderPauseIcon() {
471
+ return html`<svg
472
+ width="20"
473
+ height="20"
474
+ viewBox="0 0 24 24"
475
+ aria-hidden="true"
476
+ focusable="false"
477
+ >
478
+ <path d="M6 19h4V5H6zm8-14v14h4V5h-4z"></path>
479
+ </svg>`;
480
+ }
481
+
482
+ _setOption(option, checked) {
483
+ let value;
484
+ if (checked) {
485
+ value = option.on && option.on.length > 0 ? option.on : null;
486
+ } else {
487
+ value = option.off && option.off.length > 0 ? option.off : null;
313
488
  }
489
+ this[option.name] = value;
490
+ }
314
491
 
315
- _previousPage(ev) {
316
- ev.preventDefault();
317
- if (this._page > 1) {
318
- this._page -= 1;
319
- this.showPage();
320
- }
492
+ _nextPage(ev) {
493
+ ev.preventDefault();
494
+ if (this._page < this._pages) {
495
+ this._page += 1;
496
+ this.showPage();
321
497
  }
498
+ }
322
499
 
323
- _getOptions() {
324
- const options = {
325
- // svg content should scale with the width of the component
326
- svgViewBox: true,
327
- adjustPageHeight: true,
328
- footer: this.footer,
329
- header: this.header,
330
- breaks: this.breaks,
331
- appXPathQuery: [this.appXPath],
332
- substXPathQuery: [this.substXPath],
333
- choiceXPathQuery: [this.choiceXPath]
334
- };
335
- if (this.mdivXPath) {
336
- options.mdivXPathQuery = this.mdivXPath;
337
- }
338
- return options;
500
+ _previousPage(ev) {
501
+ ev.preventDefault();
502
+ if (this._page > 1) {
503
+ this._page -= 1;
504
+ this.showPage();
339
505
  }
506
+ }
340
507
 
341
- static get styles() {
342
- return css`
343
- :host {
344
- display: grid;
345
- grid-template-rows: auto 1fr;
346
- min-width: var(--pb-mei-min-width, auto);
347
- }
348
-
349
- #toolbar {
350
- display: flex;
351
- align-items: center;
352
- }
353
-
354
- #toolbar div {
355
- margin-right: 1rem;
356
- }
357
-
358
- #toolbar div:last-child {
359
- margin-right: 0;
360
- }
361
-
362
- #output {
363
- width: 100%;
364
- overflow: auto;
365
- }
366
-
367
- .hidden {
368
- display: none;
369
- }
370
- `;
508
+ _getOptions() {
509
+ const options = {
510
+ // svg content should scale with the width of the component
511
+ svgViewBox: true,
512
+ adjustPageHeight: true,
513
+ footer: this.footer,
514
+ header: this.header,
515
+ breaks: this.breaks,
516
+ appXPathQuery: [this.appXPath],
517
+ substXPathQuery: [this.substXPath],
518
+ choiceXPathQuery: [this.choiceXPath],
519
+ };
520
+ if (this.mdivXPath) {
521
+ options.mdivXPathQuery = this.mdivXPath;
371
522
  }
523
+ return options;
524
+ }
525
+
526
+ static get styles() {
527
+ return css`
528
+ :host {
529
+ display: grid;
530
+ grid-template-rows: auto 1fr;
531
+ min-width: var(--pb-mei-min-width, auto);
532
+ }
533
+
534
+ #toolbar {
535
+ display: flex;
536
+ align-items: center;
537
+ }
538
+
539
+ #toolbar div {
540
+ margin-right: 1rem;
541
+ }
542
+
543
+ #toolbar div:last-child {
544
+ margin-right: 0;
545
+ }
546
+
547
+ #toolbar button.pb-button--icon {
548
+ margin-right: 0.5rem;
549
+ }
550
+
551
+ #toolbar button.pb-button--icon:last-child {
552
+ margin-right: 0;
553
+ }
554
+
555
+ #output {
556
+ width: 100%;
557
+ overflow: auto;
558
+ }
559
+
560
+ .hidden {
561
+ display: none;
562
+ }
563
+
564
+ #player {
565
+ display: inline-flex;
566
+ gap: 0.5rem;
567
+ align-items: center;
568
+ }
569
+
570
+ #player .pb-button.is-active {
571
+ background-color: var(--pb-primary-color);
572
+ color: var(--pb-on-primary-color);
573
+ }
574
+
575
+ .option-toggle {
576
+ display: inline-flex;
577
+ align-items: center;
578
+ gap: 0.5rem;
579
+ margin-right: 0.75rem;
580
+ font-size: 0.95em;
581
+ }
582
+
583
+ .option-toggle:last-child {
584
+ margin-right: 0;
585
+ }
586
+
587
+ .option-toggle__control {
588
+ accent-color: var(--pb-primary-color, #1976d2);
589
+ }
590
+ `;
591
+ }
372
592
  }
373
- customElements.define('pb-mei', PbMei);
593
+ customElements.define('pb-mei', PbMei);