@mulsense/xnew 0.4.0 → 0.4.2
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/xmatter.js +0 -3
- package/dist/addons/xmatter.mjs +0 -3
- package/dist/addons/xpixi.d.ts +6 -4
- package/dist/addons/xpixi.js +0 -23
- package/dist/addons/xpixi.mjs +0 -23
- package/dist/addons/xrapier2d.js +1 -4
- package/dist/addons/xrapier2d.mjs +1 -4
- package/dist/addons/xrapier3d.js +2 -5
- package/dist/addons/xrapier3d.mjs +2 -5
- package/dist/addons/xthree.d.ts +11 -4
- package/dist/addons/xthree.js +4 -7
- package/dist/addons/xthree.mjs +4 -7
- package/dist/xnew.d.ts +14 -46
- package/dist/xnew.js +107 -187
- package/dist/xnew.mjs +107 -187
- package/package.json +8 -6
package/dist/xnew.mjs
CHANGED
|
@@ -98,7 +98,7 @@ class MapMap extends Map {
|
|
|
98
98
|
//----------------------------------------------------------------------------------------------------
|
|
99
99
|
// ticker
|
|
100
100
|
//----------------------------------------------------------------------------------------------------
|
|
101
|
-
class
|
|
101
|
+
class AnimationTicker {
|
|
102
102
|
constructor(callback, fps = 60) {
|
|
103
103
|
const self = this;
|
|
104
104
|
this.id = null;
|
|
@@ -129,7 +129,7 @@ class Timer {
|
|
|
129
129
|
this.counter = 0;
|
|
130
130
|
this.offset = 0.0;
|
|
131
131
|
this.status = 0;
|
|
132
|
-
this.ticker = new
|
|
132
|
+
this.ticker = new AnimationTicker((time) => {
|
|
133
133
|
var _a, _b;
|
|
134
134
|
let p = Math.min(this.elapsed() / this.options.duration, 1.0);
|
|
135
135
|
if (this.options.easing === 'ease-out') {
|
|
@@ -200,7 +200,7 @@ class Timer {
|
|
|
200
200
|
}
|
|
201
201
|
}
|
|
202
202
|
|
|
203
|
-
const SYSTEM_EVENTS = ['start', '
|
|
203
|
+
const SYSTEM_EVENTS = ['start', 'update', 'render', 'stop', 'finalize'];
|
|
204
204
|
|
|
205
205
|
class EventManager {
|
|
206
206
|
constructor() {
|
|
@@ -266,12 +266,12 @@ class EventManager {
|
|
|
266
266
|
};
|
|
267
267
|
}
|
|
268
268
|
resize(props) {
|
|
269
|
-
const observer = new ResizeObserver(
|
|
269
|
+
const observer = new ResizeObserver((entries) => {
|
|
270
270
|
for (const entry of entries) {
|
|
271
271
|
props.listener({ type: 'resize' });
|
|
272
272
|
break;
|
|
273
273
|
}
|
|
274
|
-
})
|
|
274
|
+
});
|
|
275
275
|
observer.observe(props.element);
|
|
276
276
|
return () => {
|
|
277
277
|
observer.unobserve(props.element);
|
|
@@ -410,7 +410,7 @@ class EventManager {
|
|
|
410
410
|
const element = props.element;
|
|
411
411
|
const options = props.options;
|
|
412
412
|
const dragstart = ({ event, position }) => {
|
|
413
|
-
map.set(event.pointerId,
|
|
413
|
+
map.set(event.pointerId, position);
|
|
414
414
|
isActive = map.size === 2 ? true : false;
|
|
415
415
|
if (isActive === true && props.type === 'gesturestart') {
|
|
416
416
|
props.listener({ event, type: props.type });
|
|
@@ -446,11 +446,11 @@ class EventManager {
|
|
|
446
446
|
map.set(event.pointerId, position);
|
|
447
447
|
};
|
|
448
448
|
const dragend = ({ event }) => {
|
|
449
|
-
|
|
449
|
+
map.delete(event.pointerId);
|
|
450
|
+
if (isActive === true && props.type === 'gestureend') {
|
|
450
451
|
props.listener({ event, type: props.type, scale: 1.0 });
|
|
451
452
|
}
|
|
452
453
|
isActive = false;
|
|
453
|
-
map.delete(event.pointerId);
|
|
454
454
|
};
|
|
455
455
|
this.add({ element, options, type: 'dragstart', listener: dragstart });
|
|
456
456
|
this.add({ element, options, type: 'dragmove', listener: dragmove });
|
|
@@ -592,8 +592,8 @@ class Unit {
|
|
|
592
592
|
}
|
|
593
593
|
static initialize(unit, anchor) {
|
|
594
594
|
var _a, _b;
|
|
595
|
-
const backup = Unit.
|
|
596
|
-
Unit.
|
|
595
|
+
const backup = Unit.currentUnit;
|
|
596
|
+
Unit.currentUnit = unit;
|
|
597
597
|
unit._ = Object.assign(unit._, {
|
|
598
598
|
currentElement: unit._.baseElement,
|
|
599
599
|
currentContext: unit._.baseContext,
|
|
@@ -609,7 +609,7 @@ class Unit {
|
|
|
609
609
|
components: [],
|
|
610
610
|
listeners: new MapMap(),
|
|
611
611
|
defines: {},
|
|
612
|
-
systems: { start: [],
|
|
612
|
+
systems: { start: [], update: [], render: [], stop: [], finalize: [] },
|
|
613
613
|
eventManager: new EventManager(),
|
|
614
614
|
});
|
|
615
615
|
// nest html element
|
|
@@ -620,13 +620,13 @@ class Unit {
|
|
|
620
620
|
Unit.extend(unit, unit._.baseComponent, unit._.props);
|
|
621
621
|
// whether the unit promise was resolved
|
|
622
622
|
Promise.all(unit._.promises.map(p => p.promise)).then(() => unit._.state = 'initialized');
|
|
623
|
-
Unit.
|
|
623
|
+
Unit.currentUnit = backup;
|
|
624
624
|
}
|
|
625
625
|
static finalize(unit) {
|
|
626
626
|
if (unit._.state !== 'finalized' && unit._.state !== 'finalizing') {
|
|
627
627
|
unit._.state = 'finalizing';
|
|
628
628
|
unit._.children.forEach((child) => child.finalize());
|
|
629
|
-
unit._.systems.finalize.forEach((
|
|
629
|
+
unit._.systems.finalize.forEach(({ execute }) => execute());
|
|
630
630
|
unit.off();
|
|
631
631
|
unit._.components.forEach((component) => Unit.component2units.delete(component, unit));
|
|
632
632
|
if (unit._.elements.length > 0) {
|
|
@@ -706,7 +706,7 @@ class Unit {
|
|
|
706
706
|
if (unit._.state === 'initialized' || unit._.state === 'stopped') {
|
|
707
707
|
unit._.state = 'started';
|
|
708
708
|
unit._.children.forEach((child) => Unit.start(child));
|
|
709
|
-
unit._.systems.start.forEach((
|
|
709
|
+
unit._.systems.start.forEach(({ execute }) => execute());
|
|
710
710
|
}
|
|
711
711
|
else if (unit._.state === 'started') {
|
|
712
712
|
unit._.children.forEach((child) => Unit.start(child));
|
|
@@ -716,31 +716,31 @@ class Unit {
|
|
|
716
716
|
if (unit._.state === 'started') {
|
|
717
717
|
unit._.state = 'stopped';
|
|
718
718
|
unit._.children.forEach((child) => Unit.stop(child));
|
|
719
|
-
unit._.systems.stop.forEach((
|
|
719
|
+
unit._.systems.stop.forEach(({ execute }) => execute());
|
|
720
720
|
}
|
|
721
721
|
}
|
|
722
722
|
static update(unit) {
|
|
723
|
-
if (unit._.state === 'started'
|
|
723
|
+
if (unit._.state === 'started') {
|
|
724
724
|
unit._.children.forEach((child) => Unit.update(child));
|
|
725
|
-
unit._.systems.update.forEach((
|
|
725
|
+
unit._.systems.update.forEach(({ execute }) => execute());
|
|
726
726
|
}
|
|
727
727
|
}
|
|
728
|
-
static
|
|
729
|
-
if (unit._.state === 'started') {
|
|
730
|
-
unit._.children.forEach((child) => Unit.
|
|
731
|
-
unit._.systems.
|
|
728
|
+
static render(unit) {
|
|
729
|
+
if (unit._.state === 'started' || unit._.state === 'started' || unit._.state === 'stopped') {
|
|
730
|
+
unit._.children.forEach((child) => Unit.render(child));
|
|
731
|
+
unit._.systems.render.forEach(({ execute }) => execute());
|
|
732
732
|
}
|
|
733
733
|
}
|
|
734
734
|
static reset() {
|
|
735
|
-
var _a
|
|
736
|
-
(_a = Unit.
|
|
737
|
-
Unit.
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
Unit.
|
|
741
|
-
Unit.
|
|
742
|
-
Unit.update(Unit.root);
|
|
735
|
+
var _a;
|
|
736
|
+
(_a = Unit.rootUnit) === null || _a === void 0 ? void 0 : _a.finalize();
|
|
737
|
+
Unit.currentUnit = Unit.rootUnit = new Unit(null, null);
|
|
738
|
+
const ticker = new AnimationTicker(() => {
|
|
739
|
+
Unit.start(Unit.rootUnit);
|
|
740
|
+
Unit.update(Unit.rootUnit);
|
|
741
|
+
Unit.render(Unit.rootUnit);
|
|
743
742
|
});
|
|
743
|
+
Unit.rootUnit.on('finalize', () => ticker.clear());
|
|
744
744
|
}
|
|
745
745
|
static wrap(unit, listener) {
|
|
746
746
|
const snapshot = Unit.snapshot(unit);
|
|
@@ -750,25 +750,27 @@ class Unit {
|
|
|
750
750
|
if (snapshot.unit._.state === 'finalized') {
|
|
751
751
|
return;
|
|
752
752
|
}
|
|
753
|
-
const
|
|
753
|
+
const currentUnit = Unit.currentUnit;
|
|
754
754
|
const backup = Unit.snapshot(snapshot.unit);
|
|
755
755
|
try {
|
|
756
|
-
Unit.
|
|
756
|
+
Unit.currentUnit = snapshot.unit;
|
|
757
757
|
snapshot.unit._.currentContext = snapshot.context;
|
|
758
758
|
snapshot.unit._.currentElement = snapshot.element;
|
|
759
|
+
snapshot.unit._.currentComponent = snapshot.component;
|
|
759
760
|
return func(...args);
|
|
760
761
|
}
|
|
761
762
|
catch (error) {
|
|
762
763
|
throw error;
|
|
763
764
|
}
|
|
764
765
|
finally {
|
|
765
|
-
Unit.
|
|
766
|
+
Unit.currentUnit = currentUnit;
|
|
766
767
|
snapshot.unit._.currentContext = backup.context;
|
|
767
768
|
snapshot.unit._.currentElement = backup.element;
|
|
769
|
+
snapshot.unit._.currentComponent = backup.component;
|
|
768
770
|
}
|
|
769
771
|
}
|
|
770
772
|
static snapshot(unit) {
|
|
771
|
-
return { unit, context: unit._.currentContext, element: unit._.currentElement };
|
|
773
|
+
return { unit, context: unit._.currentContext, element: unit._.currentElement, component: unit._.currentComponent };
|
|
772
774
|
}
|
|
773
775
|
static context(unit, key, value) {
|
|
774
776
|
if (value !== undefined) {
|
|
@@ -786,43 +788,46 @@ class Unit {
|
|
|
786
788
|
return [...((_a = Unit.component2units.get(component)) !== null && _a !== void 0 ? _a : [])];
|
|
787
789
|
}
|
|
788
790
|
on(type, listener, options) {
|
|
789
|
-
type.trim().split(/\s+/)
|
|
790
|
-
|
|
791
|
-
this._.systems[type].push(listener);
|
|
792
|
-
}
|
|
793
|
-
if (this._.listeners.has(type, listener) === false) {
|
|
794
|
-
const execute = Unit.wrap(Unit.current, listener);
|
|
795
|
-
this._.listeners.set(type, listener, { element: this.element, execute });
|
|
796
|
-
Unit.type2units.add(type, this);
|
|
797
|
-
if (/^[A-Za-z]/.test(type)) {
|
|
798
|
-
this._.eventManager.add({ element: this.element, type, listener: execute, options });
|
|
799
|
-
}
|
|
800
|
-
}
|
|
801
|
-
});
|
|
791
|
+
const types = type.trim().split(/\s+/);
|
|
792
|
+
types.forEach((type) => Unit.on(this, type, listener, options));
|
|
802
793
|
}
|
|
803
794
|
off(type, listener) {
|
|
804
795
|
const types = typeof type === 'string' ? type.trim().split(/\s+/) : [...this._.listeners.keys()];
|
|
805
|
-
types.forEach((type) =>
|
|
806
|
-
|
|
807
|
-
|
|
796
|
+
types.forEach((type) => Unit.off(this, type, listener));
|
|
797
|
+
}
|
|
798
|
+
static on(unit, type, listener, options) {
|
|
799
|
+
if (SYSTEM_EVENTS.includes(type)) {
|
|
800
|
+
unit._.systems[type].push({ listener, execute: Unit.wrap(Unit.currentUnit, listener) });
|
|
801
|
+
}
|
|
802
|
+
if (unit._.listeners.has(type, listener) === false) {
|
|
803
|
+
const execute = Unit.wrap(Unit.currentUnit, listener);
|
|
804
|
+
unit._.listeners.set(type, listener, { element: unit.element, component: unit._.currentComponent, execute });
|
|
805
|
+
Unit.type2units.add(type, unit);
|
|
806
|
+
if (/^[A-Za-z]/.test(type)) {
|
|
807
|
+
unit._.eventManager.add({ element: unit.element, type, listener: execute, options });
|
|
808
808
|
}
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
809
|
+
}
|
|
810
|
+
}
|
|
811
|
+
static off(unit, type, listener) {
|
|
812
|
+
if (SYSTEM_EVENTS.includes(type)) {
|
|
813
|
+
unit._.systems[type] = unit._.systems[type].filter(({ listener: lis }) => listener ? lis !== listener : false);
|
|
814
|
+
}
|
|
815
|
+
(listener ? [listener] : [...unit._.listeners.keys(type)]).forEach((listener) => {
|
|
816
|
+
const item = unit._.listeners.get(type, listener);
|
|
817
|
+
if (item === undefined)
|
|
818
|
+
return;
|
|
819
|
+
unit._.listeners.delete(type, listener);
|
|
820
|
+
if (/^[A-Za-z]/.test(type)) {
|
|
821
|
+
unit._.eventManager.remove({ type, listener: item.execute });
|
|
820
822
|
}
|
|
821
823
|
});
|
|
824
|
+
if (unit._.listeners.has(type) === false) {
|
|
825
|
+
Unit.type2units.delete(type, unit);
|
|
826
|
+
}
|
|
822
827
|
}
|
|
823
828
|
static emit(type, ...args) {
|
|
824
829
|
var _a, _b;
|
|
825
|
-
const current = Unit.
|
|
830
|
+
const current = Unit.currentUnit;
|
|
826
831
|
if (type[0] === '+') {
|
|
827
832
|
(_a = Unit.type2units.get(type)) === null || _a === void 0 ? void 0 : _a.forEach((unit) => {
|
|
828
833
|
var _a;
|
|
@@ -837,6 +842,7 @@ class Unit {
|
|
|
837
842
|
}
|
|
838
843
|
}
|
|
839
844
|
}
|
|
845
|
+
Unit.currentComponent = () => { };
|
|
840
846
|
Unit.component2units = new MapSet();
|
|
841
847
|
//----------------------------------------------------------------------------------------------------
|
|
842
848
|
// event
|
|
@@ -851,15 +857,15 @@ class UnitPromise {
|
|
|
851
857
|
this.component = component;
|
|
852
858
|
}
|
|
853
859
|
then(callback) {
|
|
854
|
-
this.promise = this.promise.then(Unit.wrap(Unit.
|
|
860
|
+
this.promise = this.promise.then(Unit.wrap(Unit.currentUnit, callback));
|
|
855
861
|
return this;
|
|
856
862
|
}
|
|
857
863
|
catch(callback) {
|
|
858
|
-
this.promise = this.promise.catch(Unit.wrap(Unit.
|
|
864
|
+
this.promise = this.promise.catch(Unit.wrap(Unit.currentUnit, callback));
|
|
859
865
|
return this;
|
|
860
866
|
}
|
|
861
867
|
finally(callback) {
|
|
862
|
-
this.promise = this.promise.finally(Unit.wrap(Unit.
|
|
868
|
+
this.promise = this.promise.finally(Unit.wrap(Unit.currentUnit, callback));
|
|
863
869
|
return this;
|
|
864
870
|
}
|
|
865
871
|
}
|
|
@@ -869,7 +875,7 @@ class UnitPromise {
|
|
|
869
875
|
class UnitTimer {
|
|
870
876
|
constructor(options) {
|
|
871
877
|
this.stack = [];
|
|
872
|
-
this.unit = new Unit(Unit.
|
|
878
|
+
this.unit = new Unit(Unit.currentUnit, UnitTimer.Component, Object.assign({ snapshot: Unit.snapshot(Unit.currentUnit) }, options));
|
|
873
879
|
}
|
|
874
880
|
clear() {
|
|
875
881
|
this.stack = [];
|
|
@@ -889,19 +895,19 @@ class UnitTimer {
|
|
|
889
895
|
}
|
|
890
896
|
static execute(timer, options) {
|
|
891
897
|
if (timer.unit._.state === 'finalized') {
|
|
892
|
-
timer.unit = new Unit(Unit.
|
|
898
|
+
timer.unit = new Unit(Unit.currentUnit, UnitTimer.Component, Object.assign({ snapshot: Unit.snapshot(Unit.currentUnit) }, options));
|
|
893
899
|
}
|
|
894
900
|
else if (timer.stack.length === 0) {
|
|
895
|
-
timer.stack.push(Object.assign({ snapshot: Unit.snapshot(Unit.
|
|
901
|
+
timer.stack.push(Object.assign({ snapshot: Unit.snapshot(Unit.currentUnit) }, options));
|
|
896
902
|
timer.unit.on('finalize', () => { UnitTimer.next(timer); });
|
|
897
903
|
}
|
|
898
904
|
else {
|
|
899
|
-
timer.stack.push(Object.assign({ snapshot: Unit.snapshot(Unit.
|
|
905
|
+
timer.stack.push(Object.assign({ snapshot: Unit.snapshot(Unit.currentUnit) }, options));
|
|
900
906
|
}
|
|
901
907
|
}
|
|
902
908
|
static next(timer) {
|
|
903
909
|
if (timer.stack.length > 0) {
|
|
904
|
-
timer.unit = new Unit(Unit.
|
|
910
|
+
timer.unit = new Unit(Unit.currentUnit, UnitTimer.Component, timer.stack.shift());
|
|
905
911
|
timer.unit.on('finalize', () => { UnitTimer.next(timer); });
|
|
906
912
|
}
|
|
907
913
|
}
|
|
@@ -928,10 +934,10 @@ class UnitTimer {
|
|
|
928
934
|
}
|
|
929
935
|
|
|
930
936
|
const xnew$1 = Object.assign(function (...args) {
|
|
931
|
-
if (Unit.
|
|
937
|
+
if (Unit.rootUnit === undefined) {
|
|
932
938
|
Unit.reset();
|
|
933
939
|
}
|
|
934
|
-
return new Unit(Unit.
|
|
940
|
+
return new Unit(Unit.currentUnit, ...args);
|
|
935
941
|
}, {
|
|
936
942
|
/**
|
|
937
943
|
* Creates a nested HTML/SVG element within the current component
|
|
@@ -944,7 +950,7 @@ const xnew$1 = Object.assign(function (...args) {
|
|
|
944
950
|
*/
|
|
945
951
|
nest(tag) {
|
|
946
952
|
try {
|
|
947
|
-
return Unit.nest(Unit.
|
|
953
|
+
return Unit.nest(Unit.currentUnit, tag);
|
|
948
954
|
}
|
|
949
955
|
catch (error) {
|
|
950
956
|
console.error('xnew.nest(tag: string): ', error);
|
|
@@ -962,7 +968,7 @@ const xnew$1 = Object.assign(function (...args) {
|
|
|
962
968
|
*/
|
|
963
969
|
extend(component, props) {
|
|
964
970
|
try {
|
|
965
|
-
return Unit.extend(Unit.
|
|
971
|
+
return Unit.extend(Unit.currentUnit, component, props);
|
|
966
972
|
}
|
|
967
973
|
catch (error) {
|
|
968
974
|
console.error('xnew.extend(component: Function, props?: Object): ', error);
|
|
@@ -983,7 +989,7 @@ const xnew$1 = Object.assign(function (...args) {
|
|
|
983
989
|
*/
|
|
984
990
|
context(key, value = undefined) {
|
|
985
991
|
try {
|
|
986
|
-
return Unit.context(Unit.
|
|
992
|
+
return Unit.context(Unit.currentUnit, key, value);
|
|
987
993
|
}
|
|
988
994
|
catch (error) {
|
|
989
995
|
console.error('xnew.context(key: string, value?: any): ', error);
|
|
@@ -999,9 +1005,9 @@ const xnew$1 = Object.assign(function (...args) {
|
|
|
999
1005
|
*/
|
|
1000
1006
|
promise(promise) {
|
|
1001
1007
|
try {
|
|
1002
|
-
const component = Unit.
|
|
1003
|
-
Unit.
|
|
1004
|
-
return Unit.
|
|
1008
|
+
const component = Unit.currentUnit._.currentComponent;
|
|
1009
|
+
Unit.currentUnit._.promises.push(new UnitPromise(promise, component));
|
|
1010
|
+
return Unit.currentUnit._.promises[Unit.currentUnit._.promises.length - 1];
|
|
1005
1011
|
}
|
|
1006
1012
|
catch (error) {
|
|
1007
1013
|
console.error('xnew.promise(promise: Promise<any>): ', error);
|
|
@@ -1017,8 +1023,8 @@ const xnew$1 = Object.assign(function (...args) {
|
|
|
1017
1023
|
*/
|
|
1018
1024
|
then(callback) {
|
|
1019
1025
|
try {
|
|
1020
|
-
const component = Unit.
|
|
1021
|
-
const promises = Unit.
|
|
1026
|
+
const component = Unit.currentUnit._.currentComponent;
|
|
1027
|
+
const promises = Unit.currentUnit._.promises;
|
|
1022
1028
|
return new UnitPromise(Promise.all(promises.map(p => p.promise)), null)
|
|
1023
1029
|
.then((results) => {
|
|
1024
1030
|
callback(results.filter((_result, index) => promises[index].component !== null && promises[index].component === component));
|
|
@@ -1038,7 +1044,7 @@ const xnew$1 = Object.assign(function (...args) {
|
|
|
1038
1044
|
*/
|
|
1039
1045
|
catch(callback) {
|
|
1040
1046
|
try {
|
|
1041
|
-
const promises = Unit.
|
|
1047
|
+
const promises = Unit.currentUnit._.promises;
|
|
1042
1048
|
return new UnitPromise(Promise.all(promises.map(p => p.promise)), null)
|
|
1043
1049
|
.catch(callback);
|
|
1044
1050
|
}
|
|
@@ -1056,7 +1062,7 @@ const xnew$1 = Object.assign(function (...args) {
|
|
|
1056
1062
|
*/
|
|
1057
1063
|
finally(callback) {
|
|
1058
1064
|
try {
|
|
1059
|
-
const promises = Unit.
|
|
1065
|
+
const promises = Unit.currentUnit._.promises;
|
|
1060
1066
|
return new UnitPromise(Promise.all(promises.map(p => p.promise)), null)
|
|
1061
1067
|
.finally(callback);
|
|
1062
1068
|
}
|
|
@@ -1075,7 +1081,7 @@ const xnew$1 = Object.assign(function (...args) {
|
|
|
1075
1081
|
* }), 1000)
|
|
1076
1082
|
*/
|
|
1077
1083
|
scope(callback) {
|
|
1078
|
-
const snapshot = Unit.snapshot(Unit.
|
|
1084
|
+
const snapshot = Unit.snapshot(Unit.currentUnit);
|
|
1079
1085
|
return (...args) => Unit.scope(snapshot, callback, ...args);
|
|
1080
1086
|
},
|
|
1081
1087
|
/**
|
|
@@ -1146,73 +1152,54 @@ const xnew$1 = Object.assign(function (...args) {
|
|
|
1146
1152
|
return new UnitTimer({ transition, duration, easing, iterations: 1 });
|
|
1147
1153
|
},
|
|
1148
1154
|
protect() {
|
|
1149
|
-
Unit.
|
|
1155
|
+
Unit.currentUnit._.protected = true;
|
|
1150
1156
|
}
|
|
1151
1157
|
});
|
|
1152
1158
|
|
|
1153
|
-
function AccordionFrame(
|
|
1159
|
+
function AccordionFrame(unit, { open = false, duration = 200, easing = 'ease' } = {}) {
|
|
1154
1160
|
const internal = xnew$1((internal) => {
|
|
1155
1161
|
return {
|
|
1156
|
-
frame, open, rate: 0.0,
|
|
1157
|
-
|
|
1162
|
+
frame: unit, open, rate: 0.0,
|
|
1163
|
+
transition(rate) {
|
|
1164
|
+
xnew$1.emit('-transition', { rate });
|
|
1165
|
+
}
|
|
1158
1166
|
};
|
|
1159
1167
|
});
|
|
1160
1168
|
xnew$1.context('xnew.accordionframe', internal);
|
|
1161
|
-
internal.on('-transition', ({ rate }) =>
|
|
1162
|
-
|
|
1169
|
+
internal.on('-transition', ({ rate }) => {
|
|
1170
|
+
internal.rate = rate;
|
|
1171
|
+
xnew$1.emit('-transition', { rate });
|
|
1172
|
+
});
|
|
1173
|
+
xnew$1.timeout(() => {
|
|
1174
|
+
internal.transition(open ? 1.0 : 0.0);
|
|
1175
|
+
});
|
|
1163
1176
|
return {
|
|
1164
1177
|
toggle() {
|
|
1165
1178
|
if (internal.rate === 1.0) {
|
|
1166
|
-
|
|
1179
|
+
unit.close();
|
|
1167
1180
|
}
|
|
1168
1181
|
else if (internal.rate === 0.0) {
|
|
1169
|
-
|
|
1182
|
+
unit.open();
|
|
1170
1183
|
}
|
|
1171
1184
|
},
|
|
1172
1185
|
open() {
|
|
1173
1186
|
if (internal.rate === 0.0) {
|
|
1174
|
-
xnew$1.transition((x) => internal.
|
|
1187
|
+
xnew$1.transition((x) => internal.transition(x), duration, easing);
|
|
1175
1188
|
}
|
|
1176
1189
|
},
|
|
1177
1190
|
close() {
|
|
1178
1191
|
if (internal.rate === 1.0) {
|
|
1179
|
-
xnew$1.transition((x) => internal.
|
|
1192
|
+
xnew$1.transition((x) => internal.transition(1.0 - x), duration, easing);
|
|
1180
1193
|
}
|
|
1181
1194
|
}
|
|
1182
1195
|
};
|
|
1183
1196
|
}
|
|
1184
|
-
function
|
|
1185
|
-
const internal = xnew$1.context('xnew.accordionframe');
|
|
1186
|
-
xnew$1.nest('<button style="display: flex; align-items: center; margin: 0; padding: 0; width: 100%; text-align: left; border: none; font: inherit; color: inherit; background: none; cursor: pointer;">');
|
|
1187
|
-
header.on('click', () => internal.frame.toggle());
|
|
1188
|
-
}
|
|
1189
|
-
function AccordionBullet(bullet, { type = 'arrow' } = {}) {
|
|
1190
|
-
const internal = xnew$1.context('xnew.accordionframe');
|
|
1191
|
-
xnew$1.nest('<div style="display:inline-block; position: relative; width: 0.55em; margin: 0 0.3em;">');
|
|
1192
|
-
if (type === 'arrow') {
|
|
1193
|
-
const arrow = xnew$1(`<div style="width: 100%; height: 0.55em; border-right: 0.12em solid currentColor; border-bottom: 0.12em solid currentColor; box-sizing: border-box; transform-origin: center;">`);
|
|
1194
|
-
arrow.element.style.transform = `rotate(${internal.rate * 90 - 45}deg)`;
|
|
1195
|
-
internal.on('-transition', ({ rate }) => {
|
|
1196
|
-
arrow.element.style.transform = `rotate(${rate * 90 - 45}deg)`;
|
|
1197
|
-
});
|
|
1198
|
-
}
|
|
1199
|
-
else if (type === 'plusminus') {
|
|
1200
|
-
const line1 = xnew$1(`<div style="position: absolute; width: 100%; border-top: 0.06em solid currentColor; border-bottom: 0.06em solid currentColor; box-sizing: border-box; transform-origin: center;">`);
|
|
1201
|
-
const line2 = xnew$1(`<div style="position: absolute; width: 100%; border-top: 0.06em solid currentColor; border-bottom: 0.06em solid currentColor; box-sizing: border-box; transform-origin: center;">`);
|
|
1202
|
-
line2.element.style.transform = `rotate(90deg)`;
|
|
1203
|
-
line2.element.style.opacity = `${1.0 - internal.rate}`;
|
|
1204
|
-
internal.on('-transition', ({ rate }) => {
|
|
1205
|
-
line1.element.style.transform = `rotate(${90 + rate * 90}deg)`;
|
|
1206
|
-
line2.element.style.transform = `rotate(${rate * 180}deg)`;
|
|
1207
|
-
});
|
|
1208
|
-
}
|
|
1209
|
-
}
|
|
1210
|
-
function AccordionContent(content, {} = {}) {
|
|
1197
|
+
function AccordionContent(unit, {} = {}) {
|
|
1211
1198
|
const internal = xnew$1.context('xnew.accordionframe');
|
|
1212
1199
|
xnew$1.nest(`<div style="display: ${internal.open ? 'block' : 'none'};">`);
|
|
1213
1200
|
xnew$1.nest('<div style="padding: 0; display: flex; flex-direction: column; box-sizing: border-box;">');
|
|
1214
1201
|
internal.on('-transition', ({ rate }) => {
|
|
1215
|
-
|
|
1202
|
+
unit.transition({ element: unit.element, rate });
|
|
1216
1203
|
});
|
|
1217
1204
|
return {
|
|
1218
1205
|
transition({ element, rate }) {
|
|
@@ -1311,68 +1298,6 @@ function ModalContent(content, { background = 'rgba(0, 0, 0, 0.1)' } = {}) {
|
|
|
1311
1298
|
};
|
|
1312
1299
|
}
|
|
1313
1300
|
|
|
1314
|
-
function TabFrame(frame, { select } = {}) {
|
|
1315
|
-
const internal = xnew$1((internal) => {
|
|
1316
|
-
const buttons = new Map();
|
|
1317
|
-
const contents = new Map();
|
|
1318
|
-
return {
|
|
1319
|
-
frame, buttons, contents,
|
|
1320
|
-
emit(type, ...args) { xnew$1.emit(type, ...args); }
|
|
1321
|
-
};
|
|
1322
|
-
});
|
|
1323
|
-
xnew$1.context('xnew.tabframe', internal);
|
|
1324
|
-
xnew$1.timeout(() => internal.emit('-select', { key: select !== null && select !== void 0 ? select : [...internal.buttons.keys()][0] }));
|
|
1325
|
-
}
|
|
1326
|
-
function TabButton(button, { key } = {}) {
|
|
1327
|
-
const internal = xnew$1.context('xnew.tabframe');
|
|
1328
|
-
const div = xnew$1.nest('<div>');
|
|
1329
|
-
key = key !== null && key !== void 0 ? key : (internal.buttons.size).toString();
|
|
1330
|
-
internal.buttons.set(key, button);
|
|
1331
|
-
button.on('click', () => {
|
|
1332
|
-
internal.emit('-select', { key });
|
|
1333
|
-
});
|
|
1334
|
-
internal.on('-select', ({ key }) => {
|
|
1335
|
-
const select = internal.buttons.get(key);
|
|
1336
|
-
if (select === button) {
|
|
1337
|
-
button.select({ element: div });
|
|
1338
|
-
}
|
|
1339
|
-
else {
|
|
1340
|
-
button.deselect({ element: div });
|
|
1341
|
-
}
|
|
1342
|
-
});
|
|
1343
|
-
return {
|
|
1344
|
-
select({ element }) {
|
|
1345
|
-
Object.assign(element.style, { opacity: 1.0, cursor: 'text' });
|
|
1346
|
-
},
|
|
1347
|
-
deselect({ element }) {
|
|
1348
|
-
Object.assign(element.style, { opacity: 0.6, cursor: 'pointer' });
|
|
1349
|
-
}
|
|
1350
|
-
};
|
|
1351
|
-
}
|
|
1352
|
-
function TabContent(content, { key } = {}) {
|
|
1353
|
-
const internal = xnew$1.context('xnew.tabframe');
|
|
1354
|
-
const div = xnew$1.nest('<div style="display: none;">');
|
|
1355
|
-
key = key !== null && key !== void 0 ? key : (internal.contents.size).toString();
|
|
1356
|
-
internal.contents.set(key, content);
|
|
1357
|
-
internal.on('-select', ({ key }) => {
|
|
1358
|
-
const select = internal.contents.get(key);
|
|
1359
|
-
if (select === content) {
|
|
1360
|
-
content.select({ element: div });
|
|
1361
|
-
}
|
|
1362
|
-
else {
|
|
1363
|
-
content.deselect({ element: div });
|
|
1364
|
-
}
|
|
1365
|
-
});
|
|
1366
|
-
return {
|
|
1367
|
-
select({ element }) {
|
|
1368
|
-
Object.assign(element.style, { display: 'block' });
|
|
1369
|
-
},
|
|
1370
|
-
deselect({ element }) {
|
|
1371
|
-
Object.assign(element.style, { display: 'none' });
|
|
1372
|
-
}
|
|
1373
|
-
};
|
|
1374
|
-
}
|
|
1375
|
-
|
|
1376
1301
|
function DragFrame(frame, { x = 0, y = 0 } = {}) {
|
|
1377
1302
|
const absolute = xnew$1.nest(`<div style="position: absolute; top: ${y}px; left: ${x}px;">`);
|
|
1378
1303
|
xnew$1.context('xnew.dragframe', { frame, absolute });
|
|
@@ -3466,12 +3391,7 @@ const basics = {
|
|
|
3466
3391
|
ModalFrame,
|
|
3467
3392
|
ModalContent,
|
|
3468
3393
|
AccordionFrame,
|
|
3469
|
-
AccordionHeader,
|
|
3470
|
-
AccordionBullet,
|
|
3471
3394
|
AccordionContent,
|
|
3472
|
-
TabFrame,
|
|
3473
|
-
TabButton,
|
|
3474
|
-
TabContent,
|
|
3475
3395
|
TextStream,
|
|
3476
3396
|
DragFrame,
|
|
3477
3397
|
DragTarget,
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mulsense/xnew",
|
|
3
|
-
"description": "JavaScript
|
|
3
|
+
"description": "JavaScript / TypeScript library for component-oriented programming.",
|
|
4
4
|
"keywords": [
|
|
5
5
|
"Component-Oriented Programming"
|
|
6
6
|
],
|
|
7
|
-
"version": "0.4.
|
|
7
|
+
"version": "0.4.2",
|
|
8
8
|
"main": "dist/xnew.js",
|
|
9
9
|
"module": "dist/xnew.mjs",
|
|
10
10
|
"types": "dist/xnew.d.ts",
|
|
@@ -29,6 +29,11 @@
|
|
|
29
29
|
"import": "./dist/addons/xrapier2d.mjs",
|
|
30
30
|
"require": "./dist/addons/xrapier2d.js"
|
|
31
31
|
},
|
|
32
|
+
"./addons/xrapier3d": {
|
|
33
|
+
"types": "./dist/addons/xrapier3d.d.ts",
|
|
34
|
+
"import": "./dist/addons/xrapier3d.mjs",
|
|
35
|
+
"require": "./dist/addons/xrapier3d.js"
|
|
36
|
+
},
|
|
32
37
|
"./addons/xthree": {
|
|
33
38
|
"types": "./dist/addons/xthree.d.ts",
|
|
34
39
|
"import": "./dist/addons/xthree.mjs",
|
|
@@ -53,9 +58,7 @@
|
|
|
53
58
|
"scripts": {
|
|
54
59
|
"test": "jest",
|
|
55
60
|
"build": "npx rollup --config rollup.config.js --bundleConfigAsCjs",
|
|
56
|
-
"dev": "npx rollup --config rollup.config.js --watch --bundleConfigAsCjs"
|
|
57
|
-
"build:addons": "npx rollup --config rollup.addons.config.js --bundleConfigAsCjs",
|
|
58
|
-
"dev:addons": "npx rollup --config rollup.addons.config.js --watch --bundleConfigAsCjs"
|
|
61
|
+
"dev": "npx rollup --config rollup.config.js --watch --bundleConfigAsCjs"
|
|
59
62
|
},
|
|
60
63
|
"devDependencies": {
|
|
61
64
|
"@babel/core": "^7.26.0",
|
|
@@ -72,7 +75,6 @@
|
|
|
72
75
|
"jest": "^29.7.0",
|
|
73
76
|
"jest-environment-jsdom": "^29.7.0",
|
|
74
77
|
"matter-js": "^0.20.0",
|
|
75
|
-
"onchange": "^7.1.0",
|
|
76
78
|
"pixi.js": "^8.9.2",
|
|
77
79
|
"rollup": "^3.3.0",
|
|
78
80
|
"rollup-plugin-dts": "^6.2.1",
|