@coderline/alphatab-vite 1.7.0-alpha.1627 → 1.7.0-alpha.1629

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,5 +1,5 @@
1
1
  /*!
2
- * alphaTab Vite Plugin v1.7.0-alpha.1627 (develop, build 1627)
2
+ * alphaTab Vite Plugin v1.7.0-alpha.1629 (develop, build 1629)
3
3
  *
4
4
  * Copyright © 2025, Daniel Kuschny and Contributors, All rights reserved.
5
5
  *
@@ -0,0 +1,207 @@
1
+ /*!
2
+ * alphaTab Vite Plugin v1.7.0-alpha.1629 (develop, build 1629)
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
+ * This library uses code from Vite (https://github.com/vitejs/vite/), licensed under:
11
+ *
12
+ * MIT License
13
+ * Copyright (c) 2019-present, Yuxi (Evan) You and Vite contributors
14
+ *
15
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
16
+ * of this software and associated documentation files (the "Software"), to deal
17
+ * in the Software without restriction, including without limitation the rights
18
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
19
+ * copies of the Software, and to permit persons to whom the Software is
20
+ * furnished to do so, subject to the following conditions:
21
+ *
22
+ * The above copyright notice and this permission notice shall be included in all
23
+ * copies or substantial portions of the Software.
24
+ *
25
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
26
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
27
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
28
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
29
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
30
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
31
+ * SOFTWARE.
32
+ *
33
+ * @preserve
34
+ * @license
35
+ */
36
+
37
+ 'use strict';
38
+
39
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
40
+
41
+ const bridge_utils = require('./utils.cjs');
42
+ const path = require('node:path');
43
+ const vite = require('vite');
44
+ const bridge_build = require('./build.cjs');
45
+
46
+ function _interopNamespaceDefault(e) {
47
+ const n = Object.create(null, { [Symbol.toStringTag]: { value: 'Module' } });
48
+ if (e) {
49
+ for (const k in e) {
50
+ if (k !== 'default') {
51
+ const d = Object.getOwnPropertyDescriptor(e, k);
52
+ Object.defineProperty(n, k, d.get ? d : {
53
+ enumerable: true,
54
+ get: () => e[k]
55
+ });
56
+ }
57
+ }
58
+ }
59
+ n.default = e;
60
+ return Object.freeze(n);
61
+ }
62
+
63
+ const path__namespace = /*#__PURE__*/_interopNamespaceDefault(path);
64
+
65
+ // index.ts for more details on contents and license of this file
66
+ /**
67
+ * @internal
68
+ */
69
+ // biome-ignore lint/suspicious/noConstEnum: Exception where we use them
70
+ exports.AlphaTabWorkerTypes = void 0;
71
+ (function (AlphaTabWorkerTypes) {
72
+ AlphaTabWorkerTypes["WorkerClassic"] = "worker_classic";
73
+ AlphaTabWorkerTypes["WorkerModule"] = "worker_module";
74
+ AlphaTabWorkerTypes["AudioWorklet"] = "audio_worklet";
75
+ })(exports.AlphaTabWorkerTypes || (exports.AlphaTabWorkerTypes = {}));
76
+ /**
77
+ * @internal
78
+ */
79
+ const workerCache = new WeakMap();
80
+ /**
81
+ * @internal
82
+ */
83
+ const WORKER_FILE_ID = 'alphatab_worker';
84
+ /**
85
+ * @internal
86
+ */
87
+ const WORKER_ASSET_ID = '__ALPHATAB_WORKER_ASSET__';
88
+ // https://github.com/vitejs/vite/blob/b7ddfae5f852c2948fab03e94751ce56f5f31ce0/packages/vite/src/node/plugins/worker.ts#L47
89
+ function saveEmitWorkerAsset(config, asset) {
90
+ const workerMap = workerCache.get(config.mainConfig || config);
91
+ workerMap.assets.set(asset.fileName, asset);
92
+ }
93
+ // https://github.com/vitejs/vite/blob/b7ddfae5f852c2948fab03e94751ce56f5f31ce0/packages/vite/src/node/plugins/worker.ts#L161
94
+ /**
95
+ * @internal
96
+ */
97
+ async function workerFileToUrl(config, id) {
98
+ const workerMap = workerCache.get(config.mainConfig || config);
99
+ let fileName = workerMap.bundle.get(id);
100
+ if (!fileName) {
101
+ const outputChunk = await bundleWorkerEntry(config, id);
102
+ fileName = outputChunk.fileName;
103
+ saveEmitWorkerAsset(config, {
104
+ fileName,
105
+ source: outputChunk.code
106
+ });
107
+ workerMap.bundle.set(id, fileName);
108
+ }
109
+ return encodeWorkerAssetFileName(fileName, workerMap);
110
+ }
111
+ // https://github.com/vitejs/vite/blob/b7ddfae5f852c2948fab03e94751ce56f5f31ce0/packages/vite/src/node/plugins/worker.ts#L149
112
+ function encodeWorkerAssetFileName(fileName, workerCache) {
113
+ const { fileNameHash } = workerCache;
114
+ const hash = bridge_utils.getHash(fileName);
115
+ if (!fileNameHash.get(hash)) {
116
+ fileNameHash.set(hash, fileName);
117
+ }
118
+ return `${WORKER_ASSET_ID}${hash}__`;
119
+ }
120
+ // https://github.com/vitejs/vite/blob/b7ddfae5f852c2948fab03e94751ce56f5f31ce0/packages/vite/src/node/plugins/worker.ts#L55
121
+ async function bundleWorkerEntry(config, id) {
122
+ const input = bridge_utils.cleanUrl(id);
123
+ const bundleChain = config.bundleChain ?? [];
124
+ const newBundleChain = [...bundleChain, input];
125
+ if (bundleChain.includes(input)) {
126
+ throw new Error(`Circular worker imports detected. Vite does not support it. Import chain: ${newBundleChain.join(' -> ')}`);
127
+ }
128
+ // bundle the file as entry to support imports
129
+ const { rollup } = await import('rollup');
130
+ const { plugins, rollupOptions, format } = config.worker;
131
+ const workerConfig = await plugins(newBundleChain);
132
+ const workerEnvironment = new vite.BuildEnvironment('client', workerConfig); // TODO: should this be 'worker'?
133
+ await workerEnvironment.init();
134
+ const bundle = await rollup({
135
+ ...rollupOptions,
136
+ input,
137
+ plugins: workerEnvironment.plugins.map(p => bridge_build.injectEnvironmentToHooks(workerEnvironment, p)),
138
+ preserveEntrySignatures: false
139
+ });
140
+ let chunk;
141
+ try {
142
+ const workerOutputConfig = config.worker.rollupOptions.output;
143
+ const workerConfig = workerOutputConfig
144
+ ? Array.isArray(workerOutputConfig)
145
+ ? workerOutputConfig[0] || {}
146
+ : workerOutputConfig
147
+ : {};
148
+ const { output: [outputChunk, ...outputChunks] } = await bundle.generate({
149
+ entryFileNames: path__namespace.posix.join(config.build.assetsDir, '[name]-[hash].js'),
150
+ chunkFileNames: path__namespace.posix.join(config.build.assetsDir, '[name]-[hash].js'),
151
+ assetFileNames: path__namespace.posix.join(config.build.assetsDir, '[name]-[hash].[ext]'),
152
+ ...workerConfig,
153
+ format,
154
+ sourcemap: config.build.sourcemap
155
+ });
156
+ chunk = outputChunk;
157
+ for (const outputChunk of outputChunks) {
158
+ if (outputChunk.type === 'asset') {
159
+ saveEmitWorkerAsset(config, outputChunk);
160
+ }
161
+ else if (outputChunk.type === 'chunk') {
162
+ saveEmitWorkerAsset(config, {
163
+ fileName: outputChunk.fileName,
164
+ source: outputChunk.code
165
+ });
166
+ }
167
+ }
168
+ }
169
+ finally {
170
+ await bundle.close();
171
+ }
172
+ return emitSourcemapForWorkerEntry(config, chunk);
173
+ }
174
+ // https://github.com/vitejs/vite/blob/b7ddfae5f852c2948fab03e94751ce56f5f31ce0/packages/vite/src/node/plugins/worker.ts#L124
175
+ function emitSourcemapForWorkerEntry(config, chunk) {
176
+ const { map: sourcemap } = chunk;
177
+ if (sourcemap) {
178
+ if (config.build.sourcemap === 'hidden' || config.build.sourcemap === true) {
179
+ const data = sourcemap.toString();
180
+ const mapFileName = `${chunk.fileName}.map`;
181
+ saveEmitWorkerAsset(config, {
182
+ fileName: mapFileName,
183
+ source: data
184
+ });
185
+ }
186
+ }
187
+ return chunk;
188
+ }
189
+ // https://github.com/vitejs/vite/blob/b7ddfae5f852c2948fab03e94751ce56f5f31ce0/packages/vite/src/node/plugins/worker.ts#L458
190
+ /**
191
+ * @internal
192
+ */
193
+ function isSameContent(a, b) {
194
+ if (typeof a === 'string') {
195
+ if (typeof b === 'string') {
196
+ return a === b;
197
+ }
198
+ return Buffer.from(a).equals(b);
199
+ }
200
+ return Buffer.from(b).equals(a);
201
+ }
202
+
203
+ exports.WORKER_ASSET_ID = WORKER_ASSET_ID;
204
+ exports.WORKER_FILE_ID = WORKER_FILE_ID;
205
+ exports.isSameContent = isSameContent;
206
+ exports.workerCache = workerCache;
207
+ exports.workerFileToUrl = workerFileToUrl;
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * alphaTab Vite Plugin v1.7.0-alpha.1627 (develop, build 1627)
2
+ * alphaTab Vite Plugin v1.7.0-alpha.1629 (develop, build 1629)
3
3
  *
