@coderline/alphatab 1.7.0-alpha.1529 → 1.7.0-alpha.1540

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