@ni/nimble-components 20.2.14 → 20.2.15

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.
Files changed (27) hide show
  1. package/dist/all-components-bundle.js +2276 -19
  2. package/dist/all-components-bundle.js.map +1 -1
  3. package/dist/all-components-bundle.min.js +2448 -2264
  4. package/dist/all-components-bundle.min.js.map +1 -1
  5. package/dist/esm/rich-text/editor/index.d.ts +9 -0
  6. package/dist/esm/rich-text/editor/index.js +48 -0
  7. package/dist/esm/rich-text/editor/index.js.map +1 -1
  8. package/dist/esm/rich-text/editor/styles.js +30 -1
  9. package/dist/esm/rich-text/editor/styles.js.map +1 -1
  10. package/dist/esm/rich-text/editor/testing/rich-text-editor.pageobject.d.ts +3 -0
  11. package/dist/esm/rich-text/editor/testing/rich-text-editor.pageobject.js +24 -5
  12. package/dist/esm/rich-text/editor/testing/rich-text-editor.pageobject.js.map +1 -1
  13. package/dist/esm/rich-text/models/markdown-parser.d.ts +2 -0
  14. package/dist/esm/rich-text/models/markdown-parser.js +45 -3
  15. package/dist/esm/rich-text/models/markdown-parser.js.map +1 -1
  16. package/dist/esm/rich-text/models/markdown-serializer.js +22 -1
  17. package/dist/esm/rich-text/models/markdown-serializer.js.map +1 -1
  18. package/dist/esm/rich-text/models/testing/markdown-parser-utils.d.ts +2 -0
  19. package/dist/esm/rich-text/models/testing/markdown-parser-utils.js +10 -0
  20. package/dist/esm/rich-text/models/testing/markdown-parser-utils.js.map +1 -1
  21. package/dist/esm/rich-text/viewer/styles.js +1 -10
  22. package/dist/esm/rich-text/viewer/styles.js.map +1 -1
  23. package/dist/esm/src/rich-text/editor/index.d.ts +9 -0
  24. package/dist/esm/src/rich-text/editor/testing/rich-text-editor.pageobject.d.ts +3 -0
  25. package/dist/esm/src/rich-text/models/markdown-parser.d.ts +2 -0
  26. package/dist/esm/src/rich-text/models/testing/markdown-parser-utils.d.ts +2 -0
  27. package/package.json +2 -1
@@ -16288,7 +16288,7 @@
16288
16288
 
16289
16289
  /**
16290
16290
  * Do not edit directly
16291
- * Generated on Thu, 14 Sep 2023 13:03:32 GMT
16291
+ * Generated on Thu, 14 Sep 2023 16:53:07 GMT
16292
16292
  */
16293
16293
 
16294
16294
  const Information100DarkUi = "#a46eff";
@@ -38362,7 +38362,7 @@
38362
38362
  }
38363
38363
  return result;
38364
38364
  };
