bleam 0.0.6 → 0.0.8
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/ai.cjs +3984 -25
- package/dist/ai.d.cts +503 -20
- package/dist/ai.d.ts +503 -20
- package/dist/ai.js +3946 -26
- package/dist/animated.cjs +1 -1
- package/dist/animated.js +1 -1
- package/dist/app.cjs +92 -0
- package/dist/app.js +92 -0
- package/dist/cli.cjs +653 -86
- package/dist/cli.d.cts +89 -1
- package/dist/cli.d.ts +89 -1
- package/dist/cli.js +654 -88
- package/dist/{config-ClDGHNb3.d.ts → config-Cms0rvqg.d.ts} +1 -0
- package/dist/{config-D3gPaVMb.d.cts → config-CufOVJV3.d.cts} +1 -0
- package/dist/config.d.cts +1 -1
- package/dist/config.d.ts +1 -1
- package/dist/crypto.d.cts +0 -2
- package/dist/crypto.d.ts +1 -1
- package/dist/dev-protocol.d.cts +14 -1
- package/dist/dev-protocol.d.ts +14 -1
- package/dist/files-Bo7h9fik.cjs +468 -0
- package/dist/files-Ds1wT8C2.js +445 -0
- package/dist/files-DwA7pzr3.d.cts +99 -0
- package/dist/files-VrkQlKIT.d.ts +99 -0
- package/dist/files.cjs +7 -0
- package/dist/files.d.cts +2 -0
- package/dist/files.d.ts +2 -0
- package/dist/files.js +4 -0
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/native-sqlite-xcGdamRD.js +64 -0
- package/dist/native-sqlite-yQLD5s9i.cjs +66 -0
- package/dist/platform.cjs +27 -0
- package/dist/platform.d.cts +39 -0
- package/dist/platform.d.ts +39 -0
- package/dist/platform.js +21 -0
- package/dist/runtime.d.cts +1 -6
- package/dist/runtime.d.ts +1 -6
- package/dist/{schema-ipsECAso.d.ts → schema-DOOjfXvs.d.ts} +1 -1
- package/dist/{schema-BOuUHcqo.d.cts → schema-ENSMX_1t.d.cts} +1 -1
- package/dist/schema.cjs +1 -1
- package/dist/schema.d.cts +1 -1
- package/dist/schema.d.ts +1 -1
- package/dist/schema.js +1 -1
- package/dist/state-Bx0VlTlO.cjs +852 -0
- package/dist/state-CAwe-Vw1.js +767 -0
- package/dist/state.cjs +17 -763
- package/dist/state.d.cts +107 -77
- package/dist/state.d.ts +107 -77
- package/dist/state.js +4 -745
- package/dist/ui-1WepaMS4.d.cts +92 -0
- package/dist/ui-Ce-pnUUA.d.ts +92 -0
- package/dist/ui.cjs +286 -35
- package/dist/ui.d.cts +2 -30
- package/dist/ui.d.ts +2 -30
- package/dist/ui.js +283 -36
- package/dist/window.cjs +596 -0
- package/dist/window.d.cts +63 -0
- package/dist/window.d.ts +63 -0
- package/dist/window.js +589 -0
- package/package.json +16 -14
- package/templates/basic/app/index.tsx +8 -5
- package/templates/foundation-models/app/index.tsx +32 -0
- package/templates/foundation-models/app.config.ts +5 -0
- package/templates/image-generation/app/index.tsx +39 -0
- package/templates/image-generation/app.config.ts +5 -0
- package/templates/state/app/index.tsx +30 -0
- package/templates/state/app.config.ts +5 -0
- package/dist/chrome.cjs +0 -265
- package/dist/chrome.d.cts +0 -19
- package/dist/chrome.d.ts +0 -19
- package/dist/chrome.js +0 -262
- package/dist/fs.cjs +0 -13
- package/dist/fs.d.cts +0 -8
- package/dist/fs.d.ts +0 -8
- package/dist/fs.js +0 -12
- package/dist/native-macos-D6p2SmUj.js +0 -20
- package/dist/native-macos-DLwo_ii9.cjs +0 -31
- package/dist/native-runtime-CbPzrs8j.d.cts +0 -33
- package/dist/native-runtime-DxHSrsTX.d.ts +0 -33
- package/dist/native.cjs +0 -135
- package/dist/native.d.cts +0 -34
- package/dist/native.d.ts +0 -34
- package/dist/native.js +0 -135
- /package/dist/{schema-DVmoD9JL.js → schema-Bo5Jvqus.js} +0 -0
- /package/dist/{schema-bxeeCyLn.cjs → schema-rQ13mrpD.cjs} +0 -0
|
@@ -0,0 +1,445 @@
|
|
|
1
|
+
import { t as ensureNativeScript } from "./native-runtime-C85Nuc4F.js";
|
|
2
|
+
|
|
3
|
+
//#region src/native-files.ts
|
|
4
|
+
const downloads = /* @__PURE__ */ new Map();
|
|
5
|
+
let session;
|
|
6
|
+
let sessionDelegate;
|
|
7
|
+
let downloadRetainer;
|
|
8
|
+
function settlePicker(callback) {
|
|
9
|
+
setTimeout(callback, 0);
|
|
10
|
+
}
|
|
11
|
+
function retainer() {
|
|
12
|
+
downloadRetainer ??= ensureNativeScript().createRetainer();
|
|
13
|
+
return downloadRetainer;
|
|
14
|
+
}
|
|
15
|
+
function fileUri$1(path) {
|
|
16
|
+
return path.startsWith("file://") ? path : `file://${path}`;
|
|
17
|
+
}
|
|
18
|
+
function nsString(value) {
|
|
19
|
+
return NSString.stringWithString(value);
|
|
20
|
+
}
|
|
21
|
+
function fileManager() {
|
|
22
|
+
ensureNativeScript();
|
|
23
|
+
return NSFileManager.defaultManager;
|
|
24
|
+
}
|
|
25
|
+
function ensureDirectory(path) {
|
|
26
|
+
fileManager().createDirectoryAtPathWithIntermediateDirectoriesAttributesError(path, true, null, null);
|
|
27
|
+
}
|
|
28
|
+
function parentDirectory(path) {
|
|
29
|
+
return nsString(path).stringByDeletingLastPathComponent;
|
|
30
|
+
}
|
|
31
|
+
function appGroupIdentifier() {
|
|
32
|
+
return String(NSBundle.mainBundle.objectForInfoDictionaryKey("AppGroupIdentifier") ?? "group.dev.bleam.app");
|
|
33
|
+
}
|
|
34
|
+
function containerPath() {
|
|
35
|
+
const url = fileManager().containerURLForSecurityApplicationGroupIdentifier(appGroupIdentifier());
|
|
36
|
+
if (!url?.path) throw new Error("Shared container is unavailable");
|
|
37
|
+
return String(url.path);
|
|
38
|
+
}
|
|
39
|
+
function searchPath(directory) {
|
|
40
|
+
const value = NSSearchPathForDirectoriesInDomains(directory, NSSearchPathDomainMask.UserDomain, true)?.objectAtIndex(0);
|
|
41
|
+
if (typeof value !== "string") throw new Error("Native directory unavailable");
|
|
42
|
+
return value;
|
|
43
|
+
}
|
|
44
|
+
function nativeDirectories() {
|
|
45
|
+
const shared = containerPath();
|
|
46
|
+
return {
|
|
47
|
+
cache: searchPath(NSSearchPathDirectory.Caches),
|
|
48
|
+
documents: searchPath(NSSearchPathDirectory.Document),
|
|
49
|
+
models: nsString(shared).stringByAppendingPathComponent("Models"),
|
|
50
|
+
shared,
|
|
51
|
+
temporary: NSTemporaryDirectory()
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
function nativeStat(path) {
|
|
55
|
+
if (!fileManager().fileExistsAtPath(path)) return {
|
|
56
|
+
exists: false,
|
|
57
|
+
type: "missing",
|
|
58
|
+
path,
|
|
59
|
+
uri: fileUri$1(path)
|
|
60
|
+
};
|
|
61
|
+
const attributes = fileManager().attributesOfItemAtPathError(path, null);
|
|
62
|
+
const size = Number(attributes?.objectForKey(NSFileSize) ?? void 0);
|
|
63
|
+
const createdAt = attributes?.objectForKey(NSFileCreationDate);
|
|
64
|
+
const modifiedAt = attributes?.objectForKey(NSFileModificationDate);
|
|
65
|
+
return {
|
|
66
|
+
exists: true,
|
|
67
|
+
type: attributes?.objectForKey(NSFileType) === NSFileTypeDirectory ? "directory" : "file",
|
|
68
|
+
path,
|
|
69
|
+
uri: fileUri$1(path),
|
|
70
|
+
size: Number.isFinite(size) ? size : void 0,
|
|
71
|
+
createdAt: createdAt ? createdAt.timeIntervalSince1970 * 1e3 : void 0,
|
|
72
|
+
modifiedAt: modifiedAt ? modifiedAt.timeIntervalSince1970 * 1e3 : void 0
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
async function nativeMkdir(path, recursive) {
|
|
76
|
+
fileManager().createDirectoryAtPathWithIntermediateDirectoriesAttributesError(path, recursive, null, null);
|
|
77
|
+
}
|
|
78
|
+
async function nativeRemove(path, recursive) {
|
|
79
|
+
const stat = nativeStat(path);
|
|
80
|
+
if (!stat.exists) return;
|
|
81
|
+
if (stat.type === "directory" && !recursive) {
|
|
82
|
+
const items = fileManager().contentsOfDirectoryAtPathError(path, null);
|
|
83
|
+
if (Number(items?.count ?? 0) > 0) throw new Error(`Directory is not empty: ${path}`);
|
|
84
|
+
}
|
|
85
|
+
fileManager().removeItemAtPathError(path, null);
|
|
86
|
+
}
|
|
87
|
+
async function nativeReadText(path) {
|
|
88
|
+
return String(NSString.stringWithContentsOfFileEncodingError(path, NSUTF8StringEncoding, null));
|
|
89
|
+
}
|
|
90
|
+
async function nativeWriteText(path, contents, atomic) {
|
|
91
|
+
ensureDirectory(parentDirectory(path));
|
|
92
|
+
if (!nsString(contents).writeToFileAtomicallyEncodingError(path, atomic, NSUTF8StringEncoding, null)) throw new Error(`Failed to write file: ${path}`);
|
|
93
|
+
}
|
|
94
|
+
function taskId(task) {
|
|
95
|
+
return Number(task.taskIdentifier);
|
|
96
|
+
}
|
|
97
|
+
function downloadSession() {
|
|
98
|
+
if (session) return session;
|
|
99
|
+
sessionDelegate = ensureNativeScript().createDelegate("NSURLSessionDataDelegate", {
|
|
100
|
+
URLSessionDataTaskDidReceiveResponseCompletionHandler(_session, task, response, completion) {
|
|
101
|
+
const state = downloads.get(taskId(task));
|
|
102
|
+
if (!state) {
|
|
103
|
+
completion(NSURLSessionResponseDisposition.Cancel);
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
const http = response;
|
|
107
|
+
if (http.statusCode && (http.statusCode < 200 || http.statusCode >= 300)) {
|
|
108
|
+
completion(NSURLSessionResponseDisposition.Cancel);
|
|
109
|
+
state.output.close();
|
|
110
|
+
retainer().release(state.output);
|
|
111
|
+
state.reject(/* @__PURE__ */ new Error(`Download failed: HTTP ${http.statusCode}`));
|
|
112
|
+
downloads.delete(taskId(task));
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
state.output.open();
|
|
116
|
+
completion(NSURLSessionResponseDisposition.Allow);
|
|
117
|
+
},
|
|
118
|
+
URLSessionDataTaskDidReceiveData(_session, task, data) {
|
|
119
|
+
const state = downloads.get(taskId(task));
|
|
120
|
+
if (!state) return;
|
|
121
|
+
const bytes = data.bytes;
|
|
122
|
+
const written = state.output.writeMaxLength(bytes, data.length);
|
|
123
|
+
if (written < 0) {
|
|
124
|
+
task.cancel();
|
|
125
|
+
state.output.close();
|
|
126
|
+
retainer().release(state.output);
|
|
127
|
+
state.reject(/* @__PURE__ */ new Error(`Failed to write download: ${state.path}`));
|
|
128
|
+
downloads.delete(taskId(task));
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
state.writtenBytes += written;
|
|
132
|
+
state.onProgress?.({
|
|
133
|
+
id: state.id,
|
|
134
|
+
path: state.path,
|
|
135
|
+
bytesWritten: state.writtenBytes,
|
|
136
|
+
totalBytes: state.expectedBytes
|
|
137
|
+
});
|
|
138
|
+
},
|
|
139
|
+
URLSessionTaskDidCompleteWithError(_session, task, error) {
|
|
140
|
+
const state = downloads.get(taskId(task));
|
|
141
|
+
if (!state) return;
|
|
142
|
+
downloads.delete(taskId(task));
|
|
143
|
+
state.output.close();
|
|
144
|
+
retainer().release(state.output);
|
|
145
|
+
if (error) {
|
|
146
|
+
state.reject(error);
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
if (state.expectedBytes !== void 0 && state.writtenBytes !== state.expectedBytes) {
|
|
150
|
+
state.reject(/* @__PURE__ */ new Error(`Downloaded ${state.writtenBytes} bytes, expected ${state.expectedBytes}`));
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
if (!state.temporaryPath || state.temporaryPath === state.path) {
|
|
154
|
+
state.resolve(nativeStat(state.path));
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
fileManager().removeItemAtPathError(state.path, null);
|
|
158
|
+
if (!fileManager().moveItemAtPathToPathError(state.temporaryPath, state.path, null)) {
|
|
159
|
+
state.reject(/* @__PURE__ */ new Error(`Failed to move download into place: ${state.path}`));
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
state.resolve(nativeStat(state.path));
|
|
163
|
+
}
|
|
164
|
+
}, { retainer: retainer() });
|
|
165
|
+
const configuration = NSURLSessionConfiguration.defaultSessionConfiguration;
|
|
166
|
+
session = NSURLSession.sessionWithConfigurationDelegateDelegateQueue(configuration, sessionDelegate, null);
|
|
167
|
+
return session;
|
|
168
|
+
}
|
|
169
|
+
function nativeCancelDownload(id) {
|
|
170
|
+
for (const state of downloads.values()) if (state.id === id) state.task?.cancel();
|
|
171
|
+
}
|
|
172
|
+
async function nativeDownload(request) {
|
|
173
|
+
ensureDirectory(parentDirectory(request.destination));
|
|
174
|
+
const url = NSURL.URLWithString(request.url);
|
|
175
|
+
if (!url) throw new Error(`Invalid download URL: ${request.url}`);
|
|
176
|
+
const temporaryPath = request.atomic ? `${request.destination}.download-${request.id}` : request.destination;
|
|
177
|
+
fileManager().removeItemAtPathError(temporaryPath, null);
|
|
178
|
+
const output = NSOutputStream.outputStreamToFileAtPathAppend(temporaryPath, false);
|
|
179
|
+
if (!output) throw new Error(`Failed to create output stream: ${temporaryPath}`);
|
|
180
|
+
retainer().retain(output);
|
|
181
|
+
const nativeRequest = NSMutableURLRequest.requestWithURL(url);
|
|
182
|
+
for (const [key, value] of Object.entries(request.headers ?? {})) nativeRequest.setValueForHTTPHeaderField(value, key);
|
|
183
|
+
return new Promise((resolve, reject) => {
|
|
184
|
+
const task = downloadSession().dataTaskWithRequest(nativeRequest);
|
|
185
|
+
const state = {
|
|
186
|
+
id: request.id,
|
|
187
|
+
path: request.destination,
|
|
188
|
+
temporaryPath,
|
|
189
|
+
expectedBytes: request.expectedBytes,
|
|
190
|
+
writtenBytes: 0,
|
|
191
|
+
output,
|
|
192
|
+
task,
|
|
193
|
+
resolve,
|
|
194
|
+
reject,
|
|
195
|
+
onProgress: request.onProgress
|
|
196
|
+
};
|
|
197
|
+
downloads.set(taskId(task), state);
|
|
198
|
+
task.resume();
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
function topVisibleViewController(root = UIApplication.sharedApplication.keyWindow?.rootViewController) {
|
|
202
|
+
let current = root ?? null;
|
|
203
|
+
while (current?.presentedViewController) current = current.presentedViewController;
|
|
204
|
+
const selected = current?.selectedViewController;
|
|
205
|
+
if (selected) return topVisibleViewController(selected);
|
|
206
|
+
const visible = current?.visibleViewController;
|
|
207
|
+
if (visible) return topVisibleViewController(visible);
|
|
208
|
+
return current;
|
|
209
|
+
}
|
|
210
|
+
function copyPickedFile(url, destination) {
|
|
211
|
+
ensureDirectory(destination);
|
|
212
|
+
const name = String(url.lastPathComponent ?? `picked-${Date.now()}`);
|
|
213
|
+
const target = nsString(destination).stringByAppendingPathComponent(name);
|
|
214
|
+
fileManager().removeItemAtPathError(target, null);
|
|
215
|
+
if (!fileManager().copyItemAtURLToURLError(url, NSURL.fileURLWithPath(target), null)) throw new Error(`Failed to copy picked file: ${name}`);
|
|
216
|
+
return nativeStat(target);
|
|
217
|
+
}
|
|
218
|
+
async function nativePick(request) {
|
|
219
|
+
return new Promise((resolve, reject) => {
|
|
220
|
+
ensureNativeScript().runOnUI(() => {
|
|
221
|
+
const pickerTypes = request.type === "image" ? ["public.image"] : ["public.item"];
|
|
222
|
+
const picker = UIDocumentPickerViewController.alloc().initWithDocumentTypesInMode(pickerTypes, UIDocumentPickerMode.Import);
|
|
223
|
+
picker.allowsMultipleSelection = request.multiple;
|
|
224
|
+
ensureNativeScript().createDelegate("UIDocumentPickerDelegate", {
|
|
225
|
+
documentPickerDidPickDocumentsAtURLs(controller, urls) {
|
|
226
|
+
try {
|
|
227
|
+
const values = [];
|
|
228
|
+
const count = Number(urls.count ?? 0);
|
|
229
|
+
for (let index = 0; index < count; index += 1) values.push(copyPickedFile(urls.objectAtIndex(index), request.destination));
|
|
230
|
+
controller.dismissViewControllerAnimatedCompletion(true, () => null);
|
|
231
|
+
settlePicker(() => resolve(values));
|
|
232
|
+
} catch (error) {
|
|
233
|
+
settlePicker(() => reject(error));
|
|
234
|
+
}
|
|
235
|
+
},
|
|
236
|
+
documentPickerWasCancelled(controller) {
|
|
237
|
+
controller.dismissViewControllerAnimatedCompletion(true, () => null);
|
|
238
|
+
settlePicker(() => resolve([]));
|
|
239
|
+
}
|
|
240
|
+
}, { assignTo: {
|
|
241
|
+
object: picker,
|
|
242
|
+
property: "delegate"
|
|
243
|
+
} });
|
|
244
|
+
const presenter = topVisibleViewController();
|
|
245
|
+
if (!presenter) {
|
|
246
|
+
settlePicker(() => reject(/* @__PURE__ */ new Error("No view controller available for file picker")));
|
|
247
|
+
return;
|
|
248
|
+
}
|
|
249
|
+
presenter.presentViewControllerAnimatedCompletion(picker, true, () => null);
|
|
250
|
+
});
|
|
251
|
+
});
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
//#endregion
|
|
255
|
+
//#region src/files.ts
|
|
256
|
+
const paths = {
|
|
257
|
+
get cache() {
|
|
258
|
+
return nativeDirectories().cache;
|
|
259
|
+
},
|
|
260
|
+
get documents() {
|
|
261
|
+
return nativeDirectories().documents;
|
|
262
|
+
},
|
|
263
|
+
get models() {
|
|
264
|
+
return nativeDirectories().models;
|
|
265
|
+
},
|
|
266
|
+
get shared() {
|
|
267
|
+
return nativeDirectories().shared;
|
|
268
|
+
},
|
|
269
|
+
get temporary() {
|
|
270
|
+
return nativeDirectories().temporary;
|
|
271
|
+
}
|
|
272
|
+
};
|
|
273
|
+
let directoryPromise;
|
|
274
|
+
async function directories() {
|
|
275
|
+
directoryPromise ??= Promise.resolve(nativeDirectories());
|
|
276
|
+
return directoryPromise;
|
|
277
|
+
}
|
|
278
|
+
function joinPath(...parts) {
|
|
279
|
+
const [first, ...rest] = parts.map((part) => typeof part === "string" ? part : part.path);
|
|
280
|
+
if (!first) throw new Error("Expected path");
|
|
281
|
+
return rest.reduce((path, part) => {
|
|
282
|
+
const next = part.replace(/^\/+/, "");
|
|
283
|
+
if (!next) return path;
|
|
284
|
+
return `${path.replace(/\/+$/, "")}/${next}`;
|
|
285
|
+
}, first);
|
|
286
|
+
}
|
|
287
|
+
function fileUri(path) {
|
|
288
|
+
return path.startsWith("file://") ? path : `file://${path}`;
|
|
289
|
+
}
|
|
290
|
+
function downloadId() {
|
|
291
|
+
return `download-${Date.now()}-${Math.random().toString(36).slice(2)}`;
|
|
292
|
+
}
|
|
293
|
+
function statFromNative(value) {
|
|
294
|
+
if (!value || typeof value !== "object") throw new Error("Invalid native file stat");
|
|
295
|
+
const record = value;
|
|
296
|
+
const path = stringValue(record.path, "path");
|
|
297
|
+
const type = stringValue(record.type, "type");
|
|
298
|
+
if (type !== "file" && type !== "directory" && type !== "missing") throw new Error(`Invalid native file type: ${type}`);
|
|
299
|
+
return {
|
|
300
|
+
exists: Boolean(record.exists),
|
|
301
|
+
type,
|
|
302
|
+
path,
|
|
303
|
+
uri: stringValue(record.uri, "uri"),
|
|
304
|
+
size: optionalNumber(record.size),
|
|
305
|
+
createdAt: optionalNumber(record.createdAt),
|
|
306
|
+
modifiedAt: optionalNumber(record.modifiedAt)
|
|
307
|
+
};
|
|
308
|
+
}
|
|
309
|
+
function stringValue(value, name) {
|
|
310
|
+
if (typeof value !== "string") throw new Error(`Expected ${name}`);
|
|
311
|
+
return value;
|
|
312
|
+
}
|
|
313
|
+
function optionalNumber(value) {
|
|
314
|
+
return typeof value === "number" && Number.isFinite(value) ? value : void 0;
|
|
315
|
+
}
|
|
316
|
+
function progressFromNative(value) {
|
|
317
|
+
const totalBytes = optionalNumber(value.totalBytes);
|
|
318
|
+
return {
|
|
319
|
+
id: value.id,
|
|
320
|
+
path: value.path,
|
|
321
|
+
bytesWritten: value.bytesWritten,
|
|
322
|
+
totalBytes,
|
|
323
|
+
fraction: totalBytes && totalBytes > 0 ? value.bytesWritten / totalBytes : void 0
|
|
324
|
+
};
|
|
325
|
+
}
|
|
326
|
+
function pickDestinationPath(destination) {
|
|
327
|
+
return typeof destination === "string" ? destination : destination.path;
|
|
328
|
+
}
|
|
329
|
+
function pickedFilesFromNative(value) {
|
|
330
|
+
if (!Array.isArray(value)) throw new Error("Invalid native pick result");
|
|
331
|
+
return value.map((item) => {
|
|
332
|
+
return new FileRef(statFromNative(item).path);
|
|
333
|
+
});
|
|
334
|
+
}
|
|
335
|
+
var FileRef = class {
|
|
336
|
+
uri;
|
|
337
|
+
constructor(path) {
|
|
338
|
+
this.path = path;
|
|
339
|
+
this.uri = fileUri(path);
|
|
340
|
+
}
|
|
341
|
+
async exists() {
|
|
342
|
+
return (await this.stat()).type === "file";
|
|
343
|
+
}
|
|
344
|
+
async stat() {
|
|
345
|
+
return statFromNative(nativeStat(this.path));
|
|
346
|
+
}
|
|
347
|
+
async text() {
|
|
348
|
+
const value = await nativeReadText(this.path);
|
|
349
|
+
if (typeof value !== "string") throw new Error("Expected native file text");
|
|
350
|
+
return value;
|
|
351
|
+
}
|
|
352
|
+
async json() {
|
|
353
|
+
return JSON.parse(await this.text());
|
|
354
|
+
}
|
|
355
|
+
async write(contents, options = {}) {
|
|
356
|
+
await nativeWriteText(this.path, contents, options.atomic ?? true);
|
|
357
|
+
}
|
|
358
|
+
async delete() {
|
|
359
|
+
await nativeRemove(this.path, false);
|
|
360
|
+
}
|
|
361
|
+
download(url, options = {}) {
|
|
362
|
+
return new DownloadTask(url, this.path, options);
|
|
363
|
+
}
|
|
364
|
+
};
|
|
365
|
+
var DirectoryRef = class DirectoryRef {
|
|
366
|
+
uri;
|
|
367
|
+
constructor(path) {
|
|
368
|
+
this.path = path;
|
|
369
|
+
this.uri = fileUri(path);
|
|
370
|
+
}
|
|
371
|
+
file(...parts) {
|
|
372
|
+
return new FileRef(joinPath(this.path, ...parts));
|
|
373
|
+
}
|
|
374
|
+
directory(...parts) {
|
|
375
|
+
return new DirectoryRef(joinPath(this.path, ...parts));
|
|
376
|
+
}
|
|
377
|
+
async exists() {
|
|
378
|
+
return (await this.stat()).type === "directory";
|
|
379
|
+
}
|
|
380
|
+
async stat() {
|
|
381
|
+
return statFromNative(nativeStat(this.path));
|
|
382
|
+
}
|
|
383
|
+
async create(options = {}) {
|
|
384
|
+
await nativeMkdir(this.path, options.recursive ?? true);
|
|
385
|
+
}
|
|
386
|
+
async delete(options = {}) {
|
|
387
|
+
await nativeRemove(this.path, options.recursive ?? true);
|
|
388
|
+
}
|
|
389
|
+
};
|
|
390
|
+
var DownloadTask = class {
|
|
391
|
+
id;
|
|
392
|
+
result;
|
|
393
|
+
onAbort = () => {
|
|
394
|
+
this.cancel();
|
|
395
|
+
};
|
|
396
|
+
constructor(url, destination, options = {}) {
|
|
397
|
+
this.url = url;
|
|
398
|
+
this.destination = destination;
|
|
399
|
+
this.options = options;
|
|
400
|
+
this.id = options.id ?? downloadId();
|
|
401
|
+
options.signal?.addEventListener("abort", this.onAbort, { once: true });
|
|
402
|
+
this.result = this.start().finally(() => {
|
|
403
|
+
options.signal?.removeEventListener("abort", this.onAbort);
|
|
404
|
+
});
|
|
405
|
+
}
|
|
406
|
+
async cancel() {
|
|
407
|
+
nativeCancelDownload(this.id);
|
|
408
|
+
}
|
|
409
|
+
async start() {
|
|
410
|
+
return new FileRef(statFromNative(await nativeDownload({
|
|
411
|
+
id: this.id,
|
|
412
|
+
url: this.url,
|
|
413
|
+
destination: this.destination,
|
|
414
|
+
headers: this.options.headers,
|
|
415
|
+
expectedBytes: this.options.expectedBytes,
|
|
416
|
+
atomic: this.options.atomic ?? true,
|
|
417
|
+
resume: this.options.resume ?? true,
|
|
418
|
+
onProgress: (event) => {
|
|
419
|
+
if (event.id === this.id) this.options.onProgress?.(progressFromNative(event));
|
|
420
|
+
}
|
|
421
|
+
})).path);
|
|
422
|
+
}
|
|
423
|
+
};
|
|
424
|
+
const files = {
|
|
425
|
+
paths,
|
|
426
|
+
async directories() {
|
|
427
|
+
return directories();
|
|
428
|
+
},
|
|
429
|
+
async pick(options) {
|
|
430
|
+
return pickedFilesFromNative(await nativePick({
|
|
431
|
+
type: options.type ?? "any",
|
|
432
|
+
multiple: options.multiple ?? false,
|
|
433
|
+
destination: pickDestinationPath(options.destination)
|
|
434
|
+
}));
|
|
435
|
+
},
|
|
436
|
+
file(...parts) {
|
|
437
|
+
return new FileRef(joinPath(...parts));
|
|
438
|
+
},
|
|
439
|
+
directory(...parts) {
|
|
440
|
+
return new DirectoryRef(joinPath(...parts));
|
|
441
|
+
}
|
|
442
|
+
};
|
|
443
|
+
|
|
444
|
+
//#endregion
|
|
445
|
+
export { files as i, DownloadTask as n, FileRef as r, DirectoryRef as t };
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
//#region src/files.d.ts
|
|
2
|
+
type NativeDirectories = {
|
|
3
|
+
cache: string;
|
|
4
|
+
documents: string;
|
|
5
|
+
models: string;
|
|
6
|
+
shared: string;
|
|
7
|
+
temporary: string;
|
|
8
|
+
};
|
|
9
|
+
type FileType = 'file' | 'directory' | 'missing';
|
|
10
|
+
type FileStat = {
|
|
11
|
+
exists: boolean;
|
|
12
|
+
type: FileType;
|
|
13
|
+
path: string;
|
|
14
|
+
uri: string;
|
|
15
|
+
size?: number;
|
|
16
|
+
createdAt?: number;
|
|
17
|
+
modifiedAt?: number;
|
|
18
|
+
};
|
|
19
|
+
type DownloadProgress = {
|
|
20
|
+
id: string;
|
|
21
|
+
path: string;
|
|
22
|
+
bytesWritten: number;
|
|
23
|
+
totalBytes?: number;
|
|
24
|
+
fraction?: number;
|
|
25
|
+
};
|
|
26
|
+
type DownloadOptions = {
|
|
27
|
+
id?: string;
|
|
28
|
+
headers?: Record<string, string>;
|
|
29
|
+
expectedBytes?: number;
|
|
30
|
+
atomic?: boolean;
|
|
31
|
+
resume?: boolean;
|
|
32
|
+
signal?: AbortSignal;
|
|
33
|
+
onProgress?: (progress: DownloadProgress) => void;
|
|
34
|
+
};
|
|
35
|
+
type PickFileType = 'any' | 'image';
|
|
36
|
+
type PickOptions = {
|
|
37
|
+
type?: PickFileType;
|
|
38
|
+
multiple?: boolean;
|
|
39
|
+
destination: string | DirectoryRef;
|
|
40
|
+
};
|
|
41
|
+
type CreateDirectoryOptions = {
|
|
42
|
+
recursive?: boolean;
|
|
43
|
+
};
|
|
44
|
+
type RemoveOptions = {
|
|
45
|
+
recursive?: boolean;
|
|
46
|
+
};
|
|
47
|
+
type WriteOptions = {
|
|
48
|
+
atomic?: boolean;
|
|
49
|
+
};
|
|
50
|
+
type FilePaths = {
|
|
51
|
+
readonly cache: string;
|
|
52
|
+
readonly documents: string;
|
|
53
|
+
readonly models: string;
|
|
54
|
+
readonly shared: string;
|
|
55
|
+
readonly temporary: string;
|
|
56
|
+
};
|
|
57
|
+
declare class FileRef {
|
|
58
|
+
readonly path: string;
|
|
59
|
+
readonly uri: string;
|
|
60
|
+
constructor(path: string);
|
|
61
|
+
exists(): Promise<boolean>;
|
|
62
|
+
stat(): Promise<FileStat>;
|
|
63
|
+
text(): Promise<string>;
|
|
64
|
+
json<T = unknown>(): Promise<T>;
|
|
65
|
+
write(contents: string, options?: WriteOptions): Promise<void>;
|
|
66
|
+
delete(): Promise<void>;
|
|
67
|
+
download(url: string, options?: DownloadOptions): DownloadTask;
|
|
68
|
+
}
|
|
69
|
+
declare class DirectoryRef {
|
|
70
|
+
readonly path: string;
|
|
71
|
+
readonly uri: string;
|
|
72
|
+
constructor(path: string);
|
|
73
|
+
file(...parts: string[]): FileRef;
|
|
74
|
+
directory(...parts: string[]): DirectoryRef;
|
|
75
|
+
exists(): Promise<boolean>;
|
|
76
|
+
stat(): Promise<FileStat>;
|
|
77
|
+
create(options?: CreateDirectoryOptions): Promise<void>;
|
|
78
|
+
delete(options?: RemoveOptions): Promise<void>;
|
|
79
|
+
}
|
|
80
|
+
declare class DownloadTask {
|
|
81
|
+
readonly url: string;
|
|
82
|
+
readonly destination: string;
|
|
83
|
+
readonly options: DownloadOptions;
|
|
84
|
+
readonly id: string;
|
|
85
|
+
readonly result: Promise<FileRef>;
|
|
86
|
+
private readonly onAbort;
|
|
87
|
+
constructor(url: string, destination: string, options?: DownloadOptions);
|
|
88
|
+
cancel(): Promise<void>;
|
|
89
|
+
private start;
|
|
90
|
+
}
|
|
91
|
+
declare const files: {
|
|
92
|
+
paths: FilePaths;
|
|
93
|
+
directories(): Promise<NativeDirectories>;
|
|
94
|
+
pick(options: PickOptions): Promise<FileRef[]>;
|
|
95
|
+
file(...parts: Array<string | DirectoryRef>): FileRef;
|
|
96
|
+
directory(...parts: Array<string | DirectoryRef>): DirectoryRef;
|
|
97
|
+
};
|
|
98
|
+
//#endregion
|
|
99
|
+
export { DownloadTask as a, FileStat as c, PickOptions as d, RemoveOptions as f, DownloadProgress as i, FileType as l, files as m, DirectoryRef as n, FilePaths as o, WriteOptions as p, DownloadOptions as r, FileRef as s, CreateDirectoryOptions as t, PickFileType as u };
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
//#region src/files.d.ts
|
|
2
|
+
type NativeDirectories = {
|
|
3
|
+
cache: string;
|
|
4
|
+
documents: string;
|
|
5
|
+
models: string;
|
|
6
|
+
shared: string;
|
|
7
|
+
temporary: string;
|
|
8
|
+
};
|
|
9
|
+
type FileType = 'file' | 'directory' | 'missing';
|
|
10
|
+
type FileStat = {
|
|
11
|
+
exists: boolean;
|
|
12
|
+
type: FileType;
|
|
13
|
+
path: string;
|
|
14
|
+
uri: string;
|
|
15
|
+
size?: number;
|
|
16
|
+
createdAt?: number;
|
|
17
|
+
modifiedAt?: number;
|
|
18
|
+
};
|
|
19
|
+
type DownloadProgress = {
|
|
20
|
+
id: string;
|
|
21
|
+
path: string;
|
|
22
|
+
bytesWritten: number;
|
|
23
|
+
totalBytes?: number;
|
|
24
|
+
fraction?: number;
|
|
25
|
+
};
|
|
26
|
+
type DownloadOptions = {
|
|
27
|
+
id?: string;
|
|
28
|
+
headers?: Record<string, string>;
|
|
29
|
+
expectedBytes?: number;
|
|
30
|
+
atomic?: boolean;
|
|
31
|
+
resume?: boolean;
|
|
32
|
+
signal?: AbortSignal;
|
|
33
|
+
onProgress?: (progress: DownloadProgress) => void;
|
|
34
|
+
};
|
|
35
|
+
type PickFileType = 'any' | 'image';
|
|
36
|
+
type PickOptions = {
|
|
37
|
+
type?: PickFileType;
|
|
38
|
+
multiple?: boolean;
|
|
39
|
+
destination: string | DirectoryRef;
|
|
40
|
+
};
|
|
41
|
+
type CreateDirectoryOptions = {
|
|
42
|
+
recursive?: boolean;
|
|
43
|
+
};
|
|
44
|
+
type RemoveOptions = {
|
|
45
|
+
recursive?: boolean;
|
|
46
|
+
};
|
|
47
|
+
type WriteOptions = {
|
|
48
|
+
atomic?: boolean;
|
|
49
|
+
};
|
|
50
|
+
type FilePaths = {
|
|
51
|
+
readonly cache: string;
|
|
52
|
+
readonly documents: string;
|
|
53
|
+
readonly models: string;
|
|
54
|
+
readonly shared: string;
|
|
55
|
+
readonly temporary: string;
|
|
56
|
+
};
|
|
57
|
+
declare class FileRef {
|
|
58
|
+
readonly path: string;
|
|
59
|
+
readonly uri: string;
|
|
60
|
+
constructor(path: string);
|
|
61
|
+
exists(): Promise<boolean>;
|
|
62
|
+
stat(): Promise<FileStat>;
|
|
63
|
+
text(): Promise<string>;
|
|
64
|
+
json<T = unknown>(): Promise<T>;
|
|
65
|
+
write(contents: string, options?: WriteOptions): Promise<void>;
|
|
66
|
+
delete(): Promise<void>;
|
|
67
|
+
download(url: string, options?: DownloadOptions): DownloadTask;
|
|
68
|
+
}
|
|
69
|
+
declare class DirectoryRef {
|
|
70
|
+
readonly path: string;
|
|
71
|
+
readonly uri: string;
|
|
72
|
+
constructor(path: string);
|
|
73
|
+
file(...parts: string[]): FileRef;
|
|
74
|
+
directory(...parts: string[]): DirectoryRef;
|
|
75
|
+
exists(): Promise<boolean>;
|
|
76
|
+
stat(): Promise<FileStat>;
|
|
77
|
+
create(options?: CreateDirectoryOptions): Promise<void>;
|
|
78
|
+
delete(options?: RemoveOptions): Promise<void>;
|
|
79
|
+
}
|
|
80
|
+
declare class DownloadTask {
|
|
81
|
+
readonly url: string;
|
|
82
|
+
readonly destination: string;
|
|
83
|
+
readonly options: DownloadOptions;
|
|
84
|
+
readonly id: string;
|
|
85
|
+
readonly result: Promise<FileRef>;
|
|
86
|
+
private readonly onAbort;
|
|
87
|
+
constructor(url: string, destination: string, options?: DownloadOptions);
|
|
88
|
+
cancel(): Promise<void>;
|
|
89
|
+
private start;
|
|
90
|
+
}
|
|
91
|
+
declare const files: {
|
|
92
|
+
paths: FilePaths;
|
|
93
|
+
directories(): Promise<NativeDirectories>;
|
|
94
|
+
pick(options: PickOptions): Promise<FileRef[]>;
|
|
95
|
+
file(...parts: Array<string | DirectoryRef>): FileRef;
|
|
96
|
+
directory(...parts: Array<string | DirectoryRef>): DirectoryRef;
|
|
97
|
+
};
|
|
98
|
+
//#endregion
|
|
99
|
+
export { DownloadTask as a, FileStat as c, PickOptions as d, RemoveOptions as f, DownloadProgress as i, FileType as l, files as m, DirectoryRef as n, FilePaths as o, WriteOptions as p, DownloadOptions as r, FileRef as s, CreateDirectoryOptions as t, PickFileType as u };
|
package/dist/files.cjs
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
require('./native-runtime-CsXnXkQn.cjs');
|
|
2
|
+
const require_files = require('./files-Bo7h9fik.cjs');
|
|
3
|
+
|
|
4
|
+
exports.DirectoryRef = require_files.DirectoryRef;
|
|
5
|
+
exports.DownloadTask = require_files.DownloadTask;
|
|
6
|
+
exports.FileRef = require_files.FileRef;
|
|
7
|
+
exports.files = require_files.files;
|
package/dist/files.d.cts
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { a as DownloadTask, c as FileStat, d as PickOptions, f as RemoveOptions, i as DownloadProgress, l as FileType, m as files, n as DirectoryRef, o as FilePaths, p as WriteOptions, r as DownloadOptions, s as FileRef, t as CreateDirectoryOptions, u as PickFileType } from "./files-DwA7pzr3.cjs";
|
|
2
|
+
export { CreateDirectoryOptions, DirectoryRef, DownloadOptions, DownloadProgress, DownloadTask, FilePaths, FileRef, FileStat, FileType, PickFileType, PickOptions, RemoveOptions, WriteOptions, files };
|
package/dist/files.d.ts
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { a as DownloadTask, c as FileStat, d as PickOptions, f as RemoveOptions, i as DownloadProgress, l as FileType, m as files, n as DirectoryRef, o as FilePaths, p as WriteOptions, r as DownloadOptions, s as FileRef, t as CreateDirectoryOptions, u as PickFileType } from "./files-VrkQlKIT.js";
|
|
2
|
+
export { CreateDirectoryOptions, DirectoryRef, DownloadOptions, DownloadProgress, DownloadTask, FilePaths, FileRef, FileStat, FileType, PickFileType, PickOptions, RemoveOptions, WriteOptions, files };
|
package/dist/files.js
ADDED
package/dist/index.d.cts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as HexColor, c as defineConfig, i as BleamUserInterfaceStyle, n as BleamConfig, o as appConfig, r as BleamInternalExpoConfig, s as createExpoConfig, t as BleamAppearance } from "./config-
|
|
1
|
+
import { a as HexColor, c as defineConfig, i as BleamUserInterfaceStyle, n as BleamConfig, o as appConfig, r as BleamInternalExpoConfig, s as createExpoConfig, t as BleamAppearance } from "./config-CufOVJV3.cjs";
|
|
2
2
|
export { BleamAppearance, BleamConfig, BleamInternalExpoConfig, BleamUserInterfaceStyle, HexColor, appConfig, createExpoConfig, defineConfig };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as HexColor, c as defineConfig, i as BleamUserInterfaceStyle, n as BleamConfig, o as appConfig, r as BleamInternalExpoConfig, s as createExpoConfig, t as BleamAppearance } from "./config-
|
|
1
|
+
import { a as HexColor, c as defineConfig, i as BleamUserInterfaceStyle, n as BleamConfig, o as appConfig, r as BleamInternalExpoConfig, s as createExpoConfig, t as BleamAppearance } from "./config-Cms0rvqg.js";
|
|
2
2
|
export { BleamAppearance, BleamConfig, BleamInternalExpoConfig, BleamUserInterfaceStyle, HexColor, appConfig, createExpoConfig, defineConfig };
|