@shikijs/core 1.6.5 → 1.7.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.
@@ -1005,6 +1005,11 @@ interface HighlighterCoreOptions {
1005
1005
  * Load wasm file from a custom path or using a custom function.
1006
1006
  */
1007
1007
  loadWasm?: LoadWasmOptions;
1008
+ /**
1009
+ * Emit console warnings to alert users of potential issues.
1010
+ * @default true
1011
+ */
1012
+ warnings?: boolean;
1008
1013
  }
1009
1014
  interface BundledHighlighterOptions<L extends string, T extends string> {
1010
1015
  /**
package/dist/index.mjs CHANGED
@@ -4651,6 +4651,50 @@ async function main(init) {
4651
4651
  }
4652
4652
  return false;
4653
4653
  }
4654
+ const UTF8Decoder = typeof TextDecoder != 'undefined' ? new TextDecoder('utf8') : undefined;
4655
+ function UTF8ArrayToString(heapOrArray, idx, maxBytesToRead = 1024) {
4656
+ const endIdx = idx + maxBytesToRead;
4657
+ let endPtr = idx;
4658
+ while (heapOrArray[endPtr] && !(endPtr >= endIdx))
4659
+ ++endPtr;
4660
+ if (endPtr - idx > 16 && heapOrArray.buffer && UTF8Decoder) {
4661
+ return UTF8Decoder.decode(heapOrArray.subarray(idx, endPtr));
4662
+ }
4663
+ let str = '';
4664
+ while (idx < endPtr) {
4665
+ let u0 = heapOrArray[idx++];
4666
+ if (!(u0 & 128)) {
4667
+ str += String.fromCharCode(u0);
4668
+ continue;
4669
+ }
4670
+ const u1 = heapOrArray[idx++] & 63;
4671
+ if ((u0 & 224) === 192) {
4672
+ str += String.fromCharCode(((u0 & 31) << 6) | u1);
4673
+ continue;
4674
+ }
4675
+ const u2 = heapOrArray[idx++] & 63;
4676
+ if ((u0 & 240) === 224) {
4677
+ u0 = ((u0 & 15) << 12) | (u1 << 6) | u2;
4678
+ }
4679
+ else {
4680
+ u0 = ((u0 & 7) << 18)
4681
+ | (u1 << 12)
4682
+ | (u2 << 6)
4683
+ | (heapOrArray[idx++] & 63);
4684
+ }
4685
+ if (u0 < 65536) {
4686
+ str += String.fromCharCode(u0);
4687
+ }
4688
+ else {
4689
+ const ch = u0 - 65536;
4690
+ str += String.fromCharCode(55296 | (ch >> 10), 56320 | (ch & 1023));
4691
+ }
4692
+ }
4693
+ return str;
4694
+ }
4695
+ function UTF8ToString(ptr, maxBytesToRead) {
4696
+ return ptr ? UTF8ArrayToString(binding.HEAPU8, ptr, maxBytesToRead) : '';
4697
+ }
4654
4698
  const asmLibraryArg = {
4655
4699
  emscripten_get_now: _emscripten_get_now,
4656
4700
  emscripten_memcpy_big: _emscripten_memcpy_big,
@@ -4666,6 +4710,7 @@ async function main(init) {
4666
4710
  wasmMemory = exports.memory;
4667
4711
  updateGlobalBufferAndViews(wasmMemory.buffer);
4668
4712
  Object.assign(binding, exports);
4713
+ binding.UTF8ToString = UTF8ToString;
4669
4714
  }
4670
4715
  await createWasm();
4671
4716
  return binding;
@@ -5338,10 +5383,14 @@ let _defaultWasmLoader;
5338
5383
  function setDefaultWasmLoader(_loader) {
5339
5384
  _defaultWasmLoader = _loader;
5340
5385
  }
5386
+ let instancesCount = 0;
5341
5387
  /**
5342
5388
  * Get the minimal shiki context for rendering.
5343
5389
  */
5344
5390
  async function getShikiInternal(options = {}) {
5391
+ instancesCount += 1;
5392
+ if (options.warnings !== false && instancesCount >= 10 && instancesCount % 10 === 0)
5393
+ console.warn(`[Shiki] ${instancesCount} instances have been created. Shiki is supposed to be used as a singleton, consider refactoring your code to cache your highlighter instance.`);
5345
5394
  async function normalizeGetter(p) {
5346
5395
  return Promise.resolve(typeof p === 'function' ? p() : p).then(r => r.default || r);
5347
5396
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@shikijs/core",
3
3
  "type": "module",
4
- "version": "1.6.5",
4
+ "version": "1.7.0",
5
5
  "description": "Core of Shiki",
6
6
  "author": "Pine Wu <octref@gmail.com>; Anthony Fu <anthonyfu117@hotmail.com>",
7
7
  "license": "MIT",