webuix 0.0.12 → 0.0.14

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.
package/dist/index.cjs.js CHANGED
@@ -1 +1 @@
1
- var{defineProperty:E,getOwnPropertyNames:y,getOwnPropertyDescriptor:X}=Object,w=Object.prototype.hasOwnProperty;var f=new WeakMap,b=(t)=>{var r=f.get(t),e;if(r)return r;if(r=E({},"__esModule",{value:!0}),t&&typeof t==="object"||typeof t==="function")y(t).map((n)=>!w.call(r,n)&&E(r,n,{get:()=>t[n],enumerable:!(e=X(t,n))||e.enumerable}));return f.set(t,r),r};var h=(t,r)=>{for(var e in r)E(t,e,{get:r[e],enumerable:!0,configurable:!0,set:(n)=>r[e]=()=>n})};var _={};h(_,{wrapToReadableStream:()=>c,wrapInputStream:()=>m,WXEventHandler:()=>l,WXEvent:()=>o});module.exports=b(_);var v={chunkSize:1048576,headers:{"Content-Type":"application/octet-stream"}};async function c(t,r={}){let e={...v,...r};return new Promise((n,a)=>{let i;try{if(i=t,!i)throw new Error("Failed to open file input stream")}catch(s){a(s);return}let u=()=>{try{i?.close()}catch(s){console.error("Error during abort cleanup:",s)}a(new DOMException("The operation was aborted.","AbortError"))};if(e.signal){if(e.signal.aborted){u();return}e.signal.addEventListener("abort",u)}let W=new ReadableStream({async pull(s){try{let p=S(i,e.chunkSize);if(!p){s.close(),d();return}s.enqueue(p)}catch(p){d(),s.error(p),a(new Error(`Error reading file chunk: ${p}`))}},cancel(s){console.warn("Stream canceled:",s),d()}});function d(){try{if(e.signal)e.signal.removeEventListener("abort",u);i?.close()}catch(s){console.error(`Error during cleanup: ${s}`)}}n(W)})}function S(t,r){try{let e=r?t.readChunk(r):t.read();if(typeof e==="number")return new Uint8Array([e]);else if(typeof e==="string"){let n=JSON.parse(e);return n&&Array.isArray(n)&&n.length>0?new Uint8Array(n):null}return null}catch(e){throw new Error("Error reading chunk data: "+e)}}async function m(t,r={}){let e={...v,...r};try{let n=await c(t,e);return new Response(n,e)}catch(n){throw new Error(`wrapInputStream failed: ${n}`)}}class o extends Event{_wxOrigin;_wxData;get wxOrigin(){return this._wxOrigin}set wxOrigin(t){this._wxOrigin=t}get wx(){return this._wxData}set wx(t){this._wxData=t}constructor(t){super(t,{bubbles:!0,cancelable:!0,composed:!0})}}var g={cordova:!1};class l{_initialized=!1;_handlers=new WeakMap;_eventTypes;get eventTypes(){return this._eventTypes}constructor(t=g){if(this._initialized)return;this._initialized=!0,this._eventTypes={WX_ON_BACK:t.cordova?"backbutton":"back",WX_ON_RESUME:"resume",WX_ON_REFRESH:"refresh",WX_ON_PAUSE:"pause",WX_ON_KEYBOARD:"keyboard",WX_ON_INSETS:"insets"},window.addEventListener("message",(r)=>{try{if(typeof r.data!=="string")return;let e=JSON.parse(r.data);if(!e?.type)return;let n=this._eventTypes[e.type]??e.type;this._dispatch(window,n,e)}catch(e){console.error("[WXEvent] Message error:",e)}})}_dispatch(t,r,e){let n=new o(r);n.wx=e.data,n.wxOrigin="system",t.dispatchEvent(n)}on(t,r,e){if(!this._initialized)new l;let n=(i)=>{if(!(i instanceof o)){console.warn("[WXEvent] Event is not a WXEvent:",i);return}if(i.wxOrigin==="system"){if(typeof e==="function")e(i);else if(e&&typeof e.handleEvent==="function")e.handleEvent(i)}};if(!this._handlers.has(t))this._handlers.set(t,new Map);let a=this._handlers.get(t);if(!a.has(r))a.set(r,new Set);return a.get(r).add({handler:e,wrapper:n}),t.addEventListener(r,n),()=>this.off(t,r,e)}off(t,r,e){let n=this._handlers.get(t);if(!n?.has(r))return;for(let a of n.get(r))if(a.handler===e){t.removeEventListener(r,a.wrapper),n.get(r).delete(a);break}}}
1
+ var{defineProperty:v,getOwnPropertyNames:O,getOwnPropertyDescriptor:_}=Object,x=Object.prototype.hasOwnProperty;var w=new WeakMap,h=(e)=>{var t=w.get(e),n;if(t)return t;if(t=v({},"__esModule",{value:!0}),e&&typeof e==="object"||typeof e==="function")O(e).map((r)=>!x.call(t,r)&&v(t,r,{get:()=>e[r],enumerable:!(n=_(e,r))||n.enumerable}));return w.set(e,t),t};var T=(e,t)=>{for(var n in t)v(e,n,{get:t[n],enumerable:!0,configurable:!0,set:(r)=>t[n]=()=>r})};var R={};T(R,{wrapToReadableStream:()=>E,wrapOutputStream:()=>u,wrapInputStream:()=>y,WebUI:()=>X,WXEventHandler:()=>f,WXEvent:()=>a,Intent:()=>W});module.exports=h(R);var c={chunkSize:1048576,headers:{"Content-Type":"application/octet-stream"}};async function E(e,t={}){let n={...c,...t};return new Promise((r,i)=>{let s;try{if(s=e,!s)throw new Error("Failed to open file input stream")}catch(o){i(o);return}let l=()=>{try{s?.close()}catch(o){console.error("Error during abort cleanup:",o)}i(new DOMException("The operation was aborted.","AbortError"))};if(n.signal){if(n.signal.aborted){l();return}n.signal.addEventListener("abort",l)}let b=new ReadableStream({async pull(o){try{let p=g(s,n.chunkSize);if(!p){o.close(),d();return}o.enqueue(p)}catch(p){d(),o.error(p),i(new Error(`Error reading file chunk: ${p}`))}},cancel(o){console.warn("Stream canceled:",o),d()}});function d(){try{if(n.signal)n.signal.removeEventListener("abort",l);s?.close()}catch(o){console.error(`Error during cleanup: ${o}`)}}r(b)})}function g(e,t){try{let n=t?e.readChunk(t):e.read();if(typeof n==="number")return new Uint8Array([n]);else if(typeof n==="string"){let r=JSON.parse(n);return r&&Array.isArray(r)&&r.length>0?new Uint8Array(r):null}return null}catch(n){throw new Error("Error reading chunk data: "+n)}}async function y(e,t={}){let n={...c,...t};try{let r=await E(e,n);return new Response(r,n)}catch(r){throw new Error(`wrapInputStream failed: ${r}`)}}async function u(e,t){if(!e||typeof e.getReader!=="function")throw new Error("Invalid ReadableStream provided.");if(!t||typeof t.write!=="function"||typeof t.close!=="function")throw new Error("Invalid outputStreamInstance provided. It must be an already opened stream with 'write' and 'close' methods.");let n=new WritableStream({async start(r){console.log("WritableStream started, output stream instance ready.")},async write(r,i){if(r instanceof Uint8Array)for(let s=0;s<r.length;s++)t.write(r[s]);else console.warn("Received non-Uint8Array chunk in WritableStream:",r),i.error(new TypeError("Expected Uint8Array chunks."))},async close(){console.log("WritableStream closed. Flushing and closing native stream.");try{t.flush(),t.close()}catch(r){throw console.error("Error during WritableStream close cleanup:",r),r}},async abort(r){console.error("WritableStream aborted:",r);try{t.close()}catch(i){console.error("Error during WritableStream abort cleanup:",i)}}});try{await e.pipeTo(n),console.log("Piping completed successfully.")}catch(r){let i=r instanceof Error?r:new Error(String(r));throw console.error("Error during stream piping:",i),new Error(`Failed to pipe stream: ${i.message}`)}}class a extends Event{_wxOrigin;_wxData;get wxOrigin(){return this._wxOrigin}set wxOrigin(e){this._wxOrigin=e}get wx(){return this._wxData}set wx(e){this._wxData=e}constructor(e){super(e,{bubbles:!0,cancelable:!0,composed:!0})}}var m={cordova:!1};class f{_initialized=!1;_handlers=new WeakMap;_eventTypes;get eventTypes(){return this._eventTypes}constructor(e=m){if(this._initialized)return;this._initialized=!0,this._eventTypes={WX_ON_BACK:e.cordova?"backbutton":"back",WX_ON_RESUME:"resume",WX_ON_REFRESH:"refresh",WX_ON_PAUSE:"pause",WX_ON_KEYBOARD:"keyboard",WX_ON_INSETS:"insets"},window.addEventListener("message",(t)=>{try{if(typeof t.data!=="string")return;let n=JSON.parse(t.data);if(!n?.type)return;let r=this._eventTypes[n.type]??n.type;this._dispatch(window,r,n)}catch(n){console.error("[WXEvent] Message error:",n)}})}_dispatch(e,t,n){let r=new a(t);r.wx=n.data,r.wxOrigin="system",e.dispatchEvent(r)}on(e,t,n){if(!this._initialized)new f;let r=(s)=>{if(!(s instanceof a)){console.warn("[WXEvent] Event is not a WXEvent:",s);return}if(s.wxOrigin==="system"){if(typeof n==="function")n(s);else if(n&&typeof n.handleEvent==="function")n.handleEvent(s)}};if(!this._handlers.has(e))this._handlers.set(e,new Map);let i=this._handlers.get(e);if(!i.has(t))i.set(t,new Set);return i.get(t).add({handler:n,wrapper:r}),e.addEventListener(t,r),()=>this.off(e,t,n)}off(e,t,n){let r=this._handlers.get(e);if(!r?.has(t))return;for(let i of r.get(t))if(i.handler===n){e.removeEventListener(t,i.wrapper),r.get(t).delete(i);break}}}class W{_action;_interface=null;constructor(e){if(this._action=e,typeof window==="undefined"||!window.$intent||typeof window.$intent.create!=="function")console.warn("window['$intent'] or window['$intent'].create is not defined. Intent functionality may be limited.");else this._interface=window.$intent.create(this._action)}getParsedIntent(){return this._interface}setData(e){if(this._interface&&typeof this._interface.setData==="function")this._interface.setData(e);else console.error("setData method not available on the intent interface.")}setPackage(e){if(this._interface&&typeof this._interface.setPackage==="function")this._interface.setPackage(e);else console.error("setPackage method not available on the intent interface.")}addCategory(e){if(this._interface&&typeof this._interface.addCategory==="function")this._interface.addCategory(e);else console.error("addCategory method not available on the intent interface.")}setType(e){if(this._interface&&typeof this._interface.setType==="function")this._interface.setType(e);else console.error("setType method not available on the intent interface.")}putExtra(e,t){if(this._interface&&typeof this._interface.putExtra==="function")this._interface.putExtra(e,t);else console.error("putExtra method not available on the intent interface.")}getStringExtra(e){if(this._interface&&typeof this._interface.getStringExtra==="function")return this._interface.getStringExtra(e);else return console.error("getStringExtra method not available on the intent interface."),null}getIntExtra(e){if(this._interface&&typeof this._interface.getIntExtra==="function")return this._interface.getIntExtra(e);else return console.error("getIntExtra method not available on the intent interface."),0}getBooleanExtra(e){if(this._interface&&typeof this._interface.getBooleanExtra==="function")return this._interface.getBooleanExtra(e);else return console.error("getBooleanExtra method not available on the intent interface."),!1}}class X{_interface=null;constructor(){if(typeof window==="undefined"||!window.webui)console.warn("window['webui'] is not defined. WebUI functionality may be limited.");else this._interface=window.webui}exit(){if(this._interface&&typeof this._interface.exit==="function")this._interface.exit();else console.error("exit method not available on the webui interface.")}setRefreshing(e){if(this._interface&&typeof this._interface.setRefreshing==="function")this._interface.setRefreshing(e);else console.error("setRefreshing method not available on the webui interface.")}get currentRootManager(){if(this._interface&&typeof this._interface.getCurrentRootManager!=="undefined")return this._interface.getCurrentRootManager();else return console.error("currentRootManager getter not available on the webui interface."),null}get currentApplication(){if(this._interface&&typeof this._interface.getCurrentApplication!=="undefined")return this._interface.getCurrentApplication();else return console.error("currentApplication getter not available on the webui interface."),null}getApplication(e){if(this._interface&&typeof this._interface.getApplication==="function")return this._interface.getApplication(e);else return console.error("getApplication method not available on the webui interface."),null}openFile(e){if(this._interface&&typeof this._interface.openFile==="function")this._interface.openFile(e.getParsedIntent());else console.error("openFile method not available on the webui interface.")}startActivity(e){if(this._interface&&typeof this._interface.startActivity==="function")this._interface.startActivity(e.getParsedIntent());else console.error("startActivity method not available on the webui interface.")}}
package/dist/index.d.ts CHANGED
@@ -20,6 +20,16 @@ export interface ReadableStreamInit extends RequestInit {
20
20
  }
