@kitsuyui/react-binary 0.1.6 → 0.2.0

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.
Files changed (41) hide show
  1. package/dist/Binary.cjs +66 -0
  2. package/dist/Binary.cjs.map +1 -0
  3. package/dist/{Binary.d.mts → Binary.d.cts} +1 -1
  4. package/dist/Binary.d.ts +1 -1
  5. package/dist/Binary.js +5 -64
  6. package/dist/Binary.js.map +1 -1
  7. package/dist/Detailed.cjs +132 -0
  8. package/dist/Detailed.cjs.map +1 -0
  9. package/dist/{Detailed.d.mts → Detailed.d.cts} +4 -4
  10. package/dist/Detailed.d.ts +3 -3
  11. package/dist/Detailed.js +7 -129
  12. package/dist/Detailed.js.map +1 -1
  13. package/dist/Simple.cjs +83 -0
  14. package/dist/Simple.cjs.map +1 -0
  15. package/dist/{Simple.d.mts → Simple.d.cts} +4 -4
  16. package/dist/Simple.d.ts +3 -3
  17. package/dist/Simple.js +7 -78
  18. package/dist/Simple.js.map +1 -1
  19. package/dist/{chunk-SSBW6RTY.mjs → chunk-76L6HIHJ.js} +1 -1
  20. package/dist/chunk-76L6HIHJ.js.map +1 -0
  21. package/dist/{chunk-HPBKCHK2.mjs → chunk-EIJS7GKA.js} +5 -3
  22. package/dist/chunk-EIJS7GKA.js.map +1 -0
  23. package/dist/{chunk-WHSEFUQT.mjs → chunk-KC5B3ZDB.js} +2 -2
  24. package/dist/chunk-KC5B3ZDB.js.map +1 -0
  25. package/dist/index.cjs +151 -0
  26. package/dist/index.cjs.map +1 -0
  27. package/dist/{index.d.mts → index.d.cts} +3 -3
  28. package/dist/index.js +13 -143
  29. package/dist/index.js.map +1 -1
  30. package/package.json +23 -11
  31. package/dist/Binary.mjs +0 -7
  32. package/dist/Binary.mjs.map +0 -1
  33. package/dist/Detailed.mjs +0 -10
  34. package/dist/Detailed.mjs.map +0 -1
  35. package/dist/Simple.mjs +0 -10
  36. package/dist/Simple.mjs.map +0 -1
  37. package/dist/chunk-HPBKCHK2.mjs.map +0 -1
  38. package/dist/chunk-SSBW6RTY.mjs.map +0 -1
  39. package/dist/chunk-WHSEFUQT.mjs.map +0 -1
  40. package/dist/index.mjs +0 -19
  41. package/dist/index.mjs.map +0 -1
