svelte-highlight 7.22.0 → 7.23.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/engine.d.ts CHANGED
@@ -152,7 +152,8 @@ export interface HighlightResult {
152
152
  * versions: a snapshot produced by an older or newer version of this
153
153
  * package may be rejected on resume. Callers that persist snapshots across
154
154
  * deploys (windowing, long-lived streaming sessions) should pin the engine
155
- * version or be prepared to discard stale snapshots.
155
+ * version or be prepared to discard stale snapshots. Treat a snapshot as
156
+ * read-only: it may share state with the tokenizer that produced it.
156
157
  */
157
158
  export interface Snapshot {
158
159
  pos: number;
@@ -184,15 +185,33 @@ export interface StreamSession {
184
185
  /** Tokenizes text loaded via `createSession`'s `from.code` up to (not
185
186
  * including) the first lexeme starting at or past `stopAt`. */
186
187
  advance(stopAt: number): void;
188
+ /** Same as `append(text.slice(fedLength))`, where `text` is everything
189
+ * fed so far plus more, ideally a slice of one larger string. Avoids
190
+ * re-flattening a concatenated string on every call. */
191
+ feed(text: string): void;
187
192
  /** Replaces `[from, to)` in the session's fed text with `text`, reusing
188
193
  * unaffected tokenized regions where state reconverges (see
189
194
  * `incremental-tokenize.js`). The resulting `events()` are always
190
195
  * identical to a fresh session fed the resulting text from scratch,
191
- * computed cheaper. Does not support replacing across a language change. */
192
- replace(from: number, to: number, text: string): void;
196
+ * computed cheaper. Does not support replacing across a language change.
197
+ * Returns how many leading `events()` entries are the same objects as
198
+ * before the call (0 on the first call, which re-parses). */
199
+ replace(from: number, to: number, text: string): number;
200
+ /** The last of the last `replace()`'s checkpoints (none before the first)
201
+ * within both limits: `events()[0, eventCount)` covers the text before
202
+ * `textPos` and leaves `scopes` open, so rendering can resume there. */
203
+ checkpointBefore(limits: {
204
+ eventCount?: number;
205
+ textPos?: number;
206
+ }): { textPos: number; eventCount: number; scopes: string[] } | undefined;
193
207
  finish(options?: { canonicalize?: boolean }): HighlightResult;
194
208
  snapshot(): Snapshot;
195
209
  events(): ScopeEvent[];
210
+ /** Returns the events produced since the last call and forgets them, so a
211
+ * long session doesn't retain every event. Afterward `events()`,
212
+ * `finish()`, and snapshot `eventCount`s only cover later events; don't
213
+ * mix with `replace()`. */
214
+ takeEvents(): ScopeEvent[];
196
215
  }
197
216
 
198
217
  /** The compiled program `Registry#get` returns; opaque other than its source IR's identity. */
@@ -213,8 +232,9 @@ export class UnknownLanguageError extends Error {
213
232
  }
214
233
 
215
234
  /**
216
- * Thrown by the tokenizer once a parse exceeds 500,000 iterations,
217
- * guarding against a grammar bug that never advances position.
235
+ * Thrown by the tokenizer once a parse exceeds both 500,000 iterations
236
+ * and three iterations per character consumed, guarding against a grammar
237
+ * bug that never advances position.
218
238
  */
219
239
  export class TokenizerLoopError extends Error {
220
240
  constructor(grammarName: string, iterations: number);
@@ -244,7 +264,9 @@ export interface Registry {
244
264
  tokenizeRanges(code: string, options: { language: string }): TokenRange[];
245
265
  createSession(
246
266
  language: string,
247
- options?: { from?: { code: string; snapshot?: Snapshot } },
267
+ options?: {
268
+ from?: { code: string; snapshot?: Snapshot; windowed?: boolean };
269
+ },
248
270
  ): StreamSession;
249
271
  resume(
250
272
  code: string,