diff --git a/common/predictive-text/src/index.ts b/common/predictive-text/src/index.ts new file mode 100644 index 0000000000..e087e6957d --- /dev/null +++ b/common/predictive-text/src/index.ts @@ -0,0 +1,3 @@ +export { default as LMLayer } from './lmlayer.js'; +export { default as NodeWorker } from './node/worker.js'; +export { default as WebWorker } from './web/worker.js'; \ No newline at end of file diff --git a/common/predictive-text/src/node/worker.ts b/common/predictive-text/src/node/worker.ts index bcb39806e3..d165e321a3 100644 --- a/common/predictive-text/src/node/worker.ts +++ b/common/predictive-text/src/node/worker.ts @@ -1,7 +1,7 @@ import VirtualizedWorker from "./virtualizedWorker.js"; import unwrap from '../unwrap.js'; -import { LMLayerWorkerCode } from "@keymanapp/lm-worker/build/lib/worker-main.wrapped-for-bundle.js"; +import LMLayerWorkerCode from "@keymanapp/lm-worker/build/lib/worker-main.wrapped-for-bundle.js"; export default class DefaultWorker { static constructInstance(): Worker { diff --git a/common/predictive-text/src/unwrap.ts b/common/predictive-text/src/unwrap.ts index 19af2376b0..ff4735987c 100644 --- a/common/predictive-text/src/unwrap.ts +++ b/common/predictive-text/src/unwrap.ts @@ -5,7 +5,8 @@ * * @param fn The function whose body will be returned. */ -export default function unwrap(fnCode: string): string { - let match = fnCode.match(/function[^{]+{((?:.|\r|\n)+)}[^}]*$/); +export default function unwrap(fn: Function): string { + let wrapper = fn.toString(); + let match = wrapper.match(/function[^{]+{((?:.|\r|\n)+)}[^}]*$/); return match[1]; } \ No newline at end of file diff --git a/common/predictive-text/src/web/worker.ts b/common/predictive-text/src/web/worker.ts index f1e58be185..d5a3a5ebf0 100644 --- a/common/predictive-text/src/web/worker.ts +++ b/common/predictive-text/src/web/worker.ts @@ -1,5 +1,5 @@ import unwrap from '../unwrap.js'; -import { LMLayerWorkerCode } from "@keymanapp/lm-worker/build/lib/worker-main.wrapped-for-bundle.js"; +import LMLayerWorkerCode from "@keymanapp/lm-worker/build/lib/worker-main.wrapped-for-bundle.js"; export default class DefaultWorker { @@ -21,8 +21,8 @@ export default class DefaultWorker { * } * })); */ - static asBlobURI(fnCode: string): string { - let code = unwrap(fnCode); + static asBlobURI(fn: Function): string { + let code = unwrap(fn); let blob = new Blob([code], { type: 'text/javascript' }); return URL.createObjectURL(blob); }