@coderline/alphatab 1.2.2 → 1.3.0-alpha.1005

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 (36) hide show
  1. package/README.md +39 -32
  2. package/dist/alphaTab.core.min.mjs +2 -0
  3. package/dist/alphaTab.core.min.mjs.map +1 -0
  4. package/dist/alphaTab.core.mjs +45998 -0
  5. package/dist/alphaTab.core.mjs.map +1 -0
  6. package/dist/alphaTab.d.ts +7571 -6449
  7. package/dist/alphaTab.js +45614 -42133
  8. package/dist/alphaTab.js.map +1 -0
  9. package/dist/alphaTab.min.js +2 -17
  10. package/dist/alphaTab.min.js.map +1 -0
  11. package/dist/alphaTab.min.mjs +2 -0
  12. package/dist/alphaTab.min.mjs.map +1 -0
  13. package/dist/alphaTab.mjs +63 -0
  14. package/dist/alphaTab.mjs.map +1 -0
  15. package/dist/alphaTab.vite.d.ts +38 -0
  16. package/dist/alphaTab.vite.js +782 -0
  17. package/dist/alphaTab.vite.js.map +1 -0
  18. package/dist/alphaTab.vite.mjs +758 -0
  19. package/dist/alphaTab.vite.mjs.map +1 -0
  20. package/dist/alphaTab.webpack.d.ts +43 -0
  21. package/dist/alphaTab.webpack.js +478 -0
  22. package/dist/alphaTab.webpack.js.map +1 -0
  23. package/dist/alphaTab.webpack.mjs +453 -0
  24. package/dist/alphaTab.webpack.mjs.map +1 -0
  25. package/dist/alphaTab.worker.min.mjs +2 -0
  26. package/dist/alphaTab.worker.min.mjs.map +1 -0
  27. package/dist/alphaTab.worker.mjs +21 -0
  28. package/dist/alphaTab.worker.mjs.map +1 -0
  29. package/dist/alphaTab.worklet.min.mjs +2 -0
  30. package/dist/alphaTab.worklet.min.mjs.map +1 -0
  31. package/dist/alphaTab.worklet.mjs +21 -0
  32. package/dist/alphaTab.worklet.mjs.map +1 -0
  33. package/package.json +108 -82
  34. /package/dist/font/{FONTLOG.txt → Bravura-FONTLOG.txt} +0 -0
  35. /package/dist/font/{OFL-FAQ.txt → Bravura-OFL-FAQ.txt} +0 -0
  36. /package/dist/font/{OFL.txt → Bravura-OFL.txt} +0 -0
