/** * The lean workbook factory. * * `constructWorkbook` builds a {@link WorkbookKernelBase} and registers exactly * the capabilities the caller opts into, returning a {@link WorkbookOf} typed to * that set. Unlike `createWorkbook` / `new Workbook()`, this module does **not** * statically import `./functions` (the ~1375-line builtin catalog) nor the full * capability set, so a consumer who supplies their own `functions` and a narrow * `capabilities` record gets a module graph free of the heavy defaults. */ import { WorkbookKernelBase } from './kernel' import type { WorkbookKernelOptions, WorkbookOptions } from './kernel' import type { WorkbookCapabilities } from './capability' import type { WorkbookOf } from './workbook' /** Options for {@link constructWorkbook}: workbook options plus a capability set. */ export interface ConstructWorkbookOptions< TCaps extends WorkbookCapabilities, > extends WorkbookOptions { /** The capabilities to register. Only these contribute methods to the type. */ capabilities: TCaps } /** * Build a workbook with a caller-chosen capability set, typed to exactly those * capabilities. The lean, tree-shakeable entry point: pass `functions` to avoid * pulling in the builtin catalog, and only the capabilities you reference are * bundled. * * @example * import { constructWorkbook } from '@tanstack/spreadsheet-core' * import { formatsCapability } from '@tanstack/spreadsheet-core/capabilities' * const wb = constructWorkbook({ * functions: myRegistry, * capabilities: { formatsCapability }, * }) * wb.setFormat({ sheet: 's', row: 0, col: 0 }, '0.00%') // typed */ export function constructWorkbook( opts: ConstructWorkbookOptions, ): WorkbookOf { const kernelOpts: WorkbookKernelOptions = opts return new WorkbookKernelBase(kernelOpts) as unknown as WorkbookOf }