@aegis-framework/artemis 0.3.29 → 0.4.1

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.
Files changed (59) hide show
  1. package/LICENSE +1 -1
  2. package/dist/artemis.browser.js +4 -0
  3. package/dist/artemis.browser.js.map +24 -0
  4. package/dist/artemis.js +3 -1
  5. package/dist/artemis.js.map +23 -1
  6. package/dist/types/DOM.d.ts +383 -0
  7. package/dist/types/DOM.d.ts.map +1 -0
  8. package/dist/types/Debug.d.ts +118 -0
  9. package/dist/types/Debug.d.ts.map +1 -0
  10. package/dist/types/FileSystem.d.ts +69 -0
  11. package/dist/types/FileSystem.d.ts.map +1 -0
  12. package/dist/types/Form.d.ts +32 -0
  13. package/dist/types/Form.d.ts.map +1 -0
  14. package/dist/types/Platform.d.ts +93 -0
  15. package/dist/types/Platform.d.ts.map +1 -0
  16. package/dist/types/Preload.d.ts +26 -0
  17. package/dist/types/Preload.d.ts.map +1 -0
  18. package/dist/types/Request.d.ts +86 -0
  19. package/dist/types/Request.d.ts.map +1 -0
  20. package/dist/types/Space.d.ts +205 -0
  21. package/dist/types/Space.d.ts.map +1 -0
  22. package/dist/types/SpaceAdapter/IndexedDB.d.ts +130 -0
  23. package/dist/types/SpaceAdapter/IndexedDB.d.ts.map +1 -0
  24. package/dist/types/SpaceAdapter/LocalStorage.d.ts +125 -0
  25. package/dist/types/SpaceAdapter/LocalStorage.d.ts.map +1 -0
  26. package/dist/types/SpaceAdapter/RemoteStorage.d.ts +122 -0
  27. package/dist/types/SpaceAdapter/RemoteStorage.d.ts.map +1 -0
  28. package/dist/types/SpaceAdapter/SessionStorage.d.ts +30 -0
  29. package/dist/types/SpaceAdapter/SessionStorage.d.ts.map +1 -0
  30. package/dist/types/SpaceAdapter/types.d.ts +76 -0
  31. package/dist/types/SpaceAdapter/types.d.ts.map +1 -0
  32. package/dist/types/Text.d.ts +47 -0
  33. package/dist/types/Text.d.ts.map +1 -0
  34. package/dist/types/Util.d.ts +31 -0
  35. package/dist/types/Util.d.ts.map +1 -0
  36. package/dist/types/browser.d.ts +7 -0
  37. package/dist/types/browser.d.ts.map +1 -0
  38. package/dist/types/index.d.ts +11 -0
  39. package/dist/types/index.d.ts.map +1 -0
  40. package/package.json +42 -53
  41. package/dist/artemis.min.js +0 -2
  42. package/dist/artemis.min.js.map +0 -1
  43. package/dist/index.js +0 -2
  44. package/dist/index.js.map +0 -1
  45. package/index.js +0 -10
  46. package/src/DOM.js +0 -993
  47. package/src/Debug.js +0 -233
  48. package/src/FileSystem.js +0 -109
  49. package/src/Form.js +0 -73
  50. package/src/Platform.js +0 -166
  51. package/src/Preload.js +0 -48
  52. package/src/Request.js +0 -163
  53. package/src/Space.js +0 -334
  54. package/src/SpaceAdapter/IndexedDB.js +0 -345
  55. package/src/SpaceAdapter/LocalStorage.js +0 -395
  56. package/src/SpaceAdapter/RemoteStorage.js +0 -225
  57. package/src/SpaceAdapter/SessionStorage.js +0 -46
  58. package/src/Text.js +0 -133
  59. package/src/Util.js +0 -55
