timvir 0.1.44 → 0.1.45

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.
@@ -1,6 +1,5 @@
1
1
  import { Exhibit } from 'timvir/blocks';
2
2
  import { useBlock } from 'timvir/core';
3
- import * as base58 from 'timvir/std/base58';
4
3
  import * as React from 'react';
5
4
  import { useImmer } from 'use-immer';
6
5
 
@@ -30,6 +29,76 @@ const cx = function cx() {
30
29
  return [...styleCollectionResult, ...classNamesResult].join(' ');
31
30
  };
32
31
 
32
+ const bytesToHex = (() => {
33
+ const s = Array.from({
34
+ length: 256
35
+ }).map((_, i) => i.toString(16).padStart(2, "0"));
36
+ return uint8a => [...uint8a].map(o => s[o]).join("");
37
+ })();
38
+
39
+ const alphabet = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
40
+ function encode(input) {
41
+ if (input.length === 0) {
42
+ return "";
43
+ } // Uint8Array -> BigInt (Big Endian)
44
+
45
+
46
+ let x = BigInt("0x" + bytesToHex(input));
47
+ const output = [];
48
+
49
+ while (x > 0n) {
50
+ const mod = x % 58n;
51
+ x = x / 58n;
52
+ output.push(alphabet[Number(mod)]);
53
+ }
54
+
55
+ for (let i = 0; input[i] === 0; i++) {
56
+ output.push(alphabet[0]);
57
+ }
58
+
59
+ return output.reverse().join("");
60
+ }
61
+ function decode(output) {
62
+ if (output.length === 0) {
63
+ return new Uint8Array();
64
+ }
65
+
66
+ const bytes = [0];
67
+ const letters = alphabet;
68
+
69
+ for (const char of output) {
70
+ const value = letters.indexOf(char);
71
+
72
+ if (value === undefined) {
73
+ throw new Error(`base58.decode received invalid input. Character '${char}' is not in the base58 alphabet.`);
74
+ }
75
+
76
+ for (let j = 0; j < bytes.length; j++) {
77
+ bytes[j] *= 58;
78
+ }
79
+
80
+ bytes[0] += value;
81
+ let carry = 0;
82
+
83
+ for (let j = 0; j < bytes.length; j++) {
84
+ bytes[j] += carry;
85
+ carry = bytes[j] >> 8;
86
+ bytes[j] &= 0xff;
87
+ }
88
+
89
+ while (carry > 0) {
90
+ bytes.push(carry & 0xff);
91
+ carry >>= 8;
92
+ }
93
+ }
94
+
95
+ for (let i = 0; i < output.length && output[i] === "1"; i++) {
96
+ bytes.push(0);
97
+ }
98
+
99
+ return new Uint8Array(bytes.reverse());
100
+ }
101
+
33
102
  const Context = /*#__PURE__*/React.createContext({
34
103
  seed: 0
35
104
  });
@@ -83,11 +152,11 @@ function Arbitrary(props, ref) {
83
152
  }, "Seed:"), /*#__PURE__*/React.createElement("input", {
84
153
  className: classes.input,
85
154
  placeholder: "Seed",
86
- value: base58.encode(new TextEncoder().encode(`${value.seed}`)),
155
+ value: encode(new TextEncoder().encode(`${value.seed}`)),
87
156
  onPaste: ev => {
88
157
  const v = ev.clipboardData.getData("text/plain");
89
158
  mutate(draft => {
90
- draft.seed = +base58.decode(v);
159
+ draft.seed = +decode(v);
91
160
  });
92
161
  },
93
162
  onFocus: ev => {
@@ -1,6 +1,6 @@
1
1
  import { Cover } from "..";
2
2
 
3
- import image from "../../../../assets/daniel-leone-v7daTKlZzaw-unsplash.jpg";
3
+ import image from "../../../../../assets/daniel-leone-v7daTKlZzaw-unsplash.jpg";
4
4
 
5
5
  <Cover metadata={image} img={{ src: image.src }} sources={[]} />
6
6
 
@@ -1,15 +1,15 @@
1
1
  import { Grid } from "..";
2
2
  import { Exhibit } from "../../Exhibit";
3
- import { Image } from "../../../../src/components/Image";
3
+ import { Image } from "../../../../../src/components/Image";
4
4
  import { fullWidth } from "timvir/core";
5
5
 
6
- import image1 from "../../../../assets/khachik-simonian-nXOB-wh4Oyc-unsplash.jpg"
7
- import image2 from "../../../../assets/frank-mckenna-4V8JxijgZ_c-unsplash.jpg"
8
- import image3 from "../../../../assets/jay-mantri-TFyi0QOx08c-unsplash.jpg"
9
- import image4 from "../../../../assets/jeremy-bishop-EwKXn5CapA4-unsplash.jpg"
10
- import image5 from "../../../../assets/lukasz-szmigiel-jFCViYFYcus-unsplash.jpg"
11
- import image6 from "../../../../assets/qingbao-meng-01_igFr7hd4-unsplash.jpg"
12
- import image7 from "../../../../assets/v2osk-1Z2niiBPg5A-unsplash.jpg"
6
+ import image1 from "../../../../../assets/khachik-simonian-nXOB-wh4Oyc-unsplash.jpg"
7
+ import image2 from "../../../../../assets/frank-mckenna-4V8JxijgZ_c-unsplash.jpg"
8
+ import image3 from "../../../../../assets/jay-mantri-TFyi0QOx08c-unsplash.jpg"
9
+ import image4 from "../../../../../assets/jeremy-bishop-EwKXn5CapA4-unsplash.jpg"
10
+ import image5 from "../../../../../assets/lukasz-szmigiel-jFCViYFYcus-unsplash.jpg"
11
+ import image6 from "../../../../../assets/qingbao-meng-01_igFr7hd4-unsplash.jpg"
12
+ import image7 from "../../../../../assets/v2osk-1Z2niiBPg5A-unsplash.jpg"
13
13
 
14
14
  # Grid
15
15