kellssheetsOpen spreadsheet
KELLS SHEETS / DEVELOPER

Inside Kells Sheets

The workbook model, calculation engine, local storage and standalone Cloudflare deployment workflow.

Architecture

Kells Sheets is a browser application written in HTML, CSS and JavaScript modules. Workbook operations run locally without a server database, API key or runtime secret. Serve dist over HTTP for a static preview, or run npm run build to embed the application assets in release/worker.mjs, a standalone Cloudflare module Worker. No third-party package installation is required.

FileResponsibility
dist/index.htmlEditor shell, accessible controls and workbook navigation.
dist/styles.cssResponsive layout, dark/light theme and UI styles.
dist/app.jsEditor events, selection, history, data tools and IndexedDB persistence.
dist/engine.jsFormula lexer/parser/evaluator, cell references and CSV encoding/parsing.
dist/workbook.jsWorkbook model, validation, templates, file conversion and downloads.
tests/*.test.mjsNode test cases for calculations and workbook/file operations.
STATE.jsonBuild phase checkpoint and recorded verification evidence.
src/worker-template.mjsWorker routing, embedded asset delivery, public-origin metadata and security headers.
scripts/build.mjsPackage the current assets into a single Worker module.
scripts/deploy.mjsPublish through the official Cloudflare API using local deployment credentials.
release/worker.mjsGenerated standalone Worker with embedded application and documentation assets.
docs/DEPLOYMENT.mdPortable installation, custom domains, updates and origin migration.

The app is publicly available at workbook.rohankells.com.au without ChatGPT sign-in. Spreadsheet contents are kept separately in each browser profile and origin; there is no cloud workbook API. The portable Worker has no ChatGPT Site identity or hosting dependency.

Run and check the source

Use a recent Node.js runtime with the built-in test runner. No package installation is required for the current application.

npm run dev
# Build the standalone Worker after source changes:
npm run build
# Run checks separately:
npm test
npm run check

The tests exercise formula evaluation, references, error behaviour, CSV parsing, native workbook roundtrips, validation and template calculations. A test command is a check you can run; deployment evidence is recorded separately in STATE.json.

The development command prints its local preview URL. You can also serve the static directory through another HTTP server. For example, from the project directory:

python -m http.server 8080 --directory dist

Open http://localhost:8080. Opening index.html directly with a file: URL is not supported because browser module and storage behaviour differs.

Workbook schema

Native .kells and .json files share the same UTF-8 JSON schema. Cells are sparse and keyed by uppercase A1 addresses. Raw input is a string, including formula expressions beginning with =.

{
  "id": "workbook-id",
  "name": "Untitled spreadsheet",
  "activeSheetId": "sheet-id",
  "createdAt": "2026-12-01T00:00:00.000Z",
  "updatedAt": "2026-12-01T00:00:00.000Z",
  "sheets": [{
    "id": "sheet-id", "name": "Sheet 1",
    "rows": 100, "cols": 26,
    "cells": {
      "A1": {"raw": "=SUM(B1:B10)", "style": {"bold": true}}
    },
    "widths": {"0": 180}
  }]
}

Styles support bold, italic, underline, color, background, align, format and fontSize. Width keys are zero-based column indices. Validation retains only supported fields, requires unique sheet names and IDs, and rejects invalid cell addresses.

Colours must be hexadecimal CSS values. Widths are clamped to 48–600 pixels and font sizes to 8–60. Formats are general, number, integer, currency, percent, date and text.

Formula engine

The engine parses formula input into an expression tree. It does not execute JavaScript with eval or the Function constructor. It has no network or DOM access.

import { createEvaluator } from './engine.js';
const calculate = createEvaluator(workbook, workbook.activeSheetId);
const result = calculate('A1');
// After changing raw inputs:
calculate.clear();

A new evaluator creates a new calculation cache. Clear the cache or create a fresh evaluator after workbook changes. Cell addresses are zero-based in the helper API and A1-style in the workbook itself. Sheet-name resolution is case-insensitive.

Supported formulas include bounded ranges, cross-sheet references, absolute reference markers, arithmetic, comparisons, text concatenation and the 37 functions listed in the guide. IF and IFERROR evaluate only the required result branch. Circular dependencies produce #CYCLE!.

Dates use the Excel 1900 serial-date convention. Formula text is limited to 10,000 characters, dependency nesting to 256 levels and calculation operations to a bounded budget. Whole-column ranges, external workbook links, named ranges and array formulas are not implemented.

File and storage interfaces

workbook.js exports createWorkbook, createSheet, validateWorkbook, getUsedRange, importText, workbookToJSON, workbookToCSV, downloadFile, createTemplate, TEMPLATES and LIMITS.

importText(text, filename) handles CSV, TSV and native workbooks. workbookToCSV(workbook, sheetId, evaluator) exports evaluated values; the evaluator argument is optional. Native exports preserve the full supported workbook model.

Imported cells, names and messages must be rendered as text, never inserted as HTML. CSV export adds an apostrophe to formula-like literal strings so another spreadsheet does not execute them on open.

Saving and recovery

Edits begin an IndexedDB write immediately. A localStorage recovery journal holds the active workbook until the matching write completes. The save loop uses revision tracking so a completed older write cannot mark a newer edit as saved. At startup, a valid journal that is newer than the stored workbook is recovered and written to IndexedDB. Theme and starred-workbook preferences also use localStorage.

IndexedDB and localStorage belong to an origin and browser profile. The recovery journal is not a synchronisation or backup service. Preserve meaningful save-error feedback, and keep native export available when storage fails.

Clipboard semantics

The app writes text/plain values and text/html with a unique clipboard token. A token must match the current in-memory payload before the app reuses formulas and styles, preventing old clipboard text from accidentally matching newer selection data. If browser permissions permit only the text fallback, the copy contains calculated values.

Copy supports transfers between sheets and shifts relative formula references. Cut is deferred until paste and supports moves within the same sheet. The source must still match its captured content. On a completed move, formula references fully contained in the moved rectangle are redirected; partially overlapping ranges retain their original addresses.

Filters and charts

Multi-row mutations, pasting and sorting are blocked while a row filter is active. Single-cell editing remains available. Native and CSV exports include the full sheet, including hidden rows. Charts accept two adjacent columns and up to 60 data points, and export as standalone SVG files. Chart definitions are not stored in the workbook schema.

Limits and extension points

The supported size is 20 sheets, 2,000 rows per sheet, 100 columns per sheet, 20 MB per text import and 32,767 characters per cell. The initial sheet is 100 × 26. Additions to these limits should be checked against grid rendering, import validation, formula range traversal and storage usage.

To add a formula, extend the parser/evaluator’s allowlisted function implementation and its tests. To add a stored feature, update workbook validation and native roundtrip tests so the feature survives export and re-import. To add XLSX or online collaboration, implement and verify a complete compatibility or persistence layer before exposing those features in the UI.

Deployment and checkpoints

Run npm run build to generate release/worker.mjs from the current application assets. The generated module includes the full app and its documentation. Deploy the complete file through a new or existing Cloudflare Worker’s code editor, or use the included API script:

node scripts/deploy.mjs --name my-workbook

The command reads CLOUDFLARE_ACCOUNT_ID and CLOUDFLARE_API_TOKEN from the local terminal environment. These deployment credentials are not embedded in the Worker and are not runtime secrets. Add --hostname and --zone-id to attach a custom domain in the appropriate active Cloudflare zone. The package’s docs/DEPLOYMENT.md includes dashboard, terminal and update instructions.

Origins and public metadata

The Worker adjusts canonical URLs, Open Graph URLs, sitemap entries and crawl metadata to the request origin. An optional plain-text PUBLIC_ORIGIN binding selects a preferred public origin when needed. This affects public metadata, not browser workbook storage. A directly served dist copy does not use the Worker’s substitution; update its metadata before publishing it on another static host.

Deployment checks

/healthz returns the deployed version, bundle digest and browser-local storage description. Unknown paths return a real HTTP 404, and HEAD requests return response headers without a body. Check the app, documentation and asset URLs after publishing; the health response alone does not verify a visitor’s local saving behavior.

Move existing workbooks

Before changing an app hostname, export every workbook as a native .kells file from the original address and browser profile. Import those files at the destination, check the sheets and formulas, then reload to verify the local save. Origins are isolated: changing a DNS route or adding a redirect cannot copy IndexedDB between hostnames. Native files exclude chart definitions, interface preferences and undo history. Keep the backup files and do not clear the old origin before checking the import.

STATE.json records completed phases, remaining work and actual verification evidence. Commit the exact source state used to build the deployed file and record the returned Worker version and verified hostname. Preserve the established hostname for routine updates. Do not put credentials or workbook contents in source control.