react-led-digit 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,6 +1,7 @@
1
1
  # React Seven-Segment Digit Component
2
2
 
3
3
  Intended to use in digital clock or calculator.
4
+ Pure HTML and CSS
4
5
 
5
6
  Use example:
6
7
 
@@ -82,11 +82,9 @@ class Blinker {
82
82
  if (!__classPrivateFieldGet(this, _Blinker_state, "f").subscribers.includes(fn)) {
83
83
  __classPrivateFieldGet(this, _Blinker_state, "f").subscribers.push(fn);
84
84
  }
85
- console.log('subscribe()', __classPrivateFieldGet(this, _Blinker_state, "f").subscribers, __classPrivateFieldGet(this, _Blinker_state, "f").blinks);
86
85
  }
87
86
  unsubscribe(fn) {
88
87
  __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
88
  }
91
89
  }
92
90
  exports.Blinker = Blinker;
@@ -96,12 +94,19 @@ _Blinker_initOptions = new WeakMap(), _Blinker_state = new WeakMap(), _Blinker_i
96
94
  __classPrivateFieldGet(this, _Blinker_state, "f").subscribers.forEach(fn => fn(true));
97
95
  __classPrivateFieldGet(this, _Blinker_state, "f").timeout = setTimeout(() => {
98
96
  __classPrivateFieldGet(this, _Blinker_instances, "m", _Blinker_off).call(this);
99
- }, __classPrivateFieldGet(this, _Blinker_state, "f").period * (1 - 1 / __classPrivateFieldGet(this, _Blinker_state, "f").ratio));
97
+ }, getPeriod(__classPrivateFieldGet(this, _Blinker_state, "f")).on);
100
98
  }, _Blinker_off = function _Blinker_off() {
101
99
  __classPrivateFieldGet(this, _Blinker_state, "f").blinks++;
102
100
  __classPrivateFieldGet(this, _Blinker_state, "f").visible = false;
103
101
  __classPrivateFieldGet(this, _Blinker_state, "f").subscribers.forEach(fn => fn(false));
104
102
  __classPrivateFieldGet(this, _Blinker_state, "f").timeout = setTimeout(() => {
105
103
  __classPrivateFieldGet(this, _Blinker_instances, "m", _Blinker_on).call(this);
106
- }, __classPrivateFieldGet(this, _Blinker_state, "f").period * (1 / __classPrivateFieldGet(this, _Blinker_state, "f").ratio));
104
+ }, getPeriod(__classPrivateFieldGet(this, _Blinker_state, "f")).off);
107
105
  };
106
+ function getPeriod(state) {
107
+ const total = state.ratio + 1;
108
+ return {
109
+ on: state.period * (1 / total),
110
+ off: state.period * (1 - 1 / total),
111
+ };
112
+ }
@@ -39,7 +39,7 @@ const jsx_runtime_1 = require("react/jsx-runtime");
39
39
  const react_1 = __importStar(require("react"));
40
40
  const Digit_1 = require("../Digit");
41
41
  const Blinker_1 = require("../Blinker");
