@schukai/monster 3.33.0 → 3.35.0
Sign up to get free protection for your applications and to get access to all the features.
- package/package.json +1 -1
- package/source/data/buildmap.mjs +72 -20
- package/source/data/buildtree.mjs +95 -12
- package/source/data/datasource/dom.mjs +7 -14
- package/source/data/datasource/server/restapi.mjs +8 -8
- package/source/data/transformer.mjs +13 -20
- package/source/dom/customelement.mjs +27 -36
- package/source/dom/dimension.mjs +105 -0
- package/source/dom/resourcemanager.mjs +11 -8
- package/source/dom/slotted.mjs +4 -5
- package/source/dom/updater.mjs +21 -21
- package/source/dom/util.mjs +1 -2
- package/source/i18n/formatter.mjs +6 -6
- package/source/i18n/locale.mjs +1 -1
- package/source/i18n/provider.mjs +11 -19
- package/source/i18n/providers/embed.mjs +11 -14
- package/source/i18n/translations.mjs +14 -18
- package/source/text/util.mjs +47 -18
- package/source/types/base.mjs +1 -1
- package/source/types/internal.mjs +27 -32
- package/source/types/version.mjs +1 -1
- package/source/util/runtime.mjs +119 -0
- package/test/cases/dom/assembler.mjs +0 -2
- package/test/cases/dom/attributes.mjs +0 -1
- package/test/cases/dom/dimension.mjs +128 -0
- package/test/cases/monster.mjs +1 -1
- package/test/util/jsdom.mjs +3 -1
- package/test/web/import.js +1 -0
- package/test/web/test.html +2 -2
- package/test/web/tests.js +218 -3
@@ -4,34 +4,34 @@
|
|
4
4
|
* This file is licensed under the AGPLv3 License.
|
5
5
|
* License text available at https://www.gnu.org/licenses/agpl-3.0.en.html
|
6
6
|
*/
|
7
|
-
import {internalSymbol} from "../constants.mjs";
|
8
|
-
import {extend} from "../data/extend.mjs";
|
9
|
-
import {Pathfinder} from "../data/pathfinder.mjs";
|
10
|
-
import {parseDataURL} from "./dataurl.mjs";
|
11
|
-
import {isString} from "./is.mjs";
|
12
|
-
import {Observer} from "./observer.mjs";
|
13
|
-
import {ProxyObserver} from "./proxyobserver.mjs";
|
14
|
-
import {validateObject} from "./validate.mjs";
|
15
|
-
import {isObject} from "./is.mjs";
|
16
|
-
|
17
|
-
export {equipWithInternal}
|
7
|
+
import { internalSymbol } from "../constants.mjs";
|
8
|
+
import { extend } from "../data/extend.mjs";
|
9
|
+
import { Pathfinder } from "../data/pathfinder.mjs";
|
10
|
+
import { parseDataURL } from "./dataurl.mjs";
|
11
|
+
import { isString } from "./is.mjs";
|
12
|
+
import { Observer } from "./observer.mjs";
|
13
|
+
import { ProxyObserver } from "./proxyobserver.mjs";
|
14
|
+
import { validateObject } from "./validate.mjs";
|
15
|
+
import { isObject } from "./is.mjs";
|
16
|
+
|
17
|
+
export { equipWithInternal };
|
18
18
|
|
19
19
|
/**
|
20
20
|
* @private
|
21
21
|
* @type {string}
|
22
22
|
*/
|
23
|
-
const propertyName =
|
23
|
+
const propertyName = "internalDefaults";
|
24
24
|
|
25
25
|
/**
|
26
26
|
* This function extends the given object with the following methods:
|
27
|
-
*
|
27
|
+
*
|
28
28
|
* - attachInternalObserver
|
29
29
|
* - detachInternalObserver
|
30
30
|
* - containsInternalObserver
|
31
31
|
* - setInternal
|
32
32
|
* - setInternals
|
33
33
|
* - getInternal
|
34
|
-
*
|
34
|
+
*
|
35
35
|
* @license AGPLv3
|
36
36
|
* @since 3.15.0
|
37
37
|
* @copyright schukai GmbH
|
@@ -45,7 +45,7 @@ function equipWithInternal() {
|
|
45
45
|
Object.defineProperty(self, propertyName, {
|
46
46
|
get: function () {
|
47
47
|
return {};
|
48
|
-
}
|
48
|
+
},
|
49
49
|
});
|
50
50
|
}
|
51
51
|
|
@@ -61,7 +61,7 @@ function equipWithInternal() {
|
|
61
61
|
self["attachInternalObserver"] = (observer) => {
|
62
62
|
self[internalSymbol].attachObserver(observer);
|
63
63
|
return self;
|
64
|
-
}
|
64
|
+
};
|
65
65
|
|
66
66
|
/**
|
67
67
|
* Detach a observer
|
@@ -72,18 +72,17 @@ function equipWithInternal() {
|
|
72
72
|
self["detachInternalObserver"] = (observer) => {
|
73
73
|
self[internalSymbol].detachObserver(observer);
|
74
74
|
return self;
|
75
|
-
}
|
75
|
+
};
|
76
76
|
|
77
77
|
/**
|
78
78
|
* Check if a observer is attached
|
79
|
-
*
|
79
|
+
*
|
80
80
|
* @param {Observer} observer
|
81
81
|
* @returns {boolean}
|
82
82
|
*/
|
83
83
|
self["containsInternalObserver"] = (observer) => {
|
84
84
|
return self[internalSymbol].containsObserver(observer);
|
85
|
-
}
|
86
|
-
|
85
|
+
};
|
87
86
|
|
88
87
|
/**
|
89
88
|
* Set an internal value, nested internals can be specified by path `a.b.c`
|
@@ -95,11 +94,11 @@ function equipWithInternal() {
|
|
95
94
|
self["setInternal"] = (path, value) => {
|
96
95
|
new Pathfinder(self[internalSymbol].getSubject()).setVia(path, value);
|
97
96
|
return self;
|
98
|
-
}
|
97
|
+
};
|
99
98
|
|
100
99
|
/**
|
101
100
|
* set multiple internals at once
|
102
|
-
*
|
101
|
+
*
|
103
102
|
* @param {string|object} options
|
104
103
|
* @return {Datasource}
|
105
104
|
* @throws {Error} the options does not contain a valid json definition
|
@@ -111,7 +110,7 @@ function equipWithInternal() {
|
|
111
110
|
|
112
111
|
extend(self[internalSymbol].getSubject(), defaults, options);
|
113
112
|
return self;
|
114
|
-
}
|
113
|
+
};
|
115
114
|
|
116
115
|
/**
|
117
116
|
* nested internals can be specified by path `a.b.c`
|
@@ -124,14 +123,12 @@ function equipWithInternal() {
|
|
124
123
|
let value;
|
125
124
|
|
126
125
|
try {
|
127
|
-
value = new Pathfinder(self[internalSymbol]
|
128
|
-
|
129
|
-
} catch (e) {
|
130
|
-
}
|
126
|
+
value = new Pathfinder(self[internalSymbol].getRealSubject()).getVia(path);
|
127
|
+
} catch (e) {}
|
131
128
|
|
132
129
|
if (value === undefined) return defaultValue;
|
133
130
|
return value;
|
134
|
-
}
|
131
|
+
};
|
135
132
|
}
|
136
133
|
|
137
134
|
/**
|
@@ -141,9 +138,8 @@ function equipWithInternal() {
|
|
141
138
|
* @return {boolean}
|
142
139
|
*/
|
143
140
|
function hasGetter(obj, prop) {
|
144
|
-
|
145
141
|
while (isObject(obj)) {
|
146
|
-
if (Object.getOwnPropertyDescriptor(obj, prop)?.[
|
142
|
+
if (Object.getOwnPropertyDescriptor(obj, prop)?.["get"]) {
|
147
143
|
return true;
|
148
144
|
}
|
149
145
|
obj = Object.getPrototypeOf(obj);
|
@@ -168,8 +164,7 @@ function parseOptionsJSON(data) {
|
|
168
164
|
try {
|
169
165
|
let dataUrl = parseDataURL(data);
|
170
166
|
data = dataUrl.content;
|
171
|
-
} catch (e) {
|
172
|
-
}
|
167
|
+
} catch (e) {}
|
173
168
|
|
174
169
|
try {
|
175
170
|
obj = JSON.parse(data);
|
package/source/types/version.mjs
CHANGED
@@ -0,0 +1,119 @@
|
|
1
|
+
/**
|
2
|
+
* Copyright schukai GmbH and contributors 2023. All Rights Reserved.
|
3
|
+
* Node module: @schukai/monster
|
4
|
+
* This file is licensed under the AGPLv3 License.
|
5
|
+
* License text available at https://www.gnu.org/licenses/agpl-3.0.en.html
|
6
|
+
*/
|
7
|
+
|
8
|
+
/**
|
9
|
+
* @memberOf Monster.Util
|
10
|
+
* @type {string}
|
11
|
+
*/
|
12
|
+
const ENV_AWS_LAMBDA = "aws-lambda";
|
13
|
+
/**
|
14
|
+
* @memberOf Monster.Util
|
15
|
+
* @type {string}
|
16
|
+
*/
|
17
|
+
const ENV_GOOGLE_FUNCTIONS = "google-functions";
|
18
|
+
/**
|
19
|
+
* @memberOf Monster.Util
|
20
|
+
* @type {string}
|
21
|
+
*/
|
22
|
+
const ENV_ELECTRON = "electron";
|
23
|
+
/**
|
24
|
+
* @memberOf Monster.Util
|
25
|
+
* @type {string}
|
26
|
+
*/
|
27
|
+
const ENV_NODE = "node";
|
28
|
+
/**
|
29
|
+
* @memberOf Monster.Util
|
30
|
+
* @type {string}
|
31
|
+
*/
|
32
|
+
const ENV_BROWSER = "browser";
|
33
|
+
/**
|
34
|
+
* @memberOf Monster.Util
|
35
|
+
* @type {string}
|
36
|
+
*/
|
37
|
+
const ENV_WEB_WORKER = "web-worker";
|
38
|
+
/**
|
39
|
+
* @memberOf Monster.Util
|
40
|
+
* @type {string}
|
41
|
+
*/
|
42
|
+
const ENV_DENO = "deno";
|
43
|
+
/**
|
44
|
+
* @memberOf Monster.Util
|
45
|
+
* @type {string}
|
46
|
+
*/
|
47
|
+
const ENV_UNKNOWN = "unknown";
|
48
|
+
|
49
|
+
/**
|
50
|
+
* Detects and returns the current runtime environment.
|
51
|
+
*
|
52
|
+
* - 'aws-lambda': AWS Lambda environment
|
53
|
+
* - 'google-functions': Google Cloud Functions environment
|
54
|
+
* - 'electron': Electron environment
|
55
|
+
* - 'node': Node.js environment
|
56
|
+
* - 'browser': Browser environment
|
57
|
+
* - 'web-worker': Web Worker environment
|
58
|
+
* - 'deno': Deno environment
|
59
|
+
* - 'react-native': React Native environment
|
60
|
+
* - 'unknown': Unknown environment
|
61
|
+
*
|
62
|
+
* @since 3.34.0
|
63
|
+
* @memberOf Monster.Util
|
64
|
+
* @returns {string} The detected runtime environment. Possible values are:
|
65
|
+
*/
|
66
|
+
function detectRuntimeEnvironment() {
|
67
|
+
// AWS Lambda environment
|
68
|
+
if (typeof process !== "undefined" && process.env != null && process.env.AWS_LAMBDA_FUNCTION_NAME) {
|
69
|
+
return ENV_AWS_LAMBDA;
|
70
|
+
}
|
71
|
+
|
72
|
+
// Google Cloud Functions environment
|
73
|
+
if (typeof process !== "undefined" && process.env != null && process.env.FUNCTION_NAME) {
|
74
|
+
return ENV_GOOGLE_FUNCTIONS;
|
75
|
+
}
|
76
|
+
|
77
|
+
// Node.js environment
|
78
|
+
if (typeof process !== "undefined" && process.versions != null && process.versions.node != null) {
|
79
|
+
// Electron environment
|
80
|
+
if (process.versions.electron != null) {
|
81
|
+
return ENV_ELECTRON;
|
82
|
+
}
|
83
|
+
return ENV_NODE;
|
84
|
+
}
|
85
|
+
|
86
|
+
// Browser environment
|
87
|
+
if (
|
88
|
+
typeof window !== "undefined" &&
|
89
|
+
typeof window.document !== "undefined" &&
|
90
|
+
typeof navigator !== "undefined" &&
|
91
|
+
typeof navigator.userAgent === "string"
|
92
|
+
) {
|
93
|
+
// Web Worker environment
|
94
|
+
if (typeof self === "object" && typeof importScripts === "function") {
|
95
|
+
return ENV_WEB_WORKER;
|
96
|
+
}
|
97
|
+
return ENV_BROWSER;
|
98
|
+
}
|
99
|
+
|
100
|
+
// Deno environment
|
101
|
+
if (typeof Deno !== "undefined") {
|
102
|
+
return ENV_DENO;
|
103
|
+
}
|
104
|
+
|
105
|
+
// Unknown environment
|
106
|
+
return ENV_UNKNOWN;
|
107
|
+
}
|
108
|
+
|
109
|
+
export {
|
110
|
+
ENV_AWS_LAMBDA,
|
111
|
+
ENV_GOOGLE_FUNCTIONS,
|
112
|
+
ENV_ELECTRON,
|
113
|
+
ENV_NODE,
|
114
|
+
ENV_BROWSER,
|
115
|
+
ENV_WEB_WORKER,
|
116
|
+
ENV_DENO,
|
117
|
+
ENV_UNKNOWN,
|
118
|
+
detectRuntimeEnvironment,
|
119
|
+
};
|
@@ -0,0 +1,128 @@
|
|
1
|
+
import {expect} from 'chai';
|
2
|
+
import {convertToPixels, getDeviceDPI} from "../../../../application/source/dom/dimension.mjs";
|
3
|
+
import {getWindow} from "../../../../application/source/dom/util.mjs";
|
4
|
+
import {initJSDOM, isBrowser, JSDOMExport as JSDOM} from "../../util/jsdom.mjs";
|
5
|
+
import {getGlobal} from "../../../../application/source/types/global.mjs";
|
6
|
+
import {detectRuntimeEnvironment} from "../../../../application/source/util/runtime.mjs";
|
7
|
+
|
8
|
+
|
9
|
+
function getMockWindow(dpi) {
|
10
|
+
|
11
|
+
if(detectRuntimeEnvironment() === 'browser') {
|
12
|
+
return getWindow();
|
13
|
+
}
|
14
|
+
|
15
|
+
|
16
|
+
const dom = new JSDOM('', {
|
17
|
+
pretendToBeVisual: true,
|
18
|
+
resources: 'usable',
|
19
|
+
});
|
20
|
+
|
21
|
+
dom.window.matchMedia = (query) => {
|
22
|
+
const dpiRegex = /\(max-resolution: (\d+)dpi\)/;
|
23
|
+
const match = query.match(dpiRegex);
|
24
|
+
|
25
|
+
if (match) {
|
26
|
+
const maxDpi = parseInt(match[1], 10);
|
27
|
+
return {matches: dpi <= maxDpi};
|
28
|
+
}
|
29
|
+
|
30
|
+
return {matches: false};
|
31
|
+
};
|
32
|
+
|
33
|
+
return dom.window;
|
34
|
+
}
|
35
|
+
|
36
|
+
describe('dimension', () => {
|
37
|
+
let currentEnvironment;
|
38
|
+
|
39
|
+
before(function (done) {
|
40
|
+
initJSDOM().then(() => {
|
41
|
+
//chaiDom(getDocument());
|
42
|
+
done();
|
43
|
+
});
|
44
|
+
})
|
45
|
+
|
46
|
+
beforeEach(() => {
|
47
|
+
|
48
|
+
const testDpi = 96;
|
49
|
+
const testWindow = getMockWindow(testDpi);
|
50
|
+
getGlobal().window = testWindow;
|
51
|
+
|
52
|
+
});
|
53
|
+
|
54
|
+
afterEach(() => {
|
55
|
+
delete getGlobal().window;
|
56
|
+
});
|
57
|
+
|
58
|
+
describe('convertToPixels', () => {
|
59
|
+
it('should correctly convert px values', () => {
|
60
|
+
const result = convertToPixels('100px');
|
61
|
+
expect(result).to.equal(100);
|
62
|
+
});
|
63
|
+
|
64
|
+
it('should correctly convert em values', () => {
|
65
|
+
const testElement = document.createElement('div');
|
66
|
+
testElement.style.fontSize = '16px';
|
67
|
+
document.body.appendChild(testElement);
|
68
|
+
|
69
|
+
const result = convertToPixels('2em', testElement, testElement);
|
70
|
+
expect(result).to.equal(32);
|
71
|
+
|
72
|
+
document.body.removeChild(testElement);
|
73
|
+
});
|
74
|
+
|
75
|
+
it('should correctly convert rem values', () => {
|
76
|
+
const testElement = document.createElement('div');
|
77
|
+
testElement.style.fontSize = '16px';
|
78
|
+
document.documentElement.appendChild(testElement);
|
79
|
+
|
80
|
+
const result = convertToPixels('2rem', testElement);
|
81
|
+
expect(result).to.equal(32);
|
82
|
+
|
83
|
+
document.documentElement.removeChild(testElement);
|
84
|
+
});
|
85
|
+
|
86
|
+
it('should correctly convert percentage values', () => {
|
87
|
+
const testElement = document.createElement('div');
|
88
|
+
testElement.style.width = '500px';
|
89
|
+
document.body.appendChild(testElement);
|
90
|
+
|
91
|
+
const result = convertToPixels('50%', testElement);
|
92
|
+
expect(result).to.equal(250);
|
93
|
+
|
94
|
+
document.body.removeChild(testElement);
|
95
|
+
});
|
96
|
+
|
97
|
+
it('should throw an error for unsupported units', () => {
|
98
|
+
expect(() => convertToPixels('10unsupportedUnit')).to.throw('Unsupported unit: unsupportedUnit');
|
99
|
+
});
|
100
|
+
});
|
101
|
+
|
102
|
+
|
103
|
+
describe('getDeviceDPI', () => {
|
104
|
+
it('should return the correct device DPI', () => {
|
105
|
+
const testDpi = 96;
|
106
|
+
const testWindow = getMockWindow(testDpi);
|
107
|
+
getGlobal().window = testWindow;
|
108
|
+
|
109
|
+
const deviceDpi = getDeviceDPI();
|
110
|
+
expect(deviceDpi).to.equal(testDpi * testWindow.devicePixelRatio);
|
111
|
+
|
112
|
+
delete getGlobal().window;
|
113
|
+
});
|
114
|
+
|
115
|
+
it('should cache the result and return the same value', () => {
|
116
|
+
const testDpi = 96;
|
117
|
+
const testWindow = getMockWindow(testDpi);
|
118
|
+
getGlobal().window = testWindow;
|
119
|
+
|
120
|
+
const deviceDpi1 = getDeviceDPI();
|
121
|
+
const deviceDpi2 = getDeviceDPI();
|
122
|
+
expect(deviceDpi1).to.equal(deviceDpi2);
|
123
|
+
|
124
|
+
delete getGlobal().window;
|
125
|
+
});
|
126
|
+
});
|
127
|
+
|
128
|
+
});
|
package/test/cases/monster.mjs
CHANGED
package/test/util/jsdom.mjs
CHANGED
@@ -6,6 +6,7 @@ import {getGlobal} from "../../../application/source/types/global.mjs";
|
|
6
6
|
export const isBrowser = new Function("try {return this===window;}catch(e){ return false;}");
|
7
7
|
export const isNode = new Function("try {return this===global;}catch(e){return false;}");
|
8
8
|
|
9
|
+
let JSDOMExport = null;
|
9
10
|
|
10
11
|
/**
|
11
12
|
* this helper function creates the dom stack in the node environment
|
@@ -27,6 +28,7 @@ function initJSDOM(options) {
|
|
27
28
|
}, options || {})
|
28
29
|
|
29
30
|
return import("jsdom").then(({JSDOM}) => {
|
31
|
+
JSDOMExport = JSDOM;
|
30
32
|
const {window} = new JSDOM(`<html>
|
31
33
|
<head>
|
32
34
|
</head>
|
@@ -85,5 +87,5 @@ function initJSDOM(options) {
|
|
85
87
|
});
|
86
88
|
}
|
87
89
|
|
88
|
-
export {initJSDOM}
|
90
|
+
export {initJSDOM,JSDOMExport}
|
89
91
|
|
package/test/web/import.js
CHANGED
@@ -20,6 +20,7 @@ import "../cases/dom/resource.mjs";
|
|
20
20
|
import "../cases/dom/resourcemanager.mjs";
|
21
21
|
import "../cases/dom/util.mjs";
|
22
22
|
import "../cases/dom/find.mjs";
|
23
|
+
import "../cases/dom/dimension.mjs";
|
23
24
|
import "../cases/dom/customelement.mjs";
|
24
25
|
import "../cases/dom/attributes.mjs";
|
25
26
|
import "../cases/dom/events.mjs";
|
package/test/web/test.html
CHANGED
@@ -14,8 +14,8 @@
|
|
14
14
|
</head>
|
15
15
|
<body>
|
16
16
|
<div id="headline" style="display: flex;align-items: center;justify-content: center;flex-direction: column;">
|
17
|
-
<h1 style='margin-bottom: 0.1em;'>Monster 3.
|
18
|
-
<div id="lastupdate" style='font-size:0.7em'>last update
|
17
|
+
<h1 style='margin-bottom: 0.1em;'>Monster 3.33.0</h1>
|
18
|
+
<div id="lastupdate" style='font-size:0.7em'>last update Mo 27. Mär 18:10:51 CEST 2023</div>
|
19
19
|
</div>
|
20
20
|
<div id="mocks"></div>
|
21
21
|
<div id="mocha"></div>
|