@sheetxl/studio-vanilla
Version:
SheetXL Studio - Vanilla entry point for integrating SheetXL UI.
33 lines (32 loc) • 9.8 kB
JavaScript
;/**
* @license @sheetxl/studio-vanilla - SheetXL Studio - Vanilla entry point for integrating SheetXL UI. - v0.7.27
*
* (C) 2025-present SheetXL Inc. & Michael T. Ford
* License: The license can be found at https://www.sheetxl.com/license.
*/Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const b=require("./Bc1oKNEzl3Kcj4g5.cjs");let $=null,R=null;const ce={compilerOptions:{target:"esnext"}},de=async()=>`
interface FirstTest {
isTrue?: boolean;
}
`,ee=new Map([["IReferenceRange","r"],["IRange","l"]]),te=new Map([["IWorkbook","workbook"],["ISheet","sheet"],["ICellRanges","ranges"],["ICellRange","range"],["IFormulaContext","context"]]),U=(T,S)=>{Array.from(S.keys()).forEach(C=>{const j=S.get(C);S.set(`${T}.${C}`,j)})},ue=new Map([["Scalar","*"],["FormulaError.Known",b.M.Error],["Date","Date"],["JSON","JSON"]]),pe=new Map([]),X="SheetXL";U(X,ee),U(X,te),U(X,pe);const me=new Map([["Promise",()=>({async:!0})],["Observable",()=>({stream:!0})]]);let P=null;async function fe(){if(P)return P;try{return await(await Promise.resolve().then(()=>require("./CAGI7VeRTE_NwryZ.cjs"))).initialize()}catch(T){throw P=null,T}finally{P=null}}exports.compileModule=async function(T){const S=T?.source??null;if(!S)return null;const C=(T.disableBundle||T.declarationsOnly)??!1,j=[de(),fe()],_=await Promise.all(j),ne=_[0],n=_[1];let D="",O=null;const A=[],re={allowJs:!0,declaration:!1,sourceMap:!1,inlineSourceMap:!1,inlineSources:!1,isolatedModules:!0,preserveConstEnums:!1,module:99,noResolve:!0,emitDeclarationOnly:!1,target:n.ScriptTarget.ES2020},I="script",q=`${I}.ts`,H="lib.d.ts",W="global.d.ts",F={[q]:S,[H]:`
/**
* Represents the completion of an asynchronous operation
*/
interface Promise<T> {
/**
* Attaches a callback that is invoked when the Promise is settled (fulfilled or rejected). The
* resolved value cannot be modified from the callback.
* @param onfinally The callback to execute when the Promise is settled (fulfilled or rejected).
* @returns A Promise for the completion of the callback.
*/
finally(onfinally?: (() => void) | undefined | null): Promise<T>;
}
`,[W]:ne},ie={getSourceFile:(e,o,g,r)=>n.createSourceFile(e,F[e],n.ScriptTarget.Latest,!0),fileExists:e=>F[e]!==void 0,readFile:e=>F[e],writeFile:(e,o)=>{F[e]=o},getCurrentDirectory:()=>"./",getCanonicalFileName:e=>e,useCaseSensitiveFileNames:()=>!0,getDefaultLibFileName:e=>H,getNewLine:()=>`
`},B=n.createProgram([q,W],re,ie),N=B.getTypeChecker(),oe=B.getSourceFile(q),G=B.emit();G.diagnostics.length>0&&console.warn(G.diagnostics),D=F[`${I}.js`];const L=(e,o,g,r)=>{if(e){if(e.kind===n.SyntaxKind.NumberKeyword)o.scalar=b.M.Number;else if(e.kind===n.SyntaxKind.StringKeyword)o.scalar=b.M.String;else if(e.kind===n.SyntaxKind.BooleanKeyword)o.scalar=b.M.Boolean;else if(e.kind===n.SyntaxKind.UndefinedKeyword||e.kind===n.SyntaxKind.NullKeyword||e.kind===n.SyntaxKind.VoidKeyword){if(r)return void h(e,new Error(`'undefined' is not a valid type for input: '${e?.parent?.name?.escapedText}'.`));o.scalar=b.M.Null}else if(e.kind===n.SyntaxKind.BigIntKeyword)o.scalar=b.M.Number;else if(e.kind===n.SyntaxKind.AnyKeyword)o.scalar=b.M.Null;else if(e.kind===n.SyntaxKind.ArrayType){const i=e.elementType;if(!i)return void h(e,new Error(`'Array' must be typed: '${e?.parent?.name?.escapedText}'.`));o.arrayDepth=(o.arrayDepth??0)+1,L(i,o,g,r)}else if(e.kind!==n.SyntaxKind.TupleType&&e.kind===n.SyntaxKind.TypeReference){const i=e.typeName?.getText?.()??null,f=ee.get(i);let m=!1;f&&(o.range=f,m=!0);const x=ue.get(i);if(x&&(o.scalar=x),x!==void 0&&(m=!0),r){const c=te.get(i);if(c)return c}else{const c=me.get(i);if(c){const a={...o,...c()};let t=0;if(a.async&&t++,a.stream&&t++,t>1)return void h(e,new Error(`'${i}' cannot have multiple modifiers: '${e?.parent?.name?.escapedText}'.`));o=a,m=!0}}if(!m)return void h("node",new Error(`'${i}' is not a valid type: '${e?.parent?.name?.escapedText}'.`));const p=e.typeArguments;if(p){if(p.length!==1)return void h(e,new Error(`'${i}' must be typed with exactly 1 type: '${e?.parent?.name?.escapedText}'.`));L(p[0],o,g,r)}}}else h(e,new Error(`Type is not defined for '${o?.name??"return"}'.`))},E=[],h=(e,o)=>{E.push(o)};if(n.forEachChild(oe,e=>{if(g=e,(n.getCombinedModifierFlags(g)&n.ModifierFlags.Export)!==0&&n.isFunctionDeclaration(e)){const r={},i={parameters:{}},f=e?.name?.getText();try{r.name=f;const m=N.getSymbolAtLocation(e.name).getDocumentationComment(N);if(m&&m.length>0&&m[0].text){let a=m[0].text;a=a.replace(/[\r\n]+/g,"\\n").trim(),i.summary=a}const x={};L(e.type,x,r,!1),r.returnType=x;const p={};o=e,(n.getCombinedModifierFlags(o)&n.ModifierFlags.Default)!==0&&(p.default=!0,O=f),Object.keys(p).length>0&&(r.behavior=p),r.parameters=[];const c=new Map;for(let a=0;a<e.parameters.length;a++){const t=e.parameters[a],s={};s.name=t.name?.getText();const v=L(t.type,s,r,!0);if(v){if(r.parameters.length!==0){const d=e?.parent,l=d?.name?.getText();return void h(e,new Error(`'${r.name}' contexts must be the first parameter: '${l}'.`))}r.context=v;continue}let M;if((t.initializer!==void 0&&t.initializer!==null||t.questionToken!==void 0&&t.questionToken!==null)&&(s.optional=!0,t.initializer))try{M=t.initializer.kind===n.SyntaxKind.StringLiteral?t.initializer.text:t.initializer.kind===n.SyntaxKind.NumericLiteral?parseFloat(t.initializer.text):t.initializer.kind===n.SyntaxKind.TrueKeyword||t.initializer.kind===n.SyntaxKind.FalseKeyword?t.initializer.kind===n.SyntaxKind.TrueKeyword:t.initializer.kind===n.SyntaxKind.NullKeyword?null:t.initializer.kind===n.SyntaxKind.ObjectLiteralExpression||t.initializer.kind===n.SyntaxKind.ArrayLiteralExpression?t.initializer.getText():t.initializer.getText?.()}catch(d){console.warn(`Couldn't extract default value for parameter '${s.name}'`,d)}t.dotDotDotToken&&(s.rest=!0),r.parameters.push(s);const k={description:""};i.parameters[s.name]=k;const y=N.getSymbolAtLocation(t.name).getDocumentationComment(N);y&&y.length>0&&y[0].text&&(k.description=y[0].text),M!==void 0&&(k.defaultValue=M),c.set(s.name,s)}if(e.jsDoc&&e.jsDoc.length>0){const a=e.jsDoc,t=a.length;for(let s=0;s<t;s++){const v=a[s]?.tags;if(!v)continue;const M=v.length;for(let k=0;k<M;k++){const y=v[k];let d=y?.tagName?.text;if(!d)continue;d=d.toLowerCase();let l=y.comment;const Y=d==="hidden";if((typeof l=="string"||Y)&&(typeof l=="string"&&(l=l.replace(/[\r\n]+/g,"\\n").trim()),Y||!l||(l=l.split(/\\n/)[0],l&&l.length!==0))){if(l&&typeof l=="string"){const u=/\{@link(code|plain)?\s+([^}|]+)(?:\s*\|\s*([^}]+))?\}/g;let w,K=l,z=[];for(;(w=u.exec(l))!==null;){const[J,V,le,Z]=w,se=[le.trim()];Z&&se.push(Z.trim())}l=K,z.length>0&&d==="see"&&(i.links||(i.links=[]),i.links.push(...z))}if(d==="name"){const u=l;u!==f&&(i.name=u)}else if(d!=="description"){if(d==="summary"){const u=l;u&&(i.summary=u)}else if(d==="param"){const u=y.name?.text,w=c.get(u);if(!w){E.push(new Error(`Parameter '${u}' not found in function '${f}'.`));continue}if(y.typeExpression&&y.typeExpression.type)try{const K=y.typeExpression.type;if(K.kind===n.SyntaxKind.UnionType){const z=[];w.enums=z,K.types.forEach(J=>{if(J.kind===n.SyntaxKind.LiteralType){const V=J.literal.text;V&&z.push(V)}})}}catch(K){console.warn("Error parsing JSDoc type expression:",K)}}else if(d==="returns"||d==="return")r.returnType.description=l;else if(d==="category")i.category=l;else if(d==="hidden"){let u=!0;const w=l?.toLowerCase();w==="false"?u=!1:w!=="true"&&(u=l),u!==!1&&(i.hidden=u??!0)}}}}}}Object.keys(r.returnType).length===0&&delete r.returnType,A.push([r,i])}catch(m){h(e,new Error(`'${f}': ${m.message}`))}}var o,g}),E.length>0)throw console.warn(E),new Error("There were compilation errors.",{cause:E});if(A.length===0)throw new Error("No exported functions.");const ae=`${b.te.uuidV4()}-script`;try{C||E.length!==0||(D=await(async function(e,o,g="/script.js",r="__SHEETXL"){try{const i=await(async function(){if($)return $;if(R){if(await R,!$)throw new Error("ESBuild initialization promise resolved, but instance is not available.");return $}let c,a;R=new Promise((t,s)=>{c=t,a=s});try{const{initialize:t}=await Promise.resolve().then(()=>require("./DEMlS8d4EFQa0PxN.cjs"));return $=await t(),c(),$}catch(t){throw console.error("Failed to import or initialize esbuild:",t),R=null,a(t),t}})(),f="@sheetxl/primitives",m=`
export const FormulaContext = globalThis.${r}?.FormulaContext;
export const ScalarType = globalThis.${r}?.ScalarType;
export const Observable = globalThis.${r}?.Observable;
export const IRange = globalThis.${r}?.IRange;
export const FormulaError = globalThis.${r}?.FormulaError;
// Add more exports as needed
`,x={name:"sheetxl-esbuild-in-memory",setup(c){const a="sheetxl-"+new Date().getTime();c.onResolve({filter:new RegExp(`^(${g.replace("/","\\/")}|${f})$`)},t=>({path:t.path,namespace:a})),c.onResolve({filter:/.*/},t=>{if(t.namespace!==a)return console.warn(`esbuild: Treating import "${t.path}" as external.`),{path:t.path,external:!0}}),c.onLoad({filter:/.*/,namespace:a},t=>{let s;if(t.path===g)s=o;else{if(t.path!==f)return{errors:[{text:`Cannot load unknown path in ${a}: ${t.path}`}]};s=m}return{contents:s,loader:"ts"}})}},p=await i.build({entryPoints:[g],bundle:!0,write:!1,format:"esm",plugins:[x],sourcemap:"inline",tsconfigRaw:ce,minify:!0,platform:"neutral"});if(p.outputFiles&&p.outputFiles.length>0)return p.outputFiles[0].text;throw p.errors&&p.errors.length>0?new Error(`esbuild bundling failed: ${p.errors.map(c=>c.text).join(`
`)}`):new Error("esbuild did not produce an output file.")}catch(i){throw console.error("esbuild bundling process failed:",i),i}})(0,D,I))}catch{console.warn("Error bundling script")}const Q={functions:A,commitId:ae,source:S,name:"Script",language:"typescript",compiled:D};return O&&(Q.autoRun=O),Q};