@threadlabs/looma 0.1.5 → 0.1.6

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.
@@ -1,3 +1,10 @@
1
+ import {
2
+ TABLE_CELL_BACKGROUND_PRESETS
3
+ } from "./chunk-CX4QDKSV.js";
4
+
5
+ // src/extensions/preset.ts
6
+ import { Extension as Extension7 } from "@tiptap/core";
7
+
1
8
  // ../../node_modules/.pnpm/@tiptap+extension-document@2.27.2_@tiptap+core@2.27.2_@tiptap+pm@2.27.2_/node_modules/@tiptap/extension-document/dist/index.js
2
9
  import { Node } from "@tiptap/core";
3
10
  var Document = Node.create({
@@ -3172,6 +3179,1663 @@ var CodeBlock = Node14.create({
3172
3179
  }
3173
3180
  });
3174
3181
 
3182
+ // ../../node_modules/.pnpm/@tiptap+extension-code-block-lowlight@2.27.2_@tiptap+core@2.27.2_@tiptap+pm@2.27.2__@ti_1435c0758b0eec843326ea7f0537cc85/node_modules/@tiptap/extension-code-block-lowlight/dist/index.js
3183
+ import { findChildren } from "@tiptap/core";
3184
+ import { Plugin as Plugin4, PluginKey as PluginKey4 } from "@tiptap/pm/state";
3185
+ import { Decoration as Decoration2, DecorationSet as DecorationSet2 } from "@tiptap/pm/view";
3186
+ function getDefaultExportFromCjs(x) {
3187
+ return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, "default") ? x["default"] : x;
3188
+ }
3189
+ function deepFreeze(obj) {
3190
+ if (obj instanceof Map) {
3191
+ obj.clear = obj.delete = obj.set = function() {
3192
+ throw new Error("map is read-only");
3193
+ };
3194
+ } else if (obj instanceof Set) {
3195
+ obj.add = obj.clear = obj.delete = function() {
3196
+ throw new Error("set is read-only");
3197
+ };
3198
+ }
3199
+ Object.freeze(obj);
3200
+ Object.getOwnPropertyNames(obj).forEach((name) => {
3201
+ const prop = obj[name];
3202
+ const type = typeof prop;
3203
+ if ((type === "object" || type === "function") && !Object.isFrozen(prop)) {
3204
+ deepFreeze(prop);
3205
+ }
3206
+ });
3207
+ return obj;
3208
+ }
3209
+ var Response = class {
3210
+ /**
3211
+ * @param {CompiledMode} mode
3212
+ */
3213
+ constructor(mode) {
3214
+ if (mode.data === void 0) mode.data = {};
3215
+ this.data = mode.data;
3216
+ this.isMatchIgnored = false;
3217
+ }
3218
+ ignoreMatch() {
3219
+ this.isMatchIgnored = true;
3220
+ }
3221
+ };
3222
+ function escapeHTML(value) {
3223
+ return value.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#x27;");
3224
+ }
3225
+ function inherit$1(original, ...objects) {
3226
+ const result = /* @__PURE__ */ Object.create(null);
3227
+ for (const key in original) {
3228
+ result[key] = original[key];
3229
+ }
3230
+ objects.forEach(function(obj) {
3231
+ for (const key in obj) {
3232
+ result[key] = obj[key];
3233
+ }
3234
+ });
3235
+ return (
3236
+ /** @type {T} */
3237
+ result
3238
+ );
3239
+ }
3240
+ var SPAN_CLOSE = "</span>";
3241
+ var emitsWrappingTags = (node) => {
3242
+ return !!node.scope;
3243
+ };
3244
+ var scopeToCSSClass = (name, { prefix }) => {
3245
+ if (name.startsWith("language:")) {
3246
+ return name.replace("language:", "language-");
3247
+ }
3248
+ if (name.includes(".")) {
3249
+ const pieces = name.split(".");
3250
+ return [
3251
+ `${prefix}${pieces.shift()}`,
3252
+ ...pieces.map((x, i) => `${x}${"_".repeat(i + 1)}`)
3253
+ ].join(" ");
3254
+ }
3255
+ return `${prefix}${name}`;
3256
+ };
3257
+ var HTMLRenderer = class {
3258
+ /**
3259
+ * Creates a new HTMLRenderer
3260
+ *
3261
+ * @param {Tree} parseTree - the parse tree (must support `walk` API)
3262
+ * @param {{classPrefix: string}} options
3263
+ */
3264
+ constructor(parseTree, options) {
3265
+ this.buffer = "";
3266
+ this.classPrefix = options.classPrefix;
3267
+ parseTree.walk(this);
3268
+ }
3269
+ /**
3270
+ * Adds texts to the output stream
3271
+ *
3272
+ * @param {string} text */
3273
+ addText(text) {
3274
+ this.buffer += escapeHTML(text);
3275
+ }
3276
+ /**
3277
+ * Adds a node open to the output stream (if needed)
3278
+ *
3279
+ * @param {Node} node */
3280
+ openNode(node) {
3281
+ if (!emitsWrappingTags(node)) return;
3282
+ const className = scopeToCSSClass(
3283
+ node.scope,
3284
+ { prefix: this.classPrefix }
3285
+ );
3286
+ this.span(className);
3287
+ }
3288
+ /**
3289
+ * Adds a node close to the output stream (if needed)
3290
+ *
3291
+ * @param {Node} node */
3292
+ closeNode(node) {
3293
+ if (!emitsWrappingTags(node)) return;
3294
+ this.buffer += SPAN_CLOSE;
3295
+ }
3296
+ /**
3297
+ * returns the accumulated buffer
3298
+ */
3299
+ value() {
3300
+ return this.buffer;
3301
+ }
3302
+ // helpers
3303
+ /**
3304
+ * Builds a span element
3305
+ *
3306
+ * @param {string} className */
3307
+ span(className) {
3308
+ this.buffer += `<span class="${className}">`;
3309
+ }
3310
+ };
3311
+ var newNode = (opts = {}) => {
3312
+ const result = { children: [] };
3313
+ Object.assign(result, opts);
3314
+ return result;
3315
+ };
3316
+ var TokenTree = class _TokenTree {
3317
+ constructor() {
3318
+ this.rootNode = newNode();
3319
+ this.stack = [this.rootNode];
3320
+ }
3321
+ get top() {
3322
+ return this.stack[this.stack.length - 1];
3323
+ }
3324
+ get root() {
3325
+ return this.rootNode;
3326
+ }
3327
+ /** @param {Node} node */
3328
+ add(node) {
3329
+ this.top.children.push(node);
3330
+ }
3331
+ /** @param {string} scope */
3332
+ openNode(scope) {
3333
+ const node = newNode({ scope });
3334
+ this.add(node);
3335
+ this.stack.push(node);
3336
+ }
3337
+ closeNode() {
3338
+ if (this.stack.length > 1) {
3339
+ return this.stack.pop();
3340
+ }
3341
+ return void 0;
3342
+ }
3343
+ closeAllNodes() {
3344
+ while (this.closeNode()) ;
3345
+ }
3346
+ toJSON() {
3347
+ return JSON.stringify(this.rootNode, null, 4);
3348
+ }
3349
+ /**
3350
+ * @typedef { import("./html_renderer").Renderer } Renderer
3351
+ * @param {Renderer} builder
3352
+ */
3353
+ walk(builder) {
3354
+ return this.constructor._walk(builder, this.rootNode);
3355
+ }
3356
+ /**
3357
+ * @param {Renderer} builder
3358
+ * @param {Node} node
3359
+ */
3360
+ static _walk(builder, node) {
3361
+ if (typeof node === "string") {
3362
+ builder.addText(node);
3363
+ } else if (node.children) {
3364
+ builder.openNode(node);
3365
+ node.children.forEach((child) => this._walk(builder, child));
3366
+ builder.closeNode(node);
3367
+ }
3368
+ return builder;
3369
+ }
3370
+ /**
3371
+ * @param {Node} node
3372
+ */
3373
+ static _collapse(node) {
3374
+ if (typeof node === "string") return;
3375
+ if (!node.children) return;
3376
+ if (node.children.every((el) => typeof el === "string")) {
3377
+ node.children = [node.children.join("")];
3378
+ } else {
3379
+ node.children.forEach((child) => {
3380
+ _TokenTree._collapse(child);
3381
+ });
3382
+ }
3383
+ }
3384
+ };
3385
+ var TokenTreeEmitter = class extends TokenTree {
3386
+ /**
3387
+ * @param {*} options
3388
+ */
3389
+ constructor(options) {
3390
+ super();
3391
+ this.options = options;
3392
+ }
3393
+ /**
3394
+ * @param {string} text
3395
+ */
3396
+ addText(text) {
3397
+ if (text === "") {
3398
+ return;
3399
+ }
3400
+ this.add(text);
3401
+ }
3402
+ /** @param {string} scope */
3403
+ startScope(scope) {
3404
+ this.openNode(scope);
3405
+ }
3406
+ endScope() {
3407
+ this.closeNode();
3408
+ }
3409
+ /**
3410
+ * @param {Emitter & {root: DataNode}} emitter
3411
+ * @param {string} name
3412
+ */
3413
+ __addSublanguage(emitter, name) {
3414
+ const node = emitter.root;
3415
+ if (name) node.scope = `language:${name}`;
3416
+ this.add(node);
3417
+ }
3418
+ toHTML() {
3419
+ const renderer = new HTMLRenderer(this, this.options);
3420
+ return renderer.value();
3421
+ }
3422
+ finalize() {
3423
+ this.closeAllNodes();
3424
+ return true;
3425
+ }
3426
+ };
3427
+ function source(re) {
3428
+ if (!re) return null;
3429
+ if (typeof re === "string") return re;
3430
+ return re.source;
3431
+ }
3432
+ function lookahead(re) {
3433
+ return concat("(?=", re, ")");
3434
+ }
3435
+ function anyNumberOfTimes(re) {
3436
+ return concat("(?:", re, ")*");
3437
+ }
3438
+ function optional(re) {
3439
+ return concat("(?:", re, ")?");
3440
+ }
3441
+ function concat(...args) {
3442
+ const joined = args.map((x) => source(x)).join("");
3443
+ return joined;
3444
+ }
3445
+ function stripOptionsFromArgs(args) {
3446
+ const opts = args[args.length - 1];
3447
+ if (typeof opts === "object" && opts.constructor === Object) {
3448
+ args.splice(args.length - 1, 1);
3449
+ return opts;
3450
+ } else {
3451
+ return {};
3452
+ }
3453
+ }
3454
+ function either(...args) {
3455
+ const opts = stripOptionsFromArgs(args);
3456
+ const joined = "(" + (opts.capture ? "" : "?:") + args.map((x) => source(x)).join("|") + ")";
3457
+ return joined;
3458
+ }
3459
+ function countMatchGroups(re) {
3460
+ return new RegExp(re.toString() + "|").exec("").length - 1;
3461
+ }
3462
+ function startsWith(re, lexeme) {
3463
+ const match = re && re.exec(lexeme);
3464
+ return match && match.index === 0;
3465
+ }
3466
+ var BACKREF_RE = /\[(?:[^\\\]]|\\.)*\]|\(\??|\\([1-9][0-9]*)|\\./;
3467
+ function _rewriteBackreferences(regexps, { joinWith }) {
3468
+ let numCaptures = 0;
3469
+ return regexps.map((regex) => {
3470
+ numCaptures += 1;
3471
+ const offset = numCaptures;
3472
+ let re = source(regex);
3473
+ let out = "";
3474
+ while (re.length > 0) {
3475
+ const match = BACKREF_RE.exec(re);
3476
+ if (!match) {
3477
+ out += re;
3478
+ break;
3479
+ }
3480
+ out += re.substring(0, match.index);
3481
+ re = re.substring(match.index + match[0].length);
3482
+ if (match[0][0] === "\\" && match[1]) {
3483
+ out += "\\" + String(Number(match[1]) + offset);
3484
+ } else {
3485
+ out += match[0];
3486
+ if (match[0] === "(") {
3487
+ numCaptures++;
3488
+ }
3489
+ }
3490
+ }
3491
+ return out;
3492
+ }).map((re) => `(${re})`).join(joinWith);
3493
+ }
3494
+ var MATCH_NOTHING_RE = /\b\B/;
3495
+ var IDENT_RE = "[a-zA-Z]\\w*";
3496
+ var UNDERSCORE_IDENT_RE = "[a-zA-Z_]\\w*";
3497
+ var NUMBER_RE = "\\b\\d+(\\.\\d+)?";
3498
+ var C_NUMBER_RE = "(-?)(\\b0[xX][a-fA-F0-9]+|(\\b\\d+(\\.\\d*)?|\\.\\d+)([eE][-+]?\\d+)?)";
3499
+ var BINARY_NUMBER_RE = "\\b(0b[01]+)";
3500
+ var RE_STARTERS_RE = "!|!=|!==|%|%=|&|&&|&=|\\*|\\*=|\\+|\\+=|,|-|-=|/=|/|:|;|<<|<<=|<=|<|===|==|=|>>>=|>>=|>=|>>>|>>|>|\\?|\\[|\\{|\\(|\\^|\\^=|\\||\\|=|\\|\\||~";
3501
+ var SHEBANG = (opts = {}) => {
3502
+ const beginShebang = /^#![ ]*\//;
3503
+ if (opts.binary) {
3504
+ opts.begin = concat(
3505
+ beginShebang,
3506
+ /.*\b/,
3507
+ opts.binary,
3508
+ /\b.*/
3509
+ );
3510
+ }
3511
+ return inherit$1({
3512
+ scope: "meta",
3513
+ begin: beginShebang,
3514
+ end: /$/,
3515
+ relevance: 0,
3516
+ /** @type {ModeCallback} */
3517
+ "on:begin": (m, resp) => {
3518
+ if (m.index !== 0) resp.ignoreMatch();
3519
+ }
3520
+ }, opts);
3521
+ };
3522
+ var BACKSLASH_ESCAPE = {
3523
+ begin: "\\\\[\\s\\S]",
3524
+ relevance: 0
3525
+ };
3526
+ var APOS_STRING_MODE = {
3527
+ scope: "string",
3528
+ begin: "'",
3529
+ end: "'",
3530
+ illegal: "\\n",
3531
+ contains: [BACKSLASH_ESCAPE]
3532
+ };
3533
+ var QUOTE_STRING_MODE = {
3534
+ scope: "string",
3535
+ begin: '"',
3536
+ end: '"',
3537
+ illegal: "\\n",
3538
+ contains: [BACKSLASH_ESCAPE]
3539
+ };
3540
+ var PHRASAL_WORDS_MODE = {
3541
+ begin: /\b(a|an|the|are|I'm|isn't|don't|doesn't|won't|but|just|should|pretty|simply|enough|gonna|going|wtf|so|such|will|you|your|they|like|more)\b/
3542
+ };
3543
+ var COMMENT = function(begin, end, modeOptions = {}) {
3544
+ const mode = inherit$1(
3545
+ {
3546
+ scope: "comment",
3547
+ begin,
3548
+ end,
3549
+ contains: []
3550
+ },
3551
+ modeOptions
3552
+ );
3553
+ mode.contains.push({
3554
+ scope: "doctag",
3555
+ // hack to avoid the space from being included. the space is necessary to
3556
+ // match here to prevent the plain text rule below from gobbling up doctags
3557
+ begin: "[ ]*(?=(TODO|FIXME|NOTE|BUG|OPTIMIZE|HACK|XXX):)",
3558
+ end: /(TODO|FIXME|NOTE|BUG|OPTIMIZE|HACK|XXX):/,
3559
+ excludeBegin: true,
3560
+ relevance: 0
3561
+ });
3562
+ const ENGLISH_WORD = either(
3563
+ // list of common 1 and 2 letter words in English
3564
+ "I",
3565
+ "a",
3566
+ "is",
3567
+ "so",
3568
+ "us",
3569
+ "to",
3570
+ "at",
3571
+ "if",
3572
+ "in",
3573
+ "it",
3574
+ "on",
3575
+ // note: this is not an exhaustive list of contractions, just popular ones
3576
+ /[A-Za-z]+['](d|ve|re|ll|t|s|n)/,
3577
+ // contractions - can't we'd they're let's, etc
3578
+ /[A-Za-z]+[-][a-z]+/,
3579
+ // `no-way`, etc.
3580
+ /[A-Za-z][a-z]{2,}/
3581
+ // allow capitalized words at beginning of sentences
3582
+ );
3583
+ mode.contains.push(
3584
+ {
3585
+ // TODO: how to include ", (, ) without breaking grammars that use these for
3586
+ // comment delimiters?
3587
+ // begin: /[ ]+([()"]?([A-Za-z'-]{3,}|is|a|I|so|us|[tT][oO]|at|if|in|it|on)[.]?[()":]?([.][ ]|[ ]|\))){3}/
3588
+ // ---
3589
+ // this tries to find sequences of 3 english words in a row (without any
3590
+ // "programming" type syntax) this gives us a strong signal that we've
3591
+ // TRULY found a comment - vs perhaps scanning with the wrong language.
3592
+ // It's possible to find something that LOOKS like the start of the
3593
+ // comment - but then if there is no readable text - good chance it is a
3594
+ // false match and not a comment.
3595
+ //
3596
+ // for a visual example please see:
3597
+ // https://github.com/highlightjs/highlight.js/issues/2827
3598
+ begin: concat(
3599
+ /[ ]+/,
3600
+ // necessary to prevent us gobbling up doctags like /* @author Bob Mcgill */
3601
+ "(",
3602
+ ENGLISH_WORD,
3603
+ /[.]?[:]?([.][ ]|[ ])/,
3604
+ "){3}"
3605
+ )
3606
+ // look for 3 words in a row
3607
+ }
3608
+ );
3609
+ return mode;
3610
+ };
3611
+ var C_LINE_COMMENT_MODE = COMMENT("//", "$");
3612
+ var C_BLOCK_COMMENT_MODE = COMMENT("/\\*", "\\*/");
3613
+ var HASH_COMMENT_MODE = COMMENT("#", "$");
3614
+ var NUMBER_MODE = {
3615
+ scope: "number",
3616
+ begin: NUMBER_RE,
3617
+ relevance: 0
3618
+ };
3619
+ var C_NUMBER_MODE = {
3620
+ scope: "number",
3621
+ begin: C_NUMBER_RE,
3622
+ relevance: 0
3623
+ };
3624
+ var BINARY_NUMBER_MODE = {
3625
+ scope: "number",
3626
+ begin: BINARY_NUMBER_RE,
3627
+ relevance: 0
3628
+ };
3629
+ var REGEXP_MODE = {
3630
+ scope: "regexp",
3631
+ begin: /\/(?=[^/\n]*\/)/,
3632
+ end: /\/[gimuy]*/,
3633
+ contains: [
3634
+ BACKSLASH_ESCAPE,
3635
+ {
3636
+ begin: /\[/,
3637
+ end: /\]/,
3638
+ relevance: 0,
3639
+ contains: [BACKSLASH_ESCAPE]
3640
+ }
3641
+ ]
3642
+ };
3643
+ var TITLE_MODE = {
3644
+ scope: "title",
3645
+ begin: IDENT_RE,
3646
+ relevance: 0
3647
+ };
3648
+ var UNDERSCORE_TITLE_MODE = {
3649
+ scope: "title",
3650
+ begin: UNDERSCORE_IDENT_RE,
3651
+ relevance: 0
3652
+ };
3653
+ var METHOD_GUARD = {
3654
+ // excludes method names from keyword processing
3655
+ begin: "\\.\\s*" + UNDERSCORE_IDENT_RE,
3656
+ relevance: 0
3657
+ };
3658
+ var END_SAME_AS_BEGIN = function(mode) {
3659
+ return Object.assign(
3660
+ mode,
3661
+ {
3662
+ /** @type {ModeCallback} */
3663
+ "on:begin": (m, resp) => {
3664
+ resp.data._beginMatch = m[1];
3665
+ },
3666
+ /** @type {ModeCallback} */
3667
+ "on:end": (m, resp) => {
3668
+ if (resp.data._beginMatch !== m[1]) resp.ignoreMatch();
3669
+ }
3670
+ }
3671
+ );
3672
+ };
3673
+ var MODES = /* @__PURE__ */ Object.freeze({
3674
+ __proto__: null,
3675
+ APOS_STRING_MODE,
3676
+ BACKSLASH_ESCAPE,
3677
+ BINARY_NUMBER_MODE,
3678
+ BINARY_NUMBER_RE,
3679
+ COMMENT,
3680
+ C_BLOCK_COMMENT_MODE,
3681
+ C_LINE_COMMENT_MODE,
3682
+ C_NUMBER_MODE,
3683
+ C_NUMBER_RE,
3684
+ END_SAME_AS_BEGIN,
3685
+ HASH_COMMENT_MODE,
3686
+ IDENT_RE,
3687
+ MATCH_NOTHING_RE,
3688
+ METHOD_GUARD,
3689
+ NUMBER_MODE,
3690
+ NUMBER_RE,
3691
+ PHRASAL_WORDS_MODE,
3692
+ QUOTE_STRING_MODE,
3693
+ REGEXP_MODE,
3694
+ RE_STARTERS_RE,
3695
+ SHEBANG,
3696
+ TITLE_MODE,
3697
+ UNDERSCORE_IDENT_RE,
3698
+ UNDERSCORE_TITLE_MODE
3699
+ });
3700
+ function skipIfHasPrecedingDot(match, response) {
3701
+ const before = match.input[match.index - 1];
3702
+ if (before === ".") {
3703
+ response.ignoreMatch();
3704
+ }
3705
+ }
3706
+ function scopeClassName(mode, _parent) {
3707
+ if (mode.className !== void 0) {
3708
+ mode.scope = mode.className;
3709
+ delete mode.className;
3710
+ }
3711
+ }
3712
+ function beginKeywords(mode, parent) {
3713
+ if (!parent) return;
3714
+ if (!mode.beginKeywords) return;
3715
+ mode.begin = "\\b(" + mode.beginKeywords.split(" ").join("|") + ")(?!\\.)(?=\\b|\\s)";
3716
+ mode.__beforeBegin = skipIfHasPrecedingDot;
3717
+ mode.keywords = mode.keywords || mode.beginKeywords;
3718
+ delete mode.beginKeywords;
3719
+ if (mode.relevance === void 0) mode.relevance = 0;
3720
+ }
3721
+ function compileIllegal(mode, _parent) {
3722
+ if (!Array.isArray(mode.illegal)) return;
3723
+ mode.illegal = either(...mode.illegal);
3724
+ }
3725
+ function compileMatch(mode, _parent) {
3726
+ if (!mode.match) return;
3727
+ if (mode.begin || mode.end) throw new Error("begin & end are not supported with match");
3728
+ mode.begin = mode.match;
3729
+ delete mode.match;
3730
+ }
3731
+ function compileRelevance(mode, _parent) {
3732
+ if (mode.relevance === void 0) mode.relevance = 1;
3733
+ }
3734
+ var beforeMatchExt = (mode, parent) => {
3735
+ if (!mode.beforeMatch) return;
3736
+ if (mode.starts) throw new Error("beforeMatch cannot be used with starts");
3737
+ const originalMode = Object.assign({}, mode);
3738
+ Object.keys(mode).forEach((key) => {
3739
+ delete mode[key];
3740
+ });
3741
+ mode.keywords = originalMode.keywords;
3742
+ mode.begin = concat(originalMode.beforeMatch, lookahead(originalMode.begin));
3743
+ mode.starts = {
3744
+ relevance: 0,
3745
+ contains: [
3746
+ Object.assign(originalMode, { endsParent: true })
3747
+ ]
3748
+ };
3749
+ mode.relevance = 0;
3750
+ delete originalMode.beforeMatch;
3751
+ };
3752
+ var COMMON_KEYWORDS = [
3753
+ "of",
3754
+ "and",
3755
+ "for",
3756
+ "in",
3757
+ "not",
3758
+ "or",
3759
+ "if",
3760
+ "then",
3761
+ "parent",
3762
+ // common variable name
3763
+ "list",
3764
+ // common variable name
3765
+ "value"
3766
+ // common variable name
3767
+ ];
3768
+ var DEFAULT_KEYWORD_SCOPE = "keyword";
3769
+ function compileKeywords(rawKeywords, caseInsensitive, scopeName = DEFAULT_KEYWORD_SCOPE) {
3770
+ const compiledKeywords = /* @__PURE__ */ Object.create(null);
3771
+ if (typeof rawKeywords === "string") {
3772
+ compileList(scopeName, rawKeywords.split(" "));
3773
+ } else if (Array.isArray(rawKeywords)) {
3774
+ compileList(scopeName, rawKeywords);
3775
+ } else {
3776
+ Object.keys(rawKeywords).forEach(function(scopeName2) {
3777
+ Object.assign(
3778
+ compiledKeywords,
3779
+ compileKeywords(rawKeywords[scopeName2], caseInsensitive, scopeName2)
3780
+ );
3781
+ });
3782
+ }
3783
+ return compiledKeywords;
3784
+ function compileList(scopeName2, keywordList) {
3785
+ if (caseInsensitive) {
3786
+ keywordList = keywordList.map((x) => x.toLowerCase());
3787
+ }
3788
+ keywordList.forEach(function(keyword) {
3789
+ const pair = keyword.split("|");
3790
+ compiledKeywords[pair[0]] = [scopeName2, scoreForKeyword(pair[0], pair[1])];
3791
+ });
3792
+ }
3793
+ }
3794
+ function scoreForKeyword(keyword, providedScore) {
3795
+ if (providedScore) {
3796
+ return Number(providedScore);
3797
+ }
3798
+ return commonKeyword(keyword) ? 0 : 1;
3799
+ }
3800
+ function commonKeyword(keyword) {
3801
+ return COMMON_KEYWORDS.includes(keyword.toLowerCase());
3802
+ }
3803
+ var seenDeprecations = {};
3804
+ var error = (message) => {
3805
+ console.error(message);
3806
+ };
3807
+ var warn2 = (message, ...args) => {
3808
+ console.log(`WARN: ${message}`, ...args);
3809
+ };
3810
+ var deprecated = (version2, message) => {
3811
+ if (seenDeprecations[`${version2}/${message}`]) return;
3812
+ console.log(`Deprecated as of ${version2}. ${message}`);
3813
+ seenDeprecations[`${version2}/${message}`] = true;
3814
+ };
3815
+ var MultiClassError = new Error();
3816
+ function remapScopeNames(mode, regexes, { key }) {
3817
+ let offset = 0;
3818
+ const scopeNames = mode[key];
3819
+ const emit = {};
3820
+ const positions = {};
3821
+ for (let i = 1; i <= regexes.length; i++) {
3822
+ positions[i + offset] = scopeNames[i];
3823
+ emit[i + offset] = true;
3824
+ offset += countMatchGroups(regexes[i - 1]);
3825
+ }
3826
+ mode[key] = positions;
3827
+ mode[key]._emit = emit;
3828
+ mode[key]._multi = true;
3829
+ }
3830
+ function beginMultiClass(mode) {
3831
+ if (!Array.isArray(mode.begin)) return;
3832
+ if (mode.skip || mode.excludeBegin || mode.returnBegin) {
3833
+ error("skip, excludeBegin, returnBegin not compatible with beginScope: {}");
3834
+ throw MultiClassError;
3835
+ }
3836
+ if (typeof mode.beginScope !== "object" || mode.beginScope === null) {
3837
+ error("beginScope must be object");
3838
+ throw MultiClassError;
3839
+ }
3840
+ remapScopeNames(mode, mode.begin, { key: "beginScope" });
3841
+ mode.begin = _rewriteBackreferences(mode.begin, { joinWith: "" });
3842
+ }
3843
+ function endMultiClass(mode) {
3844
+ if (!Array.isArray(mode.end)) return;
3845
+ if (mode.skip || mode.excludeEnd || mode.returnEnd) {
3846
+ error("skip, excludeEnd, returnEnd not compatible with endScope: {}");
3847
+ throw MultiClassError;
3848
+ }
3849
+ if (typeof mode.endScope !== "object" || mode.endScope === null) {
3850
+ error("endScope must be object");
3851
+ throw MultiClassError;
3852
+ }
3853
+ remapScopeNames(mode, mode.end, { key: "endScope" });
3854
+ mode.end = _rewriteBackreferences(mode.end, { joinWith: "" });
3855
+ }
3856
+ function scopeSugar(mode) {
3857
+ if (mode.scope && typeof mode.scope === "object" && mode.scope !== null) {
3858
+ mode.beginScope = mode.scope;
3859
+ delete mode.scope;
3860
+ }
3861
+ }
3862
+ function MultiClass(mode) {
3863
+ scopeSugar(mode);
3864
+ if (typeof mode.beginScope === "string") {
3865
+ mode.beginScope = { _wrap: mode.beginScope };
3866
+ }
3867
+ if (typeof mode.endScope === "string") {
3868
+ mode.endScope = { _wrap: mode.endScope };
3869
+ }
3870
+ beginMultiClass(mode);
3871
+ endMultiClass(mode);
3872
+ }
3873
+ function compileLanguage(language) {
3874
+ function langRe(value, global) {
3875
+ return new RegExp(
3876
+ source(value),
3877
+ "m" + (language.case_insensitive ? "i" : "") + (language.unicodeRegex ? "u" : "") + (global ? "g" : "")
3878
+ );
3879
+ }
3880
+ class MultiRegex {
3881
+ constructor() {
3882
+ this.matchIndexes = {};
3883
+ this.regexes = [];
3884
+ this.matchAt = 1;
3885
+ this.position = 0;
3886
+ }
3887
+ // @ts-ignore
3888
+ addRule(re, opts) {
3889
+ opts.position = this.position++;
3890
+ this.matchIndexes[this.matchAt] = opts;
3891
+ this.regexes.push([opts, re]);
3892
+ this.matchAt += countMatchGroups(re) + 1;
3893
+ }
3894
+ compile() {
3895
+ if (this.regexes.length === 0) {
3896
+ this.exec = () => null;
3897
+ }
3898
+ const terminators = this.regexes.map((el) => el[1]);
3899
+ this.matcherRe = langRe(_rewriteBackreferences(terminators, { joinWith: "|" }), true);
3900
+ this.lastIndex = 0;
3901
+ }
3902
+ /** @param {string} s */
3903
+ exec(s) {
3904
+ this.matcherRe.lastIndex = this.lastIndex;
3905
+ const match = this.matcherRe.exec(s);
3906
+ if (!match) {
3907
+ return null;
3908
+ }
3909
+ const i = match.findIndex((el, i2) => i2 > 0 && el !== void 0);
3910
+ const matchData = this.matchIndexes[i];
3911
+ match.splice(0, i);
3912
+ return Object.assign(match, matchData);
3913
+ }
3914
+ }
3915
+ class ResumableMultiRegex {
3916
+ constructor() {
3917
+ this.rules = [];
3918
+ this.multiRegexes = [];
3919
+ this.count = 0;
3920
+ this.lastIndex = 0;
3921
+ this.regexIndex = 0;
3922
+ }
3923
+ // @ts-ignore
3924
+ getMatcher(index) {
3925
+ if (this.multiRegexes[index]) return this.multiRegexes[index];
3926
+ const matcher = new MultiRegex();
3927
+ this.rules.slice(index).forEach(([re, opts]) => matcher.addRule(re, opts));
3928
+ matcher.compile();
3929
+ this.multiRegexes[index] = matcher;
3930
+ return matcher;
3931
+ }
3932
+ resumingScanAtSamePosition() {
3933
+ return this.regexIndex !== 0;
3934
+ }
3935
+ considerAll() {
3936
+ this.regexIndex = 0;
3937
+ }
3938
+ // @ts-ignore
3939
+ addRule(re, opts) {
3940
+ this.rules.push([re, opts]);
3941
+ if (opts.type === "begin") this.count++;
3942
+ }
3943
+ /** @param {string} s */
3944
+ exec(s) {
3945
+ const m = this.getMatcher(this.regexIndex);
3946
+ m.lastIndex = this.lastIndex;
3947
+ let result = m.exec(s);
3948
+ if (this.resumingScanAtSamePosition()) {
3949
+ if (result && result.index === this.lastIndex) ;
3950
+ else {
3951
+ const m2 = this.getMatcher(0);
3952
+ m2.lastIndex = this.lastIndex + 1;
3953
+ result = m2.exec(s);
3954
+ }
3955
+ }
3956
+ if (result) {
3957
+ this.regexIndex += result.position + 1;
3958
+ if (this.regexIndex === this.count) {
3959
+ this.considerAll();
3960
+ }
3961
+ }
3962
+ return result;
3963
+ }
3964
+ }
3965
+ function buildModeRegex(mode) {
3966
+ const mm = new ResumableMultiRegex();
3967
+ mode.contains.forEach((term) => mm.addRule(term.begin, { rule: term, type: "begin" }));
3968
+ if (mode.terminatorEnd) {
3969
+ mm.addRule(mode.terminatorEnd, { type: "end" });
3970
+ }
3971
+ if (mode.illegal) {
3972
+ mm.addRule(mode.illegal, { type: "illegal" });
3973
+ }
3974
+ return mm;
3975
+ }
3976
+ function compileMode(mode, parent) {
3977
+ const cmode = (
3978
+ /** @type CompiledMode */
3979
+ mode
3980
+ );
3981
+ if (mode.isCompiled) return cmode;
3982
+ [
3983
+ scopeClassName,
3984
+ // do this early so compiler extensions generally don't have to worry about
3985
+ // the distinction between match/begin
3986
+ compileMatch,
3987
+ MultiClass,
3988
+ beforeMatchExt
3989
+ ].forEach((ext) => ext(mode, parent));
3990
+ language.compilerExtensions.forEach((ext) => ext(mode, parent));
3991
+ mode.__beforeBegin = null;
3992
+ [
3993
+ beginKeywords,
3994
+ // do this later so compiler extensions that come earlier have access to the
3995
+ // raw array if they wanted to perhaps manipulate it, etc.
3996
+ compileIllegal,
3997
+ // default to 1 relevance if not specified
3998
+ compileRelevance
3999
+ ].forEach((ext) => ext(mode, parent));
4000
+ mode.isCompiled = true;
4001
+ let keywordPattern = null;
4002
+ if (typeof mode.keywords === "object" && mode.keywords.$pattern) {
4003
+ mode.keywords = Object.assign({}, mode.keywords);
4004
+ keywordPattern = mode.keywords.$pattern;
4005
+ delete mode.keywords.$pattern;
4006
+ }
4007
+ keywordPattern = keywordPattern || /\w+/;
4008
+ if (mode.keywords) {
4009
+ mode.keywords = compileKeywords(mode.keywords, language.case_insensitive);
4010
+ }
4011
+ cmode.keywordPatternRe = langRe(keywordPattern, true);
4012
+ if (parent) {
4013
+ if (!mode.begin) mode.begin = /\B|\b/;
4014
+ cmode.beginRe = langRe(cmode.begin);
4015
+ if (!mode.end && !mode.endsWithParent) mode.end = /\B|\b/;
4016
+ if (mode.end) cmode.endRe = langRe(cmode.end);
4017
+ cmode.terminatorEnd = source(cmode.end) || "";
4018
+ if (mode.endsWithParent && parent.terminatorEnd) {
4019
+ cmode.terminatorEnd += (mode.end ? "|" : "") + parent.terminatorEnd;
4020
+ }
4021
+ }
4022
+ if (mode.illegal) cmode.illegalRe = langRe(
4023
+ /** @type {RegExp | string} */
4024
+ mode.illegal
4025
+ );
4026
+ if (!mode.contains) mode.contains = [];
4027
+ mode.contains = [].concat(...mode.contains.map(function(c) {
4028
+ return expandOrCloneMode(c === "self" ? mode : c);
4029
+ }));
4030
+ mode.contains.forEach(function(c) {
4031
+ compileMode(
4032
+ /** @type Mode */
4033
+ c,
4034
+ cmode
4035
+ );
4036
+ });
4037
+ if (mode.starts) {
4038
+ compileMode(mode.starts, parent);
4039
+ }
4040
+ cmode.matcher = buildModeRegex(cmode);
4041
+ return cmode;
4042
+ }
4043
+ if (!language.compilerExtensions) language.compilerExtensions = [];
4044
+ if (language.contains && language.contains.includes("self")) {
4045
+ throw new Error("ERR: contains `self` is not supported at the top-level of a language. See documentation.");
4046
+ }
4047
+ language.classNameAliases = inherit$1(language.classNameAliases || {});
4048
+ return compileMode(
4049
+ /** @type Mode */
4050
+ language
4051
+ );
4052
+ }
4053
+ function dependencyOnParent(mode) {
4054
+ if (!mode) return false;
4055
+ return mode.endsWithParent || dependencyOnParent(mode.starts);
4056
+ }
4057
+ function expandOrCloneMode(mode) {
4058
+ if (mode.variants && !mode.cachedVariants) {
4059
+ mode.cachedVariants = mode.variants.map(function(variant) {
4060
+ return inherit$1(mode, { variants: null }, variant);
4061
+ });
4062
+ }
4063
+ if (mode.cachedVariants) {
4064
+ return mode.cachedVariants;
4065
+ }
4066
+ if (dependencyOnParent(mode)) {
4067
+ return inherit$1(mode, { starts: mode.starts ? inherit$1(mode.starts) : null });
4068
+ }
4069
+ if (Object.isFrozen(mode)) {
4070
+ return inherit$1(mode);
4071
+ }
4072
+ return mode;
4073
+ }
4074
+ var version = "11.10.0";
4075
+ var HTMLInjectionError = class extends Error {
4076
+ constructor(reason, html) {
4077
+ super(reason);
4078
+ this.name = "HTMLInjectionError";
4079
+ this.html = html;
4080
+ }
4081
+ };
4082
+ var escape = escapeHTML;
4083
+ var inherit = inherit$1;
4084
+ var NO_MATCH = /* @__PURE__ */ Symbol("nomatch");
4085
+ var MAX_KEYWORD_HITS = 7;
4086
+ var HLJS = function(hljs) {
4087
+ const languages = /* @__PURE__ */ Object.create(null);
4088
+ const aliases = /* @__PURE__ */ Object.create(null);
4089
+ const plugins = [];
4090
+ let SAFE_MODE = true;
4091
+ const LANGUAGE_NOT_FOUND = "Could not find the language '{}', did you forget to load/include a language module?";
4092
+ const PLAINTEXT_LANGUAGE = { disableAutodetect: true, name: "Plain text", contains: [] };
4093
+ let options = {
4094
+ ignoreUnescapedHTML: false,
4095
+ throwUnescapedHTML: false,
4096
+ noHighlightRe: /^(no-?highlight)$/i,
4097
+ languageDetectRe: /\blang(?:uage)?-([\w-]+)\b/i,
4098
+ classPrefix: "hljs-",
4099
+ cssSelector: "pre code",
4100
+ languages: null,
4101
+ // beta configuration options, subject to change, welcome to discuss
4102
+ // https://github.com/highlightjs/highlight.js/issues/1086
4103
+ __emitter: TokenTreeEmitter
4104
+ };
4105
+ function shouldNotHighlight(languageName) {
4106
+ return options.noHighlightRe.test(languageName);
4107
+ }
4108
+ function blockLanguage(block) {
4109
+ let classes = block.className + " ";
4110
+ classes += block.parentNode ? block.parentNode.className : "";
4111
+ const match = options.languageDetectRe.exec(classes);
4112
+ if (match) {
4113
+ const language = getLanguage(match[1]);
4114
+ if (!language) {
4115
+ warn2(LANGUAGE_NOT_FOUND.replace("{}", match[1]));
4116
+ warn2("Falling back to no-highlight mode for this block.", block);
4117
+ }
4118
+ return language ? match[1] : "no-highlight";
4119
+ }
4120
+ return classes.split(/\s+/).find((_class) => shouldNotHighlight(_class) || getLanguage(_class));
4121
+ }
4122
+ function highlight2(codeOrLanguageName, optionsOrCode, ignoreIllegals) {
4123
+ let code = "";
4124
+ let languageName = "";
4125
+ if (typeof optionsOrCode === "object") {
4126
+ code = codeOrLanguageName;
4127
+ ignoreIllegals = optionsOrCode.ignoreIllegals;
4128
+ languageName = optionsOrCode.language;
4129
+ } else {
4130
+ deprecated("10.7.0", "highlight(lang, code, ...args) has been deprecated.");
4131
+ deprecated("10.7.0", "Please use highlight(code, options) instead.\nhttps://github.com/highlightjs/highlight.js/issues/2277");
4132
+ languageName = codeOrLanguageName;
4133
+ code = optionsOrCode;
4134
+ }
4135
+ if (ignoreIllegals === void 0) {
4136
+ ignoreIllegals = true;
4137
+ }
4138
+ const context = {
4139
+ code,
4140
+ language: languageName
4141
+ };
4142
+ fire("before:highlight", context);
4143
+ const result = context.result ? context.result : _highlight(context.language, context.code, ignoreIllegals);
4144
+ result.code = context.code;
4145
+ fire("after:highlight", result);
4146
+ return result;
4147
+ }
4148
+ function _highlight(languageName, codeToHighlight, ignoreIllegals, continuation) {
4149
+ const keywordHits = /* @__PURE__ */ Object.create(null);
4150
+ function keywordData(mode, matchText) {
4151
+ return mode.keywords[matchText];
4152
+ }
4153
+ function processKeywords() {
4154
+ if (!top.keywords) {
4155
+ emitter.addText(modeBuffer);
4156
+ return;
4157
+ }
4158
+ let lastIndex = 0;
4159
+ top.keywordPatternRe.lastIndex = 0;
4160
+ let match = top.keywordPatternRe.exec(modeBuffer);
4161
+ let buf = "";
4162
+ while (match) {
4163
+ buf += modeBuffer.substring(lastIndex, match.index);
4164
+ const word = language.case_insensitive ? match[0].toLowerCase() : match[0];
4165
+ const data = keywordData(top, word);
4166
+ if (data) {
4167
+ const [kind, keywordRelevance] = data;
4168
+ emitter.addText(buf);
4169
+ buf = "";
4170
+ keywordHits[word] = (keywordHits[word] || 0) + 1;
4171
+ if (keywordHits[word] <= MAX_KEYWORD_HITS) relevance += keywordRelevance;
4172
+ if (kind.startsWith("_")) {
4173
+ buf += match[0];
4174
+ } else {
4175
+ const cssClass = language.classNameAliases[kind] || kind;
4176
+ emitKeyword(match[0], cssClass);
4177
+ }
4178
+ } else {
4179
+ buf += match[0];
4180
+ }
4181
+ lastIndex = top.keywordPatternRe.lastIndex;
4182
+ match = top.keywordPatternRe.exec(modeBuffer);
4183
+ }
4184
+ buf += modeBuffer.substring(lastIndex);
4185
+ emitter.addText(buf);
4186
+ }
4187
+ function processSubLanguage() {
4188
+ if (modeBuffer === "") return;
4189
+ let result2 = null;
4190
+ if (typeof top.subLanguage === "string") {
4191
+ if (!languages[top.subLanguage]) {
4192
+ emitter.addText(modeBuffer);
4193
+ return;
4194
+ }
4195
+ result2 = _highlight(top.subLanguage, modeBuffer, true, continuations[top.subLanguage]);
4196
+ continuations[top.subLanguage] = /** @type {CompiledMode} */
4197
+ result2._top;
4198
+ } else {
4199
+ result2 = highlightAuto(modeBuffer, top.subLanguage.length ? top.subLanguage : null);
4200
+ }
4201
+ if (top.relevance > 0) {
4202
+ relevance += result2.relevance;
4203
+ }
4204
+ emitter.__addSublanguage(result2._emitter, result2.language);
4205
+ }
4206
+ function processBuffer() {
4207
+ if (top.subLanguage != null) {
4208
+ processSubLanguage();
4209
+ } else {
4210
+ processKeywords();
4211
+ }
4212
+ modeBuffer = "";
4213
+ }
4214
+ function emitKeyword(keyword, scope) {
4215
+ if (keyword === "") return;
4216
+ emitter.startScope(scope);
4217
+ emitter.addText(keyword);
4218
+ emitter.endScope();
4219
+ }
4220
+ function emitMultiClass(scope, match) {
4221
+ let i = 1;
4222
+ const max = match.length - 1;
4223
+ while (i <= max) {
4224
+ if (!scope._emit[i]) {
4225
+ i++;
4226
+ continue;
4227
+ }
4228
+ const klass = language.classNameAliases[scope[i]] || scope[i];
4229
+ const text = match[i];
4230
+ if (klass) {
4231
+ emitKeyword(text, klass);
4232
+ } else {
4233
+ modeBuffer = text;
4234
+ processKeywords();
4235
+ modeBuffer = "";
4236
+ }
4237
+ i++;
4238
+ }
4239
+ }
4240
+ function startNewMode(mode, match) {
4241
+ if (mode.scope && typeof mode.scope === "string") {
4242
+ emitter.openNode(language.classNameAliases[mode.scope] || mode.scope);
4243
+ }
4244
+ if (mode.beginScope) {
4245
+ if (mode.beginScope._wrap) {
4246
+ emitKeyword(modeBuffer, language.classNameAliases[mode.beginScope._wrap] || mode.beginScope._wrap);
4247
+ modeBuffer = "";
4248
+ } else if (mode.beginScope._multi) {
4249
+ emitMultiClass(mode.beginScope, match);
4250
+ modeBuffer = "";
4251
+ }
4252
+ }
4253
+ top = Object.create(mode, { parent: { value: top } });
4254
+ return top;
4255
+ }
4256
+ function endOfMode(mode, match, matchPlusRemainder) {
4257
+ let matched = startsWith(mode.endRe, matchPlusRemainder);
4258
+ if (matched) {
4259
+ if (mode["on:end"]) {
4260
+ const resp = new Response(mode);
4261
+ mode["on:end"](match, resp);
4262
+ if (resp.isMatchIgnored) matched = false;
4263
+ }
4264
+ if (matched) {
4265
+ while (mode.endsParent && mode.parent) {
4266
+ mode = mode.parent;
4267
+ }
4268
+ return mode;
4269
+ }
4270
+ }
4271
+ if (mode.endsWithParent) {
4272
+ return endOfMode(mode.parent, match, matchPlusRemainder);
4273
+ }
4274
+ }
4275
+ function doIgnore(lexeme) {
4276
+ if (top.matcher.regexIndex === 0) {
4277
+ modeBuffer += lexeme[0];
4278
+ return 1;
4279
+ } else {
4280
+ resumeScanAtSamePosition = true;
4281
+ return 0;
4282
+ }
4283
+ }
4284
+ function doBeginMatch(match) {
4285
+ const lexeme = match[0];
4286
+ const newMode = match.rule;
4287
+ const resp = new Response(newMode);
4288
+ const beforeCallbacks = [newMode.__beforeBegin, newMode["on:begin"]];
4289
+ for (const cb of beforeCallbacks) {
4290
+ if (!cb) continue;
4291
+ cb(match, resp);
4292
+ if (resp.isMatchIgnored) return doIgnore(lexeme);
4293
+ }
4294
+ if (newMode.skip) {
4295
+ modeBuffer += lexeme;
4296
+ } else {
4297
+ if (newMode.excludeBegin) {
4298
+ modeBuffer += lexeme;
4299
+ }
4300
+ processBuffer();
4301
+ if (!newMode.returnBegin && !newMode.excludeBegin) {
4302
+ modeBuffer = lexeme;
4303
+ }
4304
+ }
4305
+ startNewMode(newMode, match);
4306
+ return newMode.returnBegin ? 0 : lexeme.length;
4307
+ }
4308
+ function doEndMatch(match) {
4309
+ const lexeme = match[0];
4310
+ const matchPlusRemainder = codeToHighlight.substring(match.index);
4311
+ const endMode = endOfMode(top, match, matchPlusRemainder);
4312
+ if (!endMode) {
4313
+ return NO_MATCH;
4314
+ }
4315
+ const origin = top;
4316
+ if (top.endScope && top.endScope._wrap) {
4317
+ processBuffer();
4318
+ emitKeyword(lexeme, top.endScope._wrap);
4319
+ } else if (top.endScope && top.endScope._multi) {
4320
+ processBuffer();
4321
+ emitMultiClass(top.endScope, match);
4322
+ } else if (origin.skip) {
4323
+ modeBuffer += lexeme;
4324
+ } else {
4325
+ if (!(origin.returnEnd || origin.excludeEnd)) {
4326
+ modeBuffer += lexeme;
4327
+ }
4328
+ processBuffer();
4329
+ if (origin.excludeEnd) {
4330
+ modeBuffer = lexeme;
4331
+ }
4332
+ }
4333
+ do {
4334
+ if (top.scope) {
4335
+ emitter.closeNode();
4336
+ }
4337
+ if (!top.skip && !top.subLanguage) {
4338
+ relevance += top.relevance;
4339
+ }
4340
+ top = top.parent;
4341
+ } while (top !== endMode.parent);
4342
+ if (endMode.starts) {
4343
+ startNewMode(endMode.starts, match);
4344
+ }
4345
+ return origin.returnEnd ? 0 : lexeme.length;
4346
+ }
4347
+ function processContinuations() {
4348
+ const list = [];
4349
+ for (let current = top; current !== language; current = current.parent) {
4350
+ if (current.scope) {
4351
+ list.unshift(current.scope);
4352
+ }
4353
+ }
4354
+ list.forEach((item) => emitter.openNode(item));
4355
+ }
4356
+ let lastMatch = {};
4357
+ function processLexeme(textBeforeMatch, match) {
4358
+ const lexeme = match && match[0];
4359
+ modeBuffer += textBeforeMatch;
4360
+ if (lexeme == null) {
4361
+ processBuffer();
4362
+ return 0;
4363
+ }
4364
+ if (lastMatch.type === "begin" && match.type === "end" && lastMatch.index === match.index && lexeme === "") {
4365
+ modeBuffer += codeToHighlight.slice(match.index, match.index + 1);
4366
+ if (!SAFE_MODE) {
4367
+ const err = new Error(`0 width match regex (${languageName})`);
4368
+ err.languageName = languageName;
4369
+ err.badRule = lastMatch.rule;
4370
+ throw err;
4371
+ }
4372
+ return 1;
4373
+ }
4374
+ lastMatch = match;
4375
+ if (match.type === "begin") {
4376
+ return doBeginMatch(match);
4377
+ } else if (match.type === "illegal" && !ignoreIllegals) {
4378
+ const err = new Error('Illegal lexeme "' + lexeme + '" for mode "' + (top.scope || "<unnamed>") + '"');
4379
+ err.mode = top;
4380
+ throw err;
4381
+ } else if (match.type === "end") {
4382
+ const processed = doEndMatch(match);
4383
+ if (processed !== NO_MATCH) {
4384
+ return processed;
4385
+ }
4386
+ }
4387
+ if (match.type === "illegal" && lexeme === "") {
4388
+ return 1;
4389
+ }
4390
+ if (iterations > 1e5 && iterations > match.index * 3) {
4391
+ const err = new Error("potential infinite loop, way more iterations than matches");
4392
+ throw err;
4393
+ }
4394
+ modeBuffer += lexeme;
4395
+ return lexeme.length;
4396
+ }
4397
+ const language = getLanguage(languageName);
4398
+ if (!language) {
4399
+ error(LANGUAGE_NOT_FOUND.replace("{}", languageName));
4400
+ throw new Error('Unknown language: "' + languageName + '"');
4401
+ }
4402
+ const md = compileLanguage(language);
4403
+ let result = "";
4404
+ let top = continuation || md;
4405
+ const continuations = {};
4406
+ const emitter = new options.__emitter(options);
4407
+ processContinuations();
4408
+ let modeBuffer = "";
4409
+ let relevance = 0;
4410
+ let index = 0;
4411
+ let iterations = 0;
4412
+ let resumeScanAtSamePosition = false;
4413
+ try {
4414
+ if (!language.__emitTokens) {
4415
+ top.matcher.considerAll();
4416
+ for (; ; ) {
4417
+ iterations++;
4418
+ if (resumeScanAtSamePosition) {
4419
+ resumeScanAtSamePosition = false;
4420
+ } else {
4421
+ top.matcher.considerAll();
4422
+ }
4423
+ top.matcher.lastIndex = index;
4424
+ const match = top.matcher.exec(codeToHighlight);
4425
+ if (!match) break;
4426
+ const beforeMatch = codeToHighlight.substring(index, match.index);
4427
+ const processedCount = processLexeme(beforeMatch, match);
4428
+ index = match.index + processedCount;
4429
+ }
4430
+ processLexeme(codeToHighlight.substring(index));
4431
+ } else {
4432
+ language.__emitTokens(codeToHighlight, emitter);
4433
+ }
4434
+ emitter.finalize();
4435
+ result = emitter.toHTML();
4436
+ return {
4437
+ language: languageName,
4438
+ value: result,
4439
+ relevance,
4440
+ illegal: false,
4441
+ _emitter: emitter,
4442
+ _top: top
4443
+ };
4444
+ } catch (err) {
4445
+ if (err.message && err.message.includes("Illegal")) {
4446
+ return {
4447
+ language: languageName,
4448
+ value: escape(codeToHighlight),
4449
+ illegal: true,
4450
+ relevance: 0,
4451
+ _illegalBy: {
4452
+ message: err.message,
4453
+ index,
4454
+ context: codeToHighlight.slice(index - 100, index + 100),
4455
+ mode: err.mode,
4456
+ resultSoFar: result
4457
+ },
4458
+ _emitter: emitter
4459
+ };
4460
+ } else if (SAFE_MODE) {
4461
+ return {
4462
+ language: languageName,
4463
+ value: escape(codeToHighlight),
4464
+ illegal: false,
4465
+ relevance: 0,
4466
+ errorRaised: err,
4467
+ _emitter: emitter,
4468
+ _top: top
4469
+ };
4470
+ } else {
4471
+ throw err;
4472
+ }
4473
+ }
4474
+ }
4475
+ function justTextHighlightResult(code) {
4476
+ const result = {
4477
+ value: escape(code),
4478
+ illegal: false,
4479
+ relevance: 0,
4480
+ _top: PLAINTEXT_LANGUAGE,
4481
+ _emitter: new options.__emitter(options)
4482
+ };
4483
+ result._emitter.addText(code);
4484
+ return result;
4485
+ }
4486
+ function highlightAuto(code, languageSubset) {
4487
+ languageSubset = languageSubset || options.languages || Object.keys(languages);
4488
+ const plaintext = justTextHighlightResult(code);
4489
+ const results = languageSubset.filter(getLanguage).filter(autoDetection).map(
4490
+ (name) => _highlight(name, code, false)
4491
+ );
4492
+ results.unshift(plaintext);
4493
+ const sorted = results.sort((a, b) => {
4494
+ if (a.relevance !== b.relevance) return b.relevance - a.relevance;
4495
+ if (a.language && b.language) {
4496
+ if (getLanguage(a.language).supersetOf === b.language) {
4497
+ return 1;
4498
+ } else if (getLanguage(b.language).supersetOf === a.language) {
4499
+ return -1;
4500
+ }
4501
+ }
4502
+ return 0;
4503
+ });
4504
+ const [best, secondBest] = sorted;
4505
+ const result = best;
4506
+ result.secondBest = secondBest;
4507
+ return result;
4508
+ }
4509
+ function updateClassName(element, currentLang, resultLang) {
4510
+ const language = currentLang && aliases[currentLang] || resultLang;
4511
+ element.classList.add("hljs");
4512
+ element.classList.add(`language-${language}`);
4513
+ }
4514
+ function highlightElement(element) {
4515
+ let node = null;
4516
+ const language = blockLanguage(element);
4517
+ if (shouldNotHighlight(language)) return;
4518
+ fire(
4519
+ "before:highlightElement",
4520
+ { el: element, language }
4521
+ );
4522
+ if (element.dataset.highlighted) {
4523
+ console.log("Element previously highlighted. To highlight again, first unset `dataset.highlighted`.", element);
4524
+ return;
4525
+ }
4526
+ if (element.children.length > 0) {
4527
+ if (!options.ignoreUnescapedHTML) {
4528
+ console.warn("One of your code blocks includes unescaped HTML. This is a potentially serious security risk.");
4529
+ console.warn("https://github.com/highlightjs/highlight.js/wiki/security");
4530
+ console.warn("The element with unescaped HTML:");
4531
+ console.warn(element);
4532
+ }
4533
+ if (options.throwUnescapedHTML) {
4534
+ const err = new HTMLInjectionError(
4535
+ "One of your code blocks includes unescaped HTML.",
4536
+ element.innerHTML
4537
+ );
4538
+ throw err;
4539
+ }
4540
+ }
4541
+ node = element;
4542
+ const text = node.textContent;
4543
+ const result = language ? highlight2(text, { language, ignoreIllegals: true }) : highlightAuto(text);
4544
+ element.innerHTML = result.value;
4545
+ element.dataset.highlighted = "yes";
4546
+ updateClassName(element, language, result.language);
4547
+ element.result = {
4548
+ language: result.language,
4549
+ // TODO: remove with version 11.0
4550
+ re: result.relevance,
4551
+ relevance: result.relevance
4552
+ };
4553
+ if (result.secondBest) {
4554
+ element.secondBest = {
4555
+ language: result.secondBest.language,
4556
+ relevance: result.secondBest.relevance
4557
+ };
4558
+ }
4559
+ fire("after:highlightElement", { el: element, result, text });
4560
+ }
4561
+ function configure(userOptions) {
4562
+ options = inherit(options, userOptions);
4563
+ }
4564
+ const initHighlighting = () => {
4565
+ highlightAll();
4566
+ deprecated("10.6.0", "initHighlighting() deprecated. Use highlightAll() now.");
4567
+ };
4568
+ function initHighlightingOnLoad() {
4569
+ highlightAll();
4570
+ deprecated("10.6.0", "initHighlightingOnLoad() deprecated. Use highlightAll() now.");
4571
+ }
4572
+ let wantsHighlight = false;
4573
+ function highlightAll() {
4574
+ if (document.readyState === "loading") {
4575
+ wantsHighlight = true;
4576
+ return;
4577
+ }
4578
+ const blocks = document.querySelectorAll(options.cssSelector);
4579
+ blocks.forEach(highlightElement);
4580
+ }
4581
+ function boot() {
4582
+ if (wantsHighlight) highlightAll();
4583
+ }
4584
+ if (typeof window !== "undefined" && window.addEventListener) {
4585
+ window.addEventListener("DOMContentLoaded", boot, false);
4586
+ }
4587
+ function registerLanguage(languageName, languageDefinition) {
4588
+ let lang = null;
4589
+ try {
4590
+ lang = languageDefinition(hljs);
4591
+ } catch (error$1) {
4592
+ error("Language definition for '{}' could not be registered.".replace("{}", languageName));
4593
+ if (!SAFE_MODE) {
4594
+ throw error$1;
4595
+ } else {
4596
+ error(error$1);
4597
+ }
4598
+ lang = PLAINTEXT_LANGUAGE;
4599
+ }
4600
+ if (!lang.name) lang.name = languageName;
4601
+ languages[languageName] = lang;
4602
+ lang.rawDefinition = languageDefinition.bind(null, hljs);
4603
+ if (lang.aliases) {
4604
+ registerAliases(lang.aliases, { languageName });
4605
+ }
4606
+ }
4607
+ function unregisterLanguage(languageName) {
4608
+ delete languages[languageName];
4609
+ for (const alias of Object.keys(aliases)) {
4610
+ if (aliases[alias] === languageName) {
4611
+ delete aliases[alias];
4612
+ }
4613
+ }
4614
+ }
4615
+ function listLanguages() {
4616
+ return Object.keys(languages);
4617
+ }
4618
+ function getLanguage(name) {
4619
+ name = (name || "").toLowerCase();
4620
+ return languages[name] || languages[aliases[name]];
4621
+ }
4622
+ function registerAliases(aliasList, { languageName }) {
4623
+ if (typeof aliasList === "string") {
4624
+ aliasList = [aliasList];
4625
+ }
4626
+ aliasList.forEach((alias) => {
4627
+ aliases[alias.toLowerCase()] = languageName;
4628
+ });
4629
+ }
4630
+ function autoDetection(name) {
4631
+ const lang = getLanguage(name);
4632
+ return lang && !lang.disableAutodetect;
4633
+ }
4634
+ function upgradePluginAPI(plugin) {
4635
+ if (plugin["before:highlightBlock"] && !plugin["before:highlightElement"]) {
4636
+ plugin["before:highlightElement"] = (data) => {
4637
+ plugin["before:highlightBlock"](
4638
+ Object.assign({ block: data.el }, data)
4639
+ );
4640
+ };
4641
+ }
4642
+ if (plugin["after:highlightBlock"] && !plugin["after:highlightElement"]) {
4643
+ plugin["after:highlightElement"] = (data) => {
4644
+ plugin["after:highlightBlock"](
4645
+ Object.assign({ block: data.el }, data)
4646
+ );
4647
+ };
4648
+ }
4649
+ }
4650
+ function addPlugin(plugin) {
4651
+ upgradePluginAPI(plugin);
4652
+ plugins.push(plugin);
4653
+ }
4654
+ function removePlugin(plugin) {
4655
+ const index = plugins.indexOf(plugin);
4656
+ if (index !== -1) {
4657
+ plugins.splice(index, 1);
4658
+ }
4659
+ }
4660
+ function fire(event, args) {
4661
+ const cb = event;
4662
+ plugins.forEach(function(plugin) {
4663
+ if (plugin[cb]) {
4664
+ plugin[cb](args);
4665
+ }
4666
+ });
4667
+ }
4668
+ function deprecateHighlightBlock(el) {
4669
+ deprecated("10.7.0", "highlightBlock will be removed entirely in v12.0");
4670
+ deprecated("10.7.0", "Please use highlightElement now.");
4671
+ return highlightElement(el);
4672
+ }
4673
+ Object.assign(hljs, {
4674
+ highlight: highlight2,
4675
+ highlightAuto,
4676
+ highlightAll,
4677
+ highlightElement,
4678
+ // TODO: Remove with v12 API
4679
+ highlightBlock: deprecateHighlightBlock,
4680
+ configure,
4681
+ initHighlighting,
4682
+ initHighlightingOnLoad,
4683
+ registerLanguage,
4684
+ unregisterLanguage,
4685
+ listLanguages,
4686
+ getLanguage,
4687
+ registerAliases,
4688
+ autoDetection,
4689
+ inherit,
4690
+ addPlugin,
4691
+ removePlugin
4692
+ });
4693
+ hljs.debugMode = function() {
4694
+ SAFE_MODE = false;
4695
+ };
4696
+ hljs.safeMode = function() {
4697
+ SAFE_MODE = true;
4698
+ };
4699
+ hljs.versionString = version;
4700
+ hljs.regex = {
4701
+ concat,
4702
+ lookahead,
4703
+ either,
4704
+ optional,
4705
+ anyNumberOfTimes
4706
+ };
4707
+ for (const key in MODES) {
4708
+ if (typeof MODES[key] === "object") {
4709
+ deepFreeze(MODES[key]);
4710
+ }
4711
+ }
4712
+ Object.assign(hljs, MODES);
4713
+ return hljs;
4714
+ };
4715
+ var highlight = HLJS({});
4716
+ highlight.newInstance = () => HLJS({});
4717
+ var core = highlight;
4718
+ highlight.HighlightJS = highlight;
4719
+ highlight.default = highlight;
4720
+ var HighlightJS = /* @__PURE__ */ getDefaultExportFromCjs(core);
4721
+ function parseNodes(nodes, className = []) {
4722
+ return nodes.map((node) => {
4723
+ const classes = [...className, ...node.properties ? node.properties.className : []];
4724
+ if (node.children) {
4725
+ return parseNodes(node.children, classes);
4726
+ }
4727
+ return {
4728
+ text: node.value,
4729
+ classes
4730
+ };
4731
+ }).flat();
4732
+ }
4733
+ function getHighlightNodes(result) {
4734
+ return result.value || result.children || [];
4735
+ }
4736
+ function registered(aliasOrLanguage) {
4737
+ return Boolean(HighlightJS.getLanguage(aliasOrLanguage));
4738
+ }
4739
+ function getDecorations({ doc, name, lowlight: lowlight2, defaultLanguage }) {
4740
+ const decorations = [];
4741
+ findChildren(doc, (node) => node.type.name === name).forEach((block) => {
4742
+ var _a;
4743
+ let from = block.pos + 1;
4744
+ const language = block.node.attrs.language || defaultLanguage;
4745
+ const languages = lowlight2.listLanguages();
4746
+ const nodes = language && (languages.includes(language) || registered(language) || ((_a = lowlight2.registered) === null || _a === void 0 ? void 0 : _a.call(lowlight2, language))) ? getHighlightNodes(lowlight2.highlight(language, block.node.textContent)) : getHighlightNodes(lowlight2.highlightAuto(block.node.textContent));
4747
+ parseNodes(nodes).forEach((node) => {
4748
+ const to = from + node.text.length;
4749
+ if (node.classes.length) {
4750
+ const decoration = Decoration2.inline(from, to, {
4751
+ class: node.classes.join(" ")
4752
+ });
4753
+ decorations.push(decoration);
4754
+ }
4755
+ from = to;
4756
+ });
4757
+ });
4758
+ return DecorationSet2.create(doc, decorations);
4759
+ }
4760
+ function isFunction(param) {
4761
+ return typeof param === "function";
4762
+ }
4763
+ function LowlightPlugin({ name, lowlight: lowlight2, defaultLanguage }) {
4764
+ if (!["highlight", "highlightAuto", "listLanguages"].every((api) => isFunction(lowlight2[api]))) {
4765
+ throw Error("You should provide an instance of lowlight to use the code-block-lowlight extension");
4766
+ }
4767
+ const lowlightPlugin = new Plugin4({
4768
+ key: new PluginKey4("lowlight"),
4769
+ state: {
4770
+ init: (_, { doc }) => getDecorations({
4771
+ doc,
4772
+ name,
4773
+ lowlight: lowlight2,
4774
+ defaultLanguage
4775
+ }),
4776
+ apply: (transaction, decorationSet, oldState, newState) => {
4777
+ const oldNodeName = oldState.selection.$head.parent.type.name;
4778
+ const newNodeName = newState.selection.$head.parent.type.name;
4779
+ const oldNodes = findChildren(oldState.doc, (node) => node.type.name === name);
4780
+ const newNodes = findChildren(newState.doc, (node) => node.type.name === name);
4781
+ if (transaction.docChanged && ([oldNodeName, newNodeName].includes(name) || newNodes.length !== oldNodes.length || transaction.steps.some((step) => {
4782
+ return (
4783
+ // @ts-ignore
4784
+ step.from !== void 0 && step.to !== void 0 && oldNodes.some((node) => {
4785
+ return (
4786
+ // @ts-ignore
4787
+ node.pos >= step.from && node.pos + node.node.nodeSize <= step.to
4788
+ );
4789
+ })
4790
+ );
4791
+ }))) {
4792
+ return getDecorations({
4793
+ doc: transaction.doc,
4794
+ name,
4795
+ lowlight: lowlight2,
4796
+ defaultLanguage
4797
+ });
4798
+ }
4799
+ return decorationSet.map(transaction.mapping, transaction.doc);
4800
+ }
4801
+ },
4802
+ props: {
4803
+ decorations(state) {
4804
+ return lowlightPlugin.getState(state);
4805
+ }
4806
+ }
4807
+ });
4808
+ return lowlightPlugin;
4809
+ }
4810
+ var CodeBlockLowlight = CodeBlock.extend({
4811
+ addOptions() {
4812
+ var _a;
4813
+ return {
4814
+ ...(_a = this.parent) === null || _a === void 0 ? void 0 : _a.call(this),
4815
+ lowlight: {},
4816
+ languageClassPrefix: "language-",
4817
+ exitOnTripleEnter: true,
4818
+ exitOnArrowDown: true,
4819
+ defaultLanguage: null,
4820
+ HTMLAttributes: {}
4821
+ };
4822
+ },
4823
+ addProseMirrorPlugins() {
4824
+ var _a;
4825
+ return [
4826
+ ...((_a = this.parent) === null || _a === void 0 ? void 0 : _a.call(this)) || [],
4827
+ LowlightPlugin({
4828
+ name: this.name,
4829
+ lowlight: this.options.lowlight,
4830
+ defaultLanguage: this.options.defaultLanguage
4831
+ })
4832
+ ];
4833
+ }
4834
+ });
4835
+
4836
+ // src/extensions/preset.ts
4837
+ import { common, createLowlight } from "lowlight";
4838
+
3175
4839
  // ../../node_modules/.pnpm/@tiptap+extension-table-row@2.27.2_@tiptap+core@2.27.2_@tiptap+pm@2.27.2_/node_modules/@tiptap/extension-table-row/dist/index.js
3176
4840
  import { Node as Node15, mergeAttributes as mergeAttributes20 } from "@tiptap/core";
3177
4841
  var TableRow = Node15.create({
@@ -3641,14 +5305,6 @@ var TableHeader = Node18.create({
3641
5305
  });
3642
5306
 
3643
5307
  // src/extensions/table-formatting.ts
3644
- var TABLE_CELL_BACKGROUND_PRESETS = {
3645
- none: null,
3646
- gray: "#f3f4f6",
3647
- yellow: "#fef3c7",
3648
- blue: "#dbeafe",
3649
- green: "#dcfce7",
3650
- red: "#fee2e2"
3651
- };
3652
5308
  var LoomaTable = Table.configure({
3653
5309
  resizable: true,
3654
5310
  lastColumnResizable: false
@@ -3758,6 +5414,16 @@ function setActiveTableCellBackground(editor, backgroundColor) {
3758
5414
  }
3759
5415
 
3760
5416
  // src/extensions/preset.ts
5417
+ var lowlight = createLowlight(common);
5418
+ var LoomaTableKit = Extension7.create({
5419
+ name: "loomaTableKit",
5420
+ addExtensions() {
5421
+ return [LoomaTable, TableRow, LoomaTableHeader, LoomaTableCell];
5422
+ }
5423
+ });
5424
+ function getLoomaTableExtensions() {
5425
+ return [LoomaTable, TableRow, LoomaTableHeader, LoomaTableCell];
5426
+ }
3761
5427
  function getDefaultEditorExtensions(options = {}) {
3762
5428
  const {
3763
5429
  placeholder = "Type \u201C/\u201D for commands, or start writing\u2026",
@@ -3791,22 +5457,103 @@ function getDefaultEditorExtensions(options = {}) {
3791
5457
  Image.configure({ inline: imageInline }),
3792
5458
  Highlight.configure({ multicolor: false }),
3793
5459
  Code,
3794
- CodeBlock,
5460
+ CodeBlockLowlight.configure({ lowlight }),
3795
5461
  Typography,
3796
5462
  Placeholder.configure({
3797
5463
  placeholder: ({ node }) => node.type.name === "paragraph" ? placeholder : "",
3798
5464
  emptyNodeClass: "is-editor-empty"
3799
5465
  }),
3800
- LoomaTable,
3801
- TableRow,
3802
- LoomaTableHeader,
3803
- LoomaTableCell,
5466
+ LoomaTableKit,
3804
5467
  LoomaListBehavior
3805
5468
  ];
3806
5469
  }
3807
5470
 
3808
5471
  // src/extensions/table-commands.ts
5472
+ import { TextSelection as TextSelection4 } from "@tiptap/pm/state";
3809
5473
  import { TableMap } from "@tiptap/pm/tables";
5474
+ var NO_TABLE_CAPABILITIES = {
5475
+ canAddRowBefore: false,
5476
+ canAddRowAfter: false,
5477
+ canAddColumnBefore: false,
5478
+ canAddColumnAfter: false,
5479
+ canDeleteRow: false,
5480
+ canDeleteColumn: false,
5481
+ canDeleteTable: false,
5482
+ canMergeCells: false,
5483
+ canSplitCell: false
5484
+ };
5485
+ function shouldShowTextFormattingToolbar(editor, from = editor.state.selection.from, to = editor.state.selection.to) {
5486
+ return editor.isEditable && editor.state.selection instanceof TextSelection4 && from !== to;
5487
+ }
5488
+ function getActiveTableUiState(editor) {
5489
+ const active = editor.isActive("table");
5490
+ if (!active) {
5491
+ return {
5492
+ active: false,
5493
+ showToolbar: false,
5494
+ cellAlignment: "left",
5495
+ cellBackground: null,
5496
+ capabilities: { ...NO_TABLE_CAPABILITIES }
5497
+ };
5498
+ }
5499
+ return {
5500
+ active: true,
5501
+ showToolbar: true,
5502
+ cellAlignment: getActiveTableCellAlignment(editor),
5503
+ cellBackground: getActiveTableCellBackground(editor),
5504
+ capabilities: {
5505
+ canAddRowBefore: editor.can().addRowBefore(),
5506
+ canAddRowAfter: editor.can().addRowAfter(),
5507
+ canAddColumnBefore: editor.can().addColumnBefore(),
5508
+ canAddColumnAfter: editor.can().addColumnAfter(),
5509
+ canDeleteRow: editor.can().deleteRow(),
5510
+ canDeleteColumn: editor.can().deleteColumn(),
5511
+ canDeleteTable: editor.can().deleteTable(),
5512
+ canMergeCells: editor.can().mergeCells(),
5513
+ canSplitCell: editor.can().splitCell()
5514
+ }
5515
+ };
5516
+ }
5517
+ function handleTableAction(editor, detail) {
5518
+ switch (detail.action) {
5519
+ case "align-left":
5520
+ return setActiveTableCellAlignment(editor, "left");
5521
+ case "align-center":
5522
+ return setActiveTableCellAlignment(editor, "center");
5523
+ case "align-right":
5524
+ return setActiveTableCellAlignment(editor, "right");
5525
+ case "background-none":
5526
+ return setActiveTableCellBackground(editor, TABLE_CELL_BACKGROUND_PRESETS.none);
5527
+ case "background-gray":
5528
+ return setActiveTableCellBackground(editor, TABLE_CELL_BACKGROUND_PRESETS.gray);
5529
+ case "background-yellow":
5530
+ return setActiveTableCellBackground(editor, TABLE_CELL_BACKGROUND_PRESETS.yellow);
5531
+ case "background-blue":
5532
+ return setActiveTableCellBackground(editor, TABLE_CELL_BACKGROUND_PRESETS.blue);
5533
+ case "background-green":
5534
+ return setActiveTableCellBackground(editor, TABLE_CELL_BACKGROUND_PRESETS.green);
5535
+ case "background-red":
5536
+ return setActiveTableCellBackground(editor, TABLE_CELL_BACKGROUND_PRESETS.red);
5537
+ case "add-row-before":
5538
+ return editor.chain().focus().addRowBefore().run();
5539
+ case "add-row-after":
5540
+ return editor.chain().focus().addRowAfter().run();
5541
+ case "add-column-before":
5542
+ return editor.chain().focus().addColumnBefore().run();
5543
+ case "add-column-after":
5544
+ return editor.chain().focus().addColumnAfter().run();
5545
+ case "delete-row":
5546
+ return editor.chain().focus().deleteRow().run();
5547
+ case "delete-column":
5548
+ return editor.chain().focus().deleteColumn().run();
5549
+ case "delete-table":
5550
+ return editor.chain().focus().deleteTable().run();
5551
+ case "merge-cells":
5552
+ return editor.chain().focus().mergeCells().run();
5553
+ case "split-cell":
5554
+ return editor.chain().focus().splitCell().run();
5555
+ }
5556
+ }
3810
5557
  function arrayEquals(left, right) {
3811
5558
  if (!left || left.length !== right.length) {
3812
5559
  return false;
@@ -3968,7 +5715,7 @@ function handleTableOverlayAction(editor, detail) {
3968
5715
  break;
3969
5716
  }
3970
5717
  case "add-row-after": {
3971
- const rowIndex = Math.min(boundaryIndex, rows - 1);
5718
+ const rowIndex = Math.min(boundaryIndex - 1, rows - 1);
3972
5719
  if (rowIndex < 0) return false;
3973
5720
  cellPos = getTextPositionInCell(tablePos, table, rowIndex, 0);
3974
5721
  command = () => editor.chain().focus().setTextSelection(cellPos).addRowAfter().run();
@@ -3982,7 +5729,7 @@ function handleTableOverlayAction(editor, detail) {
3982
5729
  break;
3983
5730
  }
3984
5731
  case "add-column-after": {
3985
- const colIndex = Math.min(boundaryIndex, cols - 1);
5732
+ const colIndex = Math.min(boundaryIndex - 1, cols - 1);
3986
5733
  if (colIndex < 0) return false;
3987
5734
  cellPos = getTextPositionInCell(tablePos, table, 0, colIndex);
3988
5735
  command = () => editor.chain().focus().setTextSelection(cellPos).addColumnAfter().run();
@@ -3994,8 +5741,439 @@ function handleTableOverlayAction(editor, detail) {
3994
5741
  return command();
3995
5742
  }
3996
5743
 
5744
+ // src/extensions/slash-command.ts
5745
+ import { Extension as Extension8 } from "@tiptap/core";
5746
+
5747
+ // ../../node_modules/.pnpm/@tiptap+suggestion@2.27.2_@tiptap+core@2.27.2_@tiptap+pm@2.27.2__@tiptap+pm@2.27.2/node_modules/@tiptap/suggestion/dist/index.js
5748
+ import { PluginKey as PluginKey5, Plugin as Plugin5 } from "@tiptap/pm/state";
5749
+ import { DecorationSet as DecorationSet3, Decoration as Decoration3 } from "@tiptap/pm/view";
5750
+ import { escapeForRegEx } from "@tiptap/core";
5751
+ function findSuggestionMatch(config) {
5752
+ var _a;
5753
+ const { char, allowSpaces: allowSpacesOption, allowToIncludeChar, allowedPrefixes, startOfLine, $position } = config;
5754
+ const allowSpaces = allowSpacesOption && !allowToIncludeChar;
5755
+ const escapedChar = escapeForRegEx(char);
5756
+ const suffix = new RegExp(`\\s${escapedChar}$`);
5757
+ const prefix = startOfLine ? "^" : "";
5758
+ const finalEscapedChar = allowToIncludeChar ? "" : escapedChar;
5759
+ const regexp = allowSpaces ? new RegExp(`${prefix}${escapedChar}.*?(?=\\s${finalEscapedChar}|$)`, "gm") : new RegExp(`${prefix}(?:^)?${escapedChar}[^\\s${finalEscapedChar}]*`, "gm");
5760
+ const text = ((_a = $position.nodeBefore) === null || _a === void 0 ? void 0 : _a.isText) && $position.nodeBefore.text;
5761
+ if (!text) {
5762
+ return null;
5763
+ }
5764
+ const textFrom = $position.pos - text.length;
5765
+ const match = Array.from(text.matchAll(regexp)).pop();
5766
+ if (!match || match.input === void 0 || match.index === void 0) {
5767
+ return null;
5768
+ }
5769
+ const matchPrefix = match.input.slice(Math.max(0, match.index - 1), match.index);
5770
+ const matchPrefixIsAllowed = new RegExp(`^[${allowedPrefixes === null || allowedPrefixes === void 0 ? void 0 : allowedPrefixes.join("")}\0]?$`).test(matchPrefix);
5771
+ if (allowedPrefixes !== null && !matchPrefixIsAllowed) {
5772
+ return null;
5773
+ }
5774
+ const from = textFrom + match.index;
5775
+ let to = from + match[0].length;
5776
+ if (allowSpaces && suffix.test(text.slice(to - 1, to + 1))) {
5777
+ match[0] += " ";
5778
+ to += 1;
5779
+ }
5780
+ if (from < $position.pos && to >= $position.pos) {
5781
+ return {
5782
+ range: {
5783
+ from,
5784
+ to
5785
+ },
5786
+ query: match[0].slice(char.length),
5787
+ text: match[0]
5788
+ };
5789
+ }
5790
+ return null;
5791
+ }
5792
+ var SuggestionPluginKey = new PluginKey5("suggestion");
5793
+ function Suggestion({ pluginKey = SuggestionPluginKey, editor, char = "@", allowSpaces = false, allowToIncludeChar = false, allowedPrefixes = [" "], startOfLine = false, decorationTag = "span", decorationClass = "suggestion", decorationContent = "", decorationEmptyClass = "is-empty", command = () => null, items = () => [], render = () => ({}), allow = () => true, findSuggestionMatch: findSuggestionMatch$1 = findSuggestionMatch }) {
5794
+ let props;
5795
+ const renderer = render === null || render === void 0 ? void 0 : render();
5796
+ const plugin = new Plugin5({
5797
+ key: pluginKey,
5798
+ view() {
5799
+ return {
5800
+ update: async (view, prevState) => {
5801
+ var _a, _b, _c, _d, _e, _f, _g;
5802
+ const prev = (_a = this.key) === null || _a === void 0 ? void 0 : _a.getState(prevState);
5803
+ const next = (_b = this.key) === null || _b === void 0 ? void 0 : _b.getState(view.state);
5804
+ const moved = prev.active && next.active && prev.range.from !== next.range.from;
5805
+ const started = !prev.active && next.active;
5806
+ const stopped = prev.active && !next.active;
5807
+ const changed = !started && !stopped && prev.query !== next.query;
5808
+ const handleStart = started || moved && changed;
5809
+ const handleChange = changed || moved;
5810
+ const handleExit = stopped || moved && changed;
5811
+ if (!handleStart && !handleChange && !handleExit) {
5812
+ return;
5813
+ }
5814
+ const state = handleExit && !handleStart ? prev : next;
5815
+ const decorationNode = view.dom.querySelector(`[data-decoration-id="${state.decorationId}"]`);
5816
+ props = {
5817
+ editor,
5818
+ range: state.range,
5819
+ query: state.query,
5820
+ text: state.text,
5821
+ items: [],
5822
+ command: (commandProps) => {
5823
+ return command({
5824
+ editor,
5825
+ range: state.range,
5826
+ props: commandProps
5827
+ });
5828
+ },
5829
+ decorationNode,
5830
+ // virtual node for popper.js or tippy.js
5831
+ // this can be used for building popups without a DOM node
5832
+ clientRect: decorationNode ? () => {
5833
+ var _a2;
5834
+ const { decorationId } = (_a2 = this.key) === null || _a2 === void 0 ? void 0 : _a2.getState(editor.state);
5835
+ const currentDecorationNode = view.dom.querySelector(`[data-decoration-id="${decorationId}"]`);
5836
+ return (currentDecorationNode === null || currentDecorationNode === void 0 ? void 0 : currentDecorationNode.getBoundingClientRect()) || null;
5837
+ } : null
5838
+ };
5839
+ if (handleStart) {
5840
+ (_c = renderer === null || renderer === void 0 ? void 0 : renderer.onBeforeStart) === null || _c === void 0 ? void 0 : _c.call(renderer, props);
5841
+ }
5842
+ if (handleChange) {
5843
+ (_d = renderer === null || renderer === void 0 ? void 0 : renderer.onBeforeUpdate) === null || _d === void 0 ? void 0 : _d.call(renderer, props);
5844
+ }
5845
+ if (handleChange || handleStart) {
5846
+ props.items = await items({
5847
+ editor,
5848
+ query: state.query
5849
+ });
5850
+ }
5851
+ if (handleExit) {
5852
+ (_e = renderer === null || renderer === void 0 ? void 0 : renderer.onExit) === null || _e === void 0 ? void 0 : _e.call(renderer, props);
5853
+ }
5854
+ if (handleChange) {
5855
+ (_f = renderer === null || renderer === void 0 ? void 0 : renderer.onUpdate) === null || _f === void 0 ? void 0 : _f.call(renderer, props);
5856
+ }
5857
+ if (handleStart) {
5858
+ (_g = renderer === null || renderer === void 0 ? void 0 : renderer.onStart) === null || _g === void 0 ? void 0 : _g.call(renderer, props);
5859
+ }
5860
+ },
5861
+ destroy: () => {
5862
+ var _a;
5863
+ if (!props) {
5864
+ return;
5865
+ }
5866
+ (_a = renderer === null || renderer === void 0 ? void 0 : renderer.onExit) === null || _a === void 0 ? void 0 : _a.call(renderer, props);
5867
+ }
5868
+ };
5869
+ },
5870
+ state: {
5871
+ // Initialize the plugin's internal state.
5872
+ init() {
5873
+ const state = {
5874
+ active: false,
5875
+ range: {
5876
+ from: 0,
5877
+ to: 0
5878
+ },
5879
+ query: null,
5880
+ text: null,
5881
+ composing: false
5882
+ };
5883
+ return state;
5884
+ },
5885
+ // Apply changes to the plugin state from a view transaction.
5886
+ apply(transaction, prev, _oldState, state) {
5887
+ const { isEditable } = editor;
5888
+ const { composing } = editor.view;
5889
+ const { selection } = transaction;
5890
+ const { empty, from } = selection;
5891
+ const next = { ...prev };
5892
+ next.composing = composing;
5893
+ if (isEditable && (empty || editor.view.composing)) {
5894
+ if ((from < prev.range.from || from > prev.range.to) && !composing && !prev.composing) {
5895
+ next.active = false;
5896
+ }
5897
+ const match = findSuggestionMatch$1({
5898
+ char,
5899
+ allowSpaces,
5900
+ allowToIncludeChar,
5901
+ allowedPrefixes,
5902
+ startOfLine,
5903
+ $position: selection.$from
5904
+ });
5905
+ const decorationId = `id_${Math.floor(Math.random() * 4294967295)}`;
5906
+ if (match && allow({
5907
+ editor,
5908
+ state,
5909
+ range: match.range,
5910
+ isActive: prev.active
5911
+ })) {
5912
+ next.active = true;
5913
+ next.decorationId = prev.decorationId ? prev.decorationId : decorationId;
5914
+ next.range = match.range;
5915
+ next.query = match.query;
5916
+ next.text = match.text;
5917
+ } else {
5918
+ next.active = false;
5919
+ }
5920
+ } else {
5921
+ next.active = false;
5922
+ }
5923
+ if (!next.active) {
5924
+ next.decorationId = null;
5925
+ next.range = { from: 0, to: 0 };
5926
+ next.query = null;
5927
+ next.text = null;
5928
+ }
5929
+ return next;
5930
+ }
5931
+ },
5932
+ props: {
5933
+ // Call the keydown hook if suggestion is active.
5934
+ handleKeyDown(view, event) {
5935
+ var _a;
5936
+ const { active, range } = plugin.getState(view.state);
5937
+ if (!active) {
5938
+ return false;
5939
+ }
5940
+ return ((_a = renderer === null || renderer === void 0 ? void 0 : renderer.onKeyDown) === null || _a === void 0 ? void 0 : _a.call(renderer, { view, event, range })) || false;
5941
+ },
5942
+ // Setup decorator on the currently active suggestion.
5943
+ decorations(state) {
5944
+ const { active, range, decorationId, query } = plugin.getState(state);
5945
+ if (!active) {
5946
+ return null;
5947
+ }
5948
+ const isEmpty = !(query === null || query === void 0 ? void 0 : query.length);
5949
+ const classNames = [decorationClass];
5950
+ if (isEmpty) {
5951
+ classNames.push(decorationEmptyClass);
5952
+ }
5953
+ return DecorationSet3.create(state.doc, [
5954
+ Decoration3.inline(range.from, range.to, {
5955
+ nodeName: decorationTag,
5956
+ class: classNames.join(" "),
5957
+ "data-decoration-id": decorationId,
5958
+ "data-decoration-content": decorationContent
5959
+ })
5960
+ ]);
5961
+ }
5962
+ }
5963
+ });
5964
+ return plugin;
5965
+ }
5966
+
5967
+ // src/extensions/slash-command.ts
5968
+ function getDefaultSlashCommands(onOpenImagePicker) {
5969
+ return [
5970
+ {
5971
+ title: "Text",
5972
+ description: "Plain paragraph",
5973
+ icon: "\xB6",
5974
+ keywords: ["text", "paragraph", "plain", "p"],
5975
+ command: ({ editor, range }) => {
5976
+ editor.chain().focus().deleteRange(range).setParagraph().run();
5977
+ }
5978
+ },
5979
+ ...[1, 2, 3].map((level) => ({
5980
+ title: `Heading ${level}`,
5981
+ description: level === 1 ? "Big section title" : level === 2 ? "Medium section title" : "Small section title",
5982
+ icon: `H${level}`,
5983
+ keywords: [`h${level}`, "heading", "title"],
5984
+ command: ({ editor, range }) => {
5985
+ editor.chain().focus().deleteRange(range).setHeading({ level }).run();
5986
+ }
5987
+ })),
5988
+ {
5989
+ title: "Bullet list",
5990
+ description: "Unordered list",
5991
+ icon: "\u2022",
5992
+ keywords: ["bullet", "list", "ul", "unordered"],
5993
+ command: ({ editor, range }) => {
5994
+ editor.chain().focus().deleteRange(range).toggleBulletList().run();
5995
+ }
5996
+ },
5997
+ {
5998
+ title: "Numbered list",
5999
+ description: "Ordered list",
6000
+ icon: "1.",
6001
+ keywords: ["numbered", "ordered", "list", "ol"],
6002
+ command: ({ editor, range }) => {
6003
+ editor.chain().focus().deleteRange(range).toggleOrderedList().run();
6004
+ }
6005
+ },
6006
+ {
6007
+ title: "Checklist",
6008
+ description: "Interactive to-do items",
6009
+ icon: "\u2611",
6010
+ keywords: ["check", "task", "todo", "checklist"],
6011
+ command: ({ editor, range }) => {
6012
+ editor.chain().focus().deleteRange(range).toggleTaskList().run();
6013
+ }
6014
+ },
6015
+ {
6016
+ title: "Blockquote",
6017
+ description: "Highlighted quote",
6018
+ icon: '"',
6019
+ keywords: ["quote", "blockquote", "callout"],
6020
+ command: ({ editor, range }) => {
6021
+ editor.chain().focus().deleteRange(range).toggleBlockquote().run();
6022
+ }
6023
+ },
6024
+ {
6025
+ title: "Inline code",
6026
+ description: "Monospace code span",
6027
+ icon: "`",
6028
+ keywords: ["code", "inline", "monospace"],
6029
+ command: ({ editor, range }) => {
6030
+ editor.chain().focus().deleteRange(range).toggleCode().run();
6031
+ }
6032
+ },
6033
+ {
6034
+ title: "Code block",
6035
+ description: "Formatted code block",
6036
+ icon: "<>",
6037
+ keywords: ["codeblock", "pre", "syntax", "snippet"],
6038
+ command: ({ editor, range }) => {
6039
+ editor.chain().focus().deleteRange(range).toggleCodeBlock().run();
6040
+ }
6041
+ },
6042
+ {
6043
+ title: "Table",
6044
+ description: "Insert a table",
6045
+ icon: "\u229E",
6046
+ keywords: ["table", "grid", "rows", "columns"],
6047
+ command: ({ editor, range }) => {
6048
+ insertTableAtRange(editor, range);
6049
+ }
6050
+ },
6051
+ {
6052
+ title: "Divider",
6053
+ description: "Horizontal rule",
6054
+ icon: "\u2014",
6055
+ keywords: ["divider", "hr", "rule", "line"],
6056
+ command: ({ editor, range }) => {
6057
+ editor.chain().focus().deleteRange(range).setHorizontalRule().run();
6058
+ }
6059
+ },
6060
+ {
6061
+ title: "Image",
6062
+ description: "Upload an image",
6063
+ icon: "\u25A7",
6064
+ keywords: ["image", "photo", "picture", "upload"],
6065
+ command: ({ editor, range }) => {
6066
+ editor.chain().focus().deleteRange(range).run();
6067
+ onOpenImagePicker?.();
6068
+ }
6069
+ }
6070
+ ];
6071
+ }
6072
+ var EMPTY_STATE = {
6073
+ active: false,
6074
+ items: [],
6075
+ selectedIndex: 0,
6076
+ query: "",
6077
+ rect: null,
6078
+ select: null
6079
+ };
6080
+ var LoomaSlashCommand = Extension8.create({
6081
+ name: "loomaSlashCommand",
6082
+ addOptions() {
6083
+ return {
6084
+ commands: getDefaultSlashCommands()
6085
+ };
6086
+ },
6087
+ addProseMirrorPlugins() {
6088
+ let selectedIndex = 0;
6089
+ let currentProps = null;
6090
+ const publish = (props) => {
6091
+ if (!props) {
6092
+ this.options.onStateChange?.({ ...EMPTY_STATE });
6093
+ return;
6094
+ }
6095
+ this.options.onStateChange?.({
6096
+ active: true,
6097
+ items: props.items,
6098
+ selectedIndex,
6099
+ query: props.query,
6100
+ rect: props.clientRect?.() ?? null,
6101
+ select: (index) => {
6102
+ const item = props.items[index];
6103
+ if (item) props.command(item);
6104
+ }
6105
+ });
6106
+ };
6107
+ return [
6108
+ Suggestion({
6109
+ editor: this.editor,
6110
+ char: "/",
6111
+ allowSpaces: false,
6112
+ startOfLine: false,
6113
+ items: ({ query }) => {
6114
+ const normalized = query.toLowerCase().trim();
6115
+ const commands = this.options.commands.length > 0 ? this.options.commands : getDefaultSlashCommands(this.options.onOpenImagePicker);
6116
+ if (!normalized) return commands;
6117
+ return commands.filter(
6118
+ (command) => command.title.toLowerCase().includes(normalized) || command.keywords.some((keyword) => keyword.includes(normalized))
6119
+ );
6120
+ },
6121
+ command: ({ editor, range, props }) => {
6122
+ props.command({ editor, range });
6123
+ },
6124
+ render: () => ({
6125
+ onStart: (props) => {
6126
+ currentProps = props;
6127
+ selectedIndex = 0;
6128
+ publish(props);
6129
+ },
6130
+ onUpdate: (props) => {
6131
+ currentProps = props;
6132
+ if (selectedIndex >= props.items.length) selectedIndex = 0;
6133
+ publish(props);
6134
+ },
6135
+ onKeyDown: ({ event }) => {
6136
+ if (!currentProps) return false;
6137
+ if (event.key === "ArrowDown") {
6138
+ selectedIndex = (selectedIndex + 1) % Math.max(1, currentProps.items.length);
6139
+ publish(currentProps);
6140
+ return true;
6141
+ }
6142
+ if (event.key === "ArrowUp") {
6143
+ selectedIndex = (selectedIndex - 1 + currentProps.items.length) % Math.max(1, currentProps.items.length);
6144
+ publish(currentProps);
6145
+ return true;
6146
+ }
6147
+ if (event.key === "Enter") {
6148
+ const item = currentProps.items[selectedIndex];
6149
+ if (item) currentProps.command(item);
6150
+ return true;
6151
+ }
6152
+ if (event.key === "Escape") {
6153
+ currentProps = null;
6154
+ publish(null);
6155
+ return true;
6156
+ }
6157
+ return false;
6158
+ },
6159
+ onExit: () => {
6160
+ currentProps = null;
6161
+ publish(null);
6162
+ }
6163
+ })
6164
+ })
6165
+ ];
6166
+ }
6167
+ });
6168
+ function createLoomaSlashCommandExtension(options = {}) {
6169
+ const onOpenImagePicker = options.onOpenImagePicker;
6170
+ return LoomaSlashCommand.configure({
6171
+ ...options,
6172
+ commands: options.commands ?? getDefaultSlashCommands(onOpenImagePicker)
6173
+ });
6174
+ }
6175
+
3997
6176
  export {
3998
- TABLE_CELL_BACKGROUND_PRESETS,
3999
6177
  LoomaTable,
4000
6178
  LoomaTableHeader,
4001
6179
  LoomaTableCell,
@@ -4003,8 +6181,16 @@ export {
4003
6181
  getActiveTableCellBackground,
4004
6182
  setActiveTableCellAlignment,
4005
6183
  setActiveTableCellBackground,
6184
+ LoomaTableKit,
6185
+ getLoomaTableExtensions,
4006
6186
  getDefaultEditorExtensions,
6187
+ shouldShowTextFormattingToolbar,
6188
+ getActiveTableUiState,
6189
+ handleTableAction,
4007
6190
  insertTableAtRange,
4008
6191
  normalizeActiveTableColumnWidths,
4009
- handleTableOverlayAction
6192
+ handleTableOverlayAction,
6193
+ getDefaultSlashCommands,
6194
+ LoomaSlashCommand,
6195
+ createLoomaSlashCommandExtension
4010
6196
  };