react-led-digit 0.0.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/LICENSE +21 -0
- package/README.md +18 -0
- package/lib/Blinker/Blinker.d.ts +31 -0
- package/lib/Blinker/Blinker.js +107 -0
- package/lib/Blinker/index.d.ts +1 -0
- package/lib/Blinker/index.js +17 -0
- package/lib/BlinkingDigit/BlinkingDigit.d.ts +2 -0
- package/lib/BlinkingDigit/BlinkingDigit.js +59 -0
- package/lib/BlinkingDigit/index.d.ts +1 -0
- package/lib/BlinkingDigit/index.js +17 -0
- package/lib/Digit/Digit.d.ts +26 -0
- package/lib/Digit/Digit.js +89 -0
- package/lib/Digit/charToSevenSegments.d.ts +17 -0
- package/lib/Digit/charToSevenSegments.js +46 -0
- package/lib/Digit/index.d.ts +2 -0
- package/lib/Digit/index.js +18 -0
- package/lib/components/Digit/BlinkingDigit.d.ts +2 -0
- package/lib/components/Digit/BlinkingDigit.js +59 -0
- package/lib/components/Digit/Digit.d.ts +25 -0
- package/lib/components/Digit/Digit.js +89 -0
- package/lib/components/Digit/index.d.ts +3 -0
- package/lib/components/Digit/index.js +19 -0
- package/lib/components/Digit/utils/Blinker.d.ts +31 -0
- package/lib/components/Digit/utils/Blinker.js +107 -0
- package/lib/components/Digit/utils/blinkSingleton.d.ts +23 -0
- package/lib/components/Digit/utils/blinkSingleton.js +64 -0
- package/lib/components/Digit/utils/charToSevenSegments.d.ts +17 -0
- package/lib/components/Digit/utils/charToSevenSegments.js +46 -0
- package/lib/components/Digit/utils/index.d.ts +2 -0
- package/lib/components/Digit/utils/index.js +18 -0
- package/lib/components/index.d.ts +1 -0
- package/lib/components/index.js +17 -0
- package/lib/index.d.ts +3 -0
- package/lib/index.js +19 -0
- package/package.json +120 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Sergey Yakunin
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# React Seven-Segment Digit Component
|
|
2
|
+
|
|
3
|
+
Intended to use in digital clock or calculator.
|
|
4
|
+
|
|
5
|
+
Use example:
|
|
6
|
+
|
|
7
|
+
```tsx
|
|
8
|
+
import { Digit, BlinkingDigit } from 'react-led-digit';
|
|
9
|
+
|
|
10
|
+
<div className="digital-clock">
|
|
11
|
+
<Digit value="0" />
|
|
12
|
+
<Digit value="1" />
|
|
13
|
+
<BlinkingDigit value=":" />
|
|
14
|
+
<Digit value="2" />
|
|
15
|
+
<Digit value="3" />
|
|
16
|
+
<Digit value="am" />
|
|
17
|
+
</div>;
|
|
18
|
+
```
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
type BlinkerSubscriber = (state: BlinkerState['visible']) => void;
|
|
2
|
+
type BlinkerState = {
|
|
3
|
+
timeout: null | ReturnType<typeof setTimeout>;
|
|
4
|
+
subscribers: BlinkerSubscriber[];
|
|
5
|
+
period: number;
|
|
6
|
+
ratio: number;
|
|
7
|
+
visible: boolean;
|
|
8
|
+
blinks: number;
|
|
9
|
+
};
|
|
10
|
+
type BlinkerOptions = {
|
|
11
|
+
autoRun?: boolean;
|
|
12
|
+
period?: BlinkerState['period'];
|
|
13
|
+
ratio?: BlinkerState['ratio'];
|
|
14
|
+
visible?: BlinkerState['visible'];
|
|
15
|
+
};
|
|
16
|
+
export declare class Blinker {
|
|
17
|
+
#private;
|
|
18
|
+
private static instance;
|
|
19
|
+
constructor(options?: BlinkerOptions);
|
|
20
|
+
get period(): BlinkerState['period'];
|
|
21
|
+
get ratio(): BlinkerState['ratio'];
|
|
22
|
+
get visible(): BlinkerState['visible'];
|
|
23
|
+
set period(val: BlinkerState['period']);
|
|
24
|
+
set ratio(val: BlinkerState['ratio']);
|
|
25
|
+
set visible(val: BlinkerState['visible']);
|
|
26
|
+
start(visible?: boolean): void;
|
|
27
|
+
stop(): void;
|
|
28
|
+
subscribe(fn: BlinkerSubscriber): void;
|
|
29
|
+
unsubscribe(fn: BlinkerSubscriber): void;
|
|
30
|
+
}
|
|
31
|
+
export {};
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
3
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
4
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
5
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
6
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
7
|
+
};
|
|
8
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
9
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
10
|
+
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");
|
|
11
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
12
|
+
};
|
|
13
|
+
var _Blinker_instances, _Blinker_initOptions, _Blinker_state, _Blinker_on, _Blinker_off;
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.Blinker = void 0;
|
|
16
|
+
const defaultOptions = {
|
|
17
|
+
autoRun: true,
|
|
18
|
+
period: 1000,
|
|
19
|
+
ratio: 1,
|
|
20
|
+
visible: true,
|
|
21
|
+
};
|
|
22
|
+
class Blinker {
|
|
23
|
+
constructor(options = defaultOptions) {
|
|
24
|
+
_Blinker_instances.add(this);
|
|
25
|
+
_Blinker_initOptions.set(this, defaultOptions); // store options
|
|
26
|
+
_Blinker_state.set(this, {
|
|
27
|
+
timeout: null,
|
|
28
|
+
subscribers: [],
|
|
29
|
+
period: defaultOptions.period,
|
|
30
|
+
ratio: defaultOptions.ratio,
|
|
31
|
+
visible: defaultOptions.visible,
|
|
32
|
+
blinks: 0,
|
|
33
|
+
});
|
|
34
|
+
if (!Blinker.instance) {
|
|
35
|
+
Blinker.instance = this;
|
|
36
|
+
__classPrivateFieldSet(this, _Blinker_initOptions, Object.assign(Object.assign({}, defaultOptions), options), "f");
|
|
37
|
+
__classPrivateFieldGet(this, _Blinker_state, "f").period = __classPrivateFieldGet(this, _Blinker_initOptions, "f").period;
|
|
38
|
+
__classPrivateFieldGet(this, _Blinker_state, "f").ratio = __classPrivateFieldGet(this, _Blinker_initOptions, "f").ratio;
|
|
39
|
+
__classPrivateFieldGet(this, _Blinker_state, "f").visible = __classPrivateFieldGet(this, _Blinker_initOptions, "f").visible;
|
|
40
|
+
if (__classPrivateFieldGet(this, _Blinker_initOptions, "f").autoRun)
|
|
41
|
+
this.start();
|
|
42
|
+
}
|
|
43
|
+
return Blinker.instance;
|
|
44
|
+
}
|
|
45
|
+
get period() {
|
|
46
|
+
return __classPrivateFieldGet(this, _Blinker_state, "f").period;
|
|
47
|
+
}
|
|
48
|
+
get ratio() {
|
|
49
|
+
return __classPrivateFieldGet(this, _Blinker_state, "f").ratio;
|
|
50
|
+
}
|
|
51
|
+
get visible() {
|
|
52
|
+
return __classPrivateFieldGet(this, _Blinker_state, "f").visible;
|
|
53
|
+
}
|
|
54
|
+
set period(val) {
|
|
55
|
+
if (val !== __classPrivateFieldGet(this, _Blinker_state, "f").period && val !== 0) {
|
|
56
|
+
__classPrivateFieldGet(this, _Blinker_state, "f").period = Math.abs(val);
|
|
57
|
+
this.start();
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
set ratio(val) {
|
|
61
|
+
if (val !== __classPrivateFieldGet(this, _Blinker_state, "f").ratio && val !== 0) {
|
|
62
|
+
__classPrivateFieldGet(this, _Blinker_state, "f").ratio = Math.abs(val);
|
|
63
|
+
this.start();
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
set visible(val) {
|
|
67
|
+
if (val !== __classPrivateFieldGet(this, _Blinker_state, "f").visible) {
|
|
68
|
+
__classPrivateFieldGet(this, _Blinker_state, "f").visible = val;
|
|
69
|
+
this.start();
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
start(visible = __classPrivateFieldGet(this, _Blinker_state, "f").visible) {
|
|
73
|
+
if (__classPrivateFieldGet(this, _Blinker_state, "f").timeout)
|
|
74
|
+
this.stop();
|
|
75
|
+
visible ? __classPrivateFieldGet(this, _Blinker_instances, "m", _Blinker_on).call(this) : __classPrivateFieldGet(this, _Blinker_instances, "m", _Blinker_off).call(this); // start blinking
|
|
76
|
+
}
|
|
77
|
+
stop() {
|
|
78
|
+
__classPrivateFieldGet(this, _Blinker_state, "f").timeout && clearTimeout(__classPrivateFieldGet(this, _Blinker_state, "f").timeout);
|
|
79
|
+
__classPrivateFieldGet(this, _Blinker_state, "f").timeout = null;
|
|
80
|
+
}
|
|
81
|
+
subscribe(fn) {
|
|
82
|
+
if (!__classPrivateFieldGet(this, _Blinker_state, "f").subscribers.includes(fn)) {
|
|
83
|
+
__classPrivateFieldGet(this, _Blinker_state, "f").subscribers.push(fn);
|
|
84
|
+
}
|
|
85
|
+
console.log('subscribe()', __classPrivateFieldGet(this, _Blinker_state, "f").subscribers, __classPrivateFieldGet(this, _Blinker_state, "f").blinks);
|
|
86
|
+
}
|
|
87
|
+
unsubscribe(fn) {
|
|
88
|
+
__classPrivateFieldGet(this, _Blinker_state, "f").subscribers = __classPrivateFieldGet(this, _Blinker_state, "f").subscribers.filter(i => i !== fn);
|
|
89
|
+
console.log('unsubscribe()', __classPrivateFieldGet(this, _Blinker_state, "f").subscribers, __classPrivateFieldGet(this, _Blinker_state, "f").blinks);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
exports.Blinker = Blinker;
|
|
93
|
+
_Blinker_initOptions = new WeakMap(), _Blinker_state = new WeakMap(), _Blinker_instances = new WeakSet(), _Blinker_on = function _Blinker_on() {
|
|
94
|
+
__classPrivateFieldGet(this, _Blinker_state, "f").blinks++;
|
|
95
|
+
__classPrivateFieldGet(this, _Blinker_state, "f").visible = true;
|
|
96
|
+
__classPrivateFieldGet(this, _Blinker_state, "f").subscribers.forEach(fn => fn(true));
|
|
97
|
+
__classPrivateFieldGet(this, _Blinker_state, "f").timeout = setTimeout(() => {
|
|
98
|
+
__classPrivateFieldGet(this, _Blinker_instances, "m", _Blinker_off).call(this);
|
|
99
|
+
}, __classPrivateFieldGet(this, _Blinker_state, "f").period * (1 - 1 / __classPrivateFieldGet(this, _Blinker_state, "f").ratio));
|
|
100
|
+
}, _Blinker_off = function _Blinker_off() {
|
|
101
|
+
__classPrivateFieldGet(this, _Blinker_state, "f").blinks++;
|
|
102
|
+
__classPrivateFieldGet(this, _Blinker_state, "f").visible = false;
|
|
103
|
+
__classPrivateFieldGet(this, _Blinker_state, "f").subscribers.forEach(fn => fn(false));
|
|
104
|
+
__classPrivateFieldGet(this, _Blinker_state, "f").timeout = setTimeout(() => {
|
|
105
|
+
__classPrivateFieldGet(this, _Blinker_instances, "m", _Blinker_on).call(this);
|
|
106
|
+
}, __classPrivateFieldGet(this, _Blinker_state, "f").period * (1 / __classPrivateFieldGet(this, _Blinker_state, "f").ratio));
|
|
107
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './Blinker';
|
|
@@ -0,0 +1,17 @@
|
|
|
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("./Blinker"), exports);
|
|
@@ -0,0 +1,59 @@
|
|
|
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
26
|
+
var t = {};
|
|
27
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
28
|
+
t[p] = s[p];
|
|
29
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
30
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
31
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
32
|
+
t[p[i]] = s[p[i]];
|
|
33
|
+
}
|
|
34
|
+
return t;
|
|
35
|
+
};
|
|
36
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
37
|
+
exports.BlinkingDigit = void 0;
|
|
38
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
39
|
+
const react_1 = __importStar(require("react"));
|
|
40
|
+
const Digit_1 = require("../Digit");
|
|
41
|
+
const Blinker_1 = require("../Blinker");
|
|
42
|
+
const digitBlinker = new Blinker_1.Blinker(); // all BlinkingDigit's to blink in sync
|
|
43
|
+
exports.BlinkingDigit = react_1.default.memo((_a) => {
|
|
44
|
+
var { blink } = _a, rest = __rest(_a, ["blink"]);
|
|
45
|
+
if ((blink === null || blink === void 0 ? void 0 : blink.period) === 0 ||
|
|
46
|
+
(blink === null || blink === void 0 ? void 0 : blink.ratio) === 0 ||
|
|
47
|
+
typeof (rest === null || rest === void 0 ? void 0 : rest.off) === 'boolean')
|
|
48
|
+
return (0, jsx_runtime_1.jsx)(Digit_1.Digit, Object.assign({}, rest)); // no blinker required
|
|
49
|
+
const [visible, setVisible] = (0, react_1.useState)(digitBlinker.visible);
|
|
50
|
+
(0, react_1.useEffect)(() => {
|
|
51
|
+
if (blink === null || blink === void 0 ? void 0 : blink.period)
|
|
52
|
+
digitBlinker.period = blink.period;
|
|
53
|
+
if (blink === null || blink === void 0 ? void 0 : blink.ratio)
|
|
54
|
+
digitBlinker.ratio = blink.ratio;
|
|
55
|
+
digitBlinker.subscribe(setVisible);
|
|
56
|
+
return () => digitBlinker.unsubscribe(setVisible);
|
|
57
|
+
}, [blink === null || blink === void 0 ? void 0 : blink.period, blink === null || blink === void 0 ? void 0 : blink.ratio]);
|
|
58
|
+
return (0, jsx_runtime_1.jsx)(Digit_1.Digit, Object.assign({}, rest, { off: rest.off || !visible }));
|
|
59
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './BlinkingDigit';
|
|
@@ -0,0 +1,17 @@
|
|
|
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("./BlinkingDigit"), exports);
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import React, { CSSProperties } from 'react';
|
|
2
|
+
import { SevenSegmentsValue } from './charToSevenSegments';
|
|
3
|
+
import './digit.css';
|
|
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?: 'arduino' | 'diamond' | 'rect' | 'round' | 'pill';
|
|
10
|
+
value: DigitValue;
|
|
11
|
+
};
|
|
12
|
+
type SegmentStyle = {
|
|
13
|
+
color?: 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
|
+
opacityDuration?: 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,89 @@
|
|
|
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 classnames_1 = __importDefault(require("classnames"));
|
|
20
|
+
const charToSevenSegments_1 = require("./charToSevenSegments");
|
|
21
|
+
require("./digit.css");
|
|
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-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-opacity-duration': segmentStyle === null || segmentStyle === void 0 ? void 0 : segmentStyle.opacityDuration }, 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) }));
|
|
37
|
+
};
|
|
38
|
+
exports.Digit = Digit;
|
|
39
|
+
const DigitSegments = (_a) => {
|
|
40
|
+
var { className, off, shape, 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)(onOffCx(A, off), 'segment A horizontal') }), (0, jsx_runtime_1.jsx)("i", { className: (0, classnames_1.default)(onOffCx(B, off), 'segment B vertical') }), (0, jsx_runtime_1.jsx)("i", { className: (0, classnames_1.default)(onOffCx(C, off), 'segment C vertical') }), (0, jsx_runtime_1.jsx)("i", { className: (0, classnames_1.default)(onOffCx(D, off), 'segment D horizontal') }), (0, jsx_runtime_1.jsx)("i", { className: (0, classnames_1.default)(onOffCx(E, off), 'segment E vertical') }), (0, jsx_runtime_1.jsx)("i", { className: (0, classnames_1.default)(onOffCx(F, off), 'segment F vertical') }), (0, jsx_runtime_1.jsx)("i", { className: (0, classnames_1.default)(onOffCx(G, off), 'segment G horizontal') })] }), (0, jsx_runtime_1.jsxs)("div", { className: "opacity-wrapper on", children: [(0, jsx_runtime_1.jsx)("i", { className: (0, classnames_1.default)(onOffCx(A, off), 'segment A horizontal') }), (0, jsx_runtime_1.jsx)("i", { className: (0, classnames_1.default)(onOffCx(B, off), 'segment B vertical') }), (0, jsx_runtime_1.jsx)("i", { className: (0, classnames_1.default)(onOffCx(C, off), 'segment C vertical') }), (0, jsx_runtime_1.jsx)("i", { className: (0, classnames_1.default)(onOffCx(D, off), 'segment D horizontal') }), (0, jsx_runtime_1.jsx)("i", { className: (0, classnames_1.default)(onOffCx(E, off), 'segment E vertical') }), (0, jsx_runtime_1.jsx)("i", { className: (0, classnames_1.default)(onOffCx(F, off), 'segment F vertical') }), (0, jsx_runtime_1.jsx)("i", { className: (0, classnames_1.default)(onOffCx(G, off), 'segment G horizontal') })] })] })));
|
|
42
|
+
};
|
|
43
|
+
const AmpmSegments = (_a) => {
|
|
44
|
+
var { className, off, shape, 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.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 = 'pill', 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.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 = 'pill', DP } = _a, rest = __rest(_a, ["className", "off", "shape", "DP"]);
|
|
53
|
+
return ((0, jsx_runtime_1.jsx)("div", Object.assign({ className: (0, classnames_1.default)('digit dot', shapeCx(shape), className) }, rest, { 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,17 @@
|
|
|
1
|
+
export type SevenSegmentsValue = DigitNumber | DigitSpecial | DigitLetter;
|
|
2
|
+
type DigitNumber = '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9';
|
|
3
|
+
type DigitSpecial = '_' | '-';
|
|
4
|
+
type DigitLetter = 'A' | 'C' | 'E' | 'F' | 'H' | 'J' | 'L' | 'O' | 'P' | 'S' | 'U' | 'Y' | 'c' | 'b' | 'd' | 'h' | 'n' | 'o' | 'r' | 'u';
|
|
5
|
+
/**
|
|
6
|
+
*
|
|
7
|
+
* A
|
|
8
|
+
* F B D2 AM
|
|
9
|
+
* G
|
|
10
|
+
* E C D1 PM
|
|
11
|
+
* D DP
|
|
12
|
+
*
|
|
13
|
+
*/
|
|
14
|
+
export declare const charToSevenSegments: {
|
|
15
|
+
[keyName in SevenSegmentsValue]: string;
|
|
16
|
+
};
|
|
17
|
+
export {};
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.charToSevenSegments = void 0;
|
|
4
|
+
/**
|
|
5
|
+
*
|
|
6
|
+
* A
|
|
7
|
+
* F B D2 AM
|
|
8
|
+
* G
|
|
9
|
+
* E C D1 PM
|
|
10
|
+
* D DP
|
|
11
|
+
*
|
|
12
|
+
*/
|
|
13
|
+
exports.charToSevenSegments = {
|
|
14
|
+
_: 'D',
|
|
15
|
+
'-': 'G',
|
|
16
|
+
'0': 'ABCDEF',
|
|
17
|
+
'1': 'BC',
|
|
18
|
+
'2': 'ABDEG',
|
|
19
|
+
'3': 'ABCDG',
|
|
20
|
+
'4': 'BCFG',
|
|
21
|
+
'5': 'ACDFG',
|
|
22
|
+
'6': 'ACDEFG',
|
|
23
|
+
'7': 'ABC',
|
|
24
|
+
'8': 'ABCDEFG',
|
|
25
|
+
'9': 'ABCDFG',
|
|
26
|
+
A: 'ABCEFG',
|
|
27
|
+
C: 'ADEF',
|
|
28
|
+
E: 'ADEFG',
|
|
29
|
+
F: 'AEFG',
|
|
30
|
+
H: 'BCEFG',
|
|
31
|
+
J: 'BCDE',
|
|
32
|
+
L: 'DEF',
|
|
33
|
+
O: 'ABCDEF',
|
|
34
|
+
P: 'ABEFG',
|
|
35
|
+
S: 'ACDFG',
|
|
36
|
+
U: 'BCDEF',
|
|
37
|
+
Y: 'BCDFG',
|
|
38
|
+
c: 'DEG',
|
|
39
|
+
b: 'CDEFG',
|
|
40
|
+
d: 'BCDEG',
|
|
41
|
+
h: 'CEFG',
|
|
42
|
+
n: 'CEG',
|
|
43
|
+
o: 'CDEG',
|
|
44
|
+
r: 'EG',
|
|
45
|
+
u: 'CDE',
|
|
46
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
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("./Digit"), exports);
|
|
18
|
+
__exportStar(require("./charToSevenSegments"), exports);
|
|
@@ -0,0 +1,59 @@
|
|
|
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
26
|
+
var t = {};
|
|
27
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
28
|
+
t[p] = s[p];
|
|
29
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
30
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
31
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
32
|
+
t[p[i]] = s[p[i]];
|
|
33
|
+
}
|
|
34
|
+
return t;
|
|
35
|
+
};
|
|
36
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
37
|
+
exports.BlinkingDigit = void 0;
|
|
38
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
39
|
+
const react_1 = __importStar(require("react"));
|
|
40
|
+
const Digit_1 = require("./Digit");
|
|
41
|
+
const utils_1 = require("./utils");
|
|
42
|
+
const digitBlinker = new utils_1.Blinker(); // all BlinkingDigit's to blink in sync
|
|
43
|
+
exports.BlinkingDigit = react_1.default.memo((_a) => {
|
|
44
|
+
var { blink } = _a, rest = __rest(_a, ["blink"]);
|
|
45
|
+
if ((blink === null || blink === void 0 ? void 0 : blink.period) === 0 ||
|
|
46
|
+
(blink === null || blink === void 0 ? void 0 : blink.ratio) === 0 ||
|
|
47
|
+
typeof (rest === null || rest === void 0 ? void 0 : rest.off) === 'boolean')
|
|
48
|
+
return (0, jsx_runtime_1.jsx)(Digit_1.Digit, Object.assign({}, rest)); // no blinker required
|
|
49
|
+
const [visible, setVisible] = (0, react_1.useState)(digitBlinker.visible);
|
|
50
|
+
(0, react_1.useEffect)(() => {
|
|
51
|
+
if (blink === null || blink === void 0 ? void 0 : blink.period)
|
|
52
|
+
digitBlinker.period = blink.period;
|
|
53
|
+
if (blink === null || blink === void 0 ? void 0 : blink.ratio)
|
|
54
|
+
digitBlinker.ratio = blink.ratio;
|
|
55
|
+
digitBlinker.subscribe(setVisible);
|
|
56
|
+
return () => digitBlinker.unsubscribe(setVisible);
|
|
57
|
+
}, [blink === null || blink === void 0 ? void 0 : blink.period, blink === null || blink === void 0 ? void 0 : blink.ratio]);
|
|
58
|
+
return (0, jsx_runtime_1.jsx)(Digit_1.Digit, Object.assign({}, rest, { off: rest.off || !visible }));
|
|
59
|
+
});
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import React, { CSSProperties } from 'react';
|
|
2
|
+
import { SevenSegmentsValue } from './utils/charToSevenSegments';
|
|
3
|
+
import './digit.css';
|
|
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?: 'arduino' | 'diamond' | 'rect' | 'round' | 'pill';
|
|
10
|
+
value: DigitValue;
|
|
11
|
+
};
|
|
12
|
+
type SegmentStyle = {
|
|
13
|
+
color?: 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
|
+
};
|
|
21
|
+
export type Digit = DivProps & DigitProps & {
|
|
22
|
+
segmentStyle?: SegmentStyle;
|
|
23
|
+
};
|
|
24
|
+
export declare const Digit: ({ segmentStyle, value, ...rest }: Digit) => import("react/jsx-runtime").JSX.Element;
|
|
25
|
+
export {};
|
|
@@ -0,0 +1,89 @@
|
|
|
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 classnames_1 = __importDefault(require("classnames"));
|
|
20
|
+
const charToSevenSegments_1 = require("./utils/charToSevenSegments");
|
|
21
|
+
require("./digit.css");
|
|
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-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 }, 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) }));
|
|
37
|
+
};
|
|
38
|
+
exports.Digit = Digit;
|
|
39
|
+
const DigitSegments = (_a) => {
|
|
40
|
+
var { className, off, shape, 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)(onOffCx(A, off), 'segment A horizontal') }), (0, jsx_runtime_1.jsx)("i", { className: (0, classnames_1.default)(onOffCx(B, off), 'segment B vertical') }), (0, jsx_runtime_1.jsx)("i", { className: (0, classnames_1.default)(onOffCx(C, off), 'segment C vertical') }), (0, jsx_runtime_1.jsx)("i", { className: (0, classnames_1.default)(onOffCx(D, off), 'segment D horizontal') }), (0, jsx_runtime_1.jsx)("i", { className: (0, classnames_1.default)(onOffCx(E, off), 'segment E vertical') }), (0, jsx_runtime_1.jsx)("i", { className: (0, classnames_1.default)(onOffCx(F, off), 'segment F vertical') }), (0, jsx_runtime_1.jsx)("i", { className: (0, classnames_1.default)(onOffCx(G, off), 'segment G horizontal') })] }), (0, jsx_runtime_1.jsxs)("div", { className: "opacity-wrapper on", children: [(0, jsx_runtime_1.jsx)("i", { className: (0, classnames_1.default)(onOffCx(A, off), 'segment A horizontal') }), (0, jsx_runtime_1.jsx)("i", { className: (0, classnames_1.default)(onOffCx(B, off), 'segment B vertical') }), (0, jsx_runtime_1.jsx)("i", { className: (0, classnames_1.default)(onOffCx(C, off), 'segment C vertical') }), (0, jsx_runtime_1.jsx)("i", { className: (0, classnames_1.default)(onOffCx(D, off), 'segment D horizontal') }), (0, jsx_runtime_1.jsx)("i", { className: (0, classnames_1.default)(onOffCx(E, off), 'segment E vertical') }), (0, jsx_runtime_1.jsx)("i", { className: (0, classnames_1.default)(onOffCx(F, off), 'segment F vertical') }), (0, jsx_runtime_1.jsx)("i", { className: (0, classnames_1.default)(onOffCx(G, off), 'segment G horizontal') })] })] })));
|
|
42
|
+
};
|
|
43
|
+
const AmpmSegments = (_a) => {
|
|
44
|
+
var { className, off, shape, 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.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 = 'pill', 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.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 = 'pill', DP } = _a, rest = __rest(_a, ["className", "off", "shape", "DP"]);
|
|
53
|
+
return ((0, jsx_runtime_1.jsx)("div", Object.assign({ className: (0, classnames_1.default)('digit dot', shapeCx(shape), className) }, rest, { 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,19 @@
|
|
|
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("./Digit"), exports);
|
|
18
|
+
__exportStar(require("./BlinkingDigit"), exports);
|
|
19
|
+
__exportStar(require("./utils"), exports);
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
type BlinkerSubscriber = (state: BlinkerState['visible']) => void;
|
|
2
|
+
type BlinkerState = {
|
|
3
|
+
timeout: null | ReturnType<typeof setTimeout>;
|
|
4
|
+
subscribers: BlinkerSubscriber[];
|
|
5
|
+
period: number;
|
|
6
|
+
ratio: number;
|
|
7
|
+
visible: boolean;
|
|
8
|
+
blinks: number;
|
|
9
|
+
};
|
|
10
|
+
type BlinkerOptions = {
|
|
11
|
+
autoRun?: boolean;
|
|
12
|
+
period?: BlinkerState['period'];
|
|
13
|
+
ratio?: BlinkerState['ratio'];
|
|
14
|
+
visible?: BlinkerState['visible'];
|
|
15
|
+
};
|
|
16
|
+
export declare class Blinker {
|
|
17
|
+
#private;
|
|
18
|
+
private static instance;
|
|
19
|
+
constructor(options?: BlinkerOptions);
|
|
20
|
+
get period(): BlinkerState['period'];
|
|
21
|
+
get ratio(): BlinkerState['ratio'];
|
|
22
|
+
get visible(): BlinkerState['visible'];
|
|
23
|
+
set period(val: BlinkerState['period']);
|
|
24
|
+
set ratio(val: BlinkerState['ratio']);
|
|
25
|
+
set visible(val: BlinkerState['visible']);
|
|
26
|
+
start(visible?: boolean): void;
|
|
27
|
+
stop(): void;
|
|
28
|
+
subscribe(fn: BlinkerSubscriber): void;
|
|
29
|
+
unsubscribe(fn: BlinkerSubscriber): void;
|
|
30
|
+
}
|
|
31
|
+
export {};
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
3
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
4
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
5
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
6
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
7
|
+
};
|
|
8
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
9
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
10
|
+
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");
|
|
11
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
12
|
+
};
|
|
13
|
+
var _Blinker_instances, _Blinker_initOptions, _Blinker_state, _Blinker_on, _Blinker_off;
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.Blinker = void 0;
|
|
16
|
+
const defaultOptions = {
|
|
17
|
+
autoRun: true,
|
|
18
|
+
period: 1000,
|
|
19
|
+
ratio: 1,
|
|
20
|
+
visible: true,
|
|
21
|
+
};
|
|
22
|
+
class Blinker {
|
|
23
|
+
constructor(options = defaultOptions) {
|
|
24
|
+
_Blinker_instances.add(this);
|
|
25
|
+
_Blinker_initOptions.set(this, defaultOptions); // store options
|
|
26
|
+
_Blinker_state.set(this, {
|
|
27
|
+
timeout: null,
|
|
28
|
+
subscribers: [],
|
|
29
|
+
period: defaultOptions.period,
|
|
30
|
+
ratio: defaultOptions.ratio,
|
|
31
|
+
visible: defaultOptions.visible,
|
|
32
|
+
blinks: 0,
|
|
33
|
+
});
|
|
34
|
+
if (!Blinker.instance) {
|
|
35
|
+
Blinker.instance = this;
|
|
36
|
+
__classPrivateFieldSet(this, _Blinker_initOptions, Object.assign(Object.assign({}, defaultOptions), options), "f");
|
|
37
|
+
__classPrivateFieldGet(this, _Blinker_state, "f").period = __classPrivateFieldGet(this, _Blinker_initOptions, "f").period;
|
|
38
|
+
__classPrivateFieldGet(this, _Blinker_state, "f").ratio = __classPrivateFieldGet(this, _Blinker_initOptions, "f").ratio;
|
|
39
|
+
__classPrivateFieldGet(this, _Blinker_state, "f").visible = __classPrivateFieldGet(this, _Blinker_initOptions, "f").visible;
|
|
40
|
+
if (__classPrivateFieldGet(this, _Blinker_initOptions, "f").autoRun)
|
|
41
|
+
this.start();
|
|
42
|
+
}
|
|
43
|
+
return Blinker.instance;
|
|
44
|
+
}
|
|
45
|
+
get period() {
|
|
46
|
+
return __classPrivateFieldGet(this, _Blinker_state, "f").period;
|
|
47
|
+
}
|
|
48
|
+
get ratio() {
|
|
49
|
+
return __classPrivateFieldGet(this, _Blinker_state, "f").ratio;
|
|
50
|
+
}
|
|
51
|
+
get visible() {
|
|
52
|
+
return __classPrivateFieldGet(this, _Blinker_state, "f").visible;
|
|
53
|
+
}
|
|
54
|
+
set period(val) {
|
|
55
|
+
if (val !== __classPrivateFieldGet(this, _Blinker_state, "f").period && val !== 0) {
|
|
56
|
+
__classPrivateFieldGet(this, _Blinker_state, "f").period = Math.abs(val);
|
|
57
|
+
this.start();
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
set ratio(val) {
|
|
61
|
+
if (val !== __classPrivateFieldGet(this, _Blinker_state, "f").ratio && val !== 0) {
|
|
62
|
+
__classPrivateFieldGet(this, _Blinker_state, "f").ratio = Math.abs(val);
|
|
63
|
+
this.start();
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
set visible(val) {
|
|
67
|
+
if (val !== __classPrivateFieldGet(this, _Blinker_state, "f").visible) {
|
|
68
|
+
__classPrivateFieldGet(this, _Blinker_state, "f").visible = val;
|
|
69
|
+
this.start();
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
start(visible = __classPrivateFieldGet(this, _Blinker_state, "f").visible) {
|
|
73
|
+
if (__classPrivateFieldGet(this, _Blinker_state, "f").timeout)
|
|
74
|
+
this.stop();
|
|
75
|
+
visible ? __classPrivateFieldGet(this, _Blinker_instances, "m", _Blinker_on).call(this) : __classPrivateFieldGet(this, _Blinker_instances, "m", _Blinker_off).call(this); // start blinking
|
|
76
|
+
}
|
|
77
|
+
stop() {
|
|
78
|
+
__classPrivateFieldGet(this, _Blinker_state, "f").timeout && clearTimeout(__classPrivateFieldGet(this, _Blinker_state, "f").timeout);
|
|
79
|
+
__classPrivateFieldGet(this, _Blinker_state, "f").timeout = null;
|
|
80
|
+
}
|
|
81
|
+
subscribe(fn) {
|
|
82
|
+
if (!__classPrivateFieldGet(this, _Blinker_state, "f").subscribers.includes(fn)) {
|
|
83
|
+
__classPrivateFieldGet(this, _Blinker_state, "f").subscribers.push(fn);
|
|
84
|
+
}
|
|
85
|
+
console.log('subscribe()', __classPrivateFieldGet(this, _Blinker_state, "f").subscribers, __classPrivateFieldGet(this, _Blinker_state, "f").blinks);
|
|
86
|
+
}
|
|
87
|
+
unsubscribe(fn) {
|
|
88
|
+
__classPrivateFieldGet(this, _Blinker_state, "f").subscribers = __classPrivateFieldGet(this, _Blinker_state, "f").subscribers.filter(i => i !== fn);
|
|
89
|
+
console.log('unsubscribe()', __classPrivateFieldGet(this, _Blinker_state, "f").subscribers, __classPrivateFieldGet(this, _Blinker_state, "f").blinks);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
exports.Blinker = Blinker;
|
|
93
|
+
_Blinker_initOptions = new WeakMap(), _Blinker_state = new WeakMap(), _Blinker_instances = new WeakSet(), _Blinker_on = function _Blinker_on() {
|
|
94
|
+
__classPrivateFieldGet(this, _Blinker_state, "f").blinks++;
|
|
95
|
+
__classPrivateFieldGet(this, _Blinker_state, "f").visible = true;
|
|
96
|
+
__classPrivateFieldGet(this, _Blinker_state, "f").subscribers.forEach(fn => fn(true));
|
|
97
|
+
__classPrivateFieldGet(this, _Blinker_state, "f").timeout = setTimeout(() => {
|
|
98
|
+
__classPrivateFieldGet(this, _Blinker_instances, "m", _Blinker_off).call(this);
|
|
99
|
+
}, __classPrivateFieldGet(this, _Blinker_state, "f").period * __classPrivateFieldGet(this, _Blinker_state, "f").ratio);
|
|
100
|
+
}, _Blinker_off = function _Blinker_off() {
|
|
101
|
+
__classPrivateFieldGet(this, _Blinker_state, "f").blinks++;
|
|
102
|
+
__classPrivateFieldGet(this, _Blinker_state, "f").visible = false;
|
|
103
|
+
__classPrivateFieldGet(this, _Blinker_state, "f").subscribers.forEach(fn => fn(false));
|
|
104
|
+
__classPrivateFieldGet(this, _Blinker_state, "f").timeout = setTimeout(() => {
|
|
105
|
+
__classPrivateFieldGet(this, _Blinker_instances, "m", _Blinker_on).call(this);
|
|
106
|
+
}, __classPrivateFieldGet(this, _Blinker_state, "f").period / __classPrivateFieldGet(this, _Blinker_state, "f").ratio);
|
|
107
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
type BlinkSubscriber = (state: BlinkSingleton['visible']) => void;
|
|
2
|
+
type BlinkSingletonOptions = {
|
|
3
|
+
autoRun?: boolean;
|
|
4
|
+
period?: BlinkSingleton['period'];
|
|
5
|
+
ratio?: BlinkSingleton['ratio'];
|
|
6
|
+
visible?: BlinkSingleton['visible'];
|
|
7
|
+
};
|
|
8
|
+
export type BlinkSingleton = {
|
|
9
|
+
period: number;
|
|
10
|
+
ratio: number;
|
|
11
|
+
visible: boolean;
|
|
12
|
+
subscribe: (fn: BlinkSubscriber) => void;
|
|
13
|
+
unsubscribe: (fn: BlinkSubscriber) => void;
|
|
14
|
+
run: (opts?: BlinkSingletonOptions) => void;
|
|
15
|
+
stop: () => void;
|
|
16
|
+
};
|
|
17
|
+
export declare const blinkSingleton: (opts?: {
|
|
18
|
+
autoRun: boolean;
|
|
19
|
+
period: number;
|
|
20
|
+
ratio: number;
|
|
21
|
+
visible: boolean;
|
|
22
|
+
}) => BlinkSingleton;
|
|
23
|
+
export {};
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.blinkSingleton = void 0;
|
|
4
|
+
const defaultOpts = {
|
|
5
|
+
autoRun: true,
|
|
6
|
+
period: 1000,
|
|
7
|
+
ratio: 1,
|
|
8
|
+
visible: true,
|
|
9
|
+
};
|
|
10
|
+
const handler = {
|
|
11
|
+
timeout: null,
|
|
12
|
+
subscribers: [],
|
|
13
|
+
on(i) {
|
|
14
|
+
i.visible = true;
|
|
15
|
+
this.subscribers.forEach(fn => fn(true));
|
|
16
|
+
this.timeout = setTimeout(() => {
|
|
17
|
+
this.off(i);
|
|
18
|
+
}, i.period * i.ratio);
|
|
19
|
+
},
|
|
20
|
+
off(i) {
|
|
21
|
+
i.visible = false;
|
|
22
|
+
this.subscribers.forEach(fn => fn(false));
|
|
23
|
+
this.timeout = setTimeout(() => {
|
|
24
|
+
this.on(i);
|
|
25
|
+
}, i.period / i.ratio);
|
|
26
|
+
},
|
|
27
|
+
};
|
|
28
|
+
const blinkSingleton = (opts = defaultOpts) => {
|
|
29
|
+
const options = Object.assign(Object.assign({}, defaultOpts), opts);
|
|
30
|
+
const instance = {
|
|
31
|
+
period: options.period,
|
|
32
|
+
visible: options.visible,
|
|
33
|
+
ratio: options.ratio,
|
|
34
|
+
run(opts2 = options) {
|
|
35
|
+
const options2 = Object.assign(Object.assign({}, options), opts2);
|
|
36
|
+
if (handler.timeout) {
|
|
37
|
+
if (this.period === options2.period &&
|
|
38
|
+
this.visible === options2.visible &&
|
|
39
|
+
this.ratio === options2.ratio)
|
|
40
|
+
return; // if nothing has changed, keep running
|
|
41
|
+
this.stop();
|
|
42
|
+
}
|
|
43
|
+
this.period = options2.period;
|
|
44
|
+
this.ratio = options2.ratio;
|
|
45
|
+
this.visible = options2.visible;
|
|
46
|
+
this.visible ? handler.on(this) : handler.off(this); // run here
|
|
47
|
+
},
|
|
48
|
+
stop() {
|
|
49
|
+
handler.timeout && clearTimeout(handler.timeout);
|
|
50
|
+
handler.timeout = null;
|
|
51
|
+
},
|
|
52
|
+
subscribe(fn) {
|
|
53
|
+
if (!handler.subscribers.includes(fn)) {
|
|
54
|
+
handler.subscribers.push(fn);
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
unsubscribe(fn) {
|
|
58
|
+
handler.subscribers.filter(i => i !== fn);
|
|
59
|
+
},
|
|
60
|
+
};
|
|
61
|
+
options.autoRun && instance.run();
|
|
62
|
+
return instance;
|
|
63
|
+
};
|
|
64
|
+
exports.blinkSingleton = blinkSingleton;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export type SevenSegmentsValue = DigitNumber | DigitSpecial | DigitLetter;
|
|
2
|
+
type DigitNumber = '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9';
|
|
3
|
+
type DigitSpecial = '_' | '-';
|
|
4
|
+
type DigitLetter = 'A' | 'C' | 'E' | 'F' | 'H' | 'J' | 'L' | 'O' | 'P' | 'S' | 'U' | 'Y' | 'c' | 'b' | 'd' | 'h' | 'n' | 'o' | 'r' | 'u';
|
|
5
|
+
/**
|
|
6
|
+
*
|
|
7
|
+
* A
|
|
8
|
+
* F B D2 AM
|
|
9
|
+
* G
|
|
10
|
+
* E C D1 PM
|
|
11
|
+
* D DP
|
|
12
|
+
*
|
|
13
|
+
*/
|
|
14
|
+
export declare const charToSevenSegments: {
|
|
15
|
+
[keyName in SevenSegmentsValue]: string;
|
|
16
|
+
};
|
|
17
|
+
export {};
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.charToSevenSegments = void 0;
|
|
4
|
+
/**
|
|
5
|
+
*
|
|
6
|
+
* A
|
|
7
|
+
* F B D2 AM
|
|
8
|
+
* G
|
|
9
|
+
* E C D1 PM
|
|
10
|
+
* D DP
|
|
11
|
+
*
|
|
12
|
+
*/
|
|
13
|
+
exports.charToSevenSegments = {
|
|
14
|
+
_: 'D',
|
|
15
|
+
'-': 'G',
|
|
16
|
+
'0': 'ABCDEF',
|
|
17
|
+
'1': 'BC',
|
|
18
|
+
'2': 'ABDEG',
|
|
19
|
+
'3': 'ABCDG',
|
|
20
|
+
'4': 'BCFG',
|
|
21
|
+
'5': 'ACDFG',
|
|
22
|
+
'6': 'ACDEFG',
|
|
23
|
+
'7': 'ABC',
|
|
24
|
+
'8': 'ABCDEFG',
|
|
25
|
+
'9': 'ABCDFG',
|
|
26
|
+
A: 'ABCEFG',
|
|
27
|
+
C: 'ADEF',
|
|
28
|
+
E: 'ADEFG',
|
|
29
|
+
F: 'AEFG',
|
|
30
|
+
H: 'BCEFG',
|
|
31
|
+
J: 'BCDE',
|
|
32
|
+
L: 'DEF',
|
|
33
|
+
O: 'ABCDEF',
|
|
34
|
+
P: 'ABEFG',
|
|
35
|
+
S: 'ACDFG',
|
|
36
|
+
U: 'BCDEF',
|
|
37
|
+
Y: 'BCDFG',
|
|
38
|
+
c: 'DEG',
|
|
39
|
+
b: 'CDEFG',
|
|
40
|
+
d: 'BCDEG',
|
|
41
|
+
h: 'CEFG',
|
|
42
|
+
n: 'CEG',
|
|
43
|
+
o: 'CDEG',
|
|
44
|
+
r: 'EG',
|
|
45
|
+
u: 'CDE',
|
|
46
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
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("./Blinker"), exports);
|
|
18
|
+
__exportStar(require("./charToSevenSegments"), exports);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './Digit';
|
|
@@ -0,0 +1,17 @@
|
|
|
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("./Digit"), exports);
|
package/lib/index.d.ts
ADDED
package/lib/index.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
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("./Digit"), exports);
|
|
18
|
+
__exportStar(require("./BlinkingDigit"), exports);
|
|
19
|
+
__exportStar(require("./Blinker"), exports);
|
package/package.json
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "react-led-digit",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "",
|
|
5
|
+
"main": "./lib/index.js",
|
|
6
|
+
"files": [
|
|
7
|
+
"lib/**/*"
|
|
8
|
+
],
|
|
9
|
+
"scripts": {
|
|
10
|
+
"build": "tsc --project tsconfig.build.json",
|
|
11
|
+
"clean": "rm -rf ./lib/",
|
|
12
|
+
"lint": "eslint ./src/ --fix",
|
|
13
|
+
"semantic-release": "semantic-release",
|
|
14
|
+
"test:watch": "jest --watch",
|
|
15
|
+
"test": "jest --coverage",
|
|
16
|
+
"typecheck": "tsc --noEmit",
|
|
17
|
+
"storybook": "storybook dev -p 6006",
|
|
18
|
+
"build-storybook": "storybook build"
|
|
19
|
+
},
|
|
20
|
+
"repository": {
|
|
21
|
+
"type": "git",
|
|
22
|
+
"url": "git+https://github.com/yakunins/react-digit.git"
|
|
23
|
+
},
|
|
24
|
+
"license": "MIT",
|
|
25
|
+
"author": {
|
|
26
|
+
"name": "Sergey Yakunin",
|
|
27
|
+
"email": "s@yakunins.com",
|
|
28
|
+
"url": "https://github.com/yakunins"
|
|
29
|
+
},
|
|
30
|
+
"engines": {
|
|
31
|
+
"node": ">=12.0"
|
|
32
|
+
},
|
|
33
|
+
"keywords": [
|
|
34
|
+
"react",
|
|
35
|
+
"led",
|
|
36
|
+
"digit",
|
|
37
|
+
"component",
|
|
38
|
+
"7-segment",
|
|
39
|
+
"digital",
|
|
40
|
+
"clock"
|
|
41
|
+
],
|
|
42
|
+
"homepage": "https://github.com/yakunins/real-clock",
|
|
43
|
+
"devDependencies": {
|
|
44
|
+
"@chromatic-com/storybook": "^1.6.1",
|
|
45
|
+
"@storybook/addon-essentials": "^8.2.4",
|
|
46
|
+
"@storybook/addon-interactions": "^8.2.4",
|
|
47
|
+
"@storybook/addon-links": "^8.2.4",
|
|
48
|
+
"@storybook/addon-onboarding": "^8.2.4",
|
|
49
|
+
"@storybook/blocks": "^8.2.4",
|
|
50
|
+
"@storybook/react": "^8.2.4",
|
|
51
|
+
"@storybook/react-vite": "^8.2.4",
|
|
52
|
+
"@storybook/test": "^8.2.4",
|
|
53
|
+
"@types/jest": "^29.5.12",
|
|
54
|
+
"@types/node": "^18.19.41",
|
|
55
|
+
"@typescript-eslint/eslint-plugin": "^7.16.1",
|
|
56
|
+
"@typescript-eslint/parser": "^7.16.1",
|
|
57
|
+
"classnames": "^2.5.1",
|
|
58
|
+
"eslint": "^8.57.0",
|
|
59
|
+
"eslint-config-prettier": "^9.1.0",
|
|
60
|
+
"eslint-plugin-prettier": "^5.2.1",
|
|
61
|
+
"eslint-plugin-storybook": "^0.8.0",
|
|
62
|
+
"jest": "^29.7.0",
|
|
63
|
+
"lint-staged": "^15.2.7",
|
|
64
|
+
"prettier": "^3.3.3",
|
|
65
|
+
"react": "^18.3.1",
|
|
66
|
+
"react-dom": "^18.3.1",
|
|
67
|
+
"semantic-release": "^22.0.12",
|
|
68
|
+
"storybook": "^8.2.4",
|
|
69
|
+
"ts-jest": "^29.2.3",
|
|
70
|
+
"typescript": "^5.5.3"
|
|
71
|
+
},
|
|
72
|
+
"lint-staged": {
|
|
73
|
+
"*.ts": "eslint --cache --cache-location .eslintcache --fix"
|
|
74
|
+
},
|
|
75
|
+
"release": {
|
|
76
|
+
"branches": [
|
|
77
|
+
"main"
|
|
78
|
+
],
|
|
79
|
+
"plugins": [
|
|
80
|
+
[
|
|
81
|
+
"@semantic-release/commit-analyzer",
|
|
82
|
+
{
|
|
83
|
+
"preset": "conventionalcommits",
|
|
84
|
+
"releaseRules": [
|
|
85
|
+
{
|
|
86
|
+
"type": "build",
|
|
87
|
+
"scope": "deps",
|
|
88
|
+
"release": "patch"
|
|
89
|
+
}
|
|
90
|
+
]
|
|
91
|
+
}
|
|
92
|
+
],
|
|
93
|
+
[
|
|
94
|
+
"@semantic-release/release-notes-generator",
|
|
95
|
+
{
|
|
96
|
+
"preset": "conventionalcommits",
|
|
97
|
+
"presetConfig": {
|
|
98
|
+
"types": [
|
|
99
|
+
{
|
|
100
|
+
"type": "feat",
|
|
101
|
+
"section": "Features"
|
|
102
|
+
},
|
|
103
|
+
{
|
|
104
|
+
"type": "fix",
|
|
105
|
+
"section": "Bug Fixes"
|
|
106
|
+
},
|
|
107
|
+
{
|
|
108
|
+
"type": "build",
|
|
109
|
+
"section": "Dependencies and Other Build Updates",
|
|
110
|
+
"hidden": false
|
|
111
|
+
}
|
|
112
|
+
]
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
],
|
|
116
|
+
"@semantic-release/npm",
|
|
117
|
+
"@semantic-release/github"
|
|
118
|
+
]
|
|
119
|
+
}
|
|
120
|
+
}
|