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/scoped.js CHANGED
@@ -112,41 +112,43 @@ function rewriteBlock(prelude, body, transform) {
112
112
  */
113
113
  function rewriteRules(css, transform) {
114
114
  let out = "";
115
- let prelude = "";
115
+ // The prelude is always the contiguous run since the last rule ended, so
116
+ // it's sliced out once instead of built up a char at a time (see
117
+ // bench/scoped.bench.ts).
118
+ let preludeStart = 0;
116
119
  let i = 0;
117
120
  while (i < css.length) {
118
121
  const ch = css[i];
119
122
  if (ch === "/" && css[i + 1] === "*") {
120
123
  const end = css.indexOf("*/", i + 2);
121
- const stop = end === -1 ? css.length : end + 2;
122
- prelude += css.slice(i, stop);
123
- i = stop;
124
+ i = end === -1 ? css.length : end + 2;
124
125
  continue;
125
126
  }
126
127
  if (ch === '"' || ch === "'") {
127
- const stop = findStringEnd(css, i);
128
- prelude += css.slice(i, stop);
129
- i = stop;
128
+ i = findStringEnd(css, i);
130
129
  continue;
131
130
  }
132
131
  if (ch === "{") {
133
132
  const bodyEnd = findBlockEnd(css, i + 1);
134
- out += rewriteBlock(prelude, css.slice(i + 1, bodyEnd), transform);
135
- prelude = "";
133
+ out += rewriteBlock(
134
+ css.slice(preludeStart, i),
135
+ css.slice(i + 1, bodyEnd),
136
+ transform,
137
+ );
136
138
  i = bodyEnd + 1;
139
+ preludeStart = i;
137
140
  continue;
138
141
  }
139
142
  if (ch === ";") {
140
143
  // Blockless at-rule (@import): emit as-is.
141
- out += prelude + ch;
142
- prelude = "";
143
144
  i += 1;
145
+ out += css.slice(preludeStart, i);
146
+ preludeStart = i;
144
147
  continue;
145
148
  }
146
- prelude += ch;
147
149
  i += 1;
148
150
  }
149
- return out + prelude;
151
+ return out + css.slice(preludeStart);
150
152
  }
151
153
 
152
154
  /**
package/search.d.ts CHANGED
@@ -25,14 +25,16 @@ export interface SearchOptions {
25
25
 
26
26
  /**
27
27
  * A plain string (split on `"\n"`), an array of lines used as-is, or a
28
- * duck-typed `TokenizedDocument` (only `lineCount`/`lineRange` are used;
29
- * never checked via `instanceof`) whose highlighted-HTML lines are decoded
30
- * back to plain text before matching.
28
+ * duck-typed `TokenizedDocument` (only `lineCount`/`lineRange`/`textRange`
29
+ * are used; never checked via `instanceof`). Its plain text comes from
30
+ * `textRange` when present, else from `lineRange`'s highlighted-HTML lines
31
+ * decoded back to plain text.
31
32
  */
32
33
  export type SearchSource =
33
34
  | string
34
35
  | string[]
35
- | Pick<TokenizedDocument, "lineCount" | "lineRange">;
36
+ | (Pick<TokenizedDocument, "lineCount" | "lineRange"> &
37
+ Partial<Pick<TokenizedDocument, "textRange">>);
36
38
 
37
39
  export interface Search {
38
40
  /** Runs a new search. Empty `text` clears matches without an error. */