import type { IdfDocument } from '../document.js'; import type { AnyTypeMap } from '../typemap.js'; import type { IdfObject } from '../object.js'; export interface WriteIdfOptions { /** * Emit `!- Field Name` comments after each field. * @defaultValue true */ comments?: boolean; /** * Column the field-name comments are aligned to, counting from 1 as an editor does. * * The default puts `!-` where EnergyPlus itself puts it. Its own example files write the marker * at column 30 on 223 of the 231 commented lines of `1ZoneUncontrolled.idf`, and matching that * is what keeps a rewritten object flush with the untouched objects around it: on a preserving * write, a column of its own would leave a visible seam at every edit. * * @defaultValue 30 */ commentColumn?: number; /** * Indent for field lines. * @defaultValue ' ' */ indent?: string; /** * Write `Version` first regardless of insertion order. EnergyPlus does not * require it, but every tool in the ecosystem expects it and diffs are * cleaner when it is stable. * @defaultValue true */ versionFirst?: boolean; /** * How object types are ordered. * * `'source'` keeps the order the types first appeared in the document, which is what this writer * has always done and remains the default: no default moves (FR-017). `'sorted'` orders them by * type name, which is the other language's default and what its `!-Option SortedOrder` header * declares. * * An enumeration rather than a boolean, because three behaviours exist across the two languages * and two formats and a flag cannot say which of the three is wanted. * * Orthogonal to `versionFirst`, which pins `Version` ahead of whichever order this selects. * * @defaultValue 'source' */ ordering?: 'sorted' | 'source'; /** * Put each object on a single line, with no comments and no blank separators. * * The counterpart of the other language's `output_type="compressed"`, and it means the same * thing: type name and values joined by commas, one object per line, no generator header, no * blank line between objects. The corpus checks that the two agree structurally rather than * textually, because the two writers differ on defaults that compressed output does not remove. * * `comments: false` is not this. That skips the padding and the comment and still puts every * field on its own line, which is a different, coarser output that both languages already had. * * @defaultValue false */ compressed?: boolean; /** * Reproduce the text the document was read from, per object. * * Tri-state: absent decides from the document and the other options, `true` preserves and * refuses a contradictory request, `false` formats. Asking for it on a document read without it * is not an error, because nothing was promised. * * Refused together with `indent`, `commentColumn`, `ordering` or `versionFirst`: reproducing the * original text and laying it out differently are contradictory. Not refused with `compressed` * or `comments: false`, which ask for a different output FORM the source was never going to * express, so producing it is honest. * * Cheapest where it is used: a write that reproduces most of the file copies text rather than * building it. It CROSSES OVER once most objects have changed, because this path renders each of * them AND walks the tiling, which is more work than formatting alone. On a 13 MB model with * every object edited it is roughly four times slower than a formatting write. Nothing to guard * against, since an edit touches a handful of objects and a whole model rewrite is what * `preserveFormatting: false` is for, but worth knowing before timing the wrong one. * * @defaultValue undefined, meaning decide */ preserveFormatting?: boolean; /** * What to do about a field the author deliberately left without a comment. * * Only meaningful on the preserving path, which is the only path that knows what the author * wrote. `'preserve'` leaves a bare field bare, because absence is as much a thing the author * wrote as the words are. `'generate'` labels it, for a caller who wants the file annotated. * * Neither setting touches the author's own comment lines. A comment between two objects is * carried by the text between them, and a comment on its own line inside an object is emitted * with the field below it, so asking for labels adds them and never costs a line. * * @defaultValue 'preserve' */ fieldComments?: 'preserve' | 'generate'; } /** * Serialize a document to IDF text. * * Two behaviours, chosen by how the document was read. A document read with `preserveFormatting` * is written back per object: anything unchanged is reproduced from the characters it was read * from, and everything between the objects is copied. A document read without it is formatted, * which is what this writer has always done and still does by default. * * The caveat that used to be stated here applies to the formatting path alone: `3.0` comes back as * `3` for a field the schema does not declare numeric. On the preserving path nothing is * re-rendered, so nothing is lost. */ export declare function writeIdf(document: IdfDocument, options?: WriteIdfOptions): string; /** Where `!-` goes, counted from 1. See {@link WriteIdfOptions.commentColumn}. */ export declare const DEFAULT_COMMENT_COLUMN = 30; /** The indent before each field line. See {@link WriteIdfOptions.indent}. */ export declare const DEFAULT_INDENT = " "; /** * The options a PRESERVING write resolves, which is the only set a preserved object can be * rendered on. * * `IdfDocument.renderObject` has to produce exactly the bytes this walk produces, so it resolves * its options here rather than restating the defaults. Restating them is how the two drift: the * comment column has a reason behind its value, and moving that reason in one place while the * other kept the old number would break the byte-for-byte agreement `renderObject` promises. * * The controls are not read from the caller because a preserving write refuses them. `indent`, * `commentColumn`, `ordering` and `versionFirst` throw when set alongside `preserveFormatting`, * and `comments: false` and `compressed` defeat preservation and send the document down the * formatting path, so on this path they are always their defaults. */ export declare function preservingOptions(options: WriteIdfOptions): ObjectWriteOptions; export interface ObjectWriteOptions { comments: boolean; /** Where `!-` goes, counted from 1. See {@link WriteIdfOptions.commentColumn}. */ commentColumn: number; indent: string; /** Put the whole object on one line. See `WriteIdfOptions.compressed`. */ compressed?: boolean; } /** Serialize one object. */ export declare function writeObject(obj: IdfObject, options: ObjectWriteOptions): string; //# sourceMappingURL=idf.d.ts.map