4
4
  * Copyright © 2025, Daniel Kuschny and Contributors, All rights reserved.
5
5
  *
@@ -0,0 +1,168 @@
1
+ /*!
2
+ * alphaTab Vite Plugin v1.7.0-alpha.1629 (develop, build 1629)
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
+ * This library uses code from Vite (https://github.com/vitejs/vite/), licensed under:
11
+ *
12
+ * MIT License
13
+ * Copyright (c) 2019-present, Yuxi (Evan) You and Vite contributors
14
+ *
15
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
16
+ * of this software and associated documentation files (the "Software"), to deal
17
+ * in the Software without restriction, including without limitation the rights
18
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
19
+ * copies of the Software, and to permit persons to whom the Software is
20
+ * furnished to do so, subject to the following conditions:
21
+ *
22
+ * The above copyright notice and this permission notice shall be included in all
23
+ * copies or substantial portions of the Software.
24
+ *
25
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
26
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
27
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
28
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
29
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
30
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
31
+ * SOFTWARE.
32
+ *
33
+ * @preserve
34
+ * @license
35
+ */
36
+
37
+ 'use strict';
38
+
39
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
40
+
41
+ const fs = require('node:fs');
42
+ const path = require('node:path');
43
+ const url = require('node:url');
44
+
45
+ var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
46
+ function _interopNamespaceDefault(e) {
47
+ const n = Object.create(null, { [Symbol.toStringTag]: { value: 'Module' } });
48
+ if (e) {
49
+ for (const k in e) {
50
+ if (k !== 'default') {
51
+ const d = Object.getOwnPropertyDescriptor(e, k);
52
+ Object.defineProperty(n, k, d.get ? d : {
53
+ enumerable: true,
54
+ get: () => e[k]
55
+ });
56
+ }
57
+ }
58
+ }
59
+ n.default = e;
60
+ return Object.freeze(n);
61
+ }
62
+
63
+ const path__namespace = /*#__PURE__*/_interopNamespaceDefault(path);
64
+ const url__namespace = /*#__PURE__*/_interopNamespaceDefault(url);
65
+
66
+ /**
67
+ * @public
68
+ */
69
+ function copyAssetsPlugin(options) {
70
+ let resolvedConfig;
71
+ let output = false;
72
+ return {
73
+ name: 'vite-plugin-alphatab-copy',
74
+ enforce: 'pre',
75
+ configResolved(config) {
76
+ resolvedConfig = config;
77
+ },
78
+ buildEnd() {
79
+ // reset for watch mode
80
+ output = false;
81
+ },
82
+ async buildStart() {
83
+ // run copy only once even if multiple bundles are generated
84
+ if (output) {
85
+ return;
86
+ }
87
+ output = true;
88
+ let alphaTabSourceDir = options.alphaTabSourceDir;
89
+ if (!alphaTabSourceDir) {
90
+ try {
91
+ const isEsm = typeof (typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('copyAssetsPlugin.cjs', document.baseURI).href)) === 'string';
92
+ if (isEsm) {
93
+ alphaTabSourceDir = url__namespace.fileURLToPath(undefined('@coderline/alphatab'));
94
+ }
95
+ else {
96
+ alphaTabSourceDir = require.resolve('@coderline/alphatab');
97
+ }
98
+ alphaTabSourceDir = path__namespace.resolve(alphaTabSourceDir, '..');
99
+ // walk up to package.json
100
+ while (alphaTabSourceDir) {
101
+ if (await fs.promises
102
+ .access(path__namespace.join(alphaTabSourceDir, 'package.json'), fs.constants.F_OK)
103
+ .then(() => true)
104
+ .catch(() => false)) {
105
+ // found package directory
106
+ alphaTabSourceDir = path__namespace.resolve(alphaTabSourceDir, 'dist');
107
+ break;
108
+ }
109
+ else {
110
+ // reached root
111
+ const parent = path__namespace.resolve(alphaTabSourceDir, '..');
112
+ if (parent === alphaTabSourceDir) {
113
+ alphaTabSourceDir = undefined;
114
+ }
115
+ else {
116
+ alphaTabSourceDir = parent;
117
+ }
118
+ }
119
+ }
120
+ }
121
+ catch {
122
+ alphaTabSourceDir = path__namespace.join(resolvedConfig.root, 'node_modules/@coderline/alphatab/dist/');
123
+ }
124
+ }
125
+ let isValidAlphaTabSourceDir;
126
+ if (alphaTabSourceDir) {
127
+ try {
128
+ await fs.promises.access(path__namespace.join(alphaTabSourceDir, 'alphaTab.mjs'), fs.constants.F_OK);
129
+ isValidAlphaTabSourceDir = true;
130
+ }
131
+ catch {
132
+ isValidAlphaTabSourceDir = false;
133
+ }
134
+ }
135
+ else {
136
+ isValidAlphaTabSourceDir = false;
137
+ }
138
+ if (!isValidAlphaTabSourceDir) {
139
+ resolvedConfig.logger.error('Could not find alphaTab, please ensure it is installed into node_modules or configure alphaTabSourceDir');
140
+ return;
141
+ }
142
+ const outputPath = (options.assetOutputDir ?? resolvedConfig.publicDir);
143
+ if (!outputPath) {
144
+ return;
145
+ }
146
+ async function copyFiles(subdir) {
147
+ const fullDir = path__namespace.join(alphaTabSourceDir, subdir);
148
+ const files = await fs.promises.readdir(fullDir, {
149
+ withFileTypes: true
150
+ });
151
+ await fs.promises.mkdir(path__namespace.join(outputPath, subdir), {
152
+ recursive: true
153
+ });
154
+ await Promise.all(files
155
+ .filter(f => f.isFile())
156
+ .map(async (file) => {
157
+ // node v20.12.0 has parentPath pointing to the path (not the file)
158
+ // see https://github.com/nodejs/node/pull/50976
159
+ const sourceFilename = path__namespace.join(file.parentPath ?? file.path, file.name);
160
+ await fs.promises.copyFile(sourceFilename, path__namespace.join(outputPath, subdir, file.name));
161
+ }));
162
+ }
163
+ await Promise.all([copyFiles('font'), copyFiles('soundfont')]);
164
+ }
165
+ };
166
+ }
167
+
168
+ exports.copyAssetsPlugin = copyAssetsPlugin;
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * alphaTab Vite Plugin v1.7.0-alpha.1627 (develop, build 1627)
2
+ * alphaTab Vite Plugin v1.7.0-alpha.1629 (develop, build 1629)
3
3
  *
