# Browser CAD sources, rebuilding and replacement

This directory distributes the complete unmodified sources corresponding to the
browser STEP importer, not the proprietary customer/provider application.
Both archives are supplied here; a floating upstream URL is not the source offer.
No payment, login, account data or email request is required to download them.

- `occt-import-js-0.0.23.tar.gz`: wrapper commit
  `c2148e54b456b571238d35cac037d304053d64b2`, LGPL-2.1.
- `occt-7.6.1.tar.gz`: wrapper's exact OCCT submodule commit
  `d2abb6d844231cb8f29be6894440874a4700e4a5`, LGPL-2.1 with the OCCT exception.
- `upstream-downloads.json`: archive origins, sizes and SHA256 hashes.
- `../DEPENDENCIES.json`: hashes of the distributed binary and notices.

The wrapper archive includes its CMakeLists.txt, tools, C++ import interfaces,
JavaScript interface and upstream tests. The second archive contains the complete
OCCT source tree and its notices. OCCT's additional exception covers material from
headers; it is not a waiver of the library's source-distribution requirements.
Neither library was modified by Alba. The upstream precompiled JS and WASM are
byte-identical to occt-import-js 0.0.23's npm distribution. We have not established
a byte-for-byte reproducible rebuild of that npm binary.

## Prepare the source tree

Use a durable directory with adequate disk space. Unpacking OCCT and compiling
can exceed 250 MB; build outside any RAM-backed temporary filesystem.
Verify each archive SHA256 against upstream-downloads.json before unpacking.
With Python 3.12 or later, from a directory containing these downloads:

```python
from pathlib import Path
import tarfile

work = Path('cad-build')
work.mkdir(exist_ok=True)
for name in ['occt-import-js-0.0.23.tar.gz', 'occt-7.6.1.tar.gz']:
    with tarfile.open(name) as archive:
        archive.extractall(work, filter='data')
wrapper = work / 'occt-import-js-c2148e54b456b571238d35cac037d304053d64b2'
kernel = work / 'OCCT-d2abb6d844231cb8f29be6894440874a4700e4a5'
# The wrapper archive has an empty git-submodule directory, not the kernel sources.
(wrapper / 'occt').rmdir()
kernel.rename(wrapper / 'occt')
```

Install Emscripten **3.1.69**, CMake and a C/C++ build tool in durable storage.
The upstream `tools/setup_emscripten_win.bat` records that exact Emscripten version
and MinGW 7.1.0; `tools/build_wasm_win.bat` and `tools/build_wasm_win_dist.bat`
record the original Windows build/distribution commands. The supplied CMake file
compiles the selected OCCT modules directly into the WASM alongside the wrapper.
Modify the LGPL sources as desired; keep their license and modification notices.

On Windows use the supplied setup and build scripts in the wrapper directory.
On a compatible POSIX Emscripten installation, the equivalent CMake invocation is:

```sh
# Activate your emsdk 3.1.69 environment first; use your durable build directory.
emcmake cmake -S . -B build/wasm -DEMSCRIPTEN=1 -DCMAKE_BUILD_TYPE=Release
cmake --build build/wasm --parallel 2
```

The output pair is `build/wasm/Release/occt-import-js.js` and
`build/wasm/Release/occt-import-js.wasm`. Do not mix JS and WASM from different builds.
These are source/build instructions, not a claim that Alba executed a modified
kernel build. The modified build can be tested with the supplied independent
replacement harness before use in a local exported viewer.

## Replace the library and run it locally

The browser worker loads a separate `vendor/occt-import-js.js` and that module's
separate `vendor/occt-import-js.wasm`. No integrity pin, code-signing restriction or
private server secret prevents replacing the pair in a copy of the exported site.

1. Save a copy of the static website export, including `assets/albahubs/v2/`.
2. Replace BOTH files inside `assets/albahubs/v2/vendor/` with your rebuilt pair.
   Keep the exported `cad-worker.js` and the public `ReadStepFile` interface intact,
   or adapt the worker yourself if you change that interface.
3. Before using an exported viewer, run the independent local import harness:
   `node verify-replacement.cjs /absolute/path/occt-import-js.js /absolute/path/occt-import-js.wasm /absolute/path/test-part.step`.
   The harness uses only the files supplied on its command line and has no account
   service calls. It rejects unsuccessful imports or results without mesh triangles.
4. Serve the local export with any static HTTP server, for example
   `python3 -m http.server 8000 --directory /your/durable/export`, and open it locally.
   Use synthetic models for testing. This does not grant access to hosted private
   projects or disable the real portal's identity, MFA, tenant or CAD authorization.

The same compatible pair can replace the Next application dependency's `dist`
files before the Next build; its separate WASM is copied by `copy:occt-wasm`.
This package's public source offer and notices belong to the Forged Forms/Alba Hubs
native browser runtime. Other distributions must retain these notices and source
access when they distribute the same libraries.

You may modify the LGPL libraries and reverse engineer the combined viewer for
purposes of debugging those modifications, subject to the applicable license.
No viewer term here restricts those rights. This does not confer rights in customer
CAD or authorize access to another person's hosted account. MIT Three.js and
fflate require notices, not corresponding-source or relinking offers.
