feat: establish reproducible FreeCAD web compatibility baseline

This commit is contained in:
2026-08-10 16:11:38 -04:00
parent e5a5d74dbc
commit b962a5c3b5
733 changed files with 349081 additions and 647 deletions

View File

@@ -21,7 +21,9 @@ export type NativeOcctHistoryWorkerOptions = {
const defaultWorkerFactory = () => new Worker(new URL('./nativeHistoryWorkerEntry.ts', import.meta.url), { type: 'module', name: 'occt-native-history' })
export class NativeOcctHistoryWorkerProvider implements NativeOcctHistoryProvider {
private readonly worker: WorkerLike
private worker: WorkerLike
private readonly workerFactory: () => WorkerLike
private disposed = false
private readonly options: Required<Pick<NativeOcctHistoryWorkerOptions, 'moduleUrl' | 'initializationTimeoutMs'>>
private readonly pending = new Map<string, { resolve: (response: NativeOcctHistoryProtocolResponse) => void; reject: (error: Error) => void }>()
private initialization: Promise<NativeOcctHistoryCapabilities> | null = null
@@ -52,16 +54,35 @@ export class NativeOcctHistoryWorkerProvider implements NativeOcctHistoryProvide
this.initializationReject?.(error)
this.initializationReject = null
this.current = { ...this.current, availability: 'unavailable', reason: error.message }
if (!this.disposed) this.replaceWorker()
}
private attachWorker(worker: WorkerLike) {
worker.addEventListener('message', this.onMessage)
worker.addEventListener('error', this.onError)
}
private detachWorker(worker: WorkerLike) {
worker.removeEventListener('message', this.onMessage)
worker.removeEventListener('error', this.onError)
}
private replaceWorker() {
const previous = this.worker
this.detachWorker(previous)
previous.terminate()
this.worker = this.workerFactory()
this.attachWorker(this.worker)
}
constructor(options: NativeOcctHistoryWorkerOptions = {}) {
this.worker = (options.workerFactory || defaultWorkerFactory)()
this.workerFactory = options.workerFactory || defaultWorkerFactory
this.worker = this.workerFactory()
this.options = {
moduleUrl: options.moduleUrl || '/native/occt-history/bitbybit-occt-history.js',
initializationTimeoutMs: options.initializationTimeoutMs ?? 120_000,
}
this.worker.addEventListener('message', this.onMessage)
this.worker.addEventListener('error', this.onError)
this.attachWorker(this.worker)
}
capabilities(): NativeOcctHistoryCapabilities { return { ...this.current, operations: [...this.current.operations] } }
@@ -95,9 +116,9 @@ export class NativeOcctHistoryWorkerProvider implements NativeOcctHistoryProvide
}
dispose() {
this.disposed = true
this.worker.postMessage({ type: 'dispose' })
this.worker.removeEventListener('message', this.onMessage)
this.worker.removeEventListener('error', this.onError)
this.detachWorker(this.worker)
this.worker.terminate()
this.initializationReject?.(new Error('Native OCCT history Worker disposed.'))
this.initializationReject = null