package/src/Debug.js DELETED
@@ -1,233 +0,0 @@
1
- /**
2
- * ==============================
3
- * Debug
4
- * ==============================
5
- */
6
-
7
- /* eslint no-console: "off" */
8
-
9
- /**
10
- * List of Log Levels available.
11
- */
12
- export const DebugLevel = {
13
- NONE: 0,
14
- ERROR: 1,
15
- WARNING: 2,
16
- INFO: 3,
17
- DEBUG: 4,
18
- ALL: 5
19
- };
20
-
21
- /**
22
- * This class acts as a proxy for the console. It shares the same methods as the
23
- * web console but they are conditioned to a debug level.
24
- *
25
- * @class
26
- */
27
- export class Debug {
28
-
29
- /**
30
- * @static level - Set the log level
31
- *
32
- * @param {DebugLevel} level The debug level to use
33
- *
34
- * @return {void}
35
- */
36
- static level (level) {
37
- if (typeof level === 'number') {
38
- this._level = level;
39
- }
40
- return this._level;
41
- }
42
-
43
- /**
44
- * @static log - Log the given elements.
45
- *
46
- * Logs will only be made if the level is set to DEBUG or above
47
- *
48
- * @param {...any} args
49
- *
50
- * @return {void}
51
- */
52
- static log (...args) {
53
- if (this.level () >= DebugLevel.DEBUG) {
54
- console.log (...args);
55
- }
56
- }
57
-
58
- /**
59
- * @static debug - Show a debugging log
60
- *
61
- * Logs will only be made if the level is set DEBUG or above
62
- *
63
- * @param {...any} args
64
- *
65
- * @return {void}
66
- */
67
- static debug (...args) {
68
- if (this.level () >= DebugLevel.DEBUG) {
69
- console.debug (...args);
70
- }
71
- }
72
-
73
- /**
74
- * @static info - Show an info log
75
- *
76
- * Logs will only be made if the level is set to INFO or above
77
- *
78
- * @param {...any} args
79
- *
80
- * @return {void}
81
- */
82
- static info (...args) {
83
- if (this.level () >= DebugLevel.INFO) {
84
- console.info (...args);
85
- }
86
- }
87
-
88
- /**
89
- * @static error - Show an error log
90
- *
91
- * Logs will only be made if the level is set to ERROR or above
92
- *
93
- * @param {...any} args
94
- *
95
- * @return {void}
96
- */
97
- static error (...args) {
98
- if (this.level () >= DebugLevel.ERROR) {
99
- console.error (...args);
100
- }
101
- }
102
-
103
- /**
104
- * @static warning - Show an warning log
105
- *
106
- * Logs will only be made if the level is set to WARNING or above
107
- *
108
- * @param {...any} args
109
- *
110
- * @return {void}
111
- */
112
- static warning (...args) {
113
- if (this.level () >= DebugLevel.WARNING) {
114
- console.warn (...args);
115
- }
116
- }
117
-
118
- /**
119
- * @static table - Show data as a table
120
- *
121
- * Table will only be made if the level is set to DEBUG or above
122
- *
123
- * @param {...any} args
124
- *
125
- * @return {void}
126
- */
127
- static table (...args) {
128
- if (this.level () >= DebugLevel.DEBUG) {
129
- console.table (...args);
130
- }
131
- }
132
-
133
- /**
134
- * @static group - Start an indented group
135
- *
136
- * @param {...any} args
137
- *
138
- * @return {void}
139
- */
140
- static group (...args) {
141
- if (this.level () >= DebugLevel.DEBUG) {
142
- console.group (...args);
143
- }
144
- }
145
-
146
- /**
147
- * @static groupCollapsed - Start an indented group collapsed by default
148
- *
149
- * @param {...any} args
150
- *
151
- * @return {void}
152
- */
153
- static groupCollapsed (...args) {
154
- if (this.level () >= DebugLevel.DEBUG) {
155
- console.groupCollapsed (...args);
156
- }
157
- }
158
-
159
- /**
160
- * @static groupEnd - End a previously started group
161
- *
162
- * @param {...any} args
163
- *
164
- * @return {void}
165
- */
166
- static groupEnd (...args) {
167
- if (this.level () >= DebugLevel.DEBUG) {
168
- console.groupEnd (...args);
169
- }
170
- }
171
-
172
- /**
173
- * @static time - Start a timer
174
- *
175
- * The timer will only start if the level is set to DEBUG or above
176
- *
177
- * @param {...any} args
178
- *
179
- * @return {void}
180
- */
181
- static time (...args) {
182
- if (this.level () >= DebugLevel.DEBUG) {
183
- console.time (...args);
184
- }
185
- }
186
-
187
- /**
188
- * @static timeLog - Log the time a timer has been running for
189
- *
190
- * The time will only be logged if the level is set to DEBUG or above
191
- *
192
- * @param {...any} args
193
- *
194
- * @return {void}
195
- */
196
- static timeLog (...args) {
197
- if (this.level () >= DebugLevel.DEBUG) {
198
- console.timeLog (...args);
199
- }
200
- }
201
-
202
- /**
203
- * @static timeEnd - End a timer
204
- *
205
- * The timer will only be available if the level is set to DEBUG or above
206
- *
207
- * @param {...any} args
208
- *
209
- * @return {void}
210
- */
211
- static timeEnd (...args) {
212
- if (this.level () >= DebugLevel.DEBUG) {
213
- console.timeEnd (...args);
214
- }
215
- }
216
-
217
- /**
218
- * @static trace - Show the stack trace
219
- *
220
- * The stack trace will only be available if the level is set to DEBUG or above
221
- *
222
- * @param {...any} args
223
- *
224
- * @return {void}
225
- */
226
- static trace (...args) {
227
- if (this.level () >= DebugLevel.DEBUG) {
228
- console.trace (...args);
229
- }
230
- }
231
- }
232
-
233
- Debug._level = DebugLevel.NONE;
package/src/FileSystem.js DELETED
@@ -1,109 +0,0 @@
1
- /**
2
- * ==============================
3
- * File System
4
- * ==============================
5
- */
6
-
7
- import { Request } from './Request';
8
-
9
- /**
10
- * A simple class wrapper for the File and FileReader web API, while this class
11
- * doesn't actually provide acces to the host file system, it does provide useful
12
- * utilities for form file inputs and remote content loading.
13
- *
14
- * @class
15
- */
16
- export class FileSystem {
17
-
18
-
19
- /**
20
- * @static readRemote - Read a file from a remote location given a URL. This
21
- * function will fetch the file blob using the Request class and then use the
22
- * read () function to read the blob in the format required.
23
- *
24
- * @param {type} url - URL to fetch the file from
25
- * @param {type} [type = 'base64'] - Type of data to be read, values can be
26
- * 'text', 'base64' and 'buffer'. This parameter is used for the read () function.
27
- * @param {Object} [props = {}] - Props to send to the Request object
28
- * @return {Promise<ArrayBuffer|string>} - Content of the file. The format
29
- * depends on the type parameter used.
30
- */
31
- static readRemote (url, type = 'base64', props = {}) {
32
- return Request.blob (url, {}, props).then ((file) => {
33
- return FileSystem.read (file, type);
34
- });
35
- }
36
-
37
- /**
38
- * @static read - Read a given File or Blob object.
39
- *
40
- * @param {File|Blob} file - File to read
41
- * @param {string} [type = 'text'] - Type of data to be read, values can be
42
- * 'text', 'base64' and 'buffer'.
43
- *
44
- * @return {Promise<Event, ArrayBuffer|string>} - Promise that resolves to
45
- * the Load event and content of the file. The format depends on the type
46
- * parameter used.
47
- */
48
- static read (file, type = 'text') {
49
- return new Promise ((resolve, reject) => {
50
- const reader = new FileReader ();
51
-
52
- reader.onload = (event) => {
53
- // Pass down the event object and the content
54
- resolve (event, event.target.result);
55
- };
56
-
57
- reader.onerror = (error) => {
58
- reject (error);
59
- };
60
-
61
- if (type === 'base64') {
62
- reader.readAsDataURL (file);
63
- } else if (type === 'buffer') {
64
- reader.readAsArrayBuffer (file);
65
- } else {
66
- reader.readAsText (file, 'UTF-8');
67
- }
68
- });
69
- }
70
-
71
- /**
72
- * @static create - Create a new File, this uses the File API and will note
73
- * actually create a file in the user's file system, however using it with
74
- * other features, that may be possible
75
- *
76
- * @param {string} file - Name of the file (Including extension)
77
- * @param {ArrayBuffer|ArrayBufferView|Blob|string} content - Content to save in the file
78
- * @param {string} [type = 'text/plain'] - Mime Type for the file
79
- *
80
- * @return {Promise<File>}
81
- */
82
- static create (name, content, type = 'text/plain') {
83
- return Promise.resolve (new File ([content], name, {type}));
84
- }
85
-
86
- /**
87
- * @static extension - Returns the extension of a file given its file name.
88
- *
89
- * @param {string} name - Name or full path of the file
90
- *
91
- * @return {string} - File extension without the leading dot (.)
92
- */
93
- static extension (name) {
94
- return name.split ('.').pop ();
95
- }
96
-
97
- /**
98
- * @static isImage - Check if a file is an image by its extension.
99
- *
100
- * @param {string} name - Name or full path of the file
101
- *
102
- * @return {boolean}
103
- */
104
- static isImage (name) {
105
- const extensions = ['jpg', 'jpeg', 'png', 'gif', 'svg', 'webp', 'bmp'];
106
- return extensions.indexOf (FileSystem.extension (name).toLowerCase ()) > -1;
107
- }
108
-
109
- }
package/src/Form.js DELETED
@@ -1,73 +0,0 @@
1
- /**
2
- * ==============================
3
- * Form
4
- * ==============================
5
- */
6
-
7
- import { $_ } from './DOM';
8
-
9
- /**
10
- * Utility class that provides simple function for filling and retrieving values
11
- * from froms. This class requires the use of the `data-form` attribute.
12
- *
13
- * @class
14
- */
15
- export class Form {
16
-
17
- /**
18
- * @static fill - Fill a form's inputs with the given values. Each key in the
19
- * provided object must match the `name` attribute of the input to fill.
20
- *
21
- * @param {string} name - Form name. Must match the `data-form` attribute of the Form.
22
- * @param {Object} data - JSON object with key-value pairs to fill the inputs.
23
- */
24
- static fill (name, data) {
25
- for (const field in data) {
26
- const element = $_(`form[data-form='${name}'] [name='${field}']`).get (0);
27
- if (typeof element != 'undefined') {
28
- switch (element.type) {
29
-
30
- case 'file':
31
- case 'file[]':
32
- break;
33
-
34
- default:
35
- element.value = data[field];
36
- break;
37
- }
38
- }
39
-
40
- }
41
- }
42
-
43
- /**
44
- * @static values - Get all the values from a form's input. The keys are mapped
45
- * using the `name` attribute of each input.
46
- *
47
- * @param {string} name - Form name. Must match the `data-form` attribute of the Form.
48
- * @return {Object} - Key-value JSON object
49
- */
50
- static values (name) {
51
- const data = {};
52
- $_(`form[data-form='${name}'] [name]`).each ((element) => {
53
- let value;
54
- switch (element.type) {
55
- case 'file[]':
56
- value = element.files;
57
- break;
58
- case 'file':
59
- value = element.files[0];
60
- break;
61
- default:
62
- value = element.value;
63
- break;
64
- }
65
-
66
- if (typeof value != 'undefined' && value !== null) {
67
- data[element.name] = value;
68
- }
69
- });
70
-
71
- return data;
72
- }
73
- }
package/src/Platform.js DELETED
@@ -1,166 +0,0 @@
1
- /**
2
- * ==============================
3
- * Platform
4
- * ==============================
5
- */
6
-
7
- /**
8
- * General checks for what kind of platform is the being used to run the app.
9
- * @class
10
- */
11
- export class Platform {
12
-
13
- /**
14
- * Check if the screen has a retina pixel ratio
15
- * @returns {boolean}
16
- */
17
- static retina () {
18
- return window.devicePixelRatio >= 2;
19
- }
20
-
21
- /**
22
- * Check if the device is on portrait orientation
23
- * @returns {boolean}
24
- */
25
- static portrait () {
26
- return window.orientation === 0 || window.orientation === 180;
27
- }
28
-
29
- /**
30
- * Check if the device is on landscape orientation
31
- * @returns {boolean}
32
- */
33
- static landscape () {
34
- return (window.orientation === 90 || window.orientation === -90);
35
- }
36
-
37
- /**
38
- * Get device Orientation
39
- * @returns {string} portrait | landscape
40
- */
41
- static orientation () {
42
- return Platform.portrait () ? 'portrait' : 'landscape';
43
- }
44
-
45
- /**
46
- * Check if the app is running over Electron
47
- * @returns {boolean}
48
- */
49
- static electron () {
50
- // Renderer process
51
- if (typeof window !== 'undefined' && typeof window.process === 'object' && window.process.type === 'renderer') {
52
- return true;
53
- }
54
-
55
- // Main process
56
- // eslint-disable-next-line no-undef
57
- if (typeof process !== 'undefined' && typeof process.versions === 'object' && !!process.versions.electron) {
58
- return true;
59
- }
60
-
61
- // Detect the user agent when the `nodeIntegration` option is set to true
62
- if (typeof navigator === 'object' && typeof navigator.userAgent === 'string' && navigator.userAgent.indexOf('Electron') > -1) {
63
- return true;
64
- }
65
-
66
- return false;
67
- }
68
-
69
- /**
70
- * Check if the app is running over Cordova
71
- * @returns {boolean}
72
- */
73
- static cordova () {
74
- return !!window.cordova;
75
- }
76
-
77
- /**
78
- * Check if the app is running in a desktop platform
79
- * @returns {boolean}
80
- */
81
- static desktop (platform = 'Any') {
82
- let match = false;
83
- switch (platform) {
84
- case 'Windows':
85
- match = navigator.platform.includes ('Win');
86
- break;
87
-
88
- case 'macOS':
89
- match = navigator.platform.includes ('Mac');
90
- break;
91
-
92
- case 'Linux':
93
- match = navigator.platform.includes ('Linux');
94
- break;
95
-
96
- case 'FreeBSD':
97
- match = navigator.platform.includes ('FreeBSD');
98
- break;
99
-
100
- case 'webOS':
101
- match = navigator.platform.includes ('WebTV');
102
- break;
103
-
104
- case 'Any':
105
- default:
106
- match = navigator.platform.includes ('Win')
107
- || navigator.platform.includes ('Mac')
108
- || navigator.platform.includes ('Linux')
109
- || navigator.platform.includes ('FreeBSD')
110
- || navigator.platform.includes ('WebTV');
111
- break;
112
- }
113
- return match;
114
- }
115
-
116
- /**
117
- * Check if the app is running in a mobile platform
118
- * @param {string } [platform='Any'] - Check for a specific mobile platform [Android | iOS | Opera | Windows | BlackBerry | Any]
119
- * @returns {boolean}
120
- */
121
- static mobile (platform = 'Any') {
122
- let match = false;
123
- switch (platform) {
124
- case 'Android':
125
- match = /Android/i.test (navigator.userAgent);
126
- break;
127
-
128
- case 'iOS':
129
- match = /iPhone|iPad|iPod/i.test (navigator.userAgent);
130
- break;
131
-
132
- case 'Opera':
133
- match = /Opera Mini/i.test (navigator.userAgent);
134
- break;
135
-
136
- case 'Windows':
137
- match = /Windows Phone|IEMobile|WPDesktop/i.test (navigator.userAgent);
138
- break;
139
-
140
- case 'BlackBerry':
141
- match = /BlackBerry|BB10/i.test (navigator.userAgent);
142
- break;
143
-
144
- case 'Any':
145
- default:
146
- match = /Android|iPhone|iPad|iPod|Windows Phone|IEMobile|WPDesktop|BlackBerry|BB10/i.test (navigator.userAgent);
147
- break;
148
- }
149
- return match;
150
- }
151
-
152
- /**
153
- * @static serviceWorkers - Check if the platform allows the use of service
154
- * workers
155
- *
156
- * @return {boolean} - Whether they're supported or not
157
- */
158
- static serviceWorkers () {
159
- if (typeof navigator !== 'undefined') {
160
- if ('serviceWorker' in navigator && location.protocol.indexOf ('http') > -1) {
161
- return true;
162
- }
163
- }
164
- return false;
165
- }
166
- }
package/src/Preload.js DELETED
@@ -1,48 +0,0 @@
1
- /**
2
- * ==============================
3
- * Preload
4
- * ==============================
5
- */
6
-
7
- import { Request } from './Request';
8
-
9
- /**
10
- * A simple class for asset preloading. This class assumes you have a service
11
- * worker set up that will be caching all requests.
12
- * @class
13
- */
14
- export class Preload {
15
-
16
- /**
17
- * @static image - Preload an image file
18
- *
19
- * @param {string} route - Route to the image
20
- * @return {Promise} - Resolves to the image object or gets rejected with
21
- * the rejection event
22
- */
23
- static image (route) {
24
- return new Promise((resolve, reject) => {
25
- const image = new Image ();
26
-
27
- image.onload = () => {
28
- resolve (image);
29
- };
30
-
31
- image.onerror = (e) => {
32
- reject (e);
33
- };
34
-
35
- image.src = route;
36
- });
37
- }
38
-
39
- /**
40
- * @static file - Preload any kind of file
41
- *
42
- * @param {string} route - Route to the file
43
- * @return {Promise} - Resolves or rejects depending on request success
44
- */
45
- static file (route) {
46
- return Request.blob (route);
47
- }
48
- }