package/dist/Simple.js CHANGED
@@ -1,81 +1,10 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
-
30
- // src/Simple.tsx
31
- var Simple_exports = {};
32
- __export(Simple_exports, {
33
- Simple8BitString: () => Simple8BitString,
34
- SimpleBit: () => SimpleBit
35
- });
36
- module.exports = __toCommonJS(Simple_exports);
37
-
38
- // src/Binary.tsx
39
- var import_react = __toESM(require("react"));
40
- var import_jsx_runtime = require("react/jsx-runtime");
41
- var Bits = (props) => {
42
- const { value, bitElement } = props;
43
- const bits = (value | 0).toString(2).split("");
44
- const bitLength = bits.length;
45
- const length = props.length ?? bitLength;
46
- const overflowLength = Math.max(0, bitLength - length);
47
- const zeroPaddingLength = Math.max(0, length - bitLength);
48
- const representLength = Math.max(length, bitLength);
49
- const elements = Array.from(Array(representLength)).map((_, index) => {
50
- const stand = bits[bitLength - representLength + index] === "1";
51
- const bigEndianBitOrder = index;
52
- const overflow = bigEndianBitOrder < overflowLength;
53
- const zeroPadding = bigEndianBitOrder < zeroPaddingLength;
54
- return import_react.default.createElement(bitElement, {
55
- key: index,
56
- stand,
57
- overflow,
58
- zeroPadding,
59
- littleEndianBitOrder: representLength - index - 1,
60
- bigEndianBitOrder
61
- });
62
- });
63
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, { children: elements });
64
- };
65
-
66
- // src/Simple.tsx
67
- var import_jsx_runtime2 = require("react/jsx-runtime");
68
- var SimpleBit = (props) => {
69
- const { stand, overflow } = props;
70
- const text = overflow ?? false ? "" : stand ? "1" : "0";
71
- return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_jsx_runtime2.Fragment, { children: text });
72
- };
73
- var Simple8BitString = (props) => {
74
- return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Bits, { value: props.value, length: 8, bitElement: SimpleBit });
75
- };
76
- // Annotate the CommonJS export names for ESM import in node:
77
- 0 && (module.exports = {
1
+ import {
2
+ Simple8BitString,
3
+ SimpleBit
4
+ } from "./chunk-EIJS7GKA.js";
5
+ import "./chunk-76L6HIHJ.js";
6
+ export {
78
7
  Simple8BitString,
79
8
  SimpleBit
80
- });
9
+ };
81
10
  //# sourceMappingURL=Simple.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/Simple.tsx","../src/Binary.tsx"],"sourcesContent":["import React from 'react'\nimport { Bits, EnhancedBitProps } from './Binary'\n\n/**\n * SimpleBit is a simple component that displays a bit.\n * @param props\n * @returns A component that displays a bit.\n */\nexport const SimpleBit = (props: EnhancedBitProps): JSX.Element => {\n const { stand, overflow } = props\n const text = overflow ?? false ? '' : stand ? '1' : '0'\n return <>{text}</>\n}\n\nexport const Simple8BitString = (props: { value: number }): JSX.Element => {\n return <Bits value={props.value} length={8} bitElement={SimpleBit} />\n}\n","import React from 'react'\n\n/**\n * BitProps is a type that represents the properties of a bit.\n */\nexport type BitProps = {\n stand: boolean\n}\n\n/**\n * EnhancedBitProps is a type that adds the following properties to BitProps.\n * - overflow: If true, this means that bit is out of range.\n * - zeroPadding: If true, this means that bit is padded with zero.\n */\nexport type EnhancedBitProps = BitProps & {\n overflow?: boolean\n zeroPadding?: boolean\n littleEndianBitOrder: number\n bigEndianBitOrder: number\n}\n\nexport type BitElement = React.FC<EnhancedBitProps>\n\n/**\n * Bit is a component that displays a bit.\n * This component supports the behavior of zero padding and overflow.\n * @param props\n * @returns A component that displays a bit.\n */\nexport const Bits = (props: {\n value: number\n bitElement: BitElement\n length?: number | undefined\n}): JSX.Element => {\n const { value, bitElement } = props\n const bits = (value | 0).toString(2).split('')\n const bitLength = bits.length\n const length = props.length ?? bitLength\n const overflowLength = Math.max(0, bitLength - length)\n const zeroPaddingLength = Math.max(0, length - bitLength)\n const representLength = Math.max(length, bitLength)\n const elements = Array.from(Array(representLength)).map((_, index) => {\n const stand = bits[bitLength - representLength + index] === '1'\n const bigEndianBitOrder = index\n const overflow = bigEndianBitOrder < overflowLength\n const zeroPadding = bigEndianBitOrder < zeroPaddingLength\n return React.createElement(bitElement, {\n key: index,\n stand,\n overflow,\n zeroPadding,\n littleEndianBitOrder: representLength - index - 1,\n bigEndianBitOrder,\n })\n })\n return <>{elements}</>\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,mBAAkB;AAuDT;AA1BF,IAAM,OAAO,CAAC,UAIF;AACjB,QAAM,EAAE,OAAO,WAAW,IAAI;AAC9B,QAAM,QAAQ,QAAQ,GAAG,SAAS,CAAC,EAAE,MAAM,EAAE;AAC7C,QAAM,YAAY,KAAK;AACvB,QAAM,SAAS,MAAM,UAAU;AAC/B,QAAM,iBAAiB,KAAK,IAAI,GAAG,YAAY,MAAM;AACrD,QAAM,oBAAoB,KAAK,IAAI,GAAG,SAAS,SAAS;AACxD,QAAM,kBAAkB,KAAK,IAAI,QAAQ,SAAS;AAClD,QAAM,WAAW,MAAM,KAAK,MAAM,eAAe,CAAC,EAAE,IAAI,CAAC,GAAG,UAAU;AACpE,UAAM,QAAQ,KAAK,YAAY,kBAAkB,KAAK,MAAM;AAC5D,UAAM,oBAAoB;AAC1B,UAAM,WAAW,oBAAoB;AACrC,UAAM,cAAc,oBAAoB;AACxC,WAAO,aAAAA,QAAM,cAAc,YAAY;AAAA,MACrC,KAAK;AAAA,MACL;AAAA,MACA;AAAA,MACA;AAAA,MACA,sBAAsB,kBAAkB,QAAQ;AAAA,MAChD;AAAA,IACF,CAAC;AAAA,EACH,CAAC;AACD,SAAO,2EAAG,oBAAS;AACrB;;;AD7CS,IAAAC,sBAAA;AAHF,IAAM,YAAY,CAAC,UAAyC;AACjE,QAAM,EAAE,OAAO,SAAS,IAAI;AAC5B,QAAM,OAAO,YAAY,QAAQ,KAAK,QAAQ,MAAM;AACpD,SAAO,6EAAG,gBAAK;AACjB;AAEO,IAAM,mBAAmB,CAAC,UAA0C;AACzE,SAAO,6CAAC,QAAK,OAAO,MAAM,OAAO,QAAQ,GAAG,YAAY,WAAW;AACrE;","names":["React","import_jsx_runtime"]}
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -29,4 +29,4 @@ var Bits = (props) => {
29
29
  export {
30
30
  Bits
31
31
  };
32
- //# sourceMappingURL=chunk-SSBW6RTY.mjs.map
32
+ //# sourceMappingURL=chunk-76L6HIHJ.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/Binary.tsx"],"sourcesContent":["import React from 'react'\n\n/**\n * BitProps is a type that represents the properties of a bit.\n */\nexport type BitProps = {\n stand: boolean\n}\n\n/**\n * EnhancedBitProps is a type that adds the following properties to BitProps.\n * - overflow: If true, this means that bit is out of range.\n * - zeroPadding: If true, this means that bit is padded with zero.\n */\nexport type EnhancedBitProps = BitProps & {\n overflow?: boolean\n zeroPadding?: boolean\n littleEndianBitOrder: number\n bigEndianBitOrder: number\n}\n\nexport type BitElement = React.FC<EnhancedBitProps>\n\n/**\n * Bit is a component that displays a bit.\n * This component supports the behavior of zero padding and overflow.\n * @param props\n * @returns A component that displays a bit.\n */\nexport const Bits = (props: {\n value: number\n bitElement: BitElement\n length?: number | undefined\n}): React.JSX.Element => {\n const { value, bitElement } = props\n const bits = (value | 0).toString(2).split('')\n const bitLength = bits.length\n const length = props.length ?? bitLength\n const overflowLength = Math.max(0, bitLength - length)\n const zeroPaddingLength = Math.max(0, length - bitLength)\n const representLength = Math.max(length, bitLength)\n const elements = Array.from(Array(representLength)).map((_, index) => {\n const stand = bits[bitLength - representLength + index] === '1'\n const bigEndianBitOrder = index\n const overflow = bigEndianBitOrder < overflowLength\n const zeroPadding = bigEndianBitOrder < zeroPaddingLength\n return React.createElement(bitElement, {\n key: index,\n stand,\n overflow,\n zeroPadding,\n littleEndianBitOrder: representLength - index - 1,\n bigEndianBitOrder,\n })\n })\n return <>{elements}</>\n}\n"],"mappings":";AAAA,OAAO,WAAW;AAuDT;AA1BF,IAAM,OAAO,CAAC,UAII;AACvB,QAAM,EAAE,OAAO,WAAW,IAAI;AAC9B,QAAM,QAAQ,QAAQ,GAAG,SAAS,CAAC,EAAE,MAAM,EAAE;AAC7C,QAAM,YAAY,KAAK;AACvB,QAAM,SAAS,MAAM,UAAU;AAC/B,QAAM,iBAAiB,KAAK,IAAI,GAAG,YAAY,MAAM;AACrD,QAAM,oBAAoB,KAAK,IAAI,GAAG,SAAS,SAAS;AACxD,QAAM,kBAAkB,KAAK,IAAI,QAAQ,SAAS;AAClD,QAAM,WAAW,MAAM,KAAK,MAAM,eAAe,CAAC,EAAE,IAAI,CAAC,GAAG,UAAU;AACpE,UAAM,QAAQ,KAAK,YAAY,kBAAkB,KAAK,MAAM;AAC5D,UAAM,oBAAoB;AAC1B,UAAM,WAAW,oBAAoB;AACrC,UAAM,cAAc,oBAAoB;AACxC,WAAO,MAAM,cAAc,YAAY;AAAA,MACrC,KAAK;AAAA,MACL;AAAA,MACA;AAAA,MACA;AAAA,MACA,sBAAsB,kBAAkB,QAAQ;AAAA,MAChD;AAAA,IACF,CAAC;AAAA,EACH,CAAC;AACD,SAAO,gCAAG,oBAAS;AACrB;","names":[]}
@@ -1,12 +1,14 @@
1
1
  import {
2
2
  Bits
3
- } from "./chunk-SSBW6RTY.mjs";
3
+ } from "./chunk-76L6HIHJ.js";
4
4
 
5
5
  // src/Simple.tsx
6
6
  import { Fragment, jsx } from "react/jsx-runtime";
7
7
  var SimpleBit = (props) => {
8
8
  const { stand, overflow } = props;
9
- const text = overflow ?? false ? "" : stand ? "1" : "0";
9
+ const baseText = stand ? "1" : "0";
10
+ const isOverflowVisible = overflow ?? false;
11
+ const text = isOverflowVisible ? "" : baseText;
10
12
  return /* @__PURE__ */ jsx(Fragment, { children: text });
11
13
  };
