@thinkpixellab-public/px-vue 4.0.11 → 4.0.13
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/assets/icons/ellipsis.svg +1 -0
- package/assets/icons/eyedropper.svg +1 -0
- package/bases/PxBaseColor.vue +186 -0
- package/bases/PxBaseItems.vue +2 -2
- package/bases/PxBaseSvg.vue +36 -40
- package/bases/PxBaseUniqueId.vue +5 -8
- package/components/PxBalancedText.vue +13 -5
- package/components/PxCodeSample.vue +90 -0
- package/components/PxColorPalette.vue +118 -0
- package/components/PxColorPaletteButton.vue +140 -0
- package/components/PxColorPanel.vue +267 -0
- package/components/PxColorPicker.vue +144 -0
- package/components/PxFlex.vue +1 -1
- package/components/PxIcon.vue +19 -5
- package/components/PxIconButton.vue +4 -9
- package/components/PxLabeledInput.vue +54 -0
- package/components/PxSvgRender.vue +39 -0
- package/components/PxTable.vue +125 -51
- package/package.json +3 -1
- package/stories/PxCodeSample.stories.js +53 -0
- package/stories/PxColorPalette.stories.js +59 -0
- package/stories/PxColorPanel.stories.js +45 -0
- package/stories/PxColorPicker.stories.js +44 -0
- package/stories/PxLabeledInput.stories.js +44 -0
- package/stories/PxSvgRender.stories.js +40 -0
- package/test/PxBaseColor.test.js +54 -0
- package/utils/color.js +50 -0
- package/utils/drag.js +17 -4
package/utils/color.js
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
function hsvaEnsureObject(hOrObj, s, v, a) {
|
|
2
|
+
if (typeof hOrObj === 'object') {
|
|
3
|
+
return hOrObj;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
return { h: hOrObj, s, v, a };
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
function hsvaIsEqual(hsva1, hsva2) {
|
|
10
|
+
return hsva1.h === hsva2.h && hsva1.s === hsva2.s && hsva1.v === hsva2.v && hsva1.a === hsva2.a;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function hsvaToHsla(hOrObj, s, v, a) {
|
|
14
|
+
const hsva = hsvaEnsureObject(hOrObj, s, v, a);
|
|
15
|
+
|
|
16
|
+
let l = ((2 - hsva.s) * hsva.v) / 2;
|
|
17
|
+
s = hsva.s;
|
|
18
|
+
|
|
19
|
+
if (l != 0) {
|
|
20
|
+
if (l == 1) {
|
|
21
|
+
s = 0;
|
|
22
|
+
} else if (l < 0.5) {
|
|
23
|
+
s = (s * hsva.v) / (l * 2);
|
|
24
|
+
} else {
|
|
25
|
+
s = (s * hsva.v) / (2 - l * 2);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return { h: hsva.h, s: s, l: l, a: hsva.a };
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function hslaToStr(hsla, alphaEnabled = true) {
|
|
33
|
+
if (alphaEnabled) {
|
|
34
|
+
return `hsla(${hsla.h}, ${hsla.s * 100}%, ${hsla.l * 100}%, ${hsla.a})`;
|
|
35
|
+
} else {
|
|
36
|
+
return `hsl(${hsla.h}, ${hsla.s * 100}%, ${hsla.l * 100}%)`;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function hsvaContrastColor(hsva, light = '#FFF', dark = '#000') {
|
|
41
|
+
const THRESHOLD = 0.5;
|
|
42
|
+
const hsla = hsvaToHsla(hsva);
|
|
43
|
+
if (hsla.a < THRESHOLD) {
|
|
44
|
+
return dark;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return hsla.l > THRESHOLD ? dark : light;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export { hsvaEnsureObject, hsvaIsEqual, hsvaToHsla, hslaToStr, hsvaContrastColor };
|
package/utils/drag.js
CHANGED
|
@@ -267,13 +267,26 @@ function Drag(element, options) {
|
|
|
267
267
|
coords.y = nativeEvent.clientY;
|
|
268
268
|
}
|
|
269
269
|
|
|
270
|
+
const x = this.thresholdMet && this.startEv && this.lock == 'y' ? this.startEv.x : coords.x;
|
|
271
|
+
const y = this.thresholdMet && this.startEv && this.lock == 'x' ? this.startEv.y : coords.y;
|
|
272
|
+
|
|
270
273
|
const ev = {
|
|
271
|
-
x
|
|
272
|
-
y
|
|
274
|
+
x,
|
|
275
|
+
y,
|
|
273
276
|
native: nativeEvent,
|
|
274
277
|
lock: this.lock,
|
|
275
278
|
};
|
|
276
279
|
|
|
280
|
+
if (this.thresholdMet && this.element) {
|
|
281
|
+
const rect = element.getBoundingClientRect();
|
|
282
|
+
ev.elementX = x - rect.left;
|
|
283
|
+
ev.elementY = y - rect.top;
|
|
284
|
+
ev.elementWidth = rect.width;
|
|
285
|
+
ev.elementHeight = rect.height;
|
|
286
|
+
ev.elementXPos = ev.elementX / rect.width;
|
|
287
|
+
ev.elementYPos = ev.elementY / rect.height;
|
|
288
|
+
}
|
|
289
|
+
|
|
277
290
|
return ev;
|
|
278
291
|
};
|
|
279
292
|
|
|
@@ -282,14 +295,14 @@ function Drag(element, options) {
|
|
|
282
295
|
this.addElementEvents = () => {
|
|
283
296
|
this.element.addEventListener(
|
|
284
297
|
this.supportsTouch ? 'touchstart' : 'mousedown',
|
|
285
|
-
this.onStart
|
|
298
|
+
this.onStart,
|
|
286
299
|
);
|
|
287
300
|
};
|
|
288
301
|
|
|
289
302
|
this.removeElementEvents = () => {
|
|
290
303
|
this.element.removeEventListener(
|
|
291
304
|
this.supportsTouch ? 'touchstart' : 'mousedown',
|
|
292
|
-
this.onStart
|
|
305
|
+
this.onStart,
|
|
293
306
|
);
|
|
294
307
|
};
|
|
295
308
|
|