@arcgis/coding-components 4.31.0-next.53 → 4.31.0-next.55

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 (122) hide show
  1. package/dist/arcgis-coding-components/arcgis-coding-components.esm.js +2 -2
  2. package/dist/arcgis-coding-components/assets/code-editor/arcade.worker.js +3 -3
  3. package/dist/arcgis-coding-components/assets/code-editor/sql-expr.worker.js +2 -2
  4. package/dist/arcgis-coding-components/assets/sql-expression-editor/t9n/sql-expression-editor.t9n.en.json +4 -0
  5. package/dist/arcgis-coding-components/index.esm.js +2 -2
  6. package/dist/arcgis-coding-components/{p-34426b2b.js → p-091cdb1e.js} +2 -2
  7. package/dist/arcgis-coding-components/p-0e602e10.js +6 -0
  8. package/dist/arcgis-coding-components/{p-336225b0.js → p-141487fe.js} +2 -2
  9. package/dist/arcgis-coding-components/{p-3f1428d5.js → p-32cb6ea2.js} +1 -1
  10. package/dist/arcgis-coding-components/{p-53e1217d.entry.js → p-54f78145.entry.js} +2 -2
  11. package/dist/arcgis-coding-components/{p-6227844e.js → p-5cf73c57.js} +1 -1
  12. package/dist/arcgis-coding-components/{p-764a9235.js → p-67b27736.js} +3 -3
  13. package/dist/arcgis-coding-components/{p-23bca400.js → p-74e53b4a.js} +2 -2
  14. package/dist/arcgis-coding-components/{p-dd6b4bb0.js → p-773d9ba4.js} +2 -2
  15. package/dist/arcgis-coding-components/{p-6dff7ff6.js → p-80b0534e.js} +2 -2
  16. package/dist/arcgis-coding-components/p-8efb1de5.entry.js +6 -0
  17. package/dist/arcgis-coding-components/p-989e9ba7.js +6 -0
  18. package/dist/arcgis-coding-components/{p-e46e16f4.js → p-98bc0e2e.js} +2 -2
  19. package/dist/arcgis-coding-components/{p-8e84c70c.js → p-a6baba61.js} +9 -9
  20. package/dist/arcgis-coding-components/p-ba514722.js +6 -0
  21. package/dist/arcgis-coding-components/{p-fe6fcdff.js → p-d297077d.js} +2 -2
  22. package/dist/arcgis-coding-components/p-d43d29ac.js +6 -0
  23. package/dist/arcgis-coding-components/{p-e875189a.js → p-df8755a6.js} +1 -1
  24. package/dist/arcgis-coding-components/p-e54e0516.entry.js +6 -0
  25. package/dist/cjs/{app-globals-93ebd47b.js → app-globals-e6c77e1e.js} +1 -1
  26. package/dist/cjs/{arcade-defaults-ec107258.js → arcade-defaults-a9946815.js} +4 -4
  27. package/dist/cjs/{arcade-mode-9f3ab07c.js → arcade-mode-7b6729b3.js} +16 -3
  28. package/dist/cjs/arcgis-arcade-editor_6.cjs.entry.js +47 -123
  29. package/dist/cjs/arcgis-coding-components.cjs.js +4 -4
  30. package/dist/cjs/arcgis-sql-expression-editor.cjs.entry.js +33 -11
  31. package/dist/cjs/arcgis-sql-expression-fields.cjs.entry.js +4 -4
  32. package/dist/cjs/{css-fdd5622f.js → css-0e5b9fb9.js} +1 -1
  33. package/dist/cjs/{cssMode-bda7c7a2.js → cssMode-3d5ea09f.js} +2 -2
  34. package/dist/cjs/{html-230e1430.js → html-baccaba5.js} +2 -2
  35. package/dist/cjs/{htmlMode-55f5e9d4.js → htmlMode-54ec4b3d.js} +2 -2
  36. package/dist/cjs/{index-706da5e7.js → index-9e74612d.js} +1 -1
  37. package/dist/cjs/index.cjs.js +4 -4
  38. package/dist/cjs/{javascript-9420b602.js → javascript-ed0c5ba8.js} +3 -3
  39. package/dist/cjs/{jsonMode-b09d1025.js → jsonMode-e2e8cbc6.js} +2 -2
  40. package/dist/cjs/{language-defaults-base-384446f6.js → language-defaults-base-277ce995.js} +9 -9
  41. package/dist/cjs/loader.cjs.js +4 -4
  42. package/dist/cjs/{sql-expr-defaults-d9b38c9c.js → sql-expr-defaults-a54696c1.js} +57 -34
  43. package/dist/cjs/{sql-expr-mode-32c4756e.js → sql-expr-mode-65d156b7.js} +17 -4
  44. package/dist/cjs/{tsMode-dc6ecf16.js → tsMode-5e037421.js} +2 -2
  45. package/dist/cjs/{typescript-3ad8c6b2.js → typescript-94a06ac9.js} +2 -2
  46. package/dist/cjs/useT9n-4e453944.js +115 -0
  47. package/dist/components/arcade-defaults.js +1 -1
  48. package/dist/components/arcade-mode.js +16 -3
  49. package/dist/components/arcade-results.js +2 -2
  50. package/dist/components/arcade-suggestions.js +2 -2
  51. package/dist/components/arcade-variables.js +2 -2
  52. package/dist/components/arcgis-arcade-editor.js +17 -10
  53. package/dist/components/arcgis-arcade-results.js +1 -1
  54. package/dist/components/arcgis-arcade-suggestions.js +1 -1
  55. package/dist/components/arcgis-arcade-variables.js +1 -1
  56. package/dist/components/arcgis-assets.d.ts +1 -1
  57. package/dist/components/arcgis-assets.js +1 -1
  58. package/dist/components/arcgis-code-editor.js +1 -1
  59. package/dist/components/arcgis-language-api-panel.js +1 -1
  60. package/dist/components/arcgis-sql-expression-editor.js +33 -11
  61. package/dist/components/arcgis-sql-expression-fields.js +1 -1
  62. package/dist/components/{chunk-BMBYH3VH.js → chunk-W77CUVCX.js} +54 -31
  63. package/dist/components/code-editor.js +4 -3
  64. package/dist/components/fields.js +1 -1
  65. package/dist/components/index.js +1 -1
  66. package/dist/components/index2.js +1 -1
  67. package/dist/components/language-api-panel.js +22 -4
  68. package/dist/components/language-defaults-base.js +1 -1
  69. package/dist/components/markdown.js +1 -1
  70. package/dist/components/sql-expr-defaults.js +1 -1
  71. package/dist/components/sql-expr-mode.js +15 -2
  72. package/dist/components/sql-expression-fields.js +2 -2
  73. package/dist/components/useT9n.js +2 -2
  74. package/dist/components/utilities.js +1 -1
  75. package/dist/esm/{app-globals-a6a11226.js → app-globals-5e71a2db.js} +1 -1
  76. package/dist/esm/{arcade-defaults-da87f04c.js → arcade-defaults-880f5e12.js} +4 -4
  77. package/dist/esm/{arcade-mode-ddfa9492.js → arcade-mode-970a9dae.js} +16 -3
  78. package/dist/esm/arcgis-arcade-editor_6.entry.js +42 -118
  79. package/dist/esm/arcgis-coding-components.js +5 -5
  80. package/dist/esm/arcgis-sql-expression-editor.entry.js +33 -11
  81. package/dist/esm/arcgis-sql-expression-fields.entry.js +4 -4
  82. package/dist/esm/{css-3128603e.js → css-f6ef0a8a.js} +1 -1
  83. package/dist/esm/{cssMode-9fca889c.js → cssMode-c9706c47.js} +2 -2
  84. package/dist/esm/{html-0388c262.js → html-adf0ac7b.js} +2 -2
  85. package/dist/esm/{htmlMode-e4df0119.js → htmlMode-f5b54f77.js} +2 -2
  86. package/dist/esm/{index-4ea7fae6.js → index-542987c6.js} +1 -1
  87. package/dist/esm/index.js +4 -4
  88. package/dist/esm/{javascript-b09c8010.js → javascript-17c964c5.js} +3 -3
  89. package/dist/esm/{jsonMode-683dc167.js → jsonMode-f5377551.js} +2 -2
  90. package/dist/esm/{language-defaults-base-3bedfdc0.js → language-defaults-base-cf9491cd.js} +10 -10
  91. package/dist/esm/loader.js +5 -5
  92. package/dist/esm/{sql-expr-defaults-e5c72573.js → sql-expr-defaults-5d4eebcc.js} +58 -35
  93. package/dist/esm/{sql-expr-mode-c80ae5be.js → sql-expr-mode-8e292455.js} +17 -4
  94. package/dist/esm/{tsMode-3d873185.js → tsMode-64a3b7da.js} +2 -2
  95. package/dist/esm/{typescript-f121c870.js → typescript-80a07ece.js} +2 -2
  96. package/dist/esm/useT9n-917bda01.js +113 -0
  97. package/dist/loader/cdn.js +1 -1
  98. package/dist/loader/index.cjs.js +1 -1
  99. package/dist/loader/index.es2017.js +1 -1
  100. package/dist/loader/index.js +1 -1
  101. package/dist/types/components/arcade-editor/arcade-editor.d.ts +4 -3
  102. package/dist/types/components/language-api-panel/language-api-panel.d.ts +1 -0
  103. package/dist/types/components/sql-expression-editor/sql-expression-editor.d.ts +31 -3
  104. package/dist/types/components.d.ts +27 -0
  105. package/dist/types/data/arcgis-web-compoments/actions-runner-1/_work/arcgis-web-components/arcgis-web-components/packages/coding-packages/coding-components/.stencil/stencil.config.d.ts +3 -0
  106. package/dist/types/utils/arcade-monaco/arcade-worker-manager.d.ts +6 -0
  107. package/dist/types/utils/sql-expr-monaco/sql-expr-worker-manager.d.ts +6 -0
  108. package/package.json +11 -11
  109. package/dist/arcgis-coding-components/p-2950e0ad.entry.js +0 -6
  110. package/dist/arcgis-coding-components/p-477f9563.js +0 -6
  111. package/dist/arcgis-coding-components/p-5674fca5.js +0 -6
  112. package/dist/arcgis-coding-components/p-715fa29e.js +0 -6
  113. package/dist/arcgis-coding-components/p-eaa1352e.entry.js +0 -6
  114. package/dist/types/data/actions-runner-1/_work/arcgis-web-components/arcgis-web-components/packages/coding-packages/coding-components/.stencil/stencil.config.d.ts +0 -3
  115. /package/dist/types/data/{actions-runner-1 → arcgis-web-compoments/actions-runner-1}/_work/arcgis-web-components/arcgis-web-components/packages/coding-packages/coding-components/.stencil/stories/internal/arcade-editor/arcade-editor.stories.d.ts +0 -0
  116. /package/dist/types/data/{actions-runner-1 → arcgis-web-compoments/actions-runner-1}/_work/arcgis-web-components/arcgis-web-components/packages/coding-packages/coding-components/.stencil/stories/internal/arcade-editor/editorContext.d.ts +0 -0
  117. /package/dist/types/data/{actions-runner-1 → arcgis-web-compoments/actions-runner-1}/_work/arcgis-web-components/arcgis-web-components/packages/coding-packages/coding-components/.stencil/stories/internal/code-editor/code-editor.stories.d.ts +0 -0
  118. /package/dist/types/data/{actions-runner-1 → arcgis-web-compoments/actions-runner-1}/_work/arcgis-web-components/arcgis-web-components/packages/coding-packages/coding-components/.stencil/stories/internal/sql-expression-editor/sql-expression-editor.stories.d.ts +0 -0
  119. /package/dist/types/data/{actions-runner-1 → arcgis-web-compoments/actions-runner-1}/_work/arcgis-web-components/arcgis-web-components/packages/coding-packages/coding-components/.stencil/stories/reference/stories/arcade-editor.stories.d.ts +0 -0
  120. /package/dist/types/data/{actions-runner-1 → arcgis-web-compoments/actions-runner-1}/_work/arcgis-web-components/arcgis-web-components/packages/coding-packages/coding-components/.stencil/support/sass-inline-url-importer.d.ts +0 -0
  121. /package/dist/types/data/{actions-runner-1 → arcgis-web-compoments/actions-runner-1}/_work/arcgis-web-components/arcgis-web-components/packages/coding-packages/coding-components/.stencil/support/sass-json-importer.d.ts +0 -0
  122. /package/dist/types/data/{actions-runner-1 → arcgis-web-compoments/actions-runner-1}/_work/arcgis-web-components/arcgis-web-components/packages/coding-packages/coding-components/.stencil/support/stencil-monaco-plugins.d.ts +0 -0
@@ -1,6 +1,6 @@
1
1
  /*!
2
2
  * All material copyright Esri, All Rights Reserved, unless otherwise specified.
3
3
  * See https://js.arcgis.com/4.31/esri/copyright.txt for details.
4
- * v4.31.0-next.53
4
+ * v4.31.0-next.55
5
5
  */
6
- import{p as e,b as i}from"./p-3f1428d5.js";export{s as setNonce}from"./p-3f1428d5.js";import{g as t}from"./p-e875189a.js";(()=>{const i=import.meta.url,t={};return""!==i&&(t.resourcesUrl=new URL(".",i).href),e(t)})().then((async e=>(await t(),i([["p-53e1217d",[[1,"arcgis-sql-expression-fields",{loading:[4],modelId:[1,"model-id"],_mutationCounter:[32],_flowItemRenderers:[32],_filterValue:[32]},null,{modelId:["modelIdPropChanged"]}]]],["p-2950e0ad",[[0,"arcgis-arcade-editor",{profile:[16],script:[1025],testData:[16],suggestions:[16],snippets:[16],hideDocumentationActions:[4,"hide-documentation-actions"],hideSideBar:[4,"hide-side-bar"],sideActionBarExpanded:[1540,"side-action-bar-expanded"],openedSidePanel:[1537,"opened-side-panel"],editorOptions:[16],editorInstance:[16],_preparingArcade:[32],_editorProfile:[32],_apiLibrary:[32],_showExecutionPanel:[32],_resultPanel:[32],_executingScript:[32],_consoleLogs:[32],_executionResult:[32],messages:[32],getScript:[64],setFocus:[64],getEditorInstance:[64],getTestResult:[64],updateThemeColors:[64]},null,{messages:["_messagesChanged"],profile:["_profileChanged"],testData:["_testDataChanged"],snippets:["_snippetChanged"]}],[1,"arcgis-arcade-results",{loading:[4],openedResultPanel:[1537,"opened-result-panel"],result:[16],consoleLogs:[16]}],[1,"arcgis-arcade-suggestions",{suggestions:[16],_selectedSuggestion:[32],_filterValue:[32],_colorizeStyle:[32]},null,{suggestions:["suggestionsPropChanged"]}],[1,"arcgis-arcade-variables",{loading:[4],modelId:[1,"model-id"],_mutationCounter:[32],_flowItemRenderers:[32],_filterValue:[32]},null,{modelId:["modelIdPropChanged"]}],[0,"arcgis-code-editor",{value:[1],language:[1],modelId:[1,"model-id"],editorOptions:[16],editorInstance:[16],getValue:[64],setValue:[64],insertText:[64],insertSnippet:[64],getEditorInstance:[64],setFocus:[64]},null,{language:["languagePropChange"],modelId:["modelIdPropChange"],editorOptions:["editorOptionsPropChange"]}],[1,"arcgis-language-api-panel",{hideDocumentationActions:[4,"hide-documentation-actions"],loading:[4],apiLibrary:[16],_selectedApiItem:[32],_filterValue:[32],_colorizeStyle:[32]}]]],["p-eaa1352e",[[0,"arcgis-sql-expression-editor",{profile:[16],_preparing:[32],_editorProfile:[32],_activeAction:[32],_apiLibrary:[32]},null,{profile:["_profileChanged"]}]]]],e))));
6
+ import{p as e,b as a}from"./p-32cb6ea2.js";export{s as setNonce}from"./p-32cb6ea2.js";import{g as i}from"./p-df8755a6.js";(()=>{const a=import.meta.url,i={};return""!==a&&(i.resourcesUrl=new URL(".",a).href),e(i)})().then((async e=>(await i(),a([["p-54f78145",[[1,"arcgis-sql-expression-fields",{loading:[4],modelId:[1,"model-id"],_mutationCounter:[32],_flowItemRenderers:[32],_filterValue:[32]},null,{modelId:["modelIdPropChanged"]}]]],["p-e54e0516",[[0,"arcgis-arcade-editor",{profile:[16],script:[1025],testData:[16],suggestions:[16],snippets:[16],hideDocumentationActions:[4,"hide-documentation-actions"],hideSideBar:[4,"hide-side-bar"],sideActionBarExpanded:[1540,"side-action-bar-expanded"],openedSidePanel:[1537,"opened-side-panel"],editorOptions:[16],editorInstance:[16],_preparingArcade:[32],_editorProfile:[32],_apiLibrary:[32],_showExecutionPanel:[32],_resultPanel:[32],_executingScript:[32],_consoleLogs:[32],_executionResult:[32],messages:[32],getScript:[64],setFocus:[64],getEditorInstance:[64],getTestResult:[64],updateThemeColors:[64]},null,{messages:["_messagesChanged"],profile:["_profileChanged"],testData:["_testDataChanged"],snippets:["_snippetChanged"]}],[1,"arcgis-arcade-results",{loading:[4],openedResultPanel:[1537,"opened-result-panel"],result:[16],consoleLogs:[16]}],[1,"arcgis-arcade-suggestions",{suggestions:[16],_selectedSuggestion:[32],_filterValue:[32],_colorizeStyle:[32]},null,{suggestions:["suggestionsPropChanged"]}],[1,"arcgis-arcade-variables",{loading:[4],modelId:[1,"model-id"],_mutationCounter:[32],_flowItemRenderers:[32],_filterValue:[32]},null,{modelId:["modelIdPropChanged"]}],[0,"arcgis-code-editor",{value:[1],language:[1],modelId:[1,"model-id"],editorOptions:[16],editorInstance:[16],getValue:[64],setValue:[64],insertText:[64],insertSnippet:[64],getEditorInstance:[64],setFocus:[64]},null,{language:["languagePropChange"],modelId:["modelIdPropChange"],editorOptions:["editorOptionsPropChange"]}],[1,"arcgis-language-api-panel",{hideDocumentationActions:[4,"hide-documentation-actions"],loading:[4],apiLibrary:[16],_selectedApiItem:[32],_filterValue:[32],_colorizeStyle:[32]},null,{apiLibrary:["_apiLibraryChanged"]}]]],["p-8efb1de5",[[0,"arcgis-sql-expression-editor",{profile:[16],script:[1025],_preparing:[32],_editorProfile:[32],_activeAction:[32],_apiLibrary:[32],messages:[32]},null,{messages:["_messagesChanged"],profile:["_profileChanged"]}]]]],e))));
@@ -26,8 +26,8 @@
26
26
  `,`
