@coderline/alphatab-vite 1.7.0 → 1.8.0-alpha.1632

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. package/dist/AlphaTabVitePluginOptions.cjs +38 -0
  2. package/dist/AlphaTabVitePluginOptions.d.ts +30 -0
  3. package/dist/AlphaTabVitePluginOptions.mjs +36 -0
  4. package/dist/alphaTab.vite.cjs +45 -0
  5. package/dist/alphaTab.vite.d.ts +1 -33
  6. package/dist/alphaTab.vite.mjs +2 -2328
  7. package/dist/alphaTabVitePlugin.cjs +57 -0
  8. package/dist/alphaTabVitePlugin.d.ts +5 -0
  9. package/dist/alphaTabVitePlugin.mjs +53 -0
  10. package/dist/bridge/asset.cjs +87 -0
  11. package/dist/bridge/asset.mjs +63 -0
  12. package/dist/bridge/build.cjs +242 -0
  13. package/dist/bridge/build.mjs +217 -0
  14. package/dist/bridge/config.cjs +38 -0
  15. package/dist/bridge/config.mjs +36 -0
  16. package/dist/bridge/constants.cjs +88 -0
  17. package/dist/bridge/constants.mjs +82 -0
  18. package/dist/bridge/fsUtils.cjs +60 -0
  19. package/dist/bridge/fsUtils.mjs +56 -0
  20. package/dist/bridge/index.cjs +69 -0
  21. package/dist/bridge/index.mjs +43 -0
  22. package/dist/bridge/optimizer.cjs +172 -0
  23. package/dist/bridge/optimizer.mjs +148 -0
  24. package/dist/bridge/plugins.cjs +51 -0
  25. package/dist/bridge/plugins.mjs +47 -0
  26. package/dist/bridge/resolve.cjs +75 -0
  27. package/dist/bridge/resolve.mjs +71 -0
  28. package/dist/bridge/typeUtils.cjs +38 -0
  29. package/dist/bridge/typeUtils.d.ts +3 -0
  30. package/dist/bridge/typeUtils.mjs +36 -0
  31. package/dist/bridge/utils.cjs +164 -0
  32. package/dist/bridge/utils.mjs +151 -0
  33. package/dist/bridge/worker.cjs +207 -0
  34. package/dist/bridge/worker.d.ts +10 -0
  35. package/dist/bridge/worker.mjs +180 -0
  36. package/dist/copyAssetsPlugin.cjs +168 -0
  37. package/dist/copyAssetsPlugin.d.ts +5 -0
  38. package/dist/copyAssetsPlugin.mjs +143 -0
  39. package/dist/importMetaPlugin.cjs +201 -0
  40. package/dist/importMetaPlugin.d.ts +5 -0
  41. package/dist/importMetaPlugin.mjs +197 -0
  42. package/dist/workerPlugin.cjs +224 -0
  43. package/dist/workerPlugin.d.ts +5 -0
  44. package/dist/workerPlugin.mjs +201 -0
  45. package/package.json +32 -19
  46. package/dist/alphaTab.vite.js +0 -2388
  47. package/dist/alphaTab.vite.min.mjs +0 -36
