@opentui/core 0.1.83 → 0.1.85
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/3d.js +1 -1
- package/{index-a215gqtt.js → index-2yz42vd4.js} +67 -7
- package/{index-a215gqtt.js.map → index-2yz42vd4.js.map} +5 -4
- package/index.js +419 -792
- package/index.js.map +8 -17
- package/lib/detect-links.d.ts +6 -0
- package/lib/index.d.ts +1 -0
- package/package.json +7 -7
- package/parser.worker.js +1 -1
- package/parser.worker.js.map +1 -1
- package/renderables/Code.d.ts +11 -1
- package/renderables/Markdown.d.ts +33 -10
- package/renderables/ScrollBox.d.ts +8 -1
- package/renderables/TextTable.d.ts +11 -1
- package/testing.js +1 -1
package/index.js
CHANGED
|
@@ -78,6 +78,7 @@ import {
|
|
|
78
78
|
cyan,
|
|
79
79
|
defaultKeyAliases,
|
|
80
80
|
delegate,
|
|
81
|
+
detectLinks,
|
|
81
82
|
dim,
|
|
82
83
|
env,
|
|
83
84
|
envRegistry,
|
|
@@ -153,7 +154,7 @@ import {
|
|
|
153
154
|
white,
|
|
154
155
|
wrapWithDelegates,
|
|
155
156
|
yellow
|
|
156
|
-
} from "./index-
|
|
157
|
+
} from "./index-2yz42vd4.js";
|
|
157
158
|
// src/text-buffer-view.ts
|
|
158
159
|
class TextBufferView {
|
|
159
160
|
lib;
|
|
@@ -3115,6 +3116,7 @@ class CodeRenderable extends TextBufferRenderable {
|
|
|
3115
3116
|
_hadInitialContent = false;
|
|
3116
3117
|
_lastHighlights = [];
|
|
3117
3118
|
_onHighlight;
|
|
3119
|
+
_onChunks;
|
|
3118
3120
|
_contentDefaultOptions = {
|
|
3119
3121
|
content: "",
|
|
3120
3122
|
conceal: true,
|
|
@@ -3131,6 +3133,7 @@ class CodeRenderable extends TextBufferRenderable {
|
|
|
3131
3133
|
this._drawUnstyledText = options.drawUnstyledText ?? this._contentDefaultOptions.drawUnstyledText;
|
|
3132
3134
|
this._streaming = options.streaming ?? this._contentDefaultOptions.streaming;
|
|
3133
3135
|
this._onHighlight = options.onHighlight;
|
|
3136
|
+
this._onChunks = options.onChunks;
|
|
3134
3137
|
if (this._content.length > 0) {
|
|
3135
3138
|
this.textBuffer.setText(this._content);
|
|
3136
3139
|
this.updateTextInfo();
|
|
@@ -3218,9 +3221,24 @@ class CodeRenderable extends TextBufferRenderable {
|
|
|
3218
3221
|
this._highlightsDirty = true;
|
|
3219
3222
|
}
|
|
3220
3223
|
}
|
|
3224
|
+
get onChunks() {
|
|
3225
|
+
return this._onChunks;
|
|
3226
|
+
}
|
|
3227
|
+
set onChunks(value) {
|
|
3228
|
+
if (this._onChunks !== value) {
|
|
3229
|
+
this._onChunks = value;
|
|
3230
|
+
this._highlightsDirty = true;
|
|
3231
|
+
}
|
|
3232
|
+
}
|
|
3221
3233
|
get isHighlighting() {
|
|
3222
3234
|
return this._isHighlighting;
|
|
3223
3235
|
}
|
|
3236
|
+
async transformChunks(chunks, context) {
|
|
3237
|
+
if (!this._onChunks)
|
|
3238
|
+
return chunks;
|
|
3239
|
+
const modified = await this._onChunks(chunks, context);
|
|
3240
|
+
return modified ?? chunks;
|
|
3241
|
+
}
|
|
3224
3242
|
ensureVisibleTextBeforeHighlight() {
|
|
3225
3243
|
if (this.isDestroyed)
|
|
3226
3244
|
return;
|
|
@@ -3279,9 +3297,23 @@ class CodeRenderable extends TextBufferRenderable {
|
|
|
3279
3297
|
if (this._streaming) {
|
|
3280
3298
|
this._lastHighlights = highlights;
|
|
3281
3299
|
}
|
|
3282
|
-
|
|
3300
|
+
}
|
|
3301
|
+
if (highlights.length > 0 || this._onChunks) {
|
|
3302
|
+
const context = {
|
|
3303
|
+
content,
|
|
3304
|
+
filetype,
|
|
3305
|
+
syntaxStyle: this._syntaxStyle,
|
|
3306
|
+
highlights
|
|
3307
|
+
};
|
|
3308
|
+
let chunks = treeSitterToTextChunks(content, highlights, this._syntaxStyle, {
|
|
3283
3309
|
enabled: this._conceal
|
|
3284
3310
|
});
|
|
3311
|
+
chunks = await this.transformChunks(chunks, context);
|
|
3312
|
+
if (snapshotId !== this._highlightSnapshotId) {
|
|
3313
|
+
return;
|
|
3314
|
+
}
|
|
3315
|
+
if (this.isDestroyed)
|
|
3316
|
+
return;
|
|
3285
3317
|
const styledText = new StyledText(chunks);
|
|
3286
3318
|
this.textBuffer.setStyledText(styledText);
|
|
3287
3319
|
} else {
|
|
@@ -4140,617 +4172,6 @@ class LineNumberRenderable extends Renderable {
|
|
|
4140
4172
|
}
|
|
4141
4173
|
}
|
|
4142
4174
|
}
|
|
4143
|
-
|
|
4144
|
-
// ../../node_modules/.bun/diff@8.0.2/node_modules/diff/libesm/diff/base.js
|
|
4145
|
-
class Diff {
|
|
4146
|
-
diff(oldStr, newStr, options = {}) {
|
|
4147
|
-
let callback;
|
|
4148
|
-
if (typeof options === "function") {
|
|
4149
|
-
callback = options;
|
|
4150
|
-
options = {};
|
|
4151
|
-
} else if ("callback" in options) {
|
|
4152
|
-
callback = options.callback;
|
|
4153
|
-
}
|
|
4154
|
-
const oldString = this.castInput(oldStr, options);
|
|
4155
|
-
const newString = this.castInput(newStr, options);
|
|
4156
|
-
const oldTokens = this.removeEmpty(this.tokenize(oldString, options));
|
|
4157
|
-
const newTokens = this.removeEmpty(this.tokenize(newString, options));
|
|
4158
|
-
return this.diffWithOptionsObj(oldTokens, newTokens, options, callback);
|
|
4159
|
-
}
|
|
4160
|
-
diffWithOptionsObj(oldTokens, newTokens, options, callback) {
|
|
4161
|
-
var _a;
|
|
4162
|
-
const done = (value) => {
|
|
4163
|
-
value = this.postProcess(value, options);
|
|
4164
|
-
if (callback) {
|
|
4165
|
-
setTimeout(function() {
|
|
4166
|
-
callback(value);
|
|
4167
|
-
}, 0);
|
|
4168
|
-
return;
|
|
4169
|
-
} else {
|
|
4170
|
-
return value;
|
|
4171
|
-
}
|
|
4172
|
-
};
|
|
4173
|
-
const newLen = newTokens.length, oldLen = oldTokens.length;
|
|
4174
|
-
let editLength = 1;
|
|
4175
|
-
let maxEditLength = newLen + oldLen;
|
|
4176
|
-
if (options.maxEditLength != null) {
|
|
4177
|
-
maxEditLength = Math.min(maxEditLength, options.maxEditLength);
|
|
4178
|
-
}
|
|
4179
|
-
const maxExecutionTime = (_a = options.timeout) !== null && _a !== undefined ? _a : Infinity;
|
|
4180
|
-
const abortAfterTimestamp = Date.now() + maxExecutionTime;
|
|
4181
|
-
const bestPath = [{ oldPos: -1, lastComponent: undefined }];
|
|
4182
|
-
let newPos = this.extractCommon(bestPath[0], newTokens, oldTokens, 0, options);
|
|
4183
|
-
if (bestPath[0].oldPos + 1 >= oldLen && newPos + 1 >= newLen) {
|
|
4184
|
-
return done(this.buildValues(bestPath[0].lastComponent, newTokens, oldTokens));
|
|
4185
|
-
}
|
|
4186
|
-
let minDiagonalToConsider = -Infinity, maxDiagonalToConsider = Infinity;
|
|
4187
|
-
const execEditLength = () => {
|
|
4188
|
-
for (let diagonalPath = Math.max(minDiagonalToConsider, -editLength);diagonalPath <= Math.min(maxDiagonalToConsider, editLength); diagonalPath += 2) {
|
|
4189
|
-
let basePath;
|
|
4190
|
-
const removePath = bestPath[diagonalPath - 1], addPath = bestPath[diagonalPath + 1];
|
|
4191
|
-
if (removePath) {
|
|
4192
|
-
bestPath[diagonalPath - 1] = undefined;
|
|
4193
|
-
}
|
|
4194
|
-
let canAdd = false;
|
|
4195
|
-
if (addPath) {
|
|
4196
|
-
const addPathNewPos = addPath.oldPos - diagonalPath;
|
|
4197
|
-
canAdd = addPath && 0 <= addPathNewPos && addPathNewPos < newLen;
|
|
4198
|
-
}
|
|
4199
|
-
const canRemove = removePath && removePath.oldPos + 1 < oldLen;
|
|
4200
|
-
if (!canAdd && !canRemove) {
|
|
4201
|
-
bestPath[diagonalPath] = undefined;
|
|
4202
|
-
continue;
|
|
4203
|
-
}
|
|
4204
|
-
if (!canRemove || canAdd && removePath.oldPos < addPath.oldPos) {
|
|
4205
|
-
basePath = this.addToPath(addPath, true, false, 0, options);
|
|
4206
|
-
} else {
|
|
4207
|
-
basePath = this.addToPath(removePath, false, true, 1, options);
|
|
4208
|
-
}
|
|
4209
|
-
newPos = this.extractCommon(basePath, newTokens, oldTokens, diagonalPath, options);
|
|
4210
|
-
if (basePath.oldPos + 1 >= oldLen && newPos + 1 >= newLen) {
|
|
4211
|
-
return done(this.buildValues(basePath.lastComponent, newTokens, oldTokens)) || true;
|
|
4212
|
-
} else {
|
|
4213
|
-
bestPath[diagonalPath] = basePath;
|
|
4214
|
-
if (basePath.oldPos + 1 >= oldLen) {
|
|
4215
|
-
maxDiagonalToConsider = Math.min(maxDiagonalToConsider, diagonalPath - 1);
|
|
4216
|
-
}
|
|
4217
|
-
if (newPos + 1 >= newLen) {
|
|
4218
|
-
minDiagonalToConsider = Math.max(minDiagonalToConsider, diagonalPath + 1);
|
|
4219
|
-
}
|
|
4220
|
-
}
|
|
4221
|
-
}
|
|
4222
|
-
editLength++;
|
|
4223
|
-
};
|
|
4224
|
-
if (callback) {
|
|
4225
|
-
(function exec() {
|
|
4226
|
-
setTimeout(function() {
|
|
4227
|
-
if (editLength > maxEditLength || Date.now() > abortAfterTimestamp) {
|
|
4228
|
-
return callback(undefined);
|
|
4229
|
-
}
|
|
4230
|
-
if (!execEditLength()) {
|
|
4231
|
-
exec();
|
|
4232
|
-
}
|
|
4233
|
-
}, 0);
|
|
4234
|
-
})();
|
|
4235
|
-
} else {
|
|
4236
|
-
while (editLength <= maxEditLength && Date.now() <= abortAfterTimestamp) {
|
|
4237
|
-
const ret = execEditLength();
|
|
4238
|
-
if (ret) {
|
|
4239
|
-
return ret;
|
|
4240
|
-
}
|
|
4241
|
-
}
|
|
4242
|
-
}
|
|
4243
|
-
}
|
|
4244
|
-
addToPath(path, added, removed, oldPosInc, options) {
|
|
4245
|
-
const last = path.lastComponent;
|
|
4246
|
-
if (last && !options.oneChangePerToken && last.added === added && last.removed === removed) {
|
|
4247
|
-
return {
|
|
4248
|
-
oldPos: path.oldPos + oldPosInc,
|
|
4249
|
-
lastComponent: { count: last.count + 1, added, removed, previousComponent: last.previousComponent }
|
|
4250
|
-
};
|
|
4251
|
-
} else {
|
|
4252
|
-
return {
|
|
4253
|
-
oldPos: path.oldPos + oldPosInc,
|
|
4254
|
-
lastComponent: { count: 1, added, removed, previousComponent: last }
|
|
4255
|
-
};
|
|
4256
|
-
}
|
|
4257
|
-
}
|
|
4258
|
-
extractCommon(basePath, newTokens, oldTokens, diagonalPath, options) {
|
|
4259
|
-
const newLen = newTokens.length, oldLen = oldTokens.length;
|
|
4260
|
-
let oldPos = basePath.oldPos, newPos = oldPos - diagonalPath, commonCount = 0;
|
|
4261
|
-
while (newPos + 1 < newLen && oldPos + 1 < oldLen && this.equals(oldTokens[oldPos + 1], newTokens[newPos + 1], options)) {
|
|
4262
|
-
newPos++;
|
|
4263
|
-
oldPos++;
|
|
4264
|
-
commonCount++;
|
|
4265
|
-
if (options.oneChangePerToken) {
|
|
4266
|
-
basePath.lastComponent = { count: 1, previousComponent: basePath.lastComponent, added: false, removed: false };
|
|
4267
|
-
}
|
|
4268
|
-
}
|
|
4269
|
-
if (commonCount && !options.oneChangePerToken) {
|
|
4270
|
-
basePath.lastComponent = { count: commonCount, previousComponent: basePath.lastComponent, added: false, removed: false };
|
|
4271
|
-
}
|
|
4272
|
-
basePath.oldPos = oldPos;
|
|
4273
|
-
return newPos;
|
|
4274
|
-
}
|
|
4275
|
-
equals(left, right, options) {
|
|
4276
|
-
if (options.comparator) {
|
|
4277
|
-
return options.comparator(left, right);
|
|
4278
|
-
} else {
|
|
4279
|
-
return left === right || !!options.ignoreCase && left.toLowerCase() === right.toLowerCase();
|
|
4280
|
-
}
|
|
4281
|
-
}
|
|
4282
|
-
removeEmpty(array) {
|
|
4283
|
-
const ret = [];
|
|
4284
|
-
for (let i = 0;i < array.length; i++) {
|
|
4285
|
-
if (array[i]) {
|
|
4286
|
-
ret.push(array[i]);
|
|
4287
|
-
}
|
|
4288
|
-
}
|
|
4289
|
-
return ret;
|
|
4290
|
-
}
|
|
4291
|
-
castInput(value, options) {
|
|
4292
|
-
return value;
|
|
4293
|
-
}
|
|
4294
|
-
tokenize(value, options) {
|
|
4295
|
-
return Array.from(value);
|
|
4296
|
-
}
|
|
4297
|
-
join(chars) {
|
|
4298
|
-
return chars.join("");
|
|
4299
|
-
}
|
|
4300
|
-
postProcess(changeObjects, options) {
|
|
4301
|
-
return changeObjects;
|
|
4302
|
-
}
|
|
4303
|
-
get useLongestToken() {
|
|
4304
|
-
return false;
|
|
4305
|
-
}
|
|
4306
|
-
buildValues(lastComponent, newTokens, oldTokens) {
|
|
4307
|
-
const components = [];
|
|
4308
|
-
let nextComponent;
|
|
4309
|
-
while (lastComponent) {
|
|
4310
|
-
components.push(lastComponent);
|
|
4311
|
-
nextComponent = lastComponent.previousComponent;
|
|
4312
|
-
delete lastComponent.previousComponent;
|
|
4313
|
-
lastComponent = nextComponent;
|
|
4314
|
-
}
|
|
4315
|
-
components.reverse();
|
|
4316
|
-
const componentLen = components.length;
|
|
4317
|
-
let componentPos = 0, newPos = 0, oldPos = 0;
|
|
4318
|
-
for (;componentPos < componentLen; componentPos++) {
|
|
4319
|
-
const component = components[componentPos];
|
|
4320
|
-
if (!component.removed) {
|
|
4321
|
-
if (!component.added && this.useLongestToken) {
|
|
4322
|
-
let value = newTokens.slice(newPos, newPos + component.count);
|
|
4323
|
-
value = value.map(function(value2, i) {
|
|
4324
|
-
const oldValue = oldTokens[oldPos + i];
|
|
4325
|
-
return oldValue.length > value2.length ? oldValue : value2;
|
|
4326
|
-
});
|
|
4327
|
-
component.value = this.join(value);
|
|
4328
|
-
} else {
|
|
4329
|
-
component.value = this.join(newTokens.slice(newPos, newPos + component.count));
|
|
4330
|
-
}
|
|
4331
|
-
newPos += component.count;
|
|
4332
|
-
if (!component.added) {
|
|
4333
|
-
oldPos += component.count;
|
|
4334
|
-
}
|
|
4335
|
-
} else {
|
|
4336
|
-
component.value = this.join(oldTokens.slice(oldPos, oldPos + component.count));
|
|
4337
|
-
oldPos += component.count;
|
|
4338
|
-
}
|
|
4339
|
-
}
|
|
4340
|
-
return components;
|
|
4341
|
-
}
|
|
4342
|
-
}
|
|
4343
|
-
|
|
4344
|
-
// ../../node_modules/.bun/diff@8.0.2/node_modules/diff/libesm/diff/character.js
|
|
4345
|
-
class CharacterDiff extends Diff {
|
|
4346
|
-
}
|
|
4347
|
-
var characterDiff = new CharacterDiff;
|
|
4348
|
-
|
|
4349
|
-
// ../../node_modules/.bun/diff@8.0.2/node_modules/diff/libesm/util/string.js
|
|
4350
|
-
function longestCommonPrefix(str1, str2) {
|
|
4351
|
-
let i;
|
|
4352
|
-
for (i = 0;i < str1.length && i < str2.length; i++) {
|
|
4353
|
-
if (str1[i] != str2[i]) {
|
|
4354
|
-
return str1.slice(0, i);
|
|
4355
|
-
}
|
|
4356
|
-
}
|
|
4357
|
-
return str1.slice(0, i);
|
|
4358
|
-
}
|
|
4359
|
-
function longestCommonSuffix(str1, str2) {
|
|
4360
|
-
let i;
|
|
4361
|
-
if (!str1 || !str2 || str1[str1.length - 1] != str2[str2.length - 1]) {
|
|
4362
|
-
return "";
|
|
4363
|
-
}
|
|
4364
|
-
for (i = 0;i < str1.length && i < str2.length; i++) {
|
|
4365
|
-
if (str1[str1.length - (i + 1)] != str2[str2.length - (i + 1)]) {
|
|
4366
|
-
return str1.slice(-i);
|
|
4367
|
-
}
|
|
4368
|
-
}
|
|
4369
|
-
return str1.slice(-i);
|
|
4370
|
-
}
|
|
4371
|
-
function replacePrefix(string, oldPrefix, newPrefix) {
|
|
4372
|
-
if (string.slice(0, oldPrefix.length) != oldPrefix) {
|
|
4373
|
-
throw Error(`string ${JSON.stringify(string)} doesn't start with prefix ${JSON.stringify(oldPrefix)}; this is a bug`);
|
|
4374
|
-
}
|
|
4375
|
-
return newPrefix + string.slice(oldPrefix.length);
|
|
4376
|
-
}
|
|
4377
|
-
function replaceSuffix(string, oldSuffix, newSuffix) {
|
|
4378
|
-
if (!oldSuffix) {
|
|
4379
|
-
return string + newSuffix;
|
|
4380
|
-
}
|
|
4381
|
-
if (string.slice(-oldSuffix.length) != oldSuffix) {
|
|
4382
|
-
throw Error(`string ${JSON.stringify(string)} doesn't end with suffix ${JSON.stringify(oldSuffix)}; this is a bug`);
|
|
4383
|
-
}
|
|
4384
|
-
return string.slice(0, -oldSuffix.length) + newSuffix;
|
|
4385
|
-
}
|
|
4386
|
-
function removePrefix(string, oldPrefix) {
|
|
4387
|
-
return replacePrefix(string, oldPrefix, "");
|
|
4388
|
-
}
|
|
4389
|
-
function removeSuffix(string, oldSuffix) {
|
|
4390
|
-
return replaceSuffix(string, oldSuffix, "");
|
|
4391
|
-
}
|
|
4392
|
-
function maximumOverlap(string1, string2) {
|
|
4393
|
-
return string2.slice(0, overlapCount(string1, string2));
|
|
4394
|
-
}
|
|
4395
|
-
function overlapCount(a, b) {
|
|
4396
|
-
let startA = 0;
|
|
4397
|
-
if (a.length > b.length) {
|
|
4398
|
-
startA = a.length - b.length;
|
|
4399
|
-
}
|
|
4400
|
-
let endB = b.length;
|
|
4401
|
-
if (a.length < b.length) {
|
|
4402
|
-
endB = a.length;
|
|
4403
|
-
}
|
|
4404
|
-
const map = Array(endB);
|
|
4405
|
-
let k = 0;
|
|
4406
|
-
map[0] = 0;
|
|
4407
|
-
for (let j = 1;j < endB; j++) {
|
|
4408
|
-
if (b[j] == b[k]) {
|
|
4409
|
-
map[j] = map[k];
|
|
4410
|
-
} else {
|
|
4411
|
-
map[j] = k;
|
|
4412
|
-
}
|
|
4413
|
-
while (k > 0 && b[j] != b[k]) {
|
|
4414
|
-
k = map[k];
|
|
4415
|
-
}
|
|
4416
|
-
if (b[j] == b[k]) {
|
|
4417
|
-
k++;
|
|
4418
|
-
}
|
|
4419
|
-
}
|
|
4420
|
-
k = 0;
|
|
4421
|
-
for (let i = startA;i < a.length; i++) {
|
|
4422
|
-
while (k > 0 && a[i] != b[k]) {
|
|
4423
|
-
k = map[k];
|
|
4424
|
-
}
|
|
4425
|
-
if (a[i] == b[k]) {
|
|
4426
|
-
k++;
|
|
4427
|
-
}
|
|
4428
|
-
}
|
|
4429
|
-
return k;
|
|
4430
|
-
}
|
|
4431
|
-
function trailingWs(string) {
|
|
4432
|
-
let i;
|
|
4433
|
-
for (i = string.length - 1;i >= 0; i--) {
|
|
4434
|
-
if (!string[i].match(/\s/)) {
|
|
4435
|
-
break;
|
|
4436
|
-
}
|
|
4437
|
-
}
|
|
4438
|
-
return string.substring(i + 1);
|
|
4439
|
-
}
|
|
4440
|
-
function leadingWs(string) {
|
|
4441
|
-
const match = string.match(/^\s*/);
|
|
4442
|
-
return match ? match[0] : "";
|
|
4443
|
-
}
|
|
4444
|
-
|
|
4445
|
-
// ../../node_modules/.bun/diff@8.0.2/node_modules/diff/libesm/diff/word.js
|
|
4446
|
-
var extendedWordChars = "a-zA-Z0-9_\\u{C0}-\\u{FF}\\u{D8}-\\u{F6}\\u{F8}-\\u{2C6}\\u{2C8}-\\u{2D7}\\u{2DE}-\\u{2FF}\\u{1E00}-\\u{1EFF}";
|
|
4447
|
-
var tokenizeIncludingWhitespace = new RegExp(`[${extendedWordChars}]+|\\s+|[^${extendedWordChars}]`, "ug");
|
|
4448
|
-
|
|
4449
|
-
class WordDiff extends Diff {
|
|
4450
|
-
equals(left, right, options) {
|
|
4451
|
-
if (options.ignoreCase) {
|
|
4452
|
-
left = left.toLowerCase();
|
|
4453
|
-
right = right.toLowerCase();
|
|
4454
|
-
}
|
|
4455
|
-
return left.trim() === right.trim();
|
|
4456
|
-
}
|
|
4457
|
-
tokenize(value, options = {}) {
|
|
4458
|
-
let parts;
|
|
4459
|
-
if (options.intlSegmenter) {
|
|
4460
|
-
const segmenter = options.intlSegmenter;
|
|
4461
|
-
if (segmenter.resolvedOptions().granularity != "word") {
|
|
4462
|
-
throw new Error('The segmenter passed must have a granularity of "word"');
|
|
4463
|
-
}
|
|
4464
|
-
parts = Array.from(segmenter.segment(value), (segment) => segment.segment);
|
|
4465
|
-
} else {
|
|
4466
|
-
parts = value.match(tokenizeIncludingWhitespace) || [];
|
|
4467
|
-
}
|
|
4468
|
-
const tokens = [];
|
|
4469
|
-
let prevPart = null;
|
|
4470
|
-
parts.forEach((part) => {
|
|
4471
|
-
if (/\s/.test(part)) {
|
|
4472
|
-
if (prevPart == null) {
|
|
4473
|
-
tokens.push(part);
|
|
4474
|
-
} else {
|
|
4475
|
-
tokens.push(tokens.pop() + part);
|
|
4476
|
-
}
|
|
4477
|
-
} else if (prevPart != null && /\s/.test(prevPart)) {
|
|
4478
|
-
if (tokens[tokens.length - 1] == prevPart) {
|
|
4479
|
-
tokens.push(tokens.pop() + part);
|
|
4480
|
-
} else {
|
|
4481
|
-
tokens.push(prevPart + part);
|
|
4482
|
-
}
|
|
4483
|
-
} else {
|
|
4484
|
-
tokens.push(part);
|
|
4485
|
-
}
|
|
4486
|
-
prevPart = part;
|
|
4487
|
-
});
|
|
4488
|
-
return tokens;
|
|
4489
|
-
}
|
|
4490
|
-
join(tokens) {
|
|
4491
|
-
return tokens.map((token, i) => {
|
|
4492
|
-
if (i == 0) {
|
|
4493
|
-
return token;
|
|
4494
|
-
} else {
|
|
4495
|
-
return token.replace(/^\s+/, "");
|
|
4496
|
-
}
|
|
4497
|
-
}).join("");
|
|
4498
|
-
}
|
|
4499
|
-
postProcess(changes, options) {
|
|
4500
|
-
if (!changes || options.oneChangePerToken) {
|
|
4501
|
-
return changes;
|
|
4502
|
-
}
|
|
4503
|
-
let lastKeep = null;
|
|
4504
|
-
let insertion = null;
|
|
4505
|
-
let deletion = null;
|
|
4506
|
-
changes.forEach((change) => {
|
|
4507
|
-
if (change.added) {
|
|
4508
|
-
insertion = change;
|
|
4509
|
-
} else if (change.removed) {
|
|
4510
|
-
deletion = change;
|
|
4511
|
-
} else {
|
|
4512
|
-
if (insertion || deletion) {
|
|
4513
|
-
dedupeWhitespaceInChangeObjects(lastKeep, deletion, insertion, change);
|
|
4514
|
-
}
|
|
4515
|
-
lastKeep = change;
|
|
4516
|
-
insertion = null;
|
|
4517
|
-
deletion = null;
|
|
4518
|
-
}
|
|
4519
|
-
});
|
|
4520
|
-
if (insertion || deletion) {
|
|
4521
|
-
dedupeWhitespaceInChangeObjects(lastKeep, deletion, insertion, null);
|
|
4522
|
-
}
|
|
4523
|
-
return changes;
|
|
4524
|
-
}
|
|
4525
|
-
}
|
|
4526
|
-
var wordDiff = new WordDiff;
|
|
4527
|
-
function dedupeWhitespaceInChangeObjects(startKeep, deletion, insertion, endKeep) {
|
|
4528
|
-
if (deletion && insertion) {
|
|
4529
|
-
const oldWsPrefix = leadingWs(deletion.value);
|
|
4530
|
-
const oldWsSuffix = trailingWs(deletion.value);
|
|
4531
|
-
const newWsPrefix = leadingWs(insertion.value);
|
|
4532
|
-
const newWsSuffix = trailingWs(insertion.value);
|
|
4533
|
-
if (startKeep) {
|
|
4534
|
-
const commonWsPrefix = longestCommonPrefix(oldWsPrefix, newWsPrefix);
|
|
4535
|
-
startKeep.value = replaceSuffix(startKeep.value, newWsPrefix, commonWsPrefix);
|
|
4536
|
-
deletion.value = removePrefix(deletion.value, commonWsPrefix);
|
|
4537
|
-
insertion.value = removePrefix(insertion.value, commonWsPrefix);
|
|
4538
|
-
}
|
|
4539
|
-
if (endKeep) {
|
|
4540
|
-
const commonWsSuffix = longestCommonSuffix(oldWsSuffix, newWsSuffix);
|
|
4541
|
-
endKeep.value = replacePrefix(endKeep.value, newWsSuffix, commonWsSuffix);
|
|
4542
|
-
deletion.value = removeSuffix(deletion.value, commonWsSuffix);
|
|
4543
|
-
insertion.value = removeSuffix(insertion.value, commonWsSuffix);
|
|
4544
|
-
}
|
|
4545
|
-
} else if (insertion) {
|
|
4546
|
-
if (startKeep) {
|
|
4547
|
-
const ws = leadingWs(insertion.value);
|
|
4548
|
-
insertion.value = insertion.value.substring(ws.length);
|
|
4549
|
-
}
|
|
4550
|
-
if (endKeep) {
|
|
4551
|
-
const ws = leadingWs(endKeep.value);
|
|
4552
|
-
endKeep.value = endKeep.value.substring(ws.length);
|
|
4553
|
-
}
|
|
4554
|
-
} else if (startKeep && endKeep) {
|
|
4555
|
-
const newWsFull = leadingWs(endKeep.value), delWsStart = leadingWs(deletion.value), delWsEnd = trailingWs(deletion.value);
|
|
4556
|
-
const newWsStart = longestCommonPrefix(newWsFull, delWsStart);
|
|
4557
|
-
deletion.value = removePrefix(deletion.value, newWsStart);
|
|
4558
|
-
const newWsEnd = longestCommonSuffix(removePrefix(newWsFull, newWsStart), delWsEnd);
|
|
4559
|
-
deletion.value = removeSuffix(deletion.value, newWsEnd);
|
|
4560
|
-
endKeep.value = replacePrefix(endKeep.value, newWsFull, newWsEnd);
|
|
4561
|
-
startKeep.value = replaceSuffix(startKeep.value, newWsFull, newWsFull.slice(0, newWsFull.length - newWsEnd.length));
|
|
4562
|
-
} else if (endKeep) {
|
|
4563
|
-
const endKeepWsPrefix = leadingWs(endKeep.value);
|
|
4564
|
-
const deletionWsSuffix = trailingWs(deletion.value);
|
|
4565
|
-
const overlap = maximumOverlap(deletionWsSuffix, endKeepWsPrefix);
|
|
4566
|
-
deletion.value = removeSuffix(deletion.value, overlap);
|
|
4567
|
-
} else if (startKeep) {
|
|
4568
|
-
const startKeepWsSuffix = trailingWs(startKeep.value);
|
|
4569
|
-
const deletionWsPrefix = leadingWs(deletion.value);
|
|
4570
|
-
const overlap = maximumOverlap(startKeepWsSuffix, deletionWsPrefix);
|
|
4571
|
-
deletion.value = removePrefix(deletion.value, overlap);
|
|
4572
|
-
}
|
|
4573
|
-
}
|
|
4574
|
-
|
|
4575
|
-
class WordsWithSpaceDiff extends Diff {
|
|
4576
|
-
tokenize(value) {
|
|
4577
|
-
const regex = new RegExp(`(\\r?\\n)|[${extendedWordChars}]+|[^\\S\\n\\r]+|[^${extendedWordChars}]`, "ug");
|
|
4578
|
-
return value.match(regex) || [];
|
|
4579
|
-
}
|
|
4580
|
-
}
|
|
4581
|
-
var wordsWithSpaceDiff = new WordsWithSpaceDiff;
|
|
4582
|
-
|
|
4583
|
-
// ../../node_modules/.bun/diff@8.0.2/node_modules/diff/libesm/diff/line.js
|
|
4584
|
-
class LineDiff extends Diff {
|
|
4585
|
-
constructor() {
|
|
4586
|
-
super(...arguments);
|
|
4587
|
-
this.tokenize = tokenize;
|
|
4588
|
-
}
|
|
4589
|
-
equals(left, right, options) {
|
|
4590
|
-
if (options.ignoreWhitespace) {
|
|
4591
|
-
if (!options.newlineIsToken || !left.includes(`
|
|
4592
|
-
`)) {
|
|
4593
|
-
left = left.trim();
|
|
4594
|
-
}
|
|
4595
|
-
if (!options.newlineIsToken || !right.includes(`
|
|
4596
|
-
`)) {
|
|
4597
|
-
right = right.trim();
|
|
4598
|
-
}
|
|
4599
|
-
} else if (options.ignoreNewlineAtEof && !options.newlineIsToken) {
|
|
4600
|
-
if (left.endsWith(`
|
|
4601
|
-
`)) {
|
|
4602
|
-
left = left.slice(0, -1);
|
|
4603
|
-
}
|
|
4604
|
-
if (right.endsWith(`
|
|
4605
|
-
`)) {
|
|
4606
|
-
right = right.slice(0, -1);
|
|
4607
|
-
}
|
|
4608
|
-
}
|
|
4609
|
-
return super.equals(left, right, options);
|
|
4610
|
-
}
|
|
4611
|
-
}
|
|
4612
|
-
var lineDiff = new LineDiff;
|
|
4613
|
-
function tokenize(value, options) {
|
|
4614
|
-
if (options.stripTrailingCr) {
|
|
4615
|
-
value = value.replace(/\r\n/g, `
|
|
4616
|
-
`);
|
|
4617
|
-
}
|
|
4618
|
-
const retLines = [], linesAndNewlines = value.split(/(\n|\r\n)/);
|
|
4619
|
-
if (!linesAndNewlines[linesAndNewlines.length - 1]) {
|
|
4620
|
-
linesAndNewlines.pop();
|
|
4621
|
-
}
|
|
4622
|
-
for (let i = 0;i < linesAndNewlines.length; i++) {
|
|
4623
|
-
const line = linesAndNewlines[i];
|
|
4624
|
-
if (i % 2 && !options.newlineIsToken) {
|
|
4625
|
-
retLines[retLines.length - 1] += line;
|
|
4626
|
-
} else {
|
|
4627
|
-
retLines.push(line);
|
|
4628
|
-
}
|
|
4629
|
-
}
|
|
4630
|
-
return retLines;
|
|
4631
|
-
}
|
|
4632
|
-
|
|
4633
|
-
// ../../node_modules/.bun/diff@8.0.2/node_modules/diff/libesm/diff/sentence.js
|
|
4634
|
-
function isSentenceEndPunct(char) {
|
|
4635
|
-
return char == "." || char == "!" || char == "?";
|
|
4636
|
-
}
|
|
4637
|
-
|
|
4638
|
-
class SentenceDiff extends Diff {
|
|
4639
|
-
tokenize(value) {
|
|
4640
|
-
var _a;
|
|
4641
|
-
const result = [];
|
|
4642
|
-
let tokenStartI = 0;
|
|
4643
|
-
for (let i = 0;i < value.length; i++) {
|
|
4644
|
-
if (i == value.length - 1) {
|
|
4645
|
-
result.push(value.slice(tokenStartI));
|
|
4646
|
-
break;
|
|
4647
|
-
}
|
|
4648
|
-
if (isSentenceEndPunct(value[i]) && value[i + 1].match(/\s/)) {
|
|
4649
|
-
result.push(value.slice(tokenStartI, i + 1));
|
|
4650
|
-
i = tokenStartI = i + 1;
|
|
4651
|
-
while ((_a = value[i + 1]) === null || _a === undefined ? undefined : _a.match(/\s/)) {
|
|
4652
|
-
i++;
|
|
4653
|
-
}
|
|
4654
|
-
result.push(value.slice(tokenStartI, i + 1));
|
|
4655
|
-
tokenStartI = i + 1;
|
|
4656
|
-
}
|
|
4657
|
-
}
|
|
4658
|
-
return result;
|
|
4659
|
-
}
|
|
4660
|
-
}
|
|
4661
|
-
var sentenceDiff = new SentenceDiff;
|
|
4662
|
-
|
|
4663
|
-
// ../../node_modules/.bun/diff@8.0.2/node_modules/diff/libesm/diff/css.js
|
|
4664
|
-
class CssDiff extends Diff {
|
|
4665
|
-
tokenize(value) {
|
|
4666
|
-
return value.split(/([{}:;,]|\s+)/);
|
|
4667
|
-
}
|
|
4668
|
-
}
|
|
4669
|
-
var cssDiff = new CssDiff;
|
|
4670
|
-
|
|
4671
|
-
// ../../node_modules/.bun/diff@8.0.2/node_modules/diff/libesm/diff/json.js
|
|
4672
|
-
class JsonDiff extends Diff {
|
|
4673
|
-
constructor() {
|
|
4674
|
-
super(...arguments);
|
|
4675
|
-
this.tokenize = tokenize;
|
|
4676
|
-
}
|
|
4677
|
-
get useLongestToken() {
|
|
4678
|
-
return true;
|
|
4679
|
-
}
|
|
4680
|
-
castInput(value, options) {
|
|
4681
|
-
const { undefinedReplacement, stringifyReplacer = (k, v) => typeof v === "undefined" ? undefinedReplacement : v } = options;
|
|
4682
|
-
return typeof value === "string" ? value : JSON.stringify(canonicalize(value, null, null, stringifyReplacer), null, " ");
|
|
4683
|
-
}
|
|
4684
|
-
equals(left, right, options) {
|
|
4685
|
-
return super.equals(left.replace(/,([\r\n])/g, "$1"), right.replace(/,([\r\n])/g, "$1"), options);
|
|
4686
|
-
}
|
|
4687
|
-
}
|
|
4688
|
-
var jsonDiff = new JsonDiff;
|
|
4689
|
-
function canonicalize(obj, stack, replacementStack, replacer, key) {
|
|
4690
|
-
stack = stack || [];
|
|
4691
|
-
replacementStack = replacementStack || [];
|
|
4692
|
-
if (replacer) {
|
|
4693
|
-
obj = replacer(key === undefined ? "" : key, obj);
|
|
4694
|
-
}
|
|
4695
|
-
let i;
|
|
4696
|
-
for (i = 0;i < stack.length; i += 1) {
|
|
4697
|
-
if (stack[i] === obj) {
|
|
4698
|
-
return replacementStack[i];
|
|
4699
|
-
}
|
|
4700
|
-
}
|
|
4701
|
-
let canonicalizedObj;
|
|
4702
|
-
if (Object.prototype.toString.call(obj) === "[object Array]") {
|
|
4703
|
-
stack.push(obj);
|
|
4704
|
-
canonicalizedObj = new Array(obj.length);
|
|
4705
|
-
replacementStack.push(canonicalizedObj);
|
|
4706
|
-
for (i = 0;i < obj.length; i += 1) {
|
|
4707
|
-
canonicalizedObj[i] = canonicalize(obj[i], stack, replacementStack, replacer, String(i));
|
|
4708
|
-
}
|
|
4709
|
-
stack.pop();
|
|
4710
|
-
replacementStack.pop();
|
|
4711
|
-
return canonicalizedObj;
|
|
4712
|
-
}
|
|
4713
|
-
if (obj && obj.toJSON) {
|
|
4714
|
-
obj = obj.toJSON();
|
|
4715
|
-
}
|
|
4716
|
-
if (typeof obj === "object" && obj !== null) {
|
|
4717
|
-
stack.push(obj);
|
|
4718
|
-
canonicalizedObj = {};
|
|
4719
|
-
replacementStack.push(canonicalizedObj);
|
|
4720
|
-
const sortedKeys = [];
|
|
4721
|
-
let key2;
|
|
4722
|
-
for (key2 in obj) {
|
|
4723
|
-
if (Object.prototype.hasOwnProperty.call(obj, key2)) {
|
|
4724
|
-
sortedKeys.push(key2);
|
|
4725
|
-
}
|
|
4726
|
-
}
|
|
4727
|
-
sortedKeys.sort();
|
|
4728
|
-
for (i = 0;i < sortedKeys.length; i += 1) {
|
|
4729
|
-
key2 = sortedKeys[i];
|
|
4730
|
-
canonicalizedObj[key2] = canonicalize(obj[key2], stack, replacementStack, replacer, key2);
|
|
4731
|
-
}
|
|
4732
|
-
stack.pop();
|
|
4733
|
-
replacementStack.pop();
|
|
4734
|
-
} else {
|
|
4735
|
-
canonicalizedObj = obj;
|
|
4736
|
-
}
|
|
4737
|
-
return canonicalizedObj;
|
|
4738
|
-
}
|
|
4739
|
-
|
|
4740
|
-
// ../../node_modules/.bun/diff@8.0.2/node_modules/diff/libesm/diff/array.js
|
|
4741
|
-
class ArrayDiff extends Diff {
|
|
4742
|
-
tokenize(value) {
|
|
4743
|
-
return value.slice();
|
|
4744
|
-
}
|
|
4745
|
-
join(value) {
|
|
4746
|
-
return value;
|
|
4747
|
-
}
|
|
4748
|
-
removeEmpty(value) {
|
|
4749
|
-
return value;
|
|
4750
|
-
}
|
|
4751
|
-
}
|
|
4752
|
-
var arrayDiff = new ArrayDiff;
|
|
4753
|
-
|
|
4754
4175
|
// ../../node_modules/.bun/diff@8.0.2/node_modules/diff/libesm/patch/parse.js
|
|
4755
4176
|
function parsePatch(uniDiff) {
|
|
4756
4177
|
const diffstr = uniDiff.split(/\n/), list = [];
|
|
@@ -4855,7 +4276,6 @@ function parsePatch(uniDiff) {
|
|
|
4855
4276
|
}
|
|
4856
4277
|
return list;
|
|
4857
4278
|
}
|
|
4858
|
-
|
|
4859
4279
|
// src/renderables/Text.ts
|
|
4860
4280
|
class TextRenderable extends TextBufferRenderable {
|
|
4861
4281
|
_text;
|
|
@@ -7171,6 +6591,7 @@ class TextTableRenderable extends Renderable {
|
|
|
7171
6591
|
_content;
|
|
7172
6592
|
_wrapMode;
|
|
7173
6593
|
_columnWidthMode;
|
|
6594
|
+
_columnFitter;
|
|
7174
6595
|
_cellPadding;
|
|
7175
6596
|
_showBorders;
|
|
7176
6597
|
_border;
|
|
@@ -7198,8 +6619,9 @@ class TextTableRenderable extends Renderable {
|
|
|
7198
6619
|
_cachedMeasureWidth = undefined;
|
|
7199
6620
|
_defaultOptions = {
|
|
7200
6621
|
content: [],
|
|
7201
|
-
wrapMode: "
|
|
7202
|
-
columnWidthMode: "
|
|
6622
|
+
wrapMode: "word",
|
|
6623
|
+
columnWidthMode: "full",
|
|
6624
|
+
columnFitter: "proportional",
|
|
7203
6625
|
cellPadding: 0,
|
|
7204
6626
|
showBorders: true,
|
|
7205
6627
|
border: true,
|
|
@@ -7216,10 +6638,11 @@ class TextTableRenderable extends Renderable {
|
|
|
7216
6638
|
attributes: 0
|
|
7217
6639
|
};
|
|
7218
6640
|
constructor(ctx, options = {}) {
|
|
7219
|
-
super(ctx, { ...options, buffered: true });
|
|
6641
|
+
super(ctx, { ...options, flexShrink: options.flexShrink ?? 0, buffered: true });
|
|
7220
6642
|
this._content = options.content ?? this._defaultOptions.content;
|
|
7221
6643
|
this._wrapMode = options.wrapMode ?? this._defaultOptions.wrapMode;
|
|
7222
6644
|
this._columnWidthMode = options.columnWidthMode ?? this._defaultOptions.columnWidthMode;
|
|
6645
|
+
this._columnFitter = this.resolveColumnFitter(options.columnFitter);
|
|
7223
6646
|
this._cellPadding = this.resolveCellPadding(options.cellPadding);
|
|
7224
6647
|
this._showBorders = options.showBorders ?? this._defaultOptions.showBorders;
|
|
7225
6648
|
this._border = options.border ?? this._defaultOptions.border;
|
|
@@ -7268,6 +6691,16 @@ class TextTableRenderable extends Renderable {
|
|
|
7268
6691
|
this._columnWidthMode = value;
|
|
7269
6692
|
this.invalidateLayoutAndRaster();
|
|
7270
6693
|
}
|
|
6694
|
+
get columnFitter() {
|
|
6695
|
+
return this._columnFitter;
|
|
6696
|
+
}
|
|
6697
|
+
set columnFitter(value) {
|
|
6698
|
+
const next = this.resolveColumnFitter(value);
|
|
6699
|
+
if (this._columnFitter === next)
|
|
6700
|
+
return;
|
|
6701
|
+
this._columnFitter = next;
|
|
6702
|
+
this.invalidateLayoutAndRaster();
|
|
6703
|
+
}
|
|
7271
6704
|
get cellPadding() {
|
|
7272
6705
|
return this._cellPadding;
|
|
7273
6706
|
}
|
|
@@ -7421,7 +6854,7 @@ class TextTableRenderable extends Renderable {
|
|
|
7421
6854
|
super.destroySelf();
|
|
7422
6855
|
}
|
|
7423
6856
|
setupMeasureFunc() {
|
|
7424
|
-
const measureFunc = (width, widthMode,
|
|
6857
|
+
const measureFunc = (width, widthMode, _height, _heightMode) => {
|
|
7425
6858
|
const hasWidthConstraint = widthMode !== MeasureMode.Undefined && Number.isFinite(width);
|
|
7426
6859
|
const rawWidthConstraint = hasWidthConstraint ? Math.max(1, Math.floor(width)) : undefined;
|
|
7427
6860
|
const widthConstraint = this.resolveLayoutWidthConstraint(rawWidthConstraint);
|
|
@@ -7433,9 +6866,6 @@ class TextTableRenderable extends Renderable {
|
|
|
7433
6866
|
if (widthMode === MeasureMode.AtMost && rawWidthConstraint !== undefined && this._positionType !== "absolute") {
|
|
7434
6867
|
measuredWidth = Math.min(rawWidthConstraint, measuredWidth);
|
|
7435
6868
|
}
|
|
7436
|
-
if (heightMode === MeasureMode.AtMost && Number.isFinite(height) && this._positionType !== "absolute") {
|
|
7437
|
-
measuredHeight = Math.min(Math.max(1, Math.floor(height)), measuredHeight);
|
|
7438
|
-
}
|
|
7439
6869
|
return {
|
|
7440
6870
|
width: measuredWidth,
|
|
7441
6871
|
height: measuredHeight
|
|
@@ -7607,6 +7037,9 @@ class TextTableRenderable extends Renderable {
|
|
|
7607
7037
|
tableHeight: (rowOffsets[rowOffsets.length - 1] ?? 0) + 1
|
|
7608
7038
|
};
|
|
7609
7039
|
}
|
|
7040
|
+
isFullWidthMode() {
|
|
7041
|
+
return this._columnWidthMode === "full";
|
|
7042
|
+
}
|
|
7610
7043
|
computeColumnWidths(maxTableWidth, borderLayout) {
|
|
7611
7044
|
const horizontalPadding = this.getHorizontalCellPadding();
|
|
7612
7045
|
const intrinsicWidths = new Array(this._columnCount).fill(1 + horizontalPadding);
|
|
@@ -7629,7 +7062,7 @@ class TextTableRenderable extends Renderable {
|
|
|
7629
7062
|
return intrinsicWidths;
|
|
7630
7063
|
}
|
|
7631
7064
|
if (currentWidth < maxContentWidth) {
|
|
7632
|
-
if (this.
|
|
7065
|
+
if (this.isFullWidthMode()) {
|
|
7633
7066
|
return this.expandColumnWidths(intrinsicWidths, maxContentWidth);
|
|
7634
7067
|
}
|
|
7635
7068
|
return intrinsicWidths;
|
|
@@ -7659,6 +7092,12 @@ class TextTableRenderable extends Renderable {
|
|
|
7659
7092
|
return expanded;
|
|
7660
7093
|
}
|
|
7661
7094
|
fitColumnWidths(widths, targetContentWidth) {
|
|
7095
|
+
if (this._columnFitter === "balanced") {
|
|
7096
|
+
return this.fitColumnWidthsBalanced(widths, targetContentWidth);
|
|
7097
|
+
}
|
|
7098
|
+
return this.fitColumnWidthsProportional(widths, targetContentWidth);
|
|
7099
|
+
}
|
|
7100
|
+
fitColumnWidthsProportional(widths, targetContentWidth) {
|
|
7662
7101
|
const minWidth = 1 + this.getHorizontalCellPadding();
|
|
7663
7102
|
const hardMinWidths = new Array(widths.length).fill(minWidth);
|
|
7664
7103
|
const baseWidths = widths.map((width) => Math.max(1, Math.floor(width)));
|
|
@@ -7709,6 +7148,80 @@ class TextTableRenderable extends Renderable {
|
|
|
7709
7148
|
}
|
|
7710
7149
|
return baseWidths.map((width, idx) => Math.max(floorWidths[idx], width - integerShrink[idx]));
|
|
7711
7150
|
}
|
|
7151
|
+
fitColumnWidthsBalanced(widths, targetContentWidth) {
|
|
7152
|
+
const minWidth = 1 + this.getHorizontalCellPadding();
|
|
7153
|
+
const hardMinWidths = new Array(widths.length).fill(minWidth);
|
|
7154
|
+
const baseWidths = widths.map((width) => Math.max(1, Math.floor(width)));
|
|
7155
|
+
const totalBaseWidth = baseWidths.reduce((sum, width) => sum + width, 0);
|
|
7156
|
+
const columns = baseWidths.length;
|
|
7157
|
+
if (columns === 0 || totalBaseWidth <= targetContentWidth) {
|
|
7158
|
+
return baseWidths;
|
|
7159
|
+
}
|
|
7160
|
+
const evenShare = Math.max(minWidth, Math.floor(targetContentWidth / columns));
|
|
7161
|
+
const preferredMinWidths = baseWidths.map((width) => Math.min(width, evenShare));
|
|
7162
|
+
const preferredMinTotal = preferredMinWidths.reduce((sum, width) => sum + width, 0);
|
|
7163
|
+
const floorWidths = preferredMinTotal <= targetContentWidth ? preferredMinWidths : hardMinWidths;
|
|
7164
|
+
const floorTotal = floorWidths.reduce((sum, width) => sum + width, 0);
|
|
7165
|
+
const clampedTarget = Math.max(floorTotal, targetContentWidth);
|
|
7166
|
+
if (totalBaseWidth <= clampedTarget) {
|
|
7167
|
+
return baseWidths;
|
|
7168
|
+
}
|
|
7169
|
+
const shrinkable = baseWidths.map((width, idx) => width - floorWidths[idx]);
|
|
7170
|
+
const totalShrinkable = shrinkable.reduce((sum, value) => sum + value, 0);
|
|
7171
|
+
if (totalShrinkable <= 0) {
|
|
7172
|
+
return [...floorWidths];
|
|
7173
|
+
}
|
|
7174
|
+
const targetShrink = totalBaseWidth - clampedTarget;
|
|
7175
|
+
const shrink = this.allocateShrinkByWeight(shrinkable, targetShrink, "sqrt");
|
|
7176
|
+
return baseWidths.map((width, idx) => Math.max(floorWidths[idx], width - shrink[idx]));
|
|
7177
|
+
}
|
|
7178
|
+
allocateShrinkByWeight(shrinkable, targetShrink, mode) {
|
|
7179
|
+
const shrink = new Array(shrinkable.length).fill(0);
|
|
7180
|
+
if (targetShrink <= 0) {
|
|
7181
|
+
return shrink;
|
|
7182
|
+
}
|
|
7183
|
+
const weights = shrinkable.map((value) => {
|
|
7184
|
+
if (value <= 0) {
|
|
7185
|
+
return 0;
|
|
7186
|
+
}
|
|
7187
|
+
return mode === "sqrt" ? Math.sqrt(value) : value;
|
|
7188
|
+
});
|
|
7189
|
+
const totalWeight = weights.reduce((sum, value) => sum + value, 0);
|
|
7190
|
+
if (totalWeight <= 0) {
|
|
7191
|
+
return shrink;
|
|
7192
|
+
}
|
|
7193
|
+
const fractions = new Array(shrinkable.length).fill(0);
|
|
7194
|
+
let usedShrink = 0;
|
|
7195
|
+
for (let idx = 0;idx < shrinkable.length; idx++) {
|
|
7196
|
+
if (shrinkable[idx] <= 0 || weights[idx] <= 0)
|
|
7197
|
+
continue;
|
|
7198
|
+
const exact = weights[idx] / totalWeight * targetShrink;
|
|
7199
|
+
const whole = Math.min(shrinkable[idx], Math.floor(exact));
|
|
7200
|
+
shrink[idx] = whole;
|
|
7201
|
+
fractions[idx] = exact - whole;
|
|
7202
|
+
usedShrink += whole;
|
|
7203
|
+
}
|
|
7204
|
+
let remainingShrink = targetShrink - usedShrink;
|
|
7205
|
+
while (remainingShrink > 0) {
|
|
7206
|
+
let bestIdx = -1;
|
|
7207
|
+
let bestFraction = -1;
|
|
7208
|
+
for (let idx = 0;idx < shrinkable.length; idx++) {
|
|
7209
|
+
if (shrinkable[idx] - shrink[idx] <= 0)
|
|
7210
|
+
continue;
|
|
7211
|
+
if (bestIdx === -1 || fractions[idx] > bestFraction || fractions[idx] === bestFraction && shrinkable[idx] > shrinkable[bestIdx]) {
|
|
7212
|
+
bestIdx = idx;
|
|
7213
|
+
bestFraction = fractions[idx];
|
|
7214
|
+
}
|
|
7215
|
+
}
|
|
7216
|
+
if (bestIdx === -1) {
|
|
7217
|
+
break;
|
|
7218
|
+
}
|
|
7219
|
+
shrink[bestIdx] += 1;
|
|
7220
|
+
fractions[bestIdx] = 0;
|
|
7221
|
+
remainingShrink -= 1;
|
|
7222
|
+
}
|
|
7223
|
+
return shrink;
|
|
7224
|
+
}
|
|
7712
7225
|
computeRowHeights(columnWidths) {
|
|
7713
7226
|
const horizontalPadding = this.getHorizontalCellPadding();
|
|
7714
7227
|
const verticalPadding = this.getVerticalCellPadding();
|
|
@@ -8032,7 +7545,7 @@ class TextTableRenderable extends Renderable {
|
|
|
8032
7545
|
if (width === undefined || !Number.isFinite(width) || width <= 0) {
|
|
8033
7546
|
return;
|
|
8034
7547
|
}
|
|
8035
|
-
if (this._wrapMode !== "none" || this.
|
|
7548
|
+
if (this._wrapMode !== "none" || this.isFullWidthMode()) {
|
|
8036
7549
|
return Math.max(1, Math.floor(width));
|
|
8037
7550
|
}
|
|
8038
7551
|
return;
|
|
@@ -8043,6 +7556,12 @@ class TextTableRenderable extends Renderable {
|
|
|
8043
7556
|
getVerticalCellPadding() {
|
|
8044
7557
|
return this._cellPadding * 2;
|
|
8045
7558
|
}
|
|
7559
|
+
resolveColumnFitter(value) {
|
|
7560
|
+
if (value === undefined) {
|
|
7561
|
+
return this._defaultOptions.columnFitter;
|
|
7562
|
+
}
|
|
7563
|
+
return value === "balanced" ? "balanced" : "proportional";
|
|
7564
|
+
}
|
|
8046
7565
|
resolveCellPadding(value) {
|
|
8047
7566
|
if (value === undefined || !Number.isFinite(value)) {
|
|
8048
7567
|
return this._defaultOptions.cellPadding;
|
|
@@ -9365,15 +8884,23 @@ function parseMarkdownIncremental(newContent, prevState, trailingUnstable = 2) {
|
|
|
9365
8884
|
const newTokens = x.lex(remainingContent, { gfm: true });
|
|
9366
8885
|
return { content: newContent, tokens: [...stableTokens, ...newTokens] };
|
|
9367
8886
|
} catch {
|
|
9368
|
-
|
|
8887
|
+
try {
|
|
8888
|
+
const fullTokens = x.lex(newContent, { gfm: true });
|
|
8889
|
+
return { content: newContent, tokens: fullTokens };
|
|
8890
|
+
} catch {
|
|
8891
|
+
return { content: newContent, tokens: [] };
|
|
8892
|
+
}
|
|
9369
8893
|
}
|
|
9370
8894
|
}
|
|
9371
8895
|
|
|
9372
8896
|
// src/renderables/Markdown.ts
|
|
8897
|
+
var TRAILING_MARKDOWN_BLOCK_BREAKS_RE = /(?:\r?\n){2,}$/;
|
|
8898
|
+
|
|
9373
8899
|
class MarkdownRenderable extends Renderable {
|
|
9374
8900
|
_content = "";
|
|
9375
8901
|
_syntaxStyle;
|
|
9376
8902
|
_conceal;
|
|
8903
|
+
_concealCode;
|
|
9377
8904
|
_treeSitterClient;
|
|
9378
8905
|
_tableOptions;
|
|
9379
8906
|
_renderNode;
|
|
@@ -9381,9 +8908,14 @@ class MarkdownRenderable extends Renderable {
|
|
|
9381
8908
|
_streaming = false;
|
|
9382
8909
|
_blockStates = [];
|
|
9383
8910
|
_styleDirty = false;
|
|
8911
|
+
_linkifyMarkdownChunks = (chunks, context) => detectLinks(chunks, {
|
|
8912
|
+
content: context.content,
|
|
8913
|
+
highlights: context.highlights
|
|
8914
|
+
});
|
|
9384
8915
|
_contentDefaultOptions = {
|
|
9385
8916
|
content: "",
|
|
9386
8917
|
conceal: true,
|
|
8918
|
+
concealCode: false,
|
|
9387
8919
|
streaming: false
|
|
9388
8920
|
};
|
|
9389
8921
|
constructor(ctx, options) {
|
|
@@ -9394,6 +8926,7 @@ class MarkdownRenderable extends Renderable {
|
|
|
9394
8926
|
});
|
|
9395
8927
|
this._syntaxStyle = options.syntaxStyle;
|
|
9396
8928
|
this._conceal = options.conceal ?? this._contentDefaultOptions.conceal;
|
|
8929
|
+
this._concealCode = options.concealCode ?? this._contentDefaultOptions.concealCode;
|
|
9397
8930
|
this._content = options.content ?? this._contentDefaultOptions.content;
|
|
9398
8931
|
this._treeSitterClient = options.treeSitterClient;
|
|
9399
8932
|
this._tableOptions = options.tableOptions;
|
|
@@ -9405,6 +8938,8 @@ class MarkdownRenderable extends Renderable {
|
|
|
9405
8938
|
return this._content;
|
|
9406
8939
|
}
|
|
9407
8940
|
set content(value) {
|
|
8941
|
+
if (this.isDestroyed)
|
|
8942
|
+
return;
|
|
9408
8943
|
if (this._content !== value) {
|
|
9409
8944
|
this._content = value;
|
|
9410
8945
|
this.updateBlocks();
|
|
@@ -9429,13 +8964,24 @@ class MarkdownRenderable extends Renderable {
|
|
|
9429
8964
|
this._styleDirty = true;
|
|
9430
8965
|
}
|
|
9431
8966
|
}
|
|
8967
|
+
get concealCode() {
|
|
8968
|
+
return this._concealCode;
|
|
8969
|
+
}
|
|
8970
|
+
set concealCode(value) {
|
|
8971
|
+
if (this._concealCode !== value) {
|
|
8972
|
+
this._concealCode = value;
|
|
8973
|
+
this._styleDirty = true;
|
|
8974
|
+
}
|
|
8975
|
+
}
|
|
9432
8976
|
get streaming() {
|
|
9433
8977
|
return this._streaming;
|
|
9434
8978
|
}
|
|
9435
8979
|
set streaming(value) {
|
|
8980
|
+
if (this.isDestroyed)
|
|
8981
|
+
return;
|
|
9436
8982
|
if (this._streaming !== value) {
|
|
9437
8983
|
this._streaming = value;
|
|
9438
|
-
this.
|
|
8984
|
+
this.updateBlocks(true);
|
|
9439
8985
|
}
|
|
9440
8986
|
}
|
|
9441
8987
|
get tableOptions() {
|
|
@@ -9597,92 +9143,17 @@ class MarkdownRenderable extends Renderable {
|
|
|
9597
9143
|
break;
|
|
9598
9144
|
}
|
|
9599
9145
|
}
|
|
9600
|
-
|
|
9601
|
-
|
|
9602
|
-
const group = `markup.heading.${token.depth}`;
|
|
9603
|
-
const marker = "#".repeat(token.depth) + " ";
|
|
9604
|
-
if (!this._conceal) {
|
|
9605
|
-
chunks.push(this.createChunk(marker, group));
|
|
9606
|
-
}
|
|
9607
|
-
for (const child of token.tokens) {
|
|
9608
|
-
this.renderInlineTokenWithStyle(child, chunks, group);
|
|
9609
|
-
}
|
|
9610
|
-
return chunks;
|
|
9611
|
-
}
|
|
9612
|
-
renderParagraphChunks(token) {
|
|
9613
|
-
const chunks = [];
|
|
9614
|
-
this.renderInlineContent(token.tokens, chunks);
|
|
9615
|
-
return chunks;
|
|
9616
|
-
}
|
|
9617
|
-
renderBlockquoteChunks(token) {
|
|
9618
|
-
const chunks = [];
|
|
9619
|
-
for (const child of token.tokens) {
|
|
9620
|
-
chunks.push(this.createChunk("> ", "punctuation.special"));
|
|
9621
|
-
const childChunks = this.renderTokenToChunks(child);
|
|
9622
|
-
chunks.push(...childChunks);
|
|
9623
|
-
chunks.push(this.createDefaultChunk(`
|
|
9624
|
-
`));
|
|
9625
|
-
}
|
|
9626
|
-
return chunks;
|
|
9627
|
-
}
|
|
9628
|
-
renderListChunks(token) {
|
|
9629
|
-
const chunks = [];
|
|
9630
|
-
let index = typeof token.start === "number" ? token.start : 1;
|
|
9631
|
-
for (const item of token.items) {
|
|
9632
|
-
if (token.ordered) {
|
|
9633
|
-
chunks.push(this.createChunk(`${index}. `, "markup.list"));
|
|
9634
|
-
index++;
|
|
9635
|
-
} else {
|
|
9636
|
-
chunks.push(this.createChunk("- ", "markup.list"));
|
|
9637
|
-
}
|
|
9638
|
-
for (let i = 0;i < item.tokens.length; i++) {
|
|
9639
|
-
const child = item.tokens[i];
|
|
9640
|
-
if (child.type === "text" && i === 0 && "tokens" in child && child.tokens) {
|
|
9641
|
-
this.renderInlineContent(child.tokens, chunks);
|
|
9642
|
-
chunks.push(this.createDefaultChunk(`
|
|
9643
|
-
`));
|
|
9644
|
-
} else if (child.type === "paragraph" && i === 0) {
|
|
9645
|
-
this.renderInlineContent(child.tokens, chunks);
|
|
9646
|
-
chunks.push(this.createDefaultChunk(`
|
|
9647
|
-
`));
|
|
9648
|
-
} else {
|
|
9649
|
-
const childChunks = this.renderTokenToChunks(child);
|
|
9650
|
-
chunks.push(...childChunks);
|
|
9651
|
-
chunks.push(this.createDefaultChunk(`
|
|
9652
|
-
`));
|
|
9653
|
-
}
|
|
9654
|
-
}
|
|
9655
|
-
}
|
|
9656
|
-
return chunks;
|
|
9657
|
-
}
|
|
9658
|
-
renderThematicBreakChunks() {
|
|
9659
|
-
return [this.createChunk("---", "punctuation.special")];
|
|
9660
|
-
}
|
|
9661
|
-
renderTokenToChunks(token) {
|
|
9662
|
-
switch (token.type) {
|
|
9663
|
-
case "heading":
|
|
9664
|
-
return this.renderHeadingChunks(token);
|
|
9665
|
-
case "paragraph":
|
|
9666
|
-
return this.renderParagraphChunks(token);
|
|
9667
|
-
case "blockquote":
|
|
9668
|
-
return this.renderBlockquoteChunks(token);
|
|
9669
|
-
case "list":
|
|
9670
|
-
return this.renderListChunks(token);
|
|
9671
|
-
case "hr":
|
|
9672
|
-
return this.renderThematicBreakChunks();
|
|
9673
|
-
case "space":
|
|
9674
|
-
return [];
|
|
9675
|
-
default:
|
|
9676
|
-
if ("raw" in token && token.raw) {
|
|
9677
|
-
return [this.createDefaultChunk(token.raw)];
|
|
9678
|
-
}
|
|
9679
|
-
return [];
|
|
9680
|
-
}
|
|
9681
|
-
}
|
|
9682
|
-
createTextRenderable(chunks, id, marginBottom = 0) {
|
|
9683
|
-
return new TextRenderable(this.ctx, {
|
|
9146
|
+
createMarkdownCodeRenderable(content, id, marginBottom = 0) {
|
|
9147
|
+
return new CodeRenderable(this.ctx, {
|
|
9684
9148
|
id,
|
|
9685
|
-
content
|
|
9149
|
+
content,
|
|
9150
|
+
filetype: "markdown",
|
|
9151
|
+
syntaxStyle: this._syntaxStyle,
|
|
9152
|
+
conceal: this._conceal,
|
|
9153
|
+
drawUnstyledText: false,
|
|
9154
|
+
streaming: true,
|
|
9155
|
+
onChunks: this._linkifyMarkdownChunks,
|
|
9156
|
+
treeSitterClient: this._treeSitterClient,
|
|
9686
9157
|
width: "100%",
|
|
9687
9158
|
marginBottom
|
|
9688
9159
|
});
|
|
@@ -9693,14 +9164,95 @@ class MarkdownRenderable extends Renderable {
|
|
|
9693
9164
|
content: token.text,
|
|
9694
9165
|
filetype: token.lang || undefined,
|
|
9695
9166
|
syntaxStyle: this._syntaxStyle,
|
|
9696
|
-
conceal: this.
|
|
9167
|
+
conceal: this._concealCode,
|
|
9168
|
+
drawUnstyledText: !(this._streaming && this._concealCode),
|
|
9169
|
+
streaming: this._streaming,
|
|
9697
9170
|
treeSitterClient: this._treeSitterClient,
|
|
9698
9171
|
width: "100%",
|
|
9699
9172
|
marginBottom
|
|
9700
9173
|
});
|
|
9701
9174
|
}
|
|
9175
|
+
applyMarkdownCodeRenderable(renderable, content, marginBottom) {
|
|
9176
|
+
renderable.content = content;
|
|
9177
|
+
renderable.filetype = "markdown";
|
|
9178
|
+
renderable.syntaxStyle = this._syntaxStyle;
|
|
9179
|
+
renderable.conceal = this._conceal;
|
|
9180
|
+
renderable.drawUnstyledText = false;
|
|
9181
|
+
renderable.streaming = true;
|
|
9182
|
+
renderable.marginBottom = marginBottom;
|
|
9183
|
+
}
|
|
9184
|
+
applyCodeBlockRenderable(renderable, token, marginBottom) {
|
|
9185
|
+
renderable.content = token.text;
|
|
9186
|
+
renderable.filetype = token.lang || undefined;
|
|
9187
|
+
renderable.syntaxStyle = this._syntaxStyle;
|
|
9188
|
+
renderable.conceal = this._concealCode;
|
|
9189
|
+
renderable.drawUnstyledText = !(this._streaming && this._concealCode);
|
|
9190
|
+
renderable.streaming = this._streaming;
|
|
9191
|
+
renderable.marginBottom = marginBottom;
|
|
9192
|
+
}
|
|
9193
|
+
shouldRenderSeparately(token) {
|
|
9194
|
+
return token.type === "code" || token.type === "table" || token.type === "blockquote";
|
|
9195
|
+
}
|
|
9196
|
+
getInterBlockMargin(token, hasNextToken) {
|
|
9197
|
+
if (!hasNextToken)
|
|
9198
|
+
return 0;
|
|
9199
|
+
return this.shouldRenderSeparately(token) ? 1 : 0;
|
|
9200
|
+
}
|
|
9201
|
+
createMarkdownBlockToken(raw) {
|
|
9202
|
+
return {
|
|
9203
|
+
type: "paragraph",
|
|
9204
|
+
raw,
|
|
9205
|
+
text: raw,
|
|
9206
|
+
tokens: []
|
|
9207
|
+
};
|
|
9208
|
+
}
|
|
9209
|
+
normalizeMarkdownBlockRaw(raw) {
|
|
9210
|
+
return raw.replace(TRAILING_MARKDOWN_BLOCK_BREAKS_RE, `
|
|
9211
|
+
`);
|
|
9212
|
+
}
|
|
9213
|
+
buildRenderableTokens(tokens) {
|
|
9214
|
+
if (this._renderNode) {
|
|
9215
|
+
return tokens.filter((token) => token.type !== "space");
|
|
9216
|
+
}
|
|
9217
|
+
const renderTokens = [];
|
|
9218
|
+
let markdownRaw = "";
|
|
9219
|
+
const flushMarkdownRaw = () => {
|
|
9220
|
+
if (markdownRaw.length === 0)
|
|
9221
|
+
return;
|
|
9222
|
+
const normalizedRaw = this.normalizeMarkdownBlockRaw(markdownRaw);
|
|
9223
|
+
if (normalizedRaw.length > 0) {
|
|
9224
|
+
renderTokens.push(this.createMarkdownBlockToken(normalizedRaw));
|
|
9225
|
+
}
|
|
9226
|
+
markdownRaw = "";
|
|
9227
|
+
};
|
|
9228
|
+
for (let i = 0;i < tokens.length; i += 1) {
|
|
9229
|
+
const token = tokens[i];
|
|
9230
|
+
if (token.type === "space") {
|
|
9231
|
+
if (markdownRaw.length === 0) {
|
|
9232
|
+
continue;
|
|
9233
|
+
}
|
|
9234
|
+
let nextIndex = i + 1;
|
|
9235
|
+
while (nextIndex < tokens.length && tokens[nextIndex].type === "space") {
|
|
9236
|
+
nextIndex += 1;
|
|
9237
|
+
}
|
|
9238
|
+
const nextToken = tokens[nextIndex];
|
|
9239
|
+
if (nextToken && !this.shouldRenderSeparately(nextToken)) {
|
|
9240
|
+
markdownRaw += token.raw;
|
|
9241
|
+
}
|
|
9242
|
+
continue;
|
|
9243
|
+
}
|
|
9244
|
+
if (this.shouldRenderSeparately(token)) {
|
|
9245
|
+
flushMarkdownRaw();
|
|
9246
|
+
renderTokens.push(token);
|
|
9247
|
+
continue;
|
|
9248
|
+
}
|
|
9249
|
+
markdownRaw += token.raw;
|
|
9250
|
+
}
|
|
9251
|
+
flushMarkdownRaw();
|
|
9252
|
+
return renderTokens;
|
|
9253
|
+
}
|
|
9702
9254
|
getTableRowsToRender(table) {
|
|
9703
|
-
return
|
|
9255
|
+
return table.rows;
|
|
9704
9256
|
}
|
|
9705
9257
|
hashString(value, seed) {
|
|
9706
9258
|
let hash = seed >>> 0;
|
|
@@ -9823,8 +9375,9 @@ class MarkdownRenderable extends Renderable {
|
|
|
9823
9375
|
resolveTableRenderableOptions() {
|
|
9824
9376
|
const borders = this._tableOptions?.borders ?? true;
|
|
9825
9377
|
return {
|
|
9826
|
-
columnWidthMode: this._tableOptions?.widthMode ?? "
|
|
9827
|
-
|
|
9378
|
+
columnWidthMode: this._tableOptions?.widthMode ?? "full",
|
|
9379
|
+
columnFitter: this._tableOptions?.columnFitter ?? "proportional",
|
|
9380
|
+
wrapMode: this._tableOptions?.wrapMode ?? "word",
|
|
9828
9381
|
cellPadding: this._tableOptions?.cellPadding ?? 0,
|
|
9829
9382
|
border: borders,
|
|
9830
9383
|
outerBorder: this._tableOptions?.outerBorder ?? borders,
|
|
@@ -9836,6 +9389,7 @@ class MarkdownRenderable extends Renderable {
|
|
|
9836
9389
|
}
|
|
9837
9390
|
applyTableRenderableOptions(tableRenderable, options) {
|
|
9838
9391
|
tableRenderable.columnWidthMode = options.columnWidthMode;
|
|
9392
|
+
tableRenderable.columnFitter = options.columnFitter;
|
|
9839
9393
|
tableRenderable.wrapMode = options.wrapMode;
|
|
9840
9394
|
tableRenderable.cellPadding = options.cellPadding;
|
|
9841
9395
|
tableRenderable.border = options.border;
|
|
@@ -9866,6 +9420,7 @@ class MarkdownRenderable extends Renderable {
|
|
|
9866
9420
|
width: "100%",
|
|
9867
9421
|
marginBottom,
|
|
9868
9422
|
columnWidthMode: options.columnWidthMode,
|
|
9423
|
+
columnFitter: options.columnFitter,
|
|
9869
9424
|
wrapMode: options.wrapMode,
|
|
9870
9425
|
cellPadding: options.cellPadding,
|
|
9871
9426
|
border: options.border,
|
|
@@ -9880,7 +9435,7 @@ class MarkdownRenderable extends Renderable {
|
|
|
9880
9435
|
const { cache } = this.buildTableContentCache(table, previousCache, forceRegenerate);
|
|
9881
9436
|
if (!cache) {
|
|
9882
9437
|
return {
|
|
9883
|
-
renderable: this.
|
|
9438
|
+
renderable: this.createMarkdownCodeRenderable(table.raw, id, marginBottom)
|
|
9884
9439
|
};
|
|
9885
9440
|
}
|
|
9886
9441
|
return {
|
|
@@ -9890,7 +9445,7 @@ class MarkdownRenderable extends Renderable {
|
|
|
9890
9445
|
}
|
|
9891
9446
|
createDefaultRenderable(token, index, hasNextToken = false) {
|
|
9892
9447
|
const id = `${this.id}-block-${index}`;
|
|
9893
|
-
const marginBottom = hasNextToken
|
|
9448
|
+
const marginBottom = this.getInterBlockMargin(token, hasNextToken);
|
|
9894
9449
|
if (token.type === "code") {
|
|
9895
9450
|
return this.createCodeRenderable(token, id, marginBottom);
|
|
9896
9451
|
}
|
|
@@ -9900,39 +9455,28 @@ class MarkdownRenderable extends Renderable {
|
|
|
9900
9455
|
if (token.type === "space") {
|
|
9901
9456
|
return null;
|
|
9902
9457
|
}
|
|
9903
|
-
|
|
9904
|
-
if (chunks.length === 0) {
|
|
9458
|
+
if (!token.raw) {
|
|
9905
9459
|
return null;
|
|
9906
9460
|
}
|
|
9907
|
-
return this.
|
|
9461
|
+
return this.createMarkdownCodeRenderable(token.raw, id, marginBottom);
|
|
9908
9462
|
}
|
|
9909
9463
|
updateBlockRenderable(state, token, index, hasNextToken) {
|
|
9910
|
-
const marginBottom = hasNextToken
|
|
9464
|
+
const marginBottom = this.getInterBlockMargin(token, hasNextToken);
|
|
9911
9465
|
if (token.type === "code") {
|
|
9912
|
-
|
|
9913
|
-
const codeToken = token;
|
|
9914
|
-
codeRenderable.content = codeToken.text;
|
|
9915
|
-
if (codeToken.lang) {
|
|
9916
|
-
codeRenderable.filetype = codeToken.lang;
|
|
9917
|
-
}
|
|
9918
|
-
codeRenderable.marginBottom = marginBottom;
|
|
9466
|
+
this.applyCodeBlockRenderable(state.renderable, token, marginBottom);
|
|
9919
9467
|
return;
|
|
9920
9468
|
}
|
|
9921
9469
|
if (token.type === "table") {
|
|
9922
9470
|
const tableToken = token;
|
|
9923
9471
|
const { cache, changed } = this.buildTableContentCache(tableToken, state.tableContentCache);
|
|
9924
9472
|
if (!cache) {
|
|
9925
|
-
|
|
9926
|
-
|
|
9927
|
-
if (state.tokenRaw !== tableToken.raw) {
|
|
9928
|
-
state.renderable.content = new StyledText(fallbackChunks);
|
|
9929
|
-
}
|
|
9930
|
-
state.renderable.marginBottom = marginBottom;
|
|
9473
|
+
if (state.renderable instanceof CodeRenderable) {
|
|
9474
|
+
this.applyMarkdownCodeRenderable(state.renderable, tableToken.raw, marginBottom);
|
|
9931
9475
|
state.tableContentCache = undefined;
|
|
9932
9476
|
return;
|
|
9933
9477
|
}
|
|
9934
9478
|
state.renderable.destroyRecursively();
|
|
9935
|
-
const fallbackRenderable = this.
|
|
9479
|
+
const fallbackRenderable = this.createMarkdownCodeRenderable(tableToken.raw, `${this.id}-block-${index}`, marginBottom);
|
|
9936
9480
|
this.add(fallbackRenderable);
|
|
9937
9481
|
state.renderable = fallbackRenderable;
|
|
9938
9482
|
state.tableContentCache = undefined;
|
|
@@ -9954,12 +9498,18 @@ class MarkdownRenderable extends Renderable {
|
|
|
9954
9498
|
state.tableContentCache = cache;
|
|
9955
9499
|
return;
|
|
9956
9500
|
}
|
|
9957
|
-
|
|
9958
|
-
|
|
9959
|
-
|
|
9960
|
-
|
|
9501
|
+
if (state.renderable instanceof CodeRenderable) {
|
|
9502
|
+
this.applyMarkdownCodeRenderable(state.renderable, token.raw, marginBottom);
|
|
9503
|
+
return;
|
|
9504
|
+
}
|
|
9505
|
+
state.renderable.destroyRecursively();
|
|
9506
|
+
const markdownRenderable = this.createMarkdownCodeRenderable(token.raw, `${this.id}-block-${index}`, marginBottom);
|
|
9507
|
+
this.add(markdownRenderable);
|
|
9508
|
+
state.renderable = markdownRenderable;
|
|
9961
9509
|
}
|
|
9962
|
-
updateBlocks() {
|
|
9510
|
+
updateBlocks(forceTableRefresh = false) {
|
|
9511
|
+
if (this.isDestroyed)
|
|
9512
|
+
return;
|
|
9963
9513
|
if (!this._content) {
|
|
9964
9514
|
this.clearBlockStates();
|
|
9965
9515
|
this._parseState = null;
|
|
@@ -9970,35 +9520,39 @@ class MarkdownRenderable extends Renderable {
|
|
|
9970
9520
|
const tokens = this._parseState.tokens;
|
|
9971
9521
|
if (tokens.length === 0 && this._content.length > 0) {
|
|
9972
9522
|
this.clearBlockStates();
|
|
9973
|
-
const
|
|
9974
|
-
this.add(
|
|
9523
|
+
const fallback = this.createMarkdownCodeRenderable(this._content, `${this.id}-fallback`);
|
|
9524
|
+
this.add(fallback);
|
|
9975
9525
|
this._blockStates = [
|
|
9976
9526
|
{
|
|
9977
9527
|
token: { type: "text", raw: this._content, text: this._content },
|
|
9978
9528
|
tokenRaw: this._content,
|
|
9979
|
-
renderable:
|
|
9529
|
+
renderable: fallback
|
|
9980
9530
|
}
|
|
9981
9531
|
];
|
|
9982
9532
|
return;
|
|
9983
9533
|
}
|
|
9984
|
-
const blockTokens =
|
|
9985
|
-
for (let i = 0;i < tokens.length; i++) {
|
|
9986
|
-
if (tokens[i].type !== "space") {
|
|
9987
|
-
blockTokens.push({ token: tokens[i], originalIndex: i });
|
|
9988
|
-
}
|
|
9989
|
-
}
|
|
9534
|
+
const blockTokens = this.buildRenderableTokens(tokens);
|
|
9990
9535
|
const lastBlockIndex = blockTokens.length - 1;
|
|
9991
9536
|
let blockIndex = 0;
|
|
9992
9537
|
for (let i = 0;i < blockTokens.length; i++) {
|
|
9993
|
-
const
|
|
9538
|
+
const token = blockTokens[i];
|
|
9994
9539
|
const hasNextToken = i < lastBlockIndex;
|
|
9995
9540
|
const existing = this._blockStates[blockIndex];
|
|
9541
|
+
const shouldForceRefresh = forceTableRefresh;
|
|
9996
9542
|
if (existing && existing.token === token) {
|
|
9543
|
+
if (shouldForceRefresh) {
|
|
9544
|
+
this.updateBlockRenderable(existing, token, blockIndex, hasNextToken);
|
|
9545
|
+
existing.tokenRaw = token.raw;
|
|
9546
|
+
}
|
|
9997
9547
|
blockIndex++;
|
|
9998
9548
|
continue;
|
|
9999
9549
|
}
|
|
10000
9550
|
if (existing && existing.tokenRaw === token.raw && existing.token.type === token.type) {
|
|
10001
9551
|
existing.token = token;
|
|
9552
|
+
if (shouldForceRefresh) {
|
|
9553
|
+
this.updateBlockRenderable(existing, token, blockIndex, hasNextToken);
|
|
9554
|
+
existing.tokenRaw = token.raw;
|
|
9555
|
+
}
|
|
10002
9556
|
blockIndex++;
|
|
10003
9557
|
continue;
|
|
10004
9558
|
}
|
|
@@ -10018,6 +9572,7 @@ class MarkdownRenderable extends Renderable {
|
|
|
10018
9572
|
const context = {
|
|
10019
9573
|
syntaxStyle: this._syntaxStyle,
|
|
10020
9574
|
conceal: this._conceal,
|
|
9575
|
+
concealCode: this._concealCode,
|
|
10021
9576
|
treeSitterClient: this._treeSitterClient,
|
|
10022
9577
|
defaultRender: () => this.createDefaultRenderable(token, blockIndex, hasNextToken)
|
|
10023
9578
|
};
|
|
@@ -10028,7 +9583,7 @@ class MarkdownRenderable extends Renderable {
|
|
|
10028
9583
|
}
|
|
10029
9584
|
if (!renderable) {
|
|
10030
9585
|
if (token.type === "table") {
|
|
10031
|
-
const tableBlock = this.createTableBlock(token, `${this.id}-block-${blockIndex}`, hasNextToken
|
|
9586
|
+
const tableBlock = this.createTableBlock(token, `${this.id}-block-${blockIndex}`, this.getInterBlockMargin(token, hasNextToken));
|
|
10032
9587
|
renderable = tableBlock.renderable;
|
|
10033
9588
|
tableContentCache = tableBlock.tableContentCache;
|
|
10034
9589
|
} else {
|
|
@@ -10065,44 +9620,48 @@ class MarkdownRenderable extends Renderable {
|
|
|
10065
9620
|
for (let i = 0;i < this._blockStates.length; i++) {
|
|
10066
9621
|
const state = this._blockStates[i];
|
|
10067
9622
|
const hasNextToken = i < this._blockStates.length - 1;
|
|
9623
|
+
const marginBottom = this.getInterBlockMargin(state.token, hasNextToken);
|
|
10068
9624
|
if (state.token.type === "code") {
|
|
10069
|
-
|
|
10070
|
-
|
|
10071
|
-
|
|
10072
|
-
|
|
9625
|
+
this.applyCodeBlockRenderable(state.renderable, state.token, marginBottom);
|
|
9626
|
+
continue;
|
|
9627
|
+
}
|
|
9628
|
+
if (state.token.type === "table") {
|
|
10073
9629
|
const tableToken = state.token;
|
|
10074
|
-
const marginBottom = hasNextToken ? 1 : 0;
|
|
10075
9630
|
const { cache } = this.buildTableContentCache(tableToken, state.tableContentCache, true);
|
|
10076
9631
|
if (!cache) {
|
|
10077
|
-
if (state.renderable instanceof
|
|
10078
|
-
state.renderable
|
|
10079
|
-
state.renderable.marginBottom = marginBottom;
|
|
9632
|
+
if (state.renderable instanceof CodeRenderable) {
|
|
9633
|
+
this.applyMarkdownCodeRenderable(state.renderable, tableToken.raw, marginBottom);
|
|
10080
9634
|
} else {
|
|
10081
9635
|
state.renderable.destroyRecursively();
|
|
10082
|
-
const fallbackRenderable = this.
|
|
9636
|
+
const fallbackRenderable = this.createMarkdownCodeRenderable(tableToken.raw, `${this.id}-block-${i}`, marginBottom);
|
|
10083
9637
|
this.add(fallbackRenderable);
|
|
10084
9638
|
state.renderable = fallbackRenderable;
|
|
10085
9639
|
}
|
|
10086
9640
|
state.tableContentCache = undefined;
|
|
10087
|
-
|
|
9641
|
+
continue;
|
|
9642
|
+
}
|
|
9643
|
+
if (state.renderable instanceof TextTableRenderable) {
|
|
10088
9644
|
state.renderable.content = cache.content;
|
|
10089
9645
|
this.applyTableRenderableOptions(state.renderable, this.resolveTableRenderableOptions());
|
|
10090
9646
|
state.renderable.marginBottom = marginBottom;
|
|
10091
9647
|
state.tableContentCache = cache;
|
|
10092
|
-
|
|
10093
|
-
state.renderable.destroyRecursively();
|
|
10094
|
-
const tableRenderable = this.createTextTableRenderable(cache.content, `${this.id}-block-${i}`, marginBottom);
|
|
10095
|
-
this.add(tableRenderable);
|
|
10096
|
-
state.renderable = tableRenderable;
|
|
10097
|
-
state.tableContentCache = cache;
|
|
10098
|
-
}
|
|
10099
|
-
} else {
|
|
10100
|
-
const textRenderable = state.renderable;
|
|
10101
|
-
const chunks = this.renderTokenToChunks(state.token);
|
|
10102
|
-
if (chunks.length > 0) {
|
|
10103
|
-
textRenderable.content = new StyledText(chunks);
|
|
9648
|
+
continue;
|
|
10104
9649
|
}
|
|
9650
|
+
state.renderable.destroyRecursively();
|
|
9651
|
+
const tableRenderable = this.createTextTableRenderable(cache.content, `${this.id}-block-${i}`, marginBottom);
|
|
9652
|
+
this.add(tableRenderable);
|
|
9653
|
+
state.renderable = tableRenderable;
|
|
9654
|
+
state.tableContentCache = cache;
|
|
9655
|
+
continue;
|
|
10105
9656
|
}
|
|
9657
|
+
if (state.renderable instanceof CodeRenderable) {
|
|
9658
|
+
this.applyMarkdownCodeRenderable(state.renderable, state.token.raw, marginBottom);
|
|
9659
|
+
continue;
|
|
9660
|
+
}
|
|
9661
|
+
state.renderable.destroyRecursively();
|
|
9662
|
+
const markdownRenderable = this.createMarkdownCodeRenderable(state.token.raw, `${this.id}-block-${i}`, marginBottom);
|
|
9663
|
+
this.add(markdownRenderable);
|
|
9664
|
+
state.renderable = markdownRenderable;
|
|
10106
9665
|
}
|
|
10107
9666
|
}
|
|
10108
9667
|
clearCache() {
|
|
@@ -10727,6 +10286,34 @@ class ContentRenderable extends BoxRenderable {
|
|
|
10727
10286
|
return this.getChildrenSortedByPrimaryAxis().map((child) => child.num);
|
|
10728
10287
|
}
|
|
10729
10288
|
}
|
|
10289
|
+
var SCROLLBOX_PADDING_KEYS = [
|
|
10290
|
+
"padding",
|
|
10291
|
+
"paddingX",
|
|
10292
|
+
"paddingY",
|
|
10293
|
+
"paddingTop",
|
|
10294
|
+
"paddingRight",
|
|
10295
|
+
"paddingBottom",
|
|
10296
|
+
"paddingLeft"
|
|
10297
|
+
];
|
|
10298
|
+
function pickScrollBoxPadding(options) {
|
|
10299
|
+
if (!options)
|
|
10300
|
+
return {};
|
|
10301
|
+
const picked = {};
|
|
10302
|
+
for (const key of SCROLLBOX_PADDING_KEYS) {
|
|
10303
|
+
const value = options[key];
|
|
10304
|
+
if (value !== undefined) {
|
|
10305
|
+
picked[key] = value;
|
|
10306
|
+
}
|
|
10307
|
+
}
|
|
10308
|
+
return picked;
|
|
10309
|
+
}
|
|
10310
|
+
function stripScrollBoxPadding(options) {
|
|
10311
|
+
const sanitized = { ...options };
|
|
10312
|
+
for (const key of SCROLLBOX_PADDING_KEYS) {
|
|
10313
|
+
delete sanitized[key];
|
|
10314
|
+
}
|
|
10315
|
+
return sanitized;
|
|
10316
|
+
}
|
|
10730
10317
|
|
|
10731
10318
|
class ScrollBoxRenderable extends BoxRenderable {
|
|
10732
10319
|
static idCounter = 0;
|
|
@@ -10874,27 +10461,38 @@ class ScrollBoxRenderable extends BoxRenderable {
|
|
|
10874
10461
|
this._isApplyingStickyScroll = wasApplyingStickyScroll;
|
|
10875
10462
|
}
|
|
10876
10463
|
}
|
|
10877
|
-
constructor(ctx, {
|
|
10878
|
-
|
|
10879
|
-
|
|
10880
|
-
|
|
10881
|
-
|
|
10882
|
-
|
|
10883
|
-
|
|
10884
|
-
|
|
10885
|
-
|
|
10886
|
-
|
|
10887
|
-
|
|
10888
|
-
|
|
10889
|
-
|
|
10890
|
-
|
|
10891
|
-
|
|
10892
|
-
|
|
10464
|
+
constructor(ctx, options) {
|
|
10465
|
+
const {
|
|
10466
|
+
wrapperOptions,
|
|
10467
|
+
viewportOptions,
|
|
10468
|
+
contentOptions,
|
|
10469
|
+
rootOptions,
|
|
10470
|
+
scrollbarOptions,
|
|
10471
|
+
verticalScrollbarOptions,
|
|
10472
|
+
horizontalScrollbarOptions,
|
|
10473
|
+
stickyScroll = false,
|
|
10474
|
+
stickyStart,
|
|
10475
|
+
scrollX = false,
|
|
10476
|
+
scrollY = true,
|
|
10477
|
+
scrollAcceleration,
|
|
10478
|
+
viewportCulling = true,
|
|
10479
|
+
...rootBoxOptions
|
|
10480
|
+
} = options;
|
|
10481
|
+
const forwardedContentPadding = {
|
|
10482
|
+
...pickScrollBoxPadding(rootBoxOptions),
|
|
10483
|
+
...pickScrollBoxPadding(rootOptions)
|
|
10484
|
+
};
|
|
10485
|
+
const sanitizedRootBoxOptions = stripScrollBoxPadding(rootBoxOptions);
|
|
10486
|
+
const sanitizedRootOptions = rootOptions ? stripScrollBoxPadding(rootOptions) : undefined;
|
|
10487
|
+
const mergedContentOptions = {
|
|
10488
|
+
...forwardedContentPadding,
|
|
10489
|
+
...contentOptions
|
|
10490
|
+
};
|
|
10893
10491
|
super(ctx, {
|
|
10894
10492
|
flexDirection: "row",
|
|
10895
10493
|
alignItems: "stretch",
|
|
10896
|
-
...
|
|
10897
|
-
...
|
|
10494
|
+
...sanitizedRootBoxOptions,
|
|
10495
|
+
...sanitizedRootOptions
|
|
10898
10496
|
});
|
|
10899
10497
|
this.internalId = ScrollBoxRenderable.idCounter++;
|
|
10900
10498
|
this._stickyScroll = stickyScroll;
|
|
@@ -10926,7 +10524,7 @@ class ScrollBoxRenderable extends BoxRenderable {
|
|
|
10926
10524
|
onSizeChange: () => {
|
|
10927
10525
|
this.recalculateBarProps();
|
|
10928
10526
|
},
|
|
10929
|
-
...
|
|
10527
|
+
...mergedContentOptions,
|
|
10930
10528
|
id: `scroll-box-content-${this.internalId}`
|
|
10931
10529
|
});
|
|
10932
10530
|
this.viewport.add(this.content);
|
|
@@ -11242,6 +10840,34 @@ class ScrollBoxRenderable extends BoxRenderable {
|
|
|
11242
10840
|
this.requestRender();
|
|
11243
10841
|
});
|
|
11244
10842
|
}
|
|
10843
|
+
set padding(value) {
|
|
10844
|
+
this.content.padding = value;
|
|
10845
|
+
this.requestRender();
|
|
10846
|
+
}
|
|
10847
|
+
set paddingX(value) {
|
|
10848
|
+
this.content.paddingX = value;
|
|
10849
|
+
this.requestRender();
|
|
10850
|
+
}
|
|
10851
|
+
set paddingY(value) {
|
|
10852
|
+
this.content.paddingY = value;
|
|
10853
|
+
this.requestRender();
|
|
10854
|
+
}
|
|
10855
|
+
set paddingTop(value) {
|
|
10856
|
+
this.content.paddingTop = value;
|
|
10857
|
+
this.requestRender();
|
|
10858
|
+
}
|
|
10859
|
+
set paddingRight(value) {
|
|
10860
|
+
this.content.paddingRight = value;
|
|
10861
|
+
this.requestRender();
|
|
10862
|
+
}
|
|
10863
|
+
set paddingBottom(value) {
|
|
10864
|
+
this.content.paddingBottom = value;
|
|
10865
|
+
this.requestRender();
|
|
10866
|
+
}
|
|
10867
|
+
set paddingLeft(value) {
|
|
10868
|
+
this.content.paddingLeft = value;
|
|
10869
|
+
this.requestRender();
|
|
10870
|
+
}
|
|
11245
10871
|
set rootOptions(options) {
|
|
11246
10872
|
Object.assign(this, options);
|
|
11247
10873
|
this.requestRender();
|
|
@@ -12077,6 +11703,7 @@ export {
|
|
|
12077
11703
|
env,
|
|
12078
11704
|
engine,
|
|
12079
11705
|
dim,
|
|
11706
|
+
detectLinks,
|
|
12080
11707
|
delegate,
|
|
12081
11708
|
cyan,
|
|
12082
11709
|
createTimeline,
|
|
@@ -12206,5 +11833,5 @@ export {
|
|
|
12206
11833
|
ASCIIFont
|
|
12207
11834
|
};
|
|
12208
11835
|
|
|
12209
|
-
//# debugId=
|
|
11836
|
+
//# debugId=D4980C658617B6F964756E2164756E21
|
|
12210
11837
|
//# sourceMappingURL=index.js.map
|