27
27
  `]:[`
28
28
  `]}nextPos(t,n=!1){let i=Math.max(t.line,0);return Math.max(t.column,0)<this.getLineLength(i)?(t.column+=1,n?!!this.skipSpaces(t):!0):i<this.length?(t.line+=1,t.column=0,n?!!this.skipSpaces(t):!0):!1}prevPos(t,n=!1){let i=t.line,r=t.column;if(r<1){if(i-=1,i<1)return!1;r=this.getLineLength(i)}else r=Math.min(r-1,this.getLineLength(i));return t.line=i,t.column=r,n?!!this.skipSpaces(t,!0):!0}firstPos(){return{line:1,column:0}}lastPos(){return{line:this.length,column:this.getLineLength(this.length)}}skipSpaces(t,n=!1){if(n){for(;this.prevPos(t);)if(!si(this.charAt(t))&&this.nextPos(t))return t;return null}else{for(;si(this.charAt(t));)if(!this.nextPos(t))return null;return t}}slice(t,n){if(!n&&!t)return this;if(n??(n=this.lastPos()),!t)throw new Error("cannot slice with end but not start");let i=this.lineRecords.slice(t.line-1,n.line);return t.line===n.line?i[0]=Tt(i[0],t.column,n.column):(i[0]=Tt(i[0],t.column),i.push(Tt(i.pop()??i[0],0,n.column))),new Or(i)}sliceString(t=this.firstPos(),n=this.lastPos()){let i=[];for(let r=t.line;r<=n.line;r++){let s=this.lineRecords[r-1];r===t.line?r===n.line?s=Tt(s,t.column,n.column):s=Tt(s,t.column):r===n.line&&(s=Tt(s,0,n.column));let o="",a=Math.max(s.indentation,0);a>0&&(o+=new Array(a+1).join(" ")),o+=s.line.slice(s.sliceStart,s.sliceEnd),i.push(o)}return i.join(`
