1+ type CJ3Library = any ;
2+
13declare global {
24 /**
35 * @global
@@ -67,18 +69,29 @@ declare global {
6769 } ) : Promise < void > ;
6870
6971 /**
70- * > It gives you the state of all the threads
71- * @internal
7272 * @global
73- * @see https://discord .com/channels/988743885121548329/1103695759779573850/1330613377843597365
73+ * @see https://cheerpj .com/docs/reference/cheerpjRunMain
7474 */
75- function dumpAllThread ( param : null ) : any ;
75+ function cheerpjRunMain (
76+ className : string ,
77+ classPath : string ,
78+ ...args : string [ ]
79+ ) : Promise < number > ;
7680
7781 /**
7882 * @global
79- * @see https://cheerpj.com/docs/reference/cheerpOSAddStringFile
83+ * @see https://cheerpj.com/docs/reference/cheerpjRunJar
8084 */
81- function cheerpOSAddStringFile ( path : string , data : string | Uint8Array ) : void ;
85+ function cheerpjRunJar (
86+ jarName : string ,
87+ ...args : string [ ]
88+ ) : Promise < number > ;
89+
90+ /**
91+ * @global
92+ * @see https://cheerpj.com/docs/reference/cheerpjRunLibrary
93+ */
94+ function cheerpjRunLibrary ( classPath : string ) : Promise < CJ3Library > ;
8295
8396 /**
8497 * @global
@@ -92,18 +105,45 @@ declare global {
92105
93106 /**
94107 * @global
95- * @see https://cheerpj.com/docs/reference/cheerpjRunJar
108+ * @see https://cheerpj.com/docs/reference/cjFileBlob
96109 */
97- function cheerpjRunJar (
98- jarName : string ,
99- ...args : string [ ]
100- ) : Promise < number > ;
110+ function cjFileBlob ( path : string ) : Promise < Blob > ;
111+
112+ /**
113+ * @global
114+ * @see https://cheerpj.com/docs/reference/cheerpOSAddStringFile
115+ */
116+ function cheerpOSAddStringFile ( path : string , data : string | Uint8Array ) : void ;
117+
118+ /**
119+ * @global
120+ * @see https://cheerpj.com/docs/reference/cjGetRuntimeResources
121+ */
122+ function cjGetRuntimeResources ( ) : string ;
123+
124+ /**
125+ * @global
126+ * @see https://cheerpj.com/docs/reference/cjGetProguardConfiguration
127+ */
128+ function cjGetProguardConfiguration ( ) : void ;
129+
130+ /**
131+ * > It gives you the state of all the threads
132+ * @internal
133+ * @global
134+ * @see https://discord.com/channels/988743885121548329/1103695759779573850/1330613377843597365
135+ */
136+ function dumpAllThread ( param : null ) : any ;
101137}
102138
103139
104140// import * as CheerpJ3 from "https://cjrtnc.leaningtech.com/3_20241017_546/cj3loader.js?url";
105141
106- export async function getCheerpJLink ( version : "latest" | ( string & { } ) = "3_20250113_576" ) {
142+ // @ts -ignore
143+ // const isBrowser = import.meta.env.SSR === false;
144+ type AnyString = string & { } ;
145+
146+ export async function getCheerpJLink ( version : "latest" | AnyString = "4.2" ) {
107147 const url =
108148 version !== "latest"
109149 ? `https://cjrtnc.leaningtech.com/${ version } /cj3loader.js`
@@ -113,7 +153,21 @@ export async function getCheerpJLink(version: "latest" | (string & {}) = "3_2025
113153 return url ;
114154}
115155
116- export default async function loadCheerpJ ( ) {
156+ type CheerpJ = Pick <
157+ typeof window ,
158+ | "cheerpjInit"
159+ | "cheerpjRunMain"
160+ | "cheerpjRunJar"
161+ | "cheerpjRunLibrary"
162+ | "cheerpjRunLibrary"
163+ | "cjFileBlob"
164+ | "cheerpOSAddStringFile"
165+ | "cjGetRuntimeResources"
166+ | "cjGetProguardConfiguration"
167+ | "dumpAllThread"
168+ > ;
169+
170+ export default async function loadCheerpJ ( ) : Promise < CheerpJ > {
117171 const cheerpjUrl : string =
118172 document . querySelector < HTMLTemplateElement > ( "[data-cheerpj-url]" )
119173 ?. dataset
@@ -124,14 +178,30 @@ export default async function loadCheerpJ() {
124178 const script = document . createElement ( "script" ) ;
125179 script . src = cheerpjUrl ;
126180
181+
127182 const { promise, resolve, reject } = Promise . withResolvers ( ) ;
128183
129184 script . onload = ( ) => resolve ( undefined ) ;
130185 script . onerror = ( ) => reject ( ) ;
186+
131187
132188 document . body . append ( script ) ;
133189
134190 await promise ;
191+
192+ // return {
193+ // cheerpjInit,
194+ // // cheerpjRunMain,
195+ // cheerpjRunJar,
196+ // cheerpjRunLibrary,
197+ // cheerpjCreateDisplay,
198+ // cjFileBlob,
199+ // cheerpOSAddStringFile,
200+ // cjGetRuntimeResources,
201+ // cjGetProguardConfiguration,
202+ // dumpAllThread
203+ // };
204+ return window ;
135205}
136206
137207// TODO: This was needed to mark this file as a module. Investigate if this is still needed.
0 commit comments