@fnndsc/argus 0.48.2 → 0.49.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (29) hide show
  1. package/dist/assets/{Settings-2RQVwvnQ.js → Settings-bQo_Uhzb.js} +1 -1
  2. package/dist/assets/{Texture-BTXL_xdB.js → Texture-BujGXFjY.js} +1 -1
  3. package/dist/assets/{addVolumesToViewports-DJp6hKow.js → addVolumesToViewports-lnwICSVa.js} +1 -1
  4. package/dist/assets/{asciidoc-BvmVgZkb.js → asciidoc-BDxEHPls.js} +1 -1
  5. package/dist/assets/{cornerstoneEngine-BleRTwP7.js → cornerstoneEngine-C6E2FBPw.js} +2 -2
  6. package/dist/assets/{documentEngines-Dku3XAlE.js → documentEngines-BFRE9kxy.js} +1 -1
  7. package/dist/assets/{field-DBwJhEgd.js → field-D054s_Yd.js} +1 -1
  8. package/dist/assets/{index-KIrn2OnR.js → index-3wLYaZJC.js} +1 -1
  9. package/dist/assets/{index-D4jKFjXY.js → index-B3Zv_spC.js} +1 -1
  10. package/dist/assets/{index-DniTzx9c.js → index-BhYTEuA8.js} +1 -1
  11. package/dist/assets/{index-C6QjPZQ_.js → index-C42xvwZJ.js} +1 -1
  12. package/dist/assets/{index-CNGZbo-S.js → index-CBTMj6gs.js} +1 -1
  13. package/dist/assets/{index-COu2z5IR.js → index-CD_iMftv.js} +279 -267
  14. package/dist/assets/{index-JoTqs14_.js → index-CSu2upM0.js} +1 -1
  15. package/dist/assets/{index-C2PSqMru.js → index-CVfYhfUs.js} +1 -1
  16. package/dist/assets/{index-CXPkJUt9.js → index-CpvURoYW.js} +1 -1
  17. package/dist/assets/{index-2CG51jjM.css → index-D3TCoYz4.css} +1 -1
  18. package/dist/assets/{index-96g1c4N8.js → index-DXnaTMDl.js} +1 -1
  19. package/dist/assets/{index-C7-uwVws.js → index-DlZ9lXp8.js} +1 -1
  20. package/dist/assets/{index-DvRiiN3w.js → index-DwuacFIm.js} +1 -1
  21. package/dist/assets/{index-SEFX26xD.js → index-IpdHrEB7.js} +1 -1
  22. package/dist/assets/{index-Cos2T2Dw.js → index-wHAASEDd.js} +1 -1
  23. package/dist/assets/{niivueEngine-Dd9ONOnD.js → niivueEngine-Dm-6EbPG.js} +2 -2
  24. package/dist/assets/{slabScene-gPj785hr.js → slabScene-9ah4Xg8h.js} +1 -1
  25. package/dist/assets/{syntax-CK34dlF6.js → syntax-BWBIQpR3.js} +3 -3
  26. package/dist/build.json +1 -1
  27. package/dist/index.html +2 -2
  28. package/dist/notes.json +1 -1
  29. package/package.json +1 -1