@@ -0,0 +1,201 @@
1
+ /*!
2
+ * alphaTab Vite Plugin v1.8.0-alpha.1632 (develop, build 1632)
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
+ import * as path from 'node:path';
38
+ import MagicString from 'magic-string';
39
+ import { encodeURIPath } from './bridge/utils.mjs';
40
+ import { createToImportMetaURLBasedRelativeRuntime, toOutputFilePathInJS } from './bridge/build.mjs';
41
+ import { ENV_PUBLIC_PATH } from './bridge/constants.mjs';
42
+ import 'node:fs';
43
+ import 'vite';
44
+ import { workerCache, isSameContent, AlphaTabWorkerTypes, WORKER_ASSET_ID, WORKER_FILE_ID } from './bridge/worker.mjs';
45
+
46
+ // This file contains a customized and adapted version of the Vite built-in worker plugin
47
+ // https://github.com/vitejs/vite/blob/main/packages/vite/src/node/plugins/worker.ts
48
+ // This is more or less a 1:1 copy of the original worker plugin with following adaptions:
49
+ // - Only handle syntax variants known to be used in alphaTab
50
+ // - Use the alphaTab URL markers
51
+ // - Some refactoring for better code understanding
52
+ // With https://github.com/vitejs/vite/pull/16422 integrated this custom code might not be needed anymore
53
+ // Some adjustment for audio worklet in vite might be needed to treat them as type "module" workers
54
+ // Original Sources Licensed under:
55
+ // MIT License
56
+ // Copyright (c) 2019-present, Yuxi (Evan) You and Vite contributors
57
+ // Permission is hereby granted, free of charge, to any person obtaining a copy
58
+ // of this software and associated documentation files (the "Software"), to deal
59
+ // in the Software without restriction, including without limitation the rights
60
+ // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
61
+ // copies of the Software, and to permit persons to whom the Software is
62
+ // furnished to do so, subject to the following conditions:
63
+ // The above copyright notice and this permission notice shall be included in all
64
+ // copies or substantial portions of the Software.
65
+ // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
66
+ // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
67
+ // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
68
+ // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
69
+ // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
70
+ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
71
+ // SOFTWARE.
72
+ const workerFileRE = new RegExp(`(?:\\?|&)${WORKER_FILE_ID}&type=(\\w+)(?:&|$)`);
73
+ const workerAssetUrlRE = new RegExp(`${WORKER_ASSET_ID}([a-z\\d]{8})__`, 'g');
74
+ /**
75
+ * @public
76
+ */
77
+ function workerPlugin(options) {
78
+ let resolvedConfig;
79
+ let isBuild;
80
+ let isWorker;
81
+ const isWorkerActive = options.webWorkers !== false;
82
+ const isWorkletActive = options.audioWorklets !== false;
83
+ const isActive = isWorkerActive || isWorkletActive;
84
+ return {
85
+ name: 'vite-plugin-alphatab-worker',
86
+ configResolved(config) {
87
+ resolvedConfig = config;
88
+ isBuild = config.command === 'build';
89
+ isWorker = config.isWorker;
90
+ },
91
+ buildStart() {
92
+ if (!isActive || isWorker) {
93
+ return;
94
+ }
95
+ workerCache.set(resolvedConfig, {
96
+ assets: new Map(),
97
+ bundle: new Map(),
98
+ fileNameHash: new Map()
99
+ });
100
+ },
101
+ load(id) {
102
+ if (isActive && isBuild && id.includes(WORKER_FILE_ID)) {
103
+ return '';
104
+ }
105
+ return;
106
+ },
107
+ shouldTransformCachedModule({ id }) {
108
+ if (isActive && isBuild && resolvedConfig.build.watch && id.includes(WORKER_FILE_ID)) {
109
+ return true;
110
+ }
111
+ return;
112
+ },
113
+ async transform(raw, id) {
114
+ if (!isActive) {
115
+ return;
116
+ }
117
+ const match = workerFileRE.exec(id);
118
+ if (!match) {
119
+ return;
120
+ }
121
+ // inject env to worker file, might be needed by imported scripts
122
+ const envScriptPath = JSON.stringify(path.posix.join(resolvedConfig.base, ENV_PUBLIC_PATH));
123
+ const workerType = match[1];
124
+ let injectEnv = '';
125
+ switch (workerType) {
126
+ case AlphaTabWorkerTypes.WorkerClassic:
127
+ injectEnv = `importScripts(${envScriptPath})\n`;
128
+ break;
129
+ case AlphaTabWorkerTypes.WorkerModule:
130
+ case AlphaTabWorkerTypes.AudioWorklet:
131
+ injectEnv = `import ${envScriptPath}\n`;
132
+ break;
133
+ }
134
+ if (injectEnv) {
135
+ const s = new MagicString(raw);
136
+ s.prepend(injectEnv);
137
+ return {
138
+ code: s.toString(),
139
+ map: s.generateMap({ hires: 'boundary' })
140
+ };
141
+ }
142
+ return;
143
+ },
144
+ renderChunk(code, chunk, outputOptions) {
145
+ // when building the worker URLs are replaced with some placeholders
146
+ // here we replace those placeholders with the final file names respecting chunks
147
+ let s;
148
+ const result = () => {
149
+ return (s && {
150
+ code: s.toString(),
151
+ map: resolvedConfig.build.sourcemap ? s.generateMap({ hires: 'boundary' }) : null
152
+ });
153
+ };
154
+ workerAssetUrlRE.lastIndex = 0;
155
+ if (workerAssetUrlRE.test(code)) {
156
+ const toRelativeRuntime = createToImportMetaURLBasedRelativeRuntime(outputOptions.format, resolvedConfig.isWorker);
157
+ s = new MagicString(code);
158
+ workerAssetUrlRE.lastIndex = 0;
159
+ // Replace "VITE_WORKER_ASSET__5aa0ddc0" using relative paths
160
+ const workerMap = workerCache.get(resolvedConfig.mainConfig || resolvedConfig);
161
+ const { fileNameHash } = workerMap;
162
+ let match = workerAssetUrlRE.exec(code);
163
+ while (match) {
164
+ const [full, hash] = match;
165
+ const filename = fileNameHash.get(hash);
166
+ const replacement = toOutputFilePathInJS(filename, 'asset', chunk.fileName, 'js', resolvedConfig, toRelativeRuntime);
167
+ const replacementString = typeof replacement === 'string'
168
+ ? JSON.stringify(encodeURIPath(replacement)).slice(1, -1)
169
+ : `"+${replacement.runtime}+"`;
170
+ s.update(match.index, match.index + full.length, replacementString);
171
+ match = workerAssetUrlRE.exec(code);
172
+ }
173
+ }
174
+ return result();
175
+ },
176
+ generateBundle(_, bundle) {
177
+ if (isWorker) {
178
+ return;
179
+ }
180
+ const workerMap = workerCache.get(resolvedConfig);
181
+ for (const asset of workerMap.assets.values()) {
182
+ const duplicateAsset = bundle[asset.fileName];
183
+ if (duplicateAsset) {
184
+ const content = duplicateAsset.type === 'asset' ? duplicateAsset.source : duplicateAsset.code;
185
+ // don't emit if the file name and the content is same
186
+ if (isSameContent(content, asset.source)) {
187
+ return;
188
+ }
189
+ }
190
+ this.emitFile({
191
+ type: 'asset',
192
+ fileName: asset.fileName,
193
+ source: asset.source
194
+ });
195
+ }
196
+ workerMap.assets.clear();
197
+ }
198
+ };
199
+ }
200
+
201
+ export { workerPlugin };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@coderline/alphatab-vite",
3
- "version": "1.7.0",
3
+ "version": "1.8.0-alpha.1632",
4
4
  "description": "A plugin for Vite to bundle alphaTab into your webapps.",