38365
- function run$1(config) {
38365
+ function run$1$1(config) {
38366
38366
  var _a;
38367
38367
  const { editor, from, to, text, rules, plugin, } = config;
38368
38368
  const { view } = editor;
@@ -38447,7 +38447,7 @@
38447
38447
  },
38448
38448
  props: {
38449
38449
  handleTextInput(view, from, to, text) {
38450
- return run$1({
38450
+ return run$1$1({
38451
38451
  editor,
38452
38452
  from,
38453
38453
  to,
@@ -38461,7 +38461,7 @@
38461
38461
  setTimeout(() => {
38462
38462
  const { $cursor } = view.state.selection;
38463
38463
  if ($cursor) {
38464
- run$1({
38464
+ run$1$1({
38465
38465
  editor,
38466
38466
  from: $cursor.pos,
38467
38467
  to: $cursor.pos,
@@ -38482,7 +38482,7 @@
38482
38482
  }
38483
38483
  const { $cursor } = view.state.selection;
38484
38484
  if ($cursor) {
38485
- return run$1({
38485
+ return run$1$1({
38486
38486
  editor,
38487
38487
  from: $cursor.pos,
38488
38488
  to: $cursor.pos,
@@ -38532,7 +38532,7 @@
38532
38532
  return result;
38533
38533
  });
38534
38534
  };
38535
- function run(config) {
38535
+ function run$2(config) {
38536
38536
  const { editor, state, from, to, rule, } = config;
38537
38537
  const { commands, chain, can } = new CommandManager({
38538
38538
  editor,
@@ -38632,7 +38632,7 @@
38632
38632
  state,
38633
38633
  transaction: tr,
38634
38634
  });
38635
- const handler = run({
38635
+ const handler = run$2({
38636
38636
  editor,
38637
38637
  state: chainableState,
38638
38638
  from: Math.max(from - 1, 0),
@@ -39791,6 +39791,19 @@
39791
39791
  return { ...mark.attrs };
39792
39792
  }
39793
39793
 
39794
+ /**
39795
+ * Returns a new `Transform` based on all steps of the passed transactions.
39796
+ */
39797
+ function combineTransactionSteps(oldDoc, transactions) {
39798
+ const transform = new Transform$1(oldDoc);
39799
+ transactions.forEach(transaction => {
39800
+ transaction.steps.forEach(step => {
39801
+ transform.step(step);
39802
+ });
39803
+ });
39804
+ return transform;
39805
+ }
39806
+
39794
39807
  function defaultBlockAt(match) {
39795
39808
  for (let i = 0; i < match.edgeCount; i += 1) {
39796
39809
  const { type } = match.edge(i);
@@ -39801,6 +39814,31 @@
39801
39814
  return null;
39802
39815
  }
39803
39816
 
39817
+ /**
39818
+ * Same as `findChildren` but searches only within a `range`.
39819
+ */
39820
+ function findChildrenInRange(node, range, predicate) {
39821
+ const nodesWithPos = [];
39822
+ // if (range.from === range.to) {
39823
+ // const nodeAt = node.nodeAt(range.from)
39824
+ // if (nodeAt) {
39825
+ // nodesWithPos.push({
39826
+ // node: nodeAt,
39827
+ // pos: range.from,
39828
+ // })
39829
+ // }
39830
+ // }
39831
+ node.nodesBetween(range.from, range.to, (child, pos) => {
39832
+ if (predicate(child)) {
39833
+ nodesWithPos.push({
39834
+ node: child,
39835
+ pos,
39836
+ });
39837
+ }
39838
+ });
39839
+ return nodesWithPos;
39840
+ }
39841
+
39804
39842
  function findParentNodeClosestToPos($pos, predicate) {
39805
39843
  for (let i = $pos.depth; i > 0; i -= 1) {
39806
39844
  const node = $pos.node(i);
@@ -39860,6 +39898,82 @@
39860
39898
  return {};
39861
39899
  }
39862
39900
 
39901
+ /**
39902
+ * Removes duplicated values within an array.
39903
+ * Supports numbers, strings and objects.
39904
+ */
39905
+ function removeDuplicates(array, by = JSON.stringify) {
39906
+ const seen = {};
39907
+ return array.filter(item => {
39908
+ const key = by(item);
39909
+ return Object.prototype.hasOwnProperty.call(seen, key)
39910
+ ? false
39911
+ : (seen[key] = true);
39912
+ });
39913
+ }
39914
+
39915
+ /**
39916
+ * Removes duplicated ranges and ranges that are
39917
+ * fully captured by other ranges.
39918
+ */
39919
+ function simplifyChangedRanges(changes) {
39920
+ const uniqueChanges = removeDuplicates(changes);
39921
+ return uniqueChanges.length === 1
39922
+ ? uniqueChanges
39923
+ : uniqueChanges.filter((change, index) => {
39924
+ const rest = uniqueChanges.filter((_, i) => i !== index);
39925
+ return !rest.some(otherChange => {
39926
+ return change.oldRange.from >= otherChange.oldRange.from
39927
+ && change.oldRange.to <= otherChange.oldRange.to
39928
+ && change.newRange.from >= otherChange.newRange.from
39929
+ && change.newRange.to <= otherChange.newRange.to;
39930
+ });
39931
+ });
39932
+ }
39933
+ /**
39934
+ * Returns a list of changed ranges
39935
+ * based on the first and last state of all steps.
39936
+ */
39937
+ function getChangedRanges(transform) {
39938
+ const { mapping, steps } = transform;
39939
+ const changes = [];
39940
+ mapping.maps.forEach((stepMap, index) => {
39941
+ const ranges = [];
39942
+ // This accounts for step changes where no range was actually altered
39943
+ // e.g. when setting a mark, node attribute, etc.
39944
+ // @ts-ignore
39945
+ if (!stepMap.ranges.length) {
39946
+ const { from, to } = steps[index];
39947
+ if (from === undefined || to === undefined) {
39948
+ return;
39949
+ }
39950
+ ranges.push({ from, to });
39951
+ }
39952
+ else {
39953
+ stepMap.forEach((from, to) => {
39954
+ ranges.push({ from, to });
39955
+ });
39956
+ }
39957
+ ranges.forEach(({ from, to }) => {
39958
+ const newStart = mapping.slice(index).map(from, -1);
39959
+ const newEnd = mapping.slice(index).map(to);
39960
+ const oldStart = mapping.invert().map(newStart, -1);
39961
+ const oldEnd = mapping.invert().map(newEnd);
39962
+ changes.push({
39963
+ oldRange: {
39964
+ from: oldStart,
39965
+ to: oldEnd,
39966
+ },
39967
+ newRange: {
39968
+ from: newStart,
39969
+ to: newEnd,
39970
+ },
39971
+ });
39972
+ });
39973
+ });
39974
+ return simplifyChangedRanges(changes);
39975
+ }
39976
+
39863
39977
  function getMarksBetween(from, to, doc) {
39864
39978
  const marks = [];
39865
39979
  // get all inclusive marks on empty selection
@@ -42462,6 +42576,2021 @@ img.ProseMirror-separator {
42462
42576
  },
42463
42577
  });
42464
42578
 
42579
+ // THIS FILE IS AUTOMATICALLY GENERATED DO NOT EDIT DIRECTLY
42580
+ // See update-tlds.js for encoding/decoding format
42581
+ // https://data.iana.org/TLD/tlds-alpha-by-domain.txt
42582
+ const encodedTlds = 'aaa1rp3barth4b0ott3vie4c1le2ogado5udhabi7c0ademy5centure6ountant0s9o1tor4d0s1ult4e0g1ro2tna4f0l1rica5g0akhan5ency5i0g1rbus3force5tel5kdn3l0faromeo7ibaba4pay4lfinanz6state5y2sace3tom5m0azon4ericanexpress7family11x2fam3ica3sterdam8nalytics7droid5quan4z2o0l2partments8p0le4q0uarelle8r0ab1mco4chi3my2pa2t0e3s0da2ia2sociates9t0hleta5torney7u0ction5di0ble3o3spost5thor3o0s4vianca6w0s2x0a2z0ure5ba0by2idu3namex3narepublic11d1k2r0celona5laycard4s5efoot5gains6seball5ketball8uhaus5yern5b0c1t1va3cg1n2d1e0ats2uty4er2ntley5rlin4st0buy5t2f1g1h0arti5i0ble3d1ke2ng0o3o1z2j1lack0friday9ockbuster8g1omberg7ue3m0s1w2n0pparibas9o0ats3ehringer8fa2m1nd2o0k0ing5sch2tik2on4t1utique6x2r0adesco6idgestone9oadway5ker3ther5ussels7s1t1uild0ers6siness6y1zz3v1w1y1z0h3ca0b1fe2l0l1vinklein9m0era3p2non3petown5ital0one8r0avan4ds2e0er0s4s2sa1e1h1ino4t0ering5holic7ba1n1re2s2c1d1enter4o1rn3f0a1d2g1h0anel2nel4rity4se2t2eap3intai5ristmas6ome4urch5i0priani6rcle4sco3tadel4i0c2y0eats7k1l0aims4eaning6ick2nic1que6othing5ud3ub0med6m1n1o0ach3des3ffee4llege4ogne5m0cast4mbank4unity6pany2re3uter5sec4ndos3struction8ulting7tact3ractors9oking0channel11l1p2rsica5untry4pon0s4rses6pa2r0edit0card4union9icket5own3s1uise0s6u0isinella9v1w1x1y0mru3ou3z2dabur3d1nce3ta1e1ing3sun4y2clk3ds2e0al0er2s3gree4livery5l1oitte5ta3mocrat6ntal2ist5si0gn4v2hl2iamonds6et2gital5rect0ory7scount3ver5h2y2j1k1m1np2o0cs1tor4g1mains5t1wnload7rive4tv2ubai3nlop4pont4rban5vag2r2z2earth3t2c0o2deka3u0cation8e1g1mail3erck5nergy4gineer0ing9terprises10pson4quipment8r0icsson6ni3s0q1tate5t0isalat7u0rovision8s2vents5xchange6pert3osed4ress5traspace10fage2il1rwinds6th3mily4n0s2rm0ers5shion4t3edex3edback6rrari3ero6i0at2delity5o2lm2nal1nce1ial7re0stone6mdale6sh0ing5t0ness6j1k1lickr3ghts4r2orist4wers5y2m1o0o0d0network8tball6rd1ex2sale4um3undation8x2r0ee1senius7l1ogans4ntdoor4ier7tr2ujitsu5n0d2rniture7tbol5yi3ga0l0lery3o1up4me0s3p1rden4y2b0iz3d0n2e0a1nt0ing5orge5f1g0ee3h1i0ft0s3ves2ing5l0ass3e1obal2o4m0ail3bh2o1x2n1odaddy5ld0point6f2o0dyear5g0le4p1t1v2p1q1r0ainger5phics5tis4een3ipe3ocery4up4s1t1u0ardian6cci3ge2ide2tars5ru3w1y2hair2mburg5ngout5us3bo2dfc0bank7ealth0care8lp1sinki6re1mes5gtv3iphop4samitsu7tachi5v2k0t2m1n1ockey4ldings5iday5medepot5goods5s0ense7nda3rse3spital5t0ing5t0eles2s3mail5use3w2r1sbc3t1u0ghes5yatt3undai7ibm2cbc2e1u2d1e0ee3fm2kano4l1m0amat4db2mo0bilien9n0c1dustries8finiti5o2g1k1stitute6urance4e4t0ernational10uit4vestments10o1piranga7q1r0ish4s0maili5t0anbul7t0au2v3jaguar4va3cb2e0ep2tzt3welry6io2ll2m0p2nj2o0bs1urg4t1y2p0morgan6rs3uegos4niper7kaufen5ddi3e0rryhotels6logistics9properties14fh2g1h1i0a1ds2m1nder2le4tchen5wi3m1n1oeln3matsu5sher5p0mg2n2r0d1ed3uokgroup8w1y0oto4z2la0caixa5mborghini8er3ncaster5ia3d0rover6xess5salle5t0ino3robe5w0yer5b1c1ds2ease3clerc5frak4gal2o2xus4gbt3i0dl2fe0insurance9style7ghting6ke2lly3mited4o2ncoln4de2k2psy3ve1ing5k1lc1p2oan0s3cker3us3l1ndon4tte1o3ve3pl0financial11r1s1t0d0a3u0ndbeck6xe1ury5v1y2ma0cys3drid4if1son4keup4n0agement7go3p1rket0ing3s4riott5shalls7serati6ttel5ba2c0kinsey7d1e0d0ia3et2lbourne7me1orial6n0u2rckmsd7g1h1iami3crosoft7l1ni1t2t0subishi9k1l0b1s2m0a2n1o0bi0le4da2e1i1m1nash3ey2ster5rmon3tgage6scow4to0rcycles9v0ie4p1q1r1s0d2t0n1r2u0seum3ic3tual5v1w1x1y1z2na0b1goya4me2tura4vy3ba2c1e0c1t0bank4flix4work5ustar5w0s2xt0direct7us4f0l2g0o2hk2i0co2ke1on3nja3ssan1y5l1o0kia3rthwesternmutual14on4w0ruz3tv4p1r0a1w2tt2u1yc2z2obi1server7ffice5kinawa6layan0group9dnavy5lo3m0ega4ne1g1l0ine5oo2pen3racle3nge4g0anic5igins6saka4tsuka4t2vh3pa0ge2nasonic7ris2s1tners4s1y3ssagens7y2ccw3e0t2f0izer5g1h0armacy6d1ilips5one2to0graphy6s4ysio5ics1tet2ures6d1n0g1k2oneer5zza4k1l0ace2y0station9umbing5s3m1n0c2ohl2ker3litie5rn2st3r0america6xi3ess3ime3o0d0uctions8f1gressive8mo2perties3y5tection8u0dential9s1t1ub2w0c2y2qa1pon3uebec3st5racing4dio4e0ad1lestate6tor2y4cipes5d0stone5umbrella9hab3ise0n3t2liance6n0t0als5pair3ort3ublican8st0aurant8view0s5xroth6ich0ardli6oh3l1o1p2o0cher3ks3deo3gers4om3s0vp3u0gby3hr2n2w0e2yukyu6sa0arland6fe0ty4kura4le1on3msclub4ung5ndvik0coromant12ofi4p1rl2s1ve2xo3b0i1s2c0a1b1haeffler7midt4olarships8ol3ule3warz5ience5ot3d1e0arch3t2cure1ity6ek2lect4ner3rvices6ven3w1x0y3fr2g1h0angrila6rp2w2ell3ia1ksha5oes2p0ping5uji3w0time7i0lk2na1gles5te3j1k0i0n2y0pe4l0ing4m0art3ile4n0cf3o0ccer3ial4ftbank4ware6hu2lar2utions7ng1y2y2pa0ce3ort2t3r0l2s1t0ada2ples4r1tebank4farm7c0group6ockholm6rage3e3ream4udio2y3yle4u0cks3pplies3y2ort5rf1gery5zuki5v1watch4iss4x1y0dney4stems6z2tab1ipei4lk2obao4rget4tamotors6r2too4x0i3c0i2d0k2eam2ch0nology8l1masek5nnis4va3f1g1h0d1eater2re6iaa2ckets5enda4ffany5ps2res2ol4j0maxx4x2k0maxx5l1m0all4n1o0day3kyo3ols3p1ray3shiba5tal3urs3wn2yota3s3r0ade1ing4ining5vel0channel7ers0insurance16ust3v2t1ube2i1nes3shu4v0s2w1z2ua1bank3s2g1k1nicom3versity8o2ol2ps2s1y1z2va0cations7na1guard7c1e0gas3ntures6risign5mögensberater2ung14sicherung10t2g1i0ajes4deo3g1king4llas4n1p1rgin4sa1ion4va1o3laanderen9n1odka3lkswagen7vo3te1ing3o2yage5u0elos6wales2mart4ter4ng0gou5tch0es6eather0channel12bcam3er2site5d0ding5ibo2r3f1hoswho6ien2ki2lliamhill9n0dows4e1ners6me2olterskluwer11odside6rk0s2ld3w2s1tc1f3xbox3erox4finity6ihuan4n2xx2yz3yachts4hoo3maxun5ndex5e1odobashi7ga2kohama6u0tube6t1un3za0ppos4ra3ero3ip2m1one3uerich6w2';
42583
+ // Internationalized domain names containing non-ASCII
42584
+ const encodedUtlds = 'ελ1υ2бг1ел3дети4ею2католик6ом3мкд2он1сква6онлайн5рг3рус2ф2сайт3рб3укр3қаз3հայ3ישראל5קום3ابوظبي5تصالات6رامكو5لاردن4بحرين5جزائر5سعودية6عليان5مغرب5مارات5یران5بارت2زار4يتك3ھارت5تونس4سودان3رية5شبكة4عراق2ب2مان4فلسطين6قطر3كاثوليك6وم3مصر2ليسيا5وريتانيا7قع4همراه5پاکستان7ڀارت4कॉम3नेट3भारत0म्3ोत5संगठन5বাংলা5ভারত2ৰত4ਭਾਰਤ4ભારત4ଭାରତ4இந்தியா6லங்கை6சிங்கப்பூர்11భారత్5ಭಾರತ4ഭാരതം5ලංකා4คอม3ไทย3ລາວ3გე2みんな3アマゾン4クラウド4グーグル4コム2ストア3セール3ファッション6ポイント4世界2中信1国1國1文网3亚马逊3企业2佛山2信息2健康2八卦2公司1益2台湾1灣2商城1店1标2嘉里0大酒店5在线2大拿2天主教3娱乐2家電2广东2微博2慈善2我爱你3手机2招聘2政务1府2新加坡2闻2时尚2書籍2机构2淡马锡3游戏2澳門2点看2移动2组织机构4网址1店1站1络2联通2谷歌2购物2通販2集团2電訊盈科4飞利浦3食品2餐厅2香格里拉3港2닷넷1컴2삼성2한국2';
42585
+
42586
+ /**
42587
+ * @template A
42588
+ * @template B
42589
+ * @param {A} target
42590
+ * @param {B} properties
42591
+ * @return {A & B}
42592
+ */
42593
+ const assign$2 = (target, properties) => {
42594
+ for (const key in properties) {
42595
+ target[key] = properties[key];
42596
+ }
42597
+ return target;
42598
+ };
42599
+
42600
+ /**
42601
+ * Finite State Machine generation utilities
42602
+ */
42603
+
42604
+ /**
42605
+ * @template T
42606
+ * @typedef {{ [group: string]: T[] }} Collections
42607
+ */
42608
+
42609
+ /**
42610
+ * @typedef {{ [group: string]: true }} Flags
42611
+ */
42612
+
42613
+ // Keys in scanner Collections instances
42614
+ const numeric = 'numeric';
42615
+ const ascii = 'ascii';
42616
+ const alpha$1 = 'alpha';
42617
+ const asciinumeric = 'asciinumeric';
42618
+ const alphanumeric$1 = 'alphanumeric';
42619
+ const domain = 'domain';
42620
+ const emoji = 'emoji';
42621
+ const scheme = 'scheme';
42622
+ const slashscheme = 'slashscheme';
42623
+ const whitespace = 'whitespace';
42624
+
42625
+ /**
42626
+ * @template T
42627
+ * @param {string} name
42628
+ * @param {Collections<T>} groups to register in
42629
+ * @returns {T[]} Current list of tokens in the given collection
42630
+ */
42631
+ function registerGroup(name, groups) {
42632
+ if (!(name in groups)) {
42633
+ groups[name] = [];
42634
+ }
42635
+ return groups[name];
42636
+ }
42637
+
42638
+ /**
42639
+ * @template T
42640
+ * @param {T} t token to add
42641
+ * @param {Collections<T>} groups
42642
+ * @param {Flags} flags
42643
+ */
42644
+ function addToGroups(t, flags, groups) {
42645
+ if (flags[numeric]) {
42646
+ flags[asciinumeric] = true;
42647
+ flags[alphanumeric$1] = true;
42648
+ }
42649
+ if (flags[ascii]) {
42650
+ flags[asciinumeric] = true;
42651
+ flags[alpha$1] = true;
42652
+ }
42653
+ if (flags[asciinumeric]) {
42654
+ flags[alphanumeric$1] = true;
42655
+ }
42656
+ if (flags[alpha$1]) {
42657
+ flags[alphanumeric$1] = true;
42658
+ }
42659
+ if (flags[alphanumeric$1]) {
42660
+ flags[domain] = true;
42661
+ }
42662
+ if (flags[emoji]) {
42663
+ flags[domain] = true;
42664
+ }
42665
+ for (const k in flags) {
42666
+ const group = registerGroup(k, groups);
42667
+ if (group.indexOf(t) < 0) {
42668
+ group.push(t);
42669
+ }
42670
+ }
42671
+ }
42672
+
42673
+ /**
42674
+ * @template T
42675
+ * @param {T} t token to check
42676
+ * @param {Collections<T>} groups
42677
+ * @returns {Flags} group flags that contain this token
42678
+ */
42679
+ function flagsForToken(t, groups) {
42680
+ const result = {};
42681
+ for (const c in groups) {
42682
+ if (groups[c].indexOf(t) >= 0) {
42683
+ result[c] = true;
42684
+ }
42685
+ }
42686
+ return result;
42687
+ }
42688
+
42689
+ /**
42690
+ * @template T
42691
+ * @typedef {null | T } Transition
42692
+ */
42693
+
42694
+ /**
42695
+ * Define a basic state machine state. j is the list of character transitions,
42696
+ * jr is the list of regex-match transitions, jd is the default state to
42697
+ * transition to t is the accepting token type, if any. If this is the terminal
42698
+ * state, then it does not emit a token.
42699
+ *
42700
+ * The template type T represents the type of the token this state accepts. This
42701
+ * should be a string (such as of the token exports in `text.js`) or a
42702
+ * MultiToken subclass (from `multi.js`)
42703
+ *
42704
+ * @template T
42705
+ * @param {T} [token] Token that this state emits
42706
+ */
42707
+ function State(token) {
42708
+ if (token === void 0) {
42709
+ token = null;
42710
+ }
42711
+ // this.n = null; // DEBUG: State name
42712
+ /** @type {{ [input: string]: State<T> }} j */
42713
+ this.j = {}; // IMPLEMENTATION 1
42714
+ // this.j = []; // IMPLEMENTATION 2
42715
+ /** @type {[RegExp, State<T>][]} jr */
42716
+ this.jr = [];
42717
+ /** @type {?State<T>} jd */
42718
+ this.jd = null;
42719
+ /** @type {?T} t */
42720
+ this.t = token;
42721
+ }
42722
+
42723
+ /**
42724
+ * Scanner token groups
42725
+ * @type Collections<string>
42726
+ */
42727
+ State.groups = {};
42728
+ State.prototype = {
42729
+ accepts() {
42730
+ return !!this.t;
42731
+ },
42732
+ /**
42733
+ * Follow an existing transition from the given input to the next state.
42734
+ * Does not mutate.
42735
+ * @param {string} input character or token type to transition on
42736
+ * @returns {?State<T>} the next state, if any
42737
+ */
42738
+ go(input) {
42739
+ const state = this;
42740
+ const nextState = state.j[input];
42741
+ if (nextState) {
42742
+ return nextState;
42743
+ }
42744
+ for (let i = 0; i < state.jr.length; i++) {
42745
+ const regex = state.jr[i][0];
42746
+ const nextState = state.jr[i][1]; // note: might be empty to prevent default jump
42747
+ if (nextState && regex.test(input)) {
42748
+ return nextState;
42749
+ }
42750
+ }
42751
+ // Nowhere left to jump! Return default, if any
42752
+ return state.jd;
42753
+ },
42754
+ /**
42755
+ * Whether the state has a transition for the given input. Set the second
42756
+ * argument to true to only look for an exact match (and not a default or
42757
+ * regular-expression-based transition)
42758
+ * @param {string} input
42759
+ * @param {boolean} exactOnly
42760
+ */
42761
+ has(input, exactOnly) {
42762
+ if (exactOnly === void 0) {
42763
+ exactOnly = false;
42764
+ }
42765
+ return exactOnly ? input in this.j : !!this.go(input);
42766
+ },
42767
+ /**
42768
+ * Short for "transition all"; create a transition from the array of items
42769
+ * in the given list to the same final resulting state.
42770
+ * @param {string | string[]} inputs Group of inputs to transition on
42771
+ * @param {Transition<T> | State<T>} [next] Transition options
42772
+ * @param {Flags} [flags] Collections flags to add token to
42773
+ * @param {Collections<T>} [groups] Master list of token groups
42774
+ */
42775
+ ta(inputs, next, flags, groups) {
42776
+ for (let i = 0; i < inputs.length; i++) {
42777
+ this.tt(inputs[i], next, flags, groups);
42778
+ }
42779
+ },
42780
+ /**
42781
+ * Short for "take regexp transition"; defines a transition for this state
42782
+ * when it encounters a token which matches the given regular expression
42783
+ * @param {RegExp} regexp Regular expression transition (populate first)
42784
+ * @param {T | State<T>} [next] Transition options
42785
+ * @param {Flags} [flags] Collections flags to add token to
42786
+ * @param {Collections<T>} [groups] Master list of token groups
42787
+ * @returns {State<T>} taken after the given input
42788
+ */
42789
+ tr(regexp, next, flags, groups) {
42790
+ groups = groups || State.groups;
42791
+ let nextState;
42792
+ if (next && next.j) {
42793
+ nextState = next;
42794
+ } else {
42795
+ // Token with maybe token groups
42796
+ nextState = new State(next);
42797
+ if (flags && groups) {
42798
+ addToGroups(next, flags, groups);
42799
+ }
42800
+ }
42801
+ this.jr.push([regexp, nextState]);
42802
+ return nextState;
42803
+ },
42804
+ /**
42805
+ * Short for "take transitions", will take as many sequential transitions as
42806
+ * the length of the given input and returns the
42807
+ * resulting final state.
42808
+ * @param {string | string[]} input
42809
+ * @param {T | State<T>} [next] Transition options
42810
+ * @param {Flags} [flags] Collections flags to add token to
42811
+ * @param {Collections<T>} [groups] Master list of token groups
42812
+ * @returns {State<T>} taken after the given input
42813
+ */
42814
+ ts(input, next, flags, groups) {
42815
+ let state = this;
42816
+ const len = input.length;
42817
+ if (!len) {
42818
+ return state;
42819
+ }
42820
+ for (let i = 0; i < len - 1; i++) {
42821
+ state = state.tt(input[i]);
42822
+ }
42823
+ return state.tt(input[len - 1], next, flags, groups);
42824
+ },
42825
+ /**
42826
+ * Short for "take transition", this is a method for building/working with
42827
+ * state machines.
42828
+ *
42829
+ * If a state already exists for the given input, returns it.
42830
+ *
42831
+ * If a token is specified, that state will emit that token when reached by
42832
+ * the linkify engine.
42833
+ *
42834
+ * If no state exists, it will be initialized with some default transitions
42835
+ * that resemble existing default transitions.
42836
+ *
42837
+ * If a state is given for the second argument, that state will be
42838
+ * transitioned to on the given input regardless of what that input
42839
+ * previously did.
42840
+ *
42841
+ * Specify a token group flags to define groups that this token belongs to.
42842
+ * The token will be added to corresponding entires in the given groups
42843
+ * object.
42844
+ *
42845
+ * @param {string} input character, token type to transition on
42846
+ * @param {T | State<T>} [next] Transition options
42847
+ * @param {Flags} [flags] Collections flags to add token to
42848
+ * @param {Collections<T>} [groups] Master list of groups
42849
+ * @returns {State<T>} taken after the given input
42850
+ */
42851
+ tt(input, next, flags, groups) {
42852
+ groups = groups || State.groups;
42853
+ const state = this;
42854
+
42855
+ // Check if existing state given, just a basic transition
42856
+ if (next && next.j) {
42857
+ state.j[input] = next;
42858
+ return next;
42859
+ }
42860
+ const t = next;
42861
+
42862
+ // Take the transition with the usual default mechanisms and use that as
42863
+ // a template for creating the next state
42864
+ let nextState,
42865
+ templateState = state.go(input);
42866
+ if (templateState) {
42867
+ nextState = new State();
42868
+ assign$2(nextState.j, templateState.j);
42869
+ nextState.jr.push.apply(nextState.jr, templateState.jr);
42870
+ nextState.jd = templateState.jd;
42871
+ nextState.t = templateState.t;
42872
+ } else {
42873
+ nextState = new State();
42874
+ }
42875
+ if (t) {
42876
+ // Ensure newly token is in the same groups as the old token
42877
+ if (groups) {
42878
+ if (nextState.t && typeof nextState.t === 'string') {
42879
+ const allFlags = assign$2(flagsForToken(nextState.t, groups), flags);
42880
+ addToGroups(t, allFlags, groups);
42881
+ } else if (flags) {
42882
+ addToGroups(t, flags, groups);
42883
+ }
42884
+ }
42885
+ nextState.t = t; // overwrite anything that was previously there
42886
+ }
42887
+
42888
+ state.j[input] = nextState;
42889
+ return nextState;
42890
+ }
42891
+ };
42892
+
42893
+ // Helper functions to improve minification (not exported outside linkifyjs module)
42894
+
42895
+ /**
42896
+ * @template T
42897
+ * @param {State<T>} state
42898
+ * @param {string | string[]} input
42899
+ * @param {Flags} [flags]
42900
+ * @param {Collections<T>} [groups]
42901
+ */
42902
+ const ta = (state, input, next, flags, groups) => state.ta(input, next, flags, groups);
42903
+
42904
+ /**
42905
+ * @template T
42906
+ * @param {State<T>} state
42907
+ * @param {RegExp} regexp
42908
+ * @param {T | State<T>} [next]
42909
+ * @param {Flags} [flags]
42910
+ * @param {Collections<T>} [groups]
42911
+ */
42912
+ const tr = (state, regexp, next, flags, groups) => state.tr(regexp, next, flags, groups);
42913
+
42914
+ /**
42915
+ * @template T
42916
+ * @param {State<T>} state
42917
+ * @param {string | string[]} input
42918
+ * @param {T | State<T>} [next]
42919
+ * @param {Flags} [flags]
42920
+ * @param {Collections<T>} [groups]
42921
+ */
42922
+ const ts = (state, input, next, flags, groups) => state.ts(input, next, flags, groups);
42923
+
42924
+ /**
42925
+ * @template T
42926
+ * @param {State<T>} state
42927
+ * @param {string} input
42928
+ * @param {T | State<T>} [next]
42929
+ * @param {Collections<T>} [groups]
42930
+ * @param {Flags} [flags]
42931
+ */
42932
+ const tt = (state, input, next, flags, groups) => state.tt(input, next, flags, groups);
42933
+
42934
+ /******************************************************************************
42935
+ Text Tokens
42936
+ Identifiers for token outputs from the regexp scanner
42937
+ ******************************************************************************/
42938
+
42939
+ // A valid web domain token
42940
+ const WORD = 'WORD'; // only contains a-z
42941
+ const UWORD = 'UWORD'; // contains letters other than a-z, used for IDN
42942
+
42943
+ // Special case of word
42944
+ const LOCALHOST = 'LOCALHOST';
42945
+
42946
+ // Valid top-level domain, special case of WORD (see tlds.js)
42947
+ const TLD = 'TLD';
42948
+
42949
+ // Valid IDN TLD, special case of UWORD (see tlds.js)
42950
+ const UTLD = 'UTLD';
42951
+
42952
+ // The scheme portion of a web URI protocol. Supported types include: `mailto`,
42953
+ // `file`, and user-defined custom protocols. Limited to schemes that contain
42954
+ // only letters
42955
+ const SCHEME = 'SCHEME';
42956
+
42957
+ // Similar to SCHEME, except makes distinction for schemes that must always be
42958
+ // followed by `://`, not just `:`. Supported types include `http`, `https`,
42959
+ // `ftp`, `ftps`
42960
+ const SLASH_SCHEME = 'SLASH_SCHEME';
42961
+
42962
+ // Any sequence of digits 0-9
42963
+ const NUM = 'NUM';
42964
+
42965
+ // Any number of consecutive whitespace characters that are not newline
42966
+ const WS = 'WS';
42967
+
42968
+ // New line (unix style)
42969
+ const NL$1 = 'NL'; // \n
42970
+
42971
+ // Opening/closing bracket classes
42972
+ const OPENBRACE = 'OPENBRACE'; // {
42973
+ const OPENBRACKET = 'OPENBRACKET'; // [
42974
+ const OPENANGLEBRACKET = 'OPENANGLEBRACKET'; // <
42975
+ const OPENPAREN = 'OPENPAREN'; // (
42976
+ const CLOSEBRACE = 'CLOSEBRACE'; // }
42977
+ const CLOSEBRACKET = 'CLOSEBRACKET'; // ]
42978
+ const CLOSEANGLEBRACKET = 'CLOSEANGLEBRACKET'; // >
42979
+ const CLOSEPAREN = 'CLOSEPAREN'; // )
42980
+
42981
+ // Various symbols
42982
+ const AMPERSAND = 'AMPERSAND'; // &
42983
+ const APOSTROPHE$1 = 'APOSTROPHE'; // '
42984
+ const ASTERISK = 'ASTERISK'; // *
42985
+ const AT = 'AT'; // @
42986
+ const BACKSLASH = 'BACKSLASH'; // \
42987
+ const BACKTICK = 'BACKTICK'; // `
42988
+ const CARET = 'CARET'; // ^
42989
+ const COLON = 'COLON'; // :
42990
+ const COMMA = 'COMMA'; // ,
42991
+ const DOLLAR = 'DOLLAR'; // $
42992
+ const DOT = 'DOT'; // .
42993
+ const EQUALS = 'EQUALS'; // =
42994
+ const EXCLAMATION = 'EXCLAMATION'; // !
42995
+ const HYPHEN = 'HYPHEN'; // -
42996
+ const PERCENT = 'PERCENT'; // %
42997
+ const PIPE = 'PIPE'; // |
42998
+ const PLUS = 'PLUS'; // +
42999
+ const POUND = 'POUND'; // #
43000
+ const QUERY = 'QUERY'; // ?
43001
+ const QUOTE = 'QUOTE'; // "
43002
+
43003
+ const SEMI = 'SEMI'; // ;
43004
+ const SLASH = 'SLASH'; // /
43005
+ const TILDE = 'TILDE'; // ~
43006
+ const UNDERSCORE = 'UNDERSCORE'; // _
43007
+
43008
+ // Emoji symbol
43009
+ const EMOJI$1 = 'EMOJI';
43010
+
43011
+ // Default token - anything that is not one of the above
43012
+ const SYM = 'SYM';
43013
+
43014
+ var tk = /*#__PURE__*/Object.freeze({
43015
+ __proto__: null,
43016
+ WORD: WORD,
43017
+ UWORD: UWORD,
43018
+ LOCALHOST: LOCALHOST,
43019
+ TLD: TLD,
43020
+ UTLD: UTLD,
43021
+ SCHEME: SCHEME,
43022
+ SLASH_SCHEME: SLASH_SCHEME,
43023
+ NUM: NUM,
43024
+ WS: WS,
43025
+ NL: NL$1,
43026
+ OPENBRACE: OPENBRACE,
43027
+ OPENBRACKET: OPENBRACKET,
43028
+ OPENANGLEBRACKET: OPENANGLEBRACKET,
43029
+ OPENPAREN: OPENPAREN,
43030
+ CLOSEBRACE: CLOSEBRACE,
43031
+ CLOSEBRACKET: CLOSEBRACKET,
43032
+ CLOSEANGLEBRACKET: CLOSEANGLEBRACKET,
43033
+ CLOSEPAREN: CLOSEPAREN,
43034
+ AMPERSAND: AMPERSAND,
43035
+ APOSTROPHE: APOSTROPHE$1,
43036
+ ASTERISK: ASTERISK,
43037
+ AT: AT,
43038
+ BACKSLASH: BACKSLASH,
43039
+ BACKTICK: BACKTICK,
43040
+ CARET: CARET,
43041
+ COLON: COLON,
43042
+ COMMA: COMMA,
43043
+ DOLLAR: DOLLAR,
43044
+ DOT: DOT,
43045
+ EQUALS: EQUALS,
43046
+ EXCLAMATION: EXCLAMATION,
43047
+ HYPHEN: HYPHEN,
43048
+ PERCENT: PERCENT,
43049
+ PIPE: PIPE,
43050
+ PLUS: PLUS,
43051
+ POUND: POUND,
43052
+ QUERY: QUERY,
43053
+ QUOTE: QUOTE,
43054
+ SEMI: SEMI,
43055
+ SLASH: SLASH,
43056
+ TILDE: TILDE,
43057
+ UNDERSCORE: UNDERSCORE,
43058
+ EMOJI: EMOJI$1,
43059
+ SYM: SYM
43060
+ });
43061
+
43062
+ // Note that these two Unicode ones expand into a really big one with Babel
43063
+ const ASCII_LETTER = /[a-z]/;
43064
+ const LETTER = /\p{L}/u; // Any Unicode character with letter data type
43065
+ const EMOJI = /\p{Emoji}/u; // Any Unicode emoji character
43066
+ const DIGIT = /\d/;
43067
+ const SPACE = /\s/;
43068
+
43069
+ /**
43070
+ The scanner provides an interface that takes a string of text as input, and
43071
+ outputs an array of tokens instances that can be used for easy URL parsing.
43072
+ */
43073
+ const NL = '\n'; // New line character
43074
+ const EMOJI_VARIATION = '\ufe0f'; // Variation selector, follows heart and others
43075
+ const EMOJI_JOINER = '\u200d'; // zero-width joiner
43076
+
43077
+ let tlds = null,
43078
+ utlds = null; // don't change so only have to be computed once
43079
+
43080
+ /**
43081
+ * Scanner output token:
43082
+ * - `t` is the token name (e.g., 'NUM', 'EMOJI', 'TLD')
43083
+ * - `v` is the value of the token (e.g., '123', '❤️', 'com')
43084
+ * - `s` is the start index of the token in the original string
43085
+ * - `e` is the end index of the token in the original string
43086
+ * @typedef {{t: string, v: string, s: number, e: number}} Token
43087
+ */
43088
+
43089
+ /**
43090
+ * @template T
43091
+ * @typedef {{ [collection: string]: T[] }} Collections
43092
+ */
43093
+
43094
+ /**
43095
+ * Initialize the scanner character-based state machine for the given start
43096
+ * state
43097
+ * @param {[string, boolean][]} customSchemes List of custom schemes, where each
43098
+ * item is a length-2 tuple with the first element set to the string scheme, and
43099
+ * the second element set to `true` if the `://` after the scheme is optional
43100
+ */
43101
+ function init$2(customSchemes) {
43102
+ if (customSchemes === void 0) {
43103
+ customSchemes = [];
43104
+ }
43105
+ // Frequently used states (name argument removed during minification)
43106
+ /** @type Collections<string> */
43107
+ const groups = {}; // of tokens
43108
+ State.groups = groups;
43109
+ /** @type State<string> */
43110
+ const Start = new State();
43111
+ if (tlds == null) {
43112
+ tlds = decodeTlds(encodedTlds);
43113
+ }
43114
+ if (utlds == null) {
43115
+ utlds = decodeTlds(encodedUtlds);
43116
+ }
43117
+
43118
+ // States for special URL symbols that accept immediately after start
43119
+ tt(Start, "'", APOSTROPHE$1);
43120
+ tt(Start, '{', OPENBRACE);
43121
+ tt(Start, '[', OPENBRACKET);
43122
+ tt(Start, '<', OPENANGLEBRACKET);
43123
+ tt(Start, '(', OPENPAREN);
43124
+ tt(Start, '}', CLOSEBRACE);
43125
+ tt(Start, ']', CLOSEBRACKET);
43126
+ tt(Start, '>', CLOSEANGLEBRACKET);
43127
+ tt(Start, ')', CLOSEPAREN);
43128
+ tt(Start, '&', AMPERSAND);
43129
+ tt(Start, '*', ASTERISK);
43130
+ tt(Start, '@', AT);
43131
+ tt(Start, '`', BACKTICK);
43132
+ tt(Start, '^', CARET);
43133
+ tt(Start, ':', COLON);
43134
+ tt(Start, ',', COMMA);
43135
+ tt(Start, '$', DOLLAR);
43136
+ tt(Start, '.', DOT);
43137
+ tt(Start, '=', EQUALS);
43138
+ tt(Start, '!', EXCLAMATION);
43139
+ tt(Start, '-', HYPHEN);
43140
+ tt(Start, '%', PERCENT);
43141
+ tt(Start, '|', PIPE);
43142
+ tt(Start, '+', PLUS);
43143
+ tt(Start, '#', POUND);
43144
+ tt(Start, '?', QUERY);
43145
+ tt(Start, '"', QUOTE);
43146
+ tt(Start, '/', SLASH);
43147
+ tt(Start, ';', SEMI);
43148
+ tt(Start, '~', TILDE);
43149
+ tt(Start, '_', UNDERSCORE);
43150
+ tt(Start, '\\', BACKSLASH);
43151
+ const Num = tr(Start, DIGIT, NUM, {
43152
+ [numeric]: true
43153
+ });
43154
+ tr(Num, DIGIT, Num);
43155
+
43156
+ // State which emits a word token
43157
+ const Word = tr(Start, ASCII_LETTER, WORD, {
43158
+ [ascii]: true
43159
+ });
43160
+ tr(Word, ASCII_LETTER, Word);
43161
+
43162
+ // Same as previous, but specific to non-fsm.ascii alphabet words
43163
+ const UWord = tr(Start, LETTER, UWORD, {
43164
+ [alpha$1]: true
43165
+ });
43166
+ tr(UWord, ASCII_LETTER); // Non-accepting
43167
+ tr(UWord, LETTER, UWord);
43168
+
43169
+ // Whitespace jumps
43170
+ // Tokens of only non-newline whitespace are arbitrarily long
43171
+ // If any whitespace except newline, more whitespace!
43172
+ const Ws = tr(Start, SPACE, WS, {
43173
+ [whitespace]: true
43174
+ });
43175
+ tt(Start, NL, NL$1, {
43176
+ [whitespace]: true
43177
+ });
43178
+ tt(Ws, NL); // non-accepting state to avoid mixing whitespaces
43179
+ tr(Ws, SPACE, Ws);
43180
+
43181
+ // Emoji tokens. They are not grouped by the scanner except in cases where a
43182
+ // zero-width joiner is present
43183
+ const Emoji = tr(Start, EMOJI, EMOJI$1, {
43184
+ [emoji]: true
43185
+ });
43186
+ tr(Emoji, EMOJI, Emoji);
43187
+ tt(Emoji, EMOJI_VARIATION, Emoji);
43188
+ // tt(Start, EMOJI_VARIATION, Emoji); // This one is sketchy
43189
+
43190
+ const EmojiJoiner = tt(Emoji, EMOJI_JOINER);
43191
+ tr(EmojiJoiner, EMOJI, Emoji);
43192
+ // tt(EmojiJoiner, EMOJI_VARIATION, Emoji); // also sketchy
43193
+
43194
+ // Generates states for top-level domains
43195
+ // Note that this is most accurate when tlds are in alphabetical order
43196
+ const wordjr = [[ASCII_LETTER, Word]];
43197
+ const uwordjr = [[ASCII_LETTER, null], [LETTER, UWord]];
43198
+ for (let i = 0; i < tlds.length; i++) {
43199
+ fastts(Start, tlds[i], TLD, WORD, wordjr);
43200
+ }
43201
+ for (let i = 0; i < utlds.length; i++) {
43202
+ fastts(Start, utlds[i], UTLD, UWORD, uwordjr);
43203
+ }
43204
+ addToGroups(TLD, {
43205
+ tld: true,
43206
+ ascii: true
43207
+ }, groups);
43208
+ addToGroups(UTLD, {
43209
+ utld: true,
43210
+ alpha: true
43211
+ }, groups);
43212
+
43213
+ // Collect the states generated by different protocols. NOTE: If any new TLDs
43214
+ // get added that are also protocols, set the token to be the same as the
43215
+ // protocol to ensure parsing works as expected.
43216
+ fastts(Start, 'file', SCHEME, WORD, wordjr);
43217
+ fastts(Start, 'mailto', SCHEME, WORD, wordjr);
43218
+ fastts(Start, 'http', SLASH_SCHEME, WORD, wordjr);
43219
+ fastts(Start, 'https', SLASH_SCHEME, WORD, wordjr);
43220
+ fastts(Start, 'ftp', SLASH_SCHEME, WORD, wordjr);
43221
+ fastts(Start, 'ftps', SLASH_SCHEME, WORD, wordjr);
43222
+ addToGroups(SCHEME, {
43223
+ scheme: true,
43224
+ ascii: true
43225
+ }, groups);
43226
+ addToGroups(SLASH_SCHEME, {
43227
+ slashscheme: true,
43228
+ ascii: true
43229
+ }, groups);
43230
+
43231
+ // Register custom schemes. Assumes each scheme is asciinumeric with hyphens
43232
+ customSchemes = customSchemes.sort((a, b) => a[0] > b[0] ? 1 : -1);
43233
+ for (let i = 0; i < customSchemes.length; i++) {
43234
+ const sch = customSchemes[i][0];
43235
+ const optionalSlashSlash = customSchemes[i][1];
43236
+ const flags = optionalSlashSlash ? {
43237
+ [scheme]: true
43238
+ } : {
43239
+ [slashscheme]: true
43240
+ };
43241
+ if (sch.indexOf('-') >= 0) {
43242
+ flags[domain] = true;
43243
+ } else if (!ASCII_LETTER.test(sch)) {
43244
+ flags[numeric] = true; // numbers only
43245
+ } else if (DIGIT.test(sch)) {
43246
+ flags[asciinumeric] = true;
43247
+ } else {
43248
+ flags[ascii] = true;
43249
+ }
43250
+ ts(Start, sch, sch, flags);
43251
+ }
43252
+
43253
+ // Localhost token
43254
+ ts(Start, 'localhost', LOCALHOST, {
43255
+ ascii: true
43256
+ });
43257
+
43258
+ // Set default transition for start state (some symbol)
43259
+ Start.jd = new State(SYM);
43260
+ return {
43261
+ start: Start,
43262
+ tokens: assign$2({
43263
+ groups
43264
+ }, tk)
43265
+ };
43266
+ }
43267
+
43268
+ /**
43269
+ Given a string, returns an array of TOKEN instances representing the
43270
+ composition of that string.
43271
+
43272
+ @method run
43273
+ @param {State<string>} start scanner starting state
43274
+ @param {string} str input string to scan
43275
+ @return {Token[]} list of tokens, each with a type and value
43276
+ */
43277
+ function run$1(start, str) {
43278
+ // State machine is not case sensitive, so input is tokenized in lowercased
43279
+ // form (still returns regular case). Uses selective `toLowerCase` because
43280
+ // lowercasing the entire string causes the length and character position to
43281
+ // vary in some non-English strings with V8-based runtimes.
43282
+ const iterable = stringToArray(str.replace(/[A-Z]/g, c => c.toLowerCase()));
43283
+ const charCount = iterable.length; // <= len if there are emojis, etc
43284
+ const tokens = []; // return value
43285
+
43286
+ // cursor through the string itself, accounting for characters that have
43287
+ // width with length 2 such as emojis
43288
+ let cursor = 0;
43289
+
43290
+ // Cursor through the array-representation of the string
43291
+ let charCursor = 0;
43292
+
43293
+ // Tokenize the string
43294
+ while (charCursor < charCount) {
43295
+ let state = start;
43296
+ let nextState = null;
43297
+ let tokenLength = 0;
43298
+ let latestAccepting = null;
43299
+ let sinceAccepts = -1;
43300
+ let charsSinceAccepts = -1;
43301
+ while (charCursor < charCount && (nextState = state.go(iterable[charCursor]))) {
43302
+ state = nextState;
43303
+
43304
+ // Keep track of the latest accepting state
43305
+ if (state.accepts()) {
43306
+ sinceAccepts = 0;
43307
+ charsSinceAccepts = 0;
43308
+ latestAccepting = state;
43309
+ } else if (sinceAccepts >= 0) {
43310
+ sinceAccepts += iterable[charCursor].length;
43311
+ charsSinceAccepts++;
43312
+ }
43313
+ tokenLength += iterable[charCursor].length;
43314
+ cursor += iterable[charCursor].length;
43315
+ charCursor++;
43316
+ }
43317
+
43318
+ // Roll back to the latest accepting state
43319
+ cursor -= sinceAccepts;
43320
+ charCursor -= charsSinceAccepts;
43321
+ tokenLength -= sinceAccepts;
43322
+
43323
+ // No more jumps, just make a new token from the last accepting one
43324
+ tokens.push({
43325
+ t: latestAccepting.t,
43326
+ // token type/name
43327
+ v: str.slice(cursor - tokenLength, cursor),
43328
+ // string value
43329
+ s: cursor - tokenLength,
43330
+ // start index
43331
+ e: cursor // end index (excluding)
43332
+ });
43333
+ }
43334
+
43335
+ return tokens;
43336
+ }
43337
+
43338
+ /**
43339
+ * Convert a String to an Array of characters, taking into account that some
43340
+ * characters like emojis take up two string indexes.
43341
+ *
43342
+ * Adapted from core-js (MIT license)
43343
+ * https://github.com/zloirock/core-js/blob/2d69cf5f99ab3ea3463c395df81e5a15b68f49d9/packages/core-js/internals/string-multibyte.js
43344
+ *
43345
+ * @function stringToArray
43346
+ * @param {string} str
43347
+ * @returns {string[]}
43348
+ */
43349
+ function stringToArray(str) {
43350
+ const result = [];
43351
+ const len = str.length;
43352
+ let index = 0;
43353
+ while (index < len) {
43354
+ let first = str.charCodeAt(index);
43355
+ let second;
43356
+ let char = first < 0xd800 || first > 0xdbff || index + 1 === len || (second = str.charCodeAt(index + 1)) < 0xdc00 || second > 0xdfff ? str[index] // single character
43357
+ : str.slice(index, index + 2); // two-index characters
43358
+ result.push(char);
43359
+ index += char.length;
43360
+ }
43361
+ return result;
43362
+ }
43363
+
43364
+ /**
43365
+ * Fast version of ts function for when transition defaults are well known
43366
+ * @param {State<string>} state
43367
+ * @param {string} input
43368
+ * @param {string} t
43369
+ * @param {string} defaultt
43370
+ * @param {[RegExp, State<string>][]} jr
43371
+ * @returns {State<string>}
43372
+ */
43373
+ function fastts(state, input, t, defaultt, jr) {
43374
+ let next;
43375
+ const len = input.length;
43376
+ for (let i = 0; i < len - 1; i++) {
43377
+ const char = input[i];
43378
+ if (state.j[char]) {
43379
+ next = state.j[char];
43380
+ } else {
43381
+ next = new State(defaultt);
43382
+ next.jr = jr.slice();
43383
+ state.j[char] = next;
43384
+ }
43385
+ state = next;
43386
+ }
43387
+ next = new State(t);
43388
+ next.jr = jr.slice();
43389
+ state.j[input[len - 1]] = next;
43390
+ return next;
43391
+ }
43392
+
43393
+ /**
43394
+ * Converts a string of Top-Level Domain names encoded in update-tlds.js back
43395
+ * into a list of strings.
43396
+ * @param {str} encoded encoded TLDs string
43397
+ * @returns {str[]} original TLDs list
43398
+ */
43399
+ function decodeTlds(encoded) {
43400
+ const words = [];
43401
+ const stack = [];
43402
+ let i = 0;
43403
+ let digits = '0123456789';
43404
+ while (i < encoded.length) {
43405
+ let popDigitCount = 0;
43406
+ while (digits.indexOf(encoded[i + popDigitCount]) >= 0) {
43407
+ popDigitCount++; // encountered some digits, have to pop to go one level up trie
43408
+ }
43409
+
43410
+ if (popDigitCount > 0) {
43411
+ words.push(stack.join('')); // whatever preceded the pop digits must be a word
43412
+ for (let popCount = parseInt(encoded.substring(i, i + popDigitCount), 10); popCount > 0; popCount--) {
43413
+ stack.pop();
43414
+ }
43415
+ i += popDigitCount;
43416
+ } else {
43417
+ stack.push(encoded[i]); // drop down a level into the trie
43418
+ i++;
43419
+ }
43420
+ }
43421
+ return words;
43422
+ }
43423
+
43424
+ /**
43425
+ * An object where each key is a valid DOM Event Name such as `click` or `focus`
43426
+ * and each value is an event handler function.
43427
+ *
43428
+ * https://developer.mozilla.org/en-US/docs/Web/API/Element#events
43429
+ * @typedef {?{ [event: string]: Function }} EventListeners
43430
+ */
43431
+
43432
+ /**
43433
+ * All formatted properties required to render a link, including `tagName`,
43434
+ * `attributes`, `content` and `eventListeners`.
43435
+ * @typedef {{ tagName: any, attributes: {[attr: string]: any}, content: string,
43436
+ * eventListeners: EventListeners }} IntermediateRepresentation
43437
+ */
43438
+
43439
+ /**
43440
+ * Specify either an object described by the template type `O` or a function.
43441
+ *
43442
+ * The function takes a string value (usually the link's href attribute), the
43443
+ * link type (`'url'`, `'hashtag`', etc.) and an internal token representation
43444
+ * of the link. It should return an object of the template type `O`
43445
+ * @template O
43446
+ * @typedef {O | ((value: string, type: string, token: MultiToken) => O)} OptObj
43447
+ */
43448
+
43449
+ /**
43450
+ * Specify either a function described by template type `F` or an object.
43451
+ *
43452
+ * Each key in the object should be a link type (`'url'`, `'hashtag`', etc.). Each
43453
+ * value should be a function with template type `F` that is called when the
43454
+ * corresponding link type is encountered.
43455
+ * @template F
43456
+ * @typedef {F | { [type: string]: F}} OptFn
43457
+ */
43458
+
43459
+ /**
43460
+ * Specify either a value with template type `V`, a function that returns `V` or
43461
+ * an object where each value resolves to `V`.
43462
+ *
43463
+ * The function takes a string value (usually the link's href attribute), the
43464
+ * link type (`'url'`, `'hashtag`', etc.) and an internal token representation
43465
+ * of the link. It should return an object of the template type `V`
43466
+ *
43467
+ * For the object, each key should be a link type (`'url'`, `'hashtag`', etc.).
43468
+ * Each value should either have type `V` or a function that returns V. This
43469
+ * function similarly takes a string value and a token.
43470
+ *
43471
+ * Example valid types for `Opt<string>`:
43472
+ *
43473
+ * ```js
43474
+ * 'hello'
43475
+ * (value, type, token) => 'world'
43476
+ * { url: 'hello', email: (value, token) => 'world'}
43477
+ * ```
43478
+ * @template V
43479
+ * @typedef {V | ((value: string, type: string, token: MultiToken) => V) | { [type: string]: V | ((value: string, token: MultiToken) => V) }} Opt
43480
+ */
43481
+
43482
+ /**
43483
+ * See available options: https://linkify.js.org/docs/options.html
43484
+ * @typedef {{
43485
+ * defaultProtocol?: string,
43486
+ * events?: OptObj<EventListeners>,
43487
+ * format?: Opt<string>,
43488
+ * formatHref?: Opt<string>,
43489
+ * nl2br?: boolean,
43490
+ * tagName?: Opt<any>,
43491
+ * target?: Opt<string>,
43492
+ * rel?: Opt<string>,
43493
+ * validate?: Opt<boolean>,
43494
+ * truncate?: Opt<number>,
43495
+ * className?: Opt<string>,
43496
+ * attributes?: OptObj<({ [attr: string]: any })>,
43497
+ * ignoreTags?: string[],
43498
+ * render?: OptFn<((ir: IntermediateRepresentation) => any)>
43499
+ * }} Opts
43500
+ */
43501
+
43502
+ /**
43503
+ * @type Required<Opts>
43504
+ */
43505
+ const defaults = {
43506
+ defaultProtocol: 'http',
43507
+ events: null,
43508
+ format: noop$1,
43509
+ formatHref: noop$1,
43510
+ nl2br: false,
43511
+ tagName: 'a',
43512
+ target: null,
43513
+ rel: null,
43514
+ validate: true,
43515
+ truncate: Infinity,
43516
+ className: null,
43517
+ attributes: null,
43518
+ ignoreTags: [],
43519
+ render: null
43520
+ };
43521
+
43522
+ /**
43523
+ * Utility class for linkify interfaces to apply specified
43524
+ * {@link Opts formatting and rendering options}.
43525
+ *
43526
+ * @param {Opts | Options} [opts] Option value overrides.
43527
+ * @param {(ir: IntermediateRepresentation) => any} [defaultRender] (For
43528
+ * internal use) default render function that determines how to generate an
43529
+ * HTML element based on a link token's derived tagName, attributes and HTML.
43530
+ * Similar to render option
43531
+ */
43532
+ function Options(opts, defaultRender) {
43533
+ if (defaultRender === void 0) {
43534
+ defaultRender = null;
43535
+ }
43536
+ let o = assign$2({}, defaults);
43537
+ if (opts) {
43538
+ o = assign$2(o, opts instanceof Options ? opts.o : opts);
43539
+ }
43540
+
43541
+ // Ensure all ignored tags are uppercase
43542
+ const ignoredTags = o.ignoreTags;
43543
+ const uppercaseIgnoredTags = [];
43544
+ for (let i = 0; i < ignoredTags.length; i++) {
43545
+ uppercaseIgnoredTags.push(ignoredTags[i].toUpperCase());
43546
+ }
43547
+ /** @protected */
43548
+ this.o = o;
43549
+ if (defaultRender) {
43550
+ this.defaultRender = defaultRender;
43551
+ }
43552
+ this.ignoreTags = uppercaseIgnoredTags;
43553
+ }
43554
+ Options.prototype = {
43555
+ o: defaults,
43556
+ /**
43557
+ * @type string[]
43558
+ */
43559
+ ignoreTags: [],
43560
+ /**
43561
+ * @param {IntermediateRepresentation} ir
43562
+ * @returns {any}
43563
+ */
43564
+ defaultRender(ir) {
43565
+ return ir;
43566
+ },
43567
+ /**
43568
+ * Returns true or false based on whether a token should be displayed as a
43569
+ * link based on the user options.
43570
+ * @param {MultiToken} token
43571
+ * @returns {boolean}
43572
+ */
43573
+ check(token) {
43574
+ return this.get('validate', token.toString(), token);
43575
+ },
43576
+ // Private methods
43577
+
43578
+ /**
43579
+ * Resolve an option's value based on the value of the option and the given
43580
+ * params. If operator and token are specified and the target option is
43581
+ * callable, automatically calls the function with the given argument.
43582
+ * @template {keyof Opts} K
43583
+ * @param {K} key Name of option to use
43584
+ * @param {string} [operator] will be passed to the target option if it's a
43585
+ * function. If not specified, RAW function value gets returned
43586
+ * @param {MultiToken} [token] The token from linkify.tokenize
43587
+ * @returns {Opts[K] | any}
43588
+ */
43589
+ get(key, operator, token) {
43590
+ const isCallable = operator != null;
43591
+ let option = this.o[key];
43592
+ if (!option) {
43593
+ return option;
43594
+ }
43595
+ if (typeof option === 'object') {
43596
+ option = token.t in option ? option[token.t] : defaults[key];
43597
+ if (typeof option === 'function' && isCallable) {
43598
+ option = option(operator, token);
43599
+ }
43600
+ } else if (typeof option === 'function' && isCallable) {
43601
+ option = option(operator, token.t, token);
43602
+ }
43603
+ return option;
43604
+ },
43605
+ /**
43606
+ * @template {keyof Opts} L
43607
+ * @param {L} key Name of options object to use
43608
+ * @param {string} [operator]
43609
+ * @param {MultiToken} [token]
43610
+ * @returns {Opts[L] | any}
43611
+ */
43612
+ getObj(key, operator, token) {
43613
+ let obj = this.o[key];
43614
+ if (typeof obj === 'function' && operator != null) {
43615
+ obj = obj(operator, token.t, token);
43616
+ }
43617
+ return obj;
43618
+ },
43619
+ /**
43620
+ * Convert the given token to a rendered element that may be added to the
43621
+ * calling-interface's DOM
43622
+ * @param {MultiToken} token Token to render to an HTML element
43623
+ * @returns {any} Render result; e.g., HTML string, DOM element, React
43624
+ * Component, etc.
43625
+ */
43626
+ render(token) {
43627
+ const ir = token.render(this); // intermediate representation
43628
+ const renderFn = this.get('render', null, token) || this.defaultRender;
43629
+ return renderFn(ir, token.t, token);
43630
+ }
43631
+ };
43632
+ function noop$1(val) {
43633
+ return val;
43634
+ }
43635
+
43636
+ /******************************************************************************
43637
+ Multi-Tokens
43638
+ Tokens composed of arrays of TextTokens
43639
+ ******************************************************************************/
43640
+
43641
+ /**
43642
+ * @param {string} value
43643
+ * @param {Token[]} tokens
43644
+ */
43645
+ function MultiToken(value, tokens) {
43646
+ this.t = 'token';
43647
+ this.v = value;
43648
+ this.tk = tokens;
43649
+ }
43650
+
43651
+ /**
43652
+ * Abstract class used for manufacturing tokens of text tokens. That is rather
43653
+ * than the value for a token being a small string of text, it's value an array
43654
+ * of text tokens.
43655
+ *
43656
+ * Used for grouping together URLs, emails, hashtags, and other potential
43657
+ * creations.
43658
+ * @class MultiToken
43659
+ * @property {string} t
43660
+ * @property {string} v
43661
+ * @property {Token[]} tk
43662
+ * @abstract
43663
+ */
43664
+ MultiToken.prototype = {
43665
+ isLink: false,
43666
+ /**
43667
+ * Return the string this token represents.
43668
+ * @return {string}
43669
+ */
43670
+ toString() {
43671
+ return this.v;
43672
+ },
43673
+ /**
43674
+ * What should the value for this token be in the `href` HTML attribute?
43675
+ * Returns the `.toString` value by default.
43676
+ * @param {string} [scheme]
43677
+ * @return {string}
43678
+ */
43679
+ toHref(scheme) {
43680
+ return this.toString();
43681
+ },
43682
+ /**
43683
+ * @param {Options} options Formatting options
43684
+ * @returns {string}
43685
+ */
43686
+ toFormattedString(options) {
43687
+ const val = this.toString();
43688
+ const truncate = options.get('truncate', val, this);
43689
+ const formatted = options.get('format', val, this);
43690
+ return truncate && formatted.length > truncate ? formatted.substring(0, truncate) + '…' : formatted;
43691
+ },
43692
+ /**
43693
+ *
43694
+ * @param {Options} options
43695
+ * @returns {string}
43696
+ */
43697
+ toFormattedHref(options) {
43698
+ return options.get('formatHref', this.toHref(options.get('defaultProtocol')), this);
43699
+ },
43700
+ /**
43701
+ * The start index of this token in the original input string
43702
+ * @returns {number}
43703
+ */
43704
+ startIndex() {
43705
+ return this.tk[0].s;
43706
+ },
43707
+ /**
43708
+ * The end index of this token in the original input string (up to this
43709
+ * index but not including it)
43710
+ * @returns {number}
43711
+ */
43712
+ endIndex() {
43713
+ return this.tk[this.tk.length - 1].e;
43714
+ },
43715
+ /**
43716
+ Returns an object of relevant values for this token, which includes keys
43717
+ * type - Kind of token ('url', 'email', etc.)
43718
+ * value - Original text
43719
+ * href - The value that should be added to the anchor tag's href
43720
+ attribute
43721
+ @method toObject
43722
+ @param {string} [protocol] `'http'` by default
43723
+ */
43724
+ toObject(protocol) {
43725
+ if (protocol === void 0) {
43726
+ protocol = defaults.defaultProtocol;
43727
+ }
43728
+ return {
43729
+ type: this.t,
43730
+ value: this.toString(),
43731
+ isLink: this.isLink,
43732
+ href: this.toHref(protocol),
43733
+ start: this.startIndex(),
43734
+ end: this.endIndex()
43735
+ };
43736
+ },
43737
+ /**
43738
+ *
43739
+ * @param {Options} options Formatting option
43740
+ */
43741
+ toFormattedObject(options) {
43742
+ return {
43743
+ type: this.t,
43744
+ value: this.toFormattedString(options),
43745
+ isLink: this.isLink,
43746
+ href: this.toFormattedHref(options),
43747
+ start: this.startIndex(),
43748
+ end: this.endIndex()
43749
+ };
43750
+ },
43751
+ /**
43752
+ * Whether this token should be rendered as a link according to the given options
43753
+ * @param {Options} options
43754
+ * @returns {boolean}
43755
+ */
43756
+ validate(options) {
43757
+ return options.get('validate', this.toString(), this);
43758
+ },
43759
+ /**
43760
+ * Return an object that represents how this link should be rendered.
43761
+ * @param {Options} options Formattinng options
43762
+ */
43763
+ render(options) {
43764
+ const token = this;
43765
+ const href = this.toHref(options.get('defaultProtocol'));
43766
+ const formattedHref = options.get('formatHref', href, this);
43767
+ const tagName = options.get('tagName', href, token);
43768
+ const content = this.toFormattedString(options);
43769
+ const attributes = {};
43770
+ const className = options.get('className', href, token);
43771
+ const target = options.get('target', href, token);
43772
+ const rel = options.get('rel', href, token);
43773
+ const attrs = options.getObj('attributes', href, token);
43774
+ const eventListeners = options.getObj('events', href, token);
43775
+ attributes.href = formattedHref;
43776
+ if (className) {
43777
+ attributes.class = className;
43778
+ }
43779
+ if (target) {
43780
+ attributes.target = target;
43781
+ }
43782
+ if (rel) {
43783
+ attributes.rel = rel;
43784
+ }
43785
+ if (attrs) {
43786
+ assign$2(attributes, attrs);
43787
+ }
43788
+ return {
43789
+ tagName,
43790
+ attributes,
43791
+ content,
43792
+ eventListeners
43793
+ };
43794
+ }
43795
+ };
43796
+
43797
+ /**
43798
+ * Create a new token that can be emitted by the parser state machine
43799
+ * @param {string} type readable type of the token
43800
+ * @param {object} props properties to assign or override, including isLink = true or false
43801
+ * @returns {new (value: string, tokens: Token[]) => MultiToken} new token class
43802
+ */
43803
+ function createTokenClass(type, props) {
43804
+ class Token extends MultiToken {
43805
+ constructor(value, tokens) {
43806
+ super(value, tokens);
43807
+ this.t = type;
43808
+ }
43809
+ }
43810
+ for (const p in props) {
43811
+ Token.prototype[p] = props[p];
43812
+ }
43813
+ Token.t = type;
43814
+ return Token;
43815
+ }
43816
+
43817
+ /**
43818
+ Represents a list of tokens making up a valid email address
43819
+ */
43820
+ const Email = createTokenClass('email', {
43821
+ isLink: true,
43822
+ toHref() {
43823
+ return 'mailto:' + this.toString();
43824
+ }
43825
+ });
43826
+
43827
+ /**
43828
+ Represents some plain text
43829
+ */
43830
+ const Text$1 = createTokenClass('text');
43831
+
43832
+ /**
43833
+ Multi-linebreak token - represents a line break
43834
+ @class Nl
43835
+ */
43836
+ const Nl = createTokenClass('nl');
43837
+
43838
+ /**
43839
+ Represents a list of text tokens making up a valid URL
43840
+ @class Url
43841
+ */
43842
+ const Url$1 = createTokenClass('url', {
43843
+ isLink: true,
43844
+ /**
43845
+ Lowercases relevant parts of the domain and adds the protocol if
43846
+ required. Note that this will not escape unsafe HTML characters in the
43847
+ URL.
43848
+ @param {string} [scheme] default scheme (e.g., 'https')
43849
+ @return {string} the full href
43850
+ */
43851
+ toHref(scheme) {
43852
+ if (scheme === void 0) {
43853
+ scheme = defaults.defaultProtocol;
43854
+ }
43855
+ // Check if already has a prefix scheme
43856
+ return this.hasProtocol() ? this.v : `${scheme}://${this.v}`;
43857
+ },
43858
+ /**
43859
+ * Check whether this URL token has a protocol
43860
+ * @return {boolean}
43861
+ */
43862
+ hasProtocol() {
43863
+ const tokens = this.tk;
43864
+ return tokens.length >= 2 && tokens[0].t !== LOCALHOST && tokens[1].t === COLON;
43865
+ }
43866
+ });
43867
+
43868
+ /**
43869
+ Not exactly parser, more like the second-stage scanner (although we can
43870
+ theoretically hotswap the code here with a real parser in the future... but
43871
+ for a little URL-finding utility abstract syntax trees may be a little
43872
+ overkill).
43873
+
43874
+ URL format: http://en.wikipedia.org/wiki/URI_scheme
43875
+ Email format: http://en.wikipedia.org/wiki/EmailAddress (links to RFC in
43876
+ reference)
43877
+
43878
+ @module linkify
43879
+ @submodule parser
43880
+ @main run
43881
+ */
43882
+ const makeState = arg => new State(arg);
43883
+
43884
+ /**
43885
+ * Generate the parser multi token-based state machine
43886
+ * @param {{ groups: Collections<string> }} tokens
43887
+ */
43888
+ function init$1(_ref) {
43889
+ let {
43890
+ groups
43891
+ } = _ref;
43892
+ // Types of characters the URL can definitely end in
43893
+ const qsAccepting = groups.domain.concat([AMPERSAND, ASTERISK, AT, BACKSLASH, BACKTICK, CARET, DOLLAR, EQUALS, HYPHEN, NUM, PERCENT, PIPE, PLUS, POUND, SLASH, SYM, TILDE, UNDERSCORE]);
43894
+
43895
+ // Types of tokens that can follow a URL and be part of the query string
43896
+ // but cannot be the very last characters
43897
+ // Characters that cannot appear in the URL at all should be excluded
43898
+ const qsNonAccepting = [APOSTROPHE$1, CLOSEANGLEBRACKET, CLOSEBRACE, CLOSEBRACKET, CLOSEPAREN, COLON, COMMA, DOT, EXCLAMATION, OPENANGLEBRACKET, OPENBRACE, OPENBRACKET, OPENPAREN, QUERY, QUOTE, SEMI];
43899
+
43900
+ // For addresses without the mailto prefix
43901
+ // Tokens allowed in the localpart of the email
43902
+ const localpartAccepting = [AMPERSAND, APOSTROPHE$1, ASTERISK, BACKSLASH, BACKTICK, CARET, CLOSEBRACE, DOLLAR, EQUALS, HYPHEN, OPENBRACE, PERCENT, PIPE, PLUS, POUND, QUERY, SLASH, SYM, TILDE, UNDERSCORE];
43903
+
43904
+ // The universal starting state.
43905
+ /**
43906
+ * @type State<Token>
43907
+ */
43908
+ const Start = makeState();
43909
+ const Localpart = tt(Start, TILDE); // Local part of the email address
43910
+ ta(Localpart, localpartAccepting, Localpart);
43911
+ ta(Localpart, groups.domain, Localpart);
43912
+ const Domain = makeState(),
43913
+ Scheme = makeState(),
43914
+ SlashScheme = makeState();
43915
+ ta(Start, groups.domain, Domain); // parsed string ends with a potential domain name (A)
43916
+ ta(Start, groups.scheme, Scheme); // e.g., 'mailto'
43917
+ ta(Start, groups.slashscheme, SlashScheme); // e.g., 'http'
43918
+
43919
+ ta(Domain, localpartAccepting, Localpart);
43920
+ ta(Domain, groups.domain, Domain);
43921
+ const LocalpartAt = tt(Domain, AT); // Local part of the email address plus @
43922
+
43923
+ tt(Localpart, AT, LocalpartAt); // close to an email address now
43924
+
43925
+ // Local part of an email address can be e.g. 'http' or 'mailto'
43926
+ tt(Scheme, AT, LocalpartAt);
43927
+ tt(SlashScheme, AT, LocalpartAt);
43928
+ const LocalpartDot = tt(Localpart, DOT); // Local part of the email address plus '.' (localpart cannot end in .)
43929
+ ta(LocalpartDot, localpartAccepting, Localpart);
43930
+ ta(LocalpartDot, groups.domain, Localpart);
43931
+ const EmailDomain = makeState();
43932
+ ta(LocalpartAt, groups.domain, EmailDomain); // parsed string starts with local email info + @ with a potential domain name
43933
+ ta(EmailDomain, groups.domain, EmailDomain);
43934
+ const EmailDomainDot = tt(EmailDomain, DOT); // domain followed by DOT
43935
+ ta(EmailDomainDot, groups.domain, EmailDomain);
43936
+ const Email$1 = makeState(Email); // Possible email address (could have more tlds)
43937
+ ta(EmailDomainDot, groups.tld, Email$1);
43938
+ ta(EmailDomainDot, groups.utld, Email$1);
43939
+ tt(LocalpartAt, LOCALHOST, Email$1);
43940
+
43941
+ // Hyphen can jump back to a domain name
43942
+ const EmailDomainHyphen = tt(EmailDomain, HYPHEN); // parsed string starts with local email info + @ with a potential domain name
43943
+ ta(EmailDomainHyphen, groups.domain, EmailDomain);
43944
+ ta(Email$1, groups.domain, EmailDomain);
43945
+ tt(Email$1, DOT, EmailDomainDot);
43946
+ tt(Email$1, HYPHEN, EmailDomainHyphen);
43947
+
43948
+ // Final possible email states
43949
+ const EmailColon = tt(Email$1, COLON); // URL followed by colon (potential port number here)
43950
+ /*const EmailColonPort = */
43951
+ ta(EmailColon, groups.numeric, Email); // URL followed by colon and port numner
43952
+
43953
+ // Account for dots and hyphens. Hyphens are usually parts of domain names
43954
+ // (but not TLDs)
43955
+ const DomainHyphen = tt(Domain, HYPHEN); // domain followed by hyphen
43956
+ const DomainDot = tt(Domain, DOT); // domain followed by DOT
43957
+ ta(DomainHyphen, groups.domain, Domain);
43958
+ ta(DomainDot, localpartAccepting, Localpart);
43959
+ ta(DomainDot, groups.domain, Domain);
43960
+ const DomainDotTld = makeState(Url$1); // Simplest possible URL with no query string
43961
+ ta(DomainDot, groups.tld, DomainDotTld);
43962
+ ta(DomainDot, groups.utld, DomainDotTld);
43963
+ ta(DomainDotTld, groups.domain, Domain);
43964
+ ta(DomainDotTld, localpartAccepting, Localpart);
43965
+ tt(DomainDotTld, DOT, DomainDot);
43966
+ tt(DomainDotTld, HYPHEN, DomainHyphen);
43967
+ tt(DomainDotTld, AT, LocalpartAt);
43968
+ const DomainDotTldColon = tt(DomainDotTld, COLON); // URL followed by colon (potential port number here)
43969
+ const DomainDotTldColonPort = makeState(Url$1); // TLD followed by a port number
43970
+ ta(DomainDotTldColon, groups.numeric, DomainDotTldColonPort);
43971
+
43972
+ // Long URL with optional port and maybe query string
43973
+ const Url$1$1 = makeState(Url$1);
43974
+
43975
+ // URL with extra symbols at the end, followed by an opening bracket
43976
+ const UrlNonaccept = makeState(); // URL followed by some symbols (will not be part of the final URL)
43977
+
43978
+ // Query strings
43979
+ ta(Url$1$1, qsAccepting, Url$1$1);
43980
+ ta(Url$1$1, qsNonAccepting, UrlNonaccept);
43981
+ ta(UrlNonaccept, qsAccepting, Url$1$1);
43982
+ ta(UrlNonaccept, qsNonAccepting, UrlNonaccept);
43983
+
43984
+ // Become real URLs after `SLASH` or `COLON NUM SLASH`
43985
+ // Here works with or without scheme:// prefix
43986
+ tt(DomainDotTld, SLASH, Url$1$1);
43987
+ tt(DomainDotTldColonPort, SLASH, Url$1$1);
43988
+
43989
+ // Note that domains that begin with schemes are treated slighly differently
43990
+ const SchemeColon = tt(Scheme, COLON); // e.g., 'mailto:'
43991
+ const SlashSchemeColon = tt(SlashScheme, COLON); // e.g., 'http:'
43992
+ const SlashSchemeColonSlash = tt(SlashSchemeColon, SLASH); // e.g., 'http:/'
43993
+
43994
+ const UriPrefix = tt(SlashSchemeColonSlash, SLASH); // e.g., 'http://'
43995
+
43996
+ // Scheme states can transition to domain states
43997
+ ta(Scheme, groups.domain, Domain);
43998
+ tt(Scheme, DOT, DomainDot);
43999
+ tt(Scheme, HYPHEN, DomainHyphen);
44000
+ ta(SlashScheme, groups.domain, Domain);
44001
+ tt(SlashScheme, DOT, DomainDot);
44002
+ tt(SlashScheme, HYPHEN, DomainHyphen);
44003
+
44004
+ // Force URL with scheme prefix followed by anything sane
44005
+ ta(SchemeColon, groups.domain, Url$1$1);
44006
+ tt(SchemeColon, SLASH, Url$1$1);
44007
+ ta(UriPrefix, groups.domain, Url$1$1);
44008
+ ta(UriPrefix, qsAccepting, Url$1$1);
44009
+ tt(UriPrefix, SLASH, Url$1$1);
44010
+
44011
+ // URL, followed by an opening bracket
44012
+ const UrlOpenbrace = tt(Url$1$1, OPENBRACE); // URL followed by {
44013
+ const UrlOpenbracket = tt(Url$1$1, OPENBRACKET); // URL followed by [
44014
+ const UrlOpenanglebracket = tt(Url$1$1, OPENANGLEBRACKET); // URL followed by <
44015
+ const UrlOpenparen = tt(Url$1$1, OPENPAREN); // URL followed by (
44016
+
44017
+ tt(UrlNonaccept, OPENBRACE, UrlOpenbrace);
44018
+ tt(UrlNonaccept, OPENBRACKET, UrlOpenbracket);
44019
+ tt(UrlNonaccept, OPENANGLEBRACKET, UrlOpenanglebracket);
44020
+ tt(UrlNonaccept, OPENPAREN, UrlOpenparen);
44021
+
44022
+ // Closing bracket component. This character WILL be included in the URL
44023
+ tt(UrlOpenbrace, CLOSEBRACE, Url$1$1);
44024
+ tt(UrlOpenbracket, CLOSEBRACKET, Url$1$1);
44025
+ tt(UrlOpenanglebracket, CLOSEANGLEBRACKET, Url$1$1);
44026
+ tt(UrlOpenparen, CLOSEPAREN, Url$1$1);
44027
+ tt(UrlOpenbrace, CLOSEBRACE, Url$1$1);
44028
+
44029
+ // URL that beings with an opening bracket, followed by a symbols.
44030
+ // Note that the final state can still be `UrlOpenbrace` (if the URL only
44031
+ // has a single opening bracket for some reason).
44032
+ const UrlOpenbraceQ = makeState(Url$1); // URL followed by { and some symbols that the URL can end it
44033
+ const UrlOpenbracketQ = makeState(Url$1); // URL followed by [ and some symbols that the URL can end it
44034
+ const UrlOpenanglebracketQ = makeState(Url$1); // URL followed by < and some symbols that the URL can end it
44035
+ const UrlOpenparenQ = makeState(Url$1); // URL followed by ( and some symbols that the URL can end it
44036
+ ta(UrlOpenbrace, qsAccepting, UrlOpenbraceQ);
44037
+ ta(UrlOpenbracket, qsAccepting, UrlOpenbracketQ);
44038
+ ta(UrlOpenanglebracket, qsAccepting, UrlOpenanglebracketQ);
44039
+ ta(UrlOpenparen, qsAccepting, UrlOpenparenQ);
44040
+ const UrlOpenbraceSyms = makeState(); // UrlOpenbrace followed by some symbols it cannot end it
44041
+ const UrlOpenbracketSyms = makeState(); // UrlOpenbracketQ followed by some symbols it cannot end it
44042
+ const UrlOpenanglebracketSyms = makeState(); // UrlOpenanglebracketQ followed by some symbols it cannot end it
44043
+ const UrlOpenparenSyms = makeState(); // UrlOpenparenQ followed by some symbols it cannot end it
44044
+ ta(UrlOpenbrace, qsNonAccepting);
44045
+ ta(UrlOpenbracket, qsNonAccepting);
44046
+ ta(UrlOpenanglebracket, qsNonAccepting);
44047
+ ta(UrlOpenparen, qsNonAccepting);
44048
+
44049
+ // URL that begins with an opening bracket, followed by some symbols
44050
+ ta(UrlOpenbraceQ, qsAccepting, UrlOpenbraceQ);
44051
+ ta(UrlOpenbracketQ, qsAccepting, UrlOpenbracketQ);
44052
+ ta(UrlOpenanglebracketQ, qsAccepting, UrlOpenanglebracketQ);
44053
+ ta(UrlOpenparenQ, qsAccepting, UrlOpenparenQ);
44054
+ ta(UrlOpenbraceQ, qsNonAccepting, UrlOpenbraceQ);
44055
+ ta(UrlOpenbracketQ, qsNonAccepting, UrlOpenbracketQ);
44056
+ ta(UrlOpenanglebracketQ, qsNonAccepting, UrlOpenanglebracketQ);
44057
+ ta(UrlOpenparenQ, qsNonAccepting, UrlOpenparenQ);
44058
+ ta(UrlOpenbraceSyms, qsAccepting, UrlOpenbraceSyms);
44059
+ ta(UrlOpenbracketSyms, qsAccepting, UrlOpenbracketQ);
44060
+ ta(UrlOpenanglebracketSyms, qsAccepting, UrlOpenanglebracketQ);
44061
+ ta(UrlOpenparenSyms, qsAccepting, UrlOpenparenQ);
44062
+ ta(UrlOpenbraceSyms, qsNonAccepting, UrlOpenbraceSyms);
44063
+ ta(UrlOpenbracketSyms, qsNonAccepting, UrlOpenbracketSyms);
44064
+ ta(UrlOpenanglebracketSyms, qsNonAccepting, UrlOpenanglebracketSyms);
44065
+ ta(UrlOpenparenSyms, qsNonAccepting, UrlOpenparenSyms);
44066
+
44067
+ // Close brace/bracket to become regular URL
44068
+ tt(UrlOpenbracketQ, CLOSEBRACKET, Url$1$1);
44069
+ tt(UrlOpenanglebracketQ, CLOSEANGLEBRACKET, Url$1$1);
44070
+ tt(UrlOpenparenQ, CLOSEPAREN, Url$1$1);
44071
+ tt(UrlOpenbraceQ, CLOSEBRACE, Url$1$1);
44072
+ tt(UrlOpenbracketSyms, CLOSEBRACKET, Url$1$1);
44073
+ tt(UrlOpenanglebracketSyms, CLOSEANGLEBRACKET, Url$1$1);
44074
+ tt(UrlOpenparenSyms, CLOSEPAREN, Url$1$1);
44075
+ tt(UrlOpenbraceSyms, CLOSEPAREN, Url$1$1);
44076
+ tt(Start, LOCALHOST, DomainDotTld); // localhost is a valid URL state
44077
+ tt(Start, NL$1, Nl); // single new line
44078
+
44079
+ return {
44080
+ start: Start,
44081
+ tokens: tk
44082
+ };
44083
+ }
44084
+
44085
+ /**
44086
+ * Run the parser state machine on a list of scanned string-based tokens to
44087
+ * create a list of multi tokens, each of which represents a URL, email address,
44088
+ * plain text, etc.
44089
+ *
44090
+ * @param {State<MultiToken>} start parser start state
44091
+ * @param {string} input the original input used to generate the given tokens
44092
+ * @param {Token[]} tokens list of scanned tokens
44093
+ * @returns {MultiToken[]}
44094
+ */
44095
+ function run(start, input, tokens) {
44096
+ let len = tokens.length;
44097
+ let cursor = 0;
44098
+ let multis = [];
44099
+ let textTokens = [];
44100
+ while (cursor < len) {
44101
+ let state = start;
44102
+ let secondState = null;
44103
+ let nextState = null;
44104
+ let multiLength = 0;
44105
+ let latestAccepting = null;
44106
+ let sinceAccepts = -1;
44107
+ while (cursor < len && !(secondState = state.go(tokens[cursor].t))) {
44108
+ // Starting tokens with nowhere to jump to.
44109
+ // Consider these to be just plain text
44110
+ textTokens.push(tokens[cursor++]);
44111
+ }
44112
+ while (cursor < len && (nextState = secondState || state.go(tokens[cursor].t))) {
44113
+ // Get the next state
44114
+ secondState = null;
44115
+ state = nextState;
44116
+
44117
+ // Keep track of the latest accepting state
44118
+ if (state.accepts()) {
44119
+ sinceAccepts = 0;
44120
+ latestAccepting = state;
44121
+ } else if (sinceAccepts >= 0) {
44122
+ sinceAccepts++;
44123
+ }
44124
+ cursor++;
44125
+ multiLength++;
44126
+ }
44127
+ if (sinceAccepts < 0) {
44128
+ // No accepting state was found, part of a regular text token add
44129
+ // the first text token to the text tokens array and try again from
44130
+ // the next
44131
+ cursor -= multiLength;
44132
+ if (cursor < len) {
44133
+ textTokens.push(tokens[cursor]);
44134
+ cursor++;
44135
+ }
44136
+ } else {
44137
+ // Accepting state!
44138
+ // First close off the textTokens (if available)
44139
+ if (textTokens.length > 0) {
44140
+ multis.push(initMultiToken(Text$1, input, textTokens));
44141
+ textTokens = [];
44142
+ }
44143
+
44144
+ // Roll back to the latest accepting state
44145
+ cursor -= sinceAccepts;
44146
+ multiLength -= sinceAccepts;
44147
+
44148
+ // Create a new multitoken
44149
+ const Multi = latestAccepting.t;
44150
+ const subtokens = tokens.slice(cursor - multiLength, cursor);
44151
+ multis.push(initMultiToken(Multi, input, subtokens));
44152
+ }
44153
+ }
44154
+
44155
+ // Finally close off the textTokens (if available)
44156
+ if (textTokens.length > 0) {
44157
+ multis.push(initMultiToken(Text$1, input, textTokens));
44158
+ }
44159
+ return multis;
44160
+ }
44161
+
44162
+ /**
44163
+ * Utility function for instantiating a new multitoken with all the relevant
44164
+ * fields during parsing.
44165
+ * @param {new (value: string, tokens: Token[]) => MultiToken} Multi class to instantiate
44166
+ * @param {string} input original input string
44167
+ * @param {Token[]} tokens consecutive tokens scanned from input string
44168
+ * @returns {MultiToken}
44169
+ */
44170
+ function initMultiToken(Multi, input, tokens) {
44171
+ const startIdx = tokens[0].s;
44172
+ const endIdx = tokens[tokens.length - 1].e;
44173
+ const value = input.slice(startIdx, endIdx);
44174
+ return new Multi(value, tokens);
44175
+ }
44176
+
44177
+ const warn = typeof console !== 'undefined' && console && console.warn || (() => {});
44178
+ const warnAdvice = 'until manual call of linkify.init(). Register all schemes and plugins before invoking linkify the first time.';
44179
+
44180
+ // Side-effect initialization state
44181
+ const INIT = {
44182
+ scanner: null,
44183
+ parser: null,
44184
+ tokenQueue: [],
44185
+ pluginQueue: [],
44186
+ customSchemes: [],
44187
+ initialized: false
44188
+ };
44189
+
44190
+ /**
44191
+ * @typedef {{
44192
+ * start: State<string>,
44193
+ * tokens: { groups: Collections<string> } & typeof tk
44194
+ * }} ScannerInit
44195
+ */
44196
+
44197
+ /**
44198
+ * @typedef {{
44199
+ * start: State<MultiToken>,
44200
+ * tokens: typeof multi
44201
+ * }} ParserInit
44202
+ */
44203
+
44204
+ /**
44205
+ * @typedef {(arg: { scanner: ScannerInit }) => void} TokenPlugin
44206
+ */
44207
+
44208
+ /**
44209
+ * @typedef {(arg: { scanner: ScannerInit, parser: ParserInit }) => void} Plugin
44210
+ */
44211
+
44212
+ /**
44213
+ * De-register all plugins and reset the internal state-machine. Used for
44214
+ * testing; not required in practice.
44215
+ * @private
44216
+ */
44217
+ function reset() {
44218
+ State.groups = {};
44219
+ INIT.scanner = null;
44220
+ INIT.parser = null;
44221
+ INIT.tokenQueue = [];
44222
+ INIT.pluginQueue = [];
44223
+ INIT.customSchemes = [];
44224
+ INIT.initialized = false;
44225
+ }
44226
+
44227
+ /**
44228
+ * Detect URLs with the following additional protocol. Anything with format
44229
+ * "protocol://..." will be considered a link. If `optionalSlashSlash` is set to
44230
+ * `true`, anything with format "protocol:..." will be considered a link.
44231
+ * @param {string} protocol
44232
+ * @param {boolean} [optionalSlashSlash]
44233
+ */
44234
+ function registerCustomProtocol(scheme, optionalSlashSlash) {
44235
+ if (optionalSlashSlash === void 0) {
44236
+ optionalSlashSlash = false;
44237
+ }
44238
+ if (INIT.initialized) {
44239
+ warn(`linkifyjs: already initialized - will not register custom scheme "${scheme}" ${warnAdvice}`);
44240
+ }
44241
+ if (!/^[0-9a-z]+(-[0-9a-z]+)*$/.test(scheme)) {
44242
+ throw new Error('linkifyjs: incorrect scheme format.\n 1. Must only contain digits, lowercase ASCII letters or "-"\n 2. Cannot start or end with "-"\n 3. "-" cannot repeat');
44243
+ }
44244
+ INIT.customSchemes.push([scheme, optionalSlashSlash]);
44245
+ }
44246
+
44247
+ /**
44248
+ * Initialize the linkify state machine. Called automatically the first time
44249
+ * linkify is called on a string, but may be called manually as well.
44250
+ */
44251
+ function init$3() {
44252
+ // Initialize scanner state machine and plugins
44253
+ INIT.scanner = init$2(INIT.customSchemes);
44254
+ for (let i = 0; i < INIT.tokenQueue.length; i++) {
44255
+ INIT.tokenQueue[i][1]({
44256
+ scanner: INIT.scanner
44257
+ });
44258
+ }
44259
+
44260
+ // Initialize parser state machine and plugins
44261
+ INIT.parser = init$1(INIT.scanner.tokens);
44262
+ for (let i = 0; i < INIT.pluginQueue.length; i++) {
44263
+ INIT.pluginQueue[i][1]({
44264
+ scanner: INIT.scanner,
44265
+ parser: INIT.parser
44266
+ });
44267
+ }
44268
+ INIT.initialized = true;
44269
+ }
44270
+
44271
+ /**
44272
+ * Parse a string into tokens that represent linkable and non-linkable sub-components
44273
+ * @param {string} str
44274
+ * @return {MultiToken[]} tokens
44275
+ */
44276
+ function tokenize(str) {
44277
+ if (!INIT.initialized) {
44278
+ init$3();
44279
+ }
44280
+ return run(INIT.parser.start, str, run$1(INIT.scanner.start, str));
44281
+ }
44282
+
44283
+ /**
44284
+ * Find a list of linkable items in the given string.
44285
+ * @param {string} str string to find links in
44286
+ * @param {string | Opts} [type] either formatting options or specific type of
44287
+ * links to find, e.g., 'url' or 'email'
44288
+ * @param {Opts} [opts] formatting options for final output. Cannot be specified
44289
+ * if opts already provided in `type` argument
44290
+ */
44291
+ function find$1(str, type, opts) {
44292
+ if (type === void 0) {
44293
+ type = null;
44294
+ }
44295
+ if (opts === void 0) {
44296
+ opts = null;
44297
+ }
44298
+ if (type && typeof type === 'object') {
44299
+ if (opts) {
44300
+ throw Error(`linkifyjs: Invalid link type ${type}; must be a string`);
44301
+ }
44302
+ opts = type;
44303
+ type = null;
44304
+ }
44305
+ const options = new Options(opts);
44306
+ const tokens = tokenize(str);
44307
+ const filtered = [];
44308
+ for (let i = 0; i < tokens.length; i++) {
44309
+ const token = tokens[i];
44310
+ if (token.isLink && (!type || token.t === type)) {
44311
+ filtered.push(token.toFormattedObject(options));
44312
+ }
44313
+ }
44314
+ return filtered;
44315
+ }
44316
+
44317
+ function autolink$1(options) {
44318
+ return new Plugin({
44319
+ key: new PluginKey('autolink'),
44320
+ appendTransaction: (transactions, oldState, newState) => {
44321
+ const docChanges = transactions.some(transaction => transaction.docChanged) && !oldState.doc.eq(newState.doc);
44322
+ const preventAutolink = transactions.some(transaction => transaction.getMeta('preventAutolink'));
44323
+ if (!docChanges || preventAutolink) {
44324
+ return;
44325
+ }
44326
+ const { tr } = newState;
44327
+ const transform = combineTransactionSteps(oldState.doc, [...transactions]);
44328
+ const changes = getChangedRanges(transform);
44329
+ changes.forEach(({ newRange }) => {
44330
+ // Now let’s see if we can add new links.
44331
+ const nodesInChangedRanges = findChildrenInRange(newState.doc, newRange, node => node.isTextblock);
44332
+ let textBlock;
44333
+ let textBeforeWhitespace;
44334
+ if (nodesInChangedRanges.length > 1) {
44335
+ // Grab the first node within the changed ranges (ex. the first of two paragraphs when hitting enter).
44336
+ textBlock = nodesInChangedRanges[0];
44337
+ textBeforeWhitespace = newState.doc.textBetween(textBlock.pos, textBlock.pos + textBlock.node.nodeSize, undefined, ' ');
44338
+ }
44339
+ else if (nodesInChangedRanges.length
44340
+ // We want to make sure to include the block seperator argument to treat hard breaks like spaces.
44341
+ && newState.doc.textBetween(newRange.from, newRange.to, ' ', ' ').endsWith(' ')) {
44342
+ textBlock = nodesInChangedRanges[0];
44343
+ textBeforeWhitespace = newState.doc.textBetween(textBlock.pos, newRange.to, undefined, ' ');
44344
+ }
44345
+ if (textBlock && textBeforeWhitespace) {
44346
+ const wordsBeforeWhitespace = textBeforeWhitespace.split(' ').filter(s => s !== '');
44347
+ if (wordsBeforeWhitespace.length <= 0) {
44348
+ return false;
44349
+ }
44350
+ const lastWordBeforeSpace = wordsBeforeWhitespace[wordsBeforeWhitespace.length - 1];
44351
+ const lastWordAndBlockOffset = textBlock.pos + textBeforeWhitespace.lastIndexOf(lastWordBeforeSpace);
44352
+ if (!lastWordBeforeSpace) {
44353
+ return false;
44354
+ }
44355
+ find$1(lastWordBeforeSpace)
44356
+ .filter(link => link.isLink)
44357
+ // Calculate link position.
44358
+ .map(link => ({
44359
+ ...link,
44360
+ from: lastWordAndBlockOffset + link.start + 1,
44361
+ to: lastWordAndBlockOffset + link.end + 1,
44362
+ }))
44363
+ // ignore link inside code mark
44364
+ .filter(link => {
44365
+ if (!newState.schema.marks.code) {
44366
+ return true;
44367
+ }
44368
+ return !newState.doc.rangeHasMark(link.from, link.to, newState.schema.marks.code);
44369
+ })
44370
+ // validate link
44371
+ .filter(link => {
44372
+ if (options.validate) {
44373
+ return options.validate(link.value);
44374
+ }
44375
+ return true;
44376
+ })
44377
+ // Add link mark.
44378
+ .forEach(link => {
44379
+ if (getMarksBetween(link.from, link.to, newState.doc).some(item => item.mark.type === options.type)) {
44380
+ return;
44381
+ }
44382
+ tr.addMark(link.from, link.to, options.type.create({
44383
+ href: link.href,
44384
+ }));
44385
+ });
44386
+ }
44387
+ });
44388
+ if (!tr.steps.length) {
44389
+ return;
44390
+ }
44391
+ return tr;
44392
+ },
44393
+ });
44394
+ }
44395
+
44396
+ function clickHandler(options) {
44397
+ return new Plugin({
44398
+ key: new PluginKey('handleClickLink'),
44399
+ props: {
44400
+ handleClick: (view, pos, event) => {
44401
+ var _a, _b;
44402
+ if (event.button !== 0) {
44403
+ return false;
44404
+ }
44405
+ const attrs = getAttributes(view.state, options.type.name);
44406
+ const link = event.target;
44407
+ const href = (_a = link === null || link === void 0 ? void 0 : link.href) !== null && _a !== void 0 ? _a : attrs.href;
44408
+ const target = (_b = link === null || link === void 0 ? void 0 : link.target) !== null && _b !== void 0 ? _b : attrs.target;
44409
+ if (link && href) {
44410
+ if (view.editable) {
44411
+ window.open(href, target);
44412
+ }
44413
+ return true;
44414
+ }
44415
+ return false;
44416
+ },
44417
+ },
44418
+ });
44419
+ }
44420
+
44421
+ function pasteHandler(options) {
44422
+ return new Plugin({
44423
+ key: new PluginKey('handlePasteLink'),
44424
+ props: {
44425
+ handlePaste: (view, event, slice) => {
44426
+ var _a, _b;
44427
+ const { state } = view;
44428
+ const { selection } = state;
44429
+ // Do not proceed if in code block.
44430
+ if (state.doc.resolve(selection.from).parent.type.spec.code) {
44431
+ return false;
44432
+ }
44433
+ let textContent = '';
44434
+ slice.content.forEach(node => {
44435
+ textContent += node.textContent;
44436
+ });
44437
+ let isAlreadyLink = false;
44438
+ slice.content.descendants(node => {
44439
+ if (node.marks.some(mark => mark.type.name === options.type.name)) {
44440
+ isAlreadyLink = true;
44441
+ }
44442
+ });
44443
+ if (isAlreadyLink) {
44444
+ return;
44445
+ }
44446
+ const link = find$1(textContent).find(item => item.isLink && item.value === textContent);
44447
+ if (!selection.empty && options.linkOnPaste) {
44448
+ const pastedLink = (link === null || link === void 0 ? void 0 : link.href) || null;
44449
+ if (pastedLink) {
44450
+ options.editor.commands.setMark(options.type, { href: pastedLink });
44451
+ return true;
44452
+ }
44453
+ }
44454
+ const firstChildIsText = ((_a = slice.content.firstChild) === null || _a === void 0 ? void 0 : _a.type.name) === 'text';
44455
+ const firstChildContainsLinkMark = (_b = slice.content.firstChild) === null || _b === void 0 ? void 0 : _b.marks.some(mark => mark.type.name === options.type.name);
44456
+ if ((firstChildIsText && firstChildContainsLinkMark) || !options.linkOnPaste) {
44457
+ return false;
44458
+ }
44459
+ if (link && selection.empty) {
44460
+ options.editor.commands.insertContent(`<a href="${link.href}">${link.href}</a>`);
44461
+ return true;
44462
+ }
44463
+ const { tr } = state;
44464
+ let deleteOnly = false;
44465
+ if (!selection.empty) {
44466
+ deleteOnly = true;
44467
+ tr.delete(selection.from, selection.to);
44468
+ }
44469
+ let currentPos = selection.from;
44470
+ let fragmentLinks = [];
44471
+ slice.content.forEach(node => {
44472
+ fragmentLinks = find$1(node.textContent);
44473
+ tr.insert(currentPos - 1, node);
44474
+ if (fragmentLinks.length > 0) {
44475
+ deleteOnly = false;
44476
+ fragmentLinks.forEach(fragmentLink => {
44477
+ const linkStart = currentPos + fragmentLink.start;
44478
+ const linkEnd = currentPos + fragmentLink.end;
44479
+ const hasMark = tr.doc.rangeHasMark(linkStart, linkEnd, options.type);
44480
+ if (!hasMark) {
44481
+ tr.addMark(linkStart, linkEnd, options.type.create({ href: fragmentLink.href }));
44482
+ }
44483
+ });
44484
+ }
44485
+ currentPos += node.nodeSize;
44486
+ });
44487
+ const hasFragmentLinks = fragmentLinks.length > 0;
44488
+ if (tr.docChanged && !deleteOnly && hasFragmentLinks) {
44489
+ options.editor.view.dispatch(tr);
44490
+ return true;
44491
+ }
44492
+ return false;
44493
+ },
44494
+ },
44495
+ });
44496
+ }
44497
+
44498
+ const Link = Mark.create({
44499
+ name: 'link',
44500
+ priority: 1000,
44501
+ keepOnSplit: false,
44502
+ onCreate() {
44503
+ this.options.protocols.forEach(protocol => {
44504
+ if (typeof protocol === 'string') {
44505
+ registerCustomProtocol(protocol);
44506
+ return;
44507
+ }
44508
+ registerCustomProtocol(protocol.scheme, protocol.optionalSlashes);
44509
+ });
44510
+ },
44511
+ onDestroy() {
44512
+ reset();
44513
+ },
44514
+ inclusive() {
44515
+ return this.options.autolink;
44516
+ },
44517
+ addOptions() {
44518
+ return {
44519
+ openOnClick: true,
44520
+ linkOnPaste: true,
44521
+ autolink: true,
44522
+ protocols: [],
44523
+ HTMLAttributes: {
44524
+ target: '_blank',
44525
+ rel: 'noopener noreferrer nofollow',
44526
+ class: null,
44527
+ },
44528
+ validate: undefined,
44529
+ };
44530
+ },
44531
+ addAttributes() {
44532
+ return {
44533
+ href: {
44534
+ default: null,
44535
+ },
44536
+ target: {
44537
+ default: this.options.HTMLAttributes.target,
44538
+ },
44539
+ rel: {
44540
+ default: this.options.HTMLAttributes.rel,
44541
+ },
44542
+ class: {
44543
+ default: this.options.HTMLAttributes.class,
44544
+ },
44545
+ };
44546
+ },
44547
+ parseHTML() {
44548
+ return [{ tag: 'a[href]:not([href *= "javascript:" i])' }];
44549
+ },
44550
+ renderHTML({ HTMLAttributes }) {
44551
+ return ['a', mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0];
44552
+ },
44553
+ addCommands() {
44554
+ return {
44555
+ setLink: attributes => ({ chain }) => {
44556
+ return chain().setMark(this.name, attributes).setMeta('preventAutolink', true).run();
44557
+ },
44558
+ toggleLink: attributes => ({ chain }) => {
44559
+ return chain()
44560
+ .toggleMark(this.name, attributes, { extendEmptyMarkRange: true })
44561
+ .setMeta('preventAutolink', true)
44562
+ .run();
44563
+ },
44564
+ unsetLink: () => ({ chain }) => {
44565
+ return chain()
44566
+ .unsetMark(this.name, { extendEmptyMarkRange: true })
44567
+ .setMeta('preventAutolink', true)
44568
+ .run();
44569
+ },
44570
+ };
44571
+ },
44572
+ addProseMirrorPlugins() {
44573
+ const plugins = [];
44574
+ if (this.options.autolink) {
44575
+ plugins.push(autolink$1({
44576
+ type: this.type,
44577
+ validate: this.options.validate,
44578
+ }));
44579
+ }
44580
+ if (this.options.openOnClick) {
44581
+ plugins.push(clickHandler({
44582
+ type: this.type,
44583
+ }));
44584
+ }
44585
+ plugins.push(pasteHandler({
44586
+ editor: this.editor,
44587
+ type: this.type,
44588
+ linkOnPaste: this.options.linkOnPaste,
44589
+ }));
44590
+ return plugins;
44591
+ },
44592
+ });
44593
+
42465
44594
  const ListItem$1 = Node$1.create({
42466
44595
  name: 'listItem',
42467
44596
  addOptions() {
@@ -43048,6 +45177,35 @@ img.ProseMirror-separator {
43048
45177
  color: ${controlLabelDisabledFontColor};
43049
45178
  }
43050
45179
 
45180
+ ${
45181
+ /**
45182
+ * Custom anchor stylings can be removed once leveraging 'nimble-anchor' is supported.
45183
+ * See: https://github.com/ni/nimble/issues/1516
45184
+ */ ''}
45185
+ .ProseMirror a {
45186
+ color: ${linkFontColor};
45187
+ white-space: normal;
45188
+ ${
45189
+ /**
45190
+ * Setting 'pointer-events: none;' to restrict the user from opening a link using the right-click context menu: If the user manually edits
45191
+ * the link's text content, the 'href' attribute of the anchor tag will not be updated. If they attempt to open it using
45192
+ * the right-click context menu with 'Open in new tab/window,' it will still navigate to the link specified
45193
+ * in the 'href' attribute, which may create unnecessary confusion while trying to open the link.
45194
+ *
45195
+ * Using pointer-events: none to disable link interactions can be removed when hyperlink support is added.
45196
+ * see: https://github.com/ni/nimble/issues/1527
45197
+ */ ''}
45198
+ pointer-events: none;
45199
+ }
45200
+
45201
+ :host([disabled]) .ProseMirror a {
45202
+ color: ${bodyDisabledFontColor};
45203
+ fill: currentcolor;
45204
+ cursor: default;
45205
+ }
45206
+
45207
+ ${ /** End of anchor styles */''}
45208
+
43051
45209
  .footer-section {
43052
45210
  display: flex;
43053
45211
  justify-content: space-between;
@@ -56335,12 +58493,53 @@ img.ProseMirror-separator {
56335
58493
  'autolink',
56336
58494
  'escape'
56337
58495
  ]);
56338
- return new MarkdownParser(schema, supportedTokenizerRules, defaultMarkdownParser.tokens);
58496
+ supportedTokenizerRules.validateLink = href => /^https?:\/\//i.test(href);
58497
+ /**
58498
+ * In order to display encoded characters, non-ASCII characters, emojis, and other special characters in their original form,
58499
+ * we bypass the default normalization of link text in markdown-it. This is done because we support only "AutoLink" feature in CommonMark flavor.
58500
+ * "normalizeLinkText" method reference in markdown-it: https://github.com/markdown-it/markdown-it/blob/2b6cac25823af011ff3bc7628bc9b06e483c5a08/lib/index.js#L67C1-L86C2
58501
+ *
58502
+ * We can use the default normalization once hyperlink support is added.
58503
+ * See: https://github.com/ni/nimble/issues/1527
58504
+ */
58505
+ supportedTokenizerRules.normalizeLinkText = url => url;
58506
+ return new MarkdownParser(this.updatedSchema, supportedTokenizerRules, defaultMarkdownParser.tokens);
58507
+ }
58508
+ static getSchemaWithLinkConfiguration() {
58509
+ return new Schema({
58510
+ nodes: schema.spec.nodes,
58511
+ marks: {
58512
+ link: {
58513
+ attrs: {
58514
+ href: {},
58515
+ rel: { default: 'noopener noreferrer' }
58516
+ },
58517
+ // Inclusive can be updated when hyperlink support added
58518
+ // See: https://github.com/ni/nimble/issues/1527
58519
+ inclusive: false,
58520
+ // Excludes can be removed/enabled when hyperlink support added
58521
+ // See: https://github.com/ni/nimble/issues/1527
58522
+ excludes: '_',
58523
+ toDOM(node) {
58524
+ return [
58525
+ anchorTag,
58526
+ {
58527
+ href: node.attrs.href,
58528
+ rel: node.attrs.rel
58529
+ }
58530
+ ];
58531
+ }
58532
+ },
58533
+ em: schema.spec.marks.get('em'),
58534
+ strong: schema.spec.marks.get('strong')
58535
+ }
58536
+ });
56339
58537
  }
56340
58538
  }
56341
58539
  _a$1 = RichTextMarkdownParser;
58540
+ RichTextMarkdownParser.updatedSchema = _a$1.getSchemaWithLinkConfiguration();
56342
58541
  RichTextMarkdownParser.markdownParser = _a$1.initializeMarkdownParser();
56343
- RichTextMarkdownParser.domSerializer = DOMSerializer.fromSchema(schema);
58542
+ RichTextMarkdownParser.domSerializer = DOMSerializer.fromSchema(_a$1.updatedSchema);
56344
58543
 
56345
58544
  var _a;
56346
58545
  /**
@@ -56382,7 +58581,28 @@ img.ProseMirror-separator {
56382
58581
  };
56383
58582
  const marks = {
56384
58583
  italic: defaultMarkdownSerializer.marks.em,
56385
- bold: defaultMarkdownSerializer.marks.strong
58584
+ bold: defaultMarkdownSerializer.marks.strong,
58585
+ /**
58586
+ * When a user inserts an absolute link into the editor and then modifies it, the 'defaultMarkdownSerializer.marks.link' function
58587
+ * will detect whether it should be serialized as an autolink (<url>) or a hyperlink ([text](url)) in Markdown format by
58588
+ * comparing the link text with 'href'. Since our markdown-parser only supports the autolink format, we need to ensure that the
58589
+ * serializer also only supports autolink. Unfortunately, prosemirror-markdown does not offer a built-in way to update the
58590
+ * 'defaultMarkdownSerializer' for this purpose. Therefore, we had to create a modified implementation to enable support for
58591
+ * only autolink in serialization. This modified implementation will just load the link text content in between '<>' angular brackets
58592
+ * and ignores the 'href' part.
58593
+ *
58594
+ * Autolink markdown in CommonMark flavor: https://spec.commonmark.org/0.30/#autolinks
58595
+ * ProseMirror model reference: https://github.com/ProseMirror/prosemirror-markdown/blob/c7210d0e55c82bfb0b2f7cba5dffe804575fafb3/src/to_markdown.ts#L3C1-L26C2
58596
+ *
58597
+ * The defaultMarkdownSerializer can be used once hyperlink support is added:
58598
+ * See: https://github.com/ni/nimble/issues/1527
58599
+ */
58600
+ link: {
58601
+ open: '<',
58602
+ close: '>',
58603
+ escape: false,
58604
+ expelEnclosingWhitespace: true
58605
+ }
56386
58606
  };
56387
58607
  return new MarkdownSerializer(nodes, marks);
56388
58608
  }
@@ -56602,6 +58822,7 @@ img.ProseMirror-separator {
56602
58822
  return editor;
56603
58823
  }
56604
58824
  createTiptapEditor() {
58825
+ const customLink = this.getCustomLinkExtension();
56605
58826
  /**
56606
58827
  * For more information on the extensions for the supported formatting options, refer to the links below.
56607
58828
  * Tiptap marks: https://tiptap.dev/api/marks
@@ -56622,10 +58843,55 @@ img.ProseMirror-separator {
56622
58843
  Placeholder.configure({
56623
58844
  placeholder: '',
56624
58845
  showOnlyWhenEditable: false
58846
+ }),
58847
+ customLink.configure({
58848
+ // HTMLAttribute cannot be in camelCase as we want to match it with the name in Tiptap
58849
+ // eslint-disable-next-line @typescript-eslint/naming-convention
58850
+ HTMLAttributes: {
58851
+ rel: 'noopener noreferrer',
58852
+ target: null
58853
+ },
58854
+ autolink: true,
58855
+ openOnClick: false,
58856
+ // linkOnPaste can be enabled when hyperlink support added
58857
+ // See: https://github.com/ni/nimble/issues/1527
58858
+ linkOnPaste: false,
58859
+ validate: href => /^https?:\/\//i.test(href)
56625
58860
  })
56626
58861
  ]
56627
58862
  });
56628
58863
  }
58864
+ /**
58865
+ * Extending the default link mark schema defined in the TipTap.
58866
+ *
58867
+ * "excludes": https://prosemirror.net/docs/ref/#model.MarkSpec.excludes
58868
+ * "inclusive": https://prosemirror.net/docs/ref/#model.MarkSpec.inclusive
58869
+ * "parseHTML": https://tiptap.dev/guide/custom-extensions#parse-html
58870
+ * "renderHTML": https://tiptap.dev/guide/custom-extensions/#render-html
58871
+ */
58872
+ getCustomLinkExtension() {
58873
+ return Link.extend({
58874
+ // Excludes can be removed/enabled when hyperlink support added
58875
+ // See: https://github.com/ni/nimble/issues/1527
58876
+ excludes: '_',
58877
+ // Inclusive can be updated when hyperlink support added
58878
+ // See: https://github.com/ni/nimble/issues/1527
58879
+ inclusive: false,
58880
+ parseHTML() {
58881
+ // To load the `nimble-anchor` from the HTML parsed content by markdown-parser as links in the
58882
+ // Tiptap editor, the `parseHTML` of Link extension should return `anchorTag`. This is because the
58883
+ // link mark schema in `markdown-parser.ts` file uses `<nimble-anchor>` as anchor tag and not `<a>`.
58884
+ return [{ tag: anchorTag }];
58885
+ },
58886
+ // HTMLAttribute cannot be in camelCase as we want to match it with the name in Tiptap
58887
+ // eslint-disable-next-line @typescript-eslint/naming-convention
58888
+ renderHTML({ HTMLAttributes }) {
58889
+ // The below 'a' tag should be replaced with 'nimble-anchor' once the below issue is fixed.
58890
+ // https://github.com/ni/nimble/issues/1516
58891
+ return ['a', HTMLAttributes];
58892
+ }
58893
+ });
58894
+ }
56629
58895
  /**
56630
58896
  * This function takes the Fragment from parseMarkdownToDOM function and return the serialized string using XMLSerializer
56631
58897
  */
@@ -56809,15 +59075,6 @@ img.ProseMirror-separator {
56809
59075
  li > p:empty {
56810
59076
  display: none;
56811
59077
  }
56812
-
56813
- a {
56814
- word-break: break-all;
56815
- color: ${linkFontColor};
56816
- }
56817
-
56818
- a:active {
56819
- color: ${linkActiveFontColor};
56820
- }
56821
59078
  `;
56822
59079
 
56823
59080
  /**