@c2n/color-slider 0.0.6 → 0.0.8
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/color-slider.js +17 -6
- package/package.json +18 -6
- package/react.d.ts +24 -0
- package/react.js +3 -0
- package/types/src/color-slider.d.ts +17 -1
- package/types/src/color-slider.d.ts.map +1 -1
- package/vue.d.ts +34 -0
- package/vue.js +3 -0
package/dist/color-slider.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { LitElement, html, unsafeCSS } from "lit";
|
|
1
|
+
import { LitElement, html, nothing, unsafeCSS } from "lit";
|
|
2
2
|
import { isServer } from "lit-html/is-server.js";
|
|
3
|
-
import {
|
|
3
|
+
import { property, query } from "lit/decorators.js";
|
|
4
|
+
import { customElement } from "@c2n/core/element-helper.js";
|
|
4
5
|
import { redispatchEvent } from "@c2n/core/dom-helper.js";
|
|
5
6
|
//#region src/color-slider.scss?inline
|
|
6
7
|
var color_slider_default = "/* ex : var((width: 24px), width, c2-checkbox) returns var(--c2-checkbox-width, 24px) */\n:host {\n display: block;\n}\n\n.c2-color-slider {\n display: block;\n position: relative;\n cursor: pointer;\n touch-action: none;\n outline: none;\n}\n.c2-color-slider .gradient {\n flex: 1;\n border-top-left-radius: var(--c2-color-slider--border-top-left-radius,8px);\n border-top-right-radius: var(--c2-color-slider--border-top-right-radius,8px);\n border-bottom-left-radius: var(--c2-color-slider--border-bottom-left-radius,8px);\n border-bottom-right-radius: var(--c2-color-slider--border-bottom-right-radius,8px);\n border-top: var(--c2-color-slider--border-top,1px solid rgb(248, 248, 248));\n border-bottom: var(--c2-color-slider--border-bottom,1px solid rgb(248, 248, 248));\n border-right: var(--c2-color-slider--border-right,1px solid rgb(248, 248, 248));\n border-left: var(--c2-color-slider--border-left,1px solid rgb(248, 248, 248));\n width: var(--c2-color-slider--width,160px);\n height: var(--c2-color-slider--height,12px);\n pointer-events: none;\n background: linear-gradient(to right, rgb(255, 0, 0) 0%, rgb(255, 255, 0) 17%, rgb(0, 255, 0) 33%, rgb(0, 255, 255) 50%, rgb(0, 0, 255) 67%, rgb(255, 0, 255) 83%, rgb(255, 0, 0) 100%);\n}\n.c2-color-slider .gradient ::slotted(*) {\n width: var(--c2-color-slider--width,160px);\n height: var(--c2-color-slider--height,12px);\n border-top-left-radius: var(--c2-color-slider--border-top-left-radius,8px);\n border-top-right-radius: var(--c2-color-slider--border-top-right-radius,8px);\n border-bottom-left-radius: var(--c2-color-slider--border-bottom-left-radius,8px);\n border-bottom-right-radius: var(--c2-color-slider--border-bottom-right-radius,8px);\n}\n.c2-color-slider .input-slider {\n position: absolute;\n margin: 0;\n padding: 0;\n opacity: 0;\n cursor: inherit;\n top: 0;\n left: 0;\n width: var(--c2-color-slider--width,160px);\n height: var(--c2-color-slider--height,12px);\n}\n.c2-color-slider .color-handle {\n position: absolute;\n pointer-events: none;\n box-sizing: border-box;\n width: var(--c2-color-slider__color-handle--width,12px);\n height: var(--c2-color-slider__color-handle--height,12px);\n border-top-left-radius: var(--c2-color-slider__color-handle--border-top-left-radius,6px);\n border-top-right-radius: var(--c2-color-slider__color-handle--border-top-right-radius,6px);\n border-bottom-left-radius: var(--c2-color-slider__color-handle--border-bottom-left-radius,6px);\n border-bottom-right-radius: var(--c2-color-slider__color-handle--border-bottom-right-radius,6px);\n top: 50%;\n left: 0;\n border: 2px solid white;\n box-shadow: rgba(0, 0, 0, 0.2) 0px 0px 0px 0.6px;\n cursor: inherit;\n transform: translateY(-50%);\n}";
|
|
@@ -1137,6 +1138,7 @@ var ColorSlider = class ColorSlider extends LitElement {
|
|
|
1137
1138
|
this.value = 0;
|
|
1138
1139
|
this.min = 0;
|
|
1139
1140
|
this.max = 360;
|
|
1141
|
+
this.ariaLabel = null;
|
|
1140
1142
|
if (!isServer) this.resizeObserver = new ResizeObserver(() => {
|
|
1141
1143
|
this.colorHandleRect = void 0;
|
|
1142
1144
|
this.inputSliderRect = void 0;
|
|
@@ -1160,9 +1162,8 @@ var ColorSlider = class ColorSlider extends LitElement {
|
|
|
1160
1162
|
if (!this.inputSliderRect) this.inputSliderRect = this.inputSlider.getBoundingClientRect();
|
|
1161
1163
|
const handleWidth = this.colorHandleRect.width;
|
|
1162
1164
|
const range = this.max - this.min;
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
position = position - delta;
|
|
1165
|
+
const fraction = range > 0 ? Math.min(1, Math.max(0, (this.value - this.min) / range)) : 0;
|
|
1166
|
+
let position = (this.inputSliderRect.width - handleWidth) * fraction;
|
|
1166
1167
|
position = Math.max(0, position);
|
|
1167
1168
|
position = Math.min(position, this.inputSliderRect.width - handleWidth);
|
|
1168
1169
|
this.colorHandle.style.setProperty("transform", `translate(${position}px, -50%)`);
|
|
@@ -1180,7 +1181,16 @@ var ColorSlider = class ColorSlider extends LitElement {
|
|
|
1180
1181
|
});
|
|
1181
1182
|
return html`
|
|
1182
1183
|
<div class="c2-color-slider">
|
|
1183
|
-
<input
|
|
1184
|
+
<input
|
|
1185
|
+
aria-label=${this.ariaLabel || nothing}
|
|
1186
|
+
type="range"
|
|
1187
|
+
class="input-slider"
|
|
1188
|
+
min=${this.min}
|
|
1189
|
+
max=${this.max}
|
|
1190
|
+
step="1"
|
|
1191
|
+
.value=${String(this.value)}
|
|
1192
|
+
@input=${this.handleInput}
|
|
1193
|
+
/>
|
|
1184
1194
|
<div class="gradient">
|
|
1185
1195
|
<slot></slot>
|
|
1186
1196
|
</div>
|
|
@@ -1201,6 +1211,7 @@ __decorate([property({
|
|
|
1201
1211
|
type: Number,
|
|
1202
1212
|
reflect: true
|
|
1203
1213
|
})], ColorSlider.prototype, "max", void 0);
|
|
1214
|
+
__decorate([property({ attribute: "aria-label" })], ColorSlider.prototype, "ariaLabel", void 0);
|
|
1204
1215
|
__decorate([query(".color-handle")], ColorSlider.prototype, "colorHandle", void 0);
|
|
1205
1216
|
__decorate([query(".input-slider")], ColorSlider.prototype, "inputSlider", void 0);
|
|
1206
1217
|
ColorSlider = __decorate([customElement("c2-color-slider")], ColorSlider);
|
package/package.json
CHANGED
|
@@ -1,18 +1,30 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@c2n/color-slider",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.8",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "dist/color-slider.js",
|
|
6
6
|
"exports": {
|
|
7
7
|
".": {
|
|
8
|
-
"
|
|
9
|
-
"
|
|
8
|
+
"types": "./types/src/color-slider.d.ts",
|
|
9
|
+
"default": "./dist/color-slider.js"
|
|
10
|
+
},
|
|
11
|
+
"./react": {
|
|
12
|
+
"types": "./react.d.ts",
|
|
13
|
+
"default": "./react.js"
|
|
14
|
+
},
|
|
15
|
+
"./vue": {
|
|
16
|
+
"types": "./vue.d.ts",
|
|
17
|
+
"default": "./vue.js"
|
|
10
18
|
},
|
|
11
19
|
"./custom-elements.json": "./custom-elements.json"
|
|
12
20
|
},
|
|
13
21
|
"files": [
|
|
14
22
|
"dist",
|
|
15
|
-
"types"
|
|
23
|
+
"types",
|
|
24
|
+
"react.d.ts",
|
|
25
|
+
"react.js",
|
|
26
|
+
"vue.d.ts",
|
|
27
|
+
"vue.js"
|
|
16
28
|
],
|
|
17
29
|
"keywords": [
|
|
18
30
|
"color-slider",
|
|
@@ -48,7 +60,7 @@
|
|
|
48
60
|
}
|
|
49
61
|
},
|
|
50
62
|
"dependencies": {
|
|
51
|
-
"@c2n/core": "0.0.
|
|
63
|
+
"@c2n/core": "0.0.8",
|
|
52
64
|
"@ctrl/tinycolor": "4.2.0",
|
|
53
65
|
"lit": "3.3.3"
|
|
54
66
|
},
|
|
@@ -56,5 +68,5 @@
|
|
|
56
68
|
"@c2n/config": "*"
|
|
57
69
|
},
|
|
58
70
|
"customElements": "custom-elements.json",
|
|
59
|
-
"gitHead": "
|
|
71
|
+
"gitHead": "be59cbccee1d33ca248e39f69b05c0b595ec6c6d"
|
|
60
72
|
}
|
package/react.d.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// GENERATED by @c2n/framework-types. Do not edit by hand.
|
|
2
|
+
//
|
|
3
|
+
// JSX types for the custom elements of @c2n/color-slider. Import once, anywhere in the program:
|
|
4
|
+
//
|
|
5
|
+
// import '@c2n/color-slider/react'
|
|
6
|
+
//
|
|
7
|
+
// Register the elements at module scope before React renders, or React writes an object prop as an
|
|
8
|
+
// attribute and it stringifies.
|
|
9
|
+
|
|
10
|
+
import type { DetailedHTMLProps, HTMLAttributes } from 'react'
|
|
11
|
+
import type { ColorSlider } from '@c2n/color-slider'
|
|
12
|
+
|
|
13
|
+
/** Standard React host-element attributes plus the element's own public properties. */
|
|
14
|
+
type C2Props<T> = DetailedHTMLProps<HTMLAttributes<T>, T> & Partial<Omit<T, keyof HTMLElement>>
|
|
15
|
+
|
|
16
|
+
declare module 'react' {
|
|
17
|
+
namespace JSX {
|
|
18
|
+
interface IntrinsicElements {
|
|
19
|
+
'c2-color-slider': C2Props<ColorSlider>
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export {}
|
package/react.js
ADDED
|
@@ -1,8 +1,19 @@
|
|
|
1
1
|
import { LitElement, type PropertyValueMap } from 'lit';
|
|
2
|
+
import type { TypedAddEventListener, TypedRemoveEventListener } from '@c2n/core/event-helper.js';
|
|
3
|
+
/** Events fired by {@link ColorSlider}, keyed for `addEventListener`. */
|
|
4
|
+
export interface ColorSliderEventMap {
|
|
5
|
+
input: Event;
|
|
6
|
+
}
|
|
7
|
+
export interface ColorSlider {
|
|
8
|
+
addEventListener: TypedAddEventListener<ColorSlider, ColorSliderEventMap>;
|
|
9
|
+
removeEventListener: TypedRemoveEventListener<ColorSlider, ColorSliderEventMap>;
|
|
10
|
+
}
|
|
2
11
|
/**
|
|
12
|
+
* Horizontal numeric slider rendered as a colour-gradient track, typically used for hue.
|
|
13
|
+
*
|
|
3
14
|
* @tag c2-color-slider
|
|
4
15
|
*
|
|
5
|
-
* @event {
|
|
16
|
+
* @event {Event} input - Re-dispatched from the inner range input while its value changes.
|
|
6
17
|
*
|
|
7
18
|
*
|
|
8
19
|
* @cssproperty {border-radius} [--c2-color-slider--border-radius=8px]
|
|
@@ -32,9 +43,14 @@ import { LitElement, type PropertyValueMap } from 'lit';
|
|
|
32
43
|
*/
|
|
33
44
|
export declare class ColorSlider extends LitElement {
|
|
34
45
|
static styles: import("lit").CSSResult;
|
|
46
|
+
/** Current numeric value. */
|
|
35
47
|
value: number;
|
|
48
|
+
/** Minimum selectable value. */
|
|
36
49
|
min: number;
|
|
50
|
+
/** Maximum selectable value. */
|
|
37
51
|
max: number;
|
|
52
|
+
/** Accessible name forwarded to the inner range input. */
|
|
53
|
+
ariaLabel: string | null;
|
|
38
54
|
colorHandle: HTMLElement;
|
|
39
55
|
inputSlider: HTMLElement;
|
|
40
56
|
private colorHandleRect?;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"color-slider.d.ts","sourceRoot":"","sources":["../../src/color-slider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,
|
|
1
|
+
{"version":3,"file":"color-slider.d.ts","sourceRoot":"","sources":["../../src/color-slider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAA4B,KAAK,gBAAgB,EAAE,MAAM,KAAK,CAAA;AAIjF,OAAO,KAAK,EAAE,qBAAqB,EAAE,wBAAwB,EAAE,MAAM,2BAA2B,CAAA;AAIhG,yEAAyE;AACzE,MAAM,WAAW,mBAAmB;IAClC,KAAK,EAAE,KAAK,CAAA;CACb;AAED,MAAM,WAAW,WAAW;IAC1B,gBAAgB,EAAE,qBAAqB,CAAC,WAAW,EAAE,mBAAmB,CAAC,CAAA;IACzE,mBAAmB,EAAE,wBAAwB,CAAC,WAAW,EAAE,mBAAmB,CAAC,CAAA;CAChF;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,qBACa,WAAY,SAAQ,UAAU;IACzC,OAAgB,MAAM,0BAAoB;IAE1C,6BAA6B;IACc,KAAK,EAAE,MAAM,CAAI;IAC5D,gCAAgC;IACW,GAAG,EAAE,MAAM,CAAI;IAC1D,gCAAgC;IACW,GAAG,EAAE,MAAM,CAAM;IAE5D,0DAA0D;IACV,SAAS,EAAE,MAAM,GAAG,IAAI,CAAO;IAEvD,WAAW,EAAG,WAAW,CAAA;IACzB,WAAW,EAAG,WAAW,CAAA;IAEjD,OAAO,CAAC,eAAe,CAAC,CAAS;IACjC,OAAO,CAAC,eAAe,CAAC,CAAS;IACjC,OAAO,CAAC,cAAc,CAAC,CAAgB;;IAYvC,OAAO,CAAC,WAAW;IAKV,iBAAiB,IAAI,IAAI;IAKzB,oBAAoB,IAAI,IAAI;IAKrC,OAAO,CAAC,yBAAyB;cAgBd,OAAO,CAAC,kBAAkB,EAAE,gBAAgB,CAAC,IAAI,CAAC,GAAG,IAAI;IAOnE,MAAM;CAqBhB;AAED,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,qBAAqB;QAC7B,iBAAiB,EAAE,WAAW,CAAA;KAC/B;CACF"}
|
package/vue.d.ts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
// GENERATED by @c2n/framework-types. Do not edit by hand.
|
|
2
|
+
//
|
|
3
|
+
// Vue template types for the custom elements of @c2n/color-slider. Import once, anywhere in the program:
|
|
4
|
+
//
|
|
5
|
+
// import '@c2n/color-slider/vue'
|
|
6
|
+
//
|
|
7
|
+
// Tell the compiler about the tags as well, or every c2-* tag is resolved as a Vue component and renders
|
|
8
|
+
// nothing: template.compilerOptions.isCustomElement = (tag) => tag.startsWith('c2-') in vite.config.ts.
|
|
9
|
+
|
|
10
|
+
import type { DefineComponent, HTMLAttributes } from 'vue'
|
|
11
|
+
import type { ColorSlider, ColorSliderEventMap } from '@c2n/color-slider'
|
|
12
|
+
|
|
13
|
+
/** The element's own public properties, plus every attribute Vue understands on a host element. */
|
|
14
|
+
type C2Props<T> = Partial<Omit<T, keyof HTMLElement>> & HTMLAttributes
|
|
15
|
+
|
|
16
|
+
declare module 'vue' {
|
|
17
|
+
interface GlobalComponents {
|
|
18
|
+
'c2-color-slider': DefineComponent<
|
|
19
|
+
C2Props<ColorSlider> & {
|
|
20
|
+
'aria-label'?: unknown
|
|
21
|
+
onInput?: (event: ColorSliderEventMap['input']) => void
|
|
22
|
+
}
|
|
23
|
+
>
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
declare module '@vue/runtime-dom' {
|
|
28
|
+
interface HTMLAttributes {
|
|
29
|
+
/** Vue's own definition omits it, and slotting a plain element into a component needs it. */
|
|
30
|
+
slot?: string
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export {}
|
package/vue.js
ADDED