UNPKG

@sheetxl/studio-vanilla

Version:

SheetXL Studio - Vanilla entry point for integrating SheetXL UI.

33 lines (32 loc) 9.77 kB
"use strict";/** * @license @sheetxl/studio-vanilla - SheetXL Studio - Vanilla entry point for integrating SheetXL UI. - v0.6.4 * * (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("./Bd-US8M4eZh5SC26.cjs");let $=null,L=null;const le={compilerOptions:{target:"esnext"}},se=async()=>` interface FirstTest { isTrue?: boolean; } `,Q=new Map([["IReferenceRange","r"],["IRange","l"]]),Z=new Map([["IWorkbook","workbook"],["ISheet","sheet"],["ICellRanges","ranges"],["ICellRange","range"],["IFormulaContext","context"]]),V=(T,S)=>{Array.from(S.keys()).forEach(z=>{const P=S.get(z);S.set(`${T}.${z}`,P)})},ce=new Map([["Scalar","*"],["FormulaError.Known",b.M.Error],["Date","Date"],["JSON","JSON"]]),de=new Map([]),U="SheetXL";V(U,Q),V(U,Z),V(U,de);const ue=new Map([["Promise",()=>({async:!0})],["Observable",()=>({stream:!0})]]);let R=null;async function pe(){if(R)return R;try{return await(await Promise.resolve().then(()=>require("./PTCzG15fjiV6_9ss.cjs"))).initialize()}catch(T){throw R=null,T}finally{R=null}}exports.compileModule=async function(T){const S=T?.source??null;if(!S)return null;const z=(T.disableBundle||T.declarationsOnly)??!1,P=[se(),pe()],X=await Promise.all(P),ee=X[0],n=X[1];let C="",j=null;const O=[],te={allowJs:!0,declaration:!1,sourceMap:!1,inlineSourceMap:!1,inlineSources:!1,isolatedModules:!0,preserveConstEnums:!1,module:99,noResolve:!0,emitDeclarationOnly:!1,target:n.ScriptTarget.ES2020},A="script",I=`${A}.ts`,_="lib.d.ts",H="global.d.ts",F={[I]:S,[_]:` /** * 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>; } `,[H]:ee},ne={getSourceFile:(e,o,y,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=>_,getNewLine:()=>` `},q=n.createProgram([I,H],te,ne),D=q.getTypeChecker(),re=q.getSourceFile(I),W=q.emit();W.diagnostics.length>0&&console.warn(W.diagnostics),C=F[`${A}.js`];const N=(e,o,y,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,N(i,o,y,r)}else if(e.kind!==n.SyntaxKind.TupleType&&e.kind===n.SyntaxKind.TypeReference){const i=e.typeName?.getText?.()??null,f=Q.get(i);let m=!1;f&&(o.range=f,m=!0);const x=ce.get(i);if(x&&(o.scalar=x),x!==void 0&&(m=!0),r){const c=Z.get(i);if(c)return c}else{const c=ue.get(i);if(c){const l={...o,...c()};let t=0;if(l.async&&t++,l.stream&&t++,t>1)return void h(e,new Error(`'${i}' cannot have multiple modifiers: '${e?.parent?.name?.escapedText}'.`));o=l,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}'.`));N(p[0],o,y,r)}}}else h(e,new Error(`Type is not defined for '${o?.name??"return"}'.`))},k=[],h=(e,o)=>{k.push(o)};if(n.forEachChild(re,e=>{if(y=e,(n.getCombinedModifierFlags(y)&n.ModifierFlags.Export)!==0&&n.isFunctionDeclaration(e)){const r={},i={parameters:{}},f=e?.name?.getText();try{r.name=f;const m=D.getSymbolAtLocation(e.name).getDocumentationComment(D);if(m&&m.length>0&&m[0].text){let l=m[0].text;l=l.replace(/[\r\n]+/g,"\\n").trim(),i.summary=l}const x={};N(e.type,x,r,!1),r.returnType=x;const p={};o=e,(n.getCombinedModifierFlags(o)&n.ModifierFlags.Default)!==0&&(p.default=!0,j=f),Object.keys(p).length>0&&(r.behavior=p),r.parameters=[];const c=new Map;for(let l=0;l<e.parameters.length;l++){const t=e.parameters[l],s={};s.name=t.name?.getText();const E=N(t.type,s,r,!0);if(E){if(r.parameters.length!==0){const v=e?.parent,u=v?.name?.getText();return void h(e,new Error(`'${r.name}' contexts must be the first parameter: '${u}'.`))}r.context=E;continue}let g;if((t.initializer!==void 0&&t.initializer!==null||t.questionToken!==void 0&&t.questionToken!==null)&&(s.optional=!0,t.initializer))try{g=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(v){console.warn(`Couldn't extract default value for parameter '${s.name}'`,v)}t.dotDotDotToken&&(s.rest=!0),r.parameters.push(s);const d={description:""};i.parameters[s.name]=d;const a=D.getSymbolAtLocation(t.name).getDocumentationComment(D);a&&a.length>0&&a[0].text&&(d.description=a[0].text),g!==void 0&&(d.defaultValue=g),c.set(s.name,s)}if(e.jsDoc&&e.jsDoc.length>0){const l=e.jsDoc;for(let t=0;t<l.length;t++){const s=l[t]?.tags;if(s)for(let E=0;E<s.length;E++){const g=s[E];let d=g?.tagName?.text;if(!d)continue;d=d.toLowerCase();let a=g.comment;const v=d==="hidden";if((typeof a=="string"||v)&&(typeof a=="string"&&(a=a.replace(/[\r\n]+/g,"\\n").trim()),v||!a||(a=a.split(/\\n/)[0],a&&a.length!==0))){if(a&&typeof a=="string"){const u=/\{@link(code|plain)?\s+([^}|]+)(?:\s*\|\s*([^}]+))?\}/g;let w,K=a,M=[];for(;(w=u.exec(a))!==null;){const[B,J,oe,G]=w,ae=[oe.trim()];G&&ae.push(G.trim())}a=K,M.length>0&&d==="see"&&(i.links||(i.links=[]),i.links.push(...M))}if(d==="name"){const u=a;u!==f&&(i.name=u)}else if(d!=="description"){if(d==="summary"){const u=a;u&&(i.summary=u)}else if(d==="param"){const u=g.name?.text,w=c.get(u);if(!w){k.push(new Error(`Parameter '${u}' not found in function '${f}'.`));continue}if(g.typeExpression&&g.typeExpression.type)try{const K=g.typeExpression.type;if(K.kind===n.SyntaxKind.UnionType){const M=[];w.enums=M,K.types.forEach(B=>{if(B.kind===n.SyntaxKind.LiteralType){const J=B.literal.text;J&&M.push(J)}})}}catch(K){console.warn("Error parsing JSDoc type expression:",K)}}else if(d==="returns"||d==="return")r.returnType.description=a;else if(d==="category")i.category=a;else if(d==="hidden"){let u=!0;const w=a?.toLowerCase();w==="false"?u=!1:w!=="true"&&(u=a),u!==!1&&(i.hidden=u??!0)}}}}}}Object.keys(r.returnType).length===0&&delete r.returnType,O.push([r,i])}catch(m){h(e,new Error(`'${f}': ${m.message}`))}}var o,y}),k.length>0)throw console.warn(k),new Error("There were compilation errors.",{cause:k});if(O.length===0)throw new Error("No exported functions.");const ie=`${b.Yt.uuidV4()}-script`;try{z||k.length!==0||(C=await async function(e,o,y="/script.js",r="__SHEETXL"){try{const i=await async function(){if($)return $;if(L){if(await L,!$)throw new Error("ESBuild initialization promise resolved, but instance is not available.");return $}let c,l;L=new Promise((t,s)=>{c=t,l=s});try{const{initialize:t}=await Promise.resolve().then(()=>require("./B_SQGFlHO6XiQp1E.cjs"));return $=await t(),c(),$}catch(t){throw console.error("Failed to import or initialize esbuild:",t),L=null,l(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 l="sheetxl-"+new Date().getTime();c.onResolve({filter:new RegExp(`^(${y.replace("/","\\/")}|${f})$`)},t=>({path:t.path,namespace:l})),c.onResolve({filter:/.*/},t=>{if(t.namespace!==l)return console.warn(`esbuild: Treating import "${t.path}" as external.`),{path:t.path,external:!0}}),c.onLoad({filter:/.*/,namespace:l},t=>{let s;if(t.path===y)s=o;else{if(t.path!==f)return{errors:[{text:`Cannot load unknown path in ${l}: ${t.path}`}]};s=m}return{contents:s,loader:"ts"}})}},p=await i.build({entryPoints:[y],bundle:!0,write:!1,format:"esm",plugins:[x],sourcemap:"inline",tsconfigRaw:le,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,C,A))}catch{console.warn("Error bundling script")}const Y={functions:O,commitId:ie,source:S,name:"Script",language:"typescript",compiled:C};return j&&(Y.autoRun=j),Y};