@@ -8,6 +8,22 @@ export function openFile(api: alphaTab.AlphaTabApi, file: Blob) {
88 reader . readAsArrayBuffer ( file ) ;
99}
1010
11+ export function openInputFile ( api : alphaTab . AlphaTabApi ) {
12+ const input = document . createElement ( 'input' ) ;
13+ input . type = 'file' ;
14+ if ( ! isIOS ( ) ) {
15+ input . accept = '.gp,.gp3,.gp4,.gp5,.gpx,.musicxml,.mxml,.xml,.capx' ;
16+ }
17+ input . onchange = ( ) => {
18+ if ( input . files ?. length === 1 ) {
19+ openFile ( api , input . files [ 0 ] ) ;
20+ }
21+ } ;
22+ document . body . appendChild ( input ) ;
23+ input . click ( ) ;
24+ document . body . removeChild ( input ) ;
25+ } ;
26+
1127
1228export function downloadFile ( api : alphaTab . AlphaTabApi ) {
1329 const exporter = new alphaTab . exporter . Gp7Exporter ( ) ;
@@ -19,4 +35,27 @@ export function downloadFile(api: alphaTab.AlphaTabApi) {
1935 document . body . appendChild ( a ) ;
2036 a . click ( ) ;
2137 document . body . removeChild ( a ) ;
22- }
38+ }
39+
40+
41+ const iOSPlatforms = new Set ( [ 'iPhone' , 'iPad' , 'iPod' ] ) ;
42+ function isIOS ( ) {
43+ // Tested:
44+ // - iPad Pro 12.9 - iOS 12 (navigator.platform = "iPad")
45+ // - iPad Pro 11 2020 - iOS 13 (navigator.platform = "iPad")
46+ // - iPad Air 4 - iOS 14 (navigator.platform = "iPad")
47+ // - iPad Mini 2021 - iOS 15 (navigator.platform = "iPad")
48+ // - iPad Pro 12.9 2022 - iOS 16 (navigator.platform = "iPad")
49+ // - iPad Pro 12.9 2021 - iOS 17 (navigator.platform = "MacIntel" && navigator.maxTouchPoints > 1)
50+ // - iPad 9th - iOS 18 (navigator.platform = "iPad")
51+ // - iPhone XS - iOS 12 (navigator.platform = "iPhone")
52+ // - iPhone 11 - iOS 13 (navigator.platform = "iPhone")
53+ // - iPhone 12 - iOS 14 (navigator.platform = "iPhone")
54+ // - iPhone 13 - iOS 15 (navigator.platform = "iPhone")
55+ // - iPhone 14 - iOS 16 (navigator.platform = "iPhone")
56+ // - iPhone 15 - iOS 17 (navigator.platform = "iPhone")
57+ // - iPhone 16 - iOS 18 (navigator.platform = "iPhone")
58+ // - iPhone 16 - iOS 18.6 (navigator.platform = "iPhone")
59+ return iOSPlatforms . has ( navigator . platform ) ||
60+ navigator . platform == "MacIntel" && navigator . maxTouchPoints > 1 ;
61+ }
0 commit comments