react-led-digit 0.0.9 → 0.0.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/Digit/Digit.js +8 -4
- package/lib/Digit/Digit.stories.d.ts +0 -1
- package/lib/Digit/Digit.stories.js +2 -2
- package/lib/Digit/UnstyledDigit.js +6 -5
- package/lib/Digit/UnstyledDigit.stories.d.ts +18 -0
- package/lib/Digit/UnstyledDigit.stories.js +57 -0
- package/lib/Digit/components/AmpmSegments.js +1 -1
- package/lib/Digit/components/ColonSegments.js +1 -1
- package/lib/Digit/components/DigitSegments.js +1 -1
- package/lib/Digit/components/DotSegments.js +1 -1
- package/lib/Digit/digit.css +4 -0
- package/lib/Digit/{digit.css.js → digit.css.generated.js} +5 -1
- package/lib/Digit/useStyleInjector.d.ts +22 -0
- package/lib/Digit/useStyleInjector.js +98 -0
- package/package.json +1 -1
- package/lib/Digit/useStyleInjection.d.ts +0 -16
- package/lib/Digit/useStyleInjection.js +0 -87
package/lib/Digit/Digit.js
CHANGED
|
@@ -17,11 +17,15 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
17
17
|
exports.Digit = void 0;
|
|
18
18
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
19
19
|
const UnstyledDigit_1 = require("./UnstyledDigit");
|
|
20
|
-
const
|
|
21
|
-
const
|
|
20
|
+
const useStyleInjector_1 = __importDefault(require("./useStyleInjector"));
|
|
21
|
+
const digit_css_generated_js_1 = __importDefault(require("./digit.css.generated.js"));
|
|
22
22
|
const Digit = (_a) => {
|
|
23
23
|
var rest = __rest(_a, []);
|
|
24
|
-
const scopeAttribute = (0,
|
|
25
|
-
|
|
24
|
+
const scopeAttribute = (0, useStyleInjector_1.default)(digit_css_generated_js_1.default.content, [], {
|
|
25
|
+
scopeID: digit_css_generated_js_1.default.hash,
|
|
26
|
+
});
|
|
27
|
+
if (Object.entries(scopeAttribute)[0].includes(true))
|
|
28
|
+
return ((0, jsx_runtime_1.jsx)("div", Object.assign({}, scopeAttribute, { style: { display: 'contents' }, children: (0, jsx_runtime_1.jsx)(UnstyledDigit_1.Digit, Object.assign({}, rest)) })));
|
|
29
|
+
return (0, jsx_runtime_1.jsx)(UnstyledDigit_1.Digit, Object.assign({}, rest));
|
|
26
30
|
};
|
|
27
31
|
exports.Digit = Digit;
|
|
@@ -98,9 +98,9 @@ const BlinkingDigitTest = () => {
|
|
|
98
98
|
input { border: 1px solid black; border-radius: .5rem; padding: .5rem .25rem;}
|
|
99
99
|
button { border: none; border-radius: .5rem; padding: .5rem 1rem;}
|
|
100
100
|
button, input, p { font-size: 100%; font-family: sans-serif; margin: .25rem;}
|
|
101
|
-
` }), (0, jsx_runtime_1.jsxs)("p", { children: ["charset: ", Array.from(charset).join(', ')] }), (0, jsx_runtime_1.jsx)("input", { type: "text", placeholder: "digit", ref: input, onChange: handleChange, maxLength: 1 }), (0, jsx_runtime_1.jsx)("button", { onClick: addDigit, children: "Add digit" }), (0, jsx_runtime_1.jsxs)("div", { style: grid, children: [(0, jsx_runtime_1.jsx)(__1.
|
|
101
|
+
` }), (0, jsx_runtime_1.jsx)("p", { children: "asynchronous blinking example (blinkOptions.sync = false)" }), (0, jsx_runtime_1.jsxs)("p", { children: ["charset: ", Array.from(charset).join(', ')] }), (0, jsx_runtime_1.jsx)("input", { type: "text", placeholder: "digit", ref: input, onChange: handleChange, maxLength: 1 }), (0, jsx_runtime_1.jsx)("button", { onClick: addDigit, children: "Add digit" }), (0, jsx_runtime_1.jsxs)("div", { style: grid, children: [(0, jsx_runtime_1.jsx)(__1.BlinkingDigit, { value: "8", segmentStyle: { thickness: '.35rem' } }), (0, jsx_runtime_1.jsx)(__1.BlinkingDigit, { value: "b" }), (0, jsx_runtime_1.jsx)(__1.BlinkingDigit, { value: ":", blinkOptions: {
|
|
102
102
|
period: 2000,
|
|
103
|
-
ratio: 3,
|
|
103
|
+
ratio: 1 / 3,
|
|
104
104
|
} }), dgts.split('').map((char, idx) => ((0, jsx_runtime_1.jsx)(__1.BlinkingDigit, { value: char, onClick: () => removeDigit(idx), segmentStyle: {
|
|
105
105
|
transitionDuration: '0.5s',
|
|
106
106
|
}, blinkOptions: { sync: false } }, idx)))] })] }));
|
|
@@ -21,19 +21,20 @@ const charToSevenSegments_1 = require("./charToSevenSegments");
|
|
|
21
21
|
const components_1 = require("./components");
|
|
22
22
|
const Digit = (_a) => {
|
|
23
23
|
var { segmentStyle, value } = _a, rest = __rest(_a, ["segmentStyle", "value"]);
|
|
24
|
+
const v = value.toString();
|
|
24
25
|
const type = valueToType(value);
|
|
25
26
|
const segments = type && valueToSegments(value); // {A: true, ...}
|
|
26
27
|
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, '--segment-corner-shift': segmentStyle === null || segmentStyle === void 0 ? void 0 : segmentStyle.cornerShift }, rest.style);
|
|
27
28
|
if (type === 'digit')
|
|
28
|
-
return (0, jsx_runtime_1.jsx)(components_1.DigitSegments, Object.assign({}, rest, segments, { style: sx }));
|
|
29
|
+
return (0, jsx_runtime_1.jsx)(components_1.DigitSegments, Object.assign({ "aria-label": v }, rest, segments, { style: sx }));
|
|
29
30
|
if (type === 'colon')
|
|
30
|
-
return (0, jsx_runtime_1.jsx)(components_1.ColonSegments, Object.assign({}, rest, segments, { style: sx }));
|
|
31
|
+
return (0, jsx_runtime_1.jsx)(components_1.ColonSegments, Object.assign({ "aria-label": v }, rest, segments, { style: sx }));
|
|
31
32
|
if (type === 'ampm')
|
|
32
|
-
return (0, jsx_runtime_1.jsx)(components_1.AmpmSegments, Object.assign({}, rest, segments, { style: sx }));
|
|
33
|
+
return (0, jsx_runtime_1.jsx)(components_1.AmpmSegments, Object.assign({ "aria-label": v }, rest, segments, { style: sx }));
|
|
33
34
|
if (type === 'dot')
|
|
34
|
-
return (0, jsx_runtime_1.jsx)(components_1.DotSegments, Object.assign({}, rest, segments, { style: sx }));
|
|
35
|
+
return (0, jsx_runtime_1.jsx)(components_1.DotSegments, Object.assign({ "aria-label": v }, rest, segments, { style: sx }));
|
|
35
36
|
console.warn(`(at Digit.tsx) incompatible value: ${value.toString()}`);
|
|
36
|
-
return (0, jsx_runtime_1.jsx)("div", Object.assign({}, rest, { className: (0, clsx_1.default)('digit unknown', rest.className) }));
|
|
37
|
+
return ((0, jsx_runtime_1.jsx)("div", Object.assign({ "aria-label": v }, rest, { className: (0, clsx_1.default)('digit unknown', rest.className) })));
|
|
37
38
|
};
|
|
38
39
|
exports.Digit = Digit;
|
|
39
40
|
const charset = new Set(Object.keys(charToSevenSegments_1.charToSevenSegments));
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { StoryObj } from '@storybook/react';
|
|
2
|
+
import { UnstyledDigit } from '..';
|
|
3
|
+
declare const meta: {
|
|
4
|
+
title: string;
|
|
5
|
+
component: ({ segmentStyle, value, ...rest }: UnstyledDigit) => import("react/jsx-runtime").JSX.Element;
|
|
6
|
+
tags: string[];
|
|
7
|
+
parameters: {
|
|
8
|
+
layout: string;
|
|
9
|
+
};
|
|
10
|
+
argTypes: {
|
|
11
|
+
off: {
|
|
12
|
+
control: "boolean";
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
export default meta;
|
|
17
|
+
type Story = StoryObj<typeof meta>;
|
|
18
|
+
export declare const UnstyledDigits: Story;
|
|
@@ -0,0 +1,57 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
exports.UnstyledDigits = void 0;
|
|
15
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
16
|
+
const __1 = require("..");
|
|
17
|
+
//import './digit.css';
|
|
18
|
+
const meta = {
|
|
19
|
+
title: 'Example/UnstyledDigit',
|
|
20
|
+
component: __1.UnstyledDigit,
|
|
21
|
+
tags: ['autodocs'],
|
|
22
|
+
parameters: {
|
|
23
|
+
layout: 'fullscreen', // https://storybook.js.org/docs/configure/story-layout
|
|
24
|
+
},
|
|
25
|
+
argTypes: {
|
|
26
|
+
off: { control: 'boolean' },
|
|
27
|
+
},
|
|
28
|
+
};
|
|
29
|
+
exports.default = meta;
|
|
30
|
+
const grid = {
|
|
31
|
+
display: 'flex',
|
|
32
|
+
gap: '.35rem',
|
|
33
|
+
padding: '1rem',
|
|
34
|
+
placeItems: 'center center',
|
|
35
|
+
};
|
|
36
|
+
const CustomDigit = (_a) => {
|
|
37
|
+
var rest = __rest(_a, []);
|
|
38
|
+
return ((0, jsx_runtime_1.jsx)(__1.UnstyledDigit, Object.assign({}, rest, { shape: "pill", segmentStyle: {
|
|
39
|
+
thickness: '.25rem',
|
|
40
|
+
length: '1.5rem',
|
|
41
|
+
spacing: '0.25rem',
|
|
42
|
+
filament: '.0625rem',
|
|
43
|
+
} })));
|
|
44
|
+
};
|
|
45
|
+
const UnstyledDigitTest = () => {
|
|
46
|
+
return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsxs)("div", { style: grid, children: [(0, jsx_runtime_1.jsx)(__1.UnstyledDigit, { value: 0, className: "test" }), (0, jsx_runtime_1.jsx)(__1.UnstyledDigit, { value: 1, shape: "round", segmentStyle: {
|
|
47
|
+
thickness: '.35rem',
|
|
48
|
+
color: 'green',
|
|
49
|
+
colorOff: 'blue',
|
|
50
|
+
} }), (0, jsx_runtime_1.jsx)(__1.UnstyledDigit, { value: 2, shape: "pill", segmentStyle: { thickness: '.5rem' } }), (0, jsx_runtime_1.jsx)(__1.UnstyledDigit, { value: 3, shape: "rect", segmentStyle: { spacing: '.25rem' } }), (0, jsx_runtime_1.jsx)(__1.UnstyledDigit, { value: 4, style: { color: 'red' } }), (0, jsx_runtime_1.jsx)(__1.UnstyledDigit, { value: ":" }), (0, jsx_runtime_1.jsx)(__1.UnstyledDigit, { value: 5 }), (0, jsx_runtime_1.jsx)(__1.UnstyledDigit, { value: 6 }), (0, jsx_runtime_1.jsx)(__1.UnstyledDigit, { value: 7 }), (0, jsx_runtime_1.jsx)(__1.UnstyledDigit, { value: 8, off: true }), (0, jsx_runtime_1.jsx)(__1.UnstyledDigit, { value: 9 }), (0, jsx_runtime_1.jsx)(__1.UnstyledDigit, { value: "." }), (0, jsx_runtime_1.jsx)(__1.UnstyledDigit, { value: "pm" })] }), (0, jsx_runtime_1.jsxs)("div", { style: grid, children: [(0, jsx_runtime_1.jsx)(__1.UnstyledDigit, { value: "A" }), (0, jsx_runtime_1.jsx)(__1.UnstyledDigit, { value: "C" }), (0, jsx_runtime_1.jsx)(__1.UnstyledDigit, { value: "E" }), (0, jsx_runtime_1.jsx)(__1.UnstyledDigit, { value: "F" }), (0, jsx_runtime_1.jsx)(__1.UnstyledDigit, { value: "G" }), (0, jsx_runtime_1.jsx)(__1.UnstyledDigit, { value: "H" }), (0, jsx_runtime_1.jsx)(__1.UnstyledDigit, { value: "J" }), (0, jsx_runtime_1.jsx)(__1.UnstyledDigit, { value: "L" }), (0, jsx_runtime_1.jsx)(__1.UnstyledDigit, { value: "O" }), (0, jsx_runtime_1.jsx)(__1.UnstyledDigit, { value: "P" }), (0, jsx_runtime_1.jsx)(__1.UnstyledDigit, { value: "S" }), (0, jsx_runtime_1.jsx)(__1.UnstyledDigit, { value: "U" }), (0, jsx_runtime_1.jsx)(__1.UnstyledDigit, { value: "Y" })] }), (0, jsx_runtime_1.jsxs)("div", { style: grid, children: [(0, jsx_runtime_1.jsx)(CustomDigit, { value: 0 }), (0, jsx_runtime_1.jsx)(CustomDigit, { value: 1 }), (0, jsx_runtime_1.jsx)(CustomDigit, { value: ":" }), (0, jsx_runtime_1.jsx)(CustomDigit, { value: 2 }), (0, jsx_runtime_1.jsx)(CustomDigit, { value: 3 }), (0, jsx_runtime_1.jsx)(CustomDigit, { value: "am" })] }), (0, jsx_runtime_1.jsxs)("div", { style: grid, children: [(0, jsx_runtime_1.jsx)(CustomDigit, { value: "A" }), (0, jsx_runtime_1.jsx)(CustomDigit, { value: "C" }), (0, jsx_runtime_1.jsx)(CustomDigit, { value: "E" }), (0, jsx_runtime_1.jsx)(CustomDigit, { value: "F" }), (0, jsx_runtime_1.jsx)(CustomDigit, { value: "H" }), (0, jsx_runtime_1.jsx)(CustomDigit, { value: "J" }), (0, jsx_runtime_1.jsx)(CustomDigit, { value: "L" }), (0, jsx_runtime_1.jsx)(CustomDigit, { value: "O" }), (0, jsx_runtime_1.jsx)(CustomDigit, { value: "P" }), (0, jsx_runtime_1.jsx)(CustomDigit, { value: "U" }), (0, jsx_runtime_1.jsx)(CustomDigit, { value: "Y" })] }), (0, jsx_runtime_1.jsxs)("div", { style: grid, children: [(0, jsx_runtime_1.jsx)(CustomDigit, { value: "c" }), (0, jsx_runtime_1.jsx)(CustomDigit, { value: "b" }), (0, jsx_runtime_1.jsx)(CustomDigit, { value: "d" }), (0, jsx_runtime_1.jsx)(CustomDigit, { value: "h" }), (0, jsx_runtime_1.jsx)(CustomDigit, { value: "n" }), (0, jsx_runtime_1.jsx)(CustomDigit, { value: "o" }), (0, jsx_runtime_1.jsx)(CustomDigit, { value: "r" }), (0, jsx_runtime_1.jsx)(CustomDigit, { value: "u" })] })] }));
|
|
51
|
+
};
|
|
52
|
+
exports.UnstyledDigits = {
|
|
53
|
+
args: {
|
|
54
|
+
value: '0',
|
|
55
|
+
},
|
|
56
|
+
render: UnstyledDigitTest,
|
|
57
|
+
};
|
|
@@ -20,6 +20,6 @@ const clsx_1 = __importDefault(require("clsx"));
|
|
|
20
20
|
const utils_1 = require("./utils");
|
|
21
21
|
const AmpmSegments = (_a) => {
|
|
22
22
|
var { className, off, shape = 'default', AM, PM } = _a, rest = __rest(_a, ["className", "off", "shape", "AM", "PM"]);
|
|
23
|
-
return ((0, jsx_runtime_1.jsxs)("div", Object.assign({ className: (0, clsx_1.default)('digit ampm', (0, utils_1.shapeCx)(shape), className) }, rest, { children: [(0, jsx_runtime_1.jsxs)("div", { className: "opacity-wrapper off", children: [(0, jsx_runtime_1.jsx)("i", { className: (0, clsx_1.default)('segment AM', (0, utils_1.onOffCx)(AM, off)) }), (0, jsx_runtime_1.jsx)("i", { className: (0, clsx_1.default)('segment PM', (0, utils_1.onOffCx)(PM, off)) })] }), (0, jsx_runtime_1.jsxs)("div", { className: (0, clsx_1.default)('opacity-wrapper on', off && 'off'), children: [(0, jsx_runtime_1.jsx)("i", { className: (0, clsx_1.default)('segment AM', (0, utils_1.onOffCx)(AM, off)) }), (0, jsx_runtime_1.jsx)("i", { className: (0, clsx_1.default)('segment PM', (0, utils_1.onOffCx)(PM, off)) })] })] })));
|
|
23
|
+
return ((0, jsx_runtime_1.jsxs)("div", Object.assign({ className: (0, clsx_1.default)('digit ampm', (0, utils_1.shapeCx)(shape), className) }, rest, { children: [(0, jsx_runtime_1.jsx)("code", { className: "hidden-value", children: rest['aria-label'] }), (0, jsx_runtime_1.jsxs)("div", { className: "opacity-wrapper off", children: [(0, jsx_runtime_1.jsx)("i", { className: (0, clsx_1.default)('segment AM', (0, utils_1.onOffCx)(AM, off)) }), (0, jsx_runtime_1.jsx)("i", { className: (0, clsx_1.default)('segment PM', (0, utils_1.onOffCx)(PM, off)) })] }), (0, jsx_runtime_1.jsxs)("div", { className: (0, clsx_1.default)('opacity-wrapper on', off && 'off'), children: [(0, jsx_runtime_1.jsx)("i", { className: (0, clsx_1.default)('segment AM', (0, utils_1.onOffCx)(AM, off)) }), (0, jsx_runtime_1.jsx)("i", { className: (0, clsx_1.default)('segment PM', (0, utils_1.onOffCx)(PM, off)) })] })] })));
|
|
24
24
|
};
|
|
25
25
|
exports.AmpmSegments = AmpmSegments;
|
|
@@ -20,6 +20,6 @@ const clsx_1 = __importDefault(require("clsx"));
|
|
|
20
20
|
const utils_1 = require("./utils");
|
|
21
21
|
const ColonSegments = (_a) => {
|
|
22
22
|
var { className, off, shape = 'default', D1, D2 } = _a, rest = __rest(_a, ["className", "off", "shape", "D1", "D2"]);
|
|
23
|
-
return ((0, jsx_runtime_1.jsxs)("div", Object.assign({ className: (0, clsx_1.default)('digit colon', (0, utils_1.shapeCx)(shape), className) }, rest, { children: [(0, jsx_runtime_1.jsxs)("div", { className: "opacity-wrapper off", children: [(0, jsx_runtime_1.jsx)("i", { className: (0, clsx_1.default)('segment D1', (0, utils_1.onOffCx)(D1, off)) }), (0, jsx_runtime_1.jsx)("i", { className: (0, clsx_1.default)('segment D2', (0, utils_1.onOffCx)(D2, off)) })] }), (0, jsx_runtime_1.jsxs)("div", { className: (0, clsx_1.default)('opacity-wrapper on', off && 'off'), children: [(0, jsx_runtime_1.jsx)("i", { className: (0, clsx_1.default)('segment D1', (0, utils_1.onOffCx)(D1, off)) }), (0, jsx_runtime_1.jsx)("i", { className: (0, clsx_1.default)('segment D2', (0, utils_1.onOffCx)(D2, off)) })] })] })));
|
|
23
|
+
return ((0, jsx_runtime_1.jsxs)("div", Object.assign({ className: (0, clsx_1.default)('digit colon', (0, utils_1.shapeCx)(shape), className) }, rest, { children: [(0, jsx_runtime_1.jsx)("code", { className: "hidden-value", children: rest['aria-label'] }), (0, jsx_runtime_1.jsxs)("div", { className: "opacity-wrapper off", children: [(0, jsx_runtime_1.jsx)("i", { className: (0, clsx_1.default)('segment D1', (0, utils_1.onOffCx)(D1, off)) }), (0, jsx_runtime_1.jsx)("i", { className: (0, clsx_1.default)('segment D2', (0, utils_1.onOffCx)(D2, off)) })] }), (0, jsx_runtime_1.jsxs)("div", { className: (0, clsx_1.default)('opacity-wrapper on', off && 'off'), children: [(0, jsx_runtime_1.jsx)("i", { className: (0, clsx_1.default)('segment D1', (0, utils_1.onOffCx)(D1, off)) }), (0, jsx_runtime_1.jsx)("i", { className: (0, clsx_1.default)('segment D2', (0, utils_1.onOffCx)(D2, off)) })] })] })));
|
|
24
24
|
};
|
|
25
25
|
exports.ColonSegments = ColonSegments;
|
|
@@ -20,6 +20,6 @@ const clsx_1 = __importDefault(require("clsx"));
|
|
|
20
20
|
const utils_1 = require("./utils");
|
|
21
21
|
const DigitSegments = (_a) => {
|
|
22
22
|
var { className, off, shape = 'default', A, B, C, D, E, F, G } = _a, rest = __rest(_a, ["className", "off", "shape", "A", "B", "C", "D", "E", "F", "G"]);
|
|
23
|
-
return ((0, jsx_runtime_1.jsxs)("div", Object.assign({ className: (0, clsx_1.default)('digit', (0, utils_1.shapeCx)(shape), className) }, rest, { children: [(0, jsx_runtime_1.jsxs)("div", { className: "opacity-wrapper off", children: [(0, jsx_runtime_1.jsx)("i", { className: (0, clsx_1.default)('segment A horizontal', (0, utils_1.onOffCx)(A, off)) }), (0, jsx_runtime_1.jsx)("i", { className: (0, clsx_1.default)('segment B vertical', (0, utils_1.onOffCx)(B, off)) }), (0, jsx_runtime_1.jsx)("i", { className: (0, clsx_1.default)('segment C vertical', (0, utils_1.onOffCx)(C, off)) }), (0, jsx_runtime_1.jsx)("i", { className: (0, clsx_1.default)('segment D horizontal', (0, utils_1.onOffCx)(D, off)) }), (0, jsx_runtime_1.jsx)("i", { className: (0, clsx_1.default)('segment E vertical', (0, utils_1.onOffCx)(E, off)) }), (0, jsx_runtime_1.jsx)("i", { className: (0, clsx_1.default)('segment F vertical', (0, utils_1.onOffCx)(F, off)) }), (0, jsx_runtime_1.jsx)("i", { className: (0, clsx_1.default)('segment G horizontal', (0, utils_1.onOffCx)(G, off)) })] }), (0, jsx_runtime_1.jsxs)("div", { className: (0, clsx_1.default)('opacity-wrapper on', off && 'off'), children: [(0, jsx_runtime_1.jsx)("i", { className: (0, clsx_1.default)('segment A horizontal', (0, utils_1.onOffCx)(A, off)) }), (0, jsx_runtime_1.jsx)("i", { className: (0, clsx_1.default)('segment B vertical', (0, utils_1.onOffCx)(B, off)) }), (0, jsx_runtime_1.jsx)("i", { className: (0, clsx_1.default)('segment C vertical', (0, utils_1.onOffCx)(C, off)) }), (0, jsx_runtime_1.jsx)("i", { className: (0, clsx_1.default)('segment D horizontal', (0, utils_1.onOffCx)(D, off)) }), (0, jsx_runtime_1.jsx)("i", { className: (0, clsx_1.default)('segment E vertical', (0, utils_1.onOffCx)(E, off)) }), (0, jsx_runtime_1.jsx)("i", { className: (0, clsx_1.default)('segment F vertical', (0, utils_1.onOffCx)(F, off)) }), (0, jsx_runtime_1.jsx)("i", { className: (0, clsx_1.default)('segment G horizontal', (0, utils_1.onOffCx)(G, off)) })] })] })));
|
|
23
|
+
return ((0, jsx_runtime_1.jsxs)("div", Object.assign({ className: (0, clsx_1.default)('digit', (0, utils_1.shapeCx)(shape), className) }, rest, { children: [(0, jsx_runtime_1.jsx)("code", { className: "hidden-value", children: rest['aria-label'] }), (0, jsx_runtime_1.jsxs)("div", { className: "opacity-wrapper off", children: [(0, jsx_runtime_1.jsx)("i", { className: (0, clsx_1.default)('segment A horizontal', (0, utils_1.onOffCx)(A, off)) }), (0, jsx_runtime_1.jsx)("i", { className: (0, clsx_1.default)('segment B vertical', (0, utils_1.onOffCx)(B, off)) }), (0, jsx_runtime_1.jsx)("i", { className: (0, clsx_1.default)('segment C vertical', (0, utils_1.onOffCx)(C, off)) }), (0, jsx_runtime_1.jsx)("i", { className: (0, clsx_1.default)('segment D horizontal', (0, utils_1.onOffCx)(D, off)) }), (0, jsx_runtime_1.jsx)("i", { className: (0, clsx_1.default)('segment E vertical', (0, utils_1.onOffCx)(E, off)) }), (0, jsx_runtime_1.jsx)("i", { className: (0, clsx_1.default)('segment F vertical', (0, utils_1.onOffCx)(F, off)) }), (0, jsx_runtime_1.jsx)("i", { className: (0, clsx_1.default)('segment G horizontal', (0, utils_1.onOffCx)(G, off)) })] }), (0, jsx_runtime_1.jsxs)("div", { className: (0, clsx_1.default)('opacity-wrapper on', off && 'off'), children: [(0, jsx_runtime_1.jsx)("i", { className: (0, clsx_1.default)('segment A horizontal', (0, utils_1.onOffCx)(A, off)) }), (0, jsx_runtime_1.jsx)("i", { className: (0, clsx_1.default)('segment B vertical', (0, utils_1.onOffCx)(B, off)) }), (0, jsx_runtime_1.jsx)("i", { className: (0, clsx_1.default)('segment C vertical', (0, utils_1.onOffCx)(C, off)) }), (0, jsx_runtime_1.jsx)("i", { className: (0, clsx_1.default)('segment D horizontal', (0, utils_1.onOffCx)(D, off)) }), (0, jsx_runtime_1.jsx)("i", { className: (0, clsx_1.default)('segment E vertical', (0, utils_1.onOffCx)(E, off)) }), (0, jsx_runtime_1.jsx)("i", { className: (0, clsx_1.default)('segment F vertical', (0, utils_1.onOffCx)(F, off)) }), (0, jsx_runtime_1.jsx)("i", { className: (0, clsx_1.default)('segment G horizontal', (0, utils_1.onOffCx)(G, off)) })] })] })));
|
|
24
24
|
};
|
|
25
25
|
exports.DigitSegments = DigitSegments;
|
|
@@ -20,6 +20,6 @@ const clsx_1 = __importDefault(require("clsx"));
|
|
|
20
20
|
const utils_1 = require("./utils");
|
|
21
21
|
const DotSegments = (_a) => {
|
|
22
22
|
var { className, off, shape = 'default', DP } = _a, rest = __rest(_a, ["className", "off", "shape", "DP"]);
|
|
23
|
-
return ((0, jsx_runtime_1.jsxs)("div", Object.assign({ className: (0, clsx_1.default)('digit dot', (0, utils_1.shapeCx)(shape), className) }, rest, { children: [(0, jsx_runtime_1.jsx)("div", { className: "opacity-wrapper off", children: (0, jsx_runtime_1.jsx)("i", { className: (0, clsx_1.default)('segment DP', (0, utils_1.onOffCx)(DP, off)) }) }), (0, jsx_runtime_1.jsx)("div", { className: (0, clsx_1.default)('opacity-wrapper on', off && 'off'), children: (0, jsx_runtime_1.jsx)("i", { className: (0, clsx_1.default)('segment DP', (0, utils_1.onOffCx)(DP, off)) }) })] })));
|
|
23
|
+
return ((0, jsx_runtime_1.jsxs)("div", Object.assign({ className: (0, clsx_1.default)('digit dot', (0, utils_1.shapeCx)(shape), className) }, rest, { children: [(0, jsx_runtime_1.jsx)("code", { className: "hidden-value", children: rest['aria-label'] }), (0, jsx_runtime_1.jsx)("div", { className: "opacity-wrapper off", children: (0, jsx_runtime_1.jsx)("i", { className: (0, clsx_1.default)('segment DP', (0, utils_1.onOffCx)(DP, off)) }) }), (0, jsx_runtime_1.jsx)("div", { className: (0, clsx_1.default)('opacity-wrapper on', off && 'off'), children: (0, jsx_runtime_1.jsx)("i", { className: (0, clsx_1.default)('segment DP', (0, utils_1.onOffCx)(DP, off)) }) })] })));
|
|
24
24
|
};
|
|
25
25
|
exports.DotSegments = DotSegments;
|
package/lib/Digit/digit.css
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
const css = {
|
|
4
4
|
src: `src/Digit/digit.css`,
|
|
5
|
-
hash: `
|
|
5
|
+
hash: `3775688054381318`,
|
|
6
6
|
content: `
|
|
7
7
|
/**
|
|
8
8
|
* A
|
|
@@ -57,6 +57,10 @@ const css = {
|
|
|
57
57
|
min-width: var(--thick);
|
|
58
58
|
}
|
|
59
59
|
|
|
60
|
+
.hidden-value {
|
|
61
|
+
display: none;
|
|
62
|
+
}
|
|
63
|
+
|
|
60
64
|
.opacity-wrapper {
|
|
61
65
|
position: absolute;
|
|
62
66
|
width: 100%;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
type Style = {
|
|
2
|
+
id: string;
|
|
3
|
+
content: string;
|
|
4
|
+
};
|
|
5
|
+
type InjectorOptions = {
|
|
6
|
+
scopeID?: string;
|
|
7
|
+
scopeAttributePrefix?: string;
|
|
8
|
+
selector?: string;
|
|
9
|
+
};
|
|
10
|
+
declare const useStyleInjector: (css: string, dependencies?: never[], options?: InjectorOptions) => {
|
|
11
|
+
[x: string]: boolean | undefined;
|
|
12
|
+
};
|
|
13
|
+
export declare class StyleInjector {
|
|
14
|
+
#private;
|
|
15
|
+
private static instance;
|
|
16
|
+
constructor();
|
|
17
|
+
increase(s: Style): void;
|
|
18
|
+
reduce(s: Style): void;
|
|
19
|
+
count(s: Style): number;
|
|
20
|
+
generateID: (s: string) => string;
|
|
21
|
+
}
|
|
22
|
+
export default useStyleInjector;
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
3
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
4
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
5
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
6
|
+
};
|
|
7
|
+
var _StyleInjector_styles;
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.StyleInjector = void 0;
|
|
10
|
+
const react_1 = require("react");
|
|
11
|
+
const defaultInjectorOptions = {
|
|
12
|
+
scopeAttributePrefix: 'data-style-scope-',
|
|
13
|
+
selector: 'head',
|
|
14
|
+
};
|
|
15
|
+
// Runtime style injection
|
|
16
|
+
const useStyleInjector = (css, dependencies = [], options) => {
|
|
17
|
+
const injector = new StyleInjector(); // singleton
|
|
18
|
+
const o = Object.assign(Object.assign({}, defaultInjectorOptions), options);
|
|
19
|
+
const id = (o === null || o === void 0 ? void 0 : o.scopeID) || injector.generateID(css);
|
|
20
|
+
const scopeAttribute = `${o.scopeAttributePrefix}${id}`;
|
|
21
|
+
const style = {
|
|
22
|
+
id: `css_id__${id}`,
|
|
23
|
+
content: o.scopeID ? wrapWithScope(css, scopeAttribute) : css,
|
|
24
|
+
};
|
|
25
|
+
(0, react_1.useInsertionEffect)(() => {
|
|
26
|
+
injector.increase(style);
|
|
27
|
+
return () => injector.reduce(style);
|
|
28
|
+
}, dependencies);
|
|
29
|
+
return {
|
|
30
|
+
[scopeAttribute]: o.scopeID ? true : undefined,
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
// Inject style into head if it
|
|
34
|
+
class StyleInjector {
|
|
35
|
+
constructor() {
|
|
36
|
+
_StyleInjector_styles.set(this, new Map());
|
|
37
|
+
this.generateID = (s) => cyrb53string(s);
|
|
38
|
+
if (!StyleInjector.instance) {
|
|
39
|
+
StyleInjector.instance = this;
|
|
40
|
+
}
|
|
41
|
+
return StyleInjector.instance; // singleton
|
|
42
|
+
}
|
|
43
|
+
increase(s) {
|
|
44
|
+
if (this.count(s) === 0)
|
|
45
|
+
document.head.appendChild(createStyleElement(s));
|
|
46
|
+
if (this.count(s) >= 0)
|
|
47
|
+
__classPrivateFieldGet(this, _StyleInjector_styles, "f").set(s.id, this.count(s) + 1);
|
|
48
|
+
}
|
|
49
|
+
reduce(s) {
|
|
50
|
+
var _a;
|
|
51
|
+
if (this.count(s) > 0)
|
|
52
|
+
__classPrivateFieldGet(this, _StyleInjector_styles, "f").set(s.id, this.count(s) - 1);
|
|
53
|
+
if (this.count(s) === 0)
|
|
54
|
+
(_a = document.head.querySelector(`#${s.id}`)) === null || _a === void 0 ? void 0 : _a.remove();
|
|
55
|
+
}
|
|
56
|
+
count(s) {
|
|
57
|
+
if (__classPrivateFieldGet(this, _StyleInjector_styles, "f").has(s.id))
|
|
58
|
+
return __classPrivateFieldGet(this, _StyleInjector_styles, "f").get(s.id);
|
|
59
|
+
return 0;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
exports.StyleInjector = StyleInjector;
|
|
63
|
+
_StyleInjector_styles = new WeakMap();
|
|
64
|
+
const createStyleElement = (style) => {
|
|
65
|
+
const el = document.createElement('style');
|
|
66
|
+
el.innerHTML = style.content;
|
|
67
|
+
if (style.id !== '')
|
|
68
|
+
el.id = style.id;
|
|
69
|
+
return el;
|
|
70
|
+
};
|
|
71
|
+
const wrapWithScope = (css, scopeAttribute) => {
|
|
72
|
+
const scoped = // unused bc @scope at-rule does not work in Firefox
|
|
73
|
+
`@scope ([${scopeAttribute}]) {` +
|
|
74
|
+
`:scope { display: contents; }` +
|
|
75
|
+
`${css}` +
|
|
76
|
+
`}`;
|
|
77
|
+
const isolated = `[${scopeAttribute}] { display: contents; }` +
|
|
78
|
+
`[${scopeAttribute}] {` +
|
|
79
|
+
`${css}` +
|
|
80
|
+
`}`;
|
|
81
|
+
return isolated;
|
|
82
|
+
};
|
|
83
|
+
// https://stackoverflow.com/questions/7616461/generate-a-hash-from-string-in-javascript
|
|
84
|
+
const cyrb53string = (str, seed = 0) => {
|
|
85
|
+
let h1 = 0xdeadbeef ^ seed, h2 = 0x41c6ce57 ^ seed;
|
|
86
|
+
for (let i = 0, ch; i < str.length; i++) {
|
|
87
|
+
ch = str.charCodeAt(i);
|
|
88
|
+
h1 = Math.imul(h1 ^ ch, 2654435761);
|
|
89
|
+
h2 = Math.imul(h2 ^ ch, 1597334677);
|
|
90
|
+
}
|
|
91
|
+
h1 = Math.imul(h1 ^ (h1 >>> 16), 2246822507);
|
|
92
|
+
h1 ^= Math.imul(h2 ^ (h2 >>> 13), 3266489909);
|
|
93
|
+
h2 = Math.imul(h2 ^ (h2 >>> 16), 2246822507);
|
|
94
|
+
h2 ^= Math.imul(h1 ^ (h1 >>> 13), 3266489909);
|
|
95
|
+
const num = 4294967296 * (2097151 & h2) + (h1 >>> 0);
|
|
96
|
+
return num.toString(36);
|
|
97
|
+
};
|
|
98
|
+
exports.default = useStyleInjector;
|
package/package.json
CHANGED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
type Style = {
|
|
2
|
-
id: string;
|
|
3
|
-
content: string;
|
|
4
|
-
};
|
|
5
|
-
declare const useHeadStyleInjection: (css: string, cssHash: string, dependencies?: never[], scoped?: boolean) => {
|
|
6
|
-
[x: string]: boolean | undefined;
|
|
7
|
-
};
|
|
8
|
-
export declare class StyleInjector {
|
|
9
|
-
#private;
|
|
10
|
-
private static instance;
|
|
11
|
-
constructor();
|
|
12
|
-
add(s: Style): void;
|
|
13
|
-
remove(s: Style): void;
|
|
14
|
-
has(s: Style): boolean;
|
|
15
|
-
}
|
|
16
|
-
export default useHeadStyleInjection;
|
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
3
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
4
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
5
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
6
|
-
};
|
|
7
|
-
var _StyleInjector_state;
|
|
8
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.StyleInjector = void 0;
|
|
10
|
-
const react_1 = require("react");
|
|
11
|
-
const scopeAttributePrefix = 'data-style-scope-';
|
|
12
|
-
// Runtime style injection
|
|
13
|
-
const useHeadStyleInjection = (css, cssHash, dependencies = [], scoped = true // isolate css behind @scope
|
|
14
|
-
) => {
|
|
15
|
-
const injector = new StyleInjector(); // singleton!
|
|
16
|
-
const scopeAttribute = `${scopeAttributePrefix}-${cssHash}`;
|
|
17
|
-
const style = {
|
|
18
|
-
id: `css_id__${cssHash}`,
|
|
19
|
-
content: scoped ? wrapWithScope(css, scopeAttribute) : css,
|
|
20
|
-
};
|
|
21
|
-
(0, react_1.useInsertionEffect)(() => {
|
|
22
|
-
injector.add(style);
|
|
23
|
-
return () => injector.remove(style);
|
|
24
|
-
}, dependencies);
|
|
25
|
-
return {
|
|
26
|
-
[scopeAttribute]: scoped ? true : undefined,
|
|
27
|
-
};
|
|
28
|
-
};
|
|
29
|
-
class StyleInjector {
|
|
30
|
-
constructor() {
|
|
31
|
-
_StyleInjector_state.set(this, new Map());
|
|
32
|
-
if (!StyleInjector.instance) {
|
|
33
|
-
StyleInjector.instance = this;
|
|
34
|
-
}
|
|
35
|
-
return StyleInjector.instance;
|
|
36
|
-
}
|
|
37
|
-
add(s) {
|
|
38
|
-
if (this.has(s)) {
|
|
39
|
-
const count = __classPrivateFieldGet(this, _StyleInjector_state, "f").get(s.id) + 1;
|
|
40
|
-
__classPrivateFieldGet(this, _StyleInjector_state, "f").set(s.id, count);
|
|
41
|
-
}
|
|
42
|
-
else {
|
|
43
|
-
__classPrivateFieldGet(this, _StyleInjector_state, "f").set(s.id, 1);
|
|
44
|
-
}
|
|
45
|
-
if (__classPrivateFieldGet(this, _StyleInjector_state, "f").get(s.id) === 1) {
|
|
46
|
-
document.head.appendChild(createStyleElement(s));
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
remove(s) {
|
|
50
|
-
var _a;
|
|
51
|
-
if (this.has(s)) {
|
|
52
|
-
const count = __classPrivateFieldGet(this, _StyleInjector_state, "f").get(s.id) - 1;
|
|
53
|
-
__classPrivateFieldGet(this, _StyleInjector_state, "f").set(s.id, count);
|
|
54
|
-
}
|
|
55
|
-
else {
|
|
56
|
-
console.warn(`(at useStyleInjection.ts) unable to remove style: ${s.id}`);
|
|
57
|
-
}
|
|
58
|
-
if (__classPrivateFieldGet(this, _StyleInjector_state, "f").get(s.id) === 0) {
|
|
59
|
-
(_a = document.head.querySelector(`#${s.id}`)) === null || _a === void 0 ? void 0 : _a.remove();
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
has(s) {
|
|
63
|
-
return __classPrivateFieldGet(this, _StyleInjector_state, "f").has(s.id);
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
exports.StyleInjector = StyleInjector;
|
|
67
|
-
_StyleInjector_state = new WeakMap();
|
|
68
|
-
const createStyleElement = (style) => {
|
|
69
|
-
const el = document.createElement('style');
|
|
70
|
-
el.innerHTML = style.content;
|
|
71
|
-
if (style.id !== '')
|
|
72
|
-
el.id = style.id;
|
|
73
|
-
return el;
|
|
74
|
-
};
|
|
75
|
-
const wrapWithScope = (css, scopeAttribute) => {
|
|
76
|
-
// unused bc @scope at-rule does not work in Firefox
|
|
77
|
-
const scoped = `@scope ([${scopeAttribute}]) {` +
|
|
78
|
-
`:scope { display: contents; }` +
|
|
79
|
-
`${css}` +
|
|
80
|
-
`}`;
|
|
81
|
-
const isolated = `[${scopeAttribute}] { display: contents; }` +
|
|
82
|
-
`[${scopeAttribute}] {` +
|
|
83
|
-
`${css}` +
|
|
84
|
-
`}`;
|
|
85
|
-
return isolated;
|
|
86
|
-
};
|
|
87
|
-
exports.default = useHeadStyleInjection;
|