tiny-essentials 1.20.3 → 1.21.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 +13 -11
- package/dist/_/numbers.cjs +136 -0
- package/dist/_/numbers.d.mts +24 -0
- package/dist/_/numbers.mjs +102 -0
- package/dist/v1/TinyAdvancedRaffle.min.js +1 -0
- package/dist/v1/TinyArrayPaginator.min.js +1 -0
- package/dist/v1/TinyBasicsEs.min.js +1 -1
- package/dist/v1/TinyCookieConsent.min.js +1 -0
- package/dist/v1/TinyDayNightCycle.min.js +1 -0
- package/dist/v1/TinyEssentials.min.js +1 -1
- package/dist/v1/TinyGamepad.min.js +1 -0
- package/dist/v1/TinyI18.min.js +1 -0
- package/dist/v1/TinyInventory.min.js +1 -0
- package/dist/v1/TinyInventoryTrader.min.js +1 -0
- package/dist/v1/TinyLocalStorage.min.js +1 -1
- package/dist/v1/TinyNeedBar.min.js +1 -0
- package/dist/v1/TinyRateLimiter.min.js +1 -1
- package/dist/v1/TinySmartScroller.min.js +1 -1
- package/dist/v1/TinyToastNotify.min.js +1 -1
- package/dist/v1/TinyUploadClicker.min.js +1 -1
- package/dist/v1/basics/array.cjs +21 -0
- package/dist/v1/basics/array.d.mts +8 -0
- package/dist/v1/basics/array.mjs +18 -0
- package/dist/v1/basics/clock.cjs +127 -11
- package/dist/v1/basics/clock.d.mts +26 -0
- package/dist/v1/basics/clock.mjs +96 -1
- package/dist/v1/basics/index.cjs +2 -8
- package/dist/v1/basics/index.d.mts +3 -8
- package/dist/v1/basics/index.mjs +2 -3
- package/dist/v1/basics/simpleMath.cjs +46 -0
- package/dist/v1/basics/simpleMath.d.mts +27 -0
- package/dist/v1/basics/simpleMath.mjs +42 -0
- package/dist/v1/build/TinyAdvancedRaffle.cjs +7 -0
- package/dist/v1/build/TinyAdvancedRaffle.d.mts +3 -0
- package/dist/v1/build/TinyAdvancedRaffle.mjs +2 -0
- package/dist/v1/build/TinyArrayPaginator.cjs +7 -0
- package/dist/v1/build/TinyArrayPaginator.d.mts +3 -0
- package/dist/v1/build/TinyArrayPaginator.mjs +2 -0
- package/dist/v1/build/TinyCookieConsent.cjs +7 -0
- package/dist/v1/build/TinyCookieConsent.d.mts +3 -0
- package/dist/v1/build/TinyCookieConsent.mjs +2 -0
- package/dist/v1/build/TinyDayNightCycle.cjs +7 -0
- package/dist/v1/build/TinyDayNightCycle.d.mts +3 -0
- package/dist/v1/build/TinyDayNightCycle.mjs +2 -0
- package/dist/v1/build/TinyGamepad.cjs +7 -0
- package/dist/v1/build/TinyGamepad.d.mts +3 -0
- package/dist/v1/build/TinyGamepad.mjs +2 -0
- package/dist/v1/build/TinyI18.cjs +7 -0
- package/dist/v1/build/TinyI18.d.mts +3 -0
- package/dist/v1/build/TinyI18.mjs +2 -0
- package/dist/v1/build/TinyInventory.cjs +7 -0
- package/dist/v1/build/TinyInventory.d.mts +3 -0
- package/dist/v1/build/TinyInventory.mjs +2 -0
- package/dist/v1/build/TinyInventoryTrader.cjs +7 -0
- package/dist/v1/build/TinyInventoryTrader.d.mts +3 -0
- package/dist/v1/build/TinyInventoryTrader.mjs +2 -0
- package/dist/v1/build/TinyNeedBar.cjs +7 -0
- package/dist/v1/build/TinyNeedBar.d.mts +3 -0
- package/dist/v1/build/TinyNeedBar.mjs +2 -0
- package/dist/v1/css/TinyCookieConsent.min.css +1 -0
- package/dist/v1/index.cjs +20 -8
- package/dist/v1/index.d.mts +12 -8
- package/dist/v1/index.mjs +11 -3
- package/dist/v1/libs/TinyAdvancedRaffle.cjs +1654 -0
- package/dist/v1/libs/TinyAdvancedRaffle.d.mts +851 -0
- package/dist/v1/libs/TinyAdvancedRaffle.mjs +1477 -0
- package/dist/v1/libs/TinyArrayPaginator.cjs +132 -0
- package/dist/v1/libs/TinyArrayPaginator.d.mts +78 -0
- package/dist/v1/libs/TinyArrayPaginator.mjs +119 -0
- package/dist/v1/libs/TinyCookieConsent.cjs +278 -0
- package/dist/v1/libs/TinyCookieConsent.d.mts +142 -0
- package/dist/v1/libs/TinyCookieConsent.mjs +248 -0
- package/dist/v1/libs/TinyDayNightCycle.cjs +1389 -0
- package/dist/v1/libs/TinyDayNightCycle.d.mts +673 -0
- package/dist/v1/libs/TinyDayNightCycle.mjs +1232 -0
- package/dist/v1/libs/TinyGamepad.cjs +2690 -0
- package/dist/v1/libs/TinyGamepad.d.mts +1286 -0
- package/dist/v1/libs/TinyGamepad.mjs +2386 -0
- package/dist/v1/libs/TinyHtml.d.mts +2 -2
- package/dist/v1/libs/TinyI18.cjs +946 -0
- package/dist/v1/libs/TinyI18.d.mts +418 -0
- package/dist/v1/libs/TinyI18.mjs +873 -0
- package/dist/v1/libs/TinyInventory.cjs +1788 -0
- package/dist/v1/libs/TinyInventory.d.mts +871 -0
- package/dist/v1/libs/TinyInventory.mjs +1650 -0
- package/dist/v1/libs/TinyInventoryTrader.cjs +242 -0
- package/dist/v1/libs/TinyInventoryTrader.d.mts +95 -0
- package/dist/v1/libs/TinyInventoryTrader.mjs +212 -0
- package/dist/v1/libs/TinyLocalStorage.cjs +14 -1
- package/dist/v1/libs/TinyLocalStorage.mjs +8 -1
- package/dist/v1/libs/TinyNeedBar.cjs +272 -0
- package/dist/v1/libs/TinyNeedBar.d.mts +223 -0
- package/dist/v1/libs/TinyNeedBar.mjs +241 -0
- package/dist/v1/libs/TinyRateLimiter.cjs +0 -13
- package/dist/v1/libs/TinyRateLimiter.d.mts +0 -8
- package/dist/v1/libs/TinyRateLimiter.mjs +0 -12
- package/dist/v1/libs/TinySmartScroller.cjs +0 -51
- package/dist/v1/libs/TinySmartScroller.d.mts +0 -36
- package/dist/v1/libs/TinySmartScroller.mjs +0 -46
- package/dist/v1/libs/TinyToastNotify.cjs +2 -2
- package/dist/v1/libs/TinyToastNotify.mjs +2 -2
- package/dist/v1/libs/TinyUploadClicker.cjs +1 -1
- package/docs/v1/Ai-Tips.md +51 -0
- package/docs/v1/Personal-Ai-Prompts(portuguese).md +134 -0
- package/docs/v1/Personal-Ai-Prompts.md +113 -0
- package/docs/v1/README.md +24 -0
- package/docs/v1/basics/array.md +17 -0
- package/docs/v1/basics/clock.md +51 -11
- package/docs/v1/basics/simpleMath.md +73 -0
- package/docs/v1/libs/TinyAdvancedRaffle.md +674 -0
- package/docs/v1/libs/TinyArrayPaginator.md +150 -0
- package/docs/v1/libs/TinyCookieConsent.md +152 -0
- package/docs/v1/libs/TinyDayNightCycle.md +711 -0
- package/docs/v1/libs/TinyGamepad.md +980 -0
- package/docs/v1/libs/TinyI18.md +515 -0
- package/docs/v1/libs/TinyInventory.md +777 -0
- package/docs/v1/libs/TinyInventoryTrader.md +114 -0
- package/docs/v1/libs/TinyNeedBar.md +226 -0
- package/package.json +7 -5
- package/dist/v1/basics/html_deprecated.cjs +0 -124
- package/dist/v1/basics/html_deprecated.d.mts +0 -40
- package/dist/v1/basics/html_deprecated.mjs +0 -97
- package/dist/v1/css/TinyDraggerExample.css +0 -21
- package/dist/v1/css/TinyNotify.css +0 -350
- package/dist/v1/css/aiMarker.css +0 -4
- package/docs/v1/basics/html_deprecated.md +0 -127
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
# 📦 TinyInventoryTrader
|
|
2
|
+
|
|
3
|
+
`TinyInventoryTrader` is a helper class designed to manage item transfers between two [`TinyInventory`](./TinyInventory.mjs) instances.
|
|
4
|
+
It ensures safe and configurable trading with support for strict validation, slot targeting, and batch operations.
|
|
5
|
+
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
## 🔖 Typedefs
|
|
9
|
+
|
|
10
|
+
### `TransferItemCfg`
|
|
11
|
+
|
|
12
|
+
Configuration object for a single transfer.
|
|
13
|
+
|
|
14
|
+
| Property | Type | Default | Description |
|
|
15
|
+
| ------------------- | --------- | ------- | ---------------------------------------------------------------------------- |
|
|
16
|
+
| `slotIndex` | `number` | — | Sender slot index. |
|
|
17
|
+
| `receiverSlotIndex` | `number` | — | Receiver slot index (optional). |
|
|
18
|
+
| `specialSlot` | `string` | — | Sender special slot ID. |
|
|
19
|
+
| `quantity` | `number` | `1` | Quantity to transfer. |
|
|
20
|
+
| `forceSpace` | `boolean` | `false` | Whether to force addition even if space is limited. |
|
|
21
|
+
| `strict` | `boolean` | `false` | If `true`, transfer will throw if the receiver cannot fully fit the item(s). |
|
|
22
|
+
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
## 🏗️ Class: `TinyInventoryTrader`
|
|
26
|
+
|
|
27
|
+
Manages item transfers between two `TinyInventory` instances.
|
|
28
|
+
|
|
29
|
+
### 🔑 Private Fields
|
|
30
|
+
|
|
31
|
+
* `#sender` → `TinyInventory|null`
|
|
32
|
+
* `#receiver` → `TinyInventory|null`
|
|
33
|
+
|
|
34
|
+
---
|
|
35
|
+
|
|
36
|
+
### 📥 Constructor
|
|
37
|
+
|
|
38
|
+
```js
|
|
39
|
+
new TinyInventoryTrader(sender?, receiver?)
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
* **Parameters:**
|
|
43
|
+
|
|
44
|
+
* `sender` (`TinyInventory`) → Inventory to remove items from.
|
|
45
|
+
* `receiver` (`TinyInventory`) → Inventory to add items to.
|
|
46
|
+
* **Throws:** If either argument is not a valid `TinyInventory`.
|
|
47
|
+
|
|
48
|
+
---
|
|
49
|
+
|
|
50
|
+
### 📌 Properties
|
|
51
|
+
|
|
52
|
+
* `sender` → `TinyInventory|null`
|
|
53
|
+
Current sender inventory. Setting it requires the receiver to also be a valid `TinyInventory`.
|
|
54
|
+
|
|
55
|
+
* `receiver` → `TinyInventory|null`
|
|
56
|
+
Current receiver inventory. Setting it requires the sender to also be a valid `TinyInventory`.
|
|
57
|
+
|
|
58
|
+
---
|
|
59
|
+
|
|
60
|
+
### 🔧 Methods
|
|
61
|
+
|
|
62
|
+
#### `connect(sender, receiver)`
|
|
63
|
+
|
|
64
|
+
Connects the sender and receiver inventories.
|
|
65
|
+
|
|
66
|
+
* **Parameters:**
|
|
67
|
+
|
|
68
|
+
* `sender` (`TinyInventory`) → Inventory to remove items from.
|
|
69
|
+
* `receiver` (`TinyInventory`) → Inventory to add items to.
|
|
70
|
+
* **Throws:** If arguments are not `TinyInventory`.
|
|
71
|
+
|
|
72
|
+
---
|
|
73
|
+
|
|
74
|
+
#### `disconnect()`
|
|
75
|
+
|
|
76
|
+
Disconnects both sender and receiver, preventing transfers.
|
|
77
|
+
|
|
78
|
+
---
|
|
79
|
+
|
|
80
|
+
#### `invert()`
|
|
81
|
+
|
|
82
|
+
Swaps sender and receiver roles.
|
|
83
|
+
Useful for bidirectional trading.
|
|
84
|
+
|
|
85
|
+
---
|
|
86
|
+
|
|
87
|
+
#### `transferItem(options)`
|
|
88
|
+
|
|
89
|
+
Transfers an item from sender to receiver.
|
|
90
|
+
|
|
91
|
+
* **Parameters:**
|
|
92
|
+
|
|
93
|
+
* `options` (`TransferItemCfg`) → Transfer configuration.
|
|
94
|
+
* **Returns:** `Partial<AddItemResult>` → Remaining quantity that could not be transferred.
|
|
95
|
+
* **Throws:**
|
|
96
|
+
|
|
97
|
+
* If sender or receiver is not connected.
|
|
98
|
+
* If item does not exist in sender.
|
|
99
|
+
* If `strict` is `true` and the receiver cannot fully fit the item.
|
|
100
|
+
|
|
101
|
+
---
|
|
102
|
+
|
|
103
|
+
#### `transferMultiple(items)`
|
|
104
|
+
|
|
105
|
+
Transfers multiple items at once.
|
|
106
|
+
|
|
107
|
+
* **Parameters:**
|
|
108
|
+
|
|
109
|
+
* `items` (`TransferItemCfg[]`) → Array of transfer configurations.
|
|
110
|
+
* **Returns:** `Partial<AddItemResult>[]` → Array of remaining quantities per transfer.
|
|
111
|
+
|
|
112
|
+
---
|
|
113
|
+
|
|
114
|
+
✨ With this class, you can safely move items between inventories with flexible rules, slot targeting, strict enforcement, and even batch transfers.
|
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
# 🛠️ TinyNeedBar Documentation
|
|
2
|
+
|
|
3
|
+
`TinyNeedBar` is a utility class for simulating a **"need bar" system**.
|
|
4
|
+
It allows tracking of values that decrease over time, with configurable decay factors.
|
|
5
|
+
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
## 📦 Types
|
|
9
|
+
|
|
10
|
+
### `TickResult` 🔄
|
|
11
|
+
|
|
12
|
+
Represents the result of one tick of decay.
|
|
13
|
+
|
|
14
|
+
| Property | Type | Description |
|
|
15
|
+
| ------------------- | -------- | ----------------------------------------- |
|
|
16
|
+
| `prevValue` | `number` | Infinite value before applying decay. |
|
|
17
|
+
| `removedTotal` | `number` | Total amount removed this tick. |
|
|
18
|
+
| `removedPercent` | `number` | Percentage of max removed this tick. |
|
|
19
|
+
| `currentPercent` | `number` | Current percentage relative to max. |
|
|
20
|
+
| `remainingValue` | `number` | Current clamped value (≥ 0). |
|
|
21
|
+
| `infiniteRemaining` | `number` | Current infinite value (can be negative). |
|
|
22
|
+
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
### `BarFactor` ⚡
|
|
26
|
+
|
|
27
|
+
Represents a decay factor applied to the need bar.
|
|
28
|
+
|
|
29
|
+
| Property | Type | Description |
|
|
30
|
+
| ------------ | -------- | --------------------------------- |
|
|
31
|
+
| `amount` | `number` | Base reduction value per tick. |
|
|
32
|
+
| `multiplier` | `number` | Multiplier applied to the amount. |
|
|
33
|
+
|
|
34
|
+
---
|
|
35
|
+
|
|
36
|
+
### `SerializedData` 💾
|
|
37
|
+
|
|
38
|
+
Represents the serialized state of a `TinyNeedBar` instance.
|
|
39
|
+
Can be used to export/import or clone bars.
|
|
40
|
+
|
|
41
|
+
| Property | Type | Description |
|
|
42
|
+
| --------------- | --------------------------- | ------------------------------------------- |
|
|
43
|
+
| `maxValue` | `number` | Maximum value of the bar at serialization. |
|
|
44
|
+
| `currentValue` | `number` | Current clamped value (≥ 0). |
|
|
45
|
+
| `infiniteValue` | `number` | Infinite value (can be negative). |
|
|
46
|
+
| `factors` | `Record<string, BarFactor>` | Active decay factors indexed by their keys. |
|
|
47
|
+
|
|
48
|
+
---
|
|
49
|
+
|
|
50
|
+
## 🏗️ Class: `TinyNeedBar`
|
|
51
|
+
|
|
52
|
+
### Overview
|
|
53
|
+
|
|
54
|
+
* The bar decreases over time according to **defined factors**.
|
|
55
|
+
* Each factor has an `amount` and a `multiplier`.
|
|
56
|
+
* Tracks two values:
|
|
57
|
+
|
|
58
|
+
* `currentValue` → cannot go below zero.
|
|
59
|
+
* `infiniteValue` → can decrease infinitely into negative numbers.
|
|
60
|
+
|
|
61
|
+
---
|
|
62
|
+
|
|
63
|
+
### Constructor
|
|
64
|
+
|
|
65
|
+
```ts
|
|
66
|
+
constructor(maxValue = 100, baseDecay = 1, baseDecayMulti = 1)
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
* `maxValue` – Maximum bar value (default `100`)
|
|
70
|
+
* `baseDecay` – Base decay per tick (default `1`)
|
|
71
|
+
* `baseDecayMulti` – Multiplier for base decay (default `1`)
|
|
72
|
+
|
|
73
|
+
**Example:**
|
|
74
|
+
|
|
75
|
+
```js
|
|
76
|
+
const bar = new TinyNeedBar(100, 2, 1.5);
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
---
|
|
80
|
+
|
|
81
|
+
### Getters
|
|
82
|
+
|
|
83
|
+
| Getter | Returns | Description |
|
|
84
|
+
| ---------------- | --------------------------- | ----------------------------------------- |
|
|
85
|
+
| `factors` | `Record<string, BarFactor>` | Snapshot of all active factors. |
|
|
86
|
+
| `currentPercent` | `number` | Current percentage relative to max. |
|
|
87
|
+
| `maxValue` | `number` | Maximum possible value of the bar. |
|
|
88
|
+
| `currentValue` | `number` | Current clamped value (≥ 0). |
|
|
89
|
+
| `infiniteValue` | `number` | Current infinite value (can go negative). |
|
|
90
|
+
|
|
91
|
+
---
|
|
92
|
+
|
|
93
|
+
### Setters
|
|
94
|
+
|
|
95
|
+
| Setter | Parameters | Description |
|
|
96
|
+
| --------------- | --------------- | -------------------------------------------------- |
|
|
97
|
+
| `maxValue` | `value: number` | Update max value, clamps `currentValue` if needed. |
|
|
98
|
+
| `infiniteValue` | `value: number` | Update infinite value, auto-adjust `currentValue`. |
|
|
99
|
+
|
|
100
|
+
---
|
|
101
|
+
|
|
102
|
+
### Methods
|
|
103
|
+
|
|
104
|
+
#### `getFactor(key: string): BarFactor` 🔑
|
|
105
|
+
|
|
106
|
+
Get a specific factor by key.
|
|
107
|
+
Throws an error if the factor does not exist.
|
|
108
|
+
|
|
109
|
+
```js
|
|
110
|
+
bar.getFactor("main");
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
---
|
|
114
|
+
|
|
115
|
+
#### `hasFactor(key: string): boolean` ✅
|
|
116
|
+
|
|
117
|
+
Check if a factor exists by key.
|
|
118
|
+
|
|
119
|
+
```js
|
|
120
|
+
bar.hasFactor("main"); // true or false
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
---
|
|
124
|
+
|
|
125
|
+
#### `setFactor(key: string, amount: number, multiplier = 1)` ⚡
|
|
126
|
+
|
|
127
|
+
Add or update a decay factor.
|
|
128
|
+
|
|
129
|
+
```js
|
|
130
|
+
bar.setFactor("hunger", 2, 1.2);
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
---
|
|
134
|
+
|
|
135
|
+
#### `removeFactor(key: string)` ❌
|
|
136
|
+
|
|
137
|
+
Remove a factor by key.
|
|
138
|
+
|
|
139
|
+
```js
|
|
140
|
+
bar.removeFactor("hunger");
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
---
|
|
144
|
+
|
|
145
|
+
#### `tick(): TickResult` ⏱️
|
|
146
|
+
|
|
147
|
+
Execute one tick of decay using all active factors.
|
|
148
|
+
|
|
149
|
+
```js
|
|
150
|
+
const result = bar.tick();
|
|
151
|
+
console.log(result.remainingValue);
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
---
|
|
155
|
+
|
|
156
|
+
#### `toJSON(): SerializedData` 💾
|
|
157
|
+
|
|
158
|
+
Serialize the current state to a JSON-compatible object.
|
|
159
|
+
|
|
160
|
+
```js
|
|
161
|
+
const data = bar.toJSON();
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
---
|
|
165
|
+
|
|
166
|
+
#### `static fromJSON(data: SerializedData): TinyNeedBar` 📤
|
|
167
|
+
|
|
168
|
+
Restore a `TinyNeedBar` from serialized data.
|
|
169
|
+
|
|
170
|
+
```js
|
|
171
|
+
const newBar = TinyNeedBar.fromJSON(data);
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
---
|
|
175
|
+
|
|
176
|
+
#### `clone(): TinyNeedBar` 🧬
|
|
177
|
+
|
|
178
|
+
Deep clone the bar.
|
|
179
|
+
|
|
180
|
+
```js
|
|
181
|
+
const cloned = bar.clone();
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
---
|
|
185
|
+
|
|
186
|
+
#### `clearFactors()` 🧹
|
|
187
|
+
|
|
188
|
+
Remove all factors.
|
|
189
|
+
|
|
190
|
+
```js
|
|
191
|
+
bar.clearFactors();
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
---
|
|
195
|
+
|
|
196
|
+
### ✅ Example Usage
|
|
197
|
+
|
|
198
|
+
```js
|
|
199
|
+
const bar = new TinyNeedBar(100, 2, 1.5);
|
|
200
|
+
|
|
201
|
+
// Add extra factors
|
|
202
|
+
bar.setFactor("energy", 1, 1.2);
|
|
203
|
+
bar.setFactor("fun", 0.5, 1);
|
|
204
|
+
|
|
205
|
+
// Tick simulation
|
|
206
|
+
setInterval(() => {
|
|
207
|
+
const result = bar.tick();
|
|
208
|
+
console.log(`Value: ${result.remainingValue} (${result.currentPercent}%)`);
|
|
209
|
+
}, 1000);
|
|
210
|
+
|
|
211
|
+
// Export / Import
|
|
212
|
+
const json = bar.toJSON();
|
|
213
|
+
const restored = TinyNeedBar.fromJSON(json);
|
|
214
|
+
|
|
215
|
+
// Clone
|
|
216
|
+
const clone = bar.clone();
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
---
|
|
220
|
+
|
|
221
|
+
### 🎨 Notes
|
|
222
|
+
|
|
223
|
+
* Designed for simulation & testing.
|
|
224
|
+
* Can handle multiple independent decay factors.
|
|
225
|
+
* `infiniteValue` is useful for simulations that allow negative overflow.
|
|
226
|
+
* Fully serializable for state saving/loading.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tiny-essentials",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.21.1",
|
|
4
4
|
"description": "Collection of small, essential scripts designed to be used across various projects. These simple utilities are crafted for speed, ease of use, and versatility.",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"test": "npm run test:mjs && npm run test:cjs && npm run test:js",
|
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
"test:mjs:ratelimit": "node test/index.mjs rateLimit",
|
|
15
15
|
"test:mjs:levelup": "node test/index.mjs levelUp",
|
|
16
16
|
"test:mjs:filemanager": "node test/index.mjs fileManager",
|
|
17
|
+
"test:mjs:i18": "node test/index.mjs i18",
|
|
17
18
|
"fix:prettier": "npm run fix:prettier:src && npm run fix:prettier:test && npm run fix:prettier:rollup.config && npm run fix:prettier:webpack.config",
|
|
18
19
|
"fix:prettier:src": "prettier --write ./src/*",
|
|
19
20
|
"fix:prettier:test": "prettier --write ./test/*",
|
|
@@ -24,10 +25,11 @@
|
|
|
24
25
|
"build:js": "tsc -p tsconfig.json && rollup -c && webpack --mode production",
|
|
25
26
|
"build-clean": "npm run clean && npm run build",
|
|
26
27
|
"build-dist": "npm run build",
|
|
27
|
-
"build:css": "npm run build:css:aimaker && npm run build:css:tinynotify && npm run build:css:tinydragger:example",
|
|
28
|
-
"build:css:tinydragger:example": "sass src/v1/scss/TinyDraggerExample.scss dist/v1/css/TinyDraggerExample.
|
|
29
|
-
"build:css:aimaker": "sass src/v1/scss/aiMarker.scss dist/v1/css/aiMarker.
|
|
30
|
-
"build:css:tinynotify": "sass src/v1/scss/TinyNotify.scss dist/v1/css/TinyNotify.
|
|
28
|
+
"build:css": "npm run build:css:aimaker && npm run build:css:tinynotify && npm run build:css:tinydragger:example && npm run build:css:tinycookieconsent",
|
|
29
|
+
"build:css:tinydragger:example": "sass src/v1/scss/TinyDraggerExample.scss dist/v1/css/TinyDraggerExample.min.css --no-source-map --style=compressed",
|
|
30
|
+
"build:css:aimaker": "sass src/v1/scss/aiMarker.scss dist/v1/css/aiMarker.min.css --no-source-map --style=compressed",
|
|
31
|
+
"build:css:tinynotify": "sass src/v1/scss/TinyNotify.scss dist/v1/css/TinyNotify.min.css --no-source-map --style=compressed",
|
|
32
|
+
"build:css:tinycookieconsent": "sass src/v1/scss/TinyCookieConsent.scss dist/v1/css/TinyCookieConsent.min.css --no-source-map --style=compressed",
|
|
31
33
|
"clean": "rm -rf dist",
|
|
32
34
|
"prepublishOnly": "npm run build"
|
|
33
35
|
},
|
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var TinyHtml = require('../libs/TinyHtml.cjs');
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Checks if two DOM elements are colliding on the screen.
|
|
7
|
-
*
|
|
8
|
-
* @param {Element} elem1 - First DOM element.
|
|
9
|
-
* @param {Element} elem2 - Second DOM element.
|
|
10
|
-
* @returns {boolean} - Returns true if the elements are colliding.
|
|
11
|
-
* @deprecated - Use TinyHtml.isCollWith instead.
|
|
12
|
-
*/
|
|
13
|
-
function areHtmlElsColliding(elem1, elem2) {
|
|
14
|
-
return TinyHtml.isCollWith(elem1, elem2);
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Checks if two DOM elements are colliding on the screen.
|
|
19
|
-
*
|
|
20
|
-
* @param {Element} elem1 - First DOM element.
|
|
21
|
-
* @param {Element} elem2 - Second DOM element.
|
|
22
|
-
* @returns {boolean} - Returns true if the elements are colliding.
|
|
23
|
-
* @deprecated - Use TinyHtml.isCollPerfWith instead.
|
|
24
|
-
*/
|
|
25
|
-
function areHtmlElsPerfColliding(elem1, elem2) {
|
|
26
|
-
return TinyHtml.isCollPerfWith(elem1, elem2);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
///////////////////////////////////////////////////////////////////////////
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* @typedef {import('../libs/TinyHtml.mjs').HtmlElBoxSides} HtmlElBoxSides
|
|
33
|
-
*/
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Returns the total border width and individual sides from `border{Side}Width` CSS properties.
|
|
37
|
-
*
|
|
38
|
-
* @param {Element} el - The target DOM element.
|
|
39
|
-
* @returns {HtmlElBoxSides} - Total horizontal (x) and vertical (y) border widths, and each side individually.
|
|
40
|
-
* @deprecated - Use TinyHtml.borderWidth instead.
|
|
41
|
-
*/
|
|
42
|
-
const getHtmlElBordersWidth = (el) => {
|
|
43
|
-
return TinyHtml.borderWidth(el);
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* Returns the total border size and individual sides from `border{Side}` CSS properties.
|
|
48
|
-
*
|
|
49
|
-
* @param {Element} el - The target DOM element.
|
|
50
|
-
* @returns {HtmlElBoxSides} - Total horizontal (x) and vertical (y) border sizes, and each side individually.
|
|
51
|
-
* @deprecated - Use TinyHtml.border instead.
|
|
52
|
-
*/
|
|
53
|
-
const getHtmlElBorders = (el) => {
|
|
54
|
-
return TinyHtml.border(el);
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* Returns the total margin and individual sides from `margin{Side}` CSS properties.
|
|
59
|
-
*
|
|
60
|
-
* @param {Element} el - The target DOM element.
|
|
61
|
-
* @returns {HtmlElBoxSides} - Total horizontal (x) and vertical (y) margins, and each side individually.
|
|
62
|
-
* @deprecated - Use TinyHtml.margin instead.
|
|
63
|
-
*/
|
|
64
|
-
const getHtmlElMargin = (el) => {
|
|
65
|
-
return TinyHtml.margin(el);
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* Returns the total padding and individual sides from `padding{Side}` CSS properties.
|
|
70
|
-
*
|
|
71
|
-
* @param {Element} el - The target DOM element.
|
|
72
|
-
* @returns {HtmlElBoxSides} - Total horizontal (x) and vertical (y) paddings, and each side individually.
|
|
73
|
-
* @deprecated - Use TinyHtml.padding instead.
|
|
74
|
-
*/
|
|
75
|
-
const getHtmlElPadding = (el) => {
|
|
76
|
-
return TinyHtml.padding(el);
|
|
77
|
-
};
|
|
78
|
-
|
|
79
|
-
/////////////////////////////////////////////////////////////
|
|
80
|
-
|
|
81
|
-
// The new version will receive great modifications, the deprecated code has been preserved for non-glitch designs that are using the original code.
|
|
82
|
-
|
|
83
|
-
/**
|
|
84
|
-
* Checks if the given element is at least partially visible in the viewport.
|
|
85
|
-
*
|
|
86
|
-
* @param {HTMLElement} element - The DOM element to check.
|
|
87
|
-
* @returns {boolean} True if the element is partially in the viewport, false otherwise.
|
|
88
|
-
* @deprecated - Use TinyHtml.isInViewport instead.
|
|
89
|
-
*/
|
|
90
|
-
function isInViewport(element) {
|
|
91
|
-
const elementTop = element.offsetTop;
|
|
92
|
-
const elementBottom = elementTop + element.offsetHeight;
|
|
93
|
-
|
|
94
|
-
const viewportTop = window.scrollY;
|
|
95
|
-
const viewportBottom = viewportTop + window.innerHeight;
|
|
96
|
-
|
|
97
|
-
return elementBottom > viewportTop && elementTop < viewportBottom;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
/**
|
|
101
|
-
* Checks if the given element is fully visible in the viewport (top and bottom).
|
|
102
|
-
*
|
|
103
|
-
* @param {HTMLElement} element - The DOM element to check.
|
|
104
|
-
* @returns {boolean} True if the element is fully visible in the viewport, false otherwise.
|
|
105
|
-
* @deprecated - Use TinyHtml.isScrolledIntoView instead.
|
|
106
|
-
*/
|
|
107
|
-
function isScrolledIntoView(element) {
|
|
108
|
-
const viewportTop = window.scrollY;
|
|
109
|
-
const viewportBottom = viewportTop + window.innerHeight;
|
|
110
|
-
|
|
111
|
-
const elemTop = element.offsetTop;
|
|
112
|
-
const elemBottom = elemTop + element.offsetHeight;
|
|
113
|
-
|
|
114
|
-
return elemBottom <= viewportBottom && elemTop >= viewportTop;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
exports.areHtmlElsColliding = areHtmlElsColliding;
|
|
118
|
-
exports.areHtmlElsPerfColliding = areHtmlElsPerfColliding;
|
|
119
|
-
exports.getHtmlElBorders = getHtmlElBorders;
|
|
120
|
-
exports.getHtmlElBordersWidth = getHtmlElBordersWidth;
|
|
121
|
-
exports.getHtmlElMargin = getHtmlElMargin;
|
|
122
|
-
exports.getHtmlElPadding = getHtmlElPadding;
|
|
123
|
-
exports.isInViewport = isInViewport;
|
|
124
|
-
exports.isScrolledIntoView = isScrolledIntoView;
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Checks if two DOM elements are colliding on the screen.
|
|
3
|
-
*
|
|
4
|
-
* @param {Element} elem1 - First DOM element.
|
|
5
|
-
* @param {Element} elem2 - Second DOM element.
|
|
6
|
-
* @returns {boolean} - Returns true if the elements are colliding.
|
|
7
|
-
* @deprecated - Use TinyHtml.isCollWith instead.
|
|
8
|
-
*/
|
|
9
|
-
export function areHtmlElsColliding(elem1: Element, elem2: Element): boolean;
|
|
10
|
-
/**
|
|
11
|
-
* Checks if two DOM elements are colliding on the screen.
|
|
12
|
-
*
|
|
13
|
-
* @param {Element} elem1 - First DOM element.
|
|
14
|
-
* @param {Element} elem2 - Second DOM element.
|
|
15
|
-
* @returns {boolean} - Returns true if the elements are colliding.
|
|
16
|
-
* @deprecated - Use TinyHtml.isCollPerfWith instead.
|
|
17
|
-
*/
|
|
18
|
-
export function areHtmlElsPerfColliding(elem1: Element, elem2: Element): boolean;
|
|
19
|
-
/**
|
|
20
|
-
* Checks if the given element is at least partially visible in the viewport.
|
|
21
|
-
*
|
|
22
|
-
* @param {HTMLElement} element - The DOM element to check.
|
|
23
|
-
* @returns {boolean} True if the element is partially in the viewport, false otherwise.
|
|
24
|
-
* @deprecated - Use TinyHtml.isInViewport instead.
|
|
25
|
-
*/
|
|
26
|
-
export function isInViewport(element: HTMLElement): boolean;
|
|
27
|
-
/**
|
|
28
|
-
* Checks if the given element is fully visible in the viewport (top and bottom).
|
|
29
|
-
*
|
|
30
|
-
* @param {HTMLElement} element - The DOM element to check.
|
|
31
|
-
* @returns {boolean} True if the element is fully visible in the viewport, false otherwise.
|
|
32
|
-
* @deprecated - Use TinyHtml.isScrolledIntoView instead.
|
|
33
|
-
*/
|
|
34
|
-
export function isScrolledIntoView(element: HTMLElement): boolean;
|
|
35
|
-
export function getHtmlElBordersWidth(el: Element): HtmlElBoxSides;
|
|
36
|
-
export function getHtmlElBorders(el: Element): HtmlElBoxSides;
|
|
37
|
-
export function getHtmlElMargin(el: Element): HtmlElBoxSides;
|
|
38
|
-
export function getHtmlElPadding(el: Element): HtmlElBoxSides;
|
|
39
|
-
export type HtmlElBoxSides = import("../libs/TinyHtml.mjs").HtmlElBoxSides;
|
|
40
|
-
//# sourceMappingURL=html_deprecated.d.mts.map
|
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
import TinyHtml from '../libs/TinyHtml.mjs';
|
|
2
|
-
/**
|
|
3
|
-
* Checks if two DOM elements are colliding on the screen.
|
|
4
|
-
*
|
|
5
|
-
* @param {Element} elem1 - First DOM element.
|
|
6
|
-
* @param {Element} elem2 - Second DOM element.
|
|
7
|
-
* @returns {boolean} - Returns true if the elements are colliding.
|
|
8
|
-
* @deprecated - Use TinyHtml.isCollWith instead.
|
|
9
|
-
*/
|
|
10
|
-
export function areHtmlElsColliding(elem1, elem2) {
|
|
11
|
-
return TinyHtml.isCollWith(elem1, elem2);
|
|
12
|
-
}
|
|
13
|
-
/**
|
|
14
|
-
* Checks if two DOM elements are colliding on the screen.
|
|
15
|
-
*
|
|
16
|
-
* @param {Element} elem1 - First DOM element.
|
|
17
|
-
* @param {Element} elem2 - Second DOM element.
|
|
18
|
-
* @returns {boolean} - Returns true if the elements are colliding.
|
|
19
|
-
* @deprecated - Use TinyHtml.isCollPerfWith instead.
|
|
20
|
-
*/
|
|
21
|
-
export function areHtmlElsPerfColliding(elem1, elem2) {
|
|
22
|
-
return TinyHtml.isCollPerfWith(elem1, elem2);
|
|
23
|
-
}
|
|
24
|
-
///////////////////////////////////////////////////////////////////////////
|
|
25
|
-
/**
|
|
26
|
-
* @typedef {import('../libs/TinyHtml.mjs').HtmlElBoxSides} HtmlElBoxSides
|
|
27
|
-
*/
|
|
28
|
-
/**
|
|
29
|
-
* Returns the total border width and individual sides from `border{Side}Width` CSS properties.
|
|
30
|
-
*
|
|
31
|
-
* @param {Element} el - The target DOM element.
|
|
32
|
-
* @returns {HtmlElBoxSides} - Total horizontal (x) and vertical (y) border widths, and each side individually.
|
|
33
|
-
* @deprecated - Use TinyHtml.borderWidth instead.
|
|
34
|
-
*/
|
|
35
|
-
export const getHtmlElBordersWidth = (el) => {
|
|
36
|
-
return TinyHtml.borderWidth(el);
|
|
37
|
-
};
|
|
38
|
-
/**
|
|
39
|
-
* Returns the total border size and individual sides from `border{Side}` CSS properties.
|
|
40
|
-
*
|
|
41
|
-
* @param {Element} el - The target DOM element.
|
|
42
|
-
* @returns {HtmlElBoxSides} - Total horizontal (x) and vertical (y) border sizes, and each side individually.
|
|
43
|
-
* @deprecated - Use TinyHtml.border instead.
|
|
44
|
-
*/
|
|
45
|
-
export const getHtmlElBorders = (el) => {
|
|
46
|
-
return TinyHtml.border(el);
|
|
47
|
-
};
|
|
48
|
-
/**
|
|
49
|
-
* Returns the total margin and individual sides from `margin{Side}` CSS properties.
|
|
50
|
-
*
|
|
51
|
-
* @param {Element} el - The target DOM element.
|
|
52
|
-
* @returns {HtmlElBoxSides} - Total horizontal (x) and vertical (y) margins, and each side individually.
|
|
53
|
-
* @deprecated - Use TinyHtml.margin instead.
|
|
54
|
-
*/
|
|
55
|
-
export const getHtmlElMargin = (el) => {
|
|
56
|
-
return TinyHtml.margin(el);
|
|
57
|
-
};
|
|
58
|
-
/**
|
|
59
|
-
* Returns the total padding and individual sides from `padding{Side}` CSS properties.
|
|
60
|
-
*
|
|
61
|
-
* @param {Element} el - The target DOM element.
|
|
62
|
-
* @returns {HtmlElBoxSides} - Total horizontal (x) and vertical (y) paddings, and each side individually.
|
|
63
|
-
* @deprecated - Use TinyHtml.padding instead.
|
|
64
|
-
*/
|
|
65
|
-
export const getHtmlElPadding = (el) => {
|
|
66
|
-
return TinyHtml.padding(el);
|
|
67
|
-
};
|
|
68
|
-
/////////////////////////////////////////////////////////////
|
|
69
|
-
// The new version will receive great modifications, the deprecated code has been preserved for non-glitch designs that are using the original code.
|
|
70
|
-
/**
|
|
71
|
-
* Checks if the given element is at least partially visible in the viewport.
|
|
72
|
-
*
|
|
73
|
-
* @param {HTMLElement} element - The DOM element to check.
|
|
74
|
-
* @returns {boolean} True if the element is partially in the viewport, false otherwise.
|
|
75
|
-
* @deprecated - Use TinyHtml.isInViewport instead.
|
|
76
|
-
*/
|
|
77
|
-
export function isInViewport(element) {
|
|
78
|
-
const elementTop = element.offsetTop;
|
|
79
|
-
const elementBottom = elementTop + element.offsetHeight;
|
|
80
|
-
const viewportTop = window.scrollY;
|
|
81
|
-
const viewportBottom = viewportTop + window.innerHeight;
|
|
82
|
-
return elementBottom > viewportTop && elementTop < viewportBottom;
|
|
83
|
-
}
|
|
84
|
-
/**
|
|
85
|
-
* Checks if the given element is fully visible in the viewport (top and bottom).
|
|
86
|
-
*
|
|
87
|
-
* @param {HTMLElement} element - The DOM element to check.
|
|
88
|
-
* @returns {boolean} True if the element is fully visible in the viewport, false otherwise.
|
|
89
|
-
* @deprecated - Use TinyHtml.isScrolledIntoView instead.
|
|
90
|
-
*/
|
|
91
|
-
export function isScrolledIntoView(element) {
|
|
92
|
-
const viewportTop = window.scrollY;
|
|
93
|
-
const viewportBottom = viewportTop + window.innerHeight;
|
|
94
|
-
const elemTop = element.offsetTop;
|
|
95
|
-
const elemBottom = elemTop + element.offsetHeight;
|
|
96
|
-
return elemBottom <= viewportBottom && elemTop >= viewportTop;
|
|
97
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
.dragging {
|
|
2
|
-
opacity: 0.7;
|
|
3
|
-
outline: 2px dashed #3aa;
|
|
4
|
-
z-index: 9999;
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
.dragging-collision {
|
|
8
|
-
outline: 2px dashed rgb(51, 170, 67);
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
body.drag-active {
|
|
12
|
-
cursor: grabbing !important;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
.jail-drag-active {
|
|
16
|
-
outline: 2px dashed #f90;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
.drag-hidden {
|
|
20
|
-
opacity: 0 !important;
|
|
21
|
-
}
|