@atrament/web 1.3.0 → 2.1.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/README.md CHANGED
@@ -4,7 +4,7 @@
4
4
 
5
5
  If you want to make customized Atrament build, check out [atrament-core](https://github.com/technix/atrament-core).
6
6
 
7
- If you are looking for example of a web application based on Atrament, check out [atrament-preact-ui](https://github.com/technix/atrament-preact-ui).
7
+ If you are looking for example of a web application based on Atrament, check out [atrament-web-ui](https://github.com/technix/atrament-web-ui).
8
8
 
9
9
  ## Installation
10
10
 
@@ -12,7 +12,7 @@ If you are looking for example of a web application based on Atrament, check out
12
12
 
13
13
  or
14
14
 
15
- ```<script src="https://unpkg.com/@atrament/web@1.2.1/umd/atrament.js"></script>```
15
+ ```<script src="https://unpkg.com/@atrament/web@2.1.0/umd/atrament.js"></script>```
16
16
 
17
17
  ## Usage
18
18
 
@@ -44,14 +44,18 @@ See [Atrament core documentation](https://github.com/technix/atrament-core/blob/
44
44
 
45
45
  ## Components
46
46
 
47
- - loader: fetch
48
- - persistent: [localForage](https://github.com/localForage/localForage)
47
+ - loader: fetch + fflate/jszip
48
+ - persistent: [localForage](https://github.com/localForage/localForage) / Neutralinojs storage
49
49
  - state: [nanostores](https://github.com/nanostores/nanostores)
50
50
  - sound: [howler.js](https://github.com/goldfire/howler.js)
51
-
51
+ - platform: web / Neutralinojs
52
52
 
53
53
  ## LICENSE
54
54
 
55
55
  Atrament is distributed under MIT license.
56
56
 
57
57
  Copyright (c) 2023 Serhii "techniX" Mozhaiskyi
58
+
59
+ Made with the support of the [Interactive Fiction Technology Foundation](https://iftechfoundation.org/)
60
+
61
+ <img src="https://iftechfoundation.org/logo.svg" width="200px">
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atrament/web",
3
- "version": "1.3.0",
3
+ "version": "2.1.0",
4
4
  "description": "Atrament, a text game engine - build for web browsers",
5
5
  "main": "src/index.js",
6
6
  "files": [
@@ -19,17 +19,17 @@
19
19
  },
20
20
  "license": "MIT",
21
21
  "dependencies": {
22
- "@atrament/core": "1.3.0",
22
+ "@atrament/core": "2.0.0",
23
23
  "fflate": "0.8.2",
24
24
  "howler": "2.2.4",
25
25
  "jszip": "3.10.1",
26
26
  "localforage": "1.10.0",
27
- "nanostores": "0.10.3"
27
+ "nanostores": "0.11.2"
28
28
  },
29
29
  "devDependencies": {
30
- "@babel/core": "7.24.7",
31
- "@babel/eslint-parser": "7.24.7",
32
- "@babel/preset-env": "7.24.7",
30
+ "@babel/core": "7.25.2",
31
+ "@babel/eslint-parser": "7.25.1",
32
+ "@babel/preset-env": "7.25.4",
33
33
  "@babel/register": "7.24.6",
34
34
  "babel-loader": "9.1.3",
35
35
  "eslint": "8.49.0",
@@ -39,7 +39,7 @@
39
39
  "jest-mock-console": "2.0.0",
40
40
  "path": "0.12.7",
41
41
  "terser-webpack-plugin": "5.3.10",
42
- "webpack": "5.92.1",
42
+ "webpack": "5.94.0",
43
43
  "webpack-cli": "5.1.4"
44
44
  }
45
45
  }
package/src/index.js CHANGED
@@ -1,15 +1,21 @@
1
+ /* global window */
2
+
1
3
  import atrament from '@atrament/core';
2
4
 
3
5
  import loader from './interfaces/loader-web-fflate';
4
- import persistent from './interfaces/persistent-localforage';
6
+ import persistentWeb from './interfaces/persistent-localforage';
7
+ import persistentNeutralino from './interfaces/persistent-neutralino';
5
8
  import sound from './interfaces/sound-howler';
6
9
  import state from './interfaces/state-nanostores';
10
+ import platformWeb from './interfaces/platform-web';
11
+ import platformNeutralino from './interfaces/platform-neutralino';
7
12
 
8
13
  atrament.defineInterfaces({
9
14
  loader,
10
- persistent,
15
+ persistent: window.Neutralino ? persistentNeutralino : persistentWeb,
11
16
  sound,
12
- state
17
+ state,
18
+ platform: window.Neutralino ? platformNeutralino : platformWeb
13
19
  });
14
20
 
15
21
  export default atrament;
@@ -0,0 +1,102 @@
1
+
2
+ /* global window */
3
+ const KEY_STORAGE = '__atrament_storage';
4
+
5
+ function normalizeKey(key) {
6
+ return key.replace(/[^a-zA-Z0-9]/g, (v) => `_${v.charCodeAt(0)}_`);
7
+ }
8
+
9
+ // neutralino functions
10
+
11
+ async function neuGetData(key) {
12
+ try {
13
+ const data = await window.Neutralino.storage.getData(key);
14
+ return JSON.parse(data);
15
+ } catch (e) {
16
+ console.warn(e.message);
17
+ return null;
18
+ }
19
+ }
20
+
21
+ async function neuSetData(key, value) {
22
+ const v = JSON.stringify(value);
23
+ await window.Neutralino.storage.setData(key, v);
24
+ return v;
25
+ }
26
+
27
+ async function neuDeleteData(key) {
28
+ await window.Neutralino.storage.setData(key, null);
29
+ return true;
30
+ }
31
+
32
+ // key handling
33
+
34
+ async function neuSetKey(key, item) {
35
+ let storageKeys = await neuGetData(KEY_STORAGE);
36
+ if (storageKeys === null) {
37
+ storageKeys = {};
38
+ }
39
+ storageKeys[item] = key;
40
+ await neuSetData(KEY_STORAGE, storageKeys);
41
+ }
42
+
43
+ async function neuDeleteKey(item) {
44
+ let storageKeys = await neuGetData(KEY_STORAGE);
45
+ if (storageKeys === null) {
46
+ storageKeys = {};
47
+ }
48
+ delete storageKeys[item];
49
+ await neuSetData(KEY_STORAGE, storageKeys);
50
+ }
51
+
52
+
53
+ // interface functions
54
+
55
+ function init() {
56
+ }
57
+
58
+ async function exists(item) {
59
+ const persistentKeys = await keys();
60
+ return persistentKeys.includes(item);
61
+ }
62
+
63
+ async function get(item) {
64
+ const storageKeys = await neuGetData(KEY_STORAGE);
65
+ const key = storageKeys === null ? normalizeKey(item) : storageKeys[item];
66
+ const value = await neuGetData(key);
67
+ return value;
68
+ }
69
+
70
+ async function set(item, value) {
71
+ const key = normalizeKey(item);
72
+ try {
73
+ await neuSetData(key, value);
74
+ await neuSetKey(key, item);
75
+ } catch (e) {
76
+ console.error(e.message);
77
+ }
78
+ }
79
+
80
+ async function remove(item) {
81
+ const key = normalizeKey(item);
82
+ try {
83
+ await neuDeleteData(key);
84
+ await neuDeleteKey(item);
85
+ } catch (e) {
86
+ console.error(e.message);
87
+ }
88
+ }
89
+
90
+ async function keys() {
91
+ const storageKeys = await neuGetData(KEY_STORAGE);
92
+ return storageKeys === null ? [] : Object.keys(storageKeys);
93
+ }
94
+
95
+ export default {
96
+ init,
97
+ exists,
98
+ get,
99
+ set,
100
+ remove,
101
+ keys
102
+ };
@@ -0,0 +1,23 @@
1
+ /* global window */
2
+
3
+ async function setFullscreen(enabled) {
4
+ if (enabled) {
5
+ await window.Neutralino.window.setFullScreen();
6
+ } else {
7
+ await window.Neutralino.window.exitFullScreen();
8
+ }
9
+ }
10
+
11
+ async function setTitle(title) {
12
+ await window.Neutralino.window.setTitle(title);
13
+ }
14
+
15
+ async function exitApp() {
16
+ await window.Neutralino.app.exit();
17
+ }
18
+
19
+ export default {
20
+ setFullscreen,
21
+ setTitle,
22
+ exitApp
23
+ };
@@ -0,0 +1,22 @@
1
+ /* global document */
2
+
3
+ async function setFullscreen(enabled, setFullscreenState) {
4
+ if (enabled && !document.fullscreenElement) {
5
+ try {
6
+ await document.documentElement.requestFullscreen();
7
+ } catch {
8
+ setFullscreenState(false);
9
+ }
10
+ } else if (document.fullscreenElement && document.exitFullscreen) {
11
+ document.exitFullscreen();
12
+ }
13
+ }
14
+
15
+ function setTitle(title) {
16
+ document.title = title;
17
+ }
18
+
19
+ export default {
20
+ setFullscreen,
21
+ setTitle
22
+ };