29
- `)}};function Ol(e,t=2){let n=0,i=e.length;for(let r=0;r<i;r++)switch(e.charCodeAt(r)){case 9:{let s=Math.ceil(n/t)*t;s===n?n+=t:n=s;break}case 11:case 12:case 13:case 65279:break;case 32:default:n+=1;break}return n}function Tt(e,t,n){let i=e.sliceStart,r=e.sliceEnd,s=Math.max(e.indentation,0),o=s+r-i;return n??(n=o),t=Math.max(t,0),n=Math.min(n,o),n=Math.max(n,t),n<s?(s=n,r=i):r-=o-n,o=n,o-=t,t<s?s-=t:(t-=s,s=0,i+=t),e.indentation===s&&e.sliceStart===i&&e.sliceEnd===r?e:{line:e.line,indentation:s,sliceStart:i,sliceEnd:r}}function g1(e,t,n){return!e&&!n?"":e?n?`${e}${t}${n}`:e:n}var Wl=/\u000D\u000A|\u000D(?!\u000A)|\u000A|\u2028|\u2029/u,T=class Ue{constructor(t=[]){this.lines=t}static fromString(t){return new Ue(t.split(Wl))}static appendLines(t=[]){let n=new Ue;return t.forEach(i=>{i!=null&&(typeof i=="string"?n.lines.push(i):n.lines.push(...i.lines))}),n}static joinLines(t=[],n=""){let i=new Ue;return t.forEach(r=>{if(r==null)return;let s=i.lines.pop()??"";typeof r=="string"?i.lines.push(g1(s,n,r)):(i.lines.push(g1(s,n,r.lines.slice(0)[0])),i.lines.push(...r.lines.slice(1)))}),i}static aggregateLines(t,n,i,r,s){if(i.isEmpty)return t;if(!n||t.isEmpty)return i.indentFirstLine(s);let o=r.start.line-n.end.line;if(o===0)return Ue.joinLines([t," ",i]);let a=o===1?void 0:"";return Ue.appendLines([t,a,i.indentFirstLine(s)])}get isEmpty(){return this.lines.length===0||this.lines.length===1&&this.lines[0].length===0}get maxLineLength(){return this.lines.reduce((t,n)=>Math.max(t,n.length),0)}get firstLinelength(){return(this.lines[0]??"").length}get lastLinelength(){return(this.lines[this.lines.length-1]??"").length}surroundWith(t="",n=""){return!t&&!n?this:this.isEmpty?new Ue([t+n]):this.lines.length===1?new Ue([t+this.lines[0]+n]):Ue.joinLines([t,this,n])}indentFirstLine(t=""){return this.isEmpty?this:(this.lines[0]=t+this.lines[0],this)}suffixWith(t){return this.surroundWith("",t)}toString(t=`
30
- `){return this.lines.join(t)}};function jr(e,t){return e*(t.indentWidth??2)}function dt(e=0,t){let{indentWidth:n=2}=Hr(t);return new Array(e*n+1).join(" ")}function oi(e){return e.replace(/['"]/gu,t=>t==='"'?"'":'"')}function ql(e,t){switch(e.type){case g.UnaryExpression:return s1(t)&&t.object===e;case g.BinaryExpression:case g.LogicalExpression:switch(t.type){case g.UnaryExpression:return!0;case g.MemberExpression:return t.object===e;case g.BinaryExpression:case g.LogicalExpression:return ui[t.operator]>ui[e.operator];default:return!1}case g.Literal:return s1(t)&&typeof e.value=="number"&&t.object===e;case g.AssignmentExpression:switch(t.type){case g.UnaryExpression:case g.BinaryExpression:case g.LogicalExpression:case g.ReturnStatement:return!0;case g.MemberExpression:return t.object===e;default:return!1}default:return!1}}function Q(e,t,n){switch(e?.type){case g.BinaryExpression:case g.LogicalExpression:return $l(e,t,n);case g.AssignmentExpression:return new Gr(e,t,n);case g.MemberExpression:return new M1(e,t,n);case g.Identifier:return new Wr(e,t,n);case g.CallExpression:return new jl(e,t,n);case g.ObjectExpression:return mt(e,t,n);case g.ArrayExpression:return mt(e,t,n);case g.Literal:return new Wr(e,t,n);case g.UpdateExpression:case g.UnaryExpression:return new B1(e,t,n);case g.TemplateLiteral:return new Xl(e,t,n);case g.VariableDeclaration:return new qr(e,t,n);default:throw new Error(`unknown type: ${JSON.stringify(e)}`)}}function mt(e,t,n){let i=new mi(e,t,n);switch(e.type){case g.ArrayExpression:return i.setupCollection(e.elements.map(r=>Q(r,e,n)),"SquareBrackets"),i;case g.ObjectExpression:return i.setupCollection(e.properties.map(r=>new Gl(r,e,n)),"CurlyBrackets"),i;case g.VariableDeclaration:return i.prefix="var ",i.setupCollection(e.declarations.map(r=>I1(r,e,n)),"None"),i;case g.FunctionDeclaration:return i.prefix=`function ${e.id.name}`,i.setupCollection(e.params.map(r=>Q(r,e,n)),"Parentheses"),i;case g.ForStatement:return i.prefix="for ",i.setupCollection([Q(e.init,e,n),Q(e.test,e,n),Q(e.update,e,n)],"Parentheses",";"),i;case g.ForInStatement:return i.prefix="for ",i.setupCollection([new Gr(e,t,n)],"Parentheses",""),i;case g.IfStatement:return i.prefix="if ",i.setupCollection([Q(e.test,e,n)],"Parentheses",""),i;case g.WhileStatement:return i.prefix="while ",i.setupCollection([Q(e.test,e,n)],"Parentheses",""),i;default:return i}}function I1(e,t,n){return e.init?new Gr(e,t,n):new Wr(e.id,t,n)}function $l(e,t,n){let i=[...di(e.left,e.operator),...di(e.right,e.operator)].map(s=>Q(s,e,n)),r=new mi(e,t,n);return r.setupCollection(i,"None",` ${e.operator}`),r}function di(e,t){return e.type!==g.BinaryExpression&&e.type!==g.LogicalExpression?[e]:e.operator!==t?[e]:[...di(e.left,t),...di(e.right,t)]}var Ve=class{constructor(e,t,n){this.node=e,this.parent=t,this.options=n,this.prefix="",this.suffix="",this.groupingParentheses=!1,this.groupingParentheses=ql(e,t)}get openingParenthesis(){return this.groupingParentheses?"(":""}get closingParenthesis(){return this.groupingParentheses?")":""}get leadingString(){return[this.prefix,this.openingParenthesis].join("")}get trailingString(){return[this.closingParenthesis,this.suffix].join("")}finalize(e){return typeof e=="string"&&(e=T.fromString(e)),e.surroundWith(this.leadingString,this.trailingString)}},mi=class extends Ve{constructor(e,t,n){super(e,t,n),this.node=e,this.parent=t,this.options=n,this.type="CollectionPrinter",this.bracketsType="None",this.separator=",",this.printers=[]}setupCollection(e=[],t="None",n){return this.bracketsType=t,this.separator=n??this.separator,this.printers=e,this}getOpeningBracket(e=!1,t="singleLine"){if(this.bracketsType==="None")return"";if(this.bracketsType==="CurlyBrackets")return`{${e||t==="multiline"?"":" "}`;switch(this.bracketsType){case"Parentheses":return"(";case"SquareBrackets":return"[";default:return""}}getClosingBracket(e=!1,t="singleLine"){if(this.bracketsType==="None")return"";if(this.bracketsType==="CurlyBrackets")return`${e||t==="multiline"?"":" "}}`;switch(this.bracketsType){case"Parentheses":return")";case"SquareBrackets":return"]";default:return""}}getLinesLevel(e=0){return this.bracketsType!=="None"||ml(this.parent)||F1(this.parent)||(Vr(this.node)||Ur(this.node))&&(Vr(this.parent)||Ur(this.parent))?e+1:e}finalize(e,t="singleLine",n=0){if(this.bracketsType==="None")return super.finalize(e);let i=this.getOpeningBracket(e.isEmpty,t),r=this.getClosingBracket(e.isEmpty,t);if(t==="singleLine")return super.finalize(e.surroundWith(i,r));let s=dt(n,this.options);return super.finalize(T.appendLines([i,e,s+r]))}singleLineFormat(e=0){let t=this.printers.length-1;return T.joinLines(this.printers.map((n,i)=>n.format("singleLine",e).suffixWith(i<t?this.separator:""))," ")}optimizedPrinterFormat(e,t,n=0){let i=this.getLinesLevel(n),r=dt(i,this.options),s=this.bracketsType==="None"&&t===0?"":r,o=t<this.printers.length-1?this.separator:"",a=e.format("singleLine",i).suffixWith(o);return a.maxLineLength+r.length<=this.options.wrapColumn?a.indentFirstLine(s):e.format("multiline",i).suffixWith(o).indentFirstLine(s)}multilineFormat(e=0){return T.appendLines(this.printers.map((t,n)=>this.optimizedPrinterFormat(t,n,e)))}format(e="singleLine",t=0){if(this.printers.length===0){let i=this.getOpeningBracket(!0,e),r=this.getClosingBracket(!0,e);return super.finalize(T.fromString(i+r))}if(e==="singleLine"){let i=this.singleLineFormat(t);return this.finalize(i,e,t)}let n=this.multilineFormat(t);return this.finalize(n,e,t)}},Hl=/^[a-zA-Z_$][a-zA-Z_$0-9]*$/u,Wr=class extends Ve{constructor(e,t,n){super(e,t,n),this.node=e,this.parent=t,this.options=n,this.type="StringPrinter"}format(){if(Me(this.node))return this.finalize(this.node.name);if(typeof this.node.value!="string")return this.finalize(this.node.raw);if(xl(this.parent)&&this.parent.key===this.node&&L1(this.node)&&typeof this.node.value=="string"&&Hl.test(this.node.value))return this.finalize(this.node.value);switch(this.options.quote){case"auto":{let e=JSON.stringify(this.node.value),t=oi(JSON.stringify(oi(this.node.value)));return this.finalize(e.length>t.length?t:e)}case"single":return this.finalize(oi(JSON.stringify(oi(this.node.value))));default:return this.finalize(JSON.stringify(this.node.value))}}},B1=class extends Ve{constructor(e,t,n){super(e,t,n),this.node=e,this.parent=t,this.options=n,this.type="SingleExpressionPrinter";let i=gl(e),r=pl(e);if(i||r){this.prefix=i?e.operator:"",this.suffix=r&&!e.prefix?e.operator:"",this.printer=Q(e.argument,e,this.options);return}this.printer=Q(e,t,this.options)}format(e="singleLine",t=0){return this.finalize(this.printer.format(e,t))}},qr=class extends Ve{constructor(e,t,n){super(e,t,n),this.node=e,this.parent=t,this.options=n,this.type="VariableDeclaratorsPrinter",e.declarations.length===1?(this.printer=I1(e.declarations[0],e,this.options),this.printer.prefix="var "):this.printer=mt(e,t,this.options)}format(e="singleLine",t=0){return this.finalize(this.printer.format(e,t))}},jl=class extends Ve{constructor(e,t,n){super(e,t,n),this.node=e,this.parent=t,this.options=n,this.type="CallExpressionPrinter",this.argumentsPrinter=new mi(e,t,n),this.argumentsPrinter.setupCollection(e.arguments.map(i=>Q(i,e,n)),"Parentheses"),Me(e.callee)?this.argumentsPrinter.prefix=e.callee.name:this.memberExpressionPrinter=new M1(e.callee,t,n)}format(e="singleLine",t=0){if(!this.memberExpressionPrinter)return this.finalize(this.argumentsPrinter.format(e,t));let n=this.memberExpressionPrinter.format("singleLine",t),i=this.argumentsPrinter.format("singleLine",t);if(e==="singleLine")return this.finalize(T.joinLines([n,i]));let r=jr(t,this.options)+this.leadingString.length+n.firstLinelength;return r+1<this.options.wrapColumn?(i=this.argumentsPrinter.format("multiline",t),this.finalize(T.joinLines([n,i]))):(n=this.memberExpressionPrinter.format("multiline",t),r=n.lastLinelength,r+i.maxLineLength>this.options.wrapColumn&&(i=this.argumentsPrinter.format("multiline",t+1)),this.finalize(T.joinLines([n,i])))}},M1=class extends Ve{constructor(e,t,n){if(super(e,t,n),this.node=e,this.parent=t,this.options=n,this.type="MemberExpressionPrinter",this.objectPrinter=Q(e.object,e,this.options),e.computed){let i=new mi(e.property,e,this.options);i.setupCollection([Q(e.property,e,this.options)],"SquareBrackets"),this.propertyPrinter=i}else{let i=new B1(e.property,e,this.options);i.prefix=".",this.propertyPrinter=i}}format(e="singleLine",t=0){let n=this.objectPrinter.format("singleLine",t),i=this.propertyPrinter.format("singleLine",t);if(e==="singleLine")return this.finalize(T.joinLines([n,i]));let r=jr(t,this.options)+this.leadingString.length+n.firstLinelength;r>this.options.wrapColumn&&(n=this.objectPrinter.format("multiline",t),r=n.lastLinelength);let s=i.firstLinelength+this.trailingString.length;if(r+s<this.options.wrapColumn)return this.finalize(T.joinLines([n,i]));if(this.node.computed)return this.finalize(T.joinLines([n,this.propertyPrinter.format("multiline",t)]));let o=t+1,a=dt(o,this.options);return i=this.propertyPrinter.format("singleLine",t),s=a.length+i.lastLinelength+this.trailingString.length,s>this.options.wrapColumn&&(i=this.propertyPrinter.format("multiline",o)),this.finalize(T.appendLines([n,i.indentFirstLine(a)]))}},Gl=class extends Ve{constructor(e,t,n){super(e,t,n),this.node=e,this.parent=t,this.options=n,this.type="PropertyPrinter",this.key=Q(e.key,e,this.options),e.shorthand||(this.key.suffix=":",this.value=Q(e.value,e,this.options))}format(e="singleLine",t=0){if(this.node.shorthand||!this.value)return this.finalize(this.key.format(e,t));let n=this.key.format("singleLine",t);if(e==="singleLine"){let s=this.value.format("singleLine",t);return this.finalize(T.joinLines([n,s]," "))}if(hi(this.node.value)||hi(this.node.value)){let s=this.value.format("multiline",t);return this.finalize(T.joinLines([n,s]," "))}let i=dt(t+1,this.options),r=this.value.format("singleLine",t+1).indentFirstLine(i);return r.maxLineLength+this.trailingString.length+1<=this.options.wrapColumn?this.finalize(T.appendLines([n,r])):(r=this.value.format("multiline",t+1).indentFirstLine(i),this.finalize(T.appendLines([n,r])))}},Gr=class extends Ve{constructor(e,t,n){switch(super(e,t,n),this.node=e,this.parent=t,this.options=n,this.type="OperationPrinter",this.operator="",this.noNewLineWrapping=!1,e.type){case g.AssignmentExpression:this.leftPrinter=Q(e.left,e,this.options),this.operator=` ${e.operator}`,this.rightPrinter=Q(e.right,e,this.options),this.noNewLineWrapping=(Me(e.left)||L1(e.left))&&(hi(e.right)||r1(e.right));return;case g.VariableDeclarator:this.leftPrinter=Q(e.id,e,this.options),e.init&&(this.operator=" =",this.rightPrinter=Q(e.init,e,this.options)),this.noNewLineWrapping=hi(e.init)||r1(e.init);return;case g.ForInStatement:this.leftPrinter=Q(e.left,e,this.options),this.operator=" in",this.rightPrinter=Q(e.right,e,this.options);return;case g.BinaryExpression:case g.LogicalExpression:this.leftPrinter=Q(e.left,e,this.options),this.operator=` ${e.operator}`,this.rightPrinter=Q(e.right,e,this.options);return}}format(e="singleLine",t=0){if(!this.rightPrinter)return this.finalize(this.leftPrinter.format(e,t));let n=this.leftPrinter.format("singleLine",t).suffixWith(this.operator),i=this.rightPrinter.format("singleLine",t);if(e==="singleLine")return this.finalize(T.joinLines([n,i]," "));let r=jr(t,this.options)+this.leadingString.length+n.maxLineLength+1;r>this.options.wrapColumn&&(n=this.leftPrinter.format("multiline",t).suffixWith(this.operator),r=n.lastLinelength+1);let s=i.firstLinelength+this.trailingString.length+1;if(r+s<this.options.wrapColumn)return this.finalize(T.joinLines([n,i]," "));let o=this.rightPrinter.format("multiline",t);return o.firstLinelength+this.trailingString.length+1+r<this.options.wrapColumn||this.noNewLineWrapping?this.finalize(T.joinLines([n,o]," ")):(s>this.options.wrapColumn&&(i=this.rightPrinter.format("multiline",t+1)),i=i.indentFirstLine(dt(t+1)),this.finalize(T.appendLines([n,i])))}},Xl=class extends Ve{constructor(e,t,n){super(e,t,n),this.node=e,this.parent=t,this.options=n,this.type="TemplateLiteralPrinter",this.parts=[];let i=e.expressions.map(r=>Q(r,e,this.options));this.parts.push("`"),e.quasis.forEach((r,s)=>{this.parts.push(r.value.raw),s<i.length&&(this.parts.push("${"),this.parts.push(i[s]),this.parts.push("}"))}),this.parts.push("`")}format(e="singleLine",t=0){return this.finalize(T.joinLines(this.parts.map(n=>typeof n=="string"?n:n.format(e,t))))}};function Jl(e){let t={...e.leadingComments?.slice(0,1)[0]?.loc.start??e.loc.start},n={...e.trailingComments?.slice(-1)[0]?.loc.end??e.loc.end};return{start:t,end:n}}function Ql(e){return e.trailingComments?.slice(-1)[0]?.type===g.LineComment}var ze=class{constructor(e,t,n){this.node=e,this.parent=t,this.options=n,this.indentStatementFirstLine=!0,this.externalOffset=0,this.options=Hr(this.options)}createStatementPrinter(e){switch(e.type){case g.Program:return new cn(e,this.node,this.options);case g.ImportDeclaration:return new n0(e,this.node,this.options);case g.ExpressionStatement:return new e0(e,this.node,this.options);case g.FunctionDeclaration:return new x1(e,this.node,this.options);case g.ExportNamedDeclaration:return ci(e)?new p1(e,this.node,this.options):new x1(e,this.node,this.options);case g.BlockStatement:return new cn(e,this.node,this.options);case g.ReturnStatement:return new t0(e,this.node,this.options);case g.VariableDeclaration:return new p1(e,this.node,this.options);case g.IfStatement:return new Zl(e,this.node,this.options);case g.ForStatement:case g.ForInStatement:case g.WhileStatement:return new Kl(e,this.node,this.options);case g.EmptyStatement:case g.BreakStatement:case g.ContinueStatement:return new Yl(e,this.node,this.options);default:throw new Error(`unknown type: ${JSON.stringify(e)}`)}}getFormattedBody(e,t=0){if(this.cachedBody&&this.cachedBody.level===t)return this.cachedBody.body;let n=e.format(t);return this.cachedBody={body:n,level:t},n}getStatementIndentation(e=0){return this.indentStatementFirstLine?dt(e,this.options):""}getStatementIndentationLength(e=0){return this.indentStatementFirstLine?e*this.options.indentWidth:0}getIndentation(e=0){return dt(e,this.options)}addComments(e,t=0){let n=this.getStatementIndentation(t);if(!this.node.leadingComments?.length&&!this.node.trailingComments?.length)return e.indentFirstLine(n);let i=(this.node.leadingComments??[]).reduce((s,o)=>{let a=this.formatComment(o);return{formattedLines:T.aggregateLines(s.formattedLines,s.location,a,o.loc,n),location:o.loc}},{formattedLines:new T}),r=T.aggregateLines(i.formattedLines,i.location,e,this.node.loc,n);return(this.node.trailingComments?.reduce((s,o)=>{let a=this.formatComment(o);return{formattedLines:T.aggregateLines(s.formattedLines,s.location,a,o.loc,n),location:o.loc}},{formattedLines:r,location:this.node.loc})??{formattedLines:r}).formattedLines}formatInnerComments(e=0){if(!Re(this.node)||!Array.isArray(this.node.innerComments)||!this.node.innerComments.length)return new T;let t=this.getIndentation(e);return this.node.innerComments.reduce((n,i)=>{let r=this.formatComment(i);return{formattedLines:T.aggregateLines(n.formattedLines,n.location,r,i.loc,t),location:i.loc}},{formattedLines:new T}).formattedLines}formatComment(e){switch(e.type){case g.BlockComment:return T.fromString(e.value).surroundWith("/*","*/");default:return T.fromString(e.value.trimEnd()).surroundWith("//")}}canFitSingleLine(e,t=0,n=0){return this.externalOffset+n+this.getStatementIndentationLength(t)+e.lastLinelength<=this.options.wrapColumn}},cn=class extends ze{constructor(e,t,n){super(e,t,n),this.node=e,this.printers=[],this.printers=e.body.map(i=>this.createStatementPrinter(i))}format(e=0){if(this.printers.length===0)return this.formatEmptyBlock(e);let t=[],n=Re(this.node);n&&t.push("{");let i=n?e+1:e,r;return this.printers.forEach(s=>{if($r(s.node))return;let o=Jl(s.node);r&&o.start.line-r.end.line>1&&t.push(""),r=o,t.push(s.format(i))}),n&&t.push(`${this.getIndentation(e)}}`),this.addComments(T.appendLines(t),e)}formatEmptyBlock(e=0){if(!Re(this.node))return this.addComments(T.fromString(""),e);let t=this.formatInnerComments(e+1),n="{",i=`${this.getIndentation(e)}}`;return t.isEmpty?Tr(this.parent)?this.addComments(T.appendLines([n,i]),e):this.addComments(T.fromString("{}"),e):this.addComments(T.appendLines([n,t,i]),e)}},Yl=class extends ze{constructor(e,t,n){switch(super(e,t,n),this.node=e,this.keyword="",this.node.type){case g.ContinueStatement:this.keyword="continue;";break;case g.BreakStatement:this.keyword="break;";break;default:this.keyword=";"}}format(e=0){return this.addComments(T.fromString(this.keyword),e)}},p1=class extends ze{constructor(e,t,n){if(super(e,t,n),this.node=e,ci(e))this.printer=new qr(e,t,n);else if(ci(e.declaration))this.printer=new qr(e.declaration,t,n),this.printer.prefix="export ";else throw new Error(`invalid type: ${JSON.stringify(e)}`)}format(e=0,t="optimized"){if(t==="singleLine"||t==="optimized"){let n=this.printer.format("singleLine",e).suffixWith(";");if(t==="singleLine"||this.canFitSingleLine(n,e))return this.addComments(n,e)}return this.addComments(this.printer.format("multiline",e).suffixWith(";"),e)}},x1=class extends ze{constructor(e,t,n){if(super(e,t,n),this.node=e,i1(e))this.header=mt(e,t,n),this.body=new cn(e.body,e,n);else if(i1(e.declaration))this.header=mt(e.declaration,t,n),this.header.prefix="export ",this.body=new cn(e.declaration.body,e,n);else throw new Error(`invalid type: ${JSON.stringify(e)}`)}format(e=0,t="optimized"){this.body.indentStatementFirstLine=!1;let n=this.getFormattedBody(this.body,e);if(t==="singleLine"||t==="optimized"){let r=this.header.format("singleLine",e);if(t==="singleLine"||this.canFitSingleLine(r,e,n.firstLinelength+1))return this.addComments(T.joinLines([r,n]," "),e)}let i=this.header.format("multiline",e);return this.addComments(T.joinLines([i,n]," "),e)}},Zl=class extends ze{constructor(e,t,n){super(e,t,n),this.node=e,this.header=mt(e,t,n),this.consequent=this.createStatementPrinter(e.consequent),this.consequent.indentStatementFirstLine=!1,e.alternate&&(this.alternate=this.createStatementPrinter(e.alternate),this.alternate.indentStatementFirstLine=!1)}format(e=0,t="optimized"){let n=!1,i;if(t==="singleLine"||t==="optimized"){let a=this.header.format("singleLine",e),l=Re(this.node.consequent)?2:0;(t==="singleLine"||this.canFitSingleLine(a,e,l))&&(i=a)}i||(n=!0,i=this.header.format("multiline",e));let r;if(Re(this.node.consequent)){let a=this.consequent.format(e,"optimized");r=T.joinLines([i," ",a])}else if(n||Tr(this.node.consequent)){this.consequent.indentStatementFirstLine=!0;let a=this.consequent.format(e+1,"singleLine");this.canFitSingleLine(a,e+1)||(a=this.consequent.format(e+1,"multiline")),r=T.appendLines([i,a])}else{this.consequent.indentStatementFirstLine=!1;let a=this.consequent.format(e,"singleLine");this.canFitSingleLine(a,0,i.lastLinelength+1)?r=T.joinLines([i," ",a]):(this.consequent.indentStatementFirstLine=!0,a=this.consequent.format(e+1,"optimized"),r=T.appendLines([i,a]))}if(!this.alternate)return this.addComments(r,e);let s=Ql(this.node.consequent)||!Re(this.node.consequent),o;if(this.alternate.externalOffset=0,Re(this.node.alternate)||Tr(this.node.alternate))this.alternate.indentStatementFirstLine=!1,this.alternate.externalOffset=s?5:r.lastLinelength+6,o=this.alternate.format(e,"optimized"),o=T.joinLines(["else ",o]);else{let a=s?4:r.lastLinelength+4;this.alternate.indentStatementFirstLine=!1,o=this.alternate.format(e,"singleLine"),this.canFitSingleLine(o,e,a+1)?o=T.joinLines(["else ",o]):(this.alternate.indentStatementFirstLine=!0,o=this.alternate.format(e+1,"optimized"),o=T.appendLines(["else",o]))}return s?r=T.appendLines([r,o.indentFirstLine(this.getIndentation(e))]):r=T.joinLines([r,o]," "),this.addComments(r,e)}},Kl=class extends ze{constructor(e,t,n){super(e,t,n),this.node=e,this.header=mt(e,t,n),this.body=this.createStatementPrinter(e.body)}format(e=0,t="optimized"){this.body.indentStatementFirstLine=!1;let n=this.getFormattedBody(this.body,e);if(t==="singleLine"||t==="optimized"){let r=this.header.format("singleLine",e);if(t==="singleLine"||this.canFitSingleLine(r,e,n.firstLinelength+1))return this.addComments(T.joinLines([r,n]," "),e)}let i=this.header.format("multiline",e);return this.addComments(T.joinLines([i,n]," "),e)}},e0=class extends ze{constructor(e,t,n){super(e,t,n),this.node=e,this.expression=Q(e.expression,e,n)}format(e=0,t="optimized"){if(t==="singleLine"||t==="optimized"){let n=this.expression.format("singleLine",e).suffixWith(";");if(t==="singleLine"||this.canFitSingleLine(n,e))return this.addComments(n,e)}return this.addComments(this.expression.format("multiline",e).suffixWith(";"),e)}},t0=class extends ze{constructor(e,t,n){super(e,t,n),this.node=e,this.argument=Q(e.argument,e,n)}format(e=0,t="optimized"){if(t==="singleLine"||t==="optimized"){let s=this.argument.format("singleLine",e).surroundWith("return ",";");if(t==="singleLine"||this.canFitSingleLine(s,e))return this.addComments(s,e)}if(!Vr(this.node.argument)&&!Ur(this.node.argument)){let s=this.argument.format("multiline",e).surroundWith("return ",";");return this.addComments(s,e)}let n=this.getIndentation(e+1),i=this.argument.format("multiline",e+1).indentFirstLine(n),r=this.getIndentation(e);return this.addComments(T.appendLines(["return (",i,`${r});`]),e)}},n0=class extends ze{constructor(e,t,n){super(e,t,n),this.node=e,this.libname=Q(e.specifiers[0].local,e,n),this.libsource=Q(e.source,e,n)}format(e=0){return this.addComments(T.joinLines(["import"," ",this.libname.format("singleLine",e)," from ",this.libsource.format("singleLine")]).suffixWith(";"),e)}},i0={quote:"auto"};function R1(e,t={}){try{let n=e.getText(),i=e.positionAt(n.length),r={start:{line:0,character:0},end:i},s={...i0,...t.formattingOptions??{}},o=r0(n,s);return[{range:r,newText:o}]}catch(n){return console.error("Arcade Formatting Error:",n),[]}}function r0(e,t){if(!e)return"";let n=Hr(t),i=zl.fromString(e,n),r=i.toString(),s=N1(r,{tolerant:!0,comments:!0}),o=Rl(s,i);return s.loc.start=o.start,s.loc.end=o.end,new cn(s,null,n).format().toString()}var s0=Object.values(q),o0=Object.values(un),a0=["case","catch","debugger","switch","try"],u0=o0.map(e=>({label:e,kind:ee.Constant})),l0=s0.map(e=>({label:e,kind:ee.Keyword})),c0=[{label:"exportfunction",kind:ee.Snippet,detail:"Export Function Statement",insertText:`export function \${1:functionName} ($2) {
29
+ `)}};function Ol(e,t=2){let n=0,i=e.length;for(let r=0;r<i;r++)switch(e.charCodeAt(r)){case 9:{let s=Math.ceil(n/t)*t;s===n?n+=t:n=s;break}case 11:case 12:case 13:case 65279:break;case 32:default:n+=1;break}return n}function Tt(e,t,n){let i=e.sliceStart,r=e.sliceEnd,s=Math.max(e.indentation,0),o=s+r-i;return n??(n=o),t=Math.max(t,0),n=Math.min(n,o),n=Math.max(n,t),n<s?(s=n,r=i):r-=o-n,o=n,o-=t,t<s?s-=t:(t-=s,s=0,i+=t),e.indentation===s&&e.sliceStart===i&&e.sliceEnd===r?e:{line:e.line,indentation:s,sliceStart:i,sliceEnd:r}}function g1(e,t,n){return!e&&!n?"":e?n?`${e}${t}${n}`:e:n}var Wl=/\u000D\u000A|\u000D(?!\u000A)|\u000A|\u2028|\u2029/u,T=class Ue{constructor(t=[]){this.lines=t}static fromString(t){return new Ue(t.split(Wl))}static appendLines(t=[]){let n=new Ue;return t.forEach(i=>{i!=null&&(typeof i=="string"?n.lines.push(i):n.lines.push(...i.lines))}),n}static joinLines(t=[],n=""){let i=new Ue;return t.forEach(r=>{if(r==null)return;let s=i.lines.pop()??"";typeof r=="string"?i.lines.push(g1(s,n,r)):(i.lines.push(g1(s,n,r.lines.slice(0)[0])),i.lines.push(...r.lines.slice(1)))}),i}static aggregateLines(t,n,i,r,s){if(i.isEmpty)return t;if(!n||t.isEmpty)return i.indentFirstLine(s);let o=r.start.line-n.end.line;if(o===0)return Ue.joinLines([t," ",i]);let a=o===1?void 0:"";return Ue.appendLines([t,a,i.indentFirstLine(s)])}get isEmpty(){return this.lines.length===0||this.lines.length===1&&this.lines[0].length===0}get maxLineLength(){return this.lines.reduce((t,n)=>Math.max(t,n.length),0)}get firstLineLength(){return(this.lines[0]??"").length}get lastLineLength(){return(this.lines[this.lines.length-1]??"").length}surroundWith(t="",n=""){return!t&&!n?this:this.isEmpty?new Ue([t+n]):this.lines.length===1?new Ue([t+this.lines[0]+n]):Ue.joinLines([t,this,n])}indentFirstLine(t=""){return this.isEmpty?this:(this.lines[0]=t+this.lines[0],this)}suffixWith(t){return this.surroundWith("",t)}toString(t=`
30
+ `){return this.lines.join(t)}};function jr(e,t){return e*(t.indentWidth??2)}function dt(e=0,t){let{indentWidth:n=2}=Hr(t);return new Array(e*n+1).join(" ")}function oi(e){return e.replace(/['"]/gu,t=>t==='"'?"'":'"')}function ql(e,t){switch(e.type){case g.UnaryExpression:return s1(t)&&t.object===e;case g.BinaryExpression:case g.LogicalExpression:switch(t.type){case g.UnaryExpression:return!0;case g.MemberExpression:return t.object===e;case g.BinaryExpression:case g.LogicalExpression:return ui[t.operator]>ui[e.operator];default:return!1}case g.Literal:return s1(t)&&typeof e.value=="number"&&t.object===e;case g.AssignmentExpression:switch(t.type){case g.UnaryExpression:case g.BinaryExpression:case g.LogicalExpression:case g.ReturnStatement:return!0;case g.MemberExpression:return t.object===e;default:return!1}default:return!1}}function Q(e,t,n){switch(e?.type){case g.BinaryExpression:case g.LogicalExpression:return $l(e,t,n);case g.AssignmentExpression:return new Gr(e,t,n);case g.MemberExpression:return new M1(e,t,n);case g.Identifier:return new Wr(e,t,n);case g.CallExpression:return new jl(e,t,n);case g.ObjectExpression:return mt(e,t,n);case g.ArrayExpression:return mt(e,t,n);case g.Literal:return new Wr(e,t,n);case g.UpdateExpression:case g.UnaryExpression:return new B1(e,t,n);case g.TemplateLiteral:return new Xl(e,t,n);case g.VariableDeclaration:return new qr(e,t,n);default:throw new Error(`unknown type: ${JSON.stringify(e)}`)}}function mt(e,t,n){let i=new mi(e,t,n);switch(e.type){case g.ArrayExpression:return i.setupCollection(e.elements.map(r=>Q(r,e,n)),"SquareBrackets"),i;case g.ObjectExpression:return i.setupCollection(e.properties.map(r=>new Gl(r,e,n)),"CurlyBrackets"),i;case g.VariableDeclaration:return i.prefix="var ",i.setupCollection(e.declarations.map(r=>I1(r,e,n)),"None"),i;case g.FunctionDeclaration:return i.prefix=`function ${e.id.name}`,i.setupCollection(e.params.map(r=>Q(r,e,n)),"Parentheses"),i;case g.ForStatement:return i.prefix="for ",i.setupCollection([Q(e.init,e,n),Q(e.test,e,n),Q(e.update,e,n)],"Parentheses",";"),i;case g.ForInStatement:return i.prefix="for ",i.setupCollection([new Gr(e,t,n)],"Parentheses",""),i;case g.IfStatement:return i.prefix="if ",i.setupCollection([Q(e.test,e,n)],"Parentheses",""),i;case g.WhileStatement:return i.prefix="while ",i.setupCollection([Q(e.test,e,n)],"Parentheses",""),i;default:return i}}function I1(e,t,n){return e.init?new Gr(e,t,n):new Wr(e.id,t,n)}function $l(e,t,n){let i=[...di(e.left,e.operator),...di(e.right,e.operator)].map(s=>Q(s,e,n)),r=new mi(e,t,n);return r.setupCollection(i,"None",` ${e.operator}`),r}function di(e,t){return e.type!==g.BinaryExpression&&e.type!==g.LogicalExpression?[e]:e.operator!==t?[e]:[...di(e.left,t),...di(e.right,t)]}var Ve=class{constructor(e,t,n){this.node=e,this.parent=t,this.options=n,this.prefix="",this.suffix="",this.groupingParentheses=!1,this.groupingParentheses=ql(e,t)}get openingParenthesis(){return this.groupingParentheses?"(":""}get closingParenthesis(){return this.groupingParentheses?")":""}get leadingString(){return[this.prefix,this.openingParenthesis].join("")}get trailingString(){return[this.closingParenthesis,this.suffix].join("")}finalize(e){return typeof e=="string"&&(e=T.fromString(e)),e.surroundWith(this.leadingString,this.trailingString)}},mi=class extends Ve{constructor(e,t,n){super(e,t,n),this.node=e,this.parent=t,this.options=n,this.type="CollectionPrinter",this.bracketsType="None",this.separator=",",this.printers=[]}setupCollection(e=[],t="None",n){return this.bracketsType=t,this.separator=n??this.separator,this.printers=e,this}getOpeningBracket(e=!1,t="singleLine"){if(this.bracketsType==="None")return"";if(this.bracketsType==="CurlyBrackets")return`{${e||t==="multiline"?"":" "}`;switch(this.bracketsType){case"Parentheses":return"(";case"SquareBrackets":return"[";default:return""}}getClosingBracket(e=!1,t="singleLine"){if(this.bracketsType==="None")return"";if(this.bracketsType==="CurlyBrackets")return`${e||t==="multiline"?"":" "}}`;switch(this.bracketsType){case"Parentheses":return")";case"SquareBrackets":return"]";default:return""}}getLinesLevel(e=0){return this.bracketsType!=="None"||ml(this.parent)||F1(this.parent)||(Vr(this.node)||Ur(this.node))&&(Vr(this.parent)||Ur(this.parent))?e+1:e}finalize(e,t="singleLine",n=0){if(this.bracketsType==="None")return super.finalize(e);let i=this.getOpeningBracket(e.isEmpty,t),r=this.getClosingBracket(e.isEmpty,t);if(t==="singleLine")return super.finalize(e.surroundWith(i,r));let s=dt(n,this.options);return super.finalize(T.appendLines([i,e,s+r]))}singleLineFormat(e=0){let t=this.printers.length-1;return T.joinLines(this.printers.map((n,i)=>n.format("singleLine",e).suffixWith(i<t?this.separator:""))," ")}optimizedPrinterFormat(e,t,n=0){let i=this.getLinesLevel(n),r=dt(i,this.options),s=this.bracketsType==="None"&&t===0?"":r,o=t<this.printers.length-1?this.separator:"",a=e.format("singleLine",i).suffixWith(o);return a.maxLineLength+r.length<=this.options.wrapColumn?a.indentFirstLine(s):e.format("multiline",i).suffixWith(o).indentFirstLine(s)}multilineFormat(e=0){return T.appendLines(this.printers.map((t,n)=>this.optimizedPrinterFormat(t,n,e)))}format(e="singleLine",t=0){if(this.printers.length===0){let i=this.getOpeningBracket(!0,e),r=this.getClosingBracket(!0,e);return super.finalize(T.fromString(i+r))}if(e==="singleLine"){let i=this.singleLineFormat(t);return this.finalize(i,e,t)}let n=this.multilineFormat(t);return this.finalize(n,e,t)}},Hl=/^[a-zA-Z_$][a-zA-Z_$0-9]*$/u,Wr=class extends Ve{constructor(e,t,n){super(e,t,n),this.node=e,this.parent=t,this.options=n,this.type="StringPrinter"}format(){if(Me(this.node))return this.finalize(this.node.name);if(typeof this.node.value!="string")return this.finalize(this.node.raw);if(xl(this.parent)&&this.parent.key===this.node&&L1(this.node)&&typeof this.node.value=="string"&&Hl.test(this.node.value))return this.finalize(this.node.value);switch(this.options.quote){case"auto":{let e=JSON.stringify(this.node.value),t=oi(JSON.stringify(oi(this.node.value)));return this.finalize(e.length>t.length?t:e)}case"single":return this.finalize(oi(JSON.stringify(oi(this.node.value))));default:return this.finalize(JSON.stringify(this.node.value))}}},B1=class extends Ve{constructor(e,t,n){super(e,t,n),this.node=e,this.parent=t,this.options=n,this.type="SingleExpressionPrinter";let i=gl(e),r=pl(e);if(i||r){this.prefix=i?e.operator:"",this.suffix=r&&!e.prefix?e.operator:"",this.printer=Q(e.argument,e,this.options);return}this.printer=Q(e,t,this.options)}format(e="singleLine",t=0){return this.finalize(this.printer.format(e,t))}},qr=class extends Ve{constructor(e,t,n){super(e,t,n),this.node=e,this.parent=t,this.options=n,this.type="VariableDeclaratorsPrinter",e.declarations.length===1?(this.printer=I1(e.declarations[0],e,this.options),this.printer.prefix="var "):this.printer=mt(e,t,this.options)}format(e="singleLine",t=0){return this.finalize(this.printer.format(e,t))}},jl=class extends Ve{constructor(e,t,n){super(e,t,n),this.node=e,this.parent=t,this.options=n,this.type="CallExpressionPrinter",this.argumentsPrinter=new mi(e,t,n),this.argumentsPrinter.setupCollection(e.arguments.map(i=>Q(i,e,n)),"Parentheses"),Me(e.callee)?this.argumentsPrinter.prefix=e.callee.name:this.memberExpressionPrinter=new M1(e.callee,t,n)}format(e="singleLine",t=0){if(!this.memberExpressionPrinter)return this.finalize(this.argumentsPrinter.format(e,t));let n=this.memberExpressionPrinter.format("singleLine",t),i=this.argumentsPrinter.format("singleLine",t);if(e==="singleLine")return this.finalize(T.joinLines([n,i]));let r=jr(t,this.options)+this.leadingString.length+n.firstLineLength;return r+1<this.options.wrapColumn?(i=this.argumentsPrinter.format("multiline",t),this.finalize(T.joinLines([n,i]))):(n=this.memberExpressionPrinter.format("multiline",t),r=n.lastLineLength,r+i.maxLineLength>this.options.wrapColumn&&(i=this.argumentsPrinter.format("multiline",t+1)),this.finalize(T.joinLines([n,i])))}},M1=class extends Ve{constructor(e,t,n){if(super(e,t,n),this.node=e,this.parent=t,this.options=n,this.type="MemberExpressionPrinter",this.objectPrinter=Q(e.object,e,this.options),e.computed){let i=new mi(e.property,e,this.options);i.setupCollection([Q(e.property,e,this.options)],"SquareBrackets"),this.propertyPrinter=i}else{let i=new B1(e.property,e,this.options);i.prefix=".",this.propertyPrinter=i}}format(e="singleLine",t=0){let n=this.objectPrinter.format("singleLine",t),i=this.propertyPrinter.format("singleLine",t);if(e==="singleLine")return this.finalize(T.joinLines([n,i]));let r=jr(t,this.options)+this.leadingString.length+n.firstLineLength;r>this.options.wrapColumn&&(n=this.objectPrinter.format("multiline",t),r=n.lastLineLength);let s=i.firstLineLength+this.trailingString.length;if(r+s<this.options.wrapColumn)return this.finalize(T.joinLines([n,i]));if(this.node.computed)return this.finalize(T.joinLines([n,this.propertyPrinter.format("multiline",t)]));let o=t+1,a=dt(o,this.options);return i=this.propertyPrinter.format("singleLine",t),s=a.length+i.lastLineLength+this.trailingString.length,s>this.options.wrapColumn&&(i=this.propertyPrinter.format("multiline",o)),this.finalize(T.appendLines([n,i.indentFirstLine(a)]))}},Gl=class extends Ve{constructor(e,t,n){super(e,t,n),this.node=e,this.parent=t,this.options=n,this.type="PropertyPrinter",this.key=Q(e.key,e,this.options),e.shorthand||(this.key.suffix=":",this.value=Q(e.value,e,this.options))}format(e="singleLine",t=0){if(this.node.shorthand||!this.value)return this.finalize(this.key.format(e,t));let n=this.key.format("singleLine",t);if(e==="singleLine"){let s=this.value.format("singleLine",t);return this.finalize(T.joinLines([n,s]," "))}if(hi(this.node.value)||hi(this.node.value)){let s=this.value.format("multiline",t);return this.finalize(T.joinLines([n,s]," "))}let i=dt(t+1,this.options),r=this.value.format("singleLine",t+1).indentFirstLine(i);return r.maxLineLength+this.trailingString.length+1<=this.options.wrapColumn?this.finalize(T.appendLines([n,r])):(r=this.value.format("multiline",t+1).indentFirstLine(i),this.finalize(T.appendLines([n,r])))}},Gr=class extends Ve{constructor(e,t,n){switch(super(e,t,n),this.node=e,this.parent=t,this.options=n,this.type="OperationPrinter",this.operator="",this.noNewLineWrapping=!1,e.type){case g.AssignmentExpression:this.leftPrinter=Q(e.left,e,this.options),this.operator=` ${e.operator}`,this.rightPrinter=Q(e.right,e,this.options),this.noNewLineWrapping=(Me(e.left)||L1(e.left))&&(hi(e.right)||r1(e.right));return;case g.VariableDeclarator:this.leftPrinter=Q(e.id,e,this.options),e.init&&(this.operator=" =",this.rightPrinter=Q(e.init,e,this.options)),this.noNewLineWrapping=hi(e.init)||r1(e.init);return;case g.ForInStatement:this.leftPrinter=Q(e.left,e,this.options),this.operator=" in",this.rightPrinter=Q(e.right,e,this.options);return;case g.BinaryExpression:case g.LogicalExpression:this.leftPrinter=Q(e.left,e,this.options),this.operator=` ${e.operator}`,this.rightPrinter=Q(e.right,e,this.options);return}}format(e="singleLine",t=0){if(!this.rightPrinter)return this.finalize(this.leftPrinter.format(e,t));let n=this.leftPrinter.format("singleLine",t).suffixWith(this.operator),i=this.rightPrinter.format("singleLine",t);if(e==="singleLine")return this.finalize(T.joinLines([n,i]," "));let r=jr(t,this.options)+this.leadingString.length+n.maxLineLength+1;r>this.options.wrapColumn&&(n=this.leftPrinter.format("multiline",t).suffixWith(this.operator),r=n.lastLineLength+1);let s=i.firstLineLength+this.trailingString.length+1;if(r+s<this.options.wrapColumn)return this.finalize(T.joinLines([n,i]," "));let o=this.rightPrinter.format("multiline",t);return o.firstLineLength+this.trailingString.length+1+r<this.options.wrapColumn||this.noNewLineWrapping?this.finalize(T.joinLines([n,o]," ")):(s>this.options.wrapColumn&&(i=this.rightPrinter.format("multiline",t+1)),i=i.indentFirstLine(dt(t+1)),this.finalize(T.appendLines([n,i])))}},Xl=class extends Ve{constructor(e,t,n){super(e,t,n),this.node=e,this.parent=t,this.options=n,this.type="TemplateLiteralPrinter",this.parts=[];let i=e.expressions.map(r=>Q(r,e,this.options));this.parts.push("`"),e.quasis.forEach((r,s)=>{this.parts.push(r.value.raw),s<i.length&&(this.parts.push("${"),this.parts.push(i[s]),this.parts.push("}"))}),this.parts.push("`")}format(e="singleLine",t=0){return this.finalize(T.joinLines(this.parts.map(n=>typeof n=="string"?n:n.format(e,t))))}};function Jl(e){let t={...e.leadingComments?.slice(0,1)[0]?.loc.start??e.loc.start},n={...e.trailingComments?.slice(-1)[0]?.loc.end??e.loc.end};return{start:t,end:n}}function Ql(e){return e.trailingComments?.slice(-1)[0]?.type===g.LineComment}var ze=class{constructor(e,t,n){this.node=e,this.parent=t,this.options=n,this.indentStatementFirstLine=!0,this.externalOffset=0,this.options=Hr(this.options)}createStatementPrinter(e){switch(e.type){case g.Program:return new cn(e,this.node,this.options);case g.ImportDeclaration:return new n0(e,this.node,this.options);case g.ExpressionStatement:return new e0(e,this.node,this.options);case g.FunctionDeclaration:return new x1(e,this.node,this.options);case g.ExportNamedDeclaration:return ci(e)?new p1(e,this.node,this.options):new x1(e,this.node,this.options);case g.BlockStatement:return new cn(e,this.node,this.options);case g.ReturnStatement:return new t0(e,this.node,this.options);case g.VariableDeclaration:return new p1(e,this.node,this.options);case g.IfStatement:return new Zl(e,this.node,this.options);case g.ForStatement:case g.ForInStatement:case g.WhileStatement:return new Kl(e,this.node,this.options);case g.EmptyStatement:case g.BreakStatement:case g.ContinueStatement:return new Yl(e,this.node,this.options);default:throw new Error(`unknown type: ${JSON.stringify(e)}`)}}getFormattedBody(e,t=0){if(this.cachedBody&&this.cachedBody.level===t)return this.cachedBody.body;let n=e.format(t);return this.cachedBody={body:n,level:t},n}getStatementIndentation(e=0){return this.indentStatementFirstLine?dt(e,this.options):""}getStatementIndentationLength(e=0){return this.indentStatementFirstLine?e*this.options.indentWidth:0}getIndentation(e=0){return dt(e,this.options)}addComments(e,t=0){let n=this.getStatementIndentation(t);if(!this.node.leadingComments?.length&&!this.node.trailingComments?.length)return e.indentFirstLine(n);let i=(this.node.leadingComments??[]).reduce((s,o)=>{let a=this.formatComment(o);return{formattedLines:T.aggregateLines(s.formattedLines,s.location,a,o.loc,n),location:o.loc}},{formattedLines:new T}),r=T.aggregateLines(i.formattedLines,i.location,e,this.node.loc,n);return(this.node.trailingComments?.reduce((s,o)=>{let a=this.formatComment(o);return{formattedLines:T.aggregateLines(s.formattedLines,s.location,a,o.loc,n),location:o.loc}},{formattedLines:r,location:this.node.loc})??{formattedLines:r}).formattedLines}formatInnerComments(e=0){if(!Re(this.node)||!Array.isArray(this.node.innerComments)||!this.node.innerComments.length)return new T;let t=this.getIndentation(e);return this.node.innerComments.reduce((n,i)=>{let r=this.formatComment(i);return{formattedLines:T.aggregateLines(n.formattedLines,n.location,r,i.loc,t),location:i.loc}},{formattedLines:new T}).formattedLines}formatComment(e){switch(e.type){case g.BlockComment:return T.fromString(e.value).surroundWith("/*","*/");default:return T.fromString(e.value.trimEnd()).surroundWith("//")}}canFitSingleLine(e,t=0,n=0){return this.externalOffset+n+this.getStatementIndentationLength(t)+e.lastLineLength<=this.options.wrapColumn}},cn=class extends ze{constructor(e,t,n){super(e,t,n),this.node=e,this.printers=[],this.printers=e.body.map(i=>this.createStatementPrinter(i))}format(e=0){if(this.printers.length===0)return this.formatEmptyBlock(e);let t=[],n=Re(this.node);n&&t.push("{");let i=n?e+1:e,r;return this.printers.forEach(s=>{if($r(s.node))return;let o=Jl(s.node);r&&o.start.line-r.end.line>1&&t.push(""),r=o,t.push(s.format(i))}),n&&t.push(`${this.getIndentation(e)}}`),this.addComments(T.appendLines(t),e)}formatEmptyBlock(e=0){if(!Re(this.node))return this.addComments(T.fromString(""),e);let t=this.formatInnerComments(e+1),n="{",i=`${this.getIndentation(e)}}`;return t.isEmpty?Tr(this.parent)?this.addComments(T.appendLines([n,i]),e):this.addComments(T.fromString("{}"),e):this.addComments(T.appendLines([n,t,i]),e)}},Yl=class extends ze{constructor(e,t,n){switch(super(e,t,n),this.node=e,this.keyword="",this.node.type){case g.ContinueStatement:this.keyword="continue;";break;case g.BreakStatement:this.keyword="break;";break;default:this.keyword=";"}}format(e=0){return this.addComments(T.fromString(this.keyword),e)}},p1=class extends ze{constructor(e,t,n){if(super(e,t,n),this.node=e,ci(e))this.printer=new qr(e,t,n);else if(ci(e.declaration))this.printer=new qr(e.declaration,t,n),this.printer.prefix="export ";else throw new Error(`invalid type: ${JSON.stringify(e)}`)}format(e=0,t="optimized"){if(t==="singleLine"||t==="optimized"){let n=this.printer.format("singleLine",e).suffixWith(";");if(t==="singleLine"||this.canFitSingleLine(n,e))return this.addComments(n,e)}return this.addComments(this.printer.format("multiline",e).suffixWith(";"),e)}},x1=class extends ze{constructor(e,t,n){if(super(e,t,n),this.node=e,i1(e))this.header=mt(e,t,n),this.body=new cn(e.body,e,n);else if(i1(e.declaration))this.header=mt(e.declaration,t,n),this.header.prefix="export ",this.body=new cn(e.declaration.body,e,n);else throw new Error(`invalid type: ${JSON.stringify(e)}`)}format(e=0,t="optimized"){this.body.indentStatementFirstLine=!1;let n=this.getFormattedBody(this.body,e);if(t==="singleLine"||t==="optimized"){let r=this.header.format("singleLine",e);if(t==="singleLine"||this.canFitSingleLine(r,e,n.firstLineLength+1))return this.addComments(T.joinLines([r,n]," "),e)}let i=this.header.format("multiline",e);return this.addComments(T.joinLines([i,n]," "),e)}},Zl=class extends ze{constructor(e,t,n){super(e,t,n),this.node=e,this.header=mt(e,t,n),this.consequent=this.createStatementPrinter(e.consequent),this.consequent.indentStatementFirstLine=!1,e.alternate&&(this.alternate=this.createStatementPrinter(e.alternate),this.alternate.indentStatementFirstLine=!1)}format(e=0,t="optimized"){let n=!1,i;if(t==="singleLine"||t==="optimized"){let a=this.header.format("singleLine",e),l=Re(this.node.consequent)?2:0;(t==="singleLine"||this.canFitSingleLine(a,e,l))&&(i=a)}i||(n=!0,i=this.header.format("multiline",e));let r;if(Re(this.node.consequent)){let a=this.consequent.format(e,"optimized");r=T.joinLines([i," ",a])}else if(n||Tr(this.node.consequent)){this.consequent.indentStatementFirstLine=!0;let a=this.consequent.format(e+1,"singleLine");this.canFitSingleLine(a,e+1)||(a=this.consequent.format(e+1,"multiline")),r=T.appendLines([i,a])}else{this.consequent.indentStatementFirstLine=!1;let a=this.consequent.format(e,"singleLine");this.canFitSingleLine(a,0,i.lastLineLength+1)?r=T.joinLines([i," ",a]):(this.consequent.indentStatementFirstLine=!0,a=this.consequent.format(e+1,"optimized"),r=T.appendLines([i,a]))}if(!this.alternate)return this.addComments(r,e);let s=Ql(this.node.consequent)||!Re(this.node.consequent),o;if(this.alternate.externalOffset=0,Re(this.node.alternate)||Tr(this.node.alternate))this.alternate.indentStatementFirstLine=!1,this.alternate.externalOffset=s?5:r.lastLineLength+6,o=this.alternate.format(e,"optimized"),o=T.joinLines(["else ",o]);else{let a=s?4:r.lastLineLength+4;this.alternate.indentStatementFirstLine=!1,o=this.alternate.format(e,"singleLine"),this.canFitSingleLine(o,e,a+1)?o=T.joinLines(["else ",o]):(this.alternate.indentStatementFirstLine=!0,o=this.alternate.format(e+1,"optimized"),o=T.appendLines(["else",o]))}return s?r=T.appendLines([r,o.indentFirstLine(this.getIndentation(e))]):r=T.joinLines([r,o]," "),this.addComments(r,e)}},Kl=class extends ze{constructor(e,t,n){super(e,t,n),this.node=e,this.header=mt(e,t,n),this.body=this.createStatementPrinter(e.body)}format(e=0,t="optimized"){this.body.indentStatementFirstLine=!1;let n=this.getFormattedBody(this.body,e);if(t==="singleLine"||t==="optimized"){let r=this.header.format("singleLine",e);if(t==="singleLine"||this.canFitSingleLine(r,e,n.firstLineLength+1))return this.addComments(T.joinLines([r,n]," "),e)}let i=this.header.format("multiline",e);return this.addComments(T.joinLines([i,n]," "),e)}},e0=class extends ze{constructor(e,t,n){super(e,t,n),this.node=e,this.expression=Q(e.expression,e,n)}format(e=0,t="optimized"){if(t==="singleLine"||t==="optimized"){let n=this.expression.format("singleLine",e).suffixWith(";");if(t==="singleLine"||this.canFitSingleLine(n,e))return this.addComments(n,e)}return this.addComments(this.expression.format("multiline",e).suffixWith(";"),e)}},t0=class extends ze{constructor(e,t,n){super(e,t,n),this.node=e,this.argument=Q(e.argument,e,n)}format(e=0,t="optimized"){if(t==="singleLine"||t==="optimized"){let s=this.argument.format("singleLine",e).surroundWith("return ",";");if(t==="singleLine"||this.canFitSingleLine(s,e))return this.addComments(s,e)}if(!Vr(this.node.argument)&&!Ur(this.node.argument)){let s=this.argument.format("multiline",e).surroundWith("return ",";");return this.addComments(s,e)}let n=this.getIndentation(e+1),i=this.argument.format("multiline",e+1).indentFirstLine(n),r=this.getIndentation(e);return this.addComments(T.appendLines(["return (",i,`${r});`]),e)}},n0=class extends ze{constructor(e,t,n){super(e,t,n),this.node=e,this.libraryNamePrinter=Q(e.specifiers[0].local,e,n),this.librarySourcePrinter=Q(e.source,e,n)}format(e=0){return this.addComments(T.joinLines(["import"," ",this.libraryNamePrinter.format("singleLine",e)," from ",this.librarySourcePrinter.format("singleLine")]).suffixWith(";"),e)}},i0={quote:"auto"};function R1(e,t={}){try{let n=e.getText(),i=e.positionAt(n.length),r={start:{line:0,character:0},end:i},s={...i0,...t.formattingOptions??{}},o=r0(n,s);return[{range:r,newText:o}]}catch(n){return console.error("Arcade Formatting Error:",n),[]}}function r0(e,t){if(!e)return"";let n=Hr(t),i=zl.fromString(e,n),r=i.toString(),s=N1(r,{tolerant:!0,comments:!0}),o=Rl(s,i);return s.loc.start=o.start,s.loc.end=o.end,new cn(s,null,n).format().toString()}var s0=Object.values(q),o0=Object.values(un),a0=["case","catch","debugger","switch","try"],u0=o0.map(e=>({label:e,kind:ee.Constant})),l0=s0.map(e=>({label:e,kind:ee.Keyword})),c0=[{label:"exportfunction",kind:ee.Snippet,detail:"Export Function Statement",insertText:`export function \${1:functionName} ($2) {
31
31
  $0
32
32
  }`,insertTextMode:fe.adjustIndentation,insertTextFormat:he.Snippet},{label:"exportvar",kind:ee.Snippet,detail:"Export Variable Statement",insertText:"export var ${0:variableName}\n",insertTextMode:fe.adjustIndentation,insertTextFormat:he.Snippet},{label:"for",kind:ee.Snippet,detail:"For Loop Statement",insertText:"for (var ${1:i} = 0; ${1:i} < ${2:array.length}; ${1:i}++) {\n $0\n}",insertTextMode:fe.adjustIndentation,insertTextFormat:he.Snippet},{label:"forin",kind:ee.Snippet,detail:"For-In Loop Statement",insertText:"for (var ${1:i} in ${2:arrayOrObject}) {\n $0\n}",insertTextMode:fe.adjustIndentation,insertTextFormat:he.Snippet},{label:"function",kind:ee.Snippet,detail:"Function Statement",insertText:`function \${1:functionName} ($2) {
33
33
  $0
@@ -41,4 +41,4 @@
41
41
  $0
42
42
  }`,insertTextMode:fe.adjustIndentation,insertTextFormat:he.Snippet},{label:"import",kind:ee.Snippet,detail:"Import Statement",insertText:'import ${1:namespace} from "${0:uri}"',insertTextMode:fe.adjustIndentation,insertTextFormat:he.Snippet},{label:"while",kind:ee.Snippet,detail:"While Loop Statement",insertText:`while (\${1:false}) {
43
43
  $0
44
- }`,insertTextMode:fe.adjustIndentation,insertTextFormat:he.Snippet}],h0=/\$\{(.*?)\}/gu;function ln(e,t){return t?e.replace(h0,(n,i)=>t[i].toString()):e}var Xr=/[-[\]/{}()*+?.\\^$|]/gu;function f0(e,t){return e.line>t.end.line}function d0(e,t){return e.line<t.start.line}function P1(e,t){return!(d0(e,t)||f0(e,t)||e.line===t.start.line&&e.column<t.start.column||e.line===t.end.line&&e.column>t.end.column)}var te={None:0,Keywords:1,All:255,NoKeywords:254},tt={identifiers:"a",profileVariables:"aa",constants:"ab",literals:"ab",functions:"ac",snippets:"b",keywords:"c"};function m0(e,t,n,i={}){let r=e.getText({start:{line:0,character:0},end:t}),{tokens:s,errors:o=[]}=El(r,{loc:!0,tolerant:!0});if(o.length)return{isIncomplete:!1,items:[]};let a=s.at(s.length-1),l="",c=F0(t);a?.type==="Identifier"&&P1(c,a.loc)&&(l=a.value,s.pop(),a=s[s.length-1]);let h={variables:i.profile?.variables??[],additionalCompletionItems:(i.snippets??[]).map(f=>({kind:ee.Snippet,insertTextMode:fe.adjustIndentation,insertTextFormat:he.Snippet,...f})),apiDatabase:n};return a?.type==="Punctuator"&&a.value==="."?p0(s,l,h):g0(s,l,c,h)}function g0(e,t,n,i){let r=b0(e,n);if(r===te.None)return{isIncomplete:!1,items:[]};let s=E0(e),o=[],a=new RegExp(t.replaceAll(Xr,"\\$&"),"i");return s.forEach((l,c)=>{a.test(c)&&o.push({...l,sortText:tt.identifiers})}),i.variables.forEach(l=>{a.test(l.name)&&l.completion&&o.push({...l.completion,sortText:tt.profileVariables})}),D1(r)&&c0.forEach(l=>{l.label.startsWith(t)&&o.push({...l,sortText:tt.snippets})}),i.additionalCompletionItems.forEach(l=>{a.test(l.label)&&o.push({...l,sortText:tt.snippets})}),D1(r)&&l0.forEach(l=>{a.test(l.label)&&o.push({...l,sortText:tt.keywords})}),u0.forEach(l=>{a.test(l.label)&&o.push({...l,sortText:tt.literals})}),i.apiDatabase.constantDefinitions.forEach((l,c)=>{l.type==="constant"&&l.disableDocumentation===!0||!a.test(c)||o.push({...l.completion,sortText:tt.constants})}),i.apiDatabase.functionDefinitions.forEach((l,c)=>{a.test(c)&&l.overloads.forEach(h=>{h.disableDocumentation||o.push({...h.completion,sortText:tt.functions})})}),{isIncomplete:!1,items:o}}function p0(e,t,n){let i=[...e],r=i.pop(),s=r,o=[];for(;r&&!(r.type!=="Punctuator"||r.value!=="."||(r=i.pop(),r?.type!=="Identifier"));)o=[r.value.toLowerCase(),...o],r=i.pop();if(o.length===0||!s)return{isIncomplete:!1,items:[]};let a=x0(o,t,n);return a||(a=D0(o,t,s,n),a)?a:{isIncomplete:!1,items:[]}}function x0(e,t,n){if(e.length>1)return null;let i=n.apiDatabase.constantDefinitions.get(e[0]);if(!i)return null;if(i.type!=="namespace")return{isIncomplete:!1,items:[]};let r=[],s=new RegExp(t.replaceAll(Xr,"\\$&"),"i");return i.members.forEach(o=>{o.disableDocumentation===!0||!s.test(o.name)||r.push(o.completion)}),{isIncomplete:!1,items:r}}function D0(e,t,n,i){if(!i.variables.length||!e.length)return null;let r=e.shift(),s=i.variables;for(;r;){let c=s.find(h=>h.name.toLowerCase()===r);if(!kl(c))return null;s=c.properties??[],r=e.shift()}let o=[],a=new RegExp(t.replaceAll(Xr,"\\$&"),"i"),l=y0(n.loc.start);return s.forEach(c=>{a.test(c.name)&&c.completion&&o.push(L0(l,c.completion))}),{isIncomplete:!1,items:o}}function D1(e){return(e&te.Keywords)===te.Keywords}function b0(e,t){if(!e.length)return te.All;let n=e[e.length-1];switch(n.type){case"Identifier":return te.All;case"Keyword":return["return","in","else"].includes(n.value)?te.NoKeywords:te.None;case"Punctuator":return C0(e);case"Template":return n.value.endsWith("${")?te.NoKeywords:te.All;default:return P1(t,n.loc)?te.None:te.All}}function C0(e){let t=[...e],n=t.pop();if(!n)return te.All;if(n.type!=="Punctuator")return te.None;if(n.value!=="("&&n.value!==",")return te.All;if(n.value==="(")return b1(t);let i=0;for(n=t.pop();n;){if(n.type==="Keyword")return te.None;if(n.type!=="Punctuator"){n=t.pop();continue}if(n.value===")"||n.value==="]"){i-=1,n=t.pop();continue}if(n.value==="["){if(i===0)return te.NoKeywords;i+=1,n=t.pop();continue}if(n.value==="("){if(i===0)return b1(t);i+=1,n=t.pop();continue}n=t.pop()}return te.None}function b1(e){let t=[...e],n=t.pop();return n?n.type==="Keyword"?n.value.toLowerCase()==="for"?te.All:te.NoKeywords:n.type!=="Identifier"?te.All:(n=t.pop(),n?.type==="Keyword"&&n.value.toLowerCase()==="function"?te.None:te.NoKeywords):te.All}var A0=class{constructor(e){this.tokens=e,this.currentIndex=0}increment(){if(!(this.currentIndex>=this.tokens.length))return this.currentIndex+=1,this.tokens[this.currentIndex]}get next(){return this.tokens[this.currentIndex+1]}get previous(){return this.tokens[this.currentIndex-1]}get current(){return this.tokens[this.currentIndex]}},ai={parameterFormat:"(parameter) ${name}",variableFormat:"var ${name}",functionFormat:"function ${name} (${paramsDetail})"};function E0(e){let t=new Map;if(!e.length)return t;let n=new A0(e);for(;n.current;){if(n.current.type==="Keyword"){if(n.current.value.toLowerCase()==="var"){n.increment(),_0(n,t);continue}if(n.current.value.toLowerCase()==="function"){n.increment(),v0(n,t);continue}}n.increment()}return t}function _0(e,t){for(;e.current;){if(e.current.type!=="Identifier")return;let n=e.current.value,i=n.toLowerCase();t.set(i,{label:n,kind:ee.Variable,detail:ln(ai.variableFormat,{name:n})});let r=e.increment();if(r?.type!=="Punctuator")return;if(r.value===","){e.increment();continue}if(r.value==="="){e.increment(),w0(e);continue}}}function v0(e,t){for(;e.current;){if(e.current.type!=="Identifier")return;let n=e.current.value,i=n.toLowerCase(),r={label:n,kind:ee.Function,detail:ln(ai.functionFormat,{name:n,paramsDetail:""}),insertText:`${n}()`,insertTextMode:fe.adjustIndentation,insertTextFormat:he.Snippet};t.set(i,r);let s=e.increment();if(!ht(s,"("))return;s=e.increment();let o=[];for(;s&&!(s.type!=="Identifier"||(o.push(s.value),s=e.increment(),!ht(s,",")));)s=e.increment();if(o.length){r.detail=ln(ai.functionFormat,{name:r.label,paramsDetail:o.join(", ")});let c=o.map((h,f)=>`\${${f+1}:${h}}`).join(", ");r.insertText=`${r.label}(${c})`}if(!ht(s,")")||(s=e.increment(),!ht(s,"{")))return;s=e.increment();let a=e.currentIndex,l=1;for(;s&&l>0;)ht(s,"{")?l+=1:ht(s,"}")&&(l-=1),s=e.increment();if(l===0)return;e.currentIndex=a,o.forEach(c=>{let h=c.toLowerCase();t.set(h,{label:c,kind:ee.Variable,detail:ln(ai.parameterFormat,{name:c})})})}}function ht(e,t){return e?.type==="Punctuator"&&e.value===t}function w0(e){let t=0;for(;e.current;){if(e.current.type==="Keyword"){if(ht(e.previous,".")){e.increment();continue}return}if(e.current.type==="Punctuator"&&e.current.value===";")return;if(e.current.type==="Template"&&e.current.value.startsWith("`")){t+=1,e.increment();continue}if(e.current.type==="Punctuator"&&["(","[","{"].includes(e.current.value)){t+=1,e.increment();continue}if(e.current.type==="Template"&&e.current.value.endsWith("`")){t-=1,e.increment();continue}if(e.current.type==="Punctuator"&&[")","]","}"].includes(e.current.value)){t-=1,e.increment();continue}if(!t&&e.current.type==="Punctuator"&&e.current.value===","){e.increment();return}e.increment()}}function L0(e,t){return t.insertText&&t.insertText.startsWith("[")&&(t.additionalTextEdits=[{newText:"",range:{start:{...e},end:{line:e.line,character:e.character+1}}}]),t}function F0(e){return{line:e.line+1,column:e.character}}function y0(e){return{line:e.line-1,character:e.column}}var S0=class{constructor(e,t=[]){this._apiDefinitions=e,this._profileVariables=t,this._isInBlock=!1,this._isInCallExpression=!1,this._identifierBeingAssigned=void 0,this._assignmentValidationMode="disabled",this._scriptScopeIdentifiers=new Map,this._diagnostics=[],this._undeclaredIdentifiersInFunctions=new Map,this.handleException=n=>{if(N0(n)){let{range:i,code:r,data:s}=n;this.logDiagnostic(i,{code:r,data:s})}else this.logDiagnostic({start:{line:1,column:0},end:{line:1,column:0}},{code:P.ExecutionError,data:{stack:n.stack??""}})},this.validateStatement=n=>{if(n)switch(n.type){case g.BlockStatement:n.body.forEach(this.validateStatement);return;case g.VariableDeclaration:n.declarations.forEach(i=>this.validateVariableDeclarator(i));return;case g.FunctionDeclaration:this.validateFunctionDeclaration(n);return;case g.ExportNamedDeclaration:this.validateExportDeclaration(n);return;case g.ImportDeclaration:this.validateImportDeclaration(n);return;case g.WhileStatement:this.validateWhileStatement(n);return;case g.ForStatement:this.validateForStatement(n);return;case g.ForInStatement:this.validateForInStatement(n);return;case g.IfStatement:this.validateIfStatement(n);return;case g.ReturnStatement:this.validateExpression(n.argument);return;case g.ExpressionStatement:this.validateExpression(n.expression);return;case g.BreakStatement:case g.ContinueStatement:case g.EmptyStatement:return}},this.validateExpression=n=>{if(n)switch(n.type){case g.AssignmentExpression:this.validateAssignmentExpression(n);return;case g.CallExpression:this.validateCallExpression(n);return;case g.Identifier:this.validateIdentifier(n);return;case g.Literal:this.validateLiteral(n);return;case g.ArrayExpression:n.elements.forEach(this.validateExpression);return;case g.ObjectExpression:this.validateObjectExpression(n);return;case g.UnaryExpression:this.validateUnaryExpression(n);return;case g.UpdateExpression:this.validateUpdateExpression(n);return;case g.BinaryExpression:case g.LogicalExpression:this.validateBinaryAndLogicalExpression(n);return;case g.MemberExpression:this.validateMemberExpression(n);return;case g.TemplateLiteral:n.expressions.forEach(this.validateExpression);return;default:return}}}validateScript(e){if(!e)return{diagnostics:[],program:null};this._isInBlock=!1,this._identifierBeingAssigned=void 0,this._assignmentValidationMode="disabled",this._diagnostics=[],this._scriptScopeIdentifiers.clear(),this._undeclaredIdentifiersInFunctions.clear(),this._functionScopeIdentifiers=void 0;let t=null;try{t=N1(e,{tolerant:!0}),this.handleErrors(t.errors),t.body.forEach(this.validateStatement),this.diagnoseIdentifiers(),this._undeclaredIdentifiersInFunctions.size>0&&this._undeclaredIdentifiersInFunctions.forEach(n=>{for(let i of n)this.logDiagnostic(i.node.loc,{code:P.NotDefined,data:{identifier:i.node.name}})})}catch(n){this.handleException(n)}return{diagnostics:this._diagnostics,program:t}}disableRecordIdentifierAssignment(e,t){let n=this._assignmentValidationMode;this._assignmentValidationMode="disabled",e.call(this,t),this._assignmentValidationMode=n}inBlock(e,t){let n=this._isInBlock;this._isInBlock=!0,e.call(this,t),this._isInBlock=n}get _isInFunctionScope(){return!!this._functionScopeIdentifiers}inFunctionScope(e){this._functionScopeIdentifiers=new Map,e.call(this),this.diagnoseIdentifiers(),this._functionScopeIdentifiers=void 0}logDiagnostic(e,t){let n={severity:ue.Error,...t,message:ln(_l[t.code],t.data),range:{start:{line:e.start.line-1,character:e.start.column},end:{line:e.end.line-1,character:e.end.column}}};this._diagnostics.push(n)}handleErrors(e){(e??[]).forEach(this.handleException)}getIdentifierInfo(e){return this._functionScopeIdentifiers?.get(e)??this._scriptScopeIdentifiers.get(e)}setIdentiferInfo(e,t){if(this._functionScopeIdentifiers){this._functionScopeIdentifiers.set(e,t);return}this._scriptScopeIdentifiers.set(e,t),this._undeclaredIdentifiersInFunctions.has(e)&&(this._undeclaredIdentifiersInFunctions.delete(e),t.used=!0)}isProfileVariable(e){return this._profileVariables.some(t=>t.name.toLowerCase()===e)}isApiConstant(e){return!!this._apiDefinitions?.constantDefinitions.get(e)}isApiFunction(e){return!!this._apiDefinitions?.functionDefinitions.get(e)}isApiItem(e){return this.isApiConstant(e)||this.isApiFunction(e)}validateVariableDeclarator(e){this.validateExpression(e.init),this.recordVariableIdentifier(e.id,{initialized:!!e.init})}validateFunctionDeclaration(e){this.recordFunctionIdentifier(e),this.inFunctionScope(()=>{e.params.forEach(t=>this.recordParamAsIdentifier(t)),Ut(e.body)&&this.logDiagnostic(e.body.loc,{code:P.UnexpectedEmptyFunction,data:{identifier:e.id.name},severity:ue.Warning}),this.validateStatement(e.body)})}validateExportDeclaration(e){this.validateStatement(e.declaration)}validateImportDeclaration(e){this.recordImportIdentifier(e)}validateForStatement(e){ci(e.init)?this.inBlock(this.validateStatement,e.init):this.validateExpression(e.init),this.validateExpression(e.update),this.validateExpression(e.test),Ut(e.body)&&this.logDiagnostic(e.body.loc,{code:P.EmptyBlockStatement,severity:ue.Warning}),this.inBlock(this.validateStatement,e.body)}validateWhileStatement(e){this.validateExpression(e.test),Ut(e.body)&&this.logDiagnostic(e.body.loc,{code:P.EmptyBlockStatement,severity:ue.Warning}),this.inBlock(this.validateStatement,e.body)}validateForInStatement(e){Me(e.left)?this.validateExpression(e.left):this.recordVariableIdentifier(e.left.declarations[0].id,{initialized:!0,inBlock:!0}),this.validateExpression(e.right),Ut(e.body)&&this.logDiagnostic(e.body.loc,{code:P.EmptyBlockStatement,severity:ue.Warning}),this.validateStatement(e.body)}validateIfStatement(e){this.validateExpression(e.test),Ut(e.consequent)&&this.logDiagnostic(e.consequent.loc,{code:P.EmptyBlockStatement,severity:ue.Warning}),e.alternate&&Ut(e.alternate)&&this.logDiagnostic(e.alternate.loc,{code:P.EmptyBlockStatement,severity:ue.Warning}),this.inBlock(this.validateStatement,e.consequent),this.inBlock(this.validateStatement,e.alternate)}validateAssignmentExpression(e){let t=this._identifierBeingAssigned,n=this._assignmentValidationMode;Me(e.left)&&(this._identifierBeingAssigned=e.left.name.toLowerCase(),this._assignmentValidationMode="left"),this.validateExpression(e.left),Me(e.left)&&(this._assignmentValidationMode="right"),this.validateExpression(e.right),this._identifierBeingAssigned=t,this._assignmentValidationMode=n}validateCallExpression(e){let t=this._isInCallExpression;if(this._isInCallExpression=!0,this.validateExpression(e.callee),Me(e.callee)){let n=e.callee.name.toLowerCase(),i=this.getIdentifierInfo(n),r=this._apiDefinitions?.functionDefinitions.get(n);if(!i&&r){let s=k0(r,e.arguments.length);s&&this.logDiagnostic(e.loc,s)}}e.arguments.forEach(this.validateExpression),this._isInCallExpression=t}validateIdentifier(e){let t=e.name.toLowerCase(),n=this.getIdentifierInfo(t);if(n){if(this._assignmentValidationMode==="left"&&this._identifierBeingAssigned===t){n.initialized=!0;return}if(this._assignmentValidationMode==="right"&&this._identifierBeingAssigned===t)return;n.used=!0;return}if(!(this.isProfileVariable(t)||this.isApiConstant(t))){if(this.isApiFunction(t)){if(this._isInCallExpression)return;this.logDiagnostic(e.loc,{code:P.InvalidApiFunctionUsage,data:{identifier:e.name}});return}if(this._isInFunctionScope){let i=this._undeclaredIdentifiersInFunctions.get(t);i||(i=[],this._undeclaredIdentifiersInFunctions.set(t,i)),i.push({node:e,identifier:t});return}this.logDiagnostic(e.loc,{code:P.NotDefined,data:{identifier:e.name}})}}validateLiteral(e){B0(e.raw).forEach(t=>{let n=this.getIdentifierInfo(t.toLowerCase());n&&(n.used=!0)})}logProfileOrApiConflict(e){let t=e.name.toLowerCase(),n=this.isProfileVariable(t),i=this.isApiItem(t);!n&&!i||this.logDiagnostic(e.loc,{code:n?P.ProfileVariablesConflict:P.ApiConflict,severity:ue.Warning,data:{identifier:e.name}})}logReservedKeywordsConflict(e){let t=e.name.toLowerCase();a0.includes(t)&&this.logDiagnostic(e.loc,{code:P.ReservedKeyword,severity:ue.Warning,data:{identifier:e.name}})}validateObjectExpression(e){e.properties.forEach(t=>{this.validateExpression(t.value)})}validateUnaryExpression(e){this.validateExpression(e.argument)}validateUpdateExpression(e){this.validateExpression(e.argument)}validateBinaryAndLogicalExpression(e){this.validateExpression(e.left),this.validateExpression(e.right)}validateMemberExpression(e){let t=this.flattenMemberExpressionAndValidate(e),n=t[0].object;this.disableRecordIdentifierAssignment(this.validateExpression,n),Me(n)&&(this.getIdentifierInfo(n.name.toLowerCase())||this.validateMemberExpressionWithProfile(t)||this.validateConstantMemberExpression(t))}flattenMemberExpressionAndValidate(e){switch(e.type){case g.MemberExpression:return(!Me(e.property)||e.computed)&&this.validateExpression(e.property),[...this.flattenMemberExpressionAndValidate(e.object),e];default:return[]}}extractAndValidatePropertyName(e){switch(e.type){case g.Identifier:return e.name.toLowerCase();case g.Literal:return typeof e.value!="string"?(this.logDiagnostic(e.loc,{code:P.UnexpectedPropertyIdentifier}),null):e.value.toLowerCase();default:return this.logDiagnostic(e.loc,{code:P.UnexpectedPropertyIdentifier}),null}}validateConstantMemberExpression(e){let t=e[0];if(!Me(t.object))return!1;let n=t.object.name.toLowerCase(),i=this._apiDefinitions?.constantDefinitions.get(n);if(!i)return!1;if(i.type!=="namespace")return this.logDiagnostic(t.property.loc,{code:P.NotADictionary,data:{identifier:n}}),!0;let r=this.extractAndValidatePropertyName(t.property);if(!r)return!0;if(!i.members.some(s=>s.name.toLowerCase()===r)){let s=i.members.reduce((o,a)=>`${o}${o?" | ":""}${a.completion.label.split(".").pop()}`,"");this.logDiagnostic(t.property.loc,{code:P.InvalidConstantIdentifier,data:{list:s}})}return e.length>1&&this.logDiagnostic(e[1].property.loc,{code:P.UnexpectedPropertyIdentifier}),!0}validateMemberExpressionWithProfile(e){let t=e[0];if(t.object.type!==g.Identifier)return!1;let n=t.object.name.toLowerCase(),i=this._profileVariables.find(s=>s.name.toLowerCase()===n);if(!i)return!1;if(m1(i))return this.logDiagnostic(t.object.loc,{code:P.NotADictionary,data:{identifier:i.name}}),!0;if(this._identifierBeingAssigned===n)return this.logDiagnostic(t.loc,{code:P.ProfileVariablesAreImmutable}),!0;let r=i;for(let s=0;s<e.length;s++){if(e[s].computed)return!0;if(m1(r))return this.logDiagnostic(e[s-1]?.property.loc??e[s].object.loc,{code:P.NotADictionary,data:{identifier:r.name}}),!0;let o=this.extractAndValidatePropertyName(e[s].property);if(!o)return!0;if(!r.properties||r.properties.length===0)return this.logDiagnostic(e[s].property.loc,{code:P.UnknownPropertyIdentifier,data:{identifier:o},severity:ue.Warning}),!0;let a=r.properties.find(l=>l.name.toLowerCase()===o);if(!a){let l=r.properties.reduce((c,h)=>`${c}${c?" | ":""}${h.name.split(".").pop()}`,"");return this.logDiagnostic(e[s].property.loc,{code:P.InvalidPropertyIdentifier,data:{list:l}}),!0}r=a}return!0}recordVariableIdentifier(e,t){this.logReservedKeywordsConflict(e),this.logProfileOrApiConflict(e);let n=e.name.toLowerCase(),i=this.getIdentifierInfo(n),r=this._isInFunctionScope&&i?.scope==="function",s=!this._isInFunctionScope&&i?.scope==="script";(r||s)&&this.logDiagnostic(e.loc,{code:P.AlreadyDefined,data:{identifier:e.name},severity:ue.Warning});let o=t.inBlock??this._isInBlock,{initialized:a}=t;if(!i||this._isInFunctionScope&&i.scope!=="function"){let l=this._isInFunctionScope?"function":o?"block":"script";i={node:e,used:!1,initialized:a,scope:l}}else i.node=e,i.used=!1,i.initialized=a;return i.scope==="block"&&!o&&(i.scope="script",this.logDiagnostic(e.loc,{code:P.AlreadyDefined,data:{identifier:e.name},severity:ue.Warning})),this.setIdentiferInfo(n,i),!1}recordImportIdentifier(e){let t=e.specifiers[0].local;this.logProfileOrApiConflict(t);let n=t.name.toLowerCase(),i=this.getIdentifierInfo(n);i?.scope&&this.logDiagnostic(e.specifiers[0].local.loc,{code:P.AlreadyDefined,data:{identifier:e.specifiers[0].local.name},severity:ue.Warning}),i={node:e.specifiers[0].local,used:!1,...i,scope:"script",initialized:!0},this.setIdentiferInfo(n,i)}recordFunctionIdentifier(e){this.logProfileOrApiConflict(e.id);let t=e.id.name.toLowerCase(),n=this.getIdentifierInfo(t);n?.scope&&this.logDiagnostic(e.id.loc,{code:P.AlreadyDefined,data:{identifier:e.id.name},severity:ue.Warning}),n={node:e.id,used:!1,...n,scope:"script",initialized:!0},this.setIdentiferInfo(t,n)}recordParamAsIdentifier(e){return this.recordVariableIdentifier(e,{initialized:!0})}diagnoseIdentifiers(){(this._functionScopeIdentifiers??this._scriptScopeIdentifiers).forEach(e=>{e.used?e.initialized||this.logDiagnostic(e.node.loc,{code:P.DefinedNeverAssigned,data:{identifier:e.node.name},severity:ue.Warning}):this.logDiagnostic(e.node.loc,{code:e.initialized?P.AssignedNeverUsed:P.DefinedNeverUsed,data:{identifier:e.node.name},severity:ue.Warning})})}};function N0(e){return e.name==="ParsingError"}function Ut(e){return $r(e)||Re(e)&&!e.body.length}function k0(e,t){let{min:n,max:i}=e.overloads.reduce((r,s)=>{let{min:o,max:a}=s.parametersInfo;return r.min>=0&&(r.min=Math.min(o,r.min)),r.max>=0&&(r.max=a<0?a:Math.max(a,r.max)),r},{min:Number.POSITIVE_INFINITY,max:0});return t<n?n>0?{code:P.NotEnoughArguments,data:{min:n}}:{code:P.NoArgumentExpected}:i>=0&&t>i?{code:P.TooManyArguments,data:{max:i}}:null}var I0=/\B@\w+/gu;function B0(e=""){return Array.from(e.matchAll(I0),t=>t[0].slice(1))}var T1=class{constructor(){this.languageOptions={}}configure(e={}){this.languageOptions=e,this.apiService=new Ml(this.languageOptions)}async doValidation(e,t){if(!this.apiService)return[];let n=await this.apiService.getApiDatabase(t),{profile:{variables:i=[]}={}}=t,{diagnostics:r}=new S0(n,i).validateScript(e.getText());return r}async doComplete(e,t,n){if(!this.apiService)return{isIncomplete:!1,items:[]};let i=await this.apiService.getApiDatabase(n);return m0(e,t,i,n)}async getApiLibrary(e){return this.apiService?(await this.apiService.getApiDatabase(e)).categories:[]}};var gi=class e{constructor(t,n,i,r){this._uri=t,this._languageId=n,this._version=i,this._content=r,this._lineOffsets=void 0}get uri(){return this._uri}get languageId(){return this._languageId}get version(){return this._version}getText(t){if(t){let n=this.offsetAt(t.start),i=this.offsetAt(t.end);return this._content.substring(n,i)}return this._content}update(t,n){for(let i of t)if(e.isIncremental(i)){let r=V1(i.range),s=this.offsetAt(r.start),o=this.offsetAt(r.end);this._content=this._content.substring(0,s)+i.text+this._content.substring(o,this._content.length);let a=Math.max(r.start.line,0),l=Math.max(r.end.line,0),c=this._lineOffsets,h=U1(i.text,!1,s);if(l-a===h.length)for(let d=0,m=h.length;d<m;d++)c[d+a+1]=h[d];else h.length<1e4?c.splice(a+1,l-a,...h):this._lineOffsets=c=c.slice(0,a+1).concat(h,c.slice(l+1));let f=i.text.length-(o-s);if(f!==0)for(let d=a+1+h.length,m=c.length;d<m;d++)c[d]=c[d]+f}else if(e.isFull(i))this._content=i.text,this._lineOffsets=void 0;else throw new Error("Unknown change event received");this._version=n}getLineOffsets(){return this._lineOffsets===void 0&&(this._lineOffsets=U1(this._content,!0)),this._lineOffsets}positionAt(t){t=Math.max(Math.min(t,this._content.length),0);let n=this.getLineOffsets(),i=0,r=n.length;if(r===0)return{line:0,character:t};for(;i<r;){let o=Math.floor((i+r)/2);n[o]>t?r=o:i=o+1}let s=i-1;return{line:s,character:t-n[s]}}offsetAt(t){let n=this.getLineOffsets();if(t.line>=n.length)return this._content.length;if(t.line<0)return 0;let i=n[t.line],r=t.line+1<n.length?n[t.line+1]:this._content.length;return Math.max(Math.min(i+t.character,r),i)}get lineCount(){return this.getLineOffsets().length}static isIncremental(t){let n=t;return n!=null&&typeof n.text=="string"&&n.range!==void 0&&(n.rangeLength===void 0||typeof n.rangeLength=="number")}static isFull(t){let n=t;return n!=null&&typeof n.text=="string"&&n.range===void 0&&n.rangeLength===void 0}},pi;(function(e){function t(r,s,o,a){return new gi(r,s,o,a)}e.create=t;function n(r,s,o){if(r instanceof gi)return r.update(s,o),r;throw new Error("TextDocument.update: document must be created by TextDocument.create")}e.update=n;function i(r,s){let o=r.getText(),a=Jr(s.map(M0),(h,f)=>{let d=h.range.start.line-f.range.start.line;return d===0?h.range.start.character-f.range.start.character:d}),l=0,c=[];for(let h of a){let f=r.offsetAt(h.range.start);if(f<l)throw new Error("Overlapping edit");f>l&&c.push(o.substring(l,f)),h.newText.length&&c.push(h.newText),l=r.offsetAt(h.range.end)}return c.push(o.substr(l)),c.join("")}e.applyEdits=i})(pi||(pi={}));function Jr(e,t){if(e.length<=1)return e;let n=e.length/2|0,i=e.slice(0,n),r=e.slice(n);Jr(i,t),Jr(r,t);let s=0,o=0,a=0;for(;s<i.length&&o<r.length;)t(i[s],r[o])<=0?e[a++]=i[s++]:e[a++]=r[o++];for(;s<i.length;)e[a++]=i[s++];for(;o<r.length;)e[a++]=r[o++];return e}function U1(e,t,n=0){let i=t?[n]:[];for(let r=0;r<e.length;r++){let s=e.charCodeAt(r);(s===13||s===10)&&(s===13&&r+1<e.length&&e.charCodeAt(r+1)===10&&r++,i.push(n+r+1))}return i}function V1(e){let t=e.start,n=e.end;return t.line>n.line||t.line===n.line&&t.character>n.character?{start:n,end:t}:e}function M0(e){let t=V1(e.range);return t!==e.range?{newText:e.newText,range:t}:e}globalThis.onmessage=()=>{Dr((e,t)=>new Qr(e,t))};var Qr=class{constructor(t,{languageId:n,languageOptions:i}){this._ctx=t;this._languageId=n,this._languageService=new T1,this._languageService.configure(i)}async doValidation(t,n){let i=this._getTextDocument(t);return i?await this._languageService.doValidation(i,n):await Promise.resolve([])}async doComplete(t,n,i){let r=this._getTextDocument(t);return r?await this._languageService.doComplete(r,n,i):await Promise.resolve({isIncomplete:!1,items:[]})}async doFormat(t,n){let i=this._getTextDocument(t);if(!i)return await Promise.resolve([]);let r=R1(i,n);return await Promise.resolve(r)}async getApiLibrary(t){return await this._languageService.getApiLibrary(t)}_getTextDocument(t){let n=this._ctx.getMirrorModels();for(let i of n)if(i.uri.toString()===t)return pi.create(t,this._languageId,i.version,i.getValue());return null}};})();
44
+ }`,insertTextMode:fe.adjustIndentation,insertTextFormat:he.Snippet}],h0=/\$\{(.*?)\}/gu;function ln(e,t){return t?e.replace(h0,(n,i)=>t[i].toString()):e}var Xr=/[-[\]/{}()*+?.\\^$|]/gu;function f0(e,t){return e.line>t.end.line}function d0(e,t){return e.line<t.start.line}function P1(e,t){return!(d0(e,t)||f0(e,t)||e.line===t.start.line&&e.column<t.start.column||e.line===t.end.line&&e.column>t.end.column)}var te={None:0,Keywords:1,All:255,NoKeywords:254},tt={identifiers:"a",profileVariables:"aa",constants:"ab",literals:"ab",functions:"ac",snippets:"b",keywords:"c"};function m0(e,t,n,i={}){let r=e.getText({start:{line:0,character:0},end:t}),{tokens:s,errors:o=[]}=El(r,{loc:!0,tolerant:!0});if(o.length)return{isIncomplete:!1,items:[]};let a=s.at(s.length-1),l="",c=F0(t);a?.type==="Identifier"&&P1(c,a.loc)&&(l=a.value,s.pop(),a=s[s.length-1]);let h={variables:i.profile?.variables??[],additionalCompletionItems:(i.snippets??[]).map(f=>({kind:ee.Snippet,insertTextMode:fe.adjustIndentation,insertTextFormat:he.Snippet,...f})),apiDatabase:n};return a?.type==="Punctuator"&&a.value==="."?p0(s,l,h):g0(s,l,c,h)}function g0(e,t,n,i){let r=b0(e,n);if(r===te.None)return{isIncomplete:!1,items:[]};let s=E0(e),o=[],a=new RegExp(t.replaceAll(Xr,"\\$&"),"i");return s.forEach((l,c)=>{a.test(c)&&o.push({...l,sortText:tt.identifiers})}),i.variables.forEach(l=>{a.test(l.name)&&l.completion&&o.push({...l.completion,sortText:tt.profileVariables})}),D1(r)&&c0.forEach(l=>{l.label.startsWith(t)&&o.push({...l,sortText:tt.snippets})}),i.additionalCompletionItems.forEach(l=>{a.test(l.label)&&o.push({...l,sortText:tt.snippets})}),D1(r)&&l0.forEach(l=>{a.test(l.label)&&o.push({...l,sortText:tt.keywords})}),u0.forEach(l=>{a.test(l.label)&&o.push({...l,sortText:tt.literals})}),i.apiDatabase.constantDefinitions.forEach((l,c)=>{l.type==="constant"&&l.disableDocumentation===!0||!a.test(c)||o.push({...l.completion,sortText:tt.constants})}),i.apiDatabase.functionDefinitions.forEach((l,c)=>{a.test(c)&&l.overloads.forEach(h=>{h.disableDocumentation||o.push({...h.completion,sortText:tt.functions})})}),{isIncomplete:!1,items:o}}function p0(e,t,n){let i=[...e],r=i.pop(),s=r,o=[];for(;r&&!(r.type!=="Punctuator"||r.value!=="."||(r=i.pop(),r?.type!=="Identifier"));)o=[r.value.toLowerCase(),...o],r=i.pop();if(o.length===0||!s)return{isIncomplete:!1,items:[]};let a=x0(o,t,n);return a||(a=D0(o,t,s,n),a)?a:{isIncomplete:!1,items:[]}}function x0(e,t,n){if(e.length>1)return null;let i=n.apiDatabase.constantDefinitions.get(e[0]);if(!i)return null;if(i.type!=="namespace")return{isIncomplete:!1,items:[]};let r=[],s=new RegExp(t.replaceAll(Xr,"\\$&"),"i");return i.members.forEach(o=>{o.disableDocumentation===!0||!s.test(o.name)||r.push(o.completion)}),{isIncomplete:!1,items:r}}function D0(e,t,n,i){if(!i.variables.length||!e.length)return null;let r=e.shift(),s=i.variables;for(;r;){let c=s.find(h=>h.name.toLowerCase()===r);if(!kl(c))return null;s=c.properties??[],r=e.shift()}let o=[],a=new RegExp(t.replaceAll(Xr,"\\$&"),"i"),l=y0(n.loc.start);return s.forEach(c=>{a.test(c.name)&&c.completion&&o.push(L0(l,c.completion))}),{isIncomplete:!1,items:o}}function D1(e){return(e&te.Keywords)===te.Keywords}function b0(e,t){if(!e.length)return te.All;let n=e[e.length-1];switch(n.type){case"Identifier":return te.All;case"Keyword":return["return","in","else"].includes(n.value)?te.NoKeywords:te.None;case"Punctuator":return C0(e);case"Template":return n.value.endsWith("${")?te.NoKeywords:te.All;default:return P1(t,n.loc)?te.None:te.All}}function C0(e){let t=[...e],n=t.pop();if(!n)return te.All;if(n.type!=="Punctuator")return te.None;if(n.value!=="("&&n.value!==",")return te.All;if(n.value==="(")return b1(t);let i=0;for(n=t.pop();n;){if(n.type==="Keyword")return te.None;if(n.type!=="Punctuator"){n=t.pop();continue}if(n.value===")"||n.value==="]"){i-=1,n=t.pop();continue}if(n.value==="["){if(i===0)return te.NoKeywords;i+=1,n=t.pop();continue}if(n.value==="("){if(i===0)return b1(t);i+=1,n=t.pop();continue}n=t.pop()}return te.None}function b1(e){let t=[...e],n=t.pop();return n?n.type==="Keyword"?n.value.toLowerCase()==="for"?te.All:te.NoKeywords:n.type!=="Identifier"?te.All:(n=t.pop(),n?.type==="Keyword"&&n.value.toLowerCase()==="function"?te.None:te.NoKeywords):te.All}var A0=class{constructor(e){this.tokens=e,this.currentIndex=0}increment(){if(!(this.currentIndex>=this.tokens.length))return this.currentIndex+=1,this.tokens[this.currentIndex]}get next(){return this.tokens[this.currentIndex+1]}get previous(){return this.tokens[this.currentIndex-1]}get current(){return this.tokens[this.currentIndex]}},ai={parameterFormat:"(parameter) ${name}",variableFormat:"var ${name}",functionFormat:"function ${name} (${paramsDetail})"};function E0(e){let t=new Map;if(!e.length)return t;let n=new A0(e);for(;n.current;){if(n.current.type==="Keyword"){if(n.current.value.toLowerCase()==="var"){n.increment(),_0(n,t);continue}if(n.current.value.toLowerCase()==="function"){n.increment(),v0(n,t);continue}}n.increment()}return t}function _0(e,t){for(;e.current;){if(e.current.type!=="Identifier")return;let n=e.current.value,i=n.toLowerCase();t.set(i,{label:n,kind:ee.Variable,detail:ln(ai.variableFormat,{name:n})});let r=e.increment();if(r?.type!=="Punctuator")return;if(r.value===","){e.increment();continue}if(r.value==="="){e.increment(),w0(e);continue}}}function v0(e,t){for(;e.current;){if(e.current.type!=="Identifier")return;let n=e.current.value,i=n.toLowerCase(),r={label:n,kind:ee.Function,detail:ln(ai.functionFormat,{name:n,paramsDetail:""}),insertText:`${n}()`,insertTextMode:fe.adjustIndentation,insertTextFormat:he.Snippet};t.set(i,r);let s=e.increment();if(!ht(s,"("))return;s=e.increment();let o=[];for(;s&&!(s.type!=="Identifier"||(o.push(s.value),s=e.increment(),!ht(s,",")));)s=e.increment();if(o.length){r.detail=ln(ai.functionFormat,{name:r.label,paramsDetail:o.join(", ")});let c=o.map((h,f)=>`\${${f+1}:${h}}`).join(", ");r.insertText=`${r.label}(${c})`}if(!ht(s,")")||(s=e.increment(),!ht(s,"{")))return;s=e.increment();let a=e.currentIndex,l=1;for(;s&&l>0;)ht(s,"{")?l+=1:ht(s,"}")&&(l-=1),s=e.increment();if(l===0)return;e.currentIndex=a,o.forEach(c=>{let h=c.toLowerCase();t.set(h,{label:c,kind:ee.Variable,detail:ln(ai.parameterFormat,{name:c})})})}}function ht(e,t){return e?.type==="Punctuator"&&e.value===t}function w0(e){let t=0;for(;e.current;){if(e.current.type==="Keyword"){if(ht(e.previous,".")){e.increment();continue}return}if(e.current.type==="Punctuator"&&e.current.value===";")return;if(e.current.type==="Template"&&e.current.value.startsWith("`")){t+=1,e.increment();continue}if(e.current.type==="Punctuator"&&["(","[","{"].includes(e.current.value)){t+=1,e.increment();continue}if(e.current.type==="Template"&&e.current.value.endsWith("`")){t-=1,e.increment();continue}if(e.current.type==="Punctuator"&&[")","]","}"].includes(e.current.value)){t-=1,e.increment();continue}if(!t&&e.current.type==="Punctuator"&&e.current.value===","){e.increment();return}e.increment()}}function L0(e,t){return t.insertText&&t.insertText.startsWith("[")&&(t.additionalTextEdits=[{newText:"",range:{start:{...e},end:{line:e.line,character:e.character+1}}}]),t}function F0(e){return{line:e.line+1,column:e.character}}function y0(e){return{line:e.line-1,character:e.column}}var S0=class{constructor(e,t=[]){this._apiDatabase=e,this._profileVariables=t,this._isInBlock=!1,this._isInCallExpression=!1,this._identifierBeingAssigned=void 0,this._assignmentValidationMode="disabled",this._scriptScopeIdentifiers=new Map,this._diagnostics=[],this._undeclaredIdentifiersInFunctions=new Map,this.handleException=n=>{if(N0(n)){let{range:i,code:r,data:s}=n;this.logDiagnostic(i,{code:r,data:s})}else this.logDiagnostic({start:{line:1,column:0},end:{line:1,column:0}},{code:P.ExecutionError,data:{stack:n.stack??""}})},this.validateStatement=n=>{if(n)switch(n.type){case g.BlockStatement:n.body.forEach(this.validateStatement);return;case g.VariableDeclaration:n.declarations.forEach(i=>this.validateVariableDeclarator(i));return;case g.FunctionDeclaration:this.validateFunctionDeclaration(n);return;case g.ExportNamedDeclaration:this.validateExportDeclaration(n);return;case g.ImportDeclaration:this.validateImportDeclaration(n);return;case g.WhileStatement:this.validateWhileStatement(n);return;case g.ForStatement:this.validateForStatement(n);return;case g.ForInStatement:this.validateForInStatement(n);return;case g.IfStatement:this.validateIfStatement(n);return;case g.ReturnStatement:this.validateExpression(n.argument);return;case g.ExpressionStatement:this.validateExpression(n.expression);return;case g.BreakStatement:case g.ContinueStatement:case g.EmptyStatement:return}},this.validateExpression=n=>{if(n)switch(n.type){case g.AssignmentExpression:this.validateAssignmentExpression(n);return;case g.CallExpression:this.validateCallExpression(n);return;case g.Identifier:this.validateIdentifier(n);return;case g.Literal:this.validateLiteral(n);return;case g.ArrayExpression:n.elements.forEach(this.validateExpression);return;case g.ObjectExpression:this.validateObjectExpression(n);return;case g.UnaryExpression:this.validateUnaryExpression(n);return;case g.UpdateExpression:this.validateUpdateExpression(n);return;case g.BinaryExpression:case g.LogicalExpression:this.validateBinaryAndLogicalExpression(n);return;case g.MemberExpression:this.validateMemberExpression(n);return;case g.TemplateLiteral:n.expressions.forEach(this.validateExpression);return;default:return}}}validateScript(e){if(!e)return{diagnostics:[],program:null};this._isInBlock=!1,this._identifierBeingAssigned=void 0,this._assignmentValidationMode="disabled",this._diagnostics=[],this._scriptScopeIdentifiers.clear(),this._undeclaredIdentifiersInFunctions.clear(),this._functionScopeIdentifiers=void 0;let t=null;try{t=N1(e,{tolerant:!0}),this.handleErrors(t.errors),t.body.forEach(this.validateStatement),this.diagnoseIdentifiers(),this._undeclaredIdentifiersInFunctions.size>0&&this._undeclaredIdentifiersInFunctions.forEach(n=>{for(let i of n)this.logDiagnostic(i.node.loc,{code:P.NotDefined,data:{identifier:i.node.name}})})}catch(n){this.handleException(n)}return{diagnostics:this._diagnostics,program:t}}disableRecordIdentifierAssignment(e,t){let n=this._assignmentValidationMode;this._assignmentValidationMode="disabled",e.call(this,t),this._assignmentValidationMode=n}inBlock(e,t){let n=this._isInBlock;this._isInBlock=!0,e.call(this,t),this._isInBlock=n}get _isInFunctionScope(){return!!this._functionScopeIdentifiers}inFunctionScope(e){this._functionScopeIdentifiers=new Map,e.call(this),this.diagnoseIdentifiers(),this._functionScopeIdentifiers=void 0}logDiagnostic(e,t){let n={severity:ue.Error,...t,message:ln(_l[t.code],t.data),range:{start:{line:e.start.line-1,character:e.start.column},end:{line:e.end.line-1,character:e.end.column}}};this._diagnostics.push(n)}handleErrors(e){(e??[]).forEach(this.handleException)}getIdentifierInfo(e){return this._functionScopeIdentifiers?.get(e)??this._scriptScopeIdentifiers.get(e)}setIdentifierInfo(e,t){if(this._functionScopeIdentifiers){this._functionScopeIdentifiers.set(e,t);return}this._scriptScopeIdentifiers.set(e,t),this._undeclaredIdentifiersInFunctions.has(e)&&(this._undeclaredIdentifiersInFunctions.delete(e),t.used=!0)}isProfileVariable(e){return this._profileVariables.some(t=>t.name.toLowerCase()===e)}isApiConstant(e){return!!this._apiDatabase?.constantDefinitions.get(e)}isApiFunction(e){return!!this._apiDatabase?.functionDefinitions.get(e)}isApiItem(e){return this.isApiConstant(e)||this.isApiFunction(e)}validateVariableDeclarator(e){this.validateExpression(e.init),this.recordVariableIdentifier(e.id,{initialized:!!e.init})}validateFunctionDeclaration(e){this.recordFunctionIdentifier(e),this.inFunctionScope(()=>{e.params.forEach(t=>this.recordParamAsIdentifier(t)),Ut(e.body)&&this.logDiagnostic(e.body.loc,{code:P.UnexpectedEmptyFunction,data:{identifier:e.id.name},severity:ue.Warning}),this.validateStatement(e.body)})}validateExportDeclaration(e){this.validateStatement(e.declaration)}validateImportDeclaration(e){this.recordImportIdentifier(e)}validateForStatement(e){ci(e.init)?this.inBlock(this.validateStatement,e.init):this.validateExpression(e.init),this.validateExpression(e.update),this.validateExpression(e.test),Ut(e.body)&&this.logDiagnostic(e.body.loc,{code:P.EmptyBlockStatement,severity:ue.Warning}),this.inBlock(this.validateStatement,e.body)}validateWhileStatement(e){this.validateExpression(e.test),Ut(e.body)&&this.logDiagnostic(e.body.loc,{code:P.EmptyBlockStatement,severity:ue.Warning}),this.inBlock(this.validateStatement,e.body)}validateForInStatement(e){Me(e.left)?this.validateExpression(e.left):this.recordVariableIdentifier(e.left.declarations[0].id,{initialized:!0,inBlock:!0}),this.validateExpression(e.right),Ut(e.body)&&this.logDiagnostic(e.body.loc,{code:P.EmptyBlockStatement,severity:ue.Warning}),this.validateStatement(e.body)}validateIfStatement(e){this.validateExpression(e.test),Ut(e.consequent)&&this.logDiagnostic(e.consequent.loc,{code:P.EmptyBlockStatement,severity:ue.Warning}),e.alternate&&Ut(e.alternate)&&this.logDiagnostic(e.alternate.loc,{code:P.EmptyBlockStatement,severity:ue.Warning}),this.inBlock(this.validateStatement,e.consequent),this.inBlock(this.validateStatement,e.alternate)}validateAssignmentExpression(e){let t=this._identifierBeingAssigned,n=this._assignmentValidationMode;Me(e.left)&&(this._identifierBeingAssigned=e.left.name.toLowerCase(),this._assignmentValidationMode="left"),this.validateExpression(e.left),Me(e.left)&&(this._assignmentValidationMode="right"),this.validateExpression(e.right),this._identifierBeingAssigned=t,this._assignmentValidationMode=n}validateCallExpression(e){let t=this._isInCallExpression;if(this._isInCallExpression=!0,this.validateExpression(e.callee),Me(e.callee)){let n=e.callee.name.toLowerCase(),i=this.getIdentifierInfo(n),r=this._apiDatabase?.functionDefinitions.get(n);if(!i&&r){let s=k0(r,e.arguments.length);s&&this.logDiagnostic(e.loc,s)}}e.arguments.forEach(this.validateExpression),this._isInCallExpression=t}validateIdentifier(e){let t=e.name.toLowerCase(),n=this.getIdentifierInfo(t);if(n){if(this._assignmentValidationMode==="left"&&this._identifierBeingAssigned===t){n.initialized=!0;return}if(this._assignmentValidationMode==="right"&&this._identifierBeingAssigned===t)return;n.used=!0;return}if(!(this.isProfileVariable(t)||this.isApiConstant(t))){if(this.isApiFunction(t)){if(this._isInCallExpression)return;this.logDiagnostic(e.loc,{code:P.InvalidApiFunctionUsage,data:{identifier:e.name}});return}if(this._isInFunctionScope){let i=this._undeclaredIdentifiersInFunctions.get(t);i||(i=[],this._undeclaredIdentifiersInFunctions.set(t,i)),i.push({node:e,identifier:t});return}this.logDiagnostic(e.loc,{code:P.NotDefined,data:{identifier:e.name}})}}validateLiteral(e){B0(e.raw).forEach(t=>{let n=this.getIdentifierInfo(t.toLowerCase());n&&(n.used=!0)})}logProfileOrApiConflict(e){let t=e.name.toLowerCase(),n=this.isProfileVariable(t),i=this.isApiItem(t);!n&&!i||this.logDiagnostic(e.loc,{code:n?P.ProfileVariablesConflict:P.ApiConflict,severity:ue.Warning,data:{identifier:e.name}})}logReservedKeywordsConflict(e){let t=e.name.toLowerCase();a0.includes(t)&&this.logDiagnostic(e.loc,{code:P.ReservedKeyword,severity:ue.Warning,data:{identifier:e.name}})}validateObjectExpression(e){e.properties.forEach(t=>{this.validateExpression(t.value)})}validateUnaryExpression(e){this.validateExpression(e.argument)}validateUpdateExpression(e){this.validateExpression(e.argument)}validateBinaryAndLogicalExpression(e){this.validateExpression(e.left),this.validateExpression(e.right)}validateMemberExpression(e){let t=this.flattenMemberExpressionAndValidate(e),n=t[0].object;this.disableRecordIdentifierAssignment(this.validateExpression,n),Me(n)&&(this.getIdentifierInfo(n.name.toLowerCase())||this.validateMemberExpressionWithProfile(t)||this.validateConstantMemberExpression(t))}flattenMemberExpressionAndValidate(e){switch(e.type){case g.MemberExpression:return(!Me(e.property)||e.computed)&&this.validateExpression(e.property),[...this.flattenMemberExpressionAndValidate(e.object),e];default:return[]}}extractAndValidatePropertyName(e){switch(e.type){case g.Identifier:return e.name.toLowerCase();case g.Literal:return typeof e.value!="string"?(this.logDiagnostic(e.loc,{code:P.UnexpectedPropertyIdentifier}),null):e.value.toLowerCase();default:return this.logDiagnostic(e.loc,{code:P.UnexpectedPropertyIdentifier}),null}}validateConstantMemberExpression(e){let t=e[0];if(!Me(t.object))return!1;let n=t.object.name.toLowerCase(),i=this._apiDatabase?.constantDefinitions.get(n);if(!i)return!1;if(i.type!=="namespace")return this.logDiagnostic(t.property.loc,{code:P.NotADictionary,data:{identifier:n}}),!0;let r=this.extractAndValidatePropertyName(t.property);if(!r)return!0;if(!i.members.some(s=>s.name.toLowerCase()===r)){let s=i.members.reduce((o,a)=>`${o}${o?" | ":""}${a.completion.label.split(".").pop()}`,"");this.logDiagnostic(t.property.loc,{code:P.InvalidConstantIdentifier,data:{list:s}})}return e.length>1&&this.logDiagnostic(e[1].property.loc,{code:P.UnexpectedPropertyIdentifier}),!0}validateMemberExpressionWithProfile(e){let t=e[0];if(t.object.type!==g.Identifier)return!1;let n=t.object.name.toLowerCase(),i=this._profileVariables.find(s=>s.name.toLowerCase()===n);if(!i)return!1;if(m1(i))return this.logDiagnostic(t.object.loc,{code:P.NotADictionary,data:{identifier:i.name}}),!0;if(this._identifierBeingAssigned===n)return this.logDiagnostic(t.loc,{code:P.ProfileVariablesAreImmutable}),!0;let r=i;for(let s=0;s<e.length;s++){if(e[s].computed)return!0;if(m1(r))return this.logDiagnostic(e[s-1]?.property.loc??e[s].object.loc,{code:P.NotADictionary,data:{identifier:r.name}}),!0;let o=this.extractAndValidatePropertyName(e[s].property);if(!o)return!0;if(!r.properties||r.properties.length===0)return this.logDiagnostic(e[s].property.loc,{code:P.UnknownPropertyIdentifier,data:{identifier:o},severity:ue.Warning}),!0;let a=r.properties.find(l=>l.name.toLowerCase()===o);if(!a){let l=r.properties.reduce((c,h)=>`${c}${c?" | ":""}${h.name.split(".").pop()}`,"");return this.logDiagnostic(e[s].property.loc,{code:P.InvalidPropertyIdentifier,data:{list:l}}),!0}r=a}return!0}recordVariableIdentifier(e,t){this.logReservedKeywordsConflict(e),this.logProfileOrApiConflict(e);let n=e.name.toLowerCase(),i=this.getIdentifierInfo(n),r=this._isInFunctionScope&&i?.scope==="function",s=!this._isInFunctionScope&&i?.scope==="script";(r||s)&&this.logDiagnostic(e.loc,{code:P.AlreadyDefined,data:{identifier:e.name},severity:ue.Warning});let o=t.inBlock??this._isInBlock,{initialized:a}=t;if(!i||this._isInFunctionScope&&i.scope!=="function"){let l=this._isInFunctionScope?"function":o?"block":"script";i={node:e,used:!1,initialized:a,scope:l}}else i.node=e,i.used=!1,i.initialized=a;return i.scope==="block"&&!o&&(i.scope="script",this.logDiagnostic(e.loc,{code:P.AlreadyDefined,data:{identifier:e.name},severity:ue.Warning})),this.setIdentifierInfo(n,i),!1}recordImportIdentifier(e){let t=e.specifiers[0].local;this.logProfileOrApiConflict(t);let n=t.name.toLowerCase(),i=this.getIdentifierInfo(n);i?.scope&&this.logDiagnostic(e.specifiers[0].local.loc,{code:P.AlreadyDefined,data:{identifier:e.specifiers[0].local.name},severity:ue.Warning}),i={node:e.specifiers[0].local,used:!1,...i,scope:"script",initialized:!0},this.setIdentifierInfo(n,i)}recordFunctionIdentifier(e){this.logProfileOrApiConflict(e.id);let t=e.id.name.toLowerCase(),n=this.getIdentifierInfo(t);n?.scope&&this.logDiagnostic(e.id.loc,{code:P.AlreadyDefined,data:{identifier:e.id.name},severity:ue.Warning}),n={node:e.id,used:!1,...n,scope:"script",initialized:!0},this.setIdentifierInfo(t,n)}recordParamAsIdentifier(e){return this.recordVariableIdentifier(e,{initialized:!0})}diagnoseIdentifiers(){(this._functionScopeIdentifiers??this._scriptScopeIdentifiers).forEach(e=>{e.used?e.initialized||this.logDiagnostic(e.node.loc,{code:P.DefinedNeverAssigned,data:{identifier:e.node.name},severity:ue.Warning}):this.logDiagnostic(e.node.loc,{code:e.initialized?P.AssignedNeverUsed:P.DefinedNeverUsed,data:{identifier:e.node.name},severity:ue.Warning})})}};function N0(e){return e.name==="ParsingError"}function Ut(e){return $r(e)||Re(e)&&!e.body.length}function k0(e,t){let{min:n,max:i}=e.overloads.reduce((r,s)=>{let{min:o,max:a}=s.parametersInfo;return r.min>=0&&(r.min=Math.min(o,r.min)),r.max>=0&&(r.max=a<0?a:Math.max(a,r.max)),r},{min:Number.POSITIVE_INFINITY,max:0});return t<n?n>0?{code:P.NotEnoughArguments,data:{min:n}}:{code:P.NoArgumentExpected}:i>=0&&t>i?{code:P.TooManyArguments,data:{max:i}}:null}var I0=/\B@\w+/gu;function B0(e=""){return Array.from(e.matchAll(I0),t=>t[0].slice(1))}var T1=class{constructor(){this.languageOptions={}}configure(e={}){this.languageOptions=e,this.apiService=new Ml(this.languageOptions)}async doValidation(e,t){if(!this.apiService)return[];let n=await this.apiService.getApiDatabase(t),{profile:{variables:i=[]}={}}=t,{diagnostics:r}=new S0(n,i).validateScript(e.getText());return r}async doComplete(e,t,n){if(!this.apiService)return{isIncomplete:!1,items:[]};let i=await this.apiService.getApiDatabase(n);return m0(e,t,i,n)}async getApiLibrary(e){return this.apiService?(await this.apiService.getApiDatabase(e)).categories:[]}};var gi=class e{constructor(t,n,i,r){this._uri=t,this._languageId=n,this._version=i,this._content=r,this._lineOffsets=void 0}get uri(){return this._uri}get languageId(){return this._languageId}get version(){return this._version}getText(t){if(t){let n=this.offsetAt(t.start),i=this.offsetAt(t.end);return this._content.substring(n,i)}return this._content}update(t,n){for(let i of t)if(e.isIncremental(i)){let r=V1(i.range),s=this.offsetAt(r.start),o=this.offsetAt(r.end);this._content=this._content.substring(0,s)+i.text+this._content.substring(o,this._content.length);let a=Math.max(r.start.line,0),l=Math.max(r.end.line,0),c=this._lineOffsets,h=U1(i.text,!1,s);if(l-a===h.length)for(let d=0,m=h.length;d<m;d++)c[d+a+1]=h[d];else h.length<1e4?c.splice(a+1,l-a,...h):this._lineOffsets=c=c.slice(0,a+1).concat(h,c.slice(l+1));let f=i.text.length-(o-s);if(f!==0)for(let d=a+1+h.length,m=c.length;d<m;d++)c[d]=c[d]+f}else if(e.isFull(i))this._content=i.text,this._lineOffsets=void 0;else throw new Error("Unknown change event received");this._version=n}getLineOffsets(){return this._lineOffsets===void 0&&(this._lineOffsets=U1(this._content,!0)),this._lineOffsets}positionAt(t){t=Math.max(Math.min(t,this._content.length),0);let n=this.getLineOffsets(),i=0,r=n.length;if(r===0)return{line:0,character:t};for(;i<r;){let o=Math.floor((i+r)/2);n[o]>t?r=o:i=o+1}let s=i-1;return{line:s,character:t-n[s]}}offsetAt(t){let n=this.getLineOffsets();if(t.line>=n.length)return this._content.length;if(t.line<0)return 0;let i=n[t.line],r=t.line+1<n.length?n[t.line+1]:this._content.length;return Math.max(Math.min(i+t.character,r),i)}get lineCount(){return this.getLineOffsets().length}static isIncremental(t){let n=t;return n!=null&&typeof n.text=="string"&&n.range!==void 0&&(n.rangeLength===void 0||typeof n.rangeLength=="number")}static isFull(t){let n=t;return n!=null&&typeof n.text=="string"&&n.range===void 0&&n.rangeLength===void 0}},pi;(function(e){function t(r,s,o,a){return new gi(r,s,o,a)}e.create=t;function n(r,s,o){if(r instanceof gi)return r.update(s,o),r;throw new Error("TextDocument.update: document must be created by TextDocument.create")}e.update=n;function i(r,s){let o=r.getText(),a=Jr(s.map(M0),(h,f)=>{let d=h.range.start.line-f.range.start.line;return d===0?h.range.start.character-f.range.start.character:d}),l=0,c=[];for(let h of a){let f=r.offsetAt(h.range.start);if(f<l)throw new Error("Overlapping edit");f>l&&c.push(o.substring(l,f)),h.newText.length&&c.push(h.newText),l=r.offsetAt(h.range.end)}return c.push(o.substr(l)),c.join("")}e.applyEdits=i})(pi||(pi={}));function Jr(e,t){if(e.length<=1)return e;let n=e.length/2|0,i=e.slice(0,n),r=e.slice(n);Jr(i,t),Jr(r,t);let s=0,o=0,a=0;for(;s<i.length&&o<r.length;)t(i[s],r[o])<=0?e[a++]=i[s++]:e[a++]=r[o++];for(;s<i.length;)e[a++]=i[s++];for(;o<r.length;)e[a++]=r[o++];return e}function U1(e,t,n=0){let i=t?[n]:[];for(let r=0;r<e.length;r++){let s=e.charCodeAt(r);(s===13||s===10)&&(s===13&&r+1<e.length&&e.charCodeAt(r+1)===10&&r++,i.push(n+r+1))}return i}function V1(e){let t=e.start,n=e.end;return t.line>n.line||t.line===n.line&&t.character>n.character?{start:n,end:t}:e}function M0(e){let t=V1(e.range);return t!==e.range?{newText:e.newText,range:t}:e}globalThis.onmessage=()=>{Dr((e,t)=>new Qr(e,t))};var Qr=class{constructor(t,{languageId:n,languageOptions:i}){this._ctx=t;this._languageId=n,this._languageService=new T1,this._languageService.configure(i)}async doValidation(t,n){let i=this._getTextDocument(t);return i?await this._languageService.doValidation(i,n):await Promise.resolve([])}async doComplete(t,n,i){let r=this._getTextDocument(t);return r?await this._languageService.doComplete(r,n,i):await Promise.resolve({isIncomplete:!1,items:[]})}async doFormat(t,n){let i=this._getTextDocument(t);if(!i)return await Promise.resolve([]);let r=R1(i,n);return await Promise.resolve(r)}async getApiLibrary(t){return await this._languageService.getApiLibrary(t)}_getTextDocument(t){let n=this._ctx.getMirrorModels();for(let i of n)if(i.uri.toString()===t)return pi.create(t,this._languageId,i.version,i.getValue());return null}};})();