Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
3edf218
The picture of a read file: toSVG of a DrawingRead, and tsdraft rende…
sc-frederick Nov 23, 2026
2ed8670
What a sheet of a read file shows, what is near a point, and a cache …
sc-frederick Nov 23, 2026
42e216c
The shape sweep runs about four times faster, on the smallest drawing…
sc-frederick Nov 23, 2026
ebd2afb
Read a file as its layouts show it: only, in both readers
sc-frederick Nov 23, 2026
6eaa9ee
The sheet walk takes a viewport's window from viewportWindow
sc-frederick Nov 23, 2026
5d48b38
readDXF takes the file's bytes as one Uint8Array; notes on points in …
sc-frederick Nov 23, 2026
32a19df
Editing a firm's drawing: the copy and its checks
sc-frederick Nov 23, 2026
e7c6b5c
pnpm 12.18.0 and two more strict compiler checks
sc-frederick Nov 23, 2026
761ec38
lint warns of a viewport that shows another view's notes at its scale
sc-frederick Nov 23, 2026
60fa677
The read-cache test reads again when a parallel test changes the core…
sc-frederick Nov 23, 2026
f081726
Anti-slop lint rules in every package, and SHX names for shape files
sc-frederick Nov 23, 2026
446f1d9
Editing: erase, move, turn and scale by handle
sc-frederick Nov 23, 2026
a53481c
Editing: change a text, a pen, a layer and a viewport in place
sc-frederick Nov 23, 2026
047c660
Editing: stretch by a window and the handles it names, and a polyline…
sc-frederick Nov 23, 2026
0ed03e7
Editing: additions with marks
sc-frederick Nov 23, 2026
74517e2
Editing: a row added to a schedule
sc-frederick Nov 23, 2026
b2b972e
The redline trial again: a note with no leader drawn, a dimension's o…
sc-frederick Nov 23, 2026
b0d38ea
The changed sheets drawn: the fifth check of a write, and the preview…
sc-frederick Nov 23, 2026
a040e0c
Release tsdraft 0.6.0
sc-frederick Nov 23, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .oxfmtrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"ignorePatterns": ["tools/oxlint/**"]
}
39 changes: 39 additions & 0 deletions .oxlintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"$schema": "./node_modules/oxlint/configuration_schema.json",
"extends": ["./.oxlintrc.shared.json"],
"ignorePatterns": ["tools/oxlint/**", "node_modules/**", "dist/**", "cli/dist/**"],
"overrides": [
{
"files": ["src/guards.ts", "src/json.ts", "src/shape.ts"],
"rules": {
"anti-slop/no-unsafe-dictionary-type": "off"
}
},
{
"files": [
"cli/src/worker.ts",
"src/colors.ts",
"src/drawing.ts",
"src/edit/change-shape.ts",
"src/edit/model.ts",
"src/json.ts",
"src/leaders.ts",
"src/lint.ts",
"src/points.ts",
"src/read/check.ts",
"src/rules.ts",
"src/shape.ts",
"src/shapes.ts",
"src/standard/define.ts",
"src/standard/made.ts",
"src/standard/lint.ts",
"src/standard/shape.ts",
"src/tables.ts",
"src/transparency.ts"
],
"rules": {
"anti-slop/no-unknown-parameters": "off"
}
}
]
}
45 changes: 45 additions & 0 deletions .oxlintrc.shared.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{
"$schema": "./node_modules/oxlint/configuration_schema.json",
"jsPlugins": [
{
"name": "anti-slop",
"specifier": "./tools/oxlint/anti-slop/index.ts"
},
{
"name": "anti-slop-effect",
"specifier": "./tools/oxlint/anti-slop/effect/index.ts"
}
],
"ignorePatterns": ["tools/oxlint/**", "node_modules/**", "dist/**", "cli/dist/**"],
"rules": {
"oxc/no-accumulating-spread": "error",
"anti-slop/no-array-filter-map": "error",
"anti-slop/no-reduce-accumulator-copy": "error",
"anti-slop/no-chained-type-assertions": "error",
"anti-slop/no-conditional-empty-object-spread": "error",
"anti-slop/no-known-value-widening": "error",
"anti-slop/no-module-mocking": "error",
"anti-slop/no-object-parameters": "error",
"anti-slop/no-reflect-apply": "error",
"anti-slop/no-reflect-get": "error",
"anti-slop/no-runtime-typeof": [
"error",
{
"allowInTypeGuards": true
}
],
"anti-slop/no-unsafe-dictionary-type": "error",
"anti-slop/no-shape-in-symbol-names": "error",
"anti-slop/no-unknown-parameters": "error",
"anti-slop/no-unknown-returns": "error",
"anti-slop/no-unknown-type-aliases": "error",
"anti-slop/no-widen-then-assert": "error",
"anti-slop/require-readable-spacing": "error",
"anti-slop/require-safety-comment-for-type-assertion": "error",
"anti-slop-effect/no-manual-effect-error-tag": "error",
"anti-slop-effect/no-manual-tag-comparison": "error",
"anti-slop-effect/no-manual-tagged-construction": "error",
"anti-slop-effect/no-service-constructor-imports": "error",
"anti-slop-effect/prefer-effect-match": "error"
}
}
11 changes: 11 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,17 @@ own, and each is as binding as these: before you change a part, read its page. A
- Run `pnpm verify` before finishing a change. It checks formatting, lints,
type checks, runs the tests and runs the package smoke test, which builds.
Run `pnpm fmt` to fix formatting.
- Lint runs the anti-slop rules in `tools/oxlint/anti-slop`, vendored verbatim from the revision
`provenance.json` names; `.oxlintrc.shared.json` configures them for every package, and
`.oxlintrc.json` adds this package's overrides. Add no disable comments.
- Check a value from outside the types with a guard from `src/guards.ts`, or a named guard of
your own: `typeof` may appear only in a type guard.
- `unknown` parameters, and records of `unknown`, are allowed only in the files
`.oxlintrc.json`'s `overrides` lists: the ones that decode outside input. Everywhere else,
take the type the value has once decoded, or an interface whose fields are `unknown`. Never
stand a type parameter in for `unknown`.
- Add a field only when it is present with `...(cond && { field })`, not `cond ? {...} : {}`.
- A type assertion that stays has a one-line `// SAFETY:` comment saying why it holds.
- Source files import each other with `.ts` extensions. Node runs them directly,
and `tsc` rewrites the extensions to `.js` when it builds `dist/`.
- Keep syntax erasable: no enums, namespaces or parameter properties.
Expand Down
194 changes: 193 additions & 1 deletion CHANGELOG.md