12
14
  var Simple8BitString = (props) => {
@@ -17,4 +19,4 @@ export {
17
19
  SimpleBit,
18
20
  Simple8BitString
19
21
  };
20
- //# sourceMappingURL=chunk-HPBKCHK2.mjs.map
22
+ //# sourceMappingURL=chunk-EIJS7GKA.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/Simple.tsx"],"sourcesContent":["import type React from 'react'\nimport { Bits, type EnhancedBitProps } from './Binary'\n\n/**\n * SimpleBit is a simple component that displays a bit.\n * @param props\n * @returns A component that displays a bit.\n */\nexport const SimpleBit = (props: EnhancedBitProps): React.JSX.Element => {\n const { stand, overflow } = props\n const baseText = stand ? '1' : '0'\n const isOverflowVisible = overflow ?? false\n const text = isOverflowVisible ? '' : baseText\n return <>{text}</>\n}\n\nexport const Simple8BitString = (props: { value: number }): React.JSX.Element => {\n return <Bits value={props.value} length={8} bitElement={SimpleBit} />\n}\n"],"mappings":";;;;;AAaS;AALF,IAAM,YAAY,CAAC,UAA+C;AACvE,QAAM,EAAE,OAAO,SAAS,IAAI;AAC5B,QAAM,WAAW,QAAQ,MAAM;AAC/B,QAAM,oBAAoB,YAAY;AACtC,QAAM,OAAO,oBAAoB,KAAK;AACtC,SAAO,gCAAG,gBAAK;AACjB;AAEO,IAAM,mBAAmB,CAAC,UAAgD;AAC/E,SAAO,oBAAC,QAAK,OAAO,MAAM,OAAO,QAAQ,GAAG,YAAY,WAAW;AACrE;","names":[]}
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  Bits
3
- } from "./chunk-SSBW6RTY.mjs";
3
+ } from "./chunk-76L6HIHJ.js";
4
4
 
5
5
  // src/Detailed.tsx
6
6
  import { jsx, jsxs } from "react/jsx-runtime";
@@ -68,4 +68,4 @@ export {
68
68
  DetailedBit,
69
69
  DetailedBitString
70
70
  };
