@coderline/alphatab 1.7.0-alpha.1527 → 1.7.0-alpha.1536

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.
@@ -1,749 +1,3 @@
1
- /*!
2
- * alphaTab v1.7.0-alpha.1527 (develop, build 1527)
3
- *
4
- * Copyright © 2025, 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
- * Integrated Libraries:
11
- *
12
- * Library: TinySoundFont
13
- * License: MIT
14
- * Copyright: Copyright (C) 2017, 2018 Bernhard Schelling
15
- * URL: https://github.com/schellingb/TinySoundFont
16
- * Purpose: SoundFont loading and Audio Synthesis
17
- *
18
- * Library: SFZero
19
- * License: MIT
20
- * Copyright: Copyright (C) 2012 Steve Folta ()
21
- * URL: https://github.com/stevefolta/SFZero
22
- * Purpose: TinySoundFont is based on SFZEro
23
- *
24
- * Library: Haxe Standard Library
25
- * License: MIT
26
- * Copyright: Copyright (C)2005-2025 Haxe Foundation
27
- * URL: https://github.com/HaxeFoundation/haxe/tree/development/std
28
- * Purpose: XML Parser & Zip Inflate Algorithm
29
- *
30
- * Library: SharpZipLib
31
- * License: MIT
32
- * Copyright: Copyright © 2000-2018 SharpZipLib Contributors
33
- * URL: https://github.com/icsharpcode/SharpZipLib
34
- * Purpose: Zip Deflate Algorithm for writing compressed Zips
35
- *
36
- * Library: NVorbis
37
- * License: MIT
38
- * Copyright: Copyright (c) 2020 Andrew Ward
39
- * URL: https://github.com/NVorbis/NVorbis
40
- * Purpose: Vorbis Stream Decoding
41
- *
42
- * Library: libvorbis
43
- * License: BSD-3-Clause
44
- * Copyright: Copyright (c) 2002-2020 Xiph.org Foundation
45
- * URL: https://github.com/xiph/vorbis
46
- * Purpose: NVorbis adopted some code from libvorbis.
47
- *
48
- * @preserve
49
- * @license
50
- */
51
-
52
- 'use strict';
53
-
54
- Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
55
-
56
- const fs = require('node:fs');
57
- const path = require('node:path');
58
- const url = require('node:url');
59
-
60
- function _interopNamespaceDefault(e) {
61
- const n = Object.create(null, { [Symbol.toStringTag]: { value: 'Module' } });
62
- if (e) {
63
- for (const k in e) {
64
- if (k !== 'default') {
65
- const d = Object.getOwnPropertyDescriptor(e, k);
66
- Object.defineProperty(n, k, d.get ? d : {
67
- enumerable: true,
68
- get: () => e[k]
69
- });
70
- }
71
- }
72
- }
73
- n.default = e;
74
- return Object.freeze(n);
75
- }
76
-
77
- const fs__namespace = /*#__PURE__*/_interopNamespaceDefault(fs);
78
- const path__namespace = /*#__PURE__*/_interopNamespaceDefault(path);
79
- const url__namespace = /*#__PURE__*/_interopNamespaceDefault(url);
80
-
81
- const JAVASCRIPT_MODULE_TYPE_AUTO = 'javascript/auto';
82
- const JAVASCRIPT_MODULE_TYPE_ESM = 'javascript/esm';
83
- function makeDependencySerializable(webPackWithAlphaTab, dependency, key) {
84
- webPackWithAlphaTab.webpack.util.serialization.register(dependency, key, null, {
85
- serialize(obj, context) {
86
- obj.serialize(context);
87
- },
88
- deserialize(context) {
89
- if (typeof dependency.deserialize === 'function') {
90
- return dependency.deserialize(context);
91
- }
92
- const obj = new dependency();
93
- obj.deserialize(context);
94
- return obj;
95
- }
96
- });
97
- }
98
- function tapJavaScript(normalModuleFactory, pluginName, parserPlugin) {
99
- normalModuleFactory.hooks.parser.for(JAVASCRIPT_MODULE_TYPE_AUTO).tap(pluginName, parserPlugin);
100
- normalModuleFactory.hooks.parser.for(JAVASCRIPT_MODULE_TYPE_ESM).tap(pluginName, parserPlugin);
101
- }
102
- function parseModuleUrl(parser, expr) {
103
- if (expr.type !== 'NewExpression' || expr.arguments.length !== 2) {
104
- return;
105
- }
106
- const newExpr = expr;
107
- const [arg1, arg2] = newExpr.arguments;
108
- const callee = parser.evaluateExpression(newExpr.callee);
109
- if (!callee.isIdentifier() || !callee.identifier.includes('alphaTabUrl')) {
110
- return;
111
- }
112
- const arg1Value = parser.evaluateExpression(arg1);
113
- return [arg1Value, [arg1.range[0], arg2.range[1]]];
114
- }
115
- const ALPHATAB_WORKER_RUNTIME_PREFIX = 'atworker_';
116
- function getWorkerRuntime(parser, compilation, cachedContextify, workerIndexMap) {
117
- const i = workerIndexMap.get(parser.state) || 0;
118
- workerIndexMap.set(parser.state, i + 1);
119
- const name = `${cachedContextify(parser.state.module.identifier())}|${i}`;
120
- const hash = compilation.compiler.webpack.util.createHash(compilation.outputOptions.hashFunction);
121
- hash.update(name);
122
- const digest = hash.digest(compilation.outputOptions.hashDigest);
123
- const runtime = digest.slice(0, compilation.outputOptions.hashDigestLength);
124
- return ALPHATAB_WORKER_RUNTIME_PREFIX + runtime;
125
- }
126
- function isWorkerRuntime(runtime) {
127
- if (typeof runtime !== 'string') {
128
- return false;
129
- }
130
- return runtime.startsWith(ALPHATAB_WORKER_RUNTIME_PREFIX);
131
- }
132
-
133
- /**@target web */
134
- function injectWorkerRuntimeModule(webPackWithAlphaTab) {
135
- class AlphaTabWorkerRuntimeModule extends webPackWithAlphaTab.webpack.RuntimeModule {
136
- constructor() {
137
- super('alphaTab audio worker chunk loading', webPackWithAlphaTab.webpack.RuntimeModule.STAGE_BASIC);
138
- }
139
- generate() {
140
- const compilation = this.compilation;
141
- const runtimeTemplate = compilation.runtimeTemplate;
142
- const globalObject = runtimeTemplate.globalObject;
143
- const chunkLoadingGlobalExpr = `${globalObject}[${JSON.stringify(compilation.outputOptions.chunkLoadingGlobal)}]`;
144
- const initialChunkIds = new Set(this.chunk.ids);
145
- for (const c of this.chunk.getAllInitialChunks()) {
146
- if (webPackWithAlphaTab.webpack.javascript.JavascriptModulesPlugin.chunkHasJs(c, this.chunkGraph)) {
147
- continue;
148
- }
149
- for (const id of c.ids) {
150
- initialChunkIds.add(id);
151
- }
152
- }
153
- return webPackWithAlphaTab.webpack.Template.asString([
154
- `if ( ! ('AudioWorkletGlobalScope' in ${globalObject}) ) { return; }`,
155
- 'const installedChunks = {',
156
- webPackWithAlphaTab.webpack.Template.indent(Array.from(initialChunkIds, id => `${JSON.stringify(id)}: 1`).join(',\n')),
157
- '};',
158
- '// importScripts chunk loading',
159
- `const installChunk = ${runtimeTemplate.basicFunction('data', [
160
- runtimeTemplate.destructureArray(['chunkIds', 'moreModules', 'runtime'], 'data'),
161
- 'for(const moduleId in moreModules) {',
162
- webPackWithAlphaTab.webpack.Template.indent([
163
- `if(${webPackWithAlphaTab.webpack.RuntimeGlobals.hasOwnProperty}(moreModules, moduleId)) {`,
164
- webPackWithAlphaTab.webpack.Template.indent(`${webPackWithAlphaTab.webpack.RuntimeGlobals.moduleFactories}[moduleId] = moreModules[moduleId];`),
165
- '}'
166
- ]),
167
- '}',
168
- `if(runtime) runtime(${webPackWithAlphaTab.webpack.RuntimeGlobals.require});`,
169
- 'while(chunkIds.length)',
170
- webPackWithAlphaTab.webpack.Template.indent('installedChunks[chunkIds.pop()] = 1;'),
171
- 'parentChunkLoadingFunction(data);'
172
- ])};`,
173
- `const chunkLoadingGlobal = ${chunkLoadingGlobalExpr} = ${chunkLoadingGlobalExpr} || [];`,
174
- 'const parentChunkLoadingFunction = chunkLoadingGlobal.push.bind(chunkLoadingGlobal);',
175
- 'chunkLoadingGlobal.forEach(installChunk);',
176
- 'chunkLoadingGlobal.push = installChunk;'
177
- ]);
178
- }
179
- }
180
- AlphaTabWorkerRuntimeModule.Key = 'AlphaTabWorkerRuntime';
181
- webPackWithAlphaTab.alphaTab.registerWebWorkerRuntimeModule = (pluginName, compilation) => {
182
- compilation.hooks.runtimeRequirementInTree
183
- .for(AlphaTabWorkerRuntimeModule.Key)
184
- .tap(pluginName, (chunk) => {
185
- compilation.addRuntimeModule(chunk, new AlphaTabWorkerRuntimeModule());
186
- });
187
- compilation.hooks.additionalChunkRuntimeRequirements.tap(pluginName, (chunk, runtimeRequirements) => {
188
- if (isWorkerRuntime(chunk.runtime)) {
189
- runtimeRequirements.add(webPackWithAlphaTab.webpack.RuntimeGlobals.moduleFactories);
190
- runtimeRequirements.add(webPackWithAlphaTab.alphaTab.WebWorkerRuntimeModuleKey);
191
- }
192
- });
193
- };
194
- webPackWithAlphaTab.alphaTab.WebWorkerRuntimeModuleKey = AlphaTabWorkerRuntimeModule.Key;
195
- }
196
-
197
- /**@target web */
198
- const AlphaTabWorkletSpecifierTag = Symbol('alphatab worklet specifier tag');
199
- const workletIndexMap = new WeakMap();
200
- /**
201
- * Configures the Audio Worklet aspects within webpack.
202
- * The counterpart which this plugin detects sits in alphaTab.main.ts
203
- * @param pluginName
204
- * @param options
205
- * @param compiler
206
- * @param compilation
207
- * @param normalModuleFactory
208
- * @param cachedContextify
209
- * @returns
210
- */
211
- function configureAudioWorklet(webPackWithAlphaTab, pluginName, options, compiler, compilation, normalModuleFactory, cachedContextify) {
212
- if (options.audioWorklets === false) {
213
- return;
214
- }
215
- webPackWithAlphaTab.alphaTab.registerWorkletDependency(compilation, normalModuleFactory);
216
- const handleAlphaTabWorklet = (parser, expr) => {
217
- const [arg1] = expr.arguments;
218
- const parsedUrl = parseModuleUrl(parser, arg1);
219
- if (!parsedUrl) {
220
- return;
221
- }
222
- const [url] = parsedUrl;
223
- if (!url.isString()) {
224
- return;
225
- }
226
- const runtime = getWorkerRuntime(parser, compilation, cachedContextify, workletIndexMap);
227
- const block = new webPackWithAlphaTab.webpack.AsyncDependenciesBlock({
228
- entryOptions: {
229
- chunkLoading: false,
230
- wasmLoading: false,
231
- runtime: runtime
232
- }
233
- });
234
- block.loc = expr.loc;
235
- const workletBootstrap = webPackWithAlphaTab.alphaTab.createWorkletDependency(url.string, [expr.range[0], expr.range[1]], compiler.options.output.workerPublicPath);
236
- workletBootstrap.loc = expr.loc;
237
- block.addDependency(workletBootstrap);
238
- parser.state.module.addBlock(block);
239
- return true;
240
- };
241
- const parserPlugin = (parser) => {
242
- const pattern = 'alphaTabWorklet';
243
- const itemMembers = 'addModule';
244
- parser.hooks.preDeclarator.tap(pluginName, (decl) => {
245
- if (decl.id.type === 'Identifier' && decl.id.name === pattern) {
246
- parser.tagVariable(decl.id.name, AlphaTabWorkletSpecifierTag);
247
- return true;
248
- }
249
- return;
250
- });
251
- parser.hooks.pattern.for(pattern).tap(pluginName, (pattern) => {
252
- parser.tagVariable(pattern.name, AlphaTabWorkletSpecifierTag);
253
- return true;
254
- });
255
- parser.hooks.callMemberChain
256
- .for(AlphaTabWorkletSpecifierTag)
257
- .tap(pluginName, (expression, members) => {
258
- if (itemMembers !== members.join('.')) {
259
- return;
260
- }
261
- return handleAlphaTabWorklet(parser, expression);
262
- });
263
- };
264
- tapJavaScript(normalModuleFactory, pluginName, parserPlugin);
265
- }
266
-
267
- /**@target web */
268
- const workerIndexMap = new WeakMap();
269
- /**
270
- * Configures the WebWorker aspects within webpack.
271
- * The counterpart which this plugin detects sits in alphaTab.main.ts
272
- * @param pluginName
273
- * @param options
274
- * @param compiler
275
- * @param compilation
276
- * @param normalModuleFactory
277
- * @param cachedContextify
278
- * @returns
279
- */
280
- function configureWebWorker(webPackWithAlphaTab, pluginName, options, compiler, compilation, normalModuleFactory, cachedContextify) {
281
- if (options.audioWorklets === false) {
282
- return;
283
- }
284
- webPackWithAlphaTab.alphaTab.registerWebWorkerDependency(compilation, normalModuleFactory);
285
- new webPackWithAlphaTab.webpack.javascript.EnableChunkLoadingPlugin('import-scripts').apply(compiler);
286
- const handleAlphaTabWorker = (parser, expr) => {
287
- const [arg1, arg2] = expr.arguments;
288
- const parsedUrl = parseModuleUrl(parser, arg1);
289
- if (!parsedUrl) {
290
- return;
291
- }
292
- const [url, range] = parsedUrl;
293
- if (!url.isString()) {
294
- return;
295
- }
296
- const runtime = getWorkerRuntime(parser, compilation, cachedContextify, workerIndexMap);
297
- const block = new webPackWithAlphaTab.webpack.AsyncDependenciesBlock({
298
- entryOptions: {
299
- chunkLoading: 'import-scripts',
300
- wasmLoading: false,
301
- runtime: runtime
302
- }
303
- });
304
- block.loc = expr.loc;
305
- const workletBootstrap = webPackWithAlphaTab.alphaTab.createWebWorkerDependency(url.string, range, compiler.options.output.workerPublicPath);
306
- workletBootstrap.loc = expr.loc;
307
- block.addDependency(workletBootstrap);
308
- parser.state.module.addBlock(block);
309
- const dep1 = new webPackWithAlphaTab.webpack.dependencies.ConstDependency(`{ type: ${compilation.options.output.module ? '"module"' : 'undefined'} }`, arg2.range);
310
- dep1.loc = expr.loc;
311
- parser.state.module.addPresentationalDependency(dep1);
312
- parser.walkExpression(expr.callee);
313
- parser.walkExpression(arg1.callee);
314
- return true;
315
- };
316
- const parserPlugin = (parser) => {
317
- parser.hooks.new
318
- .for('alphaTab.Environment.alphaTabWorker')
319
- .tap(pluginName, (expr) => handleAlphaTabWorker(parser, expr));
320
- };
321
- tapJavaScript(normalModuleFactory, pluginName, parserPlugin);
322
- }
323
-
324
- /**@target web */
325
- function injectWebWorkerDependency(webPackWithAlphaTab) {
326
- class AlphaTabWebWorkerDependency extends webPackWithAlphaTab.webpack.dependencies.ModuleDependency {
327
- constructor(request, range, publicPath) {
328
- super(request);
329
- this.range = range;
330
- this.publicPath = publicPath;
331
- }
332
- getReferencedExports() {
333
- return webPackWithAlphaTab.webpack.Dependency.NO_EXPORTS_REFERENCED;
334
- }
335
- get type() {
336
- return 'alphaTabWorker';
337
- }
338
- get category() {
339
- return 'worker';
340
- }
341
- updateHash(hash) {
342
- if (this._hashUpdate === undefined) {
343
- this._hashUpdate = JSON.stringify(this.publicPath);
344
- }
345
- hash.update(this._hashUpdate);
346
- }
347
- serialize(context) {
348
- const { write } = context;
349
- write(this.publicPath);
350
- super.serialize(context);
351
- }
352
- deserialize(context) {
353
- const { read } = context;
354
- this.publicPath = read();
355
- super.deserialize(context);
356
- }
357
- }
358
- AlphaTabWebWorkerDependency.Template = class WorkerDependencyTemplate extends (webPackWithAlphaTab.webpack.dependencies.ModuleDependency.Template) {
359
- apply(dependency, source, templateContext) {
360
- const { chunkGraph, moduleGraph, runtimeRequirements } = templateContext;
361
- const dep = dependency;
362
- const block = moduleGraph.getParentBlock(dependency);
363
- const entrypoint = chunkGraph.getBlockChunkGroup(block);
364
- const chunk = entrypoint.getEntrypointChunk();
365
- // We use the workerPublicPath option if provided, else we fallback to the RuntimeGlobal publicPath
366
- const workerImportBaseUrl = dep.publicPath
367
- ? `"${dep.publicPath}"`
368
- : webPackWithAlphaTab.webpack.RuntimeGlobals.publicPath;
369
- runtimeRequirements.add(webPackWithAlphaTab.webpack.RuntimeGlobals.publicPath);
370
- runtimeRequirements.add(webPackWithAlphaTab.webpack.RuntimeGlobals.baseURI);
371
- runtimeRequirements.add(webPackWithAlphaTab.webpack.RuntimeGlobals.getChunkScriptFilename);
372
- source.replace(dep.range[0], dep.range[1] - 1, `/* worker import */ ${workerImportBaseUrl} + ${webPackWithAlphaTab.webpack.RuntimeGlobals.getChunkScriptFilename}(${JSON.stringify(chunk.id)}), ${webPackWithAlphaTab.webpack.RuntimeGlobals.baseURI}`);
373
- }
374
- };
375
- makeDependencySerializable(webPackWithAlphaTab, AlphaTabWebWorkerDependency, 'AlphaTabWebWorkerDependency');
376
- webPackWithAlphaTab.alphaTab.createWebWorkerDependency = (request, range, publicPath) => new AlphaTabWebWorkerDependency(request, range, publicPath);
377
- webPackWithAlphaTab.alphaTab.registerWebWorkerDependency = (compilation, normalModuleFactory) => {
378
- compilation.dependencyFactories.set(AlphaTabWebWorkerDependency, normalModuleFactory);
379
- compilation.dependencyTemplates.set(AlphaTabWebWorkerDependency, new AlphaTabWebWorkerDependency.Template());
380
- };
381
- }
382
-
383
- /**@target web */
384
- function injectWorkletRuntimeModule(webPackWithAlphaTab) {
385
- class AlphaTabWorkletStartRuntimeModule extends webPackWithAlphaTab.webpack.RuntimeModule {
386
- constructor() {
387
- super('alphaTab audio worklet chunk lookup', webPackWithAlphaTab.webpack.RuntimeModule.STAGE_BASIC);
388
- }
389
- generate() {
390
- const compilation = this.compilation;
391
- const workletChunkLookup = new Map();
392
- const allChunks = compilation.chunks;
393
- for (const chunk of allChunks) {
394
- const isWorkletEntry = isWorkerRuntime(chunk.runtime);
395
- if (isWorkletEntry) {
396
- const workletChunks = Array.from(chunk.getAllReferencedChunks()).map(c => {
397
- // force content chunk to be created
398
- compilation.hooks.contentHash.call(c);
399
- return compilation.getPath(webPackWithAlphaTab.webpack.javascript.JavascriptModulesPlugin.getChunkFilenameTemplate(c, compilation.outputOptions), {
400
- chunk: c,
401
- contentHashType: 'javascript'
402
- });
403
- });
404
- workletChunkLookup.set(String(chunk.id), workletChunks);
405
- }
406
- }
407
- return webPackWithAlphaTab.webpack.Template.asString([
408
- `${AlphaTabWorkletStartRuntimeModule.RuntimeGlobalWorkletGetStartupChunks} = (() => {`,
409
- webPackWithAlphaTab.webpack.Template.indent([
410
- 'const lookup = new Map(',
411
- webPackWithAlphaTab.webpack.Template.indent(JSON.stringify(Array.from(workletChunkLookup.entries()))),
412
- ');',
413
- 'return (chunkId) => lookup.get(String(chunkId)) ?? [];'
414
- ]),
415
- '})();'
416
- ]);
417
- }
418
- }
419
- AlphaTabWorkletStartRuntimeModule.RuntimeGlobalWorkletGetStartupChunks = '__webpack_require__.wsc';
420
- webPackWithAlphaTab.alphaTab.RuntimeGlobalWorkletGetStartupChunks =
421
- AlphaTabWorkletStartRuntimeModule.RuntimeGlobalWorkletGetStartupChunks;
422
- webPackWithAlphaTab.alphaTab.registerWorkletRuntimeModule = (pluginName, compilation) => {
423
- compilation.hooks.runtimeRequirementInTree
424
- .for(AlphaTabWorkletStartRuntimeModule.RuntimeGlobalWorkletGetStartupChunks)
425
- .tap(pluginName, (chunk) => {
426
- compilation.addRuntimeModule(chunk, new AlphaTabWorkletStartRuntimeModule());
427
- });
428
- };
429
- }
430
-
431
- /**@target web */
432
- function injectWorkletDependency(webPackWithAlphaTab) {
433
- /**
434
- * This module dependency injects the relevant code into a worklet bootstrap script
435
- * to install chunks which have been added to the worklet via addModule before the bootstrap script starts.
436
- */
437
- class AlphaTabWorkletDependency extends webPackWithAlphaTab.webpack.dependencies.ModuleDependency {
438
- constructor(url, range, publicPath) {
439
- super(url);
440
- this.range = range;
441
- this.publicPath = publicPath;
442
- }
443
- get type() {
444
- return 'alphaTabWorklet';
445
- }
446
- get category() {
447
- return 'worker';
448
- }
449
- updateHash(hash) {
450
- if (this._hashUpdate === undefined) {
451
- this._hashUpdate = JSON.stringify(this.publicPath);
452
- }
453
- hash.update(this._hashUpdate);
454
- }
455
- serialize(context) {
456
- const { write } = context;
457
- write(this.publicPath);
458
- super.serialize(context);
459
- }
460
- deserialize(context) {
461
- const { read } = context;
462
- this.publicPath = read();
463
- super.deserialize(context);
464
- }
465
- }
466
- AlphaTabWorkletDependency.Template = class AlphaTabWorkletDependencyTemplate extends (webPackWithAlphaTab.webpack.dependencies.ModuleDependency.Template) {
467
- apply(dependency, source, templateContext) {
468
- const { chunkGraph, moduleGraph, runtimeRequirements } = templateContext;
469
- const dep = dependency;
470
- const block = moduleGraph.getParentBlock(dependency);
471
- const entrypoint = chunkGraph.getBlockChunkGroup(block);
472
- const workletImportBaseUrl = dep.publicPath
473
- ? JSON.stringify(dep.publicPath)
474
- : webPackWithAlphaTab.webpack.RuntimeGlobals.publicPath;
475
- const chunk = entrypoint.getEntrypointChunk();
476
- // worklet global scope has no 'self', need to inject it for compatibility with chunks
477
- // some plugins like the auto public path need to right location. we pass this on from the main runtime
478
- // some plugins rely on importScripts to be defined.
479
- const workletInlineBootstrap = `
480
- globalThis.self = globalThis.self || globalThis;
481
- globalThis.location = \${JSON.stringify(${webPackWithAlphaTab.webpack.RuntimeGlobals.baseURI})};
482
- globalThis.importScripts = (url) => { throw new Error("importScripts not available, dynamic loading of chunks not supported in this context", url) };
483
- `;
484
- chunkGraph.addChunkRuntimeRequirements(chunk, new Set([
485
- webPackWithAlphaTab.webpack.RuntimeGlobals.moduleFactories,
486
- webPackWithAlphaTab.alphaTab.WebWorkerRuntimeModuleKey
487
- ]));
488
- runtimeRequirements.add(webPackWithAlphaTab.alphaTab.RuntimeGlobalWorkletGetStartupChunks);
489
- source.replace(dep.range[0], dep.range[1] - 1, webPackWithAlphaTab.webpack.Template.asString([
490
- '(/* worklet bootstrap */ async function(__webpack_worklet__) {',
491
- webPackWithAlphaTab.webpack.Template.indent([
492
- `await __webpack_worklet__.addModule(URL.createObjectURL(new Blob([\`${workletInlineBootstrap}\`], { type: "application/javascript; charset=utf-8" })));`,
493
- `for (const fileName of ${webPackWithAlphaTab.alphaTab.RuntimeGlobalWorkletGetStartupChunks}(${JSON.stringify(chunk.id)})) {`,
494
- webPackWithAlphaTab.webpack.Template.indent([
495
- `await __webpack_worklet__.addModule(new URL(${workletImportBaseUrl} + fileName, ${webPackWithAlphaTab.webpack.RuntimeGlobals.baseURI}));`
496
- ]),
497
- '}'
498
- ]),
499
- '})(alphaTabWorklet)'
500
- ]));
501
- }
502
- };
503
- makeDependencySerializable(webPackWithAlphaTab, AlphaTabWorkletDependency, 'AlphaTabWorkletDependency');
504
- webPackWithAlphaTab.alphaTab.registerWorkletDependency = (compilation, normalModuleFactory) => {
505
- compilation.dependencyFactories.set(AlphaTabWorkletDependency, normalModuleFactory);
506
- compilation.dependencyTemplates.set(AlphaTabWorkletDependency, new AlphaTabWorkletDependency.Template());
507
- };
508
- webPackWithAlphaTab.alphaTab.createWorkletDependency = (request, range, publicPath) => new AlphaTabWorkletDependency(request, range, publicPath);
509
- }
510
-
511
- /**@target web */
512
- const WINDOWS_ABS_PATH_REGEXP = /^[a-zA-Z]:[\\/]/;
513
- const WINDOWS_PATH_SEPARATOR_REGEXP = /\\/g;
514
- const relativePathToRequest = (relativePath) => {
515
- if (relativePath === '') {
516
- return '@src/webpack/.';
517
- }
518
- if (relativePath === '..') {
519
- return '../.';
520
- }
521
- if (relativePath.startsWith('../')) {
522
- return relativePath;
523
- }
524
- return `./${relativePath}`;
525
- };
526
- const absoluteToRequest = (context, maybeAbsolutePath) => {
527
- if (maybeAbsolutePath[0] === '/') {
528
- if (maybeAbsolutePath.length > 1 && maybeAbsolutePath[maybeAbsolutePath.length - 1] === '/') {
529
- // this 'path' is actually a regexp generated by dynamic requires.
530
- // Don't treat it as an absolute path.
531
- return maybeAbsolutePath;
532
- }
533
- const querySplitPos = maybeAbsolutePath.indexOf('?');
534
- let resource = querySplitPos === -1 ? maybeAbsolutePath : maybeAbsolutePath.slice(0, querySplitPos);
535
- resource = relativePathToRequest(path__namespace.posix.relative(context, resource));
536
- return querySplitPos === -1 ? resource : resource + maybeAbsolutePath.slice(querySplitPos);
537
- }
538
- if (WINDOWS_ABS_PATH_REGEXP.test(maybeAbsolutePath)) {
539
- const querySplitPos = maybeAbsolutePath.indexOf('?');
540
- let resource = querySplitPos === -1 ? maybeAbsolutePath : maybeAbsolutePath.slice(0, querySplitPos);
541
- resource = path__namespace.win32.relative(context, resource);
542
- if (!WINDOWS_ABS_PATH_REGEXP.test(resource)) {
543
- resource = relativePathToRequest(resource.replace(WINDOWS_PATH_SEPARATOR_REGEXP, '/'));
544
- }
545
- return querySplitPos === -1 ? resource : resource + maybeAbsolutePath.slice(querySplitPos);
546
- }
547
- // not an absolute path
548
- return maybeAbsolutePath;
549
- };
550
- const _contextify = (context, request) => {
551
- return request
552
- .split('!')
553
- .map(r => absoluteToRequest(context, r))
554
- .join('!');
555
- };
556
- const makeCacheableWithContext = (fn) => {
557
- const cache = new WeakMap();
558
- const cachedFn = (context, identifier, associatedObjectForCache) => {
559
- if (!associatedObjectForCache) {
560
- return fn(context, identifier);
561
- }
562
- let innerCache = cache.get(associatedObjectForCache);
563
- if (innerCache === undefined) {
564
- innerCache = new Map();
565
- cache.set(associatedObjectForCache, innerCache);
566
- }
567
- let cachedResult;
568
- let innerSubCache = innerCache.get(context);
569
- if (innerSubCache === undefined) {
570
- innerSubCache = new Map();
571
- innerCache.set(context, innerSubCache);
572
- }
573
- else {
574
- cachedResult = innerSubCache.get(identifier);
575
- }
576
- if (cachedResult !== undefined) {
577
- return cachedResult;
578
- }
579
- const result = fn(context, identifier);
580
- innerSubCache.set(identifier, result);
581
- return result;
582
- };
583
- cachedFn.bindContextCache = (context, associatedObjectForCache) => {
584
- let innerSubCache;
585
- if (associatedObjectForCache) {
586
- let innerCache = cache.get(associatedObjectForCache);
587
- if (innerCache === undefined) {
588
- innerCache = new Map();
589
- cache.set(associatedObjectForCache, innerCache);
590
- }
591
- innerSubCache = innerCache.get(context);
592
- if (innerSubCache === undefined) {
593
- innerSubCache = new Map();
594
- innerCache.set(context, innerSubCache);
595
- }
596
- }
597
- else {
598
- innerSubCache = new Map();
599
- }
600
- const boundFn = (identifier) => {
601
- const cachedResult = innerSubCache.get(identifier);
602
- if (cachedResult !== undefined) {
603
- return cachedResult;
604
- }
605
- const result = fn(context, identifier);
606
- innerSubCache.set(identifier, result);
607
- return result;
608
- };
609
- return boundFn;
610
- };
611
- return cachedFn;
612
- };
613
- const contextify = makeCacheableWithContext(_contextify);
614
- class AlphaTabWebPackPlugin {
615
- constructor(options) {
616
- this.options = options ?? {};
617
- }
618
- apply(compiler) {
619
- // here we create all plugin related class implementations using
620
- // the webpack instance provided to this plugin (not as global import)
621
- // after that we use the helper and factory functions we add to webpack
622
- const webPackWithAlphaTab = {
623
- webpack: compiler.webpack,
624
- alphaTab: {}
625
- };
626
- if ('alphaTab' in compiler.webpack.util.serialization.register) {
627
- // prevent multi registration
628
- webPackWithAlphaTab.alphaTab = compiler.webpack.util.serialization.register.alphaTab;
629
- }
630
- else {
631
- compiler.webpack.util.serialization.register.alphaTab = webPackWithAlphaTab.alphaTab;
632
- injectWebWorkerDependency(webPackWithAlphaTab);
633
- injectWorkerRuntimeModule(webPackWithAlphaTab);
634
- injectWorkletDependency(webPackWithAlphaTab);
635
- injectWorkletRuntimeModule(webPackWithAlphaTab);
636
- }
637
- this._webPackWithAlphaTab = webPackWithAlphaTab;
638
- this.configureSoundFont(compiler);
639
- this.configure(compiler);
640
- }
641
- configureSoundFont(compiler) {
642
- if (this.options.assetOutputDir === false) {
643
- return;
644
- }
645
- // register soundfont as resource
646
- compiler.options.module.rules.push({
647
- test: /\.sf2/,
648
- type: 'asset/resource'
649
- });
650
- compiler.options.module.rules.push({
651
- test: /\.sf3/,
652
- type: 'asset/resource'
653
- });
654
- }
655
- configure(compiler) {
656
- const pluginName = this.constructor.name;
657
- const cachedContextify = contextify.bindContextCache(compiler.context, compiler.root);
658
- compiler.hooks.thisCompilation.tap(pluginName, (compilation, { normalModuleFactory }) => {
659
- this._webPackWithAlphaTab.alphaTab.registerWebWorkerRuntimeModule(pluginName, compilation);
660
- this._webPackWithAlphaTab.alphaTab.registerWorkletRuntimeModule(pluginName, compilation);
661
- configureAudioWorklet(this._webPackWithAlphaTab, pluginName, this.options, compiler, compilation, normalModuleFactory, cachedContextify);
662
- configureWebWorker(this._webPackWithAlphaTab, pluginName, this.options, compiler, compilation, normalModuleFactory, cachedContextify);
663
- this.configureAssetCopy(this._webPackWithAlphaTab, pluginName, compiler, compilation);
664
- });
665
- }
666
- configureAssetCopy(webPackWithAlphaTab, pluginName, compiler, compilation) {
667
- if (this.options.assetOutputDir === false) {
668
- return;
669
- }
670
- const options = this.options;
671
- compilation.hooks.processAssets.tapAsync({
672
- name: pluginName,
673
- stage: this._webPackWithAlphaTab.webpack.Compilation.PROCESS_ASSETS_STAGE_ADDITIONAL
674
- }, async (_, callback) => {
675
- let alphaTabSourceDir = options.alphaTabSourceDir;
676
- if (!alphaTabSourceDir) {
677
- try {
678
- const isEsm = typeof {} === 'string';
679
- if (isEsm) {
680
- alphaTabSourceDir = url__namespace.fileURLToPath({}('@coderline/alphatab'));
681
- }
682
- else {
683
- alphaTabSourceDir = require.resolve('@coderline/alphatab');
684
- }
685
- alphaTabSourceDir = path__namespace.resolve(alphaTabSourceDir, '..');
686
- }
687
- catch {
688
- alphaTabSourceDir = compilation.getPath('node_modules/@coderline/alphatab/dist/');
689
- }
690
- }
691
- let isValidAlphaTabSourceDir;
692
- if (alphaTabSourceDir) {
693
- try {
694
- await fs__namespace.promises.access(path__namespace.join(alphaTabSourceDir, 'alphaTab.mjs'), fs__namespace.constants.F_OK);
695
- isValidAlphaTabSourceDir = true;
696
- }
697
- catch {
698
- isValidAlphaTabSourceDir = false;
699
- }
700
- }
701
- else {
702
- isValidAlphaTabSourceDir = false;
703
- }
704
- if (!isValidAlphaTabSourceDir) {
705
- compilation.errors.push(new this._webPackWithAlphaTab.webpack.WebpackError('Could not find alphaTab, please ensure it is installed into node_modules or configure alphaTabSourceDir'));
706
- return;
707
- }
708
- const outputPath = (options.assetOutputDir ?? compiler.options.output.path);
709
- if (!outputPath) {
710
- compilation.errors.push(new this._webPackWithAlphaTab.webpack.WebpackError('Need output.path configured in application to store asset files.'));
711
- return;
712
- }
713
- async function copyFiles(subdir) {
714
- const fullDir = path__namespace.join(alphaTabSourceDir, subdir);
715
- compilation.contextDependencies.add(path__namespace.normalize(fullDir));
716
- const files = await fs__namespace.promises.readdir(fullDir, { withFileTypes: true });
717
- await fs__namespace.promises.mkdir(path__namespace.join(outputPath, subdir), { recursive: true });
718
- await Promise.all(files
719
- .filter(f => f.isFile())
720
- .map(async (file) => {
721
- // node v20.12.0 has parentPath pointing to the path (not the file)
722
- // see https://github.com/nodejs/node/pull/50976
723
- const sourceFilename = path__namespace.join(file.parentPath ?? file.path, file.name);
724
- await fs__namespace.promises.copyFile(sourceFilename, path__namespace.join(outputPath, subdir, file.name));
725
- const assetFileName = `${subdir}/${file.name}`;
726
- const existingAsset = compilation.getAsset(assetFileName);
727
- const data = await fs__namespace.promises.readFile(sourceFilename);
728
- const source = new webPackWithAlphaTab.webpack.sources.RawSource(data);
729
- if (existingAsset) {
730
- compilation.updateAsset(assetFileName, source, {
731
- copied: true,
732
- sourceFilename
733
- });
734
- }
735
- else {
736
- compilation.emitAsset(assetFileName, source, {
737
- copied: true,
738
- sourceFilename
739
- });
740
- }
741
- }));
742
- }
743
- await Promise.all([copyFiles('font'), copyFiles('soundfont')]);
744
- callback();
745
- });
746
- }
747
- }
748
-
749
- exports.AlphaTabWebPackPlugin = AlphaTabWebPackPlugin;
1
+ const plugin = require('./alphaTab.webpack.core.js');
2
+ console.warn('[alphaTab] The use of alphaTab.webpack.js via @coderline/alphatab is deprecated. Please use the new @coderline/alphatab-webpack npm package.');
3
+ module.exports = plugin;