@@ -1,4 +1,4 @@
1
- import{_ as St}from"./index-COu2z5IR.js";function An(){return{async:!1,breaks:!1,extensions:null,gfm:!0,hooks:null,pedantic:!1,renderer:null,silent:!1,tokenizer:null,walkTokens:null}}var Re=An();function zo(r){Re=r}var ye={exec:()=>null};function je(r){let t=[];return e=>{let i=Math.max(0,Math.min(3,e-1)),s=t[i];return s||(s=r(i),t[i]=s),s}}function P(r,t=""){let e=typeof r=="string"?r:r.source,i={replace:(s,n)=>{let o=typeof n=="string"?n:n.source;return o=o.replace(ut.caret,"$1"),e=e.replace(s,o),i},getRegex:()=>new RegExp(e,t)};return i}var ll=((r="")=>{try{return!!new RegExp("(?<=1)(?<!1)"+r)}catch{return!1}})(),ut={codeRemoveIndent:/^(?: {0,3}\t| {1,4})/gm,outputLinkReplace:/\\([\[\]])/g,indentCodeCompensation:/^(\s+)(?:```)/,beginningSpace:/^\s+/,endingHash:/#$/,startingSpaceChar:/^ /,endingSpaceChar:/ $/,endingSpaceTabChar:/[ \t]$/,nonSpaceChar:/[^ ]/,newLineCharGlobal:/\n/g,tabCharGlobal:/\t/g,leadingSpaceTab:/^[ \t]+/,multipleSpaceGlobal:/\s+/g,blankLine:/^[ \t]*$/,doubleBlankLine:/\n[ \t]*\n[ \t]*$/,blockquoteStart:/^ {0,3}>/,blockquoteSetextReplace:/\n {0,3}((?:=+|-+) *)(?=\n|$)/g,blockquoteSetextReplace2:/^ {0,3}>[ \t]?/gm,listReplaceNesting:/^ {1,4}(?=( {4})*[^ ])/g,listIsTask:/^\[[ xX]\] +\S/,listReplaceTask:/^\[[ xX]\] +/,listTaskCheckbox:/\[[ xX]\]/,anyLine:/\n.*\n/,hrefBrackets:/^<(.*)>$/,tableDelimiter:/[:|]/,tableAlignChars:/^\||\| *$/g,tableRowBlankLine:/\n[ \t]*$/,tableAlignRight:/^ *-+: *$/,tableAlignCenter:/^ *:-+: *$/,tableAlignLeft:/^ *:-+ *$/,startATag:/^<a /i,endATag:/^<\/a>/i,startPreScriptTag:/^<(pre|code|kbd|script)(\s|>)/i,endPreScriptTag:/^<\/(pre|code|kbd|script)(\s|>)/i,startAngleBracket:/^</,endAngleBracket:/>$/,pedanticHrefTitle:/^([^'"]*[^\s])\s+(['"])(.*)\2/,unicodeAlphaNumeric:/[\p{L}\p{N}]/u,numericCharacterReference:/&#(?:(\d{1,7})|[Xx]([A-Fa-f0-9]{1,6}));/,numericCharacterReferenceOrAmpersand:/&#(?:(\d{1,7})|[Xx]([A-Fa-f0-9]{1,6}));|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/g,escapeTest:/[&<>"']/,escapeReplace:/[&<>"']/g,escapeTestNoEncode:/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/,escapeReplaceNoEncode:/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/g,caret:/(^|[^\[])\^/g,percentDecode:/%25/g,findPipe:/\|/g,splitPipe:/ \|/,slashPipe:/\\\|/g,carriageReturn:/\r\n|\r/g,spaceLine:/^ +$/gm,notSpaceStart:/^\S*/,endingNewline:/\n$/,listItemRegex:r=>new RegExp(`^( {0,3}${r})((?:[ ][^\\n]*)?(?:\\n|$))`),nextBulletRegex:je(r=>new RegExp(`^ {0,${r}}(?:[*+-]|\\d{1,9}[.)])((?:[ ][^\\n]*)?(?:\\n|$))`)),hrRegex:je(r=>new RegExp(`^ {0,${r}}((?:-[ ]*){3,}|(?:_[ ]*){3,}|(?:\\*[ ]*){3,})(?:\\n+|$)`)),fencesBeginRegex:je(r=>new RegExp(`^ {0,${r}}(?:\`\`\`|~~~)`)),headingBeginRegex:je(r=>new RegExp(`^ {0,${r}}#`)),htmlBeginRegex:je(r=>new RegExp(`^ {0,${r}}(?:</?(?:${_i})(?: +|$|/?>)|<(?:(?:script|pre|style|textarea)(?:[\\s>]|$)|!--)|<\\?|<![A-Za-z]|<!\\[CDATA\\[)`,"i")),blockquoteBeginRegex:je(r=>new RegExp(`^ {0,${r}}>`))},cl=/^(?:[ \t]*(?:\n|$))+/,ul=/^((?: {4}| {0,3}\t)[^\n]+(?:\n(?:[ \t]*(?:\n|$))*)?)+/,hl=/^ {0,3}(`{3,}(?=[^`\n]*(?:\n|$))|~{3,})([^\n]*)(?:\n|$)(?:|([\s\S]*?)(?:\n|$))(?: {0,3}\1[~`]* *(?=\n|$)|$)/,$i=/^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/,fl=/^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/,vn=/ {0,3}(?:[*+-]|\d{1,9}[.)])/,jo=/^(?!bull |blockCode|fences|blockquote|heading|html|table)((?:.|\n(?!\s*?\n|bull |fences|blockquote|heading|hr|html|table))+?)\n {0,3}(=+|-+) *(?:\n+|$)/,Bo=P(jo).replace(/bull/g,vn).replace(/blockCode/g,/(?: {4}| {0,3}\t)/).replace(/fences/g,/ {0,3}(?:`{3,}|~{3,})/).replace(/blockquote/g,/ {0,3}>/).replace(/heading/g,/ {0,3}#{1,6}(?:\s|$)/).replace(/hr/g,/ {0,3}(?:(?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/).replace(/html/g,/ {0,3}<[^\n>]+>\n/).replace(/\|table/g,"").getRegex(),pl=P(jo).replace(/bull/g,vn).replace(/blockCode/g,/(?: {4}| {0,3}\t)/).replace(/fences/g,/ {0,3}(?:`{3,}|~{3,})/).replace(/blockquote/g,/ {0,3}>/).replace(/heading/g,/ {0,3}#{1,6}(?:\s|$)/).replace(/hr/g,/ {0,3}(?:(?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/).replace(/html/g,/ {0,3}<[^\n>]+>\n/).replace(/table/g,/ {0,3}\|?(?:[:\- ]*\|)+[\:\- ]*\n/).getRegex(),Sn=/^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table|[ \t]+\n)[^\n]+)*)/,dl=/^[^\n]+/,Tn=/(?!\s*\])(?:\\[\s\S]|[^\[\]\\])+/,ml=P(/^ {0,3}\[(label)\]: *(?:\n[ \t]*)?([^<\s][^\s]*|<.*?>)(?:(?: +(?:\n[ \t]*)?| *\n[ \t]*)(title))? *(?:\n+|$)/).replace("label",Tn).replace("title",/(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/).getRegex(),gl=P(/^(bull)([ \t][^\n]*?)?(?:\n|$)/).replace(/bull/g,vn).getRegex(),_i="address|article|aside|base|basefont|blockquote|body|caption|center|col|colgroup|dd|details|dialog|dir|div|dl|dt|fieldset|figcaption|figure|footer|form|frame|frameset|h[1-6]|head|header|hr|html|iframe|legend|li|link|main|menu|menuitem|meta|nav|noframes|ol|optgroup|option|p|param|search|section|summary|table|tbody|td|tfoot|th|thead|title|tr|track|ul",Ln=/<!--(?:-?>|[\s\S]*?(?:-->|$))/,bl=P("^ {0,3}(?:<(script|pre|style|textarea)[\\s>][\\s\\S]*?(?:</\\1>[^\\n]*\\n*|$)|comment[^\\n]*(\\n+|$)|<\\?[\\s\\S]*?(?:\\?>[^\\n]*\\n*|$)|<![A-Z][\\s\\S]*?(?:>[^\\n]*\\n*|$)|<!\\[CDATA\\[[\\s\\S]*?(?:\\]\\]>[^\\n]*\\n*|$)|</?(tag)(?: +|\\n|/?>)[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$)|<(?!(?:script|pre|style|textarea)(?![a-z0-9-]))([a-z][a-z0-9-]*)(?:attribute)*? */?>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$)|</[a-z][a-z0-9-]*\\s*>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$))","i").replace("comment",Ln).replace("tag",_i).replace("attribute",/ +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex(),Wo=r=>P(Sn).replace("hr",$i).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("|lheading","").replace("|table","").replace("blockquote"," {0,3}>").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*(?:\\n|$))|~~~)[^\\n]*(?:\\n|$)").replace("list",r).replace("html"," {0,3}(?:</?(?:tag)(?: +|\\n|/?>)|<(?:(?:script|pre|style|textarea)(?:[\\s>]|$)|!--)|<\\?|<![A-Za-z]|<!\\[CDATA\\[)").replace("tag",_i).getRegex(),$l=Wo(/ {0,3}(?:[*+-]|1[.)])[ \t]+[^ \t\n]/),_l=Wo(/ {0,3}(?:[*+-]|\d{1,9}[.)])(?:[ \t]|\n|$)/),yl=P(/^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/).replace("paragraph",_l).getRegex(),En={blockquote:yl,code:ul,def:ml,fences:hl,heading:fl,hr:$i,html:bl,lheading:Bo,list:gl,newline:cl,paragraph:$l,table:ye,text:dl},Sr=P("^ *([^\\n ].*)\\n {0,3}((?:\\| *)?:?-+:? *(?:\\| *:?-+:? *)*(?:\\| *)?)(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)").replace("hr",$i).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("blockquote"," {0,3}>").replace("code","(?: {4}| {0,3} )[^\\n]").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*(?:\\n|$))|~~~)[^\\n]*(?:\\n|$)").replace("list"," {0,3}(?:[*+-]|1[.)])[ \\t]").replace("html"," {0,3}(?:</?(?:tag)(?: +|\\n|/?>)|<(?:(?:script|pre|style|textarea)(?:[\\s>]|$)|!--)|<\\?|<![A-Za-z]|<!\\[CDATA\\[)").replace("tag",_i).getRegex(),wl={...En,lheading:pl,table:Sr,paragraph:P(Sn).replace("hr",$i).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("|lheading","").replace("table",Sr).replace("blockquote"," {0,3}>").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*(?:\\n|$))|~~~)[^\\n]*(?:\\n|$)").replace("list"," {0,3}(?:[*+-]|1[.)])[ \\t]+[^ \\t\\n]").replace("html"," {0,3}(?:</?(?:tag)(?: +|\\n|/?>)|<(?:(?:script|pre|style|textarea)(?:[\\s>]|$)|!--)|<\\?|<![A-Za-z]|<!\\[CDATA\\[)").replace("tag",_i).getRegex()},kl={...En,html:P(`^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+?</\\1> *(?:\\n{2,}|\\s*$)|<tag(?:"[^"]*"|'[^']*'|\\s[^'"/>\\s]*)*?/?> *(?:\\n{2,}|\\s*$))`).replace("comment",Ln).replace(/tag/g,"(?!(?:a|em|strong|small|s|cite|q|dfn|abbr|data|time|code|var|samp|kbd|sub|sup|i|b|u|mark|ruby|rt|rp|bdi|bdo|span|br|wbr|ins|del|img)\\b)\\w+(?!:|[^\\w\\s@]*@)\\b").getRegex(),def:/^ *\[([^\]]+)\]: *<?([^\s>]+)>?(?: +(["(][^\n]+[")]))? *(?:\n+|$)/,heading:/^(#{1,6})(.*)(?:\n+|$)/,fences:ye,lheading:/^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/,paragraph:P(Sn).replace("hr",$i).replace("heading",` *#{1,6} *[^
1
+ import{_ as St}from"./index-CD_iMftv.js";function An(){return{async:!1,breaks:!1,extensions:null,gfm:!0,hooks:null,pedantic:!1,renderer:null,silent:!1,tokenizer:null,walkTokens:null}}var Re=An();function zo(r){Re=r}var ye={exec:()=>null};function je(r){let t=[];return e=>{let i=Math.max(0,Math.min(3,e-1)),s=t[i];return s||(s=r(i),t[i]=s),s}}function P(r,t=""){let e=typeof r=="string"?r:r.source,i={replace:(s,n)=>{let o=typeof n=="string"?n:n.source;return o=o.replace(ut.caret,"$1"),e=e.replace(s,o),i},getRegex:()=>new RegExp(e,t)};return i}var ll=((r="")=>{try{return!!new RegExp("(?<=1)(?<!1)"+r)}catch{return!1}})(),ut={codeRemoveIndent:/^(?: {0,3}\t| {1,4})/gm,outputLinkReplace:/\\([\[\]])/g,indentCodeCompensation:/^(\s+)(?:```)/,beginningSpace:/^\s+/,endingHash:/#$/,startingSpaceChar:/^ /,endingSpaceChar:/ $/,endingSpaceTabChar:/[ \t]$/,nonSpaceChar:/[^ ]/,newLineCharGlobal:/\n/g,tabCharGlobal:/\t/g,leadingSpaceTab:/^[ \t]+/,multipleSpaceGlobal:/\s+/g,blankLine:/^[ \t]*$/,doubleBlankLine:/\n[ \t]*\n[ \t]*$/,blockquoteStart:/^ {0,3}>/,blockquoteSetextReplace:/\n {0,3}((?:=+|-+) *)(?=\n|$)/g,blockquoteSetextReplace2:/^ {0,3}>[ \t]?/gm,listReplaceNesting:/^ {1,4}(?=( {4})*[^ ])/g,listIsTask:/^\[[ xX]\] +\S/,listReplaceTask:/^\[[ xX]\] +/,listTaskCheckbox:/\[[ xX]\]/,anyLine:/\n.*\n/,hrefBrackets:/^<(.*)>$/,tableDelimiter:/[:|]/,tableAlignChars:/^\||\| *$/g,tableRowBlankLine:/\n[ \t]*$/,tableAlignRight:/^ *-+: *$/,tableAlignCenter:/^ *:-+: *$/,tableAlignLeft:/^ *:-+ *$/,startATag:/^<a /i,endATag:/^<\/a>/i,startPreScriptTag:/^<(pre|code|kbd|script)(\s|>)/i,endPreScriptTag:/^<\/(pre|code|kbd|script)(\s|>)/i,startAngleBracket:/^</,endAngleBracket:/>$/,pedanticHrefTitle:/^([^'"]*[^\s])\s+(['"])(.*)\2/,unicodeAlphaNumeric:/[\p{L}\p{N}]/u,numericCharacterReference:/&#(?:(\d{1,7})|[Xx]([A-Fa-f0-9]{1,6}));/,numericCharacterReferenceOrAmpersand:/&#(?:(\d{1,7})|[Xx]([A-Fa-f0-9]{1,6}));|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/g,escapeTest:/[&<>"']/,escapeReplace:/[&<>"']/g,escapeTestNoEncode:/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/,escapeReplaceNoEncode:/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/g,caret:/(^|[^\[])\^/g,percentDecode:/%25/g,findPipe:/\|/g,splitPipe:/ \|/,slashPipe:/\\\|/g,carriageReturn:/\r\n|\r/g,spaceLine:/^ +$/gm,notSpaceStart:/^\S*/,endingNewline:/\n$/,listItemRegex:r=>new RegExp(`^( {0,3}${r})((?:[ ][^\\n]*)?(?:\\n|$))`),nextBulletRegex:je(r=>new RegExp(`^ {0,${r}}(?:[*+-]|\\d{1,9}[.)])((?:[ ][^\\n]*)?(?:\\n|$))`)),hrRegex:je(r=>new RegExp(`^ {0,${r}}((?:-[ ]*){3,}|(?:_[ ]*){3,}|(?:\\*[ ]*){3,})(?:\\n+|$)`)),fencesBeginRegex:je(r=>new RegExp(`^ {0,${r}}(?:\`\`\`|~~~)`)),headingBeginRegex:je(r=>new RegExp(`^ {0,${r}}#`)),htmlBeginRegex:je(r=>new RegExp(`^ {0,${r}}(?:</?(?:${_i})(?: +|$|/?>)|<(?:(?:script|pre|style|textarea)(?:[\\s>]|$)|!--)|<\\?|<![A-Za-z]|<!\\[CDATA\\[)`,"i")),blockquoteBeginRegex:je(r=>new RegExp(`^ {0,${r}}>`))},cl=/^(?:[ \t]*(?:\n|$))+/,ul=/^((?: {4}| {0,3}\t)[^\n]+(?:\n(?:[ \t]*(?:\n|$))*)?)+/,hl=/^ {0,3}(`{3,}(?=[^`\n]*(?:\n|$))|~{3,})([^\n]*)(?:\n|$)(?:|([\s\S]*?)(?:\n|$))(?: {0,3}\1[~`]* *(?=\n|$)|$)/,$i=/^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/,fl=/^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/,vn=/ {0,3}(?:[*+-]|\d{1,9}[.)])/,jo=/^(?!bull |blockCode|fences|blockquote|heading|html|table)((?:.|\n(?!\s*?\n|bull |fences|blockquote|heading|hr|html|table))+?)\n {0,3}(=+|-+) *(?:\n+|$)/,Bo=P(jo).replace(/bull/g,vn).replace(/blockCode/g,/(?: {4}| {0,3}\t)/).replace(/fences/g,/ {0,3}(?:`{3,}|~{3,})/).replace(/blockquote/g,/ {0,3}>/).replace(/heading/g,/ {0,3}#{1,6}(?:\s|$)/).replace(/hr/g,/ {0,3}(?:(?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/).replace(/html/g,/ {0,3}<[^\n>]+>\n/).replace(/\|table/g,"").getRegex(),pl=P(jo).replace(/bull/g,vn).replace(/blockCode/g,/(?: {4}| {0,3}\t)/).replace(/fences/g,/ {0,3}(?:`{3,}|~{3,})/).replace(/blockquote/g,/ {0,3}>/).replace(/heading/g,/ {0,3}#{1,6}(?:\s|$)/).replace(/hr/g,/ {0,3}(?:(?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/).replace(/html/g,/ {0,3}<[^\n>]+>\n/).replace(/table/g,/ {0,3}\|?(?:[:\- ]*\|)+[\:\- ]*\n/).getRegex(),Sn=/^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table|[ \t]+\n)[^\n]+)*)/,dl=/^[^\n]+/,Tn=/(?!\s*\])(?:\\[\s\S]|[^\[\]\\])+/,ml=P(/^ {0,3}\[(label)\]: *(?:\n[ \t]*)?([^<\s][^\s]*|<.*?>)(?:(?: +(?:\n[ \t]*)?| *\n[ \t]*)(title))? *(?:\n+|$)/).replace("label",Tn).replace("title",/(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/).getRegex(),gl=P(/^(bull)([ \t][^\n]*?)?(?:\n|$)/).replace(/bull/g,vn).getRegex(),_i="address|article|aside|base|basefont|blockquote|body|caption|center|col|colgroup|dd|details|dialog|dir|div|dl|dt|fieldset|figcaption|figure|footer|form|frame|frameset|h[1-6]|head|header|hr|html|iframe|legend|li|link|main|menu|menuitem|meta|nav|noframes|ol|optgroup|option|p|param|search|section|summary|table|tbody|td|tfoot|th|thead|title|tr|track|ul",Ln=/<!--(?:-?>|[\s\S]*?(?:-->|$))/,bl=P("^ {0,3}(?:<(script|pre|style|textarea)[\\s>][\\s\\S]*?(?:</\\1>[^\\n]*\\n*|$)|comment[^\\n]*(\\n+|$)|<\\?[\\s\\S]*?(?:\\?>[^\\n]*\\n*|$)|<![A-Z][\\s\\S]*?(?:>[^\\n]*\\n*|$)|<!\\[CDATA\\[[\\s\\S]*?(?:\\]\\]>[^\\n]*\\n*|$)|</?(tag)(?: +|\\n|/?>)[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$)|<(?!(?:script|pre|style|textarea)(?![a-z0-9-]))([a-z][a-z0-9-]*)(?:attribute)*? */?>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$)|</[a-z][a-z0-9-]*\\s*>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$))","i").replace("comment",Ln).replace("tag",_i).replace("attribute",/ +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex(),Wo=r=>P(Sn).replace("hr",$i).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("|lheading","").replace("|table","").replace("blockquote"," {0,3}>").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*(?:\\n|$))|~~~)[^\\n]*(?:\\n|$)").replace("list",r).replace("html"," {0,3}(?:</?(?:tag)(?: +|\\n|/?>)|<(?:(?:script|pre|style|textarea)(?:[\\s>]|$)|!--)|<\\?|<![A-Za-z]|<!\\[CDATA\\[)").replace("tag",_i).getRegex(),$l=Wo(/ {0,3}(?:[*+-]|1[.)])[ \t]+[^ \t\n]/),_l=Wo(/ {0,3}(?:[*+-]|\d{1,9}[.)])(?:[ \t]|\n|$)/),yl=P(/^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/).replace("paragraph",_l).getRegex(),En={blockquote:yl,code:ul,def:ml,fences:hl,heading:fl,hr:$i,html:bl,lheading:Bo,list:gl,newline:cl,paragraph:$l,table:ye,text:dl},Sr=P("^ *([^\\n ].*)\\n {0,3}((?:\\| *)?:?-+:? *(?:\\| *:?-+:? *)*(?:\\| *)?)(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)").replace("hr",$i).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("blockquote"," {0,3}>").replace("code","(?: {4}| {0,3} )[^\\n]").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*(?:\\n|$))|~~~)[^\\n]*(?:\\n|$)").replace("list"," {0,3}(?:[*+-]|1[.)])[ \\t]").replace("html"," {0,3}(?:</?(?:tag)(?: +|\\n|/?>)|<(?:(?:script|pre|style|textarea)(?:[\\s>]|$)|!--)|<\\?|<![A-Za-z]|<!\\[CDATA\\[)").replace("tag",_i).getRegex(),wl={...En,lheading:pl,table:Sr,paragraph:P(Sn).replace("hr",$i).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("|lheading","").replace("table",Sr).replace("blockquote"," {0,3}>").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*(?:\\n|$))|~~~)[^\\n]*(?:\\n|$)").replace("list"," {0,3}(?:[*+-]|1[.)])[ \\t]+[^ \\t\\n]").replace("html"," {0,3}(?:</?(?:tag)(?: +|\\n|/?>)|<(?:(?:script|pre|style|textarea)(?:[\\s>]|$)|!--)|<\\?|<![A-Za-z]|<!\\[CDATA\\[)").replace("tag",_i).getRegex()},kl={...En,html:P(`^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+?</\\1> *(?:\\n{2,}|\\s*$)|<tag(?:"[^"]*"|'[^']*'|\\s[^'"/>\\s]*)*?/?> *(?:\\n{2,}|\\s*$))`).replace("comment",Ln).replace(/tag/g,"(?!(?:a|em|strong|small|s|cite|q|dfn|abbr|data|time|code|var|samp|kbd|sub|sup|i|b|u|mark|ruby|rt|rp|bdi|bdo|span|br|wbr|ins|del|img)\\b)\\w+(?!:|[^\\w\\s@]*@)\\b").getRegex(),def:/^ *\[([^\]]+)\]: *<?([^\s>]+)>?(?: +(["(][^\n]+[")]))? *(?:\n+|$)/,heading:/^(#{1,6})(.*)(?:\n+|$)/,fences:ye,lheading:/^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/,paragraph:P(Sn).replace("hr",$i).replace("heading",` *#{1,6} *[^
2
2
  ]`).replace("lheading",Bo).replace("|table","").replace("blockquote"," {0,3}>").replace("|fences","").replace("|list","").replace("|html","").replace("|tag","").getRegex()},xl=/^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/,Al=/^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/,Uo=/^( {2,}|\\)\n(?!\s*$)[ \t]*/,vl=/^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*_]|\b_|$)|[^ ](?= {2,}\n)))/,qt=/[\p{P}\p{S}]/u,Ve=/[\s\p{P}\p{S}]/u,yi=/[^\s\p{P}\p{S}]/u,Sl=P(/^((?![*_])punctSpace)/,"u").replace(/punctSpace/g,Ve).getRegex(),Tl=/[\p{Pi}\p{Ps}"']/u,Fo=/(?!~)[\p{P}\p{S}]/u,Ll=/(?!~)[\s\p{P}\p{S}]/u,El=/(?:[^\s\p{P}\p{S}]|~)/u,Rl=P(/link|precode-code|html/,"g").replace("link",/\[(?:[^\[\]`]|(?<a>`+)[^`]+\k<a>(?!`))*?\]\((?:\\[\s\S]|[^\\\(\)]|\((?:\\[\s\S]|[^\\\(\)])*\))*\)/).replace("precode-",ll?"(?<!`)()":"(^^|[^`])").replace("code",/(?<b>`+)[^`]+\k<b>(?!`)/).replace("html",/<(?! )[^<>]*?>/).getRegex(),qo=/^(?:\*+(?:((?!\*)punct)|([^\s*]))?)|^_+(?:((?!_)punct)|([^\s_]))?/,Il=P(qo,"u").replace(/punct/g,qt).getRegex(),Ol=P(qo,"u").replace(/punct/g,Fo).getRegex(),Cl=/^(?:\*+(?:((?!\*)(?!openQuote)punct)|([^\s*]))?)|^_+(?:((?!_)(?!openQuote)punct)|([^\s_]))?/,Dl=P(Cl,"u").replace(/openQuote/g,Tl).replace(/punct/g,qt).getRegex(),Ho="^[^_*]*?__[^_*]*?\\*[^_*]*?(?=__)|[^*]+(?=[^*])|(?!\\*)punct(\\*+)(?=[\\s]|$)|notPunctSpace(\\*+)(?!\\*)(?=punctSpace|$)|(?!\\*)punctSpace(\\*+)(?=notPunctSpace)|[\\s](\\*+)(?!\\*)(?=punct)|(?!\\*)punct(\\*+)(?!\\*)(?=punct)|notPunctSpace(\\*+)(?=notPunctSpace)",Ml=P(Ho,"gu").replace(/notPunctSpace/g,yi).replace(/punctSpace/g,Ve).replace(/punct/g,qt).getRegex(),Pl=P(Ho,"gu").replace(/notPunctSpace/g,El).replace(/punctSpace/g,Ll).replace(/punct/g,Fo).getRegex(),Nl="^[^_*]*?__[^_*]*?\\*[^_*]*?(?=__)|[^*]+(?=[^*])|(?!\\*)punct(\\*+)(?=[\\s]|$)|notPunctSpace(\\*+)(?!\\*)(?=punctSpace|$)|(?!\\*)[\\s](\\*+)(?=notPunctSpace)|[\\s](\\*+)(?!\\*)(?=punct)|(?!\\*)punct(\\*+)(?!\\*)(?=punct)|(?:(?!\\*)punct|notPunctSpace)(\\*+)(?!\\*)(?=notPunctSpace)",zl=P(Nl,"gu").replace(/notPunctSpace/g,yi).replace(/punctSpace/g,Ve).replace(/punct/g,qt).getRegex(),jl=P("^[^_*]*?\\*\\*[^_*]*?_[^_*]*?(?=\\*\\*)|[^_]+(?=[^_])|(?!_)punct(_+)(?=[\\s]|$)|notPunctSpace(_+)(?!_)(?=punctSpace|$)|(?!_)punctSpace(_+)(?=notPunctSpace)|[\\s](_+)(?!_)(?=punct)|(?!_)punct(_+)(?!_)(?=punct)","gu").replace(/notPunctSpace/g,yi).replace(/punctSpace/g,Ve).replace(/punct/g,qt).getRegex(),Bl="^[^_*]*?\\*\\*[^_*]*?_[^_*]*?(?=\\*\\*)|[^_]+(?=[^_])|(?!_)punct(_+)(?=[\\s]|$)|notPunctSpace(_+)(?!_)(?=punctSpace|$)|(?!_)[\\s](_+)(?=notPunctSpace)|[\\s](_+)(?!_)(?=punct)|(?!_)punct(_+)(?!_)(?=punct)|(?:(?!_)punct|notPunctSpace)(_+)(?!_)(?=notPunctSpace)",Wl=P(Bl,"gu").replace(/notPunctSpace/g,yi).replace(/punctSpace/g,Ve).replace(/punct/g,qt).getRegex(),Ul=P(/^~~?(?:((?!~)punct)|[^\s~])/,"u").replace(/punct/g,qt).getRegex(),Fl="^[^~]+(?=[^~])|(?!~)punct(~~?)(?=[\\s]|$)|notPunctSpace(~~?)(?!~)(?=punctSpace|$)|(?!~)punctSpace(~~?)(?=notPunctSpace)|[\\s](~~?)(?!~)(?=punct)|(?!~)punct(~~?)(?!~)(?=punct)|notPunctSpace(~~?)(?=notPunctSpace)",ql=P(Fl,"gu").replace(/notPunctSpace/g,yi).replace(/punctSpace/g,Ve).replace(/punct/g,qt).getRegex(),Hl=P(/\\(punct)/,"gu").replace(/punct/g,qt).getRegex(),Vl=P(/(`+)(?:[^`]|[^`][\s\S]*?[^`])\1(?!`)|`+|\\(punct)/,"gu").replace(/punct/g,qt).getRegex(),Gl=P(/^<(scheme:[^\s\x00-\x1f<>]*|email)>/).replace("scheme",/[a-zA-Z][a-zA-Z0-9+.-]{1,31}/).replace("email",/[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+(@)[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)+(?![-_])/).getRegex(),Yl=P(Ln).replace("(?:-->|$)","-->").getRegex(),Xl=P("^comment|^</[a-zA-Z][a-zA-Z0-9-]*\\s*>|^<[a-zA-Z][a-zA-Z0-9-]*(?:attribute)*?\\s*/?>|^<\\?[\\s\\S]*?\\?>|^<![a-zA-Z]+\\s[\\s\\S]*?>|^<!\\[CDATA\\[[\\s\\S]*?\\]\\]>").replace("comment",Yl).replace("attribute",/\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/).getRegex(),Vo=/\[(?:\\[\s\S]|[^\[\]\\])*\]/,Gi=P(/(?:\[(?:brackets|\\[\s\S]|[^\[\]\\])*\]|\\[\s\S]|`+(?!`)[^`]*?`+(?!`)|``+(?=\])|[^\[\]\\`])*?/).replace("brackets",Vo).getRegex(),Ql=P(/^!?\[(label)\]\([ \t\n]*(href)(?:(?:[ \t]+(?:\n[ \t]*)?|\n[ \t]*)(title))?[ \t\n]*\)/).replace("label",Gi).replace("href",/<(?:\\.|[^\n<>\\])+>|[^ \t\n\x00-\x1f]+|(?=\))/).replace("title",/"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/).getRegex(),Kl=P(/^!?\[(label)\]\[(ref)\]/).replace("label",Gi).replace("ref",Tn).getRegex(),Zl=P(/^!?\[(ref)\](?:\[\])?/).replace("ref",Tn).getRegex(),Tr=/(?!\s*\])(?:\\[\s\S]|[^\[\]\\]){1,999}/,Jl=P(/(?:[^\[\]\\`]*(?:\[(?:brackets|\\[\s\S]|[^\[\]\\])*\]|\\[\s\S]|`+(?!`)[^`]*?`+(?!`)|``+(?=\]))){0,999}?[^\[\]\\`]*?/).replace("brackets",Vo).getRegex(),tc=P("reflink|nolink(?!\\()","g").replace("reflink",P(/^!?\[(label)\]\[(ref)\]/).replace("label",Jl).replace("ref",Tr).getRegex()).replace("nolink",P(/^!?\[(ref)\](?:\[\])?/).replace("ref",Tr).getRegex()).getRegex(),Lr=/[hH][tT][tT][pP][sS]?|[fF][tT][pP]/,ec=/[A-Za-z0-9._+-]+@[a-zA-Z0-9-_]+(?:\.[a-zA-Z0-9-_]*[a-zA-Z0-9])+(?![\w-])/,ic=P(/(?:mailto:email|xmpp:email(?:\/[A-Za-z0-9@.]+)?)/).replace(/email/g,ec).getRegex(),Rn={_backpedal:ye,anyPunctuation:Hl,anyPunctuationOutsideCode:Vl,autolink:Gl,blockSkip:Rl,br:Uo,code:Al,del:ye,delLDelim:ye,delRDelim:ye,emStrongLDelim:Il,emStrongRDelimAst:Ml,emStrongRDelimUnd:jl,escape:xl,link:Ql,nolink:Zl,punctuation:Sl,reflink:Kl,reflinkSearch:tc,tag:Xl,text:vl,url:ye},sc={...Rn,emStrongLDelim:Dl,emStrongRDelimAst:zl,emStrongRDelimUnd:Wl,link:P(/^!?\[(label)\]\((.*?)\)/).replace("label",Gi).getRegex(),reflink:P(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace("label",Gi).getRegex()},nn={...Rn,emStrongRDelimAst:Pl,emStrongLDelim:Ol,delLDelim:Ul,delRDelim:ql,url:P(/^emailProtocol|^((?:protocol):\/\/|www\.)(?:[a-zA-Z0-9\-]+\.?)+[^\s<]*|^email/).replace("emailProtocol",ic).replace("protocol",Lr).replace("email",/[A-Za-z0-9._+-]+(@)[a-zA-Z0-9-_]+(?:\.[a-zA-Z0-9-_]*[a-zA-Z0-9])+(?![\w-])/).getRegex(),_backpedal:/(?:[^?!.,:;*_'"~()&]+|\([^)]*\)|&(?![a-zA-Z0-9]+;$)|[?!.,:;*_'"~)]+(?!$))+/,del:/^(~~?)(?=[^\s~])((?:\\[\s\S]|[^\\])*?(?:\\[\s\S]|[^\s~\\]))\1(?=[^~]|$)/,text:P(/^(?:[^a-zA-Z0-9](?=emailProtocol)|(`+|~+|[^`~])(?:(?=[`~])|(?= {2,}\n)|(?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)|[\s\S]*?(?:(?=[\\<!\[`*~_]|\b_|protocol:\/\/|www\.|$)|[^ ](?= {2,}\n)|[^a-zA-Z0-9](?=emailProtocol)|[^a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-](?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@))))/).replace("protocol",Lr).replace(/emailProtocol/g,/(?:mailto|xmpp):/).getRegex()},nc={...nn,br:P(Uo).replace("{2,}","*").getRegex(),text:P(nn.text).replace("\\b_","\\b_| {2,}\\n").replace(/\{2,\}/g,"*").getRegex()},Ci={normal:En,gfm:wl,pedantic:kl},Ze={normal:Rn,gfm:nn,breaks:nc,pedantic:sc},rc={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"},Er=r=>rc[r];function Tt(r,t){if(t){if(ut.escapeTest.test(r))return r.replace(ut.escapeReplace,Er)}else if(ut.escapeTestNoEncode.test(r))return r.replace(ut.escapeReplaceNoEncode,Er);return r}function oc(r){return ut.numericCharacterReference.test(r)?r.replace(ut.numericCharacterReferenceOrAmpersand,(t,e,i)=>{if(e===void 0&&i===void 0)return"&amp;";let s=e===void 0?Number.parseInt(i,16):Number.parseInt(e,10);return s===0||s>1114111||s>=55296&&s<=57343?"�":s===38?"&amp;":String.fromCodePoint(s)}):r}function Rr(r){try{r=encodeURI(r).replace(ut.percentDecode,"%")}catch{return null}return r}function Ir(r,t){let e=r.replace(ut.findPipe,(n,o,l)=>{let a=!1,c=o;for(;--c>=0&&l[c]==="\\";)a=!a;return a?"|":" |"}),i=e.split(ut.splitPipe),s=0;if(i[0].trim()||i.shift(),i.length>0&&!i.at(-1)?.trim()&&i.pop(),t)if(i.length>t)i.splice(t);else for(;i.length<t;)i.push("");for(;s<i.length;s++)i[s]=i[s].trim().replace(ut.slashPipe,"|");return i}function re(r,t,e){let i=r.length;if(i===0)return"";let s=0;for(;s<i&&r.charAt(i-s-1)===t;)s++;return r.slice(0,i-s)}function Or(r){let t=r.split(`
3
3
  `),e=t.length-1;for(;e>=0&&ut.blankLine.test(t[e]);)e--;return t.length-e<=2?r:t.slice(0,e+1).join(`
4
4
  `)}function Yi(r){return r.trim().toLowerCase().toUpperCase().toLowerCase()}function Cr(r,t){if(r.indexOf(t[0])===-1&&r.indexOf(t[1])===-1)return-1;let e=0;for(let i=0;i<r.length;i++)if(r[i]==="\\")i++;else if(r[i]===t[0])e++;else if(r[i]===t[1]&&(e--,e<0))return i;return e>0?-2:-1}function Rs(r,t=0){let e=t,i="";for(let s of r)if(s===" "){let n=4-e%4;i+=" ".repeat(n),e+=n}else i+=s,e++;return i}function Dr(r,t,e,i,s){let n=t.href,o=t.title||null,l=r[1].replace(s.other.outputLinkReplace,"$1"),a=r[0].charAt(0)==="!",c=i.state.inLink,u=i.state.linkEmitted,f=i.state.inRawBlock;i.state.inLink=!0,i.state.linkEmitted=!1;let h=i.inlineTokens(l),p=i.state.linkEmitted;if(i.state.linkEmitted=u,i.state.inLink=c,!a){if(p){i.state.inRawBlock=f;return}i.state.linkEmitted=!0}return{type:a?"image":"link",raw:e,href:n,title:o,text:l,tokens:h}}function ac(r,t,e){let i=r.match(e.other.indentCodeCompensation);if(i===null)return t;let s=i[1];return t.split(`
@@ -1,2 +1,2 @@
1
- import{E as m,S as we,T as le,F as Z,c as ye,a as f,I as Ge,b as w,C as Pt,d as qt,A as Ue,D as Nt,g as ze,e as xe,i as $,f as He,s as Se,m as W,h as E,N as ae,j as he,k as Vt,l as Je,n as wt,o as Gt,V as $e,p as x,P as Ut,q as zt,r as Ht,t as Jt,u as k,R as $t,v as _e,w as _t,x as S,y as Kt,z as Qt,B as jt,G as Xt,H as Yt,J as Zt,K as en,L as tn,M as nn,O as rn,Q as on}from"./syntax-CK34dlF6.js";import"./index-COu2z5IR.js";const ln=e=>{let{state:t}=e,n=t.doc.lineAt(t.selection.main.from),r=Ae(e.state,n.from);return r.line?sn(e):r.block?an(e):!1};function ke(e,t){return({state:n,dispatch:r})=>{if(n.readOnly)return!1;let o=e(t,n);return o?(r(n.update(o)),!0):!1}}const sn=ke(fn,0),cn=ke(Ke,0),an=ke((e,t)=>Ke(e,t,un(t)),0);function Ae(e,t){let n=e.languageDataAt("commentTokens",t,1);return n.length?n[0]:{}}const N=50;function hn(e,{open:t,close:n},r,o){let l=e.sliceDoc(r-N,r),s=e.sliceDoc(o,o+N),i=/\s*$/.exec(l)[0].length,c=/^\s*/.exec(s)[0].length,a=l.length-i;if(l.slice(a-t.length,a)==t&&s.slice(c,c+n.length)==n)return{open:{pos:r-i,margin:i&&1},close:{pos:o+c,margin:c&&1}};let h,u;o-r<=2*N?h=u=e.sliceDoc(r,o):(h=e.sliceDoc(r,r+N),u=e.sliceDoc(o-N,o));let d=/^\s*/.exec(h)[0].length,R=/\s*$/.exec(u)[0].length,C=u.length-R-n.length;return h.slice(d,d+t.length)==t&&u.slice(C,C+n.length)==n?{open:{pos:r+d+t.length,margin:/\s/.test(h.charAt(d+t.length))?1:0},close:{pos:o-R-n.length,margin:/\s/.test(u.charAt(C-1))?1:0}}:null}function un(e){let t=[];for(let n of e.selection.ranges){let r=e.doc.lineAt(n.from),o=n.to<=r.to?r:e.doc.lineAt(n.to);o.from>r.from&&o.from==n.to&&(o=n.to==r.to+1?r:e.doc.lineAt(n.to-1));let l=t.length-1;l>=0&&t[l].to>r.from?t[l].to=o.to:t.push({from:r.from+/^\s*/.exec(r.text)[0].length,to:o.to})}return t}function Ke(e,t,n=t.selection.ranges){let r=n.map(l=>Ae(t,l.from).block);if(!r.every(l=>l))return null;let o=n.map((l,s)=>hn(t,r[s],l.from,l.to));if(e!=2&&!o.every(l=>l))return{changes:t.changes(n.map((l,s)=>o[s]?[]:[{from:l.from,insert:r[s].open+" "},{from:l.to,insert:" "+r[s].close}]))};if(e!=1&&o.some(l=>l)){let l=[];for(let s=0,i;s<o.length;s++)if(i=o[s]){let c=r[s],{open:a,close:h}=i;l.push({from:a.pos-c.open.length,to:a.pos+a.margin},{from:h.pos-h.margin,to:h.pos+c.close.length})}return{changes:l}}return null}function fn(e,t,n=t.selection.ranges){let r=[],o=-1;e:for(let{from:l,to:s}of n){let i=r.length,c=1e9,a;for(let h=l;h<=s;){let u=t.doc.lineAt(h);if(a==null&&(a=Ae(t,u.from).line,!a))continue e;if(u.from>o&&(l==s||s>u.from)){o=u.from;let d=/^\s*/.exec(u.text)[0].length,R=d==u.length,C=u.text.slice(d,d+a.length)==a?d:-1;d<u.text.length&&d<c&&(c=d),r.push({line:u,comment:C,token:a,indent:d,empty:R,single:!1})}h=u.to+1}if(c<1e9)for(let h=i;h<r.length;h++)r[h].indent<r[h].line.text.length&&(r[h].indent=c);r.length==i+1&&(r[i].single=!0)}if(e!=2&&r.some(l=>l.comment<0&&(!l.empty||l.single))){let l=[];for(let{line:i,token:c,indent:a,empty:h,single:u}of r)(u||!h)&&l.push({from:i.from+a,insert:c+" "});let s=t.changes(l);return{changes:s,selection:t.selection.map(s,1)}}else if(e!=1&&r.some(l=>l.comment>=0)){let l=[];for(let{line:s,comment:i,token:c}of r)if(i>=0){let a=s.from+i,h=a+c.length;s.text[h-s.from]==" "&&h++,l.push({from:a,to:h})}return{changes:l}}return null}const ue=Ue.define(),dn=Ue.define(),mn=Z.define(),Qe=Z.define({combine(e){return ye(e,{minDepth:100,newGroupDelay:500,joinToEvent:(t,n)=>n},{minDepth:Math.max,newGroupDelay:Math.min,joinToEvent:(t,n)=>(r,o)=>t(r,o)||n(r,o)})}}),je=we.define({create(){return D.empty},update(e,t){let n=t.state.facet(Qe),r=t.annotation(ue);if(r){let c=g.fromTransaction(t,r.selection),a=r.side,h=a==0?e.undone:e.done;return c?h=_(h,h.length,n.minDepth,c):h=Ze(h,t.startState.selection),new D(a==0?r.rest:h,a==0?h:r.rest)}let o=t.annotation(dn);if((o=="full"||o=="before")&&(e=e.isolate()),t.annotation(le.addToHistory)===!1)return t.changes.empty?e:e.addMapping(t.changes.desc);let l=g.fromTransaction(t),s=t.annotation(le.time),i=t.annotation(le.userEvent);return l?e=e.addChanges(l,s,i,n,t):t.selection&&(e=e.addSelection(t.startState.selection,s,i,n.newGroupDelay)),(o=="full"||o=="after")&&(e=e.isolate()),e},toJSON(e){return{done:e.done.map(t=>t.toJSON()),undone:e.undone.map(t=>t.toJSON())}},fromJSON(e){return new D(e.done.map(g.fromJSON),e.undone.map(g.fromJSON))}});function pn(e={}){return[je,Qe.of(e),m.domEventHandlers({beforeinput(t,n){let r=t.inputType=="historyUndo"?Xe:t.inputType=="historyRedo"?fe:null;return r?(t.preventDefault(),r(n)):!1}})]}function ee(e,t){return function({state:n,dispatch:r}){if(!t&&n.readOnly)return!1;let o=n.field(je,!1);if(!o)return!1;let l=o.pop(e,n,t);return l?(r(l),!0):!1}}const Xe=ee(0,!1),fe=ee(1,!1),gn=ee(0,!0),yn=ee(1,!0);class g{constructor(t,n,r,o,l){this.changes=t,this.effects=n,this.mapped=r,this.startSelection=o,this.selectionsAfter=l}setSelAfter(t){return new g(this.changes,this.effects,this.mapped,this.startSelection,t)}toJSON(){var t,n,r;return{changes:(t=this.changes)===null||t===void 0?void 0:t.toJSON(),mapped:(n=this.mapped)===null||n===void 0?void 0:n.toJSON(),startSelection:(r=this.startSelection)===null||r===void 0?void 0:r.toJSON(),selectionsAfter:this.selectionsAfter.map(o=>o.toJSON())}}static fromJSON(t){return new g(t.changes&&Pt.fromJSON(t.changes),[],t.mapped&&qt.fromJSON(t.mapped),t.startSelection&&f.fromJSON(t.startSelection),t.selectionsAfter.map(f.fromJSON))}static fromTransaction(t,n){let r=A;for(let o of t.startState.facet(mn)){let l=o(t);l.length&&(r=r.concat(l))}return!r.length&&t.changes.empty?null:new g(t.changes.invert(t.startState.doc),r,void 0,n||t.startState.selection,A)}static selection(t){return new g(void 0,A,void 0,void 0,t)}}function _(e,t,n,r){let o=t+1>n+20?t-n-1:0,l=e.slice(o,t);return l.push(r),l}function xn(e,t){let n=[],r=!1;return e.iterChangedRanges((o,l)=>n.push(o,l)),t.iterChangedRanges((o,l,s,i)=>{for(let c=0;c<n.length;){let a=n[c++],h=n[c++];i>=a&&s<=h&&(r=!0)}}),r}function Sn(e,t){return e.ranges.length==t.ranges.length&&e.ranges.filter((n,r)=>n.empty!=t.ranges[r].empty).length===0}function Ye(e,t){return e.length?t.length?e.concat(t):e:t}const A=[],kn=200;function Ze(e,t){if(e.length){let n=e[e.length-1],r=n.selectionsAfter.slice(Math.max(0,n.selectionsAfter.length-kn));return r.length&&r[r.length-1].eq(t)?e:(r.push(t),_(e,e.length-1,1e9,n.setSelAfter(r)))}else return[g.selection([t])]}function An(e){let t=e[e.length-1],n=e.slice();return n[e.length-1]=t.setSelAfter(t.selectionsAfter.slice(0,t.selectionsAfter.length-1)),n}function se(e,t){if(!e.length)return e;let n=e.length,r=A;for(;n;){let o=Mn(e[n-1],t,r);if(o.changes&&!o.changes.empty||o.effects.length){let l=e.slice(0,n);return l[n-1]=o,l}else t=o.mapped,n--,r=o.selectionsAfter}return r.length?[g.selection(r)]:A}function Mn(e,t,n){let r=Ye(e.selectionsAfter.length?e.selectionsAfter.map(i=>i.map(t)):A,n);if(!e.changes)return g.selection(r);let o=e.changes.map(t),l=t.mapDesc(e.changes,!0),s=e.mapped?e.mapped.composeDesc(l):l;return new g(o,w.mapEffects(e.effects,t),s,e.startSelection.map(l),r)}const Cn=/^(input\.type|delete)($|\.)/;class D{constructor(t,n,r=0,o=void 0){this.done=t,this.undone=n,this.prevTime=r,this.prevUserEvent=o}isolate(){return this.prevTime?new D(this.done,this.undone):this}addChanges(t,n,r,o,l){let s=this.done,i=s[s.length-1];return i&&i.changes&&!i.changes.empty&&t.changes&&(!r||Cn.test(r))&&(!i.selectionsAfter.length&&n-this.prevTime<o.newGroupDelay&&o.joinToEvent(l,xn(i.changes,t.changes))||r=="input.type.compose")?s=_(s,s.length-1,o.minDepth,new g(t.changes.compose(i.changes),Ye(w.mapEffects(t.effects,i.changes),i.effects),i.mapped,i.startSelection,A)):s=_(s,s.length,o.minDepth,t),new D(s,A,n,r)}addSelection(t,n,r,o){let l=this.done.length?this.done[this.done.length-1].selectionsAfter:A;return l.length>0&&n-this.prevTime<o&&r==this.prevUserEvent&&r&&/^select($|\.)/.test(r)&&Sn(l[l.length-1],t)?this:new D(Ze(this.done,t),this.undone,n,r)}addMapping(t){return new D(se(this.done,t),se(this.undone,t),this.prevTime,this.prevUserEvent)}pop(t,n,r){let o=t==0?this.done:this.undone;if(o.length==0)return null;let l=o[o.length-1],s=l.selectionsAfter[0]||(l.startSelection?l.startSelection.map(l.changes.invertedDesc,1):n.selection);if(r&&l.selectionsAfter.length)return n.update({selection:l.selectionsAfter[l.selectionsAfter.length-1],annotations:ue.of({side:t,rest:An(o),selection:s}),userEvent:t==0?"select.undo":"select.redo",scrollIntoView:!0});if(l.changes){let i=o.length==1?A:o.slice(0,o.length-1);return l.mapped&&(i=se(i,l.mapped)),n.update({changes:l.changes,selection:l.startSelection,effects:l.effects,annotations:ue.of({side:t,rest:i,selection:s}),filter:!1,userEvent:t==0?"undo":"redo",scrollIntoView:!0})}else return null}}D.empty=new D(A,A);const Ln=[{key:"Mod-z",run:Xe,preventDefault:!0},{key:"Mod-y",mac:"Mod-Shift-z",run:fe,preventDefault:!0},{linux:"Ctrl-Shift-z",run:fe,preventDefault:!0},{key:"Mod-u",run:gn,preventDefault:!0},{key:"Alt-u",mac:"Mod-Shift-u",run:yn,preventDefault:!0}];function q(e,t){return f.create(e.ranges.map(t),e.mainIndex)}function L(e,t){return e.update({selection:t,scrollIntoView:!0,userEvent:"select"})}function v({state:e,dispatch:t},n){let r=q(e.selection,n);return r.eq(e.selection,!0)?!1:(t(L(e,r)),!0)}function te(e,t){return f.cursor(t?e.to:e.from)}function et(e,t){return v(e,n=>n.empty?e.moveByChar(n,t):te(n,t))}function p(e){return e.textDirectionAt(e.state.selection.main.head)==Nt.LTR}const tt=e=>et(e,!p(e)),nt=e=>et(e,p(e));function rt(e,t){return v(e,n=>n.empty?e.moveByGroup(n,t):te(n,t))}const vn=e=>rt(e,!p(e)),Dn=e=>rt(e,p(e));function Bn(e,t,n){if(t.type.prop(n))return!0;let r=t.to-t.from;return r&&(r>2||/[^\s,.;:]/.test(e.sliceDoc(t.from,t.to)))||t.firstChild}function ne(e,t,n){let r=Se(e).resolveInner(t.head),o=n?ae.closedBy:ae.openedBy;for(let c=t.head;;){let a=n?r.childAfter(c):r.childBefore(c);if(!a)break;Bn(e,a,o)?r=a:c=n?a.to:a.from}let l=r.type.prop(o),s,i;return l&&(s=n?W(e,r.from,1):W(e,r.to,-1))&&s.matched?i=n?s.end.to:s.end.from:i=n?r.to:r.from,f.cursor(i,n?-1:1)}const bn=e=>v(e,t=>ne(e.state,t,!p(e))),En=e=>v(e,t=>ne(e.state,t,p(e)));function ot(e,t){return v(e,n=>{if(!n.empty)return te(n,t);let r=e.moveVertically(n,t);return r.head!=n.head?r:e.moveToLineBoundary(n,t)})}const lt=e=>ot(e,!1),st=e=>ot(e,!0);function it(e){let t=e.scrollDOM.clientHeight<e.scrollDOM.scrollHeight-2,n=0,r=0,o;if(t){for(let l of e.state.facet(m.scrollMargins)){let s=l(e);s?.top&&(n=Math.max(s?.top,n)),s?.bottom&&(r=Math.max(s?.bottom,r))}o=e.scrollDOM.clientHeight-n-r}else o=(e.dom.ownerDocument.defaultView||window).innerHeight;return{marginTop:n,marginBottom:r,selfScroll:t,height:Math.max(e.defaultLineHeight,o-5)}}function ct(e,t){let n=it(e),{state:r}=e,o=q(r.selection,s=>s.empty?e.moveVertically(s,t,n.height):te(s,t));if(o.eq(r.selection))return!1;let l;if(n.selfScroll){let s=e.coordsAtPos(r.selection.main.head),i=e.scrollDOM.getBoundingClientRect(),c=i.top+n.marginTop,a=i.bottom-n.marginBottom;s&&s.top>c&&s.bottom<a&&(l=m.scrollIntoView(o.main.head,{y:"start",yMargin:s.top-c}))}return e.dispatch(L(r,o),{effects:l}),!0}const Ee=e=>ct(e,!1),de=e=>ct(e,!0);function b(e,t,n){let r=e.lineBlockAt(t.head),o=e.moveToLineBoundary(t,n);if(o.head==t.head&&o.head!=(n?r.to:r.from)&&(o=e.moveToLineBoundary(t,n,!1)),!n&&o.head==r.from&&r.length){let l=/^\s*/.exec(e.state.sliceDoc(r.from,Math.min(r.from+100,r.to)))[0].length;l&&t.head!=r.from+l&&(o=f.cursor(r.from+l))}return o}const Tn=e=>v(e,t=>b(e,t,!0)),Rn=e=>v(e,t=>b(e,t,!1)),On=e=>v(e,t=>b(e,t,!p(e))),In=e=>v(e,t=>b(e,t,p(e))),Wn=e=>v(e,t=>e.moveToLineBoundary(t,!1,!1)),Fn=e=>v(e,t=>e.moveToLineBoundary(t,!0,!1));function Pn(e,t,n){let r=!1,o=q(e.selection,l=>{let s=W(e,l.head,-1)||W(e,l.head,1)||l.head>0&&W(e,l.head-1,1)||l.head<e.doc.length&&W(e,l.head+1,-1);if(!s||!s.end)return l;r=!0;let i=s.start.from==l.head?s.end.to:s.end.from;return f.cursor(i)});return r?(t(L(e,o)),!0):!1}const qn=({state:e,dispatch:t})=>Pn(e,t);function M(e,t,n){let r=q(e.state.selection,o=>{o.undirectional&&o.head>=o.anchor!=t&&(o=f.range(o.head,o.anchor));let l=n(o);return f.range(o.anchor,l.head,l.goalColumn,l.bidiLevel||void 0,l.assoc)});return r.eq(e.state.selection)?!1:(e.dispatch(L(e.state,r)),!0)}function at(e,t){return M(e,t,n=>e.moveByChar(n,t))}const ht=e=>at(e,!p(e)),ut=e=>at(e,p(e));function ft(e,t){return M(e,t,n=>e.moveByGroup(n,t))}const Nn=e=>ft(e,!p(e)),Vn=e=>ft(e,p(e)),wn=e=>{let t=!p(e);return M(e,t,n=>ne(e.state,n,t))},Gn=e=>{let t=p(e);return M(e,t,n=>ne(e.state,n,t))};function dt(e,t){return M(e,t,n=>e.moveVertically(n,t))}const mt=e=>dt(e,!1),pt=e=>dt(e,!0);function gt(e,t){return M(e,t,n=>e.moveVertically(n,t,it(e).height))}const Te=e=>gt(e,!1),Re=e=>gt(e,!0),Un=e=>M(e,!0,t=>b(e,t,!0)),zn=e=>M(e,!1,t=>b(e,t,!1)),Hn=e=>{let t=!p(e);return M(e,t,n=>b(e,n,t))},Jn=e=>{let t=p(e);return M(e,t,n=>b(e,n,t))},$n=e=>M(e,!1,t=>f.cursor(e.lineBlockAt(t.head).from)),_n=e=>M(e,!0,t=>f.cursor(e.lineBlockAt(t.head).to)),Oe=({state:e,dispatch:t})=>(t(L(e,{anchor:0})),!0),Ie=({state:e,dispatch:t})=>(t(L(e,{anchor:e.doc.length})),!0),We=({state:e,dispatch:t})=>(t(L(e,{anchor:e.selection.main.anchor,head:0})),!0),Fe=({state:e,dispatch:t})=>(t(L(e,{anchor:e.selection.main.anchor,head:e.doc.length})),!0),Kn=({state:e,dispatch:t})=>(t(e.update({selection:{anchor:0,head:e.doc.length},userEvent:"select"})),!0),Qn=({state:e,dispatch:t})=>{let n=re(e).map(({from:r,to:o})=>f.undirectionalRange(r,Math.min(o+1,e.doc.length)));return t(e.update({selection:f.create(n),userEvent:"select"})),!0},jn=({state:e,dispatch:t})=>{let n=q(e.selection,r=>{let o=Se(e),l=o.resolveStack(r.from,1);if(r.empty){let s=o.resolveStack(r.from,-1);s.node.from>=l.node.from&&s.node.to<=l.node.to&&(l=s)}for(let s=l;s;s=s.next){let{node:i}=s;if((i.from<r.from&&i.to>=r.to||i.to>r.to&&i.from<=r.from)&&s.next)return f.undirectionalRange(i.from,i.to)}return r});return n.eq(e.selection)?!1:(t(L(e,n)),!0)};function yt(e,t){let{state:n}=e,r=n.selection,o=n.selection.ranges.slice();for(let l of n.selection.ranges){let s=n.doc.lineAt(l.head);if(t?s.to<e.state.doc.length:s.from>0)for(let i=l;;){let c=e.moveVertically(i,t);if(c.head<s.from||c.head>s.to){o.some(a=>a.head==c.head)||o.push(c);break}else{if(c.head==i.head)break;i=c}}}return o.length==r.ranges.length?!1:(e.dispatch(L(n,f.create(o,o.length-1))),!0)}const Xn=e=>yt(e,!1),Yn=e=>yt(e,!0),Zn=({state:e,dispatch:t})=>{let n=e.selection,r=null;return n.ranges.length>1?r=f.create([n.main]):n.main.empty||(r=f.create([f.cursor(n.main.head)])),r?(t(L(e,r)),!0):!1};function G(e,t){if(e.state.readOnly)return!1;let n="delete.selection",{state:r}=e,o=r.changeByRange(l=>{let{from:s,to:i}=l;if(s==i){let c=t(l);c<s?(n="delete.backward",c=z(e,c,!1)):c>s&&(n="delete.forward",c=z(e,c,!0)),s=Math.min(s,c),i=Math.max(i,c)}else s=z(e,s,!1),i=z(e,i,!0);return s==i?{range:l}:{changes:{from:s,to:i},range:f.cursor(s,s<l.head?-1:1)}});return o.changes.empty?!1:(e.dispatch(r.update(o,{scrollIntoView:!0,userEvent:n,effects:n=="delete.selection"?m.announce.of(r.phrase("Selection deleted")):void 0})),!0)}function z(e,t,n){if(e instanceof m)for(let r of e.state.facet(m.atomicRanges).map(o=>o(e)))r.between(t,t,(o,l)=>{o<t&&l>t&&(t=n?l:o)});return t}const xt=(e,t,n)=>G(e,r=>{let o=r.from,{state:l}=e,s=l.doc.lineAt(o),i,c;if(n&&!t&&o>s.from&&o<s.from+200&&!/[^ \t]/.test(i=s.text.slice(0,o-s.from))){if(i[i.length-1]==" ")return o-1;let a=xe(i,l.tabSize),h=a%he(l)||he(l);for(let u=0;u<h&&i[i.length-1-u]==" ";u++)o--;c=o}else c=E(s.text,o-s.from,t,t)+s.from,c==o&&s.number!=(t?l.doc.lines:1)?c+=t?1:-1:!t&&/[\ufe00-\ufe0f]/.test(s.text.slice(c-s.from,o-s.from))&&(c=E(s.text,c-s.from,!1,!1)+s.from);return c}),me=e=>xt(e,!1,!0),St=e=>xt(e,!0,!1),kt=(e,t)=>G(e,n=>{let r=n.head,{state:o}=e,l=o.doc.lineAt(r),s=o.charCategorizer(r);for(let i=null;;){if(r==(t?l.to:l.from)){r==n.head&&l.number!=(t?o.doc.lines:1)&&(r+=t?1:-1);break}let c=E(l.text,r-l.from,t)+l.from,a=l.text.slice(Math.min(r,c)-l.from,Math.max(r,c)-l.from),h=s(a);if(i!=null&&h!=i)break;(a!=" "||r!=n.head)&&(i=h),r=c}return r}),At=e=>kt(e,!1),er=e=>kt(e,!0),tr=e=>G(e,t=>{let n=e.lineBlockAt(t.head).to;return t.head<n?n:Math.min(e.state.doc.length,t.head+1)}),nr=e=>G(e,t=>{let n=e.moveToLineBoundary(t,!1).head;return t.head>n?n:Math.max(0,t.head-1)}),rr=e=>G(e,t=>{let n=e.moveToLineBoundary(t,!0).head;return t.head<n?n:Math.min(e.state.doc.length,t.head+1)}),or=({state:e,dispatch:t})=>{if(e.readOnly)return!1;let n=e.changeByRange(r=>({changes:{from:r.from,to:r.to,insert:He.of(["",""])},range:f.cursor(r.from)}));return t(e.update(n,{scrollIntoView:!0,userEvent:"input"})),!0},lr=({state:e,dispatch:t})=>{if(e.readOnly)return!1;let n=e.changeByRange(r=>{if(!r.empty||r.from==0||r.from==e.doc.length)return{range:r};let o=r.from,l=e.doc.lineAt(o),s=o==l.from?o-1:E(l.text,o-l.from,!1)+l.from,i=o==l.to?o+1:E(l.text,o-l.from,!0)+l.from;return{changes:{from:s,to:i,insert:e.doc.slice(o,i).append(e.doc.slice(s,o))},range:f.cursor(i)}});return n.changes.empty?!1:(t(e.update(n,{scrollIntoView:!0,userEvent:"move.character"})),!0)};function re(e){let t=[],n=-1;for(let r of e.selection.ranges){let o=e.doc.lineAt(r.from),l=e.doc.lineAt(r.to);if(!r.empty&&r.to==l.from&&(l=e.doc.lineAt(r.to-1)),n>=o.number){let s=t[t.length-1];s.to=l.to,s.ranges.push(r)}else t.push({from:o.from,to:l.to,ranges:[r]});n=l.number+1}return t}function Mt(e,t,n){if(e.readOnly)return!1;let r=[],o=[];for(let l of re(e)){if(n?l.to==e.doc.length:l.from==0)continue;let s=e.doc.lineAt(n?l.to+1:l.from-1),i=s.length+1;if(n){r.push({from:l.to,to:s.to},{from:l.from,insert:s.text+e.lineBreak});for(let c of l.ranges)o.push(f.range(Math.min(e.doc.length,c.anchor+i),Math.min(e.doc.length,c.head+i)))}else{r.push({from:s.from,to:l.from},{from:l.to,insert:e.lineBreak+s.text});for(let c of l.ranges)o.push(f.range(c.anchor-i,c.head-i))}}return r.length?(t(e.update({changes:r,scrollIntoView:!0,selection:f.create(o,e.selection.mainIndex),userEvent:"move.line"})),!0):!1}const sr=({state:e,dispatch:t})=>Mt(e,t,!1),ir=({state:e,dispatch:t})=>Mt(e,t,!0);function Ct(e,t,n){if(e.readOnly)return!1;let r=[];for(let l of re(e))n?r.push({from:l.from,insert:e.doc.slice(l.from,l.to)+e.lineBreak}):r.push({from:l.to,insert:e.lineBreak+e.doc.slice(l.from,l.to)});let o=e.changes(r);return t(e.update({changes:o,selection:e.selection.map(o,n?1:-1),scrollIntoView:!0,userEvent:"input.copyline"})),!0}const cr=({state:e,dispatch:t})=>Ct(e,t,!1),ar=({state:e,dispatch:t})=>Ct(e,t,!0),hr=e=>{if(e.state.readOnly)return!1;let{state:t}=e,n=t.changes(re(t).map(({from:o,to:l})=>(o>0?o--:l<t.doc.length&&l++,{from:o,to:l}))),r=q(t.selection,o=>{let l;if(e.lineWrapping){let s=e.lineBlockAt(o.head),i=e.coordsAtPos(o.head,o.assoc||1);i&&(l=s.bottom+e.documentTop-i.bottom+e.defaultLineHeight/2)}return e.moveVertically(o,!0,l)}).map(n);return e.dispatch({changes:n,selection:r,scrollIntoView:!0,userEvent:"delete.line"}),!0};function ur(e,t){if(/\(\)|\[\]|\{\}/.test(e.sliceDoc(t-1,t+1)))return{from:t,to:t};let n=Se(e).resolveInner(t),r=n.childBefore(t),o=n.childAfter(t),l;return r&&o&&r.to<=t&&o.from>=t&&(l=r.type.prop(ae.closedBy))&&l.indexOf(o.name)>-1&&e.doc.lineAt(r.to).from==e.doc.lineAt(o.from).from&&!/\S/.test(e.sliceDoc(r.to,o.from))?{from:r.to,to:o.from}:null}const Pe=Lt(!1),fr=Lt(!0);function Lt(e){return({state:t,dispatch:n})=>{if(t.readOnly)return!1;let r=t.changeByRange(o=>{let{from:l,to:s}=o,i=t.doc.lineAt(l),c=!e&&l==s&&ur(t,l);e&&(l=s=(s<=i.to?i:t.doc.lineAt(s)).to);let a=new Ge(t,{simulateBreak:l,simulateDoubleBreak:!!c}),h=ze(a,l);for(h==null&&(h=xe(/^\s*/.exec(t.doc.lineAt(l).text)[0],t.tabSize));s<i.to&&/\s/.test(i.text[s-i.from]);)s++;c?{from:l,to:s}=c:l>i.from&&l<i.from+100&&!/\S/.test(i.text.slice(0,l))&&(l=i.from);let u=["",$(t,h)];return c&&u.push($(t,a.lineIndent(i.from,-1))),{changes:{from:l,to:s,insert:He.of(u)},range:f.cursor(l+1+u[1].length)}});return n(t.update(r,{scrollIntoView:!0,userEvent:"input"})),!0}}function Me(e,t){let n=-1;return e.changeByRange(r=>{let o=[];for(let s=r.from;s<=r.to;){let i=e.doc.lineAt(s);i.number>n&&(r.empty||r.to>i.from)&&(t(i,o,r),n=i.number),s=i.to+1}let l=e.changes(o);return{changes:o,range:f.range(l.mapPos(r.anchor,1),l.mapPos(r.head,1))}})}const dr=({state:e,dispatch:t})=>{if(e.readOnly)return!1;let n=Object.create(null),r=new Ge(e,{overrideIndentation:l=>{let s=n[l];return s??-1}}),o=Me(e,(l,s,i)=>{let c=ze(r,l.from);if(c==null)return;/\S/.test(l.text)||(c=0);let a=/^\s*/.exec(l.text)[0],h=$(e,c);(a!=h||i.from<l.from+a.length)&&(n[l.from]=c,s.push({from:l.from,to:l.from+a.length,insert:h}))});return o.changes.empty||t(e.update(o,{userEvent:"indent"})),!0},vt=({state:e,dispatch:t})=>e.readOnly?!1:(t(e.update(Me(e,(n,r)=>{r.push({from:n.from,insert:e.facet(Vt)})}),{userEvent:"input.indent"})),!0),Dt=({state:e,dispatch:t})=>e.readOnly?!1:(t(e.update(Me(e,(n,r)=>{let o=/^\s*/.exec(n.text)[0];if(!o)return;let l=xe(o,e.tabSize),s=0,i=$(e,Math.max(0,l-he(e)));for(;s<o.length&&s<i.length&&o.charCodeAt(s)==i.charCodeAt(s);)s++;r.push({from:n.from+s,to:n.from+o.length,insert:i.slice(s)})}),{userEvent:"delete.dedent"})),!0),mr=e=>(e.setTabFocusMode(),!0),pr=[{key:"Ctrl-b",run:tt,shift:ht,preventDefault:!0},{key:"Ctrl-f",run:nt,shift:ut},{key:"Ctrl-p",run:lt,shift:mt},{key:"Ctrl-n",run:st,shift:pt},{key:"Ctrl-a",run:Wn,shift:$n},{key:"Ctrl-e",run:Fn,shift:_n},{key:"Ctrl-d",run:St},{key:"Ctrl-h",run:me},{key:"Ctrl-k",run:tr},{key:"Ctrl-Alt-h",run:At},{key:"Ctrl-o",run:or},{key:"Ctrl-t",run:lr},{key:"Ctrl-v",run:de}],gr=[{key:"ArrowLeft",run:tt,shift:ht,preventDefault:!0},{key:"Mod-ArrowLeft",mac:"Alt-ArrowLeft",run:vn,shift:Nn,preventDefault:!0},{mac:"Cmd-ArrowLeft",run:On,shift:Hn,preventDefault:!0},{key:"ArrowRight",run:nt,shift:ut,preventDefault:!0},{key:"Mod-ArrowRight",mac:"Alt-ArrowRight",run:Dn,shift:Vn,preventDefault:!0},{mac:"Cmd-ArrowRight",run:In,shift:Jn,preventDefault:!0},{key:"ArrowUp",run:lt,shift:mt,preventDefault:!0},{mac:"Cmd-ArrowUp",run:Oe,shift:We},{mac:"Ctrl-ArrowUp",run:Ee,shift:Te},{key:"ArrowDown",run:st,shift:pt,preventDefault:!0},{mac:"Cmd-ArrowDown",run:Ie,shift:Fe},{mac:"Ctrl-ArrowDown",run:de,shift:Re},{key:"PageUp",run:Ee,shift:Te},{key:"PageDown",run:de,shift:Re},{key:"Home",run:Rn,shift:zn,preventDefault:!0},{key:"Mod-Home",run:Oe,shift:We},{key:"End",run:Tn,shift:Un,preventDefault:!0},{key:"Mod-End",run:Ie,shift:Fe},{key:"Enter",run:Pe,shift:Pe},{key:"Mod-a",run:Kn},{key:"Backspace",run:me,shift:me,preventDefault:!0},{key:"Delete",run:St,preventDefault:!0},{key:"Mod-Backspace",mac:"Alt-Backspace",run:At,preventDefault:!0},{key:"Mod-Delete",mac:"Alt-Delete",run:er,preventDefault:!0},{mac:"Mod-Backspace",run:nr,preventDefault:!0},{mac:"Mod-Delete",run:rr,preventDefault:!0}].concat(pr.map(e=>({mac:e.key,run:e.run,shift:e.shift}))),yr=[{key:"Alt-ArrowLeft",mac:"Ctrl-ArrowLeft",run:bn,shift:wn},{key:"Alt-ArrowRight",mac:"Ctrl-ArrowRight",run:En,shift:Gn},{key:"Alt-ArrowUp",run:sr},{key:"Shift-Alt-ArrowUp",run:cr},{key:"Alt-ArrowDown",run:ir},{key:"Shift-Alt-ArrowDown",run:ar},{key:"Mod-Alt-ArrowUp",run:Xn},{key:"Mod-Alt-ArrowDown",run:Yn},{key:"Escape",run:Zn},{key:"Mod-Enter",run:fr},{key:"Alt-l",mac:"Ctrl-l",run:Qn},{key:"Mod-i",run:jn,preventDefault:!0},{key:"Mod-[",run:Dt},{key:"Mod-]",run:vt},{key:"Mod-Alt-\\",run:dr},{key:"Shift-Mod-k",run:hr},{key:"Shift-Mod-\\",run:qn},{key:"Mod-/",run:ln},{key:"Alt-A",mac:"Ctrl-A",run:cn},{key:"Ctrl-m",mac:"Shift-Alt-m",run:mr}].concat(gr),xr={key:"Tab",run:vt,shift:Dt},qe=typeof String.prototype.normalize=="function"?e=>e.normalize("NFKD"):e=>e;class P{constructor(t,n,r=0,o=t.length,l,s){this.test=s,this.value={from:0,to:0,precise:!1},this.done=!1,this.matches=[],this.buffer="",this.bufferPos=0,this.iter=t.iterRange(r,o),this.bufferStart=r,this.normalize=l?i=>l(qe(i)):qe,this.query=this.normalize(n)}peek(){if(this.bufferPos==this.buffer.length){if(this.bufferStart+=this.buffer.length,this.iter.next(),this.iter.done)return-1;this.bufferPos=0,this.buffer=this.iter.value}return Ht(this.buffer,this.bufferPos)}next(){for(;this.matches.length;)this.matches.pop();return this.nextOverlapping()}nextOverlapping(){for(;;){let t=this.peek();if(t<0)return this.done=!0,this;let n=_t(t),r=this.bufferStart+this.bufferPos;this.bufferPos+=Jt(t);let o=this.normalize(n);if(o.length)for(let l=0,s=r,i=!0;;l++){let c=o.charCodeAt(l),a=this.match(c,s,i,this.bufferPos+this.bufferStart,l==o.length-1);if(a)return this.value=a,this;if(l==o.length-1)break;i&&l<n.length&&n.charCodeAt(l)==c?s++:i=!1}}}match(t,n,r,o,l){let s=null;for(let i=0;i<this.matches.length;){let c=this.matches[i],a=!1;this.query.charCodeAt(c.index)==t&&(c.index==this.query.length-1?s={from:c.from,to:o,precise:l&&c.precise}:(c.index++,a=!0)),a?i++:this.matches.splice(i,1)}return this.query.charCodeAt(0)==t&&(this.query.length==1?s={from:n,to:o,precise:r&&l}:this.matches.push({from:n,index:1,precise:r})),s&&this.test&&!this.test(s.from,s.to,this.buffer,this.bufferStart)&&(s=null),s}}typeof Symbol<"u"&&(P.prototype[Symbol.iterator]=function(){return this});const Bt={from:-1,to:-1,match:/.*/.exec(""),precise:!0},Ce="gm"+(/x/.unicode==null?"":"u");class bt{constructor(t,n,r,o=0,l=t.length){if(this.text=t,this.to=l,this.curLine="",this.done=!1,this.value=Bt,/\\[sWDnr]|\n|\r|\[\^/.test(n))return new Et(t,n,r,o,l);this.re=new RegExp(n,Ce+(r?.ignoreCase?"i":"")),this.test=r?.test,this.iter=t.iter();let s=t.lineAt(o);this.curLineStart=s.from,this.matchPos=K(t,o),this.getLine(this.curLineStart)}getLine(t){this.iter.next(t),this.iter.lineBreak?this.curLine="":(this.curLine=this.iter.value,this.curLineStart+this.curLine.length>this.to&&(this.curLine=this.curLine.slice(0,this.to-this.curLineStart)),this.iter.next())}nextLine(){this.curLineStart=this.curLineStart+this.curLine.length+1,this.curLineStart>this.to?this.curLine="":this.getLine(0)}next(){for(let t=this.matchPos-this.curLineStart;;){this.re.lastIndex=t;let n=this.matchPos<=this.to&&this.re.exec(this.curLine);if(n){let r=this.curLineStart+n.index,o=r+n[0].length;if(this.matchPos=K(this.text,o+(r==o?1:0)),r==this.curLineStart+this.curLine.length&&this.nextLine(),(r<o||r>this.value.to)&&(!this.test||this.test(r,o,n)))return this.value={from:r,to:o,precise:!0,match:n},this;t=this.matchPos-this.curLineStart}else if(this.curLineStart+this.curLine.length<this.to)this.nextLine(),t=0;else return this.done=!0,this}}}const ie=new WeakMap;class F{constructor(t,n){this.from=t,this.text=n}get to(){return this.from+this.text.length}static get(t,n,r){let o=ie.get(t);if(!o||o.from>=r||o.to<=n){let i=new F(n,t.sliceString(n,r));return ie.set(t,i),i}if(o.from==n&&o.to==r)return o;let{text:l,from:s}=o;return s>n&&(l=t.sliceString(n,s)+l,s=n),o.to<r&&(l+=t.sliceString(o.to,r)),ie.set(t,new F(s,l)),new F(n,l.slice(n-s,r-s))}}class Et{constructor(t,n,r,o,l){this.text=t,this.to=l,this.done=!1,this.value=Bt,this.matchPos=K(t,o),this.re=new RegExp(n,Ce+(r?.ignoreCase?"i":"")),this.test=r?.test,this.flat=F.get(t,o,this.chunkEnd(o+5e3))}chunkEnd(t){return t>=this.to?this.to:this.text.lineAt(t).to}next(){for(;;){let t=this.re.lastIndex=this.matchPos-this.flat.from,n=this.re.exec(this.flat.text);if(n&&!n[0]&&n.index==t&&(this.re.lastIndex=t+1,n=this.re.exec(this.flat.text)),n){let r=this.flat.from+n.index,o=r+n[0].length;if((this.flat.to>=this.to||n.index+n[0].length<=this.flat.text.length-10)&&(!this.test||this.test(r,o,n)))return this.value={from:r,to:o,precise:!0,match:n},this.matchPos=K(this.text,o+(r==o?1:0)),this}if(this.flat.to==this.to)return this.done=!0,this;this.flat=F.get(this.text,this.flat.from,this.chunkEnd(this.flat.from+this.flat.text.length*2))}}}typeof Symbol<"u"&&(bt.prototype[Symbol.iterator]=Et.prototype[Symbol.iterator]=function(){return this});function Sr(e){try{return new RegExp(e,Ce),!0}catch{return!1}}function K(e,t){if(t>=e.length)return t;let n=e.lineAt(t),r;for(;t<n.to&&(r=n.text.charCodeAt(t-n.from))>=56320&&r<57344;)t++;return t}const kr=e=>{let t=wt(e,"cm-goto-line");if(t){let s=t.dom.querySelector("input[type=text]");return s&&s.select(),!0}let{state:n}=e,r=String(n.doc.lineAt(e.state.selection.main.head).number),{close:o,result:l}=Gt(e,{class:"cm-goto-line",label:n.phrase("Go to line"),input:{type:"text",name:"line",value:r},focus:!0,submitLabel:n.phrase("go")});return l.then(s=>{let i=s&&/^([+-])?(\d+)?(:\d+)?(%)?$/.exec(s.elements.line.value);if(!i){e.dispatch({effects:o});return}let c=n.doc.lineAt(n.selection.main.head),[,a,h,u,d]=i,R=u?+u.slice(1):0,C=h?+h:c.number;if(h&&d){let oe=C/100;a&&(oe=oe*(a=="-"?-1:1)+c.number/n.doc.lines),C=Math.round(n.doc.lines*oe)}else h&&a&&(C=C*(a=="-"?-1:1)+c.number);let Be=n.doc.line(Math.max(1,Math.min(n.doc.lines,C))),be=f.cursor(Be.from+Math.max(0,Math.min(R,Be.length)));e.dispatch({effects:[o,m.scrollIntoView(be.from,{y:"center"})],selection:be})}),!0},Ar={highlightWordAroundCursor:!1,minSelectionLength:1,maxMatches:100,wholeWords:!1},Mr=Z.define({combine(e){return ye(e,Ar,{highlightWordAroundCursor:(t,n)=>t||n,minSelectionLength:Math.min,maxMatches:Math.min})}});function Cr(e){return[br,Br]}const Lr=x.mark({class:"cm-selectionMatch"}),vr=x.mark({class:"cm-selectionMatch cm-selectionMatch-main"});function Ne(e,t,n,r){return(n==0||e(t.sliceDoc(n-1,n))!=k.Word)&&(r==t.doc.length||e(t.sliceDoc(r,r+1))!=k.Word)}function Dr(e,t,n,r){return e(t.sliceDoc(n,n+1))==k.Word&&e(t.sliceDoc(r-1,r))==k.Word}const Br=$e.fromClass(class{constructor(e){this.decorations=this.getDeco(e)}update(e){(e.selectionSet||e.docChanged||e.viewportChanged)&&(this.decorations=this.getDeco(e.view))}getDeco(e){let t=e.state.facet(Mr),{state:n}=e,r=n.selection;if(r.ranges.length>1)return x.none;let o=r.main,l,s=null;if(o.empty){if(!t.highlightWordAroundCursor)return x.none;let c=n.wordAt(o.head);if(!c)return x.none;s=n.charCategorizer(o.head),l=n.sliceDoc(c.from,c.to)}else{let c=o.to-o.from;if(c<t.minSelectionLength||c>200)return x.none;if(t.wholeWords){if(l=n.sliceDoc(o.from,o.to),s=n.charCategorizer(o.head),!(Ne(s,n,o.from,o.to)&&Dr(s,n,o.from,o.to)))return x.none}else if(l=n.sliceDoc(o.from,o.to),!l)return x.none}let i=[];for(let c of e.visibleRanges){let a=new P(n.doc,l,c.from,c.to);for(;!a.next().done;){let{from:h,to:u}=a.value;if((!s||Ne(s,n,h,u))&&(o.empty&&h<=o.from&&u>=o.to?i.push(vr.range(h,u)):(h>=o.to||u<=o.from)&&i.push(Lr.range(h,u)),i.length>t.maxMatches))return x.none}}return x.set(i)}},{decorations:e=>e.decorations}),br=m.baseTheme({".cm-selectionMatch":{backgroundColor:"#99ff7780"},".cm-searchMatch .cm-selectionMatch":{backgroundColor:"transparent"}}),Er=({state:e,dispatch:t})=>{let{selection:n}=e,r=f.create(n.ranges.map(o=>e.wordAt(o.head)||f.cursor(o.head)),n.mainIndex);return r.eq(n)?!1:(t(e.update({selection:r})),!0)};function Tr(e,t){let{main:n,ranges:r}=e.selection,o=e.wordAt(n.head),l=o&&o.from==n.from&&o.to==n.to;for(let s=!1,i=new P(e.doc,t,r[r.length-1].to);;)if(i.next(),i.done){if(s)return null;i=new P(e.doc,t,0,Math.max(0,r[r.length-1].from-1)),s=!0}else{if(s&&r.some(c=>c.from==i.value.from))continue;if(l){let c=e.wordAt(i.value.from);if(!c||c.from!=i.value.from||c.to!=i.value.to)continue}return i.value}}const Rr=({state:e,dispatch:t})=>{let{ranges:n}=e.selection;if(n.some(l=>l.from===l.to))return Er({state:e,dispatch:t});let r=e.sliceDoc(n[0].from,n[0].to);if(e.selection.ranges.some(l=>e.sliceDoc(l.from,l.to)!=r))return!1;let o=Tr(e,r);return o?(t(e.update({selection:e.selection.addRange(f.range(o.from,o.to),!1),effects:m.scrollIntoView(o.to)})),!0):!1},T=Z.define({combine(e){return ye(e,{top:!1,caseSensitive:!1,literal:!1,regexp:!1,wholeWord:!1,createPanel:t=>new $r(t),scrollToMatch:t=>m.scrollIntoView(t)})}});function Or(e){return e?[T.of(e),ge]:ge}class Tt{constructor(t){this.search=t.search,this.caseSensitive=!!t.caseSensitive,this.literal=!!t.literal,this.regexp=!!t.regexp,this.replace=t.replace||"",this.valid=!!this.search&&(!this.regexp||Sr(this.search)),this.unquoted=this.unquote(this.search),this.wholeWord=!!t.wholeWord,this.test=t.test}unquote(t){return this.literal?t:t.replace(/\\([nrt\\])/g,(n,r)=>r=="n"?`
1
+ import{E as m,S as we,T as le,F as Z,c as ye,a as f,I as Ge,b as w,C as Pt,d as qt,A as Ue,D as Nt,g as ze,e as xe,i as $,f as He,s as Se,m as W,h as E,N as ae,j as he,k as Vt,l as Je,n as wt,o as Gt,V as $e,p as x,P as Ut,q as zt,r as Ht,t as Jt,u as k,R as $t,v as _e,w as _t,x as S,y as Kt,z as Qt,B as jt,G as Xt,H as Yt,J as Zt,K as en,L as tn,M as nn,O as rn,Q as on}from"./syntax-BWBIQpR3.js";import"./index-CD_iMftv.js";const ln=e=>{let{state:t}=e,n=t.doc.lineAt(t.selection.main.from),r=Ae(e.state,n.from);return r.line?sn(e):r.block?an(e):!1};function ke(e,t){return({state:n,dispatch:r})=>{if(n.readOnly)return!1;let o=e(t,n);return o?(r(n.update(o)),!0):!1}}const sn=ke(fn,0),cn=ke(Ke,0),an=ke((e,t)=>Ke(e,t,un(t)),0);function Ae(e,t){let n=e.languageDataAt("commentTokens",t,1);return n.length?n[0]:{}}const N=50;function hn(e,{open:t,close:n},r,o){let l=e.sliceDoc(r-N,r),s=e.sliceDoc(o,o+N),i=/\s*$/.exec(l)[0].length,c=/^\s*/.exec(s)[0].length,a=l.length-i;if(l.slice(a-t.length,a)==t&&s.slice(c,c+n.length)==n)return{open:{pos:r-i,margin:i&&1},close:{pos:o+c,margin:c&&1}};let h,u;o-r<=2*N?h=u=e.sliceDoc(r,o):(h=e.sliceDoc(r,r+N),u=e.sliceDoc(o-N,o));let d=/^\s*/.exec(h)[0].length,R=/\s*$/.exec(u)[0].length,C=u.length-R-n.length;return h.slice(d,d+t.length)==t&&u.slice(C,C+n.length)==n?{open:{pos:r+d+t.length,margin:/\s/.test(h.charAt(d+t.length))?1:0},close:{pos:o-R-n.length,margin:/\s/.test(u.charAt(C-1))?1:0}}:null}function un(e){let t=[];for(let n of e.selection.ranges){let r=e.doc.lineAt(n.from),o=n.to<=r.to?r:e.doc.lineAt(n.to);o.from>r.from&&o.from==n.to&&(o=n.to==r.to+1?r:e.doc.lineAt(n.to-1));let l=t.length-1;l>=0&&t[l].to>r.from?t[l].to=o.to:t.push({from:r.from+/^\s*/.exec(r.text)[0].length,to:o.to})}return t}function Ke(e,t,n=t.selection.ranges){let r=n.map(l=>Ae(t,l.from).block);if(!r.every(l=>l))return null;let o=n.map((l,s)=>hn(t,r[s],l.from,l.to));if(e!=2&&!o.every(l=>l))return{changes:t.changes(n.map((l,s)=>o[s]?[]:[{from:l.from,insert:r[s].open+" "},{from:l.to,insert:" "+r[s].close}]))};if(e!=1&&o.some(l=>l)){let l=[];for(let s=0,i;s<o.length;s++)if(i=o[s]){let c=r[s],{open:a,close:h}=i;l.push({from:a.pos-c.open.length,to:a.pos+a.margin},{from:h.pos-h.margin,to:h.pos+c.close.length})}return{changes:l}}return null}function fn(e,t,n=t.selection.ranges){let r=[],o=-1;e:for(let{from:l,to:s}of n){let i=r.length,c=1e9,a;for(let h=l;h<=s;){let u=t.doc.lineAt(h);if(a==null&&(a=Ae(t,u.from).line,!a))continue e;if(u.from>o&&(l==s||s>u.from)){o=u.from;let d=/^\s*/.exec(u.text)[0].length,R=d==u.length,C=u.text.slice(d,d+a.length)==a?d:-1;d<u.text.length&&d<c&&(c=d),r.push({line:u,comment:C,token:a,indent:d,empty:R,single:!1})}h=u.to+1}if(c<1e9)for(let h=i;h<r.length;h++)r[h].indent<r[h].line.text.length&&(r[h].indent=c);r.length==i+1&&(r[i].single=!0)}if(e!=2&&r.some(l=>l.comment<0&&(!l.empty||l.single))){let l=[];for(let{line:i,token:c,indent:a,empty:h,single:u}of r)(u||!h)&&l.push({from:i.from+a,insert:c+" "});let s=t.changes(l);return{changes:s,selection:t.selection.map(s,1)}}else if(e!=1&&r.some(l=>l.comment>=0)){let l=[];for(let{line:s,comment:i,token:c}of r)if(i>=0){let a=s.from+i,h=a+c.length;s.text[h-s.from]==" "&&h++,l.push({from:a,to:h})}return{changes:l}}return null}const ue=Ue.define(),dn=Ue.define(),mn=Z.define(),Qe=Z.define({combine(e){return ye(e,{minDepth:100,newGroupDelay:500,joinToEvent:(t,n)=>n},{minDepth:Math.max,newGroupDelay:Math.min,joinToEvent:(t,n)=>(r,o)=>t(r,o)||n(r,o)})}}),je=we.define({create(){return D.empty},update(e,t){let n=t.state.facet(Qe),r=t.annotation(ue);if(r){let c=g.fromTransaction(t,r.selection),a=r.side,h=a==0?e.undone:e.done;return c?h=_(h,h.length,n.minDepth,c):h=Ze(h,t.startState.selection),new D(a==0?r.rest:h,a==0?h:r.rest)}let o=t.annotation(dn);if((o=="full"||o=="before")&&(e=e.isolate()),t.annotation(le.addToHistory)===!1)return t.changes.empty?e:e.addMapping(t.changes.desc);let l=g.fromTransaction(t),s=t.annotation(le.time),i=t.annotation(le.userEvent);return l?e=e.addChanges(l,s,i,n,t):t.selection&&(e=e.addSelection(t.startState.selection,s,i,n.newGroupDelay)),(o=="full"||o=="after")&&(e=e.isolate()),e},toJSON(e){return{done:e.done.map(t=>t.toJSON()),undone:e.undone.map(t=>t.toJSON())}},fromJSON(e){return new D(e.done.map(g.fromJSON),e.undone.map(g.fromJSON))}});function pn(e={}){return[je,Qe.of(e),m.domEventHandlers({beforeinput(t,n){let r=t.inputType=="historyUndo"?Xe:t.inputType=="historyRedo"?fe:null;return r?(t.preventDefault(),r(n)):!1}})]}function ee(e,t){return function({state:n,dispatch:r}){if(!t&&n.readOnly)return!1;let o=n.field(je,!1);if(!o)return!1;let l=o.pop(e,n,t);return l?(r(l),!0):!1}}const Xe=ee(0,!1),fe=ee(1,!1),gn=ee(0,!0),yn=ee(1,!0);class g{constructor(t,n,r,o,l){this.changes=t,this.effects=n,this.mapped=r,this.startSelection=o,this.selectionsAfter=l}setSelAfter(t){return new g(this.changes,this.effects,this.mapped,this.startSelection,t)}toJSON(){var t,n,r;return{changes:(t=this.changes)===null||t===void 0?void 0:t.toJSON(),mapped:(n=this.mapped)===null||n===void 0?void 0:n.toJSON(),startSelection:(r=this.startSelection)===null||r===void 0?void 0:r.toJSON(),selectionsAfter:this.selectionsAfter.map(o=>o.toJSON())}}static fromJSON(t){return new g(t.changes&&Pt.fromJSON(t.changes),[],t.mapped&&qt.fromJSON(t.mapped),t.startSelection&&f.fromJSON(t.startSelection),t.selectionsAfter.map(f.fromJSON))}static fromTransaction(t,n){let r=A;for(let o of t.startState.facet(mn)){let l=o(t);l.length&&(r=r.concat(l))}return!r.length&&t.changes.empty?null:new g(t.changes.invert(t.startState.doc),r,void 0,n||t.startState.selection,A)}static selection(t){return new g(void 0,A,void 0,void 0,t)}}function _(e,t,n,r){let o=t+1>n+20?t-n-1:0,l=e.slice(o,t);return l.push(r),l}function xn(e,t){let n=[],r=!1;return e.iterChangedRanges((o,l)=>n.push(o,l)),t.iterChangedRanges((o,l,s,i)=>{for(let c=0;c<n.length;){let a=n[c++],h=n[c++];i>=a&&s<=h&&(r=!0)}}),r}function Sn(e,t){return e.ranges.length==t.ranges.length&&e.ranges.filter((n,r)=>n.empty!=t.ranges[r].empty).length===0}function Ye(e,t){return e.length?t.length?e.concat(t):e:t}const A=[],kn=200;function Ze(e,t){if(e.length){let n=e[e.length-1],r=n.selectionsAfter.slice(Math.max(0,n.selectionsAfter.length-kn));return r.length&&r[r.length-1].eq(t)?e:(r.push(t),_(e,e.length-1,1e9,n.setSelAfter(r)))}else return[g.selection([t])]}function An(e){let t=e[e.length-1],n=e.slice();return n[e.length-1]=t.setSelAfter(t.selectionsAfter.slice(0,t.selectionsAfter.length-1)),n}function se(e,t){if(!e.length)return e;let n=e.length,r=A;for(;n;){let o=Mn(e[n-1],t,r);if(o.changes&&!o.changes.empty||o.effects.length){let l=e.slice(0,n);return l[n-1]=o,l}else t=o.mapped,n--,r=o.selectionsAfter}return r.length?[g.selection(r)]:A}function Mn(e,t,n){let r=Ye(e.selectionsAfter.length?e.selectionsAfter.map(i=>i.map(t)):A,n);if(!e.changes)return g.selection(r);let o=e.changes.map(t),l=t.mapDesc(e.changes,!0),s=e.mapped?e.mapped.composeDesc(l):l;return new g(o,w.mapEffects(e.effects,t),s,e.startSelection.map(l),r)}const Cn=/^(input\.type|delete)($|\.)/;class D{constructor(t,n,r=0,o=void 0){this.done=t,this.undone=n,this.prevTime=r,this.prevUserEvent=o}isolate(){return this.prevTime?new D(this.done,this.undone):this}addChanges(t,n,r,o,l){let s=this.done,i=s[s.length-1];return i&&i.changes&&!i.changes.empty&&t.changes&&(!r||Cn.test(r))&&(!i.selectionsAfter.length&&n-this.prevTime<o.newGroupDelay&&o.joinToEvent(l,xn(i.changes,t.changes))||r=="input.type.compose")?s=_(s,s.length-1,o.minDepth,new g(t.changes.compose(i.changes),Ye(w.mapEffects(t.effects,i.changes),i.effects),i.mapped,i.startSelection,A)):s=_(s,s.length,o.minDepth,t),new D(s,A,n,r)}addSelection(t,n,r,o){let l=this.done.length?this.done[this.done.length-1].selectionsAfter:A;return l.length>0&&n-this.prevTime<o&&r==this.prevUserEvent&&r&&/^select($|\.)/.test(r)&&Sn(l[l.length-1],t)?this:new D(Ze(this.done,t),this.undone,n,r)}addMapping(t){return new D(se(this.done,t),se(this.undone,t),this.prevTime,this.prevUserEvent)}pop(t,n,r){let o=t==0?this.done:this.undone;if(o.length==0)return null;let l=o[o.length-1],s=l.selectionsAfter[0]||(l.startSelection?l.startSelection.map(l.changes.invertedDesc,1):n.selection);if(r&&l.selectionsAfter.length)return n.update({selection:l.selectionsAfter[l.selectionsAfter.length-1],annotations:ue.of({side:t,rest:An(o),selection:s}),userEvent:t==0?"select.undo":"select.redo",scrollIntoView:!0});if(l.changes){let i=o.length==1?A:o.slice(0,o.length-1);return l.mapped&&(i=se(i,l.mapped)),n.update({changes:l.changes,selection:l.startSelection,effects:l.effects,annotations:ue.of({side:t,rest:i,selection:s}),filter:!1,userEvent:t==0?"undo":"redo",scrollIntoView:!0})}else return null}}D.empty=new D(A,A);const Ln=[{key:"Mod-z",run:Xe,preventDefault:!0},{key:"Mod-y",mac:"Mod-Shift-z",run:fe,preventDefault:!0},{linux:"Ctrl-Shift-z",run:fe,preventDefault:!0},{key:"Mod-u",run:gn,preventDefault:!0},{key:"Alt-u",mac:"Mod-Shift-u",run:yn,preventDefault:!0}];function q(e,t){return f.create(e.ranges.map(t),e.mainIndex)}function L(e,t){return e.update({selection:t,scrollIntoView:!0,userEvent:"select"})}function v({state:e,dispatch:t},n){let r=q(e.selection,n);return r.eq(e.selection,!0)?!1:(t(L(e,r)),!0)}function te(e,t){return f.cursor(t?e.to:e.from)}function et(e,t){return v(e,n=>n.empty?e.moveByChar(n,t):te(n,t))}function p(e){return e.textDirectionAt(e.state.selection.main.head)==Nt.LTR}const tt=e=>et(e,!p(e)),nt=e=>et(e,p(e));function rt(e,t){return v(e,n=>n.empty?e.moveByGroup(n,t):te(n,t))}const vn=e=>rt(e,!p(e)),Dn=e=>rt(e,p(e));function Bn(e,t,n){if(t.type.prop(n))return!0;let r=t.to-t.from;return r&&(r>2||/[^\s,.;:]/.test(e.sliceDoc(t.from,t.to)))||t.firstChild}function ne(e,t,n){let r=Se(e).resolveInner(t.head),o=n?ae.closedBy:ae.openedBy;for(let c=t.head;;){let a=n?r.childAfter(c):r.childBefore(c);if(!a)break;Bn(e,a,o)?r=a:c=n?a.to:a.from}let l=r.type.prop(o),s,i;return l&&(s=n?W(e,r.from,1):W(e,r.to,-1))&&s.matched?i=n?s.end.to:s.end.from:i=n?r.to:r.from,f.cursor(i,n?-1:1)}const bn=e=>v(e,t=>ne(e.state,t,!p(e))),En=e=>v(e,t=>ne(e.state,t,p(e)));function ot(e,t){return v(e,n=>{if(!n.empty)return te(n,t);let r=e.moveVertically(n,t);return r.head!=n.head?r:e.moveToLineBoundary(n,t)})}const lt=e=>ot(e,!1),st=e=>ot(e,!0);function it(e){let t=e.scrollDOM.clientHeight<e.scrollDOM.scrollHeight-2,n=0,r=0,o;if(t){for(let l of e.state.facet(m.scrollMargins)){let s=l(e);s?.top&&(n=Math.max(s?.top,n)),s?.bottom&&(r=Math.max(s?.bottom,r))}o=e.scrollDOM.clientHeight-n-r}else o=(e.dom.ownerDocument.defaultView||window).innerHeight;return{marginTop:n,marginBottom:r,selfScroll:t,height:Math.max(e.defaultLineHeight,o-5)}}function ct(e,t){let n=it(e),{state:r}=e,o=q(r.selection,s=>s.empty?e.moveVertically(s,t,n.height):te(s,t));if(o.eq(r.selection))return!1;let l;if(n.selfScroll){let s=e.coordsAtPos(r.selection.main.head),i=e.scrollDOM.getBoundingClientRect(),c=i.top+n.marginTop,a=i.bottom-n.marginBottom;s&&s.top>c&&s.bottom<a&&(l=m.scrollIntoView(o.main.head,{y:"start",yMargin:s.top-c}))}return e.dispatch(L(r,o),{effects:l}),!0}const Ee=e=>ct(e,!1),de=e=>ct(e,!0);function b(e,t,n){let r=e.lineBlockAt(t.head),o=e.moveToLineBoundary(t,n);if(o.head==t.head&&o.head!=(n?r.to:r.from)&&(o=e.moveToLineBoundary(t,n,!1)),!n&&o.head==r.from&&r.length){let l=/^\s*/.exec(e.state.sliceDoc(r.from,Math.min(r.from+100,r.to)))[0].length;l&&t.head!=r.from+l&&(o=f.cursor(r.from+l))}return o}const Tn=e=>v(e,t=>b(e,t,!0)),Rn=e=>v(e,t=>b(e,t,!1)),On=e=>v(e,t=>b(e,t,!p(e))),In=e=>v(e,t=>b(e,t,p(e))),Wn=e=>v(e,t=>e.moveToLineBoundary(t,!1,!1)),Fn=e=>v(e,t=>e.moveToLineBoundary(t,!0,!1));function Pn(e,t,n){let r=!1,o=q(e.selection,l=>{let s=W(e,l.head,-1)||W(e,l.head,1)||l.head>0&&W(e,l.head-1,1)||l.head<e.doc.length&&W(e,l.head+1,-1);if(!s||!s.end)return l;r=!0;let i=s.start.from==l.head?s.end.to:s.end.from;return f.cursor(i)});return r?(t(L(e,o)),!0):!1}const qn=({state:e,dispatch:t})=>Pn(e,t);function M(e,t,n){let r=q(e.state.selection,o=>{o.undirectional&&o.head>=o.anchor!=t&&(o=f.range(o.head,o.anchor));let l=n(o);return f.range(o.anchor,l.head,l.goalColumn,l.bidiLevel||void 0,l.assoc)});return r.eq(e.state.selection)?!1:(e.dispatch(L(e.state,r)),!0)}function at(e,t){return M(e,t,n=>e.moveByChar(n,t))}const ht=e=>at(e,!p(e)),ut=e=>at(e,p(e));function ft(e,t){return M(e,t,n=>e.moveByGroup(n,t))}const Nn=e=>ft(e,!p(e)),Vn=e=>ft(e,p(e)),wn=e=>{let t=!p(e);return M(e,t,n=>ne(e.state,n,t))},Gn=e=>{let t=p(e);return M(e,t,n=>ne(e.state,n,t))};function dt(e,t){return M(e,t,n=>e.moveVertically(n,t))}const mt=e=>dt(e,!1),pt=e=>dt(e,!0);function gt(e,t){return M(e,t,n=>e.moveVertically(n,t,it(e).height))}const Te=e=>gt(e,!1),Re=e=>gt(e,!0),Un=e=>M(e,!0,t=>b(e,t,!0)),zn=e=>M(e,!1,t=>b(e,t,!1)),Hn=e=>{let t=!p(e);return M(e,t,n=>b(e,n,t))},Jn=e=>{let t=p(e);return M(e,t,n=>b(e,n,t))},$n=e=>M(e,!1,t=>f.cursor(e.lineBlockAt(t.head).from)),_n=e=>M(e,!0,t=>f.cursor(e.lineBlockAt(t.head).to)),Oe=({state:e,dispatch:t})=>(t(L(e,{anchor:0})),!0),Ie=({state:e,dispatch:t})=>(t(L(e,{anchor:e.doc.length})),!0),We=({state:e,dispatch:t})=>(t(L(e,{anchor:e.selection.main.anchor,head:0})),!0),Fe=({state:e,dispatch:t})=>(t(L(e,{anchor:e.selection.main.anchor,head:e.doc.length})),!0),Kn=({state:e,dispatch:t})=>(t(e.update({selection:{anchor:0,head:e.doc.length},userEvent:"select"})),!0),Qn=({state:e,dispatch:t})=>{let n=re(e).map(({from:r,to:o})=>f.undirectionalRange(r,Math.min(o+1,e.doc.length)));return t(e.update({selection:f.create(n),userEvent:"select"})),!0},jn=({state:e,dispatch:t})=>{let n=q(e.selection,r=>{let o=Se(e),l=o.resolveStack(r.from,1);if(r.empty){let s=o.resolveStack(r.from,-1);s.node.from>=l.node.from&&s.node.to<=l.node.to&&(l=s)}for(let s=l;s;s=s.next){let{node:i}=s;if((i.from<r.from&&i.to>=r.to||i.to>r.to&&i.from<=r.from)&&s.next)return f.undirectionalRange(i.from,i.to)}return r});return n.eq(e.selection)?!1:(t(L(e,n)),!0)};function yt(e,t){let{state:n}=e,r=n.selection,o=n.selection.ranges.slice();for(let l of n.selection.ranges){let s=n.doc.lineAt(l.head);if(t?s.to<e.state.doc.length:s.from>0)for(let i=l;;){let c=e.moveVertically(i,t);if(c.head<s.from||c.head>s.to){o.some(a=>a.head==c.head)||o.push(c);break}else{if(c.head==i.head)break;i=c}}}return o.length==r.ranges.length?!1:(e.dispatch(L(n,f.create(o,o.length-1))),!0)}const Xn=e=>yt(e,!1),Yn=e=>yt(e,!0),Zn=({state:e,dispatch:t})=>{let n=e.selection,r=null;return n.ranges.length>1?r=f.create([n.main]):n.main.empty||(r=f.create([f.cursor(n.main.head)])),r?(t(L(e,r)),!0):!1};function G(e,t){if(e.state.readOnly)return!1;let n="delete.selection",{state:r}=e,o=r.changeByRange(l=>{let{from:s,to:i}=l;if(s==i){let c=t(l);c<s?(n="delete.backward",c=z(e,c,!1)):c>s&&(n="delete.forward",c=z(e,c,!0)),s=Math.min(s,c),i=Math.max(i,c)}else s=z(e,s,!1),i=z(e,i,!0);return s==i?{range:l}:{changes:{from:s,to:i},range:f.cursor(s,s<l.head?-1:1)}});return o.changes.empty?!1:(e.dispatch(r.update(o,{scrollIntoView:!0,userEvent:n,effects:n=="delete.selection"?m.announce.of(r.phrase("Selection deleted")):void 0})),!0)}function z(e,t,n){if(e instanceof m)for(let r of e.state.facet(m.atomicRanges).map(o=>o(e)))r.between(t,t,(o,l)=>{o<t&&l>t&&(t=n?l:o)});return t}const xt=(e,t,n)=>G(e,r=>{let o=r.from,{state:l}=e,s=l.doc.lineAt(o),i,c;if(n&&!t&&o>s.from&&o<s.from+200&&!/[^ \t]/.test(i=s.text.slice(0,o-s.from))){if(i[i.length-1]==" ")return o-1;let a=xe(i,l.tabSize),h=a%he(l)||he(l);for(let u=0;u<h&&i[i.length-1-u]==" ";u++)o--;c=o}else c=E(s.text,o-s.from,t,t)+s.from,c==o&&s.number!=(t?l.doc.lines:1)?c+=t?1:-1:!t&&/[\ufe00-\ufe0f]/.test(s.text.slice(c-s.from,o-s.from))&&(c=E(s.text,c-s.from,!1,!1)+s.from);return c}),me=e=>xt(e,!1,!0),St=e=>xt(e,!0,!1),kt=(e,t)=>G(e,n=>{let r=n.head,{state:o}=e,l=o.doc.lineAt(r),s=o.charCategorizer(r);for(let i=null;;){if(r==(t?l.to:l.from)){r==n.head&&l.number!=(t?o.doc.lines:1)&&(r+=t?1:-1);break}let c=E(l.text,r-l.from,t)+l.from,a=l.text.slice(Math.min(r,c)-l.from,Math.max(r,c)-l.from),h=s(a);if(i!=null&&h!=i)break;(a!=" "||r!=n.head)&&(i=h),r=c}return r}),At=e=>kt(e,!1),er=e=>kt(e,!0),tr=e=>G(e,t=>{let n=e.lineBlockAt(t.head).to;return t.head<n?n:Math.min(e.state.doc.length,t.head+1)}),nr=e=>G(e,t=>{let n=e.moveToLineBoundary(t,!1).head;return t.head>n?n:Math.max(0,t.head-1)}),rr=e=>G(e,t=>{let n=e.moveToLineBoundary(t,!0).head;return t.head<n?n:Math.min(e.state.doc.length,t.head+1)}),or=({state:e,dispatch:t})=>{if(e.readOnly)return!1;let n=e.changeByRange(r=>({changes:{from:r.from,to:r.to,insert:He.of(["",""])},range:f.cursor(r.from)}));return t(e.update(n,{scrollIntoView:!0,userEvent:"input"})),!0},lr=({state:e,dispatch:t})=>{if(e.readOnly)return!1;let n=e.changeByRange(r=>{if(!r.empty||r.from==0||r.from==e.doc.length)return{range:r};let o=r.from,l=e.doc.lineAt(o),s=o==l.from?o-1:E(l.text,o-l.from,!1)+l.from,i=o==l.to?o+1:E(l.text,o-l.from,!0)+l.from;return{changes:{from:s,to:i,insert:e.doc.slice(o,i).append(e.doc.slice(s,o))},range:f.cursor(i)}});return n.changes.empty?!1:(t(e.update(n,{scrollIntoView:!0,userEvent:"move.character"})),!0)};function re(e){let t=[],n=-1;for(let r of e.selection.ranges){let o=e.doc.lineAt(r.from),l=e.doc.lineAt(r.to);if(!r.empty&&r.to==l.from&&(l=e.doc.lineAt(r.to-1)),n>=o.number){let s=t[t.length-1];s.to=l.to,s.ranges.push(r)}else t.push({from:o.from,to:l.to,ranges:[r]});n=l.number+1}return t}function Mt(e,t,n){if(e.readOnly)return!1;let r=[],o=[];for(let l of re(e)){if(n?l.to==e.doc.length:l.from==0)continue;let s=e.doc.lineAt(n?l.to+1:l.from-1),i=s.length+1;if(n){r.push({from:l.to,to:s.to},{from:l.from,insert:s.text+e.lineBreak});for(let c of l.ranges)o.push(f.range(Math.min(e.doc.length,c.anchor+i),Math.min(e.doc.length,c.head+i)))}else{r.push({from:s.from,to:l.from},{from:l.to,insert:e.lineBreak+s.text});for(let c of l.ranges)o.push(f.range(c.anchor-i,c.head-i))}}return r.length?(t(e.update({changes:r,scrollIntoView:!0,selection:f.create(o,e.selection.mainIndex),userEvent:"move.line"})),!0):!1}const sr=({state:e,dispatch:t})=>Mt(e,t,!1),ir=({state:e,dispatch:t})=>Mt(e,t,!0);function Ct(e,t,n){if(e.readOnly)return!1;let r=[];for(let l of re(e))n?r.push({from:l.from,insert:e.doc.slice(l.from,l.to)+e.lineBreak}):r.push({from:l.to,insert:e.lineBreak+e.doc.slice(l.from,l.to)});let o=e.changes(r);return t(e.update({changes:o,selection:e.selection.map(o,n?1:-1),scrollIntoView:!0,userEvent:"input.copyline"})),!0}const cr=({state:e,dispatch:t})=>Ct(e,t,!1),ar=({state:e,dispatch:t})=>Ct(e,t,!0),hr=e=>{if(e.state.readOnly)return!1;let{state:t}=e,n=t.changes(re(t).map(({from:o,to:l})=>(o>0?o--:l<t.doc.length&&l++,{from:o,to:l}))),r=q(t.selection,o=>{let l;if(e.lineWrapping){let s=e.lineBlockAt(o.head),i=e.coordsAtPos(o.head,o.assoc||1);i&&(l=s.bottom+e.documentTop-i.bottom+e.defaultLineHeight/2)}return e.moveVertically(o,!0,l)}).map(n);return e.dispatch({changes:n,selection:r,scrollIntoView:!0,userEvent:"delete.line"}),!0};function ur(e,t){if(/\(\)|\[\]|\{\}/.test(e.sliceDoc(t-1,t+1)))return{from:t,to:t};let n=Se(e).resolveInner(t),r=n.childBefore(t),o=n.childAfter(t),l;return r&&o&&r.to<=t&&o.from>=t&&(l=r.type.prop(ae.closedBy))&&l.indexOf(o.name)>-1&&e.doc.lineAt(r.to).from==e.doc.lineAt(o.from).from&&!/\S/.test(e.sliceDoc(r.to,o.from))?{from:r.to,to:o.from}:null}const Pe=Lt(!1),fr=Lt(!0);function Lt(e){return({state:t,dispatch:n})=>{if(t.readOnly)return!1;let r=t.changeByRange(o=>{let{from:l,to:s}=o,i=t.doc.lineAt(l),c=!e&&l==s&&ur(t,l);e&&(l=s=(s<=i.to?i:t.doc.lineAt(s)).to);let a=new Ge(t,{simulateBreak:l,simulateDoubleBreak:!!c}),h=ze(a,l);for(h==null&&(h=xe(/^\s*/.exec(t.doc.lineAt(l).text)[0],t.tabSize));s<i.to&&/\s/.test(i.text[s-i.from]);)s++;c?{from:l,to:s}=c:l>i.from&&l<i.from+100&&!/\S/.test(i.text.slice(0,l))&&(l=i.from);let u=["",$(t,h)];return c&&u.push($(t,a.lineIndent(i.from,-1))),{changes:{from:l,to:s,insert:He.of(u)},range:f.cursor(l+1+u[1].length)}});return n(t.update(r,{scrollIntoView:!0,userEvent:"input"})),!0}}function Me(e,t){let n=-1;return e.changeByRange(r=>{let o=[];for(let s=r.from;s<=r.to;){let i=e.doc.lineAt(s);i.number>n&&(r.empty||r.to>i.from)&&(t(i,o,r),n=i.number),s=i.to+1}let l=e.changes(o);return{changes:o,range:f.range(l.mapPos(r.anchor,1),l.mapPos(r.head,1))}})}const dr=({state:e,dispatch:t})=>{if(e.readOnly)return!1;let n=Object.create(null),r=new Ge(e,{overrideIndentation:l=>{let s=n[l];return s??-1}}),o=Me(e,(l,s,i)=>{let c=ze(r,l.from);if(c==null)return;/\S/.test(l.text)||(c=0);let a=/^\s*/.exec(l.text)[0],h=$(e,c);(a!=h||i.from<l.from+a.length)&&(n[l.from]=c,s.push({from:l.from,to:l.from+a.length,insert:h}))});return o.changes.empty||t(e.update(o,{userEvent:"indent"})),!0},vt=({state:e,dispatch:t})=>e.readOnly?!1:(t(e.update(Me(e,(n,r)=>{r.push({from:n.from,insert:e.facet(Vt)})}),{userEvent:"input.indent"})),!0),Dt=({state:e,dispatch:t})=>e.readOnly?!1:(t(e.update(Me(e,(n,r)=>{let o=/^\s*/.exec(n.text)[0];if(!o)return;let l=xe(o,e.tabSize),s=0,i=$(e,Math.max(0,l-he(e)));for(;s<o.length&&s<i.length&&o.charCodeAt(s)==i.charCodeAt(s);)s++;r.push({from:n.from+s,to:n.from+o.length,insert:i.slice(s)})}),{userEvent:"delete.dedent"})),!0),mr=e=>(e.setTabFocusMode(),!0),pr=[{key:"Ctrl-b",run:tt,shift:ht,preventDefault:!0},{key:"Ctrl-f",run:nt,shift:ut},{key:"Ctrl-p",run:lt,shift:mt},{key:"Ctrl-n",run:st,shift:pt},{key:"Ctrl-a",run:Wn,shift:$n},{key:"Ctrl-e",run:Fn,shift:_n},{key:"Ctrl-d",run:St},{key:"Ctrl-h",run:me},{key:"Ctrl-k",run:tr},{key:"Ctrl-Alt-h",run:At},{key:"Ctrl-o",run:or},{key:"Ctrl-t",run:lr},{key:"Ctrl-v",run:de}],gr=[{key:"ArrowLeft",run:tt,shift:ht,preventDefault:!0},{key:"Mod-ArrowLeft",mac:"Alt-ArrowLeft",run:vn,shift:Nn,preventDefault:!0},{mac:"Cmd-ArrowLeft",run:On,shift:Hn,preventDefault:!0},{key:"ArrowRight",run:nt,shift:ut,preventDefault:!0},{key:"Mod-ArrowRight",mac:"Alt-ArrowRight",run:Dn,shift:Vn,preventDefault:!0},{mac:"Cmd-ArrowRight",run:In,shift:Jn,preventDefault:!0},{key:"ArrowUp",run:lt,shift:mt,preventDefault:!0},{mac:"Cmd-ArrowUp",run:Oe,shift:We},{mac:"Ctrl-ArrowUp",run:Ee,shift:Te},{key:"ArrowDown",run:st,shift:pt,preventDefault:!0},{mac:"Cmd-ArrowDown",run:Ie,shift:Fe},{mac:"Ctrl-ArrowDown",run:de,shift:Re},{key:"PageUp",run:Ee,shift:Te},{key:"PageDown",run:de,shift:Re},{key:"Home",run:Rn,shift:zn,preventDefault:!0},{key:"Mod-Home",run:Oe,shift:We},{key:"End",run:Tn,shift:Un,preventDefault:!0},{key:"Mod-End",run:Ie,shift:Fe},{key:"Enter",run:Pe,shift:Pe},{key:"Mod-a",run:Kn},{key:"Backspace",run:me,shift:me,preventDefault:!0},{key:"Delete",run:St,preventDefault:!0},{key:"Mod-Backspace",mac:"Alt-Backspace",run:At,preventDefault:!0},{key:"Mod-Delete",mac:"Alt-Delete",run:er,preventDefault:!0},{mac:"Mod-Backspace",run:nr,preventDefault:!0},{mac:"Mod-Delete",run:rr,preventDefault:!0}].concat(pr.map(e=>({mac:e.key,run:e.run,shift:e.shift}))),yr=[{key:"Alt-ArrowLeft",mac:"Ctrl-ArrowLeft",run:bn,shift:wn},{key:"Alt-ArrowRight",mac:"Ctrl-ArrowRight",run:En,shift:Gn},{key:"Alt-ArrowUp",run:sr},{key:"Shift-Alt-ArrowUp",run:cr},{key:"Alt-ArrowDown",run:ir},{key:"Shift-Alt-ArrowDown",run:ar},{key:"Mod-Alt-ArrowUp",run:Xn},{key:"Mod-Alt-ArrowDown",run:Yn},{key:"Escape",run:Zn},{key:"Mod-Enter",run:fr},{key:"Alt-l",mac:"Ctrl-l",run:Qn},{key:"Mod-i",run:jn,preventDefault:!0},{key:"Mod-[",run:Dt},{key:"Mod-]",run:vt},{key:"Mod-Alt-\\",run:dr},{key:"Shift-Mod-k",run:hr},{key:"Shift-Mod-\\",run:qn},{key:"Mod-/",run:ln},{key:"Alt-A",mac:"Ctrl-A",run:cn},{key:"Ctrl-m",mac:"Shift-Alt-m",run:mr}].concat(gr),xr={key:"Tab",run:vt,shift:Dt},qe=typeof String.prototype.normalize=="function"?e=>e.normalize("NFKD"):e=>e;class P{constructor(t,n,r=0,o=t.length,l,s){this.test=s,this.value={from:0,to:0,precise:!1},this.done=!1,this.matches=[],this.buffer="",this.bufferPos=0,this.iter=t.iterRange(r,o),this.bufferStart=r,this.normalize=l?i=>l(qe(i)):qe,this.query=this.normalize(n)}peek(){if(this.bufferPos==this.buffer.length){if(this.bufferStart+=this.buffer.length,this.iter.next(),this.iter.done)return-1;this.bufferPos=0,this.buffer=this.iter.value}return Ht(this.buffer,this.bufferPos)}next(){for(;this.matches.length;)this.matches.pop();return this.nextOverlapping()}nextOverlapping(){for(;;){let t=this.peek();if(t<0)return this.done=!0,this;let n=_t(t),r=this.bufferStart+this.bufferPos;this.bufferPos+=Jt(t);let o=this.normalize(n);if(o.length)for(let l=0,s=r,i=!0;;l++){let c=o.charCodeAt(l),a=this.match(c,s,i,this.bufferPos+this.bufferStart,l==o.length-1);if(a)return this.value=a,this;if(l==o.length-1)break;i&&l<n.length&&n.charCodeAt(l)==c?s++:i=!1}}}match(t,n,r,o,l){let s=null;for(let i=0;i<this.matches.length;){let c=this.matches[i],a=!1;this.query.charCodeAt(c.index)==t&&(c.index==this.query.length-1?s={from:c.from,to:o,precise:l&&c.precise}:(c.index++,a=!0)),a?i++:this.matches.splice(i,1)}return this.query.charCodeAt(0)==t&&(this.query.length==1?s={from:n,to:o,precise:r&&l}:this.matches.push({from:n,index:1,precise:r})),s&&this.test&&!this.test(s.from,s.to,this.buffer,this.bufferStart)&&(s=null),s}}typeof Symbol<"u"&&(P.prototype[Symbol.iterator]=function(){return this});const Bt={from:-1,to:-1,match:/.*/.exec(""),precise:!0},Ce="gm"+(/x/.unicode==null?"":"u");class bt{constructor(t,n,r,o=0,l=t.length){if(this.text=t,this.to=l,this.curLine="",this.done=!1,this.value=Bt,/\\[sWDnr]|\n|\r|\[\^/.test(n))return new Et(t,n,r,o,l);this.re=new RegExp(n,Ce+(r?.ignoreCase?"i":"")),this.test=r?.test,this.iter=t.iter();let s=t.lineAt(o);this.curLineStart=s.from,this.matchPos=K(t,o),this.getLine(this.curLineStart)}getLine(t){this.iter.next(t),this.iter.lineBreak?this.curLine="":(this.curLine=this.iter.value,this.curLineStart+this.curLine.length>this.to&&(this.curLine=this.curLine.slice(0,this.to-this.curLineStart)),this.iter.next())}nextLine(){this.curLineStart=this.curLineStart+this.curLine.length+1,this.curLineStart>this.to?this.curLine="":this.getLine(0)}next(){for(let t=this.matchPos-this.curLineStart;;){this.re.lastIndex=t;let n=this.matchPos<=this.to&&this.re.exec(this.curLine);if(n){let r=this.curLineStart+n.index,o=r+n[0].length;if(this.matchPos=K(this.text,o+(r==o?1:0)),r==this.curLineStart+this.curLine.length&&this.nextLine(),(r<o||r>this.value.to)&&(!this.test||this.test(r,o,n)))return this.value={from:r,to:o,precise:!0,match:n},this;t=this.matchPos-this.curLineStart}else if(this.curLineStart+this.curLine.length<this.to)this.nextLine(),t=0;else return this.done=!0,this}}}const ie=new WeakMap;class F{constructor(t,n){this.from=t,this.text=n}get to(){return this.from+this.text.length}static get(t,n,r){let o=ie.get(t);if(!o||o.from>=r||o.to<=n){let i=new F(n,t.sliceString(n,r));return ie.set(t,i),i}if(o.from==n&&o.to==r)return o;let{text:l,from:s}=o;return s>n&&(l=t.sliceString(n,s)+l,s=n),o.to<r&&(l+=t.sliceString(o.to,r)),ie.set(t,new F(s,l)),new F(n,l.slice(n-s,r-s))}}class Et{constructor(t,n,r,o,l){this.text=t,this.to=l,this.done=!1,this.value=Bt,this.matchPos=K(t,o),this.re=new RegExp(n,Ce+(r?.ignoreCase?"i":"")),this.test=r?.test,this.flat=F.get(t,o,this.chunkEnd(o+5e3))}chunkEnd(t){return t>=this.to?this.to:this.text.lineAt(t).to}next(){for(;;){let t=this.re.lastIndex=this.matchPos-this.flat.from,n=this.re.exec(this.flat.text);if(n&&!n[0]&&n.index==t&&(this.re.lastIndex=t+1,n=this.re.exec(this.flat.text)),n){let r=this.flat.from+n.index,o=r+n[0].length;if((this.flat.to>=this.to||n.index+n[0].length<=this.flat.text.length-10)&&(!this.test||this.test(r,o,n)))return this.value={from:r,to:o,precise:!0,match:n},this.matchPos=K(this.text,o+(r==o?1:0)),this}if(this.flat.to==this.to)return this.done=!0,this;this.flat=F.get(this.text,this.flat.from,this.chunkEnd(this.flat.from+this.flat.text.length*2))}}}typeof Symbol<"u"&&(bt.prototype[Symbol.iterator]=Et.prototype[Symbol.iterator]=function(){return this});function Sr(e){try{return new RegExp(e,Ce),!0}catch{return!1}}function K(e,t){if(t>=e.length)return t;let n=e.lineAt(t),r;for(;t<n.to&&(r=n.text.charCodeAt(t-n.from))>=56320&&r<57344;)t++;return t}const kr=e=>{let t=wt(e,"cm-goto-line");if(t){let s=t.dom.querySelector("input[type=text]");return s&&s.select(),!0}let{state:n}=e,r=String(n.doc.lineAt(e.state.selection.main.head).number),{close:o,result:l}=Gt(e,{class:"cm-goto-line",label:n.phrase("Go to line"),input:{type:"text",name:"line",value:r},focus:!0,submitLabel:n.phrase("go")});return l.then(s=>{let i=s&&/^([+-])?(\d+)?(:\d+)?(%)?$/.exec(s.elements.line.value);if(!i){e.dispatch({effects:o});return}let c=n.doc.lineAt(n.selection.main.head),[,a,h,u,d]=i,R=u?+u.slice(1):0,C=h?+h:c.number;if(h&&d){let oe=C/100;a&&(oe=oe*(a=="-"?-1:1)+c.number/n.doc.lines),C=Math.round(n.doc.lines*oe)}else h&&a&&(C=C*(a=="-"?-1:1)+c.number);let Be=n.doc.line(Math.max(1,Math.min(n.doc.lines,C))),be=f.cursor(Be.from+Math.max(0,Math.min(R,Be.length)));e.dispatch({effects:[o,m.scrollIntoView(be.from,{y:"center"})],selection:be})}),!0},Ar={highlightWordAroundCursor:!1,minSelectionLength:1,maxMatches:100,wholeWords:!1},Mr=Z.define({combine(e){return ye(e,Ar,{highlightWordAroundCursor:(t,n)=>t||n,minSelectionLength:Math.min,maxMatches:Math.min})}});function Cr(e){return[br,Br]}const Lr=x.mark({class:"cm-selectionMatch"}),vr=x.mark({class:"cm-selectionMatch cm-selectionMatch-main"});function Ne(e,t,n,r){return(n==0||e(t.sliceDoc(n-1,n))!=k.Word)&&(r==t.doc.length||e(t.sliceDoc(r,r+1))!=k.Word)}function Dr(e,t,n,r){return e(t.sliceDoc(n,n+1))==k.Word&&e(t.sliceDoc(r-1,r))==k.Word}const Br=$e.fromClass(class{constructor(e){this.decorations=this.getDeco(e)}update(e){(e.selectionSet||e.docChanged||e.viewportChanged)&&(this.decorations=this.getDeco(e.view))}getDeco(e){let t=e.state.facet(Mr),{state:n}=e,r=n.selection;if(r.ranges.length>1)return x.none;let o=r.main,l,s=null;if(o.empty){if(!t.highlightWordAroundCursor)return x.none;let c=n.wordAt(o.head);if(!c)return x.none;s=n.charCategorizer(o.head),l=n.sliceDoc(c.from,c.to)}else{let c=o.to-o.from;if(c<t.minSelectionLength||c>200)return x.none;if(t.wholeWords){if(l=n.sliceDoc(o.from,o.to),s=n.charCategorizer(o.head),!(Ne(s,n,o.from,o.to)&&Dr(s,n,o.from,o.to)))return x.none}else if(l=n.sliceDoc(o.from,o.to),!l)return x.none}let i=[];for(let c of e.visibleRanges){let a=new P(n.doc,l,c.from,c.to);for(;!a.next().done;){let{from:h,to:u}=a.value;if((!s||Ne(s,n,h,u))&&(o.empty&&h<=o.from&&u>=o.to?i.push(vr.range(h,u)):(h>=o.to||u<=o.from)&&i.push(Lr.range(h,u)),i.length>t.maxMatches))return x.none}}return x.set(i)}},{decorations:e=>e.decorations}),br=m.baseTheme({".cm-selectionMatch":{backgroundColor:"#99ff7780"},".cm-searchMatch .cm-selectionMatch":{backgroundColor:"transparent"}}),Er=({state:e,dispatch:t})=>{let{selection:n}=e,r=f.create(n.ranges.map(o=>e.wordAt(o.head)||f.cursor(o.head)),n.mainIndex);return r.eq(n)?!1:(t(e.update({selection:r})),!0)};function Tr(e,t){let{main:n,ranges:r}=e.selection,o=e.wordAt(n.head),l=o&&o.from==n.from&&o.to==n.to;for(let s=!1,i=new P(e.doc,t,r[r.length-1].to);;)if(i.next(),i.done){if(s)return null;i=new P(e.doc,t,0,Math.max(0,r[r.length-1].from-1)),s=!0}else{if(s&&r.some(c=>c.from==i.value.from))continue;if(l){let c=e.wordAt(i.value.from);if(!c||c.from!=i.value.from||c.to!=i.value.to)continue}return i.value}}const Rr=({state:e,dispatch:t})=>{let{ranges:n}=e.selection;if(n.some(l=>l.from===l.to))return Er({state:e,dispatch:t});let r=e.sliceDoc(n[0].from,n[0].to);if(e.selection.ranges.some(l=>e.sliceDoc(l.from,l.to)!=r))return!1;let o=Tr(e,r);return o?(t(e.update({selection:e.selection.addRange(f.range(o.from,o.to),!1),effects:m.scrollIntoView(o.to)})),!0):!1},T=Z.define({combine(e){return ye(e,{top:!1,caseSensitive:!1,literal:!1,regexp:!1,wholeWord:!1,createPanel:t=>new $r(t),scrollToMatch:t=>m.scrollIntoView(t)})}});function Or(e){return e?[T.of(e),ge]:ge}class Tt{constructor(t){this.search=t.search,this.caseSensitive=!!t.caseSensitive,this.literal=!!t.literal,this.regexp=!!t.regexp,this.replace=t.replace||"",this.valid=!!this.search&&(!this.regexp||Sr(this.search)),this.unquoted=this.unquote(this.search),this.wholeWord=!!t.wholeWord,this.test=t.test}unquote(t){return this.literal?t:t.replace(/\\([nrt\\])/g,(n,r)=>r=="n"?`
2
2
  `:r=="r"?"\r":r=="t"?" ":"\\")}eq(t){return this.search==t.search&&this.replace==t.replace&&this.caseSensitive==t.caseSensitive&&this.regexp==t.regexp&&this.wholeWord==t.wholeWord&&this.test==t.test}create(){return this.regexp?new Nr(this):new Fr(this)}getCursor(t,n=0,r){let o=t.doc?t:_e.create({doc:t});return r==null&&(r=o.doc.length),this.regexp?I(this,o,n,r):O(this,o,n,r)}}class Rt{constructor(t){this.spec=t}}function Ir(e,t,n){return(r,o,l,s)=>{if(n&&!n(r,o,l,s))return!1;let i=r>=s&&o<=s+l.length?l.slice(r-s,o-s):t.doc.sliceString(r,o);return e(i,t,r,o)}}function O(e,t,n,r){let o;return e.wholeWord&&(o=Wr(t.doc,t.charCategorizer(t.selection.main.head))),e.test&&(o=Ir(e.test,t,o)),new P(t.doc,e.unquoted,n,r,e.caseSensitive?void 0:l=>l.toLowerCase(),o)}function Wr(e,t){return(n,r,o,l)=>((l>n||l+o.length<r)&&(l=Math.max(0,n-2),o=e.sliceString(l,Math.min(e.length,r+2))),(t(Q(o,n-l))!=k.Word||t(j(o,n-l))!=k.Word)&&(t(j(o,r-l))!=k.Word||t(Q(o,r-l))!=k.Word))}class Fr extends Rt{constructor(t){super(t)}nextMatch(t,n,r){let o=O(this.spec,t,r,t.doc.length).nextOverlapping();if(o.done){let l=Math.min(t.doc.length,n+this.spec.unquoted.length);o=O(this.spec,t,0,l).nextOverlapping()}return o.done||o.value.from==n&&o.value.to==r?null:o.value}prevMatchInRange(t,n,r){for(let o=r;;){let l=Math.max(n,o-1e4-this.spec.unquoted.length),s=O(this.spec,t,l,o),i=null;for(;!s.nextOverlapping().done;)i=s.value;if(i)return i;if(l==n)return null;o-=1e4}}prevMatch(t,n,r){let o=this.prevMatchInRange(t,0,n);return o||(o=this.prevMatchInRange(t,Math.max(0,r-this.spec.unquoted.length),t.doc.length)),o&&(o.from!=n||o.to!=r)?o:null}getReplacement(t){return this.spec.unquote(this.spec.replace)}matchAll(t,n){let r=O(this.spec,t,0,t.doc.length),o=[];for(;!r.next().done;){if(o.length>=n)return null;o.push(r.value)}return o}highlight(t,n,r,o){let l=O(this.spec,t,Math.max(0,n-this.spec.unquoted.length),Math.min(r+this.spec.unquoted.length,t.doc.length));for(;!l.next().done;)o(l.value.from,l.value.to)}}function Pr(e,t,n){return(r,o,l)=>(!n||n(r,o,l))&&e(l[0],t,r,o)}function I(e,t,n,r){let o;return e.wholeWord&&(o=qr(t.charCategorizer(t.selection.main.head))),e.test&&(o=Pr(e.test,t,o)),new bt(t.doc,e.search,{ignoreCase:!e.caseSensitive,test:o},n,r)}function Q(e,t){return e.slice(E(e,t,!1),t)}function j(e,t){return e.slice(t,E(e,t))}function qr(e){return(t,n,r)=>!r[0].length||(e(Q(r.input,r.index))!=k.Word||e(j(r.input,r.index))!=k.Word)&&(e(j(r.input,r.index+r[0].length))!=k.Word||e(Q(r.input,r.index+r[0].length))!=k.Word)}class Nr extends Rt{nextMatch(t,n,r){let o=I(this.spec,t,r,t.doc.length).next();return o.done&&(o=I(this.spec,t,0,n).next()),o.done?null:o.value}prevMatchInRange(t,n,r){for(let o=1;;o++){let l=Math.max(n,r-o*1e4),s=I(this.spec,t,l,r),i=null;for(;!s.next().done;)i=s.value;if(i&&(l==n||i.from>l+10))return i;if(l==n)return null}}prevMatch(t,n,r){return this.prevMatchInRange(t,0,n)||this.prevMatchInRange(t,r,t.doc.length)}getReplacement(t){return this.spec.unquote(this.spec.replace).replace(/\$([$&]|\d+)/g,(n,r)=>{if(r=="&")return t.match[0];if(r=="$")return"$";for(let o=r.length;o>0;o--){let l=+r.slice(0,o);if(l>0&&l<t.match.length)return t.match[l]+r.slice(o)}return n})}matchAll(t,n){let r=I(this.spec,t,0,t.doc.length),o=[];for(;!r.next().done;){if(o.length>=n)return null;o.push(r.value)}return o}highlight(t,n,r,o){let l=I(this.spec,t,Math.max(0,n-250),Math.min(r+250,t.doc.length));for(;!l.next().done;)o(l.value.from,l.value.to)}}const V=w.define(),Le=w.define(),B=we.define({create(e){return new ce(pe(e).create(),null)},update(e,t){for(let n of t.effects)n.is(V)?e=new ce(n.value.create(),e.panel):n.is(Le)&&(e=new ce(e.query,n.value?ve:null));return e},provide:e=>zt.from(e,t=>t.panel)});class ce{constructor(t,n){this.query=t,this.panel=n}}const Vr=x.mark({class:"cm-searchMatch"}),wr=x.mark({class:"cm-searchMatch cm-searchMatch-selected"}),Gr=$e.fromClass(class{constructor(e){this.view=e,this.decorations=this.highlight(e.state.field(B))}update(e){let t=e.state.field(B);(t!=e.startState.field(B)||e.docChanged||e.selectionSet||e.viewportChanged)&&(this.decorations=this.highlight(t))}highlight({query:e,panel:t}){if(!t||!e.spec.valid)return x.none;let{view:n}=this,r=new $t;for(let o=0,l=n.visibleRanges,s=l.length;o<s;o++){let{from:i,to:c}=l[o];for(;o<s-1&&c>l[o+1].from-500;)c=l[++o].to;e.highlight(n.state,i,c,(a,h)=>{let u=n.state.selection.ranges.some(d=>d.from==a&&d.to==h);r.add(a,h,u?wr:Vr)})}return r.finish()}},{decorations:e=>e.decorations});function U(e){return t=>{let n=t.state.field(B,!1);return n&&n.query.spec.valid?e(t,n):Wt(t)}}const X=U((e,{query:t})=>{let{to:n}=e.state.selection.main,r=t.nextMatch(e.state,n,n);if(!r)return!1;let o=f.single(r.from,r.to),l=e.state.facet(T);return e.dispatch({selection:o,effects:[De(e,r),l.scrollToMatch(o.main,e)],userEvent:"select.search"}),It(e),!0}),Y=U((e,{query:t})=>{let{state:n}=e,{from:r}=n.selection.main,o=t.prevMatch(n,r,r);if(!o)return!1;let l=f.single(o.from,o.to),s=e.state.facet(T);return e.dispatch({selection:l,effects:[De(e,o),s.scrollToMatch(l.main,e)],userEvent:"select.search"}),It(e),!0}),Ur=U((e,{query:t})=>{let n=t.matchAll(e.state,1e3);return!n||!n.length?!1:(e.dispatch({selection:f.create(n.map(r=>f.range(r.from,r.to))),userEvent:"select.search.matches"}),!0)}),zr=({state:e,dispatch:t})=>{let n=e.selection;if(n.ranges.length>1||n.main.empty)return!1;let{from:r,to:o}=n.main,l=[],s=0;for(let i=new P(e.doc,e.sliceDoc(r,o));!i.next().done;){if(l.length>1e3)return!1;i.value.from==r&&(s=l.length),l.push(f.range(i.value.from,i.value.to))}return t(e.update({selection:f.create(l,s),userEvent:"select.search.matches"})),!0},Ve=U((e,{query:t})=>{let{state:n}=e,{from:r,to:o}=n.selection.main;if(n.readOnly)return!1;let l=t.nextMatch(n,r,r);if(!l)return!1;let s=l,i=[],c,a,h=[];s.precise?s.from==r&&s.to==o&&(a=n.toText(t.getReplacement(s)),i.push({from:s.from,to:s.to,insert:a}),s=t.nextMatch(n,s.from,s.to),h.push(m.announce.of(n.phrase("replaced match on line $",n.doc.lineAt(r).number)+"."))):s=t.nextMatch(n,s.from,s.to);let u=e.state.changes(i);return s&&(c=f.single(s.from,s.to).map(u),h.push(De(e,s)),h.push(n.facet(T).scrollToMatch(c.main,e))),e.dispatch({changes:u,selection:c,effects:h,userEvent:"input.replace"}),!0}),Hr=U((e,{query:t})=>{if(e.state.readOnly)return!1;let n=[];for(let o of t.matchAll(e.state,1e9)){let{from:l,to:s,precise:i}=o;i&&n.push({from:l,to:s,insert:t.getReplacement(o)})}if(!n.length)return!1;let r=e.state.phrase("replaced $ matches",n.length)+".";return e.dispatch({changes:n,effects:m.announce.of(r),userEvent:"input.replace.all"}),!0});function ve(e){return e.state.facet(T).createPanel(e)}function pe(e,t){var n,r,o,l,s;let i=e.selection.main,c=i.empty||i.to>i.from+100?"":e.sliceDoc(i.from,i.to);if(t&&!c)return t;let a=e.facet(T);return new Tt({search:((n=t?.literal)!==null&&n!==void 0?n:a.literal)?c:c.replace(/\n/g,"\\n"),caseSensitive:(r=t?.caseSensitive)!==null&&r!==void 0?r:a.caseSensitive,literal:(o=t?.literal)!==null&&o!==void 0?o:a.literal,regexp:(l=t?.regexp)!==null&&l!==void 0?l:a.regexp,wholeWord:(s=t?.wholeWord)!==null&&s!==void 0?s:a.wholeWord})}function Ot(e){let t=Je(e,ve);return t&&t.dom.querySelector("[main-field]")}function It(e){let t=Ot(e);t&&t==e.root.activeElement&&t.select()}const Wt=e=>{let t=e.state.field(B,!1);if(t&&t.panel){let n=Ot(e);if(n&&n!=e.root.activeElement){let r=pe(e.state,t.query.spec);r.valid&&e.dispatch({effects:V.of(r)}),n.focus(),n.select()}}else e.dispatch({effects:[Le.of(!0),t?V.of(pe(e.state,t.query.spec)):w.appendConfig.of(ge)]});return!0},Ft=e=>{let t=e.state.field(B,!1);if(!t||!t.panel)return!1;let n=Je(e,ve);return n&&n.dom.contains(e.root.activeElement)&&e.focus(),e.dispatch({effects:Le.of(!1)}),!0},Jr=[{key:"Mod-f",run:Wt,scope:"editor search-panel"},{key:"F3",run:X,shift:Y,scope:"editor search-panel",preventDefault:!0},{key:"Mod-g",run:X,shift:Y,scope:"editor search-panel",preventDefault:!0},{key:"Escape",run:Ft,scope:"editor search-panel"},{key:"Mod-Shift-l",run:zr},{key:"Mod-Alt-g",run:kr},{key:"Mod-d",run:Rr,preventDefault:!0}];class $r{constructor(t){this.view=t;let n=this.query=t.state.field(B).query.spec;this.commit=this.commit.bind(this),this.searchField=S("input",{value:n.search,placeholder:y(t,"Find"),"aria-label":y(t,"Find"),class:"cm-textfield",name:"search",form:"","main-field":"true",onchange:this.commit,onkeyup:this.commit}),this.replaceField=S("input",{value:n.replace,placeholder:y(t,"Replace"),"aria-label":y(t,"Replace"),class:"cm-textfield",name:"replace",form:"",onchange:this.commit,onkeyup:this.commit}),this.caseField=S("input",{type:"checkbox",name:"case",form:"",checked:n.caseSensitive,onchange:this.commit}),this.reField=S("input",{type:"checkbox",name:"re",form:"",checked:n.regexp,onchange:this.commit}),this.wordField=S("input",{type:"checkbox",name:"word",form:"",checked:n.wholeWord,onchange:this.commit});function r(o,l,s){return S("button",{class:"cm-button",name:o,onclick:l,type:"button"},s)}this.dom=S("div",{onkeydown:o=>this.keydown(o),class:"cm-search"},[this.searchField,r("next",()=>X(t),[y(t,"next")]),r("prev",()=>Y(t),[y(t,"previous")]),r("select",()=>Ur(t),[y(t,"all")]),S("label",null,[this.caseField,y(t,"match case")]),S("label",null,[this.reField,y(t,"regexp")]),S("label",null,[this.wordField,y(t,"by word")]),...t.state.readOnly?[]:[S("br"),this.replaceField,r("replace",()=>Ve(t),[y(t,"replace")]),r("replaceAll",()=>Hr(t),[y(t,"replace all")])],S("button",{name:"close",onclick:()=>Ft(t),"aria-label":y(t,"close"),type:"button"},["×"])])}commit(){let t=new Tt({search:this.searchField.value,caseSensitive:this.caseField.checked,regexp:this.reField.checked,wholeWord:this.wordField.checked,replace:this.replaceField.value});t.eq(this.query)||(this.query=t,this.view.dispatch({effects:V.of(t)}))}keydown(t){Kt(this.view,t,"search-panel")?t.preventDefault():t.keyCode==13&&t.target==this.searchField?(t.preventDefault(),(t.shiftKey?Y:X)(this.view)):t.keyCode==13&&t.target==this.replaceField&&(t.preventDefault(),Ve(this.view))}update(t){for(let n of t.transactions)for(let r of n.effects)r.is(V)&&!r.value.eq(this.query)&&this.setQuery(r.value)}setQuery(t){this.query=t,this.searchField.value=t.search,this.replaceField.value=t.replace,this.caseField.checked=t.caseSensitive,this.reField.checked=t.regexp,this.wordField.checked=t.wholeWord}mount(){this.searchField.select()}get pos(){return 80}get top(){return this.view.state.facet(T).top}}function y(e,t){return e.state.phrase(t)}const H=30,J=/[\s\.,:;?!]/;function De(e,{from:t,to:n}){let r=e.state.doc.lineAt(t),o=e.state.doc.lineAt(n).to,l=Math.max(r.from,t-H),s=Math.min(o,n+H),i=e.state.sliceDoc(l,s);if(l!=r.from){for(let c=0;c<H;c++)if(!J.test(i[c+1])&&J.test(i[c])){i=i.slice(c);break}}if(s!=o){for(let c=i.length-1;c>i.length-H;c--)if(!J.test(i[c-1])&&J.test(i[c])){i=i.slice(0,c);break}}return m.announce.of(`${e.state.phrase("current match")}. ${i} ${e.state.phrase("on line")} ${r.number}.`)}const _r=m.baseTheme({".cm-panel.cm-search":{padding:"2px 6px 4px",position:"relative","& [name=close]":{position:"absolute",top:"0",right:"4px",backgroundColor:"inherit",border:"none",font:"inherit",padding:0,margin:0},"& input, & button, & label":{margin:".2em .6em .2em 0"},"& input[type=checkbox]":{marginRight:".2em"},"& label":{fontSize:"80%",whiteSpace:"pre"}},"&light .cm-searchMatch":{backgroundColor:"#ffff0054"},"&dark .cm-searchMatch":{backgroundColor:"#00ffff8a"},"&light .cm-searchMatch-selected":{backgroundColor:"#ff6a0054"},"&dark .cm-searchMatch-selected":{backgroundColor:"#ff00ff8a"}}),ge=[B,Ut.low(Gr),_r],Kr=m.theme({"&":{height:"100%",color:"var(--butter)",backgroundColor:"transparent",fontSize:"0.95rem"},".cm-scroller":{fontFamily:"'Share Tech Mono', monospace",lineHeight:"1.45"},".cm-content":{caretColor:"var(--harvestgold)"},".cm-cursor, .cm-dropCursor":{borderLeftColor:"var(--harvestgold)",borderLeftWidth:"2px"},"&.cm-focused .cm-selectionBackground, .cm-selectionBackground, ::selection":{backgroundColor:"color-mix(in srgb, var(--orange) 35%, transparent)"},".cm-gutters":{backgroundColor:"transparent",color:"var(--pumpkin-pie)",border:"none"},".cm-activeLine":{backgroundColor:"color-mix(in srgb, var(--orange) 8%, transparent)"},".cm-activeLineGutter":{backgroundColor:"transparent",color:"var(--harvestgold)"},".cm-matchingBracket":{outline:"1px solid var(--harvestgold)",backgroundColor:"transparent"},".cm-searchMatch":{backgroundColor:"color-mix(in srgb, var(--daybreak) 30%, transparent)"},".cm-panels":{backgroundColor:"#000",color:"var(--butter)"},".cm-panels.cm-panels-bottom":{borderTop:"2px solid var(--orange)"}},{dark:!0});async function Xr(e,t,n,r){const o=await Qt(n),l=new m({parent:e,state:_e.create({doc:t,extensions:[jt(),Xt(),pn(),Yt(),Zt(),en(),tn(),Cr(),Or({top:!1}),nn(on),o,Kr,m.lineWrapping,rn.of([...yr,...Ln,...Jr,xr]),m.updateListener.of(s=>{s.docChanged&&r(s.state.doc.toString())})]})});return{text_get:()=>l.state.doc.toString(),text_set:s=>{l.dispatch({changes:{from:0,to:l.state.doc.length,insert:s}})},focus:()=>l.focus(),hasFocus:()=>l.contentDOM.contains(document.activeElement),blur:()=>l.contentDOM.blur(),destroy:()=>l.destroy()}}export{Xr as editField_create};
@@ -1 +1 @@
1
- import{t as T,E as R,e as M,B as We,v as Ae,a as ne,b as F,s as ke,c as Fe,f as oe,cw as ue,c8 as Ne,bW as P,aK as z,cx as fe,aJ as Y,ag as se,V as G,cy as ge,cz as D,cA as Ue,cB as Ge,cC as Be,bL as He,at as O,aO as ze,bi as B,cD as me,bN as je,cE as he,bt as $e,b_ as qe,cF as ie,cG as E,cH as H,cI as J,cJ as L,cK as re,cL as Je,cM as Ke,cN as Ze,bC as pe,am as Q,b8 as ee,cO as Xe,cP as Ye,ai as Qe,ar as we,bm as te,i as Ie,L as Ve,bK as Se,cQ as be,bA as Z,bG as et,bc as ve,bz as N,cR as ae,cS as Ee,bP as ye,cT as tt,cr as nt,K as ot,cU as st,cV as it,c1 as rt,cW as at,cX as ct,bf as lt,cY as dt,cZ as ut,c_ as ft,c$ as gt,bp as mt,d0 as ht,d1 as pt,d2 as wt,d3 as It,d4 as Vt,d5 as St,d6 as bt,d7 as vt,bg as Et,d8 as yt,av as Rt,d9 as Ct,da as Pt,H as Tt,b7 as xt,bk as Mt,db as Dt,dc as Ot,J as _t,dd as Lt,bo as Wt,de as At,df as kt,bq as Ft,dg as Nt,bs as Ut,dh as Gt,bR as Bt,di as Ht,dj as zt,bF as jt,bj as $t,dk as qt,bh as Jt,bn as Kt,dl as Zt,dm as Xt,dn as Yt,dp as Qt,dq as en,dr as tn,ds as nn,dt as on,bl as sn,bZ as rn,du as an,bT as cn,dv as ln,bS as dn,bv as un,br as fn,ct as gn,dw as mn,dx as hn,bI as pn,dy as wn,M as In,dz as Vn,dA as Sn,bw as bn,dB as vn,bD as En,bJ as yn,dC as Rn,dD as Cn,bM as Pn,dE as Tn,dF as xn,dG as Mn,bY as Dn}from"./Settings-2RQVwvnQ.js";import"./Texture-BTXL_xdB.js";import"./cornerstoneEngine-BleRTwP7.js";function On(e){return!!(e&&typeof e.setVolumes=="function"&&typeof e.addVolumes=="function")}async function _n(e,t,n,o=!1,i=!1){const s=n.map(r=>{const a=e.getViewport(r);if(!a)throw new Error(`Viewport with Id ${r} does not exist`);if(!On(a))throw new Error("setVolumesForViewports only supports viewports that implement setVolumes");return a});await Promise.all(s.map(r=>r.setVolumes(t,o,i)))}function Ln(e,t,n=0){const o=e.getOpenGLRenderWindow?.()?.getCanvas?.();o&&(o.addEventListener("webglcontextlost",()=>{console.warn(`CornerstoneRender: WebGL context lost (renderingEngine=${t}, context=${n})`),T(M,R.WEBGL_CONTEXT_LOST,{renderingEngineId:t,contextIndex:n})}),o.addEventListener("webglcontextrestored",()=>{T(M,R.WEBGL_CONTEXT_RESTORED,{renderingEngineId:t,contextIndex:n})}))}class Wn extends We{constructor(t){super(t),this._renderFlaggedViewports=()=>{this._throwIfDestroyed(),this.offscreenMultiRenderWindow&&this.performVtkDrawCall();const n=this._getViewportsAsArray(),o=[];for(let i=0;i<n.length;i++){const s=n[i];if(this._needsRender.has(s.id)){const r=this.renderViewportUsingCustomOrVtkPipeline(s);if(o.push(r),s.setRendered(),this._needsRender.delete(s.id),this._needsRender.size===0)break}}this._animationFrameSet=!1,this._animationFrameHandle=null,o.forEach(i=>{i?.element&&T(i.element,R.IMAGE_RENDERED,i)})},this.useCPURendering||this.ensureOffscreenResources()}ensureOffscreenResources(){this.offscreenMultiRenderWindow||(this.offscreenMultiRenderWindow=Ae.newInstance(),this.offScreenCanvasContainer=document.createElement("div"),this.offscreenMultiRenderWindow.setContainer(this.offScreenCanvasContainer),Ln(this.offscreenMultiRenderWindow,this.id))}enableVTKjsDrivenViewport(t){this.ensureOffscreenResources();const o=this._getViewportsAsArray().filter(l=>ne(l.type)===!1),i=o.map(l=>l.canvas),s=F(t.element);i.push(s);const{offScreenCanvasWidth:r,offScreenCanvasHeight:a}=this._resizeOffScreenCanvas(i),c=this._resize(o,r,a),d={...t,canvas:s};this.addVtkjsDrivenViewport(d,{offScreenCanvasWidth:r,offScreenCanvasHeight:a,xOffset:c})}addVtkjsDrivenViewport(t,n){this.ensureOffscreenResources();const{element:o,canvas:i,viewportId:s,type:r,defaultOptions:a}=t;o.tabIndex=-1,ke(o);const{offScreenCanvasWidth:c,offScreenCanvasHeight:d,xOffset:l}=n,{sxStartDisplayCoords:u,syStartDisplayCoords:f,sxEndDisplayCoords:m,syEndDisplayCoords:w,sx:V,sy:h,sWidth:g,sHeight:b}=this._getViewportCoordsOnOffScreenCanvas(t,c,d,l);this.offscreenMultiRenderWindow.addRenderer({viewport:[u,f,m,w],id:s,background:a.background?a.background:[0,0,0]});const S={id:s,element:o,renderingEngineId:this.id,type:r,canvas:i,sx:V,sy:h,sWidth:g,sHeight:b,defaultOptions:a||{}},v=Fe(t);if(!v)throw new Error(`Viewport Type ${r} is not supported`);const p=new v(S);p.requestedType=t.requestedType??r,this._viewports.set(s,p);const y={element:o,viewportId:s,renderingEngineId:this.id};p.suppressEvents||T(M,R.ELEMENT_ENABLED,y)}setVtkjsDrivenViewports(t){if(t.length){const n=t.map(r=>F(r.element));n.forEach(r=>{const a=window.devicePixelRatio||1,c=r.getBoundingClientRect();r.width=c.width*a,r.height=c.height*a});const{offScreenCanvasWidth:o,offScreenCanvasHeight:i}=this._resizeOffScreenCanvas(n);let s=0;for(let r=0;r<t.length;r++){const a=t[r],c=n[r],d={...a,canvas:c};this.addVtkjsDrivenViewport(d,{offScreenCanvasWidth:o,offScreenCanvasHeight:i,xOffset:s}),s+=c.width}}}_resizeVTKViewports(t,n=!0,o=!0){const i=t.map(s=>F(s.element));if(i.forEach(s=>{const r=window.devicePixelRatio||1;s.width=s.clientWidth*r,s.height=s.clientHeight*r}),i.length){const{offScreenCanvasWidth:s,offScreenCanvasHeight:r}=this._resizeOffScreenCanvas(i);this._resize(t,s,r)}t.forEach(s=>{const r=s.getCamera(),a=s.getRotation(),{flipHorizontal:c}=r,d=s;d.resetViewStateForResize?d.resetViewStateForResize():d.resetCameraForResize();const l=s.getDisplayArea();n&&(l?(c&&s.setCamera({flipHorizontal:c}),a&&s.setViewPresentation({rotation:a})):s.setCamera(r))}),o&&this.render()}performVtkDrawCall(){const{offscreenMultiRenderWindow:t}=this,n=t.getRenderWindow(),o=t.getRenderers();if(o.length){for(let i=0;i<o.length;i++){const{renderer:s,id:r}=o[i],a=r.split("::")[0];this._needsRender.has(a)?s.setDraw(!0):s.setDraw(!1)}n.render();for(let i=0;i<o.length;i++)o[i].renderer.setDraw(!1)}}renderViewportUsingCustomOrVtkPipeline(t){let n;if(t.sWidth<oe||t.sHeight<oe){console.warn("Viewport is too small",t.sWidth,t.sHeight);return}if(ne(t.type)===!0)n=t.customRenderViewportToCanvas();else{if(!this.offscreenMultiRenderWindow)throw new Error("GPU not available, and using a viewport with no custom render pipeline.");const{offscreenMultiRenderWindow:o}=this,r=o.getOpenGLRenderWindow().get3DContext().canvas;n=this._renderViewportFromVtkCanvasToOnscreenCanvas(t,r)}return n}_renderViewportFromVtkCanvasToOnscreenCanvas(t,n){const{element:o,canvas:i,sx:s,sy:r,sWidth:a,sHeight:c,id:d,renderingEngineId:l,suppressEvents:u}=t,{width:f,height:m}=i;return i.getContext("2d").drawImage(n,s,r,a,c,0,0,f,m),{element:o,suppressEvents:u,viewportId:d,renderingEngineId:l,viewportStatus:t.viewportStatus}}_resizeOffScreenCanvas(t){const{offScreenCanvasContainer:n,offscreenMultiRenderWindow:o}=this,i=Math.max(...t.map(r=>r.height));let s=0;return t.forEach(r=>{s+=r.width}),n.width=s,n.height=i,o.resize(),{offScreenCanvasWidth:s,offScreenCanvasHeight:i}}_resize(t,n,o){let i=0;for(let s=0;s<t.length;s++){const r=t[s],{sxStartDisplayCoords:a,syStartDisplayCoords:c,sxEndDisplayCoords:d,syEndDisplayCoords:l,sx:u,sy:f,sWidth:m,sHeight:w}=this._getViewportCoordsOnOffScreenCanvas(r,n,o,i);i+=r.canvas.width,r.sx=u,r.sy=f,r.sWidth=m,r.sHeight=w,this.offscreenMultiRenderWindow.getRenderer(r.id).setViewport(a,c,d,l)}return i}_getViewportCoordsOnOffScreenCanvas(t,n,o,i){const{canvas:s}=t,{width:r,height:a}=s,c=i,d=0,l=c/n,u=d+(o-a)/o,f=r/n,m=a/o;return{sxStartDisplayCoords:l,syStartDisplayCoords:u,sxEndDisplayCoords:l+f,syEndDisplayCoords:u+m,sx:c,sy:d,sWidth:r,sHeight:a}}}function No(e){return!!(e&&typeof e.canvasToWorld=="function"&&typeof e.worldToCanvas=="function")}function Uo(e){return!!(e&&typeof e.getZoom=="function"&&typeof e.setZoom=="function")}function Go(e){return!!(e&&typeof e.getPan=="function"&&typeof e.setPan=="function")}function An(e){return!!(e&&typeof e.getFrameOfReferenceUID=="function")}class kn{constructor(){this._targetsEventListeners=new Map}addEventListener(t,n,o,i){let s=this._targetsEventListeners.get(t);s||(s=new ue(t),this._targetsEventListeners.set(t,s)),s.addEventListener(n,o,i)}removeEventListener(t,n,o,i){const s=this._targetsEventListeners.get(t);s&&(s.removeEventListener(n,o,i),s.isEmpty&&this._targetsEventListeners.delete(t))}reset(){Array.from(this._targetsEventListeners.entries()).forEach(([t,n])=>{n.reset(),this._targetsEventListeners.delete(t)})}}const Fn=Object.freeze(Object.defineProperty({__proto__:null,MultiTargetEventListenerManager:kn,TargetEventListeners:ue},Symbol.toStringTag,{value:"Module"}));function Nn(e,t){const n=e.getSize();for(let o=0;o<n;o++){const i=[];e.getNodeValue(o,i),i[1]=i[1]*t,i[2]=i[2]*t,i[3]=i[3]*t,e.setNodeValue(o,i)}}const Un=Symbol("LastRuntimeId"),Gn={},Bn=4294967295,Hn="-";function zn(e,t,n){return jn(e!==null&&typeof e=="object"?e:Gn,Un,(typeof n=="number"&&n>0?n:Bn)>>>0).join(typeof t=="string"?t:Hn)}function jn(e,t,n){let o=e[t];o instanceof Array||(o=[0],Object.defineProperty(e,t,{value:o}));for(let i=!0,s=0;i&&s<o.length;++s){let r=o[s]|0;r<n?(i=!1,r=r+1):(r=0,s+1===o.length&&o.push(0)),o[s]=r}return o}const $n=Ne;function qn(e,t,n=1e-5){return Math.abs(e[0]+t[0])<n&&Math.abs(e[1]+t[1])<n&&Math.abs(e[2]+t[2])<n}function Jn(e,t){return!(e[0]<0||e[0]>=t[0]||e[1]<0||e[1]>=t[1]||e[2]<0||e[2]>=t[2])}function Kn(e,t){return!(e[0]<-P||e[0]>=t[0]+P||e[1]<-P||e[1]>=t[1]+P||e[2]<-P||e[2]>=t[2]+P)}function Zn(e,t){let n;t?n=[Y(t)]:n=z();const o=[];return n.forEach(i=>{const s=e.getActors(),r=i.getViewports().filter(fe);for(const a of r){const c=a.getActors();if(c.length!==s.length)continue;s.every(({uid:l})=>c.find(u=>l===u.uid))&&o.push(a)}}),o}function Re(e,t,n=void 0,o="_thumbnails",i={displayArea:{imageArea:[1,1]}}){if(!e||!(e instanceof HTMLCanvasElement))throw new Error("canvas element is required");const s=!t.imageId,r=!s&&t,a=s&&t,d=`renderGPUViewport-${r.imageId||a.volumeId}`,l=document.createElement("div"),u=window.devicePixelRatio||1;i.displayArea||(i.displayArea={imageArea:[1,1]});const f=e.width,m=e.height;l.style.width=`${f/u+se}px`,l.style.height=`${m/u+se}px`,l.style.visibility="hidden",l.style.position="absolute",document.body.appendChild(l);const w=d.split(":").join("-");l.setAttribute("viewport-id-for-remove",w);const V=F(l),h=Y(o)||new Wn(o);let g=h.getViewport(d);if(!g){const b={viewportId:d,type:s?G.ORTHOGRAPHIC:G.STACK,element:l,defaultOptions:{...i,suppressEvents:!0}};h.enableElement(b),g=h.getViewport(d)}return new Promise(b=>{let S=!1,{viewReference:v}=i;const p=y=>{if(S)return;if(v){const A=v;v=null,g.setViewReference(A),g.render();return}e.getContext("2d").drawImage(V,0,0,V.width,V.height,0,0,e.width,e.height);const I=g.canvasToWorld([0,0]),C=g.canvasToWorld([V.width/u,0]),$=g.canvasToWorld([0,V.height/u]),_=D([0,0,0],g.canvasToWorld([1/u,0]),I),W=D([0,0,0],g.canvasToWorld([0,1/u]),I),q=1;S=!0,l.removeEventListener(R.IMAGE_RENDERED,p),setTimeout(()=>{h.disableElement(d),document.querySelectorAll(`[viewport-id-for-remove="${w}"]`).forEach(Le=>{Le.remove()})},0),b({origin:I,bottomLeft:$,topRight:C,thicknessMm:q,rightVector:_,downVector:W})};l.addEventListener(R.IMAGE_RENDERED,p),s?g.setVolumes([a],!1,!0):g.renderImageObject(t),g.resetCamera(),n==="PT"&&!ge(r)&&g.setProperties({voiRange:{lower:r.minPixelValue,upper:r.maxPixelValue}}),g.render()})}function Ce(e,t,n,o,i){if(t.volumeId)throw new Error("Unsupported volume rendering for CPU");const r=t,a=Ue(e,r,n),c={canvas:e,viewport:a,image:r,renderingTools:{}};c.transform=Ge(c);const d=!0;return new Promise((l,u)=>{Be(c,d),l(null)})}function Xn(e){const{canvas:t,imageId:n,viewReference:o,requestType:i=He.Thumbnail,priority:s=-5,renderingEngineId:r="_thumbnails",useCPURendering:a=!1,thumbnail:c=!1,imageAspect:d=!1,viewportOptions:l}=e,u=o?.volumeId,f=u&&!n,m=o&&l?{...l,viewReference:o}:l,w=a?Ce:Re;return new Promise((V,h)=>{function g(p,y){const{modality:x}=B(me.GENERAL_SERIES,y)||{},I=!f&&p,C=f&&p;I&&(I.isPreScaled=I.isPreScaled||I.preScale?.scaled),c&&(t.height=256,t.width=256),d&&I&&(t.width=I&&t.height*I.width/I.height),t.style.width=`${t.width/devicePixelRatio}px`,t.style.height=`${t.height/devicePixelRatio}px`,C&&a&&h(new Error("CPU rendering of volume not supported")),w(t,p,x,r,m).then(V)}function b(p,y){console.error(p,y),h(p)}function S(p,y,x){return je(p,x).then(I=>{g.call(this,I,p)},I=>{b.call(this,I,p)})}const v={useRGBA:!!a,requestType:i};if(u){const p=O.getVolume(u);p||h(new Error(`Volume id ${u} not found in cache`));const y=p.imageIds[0];g(p,y)}else ze.addRequest(S.bind(null,n,null,v),i,{imageId:n},s)})}function Yn(e){const t=z(),n=[];return t.forEach(o=>{o.getViewports().filter(he).forEach(s=>{s.hasImageURI(e)&&n.push(s)})}),n}function Qn(e,t){const n=eo(e,t);return n?n.index:null}function eo(e,t){const n=t.getImageIds(),o=t.getCurrentImageIdIndex();if(n.length===0)return null;const i=c=>{const d=to(c);if(!d)return null;const l=$e(d.planeNormal,d.imagePositionPatient);return qe(l,e)},s={distance:i(n[o])??1/0,index:o},r=n.slice(o+1);for(let c=0;c<r.length;c++){const d=r[c],l=i(d);if(l!==null)if(l<=s.distance)s.distance=l,s.index=c+o+1;else break}const a=n.slice(0,o);for(let c=a.length-1;c>=0;c--){const d=a[c],l=i(d);if(!(l===null||l===s.distance))if(l<s.distance)s.distance=l,s.index=c;else break}return s.distance===1/0?null:s}function to(e){const t=B(me.IMAGE_PLANE,e);if(!t||!(t.rowCosines instanceof Array&&t.rowCosines.length===3)||!(t.columnCosines instanceof Array&&t.columnCosines.length===3)||!(t.imagePositionPatient instanceof Array&&t.imagePositionPatient.length===3))return null;const{rowCosines:n,columnCosines:o,imagePositionPatient:i}=t,s=ie(E(),...n),r=ie(E(),...o),a=H(E(),s,r);return{rowCosines:n,columnCosines:o,imagePositionPatient:i,planeNormal:a}}function no(e){const{width:t,height:n}=e.getCanvas(),{sliceToIndexMatrix:o,indexToSliceMatrix:i}=e.getSliceViewInfo(),s=J(e,[0,0]),r=J(e,[t-1,0]),a=J(e,[0,n-1]),c=D(E(),r,s),d=D(E(),a,s),l=H(E(),c,d);L(c,c),L(d,d),L(l,l);const u=Math.max(Math.abs(c[0]),Math.abs(c[1]),Math.abs(c[2])),f=Math.max(Math.abs(d[0]),Math.abs(d[1]),Math.abs(d[2]));if(!re(1,u)||!re(1,f))throw new Error("getCurrentVolumeViewportSlice is not available for rotate/oblique viewports");const{voxelManager:m}=e.getImageData(),w=e.getSliceViewInfo(),V=m.getSliceData(w);return{width:w.width,height:w.height,scalarData:V,sliceToIndexMatrix:o,indexToSliceMatrix:i}}const oo=.05;function so(e,t){const n=e.getSliceIndex(),o=t.getSliceIndex(),i=B("imagePlaneModule",n.toString()),s=B("imagePlaneModule",o.toString());if(!i||!s){console.log("Viewport spatial registration requires image plane module");return}const{imageOrientationPatient:r}=s;if(!i.imageOrientationPatient.every((f,m)=>Math.abs(f-r[m])<oo)){console.log("Viewport spatial registration only supported for same orientation (hence translation only) for now",i?.imageOrientationPatient,s?.imageOrientationPatient);return}const c=i.imagePositionPatient,d=s.imagePositionPatient,l=Je(E(),c,d),u=Ke(Ze(),l);pe.add([e.id,t.id],u)}function io(e){const{imageData:t,dimensions:n}=e.getImageData()||{};if(!t||!n)return[];const{canvas:o}=e,i=window.devicePixelRatio,s=[0,0],r=[o.width/i,0],a=[o.width/i,o.height/i],c=[0,o.height/i],d=e.canvasToWorld(s),l=e.canvasToWorld(r),u=e.canvasToWorld(a),f=e.canvasToWorld(c),m=t.worldToIndex(d),w=t.worldToIndex(l),V=t.worldToIndex(u),h=t.worldToIndex(f);return ro({dimensions:n,imageData:t,topLeftImage:m,topRightImage:w,bottomRightImage:V,bottomLeftImage:h,topLeftWorld:d,topRightWorld:l,bottomRightWorld:u,bottomLeftWorld:f})}function ro({dimensions:e,imageData:t,topLeftImage:n,topRightImage:o,bottomRightImage:i,bottomLeftImage:s,topLeftWorld:r,topRightWorld:a,bottomRightWorld:c,bottomLeftWorld:d}){const l=k(n,e)?r:t.indexToWorld([0,0,0]),u=k(o,e)?a:t.indexToWorld([e[0]-1,0,0]),f=k(i,e)?c:t.indexToWorld([e[0]-1,e[1]-1,0]),m=k(s,e)?d:t.indexToWorld([0,e[1]-1,0]);return[l,u,m,f]}function k(e,t){return e[0]>0||e[0]<t[0]-1||e[1]>0||e[1]<t[1]-1||e[2]>0||e[2]<t[2]-1}function j(e){if(!e)return;const{viewportUid:t,renderingEngineUid:n}=e.dataset;return Pe(t,n)}function Pe(e,t){if(!t||!e)return;const n=Y(t);if(!n||n.hasBeenDestroyed)return;const o=n.getViewport(e);if(!o)return;const i=An(o)?o.getFrameOfReferenceUID():void 0;return{viewport:o,renderingEngine:n,viewportId:e,renderingEngineId:t,FrameOfReferenceUID:i}}function Bo(e){const t=z();for(let n=0;n<t.length;n++){const o=t[n];if(o.getViewport(e))return Pe(e,o.id)}}function Ho(){const e=[];return z().forEach(n=>{n.getViewports().forEach(({element:i})=>{e.push(j(i))})}),e}function ao(e){const t=j(e);if(!t)return;const{viewport:n}=t;if(!(n instanceof Q))throw new Error(`An image can only be fetched for a stack viewport and not for a viewport of type: ${n.type}`);return n.getCornerstoneImage()}async function co({viewport:e,options:t={}}){const n=e.getRenderingEngine();let o=t.volumeId||`${ee()}`;o.split(":").length===0&&(o=`${Xe()}:${o}`);const{id:i,element:s}=e,r=t.viewportId||i,a=e.getImageIds(),c=e.getViewPresentation(),d=e.getViewReference();n.enableElement({viewportId:r,type:G.ORTHOGRAPHIC,element:s,defaultOptions:{background:t.background,orientation:t.orientation}}),(await Ye(o,{imageIds:a})).load();const u=n.getViewport(r);await _n(n,[{volumeId:o}],[r]);const f=()=>{u.render(),s.removeEventListener(R.VOLUME_VIEWPORT_NEW_VOLUME,f)};return s.addEventListener(R.VOLUME_VIEWPORT_NEW_VOLUME,f),u.setViewPresentation(c),u.setViewReference(d),u.render(),u}async function lo({viewport:e,options:t}){const n=e,{id:o,element:i}=n,s=e.getRenderingEngine(),{background:r}=t,a=t.viewportId||o,c=O.getVolume(n.getVolumeId());if(!(c instanceof Qe))throw new Error("Currently, you cannot decache a volume that is not an ImageVolume. So, unfortunately, volumes such as nifti (which are basic Volume, without imageIds) cannot be decached.");const d={viewportId:a,type:G.STACK,element:i,defaultOptions:{background:r}},l=n.getViewReference();s.enableElement(d);const u=s.getViewport(a);return await u.setStack(c.imageIds),u.setViewReference(l),u.render(),u}function Te(e,t=2){if(Array.isArray(e))return e.map(i=>Te(i,t)).join(", ");if(e==null||e==="")return"NaN";e=Number(e);const n=Math.abs(e);if(n<1e-4)return`${e}`;const o=n>=100?t-2:n>=10?t-1:n>=1?t:n>=.1?t+1:n>=.01?t+2:n>=.001?t+3:t+4;return e.toFixed(o)}function uo(e){return Math.round(e/P)*P}function fo(e,t,n){const o=e.length===t*n*4,i=e.length===t*n*3;if(o||i){const s=new Float32Array(t*n);let r=0,a=0;const c=o?4:3;for(let d=0;d<t;d++)for(let l=0;l<n;l++){const u=e[r],f=e[r+1],m=e[r+2];s[a]=(u+f+m)/3,r+=c,a++}return s}else return e}function go(e){if(e instanceof we)return O.getVolume(e.getVolumeId()).imageIds;if(e.getImageIds)return e.getImageIds()}function mo(e,t){const n=[...e];return t>=n.length?(ce(n),n):(ce(n),n.slice(0,t))}function ce(e){for(let t=e.length-1;t>0;t--){const n=Math.floor(Math.random()*(t+1));[e[t],e[n]]=[e[n],e[t]]}}function K(e){const t=e.toString(16);return t.length==1?"0"+t:t}function ho(e,t,n){return"#"+K(e)+K(t)+K(n)}function po(e){const t=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(e);return t?{r:parseInt(t[1],16),g:parseInt(t[2],16),b:parseInt(t[3],16)}:null}const wo=Object.freeze(Object.defineProperty({__proto__:null,hexToRgb:po,rgbToHex:ho},Symbol.toStringTag,{value:"Module"}));function Io(e,t){if(e===t)return!0;if(e==null||t==null)return!1;try{return JSON.stringify(e)===JSON.stringify(t)}catch(n){return console.debug("Error in JSON.stringify during deep comparison:",n),e===t}}function xe(e,t){const n=e,o=n.getActors?.()??[];return(t?o.find(s=>s.referencedId===t)??o.find(s=>s.referencedId?.endsWith(`:${t}`)):void 0)?.referencedId??(t?te(t):void 0)??n.getDefaultActor?.()?.referencedId}function Me(e,t,n){if(!n)throw new Error("getVolume is required, use the utilities export instead");if(Ie(e)){const o=xe(e,t),i=o?n(o):void 0,s=e.getImageData?.();return{modality:i?.metadata?.Modality??s?.metadata?.Modality,isPreScaled:le(i?.scaling)}}if(typeof e.setVolumes=="function"){const i=t?te(t):e.getVolumeId(),s=i?n(i):void 0;return{modality:s?.metadata?.Modality,isPreScaled:le(s?.scaling)}}if(typeof e.setStack=="function"){const o=e,{preScale:i}=o.getImageData()||{};return{modality:o.modality,isPreScaled:!!i?.scaled}}}function le(e){return!!e&&Object.keys(e).length>0}function Vo(e,t,n){const o=Me(e,t,n);if(!o)throw new Error("Invalid viewport type");return o.modality}function So(e){const{imageIdGroups:t,splittingTag:n}=Ve(e);return{isDynamicVolume:t.length>1,timePoints:t,splittingTag:n}}function bo(e,t){const n=e.length,{rescaleSlope:o,rescaleIntercept:i,suvbw:s}=t;if(t.modality==="PT"&&typeof s=="number")for(let r=0;r<n;r++)e[r]=s*(e[r]*o+i);else for(let r=0;r<n;r++)e[r]=e[r]*o+i;return e}function De(e,t,n){return Math.min(Math.max(t,e),n)}function Oe(e,t){if(!j(e.element))throw new Error("Scroll::Viewport is not enabled (it might be disabled)");if(e instanceof Q&&e.getImageIds().length===0)throw new Error("Scroll::Stack Viewport has no images");const{volumeId:o,delta:i,scrollSlabs:s}=t;if(e instanceof we)vo(e,o,i,s);else{if(typeof e.getCurrentImageIdIndex!="function"||typeof e.scroll!="function")return;const r=e.getCurrentImageIdIndex();if(r+i>e.getImageIds().length-1||r+i<0){const a={imageIdIndex:r,direction:i};T(M,R.STACK_SCROLL_OUT_OF_BOUNDS,a)}e.scroll(i,t.debounceLoading,t.loop)}}function vo(e,t,n,o=!1){const i=o,{numScrollSteps:s,currentStepIndex:r,sliceRangeInfo:a}=Se(e,t,i);if(s===0||!a)return;const{sliceRange:c,spacingInNormalDirection:d,camera:l}=a,{focalPoint:u,viewPlaneNormal:f,position:m}=l,{newFocalPoint:w,newPosition:V}=be(u,m,c,f,d,n);e.setCamera({focalPoint:w,position:V}),e.render();const h=r+n,g={volumeId:t,viewport:e,delta:n,desiredStepIndex:h,currentStepIndex:r,numScrollSteps:s,currentImageId:e.getCurrentImageId()};(h>s||h<0)&&e.getCurrentImageId()?T(M,R.VOLUME_VIEWPORT_SCROLL_OUT_OF_BOUNDS,g):T(M,R.VOLUME_VIEWPORT_SCROLL,g)}async function Eo(e,t={}){const{imageIndex:n,debounceLoading:o,volumeId:i}=t,s=j(e);if(!s)throw new Error("Element has been disabled");const{viewport:r}=s,{imageIndex:a,numberOfSlices:c}=yo(r,o),l=Ro(c,n)-a;Oe(r,{delta:l,debounceLoading:o,volumeId:i})}function yo(e,t){return e instanceof Q?{numberOfSlices:e.getImageIds().length,imageIndex:t?e.getTargetImageIdIndex():e.getCurrentImageIdIndex()}:{numberOfSlices:e.getNumberOfSlices(),imageIndex:e.getSliceIndex()}}function Ro(e,t){const n=e-1;return De(t,0,n)}function Co(e,t,n={}){const o=O.getVolume(e);if(!o)throw new Error(`Referenced volume with id ${e} does not exist.`);const{metadata:i,spacing:s,direction:r,dimensions:a}=o,{minX:c,maxX:d,minY:l,maxY:u,minZ:f,maxZ:m}=t,w=[Math.min(c,d),Math.min(l,u),Math.min(f,m)],V=Z(o.imageData,w),h=[Math.abs(d-c)+1,Math.abs(u-l)+1,Math.abs(m-f)+1],{targetBuffer:g}=n,b={metadata:i,dimensions:h,spacing:s,origin:V,direction:r,targetBuffer:g,scalarData:g?.type==="Float32Array"?new Float32Array(h[0]*h[1]*h[2]):void 0},S=et(ee(),b),v=S.voxelManager.getCompleteScalarDataArray(),p=h[0]*h[1],y=a[0]*a[1],x=o.voxelManager.getCompleteScalarDataArray();for(let I=0;I<h[2];I++)for(let C=0;C<h[1];C++){const $=Z(S.imageData,[0,C,I]),_=ve(o.imageData,$),W=_[2]*y+_[1]*a[0]+_[0],q=x.slice(W,W+h[0]),A=I*p+C*h[0];v.set(q,A)}return S.voxelManager.setCompleteScalarDataArray(v),S}function Po(e,t){const{viewUp:n,viewPlaneNormal:o}=t,i=N(e,[0,0,0]),s=ae(E(),n),r=ae(E(),o),a=H(E(),s,r),c=D(E(),N(e,s),i),d=D(E(),N(e,r),i);L(c,c),L(d,d);const l=H(E(),c,d);return{worldVecRowDir:a,worldVecColDir:s,worldVecSliceDir:r,ijkVecRowDir:l,ijkVecColDir:c,ijkVecSliceDir:d}}function To(e,t,n,o){const[i,s,r]=t,a=i*s;let c=0,d=0,l=0;const[u,f,m]=n.map(Math.round);for(let g=m-o;g<=m+o;g++)if(!(g<0||g>=r)){for(let b=f-o;b<=f+o;b++)if(!(b<0||b>=s))for(let S=u-o;S<=u+o;S++){if(S<0||S>=i)continue;const v=g*a+b*i+S,p=e[v];c+=p,d+=p*p,l++}}if(l===0){const g=m*a+f*i+u;return g>=0&&g<e.length?{mean:e[g],stdDev:0,count:1}:{mean:0,stdDev:0,count:0}}const w=c/l,V=d/l-w*w,h=Math.sqrt(Math.max(0,V));return{mean:w,stdDev:h,count:l}}const de=1e-6;function xo(e,t){const{lower:n,upper:o}=t.voiRange,i=o-n,s=t.VOILUTFunction,r=a=>t.invert===!0?1-a:a;if(s===Ee.SAMPLED_SIGMOID||s==="SIGMOID"){const{windowCenter:a,windowWidth:c}=ye(n,o),d=Math.max(Math.abs(c),1e-12);return r(1/(1+Math.exp(-4*(e-a)/d)))}return i===0||!Number.isFinite(i)?r(0):r(U((e-n)/i))}function X(e,t){const{lower:n,upper:o}=t.voiRange,i=t.VOILUTFunction,s=t.invert===!0?U(1-U(e)):U(e);if(i===Ee.SAMPLED_SIGMOID||i==="SIGMOID"){const{windowCenter:a,windowWidth:c}=ye(n,o),d=_e(s,de,1-de);return tt(d,a,c)}const r=o-n;return r===0||!Number.isFinite(r)?n:n+s*r}function Mo(e,t,n){const o=Math.min(e,t),i=Math.max(e,t),s=X(o,n),r=X(i,n);return{rawMin:Math.min(s,r),rawMax:Math.max(s,r)}}function U(e){return Number.isFinite(e)?_e(e,0,1):0}function _e(e,t,n){return Math.min(n,Math.max(t,e))}const{getPixelSpacingInformation:Do,calculateRadiographicPixelSpacing:Oo,getERMF:_o}=nt,Lo=(e,t)=>Vo(e,t,O.getVolume),Wo=(e,t)=>Me(e,t,O.getVolume),zo=Object.freeze(Object.defineProperty({__proto__:null,ECGUtilities:ft,FrameRange:gt,HistoryMemo:mt,PointsManager:at,ProgressiveIterator:it,RLEVoxelMap:st,VideoUtilities:ht,VoxelManager:ot,WSIUtilities:pt,actorIsA:wt,applyPreset:It,asArray:Vt,autoLoad:St,buildMetadata:bt,calculateNeighborhoodStats:To,calculateRadiographicPixelSpacing:Oo,calculateSpacingBetweenImageIds:vt,calculateViewportsSpatialRegistration:so,calibratedPixelSpacingMetadataProvider:$n,clamp:ut,clip:De,clonePoint3:Et,color:wo,colormap:yt,convertColorArrayToRgbString:Rt,convertStackToVolumeViewport:co,convertToGrayscale:fo,convertVolumeToStackViewport:lo,createLinearRGBTransferFunction:Ct,createSigmoidRGBTransferFunction:Pt,createSubVolume:Co,decimate:Tt,deepClone:xt,deepEqual:Io,deepMerge:Mt,eventListener:Fn,fnv1aHash:Dt,generateFrameImageId:Ot,generateVolumePropsFromImageIds:_t,genericMetadataProvider:Lt,genericViewportDisplaySetMetadataProvider:Wt,getAcquisitionPlaneOrientation:At,getBufferConfiguration:kt,getClosestImageId:Ft,getClosestStackImageIndexForPoint:Qn,getCubeSizeInView:Nt,getCurrentVolumeViewportSlice:no,getDynamicVolumeInfo:So,getERMF:_o,getImageDataMetadata:Ut,getImageLegacy:ao,getImageSliceDataForVolumeViewport:Gt,getMinMax:Bt,getNormalizedAspectRatio:dt,getPixelSpacingInformation:Do,getRandomSampleFromArray:mo,getRuntimeId:zn,getScalingDescriptor:Wo,getScalingParameters:Ht,getSliceRange:zt,getSpacingInNormalDirection:jt,getTargetVolumeAndSpacingInNormalDir:$t,getVOIRangeFromWindowLevel:qt,getViewportContentMode:Jt,getViewportImageCornersInWorld:io,getViewportImageIds:go,getViewportModality:Lo,getViewportsWithImageURI:Yn,getViewportsWithVolumeId:Kt,getVoiFromSigmoidRGBTransferFunction:Zt,getVolumeActorCorners:Xt,getVolumeDirectionVectors:Po,getVolumeId:te,getVolumeSliceRangeInfo:Yt,getVolumeViewReferenceId:Qt,getVolumeViewportScrollInfo:Se,getVolumeViewportsContainingSameVolumes:Zn,handleMultiframe4D:en,hasFloatScalingParameters:tn,hasNaNValues:nn,hasOwn:on,imageIdToURI:sn,imageRetrieveMetadataProvider:ct,imageToWorldCoords:rn,indexAlmostWithinDimensions:Kn,indexWithinDimensions:Jn,invertRgbTransferFunction:an,isEqual:lt,isEqualAbs:cn,isEqualNegative:ln,isGenericViewport:Ie,isImageActor:dn,isNumber:un,isOpposite:qn,isPTPrescaledWithSUV:ge,isValidVolume:fn,isVideoTransferSyntax:gn,jumpToSlice:Eo,loadImageToCanvas:Xn,logger:rt,makeVolumeMetadata:mn,mapMappedBandToRawRange:Mo,mapScalarToViewportVoiIntensity:xo,mapViewportVoiIntensityToScalar:X,planar:hn,pointInShapeCallback:pn,renderToCanvasCPU:Ce,renderToCanvasGPU:Re,resolveGenericViewportVolumeId:xe,rotateToViewCoordinates:wn,roundNumber:Te,roundToPrecision:uo,scaleArray:bo,scaleRgbTransferFunction:Nn,scroll:Oe,snapFocalPointToSlice:be,sortImageIdsAndGetSpacing:In,spatialRegistrationMetadataProvider:pe,splitImageIdsBy4DTags:Ve,transferFunctionUtils:Vn,transformIndexToWorld:Z,transformWorldToIndex:ve,transformWorldToIndexContinuous:N,triggerEvent:T,updatePlaneRestriction:Sn,updateVTKImageDataWithCornerstoneImage:bn,uuidv4:ee,viewportIsInStackMode:vn,viewportIsInVolumeMode:En,viewportSupportsDisplaySetPresentation:yn,viewportSupportsImageSlices:he,viewportSupportsStackCalibration:Rn,viewportSupportsStackCompatibility:Cn,viewportSupportsVolumeActors:fe,viewportSupportsVolumeCompatibility:Pn,viewportSupportsVolumeId:Tn,viewportSupportsVolumeURI:xn,windowLevel:Mn,worldToImageCoords:Dn},Symbol.toStringTag,{value:"Module"}));export{Oe as A,no as B,De as C,qn as D,io as E,fo as F,On as G,kn as M,Wn as T,Ln as a,Pe as b,Bo as c,Ho as d,An as e,Go as f,j as g,Uo as h,zn as i,Io as j,mo as k,Wo as l,Yn as m,Kn as n,Qn as o,so as p,Eo as q,Te as r,_n as s,Jn as t,zo as u,No as v,uo as w,Po as x,Co as y,To as z};
1
+ import{t as T,E as R,e as M,B as We,v as Ae,a as ne,b as F,s as ke,c as Fe,f as oe,cw as ue,c8 as Ne,bW as P,aK as z,cx as fe,aJ as Y,ag as se,V as G,cy as ge,cz as D,cA as Ue,cB as Ge,cC as Be,bL as He,at as O,aO as ze,bi as B,cD as me,bN as je,cE as he,bt as $e,b_ as qe,cF as ie,cG as E,cH as H,cI as J,cJ as L,cK as re,cL as Je,cM as Ke,cN as Ze,bC as pe,am as Q,b8 as ee,cO as Xe,cP as Ye,ai as Qe,ar as we,bm as te,i as Ie,L as Ve,bK as Se,cQ as be,bA as Z,bG as et,bc as ve,bz as N,cR as ae,cS as Ee,bP as ye,cT as tt,cr as nt,K as ot,cU as st,cV as it,c1 as rt,cW as at,cX as ct,bf as lt,cY as dt,cZ as ut,c_ as ft,c$ as gt,bp as mt,d0 as ht,d1 as pt,d2 as wt,d3 as It,d4 as Vt,d5 as St,d6 as bt,d7 as vt,bg as Et,d8 as yt,av as Rt,d9 as Ct,da as Pt,H as Tt,b7 as xt,bk as Mt,db as Dt,dc as Ot,J as _t,dd as Lt,bo as Wt,de as At,df as kt,bq as Ft,dg as Nt,bs as Ut,dh as Gt,bR as Bt,di as Ht,dj as zt,bF as jt,bj as $t,dk as qt,bh as Jt,bn as Kt,dl as Zt,dm as Xt,dn as Yt,dp as Qt,dq as en,dr as tn,ds as nn,dt as on,bl as sn,bZ as rn,du as an,bT as cn,dv as ln,bS as dn,bv as un,br as fn,ct as gn,dw as mn,dx as hn,bI as pn,dy as wn,M as In,dz as Vn,dA as Sn,bw as bn,dB as vn,bD as En,bJ as yn,dC as Rn,dD as Cn,bM as Pn,dE as Tn,dF as xn,dG as Mn,bY as Dn}from"./Settings-bQo_Uhzb.js";import"./Texture-BujGXFjY.js";import"./cornerstoneEngine-C6E2FBPw.js";function On(e){return!!(e&&typeof e.setVolumes=="function"&&typeof e.addVolumes=="function")}async function _n(e,t,n,o=!1,i=!1){const s=n.map(r=>{const a=e.getViewport(r);if(!a)throw new Error(`Viewport with Id ${r} does not exist`);if(!On(a))throw new Error("setVolumesForViewports only supports viewports that implement setVolumes");return a});await Promise.all(s.map(r=>r.setVolumes(t,o,i)))}function Ln(e,t,n=0){const o=e.getOpenGLRenderWindow?.()?.getCanvas?.();o&&(o.addEventListener("webglcontextlost",()=>{console.warn(`CornerstoneRender: WebGL context lost (renderingEngine=${t}, context=${n})`),T(M,R.WEBGL_CONTEXT_LOST,{renderingEngineId:t,contextIndex:n})}),o.addEventListener("webglcontextrestored",()=>{T(M,R.WEBGL_CONTEXT_RESTORED,{renderingEngineId:t,contextIndex:n})}))}class Wn extends We{constructor(t){super(t),this._renderFlaggedViewports=()=>{this._throwIfDestroyed(),this.offscreenMultiRenderWindow&&this.performVtkDrawCall();const n=this._getViewportsAsArray(),o=[];for(let i=0;i<n.length;i++){const s=n[i];if(this._needsRender.has(s.id)){const r=this.renderViewportUsingCustomOrVtkPipeline(s);if(o.push(r),s.setRendered(),this._needsRender.delete(s.id),this._needsRender.size===0)break}}this._animationFrameSet=!1,this._animationFrameHandle=null,o.forEach(i=>{i?.element&&T(i.element,R.IMAGE_RENDERED,i)})},this.useCPURendering||this.ensureOffscreenResources()}ensureOffscreenResources(){this.offscreenMultiRenderWindow||(this.offscreenMultiRenderWindow=Ae.newInstance(),this.offScreenCanvasContainer=document.createElement("div"),this.offscreenMultiRenderWindow.setContainer(this.offScreenCanvasContainer),Ln(this.offscreenMultiRenderWindow,this.id))}enableVTKjsDrivenViewport(t){this.ensureOffscreenResources();const o=this._getViewportsAsArray().filter(l=>ne(l.type)===!1),i=o.map(l=>l.canvas),s=F(t.element);i.push(s);const{offScreenCanvasWidth:r,offScreenCanvasHeight:a}=this._resizeOffScreenCanvas(i),c=this._resize(o,r,a),d={...t,canvas:s};this.addVtkjsDrivenViewport(d,{offScreenCanvasWidth:r,offScreenCanvasHeight:a,xOffset:c})}addVtkjsDrivenViewport(t,n){this.ensureOffscreenResources();const{element:o,canvas:i,viewportId:s,type:r,defaultOptions:a}=t;o.tabIndex=-1,ke(o);const{offScreenCanvasWidth:c,offScreenCanvasHeight:d,xOffset:l}=n,{sxStartDisplayCoords:u,syStartDisplayCoords:f,sxEndDisplayCoords:m,syEndDisplayCoords:w,sx:V,sy:h,sWidth:g,sHeight:b}=this._getViewportCoordsOnOffScreenCanvas(t,c,d,l);this.offscreenMultiRenderWindow.addRenderer({viewport:[u,f,m,w],id:s,background:a.background?a.background:[0,0,0]});const S={id:s,element:o,renderingEngineId:this.id,type:r,canvas:i,sx:V,sy:h,sWidth:g,sHeight:b,defaultOptions:a||{}},v=Fe(t);if(!v)throw new Error(`Viewport Type ${r} is not supported`);const p=new v(S);p.requestedType=t.requestedType??r,this._viewports.set(s,p);const y={element:o,viewportId:s,renderingEngineId:this.id};p.suppressEvents||T(M,R.ELEMENT_ENABLED,y)}setVtkjsDrivenViewports(t){if(t.length){const n=t.map(r=>F(r.element));n.forEach(r=>{const a=window.devicePixelRatio||1,c=r.getBoundingClientRect();r.width=c.width*a,r.height=c.height*a});const{offScreenCanvasWidth:o,offScreenCanvasHeight:i}=this._resizeOffScreenCanvas(n);let s=0;for(let r=0;r<t.length;r++){const a=t[r],c=n[r],d={...a,canvas:c};this.addVtkjsDrivenViewport(d,{offScreenCanvasWidth:o,offScreenCanvasHeight:i,xOffset:s}),s+=c.width}}}_resizeVTKViewports(t,n=!0,o=!0){const i=t.map(s=>F(s.element));if(i.forEach(s=>{const r=window.devicePixelRatio||1;s.width=s.clientWidth*r,s.height=s.clientHeight*r}),i.length){const{offScreenCanvasWidth:s,offScreenCanvasHeight:r}=this._resizeOffScreenCanvas(i);this._resize(t,s,r)}t.forEach(s=>{const r=s.getCamera(),a=s.getRotation(),{flipHorizontal:c}=r,d=s;d.resetViewStateForResize?d.resetViewStateForResize():d.resetCameraForResize();const l=s.getDisplayArea();n&&(l?(c&&s.setCamera({flipHorizontal:c}),a&&s.setViewPresentation({rotation:a})):s.setCamera(r))}),o&&this.render()}performVtkDrawCall(){const{offscreenMultiRenderWindow:t}=this,n=t.getRenderWindow(),o=t.getRenderers();if(o.length){for(let i=0;i<o.length;i++){const{renderer:s,id:r}=o[i],a=r.split("::")[0];this._needsRender.has(a)?s.setDraw(!0):s.setDraw(!1)}n.render();for(let i=0;i<o.length;i++)o[i].renderer.setDraw(!1)}}renderViewportUsingCustomOrVtkPipeline(t){let n;if(t.sWidth<oe||t.sHeight<oe){console.warn("Viewport is too small",t.sWidth,t.sHeight);return}if(ne(t.type)===!0)n=t.customRenderViewportToCanvas();else{if(!this.offscreenMultiRenderWindow)throw new Error("GPU not available, and using a viewport with no custom render pipeline.");const{offscreenMultiRenderWindow:o}=this,r=o.getOpenGLRenderWindow().get3DContext().canvas;n=this._renderViewportFromVtkCanvasToOnscreenCanvas(t,r)}return n}_renderViewportFromVtkCanvasToOnscreenCanvas(t,n){const{element:o,canvas:i,sx:s,sy:r,sWidth:a,sHeight:c,id:d,renderingEngineId:l,suppressEvents:u}=t,{width:f,height:m}=i;return i.getContext("2d").drawImage(n,s,r,a,c,0,0,f,m),{element:o,suppressEvents:u,viewportId:d,renderingEngineId:l,viewportStatus:t.viewportStatus}}_resizeOffScreenCanvas(t){const{offScreenCanvasContainer:n,offscreenMultiRenderWindow:o}=this,i=Math.max(...t.map(r=>r.height));let s=0;return t.forEach(r=>{s+=r.width}),n.width=s,n.height=i,o.resize(),{offScreenCanvasWidth:s,offScreenCanvasHeight:i}}_resize(t,n,o){let i=0;for(let s=0;s<t.length;s++){const r=t[s],{sxStartDisplayCoords:a,syStartDisplayCoords:c,sxEndDisplayCoords:d,syEndDisplayCoords:l,sx:u,sy:f,sWidth:m,sHeight:w}=this._getViewportCoordsOnOffScreenCanvas(r,n,o,i);i+=r.canvas.width,r.sx=u,r.sy=f,r.sWidth=m,r.sHeight=w,this.offscreenMultiRenderWindow.getRenderer(r.id).setViewport(a,c,d,l)}return i}_getViewportCoordsOnOffScreenCanvas(t,n,o,i){const{canvas:s}=t,{width:r,height:a}=s,c=i,d=0,l=c/n,u=d+(o-a)/o,f=r/n,m=a/o;return{sxStartDisplayCoords:l,syStartDisplayCoords:u,sxEndDisplayCoords:l+f,syEndDisplayCoords:u+m,sx:c,sy:d,sWidth:r,sHeight:a}}}function No(e){return!!(e&&typeof e.canvasToWorld=="function"&&typeof e.worldToCanvas=="function")}function Uo(e){return!!(e&&typeof e.getZoom=="function"&&typeof e.setZoom=="function")}function Go(e){return!!(e&&typeof e.getPan=="function"&&typeof e.setPan=="function")}function An(e){return!!(e&&typeof e.getFrameOfReferenceUID=="function")}class kn{constructor(){this._targetsEventListeners=new Map}addEventListener(t,n,o,i){let s=this._targetsEventListeners.get(t);s||(s=new ue(t),this._targetsEventListeners.set(t,s)),s.addEventListener(n,o,i)}removeEventListener(t,n,o,i){const s=this._targetsEventListeners.get(t);s&&(s.removeEventListener(n,o,i),s.isEmpty&&this._targetsEventListeners.delete(t))}reset(){Array.from(this._targetsEventListeners.entries()).forEach(([t,n])=>{n.reset(),this._targetsEventListeners.delete(t)})}}const Fn=Object.freeze(Object.defineProperty({__proto__:null,MultiTargetEventListenerManager:kn,TargetEventListeners:ue},Symbol.toStringTag,{value:"Module"}));function Nn(e,t){const n=e.getSize();for(let o=0;o<n;o++){const i=[];e.getNodeValue(o,i),i[1]=i[1]*t,i[2]=i[2]*t,i[3]=i[3]*t,e.setNodeValue(o,i)}}const Un=Symbol("LastRuntimeId"),Gn={},Bn=4294967295,Hn="-";function zn(e,t,n){return jn(e!==null&&typeof e=="object"?e:Gn,Un,(typeof n=="number"&&n>0?n:Bn)>>>0).join(typeof t=="string"?t:Hn)}function jn(e,t,n){let o=e[t];o instanceof Array||(o=[0],Object.defineProperty(e,t,{value:o}));for(let i=!0,s=0;i&&s<o.length;++s){let r=o[s]|0;r<n?(i=!1,r=r+1):(r=0,s+1===o.length&&o.push(0)),o[s]=r}return o}const $n=Ne;function qn(e,t,n=1e-5){return Math.abs(e[0]+t[0])<n&&Math.abs(e[1]+t[1])<n&&Math.abs(e[2]+t[2])<n}function Jn(e,t){return!(e[0]<0||e[0]>=t[0]||e[1]<0||e[1]>=t[1]||e[2]<0||e[2]>=t[2])}function Kn(e,t){return!(e[0]<-P||e[0]>=t[0]+P||e[1]<-P||e[1]>=t[1]+P||e[2]<-P||e[2]>=t[2]+P)}function Zn(e,t){let n;t?n=[Y(t)]:n=z();const o=[];return n.forEach(i=>{const s=e.getActors(),r=i.getViewports().filter(fe);for(const a of r){const c=a.getActors();if(c.length!==s.length)continue;s.every(({uid:l})=>c.find(u=>l===u.uid))&&o.push(a)}}),o}function Re(e,t,n=void 0,o="_thumbnails",i={displayArea:{imageArea:[1,1]}}){if(!e||!(e instanceof HTMLCanvasElement))throw new Error("canvas element is required");const s=!t.imageId,r=!s&&t,a=s&&t,d=`renderGPUViewport-${r.imageId||a.volumeId}`,l=document.createElement("div"),u=window.devicePixelRatio||1;i.displayArea||(i.displayArea={imageArea:[1,1]});const f=e.width,m=e.height;l.style.width=`${f/u+se}px`,l.style.height=`${m/u+se}px`,l.style.visibility="hidden",l.style.position="absolute",document.body.appendChild(l);const w=d.split(":").join("-");l.setAttribute("viewport-id-for-remove",w);const V=F(l),h=Y(o)||new Wn(o);let g=h.getViewport(d);if(!g){const b={viewportId:d,type:s?G.ORTHOGRAPHIC:G.STACK,element:l,defaultOptions:{...i,suppressEvents:!0}};h.enableElement(b),g=h.getViewport(d)}return new Promise(b=>{let S=!1,{viewReference:v}=i;const p=y=>{if(S)return;if(v){const A=v;v=null,g.setViewReference(A),g.render();return}e.getContext("2d").drawImage(V,0,0,V.width,V.height,0,0,e.width,e.height);const I=g.canvasToWorld([0,0]),C=g.canvasToWorld([V.width/u,0]),$=g.canvasToWorld([0,V.height/u]),_=D([0,0,0],g.canvasToWorld([1/u,0]),I),W=D([0,0,0],g.canvasToWorld([0,1/u]),I),q=1;S=!0,l.removeEventListener(R.IMAGE_RENDERED,p),setTimeout(()=>{h.disableElement(d),document.querySelectorAll(`[viewport-id-for-remove="${w}"]`).forEach(Le=>{Le.remove()})},0),b({origin:I,bottomLeft:$,topRight:C,thicknessMm:q,rightVector:_,downVector:W})};l.addEventListener(R.IMAGE_RENDERED,p),s?g.setVolumes([a],!1,!0):g.renderImageObject(t),g.resetCamera(),n==="PT"&&!ge(r)&&g.setProperties({voiRange:{lower:r.minPixelValue,upper:r.maxPixelValue}}),g.render()})}function Ce(e,t,n,o,i){if(t.volumeId)throw new Error("Unsupported volume rendering for CPU");const r=t,a=Ue(e,r,n),c={canvas:e,viewport:a,image:r,renderingTools:{}};c.transform=Ge(c);const d=!0;return new Promise((l,u)=>{Be(c,d),l(null)})}function Xn(e){const{canvas:t,imageId:n,viewReference:o,requestType:i=He.Thumbnail,priority:s=-5,renderingEngineId:r="_thumbnails",useCPURendering:a=!1,thumbnail:c=!1,imageAspect:d=!1,viewportOptions:l}=e,u=o?.volumeId,f=u&&!n,m=o&&l?{...l,viewReference:o}:l,w=a?Ce:Re;return new Promise((V,h)=>{function g(p,y){const{modality:x}=B(me.GENERAL_SERIES,y)||{},I=!f&&p,C=f&&p;I&&(I.isPreScaled=I.isPreScaled||I.preScale?.scaled),c&&(t.height=256,t.width=256),d&&I&&(t.width=I&&t.height*I.width/I.height),t.style.width=`${t.width/devicePixelRatio}px`,t.style.height=`${t.height/devicePixelRatio}px`,C&&a&&h(new Error("CPU rendering of volume not supported")),w(t,p,x,r,m).then(V)}function b(p,y){console.error(p,y),h(p)}function S(p,y,x){return je(p,x).then(I=>{g.call(this,I,p)},I=>{b.call(this,I,p)})}const v={useRGBA:!!a,requestType:i};if(u){const p=O.getVolume(u);p||h(new Error(`Volume id ${u} not found in cache`));const y=p.imageIds[0];g(p,y)}else ze.addRequest(S.bind(null,n,null,v),i,{imageId:n},s)})}function Yn(e){const t=z(),n=[];return t.forEach(o=>{o.getViewports().filter(he).forEach(s=>{s.hasImageURI(e)&&n.push(s)})}),n}function Qn(e,t){const n=eo(e,t);return n?n.index:null}function eo(e,t){const n=t.getImageIds(),o=t.getCurrentImageIdIndex();if(n.length===0)return null;const i=c=>{const d=to(c);if(!d)return null;const l=$e(d.planeNormal,d.imagePositionPatient);return qe(l,e)},s={distance:i(n[o])??1/0,index:o},r=n.slice(o+1);for(let c=0;c<r.length;c++){const d=r[c],l=i(d);if(l!==null)if(l<=s.distance)s.distance=l,s.index=c+o+1;else break}const a=n.slice(0,o);for(let c=a.length-1;c>=0;c--){const d=a[c],l=i(d);if(!(l===null||l===s.distance))if(l<s.distance)s.distance=l,s.index=c;else break}return s.distance===1/0?null:s}function to(e){const t=B(me.IMAGE_PLANE,e);if(!t||!(t.rowCosines instanceof Array&&t.rowCosines.length===3)||!(t.columnCosines instanceof Array&&t.columnCosines.length===3)||!(t.imagePositionPatient instanceof Array&&t.imagePositionPatient.length===3))return null;const{rowCosines:n,columnCosines:o,imagePositionPatient:i}=t,s=ie(E(),...n),r=ie(E(),...o),a=H(E(),s,r);return{rowCosines:n,columnCosines:o,imagePositionPatient:i,planeNormal:a}}function no(e){const{width:t,height:n}=e.getCanvas(),{sliceToIndexMatrix:o,indexToSliceMatrix:i}=e.getSliceViewInfo(),s=J(e,[0,0]),r=J(e,[t-1,0]),a=J(e,[0,n-1]),c=D(E(),r,s),d=D(E(),a,s),l=H(E(),c,d);L(c,c),L(d,d),L(l,l);const u=Math.max(Math.abs(c[0]),Math.abs(c[1]),Math.abs(c[2])),f=Math.max(Math.abs(d[0]),Math.abs(d[1]),Math.abs(d[2]));if(!re(1,u)||!re(1,f))throw new Error("getCurrentVolumeViewportSlice is not available for rotate/oblique viewports");const{voxelManager:m}=e.getImageData(),w=e.getSliceViewInfo(),V=m.getSliceData(w);return{width:w.width,height:w.height,scalarData:V,sliceToIndexMatrix:o,indexToSliceMatrix:i}}const oo=.05;function so(e,t){const n=e.getSliceIndex(),o=t.getSliceIndex(),i=B("imagePlaneModule",n.toString()),s=B("imagePlaneModule",o.toString());if(!i||!s){console.log("Viewport spatial registration requires image plane module");return}const{imageOrientationPatient:r}=s;if(!i.imageOrientationPatient.every((f,m)=>Math.abs(f-r[m])<oo)){console.log("Viewport spatial registration only supported for same orientation (hence translation only) for now",i?.imageOrientationPatient,s?.imageOrientationPatient);return}const c=i.imagePositionPatient,d=s.imagePositionPatient,l=Je(E(),c,d),u=Ke(Ze(),l);pe.add([e.id,t.id],u)}function io(e){const{imageData:t,dimensions:n}=e.getImageData()||{};if(!t||!n)return[];const{canvas:o}=e,i=window.devicePixelRatio,s=[0,0],r=[o.width/i,0],a=[o.width/i,o.height/i],c=[0,o.height/i],d=e.canvasToWorld(s),l=e.canvasToWorld(r),u=e.canvasToWorld(a),f=e.canvasToWorld(c),m=t.worldToIndex(d),w=t.worldToIndex(l),V=t.worldToIndex(u),h=t.worldToIndex(f);return ro({dimensions:n,imageData:t,topLeftImage:m,topRightImage:w,bottomRightImage:V,bottomLeftImage:h,topLeftWorld:d,topRightWorld:l,bottomRightWorld:u,bottomLeftWorld:f})}function ro({dimensions:e,imageData:t,topLeftImage:n,topRightImage:o,bottomRightImage:i,bottomLeftImage:s,topLeftWorld:r,topRightWorld:a,bottomRightWorld:c,bottomLeftWorld:d}){const l=k(n,e)?r:t.indexToWorld([0,0,0]),u=k(o,e)?a:t.indexToWorld([e[0]-1,0,0]),f=k(i,e)?c:t.indexToWorld([e[0]-1,e[1]-1,0]),m=k(s,e)?d:t.indexToWorld([0,e[1]-1,0]);return[l,u,m,f]}function k(e,t){return e[0]>0||e[0]<t[0]-1||e[1]>0||e[1]<t[1]-1||e[2]>0||e[2]<t[2]-1}function j(e){if(!e)return;const{viewportUid:t,renderingEngineUid:n}=e.dataset;return Pe(t,n)}function Pe(e,t){if(!t||!e)return;const n=Y(t);if(!n||n.hasBeenDestroyed)return;const o=n.getViewport(e);if(!o)return;const i=An(o)?o.getFrameOfReferenceUID():void 0;return{viewport:o,renderingEngine:n,viewportId:e,renderingEngineId:t,FrameOfReferenceUID:i}}function Bo(e){const t=z();for(let n=0;n<t.length;n++){const o=t[n];if(o.getViewport(e))return Pe(e,o.id)}}function Ho(){const e=[];return z().forEach(n=>{n.getViewports().forEach(({element:i})=>{e.push(j(i))})}),e}function ao(e){const t=j(e);if(!t)return;const{viewport:n}=t;if(!(n instanceof Q))throw new Error(`An image can only be fetched for a stack viewport and not for a viewport of type: ${n.type}`);return n.getCornerstoneImage()}async function co({viewport:e,options:t={}}){const n=e.getRenderingEngine();let o=t.volumeId||`${ee()}`;o.split(":").length===0&&(o=`${Xe()}:${o}`);const{id:i,element:s}=e,r=t.viewportId||i,a=e.getImageIds(),c=e.getViewPresentation(),d=e.getViewReference();n.enableElement({viewportId:r,type:G.ORTHOGRAPHIC,element:s,defaultOptions:{background:t.background,orientation:t.orientation}}),(await Ye(o,{imageIds:a})).load();const u=n.getViewport(r);await _n(n,[{volumeId:o}],[r]);const f=()=>{u.render(),s.removeEventListener(R.VOLUME_VIEWPORT_NEW_VOLUME,f)};return s.addEventListener(R.VOLUME_VIEWPORT_NEW_VOLUME,f),u.setViewPresentation(c),u.setViewReference(d),u.render(),u}async function lo({viewport:e,options:t}){const n=e,{id:o,element:i}=n,s=e.getRenderingEngine(),{background:r}=t,a=t.viewportId||o,c=O.getVolume(n.getVolumeId());if(!(c instanceof Qe))throw new Error("Currently, you cannot decache a volume that is not an ImageVolume. So, unfortunately, volumes such as nifti (which are basic Volume, without imageIds) cannot be decached.");const d={viewportId:a,type:G.STACK,element:i,defaultOptions:{background:r}},l=n.getViewReference();s.enableElement(d);const u=s.getViewport(a);return await u.setStack(c.imageIds),u.setViewReference(l),u.render(),u}function Te(e,t=2){if(Array.isArray(e))return e.map(i=>Te(i,t)).join(", ");if(e==null||e==="")return"NaN";e=Number(e);const n=Math.abs(e);if(n<1e-4)return`${e}`;const o=n>=100?t-2:n>=10?t-1:n>=1?t:n>=.1?t+1:n>=.01?t+2:n>=.001?t+3:t+4;return e.toFixed(o)}function uo(e){return Math.round(e/P)*P}function fo(e,t,n){const o=e.length===t*n*4,i=e.length===t*n*3;if(o||i){const s=new Float32Array(t*n);let r=0,a=0;const c=o?4:3;for(let d=0;d<t;d++)for(let l=0;l<n;l++){const u=e[r],f=e[r+1],m=e[r+2];s[a]=(u+f+m)/3,r+=c,a++}return s}else return e}function go(e){if(e instanceof we)return O.getVolume(e.getVolumeId()).imageIds;if(e.getImageIds)return e.getImageIds()}function mo(e,t){const n=[...e];return t>=n.length?(ce(n),n):(ce(n),n.slice(0,t))}function ce(e){for(let t=e.length-1;t>0;t--){const n=Math.floor(Math.random()*(t+1));[e[t],e[n]]=[e[n],e[t]]}}function K(e){const t=e.toString(16);return t.length==1?"0"+t:t}function ho(e,t,n){return"#"+K(e)+K(t)+K(n)}function po(e){const t=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(e);return t?{r:parseInt(t[1],16),g:parseInt(t[2],16),b:parseInt(t[3],16)}:null}const wo=Object.freeze(Object.defineProperty({__proto__:null,hexToRgb:po,rgbToHex:ho},Symbol.toStringTag,{value:"Module"}));function Io(e,t){if(e===t)return!0;if(e==null||t==null)return!1;try{return JSON.stringify(e)===JSON.stringify(t)}catch(n){return console.debug("Error in JSON.stringify during deep comparison:",n),e===t}}function xe(e,t){const n=e,o=n.getActors?.()??[];return(t?o.find(s=>s.referencedId===t)??o.find(s=>s.referencedId?.endsWith(`:${t}`)):void 0)?.referencedId??(t?te(t):void 0)??n.getDefaultActor?.()?.referencedId}function Me(e,t,n){if(!n)throw new Error("getVolume is required, use the utilities export instead");if(Ie(e)){const o=xe(e,t),i=o?n(o):void 0,s=e.getImageData?.();return{modality:i?.metadata?.Modality??s?.metadata?.Modality,isPreScaled:le(i?.scaling)}}if(typeof e.setVolumes=="function"){const i=t?te(t):e.getVolumeId(),s=i?n(i):void 0;return{modality:s?.metadata?.Modality,isPreScaled:le(s?.scaling)}}if(typeof e.setStack=="function"){const o=e,{preScale:i}=o.getImageData()||{};return{modality:o.modality,isPreScaled:!!i?.scaled}}}function le(e){return!!e&&Object.keys(e).length>0}function Vo(e,t,n){const o=Me(e,t,n);if(!o)throw new Error("Invalid viewport type");return o.modality}function So(e){const{imageIdGroups:t,splittingTag:n}=Ve(e);return{isDynamicVolume:t.length>1,timePoints:t,splittingTag:n}}function bo(e,t){const n=e.length,{rescaleSlope:o,rescaleIntercept:i,suvbw:s}=t;if(t.modality==="PT"&&typeof s=="number")for(let r=0;r<n;r++)e[r]=s*(e[r]*o+i);else for(let r=0;r<n;r++)e[r]=e[r]*o+i;return e}function De(e,t,n){return Math.min(Math.max(t,e),n)}function Oe(e,t){if(!j(e.element))throw new Error("Scroll::Viewport is not enabled (it might be disabled)");if(e instanceof Q&&e.getImageIds().length===0)throw new Error("Scroll::Stack Viewport has no images");const{volumeId:o,delta:i,scrollSlabs:s}=t;if(e instanceof we)vo(e,o,i,s);else{if(typeof e.getCurrentImageIdIndex!="function"||typeof e.scroll!="function")return;const r=e.getCurrentImageIdIndex();if(r+i>e.getImageIds().length-1||r+i<0){const a={imageIdIndex:r,direction:i};T(M,R.STACK_SCROLL_OUT_OF_BOUNDS,a)}e.scroll(i,t.debounceLoading,t.loop)}}function vo(e,t,n,o=!1){const i=o,{numScrollSteps:s,currentStepIndex:r,sliceRangeInfo:a}=Se(e,t,i);if(s===0||!a)return;const{sliceRange:c,spacingInNormalDirection:d,camera:l}=a,{focalPoint:u,viewPlaneNormal:f,position:m}=l,{newFocalPoint:w,newPosition:V}=be(u,m,c,f,d,n);e.setCamera({focalPoint:w,position:V}),e.render();const h=r+n,g={volumeId:t,viewport:e,delta:n,desiredStepIndex:h,currentStepIndex:r,numScrollSteps:s,currentImageId:e.getCurrentImageId()};(h>s||h<0)&&e.getCurrentImageId()?T(M,R.VOLUME_VIEWPORT_SCROLL_OUT_OF_BOUNDS,g):T(M,R.VOLUME_VIEWPORT_SCROLL,g)}async function Eo(e,t={}){const{imageIndex:n,debounceLoading:o,volumeId:i}=t,s=j(e);if(!s)throw new Error("Element has been disabled");const{viewport:r}=s,{imageIndex:a,numberOfSlices:c}=yo(r,o),l=Ro(c,n)-a;Oe(r,{delta:l,debounceLoading:o,volumeId:i})}function yo(e,t){return e instanceof Q?{numberOfSlices:e.getImageIds().length,imageIndex:t?e.getTargetImageIdIndex():e.getCurrentImageIdIndex()}:{numberOfSlices:e.getNumberOfSlices(),imageIndex:e.getSliceIndex()}}function Ro(e,t){const n=e-1;return De(t,0,n)}function Co(e,t,n={}){const o=O.getVolume(e);if(!o)throw new Error(`Referenced volume with id ${e} does not exist.`);const{metadata:i,spacing:s,direction:r,dimensions:a}=o,{minX:c,maxX:d,minY:l,maxY:u,minZ:f,maxZ:m}=t,w=[Math.min(c,d),Math.min(l,u),Math.min(f,m)],V=Z(o.imageData,w),h=[Math.abs(d-c)+1,Math.abs(u-l)+1,Math.abs(m-f)+1],{targetBuffer:g}=n,b={metadata:i,dimensions:h,spacing:s,origin:V,direction:r,targetBuffer:g,scalarData:g?.type==="Float32Array"?new Float32Array(h[0]*h[1]*h[2]):void 0},S=et(ee(),b),v=S.voxelManager.getCompleteScalarDataArray(),p=h[0]*h[1],y=a[0]*a[1],x=o.voxelManager.getCompleteScalarDataArray();for(let I=0;I<h[2];I++)for(let C=0;C<h[1];C++){const $=Z(S.imageData,[0,C,I]),_=ve(o.imageData,$),W=_[2]*y+_[1]*a[0]+_[0],q=x.slice(W,W+h[0]),A=I*p+C*h[0];v.set(q,A)}return S.voxelManager.setCompleteScalarDataArray(v),S}function Po(e,t){const{viewUp:n,viewPlaneNormal:o}=t,i=N(e,[0,0,0]),s=ae(E(),n),r=ae(E(),o),a=H(E(),s,r),c=D(E(),N(e,s),i),d=D(E(),N(e,r),i);L(c,c),L(d,d);const l=H(E(),c,d);return{worldVecRowDir:a,worldVecColDir:s,worldVecSliceDir:r,ijkVecRowDir:l,ijkVecColDir:c,ijkVecSliceDir:d}}function To(e,t,n,o){const[i,s,r]=t,a=i*s;let c=0,d=0,l=0;const[u,f,m]=n.map(Math.round);for(let g=m-o;g<=m+o;g++)if(!(g<0||g>=r)){for(let b=f-o;b<=f+o;b++)if(!(b<0||b>=s))for(let S=u-o;S<=u+o;S++){if(S<0||S>=i)continue;const v=g*a+b*i+S,p=e[v];c+=p,d+=p*p,l++}}if(l===0){const g=m*a+f*i+u;return g>=0&&g<e.length?{mean:e[g],stdDev:0,count:1}:{mean:0,stdDev:0,count:0}}const w=c/l,V=d/l-w*w,h=Math.sqrt(Math.max(0,V));return{mean:w,stdDev:h,count:l}}const de=1e-6;function xo(e,t){const{lower:n,upper:o}=t.voiRange,i=o-n,s=t.VOILUTFunction,r=a=>t.invert===!0?1-a:a;if(s===Ee.SAMPLED_SIGMOID||s==="SIGMOID"){const{windowCenter:a,windowWidth:c}=ye(n,o),d=Math.max(Math.abs(c),1e-12);return r(1/(1+Math.exp(-4*(e-a)/d)))}return i===0||!Number.isFinite(i)?r(0):r(U((e-n)/i))}function X(e,t){const{lower:n,upper:o}=t.voiRange,i=t.VOILUTFunction,s=t.invert===!0?U(1-U(e)):U(e);if(i===Ee.SAMPLED_SIGMOID||i==="SIGMOID"){const{windowCenter:a,windowWidth:c}=ye(n,o),d=_e(s,de,1-de);return tt(d,a,c)}const r=o-n;return r===0||!Number.isFinite(r)?n:n+s*r}function Mo(e,t,n){const o=Math.min(e,t),i=Math.max(e,t),s=X(o,n),r=X(i,n);return{rawMin:Math.min(s,r),rawMax:Math.max(s,r)}}function U(e){return Number.isFinite(e)?_e(e,0,1):0}function _e(e,t,n){return Math.min(n,Math.max(t,e))}const{getPixelSpacingInformation:Do,calculateRadiographicPixelSpacing:Oo,getERMF:_o}=nt,Lo=(e,t)=>Vo(e,t,O.getVolume),Wo=(e,t)=>Me(e,t,O.getVolume),zo=Object.freeze(Object.defineProperty({__proto__:null,ECGUtilities:ft,FrameRange:gt,HistoryMemo:mt,PointsManager:at,ProgressiveIterator:it,RLEVoxelMap:st,VideoUtilities:ht,VoxelManager:ot,WSIUtilities:pt,actorIsA:wt,applyPreset:It,asArray:Vt,autoLoad:St,buildMetadata:bt,calculateNeighborhoodStats:To,calculateRadiographicPixelSpacing:Oo,calculateSpacingBetweenImageIds:vt,calculateViewportsSpatialRegistration:so,calibratedPixelSpacingMetadataProvider:$n,clamp:ut,clip:De,clonePoint3:Et,color:wo,colormap:yt,convertColorArrayToRgbString:Rt,convertStackToVolumeViewport:co,convertToGrayscale:fo,convertVolumeToStackViewport:lo,createLinearRGBTransferFunction:Ct,createSigmoidRGBTransferFunction:Pt,createSubVolume:Co,decimate:Tt,deepClone:xt,deepEqual:Io,deepMerge:Mt,eventListener:Fn,fnv1aHash:Dt,generateFrameImageId:Ot,generateVolumePropsFromImageIds:_t,genericMetadataProvider:Lt,genericViewportDisplaySetMetadataProvider:Wt,getAcquisitionPlaneOrientation:At,getBufferConfiguration:kt,getClosestImageId:Ft,getClosestStackImageIndexForPoint:Qn,getCubeSizeInView:Nt,getCurrentVolumeViewportSlice:no,getDynamicVolumeInfo:So,getERMF:_o,getImageDataMetadata:Ut,getImageLegacy:ao,getImageSliceDataForVolumeViewport:Gt,getMinMax:Bt,getNormalizedAspectRatio:dt,getPixelSpacingInformation:Do,getRandomSampleFromArray:mo,getRuntimeId:zn,getScalingDescriptor:Wo,getScalingParameters:Ht,getSliceRange:zt,getSpacingInNormalDirection:jt,getTargetVolumeAndSpacingInNormalDir:$t,getVOIRangeFromWindowLevel:qt,getViewportContentMode:Jt,getViewportImageCornersInWorld:io,getViewportImageIds:go,getViewportModality:Lo,getViewportsWithImageURI:Yn,getViewportsWithVolumeId:Kt,getVoiFromSigmoidRGBTransferFunction:Zt,getVolumeActorCorners:Xt,getVolumeDirectionVectors:Po,getVolumeId:te,getVolumeSliceRangeInfo:Yt,getVolumeViewReferenceId:Qt,getVolumeViewportScrollInfo:Se,getVolumeViewportsContainingSameVolumes:Zn,handleMultiframe4D:en,hasFloatScalingParameters:tn,hasNaNValues:nn,hasOwn:on,imageIdToURI:sn,imageRetrieveMetadataProvider:ct,imageToWorldCoords:rn,indexAlmostWithinDimensions:Kn,indexWithinDimensions:Jn,invertRgbTransferFunction:an,isEqual:lt,isEqualAbs:cn,isEqualNegative:ln,isGenericViewport:Ie,isImageActor:dn,isNumber:un,isOpposite:qn,isPTPrescaledWithSUV:ge,isValidVolume:fn,isVideoTransferSyntax:gn,jumpToSlice:Eo,loadImageToCanvas:Xn,logger:rt,makeVolumeMetadata:mn,mapMappedBandToRawRange:Mo,mapScalarToViewportVoiIntensity:xo,mapViewportVoiIntensityToScalar:X,planar:hn,pointInShapeCallback:pn,renderToCanvasCPU:Ce,renderToCanvasGPU:Re,resolveGenericViewportVolumeId:xe,rotateToViewCoordinates:wn,roundNumber:Te,roundToPrecision:uo,scaleArray:bo,scaleRgbTransferFunction:Nn,scroll:Oe,snapFocalPointToSlice:be,sortImageIdsAndGetSpacing:In,spatialRegistrationMetadataProvider:pe,splitImageIdsBy4DTags:Ve,transferFunctionUtils:Vn,transformIndexToWorld:Z,transformWorldToIndex:ve,transformWorldToIndexContinuous:N,triggerEvent:T,updatePlaneRestriction:Sn,updateVTKImageDataWithCornerstoneImage:bn,uuidv4:ee,viewportIsInStackMode:vn,viewportIsInVolumeMode:En,viewportSupportsDisplaySetPresentation:yn,viewportSupportsImageSlices:he,viewportSupportsStackCalibration:Rn,viewportSupportsStackCompatibility:Cn,viewportSupportsVolumeActors:fe,viewportSupportsVolumeCompatibility:Pn,viewportSupportsVolumeId:Tn,viewportSupportsVolumeURI:xn,windowLevel:Mn,worldToImageCoords:Dn},Symbol.toStringTag,{value:"Module"}));export{Oe as A,no as B,De as C,qn as D,io as E,fo as F,On as G,kn as M,Wn as T,Ln as a,Pe as b,Bo as c,Ho as d,An as e,Go as f,j as g,Uo as h,zn as i,Io as j,mo as k,Wo as l,Yn as m,Kn as n,Qn as o,so as p,Eo as q,Te as r,_n as s,Jn as t,zo as u,No as v,uo as w,Po as x,Co as y,To as z};
@@ -1,5 +1,5 @@
1
1
  const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./blosc-CrUiACa7.js","./chunk-INHXZS53-D3tQiqtZ.js","./lz4-B_Exjfmr.js","./zstd-u5eweWyS.js"])))=>i.map(i=>d[i]);
2
- import{g as va}from"./_commonjsHelpers-CE1G-McA.js";import{_ as Mi}from"./index-COu2z5IR.js";var _t=1e-6,Ae=typeof Float32Array<"u"?Float32Array:Array;function qi(){var t=new Ae(9);return Ae!=Float32Array&&(t[1]=0,t[2]=0,t[3]=0,t[5]=0,t[6]=0,t[7]=0),t[0]=1,t[4]=1,t[8]=1,t}function wa(t,e){return t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=e[4],t[4]=e[5],t[5]=e[6],t[6]=e[8],t[7]=e[9],t[8]=e[10],t}function He(t,e,i,r,s,n,a,o,l){var c=new Ae(9);return c[0]=t,c[1]=e,c[2]=i,c[3]=r,c[4]=s,c[5]=n,c[6]=a,c[7]=o,c[8]=l,c}function ya(t,e){var i=e[0],r=e[1],s=e[2],n=e[3],a=e[4],o=e[5],l=e[6],c=e[7],h=e[8],d=h*a-o*c,f=-h*n+o*l,u=c*n-a*l,m=i*d+r*f+s*u;return m?(m=1/m,t[0]=d*m,t[1]=(-h*r+s*c)*m,t[2]=(o*r-s*a)*m,t[3]=f*m,t[4]=(h*i-s*l)*m,t[5]=(-o*i+s*n)*m,t[6]=u*m,t[7]=(-c*i+r*l)*m,t[8]=(a*i-r*n)*m,t):null}function Hs(t,e,i){var r=e[0],s=e[1],n=e[2],a=e[3],o=e[4],l=e[5],c=e[6],h=e[7],d=e[8],f=i[0],u=i[1],m=i[2],p=i[3],g=i[4],x=i[5],A=i[6],y=i[7],v=i[8];return t[0]=f*r+u*a+m*c,t[1]=f*s+u*o+m*h,t[2]=f*n+u*l+m*d,t[3]=p*r+g*a+x*c,t[4]=p*s+g*o+x*h,t[5]=p*n+g*l+x*d,t[6]=A*r+y*a+v*c,t[7]=A*s+y*o+v*h,t[8]=A*n+y*l+v*d,t}function J(){var t=new Ae(16);return Ae!=Float32Array&&(t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[11]=0,t[12]=0,t[13]=0,t[14]=0),t[0]=1,t[5]=1,t[10]=1,t[15]=1,t}function de(t){var e=new Ae(16);return e[0]=t[0],e[1]=t[1],e[2]=t[2],e[3]=t[3],e[4]=t[4],e[5]=t[5],e[6]=t[6],e[7]=t[7],e[8]=t[8],e[9]=t[9],e[10]=t[10],e[11]=t[11],e[12]=t[12],e[13]=t[13],e[14]=t[14],e[15]=t[15],e}function ba(t,e){return t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=e[3],t[4]=e[4],t[5]=e[5],t[6]=e[6],t[7]=e[7],t[8]=e[8],t[9]=e[9],t[10]=e[10],t[11]=e[11],t[12]=e[12],t[13]=e[13],t[14]=e[14],t[15]=e[15],t}function Ee(t,e,i,r,s,n,a,o,l,c,h,d,f,u,m,p){var g=new Ae(16);return g[0]=t,g[1]=e,g[2]=i,g[3]=r,g[4]=s,g[5]=n,g[6]=a,g[7]=o,g[8]=l,g[9]=c,g[10]=h,g[11]=d,g[12]=f,g[13]=u,g[14]=m,g[15]=p,g}function qs(t){return t[0]=1,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=1,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[10]=1,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t}function Te(t,e){if(t===e){var i=e[1],r=e[2],s=e[3],n=e[6],a=e[7],o=e[11];t[1]=e[4],t[2]=e[8],t[3]=e[12],t[4]=i,t[6]=e[9],t[7]=e[13],t[8]=r,t[9]=n,t[11]=e[14],t[12]=s,t[13]=a,t[14]=o}else t[0]=e[0],t[1]=e[4],t[2]=e[8],t[3]=e[12],t[4]=e[1],t[5]=e[5],t[6]=e[9],t[7]=e[13],t[8]=e[2],t[9]=e[6],t[10]=e[10],t[11]=e[14],t[12]=e[3],t[13]=e[7],t[14]=e[11],t[15]=e[15];return t}function Se(t,e){var i=e[0],r=e[1],s=e[2],n=e[3],a=e[4],o=e[5],l=e[6],c=e[7],h=e[8],d=e[9],f=e[10],u=e[11],m=e[12],p=e[13],g=e[14],x=e[15],A=i*o-r*a,y=i*l-s*a,v=i*c-n*a,b=r*l-s*o,w=r*c-n*o,C=s*c-n*l,M=h*p-d*m,T=h*g-f*m,E=h*x-u*m,I=d*g-f*p,S=d*x-u*p,U=f*x-u*g,B=A*U-y*S+v*I+b*E-w*T+C*M;return B?(B=1/B,t[0]=(o*U-l*S+c*I)*B,t[1]=(s*S-r*U-n*I)*B,t[2]=(p*C-g*w+x*b)*B,t[3]=(f*w-d*C-u*b)*B,t[4]=(l*E-a*U-c*T)*B,t[5]=(i*U-s*E+n*T)*B,t[6]=(g*v-m*C-x*y)*B,t[7]=(h*C-f*v+u*y)*B,t[8]=(a*S-o*E+c*M)*B,t[9]=(r*E-i*S-n*M)*B,t[10]=(m*w-p*v+x*A)*B,t[11]=(d*v-h*w-u*A)*B,t[12]=(o*T-a*I-l*M)*B,t[13]=(i*I-r*T+s*M)*B,t[14]=(p*y-m*b-g*A)*B,t[15]=(h*b-d*y+f*A)*B,t):null}function Ye(t,e,i){var r=e[0],s=e[1],n=e[2],a=e[3],o=e[4],l=e[5],c=e[6],h=e[7],d=e[8],f=e[9],u=e[10],m=e[11],p=e[12],g=e[13],x=e[14],A=e[15],y=i[0],v=i[1],b=i[2],w=i[3];return t[0]=y*r+v*o+b*d+w*p,t[1]=y*s+v*l+b*f+w*g,t[2]=y*n+v*c+b*u+w*x,t[3]=y*a+v*h+b*m+w*A,y=i[4],v=i[5],b=i[6],w=i[7],t[4]=y*r+v*o+b*d+w*p,t[5]=y*s+v*l+b*f+w*g,t[6]=y*n+v*c+b*u+w*x,t[7]=y*a+v*h+b*m+w*A,y=i[8],v=i[9],b=i[10],w=i[11],t[8]=y*r+v*o+b*d+w*p,t[9]=y*s+v*l+b*f+w*g,t[10]=y*n+v*c+b*u+w*x,t[11]=y*a+v*h+b*m+w*A,y=i[12],v=i[13],b=i[14],w=i[15],t[12]=y*r+v*o+b*d+w*p,t[13]=y*s+v*l+b*f+w*g,t[14]=y*n+v*c+b*u+w*x,t[15]=y*a+v*h+b*m+w*A,t}function tt(t,e,i){var r=i[0],s=i[1],n=i[2],a,o,l,c,h,d,f,u,m,p,g,x;return e===t?(t[12]=e[0]*r+e[4]*s+e[8]*n+e[12],t[13]=e[1]*r+e[5]*s+e[9]*n+e[13],t[14]=e[2]*r+e[6]*s+e[10]*n+e[14],t[15]=e[3]*r+e[7]*s+e[11]*n+e[15]):(a=e[0],o=e[1],l=e[2],c=e[3],h=e[4],d=e[5],f=e[6],u=e[7],m=e[8],p=e[9],g=e[10],x=e[11],t[0]=a,t[1]=o,t[2]=l,t[3]=c,t[4]=h,t[5]=d,t[6]=f,t[7]=u,t[8]=m,t[9]=p,t[10]=g,t[11]=x,t[12]=a*r+h*s+m*n+e[12],t[13]=o*r+d*s+p*n+e[13],t[14]=l*r+f*s+g*n+e[14],t[15]=c*r+u*s+x*n+e[15]),t}function fr(t,e,i){var r=i[0],s=i[1],n=i[2];return t[0]=e[0]*r,t[1]=e[1]*r,t[2]=e[2]*r,t[3]=e[3]*r,t[4]=e[4]*s,t[5]=e[5]*s,t[6]=e[6]*s,t[7]=e[7]*s,t[8]=e[8]*n,t[9]=e[9]*n,t[10]=e[10]*n,t[11]=e[11]*n,t[12]=e[12],t[13]=e[13],t[14]=e[14],t[15]=e[15],t}function Ut(t,e,i){var r=Math.sin(i),s=Math.cos(i),n=e[4],a=e[5],o=e[6],l=e[7],c=e[8],h=e[9],d=e[10],f=e[11];return e!==t&&(t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=e[3],t[12]=e[12],t[13]=e[13],t[14]=e[14],t[15]=e[15]),t[4]=n*s+c*r,t[5]=a*s+h*r,t[6]=o*s+d*r,t[7]=l*s+f*r,t[8]=c*s-n*r,t[9]=h*s-a*r,t[10]=d*s-o*r,t[11]=f*s-l*r,t}function Ca(t,e,i){var r=Math.sin(i),s=Math.cos(i),n=e[0],a=e[1],o=e[2],l=e[3],c=e[8],h=e[9],d=e[10],f=e[11];return e!==t&&(t[4]=e[4],t[5]=e[5],t[6]=e[6],t[7]=e[7],t[12]=e[12],t[13]=e[13],t[14]=e[14],t[15]=e[15]),t[0]=n*s-c*r,t[1]=a*s-h*r,t[2]=o*s-d*r,t[3]=l*s-f*r,t[8]=n*r+c*s,t[9]=a*r+h*s,t[10]=o*r+d*s,t[11]=l*r+f*s,t}function Rt(t,e,i){var r=Math.sin(i),s=Math.cos(i),n=e[0],a=e[1],o=e[2],l=e[3],c=e[4],h=e[5],d=e[6],f=e[7];return e!==t&&(t[8]=e[8],t[9]=e[9],t[10]=e[10],t[11]=e[11],t[12]=e[12],t[13]=e[13],t[14]=e[14],t[15]=e[15]),t[0]=n*s+c*r,t[1]=a*s+h*r,t[2]=o*s+d*r,t[3]=l*s+f*r,t[4]=c*s-n*r,t[5]=h*s-a*r,t[6]=d*s-o*r,t[7]=f*s-l*r,t}function Ma(t,e,i){var r=i[0],s=i[1],n=i[2],a=Math.sqrt(r*r+s*s+n*n),o,l,c;return a<_t?null:(a=1/a,r*=a,s*=a,n*=a,o=Math.sin(e),l=Math.cos(e),c=1-l,t[0]=r*r*c+l,t[1]=s*r*c+n*o,t[2]=n*r*c-s*o,t[3]=0,t[4]=r*s*c-n*o,t[5]=s*s*c+l,t[6]=n*s*c+r*o,t[7]=0,t[8]=r*n*c+s*o,t[9]=s*n*c-r*o,t[10]=n*n*c+l,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t)}function Da(t,e,i,r,s,n,a){var o=1/(e-i),l=1/(r-s),c=1/(n-a);return t[0]=-2*o,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=-2*l,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[10]=2*c,t[11]=0,t[12]=(e+i)*o,t[13]=(s+r)*l,t[14]=(a+n)*c,t[15]=1,t}var hi=Da;function Ta(t,e,i){return t[0]=e[0]*i,t[1]=e[1]*i,t[2]=e[2]*i,t[3]=e[3]*i,t[4]=e[4]*i,t[5]=e[5]*i,t[6]=e[6]*i,t[7]=e[7]*i,t[8]=e[8]*i,t[9]=e[9]*i,t[10]=e[10]*i,t[11]=e[11]*i,t[12]=e[12]*i,t[13]=e[13]*i,t[14]=e[14]*i,t[15]=e[15]*i,t}var Qs=Ye;function se(){var t=new Ae(3);return Ae!=Float32Array&&(t[0]=0,t[1]=0,t[2]=0),t}function Ve(t){var e=new Ae(3);return e[0]=t[0],e[1]=t[1],e[2]=t[2],e}function Qe(t){var e=t[0],i=t[1],r=t[2];return Math.sqrt(e*e+i*i+r*r)}function k(t,e,i){var r=new Ae(3);return r[0]=t,r[1]=e,r[2]=i,r}function Hr(t,e){return t[0]=e[0],t[1]=e[1],t[2]=e[2],t}function it(t,e,i){return t[0]=e[0]+i[0],t[1]=e[1]+i[1],t[2]=e[2]+i[2],t}function ne(t,e,i){return t[0]=e[0]-i[0],t[1]=e[1]-i[1],t[2]=e[2]-i[2],t}function ur(t,e,i){return t[0]=Math.min(e[0],i[0]),t[1]=Math.min(e[1],i[1]),t[2]=Math.min(e[2],i[2]),t}function mr(t,e,i){return t[0]=Math.max(e[0],i[0]),t[1]=Math.max(e[1],i[1]),t[2]=Math.max(e[2],i[2]),t}function Sa(t,e,i){return t[0]=e[0]*i,t[1]=e[1]*i,t[2]=e[2]*i,t}function Ea(t,e){var i=e[0]-t[0],r=e[1]-t[1],s=e[2]-t[2];return Math.sqrt(i*i+r*r+s*s)}function Ia(t,e){return t[0]=-e[0],t[1]=-e[1],t[2]=-e[2],t}function Ie(t,e){var i=e[0],r=e[1],s=e[2],n=i*i+r*r+s*s;return n>0&&(n=1/Math.sqrt(n)),t[0]=e[0]*n,t[1]=e[1]*n,t[2]=e[2]*n,t}function Fa(t,e){return t[0]*e[0]+t[1]*e[1]+t[2]*e[2]}function Jt(t,e,i){var r=e[0],s=e[1],n=e[2],a=i[0],o=i[1],l=i[2];return t[0]=s*l-n*o,t[1]=n*a-r*l,t[2]=r*o-s*a,t}function Ba(t,e,i,r){var s=e[0],n=e[1],a=e[2];return t[0]=s+r*(i[0]-s),t[1]=n+r*(i[1]-n),t[2]=a+r*(i[2]-a),t}function qr(t,e,i){var r=e[0],s=e[1],n=e[2];return t[0]=r*i[0]+s*i[3]+n*i[6],t[1]=r*i[1]+s*i[4]+n*i[7],t[2]=r*i[2]+s*i[5]+n*i[8],t}function Di(t,e){var i=t[0],r=t[1],s=t[2],n=e[0],a=e[1],o=e[2],l=Math.sqrt((i*i+r*r+s*s)*(n*n+a*a+o*o)),c=l&&Fa(t,e)/l;return Math.acos(Math.min(Math.max(c,-1),1))}function Ua(t,e){var i=t[0],r=t[1],s=t[2],n=e[0],a=e[1],o=e[2];return Math.abs(i-n)<=_t*Math.max(1,Math.abs(i),Math.abs(n))&&Math.abs(r-a)<=_t*Math.max(1,Math.abs(r),Math.abs(a))&&Math.abs(s-o)<=_t*Math.max(1,Math.abs(s),Math.abs(o))}var Qr=ne,Vt=Qe;(function(){var t=se();return function(e,i,r,s,n,a){var o,l;for(i||(i=3),r||(r=0),s?l=Math.min(s*i+r,e.length):l=e.length,o=r;o<l;o+=i)t[0]=e[o],t[1]=e[o+1],t[2]=e[o+2],n(t,t,a),e[o]=t[0],e[o+1]=t[1],e[o+2]=t[2];return e}})();function Xe(){var t=new Ae(4);return Ae!=Float32Array&&(t[0]=0,t[1]=0,t[2]=0,t[3]=0),t}function ze(t){var e=new Ae(4);return e[0]=t[0],e[1]=t[1],e[2]=t[2],e[3]=t[3],e}function ae(t,e,i,r){var s=new Ae(4);return s[0]=t,s[1]=e,s[2]=i,s[3]=r,s}function Zr(t,e,i){return t[0]=e[0]+i[0],t[1]=e[1]+i[1],t[2]=e[2]+i[2],t[3]=e[3]+i[3],t}function Ra(t,e,i){return t[0]=e[0]-i[0],t[1]=e[1]-i[1],t[2]=e[2]-i[2],t[3]=e[3]-i[3],t}function Va(t,e,i){return t[0]=e[0]*i,t[1]=e[1]*i,t[2]=e[2]*i,t[3]=e[3]*i,t}function ve(t,e,i){var r=e[0],s=e[1],n=e[2],a=e[3];return t[0]=i[0]*r+i[4]*s+i[8]*n+i[12]*a,t[1]=i[1]*r+i[5]*s+i[9]*n+i[13]*a,t[2]=i[2]*r+i[6]*s+i[10]*n+i[14]*a,t[3]=i[3]*r+i[7]*s+i[11]*n+i[15]*a,t}var Pa=Ra;(function(){var t=Xe();return function(e,i,r,s,n,a){var o,l;for(i||(i=4),r||(r=0),s?l=Math.min(s*i+r,e.length):l=e.length,o=r;o<l;o+=i)t[0]=e[o],t[1]=e[o+1],t[2]=e[o+2],t[3]=e[o+3],n(t,t,a),e[o]=t[0],e[o+1]=t[1],e[o+2]=t[2],e[o+3]=t[3];return e}})();function Na(){var t=new Ae(2);return Ae!=Float32Array&&(t[0]=0,t[1]=0),t}function La(t,e){var i=new Ae(2);return i[0]=t,i[1]=e,i}(function(){var t=Na();return function(e,i,r,s,n,a){var o,l;for(i||(i=2),r||(r=0),s?l=Math.min(s*i+r,e.length):l=e.length,o=r;o<l;o+=i)t[0]=e[o],t[1]=e[o+1],n(t,t,a),e[o]=t[0],e[o+1]=t[1];return e}})();var et=256,$t=[],Yt;for(;et--;)$t[et]=(et+256).toString(16).substring(1);function di(){var t=0,e,i="";if(!Yt||et+16>256){for(Yt=Array(t=256);t--;)Yt[t]=256*Math.random()|0;t=et=0}for(;t<16;t++)e=Yt[et+t],t==6?i+=$t[e&15|64]:t==8?i+=$t[e&63|128]:i+=$t[e],t&1&&t>1&&t<11&&(i+="-");return et++,i}var Ti,jr;function ka(){return jr||(jr=1,Ti=function(e,i){var r=e.length;if(e===i)return!0;if(r!==i.length)return!1;for(var s=0;s<r;s++)if(e[s]!==i[s])return!1;return!0}),Ti}var Oa=ka();const za=va(Oa);var ge=Uint8Array,ut=Uint16Array,Ga=Int32Array,Zs=new ge([0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0,0,0,0]),js=new ge([0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13,0,0]),Ya=new ge([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),_s=function(t,e){for(var i=new ut(31),r=0;r<31;++r)i[r]=e+=1<<t[r-1];for(var s=new Ga(i[30]),r=1;r<30;++r)for(var n=i[r];n<i[r+1];++n)s[n]=n-i[r]<<5|r;return{b:i,r:s}},Js=_s(Zs,2),$s=Js.b,Xa=Js.r;$s[28]=258,Xa[258]=28;var Wa=_s(js,0),Ka=Wa.b,Qi=new ut(32768);for(var oe=0;oe<32768;++oe){var We=(oe&43690)>>1|(oe&21845)<<1;We=(We&52428)>>2|(We&13107)<<2,We=(We&61680)>>4|(We&3855)<<4,Qi[oe]=((We&65280)>>8|(We&255)<<8)>>1}var Ft=(function(t,e,i){for(var r=t.length,s=0,n=new ut(e);s<r;++s)t[s]&&++n[t[s]-1];var a=new ut(e);for(s=1;s<e;++s)a[s]=a[s-1]+n[s-1]<<1;var o;if(i){o=new ut(1<<e);var l=15-e;for(s=0;s<r;++s)if(t[s])for(var c=s<<4|t[s],h=e-t[s],d=a[t[s]-1]++<<h,f=d|(1<<h)-1;d<=f;++d)o[Qi[d]>>l]=c}else for(o=new ut(r),s=0;s<r;++s)t[s]&&(o[s]=Qi[a[t[s]-1]++]>>15-t[s]);return o}),Pt=new ge(288);for(var oe=0;oe<144;++oe)Pt[oe]=8;for(var oe=144;oe<256;++oe)Pt[oe]=9;for(var oe=256;oe<280;++oe)Pt[oe]=7;for(var oe=280;oe<288;++oe)Pt[oe]=8;var en=new ge(32);for(var oe=0;oe<32;++oe)en[oe]=5;var Ha=Ft(Pt,9,1),qa=Ft(en,5,1),Si=function(t){for(var e=t[0],i=1;i<t.length;++i)t[i]>e&&(e=t[i]);return e},Be=function(t,e,i){var r=e/8|0;return(t[r]|t[r+1]<<8)>>(e&7)&i},Ei=function(t,e){var i=e/8|0;return(t[i]|t[i+1]<<8|t[i+2]<<16)>>(e&7)},tn=function(t){return(t+7)/8|0},ei=function(t,e,i){return(e==null||e<0)&&(e=0),(i==null||i>t.length)&&(i=t.length),new ge(t.subarray(e,i))},Qa=["unexpected EOF","invalid block type","invalid length/literal","invalid distance","stream finished","no stream handler",,"no callback","invalid UTF-8 data","extra field too long","date not in range 1980-2099","filename too long","stream finishing","invalid zip data"],ye=function(t,e,i){var r=new Error(e||Qa[t]);if(r.code=t,Error.captureStackTrace&&Error.captureStackTrace(r,ye),!i)throw r;return r},Ai=function(t,e,i,r){var s=t.length,n=0;if(!s||e.f&&!e.l)return i||new ge(0);var a=!i,o=a||e.i!=2,l=e.i;a&&(i=new ge(s*3));var c=function(at){var _e=i.length;if(at>_e){var Fe=new ge(Math.max(_e*2,at));Fe.set(i),i=Fe}},h=e.f||0,d=e.p||0,f=e.b||0,u=e.l,m=e.d,p=e.m,g=e.n,x=s*8;do{if(!u){h=Be(t,d,1);var A=Be(t,d+1,3);if(d+=3,A)if(A==1)u=Ha,m=qa,p=9,g=5;else if(A==2){var w=Be(t,d,31)+257,C=Be(t,d+10,15)+4,M=w+Be(t,d+5,31)+1;d+=14;for(var T=new ge(M),E=new ge(19),I=0;I<C;++I)E[Ya[I]]=Be(t,d+I*3,7);d+=C*3;for(var S=Si(E),U=(1<<S)-1,B=Ft(E,S,1),I=0;I<M;){var V=B[Be(t,d,U)];d+=V&15;var y=V>>4;if(y<16)T[I++]=y;else{var R=0,P=0;for(y==16?(P=3+Be(t,d,3),d+=2,R=T[I-1]):y==17?(P=3+Be(t,d,7),d+=3):y==18&&(P=11+Be(t,d,127),d+=7);P--;)T[I++]=R}}var L=T.subarray(0,w),N=T.subarray(w);p=Si(L),g=Si(N),u=Ft(L,p,1),m=Ft(N,g,1)}else ye(1);else{var y=tn(d)+4,v=t[y-4]|t[y-3]<<8,b=y+v;if(b>s){l&&ye(0);break}o&&c(f+v),i.set(t.subarray(y,b),f),e.b=f+=v,e.p=d=b*8,e.f=h;continue}if(d>x){l&&ye(0);break}}o&&c(f+131072);for(var Y=(1<<p)-1,_=(1<<g)-1,z=d;;z=d){var R=u[Ei(t,d)&Y],W=R>>4;if(d+=R&15,d>x){l&&ye(0);break}if(R||ye(2),W<256)i[f++]=W;else if(W==256){z=d,u=null;break}else{var K=W-254;if(W>264){var I=W-257,Z=Zs[I];K=Be(t,d,(1<<Z)-1)+$s[I],d+=Z}var q=m[Ei(t,d)&_],te=q>>4;q||ye(3),d+=q&15;var N=Ka[te];if(te>3){var Z=js[te];N+=Ei(t,d)&(1<<Z)-1,d+=Z}if(d>x){l&&ye(0);break}o&&c(f+131072);var ue=f+K;if(f<N){var le=n-N,je=Math.min(N,ue);for(le+f<0&&ye(3);f<je;++f)i[f]=r[le+f]}for(;f<ue;++f)i[f]=i[f-N]}}e.l=u,e.p=z,e.b=f,e.f=h,u&&(h=1,e.m=p,e.d=m,e.n=g)}while(!h);return f!=i.length&&a?ei(i,0,f):i.subarray(0,f)},Za=new ge(0),rn=function(t){(t[0]!=31||t[1]!=139||t[2]!=8)&&ye(6,"invalid gzip data");var e=t[3],i=10;e&4&&(i+=(t[10]|t[11]<<8)+2);for(var r=(e>>3&1)+(e>>4&1);r>0;r-=!t[i++]);return i+(e&2)},ja=function(t){var e=t.length;return(t[e-4]|t[e-3]<<8|t[e-2]<<16|t[e-1]<<24)>>>0},_a=function(t,e){return((t[0]&15)!=8||t[0]>>4>7||(t[0]<<8|t[1])%31)&&ye(6,"invalid zlib data"),(t[1]>>5&1)==1&&ye(6,"invalid zlib data: "+(t[1]&32?"need":"unexpected")+" dictionary"),(t[1]>>3&4)+2},Xt=(function(){function t(e,i){typeof e=="function"&&(i=e,e={}),this.ondata=i;var r=e&&e.dictionary&&e.dictionary.subarray(-32768);this.s={i:0,b:r?r.length:0},this.o=new ge(32768),this.p=new ge(0),r&&this.o.set(r)}return t.prototype.e=function(e){if(this.ondata||ye(5),this.d&&ye(4),!this.p.length)this.p=e;else if(e.length){var i=new ge(this.p.length+e.length);i.set(this.p),i.set(e,this.p.length),this.p=i}},t.prototype.c=function(e){this.s.i=+(this.d=e||!1);var i=this.s.b,r=Ai(this.p,this.s,this.o);this.ondata(ei(r,i,this.s.b),this.d),this.o=ei(r,this.s.b-32768),this.s.b=this.o.length,this.p=ei(this.p,this.s.p/8|0),this.s.p&=7},t.prototype.push=function(e,i){this.e(e),this.c(i)},t})();function Ja(t,e){return Ai(t,{i:2},e,e)}var $a=(function(){function t(e,i){this.v=1,this.r=0,Xt.call(this,e,i)}return t.prototype.push=function(e,i){if(Xt.prototype.e.call(this,e),this.r+=e.length,this.v){var r=this.p.subarray(this.v-1),s=r.length>3?rn(r):4;if(s>r.length){if(!i)return}else this.v>1&&this.onmember&&this.onmember(this.r-r.length);this.p=r.subarray(s),this.v=0}Xt.prototype.c.call(this,0),this.s.f&&!this.s.l?(this.v=tn(this.s.p)+9,this.s={i:0},this.o=new ge(0),this.push(new ge(0),i)):i&&Xt.prototype.c.call(this,i)},t})();function eo(t,e){var i=rn(t);return i+8>t.length&&ye(6,"invalid gzip data"),Ai(t.subarray(i,-8),{i:2},new ge(ja(t)),e)}function to(t,e){return Ai(t.subarray(_a(t),-4),{i:2},e,e)}function io(t,e){return t[0]==31&&t[1]==139&&t[2]==8?eo(t,e):(t[0]&15)!=8||t[0]>>4>7||(t[0]<<8|t[1])%31?Ja(t,e):to(t,e)}var ro=typeof TextDecoder<"u"&&new TextDecoder,so=0;try{ro.decode(Za,{stream:!0}),so=1}catch{}class sn{esize;ecode;edata;littleEndian;constructor(e,i,r,s){if(e%16!=0)throw new Error("This does not appear to be a NIFTI extension");this.esize=e,this.ecode=i,this.edata=r,this.littleEndian=s}toArrayBuffer(){let e=new Uint8Array(this.esize),i=new Uint8Array(this.edata);e.set(i,8);let r=new DataView(e.buffer);return r.setInt32(0,this.esize,this.littleEndian),r.setInt32(4,this.ecode,this.littleEndian),e.buffer}}class O{static crcTable=null;static GUNZIP_MAGIC_COOKIE1=31;static GUNZIP_MAGIC_COOKIE2=139;static getStringAt(e,i,r){var s="",n,a;for(n=i;n<r;n+=1)a=e.getUint8(n),a!==0&&(s+=String.fromCharCode(a));return s}static getByteAt=function(e,i){return e.getUint8(i)};static getShortAt=function(e,i,r){return e.getInt16(i,r)};static getIntAt(e,i,r){return e.getInt32(i,r)}static getFloatAt(e,i,r){return e.getFloat32(i,r)}static getDoubleAt(e,i,r){return e.getFloat64(i,r)}static getInt64At(e,i,r){const s=e.getUint32(i,r),n=e.getInt32(i+4,r);let a;return r?a=n*2**32+s:a=s*2**32+n,n<0&&(a+=-1*2**32*2**32),a}static getUint64At(e,i,r){const s=e.getUint32(i+(r?0:4),r),n=e.getUint32(i+(r?4:0),r);return r?n*2**32+s:s*2**32+n}static getExtensionsAt(e,i,r,s){let n=[],a=i;for(;a<s;){let o=r,l=O.getIntAt(e,a,r);if(!l)break;if(l+a>s&&(o=!o,l=O.getIntAt(e,a,o),l+a>s))throw new Error("This does not appear to be a valid NIFTI extension");if(l%16!=0)throw new Error("This does not appear to be a NIFTI extension");let c=O.getIntAt(e,a+4,o),h=e.buffer.slice(a+8,a+l),d=new sn(l,c,h,o);n.push(d),a+=l}return n}static toArrayBuffer(e){var i,r,s;for(i=new ArrayBuffer(e.length),r=new Uint8Array(i),s=0;s<e.length;s+=1)r[s]=e[s];return i}static isString(e){return typeof e=="string"||e instanceof String}static formatNumber(e,i=void 0){let r;return O.isString(e)?r=Number(e):r=e,i?r=r.toPrecision(5):r=r.toPrecision(7),parseFloat(r)}static makeCRCTable(){let e,i=[];for(var r=0;r<256;r++){e=r;for(var s=0;s<8;s++)e=e&1?3988292384^e>>>1:e>>>1;i[r]=e}return i}static crc32(e){O.crcTable||(O.crcTable=O.makeCRCTable());const i=O.crcTable;let r=-1;for(var s=0;s<e.byteLength;s++)r=r>>>8^i[(r^e.getUint8(s))&255];return(r^-1)>>>0}}class G{littleEndian=!1;dim_info=0;dims=[];intent_p1=0;intent_p2=0;intent_p3=0;intent_code=0;datatypeCode=0;numBitsPerVoxel=0;slice_start=0;slice_end=0;slice_code=0;pixDims=[];vox_offset=0;scl_slope=1;scl_inter=0;xyzt_units=0;cal_max=0;cal_min=0;slice_duration=0;toffset=0;description="";aux_file="";intent_name="";qform_code=0;sform_code=0;quatern_a=0;quatern_b=0;quatern_c=0;quatern_d=0;qoffset_x=0;qoffset_y=0;qoffset_z=0;affine=[[1,0,0,0],[0,1,0,0],[0,0,1,0],[0,0,0,1]];qfac=1;quatern_R;magic="0";isHDR=!1;extensionFlag=[0,0,0,0];extensionSize=0;extensionCode=0;extensions=[];static TYPE_NONE=0;static TYPE_BINARY=1;static TYPE_UINT8=2;static TYPE_INT16=4;static TYPE_INT32=8;static TYPE_FLOAT32=16;static TYPE_COMPLEX64=32;static TYPE_FLOAT64=64;static TYPE_RGB24=128;static TYPE_INT8=256;static TYPE_UINT16=512;static TYPE_UINT32=768;static TYPE_INT64=1024;static TYPE_UINT64=1280;static TYPE_FLOAT128=1536;static TYPE_COMPLEX128=1792;static TYPE_COMPLEX256=2048;static XFORM_UNKNOWN=0;static XFORM_SCANNER_ANAT=1;static XFORM_ALIGNED_ANAT=2;static XFORM_TALAIRACH=3;static XFORM_MNI_152=4;static SPATIAL_UNITS_MASK=7;static TEMPORAL_UNITS_MASK=56;static UNITS_UNKNOWN=0;static UNITS_METER=1;static UNITS_MM=2;static UNITS_MICRON=3;static UNITS_SEC=8;static UNITS_MSEC=16;static UNITS_USEC=24;static UNITS_HZ=32;static UNITS_PPM=40;static UNITS_RADS=48;static MAGIC_COOKIE=348;static STANDARD_HEADER_SIZE=348;static MAGIC_NUMBER_LOCATION=344;static MAGIC_NUMBER=[110,43,49];static MAGIC_NUMBER2=[110,105,49];static EXTENSION_HEADER_SIZE=8;readHeader(e){var i=new DataView(e),r=O.getIntAt(i,0,this.littleEndian),s,n,a,o;if(r!==G.MAGIC_COOKIE&&(this.littleEndian=!0,r=O.getIntAt(i,0,this.littleEndian)),r!==G.MAGIC_COOKIE)throw new Error("This does not appear to be a NIFTI file!");for(this.dim_info=O.getByteAt(i,39),s=0;s<8;s+=1)o=40+s*2,this.dims[s]=O.getShortAt(i,o,this.littleEndian);for(this.intent_p1=O.getFloatAt(i,56,this.littleEndian),this.intent_p2=O.getFloatAt(i,60,this.littleEndian),this.intent_p3=O.getFloatAt(i,64,this.littleEndian),this.intent_code=O.getShortAt(i,68,this.littleEndian),this.datatypeCode=O.getShortAt(i,70,this.littleEndian),this.numBitsPerVoxel=O.getShortAt(i,72,this.littleEndian),this.slice_start=O.getShortAt(i,74,this.littleEndian),s=0;s<8;s+=1)o=76+s*4,this.pixDims[s]=O.getFloatAt(i,o,this.littleEndian);if(this.vox_offset=O.getFloatAt(i,108,this.littleEndian),this.scl_slope=O.getFloatAt(i,112,this.littleEndian),this.scl_inter=O.getFloatAt(i,116,this.littleEndian),this.slice_end=O.getShortAt(i,120,this.littleEndian),this.slice_code=O.getByteAt(i,122),this.xyzt_units=O.getByteAt(i,123),this.cal_max=O.getFloatAt(i,124,this.littleEndian),this.cal_min=O.getFloatAt(i,128,this.littleEndian),this.slice_duration=O.getFloatAt(i,132,this.littleEndian),this.toffset=O.getFloatAt(i,136,this.littleEndian),this.description=O.getStringAt(i,148,228),this.aux_file=O.getStringAt(i,228,252),this.qform_code=O.getShortAt(i,252,this.littleEndian),this.sform_code=O.getShortAt(i,254,this.littleEndian),this.quatern_b=O.getFloatAt(i,256,this.littleEndian),this.quatern_c=O.getFloatAt(i,260,this.littleEndian),this.quatern_d=O.getFloatAt(i,264,this.littleEndian),this.quatern_a=Math.sqrt(1-(Math.pow(this.quatern_b,2)+Math.pow(this.quatern_c,2)+Math.pow(this.quatern_d,2))),this.qoffset_x=O.getFloatAt(i,268,this.littleEndian),this.qoffset_y=O.getFloatAt(i,272,this.littleEndian),this.qoffset_z=O.getFloatAt(i,276,this.littleEndian),this.qform_code<1&&this.sform_code<1&&(this.affine[0][0]=this.pixDims[1],this.affine[1][1]=this.pixDims[2],this.affine[2][2]=this.pixDims[3]),this.qform_code>0&&this.sform_code<this.qform_code){const l=this.quatern_a,c=this.quatern_b,h=this.quatern_c,d=this.quatern_d;for(this.qfac=this.pixDims[0]===0?1:this.pixDims[0],this.quatern_R=[[l*l+c*c-h*h-d*d,2*c*h-2*l*d,2*c*d+2*l*h],[2*c*h+2*l*d,l*l+h*h-c*c-d*d,2*h*d-2*l*c],[2*c*d-2*l*h,2*h*d+2*l*c,l*l+d*d-h*h-c*c]],n=0;n<3;n+=1)for(a=0;a<3;a+=1)this.affine[n][a]=this.quatern_R[n][a]*this.pixDims[a+1],a===2&&(this.affine[n][a]*=this.qfac);this.affine[0][3]=this.qoffset_x,this.affine[1][3]=this.qoffset_y,this.affine[2][3]=this.qoffset_z}else if(this.sform_code>0)for(n=0;n<3;n+=1)for(a=0;a<4;a+=1)o=280+(n*4+a)*4,this.affine[n][a]=O.getFloatAt(i,o,this.littleEndian);if(this.affine[3][0]=0,this.affine[3][1]=0,this.affine[3][2]=0,this.affine[3][3]=1,this.intent_name=O.getStringAt(i,328,344),this.magic=O.getStringAt(i,344,348),this.isHDR=this.magic===String.fromCharCode.apply(null,G.MAGIC_NUMBER2),i.byteLength>G.MAGIC_COOKIE){this.extensionFlag[0]=O.getByteAt(i,348),this.extensionFlag[1]=O.getByteAt(i,349),this.extensionFlag[2]=O.getByteAt(i,350),this.extensionFlag[3]=O.getByteAt(i,351);let l=!0;!this.isHDR&&this.vox_offset<=352&&(l=!1),i.byteLength<=368&&(l=!1),l&&this.extensionFlag[0]&&(this.extensions=O.getExtensionsAt(i,this.getExtensionLocation(),this.littleEndian,this.vox_offset),this.extensionSize=this.extensions[0].esize,this.extensionCode=this.extensions[0].ecode)}}toFormattedString(){var e=O.formatNumber,i="";return i+="Dim Info = "+this.dim_info+`
2
+ import{g as va}from"./_commonjsHelpers-CE1G-McA.js";import{_ as Mi}from"./index-CD_iMftv.js";var _t=1e-6,Ae=typeof Float32Array<"u"?Float32Array:Array;function qi(){var t=new Ae(9);return Ae!=Float32Array&&(t[1]=0,t[2]=0,t[3]=0,t[5]=0,t[6]=0,t[7]=0),t[0]=1,t[4]=1,t[8]=1,t}function wa(t,e){return t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=e[4],t[4]=e[5],t[5]=e[6],t[6]=e[8],t[7]=e[9],t[8]=e[10],t}function He(t,e,i,r,s,n,a,o,l){var c=new Ae(9);return c[0]=t,c[1]=e,c[2]=i,c[3]=r,c[4]=s,c[5]=n,c[6]=a,c[7]=o,c[8]=l,c}function ya(t,e){var i=e[0],r=e[1],s=e[2],n=e[3],a=e[4],o=e[5],l=e[6],c=e[7],h=e[8],d=h*a-o*c,f=-h*n+o*l,u=c*n-a*l,m=i*d+r*f+s*u;return m?(m=1/m,t[0]=d*m,t[1]=(-h*r+s*c)*m,t[2]=(o*r-s*a)*m,t[3]=f*m,t[4]=(h*i-s*l)*m,t[5]=(-o*i+s*n)*m,t[6]=u*m,t[7]=(-c*i+r*l)*m,t[8]=(a*i-r*n)*m,t):null}function Hs(t,e,i){var r=e[0],s=e[1],n=e[2],a=e[3],o=e[4],l=e[5],c=e[6],h=e[7],d=e[8],f=i[0],u=i[1],m=i[2],p=i[3],g=i[4],x=i[5],A=i[6],y=i[7],v=i[8];return t[0]=f*r+u*a+m*c,t[1]=f*s+u*o+m*h,t[2]=f*n+u*l+m*d,t[3]=p*r+g*a+x*c,t[4]=p*s+g*o+x*h,t[5]=p*n+g*l+x*d,t[6]=A*r+y*a+v*c,t[7]=A*s+y*o+v*h,t[8]=A*n+y*l+v*d,t}function J(){var t=new Ae(16);return Ae!=Float32Array&&(t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[11]=0,t[12]=0,t[13]=0,t[14]=0),t[0]=1,t[5]=1,t[10]=1,t[15]=1,t}function de(t){var e=new Ae(16);return e[0]=t[0],e[1]=t[1],e[2]=t[2],e[3]=t[3],e[4]=t[4],e[5]=t[5],e[6]=t[6],e[7]=t[7],e[8]=t[8],e[9]=t[9],e[10]=t[10],e[11]=t[11],e[12]=t[12],e[13]=t[13],e[14]=t[14],e[15]=t[15],e}function ba(t,e){return t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=e[3],t[4]=e[4],t[5]=e[5],t[6]=e[6],t[7]=e[7],t[8]=e[8],t[9]=e[9],t[10]=e[10],t[11]=e[11],t[12]=e[12],t[13]=e[13],t[14]=e[14],t[15]=e[15],t}function Ee(t,e,i,r,s,n,a,o,l,c,h,d,f,u,m,p){var g=new Ae(16);return g[0]=t,g[1]=e,g[2]=i,g[3]=r,g[4]=s,g[5]=n,g[6]=a,g[7]=o,g[8]=l,g[9]=c,g[10]=h,g[11]=d,g[12]=f,g[13]=u,g[14]=m,g[15]=p,g}function qs(t){return t[0]=1,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=1,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[10]=1,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t}function Te(t,e){if(t===e){var i=e[1],r=e[2],s=e[3],n=e[6],a=e[7],o=e[11];t[1]=e[4],t[2]=e[8],t[3]=e[12],t[4]=i,t[6]=e[9],t[7]=e[13],t[8]=r,t[9]=n,t[11]=e[14],t[12]=s,t[13]=a,t[14]=o}else t[0]=e[0],t[1]=e[4],t[2]=e[8],t[3]=e[12],t[4]=e[1],t[5]=e[5],t[6]=e[9],t[7]=e[13],t[8]=e[2],t[9]=e[6],t[10]=e[10],t[11]=e[14],t[12]=e[3],t[13]=e[7],t[14]=e[11],t[15]=e[15];return t}function Se(t,e){var i=e[0],r=e[1],s=e[2],n=e[3],a=e[4],o=e[5],l=e[6],c=e[7],h=e[8],d=e[9],f=e[10],u=e[11],m=e[12],p=e[13],g=e[14],x=e[15],A=i*o-r*a,y=i*l-s*a,v=i*c-n*a,b=r*l-s*o,w=r*c-n*o,C=s*c-n*l,M=h*p-d*m,T=h*g-f*m,E=h*x-u*m,I=d*g-f*p,S=d*x-u*p,U=f*x-u*g,B=A*U-y*S+v*I+b*E-w*T+C*M;return B?(B=1/B,t[0]=(o*U-l*S+c*I)*B,t[1]=(s*S-r*U-n*I)*B,t[2]=(p*C-g*w+x*b)*B,t[3]=(f*w-d*C-u*b)*B,t[4]=(l*E-a*U-c*T)*B,t[5]=(i*U-s*E+n*T)*B,t[6]=(g*v-m*C-x*y)*B,t[7]=(h*C-f*v+u*y)*B,t[8]=(a*S-o*E+c*M)*B,t[9]=(r*E-i*S-n*M)*B,t[10]=(m*w-p*v+x*A)*B,t[11]=(d*v-h*w-u*A)*B,t[12]=(o*T-a*I-l*M)*B,t[13]=(i*I-r*T+s*M)*B,t[14]=(p*y-m*b-g*A)*B,t[15]=(h*b-d*y+f*A)*B,t):null}function Ye(t,e,i){var r=e[0],s=e[1],n=e[2],a=e[3],o=e[4],l=e[5],c=e[6],h=e[7],d=e[8],f=e[9],u=e[10],m=e[11],p=e[12],g=e[13],x=e[14],A=e[15],y=i[0],v=i[1],b=i[2],w=i[3];return t[0]=y*r+v*o+b*d+w*p,t[1]=y*s+v*l+b*f+w*g,t[2]=y*n+v*c+b*u+w*x,t[3]=y*a+v*h+b*m+w*A,y=i[4],v=i[5],b=i[6],w=i[7],t[4]=y*r+v*o+b*d+w*p,t[5]=y*s+v*l+b*f+w*g,t[6]=y*n+v*c+b*u+w*x,t[7]=y*a+v*h+b*m+w*A,y=i[8],v=i[9],b=i[10],w=i[11],t[8]=y*r+v*o+b*d+w*p,t[9]=y*s+v*l+b*f+w*g,t[10]=y*n+v*c+b*u+w*x,t[11]=y*a+v*h+b*m+w*A,y=i[12],v=i[13],b=i[14],w=i[15],t[12]=y*r+v*o+b*d+w*p,t[13]=y*s+v*l+b*f+w*g,t[14]=y*n+v*c+b*u+w*x,t[15]=y*a+v*h+b*m+w*A,t}function tt(t,e,i){var r=i[0],s=i[1],n=i[2],a,o,l,c,h,d,f,u,m,p,g,x;return e===t?(t[12]=e[0]*r+e[4]*s+e[8]*n+e[12],t[13]=e[1]*r+e[5]*s+e[9]*n+e[13],t[14]=e[2]*r+e[6]*s+e[10]*n+e[14],t[15]=e[3]*r+e[7]*s+e[11]*n+e[15]):(a=e[0],o=e[1],l=e[2],c=e[3],h=e[4],d=e[5],f=e[6],u=e[7],m=e[8],p=e[9],g=e[10],x=e[11],t[0]=a,t[1]=o,t[2]=l,t[3]=c,t[4]=h,t[5]=d,t[6]=f,t[7]=u,t[8]=m,t[9]=p,t[10]=g,t[11]=x,t[12]=a*r+h*s+m*n+e[12],t[13]=o*r+d*s+p*n+e[13],t[14]=l*r+f*s+g*n+e[14],t[15]=c*r+u*s+x*n+e[15]),t}function fr(t,e,i){var r=i[0],s=i[1],n=i[2];return t[0]=e[0]*r,t[1]=e[1]*r,t[2]=e[2]*r,t[3]=e[3]*r,t[4]=e[4]*s,t[5]=e[5]*s,t[6]=e[6]*s,t[7]=e[7]*s,t[8]=e[8]*n,t[9]=e[9]*n,t[10]=e[10]*n,t[11]=e[11]*n,t[12]=e[12],t[13]=e[13],t[14]=e[14],t[15]=e[15],t}function Ut(t,e,i){var r=Math.sin(i),s=Math.cos(i),n=e[4],a=e[5],o=e[6],l=e[7],c=e[8],h=e[9],d=e[10],f=e[11];return e!==t&&(t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=e[3],t[12]=e[12],t[13]=e[13],t[14]=e[14],t[15]=e[15]),t[4]=n*s+c*r,t[5]=a*s+h*r,t[6]=o*s+d*r,t[7]=l*s+f*r,t[8]=c*s-n*r,t[9]=h*s-a*r,t[10]=d*s-o*r,t[11]=f*s-l*r,t}function Ca(t,e,i){var r=Math.sin(i),s=Math.cos(i),n=e[0],a=e[1],o=e[2],l=e[3],c=e[8],h=e[9],d=e[10],f=e[11];return e!==t&&(t[4]=e[4],t[5]=e[5],t[6]=e[6],t[7]=e[7],t[12]=e[12],t[13]=e[13],t[14]=e[14],t[15]=e[15]),t[0]=n*s-c*r,t[1]=a*s-h*r,t[2]=o*s-d*r,t[3]=l*s-f*r,t[8]=n*r+c*s,t[9]=a*r+h*s,t[10]=o*r+d*s,t[11]=l*r+f*s,t}function Rt(t,e,i){var r=Math.sin(i),s=Math.cos(i),n=e[0],a=e[1],o=e[2],l=e[3],c=e[4],h=e[5],d=e[6],f=e[7];return e!==t&&(t[8]=e[8],t[9]=e[9],t[10]=e[10],t[11]=e[11],t[12]=e[12],t[13]=e[13],t[14]=e[14],t[15]=e[15]),t[0]=n*s+c*r,t[1]=a*s+h*r,t[2]=o*s+d*r,t[3]=l*s+f*r,t[4]=c*s-n*r,t[5]=h*s-a*r,t[6]=d*s-o*r,t[7]=f*s-l*r,t}function Ma(t,e,i){var r=i[0],s=i[1],n=i[2],a=Math.sqrt(r*r+s*s+n*n),o,l,c;return a<_t?null:(a=1/a,r*=a,s*=a,n*=a,o=Math.sin(e),l=Math.cos(e),c=1-l,t[0]=r*r*c+l,t[1]=s*r*c+n*o,t[2]=n*r*c-s*o,t[3]=0,t[4]=r*s*c-n*o,t[5]=s*s*c+l,t[6]=n*s*c+r*o,t[7]=0,t[8]=r*n*c+s*o,t[9]=s*n*c-r*o,t[10]=n*n*c+l,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t)}function Da(t,e,i,r,s,n,a){var o=1/(e-i),l=1/(r-s),c=1/(n-a);return t[0]=-2*o,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=-2*l,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[10]=2*c,t[11]=0,t[12]=(e+i)*o,t[13]=(s+r)*l,t[14]=(a+n)*c,t[15]=1,t}var hi=Da;function Ta(t,e,i){return t[0]=e[0]*i,t[1]=e[1]*i,t[2]=e[2]*i,t[3]=e[3]*i,t[4]=e[4]*i,t[5]=e[5]*i,t[6]=e[6]*i,t[7]=e[7]*i,t[8]=e[8]*i,t[9]=e[9]*i,t[10]=e[10]*i,t[11]=e[11]*i,t[12]=e[12]*i,t[13]=e[13]*i,t[14]=e[14]*i,t[15]=e[15]*i,t}var Qs=Ye;function se(){var t=new Ae(3);return Ae!=Float32Array&&(t[0]=0,t[1]=0,t[2]=0),t}function Ve(t){var e=new Ae(3);return e[0]=t[0],e[1]=t[1],e[2]=t[2],e}function Qe(t){var e=t[0],i=t[1],r=t[2];return Math.sqrt(e*e+i*i+r*r)}function k(t,e,i){var r=new Ae(3);return r[0]=t,r[1]=e,r[2]=i,r}function Hr(t,e){return t[0]=e[0],t[1]=e[1],t[2]=e[2],t}function it(t,e,i){return t[0]=e[0]+i[0],t[1]=e[1]+i[1],t[2]=e[2]+i[2],t}function ne(t,e,i){return t[0]=e[0]-i[0],t[1]=e[1]-i[1],t[2]=e[2]-i[2],t}function ur(t,e,i){return t[0]=Math.min(e[0],i[0]),t[1]=Math.min(e[1],i[1]),t[2]=Math.min(e[2],i[2]),t}function mr(t,e,i){return t[0]=Math.max(e[0],i[0]),t[1]=Math.max(e[1],i[1]),t[2]=Math.max(e[2],i[2]),t}function Sa(t,e,i){return t[0]=e[0]*i,t[1]=e[1]*i,t[2]=e[2]*i,t}function Ea(t,e){var i=e[0]-t[0],r=e[1]-t[1],s=e[2]-t[2];return Math.sqrt(i*i+r*r+s*s)}function Ia(t,e){return t[0]=-e[0],t[1]=-e[1],t[2]=-e[2],t}function Ie(t,e){var i=e[0],r=e[1],s=e[2],n=i*i+r*r+s*s;return n>0&&(n=1/Math.sqrt(n)),t[0]=e[0]*n,t[1]=e[1]*n,t[2]=e[2]*n,t}function Fa(t,e){return t[0]*e[0]+t[1]*e[1]+t[2]*e[2]}function Jt(t,e,i){var r=e[0],s=e[1],n=e[2],a=i[0],o=i[1],l=i[2];return t[0]=s*l-n*o,t[1]=n*a-r*l,t[2]=r*o-s*a,t}function Ba(t,e,i,r){var s=e[0],n=e[1],a=e[2];return t[0]=s+r*(i[0]-s),t[1]=n+r*(i[1]-n),t[2]=a+r*(i[2]-a),t}function qr(t,e,i){var r=e[0],s=e[1],n=e[2];return t[0]=r*i[0]+s*i[3]+n*i[6],t[1]=r*i[1]+s*i[4]+n*i[7],t[2]=r*i[2]+s*i[5]+n*i[8],t}function Di(t,e){var i=t[0],r=t[1],s=t[2],n=e[0],a=e[1],o=e[2],l=Math.sqrt((i*i+r*r+s*s)*(n*n+a*a+o*o)),c=l&&Fa(t,e)/l;return Math.acos(Math.min(Math.max(c,-1),1))}function Ua(t,e){var i=t[0],r=t[1],s=t[2],n=e[0],a=e[1],o=e[2];return Math.abs(i-n)<=_t*Math.max(1,Math.abs(i),Math.abs(n))&&Math.abs(r-a)<=_t*Math.max(1,Math.abs(r),Math.abs(a))&&Math.abs(s-o)<=_t*Math.max(1,Math.abs(s),Math.abs(o))}var Qr=ne,Vt=Qe;(function(){var t=se();return function(e,i,r,s,n,a){var o,l;for(i||(i=3),r||(r=0),s?l=Math.min(s*i+r,e.length):l=e.length,o=r;o<l;o+=i)t[0]=e[o],t[1]=e[o+1],t[2]=e[o+2],n(t,t,a),e[o]=t[0],e[o+1]=t[1],e[o+2]=t[2];return e}})();function Xe(){var t=new Ae(4);return Ae!=Float32Array&&(t[0]=0,t[1]=0,t[2]=0,t[3]=0),t}function ze(t){var e=new Ae(4);return e[0]=t[0],e[1]=t[1],e[2]=t[2],e[3]=t[3],e}function ae(t,e,i,r){var s=new Ae(4);return s[0]=t,s[1]=e,s[2]=i,s[3]=r,s}function Zr(t,e,i){return t[0]=e[0]+i[0],t[1]=e[1]+i[1],t[2]=e[2]+i[2],t[3]=e[3]+i[3],t}function Ra(t,e,i){return t[0]=e[0]-i[0],t[1]=e[1]-i[1],t[2]=e[2]-i[2],t[3]=e[3]-i[3],t}function Va(t,e,i){return t[0]=e[0]*i,t[1]=e[1]*i,t[2]=e[2]*i,t[3]=e[3]*i,t}function ve(t,e,i){var r=e[0],s=e[1],n=e[2],a=e[3];return t[0]=i[0]*r+i[4]*s+i[8]*n+i[12]*a,t[1]=i[1]*r+i[5]*s+i[9]*n+i[13]*a,t[2]=i[2]*r+i[6]*s+i[10]*n+i[14]*a,t[3]=i[3]*r+i[7]*s+i[11]*n+i[15]*a,t}var Pa=Ra;(function(){var t=Xe();return function(e,i,r,s,n,a){var o,l;for(i||(i=4),r||(r=0),s?l=Math.min(s*i+r,e.length):l=e.length,o=r;o<l;o+=i)t[0]=e[o],t[1]=e[o+1],t[2]=e[o+2],t[3]=e[o+3],n(t,t,a),e[o]=t[0],e[o+1]=t[1],e[o+2]=t[2],e[o+3]=t[3];return e}})();function Na(){var t=new Ae(2);return Ae!=Float32Array&&(t[0]=0,t[1]=0),t}function La(t,e){var i=new Ae(2);return i[0]=t,i[1]=e,i}(function(){var t=Na();return function(e,i,r,s,n,a){var o,l;for(i||(i=2),r||(r=0),s?l=Math.min(s*i+r,e.length):l=e.length,o=r;o<l;o+=i)t[0]=e[o],t[1]=e[o+1],n(t,t,a),e[o]=t[0],e[o+1]=t[1];return e}})();var et=256,$t=[],Yt;for(;et--;)$t[et]=(et+256).toString(16).substring(1);function di(){var t=0,e,i="";if(!Yt||et+16>256){for(Yt=Array(t=256);t--;)Yt[t]=256*Math.random()|0;t=et=0}for(;t<16;t++)e=Yt[et+t],t==6?i+=$t[e&15|64]:t==8?i+=$t[e&63|128]:i+=$t[e],t&1&&t>1&&t<11&&(i+="-");return et++,i}var Ti,jr;function ka(){return jr||(jr=1,Ti=function(e,i){var r=e.length;if(e===i)return!0;if(r!==i.length)return!1;for(var s=0;s<r;s++)if(e[s]!==i[s])return!1;return!0}),Ti}var Oa=ka();const za=va(Oa);var ge=Uint8Array,ut=Uint16Array,Ga=Int32Array,Zs=new ge([0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0,0,0,0]),js=new ge([0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13,0,0]),Ya=new ge([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),_s=function(t,e){for(var i=new ut(31),r=0;r<31;++r)i[r]=e+=1<<t[r-1];for(var s=new Ga(i[30]),r=1;r<30;++r)for(var n=i[r];n<i[r+1];++n)s[n]=n-i[r]<<5|r;return{b:i,r:s}},Js=_s(Zs,2),$s=Js.b,Xa=Js.r;$s[28]=258,Xa[258]=28;var Wa=_s(js,0),Ka=Wa.b,Qi=new ut(32768);for(var oe=0;oe<32768;++oe){var We=(oe&43690)>>1|(oe&21845)<<1;We=(We&52428)>>2|(We&13107)<<2,We=(We&61680)>>4|(We&3855)<<4,Qi[oe]=((We&65280)>>8|(We&255)<<8)>>1}var Ft=(function(t,e,i){for(var r=t.length,s=0,n=new ut(e);s<r;++s)t[s]&&++n[t[s]-1];var a=new ut(e);for(s=1;s<e;++s)a[s]=a[s-1]+n[s-1]<<1;var o;if(i){o=new ut(1<<e);var l=15-e;for(s=0;s<r;++s)if(t[s])for(var c=s<<4|t[s],h=e-t[s],d=a[t[s]-1]++<<h,f=d|(1<<h)-1;d<=f;++d)o[Qi[d]>>l]=c}else for(o=new ut(r),s=0;s<r;++s)t[s]&&(o[s]=Qi[a[t[s]-1]++]>>15-t[s]);return o}),Pt=new ge(288);for(var oe=0;oe<144;++oe)Pt[oe]=8;for(var oe=144;oe<256;++oe)Pt[oe]=9;for(var oe=256;oe<280;++oe)Pt[oe]=7;for(var oe=280;oe<288;++oe)Pt[oe]=8;var en=new ge(32);for(var oe=0;oe<32;++oe)en[oe]=5;var Ha=Ft(Pt,9,1),qa=Ft(en,5,1),Si=function(t){for(var e=t[0],i=1;i<t.length;++i)t[i]>e&&(e=t[i]);return e},Be=function(t,e,i){var r=e/8|0;return(t[r]|t[r+1]<<8)>>(e&7)&i},Ei=function(t,e){var i=e/8|0;return(t[i]|t[i+1]<<8|t[i+2]<<16)>>(e&7)},tn=function(t){return(t+7)/8|0},ei=function(t,e,i){return(e==null||e<0)&&(e=0),(i==null||i>t.length)&&(i=t.length),new ge(t.subarray(e,i))},Qa=["unexpected EOF","invalid block type","invalid length/literal","invalid distance","stream finished","no stream handler",,"no callback","invalid UTF-8 data","extra field too long","date not in range 1980-2099","filename too long","stream finishing","invalid zip data"],ye=function(t,e,i){var r=new Error(e||Qa[t]);if(r.code=t,Error.captureStackTrace&&Error.captureStackTrace(r,ye),!i)throw r;return r},Ai=function(t,e,i,r){var s=t.length,n=0;if(!s||e.f&&!e.l)return i||new ge(0);var a=!i,o=a||e.i!=2,l=e.i;a&&(i=new ge(s*3));var c=function(at){var _e=i.length;if(at>_e){var Fe=new ge(Math.max(_e*2,at));Fe.set(i),i=Fe}},h=e.f||0,d=e.p||0,f=e.b||0,u=e.l,m=e.d,p=e.m,g=e.n,x=s*8;do{if(!u){h=Be(t,d,1);var A=Be(t,d+1,3);if(d+=3,A)if(A==1)u=Ha,m=qa,p=9,g=5;else if(A==2){var w=Be(t,d,31)+257,C=Be(t,d+10,15)+4,M=w+Be(t,d+5,31)+1;d+=14;for(var T=new ge(M),E=new ge(19),I=0;I<C;++I)E[Ya[I]]=Be(t,d+I*3,7);d+=C*3;for(var S=Si(E),U=(1<<S)-1,B=Ft(E,S,1),I=0;I<M;){var V=B[Be(t,d,U)];d+=V&15;var y=V>>4;if(y<16)T[I++]=y;else{var R=0,P=0;for(y==16?(P=3+Be(t,d,3),d+=2,R=T[I-1]):y==17?(P=3+Be(t,d,7),d+=3):y==18&&(P=11+Be(t,d,127),d+=7);P--;)T[I++]=R}}var L=T.subarray(0,w),N=T.subarray(w);p=Si(L),g=Si(N),u=Ft(L,p,1),m=Ft(N,g,1)}else ye(1);else{var y=tn(d)+4,v=t[y-4]|t[y-3]<<8,b=y+v;if(b>s){l&&ye(0);break}o&&c(f+v),i.set(t.subarray(y,b),f),e.b=f+=v,e.p=d=b*8,e.f=h;continue}if(d>x){l&&ye(0);break}}o&&c(f+131072);for(var Y=(1<<p)-1,_=(1<<g)-1,z=d;;z=d){var R=u[Ei(t,d)&Y],W=R>>4;if(d+=R&15,d>x){l&&ye(0);break}if(R||ye(2),W<256)i[f++]=W;else if(W==256){z=d,u=null;break}else{var K=W-254;if(W>264){var I=W-257,Z=Zs[I];K=Be(t,d,(1<<Z)-1)+$s[I],d+=Z}var q=m[Ei(t,d)&_],te=q>>4;q||ye(3),d+=q&15;var N=Ka[te];if(te>3){var Z=js[te];N+=Ei(t,d)&(1<<Z)-1,d+=Z}if(d>x){l&&ye(0);break}o&&c(f+131072);var ue=f+K;if(f<N){var le=n-N,je=Math.min(N,ue);for(le+f<0&&ye(3);f<je;++f)i[f]=r[le+f]}for(;f<ue;++f)i[f]=i[f-N]}}e.l=u,e.p=z,e.b=f,e.f=h,u&&(h=1,e.m=p,e.d=m,e.n=g)}while(!h);return f!=i.length&&a?ei(i,0,f):i.subarray(0,f)},Za=new ge(0),rn=function(t){(t[0]!=31||t[1]!=139||t[2]!=8)&&ye(6,"invalid gzip data");var e=t[3],i=10;e&4&&(i+=(t[10]|t[11]<<8)+2);for(var r=(e>>3&1)+(e>>4&1);r>0;r-=!t[i++]);return i+(e&2)},ja=function(t){var e=t.length;return(t[e-4]|t[e-3]<<8|t[e-2]<<16|t[e-1]<<24)>>>0},_a=function(t,e){return((t[0]&15)!=8||t[0]>>4>7||(t[0]<<8|t[1])%31)&&ye(6,"invalid zlib data"),(t[1]>>5&1)==1&&ye(6,"invalid zlib data: "+(t[1]&32?"need":"unexpected")+" dictionary"),(t[1]>>3&4)+2},Xt=(function(){function t(e,i){typeof e=="function"&&(i=e,e={}),this.ondata=i;var r=e&&e.dictionary&&e.dictionary.subarray(-32768);this.s={i:0,b:r?r.length:0},this.o=new ge(32768),this.p=new ge(0),r&&this.o.set(r)}return t.prototype.e=function(e){if(this.ondata||ye(5),this.d&&ye(4),!this.p.length)this.p=e;else if(e.length){var i=new ge(this.p.length+e.length);i.set(this.p),i.set(e,this.p.length),this.p=i}},t.prototype.c=function(e){this.s.i=+(this.d=e||!1);var i=this.s.b,r=Ai(this.p,this.s,this.o);this.ondata(ei(r,i,this.s.b),this.d),this.o=ei(r,this.s.b-32768),this.s.b=this.o.length,this.p=ei(this.p,this.s.p/8|0),this.s.p&=7},t.prototype.push=function(e,i){this.e(e),this.c(i)},t})();function Ja(t,e){return Ai(t,{i:2},e,e)}var $a=(function(){function t(e,i){this.v=1,this.r=0,Xt.call(this,e,i)}return t.prototype.push=function(e,i){if(Xt.prototype.e.call(this,e),this.r+=e.length,this.v){var r=this.p.subarray(this.v-1),s=r.length>3?rn(r):4;if(s>r.length){if(!i)return}else this.v>1&&this.onmember&&this.onmember(this.r-r.length);this.p=r.subarray(s),this.v=0}Xt.prototype.c.call(this,0),this.s.f&&!this.s.l?(this.v=tn(this.s.p)+9,this.s={i:0},this.o=new ge(0),this.push(new ge(0),i)):i&&Xt.prototype.c.call(this,i)},t})();function eo(t,e){var i=rn(t);return i+8>t.length&&ye(6,"invalid gzip data"),Ai(t.subarray(i,-8),{i:2},new ge(ja(t)),e)}function to(t,e){return Ai(t.subarray(_a(t),-4),{i:2},e,e)}function io(t,e){return t[0]==31&&t[1]==139&&t[2]==8?eo(t,e):(t[0]&15)!=8||t[0]>>4>7||(t[0]<<8|t[1])%31?Ja(t,e):to(t,e)}var ro=typeof TextDecoder<"u"&&new TextDecoder,so=0;try{ro.decode(Za,{stream:!0}),so=1}catch{}class sn{esize;ecode;edata;littleEndian;constructor(e,i,r,s){if(e%16!=0)throw new Error("This does not appear to be a NIFTI extension");this.esize=e,this.ecode=i,this.edata=r,this.littleEndian=s}toArrayBuffer(){let e=new Uint8Array(this.esize),i=new Uint8Array(this.edata);e.set(i,8);let r=new DataView(e.buffer);return r.setInt32(0,this.esize,this.littleEndian),r.setInt32(4,this.ecode,this.littleEndian),e.buffer}}class O{static crcTable=null;static GUNZIP_MAGIC_COOKIE1=31;static GUNZIP_MAGIC_COOKIE2=139;static getStringAt(e,i,r){var s="",n,a;for(n=i;n<r;n+=1)a=e.getUint8(n),a!==0&&(s+=String.fromCharCode(a));return s}static getByteAt=function(e,i){return e.getUint8(i)};static getShortAt=function(e,i,r){return e.getInt16(i,r)};static getIntAt(e,i,r){return e.getInt32(i,r)}static getFloatAt(e,i,r){return e.getFloat32(i,r)}static getDoubleAt(e,i,r){return e.getFloat64(i,r)}static getInt64At(e,i,r){const s=e.getUint32(i,r),n=e.getInt32(i+4,r);let a;return r?a=n*2**32+s:a=s*2**32+n,n<0&&(a+=-1*2**32*2**32),a}static getUint64At(e,i,r){const s=e.getUint32(i+(r?0:4),r),n=e.getUint32(i+(r?4:0),r);return r?n*2**32+s:s*2**32+n}static getExtensionsAt(e,i,r,s){let n=[],a=i;for(;a<s;){let o=r,l=O.getIntAt(e,a,r);if(!l)break;if(l+a>s&&(o=!o,l=O.getIntAt(e,a,o),l+a>s))throw new Error("This does not appear to be a valid NIFTI extension");if(l%16!=0)throw new Error("This does not appear to be a NIFTI extension");let c=O.getIntAt(e,a+4,o),h=e.buffer.slice(a+8,a+l),d=new sn(l,c,h,o);n.push(d),a+=l}return n}static toArrayBuffer(e){var i,r,s;for(i=new ArrayBuffer(e.length),r=new Uint8Array(i),s=0;s<e.length;s+=1)r[s]=e[s];return i}static isString(e){return typeof e=="string"||e instanceof String}static formatNumber(e,i=void 0){let r;return O.isString(e)?r=Number(e):r=e,i?r=r.toPrecision(5):r=r.toPrecision(7),parseFloat(r)}static makeCRCTable(){let e,i=[];for(var r=0;r<256;r++){e=r;for(var s=0;s<8;s++)e=e&1?3988292384^e>>>1:e>>>1;i[r]=e}return i}static crc32(e){O.crcTable||(O.crcTable=O.makeCRCTable());const i=O.crcTable;let r=-1;for(var s=0;s<e.byteLength;s++)r=r>>>8^i[(r^e.getUint8(s))&255];return(r^-1)>>>0}}class G{littleEndian=!1;dim_info=0;dims=[];intent_p1=0;intent_p2=0;intent_p3=0;intent_code=0;datatypeCode=0;numBitsPerVoxel=0;slice_start=0;slice_end=0;slice_code=0;pixDims=[];vox_offset=0;scl_slope=1;scl_inter=0;xyzt_units=0;cal_max=0;cal_min=0;slice_duration=0;toffset=0;description="";aux_file="";intent_name="";qform_code=0;sform_code=0;quatern_a=0;quatern_b=0;quatern_c=0;quatern_d=0;qoffset_x=0;qoffset_y=0;qoffset_z=0;affine=[[1,0,0,0],[0,1,0,0],[0,0,1,0],[0,0,0,1]];qfac=1;quatern_R;magic="0";isHDR=!1;extensionFlag=[0,0,0,0];extensionSize=0;extensionCode=0;extensions=[];static TYPE_NONE=0;static TYPE_BINARY=1;static TYPE_UINT8=2;static TYPE_INT16=4;static TYPE_INT32=8;static TYPE_FLOAT32=16;static TYPE_COMPLEX64=32;static TYPE_FLOAT64=64;static TYPE_RGB24=128;static TYPE_INT8=256;static TYPE_UINT16=512;static TYPE_UINT32=768;static TYPE_INT64=1024;static TYPE_UINT64=1280;static TYPE_FLOAT128=1536;static TYPE_COMPLEX128=1792;static TYPE_COMPLEX256=2048;static XFORM_UNKNOWN=0;static XFORM_SCANNER_ANAT=1;static XFORM_ALIGNED_ANAT=2;static XFORM_TALAIRACH=3;static XFORM_MNI_152=4;static SPATIAL_UNITS_MASK=7;static TEMPORAL_UNITS_MASK=56;static UNITS_UNKNOWN=0;static UNITS_METER=1;static UNITS_MM=2;static UNITS_MICRON=3;static UNITS_SEC=8;static UNITS_MSEC=16;static UNITS_USEC=24;static UNITS_HZ=32;static UNITS_PPM=40;static UNITS_RADS=48;static MAGIC_COOKIE=348;static STANDARD_HEADER_SIZE=348;static MAGIC_NUMBER_LOCATION=344;static MAGIC_NUMBER=[110,43,49];static MAGIC_NUMBER2=[110,105,49];static EXTENSION_HEADER_SIZE=8;readHeader(e){var i=new DataView(e),r=O.getIntAt(i,0,this.littleEndian),s,n,a,o;if(r!==G.MAGIC_COOKIE&&(this.littleEndian=!0,r=O.getIntAt(i,0,this.littleEndian)),r!==G.MAGIC_COOKIE)throw new Error("This does not appear to be a NIFTI file!");for(this.dim_info=O.getByteAt(i,39),s=0;s<8;s+=1)o=40+s*2,this.dims[s]=O.getShortAt(i,o,this.littleEndian);for(this.intent_p1=O.getFloatAt(i,56,this.littleEndian),this.intent_p2=O.getFloatAt(i,60,this.littleEndian),this.intent_p3=O.getFloatAt(i,64,this.littleEndian),this.intent_code=O.getShortAt(i,68,this.littleEndian),this.datatypeCode=O.getShortAt(i,70,this.littleEndian),this.numBitsPerVoxel=O.getShortAt(i,72,this.littleEndian),this.slice_start=O.getShortAt(i,74,this.littleEndian),s=0;s<8;s+=1)o=76+s*4,this.pixDims[s]=O.getFloatAt(i,o,this.littleEndian);if(this.vox_offset=O.getFloatAt(i,108,this.littleEndian),this.scl_slope=O.getFloatAt(i,112,this.littleEndian),this.scl_inter=O.getFloatAt(i,116,this.littleEndian),this.slice_end=O.getShortAt(i,120,this.littleEndian),this.slice_code=O.getByteAt(i,122),this.xyzt_units=O.getByteAt(i,123),this.cal_max=O.getFloatAt(i,124,this.littleEndian),this.cal_min=O.getFloatAt(i,128,this.littleEndian),this.slice_duration=O.getFloatAt(i,132,this.littleEndian),this.toffset=O.getFloatAt(i,136,this.littleEndian),this.description=O.getStringAt(i,148,228),this.aux_file=O.getStringAt(i,228,252),this.qform_code=O.getShortAt(i,252,this.littleEndian),this.sform_code=O.getShortAt(i,254,this.littleEndian),this.quatern_b=O.getFloatAt(i,256,this.littleEndian),this.quatern_c=O.getFloatAt(i,260,this.littleEndian),this.quatern_d=O.getFloatAt(i,264,this.littleEndian),this.quatern_a=Math.sqrt(1-(Math.pow(this.quatern_b,2)+Math.pow(this.quatern_c,2)+Math.pow(this.quatern_d,2))),this.qoffset_x=O.getFloatAt(i,268,this.littleEndian),this.qoffset_y=O.getFloatAt(i,272,this.littleEndian),this.qoffset_z=O.getFloatAt(i,276,this.littleEndian),this.qform_code<1&&this.sform_code<1&&(this.affine[0][0]=this.pixDims[1],this.affine[1][1]=this.pixDims[2],this.affine[2][2]=this.pixDims[3]),this.qform_code>0&&this.sform_code<this.qform_code){const l=this.quatern_a,c=this.quatern_b,h=this.quatern_c,d=this.quatern_d;for(this.qfac=this.pixDims[0]===0?1:this.pixDims[0],this.quatern_R=[[l*l+c*c-h*h-d*d,2*c*h-2*l*d,2*c*d+2*l*h],[2*c*h+2*l*d,l*l+h*h-c*c-d*d,2*h*d-2*l*c],[2*c*d-2*l*h,2*h*d+2*l*c,l*l+d*d-h*h-c*c]],n=0;n<3;n+=1)for(a=0;a<3;a+=1)this.affine[n][a]=this.quatern_R[n][a]*this.pixDims[a+1],a===2&&(this.affine[n][a]*=this.qfac);this.affine[0][3]=this.qoffset_x,this.affine[1][3]=this.qoffset_y,this.affine[2][3]=this.qoffset_z}else if(this.sform_code>0)for(n=0;n<3;n+=1)for(a=0;a<4;a+=1)o=280+(n*4+a)*4,this.affine[n][a]=O.getFloatAt(i,o,this.littleEndian);if(this.affine[3][0]=0,this.affine[3][1]=0,this.affine[3][2]=0,this.affine[3][3]=1,this.intent_name=O.getStringAt(i,328,344),this.magic=O.getStringAt(i,344,348),this.isHDR=this.magic===String.fromCharCode.apply(null,G.MAGIC_NUMBER2),i.byteLength>G.MAGIC_COOKIE){this.extensionFlag[0]=O.getByteAt(i,348),this.extensionFlag[1]=O.getByteAt(i,349),this.extensionFlag[2]=O.getByteAt(i,350),this.extensionFlag[3]=O.getByteAt(i,351);let l=!0;!this.isHDR&&this.vox_offset<=352&&(l=!1),i.byteLength<=368&&(l=!1),l&&this.extensionFlag[0]&&(this.extensions=O.getExtensionsAt(i,this.getExtensionLocation(),this.littleEndian,this.vox_offset),this.extensionSize=this.extensions[0].esize,this.extensionCode=this.extensions[0].ecode)}}toFormattedString(){var e=O.formatNumber,i="";return i+="Dim Info = "+this.dim_info+`
3
3
  `,i+="Image Dimensions (1-8): "+this.dims[0]+", "+this.dims[1]+", "+this.dims[2]+", "+this.dims[3]+", "+this.dims[4]+", "+this.dims[5]+", "+this.dims[6]+", "+this.dims[7]+`
4
4
  `,i+="Intent Parameters (1-3): "+this.intent_p1+", "+this.intent_p2+", "+this.intent_p3+`
5
5
  `,i+="Intent Code = "+this.intent_code+`