purgetss 7.3.1 → 7.4.0
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 +100 -0
- package/dist/purgetss.ui.js +1 -1
- package/lib/templates/purgetss.ui.js.cjs +7 -7
- package/package.json +1 -1
- package/src/shared/helpers/utils.js +21 -21
package/README.md
CHANGED
|
@@ -67,6 +67,106 @@ Here are its main functionalities:
|
|
|
67
67
|
- **Animation module**: Apply basic 2D matrix animations or transformations to elements or arrays of elements.
|
|
68
68
|
- **Grid system**: A two-dimensional grid system to align and distribute elements within views.
|
|
69
69
|
|
|
70
|
+
---
|
|
71
|
+
|
|
72
|
+
## Animation Module (`purgetss.ui.js`)
|
|
73
|
+
|
|
74
|
+
Install with `purgetss module` (or `purgetss m`). This places `purgetss.ui.js` in your project's `lib` folder.
|
|
75
|
+
|
|
76
|
+
### Declaring an Animation object
|
|
77
|
+
|
|
78
|
+
```xml
|
|
79
|
+
<Animation id="myAnimation" module="purgetss.ui" class="opacity-0 duration-300 ease-in" />
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
You can use any position, size, color, opacity, or transformation class from `utilities.tss`.
|
|
83
|
+
|
|
84
|
+
### Available methods
|
|
85
|
+
|
|
86
|
+
| Method | Description |
|
|
87
|
+
| --------------------------------------- | --------------------------------------------------------------------------------------------- |
|
|
88
|
+
| `play(views, cb)` / `toggle(views, cb)` | Animate views from current state to the animation state. Toggles `open`/`close` on each call. |
|
|
89
|
+
| `open(views, cb)` | Explicitly run the `open` state animation. |
|
|
90
|
+
| `close(views, cb)` | Explicitly run the `close` state animation. |
|
|
91
|
+
| `apply(views, cb)` | Apply properties instantly without animation. |
|
|
92
|
+
| `draggable(views)` | Make a view or array of views draggable inside their parent. |
|
|
93
|
+
|
|
94
|
+
### Callback event object
|
|
95
|
+
|
|
96
|
+
All callbacks (`play`, `open`, `close`, `apply`) receive an enriched event object:
|
|
97
|
+
|
|
98
|
+
```js
|
|
99
|
+
{
|
|
100
|
+
type: String, // event type ('complete' or 'applied')
|
|
101
|
+
bubbles: Boolean,
|
|
102
|
+
cancelBubble: Boolean,
|
|
103
|
+
action: String, // 'play' or 'apply'
|
|
104
|
+
state: String, // 'open' or 'close'
|
|
105
|
+
id: String, // Animation object ID
|
|
106
|
+
targetId: String, // ID of the animated view
|
|
107
|
+
index: Number, // position in array (0-based)
|
|
108
|
+
total: Number, // total views in array
|
|
109
|
+
getTarget: Function // returns the animated view object
|
|
110
|
+
}
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
When animating an **array of views**, the callback is called once per view with the corresponding `index` and `total` values.
|
|
114
|
+
|
|
115
|
+
```js
|
|
116
|
+
$.myAnimation.play([$.card1, $.card2, $.card3], (e) => {
|
|
117
|
+
console.log(`Animated ${e.index + 1} of ${e.total}`) // "Animated 1 of 3", etc.
|
|
118
|
+
if (e.index === e.total - 1) {
|
|
119
|
+
console.log('All done!')
|
|
120
|
+
}
|
|
121
|
+
})
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
### Multi-state animations
|
|
125
|
+
|
|
126
|
+
Use `open`, `close`, and `complete` modifiers inside `animationProperties` to define different states:
|
|
127
|
+
|
|
128
|
+
```xml
|
|
129
|
+
<Animation id="fadeToggle" module="purgetss.ui" class="duration-300"
|
|
130
|
+
animationProperties="{
|
|
131
|
+
open: { opacity: 1 },
|
|
132
|
+
close: { opacity: 0 }
|
|
133
|
+
}"
|
|
134
|
+
/>
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
### Draggable views
|
|
138
|
+
|
|
139
|
+
```js
|
|
140
|
+
$.myAnimation.draggable($.myView)
|
|
141
|
+
// or with constraints:
|
|
142
|
+
$.myAnimation.draggable([$.card1, $.card2])
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
Use `bounds` to restrict movement, and `drag`/`drop` modifiers for drag-state animations. Use `vertical-constraint` or `horizontal-constraint` classes to limit the drag axis.
|
|
146
|
+
|
|
147
|
+
### Utility classes for animations
|
|
148
|
+
|
|
149
|
+
| Class pattern | Description |
|
|
150
|
+
| --------------------------------------------------- | ----------------------------- |
|
|
151
|
+
| `duration-{n}` | Animation duration in ms |
|
|
152
|
+
| `delay-{n}` | Delay before animation starts |
|
|
153
|
+
| `rotate-{n}` | 2D rotation in degrees |
|
|
154
|
+
| `scale-{n}` | Scale factor |
|
|
155
|
+
| `repeat-{n}` | Number of repeats |
|
|
156
|
+
| `ease-in`, `ease-out`, `ease-linear`, `ease-in-out` | Timing curve |
|
|
157
|
+
| `zoom-in-{n}`, `zoom-out-{n}` | Zoom animations |
|
|
158
|
+
| `drag-apply`, `drag-animate` | Drag interaction style |
|
|
159
|
+
| `vertical-constraint`, `horizontal-constraint` | Constrain drag axis |
|
|
160
|
+
|
|
161
|
+
### Utility functions
|
|
162
|
+
|
|
163
|
+
| Function | Description |
|
|
164
|
+
| -------------------------------------- | -------------------------------------------------------------------------------------------------------- |
|
|
165
|
+
| `deviceInfo()` | Logs detailed platform and display information to the console. Works in both Alloy and Classic projects. |
|
|
166
|
+
| `saveComponent({ source, directory })` | Saves a view snapshot as PNG to the photo gallery. |
|
|
167
|
+
|
|
168
|
+
See the full documentation at [purgetss.com/docs/animation-module/introduction](https://purgetss.com/docs/animation-module/introduction).
|
|
169
|
+
|
|
70
170
|
In short, PurgeTSS keeps styling consistent and removes a lot of repetitive UI setup work.
|
|
71
171
|
|
|
72
172
|
### Visit the official documentation site at [purgetss.com](https://purgetss.com) to learn more.
|
package/dist/purgetss.ui.js
CHANGED
|
@@ -299,18 +299,18 @@ function Animation(args = {}) {
|
|
|
299
299
|
params.playing = false
|
|
300
300
|
if (typeof _cb === 'function') {
|
|
301
301
|
const enrichedEvent = {
|
|
302
|
-
//
|
|
302
|
+
// Safe properties from the original event
|
|
303
303
|
type: event.type,
|
|
304
304
|
bubbles: event.bubbles,
|
|
305
305
|
cancelBubble: event.cancelBubble,
|
|
306
|
-
//
|
|
306
|
+
// Added properties (primitives only)
|
|
307
307
|
action, // 'play'
|
|
308
308
|
state: params.open ? 'open' : 'close',
|
|
309
309
|
id: params.id,
|
|
310
|
-
targetId: view.id || 'unknown', //
|
|
310
|
+
targetId: view.id || 'unknown', // View ID only, not the object
|
|
311
311
|
index,
|
|
312
312
|
total,
|
|
313
|
-
//
|
|
313
|
+
// Helper method to get the view
|
|
314
314
|
getTarget: () => view
|
|
315
315
|
}
|
|
316
316
|
_cb(enrichedEvent)
|
|
@@ -340,14 +340,14 @@ function Animation(args = {}) {
|
|
|
340
340
|
type: 'applied',
|
|
341
341
|
bubbles: false,
|
|
342
342
|
cancelBubble: false,
|
|
343
|
-
//
|
|
343
|
+
// Added properties (primitives only)
|
|
344
344
|
action, // 'apply'
|
|
345
345
|
state: params.open ? 'open' : 'close',
|
|
346
346
|
id: params.id,
|
|
347
|
-
targetId: view.id || 'unknown', //
|
|
347
|
+
targetId: view.id || 'unknown', // View ID only, not the object
|
|
348
348
|
index,
|
|
349
349
|
total,
|
|
350
|
-
//
|
|
350
|
+
// Helper method to get the view
|
|
351
351
|
getTarget: () => view
|
|
352
352
|
}
|
|
353
353
|
_cb(enrichedEvent)
|
package/package.json
CHANGED
|
@@ -374,6 +374,26 @@ export function fixInvalidValues(invalidValues, currentValue) {
|
|
|
374
374
|
return invalidValues[currentValue] || currentValue
|
|
375
375
|
}
|
|
376
376
|
|
|
377
|
+
/**
|
|
378
|
+
* Recursively serialize a value for TSS output.
|
|
379
|
+
* Handles primitives, plain objects, and arrays of objects.
|
|
380
|
+
* @param {*} val - Value to serialize
|
|
381
|
+
* @returns {string} TSS-compatible string representation
|
|
382
|
+
*/
|
|
383
|
+
function serializeValue(val) {
|
|
384
|
+
if (Array.isArray(val)) {
|
|
385
|
+
const items = val.map(item => serializeValue(item))
|
|
386
|
+
return `[ ${items.join(', ')} ]`
|
|
387
|
+
}
|
|
388
|
+
if (typeof val === 'object' && val !== null) {
|
|
389
|
+
const entries = Object.entries(val)
|
|
390
|
+
.map(([k, v]) => `${k}: ${serializeValue(v)}`)
|
|
391
|
+
.join(', ')
|
|
392
|
+
return `{ ${entries} }`
|
|
393
|
+
}
|
|
394
|
+
return parseValue(val)
|
|
395
|
+
}
|
|
396
|
+
|
|
377
397
|
/**
|
|
378
398
|
* Generate custom rules for Titanium styles
|
|
379
399
|
* @param {Object} _value - Value object containing rules
|
|
@@ -399,27 +419,7 @@ export function customRules(_value, _key, changeToDash = false) {
|
|
|
399
419
|
|
|
400
420
|
customProperties += ' {_applyProperties_},'
|
|
401
421
|
} else {
|
|
402
|
-
customProperties += ` ${theModifier}: {
|
|
403
|
-
|
|
404
|
-
let extraCustomProperties = ''
|
|
405
|
-
|
|
406
|
-
_.each(theValue, (extraValue, extraModifier) => {
|
|
407
|
-
if (typeof (extraValue) === 'object' && extraValue !== null) {
|
|
408
|
-
customProperties += ` ${extraModifier}: {`
|
|
409
|
-
|
|
410
|
-
let moreExtraCustomProperties = ''
|
|
411
|
-
|
|
412
|
-
_.each(extraValue, (moreExtraValue, moreModifier) => {
|
|
413
|
-
moreExtraCustomProperties += ` ${moreModifier}: ${parseValue(moreExtraValue)},`
|
|
414
|
-
})
|
|
415
|
-
|
|
416
|
-
customProperties += `${removeLastCharacter(moreExtraCustomProperties)} },`
|
|
417
|
-
} else {
|
|
418
|
-
extraCustomProperties += ` ${extraModifier}: ${parseValue(extraValue)},`
|
|
419
|
-
}
|
|
420
|
-
})
|
|
421
|
-
|
|
422
|
-
customProperties += `${removeLastCharacter(extraCustomProperties)} },`
|
|
422
|
+
customProperties += ` ${theModifier}: ${serializeValue(theValue)},`
|
|
423
423
|
}
|
|
424
424
|
} else {
|
|
425
425
|
if (theModifier === 'apply') {
|