@mulsense/xnew 0.5.0 → 0.5.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/dist/xnew.js +15 -65
- package/dist/xnew.mjs +15 -65
- package/package.json +1 -1
package/dist/xnew.js
CHANGED
|
@@ -206,8 +206,6 @@
|
|
|
206
206
|
}
|
|
207
207
|
}
|
|
208
208
|
|
|
209
|
-
const SYSTEM_EVENTS = ['start', 'update', 'render', 'stop', 'finalize'];
|
|
210
|
-
|
|
211
209
|
class EventManager {
|
|
212
210
|
constructor() {
|
|
213
211
|
this.map = new MapMap();
|
|
@@ -524,6 +522,10 @@
|
|
|
524
522
|
return { position };
|
|
525
523
|
}
|
|
526
524
|
|
|
525
|
+
//----------------------------------------------------------------------------------------------------
|
|
526
|
+
// utils
|
|
527
|
+
//----------------------------------------------------------------------------------------------------
|
|
528
|
+
const SYSTEM_EVENTS = ['start', 'update', 'render', 'stop', 'finalize'];
|
|
527
529
|
//----------------------------------------------------------------------------------------------------
|
|
528
530
|
// unit
|
|
529
531
|
//----------------------------------------------------------------------------------------------------
|
|
@@ -632,11 +634,11 @@
|
|
|
632
634
|
unit._.state = 'finalized';
|
|
633
635
|
}
|
|
634
636
|
}
|
|
635
|
-
static nest(unit,
|
|
637
|
+
static nest(unit, htmlString, textContent) {
|
|
636
638
|
if (unit._.state !== 'invoked') {
|
|
637
639
|
throw new Error('This function can not be called after initialized.');
|
|
638
640
|
}
|
|
639
|
-
const match =
|
|
641
|
+
const match = htmlString.match(/<((\w+)[^>]*?)\/?>/);
|
|
640
642
|
if (match !== null) {
|
|
641
643
|
let element;
|
|
642
644
|
if (unit._.anchor !== null) {
|
|
@@ -649,11 +651,14 @@
|
|
|
649
651
|
element = unit._.currentElement.children[unit._.currentElement.children.length - 1];
|
|
650
652
|
}
|
|
651
653
|
unit._.currentElement = element;
|
|
654
|
+
if (textContent !== undefined) {
|
|
655
|
+
element.textContent = textContent;
|
|
656
|
+
}
|
|
652
657
|
unit._.elements.push(element);
|
|
653
658
|
return element;
|
|
654
659
|
}
|
|
655
660
|
else {
|
|
656
|
-
throw new Error(`Invalid
|
|
661
|
+
throw new Error(`Invalid html string: ${htmlString}`);
|
|
657
662
|
}
|
|
658
663
|
}
|
|
659
664
|
static extend(unit, component, props) {
|
|
@@ -945,19 +950,19 @@
|
|
|
945
950
|
}, {
|
|
946
951
|
/**
|
|
947
952
|
* Creates a nested HTML/SVG element within the current component
|
|
948
|
-
* @param
|
|
953
|
+
* @param htmlString - HTML or SVG tag name (e.g., '<div>', '<span>', '<svg>')
|
|
949
954
|
* @returns The created HTML/SVG element
|
|
950
955
|
* @throws Error if called after component initialization
|
|
951
956
|
* @example
|
|
952
957
|
* const div = xnew.nest('<div>')
|
|
953
958
|
* div.textContent = 'Hello'
|
|
954
959
|
*/
|
|
955
|
-
nest(
|
|
960
|
+
nest(htmlString, textContent) {
|
|
956
961
|
try {
|
|
957
|
-
return Unit.nest(Unit.currentUnit,
|
|
962
|
+
return Unit.nest(Unit.currentUnit, htmlString, textContent);
|
|
958
963
|
}
|
|
959
964
|
catch (error) {
|
|
960
|
-
console.error('xnew.nest(
|
|
965
|
+
console.error('xnew.nest(htmlString: string): ', error);
|
|
961
966
|
throw error;
|
|
962
967
|
}
|
|
963
968
|
},
|
|
@@ -1370,51 +1375,6 @@
|
|
|
1370
1375
|
});
|
|
1371
1376
|
}
|
|
1372
1377
|
|
|
1373
|
-
function TextStream(unit, { text = '', speed = 50, fade = 300 } = {}) {
|
|
1374
|
-
const chars = [];
|
|
1375
|
-
for (let i = 0; i < text.length; i++) {
|
|
1376
|
-
const unit = xnew$1('<span>');
|
|
1377
|
-
unit.element.textContent = text[i];
|
|
1378
|
-
unit.element.style.opacity = '0';
|
|
1379
|
-
unit.element.style.transition = `opacity ${fade}ms ease-in-out`;
|
|
1380
|
-
chars.push(unit);
|
|
1381
|
-
}
|
|
1382
|
-
let start = 0;
|
|
1383
|
-
unit.on('start', () => {
|
|
1384
|
-
start = new Date().getTime();
|
|
1385
|
-
});
|
|
1386
|
-
let state = 0;
|
|
1387
|
-
unit.on('update', () => {
|
|
1388
|
-
const index = Math.floor((new Date().getTime() - start) / speed);
|
|
1389
|
-
// Display characters up to the current index (fade in)
|
|
1390
|
-
for (let i = 0; i < chars.length; i++) {
|
|
1391
|
-
if (i <= index) {
|
|
1392
|
-
chars[i].element.style.opacity = '1';
|
|
1393
|
-
}
|
|
1394
|
-
}
|
|
1395
|
-
if (state === 0 && index >= text.length) {
|
|
1396
|
-
action();
|
|
1397
|
-
}
|
|
1398
|
-
});
|
|
1399
|
-
xnew$1.timeout(() => {
|
|
1400
|
-
xnew$1(document.body).on('click wheel', action);
|
|
1401
|
-
unit.on('keydown', action);
|
|
1402
|
-
}, 100);
|
|
1403
|
-
function action() {
|
|
1404
|
-
if (state === 0) {
|
|
1405
|
-
state = 1;
|
|
1406
|
-
for (let i = 0; i < chars.length; i++) {
|
|
1407
|
-
chars[i].element.style.opacity = '1';
|
|
1408
|
-
}
|
|
1409
|
-
xnew$1.emit('-complete');
|
|
1410
|
-
}
|
|
1411
|
-
else if (state === 1) {
|
|
1412
|
-
state = 2;
|
|
1413
|
-
xnew$1.emit('-next');
|
|
1414
|
-
}
|
|
1415
|
-
}
|
|
1416
|
-
}
|
|
1417
|
-
|
|
1418
1378
|
const context = new window.AudioContext();
|
|
1419
1379
|
const master = context.createGain();
|
|
1420
1380
|
//----------------------------------------------------------------------------------------------------
|
|
@@ -1643,7 +1603,6 @@
|
|
|
1643
1603
|
Screen,
|
|
1644
1604
|
Modal,
|
|
1645
1605
|
Accordion,
|
|
1646
|
-
TextStream,
|
|
1647
1606
|
AnalogStick,
|
|
1648
1607
|
DirectionalPad,
|
|
1649
1608
|
};
|
|
@@ -1674,16 +1633,7 @@
|
|
|
1674
1633
|
master.gain.value = value;
|
|
1675
1634
|
}
|
|
1676
1635
|
};
|
|
1677
|
-
const
|
|
1678
|
-
Object.defineProperty(temp, 'global', {
|
|
1679
|
-
get: function () {
|
|
1680
|
-
return temp.context('xnew.global');
|
|
1681
|
-
},
|
|
1682
|
-
set: function (value) {
|
|
1683
|
-
temp.context('xnew.global', value);
|
|
1684
|
-
}
|
|
1685
|
-
});
|
|
1686
|
-
const xnew = temp;
|
|
1636
|
+
const xnew = Object.assign(xnew$1, { basics, audio });
|
|
1687
1637
|
|
|
1688
1638
|
return xnew;
|
|
1689
1639
|
|
package/dist/xnew.mjs
CHANGED
|
@@ -200,8 +200,6 @@ class Timer {
|
|
|
200
200
|
}
|
|
201
201
|
}
|
|
202
202
|
|
|
203
|
-
const SYSTEM_EVENTS = ['start', 'update', 'render', 'stop', 'finalize'];
|
|
204
|
-
|
|
205
203
|
class EventManager {
|
|
206
204
|
constructor() {
|
|
207
205
|
this.map = new MapMap();
|
|
@@ -518,6 +516,10 @@ function pointer(element, event) {
|
|
|
518
516
|
return { position };
|
|
519
517
|
}
|
|
520
518
|
|
|
519
|
+
//----------------------------------------------------------------------------------------------------
|
|
520
|
+
// utils
|
|
521
|
+
//----------------------------------------------------------------------------------------------------
|
|
522
|
+
const SYSTEM_EVENTS = ['start', 'update', 'render', 'stop', 'finalize'];
|
|
521
523
|
//----------------------------------------------------------------------------------------------------
|
|
522
524
|
// unit
|
|
523
525
|
//----------------------------------------------------------------------------------------------------
|
|
@@ -626,11 +628,11 @@ class Unit {
|
|
|
626
628
|
unit._.state = 'finalized';
|
|
627
629
|
}
|
|
628
630
|
}
|
|
629
|
-
static nest(unit,
|
|
631
|
+
static nest(unit, htmlString, textContent) {
|
|
630
632
|
if (unit._.state !== 'invoked') {
|
|
631
633
|
throw new Error('This function can not be called after initialized.');
|
|
632
634
|
}
|
|
633
|
-
const match =
|
|
635
|
+
const match = htmlString.match(/<((\w+)[^>]*?)\/?>/);
|
|
634
636
|
if (match !== null) {
|
|
635
637
|
let element;
|
|
636
638
|
if (unit._.anchor !== null) {
|
|
@@ -643,11 +645,14 @@ class Unit {
|
|
|
643
645
|
element = unit._.currentElement.children[unit._.currentElement.children.length - 1];
|
|
644
646
|
}
|
|
645
647
|
unit._.currentElement = element;
|
|
648
|
+
if (textContent !== undefined) {
|
|
649
|
+
element.textContent = textContent;
|
|
650
|
+
}
|
|
646
651
|
unit._.elements.push(element);
|
|
647
652
|
return element;
|
|
648
653
|
}
|
|
649
654
|
else {
|
|
650
|
-
throw new Error(`Invalid
|
|
655
|
+
throw new Error(`Invalid html string: ${htmlString}`);
|
|
651
656
|
}
|
|
652
657
|
}
|
|
653
658
|
static extend(unit, component, props) {
|
|
@@ -939,19 +944,19 @@ const xnew$1 = Object.assign(function (...args) {
|
|
|
939
944
|
}, {
|
|
940
945
|
/**
|
|
941
946
|
* Creates a nested HTML/SVG element within the current component
|
|
942
|
-
* @param
|
|
947
|
+
* @param htmlString - HTML or SVG tag name (e.g., '<div>', '<span>', '<svg>')
|
|
943
948
|
* @returns The created HTML/SVG element
|
|
944
949
|
* @throws Error if called after component initialization
|
|
945
950
|
* @example
|
|
946
951
|
* const div = xnew.nest('<div>')
|
|
947
952
|
* div.textContent = 'Hello'
|
|
948
953
|
*/
|
|
949
|
-
nest(
|
|
954
|
+
nest(htmlString, textContent) {
|
|
950
955
|
try {
|
|
951
|
-
return Unit.nest(Unit.currentUnit,
|
|
956
|
+
return Unit.nest(Unit.currentUnit, htmlString, textContent);
|
|
952
957
|
}
|
|
953
958
|
catch (error) {
|
|
954
|
-
console.error('xnew.nest(
|
|
959
|
+
console.error('xnew.nest(htmlString: string): ', error);
|
|
955
960
|
throw error;
|
|
956
961
|
}
|
|
957
962
|
},
|
|
@@ -1364,51 +1369,6 @@ function DirectionalPad(unit, { diagonal = true, stroke = 'currentColor', stroke
|
|
|
1364
1369
|
});
|
|
1365
1370
|
}
|
|
1366
1371
|
|
|
1367
|
-
function TextStream(unit, { text = '', speed = 50, fade = 300 } = {}) {
|
|
1368
|
-
const chars = [];
|
|
1369
|
-
for (let i = 0; i < text.length; i++) {
|
|
1370
|
-
const unit = xnew$1('<span>');
|
|
1371
|
-
unit.element.textContent = text[i];
|
|
1372
|
-
unit.element.style.opacity = '0';
|
|
1373
|
-
unit.element.style.transition = `opacity ${fade}ms ease-in-out`;
|
|
1374
|
-
chars.push(unit);
|
|
1375
|
-
}
|
|
1376
|
-
let start = 0;
|
|
1377
|
-
unit.on('start', () => {
|
|
1378
|
-
start = new Date().getTime();
|
|
1379
|
-
});
|
|
1380
|
-
let state = 0;
|
|
1381
|
-
unit.on('update', () => {
|
|
1382
|
-
const index = Math.floor((new Date().getTime() - start) / speed);
|
|
1383
|
-
// Display characters up to the current index (fade in)
|
|
1384
|
-
for (let i = 0; i < chars.length; i++) {
|
|
1385
|
-
if (i <= index) {
|
|
1386
|
-
chars[i].element.style.opacity = '1';
|
|
1387
|
-
}
|
|
1388
|
-
}
|
|
1389
|
-
if (state === 0 && index >= text.length) {
|
|
1390
|
-
action();
|
|
1391
|
-
}
|
|
1392
|
-
});
|
|
1393
|
-
xnew$1.timeout(() => {
|
|
1394
|
-
xnew$1(document.body).on('click wheel', action);
|
|
1395
|
-
unit.on('keydown', action);
|
|
1396
|
-
}, 100);
|
|
1397
|
-
function action() {
|
|
1398
|
-
if (state === 0) {
|
|
1399
|
-
state = 1;
|
|
1400
|
-
for (let i = 0; i < chars.length; i++) {
|
|
1401
|
-
chars[i].element.style.opacity = '1';
|
|
1402
|
-
}
|
|
1403
|
-
xnew$1.emit('-complete');
|
|
1404
|
-
}
|
|
1405
|
-
else if (state === 1) {
|
|
1406
|
-
state = 2;
|
|
1407
|
-
xnew$1.emit('-next');
|
|
1408
|
-
}
|
|
1409
|
-
}
|
|
1410
|
-
}
|
|
1411
|
-
|
|
1412
1372
|
const context = new window.AudioContext();
|
|
1413
1373
|
const master = context.createGain();
|
|
1414
1374
|
//----------------------------------------------------------------------------------------------------
|
|
@@ -1637,7 +1597,6 @@ const basics = {
|
|
|
1637
1597
|
Screen,
|
|
1638
1598
|
Modal,
|
|
1639
1599
|
Accordion,
|
|
1640
|
-
TextStream,
|
|
1641
1600
|
AnalogStick,
|
|
1642
1601
|
DirectionalPad,
|
|
1643
1602
|
};
|
|
@@ -1668,15 +1627,6 @@ const audio = {
|
|
|
1668
1627
|
master.gain.value = value;
|
|
1669
1628
|
}
|
|
1670
1629
|
};
|
|
1671
|
-
const
|
|
1672
|
-
Object.defineProperty(temp, 'global', {
|
|
1673
|
-
get: function () {
|
|
1674
|
-
return temp.context('xnew.global');
|
|
1675
|
-
},
|
|
1676
|
-
set: function (value) {
|
|
1677
|
-
temp.context('xnew.global', value);
|
|
1678
|
-
}
|
|
1679
|
-
});
|
|
1680
|
-
const xnew = temp;
|
|
1630
|
+
const xnew = Object.assign(xnew$1, { basics, audio });
|
|
1681
1631
|
|
|
1682
1632
|
export { xnew as default };
|