mirror of
https://github.com/xxnuo/MTranServer.git
synced 2026-05-07 05:56:12 +08:00
feat: add wasm
feat: add wasm
This commit is contained in:
191
.github/workflows/build.yml
vendored
191
.github/workflows/build.yml
vendored
@@ -7,128 +7,44 @@ on:
|
||||
|
||||
permissions:
|
||||
contents: write
|
||||
packages: write
|
||||
|
||||
jobs:
|
||||
build-ui:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v3
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Set up Node.js
|
||||
uses: actions/setup-node@v4
|
||||
- name: Setup Bun
|
||||
uses: oven-sh/setup-bun@v1
|
||||
with:
|
||||
node-version: "20"
|
||||
bun-version: latest
|
||||
|
||||
- name: Install pnpm
|
||||
uses: pnpm/action-setup@v4
|
||||
with:
|
||||
version: 9
|
||||
- name: Install dependencies
|
||||
run: bun install
|
||||
|
||||
- name: Build UI
|
||||
run: make build-ui
|
||||
- name: Build All Targets
|
||||
run: bun run build:all
|
||||
|
||||
- name: Upload UI artifact
|
||||
- name: Upload Artifacts
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: ui-dist
|
||||
path: ui/dist/
|
||||
|
||||
build:
|
||||
needs: build-ui
|
||||
strategy:
|
||||
matrix:
|
||||
include:
|
||||
- os: ubuntu-latest
|
||||
goos: linux
|
||||
goarch: amd64
|
||||
- os: ubuntu-latest
|
||||
goos: linux
|
||||
goarch: arm64
|
||||
- os: ubuntu-latest
|
||||
goos: linux
|
||||
goarch: 386
|
||||
- os: macos-latest
|
||||
goos: darwin
|
||||
goarch: amd64
|
||||
- os: macos-latest
|
||||
goos: darwin
|
||||
goarch: arm64
|
||||
- os: windows-latest
|
||||
goos: windows
|
||||
goarch: amd64
|
||||
runs-on: ${{ matrix.os }}
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: Set up Go
|
||||
uses: actions/setup-go@v4
|
||||
with:
|
||||
go-version: "1.25.3"
|
||||
|
||||
- name: Download UI artifact
|
||||
uses: actions/download-artifact@v4
|
||||
with:
|
||||
name: ui-dist
|
||||
path: ui/dist/
|
||||
|
||||
- name: Download resources
|
||||
run: make download
|
||||
env:
|
||||
GOOS: ${{ matrix.goos }}
|
||||
GOARCH: ${{ matrix.goarch }}
|
||||
|
||||
- name: Build docs
|
||||
run: make generate-docs
|
||||
env:
|
||||
GOOS: ${{ matrix.goos }}
|
||||
GOARCH: ${{ matrix.goarch }}
|
||||
|
||||
- name: Build binary
|
||||
run: make build
|
||||
env:
|
||||
GOOS: ${{ matrix.goos }}
|
||||
GOARCH: ${{ matrix.goarch }}
|
||||
|
||||
- name: Upload artifact
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: mtranserver-${{ matrix.goos }}-${{ matrix.goarch }}
|
||||
path: dist/mtranserver-${{ matrix.goos }}-${{ matrix.goarch }}*
|
||||
name: binaries
|
||||
path: dist/mtranserver-*
|
||||
|
||||
release:
|
||||
needs: build
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
contents: write
|
||||
|
||||
if: startsWith(github.ref, 'refs/tags/')
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Download Artifacts
|
||||
uses: actions/download-artifact@v4
|
||||
with:
|
||||
path: artifacts
|
||||
pattern: mtranserver-*
|
||||
|
||||
- name: Organize Release Assets
|
||||
run: |
|
||||
mkdir -p release-assets
|
||||
|
||||
VERSION=$(git describe --tags --abbrev=0 2>/dev/null || echo "v0.0.0-dev")
|
||||
VERSION=${VERSION#v}
|
||||
|
||||
# Copy and rename binaries with version
|
||||
find artifacts/mtranserver-linux-amd64 -name "mtranserver-linux-amd64" -type f -exec cp {} release-assets/mtranserver-${VERSION}-linux-amd64 \;
|
||||
find artifacts/mtranserver-linux-arm64 -name "mtranserver-linux-arm64" -type f -exec cp {} release-assets/mtranserver-${VERSION}-linux-arm64 \;
|
||||
find artifacts/mtranserver-linux-386 -name "mtranserver-linux-386" -type f -exec cp {} release-assets/mtranserver-${VERSION}-linux-386 \;
|
||||
find artifacts/mtranserver-darwin-amd64 -name "mtranserver-darwin-amd64" -type f -exec cp {} release-assets/mtranserver-${VERSION}-darwin-amd64 \;
|
||||
find artifacts/mtranserver-darwin-arm64 -name "mtranserver-darwin-arm64" -type f -exec cp {} release-assets/mtranserver-${VERSION}-darwin-arm64 \;
|
||||
find artifacts/mtranserver-windows-amd64 -name "mtranserver-windows-amd64.exe" -type f -exec cp {} release-assets/mtranserver-${VERSION}-windows-amd64.exe \;
|
||||
|
||||
ls -lh release-assets/
|
||||
name: binaries
|
||||
path: release-assets
|
||||
|
||||
- name: Generate Checksums
|
||||
run: |
|
||||
@@ -136,76 +52,9 @@ jobs:
|
||||
sha256sum * > SHA256SUMS
|
||||
cat SHA256SUMS
|
||||
|
||||
- name: Determine Release Type
|
||||
id: release_info
|
||||
run: |
|
||||
if [[ "${{ github.ref }}" == refs/tags/v* ]]; then
|
||||
echo "is_release=true" >> $GITHUB_OUTPUT
|
||||
echo "tag_name=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT
|
||||
echo "prerelease=false" >> $GITHUB_OUTPUT
|
||||
else
|
||||
echo "is_release=false" >> $GITHUB_OUTPUT
|
||||
echo "tag_name=dev-$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
|
||||
echo "prerelease=true" >> $GITHUB_OUTPUT
|
||||
fi
|
||||
|
||||
- name: Generate Release Body
|
||||
id: generate_body
|
||||
run: |
|
||||
TAG="${{ steps.release_info.outputs.tag_name }}"
|
||||
REPO="${{ github.repository }}"
|
||||
IS_RELEASE="${{ steps.release_info.outputs.is_release }}"
|
||||
VERSION=$(git describe --tags --abbrev=0 2>/dev/null || echo "v0.0.0-dev")
|
||||
VERSION=${VERSION#v}
|
||||
|
||||
if [ "$IS_RELEASE" == "true" ]; then
|
||||
WARNING=""
|
||||
else
|
||||
WARNING="**Development build - may be unstable**"$'\n\n'
|
||||
fi
|
||||
|
||||
CHANGELOG=""
|
||||
if [ -f "CHANGELOG.md" ]; then
|
||||
CHANGELOG=$(cat CHANGELOG.md)
|
||||
fi
|
||||
|
||||
cat > release_body.md << EOF
|
||||
${WARNING}## MTranServer
|
||||
|
||||
## Changelog
|
||||
${CHANGELOG}
|
||||
|
||||
## Download
|
||||
|
||||
| Platform | Architecture | Binary |
|
||||
|----------|-------------|--------|
|
||||
| Linux | x64 | [mtranserver-${VERSION}-linux-amd64](https://github.com/${REPO}/releases/download/${TAG}/mtranserver-${VERSION}-linux-amd64) |
|
||||
| Linux | ARM64 | [mtranserver-${VERSION}-linux-arm64](https://github.com/${REPO}/releases/download/${TAG}/mtranserver-${VERSION}-linux-arm64) |
|
||||
| Linux | x86 | [mtranserver-${VERSION}-linux-386](https://github.com/${REPO}/releases/download/${TAG}/mtranserver-${VERSION}-linux-386) |
|
||||
| macOS | Intel | [mtranserver-${VERSION}-darwin-amd64](https://github.com/${REPO}/releases/download/${TAG}/mtranserver-${VERSION}-darwin-amd64) |
|
||||
| macOS | Apple Silicon | [mtranserver-${VERSION}-darwin-arm64](https://github.com/${REPO}/releases/download/${TAG}/mtranserver-${VERSION}-darwin-arm64) |
|
||||
| Windows | x64 | [mtranserver-${VERSION}-windows-amd64.exe](https://github.com/${REPO}/releases/download/${TAG}/mtranserver-${VERSION}-windows-amd64.exe) |
|
||||
|
||||
### Checksums
|
||||
|
||||
See [SHA256SUMS](https://github.com/${REPO}/releases/download/${TAG}/SHA256SUMS) for file verification.
|
||||
EOF
|
||||
|
||||
{
|
||||
echo "body<<EOFMARKER"
|
||||
cat release_body.md
|
||||
echo "EOFMARKER"
|
||||
} >> $GITHUB_OUTPUT
|
||||
|
||||
- name: Create Release
|
||||
uses: softprops/action-gh-release@v2
|
||||
with:
|
||||
tag_name: ${{ steps.release_info.outputs.tag_name }}
|
||||
name: ${{ steps.release_info.outputs.is_release == 'true' && format('Release {0}', steps.release_info.outputs.tag_name) || format('Development Build ({0})', steps.release_info.outputs.tag_name) }}
|
||||
body: ${{ steps.generate_body.outputs.body }}
|
||||
files: release-assets/*
|
||||
prerelease: ${{ steps.release_info.outputs.prerelease }}
|
||||
draft: false
|
||||
fail_on_unmatched_files: false
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
files: |
|
||||
release-assets/*
|
||||
generate_release_notes: true
|
||||
|
||||
@@ -11,8 +11,9 @@
|
||||
"assets"
|
||||
],
|
||||
"scripts": {
|
||||
"dev": "tsx src/main.ts",
|
||||
"dev": "bun src/main.ts",
|
||||
"build": "rm -rf dist && bun build src/main.ts --compile --outfile ./dist/mtranserver --minify --sourcemap",
|
||||
"build:all": "bun scripts/build.ts",
|
||||
"build:dev": "rm -rf dist && bun build src/main.ts --outdir dist --target node --format esm --sourcemap --external zstd-wasm-decoder --external express && tsc --emitDeclarationOnly --outDir dist",
|
||||
"start": "node dist/main.js",
|
||||
"test": "bun test",
|
||||
|
||||
22
scripts/build.ts
Normal file
22
scripts/build.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
import { $ } from "bun";
|
||||
|
||||
const targets = [
|
||||
"bun-linux-x64",
|
||||
"bun-linux-arm64",
|
||||
"bun-windows-x64",
|
||||
"bun-darwin-x64",
|
||||
"bun-darwin-arm64",
|
||||
];
|
||||
|
||||
console.log("Cleaning dist...");
|
||||
await $`rm -rf dist`;
|
||||
await $`mkdir -p dist`;
|
||||
|
||||
for (const target of targets) {
|
||||
const ext = target.includes("windows") ? ".exe" : "";
|
||||
const outfile = `dist/mtranserver-${target}${ext}`;
|
||||
console.log(`Building for ${target}...`);
|
||||
await $`bun build src/main.ts --compile --target=${target} --outfile=${outfile} --minify --sourcemap`;
|
||||
}
|
||||
|
||||
console.log("Build complete!");
|
||||
@@ -18,11 +18,7 @@ export interface ModelBuffers {
|
||||
export class ResourceLoader {
|
||||
constructor(private fileSystem: FileSystem) {}
|
||||
|
||||
async loadBergamotModule(wasmBinary: ArrayBuffer | Buffer, workerScriptPath: string): Promise<BergamotModule> {
|
||||
const { createRequire } = await import('module');
|
||||
const require = createRequire(import.meta.url);
|
||||
const loadBergamot = require(workerScriptPath);
|
||||
|
||||
async loadBergamotModule(wasmBinary: ArrayBuffer | Buffer, loadBergamot: any): Promise<BergamotModule> {
|
||||
return new Promise((resolve, reject) => {
|
||||
const timeout = setTimeout(() => {
|
||||
reject(new Error('WASM initialization timeout'));
|
||||
|
||||
4
src/globals.d.ts
vendored
Normal file
4
src/globals.d.ts
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
declare module '*.wasm' {
|
||||
const path: string;
|
||||
export default path;
|
||||
}
|
||||
373
src/lib/bergamot/LICENSE
Normal file
373
src/lib/bergamot/LICENSE
Normal file
@@ -0,0 +1,373 @@
|
||||
Mozilla Public License Version 2.0
|
||||
==================================
|
||||
|
||||
1. Definitions
|
||||
--------------
|
||||
|
||||
1.1. "Contributor"
|
||||
means each individual or legal entity that creates, contributes to
|
||||
the creation of, or owns Covered Software.
|
||||
|
||||
1.2. "Contributor Version"
|
||||
means the combination of the Contributions of others (if any) used
|
||||
by a Contributor and that particular Contributor's Contribution.
|
||||
|
||||
1.3. "Contribution"
|
||||
means Covered Software of a particular Contributor.
|
||||
|
||||
1.4. "Covered Software"
|
||||
means Source Code Form to which the initial Contributor has attached
|
||||
the notice in Exhibit A, the Executable Form of such Source Code
|
||||
Form, and Modifications of such Source Code Form, in each case
|
||||
including portions thereof.
|
||||
|
||||
1.5. "Incompatible With Secondary Licenses"
|
||||
means
|
||||
|
||||
(a) that the initial Contributor has attached the notice described
|
||||
in Exhibit B to the Covered Software; or
|
||||
|
||||
(b) that the Covered Software was made available under the terms of
|
||||
version 1.1 or earlier of the License, but not also under the
|
||||
terms of a Secondary License.
|
||||
|
||||
1.6. "Executable Form"
|
||||
means any form of the work other than Source Code Form.
|
||||
|
||||
1.7. "Larger Work"
|
||||
means a work that combines Covered Software with other material, in
|
||||
a separate file or files, that is not Covered Software.
|
||||
|
||||
1.8. "License"
|
||||
means this document.
|
||||
|
||||
1.9. "Licensable"
|
||||
means having the right to grant, to the maximum extent possible,
|
||||
whether at the time of the initial grant or subsequently, any and
|
||||
all of the rights conveyed by this License.
|
||||
|
||||
1.10. "Modifications"
|
||||
means any of the following:
|
||||
|
||||
(a) any file in Source Code Form that results from an addition to,
|
||||
deletion from, or modification of the contents of Covered
|
||||
Software; or
|
||||
|
||||
(b) any new file in Source Code Form that contains any Covered
|
||||
Software.
|
||||
|
||||
1.11. "Patent Claims" of a Contributor
|
||||
means any patent claim(s), including without limitation, method,
|
||||
process, and apparatus claims, in any patent Licensable by such
|
||||
Contributor that would be infringed, but for the grant of the
|
||||
License, by the making, using, selling, offering for sale, having
|
||||
made, import, or transfer of either its Contributions or its
|
||||
Contributor Version.
|
||||
|
||||
1.12. "Secondary License"
|
||||
means either the GNU General Public License, Version 2.0, the GNU
|
||||
Lesser General Public License, Version 2.1, the GNU Affero General
|
||||
Public License, Version 3.0, or any later versions of those
|
||||
licenses.
|
||||
|
||||
1.13. "Source Code Form"
|
||||
means the form of the work preferred for making modifications.
|
||||
|
||||
1.14. "You" (or "Your")
|
||||
means an individual or a legal entity exercising rights under this
|
||||
License. For legal entities, "You" includes any entity that
|
||||
controls, is controlled by, or is under common control with You. For
|
||||
purposes of this definition, "control" means (a) the power, direct
|
||||
or indirect, to cause the direction or management of such entity,
|
||||
whether by contract or otherwise, or (b) ownership of more than
|
||||
fifty percent (50%) of the outstanding shares or beneficial
|
||||
ownership of such entity.
|
||||
|
||||
2. License Grants and Conditions
|
||||
--------------------------------
|
||||
|
||||
2.1. Grants
|
||||
|
||||
Each Contributor hereby grants You a world-wide, royalty-free,
|
||||
non-exclusive license:
|
||||
|
||||
(a) under intellectual property rights (other than patent or trademark)
|
||||
Licensable by such Contributor to use, reproduce, make available,
|
||||
modify, display, perform, distribute, and otherwise exploit its
|
||||
Contributions, either on an unmodified basis, with Modifications, or
|
||||
as part of a Larger Work; and
|
||||
|
||||
(b) under Patent Claims of such Contributor to make, use, sell, offer
|
||||
for sale, have made, import, and otherwise transfer either its
|
||||
Contributions or its Contributor Version.
|
||||
|
||||
2.2. Effective Date
|
||||
|
||||
The licenses granted in Section 2.1 with respect to any Contribution
|
||||
become effective for each Contribution on the date the Contributor first
|
||||
distributes such Contribution.
|
||||
|
||||
2.3. Limitations on Grant Scope
|
||||
|
||||
The licenses granted in this Section 2 are the only rights granted under
|
||||
this License. No additional rights or licenses will be implied from the
|
||||
distribution or licensing of Covered Software under this License.
|
||||
Notwithstanding Section 2.1(b) above, no patent license is granted by a
|
||||
Contributor:
|
||||
|
||||
(a) for any code that a Contributor has removed from Covered Software;
|
||||
or
|
||||
|
||||
(b) for infringements caused by: (i) Your and any other third party's
|
||||
modifications of Covered Software, or (ii) the combination of its
|
||||
Contributions with other software (except as part of its Contributor
|
||||
Version); or
|
||||
|
||||
(c) under Patent Claims infringed by Covered Software in the absence of
|
||||
its Contributions.
|
||||
|
||||
This License does not grant any rights in the trademarks, service marks,
|
||||
or logos of any Contributor (except as may be necessary to comply with
|
||||
the notice requirements in Section 3.4).
|
||||
|
||||
2.4. Subsequent Licenses
|
||||
|
||||
No Contributor makes additional grants as a result of Your choice to
|
||||
distribute the Covered Software under a subsequent version of this
|
||||
License (see Section 10.2) or under the terms of a Secondary License (if
|
||||
permitted under the terms of Section 3.3).
|
||||
|
||||
2.5. Representation
|
||||
|
||||
Each Contributor represents that the Contributor believes its
|
||||
Contributions are its original creation(s) or it has sufficient rights
|
||||
to grant the rights to its Contributions conveyed by this License.
|
||||
|
||||
2.6. Fair Use
|
||||
|
||||
This License is not intended to limit any rights You have under
|
||||
applicable copyright doctrines of fair use, fair dealing, or other
|
||||
equivalents.
|
||||
|
||||
2.7. Conditions
|
||||
|
||||
Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted
|
||||
in Section 2.1.
|
||||
|
||||
3. Responsibilities
|
||||
-------------------
|
||||
|
||||
3.1. Distribution of Source Form
|
||||
|
||||
All distribution of Covered Software in Source Code Form, including any
|
||||
Modifications that You create or to which You contribute, must be under
|
||||
the terms of this License. You must inform recipients that the Source
|
||||
Code Form of the Covered Software is governed by the terms of this
|
||||
License, and how they can obtain a copy of this License. You may not
|
||||
attempt to alter or restrict the recipients' rights in the Source Code
|
||||
Form.
|
||||
|
||||
3.2. Distribution of Executable Form
|
||||
|
||||
If You distribute Covered Software in Executable Form then:
|
||||
|
||||
(a) such Covered Software must also be made available in Source Code
|
||||
Form, as described in Section 3.1, and You must inform recipients of
|
||||
the Executable Form how they can obtain a copy of such Source Code
|
||||
Form by reasonable means in a timely manner, at a charge no more
|
||||
than the cost of distribution to the recipient; and
|
||||
|
||||
(b) You may distribute such Executable Form under the terms of this
|
||||
License, or sublicense it under different terms, provided that the
|
||||
license for the Executable Form does not attempt to limit or alter
|
||||
the recipients' rights in the Source Code Form under this License.
|
||||
|
||||
3.3. Distribution of a Larger Work
|
||||
|
||||
You may create and distribute a Larger Work under terms of Your choice,
|
||||
provided that You also comply with the requirements of this License for
|
||||
the Covered Software. If the Larger Work is a combination of Covered
|
||||
Software with a work governed by one or more Secondary Licenses, and the
|
||||
Covered Software is not Incompatible With Secondary Licenses, this
|
||||
License permits You to additionally distribute such Covered Software
|
||||
under the terms of such Secondary License(s), so that the recipient of
|
||||
the Larger Work may, at their option, further distribute the Covered
|
||||
Software under the terms of either this License or such Secondary
|
||||
License(s).
|
||||
|
||||
3.4. Notices
|
||||
|
||||
You may not remove or alter the substance of any license notices
|
||||
(including copyright notices, patent notices, disclaimers of warranty,
|
||||
or limitations of liability) contained within the Source Code Form of
|
||||
the Covered Software, except that You may alter any license notices to
|
||||
the extent required to remedy known factual inaccuracies.
|
||||
|
||||
3.5. Application of Additional Terms
|
||||
|
||||
You may choose to offer, and to charge a fee for, warranty, support,
|
||||
indemnity or liability obligations to one or more recipients of Covered
|
||||
Software. However, You may do so only on Your own behalf, and not on
|
||||
behalf of any Contributor. You must make it absolutely clear that any
|
||||
such warranty, support, indemnity, or liability obligation is offered by
|
||||
You alone, and You hereby agree to indemnify every Contributor for any
|
||||
liability incurred by such Contributor as a result of warranty, support,
|
||||
indemnity or liability terms You offer. You may include additional
|
||||
disclaimers of warranty and limitations of liability specific to any
|
||||
jurisdiction.
|
||||
|
||||
4. Inability to Comply Due to Statute or Regulation
|
||||
---------------------------------------------------
|
||||
|
||||
If it is impossible for You to comply with any of the terms of this
|
||||
License with respect to some or all of the Covered Software due to
|
||||
statute, judicial order, or regulation then You must: (a) comply with
|
||||
the terms of this License to the maximum extent possible; and (b)
|
||||
describe the limitations and the code they affect. Such description must
|
||||
be placed in a text file included with all distributions of the Covered
|
||||
Software under this License. Except to the extent prohibited by statute
|
||||
or regulation, such description must be sufficiently detailed for a
|
||||
recipient of ordinary skill to be able to understand it.
|
||||
|
||||
5. Termination
|
||||
--------------
|
||||
|
||||
5.1. The rights granted under this License will terminate automatically
|
||||
if You fail to comply with any of its terms. However, if You become
|
||||
compliant, then the rights granted under this License from a particular
|
||||
Contributor are reinstated (a) provisionally, unless and until such
|
||||
Contributor explicitly and finally terminates Your grants, and (b) on an
|
||||
ongoing basis, if such Contributor fails to notify You of the
|
||||
non-compliance by some reasonable means prior to 60 days after You have
|
||||
come back into compliance. Moreover, Your grants from a particular
|
||||
Contributor are reinstated on an ongoing basis if such Contributor
|
||||
notifies You of the non-compliance by some reasonable means, this is the
|
||||
first time You have received notice of non-compliance with this License
|
||||
from such Contributor, and You become compliant prior to 30 days after
|
||||
Your receipt of the notice.
|
||||
|
||||
5.2. If You initiate litigation against any entity by asserting a patent
|
||||
infringement claim (excluding declaratory judgment actions,
|
||||
counter-claims, and cross-claims) alleging that a Contributor Version
|
||||
directly or indirectly infringes any patent, then the rights granted to
|
||||
You by any and all Contributors for the Covered Software under Section
|
||||
2.1 of this License shall terminate.
|
||||
|
||||
5.3. In the event of termination under Sections 5.1 or 5.2 above, all
|
||||
end user license agreements (excluding distributors and resellers) which
|
||||
have been validly granted by You or Your distributors under this License
|
||||
prior to termination shall survive termination.
|
||||
|
||||
************************************************************************
|
||||
* *
|
||||
* 6. Disclaimer of Warranty *
|
||||
* ------------------------- *
|
||||
* *
|
||||
* Covered Software is provided under this License on an "as is" *
|
||||
* basis, without warranty of any kind, either expressed, implied, or *
|
||||
* statutory, including, without limitation, warranties that the *
|
||||
* Covered Software is free of defects, merchantable, fit for a *
|
||||
* particular purpose or non-infringing. The entire risk as to the *
|
||||
* quality and performance of the Covered Software is with You. *
|
||||
* Should any Covered Software prove defective in any respect, You *
|
||||
* (not any Contributor) assume the cost of any necessary servicing, *
|
||||
* repair, or correction. This disclaimer of warranty constitutes an *
|
||||
* essential part of this License. No use of any Covered Software is *
|
||||
* authorized under this License except under this disclaimer. *
|
||||
* *
|
||||
************************************************************************
|
||||
|
||||
************************************************************************
|
||||
* *
|
||||
* 7. Limitation of Liability *
|
||||
* -------------------------- *
|
||||
* *
|
||||
* Under no circumstances and under no legal theory, whether tort *
|
||||
* (including negligence), contract, or otherwise, shall any *
|
||||
* Contributor, or anyone who distributes Covered Software as *
|
||||
* permitted above, be liable to You for any direct, indirect, *
|
||||
* special, incidental, or consequential damages of any character *
|
||||
* including, without limitation, damages for lost profits, loss of *
|
||||
* goodwill, work stoppage, computer failure or malfunction, or any *
|
||||
* and all other commercial damages or losses, even if such party *
|
||||
* shall have been informed of the possibility of such damages. This *
|
||||
* limitation of liability shall not apply to liability for death or *
|
||||
* personal injury resulting from such party's negligence to the *
|
||||
* extent applicable law prohibits such limitation. Some *
|
||||
* jurisdictions do not allow the exclusion or limitation of *
|
||||
* incidental or consequential damages, so this exclusion and *
|
||||
* limitation may not apply to You. *
|
||||
* *
|
||||
************************************************************************
|
||||
|
||||
8. Litigation
|
||||
-------------
|
||||
|
||||
Any litigation relating to this License may be brought only in the
|
||||
courts of a jurisdiction where the defendant maintains its principal
|
||||
place of business and such litigation shall be governed by laws of that
|
||||
jurisdiction, without reference to its conflict-of-law provisions.
|
||||
Nothing in this Section shall prevent a party's ability to bring
|
||||
cross-claims or counter-claims.
|
||||
|
||||
9. Miscellaneous
|
||||
----------------
|
||||
|
||||
This License represents the complete agreement concerning the subject
|
||||
matter hereof. If any provision of this License is held to be
|
||||
unenforceable, such provision shall be reformed only to the extent
|
||||
necessary to make it enforceable. Any law or regulation which provides
|
||||
that the language of a contract shall be construed against the drafter
|
||||
shall not be used to construe this License against a Contributor.
|
||||
|
||||
10. Versions of the License
|
||||
---------------------------
|
||||
|
||||
10.1. New Versions
|
||||
|
||||
Mozilla Foundation is the license steward. Except as provided in Section
|
||||
10.3, no one other than the license steward has the right to modify or
|
||||
publish new versions of this License. Each version will be given a
|
||||
distinguishing version number.
|
||||
|
||||
10.2. Effect of New Versions
|
||||
|
||||
You may distribute the Covered Software under the terms of the version
|
||||
of the License under which You originally received the Covered Software,
|
||||
or under the terms of any subsequent version published by the license
|
||||
steward.
|
||||
|
||||
10.3. Modified Versions
|
||||
|
||||
If you create software not governed by this License, and you want to
|
||||
create a new license for such software, you may create and use a
|
||||
modified version of this License if you rename the license and remove
|
||||
any references to the name of the license steward (except to note that
|
||||
such modified license differs from this License).
|
||||
|
||||
10.4. Distributing Source Code Form that is Incompatible With Secondary
|
||||
Licenses
|
||||
|
||||
If You choose to distribute Source Code Form that is Incompatible With
|
||||
Secondary Licenses under the terms of this version of the License, the
|
||||
notice described in Exhibit B of this License must be attached.
|
||||
|
||||
Exhibit A - Source Code Form License Notice
|
||||
-------------------------------------------
|
||||
|
||||
This Source Code Form is subject to the terms of the Mozilla Public
|
||||
License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
|
||||
If it is not possible or desirable to put the notice in a particular
|
||||
file, then You may include the notice in a location (such as a LICENSE
|
||||
file in a relevant directory) where a recipient would be likely to look
|
||||
for such a notice.
|
||||
|
||||
You may add additional accurate notices of copyright ownership.
|
||||
|
||||
Exhibit B - "Incompatible With Secondary Licenses" Notice
|
||||
---------------------------------------------------------
|
||||
|
||||
This Source Code Form is "Incompatible With Secondary Licenses", as
|
||||
defined by the Mozilla Public License, v. 2.0.
|
||||
3640
src/lib/bergamot/bergamot-translator.js
Normal file
3640
src/lib/bergamot/bergamot-translator.js
Normal file
File diff suppressed because it is too large
Load Diff
BIN
src/lib/bergamot/bergamot-translator.wasm
Executable file
BIN
src/lib/bergamot/bergamot-translator.wasm
Executable file
Binary file not shown.
204
src/lib/cld/LICENSE
Normal file
204
src/lib/cld/LICENSE
Normal file
@@ -0,0 +1,204 @@
|
||||
Unless otherwise specified, files in this directory are licensed under
|
||||
the Apache 2.0 license:
|
||||
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright [yyyy] [name of copyright owner]
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
48
src/lib/cld/cld-worker.js
Normal file
48
src/lib/cld/cld-worker.js
Normal file
@@ -0,0 +1,48 @@
|
||||
function ca(a){var b=0;return function(){return b<a.length?{done:!1,value:a[b++]}:{done:!0}}}function g(a){var b="undefined"!=typeof Symbol&&Symbol.iterator&&a[Symbol.iterator];if(b)return b.call(a);if("number"==typeof a.length)return{next:ca(a)};throw Error(String(a)+" is not an iterable or ArrayLike");}var l="function"==typeof Object.defineProperties?Object.defineProperty:function(a,b,c){if(a==Array.prototype||a==Object.prototype)return a;a[b]=c.value;return a};
|
||||
function da(a){a=["object"==typeof globalThis&&globalThis,a,"object"==typeof window&&window,"object"==typeof self&&self,"object"==typeof global&&global];for(var b=0;b<a.length;++b){var c=a[b];if(c&&c.Math==Math)return c}throw Error("Cannot find global object");}var n=da(this);function q(a,b){if(b)a:{var c=n;a=a.split(".");for(var d=0;d<a.length-1;d++){var e=a[d];if(!(e in c))break a;c=c[e]}a=a[a.length-1];d=c[a];b=b(d);b!=d&&null!=b&&l(c,a,{configurable:!0,writable:!0,value:b})}}
|
||||
function t(){this.G=!1;this.B=null;this.C=void 0;this.v=1;this.J=this.F=0;this.D=null}function u(a){if(a.G)throw new TypeError("Generator is already running");a.G=!0}t.prototype.H=function(a){this.C=a};function v(a,b){a.D={T:b,ea:!0};a.v=a.F||a.J}t.prototype.return=function(a){this.D={return:a};this.v=this.J};function w(a,b,c){a.v=c;return{value:b}}function y(a){a.F=0;var b=a.D.T;a.D=null;return b}function ea(a){this.v=new t;this.B=a}
|
||||
function fa(a,b){u(a.v);var c=a.v.B;if(c)return z(a,"return"in c?c["return"]:function(d){return{value:d,done:!0}},b,a.v.return);a.v.return(b);return A(a)}function z(a,b,c,d){try{var e=b.call(a.v.B,c);if(!(e instanceof Object))throw new TypeError("Iterator result "+e+" is not an object");if(!e.done)return a.v.G=!1,e;var h=e.value}catch(f){return a.v.B=null,v(a.v,f),A(a)}a.v.B=null;d.call(a.v,h);return A(a)}
|
||||
function A(a){for(;a.v.v;)try{var b=a.B(a.v);if(b)return a.v.G=!1,{value:b.value,done:!1}}catch(c){a.v.C=void 0,v(a.v,c)}a.v.G=!1;if(a.v.D){b=a.v.D;a.v.D=null;if(b.ea)throw b.T;return{value:b.return,done:!0}}return{value:void 0,done:!0}}
|
||||
function ha(a){this.next=function(b){u(a.v);a.v.B?b=z(a,a.v.B.next,b,a.v.H):(a.v.H(b),b=A(a));return b};this.throw=function(b){u(a.v);a.v.B?b=z(a,a.v.B["throw"],b,a.v.H):(v(a.v,b),b=A(a));return b};this.return=function(b){return fa(a,b)};this[Symbol.iterator]=function(){return this}}function ia(a){function b(d){return a.next(d)}function c(d){return a.throw(d)}return new Promise(function(d,e){function h(f){f.done?d(f.value):Promise.resolve(f.value).then(b,c).then(h,e)}h(a.next())})}
|
||||
function D(a){return ia(new ha(new ea(a)))}q("Symbol",function(a){function b(h){if(this instanceof b)throw new TypeError("Symbol is not a constructor");return new c(d+(h||"")+"_"+e++,h)}function c(h,f){this.v=h;l(this,"description",{configurable:!0,writable:!0,value:f})}if(a)return a;c.prototype.toString=function(){return this.v};var d="jscomp_symbol_"+(1E9*Math.random()>>>0)+"_",e=0;return b});
|
||||
q("Symbol.iterator",function(a){if(a)return a;a=Symbol("Symbol.iterator");for(var b="Array Int8Array Uint8Array Uint8ClampedArray Int16Array Uint16Array Int32Array Uint32Array Float32Array Float64Array".split(" "),c=0;c<b.length;c++){var d=n[b[c]];"function"===typeof d&&"function"!=typeof d.prototype[a]&&l(d.prototype,a,{configurable:!0,writable:!0,value:function(){return ja(ca(this))}})}return a});function ja(a){a={next:a};a[Symbol.iterator]=function(){return this};return a}
|
||||
q("Promise",function(a){function b(f){this.B=0;this.C=void 0;this.v=[];this.H=!1;var k=this.D();try{f(k.resolve,k.reject)}catch(m){k.reject(m)}}function c(){this.v=null}function d(f){return f instanceof b?f:new b(function(k){k(f)})}if(a)return a;c.prototype.B=function(f){if(null==this.v){this.v=[];var k=this;this.C(function(){k.F()})}this.v.push(f)};var e=n.setTimeout;c.prototype.C=function(f){e(f,0)};c.prototype.F=function(){for(;this.v&&this.v.length;){var f=this.v;this.v=[];for(var k=0;k<f.length;++k){var m=
|
||||
f[k];f[k]=null;try{m()}catch(p){this.D(p)}}}this.v=null};c.prototype.D=function(f){this.C(function(){throw f;})};b.prototype.D=function(){function f(p){return function(r){m||(m=!0,p.call(k,r))}}var k=this,m=!1;return{resolve:f(this.Y),reject:f(this.F)}};b.prototype.Y=function(f){if(f===this)this.F(new TypeError("A Promise cannot resolve to itself"));else if(f instanceof b)this.$(f);else{a:switch(typeof f){case "object":var k=null!=f;break a;case "function":k=!0;break a;default:k=!1}k?this.X(f):this.G(f)}};
|
||||
b.prototype.X=function(f){var k=void 0;try{k=f.then}catch(m){this.F(m);return}"function"==typeof k?this.aa(k,f):this.G(f)};b.prototype.F=function(f){this.J(2,f)};b.prototype.G=function(f){this.J(1,f)};b.prototype.J=function(f,k){if(0!=this.B)throw Error("Cannot settle("+f+", "+k+"): Promise already settled in state"+this.B);this.B=f;this.C=k;2===this.B&&this.Z();this.V()};b.prototype.Z=function(){var f=this;e(function(){if(f.W()){var k=n.console;"undefined"!==typeof k&&k.error(f.C)}},1)};b.prototype.W=
|
||||
function(){if(this.H)return!1;var f=n.CustomEvent,k=n.Event,m=n.dispatchEvent;if("undefined"===typeof m)return!0;"function"===typeof f?f=new f("unhandledrejection",{cancelable:!0}):"function"===typeof k?f=new k("unhandledrejection",{cancelable:!0}):(f=n.document.createEvent("CustomEvent"),f.initCustomEvent("unhandledrejection",!1,!0,f));f.promise=this;f.reason=this.C;return m(f)};b.prototype.V=function(){if(null!=this.v){for(var f=0;f<this.v.length;++f)h.B(this.v[f]);this.v=null}};var h=new c;b.prototype.$=
|
||||
function(f){var k=this.D();f.N(k.resolve,k.reject)};b.prototype.aa=function(f,k){var m=this.D();try{f.call(k,m.resolve,m.reject)}catch(p){m.reject(p)}};b.prototype.then=function(f,k){function m(x,B){return"function"==typeof x?function(aa){try{p(x(aa))}catch(ba){r(ba)}}:B}var p,r,C=new b(function(x,B){p=x;r=B});this.N(m(f,p),m(k,r));return C};b.prototype.catch=function(f){return this.then(void 0,f)};b.prototype.N=function(f,k){function m(){switch(p.B){case 1:f(p.C);break;case 2:k(p.C);break;default:throw Error("Unexpected state: "+
|
||||
p.B);}}var p=this;null==this.v?h.B(m):this.v.push(m);this.H=!0};b.resolve=d;b.reject=function(f){return new b(function(k,m){m(f)})};b.race=function(f){return new b(function(k,m){for(var p=g(f),r=p.next();!r.done;r=p.next())d(r.value).N(k,m)})};b.all=function(f){var k=g(f),m=k.next();return m.done?d([]):new b(function(p,r){function C(aa){return function(ba){x[aa]=ba;B--;0==B&&p(x)}}var x=[],B=0;do x.push(void 0),B++,d(m.value).N(C(x.length-1),r),m=k.next();while(!m.done)})};return b});
|
||||
q("globalThis",function(a){return a||n});function ka(a,b,c){if(null==a)throw new TypeError("The 'this' value for String.prototype."+c+" must not be null or undefined");if(b instanceof RegExp)throw new TypeError("First argument to String.prototype."+c+" must not be a regular expression");return a+""}
|
||||
q("String.prototype.startsWith",function(a){return a?a:function(b,c){var d=ka(this,b,"startsWith"),e=d.length,h=b.length;c=Math.max(0,Math.min(c|0,d.length));for(var f=0;f<h&&c<e;)if(d[c++]!=b[f++])return!1;return f>=h}});q("String.prototype.codePointAt",function(a){return a?a:function(b){var c=ka(this,null,"codePointAt"),d=c.length;b=Number(b)||0;if(0<=b&&b<d){b|=0;var e=c.charCodeAt(b);if(55296>e||56319<e||b+1===d)return e;b=c.charCodeAt(b+1);return 56320>b||57343<b?e:1024*(e-55296)+b+9216}}});
|
||||
function la(a,b){a instanceof String&&(a+="");var c=0,d=!1,e={next:function(){if(!d&&c<a.length){var h=c++;return{value:b(h,a[h]),done:!1}}d=!0;return{done:!0,value:void 0}}};e[Symbol.iterator]=function(){return e};return e}q("Array.prototype.keys",function(a){return a?a:function(){return la(this,function(b){return b})}});
|
||||
q("Array.prototype.fill",function(a){return a?a:function(b,c,d){var e=this.length||0;0>c&&(c=Math.max(0,e+c));if(null==d||d>e)d=e;d=Number(d);0>d&&(d=Math.max(0,e+d));for(c=Number(c||0);c<d;c++)this[c]=b;return this}});function E(a){return a?a:Array.prototype.fill}q("Int8Array.prototype.fill",E);q("Uint8Array.prototype.fill",E);q("Uint8ClampedArray.prototype.fill",E);q("Int16Array.prototype.fill",E);q("Uint16Array.prototype.fill",E);q("Int32Array.prototype.fill",E);
|
||||
q("Uint32Array.prototype.fill",E);q("Float32Array.prototype.fill",E);q("Float64Array.prototype.fill",E);var F;F||(F=typeof Module != 'undefined' ? Module : {});var ma=!!globalThis.window,na=!!globalThis.WorkerGlobalScope,oa,pa,qa,ra=(null==(oa=globalThis.process)?void 0:null==(pa=oa.versions)?void 0:pa.node)&&"renderer"!=(null==(qa=globalThis.process)?void 0:qa.type),sa,ta,ua=null==(sa=globalThis.document)?void 0:null==(ta=sa.currentScript)?void 0:ta.src;
|
||||
"undefined"!=typeof __filename?ua=__filename:na&&(ua=self.location.href);var G="",va,H;
|
||||
if(ra){var fs=require("fs");G=__dirname+"/";H=function(a){a=I(a)?new URL(a):a;return fs.readFileSync(a)};va=function(a){var b=void 0===b?!0:b;var c;return D(function(d){a=I(a)?new URL(a):a;c=fs.readFileSync(a,b?void 0:"utf8");return d.return(c)})};process.argv.slice(2);"undefined"!=typeof module&&(module.exports=F)}else if(ma||na){try{G=(new URL(".",ua)).href}catch(a){}na&&(H=function(a){var b=new XMLHttpRequest;b.open("GET",a,!1);b.responseType="arraybuffer";b.send(null);return new Uint8Array(b.response)});
|
||||
va=function(a){var b;return D(function(c){if(1==c.v)return I(a)?c.return(new Promise(function(d,e){var h=new XMLHttpRequest;h.open("GET",a,!0);h.responseType="arraybuffer";h.onload=function(){200==h.status||0==h.status&&h.response?d(h.response):e(h.status)};h.onerror=e;h.send(null)})):w(c,fetch(a,{credentials:"same-origin"}),2);b=c.C;if(b.ok)return c.return(b.arrayBuffer());throw Error(b.status+" : "+b.url);})}}var wa=console.log.bind(console),J=console.error.bind(console),K,xa=!1;
|
||||
function I(a){return a.startsWith("file://")}var ya,L,M;function za(){var a=N.buffer;ya=new Int8Array(a);new Int16Array(a);L=new Uint8Array(a);new Uint16Array(a);new Int32Array(a);M=new Uint32Array(a);new Float32Array(a);new Float64Array(a);new BigInt64Array(a);new BigUint64Array(a)}function O(a){var b,c;null==(c=(b=F).onAbort)||c.call(b,a);a="Aborted("+a+")";J(a);xa=!0;throw new WebAssembly.RuntimeError(a+". Build with -sASSERTIONS for more info.");}var P;
|
||||
function Aa(a){var b;return D(function(c){switch(c.v){case 1:if(K){c.v=2;break}c.F=3;return w(c,va(a),5);case 5:return b=c.C,c.return(new Uint8Array(b));case 3:y(c);case 2:var d=c.return;if(a==P&&K)var e=new Uint8Array(K);else if(H)e=H(a);else throw"both async and sync fetching of the wasm failed";return d.call(c,e)}})}
|
||||
function Ba(a,b){var c,d,e;return D(function(h){switch(h.v){case 1:return h.F=2,w(h,Aa(a),4);case 4:return c=h.C,w(h,WebAssembly.instantiate(c,b),5);case 5:return d=h.C,h.return(d);case 2:e=y(h),J("failed to asynchronously prepare wasm: "+e),O(e),h.v=0}})}
|
||||
function Ca(a){var b=K,c=P,d,e,h;return D(function(f){switch(f.v){case 1:if(b||I(c)||ra){f.v=2;break}f.F=3;d=fetch(c,{credentials:"same-origin"});return w(f,WebAssembly.instantiateStreaming(d,a),5);case 5:return e=f.C,f.return(e);case 3:h=y(f),J("wasm streaming compile failed: "+h),J("falling back to ArrayBuffer instantiation");case 2:return f.return(Ba(c,a))}})}function Da(a){for(;0<a.length;)a.shift()(F)}var Ea=[],Fa=[];function Ga(){var a=F.preRun.shift();Fa.push(a)}var Q=0,R=null;
|
||||
function Ha(){Q++;var a,b;null==(b=(a=F).monitorRunDependencies)||b.call(a,Q)}function Ia(a){this.A=a-24}var Ja=0,Ka=0,La=[null,[],[]],Ma=globalThis.TextDecoder&&new TextDecoder;
|
||||
function Na(a,b){b=void 0===b?0:b;var c=b;for(var d=c+void 0;a[c]&&!(c>=d);)++c;if(16<c-b&&a.buffer&&Ma)return Ma.decode(a.subarray(b,c));for(d="";b<c;){var e=a[b++];if(e&128){var h=a[b++]&63;if(192==(e&224))d+=String.fromCharCode((e&31)<<6|h);else{var f=a[b++]&63;e=224==(e&240)?(e&15)<<12|h<<6|f:(e&7)<<18|h<<12|f<<6|a[b++]&63;65536>e?d+=String.fromCharCode(e):(e-=65536,d+=String.fromCharCode(55296|e>>10,56320|e&1023))}}else d+=String.fromCharCode(e)}return d}function Oa(a){return a?Na(L,a):""}
|
||||
var Pa=[];F.print&&(wa=F.print);F.printErr&&(J=F.printErr);F.wasmBinary&&(K=F.wasmBinary);if(F.preInit)for("function"==typeof F.preInit&&(F.preInit=[F.preInit]);0<F.preInit.length;)F.preInit.shift()();
|
||||
var Qa,Ra,Sa,Ta,Ua,Va,Wa,Xa,Ya,Za,$a,ab,N,bb={a:function(a,b,c){var d=new Ia(a);M[d.A+16>>2]=0;M[d.A+4>>2]=b;M[d.A+8>>2]=c;Ja=a;Ka++;throw Ja;},c:function(){return O("")},e:function(a,b){throw"Array index "+a+" out of bounds: [0,"+b+")";},d:function(a){var b=L.length;a>>>=0;if(2147483648<a)return!1;for(var c=1;4>=c;c*=2){var d=b*(1+.2/c);d=Math.min(d,a+100663296);a:{d=(Math.min(2147483648,65536*Math.ceil(Math.max(a,d)/65536))-N.buffer.byteLength+65535)/65536|0;try{N.grow(d);za();var e=1;break a}catch(h){}e=
|
||||
void 0}if(e)return!0}return!1},b:function(a,b,c,d){for(var e=0,h=0;h<c;h++){var f=M[b>>2],k=M[b+4>>2];b+=8;for(var m=0;m<k;m++){var p=a,r=L[f+m],C=La[p];0===r||10===r?((1===p?wa:J)(Na(C)),C.length=0):C.push(r)}e+=k}M[d>>2]=e;return 0}};
|
||||
function cb(){function a(){F.calledRun=!0;if(!xa){Da(Pa);db.g();var b,c;null==(c=(b=F).onRuntimeInitialized)||c.call(b);if(F.postRun)for("function"==typeof F.postRun&&(F.postRun=[F.postRun]);F.postRun.length;)b=F.postRun.shift(),Ea.push(b);Da(Ea)}}if(0<Q)R=cb;else{if(F.preRun)for("function"==typeof F.preRun&&(F.preRun=[F.preRun]);F.preRun.length;)Ga();Da(Fa);0<Q?R=cb:F.setStatus?(F.setStatus("Running..."),setTimeout(function(){setTimeout(function(){return F.setStatus("")},1);a()},1)):a()}}var db;
|
||||
(function(){function a(e){e=db=e.exports;F._webidl_free=e.h;F._webidl_malloc=e.i;Qa=F._emscripten_bind_Language_getLanguageCode_0=e.j;Ra=F._emscripten_bind_Language___destroy___0=e.k;Sa=F._emscripten_bind_VoidPtr___destroy___0=e.l;Ta=F._emscripten_bind_LanguageGuess_getPercent_0=e.m;Ua=F._emscripten_bind_LanguageGuess_getLanguageCode_0=e.n;Va=F._emscripten_bind_LanguageGuess___destroy___0=e.o;Wa=F._emscripten_bind_LanguageInfo_detectLanguage_2=e.p;Xa=F._emscripten_bind_LanguageInfo_detectLanguage_5=
|
||||
e.q;Ya=F._emscripten_bind_LanguageInfo_getIsReliable_0=e.r;Za=F._emscripten_bind_LanguageInfo_getLanguageCode_0=e.s;$a=F._emscripten_bind_LanguageInfo_get_languages_1=e.t;ab=F._emscripten_bind_LanguageInfo___destroy___0=e.u;N=e.f;za();Q--;var h,f;null==(f=(h=F).monitorRunDependencies)||f.call(h,Q);0==Q&&R&&(h=R,R=null,h());return db}var b,c,d;return D(function(e){if(1==e.v){Ha();b={a:bb};if(F.instantiateWasm)return e.return(new Promise(function(h){F.instantiateWasm(b,function(f,k){h(a(f,k))})}));
|
||||
null!=P||(P=F.locateFile?F.locateFile("cld-worker.wasm",G):G+"cld-worker.wasm");return w(e,Ca(b),2)}c=e.C;d=a(c.instance);return e.return(d)})})();cb();function S(){}S.prototype=Object.create(S.prototype);S.prototype.constructor=S;S.prototype.I=S;S.K={};F.WrapperObject=S;function eb(a){return(a||S).K}F.getCache=eb;function T(a,b){var c=eb(b),d=c[a];if(d)return d;d=Object.create((b||S).prototype);d.A=a;return c[a]=d}F.wrapPointer=T;F.castObject=function(a,b){return T(a.A,b)};F.NULL=T(0);
|
||||
F.destroy=function(a){if(!a.__destroy__)throw"Error: Cannot destroy object. (Did you create it yourself?)";a.__destroy__();delete eb(a.I)[a.A]};F.compare=function(a,b){return a.A===b.A};F.getPointer=function(a){return a.A};F.getClass=function(a){return a.I};
|
||||
var U={buffer:0,size:0,M:0,R:[],L:0,S:function(){if(U.L){for(var a=0;a<U.R.length;a++)F._webidl_free(U.R[a]);U.R.length=0;F._webidl_free(U.buffer);U.buffer=0;U.size+=U.L;U.L=0}U.buffer||(U.size+=128,U.buffer=F._webidl_malloc(U.size),U.buffer||O());U.M=0},alloc:function(a,b){U.buffer||O();a=a.length*b.BYTES_PER_ELEMENT;a=8*Math.ceil(a/8);U.M+a>=U.size?(0<a||O(),U.L+=a,b=F._webidl_malloc(a),U.R.push(b)):(b=U.buffer+U.M,U.M+=a);return b}};
|
||||
function fb(a){if("string"===typeof a){for(var b=0,c=0;c<a.length;++c){var d=a.charCodeAt(c);127>=d?b++:2047>=d?b+=2:55296<=d&&57343>=d?(b+=4,++c):b+=3}b=Array(b+1);d=b.length;c=0;if(0<d){d=c+d-1;for(var e=0;e<a.length;++e){var h=a.codePointAt(e);if(127>=h){if(c>=d)break;b[c++]=h}else if(2047>=h){if(c+1>=d)break;b[c++]=192|h>>6;b[c++]=128|h&63}else if(65535>=h){if(c+2>=d)break;b[c++]=224|h>>12;b[c++]=128|h>>6&63;b[c++]=128|h&63}else{if(c+3>=d)break;b[c++]=240|h>>18;b[c++]=128|h>>12&63;b[c++]=128|
|
||||
h>>6&63;b[c++]=128|h&63;e++}}b[c]=0}a=U.alloc(b,ya);for(c=0;c<b.length;c++)ya[a+c]=b[c];return a}return a}function V(){throw"cannot construct a Language, no constructor in IDL";}V.prototype=Object.create(S.prototype);V.prototype.constructor=V;V.prototype.I=V;V.K={};F.Language=V;V.prototype.getLanguageCode=V.prototype.P=function(){return Oa(Qa(this.A))};V.prototype.__destroy__=function(){Ra(this.A)};function W(){throw"cannot construct a VoidPtr, no constructor in IDL";}W.prototype=Object.create(S.prototype);
|
||||
W.prototype.constructor=W;W.prototype.I=W;W.K={};F.VoidPtr=W;W.prototype.__destroy__=function(){Sa(this.A)};function X(){throw"cannot construct a LanguageGuess, no constructor in IDL";}X.prototype=Object.create(V.prototype);X.prototype.constructor=X;X.prototype.I=X;X.K={};F.LanguageGuess=X;X.prototype.getPercent=X.prototype.da=function(){return Ta(this.A)};X.prototype.getLanguageCode=X.prototype.P=function(){return Oa(Ua(this.A))};X.prototype.__destroy__=function(){Va(this.A)};
|
||||
function Y(){throw"cannot construct a LanguageInfo, no constructor in IDL";}Y.prototype=Object.create(V.prototype);Y.prototype.constructor=Y;Y.prototype.I=Y;Y.K={};F.LanguageInfo=Y;
|
||||
Y.prototype.detectLanguage=Y.prototype.O=function(a,b,c,d,e){U.S();a=a&&"object"===typeof a?a.A:fb(a);b&&"object"===typeof b&&(b=b.A);c=c&&"object"===typeof c?c.A:fb(c);d&&"object"===typeof d&&(d=d.A);e=e&&"object"===typeof e?e.A:fb(e);return void 0===c?T(Wa(a,b),Y):void 0===d?T(_emscripten_bind_LanguageInfo_detectLanguage_3(a,b,c),Y):void 0===e?T(_emscripten_bind_LanguageInfo_detectLanguage_4(a,b,c,d),Y):T(Xa(a,b,c,d,e),Y)};Y.prototype.getIsReliable=Y.prototype.ba=function(){return!!Ya(this.A)};
|
||||
Y.prototype.getLanguageCode=Y.prototype.P=function(){return Oa(Za(this.A))};Y.prototype.get_languages=Y.prototype.U=function(a){var b=this.A;a&&"object"===typeof a&&(a=a.A);return T($a(b,a),X)};Object.defineProperty(Y.prototype,"languages",{get:Y.prototype.U});Y.prototype.__destroy__=function(){ab(this.A)};Y.O=Y.prototype.O;U.alloc=U.alloc.bind(U);U.S=U.S.bind(U);
|
||||
for(var Z={ISO_8859_1:0,ISO_8859_2:1,ISO_8859_3:2,ISO_8859_4:3,ISO_8859_5:4,ISO_8859_6:5,ISO_8859_7:6,ISO_8859_8:7,ISO_8859_9:8,ISO_8859_10:9,JAPANESE_EUC_JP:10,EUC_JP:10,JAPANESE_SHIFT_JIS:11,SHIFT_JIS:11,JAPANESE_JIS:12,JIS:12,CHINESE_BIG5:13,BIG5:13,CHINESE_GB:14,CHINESE_EUC_CN:15,EUC_CN:15,KOREAN_EUC_KR:16,EUC_KR:16,UNICODE_UNUSED:17,CHINESE_EUC_DEC:18,EUC_DEC:18,CHINESE_CNS:19,CNS:19,CHINESE_BIG5_CP950:20,BIG5_CP950:20,JAPANESE_CP932:21,CP932:21,UTF8:22,UNKNOWN_ENCODING:23,ASCII_7BIT:24,RUSSIAN_KOI8_R:25,
|
||||
KOI8_R:25,RUSSIAN_CP1251:26,CP1251:26,MSFT_CP1252:27,CP1252:27,RUSSIAN_KOI8_RU:28,KOI8_RU:28,MSFT_CP1250:29,CP1250:29,ISO_8859_15:30,MSFT_CP1254:31,CP1254:31,MSFT_CP1257:32,CP1257:32,ISO_8859_11:33,MSFT_CP874:34,CP874:34,MSFT_CP1256:35,CP1256:35,MSFT_CP1255:36,CP1255:36,ISO_8859_8_I:37,HEBREW_VISUAL:38,CZECH_CP852:39,CP852:39,CZECH_CSN_369103:40,CSN_369103:40,MSFT_CP1253:41,CP1253:41,RUSSIAN_CP866:42,CP866:42,ISO_8859_13:43,ISO_2022_KR:44,GBK:45,GB18030:46,BIG5_HKSCS:47,ISO_2022_CN:48,TSCII:49,TAMIL_MONO:50,
|
||||
TAMIL_BI:51,JAGRAN:52,MACINTOSH_ROMAN:53,UTF7:54,BHASKAR:55,HTCHANAKYA:56,UTF16BE:57,UTF16LE:58,UTF32BE:59,UTF32LE:60,BINARYENC:61,HZ_GB_2312:62,UTF8UTF8:63,TAM_ELANGO:64,TAM_LTTMBARANI:65,TAM_SHREE:66,TAM_TBOOMIS:67,TAM_TMNEWS:68,TAM_WEBTAMIL:69,KDDI_SHIFT_JIS:70,DOCOMO_SHIFT_JIS:71,SOFTBANK_SHIFT_JIS:72,KDDI_ISO_2022_JP:73,ISO_2022_JP:73,SOFTBANK_ISO_2022_JP:74},gb=g(Object.keys(Z)),hb=gb.next();!hb.done;hb=gb.next()){var ib=hb.value;ib.includes("_")&&(Z[ib.replace(/_/g,"")]=Z[ib])}
|
||||
F.onRuntimeInitialized=function(){onmessage=function(a){a=a.data;if(void 0==a.tld&&void 0==a.encoding&&void 0==a.language)var b=Y.O(a.text,!a.isHTML);else{var c=String(a.encoding).toUpperCase().replace(/[_-]/g,"");c=Z.hasOwnProperty(c)?Z[c]:Z.UNKNOWN_ENCODING;b=Y.O(a.text,!a.isHTML,a.tld||null,c,a.language||null)}postMessage({language:b.P(),confident:b.ba(),languages:Array(3).fill(0).map(function(d,e){d=b.U(e);return{languageCode:d.P(),percent:d.da()}}).filter(function(d){return"un"!=d.languageCode||
|
||||
0<d.percent})});F.destroy(b)};postMessage("ready")};
|
||||
BIN
src/lib/cld/cld-worker.wasm
Executable file
BIN
src/lib/cld/cld-worker.wasm
Executable file
Binary file not shown.
@@ -1,8 +1,9 @@
|
||||
import path from 'path';
|
||||
import { TranslationEngine } from '../core/engine.js';
|
||||
import { createResourceLoader } from '../core/factory.js';
|
||||
import { getEmbeddedAssetPath } from '../assets/index.js';
|
||||
import { getConfig } from '../config/index.js';
|
||||
import loadBergamot from '../lib/bergamot/bergamot-translator.js';
|
||||
import wasmPath from '../lib/bergamot/bergamot-translator.wasm' with { type: 'file' };
|
||||
import * as logger from '../logger/index.js';
|
||||
import * as models from '../models/index.js';
|
||||
|
||||
@@ -65,10 +66,8 @@ async function getOrCreateSingleEngine(
|
||||
const engine = new TranslationEngine();
|
||||
const loader = createResourceLoader();
|
||||
|
||||
const wasmBinaryPath = getEmbeddedAssetPath('bergamot-translator.wasm');
|
||||
const workerScriptPath = getEmbeddedAssetPath('bergamot-translator.js');
|
||||
const wasmBinary = await loader.loadWasmBinary(wasmBinaryPath);
|
||||
const bergamotModule = await loader.loadBergamotModule(wasmBinary, workerScriptPath);
|
||||
const wasmBinary = await loader.loadWasmBinary(wasmPath);
|
||||
const bergamotModule = await loader.loadBergamotModule(wasmBinary, loadBergamot);
|
||||
|
||||
const modelBuffers = await loader.loadModelFiles(langPairDir, {
|
||||
model: path.basename(modelFiles.model),
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
"skipLibCheck": true,
|
||||
"resolveJsonModule": true,
|
||||
"isolatedModules": true,
|
||||
"allowJs": true,
|
||||
"types": ["node"]
|
||||
},
|
||||
"include": ["src/**/*"],
|
||||
|
||||
Reference in New Issue
Block a user