@mulsense/xnew 0.6.6 → 0.6.8
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/dist/addons/xpixi.js +1 -1
- package/dist/addons/xpixi.mjs +1 -1
- package/dist/xnew.d.ts +26 -17
- package/dist/xnew.js +49 -29
- package/dist/xnew.mjs +49 -29
- package/package.json +1 -1
package/dist/addons/xpixi.js
CHANGED
package/dist/addons/xpixi.mjs
CHANGED
package/dist/xnew.d.ts
CHANGED
|
@@ -57,16 +57,21 @@ interface Snapshot {
|
|
|
57
57
|
}
|
|
58
58
|
interface Internal {
|
|
59
59
|
parent: Unit | null;
|
|
60
|
+
ancestors: Unit[];
|
|
61
|
+
children: Unit[];
|
|
60
62
|
state: string;
|
|
61
63
|
tostart: boolean;
|
|
62
64
|
protected: boolean;
|
|
65
|
+
promises: UnitPromise[];
|
|
66
|
+
results: Record<string, any>;
|
|
67
|
+
defines: Record<string, any>;
|
|
68
|
+
systems: Record<string, {
|
|
69
|
+
listener: Function;
|
|
70
|
+
execute: Function;
|
|
71
|
+
}[]>;
|
|
63
72
|
currentElement: UnitElement;
|
|
64
73
|
currentContext: Context;
|
|
65
74
|
currentComponent: Function | null;
|
|
66
|
-
ancestors: Unit[];
|
|
67
|
-
children: Unit[];
|
|
68
|
-
promises: UnitPromise[];
|
|
69
|
-
results: Record<string, any>;
|
|
70
75
|
nestElements: {
|
|
71
76
|
element: UnitElement;
|
|
72
77
|
owned: boolean;
|
|
@@ -77,11 +82,6 @@ interface Internal {
|
|
|
77
82
|
Component: Function | null;
|
|
78
83
|
execute: Function;
|
|
79
84
|
}>;
|
|
80
|
-
defines: Record<string, any>;
|
|
81
|
-
systems: Record<string, {
|
|
82
|
-
listener: Function;
|
|
83
|
-
execute: Function;
|
|
84
|
-
}[]>;
|
|
85
85
|
eventor: Eventor;
|
|
86
86
|
}
|
|
87
87
|
declare class Unit {
|
|
@@ -179,10 +179,13 @@ declare function Accordion(unit: Unit): void;
|
|
|
179
179
|
declare function Popup(unit: Unit): void;
|
|
180
180
|
|
|
181
181
|
type ScreenFit = 'contain' | 'cover';
|
|
182
|
-
declare function Screen(unit: Unit, {
|
|
183
|
-
|
|
182
|
+
declare function Screen(unit: Unit, { width, height, fit }?: {
|
|
183
|
+
width?: number;
|
|
184
|
+
height?: number;
|
|
184
185
|
fit?: ScreenFit;
|
|
185
|
-
}):
|
|
186
|
+
}): {
|
|
187
|
+
readonly canvas: UnitElement;
|
|
188
|
+
};
|
|
186
189
|
|
|
187
190
|
declare function AnalogStick(unit: Unit, { stroke, strokeOpacity, strokeWidth, strokeLinejoin, fill, fillOpacity }?: {
|
|
188
191
|
stroke?: string;
|
|
@@ -208,7 +211,7 @@ interface PanelOptions {
|
|
|
208
211
|
open?: boolean;
|
|
209
212
|
params?: Record<string, any>;
|
|
210
213
|
}
|
|
211
|
-
declare function Panel(unit: Unit, {
|
|
214
|
+
declare function Panel(unit: Unit, { params }: PanelOptions): {
|
|
212
215
|
group({ name, open, params }: PanelOptions, inner: Function): Unit;
|
|
213
216
|
button(key: string): Unit;
|
|
214
217
|
select(key: string, { value, items }?: {
|
|
@@ -227,6 +230,12 @@ declare function Panel(unit: Unit, { name, open, params }: PanelOptions): {
|
|
|
227
230
|
separator(): void;
|
|
228
231
|
};
|
|
229
232
|
|
|
233
|
+
declare function Flow(unit: Unit): {
|
|
234
|
+
get scene(): Unit | null;
|
|
235
|
+
set scene(value: Unit);
|
|
236
|
+
next(Component: Function, props?: any): void;
|
|
237
|
+
};
|
|
238
|
+
|
|
230
239
|
type SynthesizerOptions = {
|
|
231
240
|
oscillator: OscillatorOptions;
|
|
232
241
|
amp: AmpOptions;
|
|
@@ -276,15 +285,14 @@ declare const xnew: CreateUnit & {
|
|
|
276
285
|
extend(Component: Function, props?: Object): {
|
|
277
286
|
[key: string]: any;
|
|
278
287
|
};
|
|
279
|
-
context(
|
|
288
|
+
context(key: any): any;
|
|
280
289
|
promise(promise: Function | Promise<any> | Unit): UnitPromise;
|
|
281
290
|
then(callback: Function): UnitPromise;
|
|
282
291
|
catch(callback: Function): UnitPromise;
|
|
283
|
-
|
|
284
|
-
reject(reason?: any): void;
|
|
292
|
+
commit(object?: Record<string, any>): void;
|
|
285
293
|
finally(callback: Function): UnitPromise;
|
|
286
294
|
scope(callback: any): any;
|
|
287
|
-
find(
|
|
295
|
+
find(Component: Function): Unit[];
|
|
288
296
|
emit(type: string, ...args: any[]): void;
|
|
289
297
|
timeout(callback: Function, duration?: number): UnitTimer;
|
|
290
298
|
interval(callback: Function, duration: number, iterations?: number): UnitTimer;
|
|
@@ -299,6 +307,7 @@ declare const xnew: CreateUnit & {
|
|
|
299
307
|
Panel: typeof Panel;
|
|
300
308
|
Accordion: typeof Accordion;
|
|
301
309
|
Popup: typeof Popup;
|
|
310
|
+
Flow: typeof Flow;
|
|
302
311
|
};
|
|
303
312
|
audio: {
|
|
304
313
|
load(path: string): UnitPromise;
|
package/dist/xnew.js
CHANGED
|
@@ -621,7 +621,6 @@
|
|
|
621
621
|
});
|
|
622
622
|
Unit.unit2Contexts.delete(unit);
|
|
623
623
|
unit._.currentContext = { previous: null };
|
|
624
|
-
// reset defines
|
|
625
624
|
Object.keys(unit._.defines).forEach((key) => {
|
|
626
625
|
delete unit[key];
|
|
627
626
|
});
|
|
@@ -663,6 +662,10 @@
|
|
|
663
662
|
else {
|
|
664
663
|
const backupComponent = unit._.currentComponent;
|
|
665
664
|
unit._.currentComponent = Component;
|
|
665
|
+
if (unit._.parent !== null) {
|
|
666
|
+
Unit.addContext(unit._.parent, unit, Component, unit);
|
|
667
|
+
}
|
|
668
|
+
Unit.addContext(unit, unit, Component, unit);
|
|
666
669
|
const defines = (_a = Component(unit, props !== null && props !== void 0 ? props : {})) !== null && _a !== void 0 ? _a : {};
|
|
667
670
|
unit._.currentComponent = backupComponent;
|
|
668
671
|
Unit.component2units.add(Component, unit);
|
|
@@ -766,6 +769,8 @@
|
|
|
766
769
|
}
|
|
767
770
|
static getContext(unit, key) {
|
|
768
771
|
for (let context = unit._.currentContext; context.previous !== null; context = context.previous) {
|
|
772
|
+
if (context.value === Unit.currentUnit && key === Unit.currentUnit._.currentComponent)
|
|
773
|
+
continue;
|
|
769
774
|
if (context.key === key)
|
|
770
775
|
return context.value;
|
|
771
776
|
}
|
|
@@ -934,7 +939,6 @@
|
|
|
934
939
|
const Component = args.shift();
|
|
935
940
|
const props = args.shift();
|
|
936
941
|
const unit = new Unit(Unit.currentUnit, target, Component, props);
|
|
937
|
-
Unit.addContext(Unit.currentUnit, unit, Component, unit);
|
|
938
942
|
return unit;
|
|
939
943
|
}, {
|
|
940
944
|
/**
|
|
@@ -973,7 +977,6 @@
|
|
|
973
977
|
throw new Error('xnew.extend can not be called after initialized.');
|
|
974
978
|
}
|
|
975
979
|
const defines = Unit.extend(Unit.currentUnit, Component, props);
|
|
976
|
-
Unit.addContext(Unit.currentUnit, Unit.currentUnit, Component, Unit.currentUnit);
|
|
977
980
|
return defines;
|
|
978
981
|
}
|
|
979
982
|
catch (error) {
|
|
@@ -1014,9 +1017,8 @@
|
|
|
1014
1017
|
const Component = Unit.currentUnit._.currentComponent;
|
|
1015
1018
|
let unitPromise;
|
|
1016
1019
|
if (promise instanceof Unit) {
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
.then(() => unit._.results);
|
|
1020
|
+
unitPromise = new UnitPromise(Promise.all(promise._.promises.map(p => p.promise)), Component)
|
|
1021
|
+
.then(() => promise._.results);
|
|
1020
1022
|
}
|
|
1021
1023
|
else if (promise instanceof Promise) {
|
|
1022
1024
|
unitPromise = new UnitPromise(promise, Component);
|
|
@@ -1042,12 +1044,8 @@
|
|
|
1042
1044
|
then(callback) {
|
|
1043
1045
|
try {
|
|
1044
1046
|
const currentUnit = Unit.currentUnit;
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
return new UnitPromise(Promise.all(promises.map(p => p.promise)), null)
|
|
1048
|
-
.then(() => {
|
|
1049
|
-
callback(currentUnit._.results);
|
|
1050
|
-
});
|
|
1047
|
+
return new UnitPromise(Promise.all(Unit.currentUnit._.promises.map(p => p.promise)), null)
|
|
1048
|
+
.then(() => callback(currentUnit._.results));
|
|
1051
1049
|
}
|
|
1052
1050
|
catch (error) {
|
|
1053
1051
|
console.error('xnew.then(callback: Function): ', error);
|
|
@@ -1063,8 +1061,7 @@
|
|
|
1063
1061
|
*/
|
|
1064
1062
|
catch(callback) {
|
|
1065
1063
|
try {
|
|
1066
|
-
|
|
1067
|
-
return new UnitPromise(Promise.all(promises.map(p => p.promise)), null)
|
|
1064
|
+
return new UnitPromise(Promise.all(Unit.currentUnit._.promises.map(p => p.promise)), null)
|
|
1068
1065
|
.catch(callback);
|
|
1069
1066
|
}
|
|
1070
1067
|
catch (error) {
|
|
@@ -1073,18 +1070,18 @@
|
|
|
1073
1070
|
}
|
|
1074
1071
|
},
|
|
1075
1072
|
/**
|
|
1076
|
-
*
|
|
1077
|
-
* @param object - object to
|
|
1073
|
+
* Commits a value to the current unit's promise results
|
|
1074
|
+
* @param object - object to commit to the promise
|
|
1078
1075
|
* @returns void
|
|
1079
1076
|
* @example
|
|
1080
|
-
* xnew.
|
|
1077
|
+
* xnew.commit({ data: 123});
|
|
1081
1078
|
*/
|
|
1082
|
-
|
|
1079
|
+
commit(object) {
|
|
1083
1080
|
try {
|
|
1084
1081
|
Object.assign(Unit.currentUnit._.results, object);
|
|
1085
1082
|
}
|
|
1086
1083
|
catch (error) {
|
|
1087
|
-
console.error('xnew.
|
|
1084
|
+
console.error('xnew.commit(object?: Record<string, any>): ', error);
|
|
1088
1085
|
throw error;
|
|
1089
1086
|
}
|
|
1090
1087
|
},
|
|
@@ -1097,8 +1094,7 @@
|
|
|
1097
1094
|
*/
|
|
1098
1095
|
finally(callback) {
|
|
1099
1096
|
try {
|
|
1100
|
-
|
|
1101
|
-
return new UnitPromise(Promise.all(promises.map(p => p.promise)), null)
|
|
1097
|
+
return new UnitPromise(Promise.all(Unit.currentUnit._.promises.map(p => p.promise)), null)
|
|
1102
1098
|
.finally(callback);
|
|
1103
1099
|
}
|
|
1104
1100
|
catch (error) {
|
|
@@ -1266,7 +1262,8 @@
|
|
|
1266
1262
|
});
|
|
1267
1263
|
}
|
|
1268
1264
|
|
|
1269
|
-
function Screen(unit, {
|
|
1265
|
+
function Screen(unit, { width = 800, height = 600, fit = 'contain' } = {}) {
|
|
1266
|
+
const aspect = width / height;
|
|
1270
1267
|
xnew$1.nest('<div style="width: 100%; height: 100%; display: flex; align-items: center; justify-content: center; container-type: size; overflow: hidden;">');
|
|
1271
1268
|
xnew$1.nest(`<div style="position: relative; aspect-ratio: ${aspect}; container-type: size; overflow: hidden;">`);
|
|
1272
1269
|
if (fit === 'contain') {
|
|
@@ -1276,6 +1273,10 @@
|
|
|
1276
1273
|
unit.element.style.flexShrink = '0';
|
|
1277
1274
|
unit.element.style.width = `max(100cqw, calc(100cqh * ${aspect}))`;
|
|
1278
1275
|
}
|
|
1276
|
+
const canvas = xnew$1(`<canvas width="${width}" height="${height}" style="width: 100%; height: 100%; vertical-align: bottom;">`);
|
|
1277
|
+
return {
|
|
1278
|
+
get canvas() { return canvas.element; }
|
|
1279
|
+
};
|
|
1279
1280
|
}
|
|
1280
1281
|
|
|
1281
1282
|
//----------------------------------------------------------------------------------------------------
|
|
@@ -1284,14 +1285,14 @@
|
|
|
1284
1285
|
function SVGTemplate(self, { stroke = 'currentColor', strokeOpacity = 0.8, strokeWidth = 1, strokeLinejoin = 'round', fill = null, fillOpacity = 0.8 }) {
|
|
1285
1286
|
xnew$1.nest(`<svg
|
|
1286
1287
|
viewBox="0 0 64 64"
|
|
1287
|
-
style="position: absolute; width: 100%; height: 100%; user-select: none;
|
|
1288
|
+
style="position: absolute; width: 100%; height: 100%; user-select: none; -webkit-user-select: none;
|
|
1288
1289
|
stroke: ${stroke}; stroke-opacity: ${strokeOpacity}; stroke-width: ${strokeWidth}; stroke-linejoin: ${strokeLinejoin};
|
|
1289
1290
|
${fill ? `fill: ${fill}; fill-opacity: ${fillOpacity};` : ''}
|
|
1290
1291
|
">`);
|
|
1291
1292
|
}
|
|
1292
1293
|
function AnalogStick(unit, { stroke = 'currentColor', strokeOpacity = 0.8, strokeWidth = 1, strokeLinejoin = 'round', fill = '#FFF', fillOpacity = 0.8 } = {}) {
|
|
1293
1294
|
xnew$1.nest(`<div style="width: 100%; height: 100%; display: flex; align-items: center; justify-content: center; container-type: size;">`);
|
|
1294
|
-
xnew$1.nest(`<div style="width: min(100cqw, 100cqh); aspect-ratio: 1; cursor: pointer; user-select: none; pointer-events: auto; overflow: hidden;">`);
|
|
1295
|
+
xnew$1.nest(`<div style="width: min(100cqw, 100cqh); aspect-ratio: 1; cursor: pointer; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; touch-action: none; pointer-events: auto; overflow: hidden;">`);
|
|
1295
1296
|
xnew$1((unit) => {
|
|
1296
1297
|
xnew$1.extend(SVGTemplate, { fill, fillOpacity, stroke, strokeOpacity, strokeWidth, strokeLinejoin });
|
|
1297
1298
|
xnew$1('<polygon points="32 7 27 13 37 13">');
|
|
@@ -1327,7 +1328,7 @@
|
|
|
1327
1328
|
}
|
|
1328
1329
|
function DPad(unit, { diagonal = true, stroke = 'currentColor', strokeOpacity = 0.8, strokeWidth = 1, strokeLinejoin = 'round', fill = '#FFF', fillOpacity = 0.8 } = {}) {
|
|
1329
1330
|
xnew$1.nest(`<div style="width: 100%; height: 100%; display: flex; align-items: center; justify-content: center; container-type: size;">`);
|
|
1330
|
-
xnew$1.nest(`<div style="width: min(100cqw, 100cqh); aspect-ratio: 1; cursor: pointer; user-select: none; pointer-events: auto; overflow: hidden;">`);
|
|
1331
|
+
xnew$1.nest(`<div style="width: min(100cqw, 100cqh); aspect-ratio: 1; cursor: pointer; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; touch-action: none; pointer-events: auto; overflow: hidden;">`);
|
|
1331
1332
|
const polygons = [
|
|
1332
1333
|
'<polygon points="32 32 23 23 23 4 24 3 40 3 41 4 41 23">',
|
|
1333
1334
|
'<polygon points="32 32 23 41 23 60 24 61 40 61 41 60 41 41">',
|
|
@@ -1389,13 +1390,13 @@
|
|
|
1389
1390
|
|
|
1390
1391
|
const currentColorA = 'color-mix(in srgb, currentColor 70%, transparent)';
|
|
1391
1392
|
const currentColorB = 'color-mix(in srgb, currentColor 10%, transparent)';
|
|
1392
|
-
function Panel(unit, {
|
|
1393
|
+
function Panel(unit, { params }) {
|
|
1393
1394
|
const object = params !== null && params !== void 0 ? params : {};
|
|
1394
|
-
xnew$1.extend(Group, { name, open });
|
|
1395
1395
|
return {
|
|
1396
1396
|
group({ name, open, params }, inner) {
|
|
1397
1397
|
const group = xnew$1((unit) => {
|
|
1398
|
-
xnew$1.extend(
|
|
1398
|
+
xnew$1.extend(Group, { name, open });
|
|
1399
|
+
xnew$1.extend(Panel, { params: params !== null && params !== void 0 ? params : object });
|
|
1399
1400
|
inner(unit);
|
|
1400
1401
|
});
|
|
1401
1402
|
return group;
|
|
@@ -1437,7 +1438,7 @@
|
|
|
1437
1438
|
unit.on('click', () => group.toggle());
|
|
1438
1439
|
xnew$1('<svg viewBox="0 0 12 12" style="width: 1em; height: 1em; margin-right: 0.25em;" fill="none" stroke="currentColor">', (unit) => {
|
|
1439
1440
|
xnew$1('<path d="M6 2 10 6 6 10" />');
|
|
1440
|
-
group.on('-transition', ({
|
|
1441
|
+
group.on('-transition', ({ value }) => unit.element.style.transform = `rotate(${value * 90}deg)`);
|
|
1441
1442
|
});
|
|
1442
1443
|
xnew$1('<div>', name);
|
|
1443
1444
|
});
|
|
@@ -1560,6 +1561,24 @@
|
|
|
1560
1561
|
}
|
|
1561
1562
|
}
|
|
1562
1563
|
|
|
1564
|
+
function Flow(unit) {
|
|
1565
|
+
let scene = null;
|
|
1566
|
+
return {
|
|
1567
|
+
set scene(value) {
|
|
1568
|
+
scene = value;
|
|
1569
|
+
},
|
|
1570
|
+
get scene() {
|
|
1571
|
+
return scene;
|
|
1572
|
+
},
|
|
1573
|
+
next(Component, props) {
|
|
1574
|
+
var _a;
|
|
1575
|
+
// scene change
|
|
1576
|
+
(_a = unit.scene) === null || _a === void 0 ? void 0 : _a.finalize();
|
|
1577
|
+
unit.scene = xnew$1(Component, props);
|
|
1578
|
+
}
|
|
1579
|
+
};
|
|
1580
|
+
}
|
|
1581
|
+
|
|
1563
1582
|
const context = new window.AudioContext();
|
|
1564
1583
|
const master = context.createGain();
|
|
1565
1584
|
//----------------------------------------------------------------------------------------------------
|
|
@@ -1792,6 +1811,7 @@
|
|
|
1792
1811
|
Panel,
|
|
1793
1812
|
Accordion,
|
|
1794
1813
|
Popup,
|
|
1814
|
+
Flow,
|
|
1795
1815
|
};
|
|
1796
1816
|
const audio = {
|
|
1797
1817
|
load(path) {
|
package/dist/xnew.mjs
CHANGED
|
@@ -615,7 +615,6 @@ class Unit {
|
|
|
615
615
|
});
|
|
616
616
|
Unit.unit2Contexts.delete(unit);
|
|
617
617
|
unit._.currentContext = { previous: null };
|
|
618
|
-
// reset defines
|
|
619
618
|
Object.keys(unit._.defines).forEach((key) => {
|
|
620
619
|
delete unit[key];
|
|
621
620
|
});
|
|
@@ -657,6 +656,10 @@ class Unit {
|
|
|
657
656
|
else {
|
|
658
657
|
const backupComponent = unit._.currentComponent;
|
|
659
658
|
unit._.currentComponent = Component;
|
|
659
|
+
if (unit._.parent !== null) {
|
|
660
|
+
Unit.addContext(unit._.parent, unit, Component, unit);
|
|
661
|
+
}
|
|
662
|
+
Unit.addContext(unit, unit, Component, unit);
|
|
660
663
|
const defines = (_a = Component(unit, props !== null && props !== void 0 ? props : {})) !== null && _a !== void 0 ? _a : {};
|
|
661
664
|
unit._.currentComponent = backupComponent;
|
|
662
665
|
Unit.component2units.add(Component, unit);
|
|
@@ -760,6 +763,8 @@ class Unit {
|
|
|
760
763
|
}
|
|
761
764
|
static getContext(unit, key) {
|
|
762
765
|
for (let context = unit._.currentContext; context.previous !== null; context = context.previous) {
|
|
766
|
+
if (context.value === Unit.currentUnit && key === Unit.currentUnit._.currentComponent)
|
|
767
|
+
continue;
|
|
763
768
|
if (context.key === key)
|
|
764
769
|
return context.value;
|
|
765
770
|
}
|
|
@@ -928,7 +933,6 @@ const xnew$1 = Object.assign(function (...args) {
|
|
|
928
933
|
const Component = args.shift();
|
|
929
934
|
const props = args.shift();
|
|
930
935
|
const unit = new Unit(Unit.currentUnit, target, Component, props);
|
|
931
|
-
Unit.addContext(Unit.currentUnit, unit, Component, unit);
|
|
932
936
|
return unit;
|
|
933
937
|
}, {
|
|
934
938
|
/**
|
|
@@ -967,7 +971,6 @@ const xnew$1 = Object.assign(function (...args) {
|
|
|
967
971
|
throw new Error('xnew.extend can not be called after initialized.');
|
|
968
972
|
}
|
|
969
973
|
const defines = Unit.extend(Unit.currentUnit, Component, props);
|
|
970
|
-
Unit.addContext(Unit.currentUnit, Unit.currentUnit, Component, Unit.currentUnit);
|
|
971
974
|
return defines;
|
|
972
975
|
}
|
|
973
976
|
catch (error) {
|
|
@@ -1008,9 +1011,8 @@ const xnew$1 = Object.assign(function (...args) {
|
|
|
1008
1011
|
const Component = Unit.currentUnit._.currentComponent;
|
|
1009
1012
|
let unitPromise;
|
|
1010
1013
|
if (promise instanceof Unit) {
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
.then(() => unit._.results);
|
|
1014
|
+
unitPromise = new UnitPromise(Promise.all(promise._.promises.map(p => p.promise)), Component)
|
|
1015
|
+
.then(() => promise._.results);
|
|
1014
1016
|
}
|
|
1015
1017
|
else if (promise instanceof Promise) {
|
|
1016
1018
|
unitPromise = new UnitPromise(promise, Component);
|
|
@@ -1036,12 +1038,8 @@ const xnew$1 = Object.assign(function (...args) {
|
|
|
1036
1038
|
then(callback) {
|
|
1037
1039
|
try {
|
|
1038
1040
|
const currentUnit = Unit.currentUnit;
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
return new UnitPromise(Promise.all(promises.map(p => p.promise)), null)
|
|
1042
|
-
.then(() => {
|
|
1043
|
-
callback(currentUnit._.results);
|
|
1044
|
-
});
|
|
1041
|
+
return new UnitPromise(Promise.all(Unit.currentUnit._.promises.map(p => p.promise)), null)
|
|
1042
|
+
.then(() => callback(currentUnit._.results));
|
|
1045
1043
|
}
|
|
1046
1044
|
catch (error) {
|
|
1047
1045
|
console.error('xnew.then(callback: Function): ', error);
|
|
@@ -1057,8 +1055,7 @@ const xnew$1 = Object.assign(function (...args) {
|
|
|
1057
1055
|
*/
|
|
1058
1056
|
catch(callback) {
|
|
1059
1057
|
try {
|
|
1060
|
-
|
|
1061
|
-
return new UnitPromise(Promise.all(promises.map(p => p.promise)), null)
|
|
1058
|
+
return new UnitPromise(Promise.all(Unit.currentUnit._.promises.map(p => p.promise)), null)
|
|
1062
1059
|
.catch(callback);
|
|
1063
1060
|
}
|
|
1064
1061
|
catch (error) {
|
|
@@ -1067,18 +1064,18 @@ const xnew$1 = Object.assign(function (...args) {
|
|
|
1067
1064
|
}
|
|
1068
1065
|
},
|
|
1069
1066
|
/**
|
|
1070
|
-
*
|
|
1071
|
-
* @param object - object to
|
|
1067
|
+
* Commits a value to the current unit's promise results
|
|
1068
|
+
* @param object - object to commit to the promise
|
|
1072
1069
|
* @returns void
|
|
1073
1070
|
* @example
|
|
1074
|
-
* xnew.
|
|
1071
|
+
* xnew.commit({ data: 123});
|
|
1075
1072
|
*/
|
|
1076
|
-
|
|
1073
|
+
commit(object) {
|
|
1077
1074
|
try {
|
|
1078
1075
|
Object.assign(Unit.currentUnit._.results, object);
|
|
1079
1076
|
}
|
|
1080
1077
|
catch (error) {
|
|
1081
|
-
console.error('xnew.
|
|
1078
|
+
console.error('xnew.commit(object?: Record<string, any>): ', error);
|
|
1082
1079
|
throw error;
|
|
1083
1080
|
}
|
|
1084
1081
|
},
|
|
@@ -1091,8 +1088,7 @@ const xnew$1 = Object.assign(function (...args) {
|
|
|
1091
1088
|
*/
|
|
1092
1089
|
finally(callback) {
|
|
1093
1090
|
try {
|
|
1094
|
-
|
|
1095
|
-
return new UnitPromise(Promise.all(promises.map(p => p.promise)), null)
|
|
1091
|
+
return new UnitPromise(Promise.all(Unit.currentUnit._.promises.map(p => p.promise)), null)
|
|
1096
1092
|
.finally(callback);
|
|
1097
1093
|
}
|
|
1098
1094
|
catch (error) {
|
|
@@ -1260,7 +1256,8 @@ function Popup(unit) {
|
|
|
1260
1256
|
});
|
|
1261
1257
|
}
|
|
1262
1258
|
|
|
1263
|
-
function Screen(unit, {
|
|
1259
|
+
function Screen(unit, { width = 800, height = 600, fit = 'contain' } = {}) {
|
|
1260
|
+
const aspect = width / height;
|
|
1264
1261
|
xnew$1.nest('<div style="width: 100%; height: 100%; display: flex; align-items: center; justify-content: center; container-type: size; overflow: hidden;">');
|
|
1265
1262
|
xnew$1.nest(`<div style="position: relative; aspect-ratio: ${aspect}; container-type: size; overflow: hidden;">`);
|
|
1266
1263
|
if (fit === 'contain') {
|
|
@@ -1270,6 +1267,10 @@ function Screen(unit, { aspect, fit = 'contain' } = {}) {
|
|
|
1270
1267
|
unit.element.style.flexShrink = '0';
|
|
1271
1268
|
unit.element.style.width = `max(100cqw, calc(100cqh * ${aspect}))`;
|
|
1272
1269
|
}
|
|
1270
|
+
const canvas = xnew$1(`<canvas width="${width}" height="${height}" style="width: 100%; height: 100%; vertical-align: bottom;">`);
|
|
1271
|
+
return {
|
|
1272
|
+
get canvas() { return canvas.element; }
|
|
1273
|
+
};
|
|
1273
1274
|
}
|
|
1274
1275
|
|
|
1275
1276
|
//----------------------------------------------------------------------------------------------------
|
|
@@ -1278,14 +1279,14 @@ function Screen(unit, { aspect, fit = 'contain' } = {}) {
|
|
|
1278
1279
|
function SVGTemplate(self, { stroke = 'currentColor', strokeOpacity = 0.8, strokeWidth = 1, strokeLinejoin = 'round', fill = null, fillOpacity = 0.8 }) {
|
|
1279
1280
|
xnew$1.nest(`<svg
|
|
1280
1281
|
viewBox="0 0 64 64"
|
|
1281
|
-
style="position: absolute; width: 100%; height: 100%; user-select: none;
|
|
1282
|
+
style="position: absolute; width: 100%; height: 100%; user-select: none; -webkit-user-select: none;
|
|
1282
1283
|
stroke: ${stroke}; stroke-opacity: ${strokeOpacity}; stroke-width: ${strokeWidth}; stroke-linejoin: ${strokeLinejoin};
|
|
1283
1284
|
${fill ? `fill: ${fill}; fill-opacity: ${fillOpacity};` : ''}
|
|
1284
1285
|
">`);
|
|
1285
1286
|
}
|
|
1286
1287
|
function AnalogStick(unit, { stroke = 'currentColor', strokeOpacity = 0.8, strokeWidth = 1, strokeLinejoin = 'round', fill = '#FFF', fillOpacity = 0.8 } = {}) {
|
|
1287
1288
|
xnew$1.nest(`<div style="width: 100%; height: 100%; display: flex; align-items: center; justify-content: center; container-type: size;">`);
|
|
1288
|
-
xnew$1.nest(`<div style="width: min(100cqw, 100cqh); aspect-ratio: 1; cursor: pointer; user-select: none; pointer-events: auto; overflow: hidden;">`);
|
|
1289
|
+
xnew$1.nest(`<div style="width: min(100cqw, 100cqh); aspect-ratio: 1; cursor: pointer; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; touch-action: none; pointer-events: auto; overflow: hidden;">`);
|
|
1289
1290
|
xnew$1((unit) => {
|
|
1290
1291
|
xnew$1.extend(SVGTemplate, { fill, fillOpacity, stroke, strokeOpacity, strokeWidth, strokeLinejoin });
|
|
1291
1292
|
xnew$1('<polygon points="32 7 27 13 37 13">');
|
|
@@ -1321,7 +1322,7 @@ function AnalogStick(unit, { stroke = 'currentColor', strokeOpacity = 0.8, strok
|
|
|
1321
1322
|
}
|
|
1322
1323
|
function DPad(unit, { diagonal = true, stroke = 'currentColor', strokeOpacity = 0.8, strokeWidth = 1, strokeLinejoin = 'round', fill = '#FFF', fillOpacity = 0.8 } = {}) {
|
|
1323
1324
|
xnew$1.nest(`<div style="width: 100%; height: 100%; display: flex; align-items: center; justify-content: center; container-type: size;">`);
|
|
1324
|
-
xnew$1.nest(`<div style="width: min(100cqw, 100cqh); aspect-ratio: 1; cursor: pointer; user-select: none; pointer-events: auto; overflow: hidden;">`);
|
|
1325
|
+
xnew$1.nest(`<div style="width: min(100cqw, 100cqh); aspect-ratio: 1; cursor: pointer; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; touch-action: none; pointer-events: auto; overflow: hidden;">`);
|
|
1325
1326
|
const polygons = [
|
|
1326
1327
|
'<polygon points="32 32 23 23 23 4 24 3 40 3 41 4 41 23">',
|
|
1327
1328
|
'<polygon points="32 32 23 41 23 60 24 61 40 61 41 60 41 41">',
|
|
@@ -1383,13 +1384,13 @@ function DPad(unit, { diagonal = true, stroke = 'currentColor', strokeOpacity =
|
|
|
1383
1384
|
|
|
1384
1385
|
const currentColorA = 'color-mix(in srgb, currentColor 70%, transparent)';
|
|
1385
1386
|
const currentColorB = 'color-mix(in srgb, currentColor 10%, transparent)';
|
|
1386
|
-
function Panel(unit, {
|
|
1387
|
+
function Panel(unit, { params }) {
|
|
1387
1388
|
const object = params !== null && params !== void 0 ? params : {};
|
|
1388
|
-
xnew$1.extend(Group, { name, open });
|
|
1389
1389
|
return {
|
|
1390
1390
|
group({ name, open, params }, inner) {
|
|
1391
1391
|
const group = xnew$1((unit) => {
|
|
1392
|
-
xnew$1.extend(
|
|
1392
|
+
xnew$1.extend(Group, { name, open });
|
|
1393
|
+
xnew$1.extend(Panel, { params: params !== null && params !== void 0 ? params : object });
|
|
1393
1394
|
inner(unit);
|
|
1394
1395
|
});
|
|
1395
1396
|
return group;
|
|
@@ -1431,7 +1432,7 @@ function Group(group, { name, open = false }) {
|
|
|
1431
1432
|
unit.on('click', () => group.toggle());
|
|
1432
1433
|
xnew$1('<svg viewBox="0 0 12 12" style="width: 1em; height: 1em; margin-right: 0.25em;" fill="none" stroke="currentColor">', (unit) => {
|
|
1433
1434
|
xnew$1('<path d="M6 2 10 6 6 10" />');
|
|
1434
|
-
group.on('-transition', ({
|
|
1435
|
+
group.on('-transition', ({ value }) => unit.element.style.transform = `rotate(${value * 90}deg)`);
|
|
1435
1436
|
});
|
|
1436
1437
|
xnew$1('<div>', name);
|
|
1437
1438
|
});
|
|
@@ -1554,6 +1555,24 @@ function Select(_, { key = '', value, items = [] } = {}) {
|
|
|
1554
1555
|
}
|
|
1555
1556
|
}
|
|
1556
1557
|
|
|
1558
|
+
function Flow(unit) {
|
|
1559
|
+
let scene = null;
|
|
1560
|
+
return {
|
|
1561
|
+
set scene(value) {
|
|
1562
|
+
scene = value;
|
|
1563
|
+
},
|
|
1564
|
+
get scene() {
|
|
1565
|
+
return scene;
|
|
1566
|
+
},
|
|
1567
|
+
next(Component, props) {
|
|
1568
|
+
var _a;
|
|
1569
|
+
// scene change
|
|
1570
|
+
(_a = unit.scene) === null || _a === void 0 ? void 0 : _a.finalize();
|
|
1571
|
+
unit.scene = xnew$1(Component, props);
|
|
1572
|
+
}
|
|
1573
|
+
};
|
|
1574
|
+
}
|
|
1575
|
+
|
|
1557
1576
|
const context = new window.AudioContext();
|
|
1558
1577
|
const master = context.createGain();
|
|
1559
1578
|
//----------------------------------------------------------------------------------------------------
|
|
@@ -1786,6 +1805,7 @@ const basics = {
|
|
|
1786
1805
|
Panel,
|
|
1787
1806
|
Accordion,
|
|
1788
1807
|
Popup,
|
|
1808
|
+
Flow,
|
|
1789
1809
|
};
|
|
1790
1810
|
const audio = {
|
|
1791
1811
|
load(path) {
|