tiny-essentials 1.28.17 → 1.28.19
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/changelog/1/28/18.md +14 -0
- package/dist/v1/TinyEssentials.min.js +1 -1
- package/dist/v1/TinyRadioFm.min.js +1 -1
- package/dist/v1/css/TinyCookieConsent.min.css +1 -0
- package/dist/v1/css/TinyCookieConsent.min.css.map +1 -0
- package/dist/v1/css/TinyDraggerExample.min.css +1 -0
- package/dist/v1/css/TinyDraggerExample.min.css.map +1 -0
- package/dist/v1/css/TinyLoadingScreen.min.css +1 -0
- package/dist/v1/css/TinyLoadingScreen.min.css.map +1 -0
- package/dist/v1/css/TinyNotify.min.css +1 -0
- package/dist/v1/css/TinyNotify.min.css.map +1 -0
- package/dist/v1/css/aiMarker.min.css +1 -0
- package/dist/v1/css/aiMarker.min.css.map +1 -0
- package/dist/v1/libs/media/TinyRadioFm.cjs +83 -40
- package/dist/v1/libs/media/TinyRadioFm.d.mts +7 -2
- package/dist/v1/libs/media/TinyRadioFm.d.mts.map +1 -1
- package/dist/v1/libs/media/TinyRadioFm.mjs +77 -38
- package/dist/v1/webTemplates/bootstrap/5.3/html/BootstrapDialogs.cjs +699 -0
- package/dist/v1/webTemplates/bootstrap/5.3/html/BootstrapDialogs.d.mts +290 -0
- package/dist/v1/webTemplates/bootstrap/5.3/html/BootstrapDialogs.d.mts.map +1 -0
- package/dist/v1/webTemplates/bootstrap/5.3/html/BootstrapDialogs.mjs +590 -0
- package/dist/v1/webTemplates/bootstrap/5.3/scss/input/Placeholder-Colors-Fix.scss +64 -0
- package/dist/v1/webTemplates/bootstrap/5.3/scss/spacing/Spacing-Plus.scss +31 -0
- package/docs/v1/Exports.md +10 -0
- package/docs/v1/README.md +7 -1
- package/docs/v1/libs/media/TinyRadioFm.md +40 -11
- package/docs/v1/webTemplates/bootstrap/5.3/html/BootstrapDialogs.md +162 -0
- package/package.json +13 -8
|
@@ -121,6 +121,10 @@ export type RadioConfig = {
|
|
|
121
121
|
* - Whether to play voice messages after music tracks.
|
|
122
122
|
*/
|
|
123
123
|
voiceAfterMusic: boolean;
|
|
124
|
+
/**
|
|
125
|
+
* - Weight used to calculate the probability of a voice block occurring.
|
|
126
|
+
*/
|
|
127
|
+
voiceWeight: number;
|
|
124
128
|
/**
|
|
125
129
|
* - Minimum amount of voice messages to play if voiceAfterMusic is true.
|
|
126
130
|
*/
|
|
@@ -142,7 +146,7 @@ export type RadioConfig = {
|
|
|
142
146
|
*/
|
|
143
147
|
voiceMaxConsecutive: number;
|
|
144
148
|
/**
|
|
145
|
-
* - Min times a voice track
|
|
149
|
+
* - Min times a voice track can repeat consecutively (1 = no mandatory repetition).
|
|
146
150
|
*/
|
|
147
151
|
voiceMinConsecutive: number;
|
|
148
152
|
};
|
|
@@ -285,12 +289,13 @@ export type TinyRadioFmImport = {
|
|
|
285
289
|
* @property {number} silenceDuration - Gap in ms between tracks.
|
|
286
290
|
* @property {number} queryLimit - Safety lock for max items processed.
|
|
287
291
|
* @property {boolean} voiceAfterMusic - Whether to play voice messages after music tracks.
|
|
292
|
+
* @property {number} voiceWeight - Weight used to calculate the probability of a voice block occurring.
|
|
288
293
|
* @property {number} voiceMin - Minimum amount of voice messages to play if voiceAfterMusic is true.
|
|
289
294
|
* @property {number} voiceMax - Maximum amount of voice messages to play.
|
|
290
295
|
* @property {number} musicMaxConsecutive - Max times a music track can repeat consecutively (-1 = unlimited, 0 = strictly no repetition).
|
|
291
296
|
* @property {number} musicMinConsecutive - Min times a music track must repeat consecutively (1 = no mandatory repetition).
|
|
292
297
|
* @property {number} voiceMaxConsecutive - Max times a voice track can repeat consecutively (-1 = unlimited, 0 = strictly no repetition).
|
|
293
|
-
* @property {number} voiceMinConsecutive - Min times a voice track
|
|
298
|
+
* @property {number} voiceMinConsecutive - Min times a voice track can repeat consecutively (1 = no mandatory repetition).
|
|
294
299
|
*/
|
|
295
300
|
/**
|
|
296
301
|
* An extension of MediaContent that includes temporal boundaries within a generated cycle.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TinyRadioFm.d.mts","sourceRoot":"","sources":["../../../../src/v1/libs/media/TinyRadioFm.mjs"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;
|
|
1
|
+
{"version":3,"file":"TinyRadioFm.d.mts","sourceRoot":"","sources":["../../../../src/v1/libs/media/TinyRadioFm.mjs"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAenC,YAAmE,eAAe,GAAxE,OAAO,+BAA+B,EAAE,eAAe,CAAiB;AAClF,YAAoE,gBAAgB,GAA1E,OAAO,+BAA+B,EAAE,gBAAgB,CAAkB;AACpF,YAAyF,oBAAoB,GAAnG,OAAO,+BAA+B,EAAE,oBAAoB,CAAC,eAAe,CAAC,CAAsB;AAC7G,YAAiF,YAAY,GAAnF,OAAO,+BAA+B,EAAE,YAAY,CAAC,eAAe,CAAC,CAAc;AAC7F,YAA4D,QAAQ,GAA1D,OAAO,+BAA+B,EAAE,QAAQ,CAAU;AACpE,YAA+D,WAAW,GAAhE,OAAO,+BAA+B,EAAE,WAAW,CAAa;AAC1E,YAAqE,iBAAiB,GAA5E,OAAO,+BAA+B,EAAE,iBAAiB,CAAmB;AACtF,YAAyE,qBAAqB,GAApF,OAAO,+BAA+B,EAAE,qBAAqB,CAAuB;AAC9F,YAAwE,oBAAoB,GAAlF,OAAO,+BAA+B,EAAE,oBAAoB,CAAsB;AAC5F,YAA6E,yBAAyB,GAA5F,OAAO,+BAA+B,EAAE,yBAAyB,CAA2B;AACtG,YAAuE,mBAAmB,GAAhF,OAAO,+BAA+B,EAAE,mBAAmB,CAAqB;AAO1F,YAAkB,cAAc,GAChC;;;;IAAyB,OAAO,EAArB,YAAY,CACvB;;;;IAAmB,iBAAiB,EAAzB,MAAM,CACjB;;;;IAAmB,iBAAiB,EAAzB,MAAM,CACnB;CAAA,CAAA;A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CAAC,SAAS,EAPX,MAOW,EAAE,MAAM,EANnB,KAAK,GAAC,QAAQ,GAAC,MAMI,EAAE,IAAI,EALzB,OAAO,GAAC,OAKiB,EAAE,OAAO,EAJlC,oBAIkC,EAAE,UAAU,AAHtD,CACA,EADQ,OAGqD,QAmE/D;IAED;;;;OAIG;IACH,MAAM,CAAC,EAAE,EAHE,MAGF,QAuCR;IAED;;;;OAIG;IACH,SAAS,CAAC,MAAM,EAHL,OAAO,CAAC,WAAW,CAGd,QAcf;IAED;;;OAGG;IACH,eAAe,IAFF,UAAU,GAAC,IAAI,CAO3B;IAED;;;;;;;;OAQG;IACH,aAAa,CAAC,UAAU,EANb,MAMa,EAAE,KAAK,AAL5B,CACA,EADQ,MAKyB,GAJvB,UAAU,EAAE,CAmCxB;IAED;;;OAGG;IACH,qBAAqB,IAFR,cAAc,EAAE,CAM5B;IAED;;;;;OAKG;YACG,qBAAqB;IAW3B;;;;OAIG;YACH,YAAY;IAYZ;;;OAGG;IACG,WAAW,IAFJ,OAAO,CAAC,MAAM,CAAC,CAwC3B;IAED;;;;OAIG;IACH,WAAW,CAAC,IAAI,EAHL,MAAM,GAAC,iBAGF,QAkBf;IAED;;;;;OAKG;YACH,KAAK;IAioBL;;;;OAIG;IACH,OAAO,CAAC,aAAa,AAFlB,CAAqC,EAA7B,OAEiB,QA4B3B;CACF;eAEc,WAAW"}
|
|
@@ -2,6 +2,7 @@ import { EventEmitter } from 'events';
|
|
|
2
2
|
import { blobUrlToBase64, convertToBlobUrl, parseMediaMetadata, revokeContentUrls, valMediaContentMetadata, } from '../../basics/mediaContent.mjs';
|
|
3
3
|
import { createCheckDestroyed } from '../utils/tools.mjs';
|
|
4
4
|
import { isJsonObject } from '../../basics/objChecker.mjs';
|
|
5
|
+
import TinyAdvancedRaffle from '../math/TinyAdvancedRaffle.mjs';
|
|
5
6
|
const checkDestroy = createCheckDestroyed('TinyRadioFm');
|
|
6
7
|
/**
|
|
7
8
|
* @typedef {import('../../basics/mediaContent.mjs').PictureDataType} PictureDataType
|
|
@@ -71,12 +72,13 @@ const checkDestroy = createCheckDestroyed('TinyRadioFm');
|
|
|
71
72
|
* @property {number} silenceDuration - Gap in ms between tracks.
|
|
72
73
|
* @property {number} queryLimit - Safety lock for max items processed.
|
|
73
74
|
* @property {boolean} voiceAfterMusic - Whether to play voice messages after music tracks.
|
|
75
|
+
* @property {number} voiceWeight - Weight used to calculate the probability of a voice block occurring.
|
|
74
76
|
* @property {number} voiceMin - Minimum amount of voice messages to play if voiceAfterMusic is true.
|
|
75
77
|
* @property {number} voiceMax - Maximum amount of voice messages to play.
|
|
76
78
|
* @property {number} musicMaxConsecutive - Max times a music track can repeat consecutively (-1 = unlimited, 0 = strictly no repetition).
|
|
77
79
|
* @property {number} musicMinConsecutive - Min times a music track must repeat consecutively (1 = no mandatory repetition).
|
|
78
80
|
* @property {number} voiceMaxConsecutive - Max times a voice track can repeat consecutively (-1 = unlimited, 0 = strictly no repetition).
|
|
79
|
-
* @property {number} voiceMinConsecutive - Min times a voice track
|
|
81
|
+
* @property {number} voiceMinConsecutive - Min times a voice track can repeat consecutively (1 = no mandatory repetition).
|
|
80
82
|
*/
|
|
81
83
|
//////////////////////////////////////////////////////////////////
|
|
82
84
|
/**
|
|
@@ -302,6 +304,7 @@ class TinyRadioFm extends EventEmitter {
|
|
|
302
304
|
voiceAfterMusic: true,
|
|
303
305
|
voiceMin: 0,
|
|
304
306
|
voiceMax: 1,
|
|
307
|
+
voiceWeight: 1,
|
|
305
308
|
musicMaxConsecutive: 0,
|
|
306
309
|
musicMinConsecutive: 0,
|
|
307
310
|
voiceMaxConsecutive: 0,
|
|
@@ -363,6 +366,7 @@ class TinyRadioFm extends EventEmitter {
|
|
|
363
366
|
throw new TypeError(`${minKey} must be a non-negative number.`);
|
|
364
367
|
}
|
|
365
368
|
};
|
|
369
|
+
checkRange(config.voiceWeight, 'voiceWeight');
|
|
366
370
|
checkRange(config.voiceMin, 'voiceMin');
|
|
367
371
|
checkRange(config.voiceMax, 'voiceMax');
|
|
368
372
|
checkRange(config.musicMinConsecutive, 'musicMinConsecutive');
|
|
@@ -838,11 +842,6 @@ class TinyRadioFm extends EventEmitter {
|
|
|
838
842
|
consecutiveCount: initialLastId === lastItem.id ? initialConsecutiveCount + 1 : 1,
|
|
839
843
|
};
|
|
840
844
|
}
|
|
841
|
-
/**
|
|
842
|
-
* Pool of available items for weighted selection.
|
|
843
|
-
* @type {Array<MediaContent & { weight: number }>}
|
|
844
|
-
*/
|
|
845
|
-
const pool = list.map((item) => ({ ...item, weight: item.weight ?? 1 }));
|
|
846
845
|
const random = this._prng(currentSeed);
|
|
847
846
|
/**
|
|
848
847
|
* The finalized deterministic sequence.
|
|
@@ -852,6 +851,27 @@ class TinyRadioFm extends EventEmitter {
|
|
|
852
851
|
/** @type {string|null} */
|
|
853
852
|
let lastId = initialLastId;
|
|
854
853
|
let consecutiveCount = initialConsecutiveCount;
|
|
854
|
+
// Initializes TinyAdvancedRaffle specifically for this sequence generation
|
|
855
|
+
const raffle = new TinyAdvancedRaffle({
|
|
856
|
+
rng: random,
|
|
857
|
+
normalization: 'relative',
|
|
858
|
+
});
|
|
859
|
+
// We keep the pool as an array to respect the original structure and support possible
|
|
860
|
+
// duplicate IDs, if they occur (even though it is rare).
|
|
861
|
+
/** @type {MediaContent[]} */
|
|
862
|
+
const pool = [...list];
|
|
863
|
+
// Registers all items in the Raffle system
|
|
864
|
+
pool.forEach((item) => {
|
|
865
|
+
const itemWeight = item.weight ?? 1;
|
|
866
|
+
const existing = raffle.getItem(item.id);
|
|
867
|
+
if (!existing) {
|
|
868
|
+
raffle.addItem(item.id, { weight: itemWeight });
|
|
869
|
+
}
|
|
870
|
+
else {
|
|
871
|
+
// If the ID already exists, we add its weight to maintain the correct proportion
|
|
872
|
+
raffle.setBaseWeight(item.id, existing.baseWeight + itemWeight);
|
|
873
|
+
}
|
|
874
|
+
});
|
|
855
875
|
while (pool.length > 0) {
|
|
856
876
|
/** @type {MediaContent|null} */
|
|
857
877
|
let selectedItem = null;
|
|
@@ -867,32 +887,28 @@ class TinyRadioFm extends EventEmitter {
|
|
|
867
887
|
selectedItem = sequence[sequence.length - 1];
|
|
868
888
|
}
|
|
869
889
|
}
|
|
870
|
-
// 2. Maximum repetition logic and
|
|
890
|
+
// 2. Maximum repetition logic and drawing using the Raffle
|
|
871
891
|
if (!selectedItem) {
|
|
872
|
-
let
|
|
892
|
+
let excludedId = null;
|
|
873
893
|
if (lastId !== null && maxConsecutive !== -1 && consecutiveCount >= maxConsecutive) {
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
if (totalWeight <= 0) {
|
|
881
|
-
selectedItem = validPool[0];
|
|
882
|
-
selectedIndex = pool.findIndex((p) => p.id === selectedItem?.id);
|
|
894
|
+
// Checks if there are other different items in the pool before preventing the last one
|
|
895
|
+
const hasOtherItems = pool.some((item) => item.id !== lastId);
|
|
896
|
+
if (hasOtherItems) {
|
|
897
|
+
raffle.excludeItem(lastId);
|
|
898
|
+
excludedId = lastId;
|
|
899
|
+
}
|
|
883
900
|
}
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
if (r <= sum) {
|
|
890
|
-
selectedItem = validPool[i];
|
|
891
|
-
selectedIndex = pool.findIndex((p) => p.id === selectedItem?.id);
|
|
892
|
-
break;
|
|
893
|
-
}
|
|
901
|
+
const drawResult = raffle.drawOne();
|
|
902
|
+
if (drawResult) {
|
|
903
|
+
selectedIndex = pool.findIndex((item) => item.id === drawResult.id);
|
|
904
|
+
if (selectedIndex !== -1) {
|
|
905
|
+
selectedItem = pool[selectedIndex];
|
|
894
906
|
}
|
|
895
907
|
}
|
|
908
|
+
// Removes the exclusion to avoid breaking future draws
|
|
909
|
+
if (excludedId) {
|
|
910
|
+
raffle.includeItem(excludedId);
|
|
911
|
+
}
|
|
896
912
|
}
|
|
897
913
|
// Safety fallback
|
|
898
914
|
if (!selectedItem) {
|
|
@@ -900,8 +916,25 @@ class TinyRadioFm extends EventEmitter {
|
|
|
900
916
|
selectedIndex = 0;
|
|
901
917
|
}
|
|
902
918
|
sequence.push(selectedItem);
|
|
919
|
+
// Updates the pool and the Raffle after the item has been drawn and used
|
|
903
920
|
if (selectedIndex !== -1) {
|
|
904
921
|
pool.splice(selectedIndex, 1);
|
|
922
|
+
// If this item is no longer in the pool permanently, remove it from the Raffle
|
|
923
|
+
const stillInPool = pool.some((item) => item.id === selectedItem.id);
|
|
924
|
+
if (!stillInPool) {
|
|
925
|
+
raffle.removeItem(selectedItem.id);
|
|
926
|
+
}
|
|
927
|
+
else {
|
|
928
|
+
// If it still exists, we reduce the weight proportionally to continue the draw fairly
|
|
929
|
+
const existing = raffle.getItem(selectedItem.id);
|
|
930
|
+
if (existing) {
|
|
931
|
+
const newWeight = Math.max(0, existing.baseWeight - (selectedItem.weight ?? 1));
|
|
932
|
+
if (newWeight <= 0)
|
|
933
|
+
raffle.removeItem(selectedItem.id);
|
|
934
|
+
else
|
|
935
|
+
raffle.setBaseWeight(selectedItem.id, newWeight);
|
|
936
|
+
}
|
|
937
|
+
}
|
|
905
938
|
}
|
|
906
939
|
if (selectedItem.id === lastId) {
|
|
907
940
|
consecutiveCount++;
|
|
@@ -911,6 +944,7 @@ class TinyRadioFm extends EventEmitter {
|
|
|
911
944
|
consecutiveCount = 1;
|
|
912
945
|
}
|
|
913
946
|
}
|
|
947
|
+
raffle.destroy(); // Ensures memory is cleared at the end of each cycle
|
|
914
948
|
return { items: sequence, lastId, consecutiveCount };
|
|
915
949
|
}
|
|
916
950
|
/**
|
|
@@ -956,17 +990,22 @@ class TinyRadioFm extends EventEmitter {
|
|
|
956
990
|
});
|
|
957
991
|
cycleDuration += music.duration + this.#config.silenceDuration;
|
|
958
992
|
if (this.#config.voiceAfterMusic && voiceSeq.length > 0) {
|
|
959
|
-
|
|
960
|
-
const
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
993
|
+
// Calculate chance based on weight: P = W / (W + 1)
|
|
994
|
+
const voiceChance = this.#config.voiceWeight / (this.#config.voiceWeight + 1);
|
|
995
|
+
// Only proceed if the random roll is less than the calculated chance
|
|
996
|
+
if (mixRandom() < voiceChance) {
|
|
997
|
+
const range = this.#config.voiceMax - this.#config.voiceMin + 1;
|
|
998
|
+
const voiceAmount = Math.floor(mixRandom() * range) + this.#config.voiceMin;
|
|
999
|
+
for (let v = 0; v < voiceAmount; v++) {
|
|
1000
|
+
const voice = voiceSeq[voiceCursor % voiceSeq.length];
|
|
1001
|
+
voiceCursor++;
|
|
1002
|
+
block.push({
|
|
1003
|
+
...voice,
|
|
1004
|
+
cycleStart: cycleDuration,
|
|
1005
|
+
cycleEnd: cycleDuration + voice.duration,
|
|
1006
|
+
});
|
|
1007
|
+
cycleDuration += voice.duration + this.#config.silenceDuration;
|
|
1008
|
+
}
|
|
970
1009
|
}
|
|
971
1010
|
}
|
|
972
1011
|
}
|