@@ -0,0 +1,782 @@
1
+ /**
2
+ * alphaTab v1.3.0-alpha.1005 (develop, build 1005)
3
+ *
4
+ * Copyright © 2024, Daniel Kuschny and Contributors, All rights reserved.
5
+ *
6
+ * This Source Code Form is subject to the terms of the Mozilla Public
7
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
8
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9
+ *
10
+ * SoundFont loading and Audio Synthesis based on TinySoundFont (licensed under MIT)
11
+ * Copyright (C) 2017, 2018 Bernhard Schelling (https://github.com/schellingb/TinySoundFont)
12
+ *
13
+ * TinySoundFont is based on SFZero (licensed under MIT)
14
+ * Copyright (C) 2012 Steve Folta (https://github.com/stevefolta/SFZero)
15
+ */
16
+
17
+ 'use strict';
18
+
19
+ Object.defineProperty(exports, '__esModule', { value: true });
20
+
21
+ var MagicString = require('magic-string');
22
+ var path = require('path');
23
+ var fs = require('fs');
24
+ var node_crypto = require('node:crypto');
25
+ var vite = require('vite');
26
+
27
+ function _interopNamespaceDefault(e) {
28
+ var n = Object.create(null);
29
+ if (e) {
30
+ Object.keys(e).forEach(function (k) {
31
+ if (k !== 'default') {
32
+ var d = Object.getOwnPropertyDescriptor(e, k);
33
+ Object.defineProperty(n, k, d.get ? d : {
34
+ enumerable: true,
35
+ get: function () { return e[k]; }
36
+ });
37
+ }
38
+ });
39
+ }
40
+ n.default = e;
41
+ return Object.freeze(n);
42
+ }
43
+
44
+ var path__namespace = /*#__PURE__*/_interopNamespaceDefault(path);
45
+ var fs__namespace = /*#__PURE__*/_interopNamespaceDefault(fs);
46
+
47
+ /**@target web */
48
+ // index.ts for more details on contents and license of this file
49
+ // https://github.com/vitejs/vite/blob/b7ddfae5f852c2948fab03e94751ce56f5f31ce0/packages/vite/src/node/utils.ts#L1302
50
+ function evalValue(rawValue) {
51
+ const fn = new Function(`
52
+ var console, exports, global, module, process, require
53
+ return (\n${rawValue}\n)
54
+ `);
55
+ return fn();
56
+ }
57
+ // https://github.com/vitejs/vite/blob/b7ddfae5f852c2948fab03e94751ce56f5f31ce0/packages/vite/src/shared/utils.ts#L31-L34
58
+ const postfixRE = /[?#].*$/;
59
+ function cleanUrl(url) {
60
+ return url.replace(postfixRE, '');
61
+ }
62
+ // https://github.com/vitejs/vite/blob/b7ddfae5f852c2948fab03e94751ce56f5f31ce0/packages/vite/src/node/utils.ts#L393
63
+ function tryStatSync(file) {
64
+ try {
65
+ // The "throwIfNoEntry" is a performance optimization for cases where the file does not exist
66
+ return fs__namespace.statSync(file, { throwIfNoEntry: false });
67
+ }
68
+ catch {
69
+ // Ignore errors
70
+ }
71
+ return;
72
+ }
73
+ // https://github.com/vitejs/vite/blob/b7ddfae5f852c2948fab03e94751ce56f5f31ce0/packages/vite/src/node/utils.ts#L1030
74
+ function getHash(text, length = 8) {
75
+ const h = node_crypto.createHash('sha256').update(text).digest('hex').substring(0, length);
76
+ if (length <= 64)
77
+ return h;
78
+ return h.padEnd(length, '_');
79
+ }
80
+ // https://github.com/vitejs/vite/blob/b7ddfae5f852c2948fab03e94751ce56f5f31ce0/packages/vite/src/shared/utils.ts#L40
81
+ function withTrailingSlash(path) {
82
+ if (path[path.length - 1] !== '/') {
83
+ return `${path}/`;
84
+ }
85
+ return path;
86
+ }
87
+ // https://github.com/vitejs/vite/blob/b7ddfae5f852c2948fab03e94751ce56f5f31ce0/packages/vite/src/node/utils.ts#L1268
88
+ function joinUrlSegments(a, b) {
89
+ if (!a || !b) {
90
+ return a || b || '';
91
+ }
92
+ if (a[a.length - 1] === '/') {
93
+ a = a.substring(0, a.length - 1);
94
+ }
95
+ if (b[0] !== '/') {
96
+ b = '/' + b;
97
+ }
98
+ return a + b;
99
+ }
100
+ // https://github.com/vitejs/vite/blob/b7ddfae5f852c2948fab03e94751ce56f5f31ce0/packages/vite/src/node/utils.ts#L1281
101
+ function removeLeadingSlash(str) {
102
+ return str[0] === '/' ? str.slice(1) : str;
103
+ }
104
+ // https://github.com/vitejs/vite/blob/b7ddfae5f852c2948fab03e94751ce56f5f31ce0/packages/vite/src/node/utils.ts#L319
105
+ function injectQuery(builtUrl, query) {
106
+ const queryIndex = builtUrl.indexOf('?');
107
+ return builtUrl + (queryIndex === -1 ? '?' : '&') + query;
108
+ }
109
+ // https://github.com/vitejs/vite/blob/b7ddfae5f852c2948fab03e94751ce56f5f31ce0/packages/vite/src/node/utils.ts#L1435
110
+ function partialEncodeURIPath(uri) {
111
+ if (uri.startsWith('data:'))
112
+ return uri;
113
+ const filePath = cleanUrl(uri);
114
+ const postfix = filePath !== uri ? uri.slice(filePath.length) : '';
115
+ return filePath.replaceAll('%', '%25') + postfix;
116
+ }
117
+ // https://github.com/vitejs/vite/blob/b7ddfae5f852c2948fab03e94751ce56f5f31ce0/packages/vite/src/node/utils.ts#L1424
118
+ function encodeURIPath(uri) {
119
+ if (uri.startsWith('data:'))
120
+ return uri;
121
+ const filePath = cleanUrl(uri);
122
+ const postfix = filePath !== uri ? uri.slice(filePath.length) : '';
123
+ return encodeURI(filePath) + postfix;
124
+ }
125
+
126
+ /**@target web */
127
+ const FS_PREFIX = `/@fs/`;
128
+ async function fileToUrl(id, config) {
129
+ let rtn;
130
+ if (id.startsWith(withTrailingSlash(config.root))) {
131
+ // in project root, infer short public path
132
+ rtn = '/' + path__namespace.posix.relative(config.root, id);
133
+ }
134
+ else {
135
+ // outside of project root, use absolute fs path
136
+ // (this is special handled by the serve static middleware
137
+ rtn = path__namespace.posix.join(FS_PREFIX, id);
138
+ }
139
+ const base = joinUrlSegments(config.server?.origin ?? '', config.base);
140
+ return joinUrlSegments(base, removeLeadingSlash(rtn));
141
+ }
142
+
143
+ /**@target web */
144
+ const needsEscapeRegEx = /[\n\r'\\\u2028\u2029]/;
145
+ const quoteNewlineRegEx = /([\n\r'\u2028\u2029])/g;
146
+ const backSlashRegEx = /\\/g;
147
+ function escapeId(id) {
148
+ if (!needsEscapeRegEx.test(id))
149
+ return id;
150
+ return id.replace(backSlashRegEx, '\\\\').replace(quoteNewlineRegEx, '\\$1');
151
+ }
152
+ const getResolveUrl = (path, URL = 'URL') => `new ${URL}(${path}).href`;
153
+ const getRelativeUrlFromDocument = (relativePath, umd = false) => getResolveUrl(`'${escapeId(partialEncodeURIPath(relativePath))}', ${umd ? `typeof document === 'undefined' ? location.href : ` : ''}document.currentScript && document.currentScript.src || document.baseURI`);
154
+ const getFileUrlFromFullPath = (path) => `require('u' + 'rl').pathToFileURL(${path}).href`;
155
+ const getFileUrlFromRelativePath = (path) => getFileUrlFromFullPath(`__dirname + '/${escapeId(path)}'`);
156
+ const relativeUrlMechanisms = {
157
+ amd: relativePath => {
158
+ if (relativePath[0] !== '.')
159
+ relativePath = './' + relativePath;
160
+ return getResolveUrl(`require.toUrl('${escapeId(relativePath)}'), document.baseURI`);
161
+ },
162
+ cjs: relativePath => `(typeof document === 'undefined' ? ${getFileUrlFromRelativePath(relativePath)} : ${getRelativeUrlFromDocument(relativePath)})`,
163
+ es: relativePath => getResolveUrl(`'${escapeId(partialEncodeURIPath(relativePath))}', import.meta.url`),
164
+ iife: relativePath => getRelativeUrlFromDocument(relativePath),
165
+ // NOTE: make sure rollup generate `module` params
166
+ system: relativePath => getResolveUrl(`'${escapeId(partialEncodeURIPath(relativePath))}', module.meta.url`),
167
+ umd: relativePath => `(typeof document === 'undefined' && typeof location === 'undefined' ? ${getFileUrlFromRelativePath(relativePath)} : ${getRelativeUrlFromDocument(relativePath, true)})`
168
+ };
169
+ const customRelativeUrlMechanisms = {
170
+ ...relativeUrlMechanisms,
171
+ 'worker-iife': relativePath => getResolveUrl(`'${escapeId(partialEncodeURIPath(relativePath))}', self.location.href`)
172
+ };
173
+ function createToImportMetaURLBasedRelativeRuntime(format, isWorker) {
174
+ const formatLong = isWorker && format === 'iife' ? 'worker-iife' : format;
175
+ const toRelativePath = customRelativeUrlMechanisms[formatLong];
176
+ return (filename, importer) => ({
177
+ runtime: toRelativePath(path__namespace.posix.relative(path__namespace.dirname(importer), filename))
178
+ });
179
+ }
180
+ function toOutputFilePathInJS(filename, type, hostId, hostType, config, toRelative) {
181
+ const { renderBuiltUrl } = config.experimental;
182
+ let relative = config.base === '' || config.base === './';
183
+ if (renderBuiltUrl) {
184
+ const result = renderBuiltUrl(filename, {
185
+ hostId,
186
+ hostType,
187
+ type,
188
+ ssr: !!config.build.ssr
189
+ });
190
+ if (typeof result === 'object') {
191
+ if (result.runtime) {
192
+ return { runtime: result.runtime };
193
+ }
194
+ if (typeof result.relative === 'boolean') {
195
+ relative = result.relative;
196
+ }
197
+ }
198
+ else if (result) {
199
+ return result;
200
+ }
201
+ }
202
+ if (relative && !config.build.ssr) {
203
+ return toRelative(filename, hostId);
204
+ }
205
+ return joinUrlSegments(config.base, filename);
206
+ }
207
+
208
+ /**@target web */
209
+ // index.ts for more details on contents and license of this file
210
+ // https://github.com/vitejs/vite/blob/b7ddfae5f852c2948fab03e94751ce56f5f31ce0/packages/vite/src/node/constants.ts#L143
211
+ const METADATA_FILENAME = '_metadata.json';
212
+ // https://github.com/vitejs/vite/blob/b7ddfae5f852c2948fab03e94751ce56f5f31ce0/packages/vite/src/node/constants.ts#L63
213
+ const ENV_PUBLIC_PATH = `/@vite/env`;
214
+
215
+ /**@target web */
216
+ // index.ts for more details on contents and license of this file
217
+ // https://github.com/vitejs/vite/blob/b7ddfae5f852c2948fab03e94751ce56f5f31ce0/packages/vite/src/node/fsUtils.ts#L388
218
+ function tryResolveRealFile(file, preserveSymlinks) {
219
+ const fileStat = tryStatSync(file);
220
+ if (fileStat?.isFile()) {
221
+ return file;
222
+ }
223
+ else if (fileStat?.isSymbolicLink()) {
224
+ return preserveSymlinks ? file : fs__namespace.realpathSync(file);
225
+ }
226
+ return undefined;
227
+ }
228
+
229
+ /**@target web */
230
+ // index.ts for more details on contents and license of this file
231
+ // https://github.com/vitejs/vite/blob/b7ddfae5f852c2948fab03e94751ce56f5f31ce0/packages/vite/src/node/plugins/resolve.ts#L534
232
+ function splitFileAndPostfix(path) {
233
+ const file = cleanUrl(path);
234
+ return { file, postfix: path.slice(file.length) };
235
+ }
236
+ // https://github.com/vitejs/vite/blob/b7ddfae5f852c2948fab03e94751ce56f5f31ce0/packages/vite/src/node/plugins/resolve.ts#L566-L574
237
+ function tryFsResolve(fsPath, preserveSymlinks) {
238
+ const { file, postfix } = splitFileAndPostfix(fsPath);
239
+ const res = tryCleanFsResolve(file, preserveSymlinks);
240
+ if (res)
241
+ return res + postfix;
242
+ return;
243
+ }
244
+ // https://github.com/vitejs/vite/blob/b7ddfae5f852c2948fab03e94751ce56f5f31ce0/packages/vite/src/node/plugins/resolve.ts#L580
245
+ function tryCleanFsResolve(file, preserveSymlinks) {
246
+ if (file.includes('node_modules')) {
247
+ return tryResolveRealFile(file, preserveSymlinks);
248
+ }
249
+ const normalizedResolved = tryResolveRealFile(vite.normalizePath(file));
250
+ if (!normalizedResolved) {
251
+ return tryResolveRealFile(file, preserveSymlinks);
252
+ }
253
+ return normalizedResolved;
254
+ }
255
+
256
+ /**@target web */
257
+ // index.ts for more details on contents and license of this file
258
+ // https://github.com/Danielku15/vite/blob/88b7def341f12d07d7d4f83cbe3dc73cc8c6b7be/packages/vite/src/node/optimizer/index.ts#L1356
259
+ function tryOptimizedDepResolve(config, ssr, url, depId, preserveSymlinks) {
260
+ const optimizer = getDepsOptimizer(config, ssr);
261
+ if (optimizer?.isOptimizedDepFile(depId)) {
262
+ const depFile = cleanUrl(depId);
263
+ const info = optimizedDepInfoFromFile(optimizer.metadata, depFile);
264
+ const depSrc = info?.src;
265
+ if (depSrc) {
266
+ const resolvedFile = path__namespace.resolve(path__namespace.dirname(depSrc), url);
267
+ return tryFsResolve(resolvedFile, preserveSymlinks);
268
+ }
269
+ }
270
+ return undefined;
271
+ }
272
+ // https://github.com/Danielku15/vite/blob/88b7def341f12d07d7d4f83cbe3dc73cc8c6b7be/packages/vite/src/node/optimizer/optimizer.ts#L32-L40
273
+ const depsOptimizerMap = new WeakMap();
274
+ const devSsrDepsOptimizerMap = new WeakMap();
275
+ function getDepsOptimizer(config, ssr) {
276
+ const map = ssr ? devSsrDepsOptimizerMap : depsOptimizerMap;
277
+ let optimizer = map.get(config);
278
+ if (!optimizer) {
279
+ optimizer = createDepsOptimizer(config);
280
+ map.set(config, optimizer);
281
+ }
282
+ return optimizer;
283
+ }
284
+ // https://github.com/vitejs/vite/blob/b7ddfae5f852c2948fab03e94751ce56f5f31ce0/packages/vite/src/node/optimizer/optimizer.ts#L79
285
+ function createDepsOptimizer(config) {
286
+ const depsCacheDirPrefix = vite.normalizePath(path__namespace.resolve(config.cacheDir, 'deps'));
287
+ const metadata = parseDepsOptimizerMetadata(fs__namespace.readFileSync(path__namespace.join(depsCacheDirPrefix, METADATA_FILENAME), 'utf8'), depsCacheDirPrefix);
288
+ const notImplemented = () => {
289
+ throw new Error('not implemented');
290
+ };
291
+ const depsOptimizer = {
292
+ metadata,
293
+ registerMissingImport: notImplemented,
294
+ run: notImplemented,
295
+ // https://github.com/vitejs/vite/blob/b7ddfae5f852c2948fab03e94751ce56f5f31ce0/packages/vite/src/node/optimizer/index.ts#L916
296
+ isOptimizedDepFile: id => id.startsWith(depsCacheDirPrefix),
297
+ isOptimizedDepUrl: notImplemented,
298
+ getOptimizedDepId: notImplemented,
299
+ close: notImplemented,
300
+ options: {}
301
+ };
302
+ return depsOptimizer;
303
+ }
304
+ // https://github.com/vitejs/vite/blob/b7ddfae5f852c2948fab03e94751ce56f5f31ce0/packages/vite/src/node/optimizer/index.ts#L944
305
+ function parseDepsOptimizerMetadata(jsonMetadata, depsCacheDir) {
306
+ const { hash, lockfileHash, configHash, browserHash, optimized, chunks } = JSON.parse(jsonMetadata, (key, value) => {
307
+ if (key === 'file' || key === 'src') {
308
+ return vite.normalizePath(path__namespace.resolve(depsCacheDir, value));
309
+ }
310
+ return value;
311
+ });
312
+ if (!chunks || Object.values(optimized).some(depInfo => !depInfo.fileHash)) {
313
+ // outdated _metadata.json version, ignore
314
+ return;
315
+ }
316
+ const metadata = {
317
+ hash,
318
+ lockfileHash,
319
+ configHash,
320
+ browserHash,
321
+ optimized: {},
322
+ discovered: {},
323
+ chunks: {},
324
+ depInfoList: []
325
+ };
326
+ for (const id of Object.keys(optimized)) {
327
+ addOptimizedDepInfo(metadata, 'optimized', {
328
+ ...optimized[id],
329
+ id,
330
+ browserHash
331
+ });
332
+ }
333
+ for (const id of Object.keys(chunks)) {
334
+ addOptimizedDepInfo(metadata, 'chunks', {
335
+ ...chunks[id],
336
+ id,
337
+ browserHash,
338
+ needsInterop: false
339
+ });
340
+ }
341
+ return metadata;
342
+ }
343
+ // https://github.com/vitejs/vite/blob/b7ddfae5f852c2948fab03e94751ce56f5f31ce0/packages/vite/src/node/optimizer/index.ts#L322
344
+ function addOptimizedDepInfo(metadata, type, depInfo) {
345
+ metadata[type][depInfo.id] = depInfo;
346
+ metadata.depInfoList.push(depInfo);
347
+ return depInfo;
348
+ }
349
+ // https://github.com/vitejs/vite/blob/b7ddfae5f852c2948fab03e94751ce56f5f31ce0/packages/vite/src/node/optimizer/index.ts#L1248
350
+ function optimizedDepInfoFromFile(metadata, file) {
351
+ return metadata.depInfoList.find(depInfo => depInfo.file === file);
352
+ }
353
+
354
+ /**@target web */
355
+ const workerCache = new WeakMap();
356
+ const WORKER_FILE_ID = 'alphatab_worker';
357
+ const WORKER_ASSET_ID = '__ALPHATAB_WORKER_ASSET__';
358
+ // https://github.com/vitejs/vite/blob/b7ddfae5f852c2948fab03e94751ce56f5f31ce0/packages/vite/src/node/plugins/worker.ts#L47
359
+ function saveEmitWorkerAsset(config, asset) {
360
+ const workerMap = workerCache.get(config.mainConfig || config);
361
+ workerMap.assets.set(asset.fileName, asset);
362
+ }
363
+ // https://github.com/vitejs/vite/blob/b7ddfae5f852c2948fab03e94751ce56f5f31ce0/packages/vite/src/node/plugins/worker.ts#L161
364
+ async function workerFileToUrl(config, id) {
365
+ const workerMap = workerCache.get(config.mainConfig || config);
366
+ let fileName = workerMap.bundle.get(id);
367
+ if (!fileName) {
368
+ const outputChunk = await bundleWorkerEntry(config, id);
369
+ fileName = outputChunk.fileName;
370
+ saveEmitWorkerAsset(config, {
371
+ fileName,
372
+ source: outputChunk.code
373
+ });
374
+ workerMap.bundle.set(id, fileName);
375
+ }
376
+ return encodeWorkerAssetFileName(fileName, workerMap);
377
+ }
378
+ // https://github.com/vitejs/vite/blob/b7ddfae5f852c2948fab03e94751ce56f5f31ce0/packages/vite/src/node/plugins/worker.ts#L149
379
+ function encodeWorkerAssetFileName(fileName, workerCache) {
380
+ const { fileNameHash } = workerCache;
381
+ const hash = getHash(fileName);
382
+ if (!fileNameHash.get(hash)) {
383
+ fileNameHash.set(hash, fileName);
384
+ }
385
+ return `${WORKER_ASSET_ID}${hash}__`;
386
+ }
387
+ // https://github.com/vitejs/vite/blob/b7ddfae5f852c2948fab03e94751ce56f5f31ce0/packages/vite/src/node/plugins/worker.ts#L55
388
+ async function bundleWorkerEntry(config, id) {
389
+ const input = cleanUrl(id);
390
+ const bundleChain = config.bundleChain ?? [];
391
+ const newBundleChain = [...bundleChain, input];
392
+ if (bundleChain.includes(input)) {
393
+ throw new Error('Circular worker imports detected. Vite does not support it. ' +
394
+ `Import chain: ${newBundleChain.join(' -> ')}`);
395
+ }
396
+ // bundle the file as entry to support imports
397
+ const { rollup } = await import('rollup');
398
+ const { plugins, rollupOptions, format } = config.worker;
399
+ const bundle = await rollup({
400
+ ...rollupOptions,
401
+ input,
402
+ plugins: await plugins(newBundleChain),
403
+ preserveEntrySignatures: false
404
+ });
405
+ let chunk;
406
+ try {
407
+ const workerOutputConfig = config.worker.rollupOptions.output;
408
+ const workerConfig = workerOutputConfig
409
+ ? Array.isArray(workerOutputConfig)
410
+ ? workerOutputConfig[0] || {}
411
+ : workerOutputConfig
412
+ : {};
413
+ const { output: [outputChunk, ...outputChunks] } = await bundle.generate({
414
+ entryFileNames: path__namespace.posix.join(config.build.assetsDir, '[name]-[hash].js'),
415
+ chunkFileNames: path__namespace.posix.join(config.build.assetsDir, '[name]-[hash].js'),
416
+ assetFileNames: path__namespace.posix.join(config.build.assetsDir, '[name]-[hash].[ext]'),
417
+ ...workerConfig,
418
+ format,
419
+ sourcemap: config.build.sourcemap
420
+ });
421
+ chunk = outputChunk;
422
+ outputChunks.forEach(outputChunk => {
423
+ if (outputChunk.type === 'asset') {
424
+ saveEmitWorkerAsset(config, outputChunk);
425
+ }
426
+ else if (outputChunk.type === 'chunk') {
427
+ saveEmitWorkerAsset(config, {
428
+ fileName: outputChunk.fileName,
429
+ source: outputChunk.code
430
+ });
431
+ }
432
+ });
433
+ }
434
+ finally {
435
+ await bundle.close();
436
+ }
437
+ return emitSourcemapForWorkerEntry(config, chunk);
438
+ }
439
+ // https://github.com/vitejs/vite/blob/b7ddfae5f852c2948fab03e94751ce56f5f31ce0/packages/vite/src/node/plugins/worker.ts#L124
440
+ function emitSourcemapForWorkerEntry(config, chunk) {
441
+ const { map: sourcemap } = chunk;
442
+ if (sourcemap) {
443
+ if (config.build.sourcemap === 'hidden' || config.build.sourcemap === true) {
444
+ const data = sourcemap.toString();
445
+ const mapFileName = chunk.fileName + '.map';
446
+ saveEmitWorkerAsset(config, {
447
+ fileName: mapFileName,
448
+ source: data
449
+ });
450
+ }
451
+ }
452
+ return chunk;
453
+ }
454
+ // https://github.com/vitejs/vite/blob/b7ddfae5f852c2948fab03e94751ce56f5f31ce0/packages/vite/src/node/plugins/worker.ts#L458
455
+ function isSameContent(a, b) {
456
+ if (typeof a === 'string') {
457
+ if (typeof b === 'string') {
458
+ return a === b;
459
+ }
460
+ return Buffer.from(a).equals(b);
461
+ }
462
+ return Buffer.from(b).equals(a);
463
+ }
464
+
465
+ /**@target web */
466
+ const alphaTabWorkerPatterns = [
467
+ ['alphaTabWorker', 'new URL', 'import.meta.url'],
468
+ ['alphaTabWorklet.addModule', 'new URL', 'import.meta.url']
469
+ ];
470
+ function includesAlphaTabWorker(code) {
471
+ for (const pattern of alphaTabWorkerPatterns) {
472
+ let position = 0;
473
+ for (const match of pattern) {
474
+ position = code.indexOf(match, position);
475
+ if (position === -1) {
476
+ break;
477
+ }
478
+ }
479
+ if (position !== -1) {
480
+ return true;
481
+ }
482
+ }
483
+ return false;
484
+ }
485
+ function getWorkerType(code, match) {
486
+ if (match[1].includes('.addModule')) {
487
+ return "audio_worklet" /* AlphaTabWorkerTypes.AudioWorklet */;
488
+ }
489
+ const endOfMatch = match.indices[0][1];
490
+ const startOfOptions = code.indexOf('{', endOfMatch);
491
+ if (startOfOptions === -1) {
492
+ return "worker_classic" /* AlphaTabWorkerTypes.WorkerClassic */;
493
+ }
494
+ const endOfOptions = code.indexOf('}', endOfMatch);
495
+ if (endOfOptions === -1) {
496
+ return "worker_classic" /* AlphaTabWorkerTypes.WorkerClassic */;
497
+ }
498
+ const endOfWorkerCreate = code.indexOf(')', endOfMatch);
499
+ if (startOfOptions > endOfWorkerCreate || endOfOptions > endOfWorkerCreate) {
500
+ return "worker_classic" /* AlphaTabWorkerTypes.WorkerClassic */;
501
+ }
502
+ let workerOptions = code.slice(startOfOptions, endOfOptions + 1);
503
+ try {
504
+ workerOptions = evalValue(workerOptions);
505
+ }
506
+ catch (e) {
507
+ return "worker_classic" /* AlphaTabWorkerTypes.WorkerClassic */;
508
+ }
509
+ if (typeof workerOptions === 'object' && workerOptions?.type === 'module') {
510
+ return "worker_module" /* AlphaTabWorkerTypes.WorkerModule */;
511
+ }
512
+ return "worker_classic" /* AlphaTabWorkerTypes.WorkerClassic */;
513
+ }
514
+ function importMetaUrlPlugin(options) {
515
+ let resolvedConfig;
516
+ let isBuild;
517
+ let preserveSymlinks;
518
+ const isWorkerActive = options.webWorkers !== false;
519
+ const isWorkletActive = options.audioWorklets !== false;
520
+ const isActive = isWorkerActive || isWorkletActive;
521
+ return {
522
+ name: 'vite-plugin-alphatab-url',
523
+ enforce: 'pre',
524
+ configResolved(config) {
525
+ resolvedConfig = config;
526
+ isBuild = config.command === 'build';
527
+ preserveSymlinks = config.resolve.preserveSymlinks;
528
+ },
529
+ shouldTransformCachedModule({ code }) {
530
+ if (isActive && isBuild && resolvedConfig.build.watch && includesAlphaTabWorker(code)) {
531
+ return true;
532
+ }
533
+ return;
534
+ },
535
+ async transform(code, id, options) {
536
+ if (!isActive || options?.ssr || !includesAlphaTabWorker(code)) {
537
+ return;
538
+ }
539
+ let s;
540
+ const alphaTabWorkerPattern = /\b(alphaTabWorker|alphaTabWorklet\.addModule)\s*\(\s*(new\s+URL\s*\(\s*('[^']+'|"[^"]+"|`[^`]+`)\s*,\s*import\.meta\.url\s*\))/dg;
541
+ let match;
542
+ while ((match = alphaTabWorkerPattern.exec(code))) {
543
+ const workerType = getWorkerType(code, match);
544
+ let typeActive = false;
545
+ switch (workerType) {
546
+ case "worker_classic" /* AlphaTabWorkerTypes.WorkerClassic */:
547
+ case "worker_module" /* AlphaTabWorkerTypes.WorkerModule */:
548
+ typeActive = isWorkerActive;
549
+ break;
550
+ case "audio_worklet" /* AlphaTabWorkerTypes.AudioWorklet */:
551
+ typeActive = isWorkletActive;
552
+ break;
553
+ }
554
+ if (!typeActive) {
555
+ continue;
556
+ }
557
+ s ?? (s = new MagicString(code));
558
+ const url = code.slice(match.indices[3][0] + 1, match.indices[3][1] - 1);
559
+ let file = path.resolve(path.dirname(id), url);
560
+ file =
561
+ tryFsResolve(file, preserveSymlinks) ??
562
+ tryOptimizedDepResolve(resolvedConfig, options?.ssr === true, url, id, preserveSymlinks) ??
563
+ file;
564
+ let builtUrl;
565
+ if (isBuild) {
566
+ builtUrl = await workerFileToUrl(resolvedConfig, file);
567
+ }
568
+ else {
569
+ builtUrl = await fileToUrl(cleanUrl(file), resolvedConfig);
570
+ builtUrl = injectQuery(builtUrl, `${WORKER_FILE_ID}&type=${workerType}`);
571
+ }
572
+ s.update(match.indices[3][0], match.indices[3][1],
573
+ // add `'' +` to skip vite:asset-import-meta-url plugin
574
+ `new URL('' + ${JSON.stringify(builtUrl)}, import.meta.url)`);
575
+ }
576
+ if (s) {
577
+ return {
578
+ code: s.toString(),
579
+ map: resolvedConfig.command === 'build' && resolvedConfig.build.sourcemap
580
+ ? s.generateMap({ hires: 'boundary', source: id })
581
+ : null
582
+ };
583
+ }
584
+ return null;
585
+ }
586
+ };
587
+ }
588
+
589
+ /**@target web */
590
+ function copyAssetsPlugin(options) {
591
+ let resolvedConfig;
592
+ let output = false;
593
+ return {
594
+ name: 'vite-plugin-alphatab-copy',
595
+ enforce: 'pre',
596
+ configResolved(config) {
597
+ resolvedConfig = config;
598
+ },
599
+ buildEnd() {
600
+ // reset for watch mode
601
+ output = false;
602
+ },
603
+ async buildStart() {
604
+ // run copy only once even if multiple bundles are generated
605
+ if (output) {
606
+ return;
607
+ }
608
+ output = true;
609
+ let alphaTabSourceDir = options.alphaTabSourceDir;
610
+ if (!alphaTabSourceDir) {
611
+ alphaTabSourceDir = path__namespace.join(resolvedConfig.root, 'node_modules/@coderline/alphatab/dist/');
612
+ }
613
+ if (!alphaTabSourceDir ||
614
+ !fs__namespace.promises.access(path__namespace.join(alphaTabSourceDir, 'alphaTab.mjs'), fs__namespace.constants.F_OK)) {
615
+ resolvedConfig.logger.error('Could not find alphaTab, please ensure it is installed into node_modules or configure alphaTabSourceDir');
616
+ return;
617
+ }
618
+ const outputPath = (options.assetOutputDir ?? resolvedConfig.publicDir);
619
+ if (!outputPath) {
620
+ return;
621
+ }
622
+ async function copyFiles(subdir) {
623
+ const fullDir = path__namespace.join(alphaTabSourceDir, subdir);
624
+ const files = await fs__namespace.promises.readdir(fullDir, {
625
+ withFileTypes: true
626
+ });
627
+ await fs__namespace.promises.mkdir(path__namespace.join(outputPath, subdir), {
628
+ recursive: true
629
+ });
630
+ await Promise.all(files
631
+ .filter(f => f.isFile())
632
+ .map(async (file) => {
633
+ const sourceFilename = path__namespace.join(file.path, file.name);
634
+ await fs__namespace.promises.copyFile(sourceFilename, path__namespace.join(outputPath, subdir, file.name));
635
+ }));
636
+ }
637
+ await Promise.all([copyFiles('font'), copyFiles('soundfont')]);
638
+ }
639
+ };
640
+ }
641
+
642
+ /**@target web */
643
+ const workerFileRE = new RegExp(`(?:\\?|&)${WORKER_FILE_ID}&type=(\\w+)(?:&|$)`);
644
+ const workerAssetUrlRE = new RegExp(`${WORKER_ASSET_ID}([a-z\\d]{8})__`, 'g');
645
+ function workerPlugin(options) {
646
+ let resolvedConfig;
647
+ let isBuild;
648
+ let isWorker;
649
+ const isWorkerActive = options.webWorkers !== false;
650
+ const isWorkletActive = options.audioWorklets !== false;
651
+ const isActive = isWorkerActive || isWorkletActive;
652
+ return {
653
+ name: 'vite-plugin-alphatab-worker',
654
+ configResolved(config) {
655
+ resolvedConfig = config;
656
+ isBuild = config.command === 'build';
657
+ isWorker = config.isWorker;
658
+ },
659
+ buildStart() {
660
+ if (!isActive || isWorker) {
661
+ return;
662
+ }
663
+ workerCache.set(resolvedConfig, {
664
+ assets: new Map(),
665
+ bundle: new Map(),
666
+ fileNameHash: new Map()
667
+ });
668
+ },
669
+ load(id) {
670
+ if (isActive && isBuild && id.includes(WORKER_FILE_ID)) {
671
+ return '';
672
+ }
673
+ return;
674
+ },
675
+ shouldTransformCachedModule({ id }) {
676
+ if (isActive && isBuild && resolvedConfig.build.watch && id.includes(WORKER_FILE_ID)) {
677
+ return true;
678
+ }
679
+ return;
680
+ },
681
+ async transform(raw, id) {
682
+ if (!isActive) {
683
+ return;
684
+ }
685
+ const match = workerFileRE.exec(id);
686
+ if (!match) {
687
+ return;
688
+ }
689
+ // inject env to worker file, might be needed by imported scripts
690
+ const envScriptPath = JSON.stringify(path__namespace.posix.join(resolvedConfig.base, ENV_PUBLIC_PATH));
691
+ const workerType = match[1];
692
+ let injectEnv = '';
693
+ switch (workerType) {
694
+ case "worker_classic" /* AlphaTabWorkerTypes.WorkerClassic */:
695
+ injectEnv = `importScripts(${envScriptPath})\n`;
696
+ break;
697
+ case "worker_module" /* AlphaTabWorkerTypes.WorkerModule */:
698
+ case "audio_worklet" /* AlphaTabWorkerTypes.AudioWorklet */:
699
+ injectEnv = `import ${envScriptPath}\n`;
700
+ break;
701
+ }
702
+ if (injectEnv) {
703
+ const s = new MagicString(raw);
704
+ s.prepend(injectEnv);
705
+ return {
706
+ code: s.toString(),
707
+ map: s.generateMap({ hires: 'boundary' })
708
+ };
709
+ }
710
+ return;
711
+ },
712
+ renderChunk(code, chunk, outputOptions) {
713
+ // when building the worker URLs are replaced with some placeholders
714
+ // here we replace those placeholders with the final file names respecting chunks
715
+ let s;
716
+ const result = () => {
717
+ return (s && {
718
+ code: s.toString(),
719
+ map: resolvedConfig.build.sourcemap ? s.generateMap({ hires: 'boundary' }) : null
720
+ });
721
+ };
722
+ workerAssetUrlRE.lastIndex = 0;
723
+ if (workerAssetUrlRE.test(code)) {
724
+ const toRelativeRuntime = createToImportMetaURLBasedRelativeRuntime(outputOptions.format, resolvedConfig.isWorker);
725
+ let match;
726
+ s = new MagicString(code);
727
+ workerAssetUrlRE.lastIndex = 0;
728
+ // Replace "__VITE_WORKER_ASSET__5aa0ddc0__" using relative paths
729
+ const workerMap = workerCache.get(resolvedConfig.mainConfig || resolvedConfig);
730
+ const { fileNameHash } = workerMap;
731
+ while ((match = workerAssetUrlRE.exec(code))) {
732
+ const [full, hash] = match;
733
+ const filename = fileNameHash.get(hash);
734
+ const replacement = toOutputFilePathInJS(filename, 'asset', chunk.fileName, 'js', resolvedConfig, toRelativeRuntime);
735
+ const replacementString = typeof replacement === 'string'
736
+ ? JSON.stringify(encodeURIPath(replacement)).slice(1, -1)
737
+ : `"+${replacement.runtime}+"`;
738
+ s.update(match.index, match.index + full.length, replacementString);
739
+ }
740
+ }
741
+ return result();
742
+ },
743
+ generateBundle(_, bundle) {
744
+ if (isWorker) {
745
+ return;
746
+ }
747
+ const workerMap = workerCache.get(resolvedConfig);
748
+ workerMap.assets.forEach(asset => {
749
+ const duplicateAsset = bundle[asset.fileName];
750
+ if (duplicateAsset) {
751
+ const content = duplicateAsset.type === 'asset' ? duplicateAsset.source : duplicateAsset.code;
752
+ // don't emit if the file name and the content is same
753
+ if (isSameContent(content, asset.source)) {
754
+ return;
755
+ }
756
+ }
757
+ this.emitFile({
758
+ type: 'asset',
759
+ fileName: asset.fileName,
760
+ source: asset.source
761
+ });
762
+ });
763
+ workerMap.assets.clear();
764
+ }
765
+ };
766
+ }
767
+
768
+ /**@target web */
769
+ function alphaTab(options) {
770
+ const plugins = [];
771
+ options ?? (options = {});
772
+ plugins.push(importMetaUrlPlugin(options));
773
+ plugins.push(workerPlugin(options));
774
+ plugins.push(copyAssetsPlugin(options));
775
+ return plugins;
776
+ }
777
+
778
+ /**@target web */
779
+
780
+ exports.alphaTab = alphaTab;
781
+ exports.default = alphaTab;
782
+ //# sourceMappingURL=alphaTab.vite.js.map