the editable site (validation-lab)
This commit is contained in:
commit
3ac81d5a52
13454 files changed
+2227005
No files matched your search
+22
@@ -0,0 +1,22 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2021 Pine Wu
|
||||
Copyright (c) 2023 Anthony Fu <https://github.com/antfu>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
# @shikijs/engine-oniguruma
|
||||
|
||||
Engine for Shiki using Oniguruma RegExp engine in WebAssembly.
|
||||
|
||||
[Documentation](https://shiki.style/guide/regex-engines)
|
||||
|
||||
## License
|
||||
|
||||
MIT
|
||||
+70
@@ -0,0 +1,70 @@
|
||||
interface IOnigCaptureIndex {
|
||||
start: number;
|
||||
end: number;
|
||||
length: number;
|
||||
}
|
||||
interface IOnigMatch {
|
||||
index: number;
|
||||
captureIndices: IOnigCaptureIndex[];
|
||||
}
|
||||
declare const enum FindOption {
|
||||
None = 0,
|
||||
/**
|
||||
* equivalent of ONIG_OPTION_NOT_BEGIN_STRING: (str) isn't considered as begin of string (* fail \A)
|
||||
*/
|
||||
NotBeginString = 1,
|
||||
/**
|
||||
* equivalent of ONIG_OPTION_NOT_END_STRING: (end) isn't considered as end of string (* fail \z, \Z)
|
||||
*/
|
||||
NotEndString = 2,
|
||||
/**
|
||||
* equivalent of ONIG_OPTION_NOT_BEGIN_POSITION: (start) isn't considered as start position of search (* fail \G)
|
||||
*/
|
||||
NotBeginPosition = 4,
|
||||
/**
|
||||
* used for debugging purposes.
|
||||
*/
|
||||
DebugCall = 8
|
||||
}
|
||||
interface OnigScanner {
|
||||
findNextMatchSync(string: string | OnigString, startPosition: number, options: OrMask<FindOption>): IOnigMatch | null;
|
||||
dispose?(): void;
|
||||
}
|
||||
interface OnigString {
|
||||
readonly content: string;
|
||||
dispose?(): void;
|
||||
}
|
||||
|
||||
/**
|
||||
* A union of given const enum values.
|
||||
*/
|
||||
type OrMask<T extends number> = number;
|
||||
|
||||
type Awaitable<T> = T | Promise<T>;
|
||||
|
||||
interface PatternScanner extends OnigScanner {
|
||||
}
|
||||
interface RegexEngineString extends OnigString {
|
||||
}
|
||||
/**
|
||||
* Engine for RegExp matching and scanning.
|
||||
*/
|
||||
interface RegexEngine {
|
||||
createScanner: (patterns: (string | RegExp)[]) => PatternScanner;
|
||||
createString: (s: string) => RegexEngineString;
|
||||
}
|
||||
interface WebAssemblyInstantiator {
|
||||
(importObject: Record<string, Record<string, WebAssembly.ImportValue>> | undefined): Promise<WebAssemblyInstance>;
|
||||
}
|
||||
type WebAssemblyInstance = WebAssembly.WebAssemblyInstantiatedSource | WebAssembly.Instance | WebAssembly.Instance['exports'];
|
||||
type OnigurumaLoadOptions = {
|
||||
instantiator: WebAssemblyInstantiator;
|
||||
} | {
|
||||
default: WebAssemblyInstantiator;
|
||||
} | {
|
||||
data: ArrayBufferView | ArrayBuffer | Response;
|
||||
};
|
||||
type LoadWasmOptionsPlain = OnigurumaLoadOptions | WebAssemblyInstantiator | ArrayBufferView | ArrayBuffer | Response;
|
||||
type LoadWasmOptions = Awaitable<LoadWasmOptionsPlain> | (() => Awaitable<LoadWasmOptionsPlain>);
|
||||
|
||||
export type { LoadWasmOptions as L, RegexEngine as R, WebAssemblyInstantiator as W };
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
import { L as LoadWasmOptions, R as RegexEngine } from './chunk-index.d.mjs';
|
||||
|
||||
declare function loadWasm(options: LoadWasmOptions): Promise<void>;
|
||||
|
||||
/**
|
||||
* Set the default wasm loader for `loadWasm`.
|
||||
* @internal
|
||||
*/
|
||||
declare function setDefaultWasmLoader(_loader: LoadWasmOptions): void;
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
declare function getDefaultWasmLoader(): LoadWasmOptions | undefined;
|
||||
declare function createOnigurumaEngine(options?: LoadWasmOptions | null): Promise<RegexEngine>;
|
||||
|
||||
export { createOnigurumaEngine, getDefaultWasmLoader, loadWasm, setDefaultWasmLoader };
|
||||
+448
@@ -0,0 +1,448 @@
|
||||
class ShikiError extends Error {
|
||||
constructor(message) {
|
||||
super(message);
|
||||
this.name = "ShikiError";
|
||||
}
|
||||
}
|
||||
|
||||
function getHeapMax() {
|
||||
return 2147483648;
|
||||
}
|
||||
function _emscripten_get_now() {
|
||||
return typeof performance !== "undefined" ? performance.now() : Date.now();
|
||||
}
|
||||
const alignUp = (x, multiple) => x + (multiple - x % multiple) % multiple;
|
||||
async function main(init) {
|
||||
let wasmMemory;
|
||||
let buffer;
|
||||
const binding = {};
|
||||
function updateGlobalBufferAndViews(buf) {
|
||||
buffer = buf;
|
||||
binding.HEAPU8 = new Uint8Array(buf);
|
||||
binding.HEAPU32 = new Uint32Array(buf);
|
||||
}
|
||||
function _emscripten_memcpy_big(dest, src, num) {
|
||||
binding.HEAPU8.copyWithin(dest, src, src + num);
|
||||
}
|
||||
function emscripten_realloc_buffer(size) {
|
||||
try {
|
||||
wasmMemory.grow(size - buffer.byteLength + 65535 >>> 16);
|
||||
updateGlobalBufferAndViews(wasmMemory.buffer);
|
||||
return 1;
|
||||
} catch {
|
||||
}
|
||||
}
|
||||
function _emscripten_resize_heap(requestedSize) {
|
||||
const oldSize = binding.HEAPU8.length;
|
||||
requestedSize = requestedSize >>> 0;
|
||||
const maxHeapSize = getHeapMax();
|
||||
if (requestedSize > maxHeapSize)
|
||||
return false;
|
||||
for (let cutDown = 1; cutDown <= 4; cutDown *= 2) {
|
||||
let overGrownHeapSize = oldSize * (1 + 0.2 / cutDown);
|
||||
overGrownHeapSize = Math.min(overGrownHeapSize, requestedSize + 100663296);
|
||||
const newSize = Math.min(maxHeapSize, alignUp(Math.max(requestedSize, overGrownHeapSize), 65536));
|
||||
const replacement = emscripten_realloc_buffer(newSize);
|
||||
if (replacement)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
const UTF8Decoder = typeof TextDecoder != "undefined" ? new TextDecoder("utf8") : void 0;
|
||||
function UTF8ArrayToString(heapOrArray, idx, maxBytesToRead = 1024) {
|
||||
const endIdx = idx + maxBytesToRead;
|
||||
let endPtr = idx;
|
||||
while (heapOrArray[endPtr] && !(endPtr >= endIdx)) ++endPtr;
|
||||
if (endPtr - idx > 16 && heapOrArray.buffer && UTF8Decoder) {
|
||||
return UTF8Decoder.decode(heapOrArray.subarray(idx, endPtr));
|
||||
}
|
||||
let str = "";
|
||||
while (idx < endPtr) {
|
||||
let u0 = heapOrArray[idx++];
|
||||
if (!(u0 & 128)) {
|
||||
str += String.fromCharCode(u0);
|
||||
continue;
|
||||
}
|
||||
const u1 = heapOrArray[idx++] & 63;
|
||||
if ((u0 & 224) === 192) {
|
||||
str += String.fromCharCode((u0 & 31) << 6 | u1);
|
||||
continue;
|
||||
}
|
||||
const u2 = heapOrArray[idx++] & 63;
|
||||
if ((u0 & 240) === 224) {
|
||||
u0 = (u0 & 15) << 12 | u1 << 6 | u2;
|
||||
} else {
|
||||
u0 = (u0 & 7) << 18 | u1 << 12 | u2 << 6 | heapOrArray[idx++] & 63;
|
||||
}
|
||||
if (u0 < 65536) {
|
||||
str += String.fromCharCode(u0);
|
||||
} else {
|
||||
const ch = u0 - 65536;
|
||||
str += String.fromCharCode(55296 | ch >> 10, 56320 | ch & 1023);
|
||||
}
|
||||
}
|
||||
return str;
|
||||
}
|
||||
function UTF8ToString(ptr, maxBytesToRead) {
|
||||
return ptr ? UTF8ArrayToString(binding.HEAPU8, ptr, maxBytesToRead) : "";
|
||||
}
|
||||
const asmLibraryArg = {
|
||||
emscripten_get_now: _emscripten_get_now,
|
||||
emscripten_memcpy_big: _emscripten_memcpy_big,
|
||||
emscripten_resize_heap: _emscripten_resize_heap,
|
||||
fd_write: () => 0
|
||||
};
|
||||
async function createWasm() {
|
||||
const info = {
|
||||
env: asmLibraryArg,
|
||||
wasi_snapshot_preview1: asmLibraryArg
|
||||
};
|
||||
const exports$1 = await init(info);
|
||||
wasmMemory = exports$1.memory;
|
||||
updateGlobalBufferAndViews(wasmMemory.buffer);
|
||||
Object.assign(binding, exports$1);
|
||||
binding.UTF8ToString = UTF8ToString;
|
||||
}
|
||||
await createWasm();
|
||||
return binding;
|
||||
}
|
||||
|
||||
var __defProp = Object.defineProperty;
|
||||
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
||||
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
||||
let onigBinding = null;
|
||||
function throwLastOnigError(onigBinding2) {
|
||||
throw new ShikiError(onigBinding2.UTF8ToString(onigBinding2.getLastOnigError()));
|
||||
}
|
||||
class UtfString {
|
||||
constructor(str) {
|
||||
__publicField(this, "utf16Length");
|
||||
__publicField(this, "utf8Length");
|
||||
__publicField(this, "utf16Value");
|
||||
__publicField(this, "utf8Value");
|
||||
__publicField(this, "utf16OffsetToUtf8");
|
||||
__publicField(this, "utf8OffsetToUtf16");
|
||||
const utf16Length = str.length;
|
||||
const utf8Length = UtfString._utf8ByteLength(str);
|
||||
const computeIndicesMapping = utf8Length !== utf16Length;
|
||||
const utf16OffsetToUtf8 = computeIndicesMapping ? new Uint32Array(utf16Length + 1) : null;
|
||||
if (computeIndicesMapping)
|
||||
utf16OffsetToUtf8[utf16Length] = utf8Length;
|
||||
const utf8OffsetToUtf16 = computeIndicesMapping ? new Uint32Array(utf8Length + 1) : null;
|
||||
if (computeIndicesMapping)
|
||||
utf8OffsetToUtf16[utf8Length] = utf16Length;
|
||||
const utf8Value = new Uint8Array(utf8Length);
|
||||
let i8 = 0;
|
||||
for (let i16 = 0; i16 < utf16Length; i16++) {
|
||||
const charCode = str.charCodeAt(i16);
|
||||
let codePoint = charCode;
|
||||
let wasSurrogatePair = false;
|
||||
if (charCode >= 55296 && charCode <= 56319) {
|
||||
if (i16 + 1 < utf16Length) {
|
||||
const nextCharCode = str.charCodeAt(i16 + 1);
|
||||
if (nextCharCode >= 56320 && nextCharCode <= 57343) {
|
||||
codePoint = (charCode - 55296 << 10) + 65536 | nextCharCode - 56320;
|
||||
wasSurrogatePair = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (computeIndicesMapping) {
|
||||
utf16OffsetToUtf8[i16] = i8;
|
||||
if (wasSurrogatePair)
|
||||
utf16OffsetToUtf8[i16 + 1] = i8;
|
||||
if (codePoint <= 127) {
|
||||
utf8OffsetToUtf16[i8 + 0] = i16;
|
||||
} else if (codePoint <= 2047) {
|
||||
utf8OffsetToUtf16[i8 + 0] = i16;
|
||||
utf8OffsetToUtf16[i8 + 1] = i16;
|
||||
} else if (codePoint <= 65535) {
|
||||
utf8OffsetToUtf16[i8 + 0] = i16;
|
||||
utf8OffsetToUtf16[i8 + 1] = i16;
|
||||
utf8OffsetToUtf16[i8 + 2] = i16;
|
||||
} else {
|
||||
utf8OffsetToUtf16[i8 + 0] = i16;
|
||||
utf8OffsetToUtf16[i8 + 1] = i16;
|
||||
utf8OffsetToUtf16[i8 + 2] = i16;
|
||||
utf8OffsetToUtf16[i8 + 3] = i16;
|
||||
}
|
||||
}
|
||||
if (codePoint <= 127) {
|
||||
utf8Value[i8++] = codePoint;
|
||||
} else if (codePoint <= 2047) {
|
||||
utf8Value[i8++] = 192 | (codePoint & 1984) >>> 6;
|
||||
utf8Value[i8++] = 128 | (codePoint & 63) >>> 0;
|
||||
} else if (codePoint <= 65535) {
|
||||
utf8Value[i8++] = 224 | (codePoint & 61440) >>> 12;
|
||||
utf8Value[i8++] = 128 | (codePoint & 4032) >>> 6;
|
||||
utf8Value[i8++] = 128 | (codePoint & 63) >>> 0;
|
||||
} else {
|
||||
utf8Value[i8++] = 240 | (codePoint & 1835008) >>> 18;
|
||||
utf8Value[i8++] = 128 | (codePoint & 258048) >>> 12;
|
||||
utf8Value[i8++] = 128 | (codePoint & 4032) >>> 6;
|
||||
utf8Value[i8++] = 128 | (codePoint & 63) >>> 0;
|
||||
}
|
||||
if (wasSurrogatePair)
|
||||
i16++;
|
||||
}
|
||||
this.utf16Length = utf16Length;
|
||||
this.utf8Length = utf8Length;
|
||||
this.utf16Value = str;
|
||||
this.utf8Value = utf8Value;
|
||||
this.utf16OffsetToUtf8 = utf16OffsetToUtf8;
|
||||
this.utf8OffsetToUtf16 = utf8OffsetToUtf16;
|
||||
}
|
||||
static _utf8ByteLength(str) {
|
||||
let result = 0;
|
||||
for (let i = 0, len = str.length; i < len; i++) {
|
||||
const charCode = str.charCodeAt(i);
|
||||
let codepoint = charCode;
|
||||
let wasSurrogatePair = false;
|
||||
if (charCode >= 55296 && charCode <= 56319) {
|
||||
if (i + 1 < len) {
|
||||
const nextCharCode = str.charCodeAt(i + 1);
|
||||
if (nextCharCode >= 56320 && nextCharCode <= 57343) {
|
||||
codepoint = (charCode - 55296 << 10) + 65536 | nextCharCode - 56320;
|
||||
wasSurrogatePair = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (codepoint <= 127)
|
||||
result += 1;
|
||||
else if (codepoint <= 2047)
|
||||
result += 2;
|
||||
else if (codepoint <= 65535)
|
||||
result += 3;
|
||||
else
|
||||
result += 4;
|
||||
if (wasSurrogatePair)
|
||||
i++;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
createString(onigBinding2) {
|
||||
const result = onigBinding2.omalloc(this.utf8Length);
|
||||
onigBinding2.HEAPU8.set(this.utf8Value, result);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
const _OnigString = class _OnigString {
|
||||
constructor(str) {
|
||||
__publicField(this, "id", ++_OnigString.LAST_ID);
|
||||
__publicField(this, "_onigBinding");
|
||||
__publicField(this, "content");
|
||||
__publicField(this, "utf16Length");
|
||||
__publicField(this, "utf8Length");
|
||||
__publicField(this, "utf16OffsetToUtf8");
|
||||
__publicField(this, "utf8OffsetToUtf16");
|
||||
__publicField(this, "ptr");
|
||||
if (!onigBinding)
|
||||
throw new ShikiError("Must invoke loadWasm first.");
|
||||
this._onigBinding = onigBinding;
|
||||
this.content = str;
|
||||
const utfString = new UtfString(str);
|
||||
this.utf16Length = utfString.utf16Length;
|
||||
this.utf8Length = utfString.utf8Length;
|
||||
this.utf16OffsetToUtf8 = utfString.utf16OffsetToUtf8;
|
||||
this.utf8OffsetToUtf16 = utfString.utf8OffsetToUtf16;
|
||||
if (this.utf8Length < 1e4 && !_OnigString._sharedPtrInUse) {
|
||||
if (!_OnigString._sharedPtr)
|
||||
_OnigString._sharedPtr = onigBinding.omalloc(1e4);
|
||||
_OnigString._sharedPtrInUse = true;
|
||||
onigBinding.HEAPU8.set(utfString.utf8Value, _OnigString._sharedPtr);
|
||||
this.ptr = _OnigString._sharedPtr;
|
||||
} else {
|
||||
this.ptr = utfString.createString(onigBinding);
|
||||
}
|
||||
}
|
||||
convertUtf8OffsetToUtf16(utf8Offset) {
|
||||
if (this.utf8OffsetToUtf16) {
|
||||
if (utf8Offset < 0)
|
||||
return 0;
|
||||
if (utf8Offset > this.utf8Length)
|
||||
return this.utf16Length;
|
||||
return this.utf8OffsetToUtf16[utf8Offset];
|
||||
}
|
||||
return utf8Offset;
|
||||
}
|
||||
convertUtf16OffsetToUtf8(utf16Offset) {
|
||||
if (this.utf16OffsetToUtf8) {
|
||||
if (utf16Offset < 0)
|
||||
return 0;
|
||||
if (utf16Offset > this.utf16Length)
|
||||
return this.utf8Length;
|
||||
return this.utf16OffsetToUtf8[utf16Offset];
|
||||
}
|
||||
return utf16Offset;
|
||||
}
|
||||
dispose() {
|
||||
if (this.ptr === _OnigString._sharedPtr)
|
||||
_OnigString._sharedPtrInUse = false;
|
||||
else
|
||||
this._onigBinding.ofree(this.ptr);
|
||||
}
|
||||
};
|
||||
__publicField(_OnigString, "LAST_ID", 0);
|
||||
__publicField(_OnigString, "_sharedPtr", 0);
|
||||
// a pointer to a string of 10000 bytes
|
||||
__publicField(_OnigString, "_sharedPtrInUse", false);
|
||||
let OnigString = _OnigString;
|
||||
class OnigScanner {
|
||||
constructor(patterns) {
|
||||
__publicField(this, "_onigBinding");
|
||||
__publicField(this, "_ptr");
|
||||
if (!onigBinding)
|
||||
throw new ShikiError("Must invoke loadWasm first.");
|
||||
const strPtrsArr = [];
|
||||
const strLenArr = [];
|
||||
for (let i = 0, len = patterns.length; i < len; i++) {
|
||||
const utfString = new UtfString(patterns[i]);
|
||||
strPtrsArr[i] = utfString.createString(onigBinding);
|
||||
strLenArr[i] = utfString.utf8Length;
|
||||
}
|
||||
const strPtrsPtr = onigBinding.omalloc(4 * patterns.length);
|
||||
onigBinding.HEAPU32.set(strPtrsArr, strPtrsPtr / 4);
|
||||
const strLenPtr = onigBinding.omalloc(4 * patterns.length);
|
||||
onigBinding.HEAPU32.set(strLenArr, strLenPtr / 4);
|
||||
const scannerPtr = onigBinding.createOnigScanner(strPtrsPtr, strLenPtr, patterns.length);
|
||||
for (let i = 0, len = patterns.length; i < len; i++)
|
||||
onigBinding.ofree(strPtrsArr[i]);
|
||||
onigBinding.ofree(strLenPtr);
|
||||
onigBinding.ofree(strPtrsPtr);
|
||||
if (scannerPtr === 0)
|
||||
throwLastOnigError(onigBinding);
|
||||
this._onigBinding = onigBinding;
|
||||
this._ptr = scannerPtr;
|
||||
}
|
||||
dispose() {
|
||||
this._onigBinding.freeOnigScanner(this._ptr);
|
||||
}
|
||||
findNextMatchSync(string, startPosition, arg) {
|
||||
let options = 0 /* None */;
|
||||
if (typeof arg === "number") {
|
||||
options = arg;
|
||||
}
|
||||
if (typeof string === "string") {
|
||||
string = new OnigString(string);
|
||||
const result = this._findNextMatchSync(string, startPosition, false, options);
|
||||
string.dispose();
|
||||
return result;
|
||||
}
|
||||
return this._findNextMatchSync(string, startPosition, false, options);
|
||||
}
|
||||
_findNextMatchSync(string, startPosition, debugCall, options) {
|
||||
const onigBinding2 = this._onigBinding;
|
||||
const resultPtr = onigBinding2.findNextOnigScannerMatch(this._ptr, string.id, string.ptr, string.utf8Length, string.convertUtf16OffsetToUtf8(startPosition), options);
|
||||
if (resultPtr === 0) {
|
||||
return null;
|
||||
}
|
||||
const HEAPU32 = onigBinding2.HEAPU32;
|
||||
let offset = resultPtr / 4;
|
||||
const index = HEAPU32[offset++];
|
||||
const count = HEAPU32[offset++];
|
||||
const captureIndices = [];
|
||||
for (let i = 0; i < count; i++) {
|
||||
const beg = string.convertUtf8OffsetToUtf16(HEAPU32[offset++]);
|
||||
const end = string.convertUtf8OffsetToUtf16(HEAPU32[offset++]);
|
||||
captureIndices[i] = {
|
||||
start: beg,
|
||||
end,
|
||||
length: end - beg
|
||||
};
|
||||
}
|
||||
return {
|
||||
index,
|
||||
captureIndices
|
||||
};
|
||||
}
|
||||
}
|
||||
function isInstantiatorOptionsObject(dataOrOptions) {
|
||||
return typeof dataOrOptions.instantiator === "function";
|
||||
}
|
||||
function isInstantiatorModule(dataOrOptions) {
|
||||
return typeof dataOrOptions.default === "function";
|
||||
}
|
||||
function isDataOptionsObject(dataOrOptions) {
|
||||
return typeof dataOrOptions.data !== "undefined";
|
||||
}
|
||||
function isResponse(dataOrOptions) {
|
||||
return typeof Response !== "undefined" && dataOrOptions instanceof Response;
|
||||
}
|
||||
function isArrayBuffer(data) {
|
||||
return typeof ArrayBuffer !== "undefined" && (data instanceof ArrayBuffer || ArrayBuffer.isView(data)) || typeof Buffer !== "undefined" && Buffer.isBuffer?.(data) || typeof SharedArrayBuffer !== "undefined" && data instanceof SharedArrayBuffer || typeof Uint32Array !== "undefined" && data instanceof Uint32Array;
|
||||
}
|
||||
let initPromise;
|
||||
function loadWasm(options) {
|
||||
if (initPromise)
|
||||
return initPromise;
|
||||
async function _load() {
|
||||
onigBinding = await main(async (info) => {
|
||||
let instance = options;
|
||||
instance = await instance;
|
||||
if (typeof instance === "function")
|
||||
instance = await instance(info);
|
||||
if (typeof instance === "function")
|
||||
instance = await instance(info);
|
||||
if (isInstantiatorOptionsObject(instance)) {
|
||||
instance = await instance.instantiator(info);
|
||||
} else if (isInstantiatorModule(instance)) {
|
||||
instance = await instance.default(info);
|
||||
} else {
|
||||
if (isDataOptionsObject(instance))
|
||||
instance = instance.data;
|
||||
if (isResponse(instance)) {
|
||||
if (typeof WebAssembly.instantiateStreaming === "function")
|
||||
instance = await _makeResponseStreamingLoader(instance)(info);
|
||||
else
|
||||
instance = await _makeResponseNonStreamingLoader(instance)(info);
|
||||
} else if (isArrayBuffer(instance)) {
|
||||
instance = await _makeArrayBufferLoader(instance)(info);
|
||||
} else if (instance instanceof WebAssembly.Module) {
|
||||
instance = await _makeArrayBufferLoader(instance)(info);
|
||||
} else if ("default" in instance && instance.default instanceof WebAssembly.Module) {
|
||||
instance = await _makeArrayBufferLoader(instance.default)(info);
|
||||
}
|
||||
}
|
||||
if ("instance" in instance)
|
||||
instance = instance.instance;
|
||||
if ("exports" in instance)
|
||||
instance = instance.exports;
|
||||
return instance;
|
||||
});
|
||||
}
|
||||
initPromise = _load();
|
||||
return initPromise;
|
||||
}
|
||||
function _makeArrayBufferLoader(data) {
|
||||
return (importObject) => WebAssembly.instantiate(data, importObject);
|
||||
}
|
||||
function _makeResponseStreamingLoader(data) {
|
||||
return (importObject) => WebAssembly.instantiateStreaming(data, importObject);
|
||||
}
|
||||
function _makeResponseNonStreamingLoader(data) {
|
||||
return async (importObject) => {
|
||||
const arrayBuffer = await data.arrayBuffer();
|
||||
return WebAssembly.instantiate(arrayBuffer, importObject);
|
||||
};
|
||||
}
|
||||
|
||||
let _defaultWasmLoader;
|
||||
function setDefaultWasmLoader(_loader) {
|
||||
_defaultWasmLoader = _loader;
|
||||
}
|
||||
function getDefaultWasmLoader() {
|
||||
return _defaultWasmLoader;
|
||||
}
|
||||
async function createOnigurumaEngine(options) {
|
||||
if (options)
|
||||
await loadWasm(options);
|
||||
return {
|
||||
createScanner(patterns) {
|
||||
return new OnigScanner(patterns.map((p) => typeof p === "string" ? p : p.source));
|
||||
},
|
||||
createString(s) {
|
||||
return new OnigString(s);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export { createOnigurumaEngine, getDefaultWasmLoader, loadWasm, setDefaultWasmLoader };
|
||||
+1
@@ -0,0 +1 @@
|
||||
declare const binary: ArrayBuffer; export default binary;
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
import { W as WebAssemblyInstantiator } from './chunk-index.d.mjs';
|
||||
|
||||
declare const wasmBinary: ArrayBuffer;
|
||||
declare const getWasmInstance: WebAssemblyInstantiator;
|
||||
|
||||
export { getWasmInstance as default, getWasmInstance, wasmBinary };
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
var binary = Uint8Array.from(atob("AGFzbQEAAAABoQEWYAJ/fwF/YAF/AX9gA39/fwF/YAR/f39/AX9gAX8AYAV/f39/fwF/YAN/f38AYAJ/fwBgBn9/f39/fwF/YAd/f39/f39/AX9gAAF/YAl/f39/f39/f38Bf2AIf39/f39/f38Bf2AAAGAEf39/fwBgA39+fwF+YAZ/fH9/f38Bf2AAAXxgBn9/f39/fwBgAnx/AXxgAn5/AX9gBX9/f39/AAJ1BANlbnYVZW1zY3JpcHRlbl9tZW1jcHlfYmlnAAYDZW52EmVtc2NyaXB0ZW5fZ2V0X25vdwARFndhc2lfc25hcHNob3R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ARARCyABEMwBCwvlAgIFfwF+IABBADYCAEF6IQMCQCABKAIAIgJBCEsNAEEBIAJ0QccDcUUNAEEBQTgQzwEiAkUEQEF7DwsgAiABKQIAIgc3AgAgAiABKQIwNwIwIAIgASkCKDcCKCACIAEpAiA3AiAgAkEYaiIDIAEpAhg3AgAgAiABKQIQNwIQIAIgASkCCDcCCAJAAkACQAJAIAenDgIAAQILLine truncated
|
||||
|
||||
const wasmBinary = binary;
|
||||
const getWasmInstance = async (info) => {
|
||||
return WebAssembly.instantiate(wasmBinary, info).then((wasm) => wasm.instance.exports);
|
||||
};
|
||||
|
||||
export { getWasmInstance as default, getWasmInstance, wasmBinary };
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2021 Pine Wu
|
||||
Copyright (c) 2023 Anthony Fu <https://github.com/antfu>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
# @shikijs/types
|
||||
|
||||
Types for Shiki.
|
||||
|
||||
## License
|
||||
|
||||
MIT
|
||||
Generated
Vendored
+885
@@ -0,0 +1,885 @@
|
||||
import { Element, Root } from 'hast';
|
||||
import { OnigScanner, OnigString, IGrammar, IRawGrammar, IRawTheme, IRawThemeSetting, StateStack, FontStyle } from '@shikijs/vscode-textmate';
|
||||
export { IRawGrammar as RawGrammar, IRawTheme as RawTheme, IRawThemeSetting as RawThemeSetting } from '@shikijs/vscode-textmate';
|
||||
|
||||
type Awaitable<T> = T | Promise<T>;
|
||||
type MaybeGetter<T> = Awaitable<MaybeModule<T>> | (() => Awaitable<MaybeModule<T>>);
|
||||
type MaybeModule<T> = T | {
|
||||
default: T;
|
||||
};
|
||||
type MaybeArray<T> = T | T[];
|
||||
type RequireKeys<T, K extends keyof T> = Omit<T, K> & Required<Pick<T, K>>;
|
||||
interface Nothing {
|
||||
}
|
||||
/**
|
||||
* type StringLiteralUnion<'foo'> = 'foo' | string
|
||||
* This has auto completion whereas `'foo' | string` doesn't
|
||||
* Adapted from https://github.com/microsoft/TypeScript/issues/29729
|
||||
*/
|
||||
type StringLiteralUnion<T extends U, U = string> = T | (U & Nothing);
|
||||
|
||||
interface PatternScanner extends OnigScanner {
|
||||
}
|
||||
interface RegexEngineString extends OnigString {
|
||||
}
|
||||
/**
|
||||
* Engine for RegExp matching and scanning.
|
||||
*/
|
||||
interface RegexEngine {
|
||||
createScanner: (patterns: (string | RegExp)[]) => PatternScanner;
|
||||
createString: (s: string) => RegexEngineString;
|
||||
}
|
||||
interface WebAssemblyInstantiator {
|
||||
(importObject: Record<string, Record<string, WebAssembly.ImportValue>> | undefined): Promise<WebAssemblyInstance>;
|
||||
}
|
||||
type WebAssemblyInstance = WebAssembly.WebAssemblyInstantiatedSource | WebAssembly.Instance | WebAssembly.Instance['exports'];
|
||||
type OnigurumaLoadOptions = {
|
||||
instantiator: WebAssemblyInstantiator;
|
||||
} | {
|
||||
default: WebAssemblyInstantiator;
|
||||
} | {
|
||||
data: ArrayBufferView | ArrayBuffer | Response;
|
||||
};
|
||||
type LoadWasmOptionsPlain = OnigurumaLoadOptions | WebAssemblyInstantiator | ArrayBufferView | ArrayBuffer | Response;
|
||||
type LoadWasmOptions = Awaitable<LoadWasmOptionsPlain> | (() => Awaitable<LoadWasmOptionsPlain>);
|
||||
|
||||
interface Grammar extends IGrammar {
|
||||
name: string;
|
||||
}
|
||||
|
||||
type PlainTextLanguage = 'text' | 'plaintext' | 'txt' | 'plain';
|
||||
type AnsiLanguage = 'ansi';
|
||||
type SpecialLanguage = PlainTextLanguage | AnsiLanguage;
|
||||
type LanguageInput = MaybeGetter<MaybeArray<LanguageRegistration>>;
|
||||
type ResolveBundleKey<T extends string> = [T] extends [never] ? string : T;
|
||||
interface LanguageRegistration extends IRawGrammar {
|
||||
name: string;
|
||||
scopeName: string;
|
||||
displayName?: string;
|
||||
aliases?: string[];
|
||||
/**
|
||||
* A list of languages the current language embeds.
|
||||
* If manually specifying languages to load, make sure to load the embedded
|
||||
* languages for each parent language.
|
||||
*/
|
||||
embeddedLangs?: string[];
|
||||
embeddedLanguages?: string[];
|
||||
/**
|
||||
* A list of languages that embed the current language.
|
||||
* Unlike `embeddedLangs`, the embedded languages will not be loaded automatically.
|
||||
*/
|
||||
embeddedLangsLazy?: string[];
|
||||
balancedBracketSelectors?: string[];
|
||||
unbalancedBracketSelectors?: string[];
|
||||
foldingStopMarker?: string;
|
||||
foldingStartMarker?: string;
|
||||
/**
|
||||
* Inject this language to other scopes.
|
||||
* Same as `injectTo` in VSCode's `contributes.grammars`.
|
||||
*
|
||||
* @see https://code.visualstudio.com/api/language-extensions/syntax-highlight-guide#injection-grammars
|
||||
*/
|
||||
injectTo?: string[];
|
||||
}
|
||||
interface BundledLanguageInfo {
|
||||
id: string;
|
||||
name: string;
|
||||
import: DynamicImportLanguageRegistration;
|
||||
aliases?: string[];
|
||||
}
|
||||
type DynamicImportLanguageRegistration = () => Promise<{
|
||||
default: LanguageRegistration[];
|
||||
}>;
|
||||
|
||||
interface DecorationOptions {
|
||||
/**
|
||||
* Custom decorations to wrap highlighted tokens with.
|
||||
*/
|
||||
decorations?: DecorationItem[];
|
||||
}
|
||||
interface DecorationItem {
|
||||
/**
|
||||
* Start offset or position of the decoration.
|
||||
*/
|
||||
start: OffsetOrPosition;
|
||||
/**
|
||||
* End offset or position of the decoration.
|
||||
*/
|
||||
end: OffsetOrPosition;
|
||||
/**
|
||||
* Tag name of the element to create.
|
||||
* @default 'span'
|
||||
*/
|
||||
tagName?: string;
|
||||
/**
|
||||
* Properties of the element to create.
|
||||
*/
|
||||
properties?: Element['properties'];
|
||||
/**
|
||||
* A custom function to transform the element after it has been created.
|
||||
*/
|
||||
transform?: (element: Element, type: DecorationTransformType) => Element | void;
|
||||
/**
|
||||
* By default when the decoration contains only one token, the decoration will be applied to the token.
|
||||
*
|
||||
* Set to `true` to always wrap the token with a new element
|
||||
*
|
||||
* @default false
|
||||
*/
|
||||
alwaysWrap?: boolean;
|
||||
}
|
||||
interface ResolvedDecorationItem extends Omit<DecorationItem, 'start' | 'end'> {
|
||||
start: ResolvedPosition;
|
||||
end: ResolvedPosition;
|
||||
}
|
||||
type DecorationTransformType = 'wrapper' | 'line' | 'token';
|
||||
interface Position {
|
||||
line: number;
|
||||
character: number;
|
||||
}
|
||||
type Offset = number;
|
||||
type OffsetOrPosition = Position | Offset;
|
||||
interface ResolvedPosition extends Position {
|
||||
offset: Offset;
|
||||
}
|
||||
|
||||
type SpecialTheme = 'none';
|
||||
type ThemeInput = MaybeGetter<ThemeRegistrationAny>;
|
||||
interface ThemeRegistrationRaw extends IRawTheme, Partial<Omit<ThemeRegistration, 'name' | 'settings'>> {
|
||||
}
|
||||
interface ThemeRegistration extends Partial<ThemeRegistrationResolved> {
|
||||
}
|
||||
interface ThemeRegistrationResolved extends IRawTheme {
|
||||
/**
|
||||
* Theme name
|
||||
*/
|
||||
name: string;
|
||||
/**
|
||||
* Display name
|
||||
*
|
||||
* @field shiki custom property
|
||||
*/
|
||||
displayName?: string;
|
||||
/**
|
||||
* Light/dark theme
|
||||
*
|
||||
* @field shiki custom property
|
||||
*/
|
||||
type: 'light' | 'dark';
|
||||
/**
|
||||
* Token rules
|
||||
*/
|
||||
settings: IRawThemeSetting[];
|
||||
/**
|
||||
* Same as `settings`, will use as fallback if `settings` is not present.
|
||||
*/
|
||||
tokenColors?: IRawThemeSetting[];
|
||||
/**
|
||||
* Default foreground color
|
||||
*
|
||||
* @field shiki custom property
|
||||
*/
|
||||
fg: string;
|
||||
/**
|
||||
* Background color
|
||||
*
|
||||
* @field shiki custom property
|
||||
*/
|
||||
bg: string;
|
||||
/**
|
||||
* A map of color names to new color values.
|
||||
*
|
||||
* The color key starts with '#' and should be lowercased.
|
||||
*
|
||||
* @field shiki custom property
|
||||
*/
|
||||
colorReplacements?: Record<string, string>;
|
||||
/**
|
||||
* Color map of VS Code options
|
||||
*
|
||||
* Will be used by shiki on `lang: 'ansi'` to find ANSI colors, and to find the default foreground/background colors.
|
||||
*/
|
||||
colors?: Record<string, string>;
|
||||
/**
|
||||
* JSON schema path
|
||||
*
|
||||
* @field not used by shiki
|
||||
*/
|
||||
$schema?: string;
|
||||
/**
|
||||
* Enable semantic highlighting
|
||||
*
|
||||
* @field not used by shiki
|
||||
*/
|
||||
semanticHighlighting?: boolean;
|
||||
/**
|
||||
* Tokens for semantic highlighting
|
||||
*
|
||||
* @field not used by shiki
|
||||
*/
|
||||
semanticTokenColors?: Record<string, string>;
|
||||
}
|
||||
type ThemeRegistrationAny = ThemeRegistrationRaw | ThemeRegistration | ThemeRegistrationResolved;
|
||||
type DynamicImportThemeRegistration = () => Promise<{
|
||||
default: ThemeRegistration;
|
||||
}>;
|
||||
interface BundledThemeInfo {
|
||||
id: string;
|
||||
displayName: string;
|
||||
type: 'light' | 'dark';
|
||||
import: DynamicImportThemeRegistration;
|
||||
}
|
||||
|
||||
/**
|
||||
* GrammarState is a special reference object that holds the state of a grammar.
|
||||
*
|
||||
* It's used to highlight code snippets that are part of the target language.
|
||||
*/
|
||||
interface GrammarState {
|
||||
readonly lang: string;
|
||||
readonly theme: string;
|
||||
readonly themes: string[];
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
getInternalStack: (theme?: string) => StateStack | undefined;
|
||||
getScopes: (theme?: string) => string[] | undefined;
|
||||
}
|
||||
interface CodeToTokensBaseOptions<Languages extends string = string, Themes extends string = string> extends TokenizeWithThemeOptions {
|
||||
lang?: Languages | SpecialLanguage;
|
||||
theme?: Themes | ThemeRegistrationAny | SpecialTheme;
|
||||
}
|
||||
type CodeToTokensOptions<Languages extends string = string, Themes extends string = string> = Omit<CodeToTokensBaseOptions<Languages, Themes>, 'theme'> & CodeOptionsThemes<Themes>;
|
||||
interface CodeToTokensWithThemesOptions<Languages = string, Themes = string> extends TokenizeWithThemeOptions {
|
||||
lang?: Languages | SpecialLanguage;
|
||||
/**
|
||||
* A map of color names to themes.
|
||||
*
|
||||
* `light` and `dark` are required, and arbitrary color names can be added.
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* themes: {
|
||||
* light: 'vitesse-light',
|
||||
* dark: 'vitesse-dark',
|
||||
* soft: 'nord',
|
||||
* // custom colors
|
||||
* }
|
||||
* ```
|
||||
*/
|
||||
themes: Partial<Record<string, Themes | ThemeRegistrationAny | SpecialTheme>>;
|
||||
}
|
||||
interface ThemedTokenScopeExplanation {
|
||||
scopeName: string;
|
||||
themeMatches?: IRawThemeSetting[];
|
||||
}
|
||||
interface ThemedTokenExplanation {
|
||||
content: string;
|
||||
scopes: ThemedTokenScopeExplanation[];
|
||||
}
|
||||
/**
|
||||
* A single token with color, and optionally with explanation.
|
||||
*
|
||||
* For example:
|
||||
*
|
||||
* ```json
|
||||
* {
|
||||
* "content": "shiki",
|
||||
* "color": "#D8DEE9",
|
||||
* "explanation": [
|
||||
* {
|
||||
* "content": "shiki",
|
||||
* "scopes": [
|
||||
* {
|
||||
* "scopeName": "source.js",
|
||||
* "themeMatches": []
|
||||
* },
|
||||
* {
|
||||
* "scopeName": "meta.objectliteral.js",
|
||||
* "themeMatches": []
|
||||
* },
|
||||
* {
|
||||
* "scopeName": "meta.object.member.js",
|
||||
* "themeMatches": []
|
||||
* },
|
||||
* {
|
||||
* "scopeName": "meta.array.literal.js",
|
||||
* "themeMatches": []
|
||||
* },
|
||||
* {
|
||||
* "scopeName": "variable.other.object.js",
|
||||
* "themeMatches": [
|
||||
* {
|
||||
* "name": "Variable",
|
||||
* "scope": "variable.other",
|
||||
* "settings": {
|
||||
* "foreground": "#D8DEE9"
|
||||
* }
|
||||
* },
|
||||
* {
|
||||
* "name": "[JavaScript] Variable Other Object",
|
||||
* "scope": "source.js variable.other.object",
|
||||
* "settings": {
|
||||
* "foreground": "#D8DEE9"
|
||||
* }
|
||||
* }
|
||||
* ]
|
||||
* }
|
||||
* ]
|
||||
* }
|
||||
* ]
|
||||
* }
|
||||
* ```
|
||||
*/
|
||||
interface ThemedToken extends TokenStyles, TokenBase {
|
||||
}
|
||||
interface TokenBase {
|
||||
/**
|
||||
* The content of the token
|
||||
*/
|
||||
content: string;
|
||||
/**
|
||||
* The start offset of the token, relative to the input code. 0-indexed.
|
||||
*/
|
||||
offset: number;
|
||||
/**
|
||||
* Explanation of
|
||||
*
|
||||
* - token text's matching scopes
|
||||
* - reason that token text is given a color (one matching scope matches a rule (scope -> color) in the theme)
|
||||
*/
|
||||
explanation?: ThemedTokenExplanation[];
|
||||
}
|
||||
interface TokenStyles {
|
||||
/**
|
||||
* 6 or 8 digit hex code representation of the token's color
|
||||
*/
|
||||
color?: string;
|
||||
/**
|
||||
* 6 or 8 digit hex code representation of the token's background color
|
||||
*/
|
||||
bgColor?: string;
|
||||
/**
|
||||
* Font style of token. Can be None/Italic/Bold/Underline
|
||||
*/
|
||||
fontStyle?: FontStyle;
|
||||
/**
|
||||
* Override with custom inline style for HTML renderer.
|
||||
* When specified, `color` and `fontStyle` will be ignored.
|
||||
* Prefer use object style for merging with other styles.
|
||||
*/
|
||||
htmlStyle?: Record<string, string>;
|
||||
/**
|
||||
* Extra HTML attributes for the token.
|
||||
*/
|
||||
htmlAttrs?: Record<string, string>;
|
||||
}
|
||||
interface ThemedTokenWithVariants extends TokenBase {
|
||||
/**
|
||||
* An object of color name to token styles
|
||||
*/
|
||||
variants: Record<string, TokenStyles>;
|
||||
}
|
||||
interface TokenizeWithThemeOptions {
|
||||
/**
|
||||
* Include explanation of why a token is given a color.
|
||||
*
|
||||
* You can optionally pass `scopeName` to only include explanation for scopes,
|
||||
* which is more performant than full explanation.
|
||||
*
|
||||
* @default false
|
||||
*/
|
||||
includeExplanation?: boolean | 'scopeName';
|
||||
/**
|
||||
* A map of color names to new color values.
|
||||
*
|
||||
* The color key starts with '#' and should be lowercased.
|
||||
*
|
||||
* This will be merged with theme's `colorReplacements` if any.
|
||||
*/
|
||||
colorReplacements?: Record<string, string | Record<string, string>>;
|
||||
/**
|
||||
* Lines above this length will not be tokenized for performance reasons.
|
||||
*
|
||||
* @default 0 (no limit)
|
||||
*/
|
||||
tokenizeMaxLineLength?: number;
|
||||
/**
|
||||
* Time limit in milliseconds for tokenizing a single line.
|
||||
*
|
||||
* @default 500 (0.5s)
|
||||
*/
|
||||
tokenizeTimeLimit?: number;
|
||||
/**
|
||||
* Represent the state of the grammar, allowing to continue tokenizing from a intermediate grammar state.
|
||||
*
|
||||
* You can get the grammar state from `getLastGrammarState`.
|
||||
*/
|
||||
grammarState?: GrammarState;
|
||||
/**
|
||||
* The code context of the grammar.
|
||||
* Consider it a prepended code to the input code, that only participate the grammar inference but not presented in the final output.
|
||||
*
|
||||
* This will be ignored if `grammarState` is provided.
|
||||
*/
|
||||
grammarContextCode?: string;
|
||||
}
|
||||
/**
|
||||
* Result of `codeToTokens`, an object with 2D array of tokens and meta info like background and foreground color.
|
||||
*/
|
||||
interface TokensResult {
|
||||
/**
|
||||
* 2D array of tokens, first dimension is lines, second dimension is tokens in a line.
|
||||
*/
|
||||
tokens: ThemedToken[][];
|
||||
/**
|
||||
* Foreground color of the code.
|
||||
*/
|
||||
fg?: string;
|
||||
/**
|
||||
* Background color of the code.
|
||||
*/
|
||||
bg?: string;
|
||||
/**
|
||||
* A string representation of themes applied to the token.
|
||||
*/
|
||||
themeName?: string;
|
||||
/**
|
||||
* Custom style string to be applied to the root `<pre>` element.
|
||||
* When specified, `fg` and `bg` will be ignored.
|
||||
*/
|
||||
rootStyle?: string | false;
|
||||
/**
|
||||
* The last grammar state of the code snippet.
|
||||
*/
|
||||
grammarState?: GrammarState;
|
||||
}
|
||||
|
||||
interface TransformerOptions {
|
||||
/**
|
||||
* Transformers for the Shiki pipeline.
|
||||
*/
|
||||
transformers?: ShikiTransformer[];
|
||||
}
|
||||
interface ShikiTransformerContextMeta {
|
||||
}
|
||||
/**
|
||||
* Common transformer context for all transformers hooks
|
||||
*/
|
||||
interface ShikiTransformerContextCommon {
|
||||
meta: ShikiTransformerContextMeta;
|
||||
options: CodeToHastOptions;
|
||||
codeToHast: (code: string, options: CodeToHastOptions) => Root;
|
||||
codeToTokens: (code: string, options: CodeToTokensOptions) => TokensResult;
|
||||
}
|
||||
interface ShikiTransformerContextSource extends ShikiTransformerContextCommon {
|
||||
readonly source: string;
|
||||
}
|
||||
/**
|
||||
* Transformer context for HAST related hooks
|
||||
*/
|
||||
interface ShikiTransformerContext extends ShikiTransformerContextSource {
|
||||
readonly tokens: ThemedToken[][];
|
||||
readonly root: Root;
|
||||
readonly pre: Element;
|
||||
readonly code: Element;
|
||||
readonly lines: Element[];
|
||||
readonly structure: CodeToHastOptions['structure'];
|
||||
/**
|
||||
* Utility to append class to a hast node
|
||||
*
|
||||
* If the `property.class` is a string, it will be splitted by space and converted to an array.
|
||||
*/
|
||||
addClassToHast: (hast: Element, className: string | string[]) => Element;
|
||||
}
|
||||
interface ShikiTransformer {
|
||||
/**
|
||||
* Name of the transformer
|
||||
*/
|
||||
name?: string;
|
||||
/**
|
||||
* Enforce plugin invocation tier similar to webpack loaders. Hooks ordering
|
||||
* is still subject to the `order` property in the hook object.
|
||||
*
|
||||
* Plugin invocation order:
|
||||
* - `enforce: 'pre'` plugins
|
||||
* - normal plugins
|
||||
* - `enforce: 'post'` plugins
|
||||
* - shiki post plugins
|
||||
*/
|
||||
enforce?: 'pre' | 'post';
|
||||
/**
|
||||
* Transform the raw input code before passing to the highlighter.
|
||||
*/
|
||||
preprocess?: (this: ShikiTransformerContextCommon, code: string, options: CodeToHastOptions) => string | void;
|
||||
/**
|
||||
* Transform the full tokens list before converting to HAST.
|
||||
* Return a new tokens list will replace the original one.
|
||||
*/
|
||||
tokens?: (this: ShikiTransformerContextSource, tokens: ThemedToken[][]) => ThemedToken[][] | void;
|
||||
/**
|
||||
* Transform the entire generated HAST tree. Return a new Node will replace the original one.
|
||||
*/
|
||||
root?: (this: ShikiTransformerContext, hast: Root) => Root | void;
|
||||
/**
|
||||
* Transform the `<pre>` element. Return a new Node will replace the original one.
|
||||
*/
|
||||
pre?: (this: ShikiTransformerContext, hast: Element) => Element | void;
|
||||
/**
|
||||
* Transform the `<code>` element. Return a new Node will replace the original one.
|
||||
*/
|
||||
code?: (this: ShikiTransformerContext, hast: Element) => Element | void;
|
||||
/**
|
||||
* Transform each line `<span class="line">` element.
|
||||
*
|
||||
* @param hast
|
||||
* @param line 1-based line number
|
||||
*/
|
||||
line?: (this: ShikiTransformerContext, hast: Element, line: number) => Element | void;
|
||||
/**
|
||||
* Transform each token `<span>` element.
|
||||
*/
|
||||
span?: (this: ShikiTransformerContext, hast: Element, line: number, col: number, lineElement: Element, token: ThemedToken) => Element | void;
|
||||
/**
|
||||
* Transform the generated HTML string before returning.
|
||||
* This hook will only be called with `codeToHtml`.
|
||||
*/
|
||||
postprocess?: (this: ShikiTransformerContextCommon, html: string, options: CodeToHastOptions) => string | void;
|
||||
}
|
||||
|
||||
interface HighlighterCoreOptions<Sync extends boolean = false> {
|
||||
/**
|
||||
* Custom RegExp engine.
|
||||
*/
|
||||
engine: Sync extends true ? RegexEngine : Awaitable<RegexEngine>;
|
||||
/**
|
||||
* Theme names, or theme registration objects to be loaded upfront.
|
||||
*/
|
||||
themes?: Sync extends true ? MaybeArray<ThemeRegistrationAny>[] : ThemeInput[];
|
||||
/**
|
||||
* Language names, or language registration objects to be loaded upfront.
|
||||
*/
|
||||
langs?: Sync extends true ? MaybeArray<LanguageRegistration>[] : LanguageInput[];
|
||||
/**
|
||||
* Alias of languages
|
||||
* @example { 'my-lang': 'javascript' }
|
||||
*/
|
||||
langAlias?: Record<string, string>;
|
||||
/**
|
||||
* Emit console warnings to alert users of potential issues.
|
||||
* @default true
|
||||
*/
|
||||
warnings?: boolean;
|
||||
}
|
||||
interface BundledHighlighterOptions<L extends string, T extends string> extends Pick<HighlighterCoreOptions, 'warnings'> {
|
||||
/**
|
||||
* Custom RegExp engine.
|
||||
*/
|
||||
engine?: Awaitable<RegexEngine>;
|
||||
/**
|
||||
* Theme registation
|
||||
*
|
||||
* @default []
|
||||
*/
|
||||
themes: (ThemeInput | StringLiteralUnion<T> | SpecialTheme)[];
|
||||
/**
|
||||
* Language registation
|
||||
*
|
||||
* @default []
|
||||
*/
|
||||
langs: (LanguageInput | StringLiteralUnion<L> | SpecialLanguage)[];
|
||||
/**
|
||||
* Alias of languages
|
||||
* @example { 'my-lang': 'javascript' }
|
||||
*/
|
||||
langAlias?: Record<string, StringLiteralUnion<L>>;
|
||||
}
|
||||
interface CodeOptionsSingleTheme<Themes extends string = string> {
|
||||
theme: ThemeRegistrationAny | StringLiteralUnion<Themes>;
|
||||
}
|
||||
interface CodeOptionsMultipleThemes<Themes extends string = string> {
|
||||
/**
|
||||
* A map of color names to themes.
|
||||
* This allows you to specify multiple themes for the generated code.
|
||||
*
|
||||
* ```ts
|
||||
* highlighter.codeToHtml(code, {
|
||||
* lang: 'js',
|
||||
* themes: {
|
||||
* light: 'vitesse-light',
|
||||
* dark: 'vitesse-dark',
|
||||
* }
|
||||
* })
|
||||
* ```
|
||||
*
|
||||
* Will generate:
|
||||
*
|
||||
* ```html
|
||||
* <span style="color:#111;--shiki-dark:#fff;">code</span>
|
||||
* ```
|
||||
*
|
||||
* @see https://shiki.style/guide/dual-themes
|
||||
*/
|
||||
themes: Partial<Record<string, ThemeRegistrationAny | StringLiteralUnion<Themes>>>;
|
||||
/**
|
||||
* The default theme applied to the code (via inline `color` style).
|
||||
* The rest of the themes are applied via CSS variables, and toggled by CSS overrides.
|
||||
*
|
||||
* For example, if `defaultColor` is `light`, then `light` theme is applied to the code,
|
||||
* and the `dark` theme and other custom themes are applied via CSS variables:
|
||||
*
|
||||
* ```html
|
||||
* <span style="color:#{light};--shiki-dark:#{dark};--shiki-custom:#{custom};">code</span>
|
||||
* ```
|
||||
*
|
||||
* When set to `false`, no default styles will be applied, and totally up to users to apply the styles:
|
||||
*
|
||||
* ```html
|
||||
* <span style="--shiki-light:#{light};--shiki-dark:#{dark};--shiki-custom:#{custom};">code</span>
|
||||
* ```
|
||||
*
|
||||
* When set to `light-dark()`, the default color will be rendered as `light-dark(#{light}, #{dark})`.
|
||||
*
|
||||
* ```html
|
||||
* <span style="color:light-dark(#{light}, #{dark});--shiki-dark:#{dark};--shiki-custom:#{custom};">code</span>
|
||||
* ```
|
||||
*
|
||||
* @default 'light'
|
||||
*/
|
||||
defaultColor?: StringLiteralUnion<'light' | 'dark'> | 'light-dark()' | false;
|
||||
/**
|
||||
* The strategy to render multiple colors.
|
||||
*
|
||||
* - `css-vars`: Render the colors via CSS variables.
|
||||
* - `none`: Do not render the colors, only use the default color.
|
||||
*
|
||||
* @default 'css-vars'
|
||||
*/
|
||||
colorsRendering?: 'css-vars' | 'none';
|
||||
/**
|
||||
* Prefix of CSS variables used to store the color of the other theme.
|
||||
*
|
||||
* @default '--shiki-'
|
||||
*/
|
||||
cssVariablePrefix?: string;
|
||||
}
|
||||
type CodeOptionsThemes<Themes extends string = string> = CodeOptionsSingleTheme<Themes> | CodeOptionsMultipleThemes<Themes>;
|
||||
type CodeToHastOptions<Languages extends string = string, Themes extends string = string> = CodeToHastOptionsCommon<Languages> & CodeOptionsThemes<Themes> & CodeOptionsMeta;
|
||||
interface CodeToHastOptionsCommon<Languages extends string = string> extends TransformerOptions, DecorationOptions, Pick<TokenizeWithThemeOptions, 'colorReplacements' | 'tokenizeMaxLineLength' | 'tokenizeTimeLimit' | 'grammarState' | 'grammarContextCode' | 'includeExplanation'> {
|
||||
/**
|
||||
* Data to be added to the root `<pre>` element.
|
||||
*/
|
||||
data?: Record<string, unknown>;
|
||||
/**
|
||||
* The grammar name for the code.
|
||||
*/
|
||||
lang: StringLiteralUnion<Languages | SpecialLanguage>;
|
||||
/**
|
||||
* Custom style string to be applied to the root `<pre>` element.
|
||||
*
|
||||
* When set to `false`, no style will be applied.
|
||||
*/
|
||||
rootStyle?: string | false;
|
||||
/**
|
||||
* Merge whitespace tokens to saving extra `<span>`.
|
||||
*
|
||||
* When set to true, it will merge whitespace tokens with the next token.
|
||||
* When set to false, it keep the output as-is.
|
||||
* When set to `never`, it will force to separate leading and trailing spaces from tokens.
|
||||
*
|
||||
* @default true
|
||||
*/
|
||||
mergeWhitespaces?: boolean | 'never';
|
||||
/**
|
||||
* Merge consecutive tokens with the same style to reduce the number of DOM nodes.
|
||||
* This can improve rendering performance but may affect the structure of the output.
|
||||
*
|
||||
* @default false
|
||||
*/
|
||||
mergeSameStyleTokens?: boolean;
|
||||
/**
|
||||
* The structure of the generated HAST and HTML.
|
||||
*
|
||||
* - `classic`: The classic structure with `<pre>` and `<code>` elements, each line wrapped with a `<span class="line">` element.
|
||||
* - `inline`: All tokens are rendered as `<span>`, line breaks are rendered as `<br>`. No `<pre>` or `<code>` elements. Default forground and background colors are not applied.
|
||||
*
|
||||
* @default 'classic'
|
||||
*/
|
||||
structure?: 'classic' | 'inline';
|
||||
/**
|
||||
* Tab index of the root `<pre>` element.
|
||||
*
|
||||
* Set to `false` to disable tab index.
|
||||
*
|
||||
* @default 0
|
||||
*/
|
||||
tabindex?: number | string | false;
|
||||
}
|
||||
interface CodeOptionsMeta {
|
||||
/**
|
||||
* Meta data passed to Shiki, usually used by plugin integrations to pass the code block header.
|
||||
*
|
||||
* Key values in meta will be serialized to the attributes of the root `<pre>` element.
|
||||
*
|
||||
* Keys starting with `_` will be ignored.
|
||||
*
|
||||
* A special key `__raw` key will be used to pass the raw code block header (if the integration supports it).
|
||||
*/
|
||||
meta?: {
|
||||
/**
|
||||
* Raw string of the code block header.
|
||||
*/
|
||||
__raw?: string;
|
||||
[key: string]: any;
|
||||
};
|
||||
}
|
||||
interface CodeToHastRenderOptionsCommon extends TransformerOptions, Omit<TokensResult, 'tokens'> {
|
||||
lang?: string;
|
||||
langId?: string;
|
||||
}
|
||||
type CodeToHastRenderOptions = CodeToHastRenderOptionsCommon & CodeToHastOptions;
|
||||
|
||||
/**
|
||||
* Type of object that can be bound to a grammar state
|
||||
*/
|
||||
type GrammarStateMapKey = Root | ThemedToken[][];
|
||||
/**
|
||||
* Internal context of Shiki, core textmate logic
|
||||
*/
|
||||
interface ShikiInternal<BundledLangKeys extends string = never, BundledThemeKeys extends string = never> {
|
||||
/**
|
||||
* Load a theme to the highlighter, so later it can be used synchronously.
|
||||
*/
|
||||
loadTheme: (...themes: (ThemeInput | BundledThemeKeys | SpecialTheme)[]) => Promise<void>;
|
||||
/**
|
||||
* Load a theme registration synchronously.
|
||||
*/
|
||||
loadThemeSync: (...themes: MaybeArray<ThemeRegistrationAny>[]) => void;
|
||||
/**
|
||||
* Load a language to the highlighter, so later it can be used synchronously.
|
||||
*/
|
||||
loadLanguage: (...langs: (LanguageInput | BundledLangKeys | SpecialLanguage)[]) => Promise<void>;
|
||||
/**
|
||||
* Load a language registration synchronously.
|
||||
*/
|
||||
loadLanguageSync: (...langs: MaybeArray<LanguageRegistration>[]) => void;
|
||||
/**
|
||||
* Get the registered theme object
|
||||
*/
|
||||
getTheme: (name: string | ThemeRegistrationAny) => ThemeRegistrationResolved;
|
||||
/**
|
||||
* Get the registered language object
|
||||
*/
|
||||
getLanguage: (name: string | LanguageRegistration) => Grammar;
|
||||
/**
|
||||
* Set the current theme and get the resolved theme object and color map.
|
||||
* @internal
|
||||
*/
|
||||
setTheme: (themeName: string | ThemeRegistrationAny) => {
|
||||
theme: ThemeRegistrationResolved;
|
||||
colorMap: string[];
|
||||
};
|
||||
/**
|
||||
* Resolve a language alias
|
||||
*/
|
||||
resolveLangAlias: (lang: string) => string;
|
||||
/**
|
||||
* Get the names of loaded languages
|
||||
*
|
||||
* Special-handled languages like `text`, `plain` and `ansi` are not included.
|
||||
*/
|
||||
getLoadedLanguages: () => string[];
|
||||
/**
|
||||
* Get the names of loaded themes
|
||||
*
|
||||
* Special-handled themes like `none` are not included.
|
||||
*/
|
||||
getLoadedThemes: () => string[];
|
||||
/**
|
||||
* Dispose the internal registry and release resources
|
||||
*/
|
||||
dispose: () => void;
|
||||
/**
|
||||
* Dispose the internal registry and release resources
|
||||
*/
|
||||
[Symbol.dispose]: () => void;
|
||||
}
|
||||
/**
|
||||
* Generic instance interface of Shiki
|
||||
*/
|
||||
interface HighlighterGeneric<BundledLangKeys extends string, BundledThemeKeys extends string> extends ShikiInternal<BundledLangKeys, BundledThemeKeys> {
|
||||
/**
|
||||
* Get highlighted code in HTML string
|
||||
*/
|
||||
codeToHtml: (code: string, options: CodeToHastOptions<ResolveBundleKey<BundledLangKeys>, ResolveBundleKey<BundledThemeKeys>>) => string;
|
||||
/**
|
||||
* Get highlighted code in HAST.
|
||||
* @see https://github.com/syntax-tree/hast
|
||||
*/
|
||||
codeToHast: (code: string, options: CodeToHastOptions<ResolveBundleKey<BundledLangKeys>, ResolveBundleKey<BundledThemeKeys>>) => Root;
|
||||
/**
|
||||
* Get highlighted code in tokens. Uses `codeToTokensWithThemes` or `codeToTokensBase` based on the options.
|
||||
*/
|
||||
codeToTokens: (code: string, options: CodeToTokensOptions<ResolveBundleKey<BundledLangKeys>, ResolveBundleKey<BundledThemeKeys>>) => TokensResult;
|
||||
/**
|
||||
* Get highlighted code in tokens with a single theme.
|
||||
* @returns A 2D array of tokens, first dimension is lines, second dimension is tokens in a line.
|
||||
*/
|
||||
codeToTokensBase: (code: string, options: CodeToTokensBaseOptions<ResolveBundleKey<BundledLangKeys>, ResolveBundleKey<BundledThemeKeys>>) => ThemedToken[][];
|
||||
/**
|
||||
* Get highlighted code in tokens with multiple themes.
|
||||
*
|
||||
* Different from `codeToTokensBase`, each token will have a `variants` property consisting of an object of color name to token styles.
|
||||
*
|
||||
* @returns A 2D array of tokens, first dimension is lines, second dimension is tokens in a line.
|
||||
*/
|
||||
codeToTokensWithThemes: (code: string, options: CodeToTokensWithThemesOptions<ResolveBundleKey<BundledLangKeys>, ResolveBundleKey<BundledThemeKeys>>) => ThemedTokenWithVariants[][];
|
||||
/**
|
||||
* Get the last grammar state of a code snippet.
|
||||
* You can pass the grammar state to `codeToTokens` as `grammarState` to continue tokenizing from an intermediate state.
|
||||
*/
|
||||
getLastGrammarState: {
|
||||
(element: GrammarStateMapKey, options?: never): GrammarState | undefined;
|
||||
(code: string, options: CodeToTokensBaseOptions<ResolveBundleKey<BundledLangKeys>, ResolveBundleKey<BundledThemeKeys>>): GrammarState;
|
||||
};
|
||||
/**
|
||||
* Get internal context object
|
||||
* @internal
|
||||
* @deprecated
|
||||
*/
|
||||
getInternalContext: () => ShikiInternal;
|
||||
/**
|
||||
* Get bundled languages object
|
||||
*/
|
||||
getBundledLanguages: () => Record<BundledLangKeys, LanguageInput>;
|
||||
/**
|
||||
* Get bundled themes object
|
||||
*/
|
||||
getBundledThemes: () => Record<BundledThemeKeys, ThemeInput>;
|
||||
}
|
||||
/**
|
||||
* The fine-grained core Shiki highlighter instance.
|
||||
*/
|
||||
type HighlighterCore = HighlighterGeneric<never, never>;
|
||||
/**
|
||||
* Options for creating a bundled highlighter.
|
||||
*/
|
||||
interface CreateBundledHighlighterOptions<BundledLangs extends string, BundledThemes extends string> {
|
||||
langs: Record<BundledLangs, LanguageInput>;
|
||||
themes: Record<BundledThemes, ThemeInput>;
|
||||
engine: () => Awaitable<RegexEngine>;
|
||||
}
|
||||
/**
|
||||
* @deprecated Use `CreateBundledHighlighterOptions` instead.
|
||||
*/
|
||||
interface CreatedBundledHighlighterOptions<BundledLangs extends string, BundledThemes extends string> extends CreateBundledHighlighterOptions<BundledLangs, BundledThemes> {
|
||||
}
|
||||
|
||||
type CreateHighlighterFactory<L extends string, T extends string> = (options: BundledHighlighterOptions<L, T>) => Promise<HighlighterGeneric<L, T>>;
|
||||
|
||||
declare class ShikiError extends Error {
|
||||
constructor(message: string);
|
||||
}
|
||||
|
||||
export { ShikiError };
|
||||
export type { AnsiLanguage, Awaitable, BundledHighlighterOptions, BundledLanguageInfo, BundledThemeInfo, CodeOptionsMeta, CodeOptionsMultipleThemes, CodeOptionsSingleTheme, CodeOptionsThemes, CodeToHastOptions, CodeToHastOptionsCommon, CodeToHastRenderOptions, CodeToHastRenderOptionsCommon, CodeToTokensBaseOptions, CodeToTokensOptions, CodeToTokensWithThemesOptions, CreateBundledHighlighterOptions, CreateHighlighterFactory, CreatedBundledHighlighterOptions, DecorationItem, DecorationOptions, DecorationTransformType, DynamicImportLanguageRegistration, DynamicImportThemeRegistration, Grammar, GrammarState, GrammarStateMapKey, HighlighterCore, HighlighterCoreOptions, HighlighterGeneric, LanguageInput, LanguageRegistration, LoadWasmOptions, LoadWasmOptionsPlain, MaybeArray, MaybeGetter, MaybeModule, Offset, OffsetOrPosition, OnigurumaLoadOptions, PatternScanner, PlainTextLanguage, Position, RegexEngine, RegexEngineString, RequireKeys, ResolveBundleKey, ResolvedDecorationItem, ResolvedPosition, ShikiInternal, ShikiTransformer, ShikiTransformerContext, ShikiTransformerContextCommon, ShikiTransformerContextMeta, ShikiTransformerContextSource, SpecialLanguage, SpecialTheme, StringLiteralUnion, ThemeInput, ThemeRegistration, ThemeRegistrationAny, ThemeRegistrationRaw, ThemeRegistrationResolved, ThemedToken, ThemedTokenExplanation, ThemedTokenScopeExplanation, ThemedTokenWithVariants, TokenBase, TokenStyles, TokenizeWithThemeOptions, TokensResult, TransformerOptions, WebAssemblyInstance, WebAssemblyInstantiator };
|
||||
Generated
Vendored
+8
@@ -0,0 +1,8 @@
|
||||
class ShikiError extends Error {
|
||||
constructor(message) {
|
||||
super(message);
|
||||
this.name = "ShikiError";
|
||||
}
|
||||
}
|
||||
|
||||
export { ShikiError };
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
{
|
||||
"name": "@shikijs/types",
|
||||
"type": "module",
|
||||
"version": "3.23.0",
|
||||
"description": "Type definitions for Shiki",
|
||||
"author": "Anthony Fu <anthonyfu117@hotmail.com>",
|
||||
"license": "MIT",
|
||||
"homepage": "https://github.com/shikijs/shiki#readme",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/shikijs/shiki.git",
|
||||
"directory": "packages/types"
|
||||
},
|
||||
"bugs": "https://github.com/shikijs/shiki/issues",
|
||||
"keywords": [
|
||||
"shiki"
|
||||
],
|
||||
"sideEffects": false,
|
||||
"exports": {
|
||||
".": "./dist/index.mjs"
|
||||
},
|
||||
"main": "./dist/index.mjs",
|
||||
"module": "./dist/index.mjs",
|
||||
"types": "./dist/index.d.mts",
|
||||
"files": [
|
||||
"dist"
|
||||
],
|
||||
"dependencies": {
|
||||
"@shikijs/vscode-textmate": "^10.0.2",
|
||||
"@types/hast": "^3.0.4"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "unbuild",
|
||||
"dev": "unbuild --stub"
|
||||
}
|
||||
}
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
{
|
||||
"name": "@shikijs/engine-oniguruma",
|
||||
"type": "module",
|
||||
"version": "3.23.0",
|
||||
"description": "Engine for Shiki using Oniguruma RegExp engine in WebAssembly",
|
||||
"author": "Anthony Fu <anthonyfu117@hotmail.com>",
|
||||
"license": "MIT",
|
||||
"homepage": "https://github.com/shikijs/shiki#readme",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/shikijs/shiki.git",
|
||||
"directory": "packages/engine-oniguruma"
|
||||
},
|
||||
"bugs": "https://github.com/shikijs/shiki/issues",
|
||||
"keywords": [
|
||||
"shiki",
|
||||
"shiki-engine",
|
||||
"oniguruma"
|
||||
],
|
||||
"sideEffects": false,
|
||||
"exports": {
|
||||
".": "./dist/index.mjs",
|
||||
"./wasm-inlined": "./dist/wasm-inlined.mjs"
|
||||
},
|
||||
"main": "./dist/index.mjs",
|
||||
"module": "./dist/index.mjs",
|
||||
"types": "./dist/index.d.mts",
|
||||
"files": [
|
||||
"dist"
|
||||
],
|
||||
"dependencies": {
|
||||
"@shikijs/vscode-textmate": "^10.0.2",
|
||||
"@shikijs/types": "3.23.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"vscode-oniguruma": "1.7.0"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "rimraf dist && rollup -c",
|
||||
"dev": "rollup -cw"
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user