21
21
  export declare function wrapToReadableStream(inputStream: FileInputInterfaceStream, init?: ReadableStreamInit): Promise<ReadableStream<Uint8Array>>;
22
22
  export declare function wrapInputStream(inputStream: FileInputInterfaceStream, init?: ReadableStreamInit): Promise<Response>;
23
+ /**
24
+ * This is a private interface which is not accessible in the window object.
25
+ * It is used to define the structure of a file input stream.
26
+ */
27
+ export interface FileOutputInterfaceStream {
28
+ write(b: number): void;
29
+ flush(): void;
30
+ close(): void;
31
+ }
32
+ export declare function wrapOutputStream(readableStream: ReadableStream<Uint8Array>, outputStreamInstance: FileOutputInterfaceStream): Promise<void>;
23
33
  export declare class WXEvent<T = any> extends Event {
24
34
  private _wxOrigin?;
25
35
  private _wxData?;
@@ -77,5 +87,132 @@ export declare class WXEventHandler {
77
87
  on<K extends keyof WXEventMap>(element: Window | Element, type: K, handler: WXEventListenerOrWXEventListenerObject<WXEventMap[K]>): () => void;
78
88
  off(element: Window | Element, type: WXEventType, handler: WXEventListenerOrWXEventListenerObject): void;
79
89
  }
90
+ export interface IntentData {
91
+ setPackage(packageName: string): void;
92
+ setData(data: string): void;
93
+ addCategory(category: string): void;
94
+ setType(type: string): void;
95
+ getStringExtra(name: string): string | null;
96
+ getIntExtra(name: string, defaultValue?: number): number;
97
+ getBooleanExtra(name: string, defaultValue?: boolean): boolean;
98
+ putExtra(name: string, value: string | number | boolean): void;
99
+ }
100
+ export declare class Intent {
101
+ private _action;
102
+ private _interface;
103
+ /**
104
+ * Initializes a new Intent object.
105
+ * @param {string} action The action to be performed by this intent.
106
+ */
107
+ constructor(action: string);
108
+ getParsedIntent(): IntentData | null;
109
+ /**
110
+ * Sets the data URI for the intent.
111
+ * @param {string} data The data URI string.
112
+ */
113
+ setData(data: string): void;
114
+ /**
115
+ * Sets the package name for the intent.
116
+ * This method corresponds to `setPackage` in IntentData.
117
+ * @param {string} packageName The package name to set.
118
+ */
119
+ setPackage(packageName: string): void;
120
+ /**
121
+ * Adds a category to the intent.
122
+ * This method corresponds to `addCategory` in IntentData.
123
+ * @param {string} category The category to add.
124
+ */
125
+ addCategory(category: string): void;
126
+ /**
127
+ * Sets the MIME type for the intent.
128
+ * This method corresponds to `setType` in IntentData.
129
+ * @param {string} type The MIME type to set.
130
+ */
131
+ setType(type: string): void;
132
+ /**
133
+ * Adds extended data to the intent.
134
+ * This method corresponds to the `putExtra` overloads in IntentData.
135
+ * @param {string} name The name of the extra data.
136
+ * @param {(string|number|boolean)} value The value of the extra data.
137
+ */
138
+ putExtra(name: string, value: string | number | boolean): void;
139
+ /**
140
+ * Retrieves string extra data from the intent.
141
+ * This method corresponds to `getStringExtra` in IntentData.
142
+ * @param {string} name The name of the extra data.
143
+ * @returns {string | null} The string value, or null if not found.
144
+ */
145
+ getStringExtra(name: string): string | null;
146
+ /**
147
+ * Retrieves integer extra data from the intent.
148
+ * This method corresponds to `getIntExtra` in IntentData.
149
+ * @param {string} name The name of the extra data.
150
+ * @returns {number} The integer value, or the default value if not found.
151
+ */
152
+ getIntExtra(name: string): number;
153
+ /**
154
+ * Retrieves boolean extra data from the intent.
155
+ * This method corresponds to `getBooleanExtra` in IntentData.
156
+ * @param {string} name The name of the extra data.
157
+ * @returns {boolean} The boolean value, or the default value if not found.
158
+ */
159
+ getBooleanExtra(name: string): boolean;
160
+ }
161
+ export interface WXApp {
162
+ getPackageName(): string;
163
+ getVersionName(): string;
164
+ getVersionCode(): number;
165
+ }
166
+ /**
167
+ * Represents the WebUI interface for interacting with native application functionalities.
168
+ * This class bridges JavaScript calls to methods exposed by the native ApplicationInterface.
169
+ */
170
+ export declare class WebUI {
171
+ private _interface;
172
+ constructor();
173
+ /**
174
+ * Exits the native application.
175
+ * Corresponds to `ApplicationInterface.exit()`.
176
+ */
177
+ exit(): void;
178
+ /**
179
+ * Sets the refreshing state of the pull-to-refresh mechanism.
180
+ * Requires pull-to-refresh and JavaScript refresh interceptor to be enabled natively.
181
+ * Corresponds to `ApplicationInterface.setRefreshing(state)`.
182
+ * @param {boolean} state True to show refreshing indicator, false to hide.
183
+ */
184
+ setRefreshing(state: boolean): void;
185
+ /**
186
+ * Gets information about the current root manager application.
187
+ * Corresponds to `ApplicationInterface.currentRootManager` getter.
188
+ * @returns {Object | null} An object with packageName, versionName, and versionCode, or null if unavailable.
189
+ */
190
+ get currentRootManager(): WXApp | null;
191
+ /**
192
+ * Gets information about the current application.
193
+ * Corresponds to `ApplicationInterface.currentApplication` getter.
194
+ * @returns {Object | null} An object with packageName, versionName, and versionCode, or null if unavailable.
195
+ */
196
+ get currentApplication(): WXApp | null;
197
+ /**
198
+ * Gets information about a specific application by its package name.
199
+ * Corresponds to `ApplicationInterface.getApplication(packageName)`.
200
+ * @param {string} packageName The package name of the application.
201
+ * @returns {Object | null} An object with packageName, versionName, and versionCode, or null if unavailable/error.
202
+ */
203
+ getApplication(packageName: string): WXApp | null;
204
+ /**
205
+ * Opens a file chooser dialog using the provided intent data.
206
+ * Corresponds to `ApplicationInterface.openFile(i: IntentData?)`.
207
+ * @param {Intent} intent An Intent object (from the previously defined Intent class) containing file selection details.
208
+ */
209
+ openFile(intent: Intent): void;
210
+ /**
211
+ * Starts a new activity using the provided intent data.
212
+ * Corresponds to `ApplicationInterface.startActivity(i: IntentData)`.
213
+ * @param {Intent} intent An Intent object (from the previously defined Intent class) describing the activity to start.
214
+ */
215
+ startActivity(intent: Intent): void;
216
+ }
80
217
 
81
218
  export {};
package/dist/index.esm.js CHANGED
@@ -1 +1 @@
1
- var u={chunkSize:1048576,headers:{"Content-Type":"application/octet-stream"}};async function d(t,n={}){let e={...u,...n};return new Promise((r,a)=>{let i;try{if(i=t,!i)throw new Error("Failed to open file input stream")}catch(s){a(s);return}let c=()=>{try{i?.close()}catch(s){console.error("Error during abort cleanup:",s)}a(new DOMException("The operation was aborted.","AbortError"))};if(e.signal){if(e.signal.aborted){c();return}e.signal.addEventListener("abort",c)}let v=new ReadableStream({async pull(s){try{let o=f(i,e.chunkSize);if(!o){s.close(),l();return}s.enqueue(o)}catch(o){l(),s.error(o),a(new Error(`Error reading file chunk: ${o}`))}},cancel(s){console.warn("Stream canceled:",s),l()}});function l(){try{if(e.signal)e.signal.removeEventListener("abort",c);i?.close()}catch(s){console.error(`Error during cleanup: ${s}`)}}r(v)})}function f(t,n){try{let e=n?t.readChunk(n):t.read();if(typeof e==="number")return new Uint8Array([e]);else if(typeof e==="string"){let r=JSON.parse(e);return r&&Array.isArray(r)&&r.length>0?new Uint8Array(r):null}return null}catch(e){throw new Error("Error reading chunk data: "+e)}}async function m(t,n={}){let e={...u,...n};try{let r=await d(t,e);return new Response(r,e)}catch(r){throw new Error(`wrapInputStream failed: ${r}`)}}class p extends Event{_wxOrigin;_wxData;get wxOrigin(){return this._wxOrigin}set wxOrigin(t){this._wxOrigin=t}get wx(){return this._wxData}set wx(t){this._wxData=t}constructor(t){super(t,{bubbles:!0,cancelable:!0,composed:!0})}}var W={cordova:!1};class E{_initialized=!1;_handlers=new WeakMap;_eventTypes;get eventTypes(){return this._eventTypes}constructor(t=W){if(this._initialized)return;this._initialized=!0,this._eventTypes={WX_ON_BACK:t.cordova?"backbutton":"back",WX_ON_RESUME:"resume",WX_ON_REFRESH:"refresh",WX_ON_PAUSE:"pause",WX_ON_KEYBOARD:"keyboard",WX_ON_INSETS:"insets"},window.addEventListener("message",(n)=>{try{if(typeof n.data!=="string")return;let e=JSON.parse(n.data);if(!e?.type)return;let r=this._eventTypes[e.type]??e.type;this._dispatch(window,r,e)}catch(e){console.error("[WXEvent] Message error:",e)}})}_dispatch(t,n,e){let r=new p(n);r.wx=e.data,r.wxOrigin="system",t.dispatchEvent(r)}on(t,n,e){if(!this._initialized)new E;let r=(i)=>{if(!(i instanceof p)){console.warn("[WXEvent] Event is not a WXEvent:",i);return}if(i.wxOrigin==="system"){if(typeof e==="function")e(i);else if(e&&typeof e.handleEvent==="function")e.handleEvent(i)}};if(!this._handlers.has(t))this._handlers.set(t,new Map);let a=this._handlers.get(t);if(!a.has(n))a.set(n,new Set);return a.get(n).add({handler:e,wrapper:r}),t.addEventListener(n,r),()=>this.off(t,n,e)}off(t,n,e){let r=this._handlers.get(t);if(!r?.has(n))return;for(let a of r.get(n))if(a.handler===e){t.removeEventListener(n,a.wrapper),r.get(n).delete(a);break}}}export{d as wrapToReadableStream,m as wrapInputStream,E as WXEventHandler,p as WXEvent};
1
+ var l={chunkSize:1048576,headers:{"Content-Type":"application/octet-stream"}};async function d(e,n={}){let t={...l,...n};return new Promise((r,i)=>{let s;try{if(s=e,!s)throw new Error("Failed to open file input stream")}catch(o){i(o);return}let E=()=>{try{s?.close()}catch(o){console.error("Error during abort cleanup:",o)}i(new DOMException("The operation was aborted.","AbortError"))};if(t.signal){if(t.signal.aborted){E();return}t.signal.addEventListener("abort",E)}let X=new ReadableStream({async pull(o){try{let a=w(s,t.chunkSize);if(!a){o.close(),f();return}o.enqueue(a)}catch(a){f(),o.error(a),i(new Error(`Error reading file chunk: ${a}`))}},cancel(o){console.warn("Stream canceled:",o),f()}});function f(){try{if(t.signal)t.signal.removeEventListener("abort",E);s?.close()}catch(o){console.error(`Error during cleanup: ${o}`)}}r(X)})}function w(e,n){try{let t=n?e.readChunk(n):e.read();if(typeof t==="number")return new Uint8Array([t]);else if(typeof t==="string"){let r=JSON.parse(t);return r&&Array.isArray(r)&&r.length>0?new Uint8Array(r):null}return null}catch(t){throw new Error("Error reading chunk data: "+t)}}async function y(e,n={}){let t={...l,...n};try{let r=await d(e,t);return new Response(r,t)}catch(r){throw new Error(`wrapInputStream failed: ${r}`)}}async function u(e,n){if(!e||typeof e.getReader!=="function")throw new Error("Invalid ReadableStream provided.");if(!n||typeof n.write!=="function"||typeof n.close!=="function")throw new Error("Invalid outputStreamInstance provided. It must be an already opened stream with 'write' and 'close' methods.");let t=new WritableStream({async start(r){console.log("WritableStream started, output stream instance ready.")},async write(r,i){if(r instanceof Uint8Array)for(let s=0;s<r.length;s++)n.write(r[s]);else console.warn("Received non-Uint8Array chunk in WritableStream:",r),i.error(new TypeError("Expected Uint8Array chunks."))},async close(){console.log("WritableStream closed. Flushing and closing native stream.");try{n.flush(),n.close()}catch(r){throw console.error("Error during WritableStream close cleanup:",r),r}},async abort(r){console.error("WritableStream aborted:",r);try{n.close()}catch(i){console.error("Error during WritableStream abort cleanup:",i)}}});try{await e.pipeTo(t),console.log("Piping completed successfully.")}catch(r){let i=r instanceof Error?r:new Error(String(r));throw console.error("Error during stream piping:",i),new Error(`Failed to pipe stream: ${i.message}`)}}class p extends Event{_wxOrigin;_wxData;get wxOrigin(){return this._wxOrigin}set wxOrigin(e){this._wxOrigin=e}get wx(){return this._wxData}set wx(e){this._wxData=e}constructor(e){super(e,{bubbles:!0,cancelable:!0,composed:!0})}}var b={cordova:!1};class v{_initialized=!1;_handlers=new WeakMap;_eventTypes;get eventTypes(){return this._eventTypes}constructor(e=b){if(this._initialized)return;this._initialized=!0,this._eventTypes={WX_ON_BACK:e.cordova?"backbutton":"back",WX_ON_RESUME:"resume",WX_ON_REFRESH:"refresh",WX_ON_PAUSE:"pause",WX_ON_KEYBOARD:"keyboard",WX_ON_INSETS:"insets"},window.addEventListener("message",(n)=>{try{if(typeof n.data!=="string")return;let t=JSON.parse(n.data);if(!t?.type)return;let r=this._eventTypes[t.type]??t.type;this._dispatch(window,r,t)}catch(t){console.error("[WXEvent] Message error:",t)}})}_dispatch(e,n,t){let r=new p(n);r.wx=t.data,r.wxOrigin="system",e.dispatchEvent(r)}on(e,n,t){if(!this._initialized)new v;let r=(s)=>{if(!(s instanceof p)){console.warn("[WXEvent] Event is not a WXEvent:",s);return}if(s.wxOrigin==="system"){if(typeof t==="function")t(s);else if(t&&typeof t.handleEvent==="function")t.handleEvent(s)}};if(!this._handlers.has(e))this._handlers.set(e,new Map);let i=this._handlers.get(e);if(!i.has(n))i.set(n,new Set);return i.get(n).add({handler:t,wrapper:r}),e.addEventListener(n,r),()=>this.off(e,n,t)}off(e,n,t){let r=this._handlers.get(e);if(!r?.has(n))return;for(let i of r.get(n))if(i.handler===t){e.removeEventListener(n,i.wrapper),r.get(n).delete(i);break}}}class c{_action;_interface=null;constructor(e){if(this._action=e,typeof window==="undefined"||!window.$intent||typeof window.$intent.create!=="function")console.warn("window['$intent'] or window['$intent'].create is not defined. Intent functionality may be limited.");else this._interface=window.$intent.create(this._action)}getParsedIntent(){return this._interface}setData(e){if(this._interface&&typeof this._interface.setData==="function")this._interface.setData(e);else console.error("setData method not available on the intent interface.")}setPackage(e){if(this._interface&&typeof this._interface.setPackage==="function")this._interface.setPackage(e);else console.error("setPackage method not available on the intent interface.")}addCategory(e){if(this._interface&&typeof this._interface.addCategory==="function")this._interface.addCategory(e);else console.error("addCategory method not available on the intent interface.")}setType(e){if(this._interface&&typeof this._interface.setType==="function")this._interface.setType(e);else console.error("setType method not available on the intent interface.")}putExtra(e,n){if(this._interface&&typeof this._interface.putExtra==="function")this._interface.putExtra(e,n);else console.error("putExtra method not available on the intent interface.")}getStringExtra(e){if(this._interface&&typeof this._interface.getStringExtra==="function")return this._interface.getStringExtra(e);else return console.error("getStringExtra method not available on the intent interface."),null}getIntExtra(e){if(this._interface&&typeof this._interface.getIntExtra==="function")return this._interface.getIntExtra(e);else return console.error("getIntExtra method not available on the intent interface."),0}getBooleanExtra(e){if(this._interface&&typeof this._interface.getBooleanExtra==="function")return this._interface.getBooleanExtra(e);else return console.error("getBooleanExtra method not available on the intent interface."),!1}}class W{_interface=null;constructor(){if(typeof window==="undefined"||!window.webui)console.warn("window['webui'] is not defined. WebUI functionality may be limited.");else this._interface=window.webui}exit(){if(this._interface&&typeof this._interface.exit==="function")this._interface.exit();else console.error("exit method not available on the webui interface.")}setRefreshing(e){if(this._interface&&typeof this._interface.setRefreshing==="function")this._interface.setRefreshing(e);else console.error("setRefreshing method not available on the webui interface.")}get currentRootManager(){if(this._interface&&typeof this._interface.getCurrentRootManager!=="undefined")return this._interface.getCurrentRootManager();else return console.error("currentRootManager getter not available on the webui interface."),null}get currentApplication(){if(this._interface&&typeof this._interface.getCurrentApplication!=="undefined")return this._interface.getCurrentApplication();else return console.error("currentApplication getter not available on the webui interface."),null}getApplication(e){if(this._interface&&typeof this._interface.getApplication==="function")return this._interface.getApplication(e);else return console.error("getApplication method not available on the webui interface."),null}openFile(e){if(this._interface&&typeof this._interface.openFile==="function")this._interface.openFile(e.getParsedIntent());else console.error("openFile method not available on the webui interface.")}startActivity(e){if(this._interface&&typeof this._interface.startActivity==="function")this._interface.startActivity(e.getParsedIntent());else console.error("startActivity method not available on the webui interface.")}}export{d as wrapToReadableStream,u as wrapOutputStream,y as wrapInputStream,W as WebUI,v as WXEventHandler,p as WXEvent,c as Intent};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "webuix",
3
- "version": "0.0.12",
3
+ "version": "0.0.14",
4
4
  "type": "module",
5
5
  "description": "A library to make your life easier when working with MMRL's WebUI",
6
6
  "source": "src/index.ts",
package/tsconfig.json CHANGED
@@ -13,6 +13,7 @@
13
13
  "allowImportingTsExtensions": true,
14
14
  "verbatimModuleSyntax": true,
15
15
  "noEmit": true,
16
+ "noImplicitAny": false,
16
17
 
17
18
  // Best practices
18
19
  "strict": true,