Large diffs are not rendered by default.

53 changes: 46 additions & 7 deletions GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -268,11 +268,11 @@ A line feed starts a new paragraph. `list` writes numbered or lettered notes in
hanging under its mark as CAD programs set a list, and `paragraphFormat` a paragraph's indents,
tab stops, justification and spacing. `columns: { count: 2, height: 6 }` flows the notes into
columns side by side, each `width` wide. `measureParagraph` gives its lines and its box, from the
widths `measureText` uses, and `inspectText` checks each line as a text. `underline`, `bold`,
`stack`, `superscript` and `subscript` write the codes for what they name, and `plain(text)`
escapes text from elsewhere. The codes `\H`, `\W`, `\Q`, `\A` and `\C` change the height, width,
slant, place and color of the characters after them, and `lint` refuses a code tsdraft does not
lay out, such as `\T`, and names it.
widths `measureText` uses, and the box's `corners` give its height and its bottom. `inspectText`
checks each line as a text. `underline`, `bold`, `stack`, `superscript` and `subscript` write the
codes for what they name, and `plain(text)` escapes text from elsewhere. The codes `\H`, `\W`,
`\Q`, `\A` and `\C` change the height, width, slant, place and color of the characters after them,
and `lint` refuses a code tsdraft does not lay out, such as `\T`, and names it.
[docs/paragraphs.md](https://github.com/Surfside-Software/tsdraft/blob/main/docs/paragraphs.md)
has the codes.

Expand Down Expand Up @@ -338,6 +338,13 @@ gap on paper into drawing units. On the sheet and in a block, a text with a role
height and names no view. Under a standard every text names a role: a `height`, a `style` and
`textStyle()` are refused. `sitePlan("1in-20ft")` draws the sheet at 1" = 20'.

Each drawing on a sheet is a view of its own, with a viewport of its own, even two at one scale,
such as a south and an east elevation. A viewport shows everything model space draws inside its
window, so draw each view in a part of model space of its own, far enough from the others that no
viewport takes in another's drawing. The command warns `viewport-shows-other-view` of a note, a
symbol, a dimension or a leader that a viewport of another view shows at the same scale; at
another scale, the checks of scale report it as an error.

Its layout is on a sheet format of the standard, `d.layout("C-101", { sheetFormat: "arch-d" },
(sheet) => …)`, which gives the paper, the title block and the zones the sheet is laid out by:
`sheet.zone("views")` is the box the viewport fills, as `{ left, bottom, right, top, width,
Expand Down Expand Up @@ -555,7 +562,7 @@ d.layout("C-101", { paper: "ARCH D" }, (sheet) => {
runs between bends still get their letters. The letters' text style must be one of the drawing's.
- A fence's circles or batt insulation's loops are shapes of the firm's shape file. Copy the file
beside the drawing: the command reads it there, and `toSVG`, `toPDF` and `lint` take its bytes
as `shapes`. Without it the plot leaves a gap where each shape goes, and `lint` warns
as `shx`. Without it the plot leaves a gap where each shape goes, and `lint` warns
`linetype-shape`.
- The sheet plots in black with `monochrome.ctb`. Pass `plotStyle: "acad.ctb"` to plot each
layer in its color, or `"Grayscale.ctb"` in grays. `PLOT_STYLE_TABLES` lists them.
Expand Down Expand Up @@ -661,6 +668,17 @@ Use only TypeScript that can be erased: no enums, namespaces or parameter proper
your own files with their `.ts` extension. The rules are listed in
[docs/rules.md](https://github.com/Surfside-Software/tsdraft/blob/main/docs/rules.md).

A point is a pair, `readonly [x, y]`. Written straight into a call, `[0, 0]` is one, but held in
a variable first it becomes `number[]`, which the compiler refuses as a point. Hold the options
with `satisfies` and the type they go to, or a lone point with `as const`, rather than casting:

```ts
const schedule = { style: "SCHEDULE", at: [1, 20], columns: [2, 4], rows } satisfies TableOptions;
d.table(schedule);
const center = [10, 5] as const;
d.circle(center, 2);
```

## Writing the DXF

The drawing file only exports the drawing. Write the DXF from a second file, and run it with
Expand All @@ -676,6 +694,25 @@ writeFileSync("plan.dxf", toDXF(drawing));

`toDXF` throws a `DrawingError` that lists the problems when the drawing has lint errors.

## What a firm's sheet shows

To find what to change in a firm's sheet, ask before you look through its files by hand.
`tsdraft shows` reads the sheet, and each xref you give it, and prints what the sheet shows: its
paper, and what each viewport that is on shows of the model, with the layers the sheet freezes,
turns off or does not plot left out, and the viewport's and the xref's clips applied. Each entity
comes with its handle, the inserts it was reached through, its layer as the sheet names it, its
box on the paper and its text.

```sh
tsdraft shows A-102.dwg --sheet A-102 --xref "FLOOR PLAN=../1_Model/FLOOR PLAN.dwg"
tsdraft shows A-102.dwg --sheet A-102 --near 12.5,8 --within 0.25 --xref "FLOOR PLAN=../1_Model/FLOOR PLAN.dwg"
```

A file is read once for each hash of its bytes, and the read is kept, so the second question is
fast. In code, `sheetShows`, `nearPoint` and `xrefAreas` answer the same from a read, as
[docs/reading.md](docs/reading.md#what-a-sheet-shows) says. A DWG needs a reader package
installed beside tsdraft.

## What tsdraft cannot draw yet

- A block read from another file. A block is drawn in the drawing that inserts it. An xref
Expand All @@ -694,7 +731,9 @@ writeFileSync("plan.dxf", toDXF(drawing));
- An existing drawing as a background or a base to edit. `readDXF` reads a DXF's tables, blocks,
layouts and a census of what it draws, and with `geometry` what each space draws, as
[docs/reading.md](docs/reading.md) says, but tsdraft draws nothing from a read and does not read
DWG.
DWG. An edit of a firm's file changes nothing yet: `npx tsdraft write rev-1.edit.ts` makes its
edited copy and the checks of every job, as [docs/editing.md](docs/editing.md) says, and the
copy is the file as it was.

When a drawing needs one of these, say so. Do not imitate it with something that will mislead
whoever opens the file.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ it is given its own. `DASHED`, `HIDDEN`, `CENTER`, `PHANTOM`, `DASHDOT` and `DOT
are the leading CAD app's own definitions; `d.linetype({ name, pattern })` defines another,
with dashes as positive lengths, gaps as negative ones and dots as 0. Its `marks` draw texts
along the line, such as a water main's letters, and shapes of a firm's shape file, such as a
fence's circles, which `parseShapes` reads and the plot takes as `shapes`. `parseLinetypes` reads
fence's circles, which `parseShx` reads and the plot takes as `shx`. `parseLinetypes` reads
a firm's linetype file. A polyline's `linetypeGeneration` runs the pattern on past its vertices. A
lineweight is in millimetres.

Expand Down Expand Up @@ -474,7 +474,9 @@ lint(drawing, { version: "R12" }); // check a drawing against another version
footprint that crosses a setback, and the `intent` a drawing file exports.
- [Reading drawing files](docs/reading.md) covers `readDXF`, the read model it gives of a
firm's DXF, and the readers a package adds for other formats.
- [The `tsdraft` command](docs/command.md) covers `render`, `dev`, the JSON they
- [Editing a firm's drawing](docs/editing.md) covers the edit file, the edited copy of a DXF, the
checks of every job and `tsdraft write`.
- [The `tsdraft` command](docs/command.md) covers `render`, `dev`, `write`, the JSON they
give, and what happens without the PNG renderer.

## Development
Expand Down
8 changes: 8 additions & 0 deletions cli/AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,14 @@
is lost.
`test/warm.test.ts` holds all of this by counting what a build reads and by comparing a
warm answer with a cold one, never by timing.
- An edit file builds in two steps. Its own process, as any drawing file's, loads it, builds its
edit, with the source's read from the cache only when the edit asks for it, and answers with
the edit as data, `plan`. The process that keeps the reads, one for the life of a `Builder`,
then draws it: it keeps the source's read and its pictures before the edit as fragments, and
joins them for each edit with `editedPicture`. It loads no drawing file and no module of the
user's, only the command's own library and readers, so it may serve every build. What it
keeps is made again when the read or any file its context read is not as it was. `dev` asks it
for the pictures of changes only when one is fetched; `render` draws them with the build.
- The page in `assets/page.html` has no framework and no build step. It finds an entity's element
by `data-entity="<index>"`, which `toSVG` writes on each element. Position is no guide, since
`toSVG` leaves out entities on layers that are off or frozen. The fallback to position among
Expand Down
40 changes: 39 additions & 1 deletion cli/assets/page.html
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,10 @@ <h3>Diagnostics</h3>
// the layout shown, or null for model space, and stays undefined until one is chosen.
let pictures = { model: null, layouts: [] };
let tab;
// For an edit file, whether the picture of what the edit changes is on screen.
let showChanges = false;
/** Counts the pictures of changes asked for, so only the last one asked is shown. */
let changesAsked = 0;
let entities = [];
let indexed = false;
let fitBox = null;
Expand Down Expand Up @@ -595,6 +599,7 @@ <h3>Diagnostics</h3>
else if (event.key === "+" || event.key === "=") zoom(1 / 1.5);
else if (event.key === "-") zoom(1.5);
else if (event.key === "Escape") select(null);
else if (event.key === "c" || event.key === "C") toggleChanges();
});