4
4
  * Copyright © 2025, Daniel Kuschny and Contributors, All rights reserved.
5
5
  *
@@ -0,0 +1,201 @@
1
+ /*!
2
+ * alphaTab Vite Plugin v1.7.0-alpha.1629 (develop, build 1629)
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
+ * This library uses code from Vite (https://github.com/vitejs/vite/), licensed under:
11
+ *
12
+ * MIT License
13
+ * Copyright (c) 2019-present, Yuxi (Evan) You and Vite contributors
14
+ *
15
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
16
+ * of this software and associated documentation files (the "Software"), to deal
17
+ * in the Software without restriction, including without limitation the rights
18
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
19
+ * copies of the Software, and to permit persons to whom the Software is
20
+ * furnished to do so, subject to the following conditions:
21
+ *
22
+ * The above copyright notice and this permission notice shall be included in all
23
+ * copies or substantial portions of the Software.
24
+ *
25
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
26
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
27
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
28
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
29
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
30
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
31
+ * SOFTWARE.
32
+ *
33
+ * @preserve
34
+ * @license
35
+ */
36
+
37
+ 'use strict';
38
+
39
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
40
+
41
+ const path = require('node:path');
42
+ const MagicString = require('magic-string');
43
+ const bridge_asset = require('./bridge/asset.cjs');
44
+ const bridge_utils = require('./bridge/utils.cjs');
45
+ const bridge_optimizer = require('./bridge/optimizer.cjs');
46
+ const bridge_resolve = require('./bridge/resolve.cjs');
47
+ const bridge_worker = require('./bridge/worker.cjs');
48
+
49
+ // This file contains a customized and adapted version of the Vite built-in workerImportMetaUrl plugin
50
+ // https://github.com/vitejs/vite/blob/main/packages/vite/src/node/plugins/workerImportMetaUrl.ts
51
+ // The main adaptions are:
52
+ // - Custom syntax detection for workers and audio worklets
53
+ // - Custom worker types and worker URLs to not overlap with the original plugin
54
+ // With https://github.com/vitejs/vite/pull/16422 integrated this custom code should not be needed anymore
55
+ // Original Sources Licensed under:
56
+ // MIT License
57
+ // Copyright (c) 2019-present, Yuxi (Evan) You and Vite contributors
58
+ // Permission is hereby granted, free of charge, to any person obtaining a copy
59
+ // of this software and associated documentation files (the "Software"), to deal
60
+ // in the Software without restriction, including without limitation the rights
61
+ // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
62
+ // copies of the Software, and to permit persons to whom the Software is
63
+ // furnished to do so, subject to the following conditions:
64
+ // The above copyright notice and this permission notice shall be included in all
65
+ // copies or substantial portions of the Software.
66
+ // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
67
+ // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
68
+ // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
69
+ // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
70
+ // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
71
+ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
72
+ // SOFTWARE.
73
+ const alphaTabWorkerPatterns = [
74
+ ['alphaTabWorker', 'new', 'alphaTabUrl', 'import.meta.url'],
75
+ ['alphaTabWorklet.addModule', 'new', 'alphaTabUrl', 'import.meta.url']
76
+ ];
77
+ function includesAlphaTabWorker(code) {
78
+ for (const pattern of alphaTabWorkerPatterns) {
79
+ let position = 0;
80
+ for (const match of pattern) {
81
+ position = code.indexOf(match, position);
82
+ if (position === -1) {
83
+ break;
84
+ }
85
+ }
86
+ if (position !== -1) {
87
+ return true;
88
+ }
89
+ }
90
+ return false;
91
+ }
92
+ function getWorkerType(code, match) {
93
+ if (match[1].includes('.addModule')) {
94
+ return bridge_worker.AlphaTabWorkerTypes.AudioWorklet;
95
+ }
96
+ const endOfMatch = match.indices[0][1];
97
+ const startOfOptions = code.indexOf('{', endOfMatch);
98
+ if (startOfOptions === -1) {
99
+ return bridge_worker.AlphaTabWorkerTypes.WorkerClassic;
100
+ }
101
+ const endOfOptions = code.indexOf('}', endOfMatch);
102
+ if (endOfOptions === -1) {
103
+ return bridge_worker.AlphaTabWorkerTypes.WorkerClassic;
104
+ }
105
+ const endOfWorkerCreate = code.indexOf(')', endOfMatch);
106
+ if (startOfOptions > endOfWorkerCreate || endOfOptions > endOfWorkerCreate) {
107
+ return bridge_worker.AlphaTabWorkerTypes.WorkerClassic;
108
+ }
109
+ let workerOptions = code.slice(startOfOptions, endOfOptions + 1);
110
+ try {
111
+ workerOptions = bridge_utils.evalValue(workerOptions);
112
+ }
113
+ catch {
114
+ return bridge_worker.AlphaTabWorkerTypes.WorkerClassic;
115
+ }
116
+ if (typeof workerOptions === 'object' && workerOptions?.type === 'module') {
117
+ return bridge_worker.AlphaTabWorkerTypes.WorkerModule;
118
+ }
119
+ return bridge_worker.AlphaTabWorkerTypes.WorkerClassic;
120
+ }
121
+ /**
122
+ * @public
123
+ */
124
+ function importMetaUrlPlugin(options) {
125
+ let resolvedConfig;
126
+ let isBuild;
127
+ let preserveSymlinks;
128
+ const isWorkerActive = options.webWorkers !== false;
129
+ const isWorkletActive = options.audioWorklets !== false;
130
+ const isActive = isWorkerActive || isWorkletActive;
131
+ return {
132
+ name: 'vite-plugin-alphatab-url',
133
+ enforce: 'pre',
134
+ configResolved(config) {
135
+ resolvedConfig = config;
136
+ isBuild = config.command === 'build';
137
+ preserveSymlinks = config.resolve.preserveSymlinks;
138
+ },
139
+ shouldTransformCachedModule({ code }) {
140
+ if (isActive && isBuild && resolvedConfig.build.watch && includesAlphaTabWorker(code)) {
141
+ return true;
142
+ }
143
+ return;
144
+ },
145
+ async transform(code, id, options) {
146
+ if (!isActive || options?.ssr || !includesAlphaTabWorker(code)) {
147
+ return;
148
+ }
149
+ let s;
150
+ const alphaTabWorkerPattern = /\b(alphaTabWorker|alphaTabWorklet\.addModule)\s*\(\s*(new\s+[^ (]+alphaTabUrl\s*\(\s*('[^']+'|"[^"]+"|`[^`]+`)\s*,\s*import\.meta\.url\s*\))/dg;
151
+ let match = alphaTabWorkerPattern.exec(code);
152
+ while (match) {
153
+ const workerType = getWorkerType(code, match);
154
+ let typeActive = false;
155
+ switch (workerType) {
156
+ case bridge_worker.AlphaTabWorkerTypes.WorkerClassic:
157
+ case bridge_worker.AlphaTabWorkerTypes.WorkerModule:
158
+ typeActive = isWorkerActive;
159
+ break;
160
+ case bridge_worker.AlphaTabWorkerTypes.AudioWorklet:
161
+ typeActive = isWorkletActive;
162
+ break;
163
+ }
164
+ if (!typeActive) {
165
+ match = alphaTabWorkerPattern.exec(code);
166
+ continue;
167
+ }
168
+ s ??= new MagicString(code);
169
+ const url = code.slice(match.indices[3][0] + 1, match.indices[3][1] - 1);
170
+ let file = path.resolve(path.dirname(id), url);
171
+ file =
172
+ bridge_resolve.tryFsResolve(file, preserveSymlinks) ??
173
+ bridge_optimizer.tryOptimizedDepResolve(resolvedConfig, options?.ssr === true, url, id, preserveSymlinks) ??
174
+ file;
175
+ let builtUrl;
176
+ if (isBuild) {
177
+ builtUrl = await bridge_worker.workerFileToUrl(resolvedConfig, file);
178
+ }
179
+ else {
180
+ builtUrl = await bridge_asset.fileToUrl(bridge_utils.cleanUrl(file), resolvedConfig);
181
+ builtUrl = bridge_utils.injectQuery(builtUrl, `${bridge_worker.WORKER_FILE_ID}&type=${workerType}`);
182
+ }
183
+ s.update(match.indices[3][0], match.indices[3][1],
184
+ // add `'' +` to skip vite:asset-import-meta-url plugin
185
+ `new URL('' + ${JSON.stringify(builtUrl)}, import.meta.url)`);
186
+ match = alphaTabWorkerPattern.exec(code);
187
+ }
188
+ if (s) {
189
+ return {
190
+ code: s.toString(),
191
+ map: resolvedConfig.command === 'build' && resolvedConfig.build.sourcemap
192
+ ? s.generateMap({ hires: 'boundary', source: id })
193
+ : null
194
+ };
195
+ }
196
+ return null;
197
+ }
198
+ };
199
+ }
200
+
201
+ exports.importMetaUrlPlugin = importMetaUrlPlugin;
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * alphaTab Vite Plugin v1.7.0-alpha.1627 (develop, build 1627)
2
+ * alphaTab Vite Plugin v1.7.0-alpha.1629 (develop, build 1629)
3
3
  *
4
4
  * Copyright © 2025, Daniel Kuschny and Contributors, All rights reserved.
5
5
  *