md-editor-v3 2.9.0 → 2.9.1
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/lib/md-editor-v3.es.js +1043 -50
- package/lib/md-editor-v3.umd.js +77 -77
- package/lib/style.css +1 -1
- package/package.json +3 -2
package/lib/md-editor-v3.es.js
CHANGED
|
@@ -231,7 +231,7 @@ const staticTextDefault = {
|
|
|
231
231
|
}
|
|
232
232
|
}
|
|
233
233
|
};
|
|
234
|
-
const mermaidUrl = `${cdnBase}/mermaid/
|
|
234
|
+
const mermaidUrl = `${cdnBase}/mermaid/10.0.2/mermaid.esm.min.mjs`;
|
|
235
235
|
const katexUrl = {
|
|
236
236
|
js: `${cdnBase}/KaTeX/0.16.3/katex.min.js`,
|
|
237
237
|
css: `${cdnBase}/KaTeX/0.16.3/katex.min.css`
|
|
@@ -562,13 +562,20 @@ const keyMove = (trigger, moveHandler) => {
|
|
|
562
562
|
};
|
|
563
563
|
const appendHandler = (ele, checkKey = "") => {
|
|
564
564
|
const insertedEle = document.getElementById(ele.id);
|
|
565
|
+
const onload = (e) => {
|
|
566
|
+
if (typeof ele.onload === "function") {
|
|
567
|
+
ele.onload(e);
|
|
568
|
+
}
|
|
569
|
+
ele.removeEventListener("load", onload);
|
|
570
|
+
};
|
|
565
571
|
if (!insertedEle) {
|
|
572
|
+
ele.addEventListener("load", onload);
|
|
566
573
|
document.head.appendChild(ele);
|
|
567
574
|
} else if (checkKey !== "" && ele.onload instanceof Function) {
|
|
568
575
|
if (Reflect.get(window, checkKey)) {
|
|
569
|
-
ele.
|
|
576
|
+
ele.dispatchEvent(new Event("load"));
|
|
570
577
|
} else {
|
|
571
|
-
insertedEle.addEventListener("load",
|
|
578
|
+
insertedEle.addEventListener("load", onload);
|
|
572
579
|
}
|
|
573
580
|
}
|
|
574
581
|
};
|
|
@@ -5077,6 +5084,983 @@ function styleInject(css2, ref2) {
|
|
|
5077
5084
|
var css = ".medium-zoom-overlay{position:fixed;top:0;right:0;bottom:0;left:0;opacity:0;transition:opacity .3s;will-change:opacity}.medium-zoom--opened .medium-zoom-overlay{cursor:pointer;cursor:zoom-out;opacity:1}.medium-zoom-image{cursor:pointer;cursor:zoom-in;transition:transform .3s cubic-bezier(.2,0,.2,1)!important}.medium-zoom-image--hidden{visibility:hidden}.medium-zoom-image--opened{position:relative;cursor:pointer;cursor:zoom-out;will-change:transform}";
|
|
5078
5085
|
styleInject(css);
|
|
5079
5086
|
var mediumZoom$1 = mediumZoom;
|
|
5087
|
+
const perf = typeof performance === "object" && performance && typeof performance.now === "function" ? performance : Date;
|
|
5088
|
+
const hasAbortController = typeof AbortController === "function";
|
|
5089
|
+
const AC = hasAbortController ? AbortController : class AbortController2 {
|
|
5090
|
+
constructor() {
|
|
5091
|
+
this.signal = new AS();
|
|
5092
|
+
}
|
|
5093
|
+
abort(reason = new Error("This operation was aborted")) {
|
|
5094
|
+
this.signal.reason = this.signal.reason || reason;
|
|
5095
|
+
this.signal.aborted = true;
|
|
5096
|
+
this.signal.dispatchEvent({
|
|
5097
|
+
type: "abort",
|
|
5098
|
+
target: this.signal
|
|
5099
|
+
});
|
|
5100
|
+
}
|
|
5101
|
+
};
|
|
5102
|
+
const hasAbortSignal = typeof AbortSignal === "function";
|
|
5103
|
+
const hasACAbortSignal = typeof AC.AbortSignal === "function";
|
|
5104
|
+
const AS = hasAbortSignal ? AbortSignal : hasACAbortSignal ? AC.AbortController : class AbortSignal2 {
|
|
5105
|
+
constructor() {
|
|
5106
|
+
this.reason = void 0;
|
|
5107
|
+
this.aborted = false;
|
|
5108
|
+
this._listeners = [];
|
|
5109
|
+
}
|
|
5110
|
+
dispatchEvent(e) {
|
|
5111
|
+
if (e.type === "abort") {
|
|
5112
|
+
this.aborted = true;
|
|
5113
|
+
this.onabort(e);
|
|
5114
|
+
this._listeners.forEach((f) => f(e), this);
|
|
5115
|
+
}
|
|
5116
|
+
}
|
|
5117
|
+
onabort() {
|
|
5118
|
+
}
|
|
5119
|
+
addEventListener(ev, fn) {
|
|
5120
|
+
if (ev === "abort") {
|
|
5121
|
+
this._listeners.push(fn);
|
|
5122
|
+
}
|
|
5123
|
+
}
|
|
5124
|
+
removeEventListener(ev, fn) {
|
|
5125
|
+
if (ev === "abort") {
|
|
5126
|
+
this._listeners = this._listeners.filter((f) => f !== fn);
|
|
5127
|
+
}
|
|
5128
|
+
}
|
|
5129
|
+
};
|
|
5130
|
+
const warned = /* @__PURE__ */ new Set();
|
|
5131
|
+
const deprecatedOption = (opt, instead) => {
|
|
5132
|
+
const code = `LRU_CACHE_OPTION_${opt}`;
|
|
5133
|
+
if (shouldWarn(code)) {
|
|
5134
|
+
warn(code, `${opt} option`, `options.${instead}`, LRUCache);
|
|
5135
|
+
}
|
|
5136
|
+
};
|
|
5137
|
+
const deprecatedMethod = (method, instead) => {
|
|
5138
|
+
const code = `LRU_CACHE_METHOD_${method}`;
|
|
5139
|
+
if (shouldWarn(code)) {
|
|
5140
|
+
const { prototype } = LRUCache;
|
|
5141
|
+
const { get } = Object.getOwnPropertyDescriptor(prototype, method);
|
|
5142
|
+
warn(code, `${method} method`, `cache.${instead}()`, get);
|
|
5143
|
+
}
|
|
5144
|
+
};
|
|
5145
|
+
const deprecatedProperty = (field, instead) => {
|
|
5146
|
+
const code = `LRU_CACHE_PROPERTY_${field}`;
|
|
5147
|
+
if (shouldWarn(code)) {
|
|
5148
|
+
const { prototype } = LRUCache;
|
|
5149
|
+
const { get } = Object.getOwnPropertyDescriptor(prototype, field);
|
|
5150
|
+
warn(code, `${field} property`, `cache.${instead}`, get);
|
|
5151
|
+
}
|
|
5152
|
+
};
|
|
5153
|
+
const emitWarning = (...a) => {
|
|
5154
|
+
typeof process === "object" && process && typeof process.emitWarning === "function" ? process.emitWarning(...a) : console.error(...a);
|
|
5155
|
+
};
|
|
5156
|
+
const shouldWarn = (code) => !warned.has(code);
|
|
5157
|
+
const warn = (code, what, instead, fn) => {
|
|
5158
|
+
warned.add(code);
|
|
5159
|
+
const msg = `The ${what} is deprecated. Please use ${instead} instead.`;
|
|
5160
|
+
emitWarning(msg, "DeprecationWarning", code, fn);
|
|
5161
|
+
};
|
|
5162
|
+
const isPosInt = (n) => n && n === Math.floor(n) && n > 0 && isFinite(n);
|
|
5163
|
+
const getUintArray = (max) => !isPosInt(max) ? null : max <= Math.pow(2, 8) ? Uint8Array : max <= Math.pow(2, 16) ? Uint16Array : max <= Math.pow(2, 32) ? Uint32Array : max <= Number.MAX_SAFE_INTEGER ? ZeroArray : null;
|
|
5164
|
+
class ZeroArray extends Array {
|
|
5165
|
+
constructor(size) {
|
|
5166
|
+
super(size);
|
|
5167
|
+
this.fill(0);
|
|
5168
|
+
}
|
|
5169
|
+
}
|
|
5170
|
+
class Stack {
|
|
5171
|
+
constructor(max) {
|
|
5172
|
+
if (max === 0) {
|
|
5173
|
+
return [];
|
|
5174
|
+
}
|
|
5175
|
+
const UintArray = getUintArray(max);
|
|
5176
|
+
this.heap = new UintArray(max);
|
|
5177
|
+
this.length = 0;
|
|
5178
|
+
}
|
|
5179
|
+
push(n) {
|
|
5180
|
+
this.heap[this.length++] = n;
|
|
5181
|
+
}
|
|
5182
|
+
pop() {
|
|
5183
|
+
return this.heap[--this.length];
|
|
5184
|
+
}
|
|
5185
|
+
}
|
|
5186
|
+
class LRUCache {
|
|
5187
|
+
constructor(options = {}) {
|
|
5188
|
+
const {
|
|
5189
|
+
max = 0,
|
|
5190
|
+
ttl,
|
|
5191
|
+
ttlResolution = 1,
|
|
5192
|
+
ttlAutopurge,
|
|
5193
|
+
updateAgeOnGet,
|
|
5194
|
+
updateAgeOnHas,
|
|
5195
|
+
allowStale,
|
|
5196
|
+
dispose,
|
|
5197
|
+
disposeAfter,
|
|
5198
|
+
noDisposeOnSet,
|
|
5199
|
+
noUpdateTTL,
|
|
5200
|
+
maxSize = 0,
|
|
5201
|
+
maxEntrySize = 0,
|
|
5202
|
+
sizeCalculation,
|
|
5203
|
+
fetchMethod,
|
|
5204
|
+
fetchContext,
|
|
5205
|
+
noDeleteOnFetchRejection,
|
|
5206
|
+
noDeleteOnStaleGet,
|
|
5207
|
+
allowStaleOnFetchRejection,
|
|
5208
|
+
allowStaleOnFetchAbort,
|
|
5209
|
+
ignoreFetchAbort
|
|
5210
|
+
} = options;
|
|
5211
|
+
const { length, maxAge, stale } = options instanceof LRUCache ? {} : options;
|
|
5212
|
+
if (max !== 0 && !isPosInt(max)) {
|
|
5213
|
+
throw new TypeError("max option must be a nonnegative integer");
|
|
5214
|
+
}
|
|
5215
|
+
const UintArray = max ? getUintArray(max) : Array;
|
|
5216
|
+
if (!UintArray) {
|
|
5217
|
+
throw new Error("invalid max value: " + max);
|
|
5218
|
+
}
|
|
5219
|
+
this.max = max;
|
|
5220
|
+
this.maxSize = maxSize;
|
|
5221
|
+
this.maxEntrySize = maxEntrySize || this.maxSize;
|
|
5222
|
+
this.sizeCalculation = sizeCalculation || length;
|
|
5223
|
+
if (this.sizeCalculation) {
|
|
5224
|
+
if (!this.maxSize && !this.maxEntrySize) {
|
|
5225
|
+
throw new TypeError("cannot set sizeCalculation without setting maxSize or maxEntrySize");
|
|
5226
|
+
}
|
|
5227
|
+
if (typeof this.sizeCalculation !== "function") {
|
|
5228
|
+
throw new TypeError("sizeCalculation set to non-function");
|
|
5229
|
+
}
|
|
5230
|
+
}
|
|
5231
|
+
this.fetchMethod = fetchMethod || null;
|
|
5232
|
+
if (this.fetchMethod && typeof this.fetchMethod !== "function") {
|
|
5233
|
+
throw new TypeError("fetchMethod must be a function if specified");
|
|
5234
|
+
}
|
|
5235
|
+
this.fetchContext = fetchContext;
|
|
5236
|
+
if (!this.fetchMethod && fetchContext !== void 0) {
|
|
5237
|
+
throw new TypeError("cannot set fetchContext without fetchMethod");
|
|
5238
|
+
}
|
|
5239
|
+
this.keyMap = /* @__PURE__ */ new Map();
|
|
5240
|
+
this.keyList = new Array(max).fill(null);
|
|
5241
|
+
this.valList = new Array(max).fill(null);
|
|
5242
|
+
this.next = new UintArray(max);
|
|
5243
|
+
this.prev = new UintArray(max);
|
|
5244
|
+
this.head = 0;
|
|
5245
|
+
this.tail = 0;
|
|
5246
|
+
this.free = new Stack(max);
|
|
5247
|
+
this.initialFill = 1;
|
|
5248
|
+
this.size = 0;
|
|
5249
|
+
if (typeof dispose === "function") {
|
|
5250
|
+
this.dispose = dispose;
|
|
5251
|
+
}
|
|
5252
|
+
if (typeof disposeAfter === "function") {
|
|
5253
|
+
this.disposeAfter = disposeAfter;
|
|
5254
|
+
this.disposed = [];
|
|
5255
|
+
} else {
|
|
5256
|
+
this.disposeAfter = null;
|
|
5257
|
+
this.disposed = null;
|
|
5258
|
+
}
|
|
5259
|
+
this.noDisposeOnSet = !!noDisposeOnSet;
|
|
5260
|
+
this.noUpdateTTL = !!noUpdateTTL;
|
|
5261
|
+
this.noDeleteOnFetchRejection = !!noDeleteOnFetchRejection;
|
|
5262
|
+
this.allowStaleOnFetchRejection = !!allowStaleOnFetchRejection;
|
|
5263
|
+
this.allowStaleOnFetchAbort = !!allowStaleOnFetchAbort;
|
|
5264
|
+
this.ignoreFetchAbort = !!ignoreFetchAbort;
|
|
5265
|
+
if (this.maxEntrySize !== 0) {
|
|
5266
|
+
if (this.maxSize !== 0) {
|
|
5267
|
+
if (!isPosInt(this.maxSize)) {
|
|
5268
|
+
throw new TypeError("maxSize must be a positive integer if specified");
|
|
5269
|
+
}
|
|
5270
|
+
}
|
|
5271
|
+
if (!isPosInt(this.maxEntrySize)) {
|
|
5272
|
+
throw new TypeError("maxEntrySize must be a positive integer if specified");
|
|
5273
|
+
}
|
|
5274
|
+
this.initializeSizeTracking();
|
|
5275
|
+
}
|
|
5276
|
+
this.allowStale = !!allowStale || !!stale;
|
|
5277
|
+
this.noDeleteOnStaleGet = !!noDeleteOnStaleGet;
|
|
5278
|
+
this.updateAgeOnGet = !!updateAgeOnGet;
|
|
5279
|
+
this.updateAgeOnHas = !!updateAgeOnHas;
|
|
5280
|
+
this.ttlResolution = isPosInt(ttlResolution) || ttlResolution === 0 ? ttlResolution : 1;
|
|
5281
|
+
this.ttlAutopurge = !!ttlAutopurge;
|
|
5282
|
+
this.ttl = ttl || maxAge || 0;
|
|
5283
|
+
if (this.ttl) {
|
|
5284
|
+
if (!isPosInt(this.ttl)) {
|
|
5285
|
+
throw new TypeError("ttl must be a positive integer if specified");
|
|
5286
|
+
}
|
|
5287
|
+
this.initializeTTLTracking();
|
|
5288
|
+
}
|
|
5289
|
+
if (this.max === 0 && this.ttl === 0 && this.maxSize === 0) {
|
|
5290
|
+
throw new TypeError("At least one of max, maxSize, or ttl is required");
|
|
5291
|
+
}
|
|
5292
|
+
if (!this.ttlAutopurge && !this.max && !this.maxSize) {
|
|
5293
|
+
const code = "LRU_CACHE_UNBOUNDED";
|
|
5294
|
+
if (shouldWarn(code)) {
|
|
5295
|
+
warned.add(code);
|
|
5296
|
+
const msg = "TTL caching without ttlAutopurge, max, or maxSize can result in unbounded memory consumption.";
|
|
5297
|
+
emitWarning(msg, "UnboundedCacheWarning", code, LRUCache);
|
|
5298
|
+
}
|
|
5299
|
+
}
|
|
5300
|
+
if (stale) {
|
|
5301
|
+
deprecatedOption("stale", "allowStale");
|
|
5302
|
+
}
|
|
5303
|
+
if (maxAge) {
|
|
5304
|
+
deprecatedOption("maxAge", "ttl");
|
|
5305
|
+
}
|
|
5306
|
+
if (length) {
|
|
5307
|
+
deprecatedOption("length", "sizeCalculation");
|
|
5308
|
+
}
|
|
5309
|
+
}
|
|
5310
|
+
getRemainingTTL(key) {
|
|
5311
|
+
return this.has(key, { updateAgeOnHas: false }) ? Infinity : 0;
|
|
5312
|
+
}
|
|
5313
|
+
initializeTTLTracking() {
|
|
5314
|
+
this.ttls = new ZeroArray(this.max);
|
|
5315
|
+
this.starts = new ZeroArray(this.max);
|
|
5316
|
+
this.setItemTTL = (index2, ttl, start = perf.now()) => {
|
|
5317
|
+
this.starts[index2] = ttl !== 0 ? start : 0;
|
|
5318
|
+
this.ttls[index2] = ttl;
|
|
5319
|
+
if (ttl !== 0 && this.ttlAutopurge) {
|
|
5320
|
+
const t = setTimeout(() => {
|
|
5321
|
+
if (this.isStale(index2)) {
|
|
5322
|
+
this.delete(this.keyList[index2]);
|
|
5323
|
+
}
|
|
5324
|
+
}, ttl + 1);
|
|
5325
|
+
if (t.unref) {
|
|
5326
|
+
t.unref();
|
|
5327
|
+
}
|
|
5328
|
+
}
|
|
5329
|
+
};
|
|
5330
|
+
this.updateItemAge = (index2) => {
|
|
5331
|
+
this.starts[index2] = this.ttls[index2] !== 0 ? perf.now() : 0;
|
|
5332
|
+
};
|
|
5333
|
+
this.statusTTL = (status, index2) => {
|
|
5334
|
+
if (status) {
|
|
5335
|
+
status.ttl = this.ttls[index2];
|
|
5336
|
+
status.start = this.starts[index2];
|
|
5337
|
+
status.now = cachedNow || getNow();
|
|
5338
|
+
status.remainingTTL = status.now + status.ttl - status.start;
|
|
5339
|
+
}
|
|
5340
|
+
};
|
|
5341
|
+
let cachedNow = 0;
|
|
5342
|
+
const getNow = () => {
|
|
5343
|
+
const n = perf.now();
|
|
5344
|
+
if (this.ttlResolution > 0) {
|
|
5345
|
+
cachedNow = n;
|
|
5346
|
+
const t = setTimeout(() => cachedNow = 0, this.ttlResolution);
|
|
5347
|
+
if (t.unref) {
|
|
5348
|
+
t.unref();
|
|
5349
|
+
}
|
|
5350
|
+
}
|
|
5351
|
+
return n;
|
|
5352
|
+
};
|
|
5353
|
+
this.getRemainingTTL = (key) => {
|
|
5354
|
+
const index2 = this.keyMap.get(key);
|
|
5355
|
+
if (index2 === void 0) {
|
|
5356
|
+
return 0;
|
|
5357
|
+
}
|
|
5358
|
+
return this.ttls[index2] === 0 || this.starts[index2] === 0 ? Infinity : this.starts[index2] + this.ttls[index2] - (cachedNow || getNow());
|
|
5359
|
+
};
|
|
5360
|
+
this.isStale = (index2) => {
|
|
5361
|
+
return this.ttls[index2] !== 0 && this.starts[index2] !== 0 && (cachedNow || getNow()) - this.starts[index2] > this.ttls[index2];
|
|
5362
|
+
};
|
|
5363
|
+
}
|
|
5364
|
+
updateItemAge(_index) {
|
|
5365
|
+
}
|
|
5366
|
+
statusTTL(_status, _index) {
|
|
5367
|
+
}
|
|
5368
|
+
setItemTTL(_index, _ttl, _start) {
|
|
5369
|
+
}
|
|
5370
|
+
isStale(_index) {
|
|
5371
|
+
return false;
|
|
5372
|
+
}
|
|
5373
|
+
initializeSizeTracking() {
|
|
5374
|
+
this.calculatedSize = 0;
|
|
5375
|
+
this.sizes = new ZeroArray(this.max);
|
|
5376
|
+
this.removeItemSize = (index2) => {
|
|
5377
|
+
this.calculatedSize -= this.sizes[index2];
|
|
5378
|
+
this.sizes[index2] = 0;
|
|
5379
|
+
};
|
|
5380
|
+
this.requireSize = (k, v, size, sizeCalculation) => {
|
|
5381
|
+
if (this.isBackgroundFetch(v)) {
|
|
5382
|
+
return 0;
|
|
5383
|
+
}
|
|
5384
|
+
if (!isPosInt(size)) {
|
|
5385
|
+
if (sizeCalculation) {
|
|
5386
|
+
if (typeof sizeCalculation !== "function") {
|
|
5387
|
+
throw new TypeError("sizeCalculation must be a function");
|
|
5388
|
+
}
|
|
5389
|
+
size = sizeCalculation(v, k);
|
|
5390
|
+
if (!isPosInt(size)) {
|
|
5391
|
+
throw new TypeError("sizeCalculation return invalid (expect positive integer)");
|
|
5392
|
+
}
|
|
5393
|
+
} else {
|
|
5394
|
+
throw new TypeError("invalid size value (must be positive integer). When maxSize or maxEntrySize is used, sizeCalculation or size must be set.");
|
|
5395
|
+
}
|
|
5396
|
+
}
|
|
5397
|
+
return size;
|
|
5398
|
+
};
|
|
5399
|
+
this.addItemSize = (index2, size, status) => {
|
|
5400
|
+
this.sizes[index2] = size;
|
|
5401
|
+
if (this.maxSize) {
|
|
5402
|
+
const maxSize = this.maxSize - this.sizes[index2];
|
|
5403
|
+
while (this.calculatedSize > maxSize) {
|
|
5404
|
+
this.evict(true);
|
|
5405
|
+
}
|
|
5406
|
+
}
|
|
5407
|
+
this.calculatedSize += this.sizes[index2];
|
|
5408
|
+
if (status) {
|
|
5409
|
+
status.entrySize = size;
|
|
5410
|
+
status.totalCalculatedSize = this.calculatedSize;
|
|
5411
|
+
}
|
|
5412
|
+
};
|
|
5413
|
+
}
|
|
5414
|
+
removeItemSize(_index) {
|
|
5415
|
+
}
|
|
5416
|
+
addItemSize(_index, _size) {
|
|
5417
|
+
}
|
|
5418
|
+
requireSize(_k, _v, size, sizeCalculation) {
|
|
5419
|
+
if (size || sizeCalculation) {
|
|
5420
|
+
throw new TypeError("cannot set size without setting maxSize or maxEntrySize on cache");
|
|
5421
|
+
}
|
|
5422
|
+
}
|
|
5423
|
+
*indexes({ allowStale = this.allowStale } = {}) {
|
|
5424
|
+
if (this.size) {
|
|
5425
|
+
for (let i = this.tail; true; ) {
|
|
5426
|
+
if (!this.isValidIndex(i)) {
|
|
5427
|
+
break;
|
|
5428
|
+
}
|
|
5429
|
+
if (allowStale || !this.isStale(i)) {
|
|
5430
|
+
yield i;
|
|
5431
|
+
}
|
|
5432
|
+
if (i === this.head) {
|
|
5433
|
+
break;
|
|
5434
|
+
} else {
|
|
5435
|
+
i = this.prev[i];
|
|
5436
|
+
}
|
|
5437
|
+
}
|
|
5438
|
+
}
|
|
5439
|
+
}
|
|
5440
|
+
*rindexes({ allowStale = this.allowStale } = {}) {
|
|
5441
|
+
if (this.size) {
|
|
5442
|
+
for (let i = this.head; true; ) {
|
|
5443
|
+
if (!this.isValidIndex(i)) {
|
|
5444
|
+
break;
|
|
5445
|
+
}
|
|
5446
|
+
if (allowStale || !this.isStale(i)) {
|
|
5447
|
+
yield i;
|
|
5448
|
+
}
|
|
5449
|
+
if (i === this.tail) {
|
|
5450
|
+
break;
|
|
5451
|
+
} else {
|
|
5452
|
+
i = this.next[i];
|
|
5453
|
+
}
|
|
5454
|
+
}
|
|
5455
|
+
}
|
|
5456
|
+
}
|
|
5457
|
+
isValidIndex(index2) {
|
|
5458
|
+
return index2 !== void 0 && this.keyMap.get(this.keyList[index2]) === index2;
|
|
5459
|
+
}
|
|
5460
|
+
*entries() {
|
|
5461
|
+
for (const i of this.indexes()) {
|
|
5462
|
+
if (this.valList[i] !== void 0 && this.keyList[i] !== void 0 && !this.isBackgroundFetch(this.valList[i])) {
|
|
5463
|
+
yield [this.keyList[i], this.valList[i]];
|
|
5464
|
+
}
|
|
5465
|
+
}
|
|
5466
|
+
}
|
|
5467
|
+
*rentries() {
|
|
5468
|
+
for (const i of this.rindexes()) {
|
|
5469
|
+
if (this.valList[i] !== void 0 && this.keyList[i] !== void 0 && !this.isBackgroundFetch(this.valList[i])) {
|
|
5470
|
+
yield [this.keyList[i], this.valList[i]];
|
|
5471
|
+
}
|
|
5472
|
+
}
|
|
5473
|
+
}
|
|
5474
|
+
*keys() {
|
|
5475
|
+
for (const i of this.indexes()) {
|
|
5476
|
+
if (this.keyList[i] !== void 0 && !this.isBackgroundFetch(this.valList[i])) {
|
|
5477
|
+
yield this.keyList[i];
|
|
5478
|
+
}
|
|
5479
|
+
}
|
|
5480
|
+
}
|
|
5481
|
+
*rkeys() {
|
|
5482
|
+
for (const i of this.rindexes()) {
|
|
5483
|
+
if (this.keyList[i] !== void 0 && !this.isBackgroundFetch(this.valList[i])) {
|
|
5484
|
+
yield this.keyList[i];
|
|
5485
|
+
}
|
|
5486
|
+
}
|
|
5487
|
+
}
|
|
5488
|
+
*values() {
|
|
5489
|
+
for (const i of this.indexes()) {
|
|
5490
|
+
if (this.valList[i] !== void 0 && !this.isBackgroundFetch(this.valList[i])) {
|
|
5491
|
+
yield this.valList[i];
|
|
5492
|
+
}
|
|
5493
|
+
}
|
|
5494
|
+
}
|
|
5495
|
+
*rvalues() {
|
|
5496
|
+
for (const i of this.rindexes()) {
|
|
5497
|
+
if (this.valList[i] !== void 0 && !this.isBackgroundFetch(this.valList[i])) {
|
|
5498
|
+
yield this.valList[i];
|
|
5499
|
+
}
|
|
5500
|
+
}
|
|
5501
|
+
}
|
|
5502
|
+
[Symbol.iterator]() {
|
|
5503
|
+
return this.entries();
|
|
5504
|
+
}
|
|
5505
|
+
find(fn, getOptions) {
|
|
5506
|
+
for (const i of this.indexes()) {
|
|
5507
|
+
const v = this.valList[i];
|
|
5508
|
+
const value = this.isBackgroundFetch(v) ? v.__staleWhileFetching : v;
|
|
5509
|
+
if (value === void 0)
|
|
5510
|
+
continue;
|
|
5511
|
+
if (fn(value, this.keyList[i], this)) {
|
|
5512
|
+
return this.get(this.keyList[i], getOptions);
|
|
5513
|
+
}
|
|
5514
|
+
}
|
|
5515
|
+
}
|
|
5516
|
+
forEach(fn, thisp = this) {
|
|
5517
|
+
for (const i of this.indexes()) {
|
|
5518
|
+
const v = this.valList[i];
|
|
5519
|
+
const value = this.isBackgroundFetch(v) ? v.__staleWhileFetching : v;
|
|
5520
|
+
if (value === void 0)
|
|
5521
|
+
continue;
|
|
5522
|
+
fn.call(thisp, value, this.keyList[i], this);
|
|
5523
|
+
}
|
|
5524
|
+
}
|
|
5525
|
+
rforEach(fn, thisp = this) {
|
|
5526
|
+
for (const i of this.rindexes()) {
|
|
5527
|
+
const v = this.valList[i];
|
|
5528
|
+
const value = this.isBackgroundFetch(v) ? v.__staleWhileFetching : v;
|
|
5529
|
+
if (value === void 0)
|
|
5530
|
+
continue;
|
|
5531
|
+
fn.call(thisp, value, this.keyList[i], this);
|
|
5532
|
+
}
|
|
5533
|
+
}
|
|
5534
|
+
get prune() {
|
|
5535
|
+
deprecatedMethod("prune", "purgeStale");
|
|
5536
|
+
return this.purgeStale;
|
|
5537
|
+
}
|
|
5538
|
+
purgeStale() {
|
|
5539
|
+
let deleted = false;
|
|
5540
|
+
for (const i of this.rindexes({ allowStale: true })) {
|
|
5541
|
+
if (this.isStale(i)) {
|
|
5542
|
+
this.delete(this.keyList[i]);
|
|
5543
|
+
deleted = true;
|
|
5544
|
+
}
|
|
5545
|
+
}
|
|
5546
|
+
return deleted;
|
|
5547
|
+
}
|
|
5548
|
+
dump() {
|
|
5549
|
+
const arr = [];
|
|
5550
|
+
for (const i of this.indexes({ allowStale: true })) {
|
|
5551
|
+
const key = this.keyList[i];
|
|
5552
|
+
const v = this.valList[i];
|
|
5553
|
+
const value = this.isBackgroundFetch(v) ? v.__staleWhileFetching : v;
|
|
5554
|
+
if (value === void 0)
|
|
5555
|
+
continue;
|
|
5556
|
+
const entry = { value };
|
|
5557
|
+
if (this.ttls) {
|
|
5558
|
+
entry.ttl = this.ttls[i];
|
|
5559
|
+
const age = perf.now() - this.starts[i];
|
|
5560
|
+
entry.start = Math.floor(Date.now() - age);
|
|
5561
|
+
}
|
|
5562
|
+
if (this.sizes) {
|
|
5563
|
+
entry.size = this.sizes[i];
|
|
5564
|
+
}
|
|
5565
|
+
arr.unshift([key, entry]);
|
|
5566
|
+
}
|
|
5567
|
+
return arr;
|
|
5568
|
+
}
|
|
5569
|
+
load(arr) {
|
|
5570
|
+
this.clear();
|
|
5571
|
+
for (const [key, entry] of arr) {
|
|
5572
|
+
if (entry.start) {
|
|
5573
|
+
const age = Date.now() - entry.start;
|
|
5574
|
+
entry.start = perf.now() - age;
|
|
5575
|
+
}
|
|
5576
|
+
this.set(key, entry.value, entry);
|
|
5577
|
+
}
|
|
5578
|
+
}
|
|
5579
|
+
dispose(_v, _k, _reason) {
|
|
5580
|
+
}
|
|
5581
|
+
set(k, v, {
|
|
5582
|
+
ttl = this.ttl,
|
|
5583
|
+
start,
|
|
5584
|
+
noDisposeOnSet = this.noDisposeOnSet,
|
|
5585
|
+
size = 0,
|
|
5586
|
+
sizeCalculation = this.sizeCalculation,
|
|
5587
|
+
noUpdateTTL = this.noUpdateTTL,
|
|
5588
|
+
status
|
|
5589
|
+
} = {}) {
|
|
5590
|
+
size = this.requireSize(k, v, size, sizeCalculation);
|
|
5591
|
+
if (this.maxEntrySize && size > this.maxEntrySize) {
|
|
5592
|
+
if (status) {
|
|
5593
|
+
status.set = "miss";
|
|
5594
|
+
status.maxEntrySizeExceeded = true;
|
|
5595
|
+
}
|
|
5596
|
+
this.delete(k);
|
|
5597
|
+
return this;
|
|
5598
|
+
}
|
|
5599
|
+
let index2 = this.size === 0 ? void 0 : this.keyMap.get(k);
|
|
5600
|
+
if (index2 === void 0) {
|
|
5601
|
+
index2 = this.newIndex();
|
|
5602
|
+
this.keyList[index2] = k;
|
|
5603
|
+
this.valList[index2] = v;
|
|
5604
|
+
this.keyMap.set(k, index2);
|
|
5605
|
+
this.next[this.tail] = index2;
|
|
5606
|
+
this.prev[index2] = this.tail;
|
|
5607
|
+
this.tail = index2;
|
|
5608
|
+
this.size++;
|
|
5609
|
+
this.addItemSize(index2, size, status);
|
|
5610
|
+
if (status) {
|
|
5611
|
+
status.set = "add";
|
|
5612
|
+
}
|
|
5613
|
+
noUpdateTTL = false;
|
|
5614
|
+
} else {
|
|
5615
|
+
this.moveToTail(index2);
|
|
5616
|
+
const oldVal = this.valList[index2];
|
|
5617
|
+
if (v !== oldVal) {
|
|
5618
|
+
if (this.isBackgroundFetch(oldVal)) {
|
|
5619
|
+
oldVal.__abortController.abort(new Error("replaced"));
|
|
5620
|
+
} else {
|
|
5621
|
+
if (!noDisposeOnSet) {
|
|
5622
|
+
this.dispose(oldVal, k, "set");
|
|
5623
|
+
if (this.disposeAfter) {
|
|
5624
|
+
this.disposed.push([oldVal, k, "set"]);
|
|
5625
|
+
}
|
|
5626
|
+
}
|
|
5627
|
+
}
|
|
5628
|
+
this.removeItemSize(index2);
|
|
5629
|
+
this.valList[index2] = v;
|
|
5630
|
+
this.addItemSize(index2, size, status);
|
|
5631
|
+
if (status) {
|
|
5632
|
+
status.set = "replace";
|
|
5633
|
+
const oldValue = oldVal && this.isBackgroundFetch(oldVal) ? oldVal.__staleWhileFetching : oldVal;
|
|
5634
|
+
if (oldValue !== void 0)
|
|
5635
|
+
status.oldValue = oldValue;
|
|
5636
|
+
}
|
|
5637
|
+
} else if (status) {
|
|
5638
|
+
status.set = "update";
|
|
5639
|
+
}
|
|
5640
|
+
}
|
|
5641
|
+
if (ttl !== 0 && this.ttl === 0 && !this.ttls) {
|
|
5642
|
+
this.initializeTTLTracking();
|
|
5643
|
+
}
|
|
5644
|
+
if (!noUpdateTTL) {
|
|
5645
|
+
this.setItemTTL(index2, ttl, start);
|
|
5646
|
+
}
|
|
5647
|
+
this.statusTTL(status, index2);
|
|
5648
|
+
if (this.disposeAfter) {
|
|
5649
|
+
while (this.disposed.length) {
|
|
5650
|
+
this.disposeAfter(...this.disposed.shift());
|
|
5651
|
+
}
|
|
5652
|
+
}
|
|
5653
|
+
return this;
|
|
5654
|
+
}
|
|
5655
|
+
newIndex() {
|
|
5656
|
+
if (this.size === 0) {
|
|
5657
|
+
return this.tail;
|
|
5658
|
+
}
|
|
5659
|
+
if (this.size === this.max && this.max !== 0) {
|
|
5660
|
+
return this.evict(false);
|
|
5661
|
+
}
|
|
5662
|
+
if (this.free.length !== 0) {
|
|
5663
|
+
return this.free.pop();
|
|
5664
|
+
}
|
|
5665
|
+
return this.initialFill++;
|
|
5666
|
+
}
|
|
5667
|
+
pop() {
|
|
5668
|
+
if (this.size) {
|
|
5669
|
+
const val = this.valList[this.head];
|
|
5670
|
+
this.evict(true);
|
|
5671
|
+
return val;
|
|
5672
|
+
}
|
|
5673
|
+
}
|
|
5674
|
+
evict(free) {
|
|
5675
|
+
const head = this.head;
|
|
5676
|
+
const k = this.keyList[head];
|
|
5677
|
+
const v = this.valList[head];
|
|
5678
|
+
if (this.isBackgroundFetch(v)) {
|
|
5679
|
+
v.__abortController.abort(new Error("evicted"));
|
|
5680
|
+
} else {
|
|
5681
|
+
this.dispose(v, k, "evict");
|
|
5682
|
+
if (this.disposeAfter) {
|
|
5683
|
+
this.disposed.push([v, k, "evict"]);
|
|
5684
|
+
}
|
|
5685
|
+
}
|
|
5686
|
+
this.removeItemSize(head);
|
|
5687
|
+
if (free) {
|
|
5688
|
+
this.keyList[head] = null;
|
|
5689
|
+
this.valList[head] = null;
|
|
5690
|
+
this.free.push(head);
|
|
5691
|
+
}
|
|
5692
|
+
this.head = this.next[head];
|
|
5693
|
+
this.keyMap.delete(k);
|
|
5694
|
+
this.size--;
|
|
5695
|
+
return head;
|
|
5696
|
+
}
|
|
5697
|
+
has(k, { updateAgeOnHas = this.updateAgeOnHas, status } = {}) {
|
|
5698
|
+
const index2 = this.keyMap.get(k);
|
|
5699
|
+
if (index2 !== void 0) {
|
|
5700
|
+
if (!this.isStale(index2)) {
|
|
5701
|
+
if (updateAgeOnHas) {
|
|
5702
|
+
this.updateItemAge(index2);
|
|
5703
|
+
}
|
|
5704
|
+
if (status)
|
|
5705
|
+
status.has = "hit";
|
|
5706
|
+
this.statusTTL(status, index2);
|
|
5707
|
+
return true;
|
|
5708
|
+
} else if (status) {
|
|
5709
|
+
status.has = "stale";
|
|
5710
|
+
this.statusTTL(status, index2);
|
|
5711
|
+
}
|
|
5712
|
+
} else if (status) {
|
|
5713
|
+
status.has = "miss";
|
|
5714
|
+
}
|
|
5715
|
+
return false;
|
|
5716
|
+
}
|
|
5717
|
+
peek(k, { allowStale = this.allowStale } = {}) {
|
|
5718
|
+
const index2 = this.keyMap.get(k);
|
|
5719
|
+
if (index2 !== void 0 && (allowStale || !this.isStale(index2))) {
|
|
5720
|
+
const v = this.valList[index2];
|
|
5721
|
+
return this.isBackgroundFetch(v) ? v.__staleWhileFetching : v;
|
|
5722
|
+
}
|
|
5723
|
+
}
|
|
5724
|
+
backgroundFetch(k, index2, options, context) {
|
|
5725
|
+
const v = index2 === void 0 ? void 0 : this.valList[index2];
|
|
5726
|
+
if (this.isBackgroundFetch(v)) {
|
|
5727
|
+
return v;
|
|
5728
|
+
}
|
|
5729
|
+
const ac = new AC();
|
|
5730
|
+
if (options.signal) {
|
|
5731
|
+
options.signal.addEventListener("abort", () => ac.abort(options.signal.reason));
|
|
5732
|
+
}
|
|
5733
|
+
const fetchOpts = {
|
|
5734
|
+
signal: ac.signal,
|
|
5735
|
+
options,
|
|
5736
|
+
context
|
|
5737
|
+
};
|
|
5738
|
+
const cb = (v2, updateCache = false) => {
|
|
5739
|
+
const { aborted } = ac.signal;
|
|
5740
|
+
const ignoreAbort = options.ignoreFetchAbort && v2 !== void 0;
|
|
5741
|
+
if (options.status) {
|
|
5742
|
+
if (aborted && !updateCache) {
|
|
5743
|
+
options.status.fetchAborted = true;
|
|
5744
|
+
options.status.fetchError = ac.signal.reason;
|
|
5745
|
+
if (ignoreAbort)
|
|
5746
|
+
options.status.fetchAbortIgnored = true;
|
|
5747
|
+
} else {
|
|
5748
|
+
options.status.fetchResolved = true;
|
|
5749
|
+
}
|
|
5750
|
+
}
|
|
5751
|
+
if (aborted && !ignoreAbort && !updateCache) {
|
|
5752
|
+
return fetchFail(ac.signal.reason);
|
|
5753
|
+
}
|
|
5754
|
+
if (this.valList[index2] === p) {
|
|
5755
|
+
if (v2 === void 0) {
|
|
5756
|
+
if (p.__staleWhileFetching) {
|
|
5757
|
+
this.valList[index2] = p.__staleWhileFetching;
|
|
5758
|
+
} else {
|
|
5759
|
+
this.delete(k);
|
|
5760
|
+
}
|
|
5761
|
+
} else {
|
|
5762
|
+
if (options.status)
|
|
5763
|
+
options.status.fetchUpdated = true;
|
|
5764
|
+
this.set(k, v2, fetchOpts.options);
|
|
5765
|
+
}
|
|
5766
|
+
}
|
|
5767
|
+
return v2;
|
|
5768
|
+
};
|
|
5769
|
+
const eb = (er) => {
|
|
5770
|
+
if (options.status) {
|
|
5771
|
+
options.status.fetchRejected = true;
|
|
5772
|
+
options.status.fetchError = er;
|
|
5773
|
+
}
|
|
5774
|
+
return fetchFail(er);
|
|
5775
|
+
};
|
|
5776
|
+
const fetchFail = (er) => {
|
|
5777
|
+
const { aborted } = ac.signal;
|
|
5778
|
+
const allowStaleAborted = aborted && options.allowStaleOnFetchAbort;
|
|
5779
|
+
const allowStale = allowStaleAborted || options.allowStaleOnFetchRejection;
|
|
5780
|
+
const noDelete = allowStale || options.noDeleteOnFetchRejection;
|
|
5781
|
+
if (this.valList[index2] === p) {
|
|
5782
|
+
const del = !noDelete || p.__staleWhileFetching === void 0;
|
|
5783
|
+
if (del) {
|
|
5784
|
+
this.delete(k);
|
|
5785
|
+
} else if (!allowStaleAborted) {
|
|
5786
|
+
this.valList[index2] = p.__staleWhileFetching;
|
|
5787
|
+
}
|
|
5788
|
+
}
|
|
5789
|
+
if (allowStale) {
|
|
5790
|
+
if (options.status && p.__staleWhileFetching !== void 0) {
|
|
5791
|
+
options.status.returnedStale = true;
|
|
5792
|
+
}
|
|
5793
|
+
return p.__staleWhileFetching;
|
|
5794
|
+
} else if (p.__returned === p) {
|
|
5795
|
+
throw er;
|
|
5796
|
+
}
|
|
5797
|
+
};
|
|
5798
|
+
const pcall = (res, rej) => {
|
|
5799
|
+
this.fetchMethod(k, v, fetchOpts).then((v2) => res(v2), rej);
|
|
5800
|
+
ac.signal.addEventListener("abort", () => {
|
|
5801
|
+
if (!options.ignoreFetchAbort || options.allowStaleOnFetchAbort) {
|
|
5802
|
+
res();
|
|
5803
|
+
if (options.allowStaleOnFetchAbort) {
|
|
5804
|
+
res = (v2) => cb(v2, true);
|
|
5805
|
+
}
|
|
5806
|
+
}
|
|
5807
|
+
});
|
|
5808
|
+
};
|
|
5809
|
+
if (options.status)
|
|
5810
|
+
options.status.fetchDispatched = true;
|
|
5811
|
+
const p = new Promise(pcall).then(cb, eb);
|
|
5812
|
+
p.__abortController = ac;
|
|
5813
|
+
p.__staleWhileFetching = v;
|
|
5814
|
+
p.__returned = null;
|
|
5815
|
+
if (index2 === void 0) {
|
|
5816
|
+
this.set(k, p, __spreadProps(__spreadValues({}, fetchOpts.options), { status: void 0 }));
|
|
5817
|
+
index2 = this.keyMap.get(k);
|
|
5818
|
+
} else {
|
|
5819
|
+
this.valList[index2] = p;
|
|
5820
|
+
}
|
|
5821
|
+
return p;
|
|
5822
|
+
}
|
|
5823
|
+
isBackgroundFetch(p) {
|
|
5824
|
+
return p && typeof p === "object" && typeof p.then === "function" && Object.prototype.hasOwnProperty.call(p, "__staleWhileFetching") && Object.prototype.hasOwnProperty.call(p, "__returned") && (p.__returned === p || p.__returned === null);
|
|
5825
|
+
}
|
|
5826
|
+
async fetch(k, {
|
|
5827
|
+
allowStale = this.allowStale,
|
|
5828
|
+
updateAgeOnGet = this.updateAgeOnGet,
|
|
5829
|
+
noDeleteOnStaleGet = this.noDeleteOnStaleGet,
|
|
5830
|
+
ttl = this.ttl,
|
|
5831
|
+
noDisposeOnSet = this.noDisposeOnSet,
|
|
5832
|
+
size = 0,
|
|
5833
|
+
sizeCalculation = this.sizeCalculation,
|
|
5834
|
+
noUpdateTTL = this.noUpdateTTL,
|
|
5835
|
+
noDeleteOnFetchRejection = this.noDeleteOnFetchRejection,
|
|
5836
|
+
allowStaleOnFetchRejection = this.allowStaleOnFetchRejection,
|
|
5837
|
+
ignoreFetchAbort = this.ignoreFetchAbort,
|
|
5838
|
+
allowStaleOnFetchAbort = this.allowStaleOnFetchAbort,
|
|
5839
|
+
fetchContext = this.fetchContext,
|
|
5840
|
+
forceRefresh = false,
|
|
5841
|
+
status,
|
|
5842
|
+
signal
|
|
5843
|
+
} = {}) {
|
|
5844
|
+
if (!this.fetchMethod) {
|
|
5845
|
+
if (status)
|
|
5846
|
+
status.fetch = "get";
|
|
5847
|
+
return this.get(k, {
|
|
5848
|
+
allowStale,
|
|
5849
|
+
updateAgeOnGet,
|
|
5850
|
+
noDeleteOnStaleGet,
|
|
5851
|
+
status
|
|
5852
|
+
});
|
|
5853
|
+
}
|
|
5854
|
+
const options = {
|
|
5855
|
+
allowStale,
|
|
5856
|
+
updateAgeOnGet,
|
|
5857
|
+
noDeleteOnStaleGet,
|
|
5858
|
+
ttl,
|
|
5859
|
+
noDisposeOnSet,
|
|
5860
|
+
size,
|
|
5861
|
+
sizeCalculation,
|
|
5862
|
+
noUpdateTTL,
|
|
5863
|
+
noDeleteOnFetchRejection,
|
|
5864
|
+
allowStaleOnFetchRejection,
|
|
5865
|
+
allowStaleOnFetchAbort,
|
|
5866
|
+
ignoreFetchAbort,
|
|
5867
|
+
status,
|
|
5868
|
+
signal
|
|
5869
|
+
};
|
|
5870
|
+
let index2 = this.keyMap.get(k);
|
|
5871
|
+
if (index2 === void 0) {
|
|
5872
|
+
if (status)
|
|
5873
|
+
status.fetch = "miss";
|
|
5874
|
+
const p = this.backgroundFetch(k, index2, options, fetchContext);
|
|
5875
|
+
return p.__returned = p;
|
|
5876
|
+
} else {
|
|
5877
|
+
const v = this.valList[index2];
|
|
5878
|
+
if (this.isBackgroundFetch(v)) {
|
|
5879
|
+
const stale = allowStale && v.__staleWhileFetching !== void 0;
|
|
5880
|
+
if (status) {
|
|
5881
|
+
status.fetch = "inflight";
|
|
5882
|
+
if (stale)
|
|
5883
|
+
status.returnedStale = true;
|
|
5884
|
+
}
|
|
5885
|
+
return stale ? v.__staleWhileFetching : v.__returned = v;
|
|
5886
|
+
}
|
|
5887
|
+
const isStale = this.isStale(index2);
|
|
5888
|
+
if (!forceRefresh && !isStale) {
|
|
5889
|
+
if (status)
|
|
5890
|
+
status.fetch = "hit";
|
|
5891
|
+
this.moveToTail(index2);
|
|
5892
|
+
if (updateAgeOnGet) {
|
|
5893
|
+
this.updateItemAge(index2);
|
|
5894
|
+
}
|
|
5895
|
+
this.statusTTL(status, index2);
|
|
5896
|
+
return v;
|
|
5897
|
+
}
|
|
5898
|
+
const p = this.backgroundFetch(k, index2, options, fetchContext);
|
|
5899
|
+
const hasStale = p.__staleWhileFetching !== void 0;
|
|
5900
|
+
const staleVal = hasStale && allowStale;
|
|
5901
|
+
if (status) {
|
|
5902
|
+
status.fetch = hasStale && isStale ? "stale" : "refresh";
|
|
5903
|
+
if (staleVal && isStale)
|
|
5904
|
+
status.returnedStale = true;
|
|
5905
|
+
}
|
|
5906
|
+
return staleVal ? p.__staleWhileFetching : p.__returned = p;
|
|
5907
|
+
}
|
|
5908
|
+
}
|
|
5909
|
+
get(k, {
|
|
5910
|
+
allowStale = this.allowStale,
|
|
5911
|
+
updateAgeOnGet = this.updateAgeOnGet,
|
|
5912
|
+
noDeleteOnStaleGet = this.noDeleteOnStaleGet,
|
|
5913
|
+
status
|
|
5914
|
+
} = {}) {
|
|
5915
|
+
const index2 = this.keyMap.get(k);
|
|
5916
|
+
if (index2 !== void 0) {
|
|
5917
|
+
const value = this.valList[index2];
|
|
5918
|
+
const fetching = this.isBackgroundFetch(value);
|
|
5919
|
+
this.statusTTL(status, index2);
|
|
5920
|
+
if (this.isStale(index2)) {
|
|
5921
|
+
if (status)
|
|
5922
|
+
status.get = "stale";
|
|
5923
|
+
if (!fetching) {
|
|
5924
|
+
if (!noDeleteOnStaleGet) {
|
|
5925
|
+
this.delete(k);
|
|
5926
|
+
}
|
|
5927
|
+
if (status)
|
|
5928
|
+
status.returnedStale = allowStale;
|
|
5929
|
+
return allowStale ? value : void 0;
|
|
5930
|
+
} else {
|
|
5931
|
+
if (status) {
|
|
5932
|
+
status.returnedStale = allowStale && value.__staleWhileFetching !== void 0;
|
|
5933
|
+
}
|
|
5934
|
+
return allowStale ? value.__staleWhileFetching : void 0;
|
|
5935
|
+
}
|
|
5936
|
+
} else {
|
|
5937
|
+
if (status)
|
|
5938
|
+
status.get = "hit";
|
|
5939
|
+
if (fetching) {
|
|
5940
|
+
return value.__staleWhileFetching;
|
|
5941
|
+
}
|
|
5942
|
+
this.moveToTail(index2);
|
|
5943
|
+
if (updateAgeOnGet) {
|
|
5944
|
+
this.updateItemAge(index2);
|
|
5945
|
+
}
|
|
5946
|
+
return value;
|
|
5947
|
+
}
|
|
5948
|
+
} else if (status) {
|
|
5949
|
+
status.get = "miss";
|
|
5950
|
+
}
|
|
5951
|
+
}
|
|
5952
|
+
connect(p, n) {
|
|
5953
|
+
this.prev[n] = p;
|
|
5954
|
+
this.next[p] = n;
|
|
5955
|
+
}
|
|
5956
|
+
moveToTail(index2) {
|
|
5957
|
+
if (index2 !== this.tail) {
|
|
5958
|
+
if (index2 === this.head) {
|
|
5959
|
+
this.head = this.next[index2];
|
|
5960
|
+
} else {
|
|
5961
|
+
this.connect(this.prev[index2], this.next[index2]);
|
|
5962
|
+
}
|
|
5963
|
+
this.connect(this.tail, index2);
|
|
5964
|
+
this.tail = index2;
|
|
5965
|
+
}
|
|
5966
|
+
}
|
|
5967
|
+
get del() {
|
|
5968
|
+
deprecatedMethod("del", "delete");
|
|
5969
|
+
return this.delete;
|
|
5970
|
+
}
|
|
5971
|
+
delete(k) {
|
|
5972
|
+
let deleted = false;
|
|
5973
|
+
if (this.size !== 0) {
|
|
5974
|
+
const index2 = this.keyMap.get(k);
|
|
5975
|
+
if (index2 !== void 0) {
|
|
5976
|
+
deleted = true;
|
|
5977
|
+
if (this.size === 1) {
|
|
5978
|
+
this.clear();
|
|
5979
|
+
} else {
|
|
5980
|
+
this.removeItemSize(index2);
|
|
5981
|
+
const v = this.valList[index2];
|
|
5982
|
+
if (this.isBackgroundFetch(v)) {
|
|
5983
|
+
v.__abortController.abort(new Error("deleted"));
|
|
5984
|
+
} else {
|
|
5985
|
+
this.dispose(v, k, "delete");
|
|
5986
|
+
if (this.disposeAfter) {
|
|
5987
|
+
this.disposed.push([v, k, "delete"]);
|
|
5988
|
+
}
|
|
5989
|
+
}
|
|
5990
|
+
this.keyMap.delete(k);
|
|
5991
|
+
this.keyList[index2] = null;
|
|
5992
|
+
this.valList[index2] = null;
|
|
5993
|
+
if (index2 === this.tail) {
|
|
5994
|
+
this.tail = this.prev[index2];
|
|
5995
|
+
} else if (index2 === this.head) {
|
|
5996
|
+
this.head = this.next[index2];
|
|
5997
|
+
} else {
|
|
5998
|
+
this.next[this.prev[index2]] = this.next[index2];
|
|
5999
|
+
this.prev[this.next[index2]] = this.prev[index2];
|
|
6000
|
+
}
|
|
6001
|
+
this.size--;
|
|
6002
|
+
this.free.push(index2);
|
|
6003
|
+
}
|
|
6004
|
+
}
|
|
6005
|
+
}
|
|
6006
|
+
if (this.disposed) {
|
|
6007
|
+
while (this.disposed.length) {
|
|
6008
|
+
this.disposeAfter(...this.disposed.shift());
|
|
6009
|
+
}
|
|
6010
|
+
}
|
|
6011
|
+
return deleted;
|
|
6012
|
+
}
|
|
6013
|
+
clear() {
|
|
6014
|
+
for (const index2 of this.rindexes({ allowStale: true })) {
|
|
6015
|
+
const v = this.valList[index2];
|
|
6016
|
+
if (this.isBackgroundFetch(v)) {
|
|
6017
|
+
v.__abortController.abort(new Error("deleted"));
|
|
6018
|
+
} else {
|
|
6019
|
+
const k = this.keyList[index2];
|
|
6020
|
+
this.dispose(v, k, "delete");
|
|
6021
|
+
if (this.disposeAfter) {
|
|
6022
|
+
this.disposed.push([v, k, "delete"]);
|
|
6023
|
+
}
|
|
6024
|
+
}
|
|
6025
|
+
}
|
|
6026
|
+
this.keyMap.clear();
|
|
6027
|
+
this.valList.fill(null);
|
|
6028
|
+
this.keyList.fill(null);
|
|
6029
|
+
if (this.ttls) {
|
|
6030
|
+
this.ttls.fill(0);
|
|
6031
|
+
this.starts.fill(0);
|
|
6032
|
+
}
|
|
6033
|
+
if (this.sizes) {
|
|
6034
|
+
this.sizes.fill(0);
|
|
6035
|
+
}
|
|
6036
|
+
this.head = 0;
|
|
6037
|
+
this.tail = 0;
|
|
6038
|
+
this.initialFill = 1;
|
|
6039
|
+
this.free.length = 0;
|
|
6040
|
+
this.calculatedSize = 0;
|
|
6041
|
+
this.size = 0;
|
|
6042
|
+
if (this.disposed) {
|
|
6043
|
+
while (this.disposed.length) {
|
|
6044
|
+
this.disposeAfter(...this.disposed.shift());
|
|
6045
|
+
}
|
|
6046
|
+
}
|
|
6047
|
+
}
|
|
6048
|
+
get reset() {
|
|
6049
|
+
deprecatedMethod("reset", "clear");
|
|
6050
|
+
return this.clear;
|
|
6051
|
+
}
|
|
6052
|
+
get length() {
|
|
6053
|
+
deprecatedProperty("length", "size");
|
|
6054
|
+
return this.size;
|
|
6055
|
+
}
|
|
6056
|
+
static get AbortController() {
|
|
6057
|
+
return AC;
|
|
6058
|
+
}
|
|
6059
|
+
static get AbortSignal() {
|
|
6060
|
+
return AS;
|
|
6061
|
+
}
|
|
6062
|
+
}
|
|
6063
|
+
var LRUCache$1 = LRUCache;
|
|
5080
6064
|
const splitHelp = (textarea) => {
|
|
5081
6065
|
const text = textarea.value;
|
|
5082
6066
|
const prefixStr = text.substring(0, textarea.selectionStart);
|
|
@@ -5751,6 +6735,7 @@ const useMarked = (props) => {
|
|
|
5751
6735
|
const editorId = inject("editorId");
|
|
5752
6736
|
const highlightUrl2 = inject("highlight");
|
|
5753
6737
|
const previewOnly = inject("previewOnly");
|
|
6738
|
+
const theme = inject("theme");
|
|
5754
6739
|
const highlightIns = (_a = editorExtensions == null ? void 0 : editorExtensions.highlight) == null ? void 0 : _a.instance;
|
|
5755
6740
|
const mermaidIns = (_b = editorExtensions == null ? void 0 : editorExtensions.mermaid) == null ? void 0 : _b.instance;
|
|
5756
6741
|
const katexIns = (_c = editorExtensions == null ? void 0 : editorExtensions.katex) == null ? void 0 : _c.instance;
|
|
@@ -5759,6 +6744,15 @@ const useMarked = (props) => {
|
|
|
5759
6744
|
const heads = ref([]);
|
|
5760
6745
|
let mermaidTasks = [];
|
|
5761
6746
|
let mermaidIds = [];
|
|
6747
|
+
const mermaidCache = new LRUCache$1({
|
|
6748
|
+
max: 1e3,
|
|
6749
|
+
ttl: 6e5
|
|
6750
|
+
});
|
|
6751
|
+
const mermaidData = useMermaid(props);
|
|
6752
|
+
const katexInited = useKatex(props, marked);
|
|
6753
|
+
const extensionsInited = computed(() => {
|
|
6754
|
+
return mermaidData.mermaidInited && highlightInited.value && katexInited.value;
|
|
6755
|
+
});
|
|
5762
6756
|
let renderer = new marked.Renderer();
|
|
5763
6757
|
renderer.image = (href, title, desc) => {
|
|
5764
6758
|
return `<span class="figure"><img src="${href}" title="${title || ""}" alt="${desc || ""}" zoom><span class="figcaption">${desc || ""}</span></span>`;
|
|
@@ -5778,16 +6772,25 @@ const useMarked = (props) => {
|
|
|
5778
6772
|
const idRand = uuid();
|
|
5779
6773
|
try {
|
|
5780
6774
|
if (isServer) {
|
|
5781
|
-
return `<p class="${prefix}-mermaid
|
|
6775
|
+
return `<p class="${prefix}-mermaid">${code}</p>`;
|
|
5782
6776
|
} else {
|
|
6777
|
+
const cacheSvg = mermaidCache.get(code);
|
|
6778
|
+
if (cacheSvg) {
|
|
6779
|
+
return `<p class="${prefix}-mermaid" data-processed>${cacheSvg}</p>`;
|
|
6780
|
+
}
|
|
5783
6781
|
const mermaid = mermaidIns || window.mermaid;
|
|
5784
|
-
if (
|
|
5785
|
-
|
|
6782
|
+
if (mermaidData.mermaidInited) {
|
|
6783
|
+
const render = mermaid.renderAsync || mermaid.render;
|
|
6784
|
+
const mermaidRenderTask = render(idRand, code);
|
|
6785
|
+
mermaidRenderTask.then((svg) => {
|
|
6786
|
+
mermaidCache.set(code, typeof svg === "string" ? svg : svg.svg);
|
|
6787
|
+
});
|
|
6788
|
+
mermaidTasks.push(mermaidRenderTask);
|
|
5786
6789
|
} else {
|
|
5787
|
-
return `<p class="${prefix}-mermaid
|
|
6790
|
+
return `<p class="${prefix}-mermaid">${code}</p>`;
|
|
5788
6791
|
}
|
|
5789
6792
|
}
|
|
5790
|
-
const mermaidTemplate = `<script type="text/tmplate"
|
|
6793
|
+
const mermaidTemplate = `<script type="text/tmplate">${idRand}<\/script>`;
|
|
5791
6794
|
mermaidIds.push(mermaidTemplate);
|
|
5792
6795
|
return mermaidTemplate;
|
|
5793
6796
|
} catch (error) {
|
|
@@ -5855,37 +6858,34 @@ const useMarked = (props) => {
|
|
|
5855
6858
|
}
|
|
5856
6859
|
});
|
|
5857
6860
|
}
|
|
5858
|
-
const katexInited = useKatex(props, marked);
|
|
5859
|
-
const mermaidData = useMermaid(props);
|
|
5860
6861
|
const html = ref(props.sanitize(marked(props.value || "", { renderer })));
|
|
5861
|
-
const asyncReplace = async () => {
|
|
5862
|
-
let unresolveHtml = props.sanitize(marked(
|
|
5863
|
-
const
|
|
6862
|
+
const asyncReplace = async (value) => {
|
|
6863
|
+
let unresolveHtml = props.sanitize(marked(value, { renderer }));
|
|
6864
|
+
const mermaidTasksCopy = [...mermaidTasks];
|
|
6865
|
+
const mermaidIdsCopy = [...mermaidIds];
|
|
6866
|
+
mermaidIds = [];
|
|
6867
|
+
mermaidTasks = [];
|
|
6868
|
+
const taskResults = await Promise.allSettled(mermaidTasksCopy);
|
|
5864
6869
|
taskResults.forEach((r, index2) => {
|
|
5865
6870
|
if (r.status === "fulfilled") {
|
|
5866
|
-
unresolveHtml = unresolveHtml.replace(
|
|
6871
|
+
unresolveHtml = unresolveHtml.replace(mermaidIdsCopy[index2], `<p class="${prefix}-mermaid" data-processed>${typeof r.value === "string" ? r.value : r.value.svg}</p>`);
|
|
5867
6872
|
} else {
|
|
5868
|
-
unresolveHtml = unresolveHtml.replace(
|
|
6873
|
+
unresolveHtml = unresolveHtml.replace(mermaidIdsCopy[index2], `<p class="${prefix}-mermaid-error">${r.reason || ""}</p>`);
|
|
5869
6874
|
}
|
|
5870
6875
|
});
|
|
5871
|
-
mermaidIds = [];
|
|
5872
|
-
mermaidTasks = [];
|
|
5873
6876
|
return unresolveHtml;
|
|
5874
6877
|
};
|
|
5875
6878
|
const markHtml = debounce(async () => {
|
|
5876
6879
|
heads.value = [];
|
|
5877
|
-
const resolveHtml = await asyncReplace();
|
|
6880
|
+
const resolveHtml = await asyncReplace(props.value || "");
|
|
5878
6881
|
html.value = resolveHtml;
|
|
5879
6882
|
bus.emit(editorId, "buildFinished", html.value);
|
|
5880
6883
|
props.onHtmlChanged(html.value);
|
|
5881
6884
|
}, (editorConfig == null ? void 0 : editorConfig.renderDelay) !== void 0 ? editorConfig == null ? void 0 : editorConfig.renderDelay : previewOnly ? 0 : 500);
|
|
5882
|
-
watch([
|
|
5883
|
-
|
|
5884
|
-
|
|
5885
|
-
|
|
5886
|
-
katexInited,
|
|
5887
|
-
toRef(props, "value")
|
|
5888
|
-
], markHtml);
|
|
6885
|
+
watch([extensionsInited, toRef(mermaidData, "reRender"), toRef(props, "value")], markHtml);
|
|
6886
|
+
watch([theme], () => {
|
|
6887
|
+
mermaidCache.clear();
|
|
6888
|
+
});
|
|
5889
6889
|
const highlightLoad = () => {
|
|
5890
6890
|
marked.setOptions({
|
|
5891
6891
|
highlight: (code, language) => {
|
|
@@ -6087,48 +7087,41 @@ const useMermaid = (props) => {
|
|
|
6087
7087
|
const mermaidConf = editorExtensions == null ? void 0 : editorExtensions.mermaid;
|
|
6088
7088
|
const mermaidData = reactive({
|
|
6089
7089
|
reRender: false,
|
|
6090
|
-
mermaidInited:
|
|
7090
|
+
mermaidInited: false
|
|
6091
7091
|
});
|
|
6092
|
-
const
|
|
7092
|
+
const setMermaidTheme = () => {
|
|
6093
7093
|
if (!props.noMermaid) {
|
|
6094
|
-
|
|
6095
|
-
|
|
6096
|
-
|
|
6097
|
-
|
|
6098
|
-
|
|
6099
|
-
} else if (window.mermaid) {
|
|
6100
|
-
window.mermaid.initialize({
|
|
6101
|
-
startOnLoad: false,
|
|
6102
|
-
theme: theme.value === "dark" ? "dark" : "default"
|
|
6103
|
-
});
|
|
6104
|
-
}
|
|
7094
|
+
const mermaid = (mermaidConf == null ? void 0 : mermaidConf.instance) || window.mermaid;
|
|
7095
|
+
mermaid.initialize({
|
|
7096
|
+
startOnLoad: false,
|
|
7097
|
+
theme: theme.value === "dark" ? "dark" : "default"
|
|
7098
|
+
});
|
|
6105
7099
|
mermaidData.reRender = !mermaidData.reRender;
|
|
6106
7100
|
}
|
|
6107
7101
|
};
|
|
6108
|
-
watch(() => theme.value,
|
|
6109
|
-
let mermaidScript;
|
|
7102
|
+
watch(() => theme.value, setMermaidTheme);
|
|
6110
7103
|
onMounted(() => {
|
|
6111
|
-
if (
|
|
6112
|
-
|
|
7104
|
+
if (props.noMermaid) {
|
|
7105
|
+
return;
|
|
7106
|
+
}
|
|
7107
|
+
if (!(mermaidConf == null ? void 0 : mermaidConf.instance)) {
|
|
7108
|
+
const mermaidScript = document.createElement("script");
|
|
6113
7109
|
mermaidScript.id = `${prefix}-mermaid`;
|
|
6114
7110
|
const jsSrc = (mermaidConf == null ? void 0 : mermaidConf.js) || mermaidUrl;
|
|
6115
7111
|
if (/\.mjs/.test(jsSrc)) {
|
|
6116
7112
|
mermaidScript.setAttribute("type", "module");
|
|
6117
|
-
mermaidScript.innerHTML = `import mermaid from "${jsSrc}";window.mermaid=mermaid;document.getElementById('${prefix}-mermaid').
|
|
7113
|
+
mermaidScript.innerHTML = `import mermaid from "${jsSrc}";window.mermaid=mermaid;document.getElementById('${prefix}-mermaid').dispatchEvent(new Event('load'));`;
|
|
6118
7114
|
} else {
|
|
6119
7115
|
mermaidScript.src = jsSrc;
|
|
6120
7116
|
}
|
|
6121
7117
|
mermaidScript.onload = () => {
|
|
6122
|
-
|
|
6123
|
-
startOnLoad: false,
|
|
6124
|
-
theme: theme.value === "dark" ? "dark" : "default",
|
|
6125
|
-
logLevel: "Fatal"
|
|
6126
|
-
});
|
|
7118
|
+
setMermaidTheme();
|
|
6127
7119
|
mermaidData.mermaidInited = true;
|
|
6128
7120
|
};
|
|
6129
7121
|
appendHandler(mermaidScript, "mermaid");
|
|
6130
|
-
} else
|
|
6131
|
-
|
|
7122
|
+
} else {
|
|
7123
|
+
setMermaidTheme();
|
|
7124
|
+
mermaidData.mermaidInited = true;
|
|
6132
7125
|
}
|
|
6133
7126
|
});
|
|
6134
7127
|
return mermaidData;
|