react-led-digit 0.0.5 → 0.0.7
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/lib/BlinkingDigit/BlinkingDigit.js +3 -3
- package/lib/Digit/Digit.d.ts +3 -27
- package/lib/Digit/Digit.js +6 -68
- package/lib/Digit/UnstyledDigit.d.ts +26 -0
- package/lib/Digit/UnstyledDigit.js +66 -0
- package/lib/Digit/charToSevenSegments.d.ts +0 -2
- package/lib/Digit/charToSevenSegments.js +0 -2
- package/lib/Digit/components/AmpmSegments.d.ts +11 -0
- package/lib/Digit/components/AmpmSegments.js +25 -0
- package/lib/Digit/components/ColonSegments.d.ts +11 -0
- package/lib/Digit/components/ColonSegments.js +25 -0
- package/lib/Digit/components/DigitSegments.d.ts +16 -0
- package/lib/Digit/components/DigitSegments.js +25 -0
- package/lib/Digit/components/DotSegments.d.ts +10 -0
- package/lib/Digit/components/DotSegments.js +25 -0
- package/lib/Digit/components/index.d.ts +4 -0
- package/lib/Digit/components/index.js +20 -0
- package/lib/Digit/components/utils.d.ts +3 -0
- package/lib/Digit/components/utils.js +12 -0
- package/lib/Digit/digit.css +120 -41
- package/lib/Digit/index.d.ts +1 -0
- package/lib/Digit/index.js +3 -0
- package/lib/Digit/useStyleInjection.d.ts +4 -0
- package/lib/Digit/useStyleInjection.js +70 -0
- package/package.json +17 -13
|
@@ -40,7 +40,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
40
40
|
exports.BlinkingDigit = void 0;
|
|
41
41
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
42
42
|
const react_1 = __importStar(require("react"));
|
|
43
|
-
const
|
|
43
|
+
const clsx_1 = __importDefault(require("clsx"));
|
|
44
44
|
const Digit_1 = require("../Digit");
|
|
45
45
|
const Blinker_1 = require("../Blinker");
|
|
46
46
|
const blinker = new Blinker_1.Blinker(); // singleton makes all BlinkingDigit's to blink synchronoulsy
|
|
@@ -58,6 +58,6 @@ exports.BlinkingDigit = react_1.default.memo((_a) => {
|
|
|
58
58
|
if ((blinkOptions === null || blinkOptions === void 0 ? void 0 : blinkOptions.period) === 0 ||
|
|
59
59
|
(blinkOptions === null || blinkOptions === void 0 ? void 0 : blinkOptions.ratio) === 0 ||
|
|
60
60
|
typeof (rest === null || rest === void 0 ? void 0 : rest.off) === 'boolean')
|
|
61
|
-
return (0, jsx_runtime_1.jsx)(Digit_1.Digit, Object.assign({}, rest, { className: (0,
|
|
62
|
-
return ((0, jsx_runtime_1.jsx)(Digit_1.Digit, Object.assign({}, rest, { className: (0,
|
|
61
|
+
return (0, jsx_runtime_1.jsx)(Digit_1.Digit, Object.assign({}, rest, { className: (0, clsx_1.default)('blinking', className) })); // no blinker required
|
|
62
|
+
return ((0, jsx_runtime_1.jsx)(Digit_1.Digit, Object.assign({}, rest, { className: (0, clsx_1.default)('blinking', className), off: rest.off || !visible })));
|
|
63
63
|
});
|
package/lib/Digit/Digit.d.ts
CHANGED
|
@@ -1,27 +1,3 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
import
|
|
4
|
-
type NumValue = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9;
|
|
5
|
-
type DigitValue = NumValue | SevenSegmentsValue | 'am' | 'pm' | ':' | '.';
|
|
6
|
-
type DivProps = React.HTMLAttributes<HTMLDivElement>;
|
|
7
|
-
type DigitProps = {
|
|
8
|
-
off?: boolean;
|
|
9
|
-
shape?: 'default' | 'rect' | 'round' | 'pill';
|
|
10
|
-
value: DigitValue;
|
|
11
|
-
};
|
|
12
|
-
type SegmentStyle = {
|
|
13
|
-
color?: CSSProperties['color'];
|
|
14
|
-
colorOff?: CSSProperties['color'];
|
|
15
|
-
length?: CSSProperties['width'];
|
|
16
|
-
thickness?: CSSProperties['width'];
|
|
17
|
-
spacing?: CSSProperties['width'];
|
|
18
|
-
filament?: CSSProperties['width'];
|
|
19
|
-
opacityOn?: CSSProperties['opacity'];
|
|
20
|
-
opacityOff?: CSSProperties['opacity'];
|
|
21
|
-
transitionDuration?: CSSProperties['transitionDuration'];
|
|
22
|
-
};
|
|
23
|
-
export type Digit = DivProps & DigitProps & {
|
|
24
|
-
segmentStyle?: SegmentStyle;
|
|
25
|
-
};
|
|
26
|
-
export declare const Digit: ({ segmentStyle, value, ...rest }: Digit) => import("react/jsx-runtime").JSX.Element;
|
|
27
|
-
export {};
|
|
1
|
+
import { Digit as UnstyledDigit } from './UnstyledDigit';
|
|
2
|
+
export type Digit = UnstyledDigit;
|
|
3
|
+
export declare const Digit: ({ ...rest }: Digit) => import("react/jsx-runtime").JSX.Element;
|
package/lib/Digit/Digit.js
CHANGED
|
@@ -16,74 +16,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
exports.Digit = void 0;
|
|
18
18
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
19
|
-
const
|
|
20
|
-
const
|
|
21
|
-
require("./digit.css");
|
|
19
|
+
const UnstyledDigit_1 = require("./UnstyledDigit");
|
|
20
|
+
const useStyleInjection_1 = __importDefault(require("./useStyleInjection"));
|
|
21
|
+
const digit_css_js_1 = __importDefault(require("./digit.css.js"));
|
|
22
22
|
const Digit = (_a) => {
|
|
23
|
-
var
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
const sx = Object.assign({ '--segment-color': segmentStyle === null || segmentStyle === void 0 ? void 0 : segmentStyle.color, '--segment-color-off': segmentStyle === null || segmentStyle === void 0 ? void 0 : segmentStyle.colorOff, '--segment-thickness': segmentStyle === null || segmentStyle === void 0 ? void 0 : segmentStyle.thickness, '--segment-spacing': segmentStyle === null || segmentStyle === void 0 ? void 0 : segmentStyle.spacing, '--segment-length': segmentStyle === null || segmentStyle === void 0 ? void 0 : segmentStyle.length, '--segment-filament': segmentStyle === null || segmentStyle === void 0 ? void 0 : segmentStyle.filament, '--segment-opacity-on': segmentStyle === null || segmentStyle === void 0 ? void 0 : segmentStyle.opacityOn, '--segment-opacity-off': segmentStyle === null || segmentStyle === void 0 ? void 0 : segmentStyle.opacityOff, '--segment-transition-duration': segmentStyle === null || segmentStyle === void 0 ? void 0 : segmentStyle.transitionDuration }, rest.style);
|
|
27
|
-
if (type === 'digit')
|
|
28
|
-
return (0, jsx_runtime_1.jsx)(DigitSegments, Object.assign({}, rest, segments, { style: sx }));
|
|
29
|
-
if (type === 'colon')
|
|
30
|
-
return (0, jsx_runtime_1.jsx)(ColonSegments, Object.assign({}, rest, segments, { style: sx }));
|
|
31
|
-
if (type === 'ampm')
|
|
32
|
-
return (0, jsx_runtime_1.jsx)(AmpmSegments, Object.assign({}, rest, segments, { style: sx }));
|
|
33
|
-
if (type === 'dot')
|
|
34
|
-
return (0, jsx_runtime_1.jsx)(DotSegments, Object.assign({}, rest, segments, { style: sx }));
|
|
35
|
-
console.warn(`Digit.tsx: incompatible value: ${value.toString()}`);
|
|
36
|
-
return (0, jsx_runtime_1.jsx)("div", Object.assign({}, rest, { className: (0, classnames_1.default)('digit unknown', rest.className) }));
|
|
23
|
+
var rest = __rest(_a, []);
|
|
24
|
+
const scopeAttribute = (0, useStyleInjection_1.default)(digit_css_js_1.default.content, digit_css_js_1.default.hash);
|
|
25
|
+
return ((0, jsx_runtime_1.jsx)("div", Object.assign({}, scopeAttribute, { style: { display: 'contents' }, children: (0, jsx_runtime_1.jsx)(UnstyledDigit_1.Digit, Object.assign({}, rest)) })));
|
|
37
26
|
};
|
|
38
27
|
exports.Digit = Digit;
|
|
39
|
-
const DigitSegments = (_a) => {
|
|
40
|
-
var { className, off, shape = 'default', A, B, C, D, E, F, G } = _a, rest = __rest(_a, ["className", "off", "shape", "A", "B", "C", "D", "E", "F", "G"]);
|
|
41
|
-
return ((0, jsx_runtime_1.jsxs)("div", Object.assign({ className: (0, classnames_1.default)('digit', shapeCx(shape), className) }, rest, { children: [(0, jsx_runtime_1.jsxs)("div", { className: "opacity-wrapper off", children: [(0, jsx_runtime_1.jsx)("i", { className: (0, classnames_1.default)('segment A horizontal', onOffCx(A, off)) }), (0, jsx_runtime_1.jsx)("i", { className: (0, classnames_1.default)('segment B vertical', onOffCx(B, off)) }), (0, jsx_runtime_1.jsx)("i", { className: (0, classnames_1.default)('segment C vertical', onOffCx(C, off)) }), (0, jsx_runtime_1.jsx)("i", { className: (0, classnames_1.default)('segment D horizontal', onOffCx(D, off)) }), (0, jsx_runtime_1.jsx)("i", { className: (0, classnames_1.default)('segment E vertical', onOffCx(E, off)) }), (0, jsx_runtime_1.jsx)("i", { className: (0, classnames_1.default)('segment F vertical', onOffCx(F, off)) }), (0, jsx_runtime_1.jsx)("i", { className: (0, classnames_1.default)('segment G horizontal', onOffCx(G, off)) })] }), (0, jsx_runtime_1.jsxs)("div", { className: (0, classnames_1.default)('opacity-wrapper on', off && 'off'), children: [(0, jsx_runtime_1.jsx)("i", { className: (0, classnames_1.default)('segment A horizontal', onOffCx(A, off)) }), (0, jsx_runtime_1.jsx)("i", { className: (0, classnames_1.default)('segment B vertical', onOffCx(B, off)) }), (0, jsx_runtime_1.jsx)("i", { className: (0, classnames_1.default)('segment C vertical', onOffCx(C, off)) }), (0, jsx_runtime_1.jsx)("i", { className: (0, classnames_1.default)('segment D horizontal', onOffCx(D, off)) }), (0, jsx_runtime_1.jsx)("i", { className: (0, classnames_1.default)('segment E vertical', onOffCx(E, off)) }), (0, jsx_runtime_1.jsx)("i", { className: (0, classnames_1.default)('segment F vertical', onOffCx(F, off)) }), (0, jsx_runtime_1.jsx)("i", { className: (0, classnames_1.default)('segment G horizontal', onOffCx(G, off)) })] })] })));
|
|
42
|
-
};
|
|
43
|
-
const AmpmSegments = (_a) => {
|
|
44
|
-
var { className, off, shape = 'default', AM, PM } = _a, rest = __rest(_a, ["className", "off", "shape", "AM", "PM"]);
|
|
45
|
-
return ((0, jsx_runtime_1.jsxs)("div", Object.assign({ className: (0, classnames_1.default)('digit ampm', shapeCx(shape), className) }, rest, { children: [(0, jsx_runtime_1.jsxs)("div", { className: "opacity-wrapper off", children: [(0, jsx_runtime_1.jsx)("i", { className: (0, classnames_1.default)('segment AM', onOffCx(AM, off)) }), (0, jsx_runtime_1.jsx)("i", { className: (0, classnames_1.default)('segment PM', onOffCx(PM, off)) })] }), (0, jsx_runtime_1.jsxs)("div", { className: (0, classnames_1.default)('opacity-wrapper on', off && 'off'), children: [(0, jsx_runtime_1.jsx)("i", { className: (0, classnames_1.default)('segment AM', onOffCx(AM, off)) }), (0, jsx_runtime_1.jsx)("i", { className: (0, classnames_1.default)('segment PM', onOffCx(PM, off)) })] })] })));
|
|
46
|
-
};
|
|
47
|
-
const ColonSegments = (_a) => {
|
|
48
|
-
var { className, off, shape = 'default', D1, D2 } = _a, rest = __rest(_a, ["className", "off", "shape", "D1", "D2"]);
|
|
49
|
-
return ((0, jsx_runtime_1.jsxs)("div", Object.assign({ className: (0, classnames_1.default)('digit colon', shapeCx(shape), className) }, rest, { children: [(0, jsx_runtime_1.jsxs)("div", { className: "opacity-wrapper off", children: [(0, jsx_runtime_1.jsx)("i", { className: (0, classnames_1.default)('segment D1', onOffCx(D1, off)) }), (0, jsx_runtime_1.jsx)("i", { className: (0, classnames_1.default)('segment D2', onOffCx(D2, off)) })] }), (0, jsx_runtime_1.jsxs)("div", { className: (0, classnames_1.default)('opacity-wrapper on', off && 'off'), children: [(0, jsx_runtime_1.jsx)("i", { className: (0, classnames_1.default)('segment D1', onOffCx(D1, off)) }), (0, jsx_runtime_1.jsx)("i", { className: (0, classnames_1.default)('segment D2', onOffCx(D2, off)) })] })] })));
|
|
50
|
-
};
|
|
51
|
-
const DotSegments = (_a) => {
|
|
52
|
-
var { className, off, shape = 'default', DP } = _a, rest = __rest(_a, ["className", "off", "shape", "DP"]);
|
|
53
|
-
return ((0, jsx_runtime_1.jsxs)("div", Object.assign({ className: (0, classnames_1.default)('digit dot', shapeCx(shape), className) }, rest, { children: [(0, jsx_runtime_1.jsx)("div", { className: "opacity-wrapper off", children: (0, jsx_runtime_1.jsx)("i", { className: (0, classnames_1.default)('segment DP', onOffCx(DP, off)) }) }), (0, jsx_runtime_1.jsx)("div", { className: (0, classnames_1.default)('opacity-wrapper on', off && 'off'), children: (0, jsx_runtime_1.jsx)("i", { className: (0, classnames_1.default)('segment DP', onOffCx(DP, off)) }) })] })));
|
|
54
|
-
};
|
|
55
|
-
const charset = new Set(Object.keys(charToSevenSegments_1.charToSevenSegments));
|
|
56
|
-
function valueToType(v) {
|
|
57
|
-
const str = v.toString();
|
|
58
|
-
if (str === ':')
|
|
59
|
-
return 'colon';
|
|
60
|
-
if (str === '.')
|
|
61
|
-
return 'dot';
|
|
62
|
-
if (str.toLowerCase() === 'am' || str.toLowerCase() === 'pm')
|
|
63
|
-
return 'ampm';
|
|
64
|
-
if (charset.has(str))
|
|
65
|
-
return 'digit';
|
|
66
|
-
return undefined;
|
|
67
|
-
}
|
|
68
|
-
function valueToSegments(v) {
|
|
69
|
-
const str = v === null || v === void 0 ? void 0 : v.toString();
|
|
70
|
-
if (str.toLowerCase() === 'am')
|
|
71
|
-
return { AM: true };
|
|
72
|
-
if (str.toLowerCase() === 'pm')
|
|
73
|
-
return { PM: true };
|
|
74
|
-
if (str === ':')
|
|
75
|
-
return { D1: true, D2: true };
|
|
76
|
-
if (str === '.')
|
|
77
|
-
return { DP: true };
|
|
78
|
-
const segments = charToSevenSegments_1.charToSevenSegments[str];
|
|
79
|
-
return stringToProps(segments);
|
|
80
|
-
}
|
|
81
|
-
// Convert "AB" into object {A: true, B: true}
|
|
82
|
-
const stringToProps = (str) => Object.fromEntries(Array.from(str).map(char => [char, true]));
|
|
83
|
-
const onOffCx = (value, off) => value && !off ? 'on' : 'off';
|
|
84
|
-
const shapeCx = (shape) => {
|
|
85
|
-
if (!shape) {
|
|
86
|
-
return null;
|
|
87
|
-
}
|
|
88
|
-
return 'shape-' + shape;
|
|
89
|
-
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import React, { CSSProperties } from 'react';
|
|
2
|
+
import { SevenSegmentsValue } from './charToSevenSegments';
|
|
3
|
+
type NumValue = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9;
|
|
4
|
+
type DigitValue = NumValue | SevenSegmentsValue | 'am' | 'pm' | ':' | '.';
|
|
5
|
+
type DivProps = React.HTMLAttributes<HTMLDivElement>;
|
|
6
|
+
export type DigitProps = {
|
|
7
|
+
off?: boolean;
|
|
8
|
+
shape?: 'default' | 'rect' | 'round' | 'pill';
|
|
9
|
+
value: DigitValue;
|
|
10
|
+
};
|
|
11
|
+
type SegmentStyle = {
|
|
12
|
+
color?: CSSProperties['color'];
|
|
13
|
+
colorOff?: CSSProperties['color'];
|
|
14
|
+
length?: CSSProperties['width'];
|
|
15
|
+
thickness?: CSSProperties['width'];
|
|
16
|
+
spacing?: CSSProperties['width'];
|
|
17
|
+
filament?: CSSProperties['width'];
|
|
18
|
+
opacityOn?: CSSProperties['opacity'];
|
|
19
|
+
opacityOff?: CSSProperties['opacity'];
|
|
20
|
+
transitionDuration?: CSSProperties['transitionDuration'];
|
|
21
|
+
};
|
|
22
|
+
export type Digit = DivProps & DigitProps & {
|
|
23
|
+
segmentStyle?: SegmentStyle;
|
|
24
|
+
};
|
|
25
|
+
export declare const Digit: ({ segmentStyle, value, ...rest }: Digit) => import("react/jsx-runtime").JSX.Element;
|
|
26
|
+
export {};
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
3
|
+
var t = {};
|
|
4
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
5
|
+
t[p] = s[p];
|
|
6
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
7
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
8
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
9
|
+
t[p[i]] = s[p[i]];
|
|
10
|
+
}
|
|
11
|
+
return t;
|
|
12
|
+
};
|
|
13
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.Digit = void 0;
|
|
18
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
19
|
+
const clsx_1 = __importDefault(require("clsx"));
|
|
20
|
+
const charToSevenSegments_1 = require("./charToSevenSegments");
|
|
21
|
+
const components_1 = require("./components");
|
|
22
|
+
const Digit = (_a) => {
|
|
23
|
+
var { segmentStyle, value } = _a, rest = __rest(_a, ["segmentStyle", "value"]);
|
|
24
|
+
const type = valueToType(value);
|
|
25
|
+
const segments = type && valueToSegments(value); // {A: true, ...}
|
|
26
|
+
const sx = Object.assign({ '--segment-color': segmentStyle === null || segmentStyle === void 0 ? void 0 : segmentStyle.color, '--segment-color-off': segmentStyle === null || segmentStyle === void 0 ? void 0 : segmentStyle.colorOff, '--segment-thickness': segmentStyle === null || segmentStyle === void 0 ? void 0 : segmentStyle.thickness, '--segment-spacing': segmentStyle === null || segmentStyle === void 0 ? void 0 : segmentStyle.spacing, '--segment-length': segmentStyle === null || segmentStyle === void 0 ? void 0 : segmentStyle.length, '--segment-filament': segmentStyle === null || segmentStyle === void 0 ? void 0 : segmentStyle.filament, '--segment-opacity-on': segmentStyle === null || segmentStyle === void 0 ? void 0 : segmentStyle.opacityOn, '--segment-opacity-off': segmentStyle === null || segmentStyle === void 0 ? void 0 : segmentStyle.opacityOff, '--segment-transition-duration': segmentStyle === null || segmentStyle === void 0 ? void 0 : segmentStyle.transitionDuration }, rest.style);
|
|
27
|
+
if (type === 'digit')
|
|
28
|
+
return (0, jsx_runtime_1.jsx)(components_1.DigitSegments, Object.assign({}, rest, segments, { style: sx }));
|
|
29
|
+
if (type === 'colon')
|
|
30
|
+
return (0, jsx_runtime_1.jsx)(components_1.ColonSegments, Object.assign({}, rest, segments, { style: sx }));
|
|
31
|
+
if (type === 'ampm')
|
|
32
|
+
return (0, jsx_runtime_1.jsx)(components_1.AmpmSegments, Object.assign({}, rest, segments, { style: sx }));
|
|
33
|
+
if (type === 'dot')
|
|
34
|
+
return (0, jsx_runtime_1.jsx)(components_1.DotSegments, Object.assign({}, rest, segments, { style: sx }));
|
|
35
|
+
console.warn(`Digit.tsx: incompatible value: ${value.toString()}`);
|
|
36
|
+
return (0, jsx_runtime_1.jsx)("div", Object.assign({}, rest, { className: (0, clsx_1.default)('digit unknown', rest.className) }));
|
|
37
|
+
};
|
|
38
|
+
exports.Digit = Digit;
|
|
39
|
+
const charset = new Set(Object.keys(charToSevenSegments_1.charToSevenSegments));
|
|
40
|
+
function valueToType(v) {
|
|
41
|
+
const str = v.toString();
|
|
42
|
+
if (str === ':')
|
|
43
|
+
return 'colon';
|
|
44
|
+
if (str === '.')
|
|
45
|
+
return 'dot';
|
|
46
|
+
if (str.toLowerCase() === 'am' || str.toLowerCase() === 'pm')
|
|
47
|
+
return 'ampm';
|
|
48
|
+
if (charset.has(str))
|
|
49
|
+
return 'digit';
|
|
50
|
+
return undefined;
|
|
51
|
+
}
|
|
52
|
+
function valueToSegments(v) {
|
|
53
|
+
const str = v === null || v === void 0 ? void 0 : v.toString();
|
|
54
|
+
if (str.toLowerCase() === 'am')
|
|
55
|
+
return { AM: true };
|
|
56
|
+
if (str.toLowerCase() === 'pm')
|
|
57
|
+
return { PM: true };
|
|
58
|
+
if (str === ':')
|
|
59
|
+
return { D1: true, D2: true };
|
|
60
|
+
if (str === '.')
|
|
61
|
+
return { DP: true };
|
|
62
|
+
const segments = charToSevenSegments_1.charToSevenSegments[str];
|
|
63
|
+
return stringToProps(segments);
|
|
64
|
+
}
|
|
65
|
+
// Convert "AB" into object {A: true, B: true}
|
|
66
|
+
const stringToProps = (str) => Object.fromEntries(Array.from(str).map(char => [char, true]));
|
|
@@ -3,13 +3,11 @@ type DigitNumber = '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9';
|
|
|
3
3
|
type DigitSpecial = '_' | '-';
|
|
4
4
|
type DigitLetter = 'A' | 'C' | 'E' | 'F' | 'G' | 'H' | 'J' | 'L' | 'O' | 'P' | 'S' | 'U' | 'Y' | 'c' | 'b' | 'd' | 'h' | 'n' | 'o' | 'r' | 't' | 'u';
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
7
6
|
* A
|
|
8
7
|
* F B D2 AM
|
|
9
8
|
* G
|
|
10
9
|
* E C D1 PM
|
|
11
10
|
* D DP
|
|
12
|
-
*
|
|
13
11
|
*/
|
|
14
12
|
export declare const charToSevenSegments: {
|
|
15
13
|
[keyName in SevenSegmentsValue]: string;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { DigitProps } from '../UnstyledDigit';
|
|
2
|
+
type DivProps = React.HTMLAttributes<HTMLDivElement>;
|
|
3
|
+
export type AmpmSegments = DivProps & {
|
|
4
|
+
className?: string;
|
|
5
|
+
off?: DigitProps['off'];
|
|
6
|
+
shape?: DigitProps['shape'];
|
|
7
|
+
AM?: boolean;
|
|
8
|
+
PM?: boolean;
|
|
9
|
+
};
|
|
10
|
+
export declare const AmpmSegments: ({ className, off, shape, AM, PM, ...rest }: AmpmSegments) => import("react/jsx-runtime").JSX.Element;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
3
|
+
var t = {};
|
|
4
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
5
|
+
t[p] = s[p];
|
|
6
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
7
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
8
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
9
|
+
t[p[i]] = s[p[i]];
|
|
10
|
+
}
|
|
11
|
+
return t;
|
|
12
|
+
};
|
|
13
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.AmpmSegments = void 0;
|
|
18
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
19
|
+
const clsx_1 = __importDefault(require("clsx"));
|
|
20
|
+
const utils_1 = require("./utils");
|
|
21
|
+
const AmpmSegments = (_a) => {
|
|
22
|
+
var { className, off, shape = 'default', AM, PM } = _a, rest = __rest(_a, ["className", "off", "shape", "AM", "PM"]);
|
|
23
|
+
return ((0, jsx_runtime_1.jsxs)("div", Object.assign({ className: (0, clsx_1.default)('digit ampm', (0, utils_1.shapeCx)(shape), className) }, rest, { children: [(0, jsx_runtime_1.jsxs)("div", { className: "opacity-wrapper off", children: [(0, jsx_runtime_1.jsx)("i", { className: (0, clsx_1.default)('segment AM', (0, utils_1.onOffCx)(AM, off)) }), (0, jsx_runtime_1.jsx)("i", { className: (0, clsx_1.default)('segment PM', (0, utils_1.onOffCx)(PM, off)) })] }), (0, jsx_runtime_1.jsxs)("div", { className: (0, clsx_1.default)('opacity-wrapper on', off && 'off'), children: [(0, jsx_runtime_1.jsx)("i", { className: (0, clsx_1.default)('segment AM', (0, utils_1.onOffCx)(AM, off)) }), (0, jsx_runtime_1.jsx)("i", { className: (0, clsx_1.default)('segment PM', (0, utils_1.onOffCx)(PM, off)) })] })] })));
|
|
24
|
+
};
|
|
25
|
+
exports.AmpmSegments = AmpmSegments;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { DigitProps } from '../UnstyledDigit';
|
|
2
|
+
type DivProps = React.HTMLAttributes<HTMLDivElement>;
|
|
3
|
+
export type ColonSegments = DivProps & {
|
|
4
|
+
className?: string;
|
|
5
|
+
off?: DigitProps['off'];
|
|
6
|
+
shape?: DigitProps['shape'];
|
|
7
|
+
D1?: boolean;
|
|
8
|
+
D2?: boolean;
|
|
9
|
+
};
|
|
10
|
+
export declare const ColonSegments: ({ className, off, shape, D1, D2, ...rest }: ColonSegments) => import("react/jsx-runtime").JSX.Element;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
3
|
+
var t = {};
|
|
4
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
5
|
+
t[p] = s[p];
|
|
6
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
7
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
8
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
9
|
+
t[p[i]] = s[p[i]];
|
|
10
|
+
}
|
|
11
|
+
return t;
|
|
12
|
+
};
|
|
13
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.ColonSegments = void 0;
|
|
18
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
19
|
+
const clsx_1 = __importDefault(require("clsx"));
|
|
20
|
+
const utils_1 = require("./utils");
|
|
21
|
+
const ColonSegments = (_a) => {
|
|
22
|
+
var { className, off, shape = 'default', D1, D2 } = _a, rest = __rest(_a, ["className", "off", "shape", "D1", "D2"]);
|
|
23
|
+
return ((0, jsx_runtime_1.jsxs)("div", Object.assign({ className: (0, clsx_1.default)('digit colon', (0, utils_1.shapeCx)(shape), className) }, rest, { children: [(0, jsx_runtime_1.jsxs)("div", { className: "opacity-wrapper off", children: [(0, jsx_runtime_1.jsx)("i", { className: (0, clsx_1.default)('segment D1', (0, utils_1.onOffCx)(D1, off)) }), (0, jsx_runtime_1.jsx)("i", { className: (0, clsx_1.default)('segment D2', (0, utils_1.onOffCx)(D2, off)) })] }), (0, jsx_runtime_1.jsxs)("div", { className: (0, clsx_1.default)('opacity-wrapper on', off && 'off'), children: [(0, jsx_runtime_1.jsx)("i", { className: (0, clsx_1.default)('segment D1', (0, utils_1.onOffCx)(D1, off)) }), (0, jsx_runtime_1.jsx)("i", { className: (0, clsx_1.default)('segment D2', (0, utils_1.onOffCx)(D2, off)) })] })] })));
|
|
24
|
+
};
|
|
25
|
+
exports.ColonSegments = ColonSegments;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { DigitProps } from '../UnstyledDigit';
|
|
2
|
+
type DivProps = React.HTMLAttributes<HTMLDivElement>;
|
|
3
|
+
export type DigitSegments = DivProps & {
|
|
4
|
+
className?: string;
|
|
5
|
+
off?: DigitProps['off'];
|
|
6
|
+
shape?: DigitProps['shape'];
|
|
7
|
+
A?: boolean;
|
|
8
|
+
B?: boolean;
|
|
9
|
+
C?: boolean;
|
|
10
|
+
D?: boolean;
|
|
11
|
+
E?: boolean;
|
|
12
|
+
F?: boolean;
|
|
13
|
+
G?: boolean;
|
|
14
|
+
};
|
|
15
|
+
export declare const DigitSegments: ({ className, off, shape, A, B, C, D, E, F, G, ...rest }: DigitSegments) => import("react/jsx-runtime").JSX.Element;
|
|
16
|
+
export {};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
3
|
+
var t = {};
|
|
4
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
5
|
+
t[p] = s[p];
|
|
6
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
7
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
8
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
9
|
+
t[p[i]] = s[p[i]];
|
|
10
|
+
}
|
|
11
|
+
return t;
|
|
12
|
+
};
|
|
13
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.DigitSegments = void 0;
|
|
18
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
19
|
+
const clsx_1 = __importDefault(require("clsx"));
|
|
20
|
+
const utils_1 = require("./utils");
|
|
21
|
+
const DigitSegments = (_a) => {
|
|
22
|
+
var { className, off, shape = 'default', A, B, C, D, E, F, G } = _a, rest = __rest(_a, ["className", "off", "shape", "A", "B", "C", "D", "E", "F", "G"]);
|
|
23
|
+
return ((0, jsx_runtime_1.jsxs)("div", Object.assign({ className: (0, clsx_1.default)('digit', (0, utils_1.shapeCx)(shape), className) }, rest, { children: [(0, jsx_runtime_1.jsxs)("div", { className: "opacity-wrapper off", children: [(0, jsx_runtime_1.jsx)("i", { className: (0, clsx_1.default)('segment A horizontal', (0, utils_1.onOffCx)(A, off)) }), (0, jsx_runtime_1.jsx)("i", { className: (0, clsx_1.default)('segment B vertical', (0, utils_1.onOffCx)(B, off)) }), (0, jsx_runtime_1.jsx)("i", { className: (0, clsx_1.default)('segment C vertical', (0, utils_1.onOffCx)(C, off)) }), (0, jsx_runtime_1.jsx)("i", { className: (0, clsx_1.default)('segment D horizontal', (0, utils_1.onOffCx)(D, off)) }), (0, jsx_runtime_1.jsx)("i", { className: (0, clsx_1.default)('segment E vertical', (0, utils_1.onOffCx)(E, off)) }), (0, jsx_runtime_1.jsx)("i", { className: (0, clsx_1.default)('segment F vertical', (0, utils_1.onOffCx)(F, off)) }), (0, jsx_runtime_1.jsx)("i", { className: (0, clsx_1.default)('segment G horizontal', (0, utils_1.onOffCx)(G, off)) })] }), (0, jsx_runtime_1.jsxs)("div", { className: (0, clsx_1.default)('opacity-wrapper on', off && 'off'), children: [(0, jsx_runtime_1.jsx)("i", { className: (0, clsx_1.default)('segment A horizontal', (0, utils_1.onOffCx)(A, off)) }), (0, jsx_runtime_1.jsx)("i", { className: (0, clsx_1.default)('segment B vertical', (0, utils_1.onOffCx)(B, off)) }), (0, jsx_runtime_1.jsx)("i", { className: (0, clsx_1.default)('segment C vertical', (0, utils_1.onOffCx)(C, off)) }), (0, jsx_runtime_1.jsx)("i", { className: (0, clsx_1.default)('segment D horizontal', (0, utils_1.onOffCx)(D, off)) }), (0, jsx_runtime_1.jsx)("i", { className: (0, clsx_1.default)('segment E vertical', (0, utils_1.onOffCx)(E, off)) }), (0, jsx_runtime_1.jsx)("i", { className: (0, clsx_1.default)('segment F vertical', (0, utils_1.onOffCx)(F, off)) }), (0, jsx_runtime_1.jsx)("i", { className: (0, clsx_1.default)('segment G horizontal', (0, utils_1.onOffCx)(G, off)) })] })] })));
|
|
24
|
+
};
|
|
25
|
+
exports.DigitSegments = DigitSegments;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { DigitProps } from '../UnstyledDigit';
|
|
2
|
+
type DivProps = React.HTMLAttributes<HTMLDivElement>;
|
|
3
|
+
export type DotSegments = DivProps & {
|
|
4
|
+
className?: string;
|
|
5
|
+
off?: DigitProps['off'];
|
|
6
|
+
shape?: DigitProps['shape'];
|
|
7
|
+
DP?: boolean;
|
|
8
|
+
};
|
|
9
|
+
export declare const DotSegments: ({ className, off, shape, DP, ...rest }: DotSegments) => import("react/jsx-runtime").JSX.Element;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
3
|
+
var t = {};
|
|
4
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
5
|
+
t[p] = s[p];
|
|
6
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
7
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
8
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
9
|
+
t[p[i]] = s[p[i]];
|
|
10
|
+
}
|
|
11
|
+
return t;
|
|
12
|
+
};
|
|
13
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.DotSegments = void 0;
|
|
18
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
19
|
+
const clsx_1 = __importDefault(require("clsx"));
|
|
20
|
+
const utils_1 = require("./utils");
|
|
21
|
+
const DotSegments = (_a) => {
|
|
22
|
+
var { className, off, shape = 'default', DP } = _a, rest = __rest(_a, ["className", "off", "shape", "DP"]);
|
|
23
|
+
return ((0, jsx_runtime_1.jsxs)("div", Object.assign({ className: (0, clsx_1.default)('digit dot', (0, utils_1.shapeCx)(shape), className) }, rest, { children: [(0, jsx_runtime_1.jsx)("div", { className: "opacity-wrapper off", children: (0, jsx_runtime_1.jsx)("i", { className: (0, clsx_1.default)('segment DP', (0, utils_1.onOffCx)(DP, off)) }) }), (0, jsx_runtime_1.jsx)("div", { className: (0, clsx_1.default)('opacity-wrapper on', off && 'off'), children: (0, jsx_runtime_1.jsx)("i", { className: (0, clsx_1.default)('segment DP', (0, utils_1.onOffCx)(DP, off)) }) })] })));
|
|
24
|
+
};
|
|
25
|
+
exports.DotSegments = DotSegments;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./AmpmSegments"), exports);
|
|
18
|
+
__exportStar(require("./ColonSegments"), exports);
|
|
19
|
+
__exportStar(require("./DigitSegments"), exports);
|
|
20
|
+
__exportStar(require("./DotSegments"), exports);
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.shapeCx = exports.onOffCx = void 0;
|
|
4
|
+
const onOffCx = (value, off) => value && !off ? 'on' : 'off';
|
|
5
|
+
exports.onOffCx = onOffCx;
|
|
6
|
+
const shapeCx = (shape) => {
|
|
7
|
+
if (!shape) {
|
|
8
|
+
return null;
|
|
9
|
+
}
|
|
10
|
+
return 'shape-' + shape;
|
|
11
|
+
};
|
|
12
|
+
exports.shapeCx = shapeCx;
|
package/lib/Digit/digit.css
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
* D DP
|
|
8
|
-
*
|
|
2
|
+
* A
|
|
3
|
+
* F B D2 AM
|
|
4
|
+
* G
|
|
5
|
+
* E C D1 PM
|
|
6
|
+
* D DP
|
|
9
7
|
*/
|
|
10
8
|
|
|
11
9
|
.digit {
|
|
12
10
|
--color: var(--segment-color, currentColor);
|
|
13
11
|
--color-off: var(--segment-color-off, var(--color));
|
|
14
|
-
--thick: var(--segment-thickness, 0.
|
|
15
|
-
--length: var(--segment-length,
|
|
16
|
-
--spacing: var(--segment-spacing, 0.
|
|
17
|
-
--filament: var(--segment-filament,
|
|
12
|
+
--thick: var(--segment-thickness, 0.25rem); /* =4px */
|
|
13
|
+
--length: var(--segment-length, 1rem);
|
|
14
|
+
--spacing: var(--segment-spacing, 0.0625rem); /* =1px */
|
|
15
|
+
--filament: var(--segment-filament, 0rem); /* vertical squeeze for A, D */
|
|
18
16
|
--opacity-on: var(--segment-opacity-on, 1);
|
|
19
17
|
--opacity-off: var(--segment-opacity-off, 0.1);
|
|
20
18
|
--transition-duration: var(--segment-transition-duration, 0.25s);
|
|
19
|
+
/* distortion of diamond, -0.5...0.5 */
|
|
20
|
+
--corner-shift: var(--diamond-corner-shift, 0.2);
|
|
21
21
|
|
|
22
22
|
--svg-am: url('data:image/svg+xml,<svg version="1.1" xmlns="http://www.w3.org/2000/svg" x="0px" y="0px" viewBox="0 0 16 16" xml:space="preserve"><style type="text/css">.st0{fill:none;stroke:black;stroke-linecap:square;stroke-linejoin:round;stroke-miterlimit:10;stroke-width:1;}</style><polyline class="st0" points="1.4,11.5 1.4,11.4 3.8,3.5 4.2,3.5 6.6,11.4 6.6,11.5 "/><polyline class="st0" points="14.5,11.5 14.5,3.5 14.1,3.5 11.5,9.9 11.3,9.9 8.9,3.5 8.5,3.5 8.5,11.5 "/><line class="st0" x1="2.6" y1="9.5" x2="5.4" y2="9.5"/></svg>');
|
|
23
23
|
--svg-pm: url('data:image/svg+xml,<svg version="1.1" xmlns="http://www.w3.org/2000/svg" x="0px" y="0px" viewBox="0 0 16 16" xml:space="preserve"><style type="text/css">.st0{fill:none;stroke:black;stroke-linecap:square;stroke-linejoin:round;stroke-miterlimit:10;stroke-width:1;}</style><path class="st0" d="M1.5,11.5V3.4h2.1c1.6,0,2.5,1,2.5,2.2s-1,2.3-2.5,2.3H2.2"/><polyline class="st0" points="14.5,11.5 14.5,3.5 14.1,3.5 11.5,9.9 11.3,9.9 8.9,3.5 8.5,3.5 8.5,11.5 "/></svg>');
|
|
@@ -50,41 +50,48 @@
|
|
|
50
50
|
min-width: var(--thick);
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
-
|
|
53
|
+
.opacity-wrapper {
|
|
54
54
|
position: absolute;
|
|
55
55
|
width: 100%;
|
|
56
56
|
height: 100%;
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
-
|
|
60
|
-
|
|
59
|
+
.opacity-wrapper,
|
|
60
|
+
.opacity-wrapper .segment {
|
|
61
61
|
transition-property: background-color, border-color, opacity, visibility;
|
|
62
62
|
transition-duration: var(--transition-duration);
|
|
63
63
|
}
|
|
64
64
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
65
|
+
.opacity-wrapper.off.on .segment.off,
|
|
66
|
+
.opacity-wrapper.on .segment.off,
|
|
67
|
+
.opacity-wrapper.off .segment.on {
|
|
68
68
|
visibility: hidden;
|
|
69
69
|
}
|
|
70
|
-
|
|
71
|
-
|
|
70
|
+
.opacity-wrapper.off .segment.off,
|
|
71
|
+
.opacity-wrapper.on .segment.on {
|
|
72
72
|
visibility: visible;
|
|
73
73
|
}
|
|
74
74
|
|
|
75
|
-
|
|
75
|
+
.opacity-wrapper.on {
|
|
76
76
|
opacity: var(--opacity-on);
|
|
77
77
|
}
|
|
78
|
-
|
|
78
|
+
.opacity-wrapper.off {
|
|
79
79
|
opacity: var(--opacity-off);
|
|
80
80
|
}
|
|
81
|
-
|
|
81
|
+
.opacity-wrapper.off.on {
|
|
82
|
+
opacity: 0;
|
|
83
|
+
}
|
|
84
|
+
.opacity-wrapper.on:not(.off) .segment.on {
|
|
85
|
+
opacity: 1;
|
|
86
|
+
}
|
|
87
|
+
.opacity-wrapper.on:not(.off) .segment.off {
|
|
82
88
|
opacity: 0;
|
|
83
89
|
}
|
|
84
90
|
|
|
85
91
|
/* segments */
|
|
86
|
-
|
|
92
|
+
.segment {
|
|
87
93
|
--th-half-100: calc(100% - var(--th-half));
|
|
94
|
+
--shft: calc(var(--thick) * var(--corner-shift));
|
|
88
95
|
|
|
89
96
|
background-color: var(--color);
|
|
90
97
|
display: block;
|
|
@@ -120,15 +127,21 @@
|
|
|
120
127
|
width: var(--length);
|
|
121
128
|
height: var(--thick);
|
|
122
129
|
left: calc(var(--th-half) + var(--sp-half));
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
130
|
+
|
|
131
|
+
&.A,
|
|
132
|
+
&.D {
|
|
133
|
+
width: calc(var(--length) + var(--shft) * 2);
|
|
134
|
+
left: calc(var(--th-half) + var(--sp-half) - var(--shft));
|
|
135
|
+
}
|
|
136
|
+
&.A {
|
|
137
|
+
top: calc(var(--filament) + var(--shft));
|
|
138
|
+
}
|
|
139
|
+
&.D {
|
|
140
|
+
bottom: calc(var(--filament) + var(--shft));
|
|
141
|
+
}
|
|
142
|
+
&.G {
|
|
143
|
+
bottom: calc(var(--length) + var(--spacing));
|
|
144
|
+
}
|
|
132
145
|
}
|
|
133
146
|
|
|
134
147
|
/* spearheads */
|
|
@@ -141,6 +154,28 @@
|
|
|
141
154
|
var(--th-half-100) 100%,
|
|
142
155
|
var(--th-half) 100%
|
|
143
156
|
);
|
|
157
|
+
&.A {
|
|
158
|
+
/* x y */
|
|
159
|
+
clip-path: polygon(
|
|
160
|
+
0 calc(50% - var(--shft)),
|
|
161
|
+
calc(var(--th-half) - var(--shft)) 0,
|
|
162
|
+
calc(var(--th-half-100) + var(--shft)) 0,
|
|
163
|
+
100% calc(50% - var(--shft)),
|
|
164
|
+
calc(var(--th-half-100) - var(--shft)) 100%,
|
|
165
|
+
calc(var(--th-half) + var(--shft)) 100%
|
|
166
|
+
);
|
|
167
|
+
}
|
|
168
|
+
&.D {
|
|
169
|
+
/* x y */
|
|
170
|
+
clip-path: polygon(
|
|
171
|
+
0 calc(50% + var(--shft)),
|
|
172
|
+
calc(var(--th-half) + var(--shft)) 0,
|
|
173
|
+
calc(var(--th-half-100) - var(--shft)) 0,
|
|
174
|
+
100% calc(50% + var(--shft)),
|
|
175
|
+
calc(var(--th-half-100) + var(--shft)) 100%,
|
|
176
|
+
calc(var(--th-half) - var(--shft)) 100%
|
|
177
|
+
);
|
|
178
|
+
}
|
|
144
179
|
}
|
|
145
180
|
&.vertical {
|
|
146
181
|
clip-path: polygon(
|
|
@@ -151,6 +186,50 @@
|
|
|
151
186
|
100% var(--th-half-100),
|
|
152
187
|
100% var(--th-half)
|
|
153
188
|
);
|
|
189
|
+
&.B {
|
|
190
|
+
/* x y */
|
|
191
|
+
clip-path: polygon(
|
|
192
|
+
calc(50% + var(--shft)) 0,
|
|
193
|
+
0 calc(var(--th-half) + var(--shft)),
|
|
194
|
+
0 var(--th-half-100),
|
|
195
|
+
50% 100%,
|
|
196
|
+
100% var(--th-half-100),
|
|
197
|
+
100% calc(var(--th-half) - var(--shft))
|
|
198
|
+
);
|
|
199
|
+
}
|
|
200
|
+
&.C {
|
|
201
|
+
/* x y */
|
|
202
|
+
clip-path: polygon(
|
|
203
|
+
50% 0,
|
|
204
|
+
0 var(--th-half),
|
|
205
|
+
0 calc(var(--th-half-100) - var(--shft)),
|
|
206
|
+
calc(50% + var(--shft)) 100%,
|
|
207
|
+
100% calc(var(--th-half-100) + var(--shft)),
|
|
208
|
+
100% var(--th-half)
|
|
209
|
+
);
|
|
210
|
+
}
|
|
211
|
+
&.E {
|
|
212
|
+
/* x y */
|
|
213
|
+
clip-path: polygon(
|
|
214
|
+
50% 0,
|
|
215
|
+
0 var(--th-half),
|
|
216
|
+
0 calc(var(--th-half-100) + var(--shft)),
|
|
217
|
+
calc(50% - var(--shft)) 100%,
|
|
218
|
+
100% calc(var(--th-half-100) - var(--shft)),
|
|
219
|
+
100% var(--th-half)
|
|
220
|
+
);
|
|
221
|
+
}
|
|
222
|
+
&.F {
|
|
223
|
+
/* x y */
|
|
224
|
+
clip-path: polygon(
|
|
225
|
+
calc(50% - var(--shft)) 0,
|
|
226
|
+
0 calc(var(--th-half) - var(--shft)),
|
|
227
|
+
0 var(--th-half-100),
|
|
228
|
+
50% 100%,
|
|
229
|
+
100% var(--th-half-100),
|
|
230
|
+
100% calc(var(--th-half) + var(--shft))
|
|
231
|
+
);
|
|
232
|
+
}
|
|
154
233
|
}
|
|
155
234
|
}
|
|
156
235
|
|
|
@@ -170,7 +249,7 @@
|
|
|
170
249
|
&.ampm {
|
|
171
250
|
--digit-width: calc(var(--length) + var(--thick) + var(--spacing));
|
|
172
251
|
|
|
173
|
-
|
|
252
|
+
.segment {
|
|
174
253
|
background: var(--color);
|
|
175
254
|
width: var(--digit-width);
|
|
176
255
|
height: var(--length);
|
|
@@ -183,7 +262,7 @@
|
|
|
183
262
|
contain;
|
|
184
263
|
}
|
|
185
264
|
|
|
186
|
-
|
|
265
|
+
.AM {
|
|
187
266
|
bottom: calc(var(--digit-height) / 2 + var(--thick) / 4);
|
|
188
267
|
mask-image: var(--svg-am);
|
|
189
268
|
}
|
|
@@ -193,7 +272,7 @@
|
|
|
193
272
|
mask-composite: exclude;
|
|
194
273
|
mask-image: var(--svg-am), linear-gradient(var(--color) 0 0);
|
|
195
274
|
}
|
|
196
|
-
|
|
275
|
+
.PM {
|
|
197
276
|
top: calc(var(--digit-height) / 2 + var(--thick) / 4);
|
|
198
277
|
mask-image: var(--svg-pm);
|
|
199
278
|
}
|
|
@@ -225,19 +304,19 @@
|
|
|
225
304
|
left: calc(var(--digit-width) / 2 - var(--dot-border-width));
|
|
226
305
|
}
|
|
227
306
|
/* lower part of a colon */
|
|
228
|
-
|
|
307
|
+
.segment.D1 {
|
|
229
308
|
top: calc(var(--digit-height) / 3 - var(--thick) / 2);
|
|
230
309
|
}
|
|
231
310
|
/* upper part of a colon */
|
|
232
|
-
|
|
311
|
+
.segment.D2 {
|
|
233
312
|
bottom: calc(var(--digit-height) / 3 - var(--thick) / 2);
|
|
234
313
|
}
|
|
235
314
|
/* dot itself */
|
|
236
|
-
|
|
315
|
+
.segment.DP {
|
|
237
316
|
bottom: 0;
|
|
238
317
|
}
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
318
|
+
&.shape-default .segment {
|
|
319
|
+
border-radius: var(--radius-pill);
|
|
320
|
+
}
|
|
242
321
|
}
|
|
243
322
|
}
|
package/lib/Digit/index.d.ts
CHANGED
package/lib/Digit/index.js
CHANGED
|
@@ -14,5 +14,8 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.UnstyledDigit = void 0;
|
|
17
18
|
__exportStar(require("./Digit"), exports);
|
|
19
|
+
var UnstyledDigit_1 = require("./UnstyledDigit");
|
|
20
|
+
Object.defineProperty(exports, "UnstyledDigit", { enumerable: true, get: function () { return UnstyledDigit_1.Digit; } });
|
|
18
21
|
__exportStar(require("./charToSevenSegments"), exports);
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
3
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
4
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
5
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
6
|
+
};
|
|
7
|
+
var _StyleInjectionState_state;
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
const react_1 = require("react");
|
|
10
|
+
const scopeAttribute = 'data-style-scope-id';
|
|
11
|
+
// Runtime style injection
|
|
12
|
+
const useHeadStyleInjection = (css, id, dependencies = [], scoped = true // isolate css behind @scope
|
|
13
|
+
) => {
|
|
14
|
+
const injected = new StyleInjectionState(); // singleton's state
|
|
15
|
+
const _id = `_${id}`; // safe id to make CSS selectors work
|
|
16
|
+
const style = {
|
|
17
|
+
id: `inject_id_${_id}`, // hash of css content
|
|
18
|
+
css: scoped ? wrapWithScope(css, _id) : css,
|
|
19
|
+
};
|
|
20
|
+
(0, react_1.useInsertionEffect)(() => {
|
|
21
|
+
injected.add(style);
|
|
22
|
+
return () => injected.remove(style);
|
|
23
|
+
}, dependencies);
|
|
24
|
+
return {
|
|
25
|
+
[scopeAttribute]: _id,
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
class StyleInjectionState {
|
|
29
|
+
constructor() {
|
|
30
|
+
_StyleInjectionState_state.set(this, {
|
|
31
|
+
injected: new Set(),
|
|
32
|
+
});
|
|
33
|
+
if (!StyleInjectionState.instance) {
|
|
34
|
+
StyleInjectionState.instance = this; // create first instance if needed
|
|
35
|
+
}
|
|
36
|
+
return StyleInjectionState.instance;
|
|
37
|
+
}
|
|
38
|
+
add(s) {
|
|
39
|
+
if (!this.has(s)) {
|
|
40
|
+
__classPrivateFieldGet(this, _StyleInjectionState_state, "f").injected.add(s.id);
|
|
41
|
+
document.head.appendChild(createStyleElement(s.css, s.id));
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
remove(s) {
|
|
45
|
+
var _a;
|
|
46
|
+
if (this.has(s)) {
|
|
47
|
+
__classPrivateFieldGet(this, _StyleInjectionState_state, "f").injected.delete(s.id);
|
|
48
|
+
(_a = document.head.querySelector(`#${s.id}`)) === null || _a === void 0 ? void 0 : _a.remove();
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
has(s) {
|
|
52
|
+
return __classPrivateFieldGet(this, _StyleInjectionState_state, "f").injected.has(s.id);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
_StyleInjectionState_state = new WeakMap();
|
|
56
|
+
const createStyleElement = (content, id = '') => {
|
|
57
|
+
const el = document.createElement('style');
|
|
58
|
+
el.innerHTML = content;
|
|
59
|
+
if (id !== '')
|
|
60
|
+
el.id = id;
|
|
61
|
+
return el;
|
|
62
|
+
};
|
|
63
|
+
const wrapWithScope = (rules, _id) => {
|
|
64
|
+
const isolated = `@scope ([${scopeAttribute}=${_id}]) {
|
|
65
|
+
:scope { display: contents; }
|
|
66
|
+
${rules}
|
|
67
|
+
}`;
|
|
68
|
+
return isolated;
|
|
69
|
+
};
|
|
70
|
+
exports.default = useHeadStyleInjection;
|
package/package.json
CHANGED
|
@@ -1,23 +1,26 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-led-digit",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"description": "",
|
|
3
|
+
"version": "0.0.7",
|
|
4
|
+
"description": "react component for 7-segment display (digit), includes dot, colon and am-pm digits",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"files": [
|
|
7
7
|
"lib/**/*"
|
|
8
8
|
],
|
|
9
9
|
"scripts": {
|
|
10
|
-
"build": "npm
|
|
10
|
+
"build": "npm-run-all clean css-to-js build-ts css-copy",
|
|
11
|
+
"build-storybook": "storybook build",
|
|
11
12
|
"build-ts": "tsc --project tsconfig.build.json",
|
|
12
13
|
"clean": "rimraf lib",
|
|
13
|
-
"copy
|
|
14
|
+
"css-copy": "npx cpy src/**/*.css lib",
|
|
15
|
+
"css-to-js-watch": "node css-to-js --watch",
|
|
16
|
+
"css-to-js": "node css-to-js",
|
|
17
|
+
"dev": "npm-run-all --parallel storybook css-to-js-watch",
|
|
14
18
|
"lint": "eslint ./src/ --fix",
|
|
15
19
|
"semantic-release": "semantic-release",
|
|
20
|
+
"storybook": "storybook dev -p 6006 && npm run css-to-js-watch",
|
|
16
21
|
"test:watch": "jest --watch",
|
|
17
22
|
"test": "jest --coverage",
|
|
18
|
-
"typecheck": "tsc --noEmit"
|
|
19
|
-
"storybook": "storybook dev -p 6006",
|
|
20
|
-
"build-storybook": "storybook build"
|
|
23
|
+
"typecheck": "tsc --noEmit"
|
|
21
24
|
},
|
|
22
25
|
"repository": {
|
|
23
26
|
"type": "git",
|
|
@@ -34,17 +37,15 @@
|
|
|
34
37
|
"node": ">=12.0"
|
|
35
38
|
},
|
|
36
39
|
"keywords": [
|
|
37
|
-
"
|
|
40
|
+
"7-segment",
|
|
38
41
|
"led",
|
|
39
42
|
"digit",
|
|
43
|
+
"react",
|
|
40
44
|
"component",
|
|
41
|
-
"
|
|
42
|
-
"
|
|
45
|
+
"seven-segments",
|
|
46
|
+
"display",
|
|
43
47
|
"clock"
|
|
44
48
|
],
|
|
45
|
-
"dependencies": {
|
|
46
|
-
"classnames": "^2.5.1"
|
|
47
|
-
},
|
|
48
49
|
"devDependencies": {
|
|
49
50
|
"@chromatic-com/storybook": "^1.6.1",
|
|
50
51
|
"@storybook/addon-essentials": "^8.2.4",
|
|
@@ -59,6 +60,8 @@
|
|
|
59
60
|
"@types/node": "^18.19.41",
|
|
60
61
|
"@typescript-eslint/eslint-plugin": "^7.16.1",
|
|
61
62
|
"@typescript-eslint/parser": "^7.16.1",
|
|
63
|
+
"chokidar": "^4.0.1",
|
|
64
|
+
"clsx": "^2.1.1",
|
|
62
65
|
"cpy-cli": "^5.0.0",
|
|
63
66
|
"eslint": "^8.57.0",
|
|
64
67
|
"eslint-config-prettier": "^9.1.0",
|
|
@@ -66,6 +69,7 @@
|
|
|
66
69
|
"eslint-plugin-storybook": "^0.8.0",
|
|
67
70
|
"jest": "^29.7.0",
|
|
68
71
|
"lint-staged": "^15.2.7",
|
|
72
|
+
"npm-run-all": "^4.1.5",
|
|
69
73
|
"prettier": "^3.3.3",
|
|
70
74
|
"react": "^18.3.1",
|
|
71
75
|
"react-dom": "^18.3.1",
|