@commentray/render 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/code-browser-client.bundle.js +5 -5
- package/dist/code-browser-scroll-sync.d.ts +7 -0
- package/dist/code-browser-scroll-sync.d.ts.map +1 -0
- package/dist/code-browser-scroll-sync.js +14 -0
- package/dist/code-browser-scroll-sync.js.map +1 -0
- package/dist/code-browser.d.ts +29 -0
- package/dist/code-browser.d.ts.map +1 -1
- package/dist/code-browser.js +102 -11
- package/dist/code-browser.js.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/markdown-pipeline.d.ts +23 -1
- package/dist/markdown-pipeline.d.ts.map +1 -1
- package/dist/markdown-pipeline.js +129 -1
- package/dist/markdown-pipeline.js.map +1 -1
- package/dist/package-version.d.ts +5 -0
- package/dist/package-version.d.ts.map +1 -0
- package/dist/package-version.js +14 -0
- package/dist/package-version.js.map +1 -0
- package/dist/side-by-side.d.ts +3 -0
- package/dist/side-by-side.d.ts.map +1 -1
- package/dist/side-by-side.js +4 -2
- package/dist/side-by-side.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
"use strict";(()=>{var T=class{static ToInt32Array(e){let t=new Int32Array(e.length);for(let r=0,s=e.length;r<s;r++)t[r]=e[r];return t}},F=class{static getHashCode(e){let t=5381,r=t;for(let s=0,i=e.length;s<i&&e[s]!="\0"&&(t=(t<<5)+t^e.charCodeAt(s),s!==i-1&&e[s+1]!=="\0");s+=2)r=(r<<5)+r^e.charCodeAt(s+1);return t+1566083941*r|0}},g=class{constructor(e){this.entries=void 0,this.entries=e!==void 0?e:new Map}add(e,t){if(this.entries.has(e))throw new Error(`A meta entry with key ${e} is already present.`);this.entries.set(e,t)}get(e){return this.entries.get(e)}get allEntries(){return this.entries}toJSON(){return{entries:Object.fromEntries(this.entries)}}},N=class{static mergeMeta(e){if(e.length===0)return new g;if(e.length===1)return e[0];let t=new Map;for(let s of e)for(let[i,n]of s.allEntries){let h=t.get(i);h===void 0?t.set(i,[n]):h.push(n)}let r=new Map;for(let[s,i]of t)if(i.length!==1){if(i.every(n=>typeof n=="number")){let n=i.reduce((h,o)=>h+o,0);r.set(s,n);continue}for(let n=0;n<i.length;n++)r.set(`${s}_${n}`,i[n])}else r.set(s,i[0]);return new g(r)}},Q=class{static isSurrogate(e){let t=e.charCodeAt(0);return t>=55296&&t<=57343}static isAlphanumeric(e){let t=e.charCodeAt(0);return t>=48&&t<=57||t>=65&&t<=90||t>=97&&t<=122}static isLowerAlpha(e){let t=e.charCodeAt(0);return t>=97&&t<=122}},H=class{constructor(e,t){this.usableSearchers=void 0,this.usableSearchers=new Map;for(let r of t)e.includes(r.type)&&this.usableSearchers.set(r.type,r)}has(e){return this.usableSearchers.has(e)}minQuality(e){return this.usableSearchers.get(e).minQuality}spec(e){return this.usableSearchers.get(e)}},z=class{constructor(e,t,r){this.matches=void 0,this.query=void 0,this.meta=void 0,this.matches=e,this.query=t,this.meta=r}},m,q;(function(a){a.Fuzzy="fuzzy",a.Substring="substring",a.Prefix="prefix"})(m||(m={}));var L=class{constructor(e,t){this.type=void 0,this.minQuality=void 0,this.type=e,this.minQuality=Math.max(0,t)}},R=class extends L{constructor(e){super(m.Fuzzy,e)}},b=class extends L{constructor(e){super(m.Substring,e)}},C=class extends L{constructor(e){super(m.Prefix,e)}},I=class{constructor(e,t=10,r=[new R(.3),new b(0),new C(0)]){this.string=void 0,this.topN=void 0,this.searchers=void 0,this.string=e,this.topN=Math.max(0,t),this.searchers=r}},V=class{constructor(e,t){this.removedEntities=void 0,this.meta=void 0,this.removedEntities=e,this.meta=t}},W=class{static mergeResults(e,t){let r=e.query,s=this.mergeMatches(e.matches,t.matches,r.topN),i=N.mergeMeta([e.meta,t.meta]);return new z(s,r,i)}static mergeMatches(e,t,r){if(t.length===0)return e;if(e.length===0)return t;let s=[...e,...t];return s.sort((i,n)=>i.quality>n.quality?-1:i.quality<n.quality?1:0),s.length<=r?s:s.slice(0,r)}},J=class{constructor(e,t,r){this.maxQueryLength=void 0,this.mainSearcher=void 0,this.secondarySearcher=void 0,this.maxQueryLength=e,this.mainSearcher=t,this.secondarySearcher=r}indexEntities(e,t,r){return this.secondarySearcher.indexEntities([],t,r),this.mainSearcher.indexEntities(e,t,r)}getMatches(e){return e.string?(e.string.length>this.maxQueryLength&&(e=new I(e.string.substring(0,this.maxQueryLength),e.topN,e.searchers)),W.mergeResults(this.mainSearcher.getMatches(e),this.secondarySearcher.getMatches(e))):new z([],e,new g)}tryGetTerms(e){let t=this.mainSearcher.tryGetTerms(e);return t!==null?t:this.secondarySearcher.tryGetTerms(e)}getTerms(){return this.mainSearcher.getTerms().concat(this.secondarySearcher.getTerms())}tryGetEntity(e){var t,r;return(t=(r=this.mainSearcher.tryGetEntity(e))!=null?r:this.secondarySearcher.tryGetEntity(e))!=null?t:null}getEntities(){return this.mainSearcher.getEntities().concat(this.secondarySearcher.getEntities())}removeEntities(e){let t=[];for(let s=0,i=e.length;s<i;s++)(this.mainSearcher.removeEntity(e[s])||this.secondarySearcher.removeEntity(e[s]))&&t.push(e[s]);let r=new g;return new V(t,r)}upsertEntities(e,t,r){let s=[],i=[];for(let n=0,h=e.length;n<h;n++){let o=e[n],c=t(o);this.tryUpdate(o,c,r)||(s.push(c),i.push(o))}return this.removeEntities(s),i.length>0?this.reindexSecondarySearcher(i,t,r):new g}reindexSecondarySearcher(e,t,r){let s=this.secondarySearcher.getEntities().concat(e);return this.secondarySearcher.indexEntities(s,t,r)}tryUpdate(e,t,r){return this.tryUpdateSearcher(e,t,r,this.mainSearcher)||this.tryUpdateSearcher(e,t,r,this.secondarySearcher)}tryUpdateSearcher(e,t,r,s){let i=s.tryGetTerms(t);if(i===null)return!1;if(this.termsAreEqual(i,r(e))){if(!s.replaceEntity(t,e,t))throw new Error(`Entity with id ${t} was not present.`);return!0}return!1}termsAreEqual(e,t){return e===t||e!=null&&t!=null&&e.length===t.length&&e.every((r,s)=>r===t[s])}removeEntity(e){return this.mainSearcher.removeEntity(e)||this.secondarySearcher.removeEntity(e)}replaceEntity(e,t,r){return this.mainSearcher.replaceEntity(e,t,r)||this.secondarySearcher.replaceEntity(e,t,r)}save(e){this.mainSearcher.save(e),this.secondarySearcher.save(e)}load(e){this.mainSearcher.load(e),this.secondarySearcher.load(e)}},X=class{constructor(e){this.dynamicSearcher=void 0,this.dynamicSearcher=e}removeEntities(e){let t=performance.now(),r=this.dynamicSearcher.removeEntities(e),s=Math.round(performance.now()-t);return r.meta.add("removalDuration",s),r}upsertEntities(e,t,r){let s=performance.now(),i=this.dynamicSearcher.upsertEntities(e,t,r),n=Math.round(performance.now()-s);return i.add("upsertDuration",n),i}indexEntities(e,t,r){let s=performance.now(),i=this.dynamicSearcher.indexEntities(e,t,r),n=Math.round(performance.now()-s);return i.add("indexingDurationTotal",n),i}getMatches(e){let t=performance.now(),r=this.dynamicSearcher.getMatches(e),s=Math.round(performance.now()-t);return r.meta.add("queryDuration",s),r}tryGetEntity(e){return this.dynamicSearcher.tryGetEntity(e)}getEntities(){return this.dynamicSearcher.getEntities()}tryGetTerms(e){return this.dynamicSearcher.tryGetTerms(e)}getTerms(){return this.dynamicSearcher.getTerms()}removeEntity(e){return this.dynamicSearcher.removeEntity(e)}replaceEntity(e,t,r){return this.dynamicSearcher.replaceEntity(e,t,r)}save(e){this.dynamicSearcher.save(e)}load(e){this.dynamicSearcher.load(e)}},Y=class{constructor(e,t,r){this.entity=void 0,this.quality=void 0,this.matchedString=void 0,this.entity=e,this.quality=t,this.matchedString=r}},Z=class{constructor(e){this.query=void 0,this.matchedIndexes=new Set,this.matches=[],this.meta=[],this.query=e}},k=class{constructor(e,t=0,r){this.string=void 0,this.minQuality=void 0,this.searcherType=void 0,this.string=e,this.minQuality=Math.max(0,Math.min(1,t)),this.searcherType=r}},_=class{constructor(e,t){this.stringSearcher=void 0,this.searcherTypes=void 0,this.entities=void 0,this.idToIndex=void 0,this.terms=void 0,this.termIndexToEntityIndex=void 0,this.entityIndexToFirstTermIndex=void 0,this.searchersAndQualityOffsets=[{searcherType:m.Prefix,qualityOffset:2},{searcherType:m.Substring,qualityOffset:1},{searcherType:m.Fuzzy,qualityOffset:0}],this.stringSearcher=e,this.searcherTypes=t,this.entities=[],this.idToIndex=new Map,this.terms=[],this.termIndexToEntityIndex=new Int32Array(0),this.entityIndexToFirstTermIndex=new Int32Array(0)}indexEntities(e,t,r){this.entities=[...e],this.idToIndex=new Map,this.terms=[];let s=[],i=[];for(let h=0,o=e.length;h<o;h++){this.idToIndex.set(t(e[h]),h);let c=r(e[h]);i.push(this.terms.length),this.terms.push(...c),s.push(...c.map(()=>h))}this.termIndexToEntityIndex=T.ToInt32Array(s),this.entityIndexToFirstTermIndex=T.ToInt32Array(i);let n=this.stringSearcher.index(this.terms);return n.add("numberOfEntities",this.entities.length),n.add("numberOfTerms",this.terms.length),n}getMatches(e){let t=new Z(e),r=new H(this.searcherTypes,e.searchers);for(let{searcherType:i,qualityOffset:n}of this.searchersAndQualityOffsets){if(e.topN==t.matches.length)break;r.has(i)&&this.addMatchesFromSearcher(t,r.spec(i),n)}let s=N.mergeMeta(t.meta);return new z(t.matches,e,s)}addMatchesFromSearcher(e,t,r){let s=Math.max(0,t.minQuality-r);if(s>1)return;let i=new k(e.query.string,s,t.type),n=this.stringSearcher.getMatches(i);this.addMatchesFromResult(e,n,r)}addMatchesFromResult(e,t,r){if(e.meta.push(t.meta),e.query.topN!==0)for(let s=0,i=t.matches.length;s<i;s++){let n=t.matches[s],h=this.termIndexToEntityIndex[n.index];if(!e.matchedIndexes.has(h)&&this.entities[h]!==null&&(e.matchedIndexes.add(h),e.matches.push(new Y(this.entities[h],n.quality+r,this.terms[n.index])),e.matches.length===e.query.topN))break}}tryGetEntity(e){let t=this.idToIndex.get(e);return t===void 0?null:this.entities[t]}getEntities(){return this.entities.filter(e=>e!==null)}tryGetTerms(e){let t=this.idToIndex.get(e);return t===void 0?null:this.terms.slice(this.entityIndexToFirstTermIndex[t],t===this.entities.length-1?this.terms.length:this.entityIndexToFirstTermIndex[t+1])}getTerms(){let e=[];for(let t=0,r=this.termIndexToEntityIndex.length;t<r;t++)this.entities[this.termIndexToEntityIndex[t]]!==null&&e.push(this.terms[t]);return e}removeEntity(e){let t=this.idToIndex.get(e);return t!==void 0&&(this.entities[t]=null,this.idToIndex.delete(e),!0)}replaceEntity(e,t,r){let s=this.idToIndex.get(e);return s!==void 0&&(this.entities[s]=t,this.idToIndex.delete(e),this.idToIndex.set(r,s),!0)}save(e){e.add(this.entities),e.add(this.idToIndex),e.add(this.terms),e.add(this.termIndexToEntityIndex),e.add(this.entityIndexToFirstTermIndex),this.stringSearcher.save(e)}load(e){this.entities=e.get(),this.idToIndex=e.get(),this.terms=e.get(),this.termIndexToEntityIndex=e.get(),this.entityIndexToFirstTermIndex=e.get(),this.stringSearcher.load(e)}},w=class{constructor(e,t){this.strings=void 0,this.meta=void 0,this.strings=e,this.meta=t}},ee=class{constructor(e,t){this.treatCharacterAsSpace=void 0,this.allowCharacter=void 0,this.numberOfSurrogateCharacters=0,this.treatCharacterAsSpace=e,this.allowCharacter=t}normalize(e){let t=new Array(e.length),r=0,s=!1,i=!1;for(let n=0,h=e.length;n<h;n++){let o=this.getNormalizedCharacter(e[n]);o!==""&&(o===" "?s=!0:(s&&i&&(t[r++]=" "),t[r++]=o,i=!0,s=!1))}return i?t.join(""):""}getNormalizedCharacter(e){return e===" "||this.treatCharacterAsSpace(e)?" ":this.isSurrogate(e)||!this.allowCharacter(e)?"":e.toLowerCase()}isSurrogate(e){return!!Q.isSurrogate(e)&&(this.numberOfSurrogateCharacters++,!0)}normalizeBulk(e){this.numberOfSurrogateCharacters=0;let t=e.map(s=>this.normalize(s)),r=new g;return r.add("numberOfSurrogateCharacters",this.numberOfSurrogateCharacters),new w(t,r)}},te=class{constructor(e){this.normalizationFunction=void 0,this.normalizationFunction=e}normalize(e){return this.normalizationFunction(e)}normalizeBulk(e){let t=e.map(r=>this.normalize(r));return new w(t,new g)}},re=class{constructor(e){this.normalizers=void 0,this.normalizers=e}normalize(e){for(let t=0,r=this.normalizers.length;t<r;t++)e=this.normalizers[t].normalize(e);return e}normalizeBulk(e){let t=new g;for(let r=0,s=this.normalizers.length;r<s;r++){let i=this.normalizers[r].normalizeBulk(e);e=i.strings;for(let n of i.meta.allEntries)t.add(n[0],n[1])}return new w(e,t)}},se=class{normalize(e){return e||""}normalizeBulk(e){let t=e.map(r=>this.normalize(r));return new w(t,new g)}},ie=class{constructor(e,t){this.normalizeVariationsAndInput=void 0,this.replacements=void 0,this.normalizeVariationsAndInput=t,this.replacements=[];for(let r of e){let s=new Map;for(let[i,n]of r)for(let h of n){let o=t(h);s.set(o,i)}this.replacements.push(s)}}normalize(e){e=this.normalizeVariationsAndInput(e);let t=new Array(e.length),r=0;for(let s=0,i=e.length;s<i;s++)for(let n of this.replacements){let h=n.get(e[s]);if(h!==void 0){t[r++]=h;break}t[r++]=e[s]}return t.join("")}normalizeBulk(e){let t=e.map(r=>this.normalize(r));return new w(t,new g)}},ne=class{static create(e){let t=new se,r=new ie(e.replacements,n=>n.toLowerCase().normalize("NFKC")),s=new te(n=>n.normalize("NFKD")),i=new ee(e.treatCharacterAsSpace,e.allowCharacter);return new re([t,r,s,i])}},D=class{constructor(e,t){this.index=void 0,this.quality=void 0,this.index=e,this.quality=t}},S=class{constructor(e,t,r){this.matches=void 0,this.query=void 0,this.meta=void 0,this.matches=e,this.query=t,this.meta=r}},ae=class{constructor(e){this.stringSearcher=void 0,this.distinctMapping=void 0,this.sortMapping=void 0,this.stringSearcher=e,this.distinctMapping=new Int32Array(0),this.sortMapping=new Int32Array(0)}index(e){let t=e.map((o,c)=>({term:o,index:c}));t.sort((o,c)=>o.term<c.term?-1:o.term>c.term?1:0),this.sortMapping=new Int32Array(t.length);for(let o=0,c=t.length;o<c;o++)this.sortMapping[o]=t[o].index;let r=[],s=[],i=0,n=null;for(let o=0,c=t.length;o<c;o++){let d=t[o].term;d!=n&&(r[i]=d,s[i]=o,i++),n=d}s[i++]=t.length,this.distinctMapping=T.ToInt32Array(s);let h=this.stringSearcher.index(r);return h.add("numberOfDistinctTerms",r.length),h}getMatches(e){let t=this.stringSearcher.getMatches(e),r=new Array(t.matches.length),s=0;return t.matches.forEach(i=>{let n=this.distinctMapping[i.index+1];for(let h=this.distinctMapping[i.index];h<n;h++)r[s++]=new D(this.sortMapping[h],i.quality)}),new S(r,e,t.meta)}save(e){e.add(this.distinctMapping),e.add(this.sortMapping),this.stringSearcher.save(e)}load(e){this.distinctMapping=e.get(),this.sortMapping=e.get(),this.stringSearcher.load(e)}},he=class{constructor(e,t){this.entitySearcher=void 0,this.searcherTypes=void 0,this.entitySearcher=e,this.searcherTypes=t}indexEntities(e,t,r){return this.entitySearcher.indexEntities(e,t,r)}getMatches(e){let t=new H(this.searcherTypes,e.searchers);if(e.topN>200)return this.entitySearcher.getMatches(e);if(e.string.length<=3&&t.has(m.Prefix)&&t.minQuality(m.Prefix)<2.2){let r=new I(e.string,e.topN,[new C(2.3)]),s=this.entitySearcher.getMatches(r);if(s.matches.length==e.topN)return new z(s.matches,e,s.meta)}if(e.string.length<=3&&!t.has(m.Prefix)&&t.has(m.Substring)&&t.minQuality(m.Substring)<1.2){let r=new I(e.string,e.topN,[new b(1.3)]),s=this.entitySearcher.getMatches(r);if(s.matches.length==e.topN)return new z(s.matches,e,s.meta)}return this.entitySearcher.getMatches(e)}tryGetEntity(e){return this.entitySearcher.tryGetEntity(e)}getEntities(){return this.entitySearcher.getEntities()}tryGetTerms(e){return this.entitySearcher.tryGetTerms(e)}getTerms(){return this.entitySearcher.getTerms()}removeEntity(e){return this.entitySearcher.removeEntity(e)}replaceEntity(e,t,r){return this.entitySearcher.replaceEntity(e,t,r)}save(e){return this.entitySearcher.save(e)}load(e){return this.entitySearcher.load(e)}},P=class{constructor(){this.ids=void 0,this.frequencies=void 0,this.ids=[],this.frequencies=[]}addId(e,t){this.ids.push(e),this.frequencies.push(t)}seal(){this.ids=T.ToInt32Array(this.ids),this.frequencies=T.ToInt32Array(this.frequencies)}get length(){return this.ids.length}save(e){e.add(this.ids),e.add(this.frequencies)}load(e){this.ids=e.get(),this.frequencies=e.get()}},A=class{constructor(){this.ngramToTermIds=void 0,this.ngramToTermIds=new Map}add(e,t,r){let s=this.ngramToTermIds.get(e);s||(s=new P,this.ngramToTermIds.set(e,s)),s.addId(t,r)}seal(){for(let e of this.ngramToTermIds.values())e.seal()}getIds(e){return this.ngramToTermIds.get(e)}get size(){return this.ngramToTermIds.size}save(e){e.add(this.ngramToTermIds.size);for(let[t,r]of this.ngramToTermIds)e.add(t),r.save(e)}load(e){let t=e.get();for(let r=0;r<t;r++){let s=e.get(),i=new P;i.load(e),this.ngramToTermIds.set(s,i)}}},oe=class{static ComputeJaccardCoefficient(e,t,r){return r/(e+t-r)}static ComputeOverlapMaxCoefficient(e,t,r){return r/Math.max(e,t)}},ce=class{constructor(e){this.ngramComputer=void 0,this.invertedIndex=void 0,this.numberOfNgrams=void 0,this.commonNgramCounts=void 0,this.ngramComputer=e,this.invertedIndex=new A,this.numberOfNgrams=new Int32Array(0),this.commonNgramCounts=new Int32Array(0)}index(e){let t=performance.now();this.invertedIndex=new A,this.commonNgramCounts=new Int32Array(e.length),this.numberOfNgrams=new Int32Array(e.length);let r=0;for(let n=0,h=e.length;n<h;n++){let o=e[n];if(!this.isValidTerm(o)){this.numberOfNgrams[n]=0,r++;continue}let c=this.ngramComputer.computeNgrams(o);this.numberOfNgrams[n]=c.length;let d=this.getNgramsToFrequency(c);for(let[l,u]of d)this.invertedIndex.add(l,n,u)}this.invertedIndex.seal();let s=Math.round(performance.now()-t),i=new g;return i.add("numberOfInvalidTerms",r),i.add("indexingDurationFuzzySearcher",s),i}isValidTerm(e){return e!=null&&e.trim()!==""}getMatches(e){if(this.invertedIndex.size===0)return new S([],e,new g);let t=this.ngramComputer.computeNgrams(e.string),r=this.getNgramsToFrequency(t),s=t.length;this.computeCommonNgramCounts(r);let i=this.getMatchesFromCommonNgrams(s,e.minQuality);return new S(i,e,new g)}computeCommonNgramCounts(e){this.commonNgramCounts.fill(0);for(let[t,r]of e){let s=this.invertedIndex.getIds(t);if(s!=null)for(let i=0,n=s.length;i<n;i++)this.commonNgramCounts[s.ids[i]]+=Math.min(r,s.frequencies[i])}}getNgramsToFrequency(e){let t=new Map;for(let r=0,s=e.length;r<s;r++){let i=e[r],n=t.get(i);t.set(i,n!==void 0?n+1:1)}return t}getMatchesFromCommonNgrams(e,t){let r=[];for(let s=0,i=this.numberOfNgrams.length;s<i;s++){let n=oe.ComputeOverlapMaxCoefficient(e,this.numberOfNgrams[s],this.commonNgramCounts[s]);n>t&&r.push(new D(s,n))}return r}save(e){this.invertedIndex.save(e),e.add(this.numberOfNgrams)}load(e){this.invertedIndex=new A,this.invertedIndex.load(e),this.numberOfNgrams=e.get(),this.commonNgramCounts=new Int32Array(this.numberOfNgrams.length)}},de=class{constructor(e,t){this.stringSearcher=void 0,this.penaltyFactor=void 0,this.hashCodes=void 0,this.stringSearcher=e,this.penaltyFactor=1-t,this.hashCodes=new Int32Array(0)}index(e){this.hashCodes=new Int32Array(e.length);for(let t=0,r=e.length;t<r;t++)this.hashCodes[t]=F.getHashCode(e[t]);return this.stringSearcher.index(e)}getMatches(e){let t=F.getHashCode(e.string),r=this.stringSearcher.getMatches(e),s=r.matches.map(i=>this.penalizeMatch(i,t)).filter(i=>i.quality>=e.minQuality);return new S(s,r.query,r.meta)}penalizeMatch(e,t){return e.quality*=this.hashCodes[e.index]===t?1:this.penaltyFactor,e}save(e){e.add(this.hashCodes),this.stringSearcher.save(e)}load(e){this.hashCodes=e.get(),this.stringSearcher.load(e)}},ue=class{constructor(e,t){this.ngramN=void 0,this.transformNgram=void 0,this.ngramN=e,this.transformNgram=t??(r=>r)}computeNgrams(e){if(e.length===0)return[];if(e.length<=this.ngramN){let r=this.transformNgram(e);return r?[r]:[]}let t=[];for(let r=0,s=this.maximumNumberOfNgrams(e);r<s;r++){let i=this.transformNgram(e.substring(r,r+this.ngramN));i&&t.push(i)}return t}maximumNumberOfNgrams(e){return Math.max(e.length-this.ngramN+1,e.length>0?1:0)}},le=class{constructor(e,t,r){this.paddingLeft=void 0,this.paddingRight=void 0,this.paddingMiddle=void 0,this.paddingLeft=e,this.paddingRight=t,this.paddingMiddle=r}normalize(e){return e&&`${this.paddingLeft}${e.split(" ").join(this.paddingMiddle)}${this.paddingRight}`}normalizeBulk(e){let t=e.map(s=>this.normalize(s)),r=new g;return new w(t,r)}},$=class{};$.Value=new Map([["a",["\u1D8F","\u2C65","\u0251","\u1D00","\u0250","\u0252"]],["aa",["\xE5","\uA733"]],["ae",["\xE4","\xE6","\u1D01","\u1D2D","\u1D46","\u01FD","\u01E3","\u1D02"]],["ao",["\uA735"]],["au",["\uA737"]],["av",["\uA739","\uA73B"]],["ay",["\uA73D"]],["b",["\u0180","\u0253","\u0183","\u1D6C","\u1D80","\u0299"]],["c",["\u023C","\u0188","\u0255","\u1D04","\uA73F","\u2184"]],["d",["\u0111","\xF0","\u0256","\u0257","\u018C","\u1D6D","\u1D81","\u1D91","\u0221","\u1D05","\uA77A"]],["db",["\u0238"]],["e",["\u1D92","\u0247","\u2C78","\u1D07","\u0259","\u01DD","\u025B"]],["eo",["\u1D14"]],["f",["\u0192","\u1D6E","\u1D82","\uA730","\uA77C"]],["g",["\u01E5","\u0260","\u1D83","\u0262","\u021D","\u014B","\uA7A1","\u1D79","\uA77F"]],["h",["\u0127","\u2C68","\u0266","\u029C","\u0303","\u0267","\u2C76","\u0265"]],["hv",["\u0195"]],["i",["\u0268","\u1D7B","\u1D96","\u0131","\u026A","\u0269"]],["j",["\u0249","\u0237","\u029D","\u025F","\u0284","\u1D0A"]],["k",["\u0199","\u2C6A","\u1D84","\uA741","\u1D0B","\uA743","\uA745","\uA7A3"]],["l",["\u0142","\u019A","\u2C61","\u026B","\u026C","\u1D85","\u026D","\u0234","\u029F","\uA749","\uA781","\uA747"]],["m",["\u1D6F","\u1D86","\u0271","\u1D0D","\u026F"]],["n",["\u0272","\u019E","\u1D70","\u1D87","\u0273","\u0235","\u0274","\uA791","\uA7A5"]],["o",["\xF8","\u01FF","\u0275","\u0254","\u2C7A","\u1D0F","\uA74B","\uA74D"]],["oe",["\xF6","\u0153"]],["oi",["\u01A3"]],["oo",["\uA74F"]],["ou",["\u0223"]],["p",["\u1D7D","\u01A5","\u1D71","\u1D88","\u1D18","\u01BF","\uA751","\uA753","\uA755"]],["q",["\u024B","\u02A0","\uA757","\uA759"]],["qp",["\u0239"]],["r",["\u024D","\u027D","\uA75B","\u1D72","\u1D89","\u027C","\u027E","\u1D73","\u0280","\u0279","\u0281","\uA7A7","\uA783"]],["s",["\u1D74","\u1D8A","\u0282","\u023F","\uA731","\u0283","\uA7A9","\uA785","\u017F"]],["ss",["\xDF"]],["t",["\u0167","\u2C66","\u01AD","\u0288","\u1D75","\u01AB","\u0236","\u1D1B","\uA787"]],["th",["\xFE"]],["tz",["\uA729"]],["u",["\u0289","\u028A","\u1D7E","\u1D1C","\u1D99"]],["ue",["\xFC","\u1D6B"]],["v",["\u028B","\u1D8C","\u2C71","\u2C74","\u1D20","\u028C","\uA75F"]],["vy",["\uA761"]],["w",["\u2C73","\u1D21","\u028D"]],["x",["\u1D8D"]],["y",["\u024F","\u01B4","\u028F","\u1EFF"]],["z",["\u01B6","\u0225","\u2C6C","\u1D76","\u1D8E","\u0290","\u0291","\u0240","\u1D22","\u0292","\u01B9","\uA763"]]]);var G=class a{constructor(e,t,r){this.replacements=void 0,this.treatCharacterAsSpace=void 0,this.allowCharacter=void 0,this.replacements=e,this.treatCharacterAsSpace=t,this.allowCharacter=r}static createDefaultConfig(){let e=new Set(["_","-","\u2013","/",","," "]);return new a([$.Value],t=>e.has(t),t=>Q.isAlphanumeric(t))}},B=class{constructor(e,t,r="normalizationDuration"){this.stringSearcher=void 0,this.normalizer=void 0,this.normalizationDurationMetaKey=void 0,this.stringSearcher=e,this.normalizer=t,this.normalizationDurationMetaKey=r}index(e){let t=performance.now(),r=this.normalizer.normalizeBulk(e),s=Math.round(performance.now()-t),i=this.stringSearcher.index(r.strings);i.add(this.normalizationDurationMetaKey,s);for(let n of r.meta.allEntries)i.add(n[0],n[1]);return i}getMatches(e){let t=new k(this.normalizer.normalize(e.string),e.minQuality,e.searcherType),r=this.stringSearcher.getMatches(t);return new S(r.matches,e,r.meta)}save(e){this.stringSearcher.save(e)}load(e){this.stringSearcher.load(e)}},me=class{constructor(e){this.suffixArraySearcher=void 0,this.suffixArraySearcher=e}index(e){return this.suffixArraySearcher.index(e)}getMatches(e){if(!e.string)return new S([],e,new g);let t=this.modifyQueryString(e.string),r=new k(t,e.minQuality,e.searcherType);return this.suffixArraySearcher.getMatches(r,e.string.length)}modifyQueryString(e){return`${this.suffixArraySearcher.separator}${e}`}save(e){this.suffixArraySearcher.save(e)}load(e){this.suffixArraySearcher.load(e)}},ge=class{constructor(e,t,r){this.prefixSearcher=void 0,this.substringSearcher=void 0,this.fuzzySearcher=void 0,this.prefixSearcher=e,this.substringSearcher=t,this.fuzzySearcher=r}index(e){let t=[];if(this.prefixSearcher&&!this.substringSearcher){let r=this.prefixSearcher.index(e);t.push(r)}if(this.substringSearcher){let r=this.substringSearcher.index(e);t.push(r)}if(this.fuzzySearcher){let r=this.fuzzySearcher.index(e);t.push(r)}return N.mergeMeta(t)}getMatches(e){if(!e.searcherType)throw new Error("SearcherSwitch requires a searcher type.");switch(e.searcherType){case m.Prefix:if(!this.prefixSearcher)throw new Error("No prefix searcher has been indexed.");return this.prefixSearcher.getMatches(e);case m.Substring:if(!this.substringSearcher)throw new Error("No substring searcher has been indexed.");return this.substringSearcher.getMatches(e);case m.Fuzzy:if(!this.fuzzySearcher)throw new Error("No fuzzy searcher has been indexed.");return this.fuzzySearcher.getMatches(e);default:throw new Error(`Unknown searcher type: ${e.searcherType}`)}}save(e){this.prefixSearcher&&!this.substringSearcher&&this.prefixSearcher.save(e),this.substringSearcher&&this.substringSearcher.save(e),this.fuzzySearcher&&this.fuzzySearcher.save(e)}load(e){this.prefixSearcher&&!this.substringSearcher&&this.prefixSearcher.load(e),this.substringSearcher&&this.substringSearcher.load(e),this.fuzzySearcher&&this.fuzzySearcher.load(e)}};(function(a){a.QualityAndIndex="qualityAndIndex",a.QualityAndMatchedString="qualityAndMatchedString"})(q||(q={}));var fe=class{constructor(e,t){this.sortOrder=void 0,this.entitySearcher=void 0,this.collator=new Intl.Collator(void 0,{numeric:!0}),this.sortOrder=e,this.entitySearcher=t}indexEntities(e,t,r){return this.entitySearcher.indexEntities(e,t,r)}getMatches(e){let t=this.entitySearcher.getMatches(e);switch(this.sortOrder){case q.QualityAndIndex:return t;case q.QualityAndMatchedString:return this.sortMatchesByQualityAndMatchedString(t.matches),t;default:throw new Error(`Unsupported sort order: ${this.sortOrder}`)}}sortMatchesByQualityAndMatchedString(e){e.sort((t,r)=>t.quality>r.quality?-1:t.quality<r.quality?1:this.collator.compare(t.matchedString,r.matchedString))}tryGetEntity(e){return this.entitySearcher.tryGetEntity(e)}getEntities(){return this.entitySearcher.getEntities()}tryGetTerms(e){return this.entitySearcher.tryGetTerms(e)}getTerms(){return this.entitySearcher.getTerms()}save(e){this.entitySearcher.save(e)}load(e){this.entitySearcher.load(e)}removeEntity(e){return this.entitySearcher.removeEntity(e)}replaceEntity(e,t,r){return this.entitySearcher.replaceEntity(e,t,r)}},ye=class{constructor(e){this.stringSearcher=void 0,this.stringSearcher=e}index(e){return this.stringSearcher.index(e)}getMatches(e){let t=this.stringSearcher.getMatches(e);return t.matches.sort(this.compareMatchesByQualityAndIndex),t}compareMatchesByQualityAndIndex(e,t){return e.quality>t.quality?-1:e.quality<t.quality?1:e.index<t.index?-1:e.index>t.index?1:0}save(e){this.stringSearcher.save(e)}load(e){this.stringSearcher.load(e)}},O=class{static compareOrdinal(e,t,r,s,i){let n=Math.min(t+i,e.length),h=Math.min(s+i,r.length),o=t,c=s;for(;o<n&&c<h;){let u=e.charCodeAt(o),x=r.charCodeAt(c);if(u<x)return-1;if(u>x)return 1;o++,c++}let d=n-t,l=h-s;return d===l?0:d<l?-1:1}},pe=class a{static create(e){if(e==null)throw new Error("Input string cannot be null.");let t=new a(e);return t.FormInitialChains(),t.BuildSufixArray(),t.sa}constructor(e){this.inputString=void 0,this.eoc=2147483647,this.sa=void 0,this.isa=void 0,this.chainHeadsDict=void 0,this.chainStack=[],this.subChains=[],this.nextRank=1,this.inputString=e;let t=e.length;this.sa=new Int32Array(t),this.isa=new Int32Array(t),this.chainHeadsDict=new Map}FormInitialChains(){this.FindInitialChains(),this.SortAndPushSubchains()}FindInitialChains(){for(let e=0;e<this.inputString.length;e++){let t=this.inputString.charCodeAt(e),r=this.chainHeadsDict.get(t);this.isa[e]=r!==void 0?r:this.eoc,this.chainHeadsDict.set(t,e)}for(let e of this.chainHeadsDict.values()){let t=new U(e,1);this.subChains.push(t)}}BuildSufixArray(){for(;this.chainStack.length>0;){let e=this.chainStack.pop();this.isa[e.head]===this.eoc?this.RankSuffix(e.head):this.RefineChainWithInductionSorting(e)}}RankSuffix(e){this.isa[e]=-this.nextRank,this.sa[this.nextRank-1]=e,this.nextRank++}RefineChainWithInductionSorting(e){let t=[];for(this.chainHeadsDict.clear(),this.subChains=[];e.head!==this.eoc;){let r=this.isa[e.head];if(e.head+e.length>this.inputString.length-1)this.RankSuffix(e.head);else if(this.isa[e.head+e.length]<0){let s=new Se(e.head,-this.isa[e.head+e.length]);t.push(s)}else this.ExtendChain(e);e.head=r}this.SortAndPushSubchains(),this.SortAndRankNotedSuffixes(t)}ExtendChain(e){let t=this.inputString.charCodeAt(e.head+e.length);if(this.chainHeadsDict.has(t))this.isa[this.chainHeadsDict.get(t)]=e.head,this.isa[e.head]=this.eoc;else{this.isa[e.head]=this.eoc;let r=new U(e.head,e.length+1);this.subChains.push(r)}this.chainHeadsDict.set(t,e.head)}SortAndRankNotedSuffixes(e){e.sort((t,r)=>t.rank-r.rank);for(let t=0;t<e.length;t++)this.RankSuffix(e[t].head)}SortAndPushSubchains(){this.subChains.sort((e,t)=>{let r=Math.min(e.length,t.length);return O.compareOrdinal(this.inputString,e.head,this.inputString,t.head,r)});for(let e=this.subChains.length-1;e>=0;e--)this.chainStack.push(this.subChains[e])}},Se=class{constructor(e,t){this.head=void 0,this.rank=void 0,this.head=e,this.rank=t}},U=class{constructor(e,t){this.head=void 0,this.length=void 0,this.head=e,this.length=t}},ve=class{constructor(e){this.separator=void 0,this.str=void 0,this.suffixArray=void 0,this.indexToTermIndex=void 0,this.termLengths=void 0,this.separator=e,this.str="",this.suffixArray=new Int32Array(0),this.indexToTermIndex=new Int32Array(0),this.termLengths=new Int32Array(0)}index(e){let t=performance.now();this.str=e.length>0?this.separator+e.join(this.separator)+this.separator:"",this.suffixArray=pe.create(this.str),this.indexToTermIndex=new Int32Array(this.suffixArray.length),this.termLengths=new Int32Array(e.length);let r=0;for(let n=0;n<e.length;n++){this.termLengths[n]=e[n].length;for(let h=0;h<=e[n].length;h++)this.indexToTermIndex[r++]=n}this.indexToTermIndex[r++]=-1;let s=Math.round(performance.now()-t),i=new g;return i.add("indexingDurationSuffixArraySearcher",s),i}getMatches(e,t){if(!e.string)return new S([],e,new g);let[r,s]=this.GetPositionsInSuffixArray(e.string),i=new Int32Array(s-r),n=new Set,h=0;for(let d=r;d<s;d++){let l=this.indexToTermIndex[this.suffixArray[d]];n.has(l)||(n.add(l),i[h++]=l)}let o=[];t=t??e.string.length;let c=0;for(let d=0;d<h;d++)c=this.computeQuality(t,this.termLengths[i[d]]),c>e.minQuality&&o.push(new D(i[d],c));return new S(o,e,new g)}computeQuality(e,t){return e/t}GetPositionsInSuffixArray(e){let t=0,r=this.suffixArray.length,s=0;for(;t<r;)s=Math.floor((t+r)/2),O.compareOrdinal(e,0,this.str,this.suffixArray[s],e.length)>0?t=s+1:r=s;let i=t;for(r=this.suffixArray.length;t<r;)s=Math.floor((t+r)/2),O.compareOrdinal(e,0,this.str,this.suffixArray[s],e.length)==0?t=s+1:r=s;return[i,r]}save(e){e.add(this.str),e.add(this.suffixArray),e.add(this.indexToTermIndex),e.add(this.termLengths)}load(e){this.str=e.get(),this.suffixArray=e.get(),this.indexToTermIndex=e.get(),this.termLengths=e.get()}},j=class{static createSearcher(e){let t=this.createDefaultNormalizer(e),r=this.tryCreateFuzzySearcher(e),s=this.tryCreateSubstringSearcher(e),i=this.tryCreatePrefixSearcher(e,s),n=new ge(i,s,r);n=new ae(n),n=new ye(n),n=new B(n,t,"normalizationDurationDefault");let h=new _(n,e.searcherTypes);return h=new he(h,e.searcherTypes),h=new fe(e.sortOrder,h),h}static createDefaultNormalizer(e){let t=new Set;e.fuzzySearchConfig&&(e.fuzzySearchConfig.paddingLeft.split("").forEach(s=>t.add(s)),e.fuzzySearchConfig.paddingRight.split("").forEach(s=>t.add(s)),e.fuzzySearchConfig.paddingMiddle.split("").forEach(s=>t.add(s))),e.substringSearchConfig&&e.substringSearchConfig.suffixArraySeparator.split("").forEach(s=>t.add(s));let r=new G(e.normalizerConfig.replacements,e.normalizerConfig.treatCharacterAsSpace,s=>e.normalizerConfig.allowCharacter(s)&&!t.has(s));return ne.create(r)}static tryCreateFuzzySearcher(e){if(!e.searcherTypes.includes(m.Fuzzy))return null;if(e.fuzzySearchConfig===void 0)throw new Error("Unable to create fuzzy searcher: No fuzzy search config provided.");return this.createFuzzySearcher(e.fuzzySearchConfig)}static createFuzzySearcher(e){let t=new ue(e.ngramN,e.transformNgram),r=new le(e.paddingLeft,e.paddingRight,e.paddingMiddle),s=new ce(t);return s=new de(s,e.inequalityPenalty),s=new B(s,r,"normalizationDurationNgrams"),s}static tryCreateSubstringSearcher(e){if(!e.searcherTypes.includes(m.Substring))return null;if(e.substringSearchConfig===void 0)throw new Error("Unable to create substring searcher: No substring search config provided.");return this.createSubstringSearcher(e.substringSearchConfig)}static createSubstringSearcher(e){return new ve(e.suffixArraySeparator)}static tryCreatePrefixSearcher(e,t){if(!e.searcherTypes.includes(m.Prefix))return null;if(e.substringSearchConfig===void 0)throw new Error("Unable to create prefix searcher: No substring search config provided.");return this.createPrefixSearcher(e.substringSearchConfig,t)}static createPrefixSearcher(e,t){return t===null&&(t=this.createSubstringSearcher(e)),new me(t)}},we=class a{constructor(e,t,r,s,i,n){this.paddingLeft=void 0,this.paddingRight=void 0,this.paddingMiddle=void 0,this.ngramN=void 0,this.transformNgram=void 0,this.inequalityPenalty=void 0,this.paddingLeft=e,this.paddingRight=t,this.paddingMiddle=r,this.ngramN=s,this.transformNgram=i,this.inequalityPenalty=n}static createDefaultConfig(){return new a("$$","!","!$$",3,e=>e.endsWith("$")?null:e.indexOf("$")===-1?e.split("").sort().join(""):e,.05)}};var xe=class a{constructor(e){this.suffixArraySeparator=void 0,this.suffixArraySeparator=e}static createDefaultConfig(){return new a("$")}},Te=class a{constructor(e,t,r,s,i,n){this.searcherTypes=void 0,this.maxQueryLength=void 0,this.sortOrder=void 0,this.normalizerConfig=void 0,this.fuzzySearchConfig=void 0,this.substringSearchConfig=void 0,this.searcherTypes=e,this.maxQueryLength=t,this.sortOrder=r,this.normalizerConfig=s,this.fuzzySearchConfig=i,this.substringSearchConfig=n}static createDefaultConfig(){let e=[m.Fuzzy,m.Substring,m.Prefix],t=q.QualityAndMatchedString,r=G.createDefaultConfig(),s=we.createDefaultConfig(),i=xe.createDefaultConfig();return new a(e,150,t,r,s,i)}},K=class{static createSearcher(e){let t=j.createSearcher(e),r=j.createSearcher(e),s=new J(e.maxQueryLength,t,r);return s=new X(s),s}static createDefaultSearcher(){let e=Te.createDefaultConfig();return this.createSearcher(e)}};function ze(a,e){let t=e.map(o=>o.trim()).filter(Boolean);if(t.length===0)return[];let r=a.toLowerCase(),s=t.map(o=>o.toLowerCase()),i=[],n=0,h=0;for(;n<a.length&&h<400;){let o=n,c=-1,d=!0;for(let l of s){if(l.length===0)continue;let u=r.indexOf(l,o);if(u<0){d=!1;break}c<0&&(c=u),o=u+l.length}if(!d||c<0)break;i.push({start:c,end:o}),h++,n=c+1}return i}function Ie(a,e){let t=Math.max(0,Math.min(e,a.length)),r=0;for(let s=0;s<t;s++)a[s]===`
|
|
2
|
-
`&&r++;return r}function
|
|
3
|
-
`);return e<0||e>=t.length?"":t[e]??""}function
|
|
4
|
-
`),
|
|
5
|
-
`).map((
|
|
1
|
+
"use strict";(()=>{var b=class{static ToInt32Array(e){let t=new Int32Array(e.length);for(let r=0,s=e.length;r<s;r++)t[r]=e[r];return t}},O=class{static getHashCode(e){let t=5381,r=t;for(let s=0,i=e.length;s<i&&e[s]!="\0"&&(t=(t<<5)+t^e.charCodeAt(s),s!==i-1&&e[s+1]!=="\0");s+=2)r=(r<<5)+r^e.charCodeAt(s+1);return t+1566083941*r|0}},m=class{constructor(e){this.entries=void 0,this.entries=e!==void 0?e:new Map}add(e,t){if(this.entries.has(e))throw new Error(`A meta entry with key ${e} is already present.`);this.entries.set(e,t)}get(e){return this.entries.get(e)}get allEntries(){return this.entries}toJSON(){return{entries:Object.fromEntries(this.entries)}}},N=class{static mergeMeta(e){if(e.length===0)return new m;if(e.length===1)return e[0];let t=new Map;for(let s of e)for(let[i,n]of s.allEntries){let h=t.get(i);h===void 0?t.set(i,[n]):h.push(n)}let r=new Map;for(let[s,i]of t)if(i.length!==1){if(i.every(n=>typeof n=="number")){let n=i.reduce((h,o)=>h+o,0);r.set(s,n);continue}for(let n=0;n<i.length;n++)r.set(`${s}_${n}`,i[n])}else r.set(s,i[0]);return new m(r)}},F=class{static isSurrogate(e){let t=e.charCodeAt(0);return t>=55296&&t<=57343}static isAlphanumeric(e){let t=e.charCodeAt(0);return t>=48&&t<=57||t>=65&&t<=90||t>=97&&t<=122}static isLowerAlpha(e){let t=e.charCodeAt(0);return t>=97&&t<=122}},Q=class{constructor(e,t){this.usableSearchers=void 0,this.usableSearchers=new Map;for(let r of t)e.includes(r.type)&&this.usableSearchers.set(r.type,r)}has(e){return this.usableSearchers.has(e)}minQuality(e){return this.usableSearchers.get(e).minQuality}spec(e){return this.usableSearchers.get(e)}},z=class{constructor(e,t,r){this.matches=void 0,this.query=void 0,this.meta=void 0,this.matches=e,this.query=t,this.meta=r}},l,q;(function(a){a.Fuzzy="fuzzy",a.Substring="substring",a.Prefix="prefix"})(l||(l={}));var L=class{constructor(e,t){this.type=void 0,this.minQuality=void 0,this.type=e,this.minQuality=Math.max(0,t)}},k=class extends L{constructor(e){super(l.Fuzzy,e)}},I=class extends L{constructor(e){super(l.Substring,e)}},E=class extends L{constructor(e){super(l.Prefix,e)}},M=class{constructor(e,t=10,r=[new k(.3),new I(0),new E(0)]){this.string=void 0,this.topN=void 0,this.searchers=void 0,this.string=e,this.topN=Math.max(0,t),this.searchers=r}},V=class{constructor(e,t){this.removedEntities=void 0,this.meta=void 0,this.removedEntities=e,this.meta=t}},W=class{static mergeResults(e,t){let r=e.query,s=this.mergeMatches(e.matches,t.matches,r.topN),i=N.mergeMeta([e.meta,t.meta]);return new z(s,r,i)}static mergeMatches(e,t,r){if(t.length===0)return e;if(e.length===0)return t;let s=[...e,...t];return s.sort((i,n)=>i.quality>n.quality?-1:i.quality<n.quality?1:0),s.length<=r?s:s.slice(0,r)}},J=class{constructor(e,t,r){this.maxQueryLength=void 0,this.mainSearcher=void 0,this.secondarySearcher=void 0,this.maxQueryLength=e,this.mainSearcher=t,this.secondarySearcher=r}indexEntities(e,t,r){return this.secondarySearcher.indexEntities([],t,r),this.mainSearcher.indexEntities(e,t,r)}getMatches(e){return e.string?(e.string.length>this.maxQueryLength&&(e=new M(e.string.substring(0,this.maxQueryLength),e.topN,e.searchers)),W.mergeResults(this.mainSearcher.getMatches(e),this.secondarySearcher.getMatches(e))):new z([],e,new m)}tryGetTerms(e){let t=this.mainSearcher.tryGetTerms(e);return t!==null?t:this.secondarySearcher.tryGetTerms(e)}getTerms(){return this.mainSearcher.getTerms().concat(this.secondarySearcher.getTerms())}tryGetEntity(e){var t,r;return(t=(r=this.mainSearcher.tryGetEntity(e))!=null?r:this.secondarySearcher.tryGetEntity(e))!=null?t:null}getEntities(){return this.mainSearcher.getEntities().concat(this.secondarySearcher.getEntities())}removeEntities(e){let t=[];for(let s=0,i=e.length;s<i;s++)(this.mainSearcher.removeEntity(e[s])||this.secondarySearcher.removeEntity(e[s]))&&t.push(e[s]);let r=new m;return new V(t,r)}upsertEntities(e,t,r){let s=[],i=[];for(let n=0,h=e.length;n<h;n++){let o=e[n],c=t(o);this.tryUpdate(o,c,r)||(s.push(c),i.push(o))}return this.removeEntities(s),i.length>0?this.reindexSecondarySearcher(i,t,r):new m}reindexSecondarySearcher(e,t,r){let s=this.secondarySearcher.getEntities().concat(e);return this.secondarySearcher.indexEntities(s,t,r)}tryUpdate(e,t,r){return this.tryUpdateSearcher(e,t,r,this.mainSearcher)||this.tryUpdateSearcher(e,t,r,this.secondarySearcher)}tryUpdateSearcher(e,t,r,s){let i=s.tryGetTerms(t);if(i===null)return!1;if(this.termsAreEqual(i,r(e))){if(!s.replaceEntity(t,e,t))throw new Error(`Entity with id ${t} was not present.`);return!0}return!1}termsAreEqual(e,t){return e===t||e!=null&&t!=null&&e.length===t.length&&e.every((r,s)=>r===t[s])}removeEntity(e){return this.mainSearcher.removeEntity(e)||this.secondarySearcher.removeEntity(e)}replaceEntity(e,t,r){return this.mainSearcher.replaceEntity(e,t,r)||this.secondarySearcher.replaceEntity(e,t,r)}save(e){this.mainSearcher.save(e),this.secondarySearcher.save(e)}load(e){this.mainSearcher.load(e),this.secondarySearcher.load(e)}},X=class{constructor(e){this.dynamicSearcher=void 0,this.dynamicSearcher=e}removeEntities(e){let t=performance.now(),r=this.dynamicSearcher.removeEntities(e),s=Math.round(performance.now()-t);return r.meta.add("removalDuration",s),r}upsertEntities(e,t,r){let s=performance.now(),i=this.dynamicSearcher.upsertEntities(e,t,r),n=Math.round(performance.now()-s);return i.add("upsertDuration",n),i}indexEntities(e,t,r){let s=performance.now(),i=this.dynamicSearcher.indexEntities(e,t,r),n=Math.round(performance.now()-s);return i.add("indexingDurationTotal",n),i}getMatches(e){let t=performance.now(),r=this.dynamicSearcher.getMatches(e),s=Math.round(performance.now()-t);return r.meta.add("queryDuration",s),r}tryGetEntity(e){return this.dynamicSearcher.tryGetEntity(e)}getEntities(){return this.dynamicSearcher.getEntities()}tryGetTerms(e){return this.dynamicSearcher.tryGetTerms(e)}getTerms(){return this.dynamicSearcher.getTerms()}removeEntity(e){return this.dynamicSearcher.removeEntity(e)}replaceEntity(e,t,r){return this.dynamicSearcher.replaceEntity(e,t,r)}save(e){this.dynamicSearcher.save(e)}load(e){this.dynamicSearcher.load(e)}},Y=class{constructor(e,t,r){this.entity=void 0,this.quality=void 0,this.matchedString=void 0,this.entity=e,this.quality=t,this.matchedString=r}},Z=class{constructor(e){this.query=void 0,this.matchedIndexes=new Set,this.matches=[],this.meta=[],this.query=e}},R=class{constructor(e,t=0,r){this.string=void 0,this.minQuality=void 0,this.searcherType=void 0,this.string=e,this.minQuality=Math.max(0,Math.min(1,t)),this.searcherType=r}},_=class{constructor(e,t){this.stringSearcher=void 0,this.searcherTypes=void 0,this.entities=void 0,this.idToIndex=void 0,this.terms=void 0,this.termIndexToEntityIndex=void 0,this.entityIndexToFirstTermIndex=void 0,this.searchersAndQualityOffsets=[{searcherType:l.Prefix,qualityOffset:2},{searcherType:l.Substring,qualityOffset:1},{searcherType:l.Fuzzy,qualityOffset:0}],this.stringSearcher=e,this.searcherTypes=t,this.entities=[],this.idToIndex=new Map,this.terms=[],this.termIndexToEntityIndex=new Int32Array(0),this.entityIndexToFirstTermIndex=new Int32Array(0)}indexEntities(e,t,r){this.entities=[...e],this.idToIndex=new Map,this.terms=[];let s=[],i=[];for(let h=0,o=e.length;h<o;h++){this.idToIndex.set(t(e[h]),h);let c=r(e[h]);i.push(this.terms.length),this.terms.push(...c),s.push(...c.map(()=>h))}this.termIndexToEntityIndex=b.ToInt32Array(s),this.entityIndexToFirstTermIndex=b.ToInt32Array(i);let n=this.stringSearcher.index(this.terms);return n.add("numberOfEntities",this.entities.length),n.add("numberOfTerms",this.terms.length),n}getMatches(e){let t=new Z(e),r=new Q(this.searcherTypes,e.searchers);for(let{searcherType:i,qualityOffset:n}of this.searchersAndQualityOffsets){if(e.topN==t.matches.length)break;r.has(i)&&this.addMatchesFromSearcher(t,r.spec(i),n)}let s=N.mergeMeta(t.meta);return new z(t.matches,e,s)}addMatchesFromSearcher(e,t,r){let s=Math.max(0,t.minQuality-r);if(s>1)return;let i=new R(e.query.string,s,t.type),n=this.stringSearcher.getMatches(i);this.addMatchesFromResult(e,n,r)}addMatchesFromResult(e,t,r){if(e.meta.push(t.meta),e.query.topN!==0)for(let s=0,i=t.matches.length;s<i;s++){let n=t.matches[s],h=this.termIndexToEntityIndex[n.index];if(!e.matchedIndexes.has(h)&&this.entities[h]!==null&&(e.matchedIndexes.add(h),e.matches.push(new Y(this.entities[h],n.quality+r,this.terms[n.index])),e.matches.length===e.query.topN))break}}tryGetEntity(e){let t=this.idToIndex.get(e);return t===void 0?null:this.entities[t]}getEntities(){return this.entities.filter(e=>e!==null)}tryGetTerms(e){let t=this.idToIndex.get(e);return t===void 0?null:this.terms.slice(this.entityIndexToFirstTermIndex[t],t===this.entities.length-1?this.terms.length:this.entityIndexToFirstTermIndex[t+1])}getTerms(){let e=[];for(let t=0,r=this.termIndexToEntityIndex.length;t<r;t++)this.entities[this.termIndexToEntityIndex[t]]!==null&&e.push(this.terms[t]);return e}removeEntity(e){let t=this.idToIndex.get(e);return t!==void 0&&(this.entities[t]=null,this.idToIndex.delete(e),!0)}replaceEntity(e,t,r){let s=this.idToIndex.get(e);return s!==void 0&&(this.entities[s]=t,this.idToIndex.delete(e),this.idToIndex.set(r,s),!0)}save(e){e.add(this.entities),e.add(this.idToIndex),e.add(this.terms),e.add(this.termIndexToEntityIndex),e.add(this.entityIndexToFirstTermIndex),this.stringSearcher.save(e)}load(e){this.entities=e.get(),this.idToIndex=e.get(),this.terms=e.get(),this.termIndexToEntityIndex=e.get(),this.entityIndexToFirstTermIndex=e.get(),this.stringSearcher.load(e)}},T=class{constructor(e,t){this.strings=void 0,this.meta=void 0,this.strings=e,this.meta=t}},ee=class{constructor(e,t){this.treatCharacterAsSpace=void 0,this.allowCharacter=void 0,this.numberOfSurrogateCharacters=0,this.treatCharacterAsSpace=e,this.allowCharacter=t}normalize(e){let t=new Array(e.length),r=0,s=!1,i=!1;for(let n=0,h=e.length;n<h;n++){let o=this.getNormalizedCharacter(e[n]);o!==""&&(o===" "?s=!0:(s&&i&&(t[r++]=" "),t[r++]=o,i=!0,s=!1))}return i?t.join(""):""}getNormalizedCharacter(e){return e===" "||this.treatCharacterAsSpace(e)?" ":this.isSurrogate(e)||!this.allowCharacter(e)?"":e.toLowerCase()}isSurrogate(e){return!!F.isSurrogate(e)&&(this.numberOfSurrogateCharacters++,!0)}normalizeBulk(e){this.numberOfSurrogateCharacters=0;let t=e.map(s=>this.normalize(s)),r=new m;return r.add("numberOfSurrogateCharacters",this.numberOfSurrogateCharacters),new T(t,r)}},te=class{constructor(e){this.normalizationFunction=void 0,this.normalizationFunction=e}normalize(e){return this.normalizationFunction(e)}normalizeBulk(e){let t=e.map(r=>this.normalize(r));return new T(t,new m)}},re=class{constructor(e){this.normalizers=void 0,this.normalizers=e}normalize(e){for(let t=0,r=this.normalizers.length;t<r;t++)e=this.normalizers[t].normalize(e);return e}normalizeBulk(e){let t=new m;for(let r=0,s=this.normalizers.length;r<s;r++){let i=this.normalizers[r].normalizeBulk(e);e=i.strings;for(let n of i.meta.allEntries)t.add(n[0],n[1])}return new T(e,t)}},se=class{normalize(e){return e||""}normalizeBulk(e){let t=e.map(r=>this.normalize(r));return new T(t,new m)}},ie=class{constructor(e,t){this.normalizeVariationsAndInput=void 0,this.replacements=void 0,this.normalizeVariationsAndInput=t,this.replacements=[];for(let r of e){let s=new Map;for(let[i,n]of r)for(let h of n){let o=t(h);s.set(o,i)}this.replacements.push(s)}}normalize(e){e=this.normalizeVariationsAndInput(e);let t=new Array(e.length),r=0;for(let s=0,i=e.length;s<i;s++)for(let n of this.replacements){let h=n.get(e[s]);if(h!==void 0){t[r++]=h;break}t[r++]=e[s]}return t.join("")}normalizeBulk(e){let t=e.map(r=>this.normalize(r));return new T(t,new m)}},ne=class{static create(e){let t=new se,r=new ie(e.replacements,n=>n.toLowerCase().normalize("NFKC")),s=new te(n=>n.normalize("NFKD")),i=new ee(e.treatCharacterAsSpace,e.allowCharacter);return new re([t,r,s,i])}},H=class{constructor(e,t){this.index=void 0,this.quality=void 0,this.index=e,this.quality=t}},S=class{constructor(e,t,r){this.matches=void 0,this.query=void 0,this.meta=void 0,this.matches=e,this.query=t,this.meta=r}},ae=class{constructor(e){this.stringSearcher=void 0,this.distinctMapping=void 0,this.sortMapping=void 0,this.stringSearcher=e,this.distinctMapping=new Int32Array(0),this.sortMapping=new Int32Array(0)}index(e){let t=e.map((o,c)=>({term:o,index:c}));t.sort((o,c)=>o.term<c.term?-1:o.term>c.term?1:0),this.sortMapping=new Int32Array(t.length);for(let o=0,c=t.length;o<c;o++)this.sortMapping[o]=t[o].index;let r=[],s=[],i=0,n=null;for(let o=0,c=t.length;o<c;o++){let d=t[o].term;d!=n&&(r[i]=d,s[i]=o,i++),n=d}s[i++]=t.length,this.distinctMapping=b.ToInt32Array(s);let h=this.stringSearcher.index(r);return h.add("numberOfDistinctTerms",r.length),h}getMatches(e){let t=this.stringSearcher.getMatches(e),r=new Array(t.matches.length),s=0;return t.matches.forEach(i=>{let n=this.distinctMapping[i.index+1];for(let h=this.distinctMapping[i.index];h<n;h++)r[s++]=new H(this.sortMapping[h],i.quality)}),new S(r,e,t.meta)}save(e){e.add(this.distinctMapping),e.add(this.sortMapping),this.stringSearcher.save(e)}load(e){this.distinctMapping=e.get(),this.sortMapping=e.get(),this.stringSearcher.load(e)}},he=class{constructor(e,t){this.entitySearcher=void 0,this.searcherTypes=void 0,this.entitySearcher=e,this.searcherTypes=t}indexEntities(e,t,r){return this.entitySearcher.indexEntities(e,t,r)}getMatches(e){let t=new Q(this.searcherTypes,e.searchers);if(e.topN>200)return this.entitySearcher.getMatches(e);if(e.string.length<=3&&t.has(l.Prefix)&&t.minQuality(l.Prefix)<2.2){let r=new M(e.string,e.topN,[new E(2.3)]),s=this.entitySearcher.getMatches(r);if(s.matches.length==e.topN)return new z(s.matches,e,s.meta)}if(e.string.length<=3&&!t.has(l.Prefix)&&t.has(l.Substring)&&t.minQuality(l.Substring)<1.2){let r=new M(e.string,e.topN,[new I(1.3)]),s=this.entitySearcher.getMatches(r);if(s.matches.length==e.topN)return new z(s.matches,e,s.meta)}return this.entitySearcher.getMatches(e)}tryGetEntity(e){return this.entitySearcher.tryGetEntity(e)}getEntities(){return this.entitySearcher.getEntities()}tryGetTerms(e){return this.entitySearcher.tryGetTerms(e)}getTerms(){return this.entitySearcher.getTerms()}removeEntity(e){return this.entitySearcher.removeEntity(e)}replaceEntity(e,t,r){return this.entitySearcher.replaceEntity(e,t,r)}save(e){return this.entitySearcher.save(e)}load(e){return this.entitySearcher.load(e)}},$=class{constructor(){this.ids=void 0,this.frequencies=void 0,this.ids=[],this.frequencies=[]}addId(e,t){this.ids.push(e),this.frequencies.push(t)}seal(){this.ids=b.ToInt32Array(this.ids),this.frequencies=b.ToInt32Array(this.frequencies)}get length(){return this.ids.length}save(e){e.add(this.ids),e.add(this.frequencies)}load(e){this.ids=e.get(),this.frequencies=e.get()}},A=class{constructor(){this.ngramToTermIds=void 0,this.ngramToTermIds=new Map}add(e,t,r){let s=this.ngramToTermIds.get(e);s||(s=new $,this.ngramToTermIds.set(e,s)),s.addId(t,r)}seal(){for(let e of this.ngramToTermIds.values())e.seal()}getIds(e){return this.ngramToTermIds.get(e)}get size(){return this.ngramToTermIds.size}save(e){e.add(this.ngramToTermIds.size);for(let[t,r]of this.ngramToTermIds)e.add(t),r.save(e)}load(e){let t=e.get();for(let r=0;r<t;r++){let s=e.get(),i=new $;i.load(e),this.ngramToTermIds.set(s,i)}}},oe=class{static ComputeJaccardCoefficient(e,t,r){return r/(e+t-r)}static ComputeOverlapMaxCoefficient(e,t,r){return r/Math.max(e,t)}},ce=class{constructor(e){this.ngramComputer=void 0,this.invertedIndex=void 0,this.numberOfNgrams=void 0,this.commonNgramCounts=void 0,this.ngramComputer=e,this.invertedIndex=new A,this.numberOfNgrams=new Int32Array(0),this.commonNgramCounts=new Int32Array(0)}index(e){let t=performance.now();this.invertedIndex=new A,this.commonNgramCounts=new Int32Array(e.length),this.numberOfNgrams=new Int32Array(e.length);let r=0;for(let n=0,h=e.length;n<h;n++){let o=e[n];if(!this.isValidTerm(o)){this.numberOfNgrams[n]=0,r++;continue}let c=this.ngramComputer.computeNgrams(o);this.numberOfNgrams[n]=c.length;let d=this.getNgramsToFrequency(c);for(let[g,u]of d)this.invertedIndex.add(g,n,u)}this.invertedIndex.seal();let s=Math.round(performance.now()-t),i=new m;return i.add("numberOfInvalidTerms",r),i.add("indexingDurationFuzzySearcher",s),i}isValidTerm(e){return e!=null&&e.trim()!==""}getMatches(e){if(this.invertedIndex.size===0)return new S([],e,new m);let t=this.ngramComputer.computeNgrams(e.string),r=this.getNgramsToFrequency(t),s=t.length;this.computeCommonNgramCounts(r);let i=this.getMatchesFromCommonNgrams(s,e.minQuality);return new S(i,e,new m)}computeCommonNgramCounts(e){this.commonNgramCounts.fill(0);for(let[t,r]of e){let s=this.invertedIndex.getIds(t);if(s!=null)for(let i=0,n=s.length;i<n;i++)this.commonNgramCounts[s.ids[i]]+=Math.min(r,s.frequencies[i])}}getNgramsToFrequency(e){let t=new Map;for(let r=0,s=e.length;r<s;r++){let i=e[r],n=t.get(i);t.set(i,n!==void 0?n+1:1)}return t}getMatchesFromCommonNgrams(e,t){let r=[];for(let s=0,i=this.numberOfNgrams.length;s<i;s++){let n=oe.ComputeOverlapMaxCoefficient(e,this.numberOfNgrams[s],this.commonNgramCounts[s]);n>t&&r.push(new H(s,n))}return r}save(e){this.invertedIndex.save(e),e.add(this.numberOfNgrams)}load(e){this.invertedIndex=new A,this.invertedIndex.load(e),this.numberOfNgrams=e.get(),this.commonNgramCounts=new Int32Array(this.numberOfNgrams.length)}},de=class{constructor(e,t){this.stringSearcher=void 0,this.penaltyFactor=void 0,this.hashCodes=void 0,this.stringSearcher=e,this.penaltyFactor=1-t,this.hashCodes=new Int32Array(0)}index(e){this.hashCodes=new Int32Array(e.length);for(let t=0,r=e.length;t<r;t++)this.hashCodes[t]=O.getHashCode(e[t]);return this.stringSearcher.index(e)}getMatches(e){let t=O.getHashCode(e.string),r=this.stringSearcher.getMatches(e),s=r.matches.map(i=>this.penalizeMatch(i,t)).filter(i=>i.quality>=e.minQuality);return new S(s,r.query,r.meta)}penalizeMatch(e,t){return e.quality*=this.hashCodes[e.index]===t?1:this.penaltyFactor,e}save(e){e.add(this.hashCodes),this.stringSearcher.save(e)}load(e){this.hashCodes=e.get(),this.stringSearcher.load(e)}},ue=class{constructor(e,t){this.ngramN=void 0,this.transformNgram=void 0,this.ngramN=e,this.transformNgram=t??(r=>r)}computeNgrams(e){if(e.length===0)return[];if(e.length<=this.ngramN){let r=this.transformNgram(e);return r?[r]:[]}let t=[];for(let r=0,s=this.maximumNumberOfNgrams(e);r<s;r++){let i=this.transformNgram(e.substring(r,r+this.ngramN));i&&t.push(i)}return t}maximumNumberOfNgrams(e){return Math.max(e.length-this.ngramN+1,e.length>0?1:0)}},le=class{constructor(e,t,r){this.paddingLeft=void 0,this.paddingRight=void 0,this.paddingMiddle=void 0,this.paddingLeft=e,this.paddingRight=t,this.paddingMiddle=r}normalize(e){return e&&`${this.paddingLeft}${e.split(" ").join(this.paddingMiddle)}${this.paddingRight}`}normalizeBulk(e){let t=e.map(s=>this.normalize(s)),r=new m;return new T(t,r)}},G=class{};G.Value=new Map([["a",["\u1D8F","\u2C65","\u0251","\u1D00","\u0250","\u0252"]],["aa",["\xE5","\uA733"]],["ae",["\xE4","\xE6","\u1D01","\u1D2D","\u1D46","\u01FD","\u01E3","\u1D02"]],["ao",["\uA735"]],["au",["\uA737"]],["av",["\uA739","\uA73B"]],["ay",["\uA73D"]],["b",["\u0180","\u0253","\u0183","\u1D6C","\u1D80","\u0299"]],["c",["\u023C","\u0188","\u0255","\u1D04","\uA73F","\u2184"]],["d",["\u0111","\xF0","\u0256","\u0257","\u018C","\u1D6D","\u1D81","\u1D91","\u0221","\u1D05","\uA77A"]],["db",["\u0238"]],["e",["\u1D92","\u0247","\u2C78","\u1D07","\u0259","\u01DD","\u025B"]],["eo",["\u1D14"]],["f",["\u0192","\u1D6E","\u1D82","\uA730","\uA77C"]],["g",["\u01E5","\u0260","\u1D83","\u0262","\u021D","\u014B","\uA7A1","\u1D79","\uA77F"]],["h",["\u0127","\u2C68","\u0266","\u029C","\u0303","\u0267","\u2C76","\u0265"]],["hv",["\u0195"]],["i",["\u0268","\u1D7B","\u1D96","\u0131","\u026A","\u0269"]],["j",["\u0249","\u0237","\u029D","\u025F","\u0284","\u1D0A"]],["k",["\u0199","\u2C6A","\u1D84","\uA741","\u1D0B","\uA743","\uA745","\uA7A3"]],["l",["\u0142","\u019A","\u2C61","\u026B","\u026C","\u1D85","\u026D","\u0234","\u029F","\uA749","\uA781","\uA747"]],["m",["\u1D6F","\u1D86","\u0271","\u1D0D","\u026F"]],["n",["\u0272","\u019E","\u1D70","\u1D87","\u0273","\u0235","\u0274","\uA791","\uA7A5"]],["o",["\xF8","\u01FF","\u0275","\u0254","\u2C7A","\u1D0F","\uA74B","\uA74D"]],["oe",["\xF6","\u0153"]],["oi",["\u01A3"]],["oo",["\uA74F"]],["ou",["\u0223"]],["p",["\u1D7D","\u01A5","\u1D71","\u1D88","\u1D18","\u01BF","\uA751","\uA753","\uA755"]],["q",["\u024B","\u02A0","\uA757","\uA759"]],["qp",["\u0239"]],["r",["\u024D","\u027D","\uA75B","\u1D72","\u1D89","\u027C","\u027E","\u1D73","\u0280","\u0279","\u0281","\uA7A7","\uA783"]],["s",["\u1D74","\u1D8A","\u0282","\u023F","\uA731","\u0283","\uA7A9","\uA785","\u017F"]],["ss",["\xDF"]],["t",["\u0167","\u2C66","\u01AD","\u0288","\u1D75","\u01AB","\u0236","\u1D1B","\uA787"]],["th",["\xFE"]],["tz",["\uA729"]],["u",["\u0289","\u028A","\u1D7E","\u1D1C","\u1D99"]],["ue",["\xFC","\u1D6B"]],["v",["\u028B","\u1D8C","\u2C71","\u2C74","\u1D20","\u028C","\uA75F"]],["vy",["\uA761"]],["w",["\u2C73","\u1D21","\u028D"]],["x",["\u1D8D"]],["y",["\u024F","\u01B4","\u028F","\u1EFF"]],["z",["\u01B6","\u0225","\u2C6C","\u1D76","\u1D8E","\u0290","\u0291","\u0240","\u1D22","\u0292","\u01B9","\uA763"]]]);var P=class a{constructor(e,t,r){this.replacements=void 0,this.treatCharacterAsSpace=void 0,this.allowCharacter=void 0,this.replacements=e,this.treatCharacterAsSpace=t,this.allowCharacter=r}static createDefaultConfig(){let e=new Set(["_","-","\u2013","/",","," "]);return new a([G.Value],t=>e.has(t),t=>F.isAlphanumeric(t))}},B=class{constructor(e,t,r="normalizationDuration"){this.stringSearcher=void 0,this.normalizer=void 0,this.normalizationDurationMetaKey=void 0,this.stringSearcher=e,this.normalizer=t,this.normalizationDurationMetaKey=r}index(e){let t=performance.now(),r=this.normalizer.normalizeBulk(e),s=Math.round(performance.now()-t),i=this.stringSearcher.index(r.strings);i.add(this.normalizationDurationMetaKey,s);for(let n of r.meta.allEntries)i.add(n[0],n[1]);return i}getMatches(e){let t=new R(this.normalizer.normalize(e.string),e.minQuality,e.searcherType),r=this.stringSearcher.getMatches(t);return new S(r.matches,e,r.meta)}save(e){this.stringSearcher.save(e)}load(e){this.stringSearcher.load(e)}},me=class{constructor(e){this.suffixArraySearcher=void 0,this.suffixArraySearcher=e}index(e){return this.suffixArraySearcher.index(e)}getMatches(e){if(!e.string)return new S([],e,new m);let t=this.modifyQueryString(e.string),r=new R(t,e.minQuality,e.searcherType);return this.suffixArraySearcher.getMatches(r,e.string.length)}modifyQueryString(e){return`${this.suffixArraySearcher.separator}${e}`}save(e){this.suffixArraySearcher.save(e)}load(e){this.suffixArraySearcher.load(e)}},ge=class{constructor(e,t,r){this.prefixSearcher=void 0,this.substringSearcher=void 0,this.fuzzySearcher=void 0,this.prefixSearcher=e,this.substringSearcher=t,this.fuzzySearcher=r}index(e){let t=[];if(this.prefixSearcher&&!this.substringSearcher){let r=this.prefixSearcher.index(e);t.push(r)}if(this.substringSearcher){let r=this.substringSearcher.index(e);t.push(r)}if(this.fuzzySearcher){let r=this.fuzzySearcher.index(e);t.push(r)}return N.mergeMeta(t)}getMatches(e){if(!e.searcherType)throw new Error("SearcherSwitch requires a searcher type.");switch(e.searcherType){case l.Prefix:if(!this.prefixSearcher)throw new Error("No prefix searcher has been indexed.");return this.prefixSearcher.getMatches(e);case l.Substring:if(!this.substringSearcher)throw new Error("No substring searcher has been indexed.");return this.substringSearcher.getMatches(e);case l.Fuzzy:if(!this.fuzzySearcher)throw new Error("No fuzzy searcher has been indexed.");return this.fuzzySearcher.getMatches(e);default:throw new Error(`Unknown searcher type: ${e.searcherType}`)}}save(e){this.prefixSearcher&&!this.substringSearcher&&this.prefixSearcher.save(e),this.substringSearcher&&this.substringSearcher.save(e),this.fuzzySearcher&&this.fuzzySearcher.save(e)}load(e){this.prefixSearcher&&!this.substringSearcher&&this.prefixSearcher.load(e),this.substringSearcher&&this.substringSearcher.load(e),this.fuzzySearcher&&this.fuzzySearcher.load(e)}};(function(a){a.QualityAndIndex="qualityAndIndex",a.QualityAndMatchedString="qualityAndMatchedString"})(q||(q={}));var fe=class{constructor(e,t){this.sortOrder=void 0,this.entitySearcher=void 0,this.collator=new Intl.Collator(void 0,{numeric:!0}),this.sortOrder=e,this.entitySearcher=t}indexEntities(e,t,r){return this.entitySearcher.indexEntities(e,t,r)}getMatches(e){let t=this.entitySearcher.getMatches(e);switch(this.sortOrder){case q.QualityAndIndex:return t;case q.QualityAndMatchedString:return this.sortMatchesByQualityAndMatchedString(t.matches),t;default:throw new Error(`Unsupported sort order: ${this.sortOrder}`)}}sortMatchesByQualityAndMatchedString(e){e.sort((t,r)=>t.quality>r.quality?-1:t.quality<r.quality?1:this.collator.compare(t.matchedString,r.matchedString))}tryGetEntity(e){return this.entitySearcher.tryGetEntity(e)}getEntities(){return this.entitySearcher.getEntities()}tryGetTerms(e){return this.entitySearcher.tryGetTerms(e)}getTerms(){return this.entitySearcher.getTerms()}save(e){this.entitySearcher.save(e)}load(e){this.entitySearcher.load(e)}removeEntity(e){return this.entitySearcher.removeEntity(e)}replaceEntity(e,t,r){return this.entitySearcher.replaceEntity(e,t,r)}},ye=class{constructor(e){this.stringSearcher=void 0,this.stringSearcher=e}index(e){return this.stringSearcher.index(e)}getMatches(e){let t=this.stringSearcher.getMatches(e);return t.matches.sort(this.compareMatchesByQualityAndIndex),t}compareMatchesByQualityAndIndex(e,t){return e.quality>t.quality?-1:e.quality<t.quality?1:e.index<t.index?-1:e.index>t.index?1:0}save(e){this.stringSearcher.save(e)}load(e){this.stringSearcher.load(e)}},D=class{static compareOrdinal(e,t,r,s,i){let n=Math.min(t+i,e.length),h=Math.min(s+i,r.length),o=t,c=s;for(;o<n&&c<h;){let u=e.charCodeAt(o),f=r.charCodeAt(c);if(u<f)return-1;if(u>f)return 1;o++,c++}let d=n-t,g=h-s;return d===g?0:d<g?-1:1}},pe=class a{static create(e){if(e==null)throw new Error("Input string cannot be null.");let t=new a(e);return t.FormInitialChains(),t.BuildSufixArray(),t.sa}constructor(e){this.inputString=void 0,this.eoc=2147483647,this.sa=void 0,this.isa=void 0,this.chainHeadsDict=void 0,this.chainStack=[],this.subChains=[],this.nextRank=1,this.inputString=e;let t=e.length;this.sa=new Int32Array(t),this.isa=new Int32Array(t),this.chainHeadsDict=new Map}FormInitialChains(){this.FindInitialChains(),this.SortAndPushSubchains()}FindInitialChains(){for(let e=0;e<this.inputString.length;e++){let t=this.inputString.charCodeAt(e),r=this.chainHeadsDict.get(t);this.isa[e]=r!==void 0?r:this.eoc,this.chainHeadsDict.set(t,e)}for(let e of this.chainHeadsDict.values()){let t=new U(e,1);this.subChains.push(t)}}BuildSufixArray(){for(;this.chainStack.length>0;){let e=this.chainStack.pop();this.isa[e.head]===this.eoc?this.RankSuffix(e.head):this.RefineChainWithInductionSorting(e)}}RankSuffix(e){this.isa[e]=-this.nextRank,this.sa[this.nextRank-1]=e,this.nextRank++}RefineChainWithInductionSorting(e){let t=[];for(this.chainHeadsDict.clear(),this.subChains=[];e.head!==this.eoc;){let r=this.isa[e.head];if(e.head+e.length>this.inputString.length-1)this.RankSuffix(e.head);else if(this.isa[e.head+e.length]<0){let s=new Se(e.head,-this.isa[e.head+e.length]);t.push(s)}else this.ExtendChain(e);e.head=r}this.SortAndPushSubchains(),this.SortAndRankNotedSuffixes(t)}ExtendChain(e){let t=this.inputString.charCodeAt(e.head+e.length);if(this.chainHeadsDict.has(t))this.isa[this.chainHeadsDict.get(t)]=e.head,this.isa[e.head]=this.eoc;else{this.isa[e.head]=this.eoc;let r=new U(e.head,e.length+1);this.subChains.push(r)}this.chainHeadsDict.set(t,e.head)}SortAndRankNotedSuffixes(e){e.sort((t,r)=>t.rank-r.rank);for(let t=0;t<e.length;t++)this.RankSuffix(e[t].head)}SortAndPushSubchains(){this.subChains.sort((e,t)=>{let r=Math.min(e.length,t.length);return D.compareOrdinal(this.inputString,e.head,this.inputString,t.head,r)});for(let e=this.subChains.length-1;e>=0;e--)this.chainStack.push(this.subChains[e])}},Se=class{constructor(e,t){this.head=void 0,this.rank=void 0,this.head=e,this.rank=t}},U=class{constructor(e,t){this.head=void 0,this.length=void 0,this.head=e,this.length=t}},ve=class{constructor(e){this.separator=void 0,this.str=void 0,this.suffixArray=void 0,this.indexToTermIndex=void 0,this.termLengths=void 0,this.separator=e,this.str="",this.suffixArray=new Int32Array(0),this.indexToTermIndex=new Int32Array(0),this.termLengths=new Int32Array(0)}index(e){let t=performance.now();this.str=e.length>0?this.separator+e.join(this.separator)+this.separator:"",this.suffixArray=pe.create(this.str),this.indexToTermIndex=new Int32Array(this.suffixArray.length),this.termLengths=new Int32Array(e.length);let r=0;for(let n=0;n<e.length;n++){this.termLengths[n]=e[n].length;for(let h=0;h<=e[n].length;h++)this.indexToTermIndex[r++]=n}this.indexToTermIndex[r++]=-1;let s=Math.round(performance.now()-t),i=new m;return i.add("indexingDurationSuffixArraySearcher",s),i}getMatches(e,t){if(!e.string)return new S([],e,new m);let[r,s]=this.GetPositionsInSuffixArray(e.string),i=new Int32Array(s-r),n=new Set,h=0;for(let d=r;d<s;d++){let g=this.indexToTermIndex[this.suffixArray[d]];n.has(g)||(n.add(g),i[h++]=g)}let o=[];t=t??e.string.length;let c=0;for(let d=0;d<h;d++)c=this.computeQuality(t,this.termLengths[i[d]]),c>e.minQuality&&o.push(new H(i[d],c));return new S(o,e,new m)}computeQuality(e,t){return e/t}GetPositionsInSuffixArray(e){let t=0,r=this.suffixArray.length,s=0;for(;t<r;)s=Math.floor((t+r)/2),D.compareOrdinal(e,0,this.str,this.suffixArray[s],e.length)>0?t=s+1:r=s;let i=t;for(r=this.suffixArray.length;t<r;)s=Math.floor((t+r)/2),D.compareOrdinal(e,0,this.str,this.suffixArray[s],e.length)==0?t=s+1:r=s;return[i,r]}save(e){e.add(this.str),e.add(this.suffixArray),e.add(this.indexToTermIndex),e.add(this.termLengths)}load(e){this.str=e.get(),this.suffixArray=e.get(),this.indexToTermIndex=e.get(),this.termLengths=e.get()}},j=class{static createSearcher(e){let t=this.createDefaultNormalizer(e),r=this.tryCreateFuzzySearcher(e),s=this.tryCreateSubstringSearcher(e),i=this.tryCreatePrefixSearcher(e,s),n=new ge(i,s,r);n=new ae(n),n=new ye(n),n=new B(n,t,"normalizationDurationDefault");let h=new _(n,e.searcherTypes);return h=new he(h,e.searcherTypes),h=new fe(e.sortOrder,h),h}static createDefaultNormalizer(e){let t=new Set;e.fuzzySearchConfig&&(e.fuzzySearchConfig.paddingLeft.split("").forEach(s=>t.add(s)),e.fuzzySearchConfig.paddingRight.split("").forEach(s=>t.add(s)),e.fuzzySearchConfig.paddingMiddle.split("").forEach(s=>t.add(s))),e.substringSearchConfig&&e.substringSearchConfig.suffixArraySeparator.split("").forEach(s=>t.add(s));let r=new P(e.normalizerConfig.replacements,e.normalizerConfig.treatCharacterAsSpace,s=>e.normalizerConfig.allowCharacter(s)&&!t.has(s));return ne.create(r)}static tryCreateFuzzySearcher(e){if(!e.searcherTypes.includes(l.Fuzzy))return null;if(e.fuzzySearchConfig===void 0)throw new Error("Unable to create fuzzy searcher: No fuzzy search config provided.");return this.createFuzzySearcher(e.fuzzySearchConfig)}static createFuzzySearcher(e){let t=new ue(e.ngramN,e.transformNgram),r=new le(e.paddingLeft,e.paddingRight,e.paddingMiddle),s=new ce(t);return s=new de(s,e.inequalityPenalty),s=new B(s,r,"normalizationDurationNgrams"),s}static tryCreateSubstringSearcher(e){if(!e.searcherTypes.includes(l.Substring))return null;if(e.substringSearchConfig===void 0)throw new Error("Unable to create substring searcher: No substring search config provided.");return this.createSubstringSearcher(e.substringSearchConfig)}static createSubstringSearcher(e){return new ve(e.suffixArraySeparator)}static tryCreatePrefixSearcher(e,t){if(!e.searcherTypes.includes(l.Prefix))return null;if(e.substringSearchConfig===void 0)throw new Error("Unable to create prefix searcher: No substring search config provided.");return this.createPrefixSearcher(e.substringSearchConfig,t)}static createPrefixSearcher(e,t){return t===null&&(t=this.createSubstringSearcher(e)),new me(t)}},we=class a{constructor(e,t,r,s,i,n){this.paddingLeft=void 0,this.paddingRight=void 0,this.paddingMiddle=void 0,this.ngramN=void 0,this.transformNgram=void 0,this.inequalityPenalty=void 0,this.paddingLeft=e,this.paddingRight=t,this.paddingMiddle=r,this.ngramN=s,this.transformNgram=i,this.inequalityPenalty=n}static createDefaultConfig(){return new a("$$","!","!$$",3,e=>e.endsWith("$")?null:e.indexOf("$")===-1?e.split("").sort().join(""):e,.05)}};var xe=class a{constructor(e){this.suffixArraySeparator=void 0,this.suffixArraySeparator=e}static createDefaultConfig(){return new a("$")}},Te=class a{constructor(e,t,r,s,i,n){this.searcherTypes=void 0,this.maxQueryLength=void 0,this.sortOrder=void 0,this.normalizerConfig=void 0,this.fuzzySearchConfig=void 0,this.substringSearchConfig=void 0,this.searcherTypes=e,this.maxQueryLength=t,this.sortOrder=r,this.normalizerConfig=s,this.fuzzySearchConfig=i,this.substringSearchConfig=n}static createDefaultConfig(){let e=[l.Fuzzy,l.Substring,l.Prefix],t=q.QualityAndMatchedString,r=P.createDefaultConfig(),s=we.createDefaultConfig(),i=xe.createDefaultConfig();return new a(e,150,t,r,s,i)}},K=class{static createSearcher(e){let t=j.createSearcher(e),r=j.createSearcher(e),s=new J(e.maxQueryLength,t,r);return s=new X(s),s}static createDefaultSearcher(){let e=Te.createDefaultConfig();return this.createSearcher(e)}};function be(a,e,t,r,s){let i=Math.max(0,e-t),n=Math.max(0,r-s);return i<=0?0:a/i*n}function ze(a,e){let t=e.map(o=>o.trim()).filter(Boolean);if(t.length===0)return[];let r=a.toLowerCase(),s=t.map(o=>o.toLowerCase()),i=[],n=0,h=0;for(;n<a.length&&h<400;){let o=n,c=-1,d=!0;for(let g of s){if(g.length===0)continue;let u=r.indexOf(g,o);if(u<0){d=!1;break}c<0&&(c=u),o=u+g.length}if(!d||c<0)break;i.push({start:c,end:o}),h++,n=c+1}return i}function Me(a,e){let t=Math.max(0,Math.min(e,a.length)),r=0;for(let s=0;s<t;s++)a[s]===`
|
|
2
|
+
`&&r++;return r}function Ie(a,e){let t=a.split(`
|
|
3
|
+
`);return e<0||e>=t.length?"":t[e]??""}function Le(a){return a.trim().split(/\s+/).filter(Boolean)}function Ne(a,e,t){return Math.max(e,Math.min(t,a))}function Ee(a){try{return decodeURIComponent(escape(atob(a)))}catch{try{return atob(a)}catch{return""}}}function ke(a){return a.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}function Re(a,e){let t=a.replace(/\s+/g," ").trim();return t.length<=e?t:`${t.slice(0,e-1)}\u2026`}function He(a,e){let t=new Map;for(let r of a){let s=`${r.kind}:${r.line}`,i=t.get(s);(!i||r.score>i.score)&&t.set(s,r)}return[...t.values()].sort((r,s)=>s.score-r.score).slice(0,e)}function Ce(a,e,t){let r=ze(a,t),s=new Set,i=[];for(let n of r){let h=Me(a,n.start);s.has(h)||(s.add(h),i.push({kind:e,line:h,text:Ie(a,h),score:1e3,source:"ordered"}))}return i}function De(a,e,t){let r=e.trim();if(!r)return[];let s=new M(r,t,[new k(.22),new I(0),new E(0)]),i=a.getMatches(s),n=[];for(let h of i.matches){let o=h.entity;n.push({kind:o.kind,line:o.line,text:o.text,score:100+h.quality,source:"fuzzy"})}return n}function Oe(a){let{rawCode:e,rawMd:t,mdLines:r,searcher:s,searchInput:i,searchClear:n,searchResults:h,docPane:o}=a,c;function d(){clearTimeout(c),c=void 0,i.value="",h.innerHTML="",h.hidden=!0}function g(){let u=Le(i.value);if(u.length===0){h.hidden=!0,h.innerHTML="";return}let f=Ce(e,"code",u),w=Ce(t,"md",u),v=De(s,i.value,60),p=He([...f,...w,...v],80);if(h.hidden=!1,p.length===0){h.innerHTML='<div class="hint">No matches. Try fewer tokens or looser spelling (fuzzy matches per line).</div>';return}let x=[];x.push(`<div class="hint">Whole source: whitespace tokens in order (may span lines). Per-line fuzzy ranking for typos. ${p.length} hit(s).</div>`);for(let y of p){let C=y.kind==="code"?`Code L${y.line+1}`:`Commentray L${y.line+1}`,qe=y.source==="ordered"?"ordered":"fuzzy";x.push(`<button type="button" class="hit" data-kind="${y.kind}" data-line="${String(y.line)}"><span class="meta">${C} <span class="src-tag">(${qe})</span></span><div class="snippet">${ke(Re(y.text,200))}</div></button>`)}h.innerHTML=x.join("")}h.addEventListener("click",u=>{let f=u.target;for(;f&&f!==h&&(!f.classList||!f.classList.contains("hit"));)f=f.parentElement;if(!f||!f.classList||!f.classList.contains("hit"))return;let w=f.getAttribute("data-kind"),v=parseInt(f.getAttribute("data-line")||"0",10);if(w==="code"){let p=document.getElementById(`code-line-${String(v)}`);p&&p.scrollIntoView({block:"nearest",behavior:"smooth"})}else{let p=r.length;if(p<=0)return;let x=v/Math.max(1,p-1),y=o.scrollHeight-o.clientHeight;o.scrollTo({top:x*Math.max(0,y),behavior:"smooth"})}}),i.addEventListener("input",()=>{clearTimeout(c),c=setTimeout(g,200)}),n.addEventListener("click",d),document.addEventListener("keydown",u=>{if(u.key!=="Escape")return;let f=i.value.trim().length>0,w=document.activeElement===i,v=!h.hidden;!f&&!w&&!v||(d(),w&&i.blur(),u.preventDefault())})}function Fe(a,e,t){let r=localStorage.getItem(a)==="1";t.checked=r,r&&e.classList.add("wrap"),t.addEventListener("change",()=>{t.checked?(e.classList.add("wrap"),localStorage.setItem(a,"1")):(e.classList.remove("wrap"),localStorage.setItem(a,"0"))})}function Qe(a,e){let t="none";a.addEventListener("scroll",()=>{t!=="doc"&&(t="code",e.scrollTop=be(a.scrollTop,a.scrollHeight,a.clientHeight,e.scrollHeight,e.clientHeight),t="none")},{passive:!0}),e.addEventListener("scroll",()=>{t!=="code"&&(t="doc",a.scrollTop=be(e.scrollTop,e.scrollHeight,e.clientHeight,a.scrollHeight,a.clientHeight),t="none")},{passive:!0})}function $e(a,e,t,r,s){let i=!1,n=s;function h(c){if(!i)return;let d=e.getBoundingClientRect(),g=c.clientX-d.left,u=Ne(g/d.width*100,15,85);n=u,t.style.flex=`0 0 ${u}%`}function o(){i=!1,window.removeEventListener("mousemove",h),window.removeEventListener("mouseup",o),document.body.style.cursor="",document.body.style.userSelect="",localStorage.setItem(a,String(n))}r.addEventListener("mousedown",c=>{c.preventDefault(),i=!0,document.body.style.cursor="col-resize",document.body.style.userSelect="none",window.addEventListener("mousemove",h),window.addEventListener("mouseup",o)})}function Ae(){let a="commentray.codeCommentrayStatic.splitPct",e="commentray.codeCommentrayStatic.wrap",t=document.getElementById("shell"),r=document.getElementById("code-pane"),s=document.getElementById("doc-pane"),i=document.getElementById("gutter"),n=document.getElementById("wrap-lines"),h=document.getElementById("search-q"),o=document.getElementById("search-clear"),c=document.getElementById("search-results");if(!t||!r||!s||!i||!n||!h||!o||!c)return;let d=Ee(r.getAttribute("data-raw-code-b64")||""),g=Ee(r.getAttribute("data-raw-md-b64")||""),u=g.split(`
|
|
4
|
+
`),w=[...d.split(`
|
|
5
|
+
`).map((y,C)=>({kind:"code",line:C,text:y})),...u.map((y,C)=>({kind:"md",line:C,text:y}))],v=K.createDefaultSearcher();v.indexEntities(w,y=>`${y.kind}:${y.line}`,y=>[y.text]),Oe({rawCode:d,rawMd:g,mdLines:u,searcher:v,searchInput:h,searchClear:o,searchResults:c,docPane:s});let p=parseFloat(localStorage.getItem(a)||"50"),x=Ne(Number.isFinite(p)?p:50,15,85);r.style.flex=`0 0 ${x}%`,Fe(e,r,n),$e(a,t,r,i,x),Qe(r,s)}document.readyState==="loading"?document.addEventListener("DOMContentLoaded",Ae):Ae();})();
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Maps one pane’s scroll position to the other for **proportional** scroll sync
|
|
3
|
+
* (static code browser). Mirrors the ratio fallback used while editing when
|
|
4
|
+
* there are no block markers yet.
|
|
5
|
+
*/
|
|
6
|
+
export declare function mirroredScrollTop(sourceScrollTop: number, sourceScrollHeight: number, sourceClientHeight: number, targetScrollHeight: number, targetClientHeight: number): number;
|
|
7
|
+
//# sourceMappingURL=code-browser-scroll-sync.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"code-browser-scroll-sync.d.ts","sourceRoot":"","sources":["../src/code-browser-scroll-sync.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,wBAAgB,iBAAiB,CAC/B,eAAe,EAAE,MAAM,EACvB,kBAAkB,EAAE,MAAM,EAC1B,kBAAkB,EAAE,MAAM,EAC1B,kBAAkB,EAAE,MAAM,EAC1B,kBAAkB,EAAE,MAAM,GACzB,MAAM,CAMR"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Maps one pane’s scroll position to the other for **proportional** scroll sync
|
|
3
|
+
* (static code browser). Mirrors the ratio fallback used while editing when
|
|
4
|
+
* there are no block markers yet.
|
|
5
|
+
*/
|
|
6
|
+
export function mirroredScrollTop(sourceScrollTop, sourceScrollHeight, sourceClientHeight, targetScrollHeight, targetClientHeight) {
|
|
7
|
+
const maxSource = Math.max(0, sourceScrollHeight - sourceClientHeight);
|
|
8
|
+
const maxTarget = Math.max(0, targetScrollHeight - targetClientHeight);
|
|
9
|
+
if (maxSource <= 0)
|
|
10
|
+
return 0;
|
|
11
|
+
const ratio = sourceScrollTop / maxSource;
|
|
12
|
+
return ratio * maxTarget;
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=code-browser-scroll-sync.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"code-browser-scroll-sync.js","sourceRoot":"","sources":["../src/code-browser-scroll-sync.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,UAAU,iBAAiB,CAC/B,eAAuB,EACvB,kBAA0B,EAC1B,kBAA0B,EAC1B,kBAA0B,EAC1B,kBAA0B;IAE1B,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,kBAAkB,GAAG,kBAAkB,CAAC,CAAC;IACvE,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,kBAAkB,GAAG,kBAAkB,CAAC,CAAC;IACvE,IAAI,SAAS,IAAI,CAAC;QAAE,OAAO,CAAC,CAAC;IAC7B,MAAM,KAAK,GAAG,eAAe,GAAG,SAAS,CAAC;IAC1C,OAAO,KAAK,GAAG,SAAS,CAAC;AAC3B,CAAC"}
|
package/dist/code-browser.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type CommentrayOutputUrlOptions } from "./markdown-pipeline.js";
|
|
1
2
|
export type CodeBrowserPageOptions = {
|
|
2
3
|
title?: string;
|
|
3
4
|
/** Repo-relative (or otherwise meaningful) path to display prominently in the toolbar. */
|
|
@@ -8,6 +9,34 @@ export type CodeBrowserPageOptions = {
|
|
|
8
9
|
includeMermaidRuntime?: boolean;
|
|
9
10
|
/** Highlight.js stylesheet base name (e.g. github, github-dark). */
|
|
10
11
|
hljsTheme?: string;
|
|
12
|
+
/**
|
|
13
|
+
* Public Git (or other) URL for the repository whose source is shown — renders
|
|
14
|
+
* as an Octocat link in the toolbar (top-right cluster on wide viewports).
|
|
15
|
+
* Only `http:` / `https:` URLs are emitted.
|
|
16
|
+
*/
|
|
17
|
+
githubRepoUrl?: string;
|
|
18
|
+
/**
|
|
19
|
+
* Home URL for the Commentray project (shown as “Rendered with Commentray”).
|
|
20
|
+
* Only `http:` / `https:` URLs are emitted.
|
|
21
|
+
*/
|
|
22
|
+
toolHomeUrl?: string;
|
|
23
|
+
/**
|
|
24
|
+
* When set, local `img`/`a` URLs and optional GitHub blob/tree rewrites resolve to paths
|
|
25
|
+
* relative to the generated HTML file.
|
|
26
|
+
*/
|
|
27
|
+
commentrayOutputUrls?: CommentrayOutputUrlOptions;
|
|
28
|
+
/**
|
|
29
|
+
* Optional “Also on GitHub …” toolbar links (other repo files). Used when only a single
|
|
30
|
+
* `index.html` is published so in-repo Markdown links cannot target sibling paths on Pages.
|
|
31
|
+
*/
|
|
32
|
+
relatedGithubNav?: {
|
|
33
|
+
label: string;
|
|
34
|
+
href: string;
|
|
35
|
+
}[];
|
|
36
|
+
/**
|
|
37
|
+
* Free-form label for `<meta name="generator">` (e.g. package versions). Omitted when unset.
|
|
38
|
+
*/
|
|
39
|
+
generatorLabel?: string;
|
|
11
40
|
};
|
|
12
41
|
/**
|
|
13
42
|
* Static HTML shell for a minimal “code browser”: code + rendered commentray,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"code-browser.d.ts","sourceRoot":"","sources":["../src/code-browser.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"code-browser.d.ts","sourceRoot":"","sources":["../src/code-browser.ts"],"names":[],"mappings":"AAKA,OAAO,EACL,KAAK,0BAA0B,EAGhC,MAAM,wBAAwB,CAAC;AAEhC,MAAM,MAAM,sBAAsB,GAAG;IACnC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,0FAA0F;IAC1F,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,kBAAkB,EAAE,MAAM,CAAC;IAC3B,qBAAqB,CAAC,EAAE,OAAO,CAAC;IAChC,oEAAoE;IACpE,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;;OAIG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB;;;OAGG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB;;;OAGG;IACH,oBAAoB,CAAC,EAAE,0BAA0B,CAAC;IAClD;;;OAGG;IACH,gBAAgB,CAAC,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;IACrD;;OAEG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB,CAAC;AAsVF;;;;GAIG;AACH,wBAAsB,qBAAqB,CAAC,IAAI,EAAE,sBAAsB,GAAG,OAAO,CAAC,MAAM,CAAC,CA0CzF"}
|
package/dist/code-browser.js
CHANGED
|
@@ -2,7 +2,13 @@ import { existsSync, readFileSync } from "node:fs";
|
|
|
2
2
|
import { dirname, join } from "node:path";
|
|
3
3
|
import { fileURLToPath } from "node:url";
|
|
4
4
|
import { escapeHtml } from "./html-utils.js";
|
|
5
|
-
import { renderFencedCode, renderMarkdownToHtml } from "./markdown-pipeline.js";
|
|
5
|
+
import { renderFencedCode, renderMarkdownToHtml, } from "./markdown-pipeline.js";
|
|
6
|
+
function renderGeneratorMetaHtml(label) {
|
|
7
|
+
const t = label?.trim();
|
|
8
|
+
if (!t)
|
|
9
|
+
return "";
|
|
10
|
+
return `<meta name="generator" content="${escapeHtml(t)}" />\n `;
|
|
11
|
+
}
|
|
6
12
|
function extractPreCodeInner(html) {
|
|
7
13
|
const m = /<pre(?:\s[^>]*)?>\s*<code(?:\s[^>]*)?>([\s\S]*?)<\/code>\s*<\/pre>/i.exec(html.trim());
|
|
8
14
|
return m ? m[1] : escapeHtml(html);
|
|
@@ -47,6 +53,43 @@ function renderFilePathLabel(filePath, fallbackTitle) {
|
|
|
47
53
|
`<span class="file-path__base">${escapeHtml(base)}</span>` +
|
|
48
54
|
`</strong>`);
|
|
49
55
|
}
|
|
56
|
+
/** GitHub “mark” glyph (Octicons-style path), MIT-licensed silhouette. */
|
|
57
|
+
const GITHUB_MARK_SVG = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" width="20" height="20" fill="currentColor" aria-hidden="true">' +
|
|
58
|
+
'<path d="M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.013 8.013 0 0016 8c0-4.42-3.58-8-8-8z"/>' +
|
|
59
|
+
"</svg>";
|
|
60
|
+
function safeExternalHttpUrl(url) {
|
|
61
|
+
const t = url?.trim();
|
|
62
|
+
if (!t)
|
|
63
|
+
return null;
|
|
64
|
+
if (!/^https?:\/\//i.test(t))
|
|
65
|
+
return null;
|
|
66
|
+
return t;
|
|
67
|
+
}
|
|
68
|
+
function buildToolbarEndHtml(githubRepoUrl, toolHomeUrl) {
|
|
69
|
+
const gh = safeExternalHttpUrl(githubRepoUrl);
|
|
70
|
+
const tool = safeExternalHttpUrl(toolHomeUrl);
|
|
71
|
+
const bits = [];
|
|
72
|
+
if (gh) {
|
|
73
|
+
const he = escapeHtml(gh);
|
|
74
|
+
bits.push(`<a class="toolbar-github" href="${he}" target="_blank" rel="noopener noreferrer" aria-label="View repository on GitHub" title="View repository on GitHub">${GITHUB_MARK_SVG}</a>`);
|
|
75
|
+
}
|
|
76
|
+
if (tool) {
|
|
77
|
+
const te = escapeHtml(tool);
|
|
78
|
+
bits.push(`<span class="toolbar-attribution" role="note">Rendered with <a href="${te}" target="_blank" rel="noopener noreferrer">Commentray</a></span>`);
|
|
79
|
+
}
|
|
80
|
+
if (bits.length === 0)
|
|
81
|
+
return "";
|
|
82
|
+
return `<div class="toolbar__end">${bits.join("")}</div>`;
|
|
83
|
+
}
|
|
84
|
+
function renderRelatedGithubNavHtml(links) {
|
|
85
|
+
if (links.length === 0)
|
|
86
|
+
return "";
|
|
87
|
+
const parts = links.map((l) => `<a href="${escapeHtml(l.href)}" target="_blank" rel="noopener noreferrer">${escapeHtml(l.label)}</a>`);
|
|
88
|
+
return (`<nav class="toolbar-related" aria-label="Open other repository files on GitHub">` +
|
|
89
|
+
`<span class="toolbar-related__prefix">Also on GitHub</span>` +
|
|
90
|
+
`<span class="toolbar-related__links">${parts.join('<span class="toolbar-related__sep" aria-hidden="true"> · </span>')}</span>` +
|
|
91
|
+
`</nav>`);
|
|
92
|
+
}
|
|
50
93
|
/** IIFE produced by `npm run build -w @commentray/render` (esbuild of `code-browser-client.ts`). */
|
|
51
94
|
function loadCodeBrowserClientBundle() {
|
|
52
95
|
const here = dirname(fileURLToPath(import.meta.url));
|
|
@@ -68,6 +111,30 @@ const CODE_BROWSER_STYLES = `
|
|
|
68
111
|
border-bottom: 1px solid color-mix(in oklab, CanvasText 18%, Canvas);
|
|
69
112
|
font-size: 13px; flex: 0 0 auto;
|
|
70
113
|
}
|
|
114
|
+
.toolbar__main {
|
|
115
|
+
display: flex; flex-wrap: wrap; align-items: center; gap: 10px 14px;
|
|
116
|
+
flex: 1 1 280px;
|
|
117
|
+
min-width: 0;
|
|
118
|
+
}
|
|
119
|
+
.toolbar__end {
|
|
120
|
+
display: flex; flex-wrap: wrap; align-items: center; gap: 10px 14px;
|
|
121
|
+
margin-left: auto;
|
|
122
|
+
justify-content: flex-end;
|
|
123
|
+
}
|
|
124
|
+
.toolbar-github {
|
|
125
|
+
display: inline-flex; align-items: center; justify-content: center;
|
|
126
|
+
width: 34px; height: 34px; border-radius: 8px;
|
|
127
|
+
border: 1px solid color-mix(in oklab, CanvasText 22%, Canvas);
|
|
128
|
+
background: color-mix(in oklab, CanvasText 6%, Canvas);
|
|
129
|
+
color: CanvasText;
|
|
130
|
+
}
|
|
131
|
+
.toolbar-github:hover { background: color-mix(in oklab, CanvasText 11%, Canvas); }
|
|
132
|
+
.toolbar-github:focus-visible { outline: 2px solid color-mix(in oklab, CanvasText 45%, Canvas); outline-offset: 2px; }
|
|
133
|
+
.toolbar-attribution {
|
|
134
|
+
font-size: 11px; line-height: 1.35; opacity: 0.82; max-width: min(360px, 42vw);
|
|
135
|
+
text-align: right; color: color-mix(in oklab, CanvasText 88%, Canvas);
|
|
136
|
+
}
|
|
137
|
+
.toolbar-attribution a { color: inherit; font-weight: 600; text-decoration: underline; text-underline-offset: 2px; }
|
|
71
138
|
.toolbar label { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; user-select: none; }
|
|
72
139
|
.toolbar .file-path {
|
|
73
140
|
font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, monospace;
|
|
@@ -83,6 +150,18 @@ const CODE_BROWSER_STYLES = `
|
|
|
83
150
|
color: CanvasText; font-weight: 600;
|
|
84
151
|
}
|
|
85
152
|
.toolbar .file-path--title { font-weight: 600; }
|
|
153
|
+
.toolbar-related {
|
|
154
|
+
display: inline-flex; flex-wrap: wrap; align-items: baseline; gap: 6px 10px;
|
|
155
|
+
max-width: min(520px, 90vw); font-size: 12px; line-height: 1.35;
|
|
156
|
+
color: color-mix(in oklab, CanvasText 88%, Canvas);
|
|
157
|
+
}
|
|
158
|
+
.toolbar-related__prefix { font-weight: 600; opacity: 0.85; white-space: nowrap; }
|
|
159
|
+
.toolbar-related__links { min-width: 0; }
|
|
160
|
+
.toolbar-related a {
|
|
161
|
+
color: inherit; text-decoration: underline; text-underline-offset: 2px; font-weight: 500;
|
|
162
|
+
word-break: break-word;
|
|
163
|
+
}
|
|
164
|
+
.toolbar-related__sep { opacity: 0.55; user-select: none; }
|
|
86
165
|
.toolbar .search-field {
|
|
87
166
|
display: inline-flex; align-items: center; gap: 6px; flex: 1 1 220px; min-width: 160px;
|
|
88
167
|
}
|
|
@@ -159,13 +238,13 @@ const CODE_BROWSER_STYLES = `
|
|
|
159
238
|
.app { display: flex; flex-direction: column; height: 100vh; }
|
|
160
239
|
`;
|
|
161
240
|
function buildCodeBrowserPageHtml(p) {
|
|
162
|
-
const { title, filePathHtml, codeHtml, commentrayHtml, rawCodeB64, rawMdB64, hljs, hljsDark, mermaidScript, } = p;
|
|
241
|
+
const { title, generatorMetaHtml, filePathHtml, relatedNavHtml, toolbarEndHtml, codeHtml, commentrayHtml, rawCodeB64, rawMdB64, hljs, hljsDark, mermaidScript, } = p;
|
|
163
242
|
return `<!doctype html>
|
|
164
243
|
<html lang="en">
|
|
165
244
|
<head>
|
|
166
245
|
<meta charset="utf-8" />
|
|
167
246
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
168
|
-
<title>${escapeHtml(title)}</title>
|
|
247
|
+
${generatorMetaHtml}<title>${escapeHtml(title)}</title>
|
|
169
248
|
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/highlightjs/cdn-release@11.11.1/build/styles/${escapeHtml(hljs)}.min.css" media="(prefers-color-scheme: light)" />
|
|
170
249
|
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/highlightjs/cdn-release@11.11.1/build/styles/${escapeHtml(hljsDark)}.min.css" media="(prefers-color-scheme: dark)" />
|
|
171
250
|
<style>
|
|
@@ -175,13 +254,17 @@ ${CODE_BROWSER_STYLES}
|
|
|
175
254
|
<body>
|
|
176
255
|
<div class="app">
|
|
177
256
|
<header class="toolbar" aria-label="View options">
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
<
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
257
|
+
<div class="toolbar__main">
|
|
258
|
+
${filePathHtml}
|
|
259
|
+
<span class="search-field">
|
|
260
|
+
<label for="search-q">Search</label>
|
|
261
|
+
<input type="search" id="search-q" placeholder="Whole source (ordered tokens + fuzzy lines)…" autocomplete="off" spellcheck="false" />
|
|
262
|
+
<button type="button" id="search-clear" title="Clear search">Clear</button>
|
|
263
|
+
</span>
|
|
264
|
+
${relatedNavHtml}
|
|
265
|
+
<label><input type="checkbox" id="wrap-lines" /> Wrap code lines</label>
|
|
266
|
+
</div>
|
|
267
|
+
${toolbarEndHtml}
|
|
185
268
|
</header>
|
|
186
269
|
<div class="search-results" id="search-results" hidden aria-live="polite"></div>
|
|
187
270
|
<div class="shell" id="shell">
|
|
@@ -211,12 +294,15 @@ ${loadCodeBrowserClientBundle()}
|
|
|
211
294
|
export async function renderCodeBrowserHtml(opts) {
|
|
212
295
|
const [codeHtml, commentrayHtml] = await Promise.all([
|
|
213
296
|
renderCodeLineBlocks(opts.code, opts.language),
|
|
214
|
-
renderMarkdownToHtml(opts.commentrayMarkdown
|
|
297
|
+
renderMarkdownToHtml(opts.commentrayMarkdown, {
|
|
298
|
+
commentrayOutputUrls: opts.commentrayOutputUrls,
|
|
299
|
+
}),
|
|
215
300
|
]);
|
|
216
301
|
const rawCodeB64 = Buffer.from(opts.code, "utf8").toString("base64");
|
|
217
302
|
const rawMdB64 = Buffer.from(opts.commentrayMarkdown, "utf8").toString("base64");
|
|
218
303
|
const title = opts.title ?? opts.filePath ?? "Commentray";
|
|
219
304
|
const filePathHtml = renderFilePathLabel(opts.filePath, title);
|
|
305
|
+
const toolbarEndHtml = buildToolbarEndHtml(opts.githubRepoUrl, opts.toolHomeUrl);
|
|
220
306
|
const hljs = opts.hljsTheme ?? "github";
|
|
221
307
|
const hljsDark = opts.hljsTheme?.includes("dark") ? opts.hljsTheme : "github-dark";
|
|
222
308
|
const mermaidScript = opts.includeMermaidRuntime
|
|
@@ -226,9 +312,14 @@ mermaid.initialize({ startOnLoad: true, securityLevel: "strict" });
|
|
|
226
312
|
mermaid.run({ querySelector: ".mermaid" });
|
|
227
313
|
</script>`
|
|
228
314
|
: "";
|
|
315
|
+
const relatedNavHtml = renderRelatedGithubNavHtml(opts.relatedGithubNav ?? []);
|
|
316
|
+
const generatorMetaHtml = renderGeneratorMetaHtml(opts.generatorLabel);
|
|
229
317
|
return buildCodeBrowserPageHtml({
|
|
230
318
|
title,
|
|
319
|
+
generatorMetaHtml,
|
|
231
320
|
filePathHtml,
|
|
321
|
+
relatedNavHtml,
|
|
322
|
+
toolbarEndHtml,
|
|
232
323
|
codeHtml,
|
|
233
324
|
commentrayHtml,
|
|
234
325
|
rawCodeB64,
|
package/dist/code-browser.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"code-browser.js","sourceRoot":"","sources":["../src/code-browser.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACnD,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEzC,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,
|
|
1
|
+
{"version":3,"file":"code-browser.js","sourceRoot":"","sources":["../src/code-browser.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACnD,OAAO,EAAE,OAAO,EAAE,IAAI,EA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,EAAE,KAAK,CAAC,CAAC;IAC/D,MAAM,cAAc,GAAG,mBAAmB,CAAC,IAAI,CAAC,aAAa,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC;IACjF,MAAM,IAAI,GAAG,IAAI,CAAC,SAAS,IAAI,QAAQ,CAAC;IACxC,MAAM,QAAQ,GAAG,IAAI,CAAC,SAAS,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,aAAa,CAAC;IAEnF,MAAM,aAAa,GAAG,IAAI,CAAC,qBAAqB;QAC9C,CAAC,CAAC;;;;UAII;QACN,CAAC,CAAC,EAAE,CAAC;IAEP,MAAM,cAAc,GAAG,0BAA0B,CAAC,IAAI,CAAC,gBAAgB,IAAI,EAAE,CAAC,CAAC;IAC/E,MAAM,iBAAiB,GAAG,uBAAuB,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;IAEvE,OAAO,wBAAwB,CAAC;QAC9B,KAAK;QACL,iBAAiB;QACjB,YAAY;QACZ,cAAc;QACd,cAAc;QACd,QAAQ;QACR,cAAc;QACd,UAAU;QACV,QAAQ;QACR,IAAI;QACJ,QAAQ;QACR,aAAa;KACd,CAAC,CAAC;AACL,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
export { renderCodeBrowserHtml } from "./code-browser.js";
|
|
2
2
|
export type { CodeBrowserPageOptions } from "./code-browser.js";
|
|
3
|
+
export { commentrayRenderVersion } from "./package-version.js";
|
|
4
|
+
export type { CommentrayOutputUrlOptions, MarkdownPipelineOptions } from "./markdown-pipeline.js";
|
|
3
5
|
export { renderFencedCode, renderMarkdownToHtml } from "./markdown-pipeline.js";
|
|
4
6
|
export { renderSideBySideHtml } from "./side-by-side.js";
|
|
5
7
|
export type { SideBySideOptions } from "./side-by-side.js";
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAC1D,YAAY,EAAE,sBAAsB,EAAE,MAAM,mBAAmB,CAAC;AAChE,OAAO,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAChF,OAAO,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AACzD,YAAY,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAC1D,YAAY,EAAE,sBAAsB,EAAE,MAAM,mBAAmB,CAAC;AAChE,OAAO,EAAE,uBAAuB,EAAE,MAAM,sBAAsB,CAAC;AAC/D,YAAY,EAAE,0BAA0B,EAAE,uBAAuB,EAAE,MAAM,wBAAwB,CAAC;AAClG,OAAO,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAChF,OAAO,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AACzD,YAAY,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { renderCodeBrowserHtml } from "./code-browser.js";
|
|
2
|
+
export { commentrayRenderVersion } from "./package-version.js";
|
|
2
3
|
export { renderFencedCode, renderMarkdownToHtml } from "./markdown-pipeline.js";
|
|
3
4
|
export { renderSideBySideHtml } from "./side-by-side.js";
|
|
4
5
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAE1D,OAAO,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAChF,OAAO,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAE1D,OAAO,EAAE,uBAAuB,EAAE,MAAM,sBAAsB,CAAC;AAE/D,OAAO,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAChF,OAAO,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC"}
|
|
@@ -1,3 +1,25 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* When generating static HTML (Pages, `commentray render`), rewrites `img[src]` and `a[href]`
|
|
3
|
+
* so local assets work from the output file location.
|
|
4
|
+
*
|
|
5
|
+
* **URL rules** (same commentray file as in the editor):
|
|
6
|
+
* - **`/path/to/file`** — repository root (leading slash), POSIX-style.
|
|
7
|
+
* - **`./` / `../` / `figures/a.png`** — relative to the commentray file’s directory
|
|
8
|
+
* (`markdownUrlBaseDirAbs`), i.e. normal Markdown resolution.
|
|
9
|
+
*/
|
|
10
|
+
export type CommentrayOutputUrlOptions = {
|
|
11
|
+
repoRootAbs: string;
|
|
12
|
+
htmlOutputFileAbs: string;
|
|
13
|
+
markdownUrlBaseDirAbs: string;
|
|
14
|
+
/** When set, `https://github.com/<owner>/<repo>/blob|tree/<branch>/…` becomes a `/…` repo path. */
|
|
15
|
+
githubBlobRepo?: {
|
|
16
|
+
owner: string;
|
|
17
|
+
repo: string;
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
export type MarkdownPipelineOptions = {
|
|
21
|
+
commentrayOutputUrls?: CommentrayOutputUrlOptions;
|
|
22
|
+
};
|
|
23
|
+
export declare function renderMarkdownToHtml(markdown: string, options?: MarkdownPipelineOptions): Promise<string>;
|
|
2
24
|
export declare function renderFencedCode(markdownFence: string): Promise<string>;
|
|
3
25
|
//# sourceMappingURL=markdown-pipeline.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"markdown-pipeline.d.ts","sourceRoot":"","sources":["../src/markdown-pipeline.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"markdown-pipeline.d.ts","sourceRoot":"","sources":["../src/markdown-pipeline.ts"],"names":[],"mappings":"AAeA;;;;;;;;GAQG;AACH,MAAM,MAAM,0BAA0B,GAAG;IACvC,WAAW,EAAE,MAAM,CAAC;IACpB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,qBAAqB,EAAE,MAAM,CAAC;IAC9B,mGAAmG;IACnG,cAAc,CAAC,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC;CAClD,CAAC;AAEF,MAAM,MAAM,uBAAuB,GAAG;IACpC,oBAAoB,CAAC,EAAE,0BAA0B,CAAC;CACnD,CAAC;AA6IF,wBAAsB,oBAAoB,CACxC,QAAQ,EAAE,MAAM,EAChB,OAAO,CAAC,EAAE,uBAAuB,GAChC,OAAO,CAAC,MAAM,CAAC,CAyBjB;AAED,wBAAsB,gBAAgB,CAAC,aAAa,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAE7E"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import path from "node:path";
|
|
1
2
|
import rehypeHighlight from "rehype-highlight";
|
|
2
3
|
import rehypeSanitize, { defaultSchema } from "rehype-sanitize";
|
|
3
4
|
import rehypeStringify from "rehype-stringify";
|
|
@@ -7,6 +8,117 @@ import remarkRehype from "remark-rehype";
|
|
|
7
8
|
import { unified } from "unified";
|
|
8
9
|
import { visit } from "unist-util-visit";
|
|
9
10
|
import { escapeHtml } from "./html-utils.js";
|
|
11
|
+
function escapeRegExp(s) {
|
|
12
|
+
return s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
13
|
+
}
|
|
14
|
+
function stripUrlQueryAndHash(s) {
|
|
15
|
+
let end = s.length;
|
|
16
|
+
const q = s.indexOf("?");
|
|
17
|
+
const h = s.indexOf("#");
|
|
18
|
+
if (q >= 0)
|
|
19
|
+
end = Math.min(end, q);
|
|
20
|
+
if (h >= 0)
|
|
21
|
+
end = Math.min(end, h);
|
|
22
|
+
return s.slice(0, end);
|
|
23
|
+
}
|
|
24
|
+
function tryExtractRepoFilePathFromGithubUrl(url, owner, repo) {
|
|
25
|
+
const re = new RegExp(`^https://github\\.com/${escapeRegExp(owner)}/${escapeRegExp(repo)}/(?:blob|tree)/[^/]+/(.+)$`, "i");
|
|
26
|
+
const m = re.exec(url.trim());
|
|
27
|
+
if (!m)
|
|
28
|
+
return null;
|
|
29
|
+
let tail = m[1];
|
|
30
|
+
try {
|
|
31
|
+
tail = decodeURIComponent(tail);
|
|
32
|
+
}
|
|
33
|
+
catch {
|
|
34
|
+
// keep encoded path
|
|
35
|
+
}
|
|
36
|
+
return stripUrlQueryAndHash(tail);
|
|
37
|
+
}
|
|
38
|
+
function remarkGithubBlobToRepoPaths(opts) {
|
|
39
|
+
const { owner, repo } = opts;
|
|
40
|
+
return (tree) => {
|
|
41
|
+
const rewrite = (url) => {
|
|
42
|
+
const next = tryExtractRepoFilePathFromGithubUrl(url, owner, repo);
|
|
43
|
+
if (!next)
|
|
44
|
+
return null;
|
|
45
|
+
const posix = next.replace(/\\/g, "/").replace(/^\/+/, "");
|
|
46
|
+
return posix ? `/${posix}` : null;
|
|
47
|
+
};
|
|
48
|
+
visit(tree, "link", (node) => {
|
|
49
|
+
const next = rewrite(node.url);
|
|
50
|
+
if (next)
|
|
51
|
+
node.url = next;
|
|
52
|
+
});
|
|
53
|
+
visit(tree, "image", (node) => {
|
|
54
|
+
const next = rewrite(node.url);
|
|
55
|
+
if (next)
|
|
56
|
+
node.url = next;
|
|
57
|
+
});
|
|
58
|
+
visit(tree, "definition", (node) => {
|
|
59
|
+
const next = rewrite(node.url);
|
|
60
|
+
if (next)
|
|
61
|
+
node.url = next;
|
|
62
|
+
});
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
function posixHref(fsPath) {
|
|
66
|
+
return fsPath.split(path.sep).join("/");
|
|
67
|
+
}
|
|
68
|
+
function decodeUrlPath(s) {
|
|
69
|
+
try {
|
|
70
|
+
return decodeURIComponent(s);
|
|
71
|
+
}
|
|
72
|
+
catch {
|
|
73
|
+
return s;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
function rehypeCommentrayOutputUrls(ctx) {
|
|
77
|
+
const repoRoot = path.resolve(ctx.repoRootAbs);
|
|
78
|
+
const htmlDir = path.dirname(path.resolve(ctx.htmlOutputFileAbs));
|
|
79
|
+
const baseDir = path.resolve(ctx.markdownUrlBaseDirAbs);
|
|
80
|
+
function resolveTargetAbs(raw) {
|
|
81
|
+
const t = raw.trim();
|
|
82
|
+
if (!t || t.startsWith("#"))
|
|
83
|
+
return null;
|
|
84
|
+
if (/^[a-zA-Z][a-zA-Z0-9+.-]*:/i.test(t))
|
|
85
|
+
return null;
|
|
86
|
+
if (t.startsWith("//"))
|
|
87
|
+
return null;
|
|
88
|
+
let resolved;
|
|
89
|
+
if (t.startsWith("/")) {
|
|
90
|
+
const rest = decodeUrlPath(t.replace(/^\/+/, ""));
|
|
91
|
+
const segments = rest.split("/").filter((s) => s && s !== "." && s !== "..");
|
|
92
|
+
resolved = path.normalize(path.join(repoRoot, ...segments));
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
const decoded = decodeUrlPath(t);
|
|
96
|
+
resolved = path.normalize(path.resolve(baseDir, decoded));
|
|
97
|
+
}
|
|
98
|
+
const relToRepo = path.relative(repoRoot, resolved);
|
|
99
|
+
if (relToRepo.startsWith("..") || path.isAbsolute(relToRepo))
|
|
100
|
+
return null;
|
|
101
|
+
const out = path.relative(htmlDir, resolved);
|
|
102
|
+
if (path.isAbsolute(out))
|
|
103
|
+
return null;
|
|
104
|
+
return posixHref(out);
|
|
105
|
+
}
|
|
106
|
+
return (tree) => {
|
|
107
|
+
visit(tree, "element", (node) => {
|
|
108
|
+
if (node.tagName !== "a" && node.tagName !== "img")
|
|
109
|
+
return;
|
|
110
|
+
const key = node.tagName === "a" ? "href" : "src";
|
|
111
|
+
const raw = node.properties?.[key];
|
|
112
|
+
if (typeof raw !== "string")
|
|
113
|
+
return;
|
|
114
|
+
const next = resolveTargetAbs(raw);
|
|
115
|
+
if (next == null)
|
|
116
|
+
return;
|
|
117
|
+
node.properties ??= {};
|
|
118
|
+
node.properties[key] = next;
|
|
119
|
+
});
|
|
120
|
+
};
|
|
121
|
+
}
|
|
10
122
|
function remarkMermaidPlaceholders() {
|
|
11
123
|
return (tree) => {
|
|
12
124
|
visit(tree, "code", (node, index, parent) => {
|
|
@@ -29,13 +141,29 @@ sanitizeSchema.attributes = {
|
|
|
29
141
|
span: [...(sanitizeSchema.attributes?.span ?? []), "className"],
|
|
30
142
|
div: ["className"],
|
|
31
143
|
};
|
|
32
|
-
export async function renderMarkdownToHtml(markdown) {
|
|
144
|
+
export async function renderMarkdownToHtml(markdown, options) {
|
|
145
|
+
const outUrls = options?.commentrayOutputUrls;
|
|
33
146
|
const file = await unified()
|
|
34
147
|
.use(remarkParse)
|
|
35
148
|
.use(remarkGfm)
|
|
149
|
+
.use(function remarkGithubBlobMaybe() {
|
|
150
|
+
return (tree) => {
|
|
151
|
+
const gh = outUrls?.githubBlobRepo;
|
|
152
|
+
if (!gh)
|
|
153
|
+
return;
|
|
154
|
+
remarkGithubBlobToRepoPaths({ owner: gh.owner, repo: gh.repo })(tree);
|
|
155
|
+
};
|
|
156
|
+
})
|
|
36
157
|
.use(remarkMermaidPlaceholders)
|
|
37
158
|
.use(remarkRehype, { allowDangerousHtml: true })
|
|
38
159
|
.use(rehypeSanitize, sanitizeSchema)
|
|
160
|
+
.use(function rehypeOutputUrlsMaybe() {
|
|
161
|
+
return (tree) => {
|
|
162
|
+
if (!outUrls)
|
|
163
|
+
return;
|
|
164
|
+
rehypeCommentrayOutputUrls(outUrls)(tree);
|
|
165
|
+
};
|
|
166
|
+
})
|
|
39
167
|
.use(rehypeHighlight)
|
|
40
168
|
.use(rehypeStringify)
|
|
41
169
|
.process(markdown);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"markdown-pipeline.js","sourceRoot":"","sources":["../src/markdown-pipeline.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"markdown-pipeline.js","sourceRoot":"","sources":["../src/markdown-pipeline.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAC;AAI7B,OAAO,eAAe,MAAM,kBAAkB,CAAC;AAC/C,OAAO,cAAc,EAAE,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChE,OAAO,eAAe,MAAM,kBAAkB,CAAC;AAC/C,OAAO,SAAS,MAAM,YAAY,CAAC;AACnC,OAAO,WAAW,MAAM,cAAc,CAAC;AACvC,OAAO,YAAY,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAEzC,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAuB7C,SAAS,YAAY,CAAC,CAAS;IAC7B,OAAO,CAAC,CAAC,OAAO,CAAC,qBAAqB,EAAE,MAAM,CAAC,CAAC;AAClD,CAAC;AAED,SAAS,oBAAoB,CAAC,CAAS;IACrC,IAAI,GAAG,GAAG,CAAC,CAAC,MAAM,CAAC;IACnB,MAAM,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IACzB,MAAM,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IACzB,IAAI,CAAC,IAAI,CAAC;QAAE,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC;IAC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,CAAC,CAAC;IACJ,CAAC,CAAC;SACD,GAAG,CAAC,yBAAyB,CAAC;SAC9B,GAAG,CAAC,YAAY,EAAE,EAAE,kBAAkB,EAAE,IAAI,EAAE,CAAC;SAC/C,GAAG,CAAC,cAAc,EAAE,cAAc,CAAC;SACnC,GAAG,CAAC,SAAS,qBAAqB;QACjC,OAAO,CAAC,IAAc,EAAE,EAAE;YACxB,IAAI,CAAC,OAAO;gBAAE,OAAO;YACrB,0BAA0B,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC;QAC5C,CAAC,CAAC;IACJ,CAAC,CAAC;SACD,GAAG,CAAC,eAAe,CAAC;SACpB,GAAG,CAAC,eAAe,CAAC;SACpB,OAAO,CAAC,QAAQ,CAAC,CAAC;IACrB,OAAO,MAAM,CAAC,IAAI,CAAC,CAAC;AACtB,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,gBAAgB,CAAC,aAAqB;IAC1D,OAAO,oBAAoB,CAAC,aAAa,CAAC,CAAC;AAC7C,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"package-version.d.ts","sourceRoot":"","sources":["../src/package-version.ts"],"names":[],"mappings":"AAIA;;GAEG;AACH,wBAAgB,uBAAuB,IAAI,MAAM,CAMhD"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { readFileSync } from "node:fs";
|
|
2
|
+
import { dirname, join } from "node:path";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
/**
|
|
5
|
+
* Reads `version` from this package’s `package.json` (works for both `src/` and `dist/` layouts).
|
|
6
|
+
*/
|
|
7
|
+
export function commentrayRenderVersion() {
|
|
8
|
+
const here = dirname(fileURLToPath(import.meta.url));
|
|
9
|
+
const packageDir = join(here, "..");
|
|
10
|
+
const raw = readFileSync(join(packageDir, "package.json"), "utf8");
|
|
11
|
+
const j = JSON.parse(raw);
|
|
12
|
+
return j.version ?? "0.0.0";
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=package-version.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"package-version.js","sourceRoot":"","sources":["../src/package-version.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEzC;;GAEG;AACH,MAAM,UAAU,uBAAuB;IACrC,MAAM,IAAI,GAAG,OAAO,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;IACrD,MAAM,UAAU,GAAG,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IACpC,MAAM,GAAG,GAAG,YAAY,CAAC,IAAI,CAAC,UAAU,EAAE,cAAc,CAAC,EAAE,MAAM,CAAC,CAAC;IACnE,MAAM,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAyB,CAAC;IAClD,OAAO,CAAC,CAAC,OAAO,IAAI,OAAO,CAAC;AAC9B,CAAC"}
|
package/dist/side-by-side.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type CommentrayOutputUrlOptions } from "./markdown-pipeline.js";
|
|
1
2
|
export type SideBySideOptions = {
|
|
2
3
|
title?: string;
|
|
3
4
|
/** Source code text (not yet fenced). */
|
|
@@ -8,6 +9,8 @@ export type SideBySideOptions = {
|
|
|
8
9
|
commentrayMarkdown: string;
|
|
9
10
|
/** When true, include Mermaid runtime from CDN in the footer. */
|
|
10
11
|
includeMermaidRuntime?: boolean;
|
|
12
|
+
/** Optional static URL rewriting for the commentray pane (images, local links, GitHub blob). */
|
|
13
|
+
commentrayOutputUrls?: CommentrayOutputUrlOptions;
|
|
11
14
|
};
|
|
12
15
|
export declare function renderSideBySideHtml(opts: SideBySideOptions): Promise<string>;
|
|
13
16
|
//# sourceMappingURL=side-by-side.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"side-by-side.d.ts","sourceRoot":"","sources":["../src/side-by-side.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"side-by-side.d.ts","sourceRoot":"","sources":["../src/side-by-side.ts"],"names":[],"mappings":"AACA,OAAO,EACL,KAAK,0BAA0B,EAGhC,MAAM,wBAAwB,CAAC;AAEhC,MAAM,MAAM,iBAAiB,GAAG;IAC9B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,yCAAyC;IACzC,IAAI,EAAE,MAAM,CAAC;IACb,2DAA2D;IAC3D,QAAQ,EAAE,MAAM,CAAC;IACjB,gCAAgC;IAChC,kBAAkB,EAAE,MAAM,CAAC;IAC3B,iEAAiE;IACjE,qBAAqB,CAAC,EAAE,OAAO,CAAC;IAChC,gGAAgG;IAChG,oBAAoB,CAAC,EAAE,0BAA0B,CAAC;CACnD,CAAC;AAEF,wBAAsB,oBAAoB,CAAC,IAAI,EAAE,iBAAiB,GAAG,OAAO,CAAC,MAAM,CAAC,CAmDnF"}
|
package/dist/side-by-side.js
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { escapeHtml } from "./html-utils.js";
|
|
2
|
-
import { renderFencedCode, renderMarkdownToHtml } from "./markdown-pipeline.js";
|
|
2
|
+
import { renderFencedCode, renderMarkdownToHtml, } from "./markdown-pipeline.js";
|
|
3
3
|
export async function renderSideBySideHtml(opts) {
|
|
4
4
|
const fence = "```" + opts.language + "\n" + opts.code + "\n```\n";
|
|
5
5
|
const [codeHtml, commentrayHtml] = await Promise.all([
|
|
6
6
|
renderFencedCode(fence),
|
|
7
|
-
renderMarkdownToHtml(opts.commentrayMarkdown
|
|
7
|
+
renderMarkdownToHtml(opts.commentrayMarkdown, {
|
|
8
|
+
commentrayOutputUrls: opts.commentrayOutputUrls,
|
|
9
|
+
}),
|
|
8
10
|
]);
|
|
9
11
|
const mermaidScript = opts.includeMermaidRuntime
|
|
10
12
|
? `<script type="module">
|
package/dist/side-by-side.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"side-by-side.js","sourceRoot":"","sources":["../src/side-by-side.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,
|
|
1
|
+
{"version":3,"file":"side-by-side.js","sourceRoot":"","sources":["../src/side-by-side.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAEL,gBAAgB,EAChB,oBAAoB,GACrB,MAAM,wBAAwB,CAAC;AAgBhC,MAAM,CAAC,KAAK,UAAU,oBAAoB,CAAC,IAAuB;IAChE,MAAM,KAAK,GAAG,KAAK,GAAG,IAAI,CAAC,QAAQ,GAAG,IAAI,GAAG,IAAI,CAAC,IAAI,GAAG,SAAS,CAAC;IACnE,MAAM,CAAC,QAAQ,EAAE,cAAc,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC;QACnD,gBAAgB,CAAC,KAAK,CAAC;QACvB,oBAAoB,CAAC,IAAI,CAAC,kBAAkB,EAAE;YAC5C,oBAAoB,EAAE,IAAI,CAAC,oBAAoB;SAChD,CAAC;KACH,CAAC,CAAC;IAEH,MAAM,aAAa,GAAG,IAAI,CAAC,qBAAqB;QAC9C,CAAC,CAAC;;;;UAII;QACN,CAAC,CAAC,EAAE,CAAC;IAEP,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,IAAI,YAAY,CAAC;IAEzC,OAAO;;;;;aAKI,UAAU,CAAC,KAAK,CAAC;;;;;;;;;;;;;;;;;UAiBpB,QAAQ;;;;UAIR,cAAc;;;MAGlB,aAAa;;QAEX,CAAC;AACT,CAAC"}
|