/** Shows the picture of the chosen tab: a layout's sheet, or model space. */
Expand All @@ -603,7 +608,8 @@ <h3>Diagnostics</h3>
// A drawing with a layout opens on its first, as CAD does.
if (tab === undefined || (tab !== null && !names.includes(tab))) tab = names[0] ?? null;
const bar = $("tabs");
bar.hidden = names.length === 0;
const changes = lastGood?.outputs?.changes ?? null;
bar.hidden = names.length === 0 && !changes;
// The plot of the sheet on screen, and of the set, as the server makes them.
const plots = lastGood?.outputs;
const sheetPdf = plots?.layouts?.find((sheet) => sheet.name === tab)?.pdf;
Expand Down Expand Up @@ -634,12 +640,43 @@ <h3>Diagnostics</h3>
return button;
}),
...links,
...(changes ? [changesButton()] : []),
);
if (showChanges && changes) {
// The server draws the picture of changes when first asked for.
const url = tab === null ? changes.svg : changes.layouts.find((s) => s.name === tab)?.svg;
if (!url) return;
const asked = ++changesAsked;
fetch(url)
.then((res) => (res.ok ? res.text() : null))
.then((source) => {
if (source && asked === changesAsked && showChanges) showDrawing(source);
});
return;
}
const source =
tab === null ? pictures.model : pictures.layouts.find((s) => s.name === tab)?.svg;
if (source) showDrawing(source);
}

/** The toggle between the edited drawing and the picture of what the edit changes (C). */
function changesButton() {
const button = document.createElement("button");
button.textContent = "Changes";
button.title = "What the edit erases, in red, and moves, in amber (C)";
button.classList.toggle("on", showChanges);
button.addEventListener("click", toggleChanges);
return button;
}

function toggleChanges() {
if (!lastGood?.outputs?.changes) return;
showChanges = !showChanges;
moved = true;
showTab();
paintHidden();
}

function showDrawing(source) {
holder.innerHTML = source;
svg = holder.querySelector("svg");
Expand Down Expand Up @@ -973,6 +1010,7 @@ <h3>Diagnostics</h3>
holder.classList.remove("stale");
svg = null;
pictures = { model: null, layouts: [] };
showChanges = false;
tab = undefined;
$("tabs").hidden = true;
entities = [];
Expand Down
Loading