71
- //# sourceMappingURL=chunk-WHSEFUQT.mjs.map
71
+ //# sourceMappingURL=chunk-KC5B3ZDB.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/Detailed.tsx"],"sourcesContent":["import type React from 'react'\nimport { Bits, type EnhancedBitProps } from './Binary'\n\nexport type DetailedBitProps = EnhancedBitProps & {\n displayLittleEndianBitOrder?: boolean | undefined\n displayBigEndianBitOrder?: boolean | undefined\n}\n\nexport const DetailedBit = (props: DetailedBitProps): React.JSX.Element => {\n const { stand, overflow, zeroPadding } = props\n const displayLittleEndianBitOrder = props.displayLittleEndianBitOrder ?? false\n const displayBigEndianBitOrder = props.displayBigEndianBitOrder ?? false\n const text = stand ? '1' : '0'\n const border = overflow\n ? '1px dotted red'\n : zeroPadding\n ? '1px dotted gray'\n : '1px solid #cccccc'\n const margin = '0.5px'\n const color = stand ? '#999999' : '#cccccc'\n const backgroundColor = stand ? '#000000' : '#ffffff'\n const fontFamily = 'monospace'\n return (\n <div style={{ display: 'inline-block', fontFamily, margin }}>\n <div\n style={{\n color,\n backgroundColor,\n border,\n }}\n >\n {text}\n </div>\n {displayLittleEndianBitOrder && (\n <IndexLabel index={props.littleEndianBitOrder} />\n )}\n {displayBigEndianBitOrder && (\n <IndexLabel index={props.bigEndianBitOrder} />\n )}\n </div>\n )\n}\n\nconst IndexLabel = (props: { index: number }): React.JSX.Element => {\n return (\n <div\n style={{\n userSelect: 'none',\n fontSize: '0.5em',\n textAlign: 'center',\n lineHeight: '1em',\n }}\n >\n {props.index}\n </div>\n )\n}\n\nexport const DetailedBitString = (props: {\n value: number\n length?: number\n showLittleEndianBitOrder?: boolean | undefined\n showBigEndianBitOrder?: boolean | undefined\n}): React.JSX.Element => {\n const showLittleEndianBitOrder = props.showLittleEndianBitOrder ?? false\n const showBigEndianBitOrder = props.showBigEndianBitOrder ?? false\n return (\n <Bits\n value={props.value}\n length={props.length}\n bitElement={(props) => (\n <DetailedBit\n {...props}\n displayLittleEndianBitOrder={showLittleEndianBitOrder}\n displayBigEndianBitOrder={showBigEndianBitOrder}\n />\n )}\n />\n )\n}\n"],"mappings":";;;;;AAuBI,SACE,KADF;AAfG,IAAM,cAAc,CAAC,UAA+C;AACzE,QAAM,EAAE,OAAO,UAAU,YAAY,IAAI;AACzC,QAAM,8BAA8B,MAAM,+BAA+B;AACzE,QAAM,2BAA2B,MAAM,4BAA4B;AACnE,QAAM,OAAO,QAAQ,MAAM;AAC3B,QAAM,SAAS,WACX,mBACA,cACE,oBACA;AACN,QAAM,SAAS;AACf,QAAM,QAAQ,QAAQ,YAAY;AAClC,QAAM,kBAAkB,QAAQ,YAAY;AAC5C,QAAM,aAAa;AACnB,SACE,qBAAC,SAAI,OAAO,EAAE,SAAS,gBAAgB,YAAY,OAAO,GACxD;AAAA;AAAA,MAAC;AAAA;AAAA,QACC,OAAO;AAAA,UACL;AAAA,UACA;AAAA,UACA;AAAA,QACF;AAAA,QAEC;AAAA;AAAA,IACH;AAAA,IACC,+BACC,oBAAC,cAAW,OAAO,MAAM,sBAAsB;AAAA,IAEhD,4BACC,oBAAC,cAAW,OAAO,MAAM,mBAAmB;AAAA,KAEhD;AAEJ;AAEA,IAAM,aAAa,CAAC,UAAgD;AAClE,SACE;AAAA,IAAC;AAAA;AAAA,MACC,OAAO;AAAA,QACL,YAAY;AAAA,QACZ,UAAU;AAAA,QACV,WAAW;AAAA,QACX,YAAY;AAAA,MACd;AAAA,MAEC,gBAAM;AAAA;AAAA,EACT;AAEJ;AAEO,IAAM,oBAAoB,CAAC,UAKT;AACvB,QAAM,2BAA2B,MAAM,4BAA4B;AACnE,QAAM,wBAAwB,MAAM,yBAAyB;AAC7D,SACE;AAAA,IAAC;AAAA;AAAA,MACC,OAAO,MAAM;AAAA,MACb,QAAQ,MAAM;AAAA,MACd,YAAY,CAACA,WACX;AAAA,QAAC;AAAA;AAAA,UACE,GAAGA;AAAA,UACJ,6BAA6B;AAAA,UAC7B,0BAA0B;AAAA;AAAA,MAC5B;AAAA;AAAA,EAEJ;AAEJ;","names":["props"]}
package/dist/index.cjs ADDED
@@ -0,0 +1,151 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/index.ts
31
+ var index_exports = {};
32
+ __export(index_exports, {
33
+ Bits: () => Bits,
34
+ DetailedBit: () => DetailedBit,
35
+ DetailedBitString: () => DetailedBitString,
36
+ Simple8BitString: () => Simple8BitString,
37
+ SimpleBit: () => SimpleBit
38
+ });
39
+ module.exports = __toCommonJS(index_exports);
40
+
41
+ // src/Binary.tsx
42
+ var import_react = __toESM(require("react"), 1);
43
+ var import_jsx_runtime = require("react/jsx-runtime");
44
+ var Bits = (props) => {
45
+ const { value, bitElement } = props;
46
+ const bits = (value | 0).toString(2).split("");
47
+ const bitLength = bits.length;
48
+ const length = props.length ?? bitLength;
49
+ const overflowLength = Math.max(0, bitLength - length);
50
+ const zeroPaddingLength = Math.max(0, length - bitLength);
51
+ const representLength = Math.max(length, bitLength);
52
+ const elements = Array.from(Array(representLength)).map((_, index) => {
53
+ const stand = bits[bitLength - representLength + index] === "1";
54
+ const bigEndianBitOrder = index;
55
+ const overflow = bigEndianBitOrder < overflowLength;
56
+ const zeroPadding = bigEndianBitOrder < zeroPaddingLength;
57
+ return import_react.default.createElement(bitElement, {
58
+ key: index,
59
+ stand,
60
+ overflow,
61
+ zeroPadding,
62
+ littleEndianBitOrder: representLength - index - 1,
63
+ bigEndianBitOrder
64
+ });
65
+ });
66
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, { children: elements });
67
+ };
68
+
69
+ // src/Simple.tsx
70
+ var import_jsx_runtime2 = require("react/jsx-runtime");
71
+ var SimpleBit = (props) => {
72
+ const { stand, overflow } = props;
73
+ const baseText = stand ? "1" : "0";
74
+ const isOverflowVisible = overflow ?? false;
75
+ const text = isOverflowVisible ? "" : baseText;
76
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_jsx_runtime2.Fragment, { children: text });
77
+ };
78
+ var Simple8BitString = (props) => {
79
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Bits, { value: props.value, length: 8, bitElement: SimpleBit });
80
+ };
81
+
82
+ // src/Detailed.tsx
83
+ var import_jsx_runtime3 = require("react/jsx-runtime");
84
+ var DetailedBit = (props) => {
85
+ const { stand, overflow, zeroPadding } = props;
86
+ const displayLittleEndianBitOrder = props.displayLittleEndianBitOrder ?? false;
87
+ const displayBigEndianBitOrder = props.displayBigEndianBitOrder ?? false;
88
+ const text = stand ? "1" : "0";
89
+ const border = overflow ? "1px dotted red" : zeroPadding ? "1px dotted gray" : "1px solid #cccccc";
90
+ const margin = "0.5px";
91
+ const color = stand ? "#999999" : "#cccccc";
92
+ const backgroundColor = stand ? "#000000" : "#ffffff";
93
+ const fontFamily = "monospace";
94
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { style: { display: "inline-block", fontFamily, margin }, children: [
95
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
96
+ "div",
97
+ {
98
+ style: {
99
+ color,
100
+ backgroundColor,
101
+ border
102
+ },
103
+ children: text
104
+ }
105
+ ),
106
+ displayLittleEndianBitOrder && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(IndexLabel, { index: props.littleEndianBitOrder }),
107
+ displayBigEndianBitOrder && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(IndexLabel, { index: props.bigEndianBitOrder })
108
+ ] });
109
+ };
110
+ var IndexLabel = (props) => {
111
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
112
+ "div",
113
+ {
114
+ style: {
115
+ userSelect: "none",
116
+ fontSize: "0.5em",
117
+ textAlign: "center",
118
+ lineHeight: "1em"
119
+ },
120
+ children: props.index
121
+ }
122
+ );
123
+ };
124
+ var DetailedBitString = (props) => {
125
+ const showLittleEndianBitOrder = props.showLittleEndianBitOrder ?? false;
126
+ const showBigEndianBitOrder = props.showBigEndianBitOrder ?? false;
127
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
128
+ Bits,
129
+ {
130
+ value: props.value,
131
+ length: props.length,
132
+ bitElement: (props2) => /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
133
+ DetailedBit,
134
+ {
135
+ ...props2,
136
+ displayLittleEndianBitOrder: showLittleEndianBitOrder,
137
+ displayBigEndianBitOrder: showBigEndianBitOrder
138
+ }
139
+ )
140
+ }
141
+ );
142
+ };
143
+ // Annotate the CommonJS export names for ESM import in node:
144
+ 0 && (module.exports = {
145
+ Bits,
146
+ DetailedBit,
147
+ DetailedBitString,
148
+ Simple8BitString,
149
+ SimpleBit
150
+ });
151
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts","../src/Binary.tsx","../src/Simple.tsx","../src/Detailed.tsx"],"sourcesContent":["export * from './Binary'\nexport * from './Simple'\nexport * from './Detailed'\n","import React from 'react'\n\n/**\n * BitProps is a type that represents the properties of a bit.\n */\nexport type BitProps = {\n stand: boolean\n}\n\n/**\n * EnhancedBitProps is a type that adds the following properties to BitProps.\n * - overflow: If true, this means that bit is out of range.\n * - zeroPadding: If true, this means that bit is padded with zero.\n */\nexport type EnhancedBitProps = BitProps & {\n overflow?: boolean\n zeroPadding?: boolean\n littleEndianBitOrder: number\n bigEndianBitOrder: number\n}\n\nexport type BitElement = React.FC<EnhancedBitProps>\n\n/**\n * Bit is a component that displays a bit.\n * This component supports the behavior of zero padding and overflow.\n * @param props\n * @returns A component that displays a bit.\n */\nexport const Bits = (props: {\n value: number\n bitElement: BitElement\n length?: number | undefined\n}): React.JSX.Element => {\n const { value, bitElement } = props\n const bits = (value | 0).toString(2).split('')\n const bitLength = bits.length\n const length = props.length ?? bitLength\n const overflowLength = Math.max(0, bitLength - length)\n const zeroPaddingLength = Math.max(0, length - bitLength)\n const representLength = Math.max(length, bitLength)\n const elements = Array.from(Array(representLength)).map((_, index) => {\n const stand = bits[bitLength - representLength + index] === '1'\n const bigEndianBitOrder = index\n const overflow = bigEndianBitOrder < overflowLength\n const zeroPadding = bigEndianBitOrder < zeroPaddingLength\n return React.createElement(bitElement, {\n key: index,\n stand,\n overflow,\n zeroPadding,\n littleEndianBitOrder: representLength - index - 1,\n bigEndianBitOrder,\n })\n })\n return <>{elements}</>\n}\n","import type React from 'react'\nimport { Bits, type EnhancedBitProps } from './Binary'\n\n/**\n * SimpleBit is a simple component that displays a bit.\n * @param props\n * @returns A component that displays a bit.\n */\nexport const SimpleBit = (props: EnhancedBitProps): React.JSX.Element => {\n const { stand, overflow } = props\n const baseText = stand ? '1' : '0'\n const isOverflowVisible = overflow ?? false\n const text = isOverflowVisible ? '' : baseText\n return <>{text}</>\n}\n\nexport const Simple8BitString = (props: { value: number }): React.JSX.Element => {\n return <Bits value={props.value} length={8} bitElement={SimpleBit} />\n}\n","import type React from 'react'\nimport { Bits, type EnhancedBitProps } from './Binary'\n\nexport type DetailedBitProps = EnhancedBitProps & {\n displayLittleEndianBitOrder?: boolean | undefined\n displayBigEndianBitOrder?: boolean | undefined\n}\n\nexport const DetailedBit = (props: DetailedBitProps): React.JSX.Element => {\n const { stand, overflow, zeroPadding } = props\n const displayLittleEndianBitOrder = props.displayLittleEndianBitOrder ?? false\n const displayBigEndianBitOrder = props.displayBigEndianBitOrder ?? false\n const text = stand ? '1' : '0'\n const border = overflow\n ? '1px dotted red'\n : zeroPadding\n ? '1px dotted gray'\n : '1px solid #cccccc'\n const margin = '0.5px'\n const color = stand ? '#999999' : '#cccccc'\n const backgroundColor = stand ? '#000000' : '#ffffff'\n const fontFamily = 'monospace'\n return (\n <div style={{ display: 'inline-block', fontFamily, margin }}>\n <div\n style={{\n color,\n backgroundColor,\n border,\n }}\n >\n {text}\n </div>\n {displayLittleEndianBitOrder && (\n <IndexLabel index={props.littleEndianBitOrder} />\n )}\n {displayBigEndianBitOrder && (\n <IndexLabel index={props.bigEndianBitOrder} />\n )}\n </div>\n )\n}\n\nconst IndexLabel = (props: { index: number }): React.JSX.Element => {\n return (\n <div\n style={{\n userSelect: 'none',\n fontSize: '0.5em',\n textAlign: 'center',\n lineHeight: '1em',\n }}\n >\n {props.index}\n </div>\n )\n}\n\nexport const DetailedBitString = (props: {\n value: number\n length?: number\n showLittleEndianBitOrder?: boolean | undefined\n showBigEndianBitOrder?: boolean | undefined\n}): React.JSX.Element => {\n const showLittleEndianBitOrder = props.showLittleEndianBitOrder ?? false\n const showBigEndianBitOrder = props.showBigEndianBitOrder ?? false\n return (\n <Bits\n value={props.value}\n length={props.length}\n bitElement={(props) => (\n <DetailedBit\n {...props}\n displayLittleEndianBitOrder={showLittleEndianBitOrder}\n displayBigEndianBitOrder={showBigEndianBitOrder}\n />\n )}\n />\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,mBAAkB;AAuDT;AA1BF,IAAM,OAAO,CAAC,UAII;AACvB,QAAM,EAAE,OAAO,WAAW,IAAI;AAC9B,QAAM,QAAQ,QAAQ,GAAG,SAAS,CAAC,EAAE,MAAM,EAAE;AAC7C,QAAM,YAAY,KAAK;AACvB,QAAM,SAAS,MAAM,UAAU;AAC/B,QAAM,iBAAiB,KAAK,IAAI,GAAG,YAAY,MAAM;AACrD,QAAM,oBAAoB,KAAK,IAAI,GAAG,SAAS,SAAS;AACxD,QAAM,kBAAkB,KAAK,IAAI,QAAQ,SAAS;AAClD,QAAM,WAAW,MAAM,KAAK,MAAM,eAAe,CAAC,EAAE,IAAI,CAAC,GAAG,UAAU;AACpE,UAAM,QAAQ,KAAK,YAAY,kBAAkB,KAAK,MAAM;AAC5D,UAAM,oBAAoB;AAC1B,UAAM,WAAW,oBAAoB;AACrC,UAAM,cAAc,oBAAoB;AACxC,WAAO,aAAAA,QAAM,cAAc,YAAY;AAAA,MACrC,KAAK;AAAA,MACL;AAAA,MACA;AAAA,MACA;AAAA,MACA,sBAAsB,kBAAkB,QAAQ;AAAA,MAChD;AAAA,IACF,CAAC;AAAA,EACH,CAAC;AACD,SAAO,2EAAG,oBAAS;AACrB;;;AC3CS,IAAAC,sBAAA;AALF,IAAM,YAAY,CAAC,UAA+C;AACvE,QAAM,EAAE,OAAO,SAAS,IAAI;AAC5B,QAAM,WAAW,QAAQ,MAAM;AAC/B,QAAM,oBAAoB,YAAY;AACtC,QAAM,OAAO,oBAAoB,KAAK;AACtC,SAAO,6EAAG,gBAAK;AACjB;AAEO,IAAM,mBAAmB,CAAC,UAAgD;AAC/E,SAAO,6CAAC,QAAK,OAAO,MAAM,OAAO,QAAQ,GAAG,YAAY,WAAW;AACrE;;;ACKI,IAAAC,sBAAA;AAfG,IAAM,cAAc,CAAC,UAA+C;AACzE,QAAM,EAAE,OAAO,UAAU,YAAY,IAAI;AACzC,QAAM,8BAA8B,MAAM,+BAA+B;AACzE,QAAM,2BAA2B,MAAM,4BAA4B;AACnE,QAAM,OAAO,QAAQ,MAAM;AAC3B,QAAM,SAAS,WACX,mBACA,cACE,oBACA;AACN,QAAM,SAAS;AACf,QAAM,QAAQ,QAAQ,YAAY;AAClC,QAAM,kBAAkB,QAAQ,YAAY;AAC5C,QAAM,aAAa;AACnB,SACE,8CAAC,SAAI,OAAO,EAAE,SAAS,gBAAgB,YAAY,OAAO,GACxD;AAAA;AAAA,MAAC;AAAA;AAAA,QACC,OAAO;AAAA,UACL;AAAA,UACA;AAAA,UACA;AAAA,QACF;AAAA,QAEC;AAAA;AAAA,IACH;AAAA,IACC,+BACC,6CAAC,cAAW,OAAO,MAAM,sBAAsB;AAAA,IAEhD,4BACC,6CAAC,cAAW,OAAO,MAAM,mBAAmB;AAAA,KAEhD;AAEJ;AAEA,IAAM,aAAa,CAAC,UAAgD;AAClE,SACE;AAAA,IAAC;AAAA;AAAA,MACC,OAAO;AAAA,QACL,YAAY;AAAA,QACZ,UAAU;AAAA,QACV,WAAW;AAAA,QACX,YAAY;AAAA,MACd;AAAA,MAEC,gBAAM;AAAA;AAAA,EACT;AAEJ;AAEO,IAAM,oBAAoB,CAAC,UAKT;AACvB,QAAM,2BAA2B,MAAM,4BAA4B;AACnE,QAAM,wBAAwB,MAAM,yBAAyB;AAC7D,SACE;AAAA,IAAC;AAAA;AAAA,MACC,OAAO,MAAM;AAAA,MACb,QAAQ,MAAM;AAAA,MACd,YAAY,CAACC,WACX;AAAA,QAAC;AAAA;AAAA,UACE,GAAGA;AAAA,UACJ,6BAA6B;AAAA,UAC7B,0BAA0B;AAAA;AAAA,MAC5B;AAAA;AAAA,EAEJ;AAEJ;","names":["React","import_jsx_runtime","import_jsx_runtime","props"]}
@@ -1,4 +1,4 @@
1
- export { BitElement, BitProps, Bits, EnhancedBitProps } from './Binary.mjs';
2
- export { Simple8BitString, SimpleBit } from './Simple.mjs';
3
- export { DetailedBit, DetailedBitProps, DetailedBitString } from './Detailed.mjs';
1
+ export { BitElement, BitProps, Bits, EnhancedBitProps } from './Binary.cjs';
2
+ export { Simple8BitString, SimpleBit } from './Simple.cjs';
3
+ export { DetailedBit, DetailedBitProps, DetailedBitString } from './Detailed.cjs';
4
4
  import 'react';
package/dist/index.js CHANGED
@@ -1,149 +1,19 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
-
30
- // src/index.ts
31
- var src_exports = {};
32
- __export(src_exports, {
33
- Bits: () => Bits,
34
- DetailedBit: () => DetailedBit,
35
- DetailedBitString: () => DetailedBitString,
36
- Simple8BitString: () => Simple8BitString,
37
- SimpleBit: () => SimpleBit
38
- });
39
- module.exports = __toCommonJS(src_exports);
40
-
41
- // src/Binary.tsx
42
- var import_react = __toESM(require("react"));
43
- var import_jsx_runtime = require("react/jsx-runtime");
44
- var Bits = (props) => {
45
- const { value, bitElement } = props;
46
- const bits = (value | 0).toString(2).split("");
47
- const bitLength = bits.length;
48
- const length = props.length ?? bitLength;
49
- const overflowLength = Math.max(0, bitLength - length);
50
- const zeroPaddingLength = Math.max(0, length - bitLength);
51
- const representLength = Math.max(length, bitLength);
52
- const elements = Array.from(Array(representLength)).map((_, index) => {
53
- const stand = bits[bitLength - representLength + index] === "1";
54
- const bigEndianBitOrder = index;
55
- const overflow = bigEndianBitOrder < overflowLength;
56
- const zeroPadding = bigEndianBitOrder < zeroPaddingLength;
57
- return import_react.default.createElement(bitElement, {
58
- key: index,
59
- stand,
60
- overflow,
61
- zeroPadding,
62
- littleEndianBitOrder: representLength - index - 1,
63
- bigEndianBitOrder
64
- });
65
- });
66
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, { children: elements });
67
- };
68
-
69
- // src/Simple.tsx
70
- var import_jsx_runtime2 = require("react/jsx-runtime");
71
- var SimpleBit = (props) => {
72
- const { stand, overflow } = props;
73
- const text = overflow ?? false ? "" : stand ? "1" : "0";
74
- return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_jsx_runtime2.Fragment, { children: text });
75
- };
76
- var Simple8BitString = (props) => {
77
- return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Bits, { value: props.value, length: 8, bitElement: SimpleBit });
78
- };
79
-
80
- // src/Detailed.tsx
81
- var import_jsx_runtime3 = require("react/jsx-runtime");
82
- var DetailedBit = (props) => {
83
- const { stand, overflow, zeroPadding } = props;
84
- const displayLittleEndianBitOrder = props.displayLittleEndianBitOrder ?? false;
85
- const displayBigEndianBitOrder = props.displayBigEndianBitOrder ?? false;
86
- const text = stand ? "1" : "0";
87
- const border = overflow ? "1px dotted red" : zeroPadding ? "1px dotted gray" : "1px solid #cccccc";
88
- const margin = "0.5px";
89
- const color = stand ? "#999999" : "#cccccc";
90
- const backgroundColor = stand ? "#000000" : "#ffffff";
91
- const fontFamily = "monospace";
92
- return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { style: { display: "inline-block", fontFamily, margin }, children: [
93
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
94
- "div",
95
- {
96
- style: {
97
- color,
98
- backgroundColor,
99
- border
100
- },
101
- children: text
102
- }
103
- ),
104
- displayLittleEndianBitOrder && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(IndexLabel, { index: props.littleEndianBitOrder }),
105
- displayBigEndianBitOrder && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(IndexLabel, { index: props.bigEndianBitOrder })
106
- ] });
107
- };
108
- var IndexLabel = (props) => {
109
- return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
110
- "div",
111
- {
112
- style: {
113
- userSelect: "none",
114
- fontSize: "0.5em",
115
- textAlign: "center",
116
- lineHeight: "1em"
117
- },
118
- children: props.index
119
- }
120
- );
121
- };
122
- var DetailedBitString = (props) => {
123
- const showLittleEndianBitOrder = props.showLittleEndianBitOrder ?? false;
124
- const showBigEndianBitOrder = props.showBigEndianBitOrder ?? false;
125
- return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
126
- Bits,
127
- {
128
- value: props.value,
129
- length: props.length,
130
- bitElement: (props2) => /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
131
- DetailedBit,
132
- {
133
- ...props2,
134
- displayLittleEndianBitOrder: showLittleEndianBitOrder,
135
- displayBigEndianBitOrder: showBigEndianBitOrder
136
- }
137
- )
138
- }
139
- );
140
- };
141
- // Annotate the CommonJS export names for ESM import in node:
142
- 0 && (module.exports = {
1
+ import {
2
+ DetailedBit,
3
+ DetailedBitString
4
+ } from "./chunk-KC5B3ZDB.js";
5
+ import {
6
+ Simple8BitString,
7
+ SimpleBit
8
+ } from "./chunk-EIJS7GKA.js";
9
+ import {
10
+ Bits
11
+ } from "./chunk-76L6HIHJ.js";
12
+ export {
143
13
  Bits,
144
14
  DetailedBit,
145
15
  DetailedBitString,
146
16
  Simple8BitString,
147
17
  SimpleBit
148
- });
18
+ };
149
19
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/Binary.tsx","../src/Simple.tsx","../src/Detailed.tsx"],"sourcesContent":["export * from './Binary'\nexport * from './Simple'\nexport * from './Detailed'\n","import React from 'react'\n\n/**\n * BitProps is a type that represents the properties of a bit.\n */\nexport type BitProps = {\n stand: boolean\n}\n\n/**\n * EnhancedBitProps is a type that adds the following properties to BitProps.\n * - overflow: If true, this means that bit is out of range.\n * - zeroPadding: If true, this means that bit is padded with zero.\n */\nexport type EnhancedBitProps = BitProps & {\n overflow?: boolean\n zeroPadding?: boolean\n littleEndianBitOrder: number\n bigEndianBitOrder: number\n}\n\nexport type BitElement = React.FC<EnhancedBitProps>\n\n/**\n * Bit is a component that displays a bit.\n * This component supports the behavior of zero padding and overflow.\n * @param props\n * @returns A component that displays a bit.\n */\nexport const Bits = (props: {\n value: number\n bitElement: BitElement\n length?: number | undefined\n}): JSX.Element => {\n const { value, bitElement } = props\n const bits = (value | 0).toString(2).split('')\n const bitLength = bits.length\n const length = props.length ?? bitLength\n const overflowLength = Math.max(0, bitLength - length)\n const zeroPaddingLength = Math.max(0, length - bitLength)\n const representLength = Math.max(length, bitLength)\n const elements = Array.from(Array(representLength)).map((_, index) => {\n const stand = bits[bitLength - representLength + index] === '1'\n const bigEndianBitOrder = index\n const overflow = bigEndianBitOrder < overflowLength\n const zeroPadding = bigEndianBitOrder < zeroPaddingLength\n return React.createElement(bitElement, {\n key: index,\n stand,\n overflow,\n zeroPadding,\n littleEndianBitOrder: representLength - index - 1,\n bigEndianBitOrder,\n })\n })\n return <>{elements}</>\n}\n","import React from 'react'\nimport { Bits, EnhancedBitProps } from './Binary'\n\n/**\n * SimpleBit is a simple component that displays a bit.\n * @param props\n * @returns A component that displays a bit.\n */\nexport const SimpleBit = (props: EnhancedBitProps): JSX.Element => {\n const { stand, overflow } = props\n const text = overflow ?? false ? '' : stand ? '1' : '0'\n return <>{text}</>\n}\n\nexport const Simple8BitString = (props: { value: number }): JSX.Element => {\n return <Bits value={props.value} length={8} bitElement={SimpleBit} />\n}\n","import React from 'react'\nimport { Bits, EnhancedBitProps } from './Binary'\n\nexport type DetailedBitProps = EnhancedBitProps & {\n displayLittleEndianBitOrder?: boolean | undefined\n displayBigEndianBitOrder?: boolean | undefined\n}\n\nexport const DetailedBit = (props: DetailedBitProps): JSX.Element => {\n const { stand, overflow, zeroPadding } = props\n const displayLittleEndianBitOrder = props.displayLittleEndianBitOrder ?? false\n const displayBigEndianBitOrder = props.displayBigEndianBitOrder ?? false\n const text = stand ? '1' : '0'\n const border = overflow\n ? '1px dotted red'\n : zeroPadding\n ? '1px dotted gray'\n : '1px solid #cccccc'\n const margin = '0.5px'\n const color = stand ? '#999999' : '#cccccc'\n const backgroundColor = stand ? '#000000' : '#ffffff'\n const fontFamily = 'monospace'\n return (\n <div style={{ display: 'inline-block', fontFamily, margin }}>\n <div\n style={{\n color,\n backgroundColor,\n border,\n }}\n >\n {text}\n </div>\n {displayLittleEndianBitOrder && (\n <IndexLabel index={props.littleEndianBitOrder} />\n )}\n {displayBigEndianBitOrder && (\n <IndexLabel index={props.bigEndianBitOrder} />\n )}\n </div>\n )\n}\n\nconst IndexLabel = (props: { index: number }): JSX.Element => {\n return (\n <div\n style={{\n userSelect: 'none',\n fontSize: '0.5em',\n textAlign: 'center',\n lineHeight: '1em',\n }}\n >\n {props.index}\n </div>\n )\n}\n\nexport const DetailedBitString = (props: {\n value: number\n length?: number\n showLittleEndianBitOrder?: boolean | undefined\n showBigEndianBitOrder?: boolean | undefined\n}): JSX.Element => {\n const showLittleEndianBitOrder = props.showLittleEndianBitOrder ?? false\n const showBigEndianBitOrder = props.showBigEndianBitOrder ?? false\n return (\n <Bits\n value={props.value}\n length={props.length}\n bitElement={(props) => (\n <DetailedBit\n {...props}\n displayLittleEndianBitOrder={showLittleEndianBitOrder}\n displayBigEndianBitOrder={showBigEndianBitOrder}\n />\n )}\n />\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,mBAAkB;AAuDT;AA1BF,IAAM,OAAO,CAAC,UAIF;AACjB,QAAM,EAAE,OAAO,WAAW,IAAI;AAC9B,QAAM,QAAQ,QAAQ,GAAG,SAAS,CAAC,EAAE,MAAM,EAAE;AAC7C,QAAM,YAAY,KAAK;AACvB,QAAM,SAAS,MAAM,UAAU;AAC/B,QAAM,iBAAiB,KAAK,IAAI,GAAG,YAAY,MAAM;AACrD,QAAM,oBAAoB,KAAK,IAAI,GAAG,SAAS,SAAS;AACxD,QAAM,kBAAkB,KAAK,IAAI,QAAQ,SAAS;AAClD,QAAM,WAAW,MAAM,KAAK,MAAM,eAAe,CAAC,EAAE,IAAI,CAAC,GAAG,UAAU;AACpE,UAAM,QAAQ,KAAK,YAAY,kBAAkB,KAAK,MAAM;AAC5D,UAAM,oBAAoB;AAC1B,UAAM,WAAW,oBAAoB;AACrC,UAAM,cAAc,oBAAoB;AACxC,WAAO,aAAAA,QAAM,cAAc,YAAY;AAAA,MACrC,KAAK;AAAA,MACL;AAAA,MACA;AAAA,MACA;AAAA,MACA,sBAAsB,kBAAkB,QAAQ;AAAA,MAChD;AAAA,IACF,CAAC;AAAA,EACH,CAAC;AACD,SAAO,2EAAG,oBAAS;AACrB;;;AC7CS,IAAAC,sBAAA;AAHF,IAAM,YAAY,CAAC,UAAyC;AACjE,QAAM,EAAE,OAAO,SAAS,IAAI;AAC5B,QAAM,OAAO,YAAY,QAAQ,KAAK,QAAQ,MAAM;AACpD,SAAO,6EAAG,gBAAK;AACjB;AAEO,IAAM,mBAAmB,CAAC,UAA0C;AACzE,SAAO,6CAAC,QAAK,OAAO,MAAM,OAAO,QAAQ,GAAG,YAAY,WAAW;AACrE;;;ACOI,IAAAC,sBAAA;AAfG,IAAM,cAAc,CAAC,UAAyC;AACnE,QAAM,EAAE,OAAO,UAAU,YAAY,IAAI;AACzC,QAAM,8BAA8B,MAAM,+BAA+B;AACzE,QAAM,2BAA2B,MAAM,4BAA4B;AACnE,QAAM,OAAO,QAAQ,MAAM;AAC3B,QAAM,SAAS,WACX,mBACA,cACE,oBACA;AACN,QAAM,SAAS;AACf,QAAM,QAAQ,QAAQ,YAAY;AAClC,QAAM,kBAAkB,QAAQ,YAAY;AAC5C,QAAM,aAAa;AACnB,SACE,8CAAC,SAAI,OAAO,EAAE,SAAS,gBAAgB,YAAY,OAAO,GACxD;AAAA;AAAA,MAAC;AAAA;AAAA,QACC,OAAO;AAAA,UACL;AAAA,UACA;AAAA,UACA;AAAA,QACF;AAAA,QAEC;AAAA;AAAA,IACH;AAAA,IACC,+BACC,6CAAC,cAAW,OAAO,MAAM,sBAAsB;AAAA,IAEhD,4BACC,6CAAC,cAAW,OAAO,MAAM,mBAAmB;AAAA,KAEhD;AAEJ;AAEA,IAAM,aAAa,CAAC,UAA0C;AAC5D,SACE;AAAA,IAAC;AAAA;AAAA,MACC,OAAO;AAAA,QACL,YAAY;AAAA,QACZ,UAAU;AAAA,QACV,WAAW;AAAA,QACX,YAAY;AAAA,MACd;AAAA,MAEC,gBAAM;AAAA;AAAA,EACT;AAEJ;AAEO,IAAM,oBAAoB,CAAC,UAKf;AACjB,QAAM,2BAA2B,MAAM,4BAA4B;AACnE,QAAM,wBAAwB,MAAM,yBAAyB;AAC7D,SACE;AAAA,IAAC;AAAA;AAAA,MACC,OAAO,MAAM;AAAA,MACb,QAAQ,MAAM;AAAA,MACd,YAAY,CAACC,WACX;AAAA,QAAC;AAAA;AAAA,UACE,GAAGA;AAAA,UACJ,6BAA6B;AAAA,UAC7B,0BAA0B;AAAA;AAAA,MAC5B;AAAA;AAAA,EAEJ;AAEJ;","names":["React","import_jsx_runtime","import_jsx_runtime","props"]}
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
package/package.json CHANGED
@@ -1,35 +1,47 @@
1
1
  {
2
2
  "name": "@kitsuyui/react-binary",
3
- "version": "0.1.6",
3
+ "version": "0.2.0",
4
4
  "description": "Binary representation of number for React",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "https://github.com/kitsuyui/react-playground.git"
8
+ },
5
9
  "license": "MIT",
6
10
  "author": "Yui Kitsu <kitsuyui@kitsuyui.com>",
11
+ "type": "module",
7
12
  "exports": {
8
13
  ".": {
9
- "require": "./dist/index.js",
10
- "import": "./dist/index.mjs",
11
- "types": "./dist/index.d.ts"
14
+ "require": {
15
+ "type": "./dist/index.d.cts",
16
+ "default": "./dist/index.cjs"
17
+ },
18
+ "import": {
19
+ "type": "./dist/index.d.ts",
20
+ "default": "./dist/index.js"
21
+ }
12
22
  }
13
23
  },
14
24
  "main": "./dist/index.js",
15
- "module": "./dist/index.mjs",
25
+ "module": "./dist/index.js",
16
26
  "types": "./dist/index.d.ts",
17
27
  "files": [
18
28
  "dist",
19
29
  "package.json"
20
30
  ],
21
31
  "devDependencies": {
22
- "@types/react": "^18.3.3",
23
- "@types/react-dom": "^18.3.0",
24
- "react": "^18.3.1",
25
- "react-dom": "^18.3.1"
32
+ "@types/react": "^19.1.8",
33
+ "@types/react-dom": "^19.1.6",
34
+ "react": "^19.1.0",
35
+ "react-dom": "^19.1.0"
26
36
  },
27
37
  "peerDependencies": {
28
38
  "react": "*",
29
39
  "react-dom": "*"
30
40
  },
31
41
  "scripts": {
32
- "build": "tsup --config ../../tsup.config.mjs --clean",
33
- "dev": "tsup --config ../../tsup.config.mjs --watch"
42
+ "build": "tsup --clean",
43
+ "dev": "tsup --watch",
44
+ "test": "vitest run",
45
+ "validate": "validate-package-exports --check --verify"
34
46
  }
35
47
  }
package/dist/Binary.mjs DELETED
@@ -1,7 +0,0 @@
1
- import {
2
- Bits
3
- } from "./chunk-SSBW6RTY.mjs";
4
- export {
5
- Bits
6
- };
7
- //# sourceMappingURL=Binary.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
package/dist/Detailed.mjs DELETED
@@ -1,10 +0,0 @@
1
- import {
2
- DetailedBit,
3
- DetailedBitString
4
- } from "./chunk-WHSEFUQT.mjs";
5
- import "./chunk-SSBW6RTY.mjs";
6
- export {
7
- DetailedBit,
8
- DetailedBitString
9
- };
10
- //# sourceMappingURL=Detailed.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
package/dist/Simple.mjs DELETED
@@ -1,10 +0,0 @@
1
- import {
2
- Simple8BitString,
3
- SimpleBit
4
- } from "./chunk-HPBKCHK2.mjs";
5
- import "./chunk-SSBW6RTY.mjs";
6
- export {
7
- Simple8BitString,
8
- SimpleBit
9
- };
10
- //# sourceMappingURL=Simple.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/Simple.tsx"],"sourcesContent":["import React from 'react'\nimport { Bits, EnhancedBitProps } from './Binary'\n\n/**\n * SimpleBit is a simple component that displays a bit.\n * @param props\n * @returns A component that displays a bit.\n */\nexport const SimpleBit = (props: EnhancedBitProps): JSX.Element => {\n const { stand, overflow } = props\n const text = overflow ?? false ? '' : stand ? '1' : '0'\n return <>{text}</>\n}\n\nexport const Simple8BitString = (props: { value: number }): JSX.Element => {\n return <Bits value={props.value} length={8} bitElement={SimpleBit} />\n}\n"],"mappings":";;;;;AAWS;AAHF,IAAM,YAAY,CAAC,UAAyC;AACjE,QAAM,EAAE,OAAO,SAAS,IAAI;AAC5B,QAAM,OAAO,YAAY,QAAQ,KAAK,QAAQ,MAAM;AACpD,SAAO,gCAAG,gBAAK;AACjB;AAEO,IAAM,mBAAmB,CAAC,UAA0C;AACzE,SAAO,oBAAC,QAAK,OAAO,MAAM,OAAO,QAAQ,GAAG,YAAY,WAAW;AACrE;","names":[]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/Binary.tsx"],"sourcesContent":["import React from 'react'\n\n/**\n * BitProps is a type that represents the properties of a bit.\n */\nexport type BitProps = {\n stand: boolean\n}\n\n/**\n * EnhancedBitProps is a type that adds the following properties to BitProps.\n * - overflow: If true, this means that bit is out of range.\n * - zeroPadding: If true, this means that bit is padded with zero.\n */\nexport type EnhancedBitProps = BitProps & {\n overflow?: boolean\n zeroPadding?: boolean\n littleEndianBitOrder: number\n bigEndianBitOrder: number\n}\n\nexport type BitElement = React.FC<EnhancedBitProps>\n\n/**\n * Bit is a component that displays a bit.\n * This component supports the behavior of zero padding and overflow.\n * @param props\n * @returns A component that displays a bit.\n */\nexport const Bits = (props: {\n value: number\n bitElement: BitElement\n length?: number | undefined\n}): JSX.Element => {\n const { value, bitElement } = props\n const bits = (value | 0).toString(2).split('')\n const bitLength = bits.length\n const length = props.length ?? bitLength\n const overflowLength = Math.max(0, bitLength - length)\n const zeroPaddingLength = Math.max(0, length - bitLength)\n const representLength = Math.max(length, bitLength)\n const elements = Array.from(Array(representLength)).map((_, index) => {\n const stand = bits[bitLength - representLength + index] === '1'\n const bigEndianBitOrder = index\n const overflow = bigEndianBitOrder < overflowLength\n const zeroPadding = bigEndianBitOrder < zeroPaddingLength\n return React.createElement(bitElement, {\n key: index,\n stand,\n overflow,\n zeroPadding,\n littleEndianBitOrder: representLength - index - 1,\n bigEndianBitOrder,\n })\n })\n return <>{elements}</>\n}\n"],"mappings":";AAAA,OAAO,WAAW;AAuDT;AA1BF,IAAM,OAAO,CAAC,UAIF;AACjB,QAAM,EAAE,OAAO,WAAW,IAAI;AAC9B,QAAM,QAAQ,QAAQ,GAAG,SAAS,CAAC,EAAE,MAAM,EAAE;AAC7C,QAAM,YAAY,KAAK;AACvB,QAAM,SAAS,MAAM,UAAU;AAC/B,QAAM,iBAAiB,KAAK,IAAI,GAAG,YAAY,MAAM;AACrD,QAAM,oBAAoB,KAAK,IAAI,GAAG,SAAS,SAAS;AACxD,QAAM,kBAAkB,KAAK,IAAI,QAAQ,SAAS;AAClD,QAAM,WAAW,MAAM,KAAK,MAAM,eAAe,CAAC,EAAE,IAAI,CAAC,GAAG,UAAU;AACpE,UAAM,QAAQ,KAAK,YAAY,kBAAkB,KAAK,MAAM;AAC5D,UAAM,oBAAoB;AAC1B,UAAM,WAAW,oBAAoB;AACrC,UAAM,cAAc,oBAAoB;AACxC,WAAO,MAAM,cAAc,YAAY;AAAA,MACrC,KAAK;AAAA,MACL;AAAA,MACA;AAAA,MACA;AAAA,MACA,sBAAsB,kBAAkB,QAAQ;AAAA,MAChD;AAAA,IACF,CAAC;AAAA,EACH,CAAC;AACD,SAAO,gCAAG,oBAAS;AACrB;","names":[]}