@digipair/engine 0.113.0 → 0.114.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.
- package/README.md +7 -0
- package/{index.cjs.js → dist/index.cjs.js} +85 -74
- package/{index.esm.js → dist/index.esm.js} +10203 -11328
- package/{src → dist/src}/index.d.ts +1 -0
- package/dist/src/index.d.ts.map +1 -0
- package/{src → dist/src}/lib/alias.interface.d.ts +1 -0
- package/dist/src/lib/alias.interface.d.ts.map +1 -0
- package/{src → dist/src}/lib/engine.d.ts +1 -0
- package/dist/src/lib/engine.d.ts.map +1 -0
- package/{src → dist/src}/lib/pins-settings.interface.d.ts +1 -0
- package/dist/src/lib/pins-settings.interface.d.ts.map +1 -0
- package/package.json +26 -6
- package/index.d.ts +0 -2
- /package/{index.cjs.d.ts → dist/index.d.ts} +0 -0
- /package/{schema.fr.json → dist/schema.fr.json} +0 -0
- /package/{schema.json → dist/schema.json} +0 -0
package/README.md
ADDED
|
@@ -1,43 +1,30 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
var Handlebars = require('handlebars/dist/handlebars.min.js');
|
|
3
|
+
var HandlebarsNamespace = require('handlebars/dist/handlebars.min.js');
|
|
6
4
|
var feelin = require('feelin');
|
|
7
5
|
var celJs = require('cel-js');
|
|
8
6
|
|
|
9
|
-
function
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
get: function () { return e[k]; }
|
|
19
|
-
});
|
|
20
|
-
}
|
|
7
|
+
function _interopNamespaceDefault(e) {
|
|
8
|
+
var n = Object.create(null);
|
|
9
|
+
if (e) {
|
|
10
|
+
Object.keys(e).forEach(function (k) {
|
|
11
|
+
if (k !== 'default') {
|
|
12
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
13
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
14
|
+
enumerable: true,
|
|
15
|
+
get: function () { return e[k]; }
|
|
21
16
|
});
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
n.default = e;
|
|
21
|
+
return Object.freeze(n);
|
|
25
22
|
}
|
|
26
23
|
|
|
27
|
-
var
|
|
28
|
-
|
|
29
|
-
function _extends() {
|
|
30
|
-
_extends = Object.assign || function assign(target) {
|
|
31
|
-
for(var i = 1; i < arguments.length; i++){
|
|
32
|
-
var source = arguments[i];
|
|
33
|
-
for(var key in source)if (Object.prototype.hasOwnProperty.call(source, key)) target[key] = source[key];
|
|
34
|
-
}
|
|
35
|
-
return target;
|
|
36
|
-
};
|
|
37
|
-
return _extends.apply(this, arguments);
|
|
38
|
-
}
|
|
24
|
+
var HandlebarsNamespace__namespace = /*#__PURE__*/_interopNamespaceDefault(HandlebarsNamespace);
|
|
39
25
|
|
|
40
|
-
|
|
26
|
+
const Handlebars = HandlebarsNamespace__namespace.default || HandlebarsNamespace__namespace;
|
|
27
|
+
Handlebars.registerHelper('JSONstringify', function(value) {
|
|
41
28
|
return JSON.stringify(value);
|
|
42
29
|
});
|
|
43
30
|
const DIGIPAIR_FUNCTIONS = {
|
|
@@ -53,8 +40,7 @@ const DIGIPAIR_FUNCTIONS = {
|
|
|
53
40
|
JSONstringify: (value)=>JSON.stringify(value)
|
|
54
41
|
};
|
|
55
42
|
const globalInstance = typeof window === 'undefined' ? global : window;
|
|
56
|
-
|
|
57
|
-
const _config = globalInstance.__DIGIPAIR_CONFIG__ = (_globalInstance___DIGIPAIR_CONFIG__ = globalInstance.__DIGIPAIR_CONFIG__) != null ? _globalInstance___DIGIPAIR_CONFIG__ : {
|
|
43
|
+
const _config = globalInstance.__DIGIPAIR_CONFIG__ = globalInstance.__DIGIPAIR_CONFIG__ ?? {
|
|
58
44
|
LIBRARIES: {},
|
|
59
45
|
BASE_URL: 'https://cdn.jsdelivr.net/npm',
|
|
60
46
|
ALIAS: [],
|
|
@@ -66,7 +52,10 @@ const isPinsSettings = (value)=>{
|
|
|
66
52
|
};
|
|
67
53
|
const config = {
|
|
68
54
|
set: (key, value)=>{
|
|
69
|
-
_config[key] = key === 'LIBRARIES' && _config[key] ?
|
|
55
|
+
_config[key] = key === 'LIBRARIES' && _config[key] ? {
|
|
56
|
+
..._config[key],
|
|
57
|
+
...value
|
|
58
|
+
} : value;
|
|
70
59
|
},
|
|
71
60
|
log: (level, path, message, context, data)=>_config.LOGGER(level, path, message, context, data)
|
|
72
61
|
};
|
|
@@ -77,15 +66,23 @@ const applyTemplate = (value, context)=>{
|
|
|
77
66
|
result = value.substring(7);
|
|
78
67
|
} else if (result.startsWith('EVALUATE:')) {
|
|
79
68
|
const path = result.replace(/^EVALUATE:/, '');
|
|
80
|
-
result = feelin.evaluate(path,
|
|
69
|
+
result = feelin.evaluate(path, {
|
|
70
|
+
...context,
|
|
71
|
+
...DIGIPAIR_FUNCTIONS
|
|
72
|
+
});
|
|
81
73
|
} else if (result.startsWith('FEEL:')) {
|
|
82
74
|
const path = result.replace(/^FEEL:/, '');
|
|
83
|
-
result = feelin.evaluate(path,
|
|
75
|
+
result = feelin.evaluate(path, {
|
|
76
|
+
...context,
|
|
77
|
+
...DIGIPAIR_FUNCTIONS
|
|
78
|
+
});
|
|
84
79
|
} else if (result.startsWith('CEL:')) {
|
|
85
80
|
const path = result.replace(/^CEL:/, '');
|
|
86
|
-
result = celJs.evaluate(path,
|
|
81
|
+
result = celJs.evaluate(path, {
|
|
82
|
+
...context
|
|
83
|
+
}, DIGIPAIR_FUNCTIONS);
|
|
87
84
|
} else {
|
|
88
|
-
const template =
|
|
85
|
+
const template = Handlebars.compile(value, {
|
|
89
86
|
noEscape: true
|
|
90
87
|
});
|
|
91
88
|
result = template(context);
|
|
@@ -101,32 +98,37 @@ const applyTemplate = (value, context)=>{
|
|
|
101
98
|
return result;
|
|
102
99
|
};
|
|
103
100
|
const executePins = async (settingsOrigin, context = {})=>{
|
|
104
|
-
var _settings_conditions, _settings_conditions1;
|
|
105
101
|
let settings = preparePinsSettings(settingsOrigin, context);
|
|
106
102
|
_config.LOGGER('INFO', context.__PATH__, `execute:${settings.library}:${settings.element}:start`, context, settings);
|
|
107
103
|
const alias = _config.ALIAS.find((alias)=>settings.library.split(':')[0] === alias.name);
|
|
108
104
|
const config = context.config || {};
|
|
109
105
|
let version = (config.VERSIONS || {})[settings.library] || 'latest';
|
|
110
106
|
if (alias) {
|
|
111
|
-
settings = preparePinsSettings(
|
|
112
|
-
settings
|
|
107
|
+
settings = preparePinsSettings({
|
|
108
|
+
...settings,
|
|
109
|
+
...alias
|
|
110
|
+
}, {
|
|
111
|
+
settings: {
|
|
112
|
+
...settings,
|
|
113
113
|
version,
|
|
114
114
|
library: settings.library.substring(alias.name.length + 1)
|
|
115
|
-
}
|
|
115
|
+
}
|
|
116
116
|
});
|
|
117
117
|
version = (config.VERSIONS || {})[settings.library] || 'latest';
|
|
118
118
|
}
|
|
119
|
-
if (
|
|
119
|
+
if (settings.conditions?.each) {
|
|
120
120
|
const results = [];
|
|
121
121
|
for(let index = 0; index < settings.conditions.each.length; index++){
|
|
122
|
-
var _itemSettings_conditions;
|
|
123
122
|
const item = settings.conditions.each[index];
|
|
124
|
-
const itemSettingsOrigin =
|
|
125
|
-
|
|
123
|
+
const itemSettingsOrigin = {
|
|
124
|
+
...settingsOrigin,
|
|
125
|
+
conditions: {
|
|
126
|
+
...settingsOrigin.conditions,
|
|
126
127
|
each: undefined
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
const itemContext =
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
const itemContext = {
|
|
131
|
+
...context,
|
|
130
132
|
item,
|
|
131
133
|
index,
|
|
132
134
|
parent: {
|
|
@@ -134,9 +136,9 @@ const executePins = async (settingsOrigin, context = {})=>{
|
|
|
134
136
|
index: context.index,
|
|
135
137
|
parent: context.parent
|
|
136
138
|
}
|
|
137
|
-
}
|
|
139
|
+
};
|
|
138
140
|
const itemSettings = preparePinsSettings(itemSettingsOrigin, itemContext);
|
|
139
|
-
if (typeof
|
|
141
|
+
if (typeof itemSettings.conditions?.if !== 'undefined' && !itemSettings.conditions.if) {
|
|
140
142
|
continue;
|
|
141
143
|
}
|
|
142
144
|
let itemResult = null;
|
|
@@ -152,11 +154,11 @@ const executePins = async (settingsOrigin, context = {})=>{
|
|
|
152
154
|
}
|
|
153
155
|
return results;
|
|
154
156
|
}
|
|
155
|
-
if (typeof
|
|
157
|
+
if (typeof settings.conditions?.if !== 'undefined' && !settings.conditions.if) {
|
|
156
158
|
throw 'DIGIPAIR_CONDITIONS_IF_FALSE';
|
|
157
159
|
}
|
|
158
|
-
const library = _config.LIBRARIES[settings.library] || (typeof window === 'undefined' ? require(settings.library) : await (
|
|
159
|
-
const pins = library
|
|
160
|
+
const library = _config.LIBRARIES[settings.library] || (typeof window === 'undefined' ? require(settings.library) : await import(isRemoteVersion.test(version) ? `${version}` : `${_config.BASE_URL}/${settings.library}@${version}/index.esm.js`));
|
|
161
|
+
const pins = library?.[settings.element];
|
|
160
162
|
if (!pins) {
|
|
161
163
|
throw new Error(`Element ${settings.element} not found in library ${settings.library}`);
|
|
162
164
|
}
|
|
@@ -169,14 +171,15 @@ const executePinsList = async (pinsSettingsList, context, path = 'root')=>{
|
|
|
169
171
|
for(let i = 0; i < pinsSettingsList.length; i++){
|
|
170
172
|
const settings = pinsSettingsList[i];
|
|
171
173
|
try {
|
|
172
|
-
previous = await executePins(settings,
|
|
174
|
+
previous = await executePins(settings, {
|
|
175
|
+
...context,
|
|
173
176
|
previous,
|
|
174
177
|
parent: {
|
|
175
178
|
previous: context.previous,
|
|
176
179
|
parent: context.parent
|
|
177
180
|
},
|
|
178
181
|
__PATH__: `${path}[${i}]`
|
|
179
|
-
})
|
|
182
|
+
});
|
|
180
183
|
} catch (error) {
|
|
181
184
|
if (error === 'DIGIPAIR_CONDITIONS_IF_FALSE') {
|
|
182
185
|
continue;
|
|
@@ -189,22 +192,27 @@ const executePinsList = async (pinsSettingsList, context, path = 'root')=>{
|
|
|
189
192
|
const generateElementFromPins = async (pinsSettings, parent, context, document = typeof window !== 'undefined' ? window.document : global.document, options = {
|
|
190
193
|
import: true
|
|
191
194
|
})=>{
|
|
192
|
-
var _settings_conditions, _settings_conditions1;
|
|
193
195
|
let settings = preparePinsSettings(pinsSettings, context);
|
|
194
196
|
const alias = _config.ALIAS.find((alias)=>settings.library.split(':')[0] === alias.name);
|
|
195
197
|
if (alias) {
|
|
196
|
-
settings = preparePinsSettings(
|
|
198
|
+
settings = preparePinsSettings({
|
|
199
|
+
...settings,
|
|
200
|
+
...alias
|
|
201
|
+
}, {
|
|
197
202
|
settings
|
|
198
203
|
});
|
|
199
204
|
}
|
|
200
|
-
if (
|
|
205
|
+
if (settings.conditions?.each) {
|
|
201
206
|
for(let index = 0; index < settings.conditions.each.length; index++){
|
|
202
207
|
const item = settings.conditions.each[index];
|
|
203
|
-
await generateElementFromPins(
|
|
204
|
-
|
|
208
|
+
await generateElementFromPins({
|
|
209
|
+
...pinsSettings,
|
|
210
|
+
conditions: {
|
|
211
|
+
...pinsSettings.conditions,
|
|
205
212
|
each: undefined
|
|
206
|
-
}
|
|
207
|
-
}
|
|
213
|
+
}
|
|
214
|
+
}, parent, {
|
|
215
|
+
...context,
|
|
208
216
|
item,
|
|
209
217
|
index,
|
|
210
218
|
parent: {
|
|
@@ -212,11 +220,11 @@ const generateElementFromPins = async (pinsSettings, parent, context, document =
|
|
|
212
220
|
index: context.index,
|
|
213
221
|
parent: context.parent
|
|
214
222
|
}
|
|
215
|
-
}
|
|
223
|
+
}, document, options);
|
|
216
224
|
}
|
|
217
225
|
return;
|
|
218
226
|
}
|
|
219
|
-
if (typeof
|
|
227
|
+
if (typeof settings.conditions?.if !== 'undefined' && !settings.conditions.if) {
|
|
220
228
|
return;
|
|
221
229
|
}
|
|
222
230
|
const element = document.createElement(pinsSettings.element);
|
|
@@ -227,7 +235,7 @@ const generateElementFromPins = async (pinsSettings, parent, context, document =
|
|
|
227
235
|
if (options.import && library !== 'web' && !_config.LIBRARIES[library]) {
|
|
228
236
|
const config = context.config || {};
|
|
229
237
|
const version = (config.VERSIONS || {})[library] || 'latest';
|
|
230
|
-
(
|
|
238
|
+
import(isRemoteVersion.test(version) ? `${version}` : `${_config.BASE_URL}/${library}@${version}/index.esm.js`);
|
|
231
239
|
}
|
|
232
240
|
Object.entries(settings.properties || {}).forEach(([key, value])=>{
|
|
233
241
|
if (key === 'textContent') {
|
|
@@ -243,9 +251,10 @@ const generateElementFromPins = async (pinsSettings, parent, context, document =
|
|
|
243
251
|
Object.entries(settings.events || {}).forEach(([key, pinsList])=>{
|
|
244
252
|
element.addEventListener(key, (_event)=>{
|
|
245
253
|
const event = _event;
|
|
246
|
-
executePinsList(pinsList,
|
|
254
|
+
executePinsList(pinsList, {
|
|
255
|
+
...context,
|
|
247
256
|
event: event.detail
|
|
248
|
-
}
|
|
257
|
+
}, `${context.__PATH__}.events[${key}]`);
|
|
249
258
|
});
|
|
250
259
|
});
|
|
251
260
|
const pinsList = settings.pins || [];
|
|
@@ -253,18 +262,19 @@ const generateElementFromPins = async (pinsSettings, parent, context, document =
|
|
|
253
262
|
const item = pinsList[i];
|
|
254
263
|
await generateElementFromPins(item, element, context, document, options);
|
|
255
264
|
}
|
|
256
|
-
if (
|
|
265
|
+
if (parent?.nodeName === 'TEMPLATE') {
|
|
257
266
|
parent.content.appendChild(element);
|
|
258
267
|
} else {
|
|
259
|
-
parent
|
|
268
|
+
parent?.appendChild(element);
|
|
260
269
|
}
|
|
261
270
|
return element;
|
|
262
271
|
};
|
|
263
272
|
const preparePinsSettings = (settings, context)=>{
|
|
264
|
-
const localContext =
|
|
273
|
+
const localContext = {
|
|
274
|
+
...context,
|
|
265
275
|
variables: context.variables || {},
|
|
266
276
|
conditions: context.conditions || {}
|
|
267
|
-
}
|
|
277
|
+
};
|
|
268
278
|
const conditions = {};
|
|
269
279
|
for (const [key, value] of Object.entries(settings.conditions || {})){
|
|
270
280
|
conditions[key] = applyTemplate(value, localContext);
|
|
@@ -273,10 +283,11 @@ const preparePinsSettings = (settings, context)=>{
|
|
|
273
283
|
for (const [key, value] of Object.entries(settings.properties || {})){
|
|
274
284
|
properties[key] = applyTemplate(value, localContext);
|
|
275
285
|
}
|
|
276
|
-
return
|
|
286
|
+
return {
|
|
287
|
+
...settings,
|
|
277
288
|
properties,
|
|
278
289
|
conditions
|
|
279
|
-
}
|
|
290
|
+
};
|
|
280
291
|
};
|
|
281
292
|
|
|
282
293
|
exports.applyTemplate = applyTemplate;
|