summaryrefslogtreecommitdiff
path: root/packages/sortug
diff options
context:
space:
mode:
Diffstat (limited to 'packages/sortug')
-rw-r--r--packages/sortug/.gitignore34
-rw-r--r--packages/sortug/README.md15
-rw-r--r--packages/sortug/bun.lock25
-rw-r--r--packages/sortug/index.ts4
-rw-r--r--packages/sortug/package.json11
-rw-r--r--packages/sortug/src/styles.module.css247
-rw-r--r--packages/sortug/src/types.ts9
-rw-r--r--packages/sortug/src/utils.ts87
-rw-r--r--packages/sortug/tsconfig.json28
9 files changed, 460 insertions, 0 deletions
diff --git a/packages/sortug/.gitignore b/packages/sortug/.gitignore
new file mode 100644
index 0000000..a14702c
--- /dev/null
+++ b/packages/sortug/.gitignore
@@ -0,0 +1,34 @@
+# dependencies (bun install)
+node_modules
+
+# output
+out
+dist
+*.tgz
+
+# code coverage
+coverage
+*.lcov
+
+# logs
+logs
+_.log
+report.[0-9]_.[0-9]_.[0-9]_.[0-9]_.json
+
+# dotenv environment variable files
+.env
+.env.development.local
+.env.test.local
+.env.production.local
+.env.local
+
+# caches
+.eslintcache
+.cache
+*.tsbuildinfo
+
+# IntelliJ based IDEs
+.idea
+
+# Finder (MacOS) folder config
+.DS_Store
diff --git a/packages/sortug/README.md b/packages/sortug/README.md
new file mode 100644
index 0000000..fe083f8
--- /dev/null
+++ b/packages/sortug/README.md
@@ -0,0 +1,15 @@
+# sortug
+
+To install dependencies:
+
+```bash
+bun install
+```
+
+To run:
+
+```bash
+bun run index.ts
+```
+
+This project was created using `bun init` in bun v1.2.12. [Bun](https://bun.sh) is a fast all-in-one JavaScript runtime.
diff --git a/packages/sortug/bun.lock b/packages/sortug/bun.lock
new file mode 100644
index 0000000..d50feb5
--- /dev/null
+++ b/packages/sortug/bun.lock
@@ -0,0 +1,25 @@
+{
+ "lockfileVersion": 1,
+ "workspaces": {
+ "": {
+ "name": "sortug",
+ "devDependencies": {
+ "@types/bun": "latest",
+ },
+ "peerDependencies": {
+ "typescript": "^5",
+ },
+ },
+ },
+ "packages": {
+ "@types/bun": ["@types/bun@1.2.16", "", { "dependencies": { "bun-types": "1.2.16" } }, "sha512-1aCZJ/6nSiViw339RsaNhkNoEloLaPzZhxMOYEa7OzRzO41IGg5n/7I43/ZIAW/c+Q6cT12Vf7fOZOoVIzb5BQ=="],
+
+ "@types/node": ["@types/node@24.0.1", "", { "dependencies": { "undici-types": "~7.8.0" } }, "sha512-MX4Zioh39chHlDJbKmEgydJDS3tspMP/lnQC67G3SWsTnb9NeYVWOjkxpOSy4oMfPs4StcWHwBrvUb4ybfnuaw=="],
+
+ "bun-types": ["bun-types@1.2.16", "", { "dependencies": { "@types/node": "*" } }, "sha512-ciXLrHV4PXax9vHvUrkvun9VPVGOVwbbbBF/Ev1cXz12lyEZMoJpIJABOfPcN9gDJRaiKF9MVbSygLg4NXu3/A=="],
+
+ "typescript": ["typescript@5.8.3", "", { "bin": { "tsc": "bin/tsc", "tsserver": "bin/tsserver" } }, "sha512-p1diW6TqL9L07nNxvRMM7hMMw4c5XOo/1ibL4aAIGmSAt9slTE1Xgw5KWuof2uTOvCg9BY7ZRi+GaF+7sfgPeQ=="],
+
+ "undici-types": ["undici-types@7.8.0", "", {}, "sha512-9UJ2xGDvQ43tYyVMpuHlsgApydB8ZKfVYTsLDhXkFL/6gfkp+U8xTGdh8pMJv1SpZna0zxG1DwsKZsreLbXBxw=="],
+ }
+}
diff --git a/packages/sortug/index.ts b/packages/sortug/index.ts
new file mode 100644
index 0000000..039454f
--- /dev/null
+++ b/packages/sortug/index.ts
@@ -0,0 +1,4 @@
+export type * from "./src/types";
+export * from "./src/utils";
+import styles from "./src/styles.module.css";
+export { styles };
diff --git a/packages/sortug/package.json b/packages/sortug/package.json
new file mode 100644
index 0000000..4d03854
--- /dev/null
+++ b/packages/sortug/package.json
@@ -0,0 +1,11 @@
+{
+ "name": "@sortug/lib",
+ "module": "index.ts",
+ "type": "module",
+ "devDependencies": {
+ "@types/bun": "latest"
+ },
+ "peerDependencies": {
+ "typescript": "^5"
+ }
+}
diff --git a/packages/sortug/src/styles.module.css b/packages/sortug/src/styles.module.css
new file mode 100644
index 0000000..0e7db6a
--- /dev/null
+++ b/packages/sortug/src/styles.module.css
@@ -0,0 +1,247 @@
+/* SORTUG CSS */
+/* variables */
+:root {
+ --bai: rgba(255, 255, 255, 1);
+ --baizi: rgba(230, 230, 230);
+ --hui: rgba(130, 130, 130, 1);
+ --hei: rgba(0, 0, 0, 1);
+ --hong: rgb(141, 15, 15, 1);
+ --huang: rgb(230, 180, 60, 1);
+ --lan: rgb(30, 60, 80, 1);
+}
+
+[data-theme="dark"] {
+ --bg: hei;
+ --fg: baizi;
+}
+
+[data-theme="light"] {
+ --bg: white;
+ --fg: black;
+}
+
+* {
+ box-sizing: border-box;
+}
+
+html,
+body,
+#root {
+ height: 100%;
+ min-height: 100%;
+ overscroll-behavior: none;
+ color: var(--fg);
+ -webkit-font-smoothing: antialiased;
+ margin: 0;
+}
+
+/* tailwindy classes */
+.card {
+ padding: 1rem;
+ max-width: max-content;
+}
+
+button,
+.button {
+ max-width: max-content;
+ padding: 0.5rem;
+ border: 1px solid var(--fg);
+}
+
+/* borders */
+.nb {
+ border: none;
+}
+
+/* widths */
+.hw {
+ width: 50%;
+}
+
+.qw {
+ width: 25%;
+}
+
+.tqw {
+ width: 75%;
+}
+
+/* flex */
+.row {
+ display: flex;
+ align-items: center;
+}
+
+.sy {
+ overflow-y: scroll;
+}
+
+.fsy {
+ overflow-y: scroll;
+ height: 100%;
+}
+
+.fxc {
+ display: flex;
+ justify-content: center;
+ align-items: baseline;
+}
+
+/* flex spread */
+.fs {
+ display: flex;
+ justify-content: space-between;
+}
+
+.fsc {
+ display: flex;
+ justify-content: space-between;
+ align-items: center;
+}
+
+.g1 {
+ gap: 0.5rem;
+}
+
+.g2 {
+ gap: 1rem;
+}
+
+.address {
+ font-family: "Courier New", Courier, monospace;
+}
+
+.spread {
+ justify-content: space-between;
+}
+
+.even {
+ justify-content: space-evenly;
+}
+
+.flexc {
+ justify-content: center;
+}
+
+.cp {
+ cursor: pointer;
+}
+
+/* centering */
+.gc {
+ position: fixed;
+ top: 50%;
+ left: 50%;
+ transform: translate(-50%, -50%);
+}
+
+.agc {
+ position: absolute;
+ top: 50%;
+ left: 50%;
+ transform: translate(-50%, -50%);
+}
+
+.ac {
+ position: absolute;
+ left: 50%;
+ transform: translateX(-50%);
+}
+
+.xc {
+ position: fixed;
+ left: 50%;
+ transform: translateX(-50%);
+ z-index: 20;
+}
+
+.tc {
+ text-align: center;
+}
+
+.bc {
+ display: block;
+ margin-left: auto;
+ margin-right: auto;
+}
+
+.blocks {
+ & * {
+ display: block;
+ }
+}
+
+.bold {
+ font-weight: 700;
+}
+
+.weak {
+ opacity: 0.7;
+}
+
+.all-c {
+ & * {
+ margin-left: auto;
+ margin-right: auto;
+ }
+}
+
+.mb-1 {
+ margin-bottom: 1rem;
+}
+
+.error {
+ color: red;
+ text-align: center;
+}
+
+.tabs {
+ display: flex;
+ justify-content: space-evenly;
+ align-items: center;
+
+ & .tab {
+ cursor: pointer;
+ opacity: 0.5;
+ }
+
+ & .tab.active {
+ opacity: 1;
+ }
+}
+
+.disabled {
+ opacity: 0.5;
+}
+
+.smol {
+ font-size: 0.9rem;
+}
+
+/* The Modal (background) */
+#modal-bg {
+ position: fixed;
+ z-index: 1;
+ left: 0;
+ top: 0;
+ width: 100%;
+ height: 100%;
+ overflow: auto;
+ background-color: rgba(0, 0, 0, 0.4);
+ z-index: 998;
+}
+
+/* Modal Content */
+#modal-fg {
+ background-color: var(--bg);
+ position: fixed;
+ top: 50%;
+ left: 50%;
+ transform: translate(-50%, -50%);
+ padding: 20px;
+ z-index: 999;
+ max-height: 90vh;
+ min-height: 20vh;
+ max-width: 90vw;
+ overflow: auto;
+} \ No newline at end of file
diff --git a/packages/sortug/src/types.ts b/packages/sortug/src/types.ts
new file mode 100644
index 0000000..4d8ba56
--- /dev/null
+++ b/packages/sortug/src/types.ts
@@ -0,0 +1,9 @@
+export type BResult<Success, Error> = { ok: Success } | { error: Error };
+
+export type Result<Success> = { ok: Success } | { error: string };
+
+export type AsyncRes<Success> = Promise<Result<Success>>;
+
+export type HexString = `0x${string}`;
+
+export type UrbitID = `~${string}`;
diff --git a/packages/sortug/src/utils.ts b/packages/sortug/src/utils.ts
new file mode 100644
index 0000000..687b8db
--- /dev/null
+++ b/packages/sortug/src/utils.ts
@@ -0,0 +1,87 @@
+export function randomFromArray<T>(a: Array<T>): T {
+ const l = a.length;
+ const ind = Math.floor(Math.random() * l);
+ if (ind === l) return a[ind - 1];
+ else return a[ind];
+}
+export function randomFromArrayAcc<T>(a: Array<T>, s?: Set<T>): T {
+ const st = s ? s : new Set(a);
+ const l = a.length;
+ const ind = Math.floor(Math.random() * l);
+ const res = ind === l ? a[ind - 1] : a[ind];
+ if (st.has(res)) return randomFromArrayAcc(a, st);
+ else {
+ st.add(res);
+ // TODO have to return this too?
+ return res;
+ }
+}
+export function notRandomFromArray<T>(data: string, a: Array<T>): T {
+ const l = a.length;
+ const ind = hashTextToNumber(data, l - 1);
+ return a[ind];
+}
+
+function hashTextToNumber(text: string, max: number): number {
+ let hash = 0;
+ for (let i = 0; i < text.length; i++) {
+ const char = text.charCodeAt(i);
+ hash = (hash << 5) - hash + char;
+ hash = hash & hash; // Convert to 32-bit integer
+ }
+ // Make sure the hash is positive and within the given range
+ return Math.abs(hash) % max;
+}
+
+// Format time for display (HH:MM:SS)
+export const formatTime = (seconds: number): string => {
+ const hrs = Math.floor(seconds / 3600);
+ const mins = Math.floor((seconds % 3600) / 60);
+ const secs = Math.floor(seconds % 60);
+
+ return `${hrs.toString().padStart(2, "0")}:${mins
+ .toString()
+ .padStart(2, "0")}:${secs.toString().padStart(2, "0")}`;
+};
+
+export function date_diff(date: number, type: "short" | "long") {
+ const now = new Date().getTime();
+ const diff = now - new Date(date).getTime();
+ if (type == "short") {
+ return to_string(diff / 1000);
+ } else {
+ return to_string_long(diff / 1000);
+ }
+}
+
+function to_string(s: number) {
+ if (s < 60) {
+ return "now";
+ } else if (s < 3600) {
+ return `${Math.ceil(s / 60)}m`;
+ } else if (s < 86400) {
+ return `${Math.ceil(s / 60 / 60)}h`;
+ } else if (s < 2678400) {
+ return `${Math.ceil(s / 60 / 60 / 24)}d`;
+ } else if (s < 32140800) {
+ return `${Math.ceil(s / 60 / 60 / 24 / 30)}mo`;
+ } else {
+ return `${Math.ceil(s / 60 / 60 / 24 / 30 / 12)}y`;
+ }
+}
+
+function to_string_long(s: number) {
+ if (s < 60) {
+ return "right now";
+ } else if (s < 3600) {
+ return `${Math.ceil(s / 60)} minutes ago`;
+ } else if (s < 86400) {
+ return `${Math.ceil(s / 60 / 60)} hours ago`;
+ } else if (s < 2678400) {
+ return `${Math.ceil(s / 60 / 60 / 24)} days ago`;
+ } else if (s < 32140800) {
+ return `${Math.ceil(s / 60 / 60 / 24 / 30)} months ago`;
+ } else {
+ return `${Math.ceil(s / 60 / 60 / 24 / 30 / 12)} years ago`;
+ }
+}
diff --git a/packages/sortug/tsconfig.json b/packages/sortug/tsconfig.json
new file mode 100644
index 0000000..9c62f74
--- /dev/null
+++ b/packages/sortug/tsconfig.json
@@ -0,0 +1,28 @@
+{
+ "compilerOptions": {
+ // Environment setup & latest features
+ "lib": ["ESNext"],
+ "target": "ESNext",
+ "module": "ESNext",
+ "moduleDetection": "force",
+ "jsx": "react-jsx",
+ "allowJs": true,
+
+ // Bundler mode
+ "moduleResolution": "bundler",
+ "allowImportingTsExtensions": true,
+ "verbatimModuleSyntax": true,
+ "noEmit": true,
+
+ // Best practices
+ "strict": true,
+ "skipLibCheck": true,
+ "noFallthroughCasesInSwitch": true,
+ "noUncheckedIndexedAccess": true,
+
+ // Some stricter flags (disabled by default)
+ "noUnusedLocals": false,
+ "noUnusedParameters": false,
+ "noPropertyAccessFromIndexSignature": false
+ }
+}