| 988 | } |
| 989 | |
| 990 | function selectPreview(previews, selector) { |
| 991 | if (selector == null || selector === "") { |
| 992 | return previews[0]; |
| 993 | } |
| 994 | const numeric = Number(selector); |
| 995 | if (Number.isInteger(numeric)) { |
| 996 | const match = previews[numeric - 1] ?? previews[numeric]; |
| 997 | if (match) { |
| 998 | return match; |
| 999 | } |
| 1000 | } |
| 1001 | const named = previews.find((item) => item.name === selector); |
| 1002 | if (!named) { |
| 1003 | throw new Error( |
| 1004 | `No preview matched ${JSON.stringify(selector)}. Available: ${previews |
| 1005 | .map((item) => item.name || `#${item.index + 1}`) |
| 1006 | .join(", ")}`, |
| 1007 | ); |
| 1008 | } |
| 1009 | return named; |
| 1010 | } |
| 1011 | |
| 1012 | function removeRanges(source, ranges) { |
| 1013 | let output = ""; |