5
5
  "keywords": [
6
6
  "guitar",
@@ -22,38 +22,51 @@
22
22
  "url": "git+https://github.com/coderline/alphaTab.git"
23
23
  },
24
24
  "type": "module",
25
- "main": "dist/alphaTab.vite.js",
26
- "module": "dist/alphaTab.vite.mjs",
27
- "typings": "dist/alphaTab.vite.d.ts",
25
+ "exports": {
26
+ ".": {
27
+ "types": "./dist/alphaTab.vite.d.ts",
28
+ "require": "./dist/alphaTab.vite.cjs",
29
+ "import": "./dist/alphaTab.vite.mjs"
30
+ },
31
+ "./*": {
32
+ "types": "./dist/*.d.ts",
33
+ "require": "./dist/*.cjs",
34
+ "import": "./dist/*.mjs"
35
+ }
36
+ },
28
37
  "scripts": {
29
38
  "clean": "rimraf dist",
30
39
  "lint": "biome lint",
31
40
  "typecheck": "tsc --noEmit",
32
- "build": "vite build --mode esm && vite build --mode cjs",
41
+ "build": "vite build",
33
42
  "test": "mocha"
34
43
  },
35
44
  "dependencies": {
36
- "vite": "^7.1.7"
45
+ "magic-string": "^0.30.21",
46
+ "vite": "^7.2.6"
47
+ },
48
+ "engines": {
49
+ "node": ">=20.19.0"
37
50
  },
38
51
  "devDependencies": {
39
- "@biomejs/biome": "^2.2.4",
40
- "@microsoft/api-extractor": "^7.52.13",
41
- "@types/chai": "^5.2.2",
52
+ "@biomejs/biome": "^2.2.6",
53
+ "@microsoft/api-extractor": "^7.53.3",
54
+ "@types/chai": "^5.2.3",
42
55
  "@types/mocha": "^10.0.10",
43
- "@types/node": "^24.5.2",
56
+ "@types/node": "^24.10.0",
44
57
  "assert": "^2.1.0",
45
- "chai": "^6.0.1",
46
- "mocha": "^11.7.1",
47
- "rimraf": "^6.0.1",
48
- "terser": "^5.43.1",
58
+ "chai": "^6.2.1",
59
+ "mocha": "^11.7.5",
60
+ "rimraf": "^6.1.0",
61
+ "rollup-plugin-node-externals": "^8.1.2",
62
+ "terser": "^5.44.1",
49
63
  "tslib": "^2.8.1",
50
- "tsx": "^4.20.5",
51
- "typescript": "^5.9.2"
64
+ "tsx": "^4.20.6",
65
+ "typescript": "^5.9.3"
52
66
  },
53
67
  "files": [
54
- "/dist/alphaTab*.js",
55
- "/dist/alphaTab*.mjs",
56
- "/dist/alphaTab*.ts",
68
+ "/dist/**",
69
+ "!/dist/types",
57
70
  "LICENSE",
58
71
  "LICENSE.header",
59
72
  "README.md"