@nativescript/canvas-polyfill 2.0.0-alpha.9 → 2.0.0-beta.0
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/DOM/Document.d.ts +2 -1
- package/DOM/Element.js +3 -6
- package/DOM/Element.js.map +1 -1
- package/DOM/HTMLCanvasElement.d.ts +3 -0
- package/DOM/HTMLCanvasElement.js +5 -0
- package/DOM/HTMLCanvasElement.js.map +1 -1
- package/DOM/HTMLImageElement.js +9 -17
- package/DOM/HTMLImageElement.js.map +1 -1
- package/DOM/HTMLVideoElement.js +10 -20
- package/DOM/HTMLVideoElement.js.map +1 -1
- package/DOM/Node.js +3 -5
- package/DOM/Node.js.map +1 -1
- package/DOM/XMLDocument.js +2 -4
- package/DOM/XMLDocument.js.map +1 -1
- package/LICENSE +201 -0
- package/MutationObserver.d.ts +10 -0
- package/MutationObserver.js +22 -0
- package/MutationObserver.js.map +1 -0
- package/URL.android.d.ts +16 -14
- package/URL.android.js +293 -42
- package/URL.android.js.map +1 -1
- package/URL.ios.d.ts +19 -5
- package/URL.ios.js +536 -96
- package/URL.ios.js.map +1 -1
- package/async/file/file.android.js +2 -3
- package/async/file/file.android.js.map +1 -1
- package/async/file/file.ios.js +26 -39
- package/async/file/file.ios.js.map +1 -1
- package/async/http/http.android.js +6 -1
- package/async/http/http.android.js.map +1 -1
- package/async/http/http.ios.js +9 -4
- package/async/http/http.ios.js.map +1 -1
- package/async/xhr/TNSXMLHttpRequest.js +126 -10
- package/async/xhr/TNSXMLHttpRequest.js.map +1 -1
- package/index.d.ts +1 -0
- package/index.js +8 -0
- package/index.js.map +1 -1
- package/localStorage.d.ts +2 -0
- package/localStorage.js +150 -0
- package/localStorage.js.map +1 -0
- package/package.json +6 -7
- package/platforms/android/async-release.aar +0 -0
- package/platforms/android/canvas_polyfill.aar +0 -0
- package/platforms/android/java/org/nativescript/canvas/polyfill/Utils.java +31 -9
- package/resize.js +15 -10
- package/resize.js.map +1 -1
- package/url-search.d.ts +0 -0
- package/url-search.js +343 -0
- package/url-search.js.map +1 -0
package/URL.ios.js
CHANGED
|
@@ -1,142 +1,564 @@
|
|
|
1
|
-
|
|
2
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
3
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
4
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
5
|
-
};
|
|
6
|
-
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
7
|
-
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
8
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
9
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
10
|
-
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
11
|
-
};
|
|
12
|
-
var _URL_native;
|
|
13
|
-
import { knownFolders, File as NSFile, isIOS, path, Folder, Application } from '@nativescript/core';
|
|
1
|
+
import { knownFolders, File as NSFile, path, Folder } from '@nativescript/core';
|
|
14
2
|
const BLOB_PATH = 'blob:nativescript/';
|
|
15
3
|
const BLOB_DIR = 'ns_blobs';
|
|
16
4
|
const BLOB_KEYS = 'org.nativescript.canvas.blob.keys';
|
|
17
5
|
let sharedPreferences;
|
|
6
|
+
const BLOB_STORE = new Map();
|
|
7
|
+
/*
|
|
8
|
+
export class URLSearchParams {
|
|
9
|
+
_native = new Map();
|
|
10
|
+
constructor(search: string | URLSearchParams) {
|
|
11
|
+
if (search instanceof URLSearchParams) {
|
|
12
|
+
this._native = new Map(search._native);
|
|
13
|
+
} else if (typeof search === 'string') {
|
|
14
|
+
this._native = NSURLComponents.alloc().initWithString(search);
|
|
15
|
+
} else {
|
|
16
|
+
this._native = NSURLComponents.alloc().initWithString((<any>search)?.toString?.());
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
append(name: string, value: string) {
|
|
21
|
+
let queryItems: NSMutableArray<NSURLQueryItem> = this._native.queryItems.mutableCopy();
|
|
22
|
+
if (!queryItems) {
|
|
23
|
+
queryItems = NSMutableArray.array();
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
if (value) {
|
|
27
|
+
queryItems.addObject(NSURLQueryItem.queryItemWithNameValue(name, value));
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
this._native.queryItems = queryItems;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
set(name: string, value: string) {
|
|
34
|
+
let queryItems: NSMutableArray<NSURLQueryItem> = this._native.queryItems.mutableCopy();
|
|
35
|
+
if (!queryItems) {
|
|
36
|
+
queryItems = NSMutableArray.array();
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
queryItems.filterUsingPredicate(NSPredicate.predicateWithFormatArgumentArray('name != %@', NSArray.arrayWithObject(value)));
|
|
40
|
+
|
|
41
|
+
if (value) {
|
|
42
|
+
queryItems.addObject(NSURLQueryItem.queryItemWithNameValue(name, value));
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
this._native.queryItems = queryItems;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
get(name: string) {
|
|
49
|
+
const queryItems = this._native.queryItems;
|
|
50
|
+
const count = queryItems.count;
|
|
51
|
+
for (let i = 0; i < count; i++) {
|
|
52
|
+
const queryItem = queryItems.objectAtIndex(i);
|
|
53
|
+
if (queryItem.name === name) {
|
|
54
|
+
return queryItem.value;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return null;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
delete(name: string, value?: string) {
|
|
61
|
+
const queryItems: NSMutableArray<NSURLQueryItem> = this._native.queryItems.mutableCopy();
|
|
62
|
+
if (!queryItems) {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
if (!value) {
|
|
67
|
+
queryItems.filterUsingPredicate(NSPredicate.predicateWithFormatArgumentArray('name != %@', NSArray.arrayWithObject(value)));
|
|
68
|
+
this._native.queryItems = queryItems;
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
queryItems.filterUsingPredicate(NSPredicate.predicateWithFormatArgumentArray('name != %@ OR value != %@', NSArray.arrayWithArray([name, value])));
|
|
73
|
+
|
|
74
|
+
this._native.queryItems = queryItems;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
toString() {
|
|
78
|
+
return this._native.string;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
*/
|
|
82
|
+
import './url-search';
|
|
83
|
+
/*
|
|
18
84
|
export class URL {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
let baseUrl;
|
|
22
|
-
let nativeURL;
|
|
85
|
+
_native: NSURLComponents;
|
|
86
|
+
constructor(url: string, base?: string | URL) {
|
|
87
|
+
let baseUrl: NSURL;
|
|
88
|
+
let nativeURL: NSURL;
|
|
23
89
|
if (base instanceof URL) {
|
|
24
|
-
baseUrl =
|
|
25
|
-
}
|
|
26
|
-
else {
|
|
90
|
+
baseUrl = base._native.URL;
|
|
91
|
+
} else {
|
|
27
92
|
baseUrl = NSURL.URLWithString(base);
|
|
28
93
|
}
|
|
94
|
+
|
|
29
95
|
if (baseUrl) {
|
|
30
96
|
nativeURL = NSURL.URLWithStringRelativeToURL(url, baseUrl);
|
|
31
|
-
}
|
|
32
|
-
else {
|
|
97
|
+
} else {
|
|
33
98
|
nativeURL = NSURL.URLWithString(url);
|
|
34
99
|
}
|
|
35
|
-
|
|
100
|
+
|
|
101
|
+
this._native = NSURLComponents.componentsWithString(nativeURL.absoluteString);
|
|
36
102
|
}
|
|
103
|
+
|
|
37
104
|
get native() {
|
|
38
|
-
return
|
|
105
|
+
return this._native.URL;
|
|
39
106
|
}
|
|
107
|
+
|
|
40
108
|
get hash() {
|
|
41
109
|
const hash = this.native.fragment;
|
|
42
110
|
return hash ? `#${hash}` : '';
|
|
43
111
|
}
|
|
44
|
-
|
|
45
|
-
|
|
112
|
+
|
|
113
|
+
set hash(value: string) {
|
|
114
|
+
this._native.fragment = value;
|
|
46
115
|
}
|
|
116
|
+
|
|
47
117
|
get host() {
|
|
48
118
|
return this.native.host;
|
|
49
119
|
}
|
|
50
|
-
|
|
51
|
-
|
|
120
|
+
|
|
121
|
+
set host(value: string) {
|
|
122
|
+
this._native.host = value;
|
|
52
123
|
}
|
|
124
|
+
|
|
53
125
|
get hostname() {
|
|
54
126
|
return this.native.host;
|
|
55
127
|
}
|
|
56
|
-
|
|
57
|
-
|
|
128
|
+
|
|
129
|
+
set hostname(value: string) {
|
|
130
|
+
this._native.host = value;
|
|
58
131
|
}
|
|
132
|
+
|
|
59
133
|
get href() {
|
|
60
|
-
return
|
|
134
|
+
return this._native.URL.absoluteString;
|
|
61
135
|
}
|
|
62
|
-
|
|
63
|
-
|
|
136
|
+
|
|
137
|
+
set href(value: string) {
|
|
138
|
+
this._native = NSURLComponents.componentsWithString(value);
|
|
64
139
|
}
|
|
140
|
+
|
|
65
141
|
get origin() {
|
|
66
142
|
return `${this.native.scheme}${this.native.host}`;
|
|
67
143
|
}
|
|
144
|
+
|
|
68
145
|
get password() {
|
|
69
146
|
return this.native.password;
|
|
70
147
|
}
|
|
71
|
-
|
|
72
|
-
|
|
148
|
+
|
|
149
|
+
set password(value: string) {
|
|
150
|
+
this._native.password = value;
|
|
73
151
|
}
|
|
152
|
+
|
|
74
153
|
get pathname() {
|
|
75
154
|
return this.native.path;
|
|
76
155
|
}
|
|
77
|
-
|
|
78
|
-
|
|
156
|
+
|
|
157
|
+
set pathname(value: string) {
|
|
158
|
+
this._native.path = value;
|
|
79
159
|
}
|
|
160
|
+
|
|
80
161
|
get port() {
|
|
81
162
|
return String(this.native.port);
|
|
82
163
|
}
|
|
83
|
-
|
|
84
|
-
|
|
164
|
+
|
|
165
|
+
set port(value: string) {
|
|
166
|
+
this._native.port = +value;
|
|
85
167
|
}
|
|
168
|
+
|
|
86
169
|
get protocol() {
|
|
87
170
|
return this.native.scheme + ':';
|
|
88
171
|
}
|
|
89
|
-
|
|
90
|
-
|
|
172
|
+
|
|
173
|
+
set protocol(value: string) {
|
|
174
|
+
this._native.scheme = value;
|
|
91
175
|
}
|
|
176
|
+
|
|
92
177
|
get search() {
|
|
93
178
|
const query = this.native.query;
|
|
94
179
|
return query ? `?${query}` : '';
|
|
95
180
|
}
|
|
96
|
-
|
|
97
|
-
|
|
181
|
+
|
|
182
|
+
set search(value: string) {
|
|
183
|
+
this._native.query = value;
|
|
98
184
|
}
|
|
185
|
+
|
|
99
186
|
get username() {
|
|
100
187
|
return this.native.user;
|
|
101
188
|
}
|
|
102
|
-
|
|
103
|
-
|
|
189
|
+
|
|
190
|
+
set username(value: string) {
|
|
191
|
+
this._native.user = value;
|
|
104
192
|
}
|
|
193
|
+
|
|
194
|
+
get searchParams() {
|
|
195
|
+
return new URLSearchParams(this.native.absoluteString);
|
|
196
|
+
}
|
|
197
|
+
|
|
105
198
|
toJSON() {
|
|
106
199
|
return this.native.toString();
|
|
107
200
|
}
|
|
201
|
+
|
|
108
202
|
toString() {
|
|
109
203
|
return this.native.toString();
|
|
110
204
|
}
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
205
|
+
|
|
206
|
+
public static createObjectURL(object: any, options = null): string {
|
|
207
|
+
// const buf = (Blob as any).InternalAccessor.getBuffer(object);
|
|
208
|
+
if (object instanceof Blob || object instanceof File) {
|
|
114
209
|
const id = this.getUUID();
|
|
210
|
+
const ret = `blob:nativescript/${id}`;
|
|
211
|
+
BLOB_STORE.set(ret, {
|
|
212
|
+
blob: object,
|
|
213
|
+
type: object?.type,
|
|
214
|
+
ext: options?.ext,
|
|
215
|
+
});
|
|
216
|
+
return ret;
|
|
217
|
+
|
|
218
|
+
// const id = this.getUUID();
|
|
219
|
+
// const exists = Folder.exists(path.join(knownFolders.documents().path, BLOB_DIR));
|
|
220
|
+
// if (!exists) {
|
|
221
|
+
// Folder.fromPath(path.join(knownFolders.documents().path, BLOB_DIR));
|
|
222
|
+
// }
|
|
223
|
+
// let fileName = id;
|
|
224
|
+
// // todo get type from magic bytes
|
|
225
|
+
// if (options?.appendExt) {
|
|
226
|
+
// fileName = `${fileName}.${options.ext}`;
|
|
227
|
+
// }
|
|
228
|
+
|
|
229
|
+
// const filePath = path.join(knownFolders.documents().path, BLOB_DIR, fileName);
|
|
230
|
+
|
|
231
|
+
// NSFile.fromPath(filePath).writeSync(NSData.dataWithData(buf));
|
|
232
|
+
|
|
233
|
+
// URL.putItem(id, fileName);
|
|
234
|
+
// return `${BLOB_PATH}${id}`;
|
|
235
|
+
}
|
|
236
|
+
return null;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
public static createObjectURLLegacy(object: any, options = null): string {
|
|
240
|
+
return this.createObjectURLLegacyWithId(this.getUUID(), object, options);
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
static createObjectURLLegacyWithId(id: string, object: any, options = null): string {
|
|
244
|
+
const buf = (Blob as any).InternalAccessor.getBuffer(object);
|
|
245
|
+
if (buf || object instanceof Blob || object instanceof File) {
|
|
115
246
|
const exists = Folder.exists(path.join(knownFolders.documents().path, BLOB_DIR));
|
|
116
247
|
if (!exists) {
|
|
117
248
|
Folder.fromPath(path.join(knownFolders.documents().path, BLOB_DIR));
|
|
118
249
|
}
|
|
119
250
|
let fileName = id;
|
|
120
251
|
// todo get type from magic bytes
|
|
121
|
-
if (options
|
|
252
|
+
if (options?.ext) {
|
|
122
253
|
fileName = `${fileName}.${options.ext}`;
|
|
123
254
|
}
|
|
255
|
+
|
|
124
256
|
const filePath = path.join(knownFolders.documents().path, BLOB_DIR, fileName);
|
|
125
|
-
|
|
126
|
-
|
|
257
|
+
|
|
258
|
+
NSFile.fromPath(filePath).writeSync(NSData.dataWithData(buf));
|
|
259
|
+
|
|
260
|
+
URL.putItem(id, fileName);
|
|
261
|
+
return `${BLOB_PATH}${id}`;
|
|
262
|
+
}
|
|
263
|
+
return null;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
public static revokeObjectURL(url: string) {
|
|
267
|
+
if (typeof url === 'string') {
|
|
268
|
+
const blob = BLOB_STORE.get(url);
|
|
269
|
+
if (blob.path) {
|
|
270
|
+
if (NSFile.exists(blob.path)) {
|
|
271
|
+
const file = NSFile.fromPath(blob.path);
|
|
272
|
+
file.removeSync();
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
BLOB_STORE.delete(url);
|
|
276
|
+
|
|
277
|
+
// const id = url.replace(BLOB_PATH, '');
|
|
278
|
+
// const realPath = URL.getItem(id);
|
|
279
|
+
// if (NSFile.exists(realPath)) {
|
|
280
|
+
// const file = NSFile.fromPath(realPath);
|
|
281
|
+
// file.removeSync();
|
|
282
|
+
// }
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
public static InternalAccessor = class {
|
|
287
|
+
public static getPath(url: string) {
|
|
288
|
+
const blob = BLOB_STORE.get(url);
|
|
289
|
+
if (!blob) {
|
|
290
|
+
return '';
|
|
291
|
+
}
|
|
292
|
+
if (blob.path) {
|
|
293
|
+
return blob.path;
|
|
294
|
+
}
|
|
295
|
+
//const buf = (Blob as any).InternalAccessor.getBuffer(blob.blob);
|
|
296
|
+
|
|
297
|
+
const id = url.replace(BLOB_PATH, '');
|
|
298
|
+
|
|
299
|
+
if (id === '') {
|
|
300
|
+
return '';
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
const created = URL.createObjectURLLegacyWithId(id, blob.blob, {
|
|
304
|
+
type: blob?.type,
|
|
305
|
+
ext: blob?.ext,
|
|
306
|
+
});
|
|
307
|
+
|
|
308
|
+
if (!created) {
|
|
309
|
+
return '';
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
let fileName = id;
|
|
313
|
+
|
|
314
|
+
if (blob?.ext) {
|
|
315
|
+
fileName = `${fileName}.${blob?.ext}`;
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
const filePath = path.join(knownFolders.documents().path, BLOB_DIR, fileName);
|
|
319
|
+
|
|
320
|
+
blob.path = filePath;
|
|
321
|
+
BLOB_STORE.set(url, blob);
|
|
322
|
+
return filePath;
|
|
323
|
+
|
|
324
|
+
// if (typeof url === 'string') {
|
|
325
|
+
// const id = url.replace(BLOB_PATH, '');
|
|
326
|
+
// return URL.getItem(id);
|
|
327
|
+
// }
|
|
328
|
+
// return '';
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
public static getData(url: string) {
|
|
332
|
+
return BLOB_STORE.get(url);
|
|
333
|
+
}
|
|
334
|
+
};
|
|
335
|
+
|
|
336
|
+
private static getUUID() {
|
|
337
|
+
return NSUUID.UUID().UUIDString;
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
private static putItem(key: string, value: string) {
|
|
341
|
+
if (!sharedPreferences) {
|
|
342
|
+
sharedPreferences = NSUserDefaults.alloc().initWithSuiteName(BLOB_KEYS);
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
(<NSUserDefaults>sharedPreferences).setObjectForKey(value, key);
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
private static getItem(key: string) {
|
|
349
|
+
const fileDir = Folder.fromPath(path.join(knownFolders.documents().path, BLOB_DIR));
|
|
350
|
+
let fileName = null;
|
|
351
|
+
|
|
352
|
+
if (!sharedPreferences) {
|
|
353
|
+
sharedPreferences = NSUserDefaults.alloc().initWithSuiteName(BLOB_KEYS);
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
if (!(<NSUserDefaults>sharedPreferences).objectForKey(key)) {
|
|
357
|
+
return null;
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
fileName = (<NSUserDefaults>sharedPreferences).stringForKey(key);
|
|
361
|
+
|
|
362
|
+
if (fileName) {
|
|
363
|
+
return path.join(fileDir.path, fileName);
|
|
364
|
+
}
|
|
365
|
+
return null;
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
*/
|
|
369
|
+
export class URL {
|
|
370
|
+
constructor(url, base) {
|
|
371
|
+
this._isBlobURL = false;
|
|
372
|
+
if (url?.startsWith?.('blob:')) {
|
|
373
|
+
this._isBlobURL = true;
|
|
374
|
+
}
|
|
375
|
+
let baseUrl;
|
|
376
|
+
if (typeof url === 'string' && url.startsWith('blob:')) {
|
|
377
|
+
this._native = new global.CanvasModule.URL(url);
|
|
378
|
+
}
|
|
379
|
+
else {
|
|
380
|
+
if (base instanceof URL) {
|
|
381
|
+
baseUrl = base._native.toString();
|
|
382
|
+
}
|
|
383
|
+
else if (base) {
|
|
384
|
+
try {
|
|
385
|
+
baseUrl = base.toString();
|
|
386
|
+
}
|
|
387
|
+
catch (e) {
|
|
388
|
+
throw new TypeError(`Failed to construct 'URL': Invalid base URL`);
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
try {
|
|
392
|
+
if (baseUrl) {
|
|
393
|
+
this._native = new global.CanvasModule.URL(url, baseUrl);
|
|
394
|
+
}
|
|
395
|
+
else {
|
|
396
|
+
this._native = new global.CanvasModule.URL(url);
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
catch (e) {
|
|
400
|
+
throw new TypeError(`Failed to construct 'URL': Invalid URL`);
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
get native() {
|
|
405
|
+
return this._native;
|
|
406
|
+
}
|
|
407
|
+
get hash() {
|
|
408
|
+
return this.native.hash;
|
|
409
|
+
}
|
|
410
|
+
set hash(value) {
|
|
411
|
+
this.native.hash = value;
|
|
412
|
+
}
|
|
413
|
+
get host() {
|
|
414
|
+
return this.native.host;
|
|
415
|
+
}
|
|
416
|
+
set host(value) {
|
|
417
|
+
this.native.host = value;
|
|
418
|
+
}
|
|
419
|
+
get hostname() {
|
|
420
|
+
return this.native.hostname;
|
|
421
|
+
}
|
|
422
|
+
set hostname(value) {
|
|
423
|
+
this.native.hostname = value;
|
|
424
|
+
}
|
|
425
|
+
get href() {
|
|
426
|
+
return this.native.href;
|
|
427
|
+
}
|
|
428
|
+
set href(value) {
|
|
429
|
+
this.native.href = value;
|
|
430
|
+
}
|
|
431
|
+
get origin() {
|
|
432
|
+
// let url = this._native;
|
|
433
|
+
// if (this._isBlobURL) {
|
|
434
|
+
// url = new java.net.URI(this._native.toString().replace('blob:', ''));
|
|
435
|
+
// }
|
|
436
|
+
// return `${url.getScheme()}://${url.getHost()}`;
|
|
437
|
+
return this.native.origin;
|
|
438
|
+
}
|
|
439
|
+
get password() {
|
|
440
|
+
return this.native.password;
|
|
441
|
+
}
|
|
442
|
+
set password(value) {
|
|
443
|
+
this.native.password = value;
|
|
444
|
+
}
|
|
445
|
+
get pathname() {
|
|
446
|
+
return this.native.pathname;
|
|
447
|
+
}
|
|
448
|
+
set pathname(value) {
|
|
449
|
+
this.native.pathname = value;
|
|
450
|
+
}
|
|
451
|
+
get port() {
|
|
452
|
+
return this.native.port;
|
|
453
|
+
}
|
|
454
|
+
set port(value) {
|
|
455
|
+
this.native.port = value;
|
|
456
|
+
}
|
|
457
|
+
get protocol() {
|
|
458
|
+
return this.native.protocol;
|
|
459
|
+
}
|
|
460
|
+
set protocol(value) {
|
|
461
|
+
this.native.protocol = value;
|
|
462
|
+
}
|
|
463
|
+
get search() {
|
|
464
|
+
return this.native.search;
|
|
465
|
+
}
|
|
466
|
+
set search(value) {
|
|
467
|
+
this.native.search = value;
|
|
468
|
+
}
|
|
469
|
+
get searchParams() {
|
|
470
|
+
return new URLSearchParams(this.native.toString());
|
|
471
|
+
}
|
|
472
|
+
get username() {
|
|
473
|
+
return this.native.username;
|
|
474
|
+
}
|
|
475
|
+
set username(value) {
|
|
476
|
+
this.native.username = value;
|
|
477
|
+
}
|
|
478
|
+
toJSON() {
|
|
479
|
+
return this.native.toString();
|
|
480
|
+
}
|
|
481
|
+
toString() {
|
|
482
|
+
return this.native.toString();
|
|
483
|
+
}
|
|
484
|
+
static canParse(url, base) {
|
|
485
|
+
let ret = false;
|
|
486
|
+
if (url?.startsWith?.('blob:')) {
|
|
487
|
+
ret = true;
|
|
488
|
+
}
|
|
489
|
+
let baseUrl;
|
|
490
|
+
if (typeof url === 'string' && url.startsWith('blob:')) {
|
|
491
|
+
ret = true;
|
|
492
|
+
}
|
|
493
|
+
else {
|
|
494
|
+
if (base instanceof URL) {
|
|
495
|
+
baseUrl = base._native.toString();
|
|
127
496
|
}
|
|
128
|
-
else {
|
|
497
|
+
else if (base) {
|
|
129
498
|
try {
|
|
130
|
-
|
|
131
|
-
const fos = new java.io.FileOutputStream(file);
|
|
132
|
-
fos.write(Array.from(buf));
|
|
133
|
-
fos.flush();
|
|
134
|
-
fos.close();
|
|
499
|
+
baseUrl = base.toString();
|
|
135
500
|
}
|
|
136
501
|
catch (e) {
|
|
137
|
-
|
|
502
|
+
throw new TypeError(`Failed to construct 'URL': Invalid base URL`);
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
try {
|
|
506
|
+
if (baseUrl) {
|
|
507
|
+
ret = global.CanvasModule.URL.canParse(url, baseUrl);
|
|
508
|
+
}
|
|
509
|
+
else {
|
|
510
|
+
ret = global.CanvasModule.URL.canParse(url);
|
|
138
511
|
}
|
|
139
512
|
}
|
|
513
|
+
catch (e) { }
|
|
514
|
+
}
|
|
515
|
+
return ret;
|
|
516
|
+
}
|
|
517
|
+
static createObjectURL(object, options = null) {
|
|
518
|
+
// const buf = (Blob as any).InternalAccessor.getBuffer(object);
|
|
519
|
+
if (object instanceof Blob || object instanceof File) {
|
|
520
|
+
const id = this.getUUID();
|
|
521
|
+
const ret = `blob:nativescript/${id}`;
|
|
522
|
+
BLOB_STORE.set(ret, {
|
|
523
|
+
blob: object,
|
|
524
|
+
type: object?.type,
|
|
525
|
+
ext: options?.ext,
|
|
526
|
+
});
|
|
527
|
+
return ret;
|
|
528
|
+
// const id = this.getUUID();
|
|
529
|
+
// const exists = Folder.exists(path.join(knownFolders.documents().path, BLOB_DIR));
|
|
530
|
+
// if (!exists) {
|
|
531
|
+
// Folder.fromPath(path.join(knownFolders.documents().path, BLOB_DIR));
|
|
532
|
+
// }
|
|
533
|
+
// let fileName = id;
|
|
534
|
+
// // todo get type from magic bytes
|
|
535
|
+
// if (options?.appendExt) {
|
|
536
|
+
// fileName = `${fileName}.${options.ext}`;
|
|
537
|
+
// }
|
|
538
|
+
// const filePath = path.join(knownFolders.documents().path, BLOB_DIR, fileName);
|
|
539
|
+
// NSFile.fromPath(filePath).writeSync(NSData.dataWithData(buf));
|
|
540
|
+
// URL.putItem(id, fileName);
|
|
541
|
+
// return `${BLOB_PATH}${id}`;
|
|
542
|
+
}
|
|
543
|
+
return null;
|
|
544
|
+
}
|
|
545
|
+
static createObjectURLLegacy(object, options = null) {
|
|
546
|
+
return this.createObjectURLLegacyWithId(this.getUUID(), object, options);
|
|
547
|
+
}
|
|
548
|
+
static createObjectURLLegacyWithId(id, object, options = null) {
|
|
549
|
+
const buf = Blob.InternalAccessor.getBuffer(object);
|
|
550
|
+
if (buf || object instanceof Blob || object instanceof File) {
|
|
551
|
+
const exists = Folder.exists(path.join(knownFolders.documents().path, BLOB_DIR));
|
|
552
|
+
if (!exists) {
|
|
553
|
+
Folder.fromPath(path.join(knownFolders.documents().path, BLOB_DIR));
|
|
554
|
+
}
|
|
555
|
+
let fileName = id;
|
|
556
|
+
// todo get type from magic bytes
|
|
557
|
+
if (options?.ext) {
|
|
558
|
+
fileName = `${fileName}.${options.ext}`;
|
|
559
|
+
}
|
|
560
|
+
const filePath = path.join(knownFolders.documents().path, BLOB_DIR, fileName);
|
|
561
|
+
NSFile.fromPath(filePath).writeSync(NSData.dataWithData(buf));
|
|
140
562
|
URL.putItem(id, fileName);
|
|
141
563
|
return `${BLOB_PATH}${id}`;
|
|
142
564
|
}
|
|
@@ -144,66 +566,84 @@ export class URL {
|
|
|
144
566
|
}
|
|
145
567
|
static revokeObjectURL(url) {
|
|
146
568
|
if (typeof url === 'string') {
|
|
147
|
-
const
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
569
|
+
const blob = BLOB_STORE.get(url);
|
|
570
|
+
if (blob.path) {
|
|
571
|
+
if (NSFile.exists(blob.path)) {
|
|
572
|
+
const file = NSFile.fromPath(blob.path);
|
|
573
|
+
file.removeSync();
|
|
574
|
+
}
|
|
152
575
|
}
|
|
576
|
+
BLOB_STORE.delete(url);
|
|
577
|
+
// const id = url.replace(BLOB_PATH, '');
|
|
578
|
+
// const realPath = URL.getItem(id);
|
|
579
|
+
// if (NSFile.exists(realPath)) {
|
|
580
|
+
// const file = NSFile.fromPath(realPath);
|
|
581
|
+
// file.removeSync();
|
|
582
|
+
// }
|
|
153
583
|
}
|
|
154
584
|
}
|
|
155
585
|
static getUUID() {
|
|
156
|
-
|
|
157
|
-
return NSUUID.UUID().UUIDString;
|
|
158
|
-
}
|
|
159
|
-
return java.util.UUID.randomUUID().toString();
|
|
586
|
+
return NSUUID.UUID().UUIDString;
|
|
160
587
|
}
|
|
161
588
|
static putItem(key, value) {
|
|
162
|
-
if (
|
|
163
|
-
|
|
164
|
-
sharedPreferences = Application.getNativeApplication().getApplicationContext().getSharedPreferences(BLOB_KEYS, 0);
|
|
165
|
-
}
|
|
166
|
-
sharedPreferences.edit().putString(key, value).apply();
|
|
167
|
-
}
|
|
168
|
-
else {
|
|
169
|
-
if (!sharedPreferences) {
|
|
170
|
-
sharedPreferences = NSUserDefaults.alloc().initWithSuiteName(BLOB_KEYS);
|
|
171
|
-
}
|
|
172
|
-
sharedPreferences.setObjectForKey(value, key);
|
|
589
|
+
if (!sharedPreferences) {
|
|
590
|
+
sharedPreferences = NSUserDefaults.alloc().initWithSuiteName(BLOB_KEYS);
|
|
173
591
|
}
|
|
592
|
+
sharedPreferences.setObjectForKey(value, key);
|
|
174
593
|
}
|
|
175
594
|
static getItem(key) {
|
|
176
595
|
const fileDir = Folder.fromPath(path.join(knownFolders.documents().path, BLOB_DIR));
|
|
177
596
|
let fileName = null;
|
|
178
|
-
if (
|
|
179
|
-
|
|
180
|
-
sharedPreferences = Application.getNativeApplication().getApplicationContext().getSharedPreferences(BLOB_KEYS, 0);
|
|
181
|
-
}
|
|
182
|
-
fileName = sharedPreferences.getString(key, null);
|
|
597
|
+
if (!sharedPreferences) {
|
|
598
|
+
sharedPreferences = NSUserDefaults.alloc().initWithSuiteName(BLOB_KEYS);
|
|
183
599
|
}
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
sharedPreferences = NSUserDefaults.alloc().initWithSuiteName(BLOB_KEYS);
|
|
187
|
-
}
|
|
188
|
-
if (!sharedPreferences.objectForKey(key)) {
|
|
189
|
-
return null;
|
|
190
|
-
}
|
|
191
|
-
fileName = sharedPreferences.stringForKey(key);
|
|
600
|
+
if (!sharedPreferences.objectForKey(key)) {
|
|
601
|
+
return null;
|
|
192
602
|
}
|
|
603
|
+
fileName = sharedPreferences.stringForKey(key);
|
|
193
604
|
if (fileName) {
|
|
194
605
|
return path.join(fileDir.path, fileName);
|
|
195
606
|
}
|
|
196
607
|
return null;
|
|
197
608
|
}
|
|
198
609
|
}
|
|
199
|
-
_URL_native = new WeakMap();
|
|
200
610
|
URL.InternalAccessor = class {
|
|
201
611
|
static getPath(url) {
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
return
|
|
612
|
+
const blob = BLOB_STORE.get(url);
|
|
613
|
+
if (!blob) {
|
|
614
|
+
return '';
|
|
205
615
|
}
|
|
206
|
-
|
|
616
|
+
if (blob.path) {
|
|
617
|
+
return blob.path;
|
|
618
|
+
}
|
|
619
|
+
//const buf = (Blob as any).InternalAccessor.getBuffer(blob.blob);
|
|
620
|
+
const id = url.replace(BLOB_PATH, '');
|
|
621
|
+
if (id === '') {
|
|
622
|
+
return '';
|
|
623
|
+
}
|
|
624
|
+
const created = URL.createObjectURLLegacyWithId(id, blob.blob, {
|
|
625
|
+
type: blob?.type,
|
|
626
|
+
ext: blob?.ext,
|
|
627
|
+
});
|
|
628
|
+
if (!created) {
|
|
629
|
+
return '';
|
|
630
|
+
}
|
|
631
|
+
let fileName = id;
|
|
632
|
+
if (blob?.ext) {
|
|
633
|
+
fileName = `${fileName}.${blob?.ext}`;
|
|
634
|
+
}
|
|
635
|
+
const filePath = path.join(knownFolders.documents().path, BLOB_DIR, fileName);
|
|
636
|
+
blob.path = filePath;
|
|
637
|
+
BLOB_STORE.set(url, blob);
|
|
638
|
+
return filePath;
|
|
639
|
+
// if (typeof url === 'string') {
|
|
640
|
+
// const id = url.replace(BLOB_PATH, '');
|
|
641
|
+
// return URL.getItem(id);
|
|
642
|
+
// }
|
|
643
|
+
// return '';
|
|
644
|
+
}
|
|
645
|
+
static getData(url) {
|
|
646
|
+
return BLOB_STORE.get(url);
|
|
207
647
|
}
|
|
208
648
|
};
|
|
209
649
|
//# sourceMappingURL=URL.ios.js.map
|