diff options
Diffstat (limited to 'packages/sortug/src')
| -rw-r--r-- | packages/sortug/src/styles.module.css | 247 | ||||
| -rw-r--r-- | packages/sortug/src/types.ts | 9 | ||||
| -rw-r--r-- | packages/sortug/src/utils.ts | 87 |
3 files changed, 343 insertions, 0 deletions
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`; + } +} |
