Spaces:
Running
Running
Add 4 files
Browse files
README.md
CHANGED
@@ -1,11 +1,20 @@
|
|
1 |
---
|
|
|
2 |
title: Babel Library Locator
|
3 |
-
emoji: π
|
4 |
-
colorFrom: red
|
5 |
-
colorTo: pink
|
6 |
sdk: static
|
7 |
-
|
8 |
-
|
|
|
9 |
---
|
10 |
|
11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
---
|
2 |
+
license: apache-2.0
|
3 |
title: Babel Library Locator
|
|
|
|
|
|
|
4 |
sdk: static
|
5 |
+
emoji: π¨βπ»
|
6 |
+
colorFrom: yellow
|
7 |
+
colorTo: green
|
8 |
---
|
9 |
|
10 |
+
# Babel Library Locator
|
11 |
+
|
12 |
+
This app is a simple tool that converts the location of a book in the Babel library into a unique identifier that can be used to find the book. The app takes the location as input and returns the room number, wall number, shelf number, book number, and page number as output.
|
13 |
+
|
14 |
+
## Usage
|
15 |
+
|
16 |
+
Enter the location of the book in the input field and click the "Convert" button to see the result.
|
17 |
+
|
18 |
+
## Development
|
19 |
+
|
20 |
+
This app is built using Alpine.js, DaisyUI, and Tailwind CSS.
|
index.html
CHANGED
@@ -1,19 +1 @@
|
|
1 |
-
|
2 |
-
<html>
|
3 |
-
<head>
|
4 |
-
<meta charset="utf-8" />
|
5 |
-
<meta name="viewport" content="width=device-width" />
|
6 |
-
<title>My static Space</title>
|
7 |
-
<link rel="stylesheet" href="style.css" />
|
8 |
-
</head>
|
9 |
-
<body>
|
10 |
-
<div class="card">
|
11 |
-
<h1>Welcome to your static Space!</h1>
|
12 |
-
<p>You can modify this app directly by editing <i>index.html</i> in the Files and versions tab.</p>
|
13 |
-
<p>
|
14 |
-
Also don't forget to check the
|
15 |
-
<a href="https://huggingface.co/docs/hub/spaces" target="_blank">Spaces documentation</a>.
|
16 |
-
</p>
|
17 |
-
</div>
|
18 |
-
</body>
|
19 |
-
</html>
|
|
|
1 |
+
<html><head><link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/full.css" rel="stylesheet" type="text/css" /><script defer src="https://cdn.jsdelivr.net/npm/[email protected]/dist/cdn.min.js"></script><script src="https://cdn.tailwindcss.com?plugins=forms,typography,aspect-ratio"></script><script defer src="https://cdnjs.cloudflare.com/ajax/libs/three.js/0.156.1/three.min.js"></script><script type="module" src="main.js"></script><title>Babel Library Locator</title></head></html>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
main.js
ADDED
@@ -0,0 +1,133 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
const $ = (...params) => document.querySelector(...params);
|
2 |
+
|
3 |
+
/**
|
4 |
+
* Take a string representing the location in the library
|
5 |
+
* and return an object containing the following properties:
|
6 |
+
* room: the room number
|
7 |
+
* wall: the wall number
|
8 |
+
* shelf: the shelf number
|
9 |
+
* book: the book number
|
10 |
+
* page: the page number
|
11 |
+
*/
|
12 |
+
function getLocationDetails(location) {
|
13 |
+
const parts = location.split(".");
|
14 |
+
return {
|
15 |
+
room: parseInt(parts[0], 36),
|
16 |
+
wall: parseInt(parts[1]),
|
17 |
+
shelf: parseInt(parts[2]),
|
18 |
+
book: parseInt(parts[3]),
|
19 |
+
page: parseInt(parts[4]),
|
20 |
+
};
|
21 |
+
}
|
22 |
+
|
23 |
+
/**
|
24 |
+
* Take an object containing the following properties:
|
25 |
+
* room: the room number
|
26 |
+
* wall: the wall number
|
27 |
+
* shelf: the shelf number
|
28 |
+
* book: the book number
|
29 |
+
* page: the page number
|
30 |
+
* and return a string representing the unique identifier for the book.
|
31 |
+
*/
|
32 |
+
function getUniqueBookId(location) {
|
33 |
+
const { room, wall, shelf, book, page } = location;
|
34 |
+
return (room * 1000 + wall * 100 + shelf * 32 + book * 410) + page * 161;
|
35 |
+
}
|
36 |
+
|
37 |
+
/**
|
38 |
+
* Given a book index (integer 1-100), return the page number (1-410)
|
39 |
+
*/
|
40 |
+
function getPageNumber(bookIndex) {
|
41 |
+
return (bookIndex - 1) % 410 + 1;
|
42 |
+
}
|
43 |
+
|
44 |
+
/**
|
45 |
+
* Given a book index (integer 1-100), return the book number (1-32)
|
46 |
+
*/
|
47 |
+
function getBookNumber(bookIndex) {
|
48 |
+
return (bookIndex - 1) % 64 + 1;
|
49 |
+
}
|
50 |
+
|
51 |
+
/**
|
52 |
+
* Given a book index (integer 1-100), return the shelf number (1-5)
|
53 |
+
*/
|
54 |
+
function getShelfNumber(bookIndex) {
|
55 |
+
return (bookIndex - 1) % 32 + 1;
|
56 |
+
}
|
57 |
+
|
58 |
+
/**
|
59 |
+
* Given a book index (integer 1-100), return the wall number (1-4)
|
60 |
+
*/
|
61 |
+
function getWallNumber(bookIndex) {
|
62 |
+
return (bookIndex - 1) % 8 + 1;
|
63 |
+
}
|
64 |
+
|
65 |
+
/**
|
66 |
+
* Given a book index (integer 1-100), return the room number (string containing a letter and an integer)
|
67 |
+
*/
|
68 |
+
function getRoomNumber(bookIndex) {
|
69 |
+
return "Room " + ((bookIndex - 1) % 26 + 1).toUpperCase();
|
70 |
+
}
|
71 |
+
|
72 |
+
$(document).addEventListener("alpine:init", () => {
|
73 |
+
const app = new Alpine.Component();
|
74 |
+
|
75 |
+
app.define("location-details", {
|
76 |
+
input: "",
|
77 |
+
bookIndex: 0,
|
78 |
+
uniqueId: "",
|
79 |
+
});
|
80 |
+
|
81 |
+
app.store({
|
82 |
+
index: 1,
|
83 |
+
inputs: [],
|
84 |
+
});
|
85 |
+
|
86 |
+
app.watch("Input", (value) => {
|
87 |
+
const location = getLocationDetails(value);
|
88 |
+
app.bookIndex = getUniqueBookId(location);
|
89 |
+
app.uniqueId = getRoomNumber(app.bookIndex) + "." + getWallNumber(app.bookIndex) + "." + getShelfNumber(app.bookIndex) + "." + getBookNumber(app.bookIndex) + "." + getPageNumber(app.bookIndex);
|
90 |
+
});
|
91 |
+
|
92 |
+
app.watch("bookIndex", (value) => {
|
93 |
+
app.uniqueId = getRoomNumber(value) + "." + getWallNumber(value) + "." + getShelfNumber(value) + "." + getBookNumber(value) + "." + getPageNumber(value);
|
94 |
+
});
|
95 |
+
|
96 |
+
app.mount("#app");
|
97 |
+
|
98 |
+
// Update the input value with the unique identifier
|
99 |
+
app.on("change:bookIndex", (e) => {
|
100 |
+
const pagination = app.bookIndex;
|
101 |
+
const otherBooks = app. books.map((book) => book.bookIndex);
|
102 |
+
if (!otherBooks.includes(pagination)) {
|
103 |
+
app.bookIndex = pagination;
|
104 |
+
app.uniqueId = getRoomNumber(pagination) + "." + getWallNumber(pagination) + "." + getShelfNumber(pagination) + "." + getBookNumber(pagination) + "." + getPageNumber(pagination);
|
105 |
+
}
|
106 |
+
});
|
107 |
+
|
108 |
+
// Update the button label with the unique identifier
|
109 |
+
app.on("click", (e) => {
|
110 |
+
const pagination = app.bookIndex;
|
111 |
+
const otherBooks = app. books.map((book) => book.bookIndex);
|
112 |
+
if (!otherBooks.includes(pagination)) {
|
113 |
+
app.uniqueId = getRoomNumber(pagination) + "." + getWallNumber(pagination) + "." + getShelfNumber(pagination) + "." + getBookNumber(pagination) + "." + getPageNumber(pagination);
|
114 |
+
}
|
115 |
+
});
|
116 |
+
});
|
117 |
+
|
118 |
+
$(document).addEventListener("DOMContentLoaded", () => {
|
119 |
+
const app = new Alpine.Component();
|
120 |
+
|
121 |
+
app.define("library", {
|
122 |
+
books: [],
|
123 |
+
addBook: (title) => {
|
124 |
+
return { bookIndex: app.books.length + 1, title };
|
125 |
+
},
|
126 |
+
});
|
127 |
+
|
128 |
+
app.store({
|
129 |
+
books: [],
|
130 |
+
});
|
131 |
+
|
132 |
+
app.mount("#app");
|
133 |
+
});
|
style.css
CHANGED
@@ -1,28 +1,79 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
|
4 |
}
|
5 |
|
6 |
-
|
7 |
-
|
8 |
-
margin-top: 0;
|
9 |
}
|
10 |
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
margin-bottom: 10px;
|
15 |
-
margin-top: 5px;
|
16 |
}
|
17 |
|
18 |
-
.
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
border-radius: 16px;
|
24 |
}
|
25 |
|
26 |
-
.
|
27 |
-
|
|
|
|
|
|
|
|
|
28 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
html {
|
2 |
+
font-family: '', sans-serif;
|
3 |
+
background-color: #f9f9f9 !important;
|
4 |
}
|
5 |
|
6 |
+
.prose {
|
7 |
+
background-color: rgb(255, 255, 255);
|
|
|
8 |
}
|
9 |
|
10 |
+
.container {
|
11 |
+
margin-left: 10px;
|
12 |
+
margin-right: 10px;
|
|
|
|
|
13 |
}
|
14 |
|
15 |
+
.books {
|
16 |
+
display: flex;
|
17 |
+
flex-wrap: wrap;
|
18 |
+
margin: 1rem;
|
19 |
+
justify-content: center;
|
|
|
20 |
}
|
21 |
|
22 |
+
.book {
|
23 |
+
width: 30%;
|
24 |
+
height: 10rem;
|
25 |
+
border: none;
|
26 |
+
border-radius: 10%;
|
27 |
+
margin: 1rem;
|
28 |
}
|
29 |
+
|
30 |
+
.book-title {
|
31 |
+
font-size: 1.2rem;
|
32 |
+
font-weight: bold;
|
33 |
+
}
|
34 |
+
|
35 |
+
.book-author {
|
36 |
+
font-size: 0.8rem;
|
37 |
+
}
|
38 |
+
|
39 |
+
.book-genre {
|
40 |
+
font-size: 0.8rem;
|
41 |
+
}
|
42 |
+
|
43 |
+
.book input {
|
44 |
+
width: 100%;
|
45 |
+
height: 2.5rem;
|
46 |
+
padding-left: 0.5rem;
|
47 |
+
padding-right: 0.5rem;
|
48 |
+
margin-bottom: 0.5rem;
|
49 |
+
}
|
50 |
+
|
51 |
+
button {
|
52 |
+
position: absolute;
|
53 |
+
bottom: 1rem;
|
54 |
+
right: 1rem;
|
55 |
+
z-index: 1;
|
56 |
+
border: none;
|
57 |
+
cursor: pointer;
|
58 |
+
outline: none;
|
59 |
+
padding: 1rem;
|
60 |
+
background-color: #4caf50;
|
61 |
+
color: #fff;
|
62 |
+
font-size: 1rem;
|
63 |
+
text-transform: uppercase;
|
64 |
+
border-radius: 50px;
|
65 |
+
height: 3rem;
|
66 |
+
transition: background-color 0.3s ease;
|
67 |
+
}
|
68 |
+
|
69 |
+
button:hover {
|
70 |
+
background-color: #4cb550;
|
71 |
+
}
|
72 |
+
|
73 |
+
.book {
|
74 |
+
background-color: rgb(255, 255, 255);
|
75 |
+
}
|
76 |
+
|
77 |
+
.book.selected {
|
78 |
+
box-shadow: 0 0 0 2px #4caf50;
|
79 |
+
}
|