42
- const digitBlinker = new Blinker_1.Blinker(); // all BlinkingDigit's to blink in sync
42
+ const digitBlinker = new Blinker_1.Blinker(); // singleton makes all BlinkingDigit's to blink synchronoulsy
43
43
  exports.BlinkingDigit = react_1.default.memo((_a) => {
44
44
  var { blink } = _a, rest = __rest(_a, ["blink"]);
45
45
  if ((blink === null || blink === void 0 ? void 0 : blink.period) === 0 ||
@@ -6,18 +6,19 @@ type DigitValue = NumValue | SevenSegmentsValue | 'am' | 'pm' | ':' | '.';
6
6
  type DivProps = React.HTMLAttributes<HTMLDivElement>;
7
7
  type DigitProps = {
8
8
  off?: boolean;
9
- shape?: 'arduino' | 'diamond' | 'rect' | 'round' | 'pill';
9
+ shape?: 'default' | 'rect' | 'round' | 'pill';
10
10
  value: DigitValue;
11
11
  };
12
12
  type SegmentStyle = {
13
13
  color?: CSSProperties['color'];
14
+ colorOff?: CSSProperties['color'];
14
15
  length?: CSSProperties['width'];
15
16
  thickness?: CSSProperties['width'];
16
17
  spacing?: CSSProperties['width'];
17
18
  filament?: CSSProperties['width'];
18
19
  opacityOn?: CSSProperties['opacity'];
19
20
  opacityOff?: CSSProperties['opacity'];
20
- opacityDuration?: CSSProperties['transitionDuration'];
21
+ transitionDuration?: CSSProperties['transitionDuration'];
21
22
  };
22
23
  export type Digit = DivProps & DigitProps & {
23
24
  segmentStyle?: SegmentStyle;
@@ -23,7 +23,7 @@ const Digit = (_a) => {
23
23
  var { segmentStyle, value } = _a, rest = __rest(_a, ["segmentStyle", "value"]);
24
24
  const type = valueToType(value);
25
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);
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
27
  if (type === 'digit')
28
28
  return (0, jsx_runtime_1.jsx)(DigitSegments, Object.assign({}, rest, segments, { style: sx }));
29
29
  if (type === 'colon')
@@ -37,19 +37,19 @@ const Digit = (_a) => {
37
37
  };
38
38
  exports.Digit = Digit;
39
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"]);
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
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
42
  };
43
43
  const AmpmSegments = (_a) => {
44
- var { className, off, shape, AM, PM } = _a, rest = __rest(_a, ["className", "off", "shape", "AM", "PM"]);
44
+ var { className, off, shape = 'default', AM, PM } = _a, rest = __rest(_a, ["className", "off", "shape", "AM", "PM"]);
45
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
46
  };
47
47
  const ColonSegments = (_a) => {
48
- var { className, off, shape = 'pill', D1, D2 } = _a, rest = __rest(_a, ["className", "off", "shape", "D1", "D2"]);
48
+ var { className, off, shape = 'default', D1, D2 } = _a, rest = __rest(_a, ["className", "off", "shape", "D1", "D2"]);
49
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
50
  };
51
51
  const DotSegments = (_a) => {
52
- var { className, off, shape = 'pill', DP } = _a, rest = __rest(_a, ["className", "off", "shape", "DP"]);
52
+ var { className, off, shape = 'default', DP } = _a, rest = __rest(_a, ["className", "off", "shape", "DP"]);
53
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
54
  };
55
55
  const charset = new Set(Object.keys(charToSevenSegments_1.charToSevenSegments));
@@ -0,0 +1,241 @@
1
+ /**
2
+ *
3
+ * A
4
+ * F B D2 AM
5
+ * G
6
+ * E C D1 PM
7
+ * D DP
8
+ *
9
+ */
10
+
11
+ .digit {
12
+ --color: var(--segment-color, currentColor);
13
+ --color-off: var(--segment-color-off, var(--color));
14
+ --thick: var(--segment-thickness, 0.25em); /* 4px */
15
+ --length: var(--segment-length, 1em);
16
+ --spacing: var(--segment-spacing, 0.0625em); /* 1px */
17
+ --filament: var(--segment-filament, 0); /* vertical shift of A and D */
18
+ --corner: var(--segment-corner, 0); /* vertical shift of A and D */
19
+ --opacity-on: var(--segment-opacity-on, 1);
20
+ --opacity-off: var(--segment-opacity-off, 0.1);
21
+ --transition-duration: var(--segment-transition-duration, 0.25s);
22
+
23
+ --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>');
24
+ --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>');
25
+
26
+ /* computed values */
27
+ --digit-width: calc(var(--length) + var(--thick) + var(--spacing));
28
+ --digit-height: calc(var(--length) * 2 + var(--thick) + var(--spacing) * 2);
29
+
30
+ --thick-minus: calc(var(--thick) * -1);
31
+ --th-half: calc(var(--thick) / 2);
32
+ --th-half-minus: calc(var(--th-half) * -1);
33
+ --spacing-minus: calc(var(--spacing) * -1);
34
+ --sp-half: calc(var(--spacing) / 2);
35
+ --sp-half-minus: calc(var(--sp-half) * -1);
36
+
37
+ --radius-round: calc(var(--thick) * 0.33);
38
+ --radius-pill: 100em;
39
+
40
+ display: inline-block;
41
+ position: relative;
42
+ width: var(--digit-width);
43
+ height: var(--digit-height);
44
+
45
+ /* prevents flex-shrink effect */
46
+ min-width: var(--digit-width);
47
+ min-height: var(--digit-height);
48
+
49
+ &.unknown {
50
+ width: var(--thick);
51
+ min-width: var(--thick);
52
+ }
53
+
54
+ & .opacity-wrapper {
55
+ position: absolute;
56
+ width: 100%;
57
+ height: 100%;
58
+ }
59
+
60
+ & .opacity-wrapper.on .segment.off,
61
+ & .opacity-wrapper.off .segment.on {
62
+ opacity: 0;
63
+ }
64
+ & .opacity-wrapper.on .segment.on,
65
+ & .opacity-wrapper.off .segment.off {
66
+ opacity: 1;
67
+ }
68
+
69
+ & .opacity-wrapper.on,
70
+ & .segment.on {
71
+ opacity: var(--opacity-on);
72
+ }
73
+ & .opacity-wrapper.off,
74
+ & .segment.off {
75
+ opacity: var(--opacity-off);
76
+ }
77
+
78
+ & .segment {
79
+ transition-property: opacity, background-color, border-color;
80
+ transition-duration: var(--transition-duration);
81
+ }
82
+
83
+ /* segments */
84
+ & .segment {
85
+ --th-half-100: calc(100% - var(--th-half));
86
+
87
+ background-color: var(--color);
88
+ display: block;
89
+ position: absolute;
90
+
91
+ &.segment.off {
92
+ background-color: var(--color-off);
93
+ border-color: var(--color-off);
94
+ }
95
+ /* vertical segments */
96
+ &.vertical {
97
+ width: var(--thick);
98
+ height: var(--length);
99
+ left: 0;
100
+
101
+ &.B,
102
+ &.C {
103
+ left: auto;
104
+ right: 0;
105
+ }
106
+ }
107
+ &.E,
108
+ &.C {
109
+ bottom: calc(var(--th-half) + var(--sp-half));
110
+ }
111
+ &.F,
112
+ &.B {
113
+ top: calc(var(--th-half) + var(--sp-half));
114
+ }
115
+
116
+ /* horizontal segments */
117
+ &.horizontal {
118
+ width: var(--length);
119
+ height: var(--thick);
120
+ left: calc(var(--th-half) + var(--sp-half));
121
+ }
122
+ &.A {
123
+ top: var(--filament);
124
+ }
125
+ &.D {
126
+ bottom: var(--filament);
127
+ }
128
+ &.G {
129
+ bottom: calc(var(--length) + var(--spacing));
130
+ }
131
+
132
+ /* spearheads */
133
+ &.horizontal {
134
+ clip-path: polygon(
135
+ 0 50%,
136
+ var(--th-half) 0,
137
+ var(--th-half-100) 0,
138
+ 100% 50%,
139
+ var(--th-half-100) 100%,
140
+ var(--th-half) 100%
141
+ );
142
+ }
143
+ &.vertical {
144
+ clip-path: polygon(
145
+ 50% 0,
146
+ 0 var(--th-half),
147
+ 0 var(--th-half-100),
148
+ 50% 100%,
149
+ 100% var(--th-half-100),
150
+ 100% var(--th-half)
151
+ );
152
+ }
153
+ }
154
+
155
+ /* segment shapes */
156
+ &.shape-rect .segment.segment {
157
+ clip-path: unset;
158
+ }
159
+ &.shape-round .segment.segment {
160
+ border-radius: var(--radius-round);
161
+ clip-path: unset;
162
+ }
163
+ &.shape-pill .segment.segment {
164
+ border-radius: var(--radius-pill);
165
+ clip-path: unset;
166
+ }
167
+
168
+ &.ampm {
169
+ --digit-width: calc(var(--length) + var(--thick) + var(--spacing));
170
+
171
+ & .segment {
172
+ background: var(--color);
173
+ width: var(--digit-width);
174
+ height: var(--length);
175
+
176
+ mask-origin: fill-box;
177
+ mask-position: center;
178
+ mask-repeat: no-repeat;
179
+ mask-size:
180
+ auto 85%,
181
+ contain;
182
+ }
183
+
184
+ & .AM {
185
+ bottom: calc(var(--digit-height) / 2 + var(--thick) / 4);
186
+ mask-image: var(--svg-am);
187
+ }
188
+ &.shape-rect .AM,
189
+ &.shape-pill .AM,
190
+ &.shape-round .AM {
191
+ mask-composite: exclude;
192
+ mask-image: var(--svg-am), linear-gradient(var(--color) 0 0);
193
+ }
194
+ & .PM {
195
+ top: calc(var(--digit-height) / 2 + var(--thick) / 4);
196
+ mask-image: var(--svg-pm);
197
+ }
198
+ &.shape-rect .PM,
199
+ &.shape-pill .PM,
200
+ &.shape-round .PM {
201
+ mask-composite: exclude;
202
+ mask-image: var(--svg-pm), linear-gradient(var(--color) 0 0);
203
+ }
204
+ &.shape-round .segment {
205
+ border-radius: var(--radius-round);
206
+ }
207
+ &.shape-pill .segment {
208
+ border-radius: var(--radius-pill);
209
+ }
210
+ }
211
+
212
+ &.dot,
213
+ &.colon {
214
+ --digit-width: calc(var(--thick) * 3);
215
+
216
+ & .segment {
217
+ --dot-border-width: calc(var(--thick) * 0.6);
218
+
219
+ border: var(--dot-border-width) solid var(--color); /* dot made from border to have same size on zoom */
220
+ position: absolute;
221
+ width: 0;
222
+ height: 0;
223
+ left: calc(var(--digit-width) / 2 - var(--dot-border-width));
224
+ }
225
+ /* lower part of a colon */
226
+ & .segment.D1 {
227
+ top: calc(var(--digit-height) / 3 - var(--thick) / 2);
228
+ }
229
+ /* upper part of a colon */
230
+ & .segment.D2 {
231
+ bottom: calc(var(--digit-height) / 3 - var(--thick) / 2);
232
+ }
233
+ /* dot itself */
234
+ & .segment.DP {
235
+ bottom: 0;
236
+ }
237
+ }
238
+ &.shape-default .segment {
239
+ border-radius: var(--radius-pill);
240
+ }
241
+ }
package/package.json CHANGED
@@ -1,14 +1,16 @@
1
1
  {
2
2
  "name": "react-led-digit",
3
- "version": "0.0.1",
3
+ "version": "0.0.2",
4
4
  "description": "",
5
5
  "main": "./lib/index.js",
6
6
  "files": [
7
7
  "lib/**/*"
8
8
  ],
9
9
  "scripts": {
10
- "build": "tsc --project tsconfig.build.json",
11
- "clean": "rm -rf ./lib/",
10
+ "build": "npm run clean && npm run build-ts && npm run copy-css",
11
+ "build-ts": "tsc --project tsconfig.build.json",
12
+ "clean": "rimraf lib",
13
+ "copy-css": "npx cpy src/**/*.css lib",
12
14
  "lint": "eslint ./src/ --fix",
13
15
  "semantic-release": "semantic-release",
14
16
  "test:watch": "jest --watch",
@@ -19,7 +21,7 @@
19
21
  },
20
22
  "repository": {
21
23
  "type": "git",
22
- "url": "git+https://github.com/yakunins/react-digit.git"
24
+ "url": "git+https://github.com/yakunins/react-led-digit.git"
23
25
  },
24
26
  "license": "MIT",
25
27
  "author": {
@@ -55,6 +57,7 @@
55
57
  "@typescript-eslint/eslint-plugin": "^7.16.1",
56
58
  "@typescript-eslint/parser": "^7.16.1",
57
59
  "classnames": "^2.5.1",
60
+ "cpy-cli": "^5.0.0",
58
61
  "eslint": "^8.57.0",
59
62
  "eslint-config-prettier": "^9.1.0",
60
63
  "eslint-plugin-prettier": "^5.2.1",
@@ -64,6 +67,7 @@
64
67
  "prettier": "^3.3.3",
65
68
  "react": "^18.3.1",
66
69
  "react-dom": "^18.3.1",
70
+ "rimraf": "^6.0.1",
67
71
  "semantic-release": "^22.0.12",
68
72
  "storybook": "^8.2.4",
69
73
  "ts-jest": "^29.2.3",
@@ -1,2 +0,0 @@
1
- import React from 'react';
2
- export declare const BlinkingDigit: React.MemoExoticComponent<({ blink, ...rest }: BlinkingDigit) => import("react/jsx-runtime").JSX.Element>;
@@ -1,59 +0,0 @@
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
- });
@@ -1,25 +0,0 @@
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 {};
@@ -1,89 +0,0 @@
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
- };
@@ -1,3 +0,0 @@
1
- export * from './Digit';
2
- export * from './BlinkingDigit';
3
- export * from './utils';
@@ -1,19 +0,0 @@
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);
@@ -1,31 +0,0 @@
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 {};
@@ -1,107 +0,0 @@
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
- };
@@ -1,23 +0,0 @@
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 {};
@@ -1,64 +0,0 @@
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;
@@ -1,17 +0,0 @@
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 {};
@@ -1,46 +0,0 @@
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
- };
@@ -1,2 +0,0 @@
1
- export * from './Blinker';
2
- export * from './charToSevenSegments';
@@ -1,18 +0,0 @@
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);
@@ -1 +0,0 @@
1
- export * from './Digit';
@@ -1,17 +0,0 @@
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);