Skip to content

Commit 9845a7e

Browse files
authored
Merge pull request #10 from eshaz/fix-web-worker
Fix Web Worker Dependency
2 parents 93f4f84 + fa952c8 commit 9845a7e

11 files changed

+1828
-1023
lines changed

build.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ const build = async (simdPath, scalarPath) => {
6565
rollupInputConfig.input = rollupInput;
6666
rollupInputConfig.plugins = [nodeResolve(), commonjs()];
6767

68-
const rollupOutputConfig = JSON.parse(rollupConfig);
69-
rollupOutputConfig.output.file = distPath + rollupOutput;
68+
const rollupOutputConfig = JSON.parse(rollupConfig).output;
69+
rollupOutputConfig.file = distPath + rollupOutput;
7070

7171
const bundle = await rollup(rollupInputConfig);
7272
const bundleOutput = await bundle

demo/synaudio.js

+14-8
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
11
(function (global, factory) {
2-
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('web-worker')) :
3-
typeof define === 'function' && define.amd ? define(['web-worker'], factory) :
2+
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('@eshaz/web-worker')) :
3+
typeof define === 'function' && define.amd ? define(['@eshaz/web-worker'], factory) :
44
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.SynAudio = factory(global.Worker));
55
})(this, (function (Worker) { 'use strict';
66

7-
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
8-
9-
var Worker__default = /*#__PURE__*/_interopDefaultLegacy(Worker);
10-
117
const encode = (byteArray) => {
128
const charArray = [];
139

@@ -146,6 +142,7 @@
146142
byte1 === 61 || // =
147143
byte1 === 13 || // CR
148144
byte1 === 96 || // `
145+
(byte1 === 92 && (byte2 === 85 || byte2 === 117)) || // \u or \U
149146
(byte1 === 36 && byte2 === 123); // ${
150147

151148
// search for the byte offset with the least amount of escape characters
@@ -166,6 +163,9 @@
166163
}
167164
}
168165

166+
const escapeCharacter = (byte1, charArray) =>
167+
charArray.push("=", String.fromCharCode((byte1 + 64) % 256));
168+
169169
const charArray = [
170170
"dynEncode", // magic signature
171171
"00", // version 0x00 - 0xfe (0xff reserved)
@@ -177,12 +177,18 @@
177177
const byte2 = (byteArray[i + 1] + offset) % 256;
178178

179179
if (shouldEscape(byte1, byte2)) {
180-
charArray.push("=", String.fromCharCode((byte1 + 64) % 256));
180+
escapeCharacter(byte1, charArray);
181181
} else {
182182
charArray.push(String.fromCharCode(byte1));
183183
}
184184
}
185185

186+
// correct edge case where escape character is at end of string
187+
if (charArray[charArray.length - 1] === "\\") {
188+
charArray.pop();
189+
escapeCharacter("\\", charArray);
190+
}
191+
186192
return charArray.join("");
187193
};
188194

@@ -327,7 +333,7 @@
327333
this._sourceCache.set(functionName, source);
328334
}
329335

330-
const worker = new (globalThis.Worker || Worker__default["default"])(source, {
336+
const worker = new (globalThis.Worker || Worker)(source, {
331337
name: "SynAudio",
332338
});
333339

demo/synaudio.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

demo/synaudio.min.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/synaudio.js

+14-8
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
11
(function (global, factory) {
2-
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('web-worker')) :
3-
typeof define === 'function' && define.amd ? define(['web-worker'], factory) :
2+
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('@eshaz/web-worker')) :
3+
typeof define === 'function' && define.amd ? define(['@eshaz/web-worker'], factory) :
44
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.SynAudio = factory(global.Worker));
55
})(this, (function (Worker) { 'use strict';
66

7-
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
8-
9-
var Worker__default = /*#__PURE__*/_interopDefaultLegacy(Worker);
10-
117
const encode = (byteArray) => {
128
const charArray = [];
139

@@ -146,6 +142,7 @@
146142
byte1 === 61 || // =
147143
byte1 === 13 || // CR
148144
byte1 === 96 || // `
145+
(byte1 === 92 && (byte2 === 85 || byte2 === 117)) || // \u or \U
149146
(byte1 === 36 && byte2 === 123); // ${
150147

151148
// search for the byte offset with the least amount of escape characters
@@ -166,6 +163,9 @@
166163
}
167164
}
168165

166+
const escapeCharacter = (byte1, charArray) =>
167+
charArray.push("=", String.fromCharCode((byte1 + 64) % 256));
168+
169169
const charArray = [
170170
"dynEncode", // magic signature
171171
"00", // version 0x00 - 0xfe (0xff reserved)
@@ -177,12 +177,18 @@
177177
const byte2 = (byteArray[i + 1] + offset) % 256;
178178

179179
if (shouldEscape(byte1, byte2)) {
180-
charArray.push("=", String.fromCharCode((byte1 + 64) % 256));
180+
escapeCharacter(byte1, charArray);
181181
} else {
182182
charArray.push(String.fromCharCode(byte1));
183183
}
184184
}
185185

186+
// correct edge case where escape character is at end of string
187+
if (charArray[charArray.length - 1] === "\\") {
188+
charArray.pop();
189+
escapeCharacter("\\", charArray);
190+
}
191+
186192
return charArray.join("");
187193
};
188194

@@ -327,7 +333,7 @@
327333
this._sourceCache.set(functionName, source);
328334
}
329335

330-
const worker = new (globalThis.Worker || Worker__default["default"])(source, {
336+
const worker = new (globalThis.Worker || Worker)(source, {
331337
name: "SynAudio",
332338
});
333339

0 commit comments

Comments
 (0)