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