mirror of
https://github.com/maunium/stickerpicker
synced 2025-10-14 20:08:09 +00:00
Compare commits
7 Commits
d64a28f02d
...
267c184a52
Author | SHA1 | Date | |
---|---|---|---|
|
267c184a52 | ||
|
4b96d23621 | ||
|
3ce380645d | ||
|
a8effa2efa | ||
|
c8938f7ade | ||
|
c2c9b8f8e2 | ||
|
c8f885ab5b |
1
setup.py
1
setup.py
@ -50,5 +50,6 @@ setuptools.setup(
|
|||||||
entry_points={"console_scripts": [
|
entry_points={"console_scripts": [
|
||||||
"sticker-import=sticker.stickerimport:cmd",
|
"sticker-import=sticker.stickerimport:cmd",
|
||||||
"sticker-pack=sticker.pack:cmd",
|
"sticker-pack=sticker.pack:cmd",
|
||||||
|
"sticker-download-thumbnails=sticker.download_thumbnails:cmd",
|
||||||
]},
|
]},
|
||||||
)
|
)
|
||||||
|
58
sticker/download_thumbnails.py
Normal file
58
sticker/download_thumbnails.py
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
# maunium-stickerpicker - A fast and simple Matrix sticker picker widget.
|
||||||
|
# Copyright (C) 2025 Tulir Asokan
|
||||||
|
#
|
||||||
|
# This program is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU Affero General Public License as published by
|
||||||
|
# the Free Software Foundation, either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU Affero General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU Affero General Public License
|
||||||
|
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
from pathlib import Path
|
||||||
|
from typing import Dict
|
||||||
|
import argparse
|
||||||
|
import asyncio
|
||||||
|
import json
|
||||||
|
|
||||||
|
from aiohttp import ClientSession
|
||||||
|
from yarl import URL
|
||||||
|
|
||||||
|
from .lib import matrix, util
|
||||||
|
|
||||||
|
parser = argparse.ArgumentParser()
|
||||||
|
parser.add_argument("--config",
|
||||||
|
help="Path to JSON file with Matrix homeserver and access_token",
|
||||||
|
type=str, default="config.json", metavar="file")
|
||||||
|
parser.add_argument("path", help="Path to the sticker pack JSON file", type=str)
|
||||||
|
|
||||||
|
|
||||||
|
async def main(args: argparse.Namespace) -> None:
|
||||||
|
await matrix.load_config(args.config)
|
||||||
|
with util.open_utf8(args.path) as pack_file:
|
||||||
|
pack = json.load(pack_file)
|
||||||
|
print(f"Loaded existing pack meta from {args.path}")
|
||||||
|
|
||||||
|
stickers_data: Dict[str, bytes] = {}
|
||||||
|
async with ClientSession() as sess:
|
||||||
|
for sticker in pack["stickers"]:
|
||||||
|
dl_url = URL(matrix.homeserver_url) / "_matrix/client/v1/media/download" / sticker["url"].removeprefix("mxc://")
|
||||||
|
print("Downloading", sticker["url"])
|
||||||
|
async with sess.get(dl_url, headers={"Authorization": f"Bearer {matrix.access_token}"}) as resp:
|
||||||
|
resp.raise_for_status()
|
||||||
|
stickers_data[sticker["url"]] = await resp.read()
|
||||||
|
|
||||||
|
print("All stickers downloaded, generating thumbnails...")
|
||||||
|
util.add_thumbnails(pack["stickers"], stickers_data, Path(args.path).parent)
|
||||||
|
print("Done!")
|
||||||
|
|
||||||
|
def cmd():
|
||||||
|
asyncio.run(main(parser.parse_args()))
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
cmd()
|
@ -59,7 +59,7 @@ async def load_config(path: str) -> None:
|
|||||||
print("Matrix config file not found. Please enter your homeserver and access token.")
|
print("Matrix config file not found. Please enter your homeserver and access token.")
|
||||||
homeserver_url = input("Homeserver URL: ")
|
homeserver_url = input("Homeserver URL: ")
|
||||||
access_token = input("Access token: ")
|
access_token = input("Access token: ")
|
||||||
whoami_url = URL(homeserver_url) / "_matrix" / "client" / "r0" / "account" / "whoami"
|
whoami_url = URL(homeserver_url) / "_matrix" / "client" / "v3" / "account" / "whoami"
|
||||||
if whoami_url.scheme not in ("https", "http"):
|
if whoami_url.scheme not in ("https", "http"):
|
||||||
whoami_url = whoami_url.with_scheme("https")
|
whoami_url = whoami_url.with_scheme("https")
|
||||||
user_id = await whoami(whoami_url, access_token)
|
user_id = await whoami(whoami_url, access_token)
|
||||||
@ -71,7 +71,7 @@ async def load_config(path: str) -> None:
|
|||||||
}, config_file)
|
}, config_file)
|
||||||
print(f"Wrote config to {path}")
|
print(f"Wrote config to {path}")
|
||||||
|
|
||||||
upload_url = URL(homeserver_url) / "_matrix" / "media" / "r0" / "upload"
|
upload_url = URL(homeserver_url) / "_matrix" / "media" / "v3" / "upload"
|
||||||
|
|
||||||
|
|
||||||
async def whoami(url: URL, access_token: str) -> str:
|
async def whoami(url: URL, access_token: str) -> str:
|
||||||
|
@ -17,6 +17,8 @@ from functools import partial
|
|||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
import os.path
|
import os.path
|
||||||
import json
|
import json
|
||||||
|
from pathlib import Path
|
||||||
|
from typing import Dict, List
|
||||||
|
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
|
|
||||||
@ -24,19 +26,19 @@ from . import matrix
|
|||||||
|
|
||||||
open_utf8 = partial(open, encoding='UTF-8')
|
open_utf8 = partial(open, encoding='UTF-8')
|
||||||
|
|
||||||
def convert_image(data: bytes) -> (bytes, int, int):
|
def convert_image(data: bytes, max_w=256, max_h=256) -> (bytes, int, int):
|
||||||
image: Image.Image = Image.open(BytesIO(data)).convert("RGBA")
|
image: Image.Image = Image.open(BytesIO(data)).convert("RGBA")
|
||||||
new_file = BytesIO()
|
new_file = BytesIO()
|
||||||
image.save(new_file, "png")
|
image.save(new_file, "png")
|
||||||
w, h = image.size
|
w, h = image.size
|
||||||
if w > 256 or h > 256:
|
if w > max_w or h > max_h:
|
||||||
# Set the width and height to lower values so clients wouldn't show them as huge images
|
# Set the width and height to lower values so clients wouldn't show them as huge images
|
||||||
if w > h:
|
if w > h:
|
||||||
h = int(h / (w / 256))
|
h = int(h / (w / max_w))
|
||||||
w = 256
|
w = max_w
|
||||||
else:
|
else:
|
||||||
w = int(w / (h / 256))
|
w = int(w / (h / max_h))
|
||||||
h = 256
|
h = max_h
|
||||||
return new_file.getvalue(), w, h
|
return new_file.getvalue(), w, h
|
||||||
|
|
||||||
|
|
||||||
@ -78,3 +80,15 @@ def make_sticker(mxc: str, width: int, height: int, size: int,
|
|||||||
},
|
},
|
||||||
"msgtype": "m.sticker",
|
"msgtype": "m.sticker",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def add_thumbnails(stickers: List[matrix.StickerInfo], stickers_data: Dict[str, bytes], output_dir: str) -> None:
|
||||||
|
thumbnails = Path(output_dir, "thumbnails")
|
||||||
|
thumbnails.mkdir(parents=True, exist_ok=True)
|
||||||
|
|
||||||
|
for sticker in stickers:
|
||||||
|
image_data, _, _ = convert_image(stickers_data[sticker["url"]], 128, 128)
|
||||||
|
|
||||||
|
name = sticker["url"].split("/")[-1]
|
||||||
|
thumbnail_path = thumbnails / name
|
||||||
|
thumbnail_path.write_bytes(image_data)
|
@ -13,6 +13,7 @@
|
|||||||
#
|
#
|
||||||
# You should have received a copy of the GNU Affero General Public License
|
# You should have received a copy of the GNU Affero General Public License
|
||||||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
from pathlib import Path
|
||||||
from typing import Dict, Optional
|
from typing import Dict, Optional
|
||||||
from hashlib import sha256
|
from hashlib import sha256
|
||||||
import mimetypes
|
import mimetypes
|
||||||
@ -107,9 +108,11 @@ async def main(args: argparse.Namespace) -> None:
|
|||||||
old_stickers = {sticker["id"]: sticker for sticker in pack["stickers"]}
|
old_stickers = {sticker["id"]: sticker for sticker in pack["stickers"]}
|
||||||
pack["stickers"] = []
|
pack["stickers"] = []
|
||||||
|
|
||||||
|
stickers_data: Dict[str, bytes] = {}
|
||||||
for file in sorted(os.listdir(args.path)):
|
for file in sorted(os.listdir(args.path)):
|
||||||
sticker = await upload_sticker(file, args.path, old_stickers=old_stickers)
|
sticker = await upload_sticker(file, args.path, old_stickers=old_stickers)
|
||||||
if sticker:
|
if sticker:
|
||||||
|
stickers_data[sticker["url"]] = Path(args.path, file).read_bytes()
|
||||||
pack["stickers"].append(sticker)
|
pack["stickers"].append(sticker)
|
||||||
|
|
||||||
with util.open_utf8(meta_path, "w") as pack_file:
|
with util.open_utf8(meta_path, "w") as pack_file:
|
||||||
@ -122,6 +125,8 @@ async def main(args: argparse.Namespace) -> None:
|
|||||||
with util.open_utf8(picker_pack_path, "w") as pack_file:
|
with util.open_utf8(picker_pack_path, "w") as pack_file:
|
||||||
json.dump(pack, pack_file)
|
json.dump(pack, pack_file)
|
||||||
print(f"Copied pack to {picker_pack_path}")
|
print(f"Copied pack to {picker_pack_path}")
|
||||||
|
|
||||||
|
util.add_thumbnails(pack["stickers"], stickers_data, args.add_to_index)
|
||||||
util.add_to_index(picker_file_name, args.add_to_index)
|
util.add_to_index(picker_file_name, args.add_to_index)
|
||||||
|
|
||||||
|
|
||||||
@ -138,7 +143,7 @@ parser.add_argument("path", help="Path to the sticker pack directory", type=str)
|
|||||||
|
|
||||||
|
|
||||||
def cmd():
|
def cmd():
|
||||||
asyncio.get_event_loop().run_until_complete(main(parser.parse_args()))
|
asyncio.run(main(parser.parse_args()))
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
@ -13,7 +13,7 @@
|
|||||||
#
|
#
|
||||||
# You should have received a copy of the GNU Affero General Public License
|
# You should have received a copy of the GNU Affero General Public License
|
||||||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
from typing import Dict
|
from typing import Dict, Tuple
|
||||||
import argparse
|
import argparse
|
||||||
import asyncio
|
import asyncio
|
||||||
import os.path
|
import os.path
|
||||||
@ -29,7 +29,7 @@ from telethon.tl.types.messages import StickerSet as StickerSetFull
|
|||||||
from .lib import matrix, util
|
from .lib import matrix, util
|
||||||
|
|
||||||
|
|
||||||
async def reupload_document(client: TelegramClient, document: Document) -> matrix.StickerInfo:
|
async def reupload_document(client: TelegramClient, document: Document) -> Tuple[matrix.StickerInfo, bytes]:
|
||||||
print(f"Reuploading {document.id}", end="", flush=True)
|
print(f"Reuploading {document.id}", end="", flush=True)
|
||||||
data = await client.download_media(document, file=bytes)
|
data = await client.download_media(document, file=bytes)
|
||||||
print(".", end="", flush=True)
|
print(".", end="", flush=True)
|
||||||
@ -37,7 +37,7 @@ async def reupload_document(client: TelegramClient, document: Document) -> matri
|
|||||||
print(".", end="", flush=True)
|
print(".", end="", flush=True)
|
||||||
mxc = await matrix.upload(data, "image/png", f"{document.id}.png")
|
mxc = await matrix.upload(data, "image/png", f"{document.id}.png")
|
||||||
print(".", flush=True)
|
print(".", flush=True)
|
||||||
return util.make_sticker(mxc, width, height, len(data))
|
return util.make_sticker(mxc, width, height, len(data)), data
|
||||||
|
|
||||||
|
|
||||||
def add_meta(document: Document, info: matrix.StickerInfo, pack: StickerSetFull) -> None:
|
def add_meta(document: Document, info: matrix.StickerInfo, pack: StickerSetFull) -> None:
|
||||||
@ -75,15 +75,17 @@ async def reupload_pack(client: TelegramClient, pack: StickerSetFull, output_dir
|
|||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
stickers_data: Dict[str, bytes] = {}
|
||||||
reuploaded_documents: Dict[int, matrix.StickerInfo] = {}
|
reuploaded_documents: Dict[int, matrix.StickerInfo] = {}
|
||||||
for document in pack.documents:
|
for document in pack.documents:
|
||||||
try:
|
try:
|
||||||
reuploaded_documents[document.id] = already_uploaded[document.id]
|
reuploaded_documents[document.id] = already_uploaded[document.id]
|
||||||
print(f"Skipped reuploading {document.id}")
|
print(f"Skipped reuploading {document.id}")
|
||||||
except KeyError:
|
except KeyError:
|
||||||
reuploaded_documents[document.id] = await reupload_document(client, document)
|
reuploaded_documents[document.id], data = await reupload_document(client, document)
|
||||||
# Always ensure the body and telegram metadata is correct
|
# Always ensure the body and telegram metadata is correct
|
||||||
add_meta(document, reuploaded_documents[document.id], pack)
|
add_meta(document, reuploaded_documents[document.id], pack)
|
||||||
|
stickers_data[reuploaded_documents[document.id]["url"]] = data
|
||||||
|
|
||||||
for sticker in pack.packs:
|
for sticker in pack.packs:
|
||||||
if not sticker.emoticon:
|
if not sticker.emoticon:
|
||||||
@ -107,6 +109,7 @@ async def reupload_pack(client: TelegramClient, pack: StickerSetFull, output_dir
|
|||||||
}, pack_file, ensure_ascii=False)
|
}, pack_file, ensure_ascii=False)
|
||||||
print(f"Saved {pack.set.title} as {pack.set.short_name}.json")
|
print(f"Saved {pack.set.title} as {pack.set.short_name}.json")
|
||||||
|
|
||||||
|
util.add_thumbnails(list(reuploaded_documents.values()), stickers_data, output_dir)
|
||||||
util.add_to_index(os.path.basename(pack_path), output_dir)
|
util.add_to_index(os.path.basename(pack_path), output_dir)
|
||||||
|
|
||||||
|
|
||||||
@ -158,7 +161,7 @@ async def main(args: argparse.Namespace) -> None:
|
|||||||
|
|
||||||
|
|
||||||
def cmd() -> None:
|
def cmd() -> None:
|
||||||
asyncio.get_event_loop().run_until_complete(main(parser.parse_args()))
|
asyncio.run(main(parser.parse_args()))
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import {Component, html} from "../lib/htm/preact.js";
|
import {Component, html} from "../lib/htm/preact.js";
|
||||||
import * as widgetAPI from "./widget-api.js";
|
import * as widgetAPI from "./widget-api.js";
|
||||||
|
import {Spinner} from "./spinner.js";
|
||||||
import {SearchBox} from "./search-box.js";
|
import {SearchBox} from "./search-box.js";
|
||||||
|
|
||||||
const GIPHY_SEARCH_DEBOUNCE = 1000
|
const GIPHY_SEARCH_DEBOUNCE = 1000
|
||||||
@ -24,6 +25,7 @@ export class GiphySearchTab extends Component {
|
|||||||
searchTerm: "",
|
searchTerm: "",
|
||||||
gifs: [],
|
gifs: [],
|
||||||
loading: false,
|
loading: false,
|
||||||
|
debouncing: false,
|
||||||
error: null,
|
error: null,
|
||||||
}
|
}
|
||||||
this.handleGifClick = this.handleGifClick.bind(this)
|
this.handleGifClick = this.handleGifClick.bind(this)
|
||||||
@ -34,13 +36,14 @@ export class GiphySearchTab extends Component {
|
|||||||
|
|
||||||
async makeGifSearchRequest() {
|
async makeGifSearchRequest() {
|
||||||
try {
|
try {
|
||||||
const resp = await fetch(`https://api.giphy.com/v1/gifs/search?q=${this.state.searchTerm}&api_key=${GIPHY_API_KEY}`)
|
this.setState({gifs: [], debouncing: false, loading: true})
|
||||||
// TODO handle error responses properly?
|
try {
|
||||||
const data = await resp.json()
|
const resp = await fetch(`https://api.giphy.com/v1/gifs/search?q=${this.state.searchTerm}&api_key=${GIPHY_API_KEY}`)
|
||||||
if (data.data.length === 0) {
|
const { data: gifs, meta } = await resp.json()
|
||||||
this.setState({gifs: [], error: "No results"})
|
const error = meta.msg !== 'OK' ? `An issue happened, please try again (${meta.msg})` : null
|
||||||
} else {
|
this.setState({gifs, error, loading: false})
|
||||||
this.setState({gifs: data.data, error: null})
|
} catch (e) {
|
||||||
|
this.setState({gifs: [], error: `An issue happened, please try again (${e.message})`, loading: false})
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.setState({error})
|
this.setState({error})
|
||||||
@ -59,7 +62,7 @@ export class GiphySearchTab extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
updateGifSearchQuery(event) {
|
updateGifSearchQuery(event) {
|
||||||
this.setState({searchTerm: event.target.value})
|
this.setState({searchTerm: event.target.value, debouncing: true})
|
||||||
clearTimeout(this.searchTimeout)
|
clearTimeout(this.searchTimeout)
|
||||||
this.searchTimeout = setTimeout(() => this.makeGifSearchRequest(), GIPHY_SEARCH_DEBOUNCE)
|
this.searchTimeout = setTimeout(() => this.makeGifSearchRequest(), GIPHY_SEARCH_DEBOUNCE)
|
||||||
}
|
}
|
||||||
@ -82,24 +85,36 @@ export class GiphySearchTab extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
// TODO display loading state?
|
|
||||||
return html`
|
return html`
|
||||||
<${SearchBox} onInput=${this.updateGifSearchQuery} onKeyUp=${this.searchKeyUp} value=${this.state.searchTerm} placeholder="Find GIFs"/>
|
<${SearchBox}
|
||||||
|
onInput=${this.updateGifSearchQuery}
|
||||||
|
onKeyUp=${this.searchKeyUp}
|
||||||
|
value=${this.state.searchTerm}
|
||||||
|
loading=${this.state.debouncing}
|
||||||
|
placeholder="Find GIFs"
|
||||||
|
/>
|
||||||
<div class="pack-list">
|
<div class="pack-list">
|
||||||
<section class="stickerpack" id="pack-giphy">
|
<section class="stickerpack" id="pack-giphy">
|
||||||
<div class="error">
|
${this.state.loading ?
|
||||||
${this.state.error}
|
html`<${Spinner} size=${80} green/>` :
|
||||||
</div>
|
html`
|
||||||
<div class="sticker-list">
|
<div class="search-error">
|
||||||
${this.state.gifs.map((gif) => html`
|
${this.state.error}
|
||||||
<div class="sticker" onClick=${() => this.handleGifClick(gif)} data-gif-id=${gif.id}>
|
|
||||||
<img src=${gif.images.fixed_height.url} alt=${gif.title} class="visible" data=/>
|
|
||||||
</div>
|
</div>
|
||||||
`)}
|
${this.state.searchTerm && this.state.gifs.length === 0 && !this.state.error && !this.state.loading
|
||||||
</div>
|
? html`<div class="search-empty">No GIFs match your search</div>`
|
||||||
<div class="footer powered-by-giphy">
|
: null}
|
||||||
<img src="./res/powered-by-giphy.png" alt="Powered by GIPHY"/>
|
<div class="sticker-list">
|
||||||
</div>
|
${this.state.gifs.map((gif) => html`
|
||||||
|
<div class="sticker" onClick=${() => this.handleGifClick(gif)} data-gif-id=${gif.id}>
|
||||||
|
<img src=${gif.images.fixed_height.url} alt=${gif.title} class="visible" data=/>
|
||||||
|
</div>
|
||||||
|
`)}
|
||||||
|
</div>
|
||||||
|
<div class="footer powered-by-giphy">
|
||||||
|
<img src="./res/powered-by-giphy.png" alt="Powered by GIPHY"/>
|
||||||
|
</div>
|
||||||
|
`}
|
||||||
</section>
|
</section>
|
||||||
</div>
|
</div>
|
||||||
`
|
`
|
||||||
|
@ -29,10 +29,8 @@ const params = new URLSearchParams(document.location.search)
|
|||||||
if (params.has('config')) {
|
if (params.has('config')) {
|
||||||
INDEX = params.get("config")
|
INDEX = params.get("config")
|
||||||
}
|
}
|
||||||
// This is updated from packs/index.json
|
|
||||||
let HOMESERVER_URL = "https://matrix-client.matrix.org"
|
|
||||||
|
|
||||||
const makeThumbnailURL = mxc => `${HOMESERVER_URL}/_matrix/media/v3/thumbnail/${mxc.slice(6)}?height=128&width=128&method=scale`
|
const makeThumbnailURL = mxc => `${PACKS_BASE_URL}/thumbnails/${mxc.split("/").slice(-1)[0]}`
|
||||||
|
|
||||||
// We need to detect iOS webkit because it has a bug related to scrolling non-fixed divs
|
// We need to detect iOS webkit because it has a bug related to scrolling non-fixed divs
|
||||||
// This is also used to fix scrolling to sections on Element iOS
|
// This is also used to fix scrolling to sections on Element iOS
|
||||||
@ -165,7 +163,6 @@ class App extends Component {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
const indexData = await indexRes.json()
|
const indexData = await indexRes.json()
|
||||||
HOMESERVER_URL = indexData.homeserver_url || HOMESERVER_URL
|
|
||||||
if (indexData.giphy_api_key !== undefined) {
|
if (indexData.giphy_api_key !== undefined) {
|
||||||
setGiphyAPIKey(indexData.giphy_api_key, indexData.giphy_mxc_prefix)
|
setGiphyAPIKey(indexData.giphy_api_key, indexData.giphy_mxc_prefix)
|
||||||
}
|
}
|
||||||
@ -325,7 +322,7 @@ class App extends Component {
|
|||||||
<${SearchBox} onInput=${this.searchStickers} value=${this.state.filtering.searchTerm ?? ""}/>
|
<${SearchBox} onInput=${this.searchStickers} value=${this.state.filtering.searchTerm ?? ""}/>
|
||||||
<div class="pack-list ${isMobileSafari ? "ios-safari-hack" : ""}" ref=${(elem) => (this.packListRef = elem)}>
|
<div class="pack-list ${isMobileSafari ? "ios-safari-hack" : ""}" ref=${(elem) => (this.packListRef = elem)}>
|
||||||
${filterActive && packs.length === 0
|
${filterActive && packs.length === 0
|
||||||
? html`<div class="search-empty"><h1>No stickers match your search</h1></div>`
|
? html`<div class="search-empty">No stickers match your search</div>`
|
||||||
: null}
|
: null}
|
||||||
${packs.map((pack) => html`<${Pack} id=${pack.id} pack=${pack} send=${this.sendSticker}/>`)}
|
${packs.map((pack) => html`<${Pack} id=${pack.id} pack=${pack} send=${this.sendSticker}/>`)}
|
||||||
<${Settings} app=${this}/>
|
<${Settings} app=${this}/>
|
||||||
|
@ -14,12 +14,15 @@
|
|||||||
// You should have received a copy of the GNU Affero General Public License
|
// You should have received a copy of the GNU Affero General Public License
|
||||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
import {html} from "../lib/htm/preact.js"
|
import {html} from "../lib/htm/preact.js"
|
||||||
|
import {Spinner} from "./spinner.js";
|
||||||
|
|
||||||
export const SearchBox = ({onInput, onKeyUp, value, placeholder = 'Find stickers'}) => {
|
export const SearchBox = ({onInput, onKeyUp, value, loading = false, placeholder = 'Find stickers'}) => {
|
||||||
const component = html`
|
const component = html`
|
||||||
<div class="search-box">
|
<div class="search-box">
|
||||||
<input type="text" placeholder=${placeholder} value=${value} onInput=${onInput} onKeyUp=${onKeyUp}/>
|
<input type="text" placeholder=${placeholder} value=${value} onInput=${onInput} onKeyUp=${onKeyUp}/>
|
||||||
<span class="icon icon-search"/>
|
${!loading ?
|
||||||
|
html`<span class="icon icon-search"/>` :
|
||||||
|
html`<div class="search-spinner"><${Spinner} size=${14}/></div>`}
|
||||||
</div>
|
</div>
|
||||||
`
|
`
|
||||||
return component
|
return component
|
||||||
|
@ -1 +1 @@
|
|||||||
*{font-family:sans-serif}body{margin:0}h1{font-size:1rem}:root{--stickers-per-row: 4;--sticker-size: calc(100vw / var(--stickers-per-row))}main{color:var(--text-color)}main.spinner{margin-top:5rem}main.error,main.empty{margin:2rem}main.empty{text-align:center}main.has-content{position:fixed;top:0;left:0;right:0;bottom:0;display:grid;grid-template-rows:calc(12vw + 2px) min-content auto}main.theme-light{--highlight-color: #eee;--search-box-color: var(--highlight-color);--text-color: black;background-color:#fff}main.theme-dark{--highlight-color: #444;--search-box-color: #383e4b;--text-color: white;background-color:#22262e}main.theme-dark .icon.icon-giphy{background-image:url(../res/giphy-dark.svg)}main.theme-black{--highlight-color: #222;--search-box-color: var(--highlight-color);--text-color: white;background-color:#000}main.theme-black .icon.icon-giphy{background-image:url(../res/giphy-dark.svg)}div.powered-by-giphy{padding:1rem}div.powered-by-giphy>img{width:100%}.icon{width:100%;height:100%;background-color:var(--text-color);mask-size:contain;-webkit-mask-size:contain;mask-image:var(--icon-image);-webkit-mask-image:var(--icon-image)}.icon.icon-settings{--icon-image: url(../res/settings.svg)}.icon.icon-recent{--icon-image: url(../res/recent.svg)}.icon.icon.icon-search{--icon-image: url(../res/search.svg)}.icon.icon.icon-giphy{background:center/contain no-repeat url(../res/giphy-light.svg);mask:unset}nav{display:flex;overflow-x:auto}nav>a{border-bottom:2px solid rgba(0,0,0,0)}nav>a.visible{border-bottom-color:green}nav>a>div.sticker{width:12vw;height:12vw}div.pack-list,nav{scrollbar-width:none}div.pack-list::-webkit-scrollbar,nav::-webkit-scrollbar{display:none}div.pack-list{overflow-y:auto}div.pack-list.ios-safari-hack{position:fixed;top:calc(calc(12vw + 2px) + calc(2 * 0.7rem + 2 * 0.5rem + 1rem));bottom:0;left:0;right:0;-webkit-overflow-scrolling:touch}div.search-empty{margin:1.2rem;text-align:center}section.stickerpack{margin-top:.75rem}section.stickerpack>div.sticker-list{display:flex;flex-wrap:wrap}section.stickerpack>h1{margin:0 0 0 .75rem}section.stickerpack#pack-giphy{display:flex;justify-content:space-between;flex-direction:column;min-height:100%}div.sticker{display:flex;padding:4px;cursor:pointer;position:relative;width:var(--sticker-size);height:var(--sticker-size);box-sizing:border-box}div.sticker:hover{background-color:var(--highlight-color)}div.sticker>img{display:none;width:100%;object-fit:contain}div.sticker>img.visible{display:initial}div.sticker>.icon{width:70%;height:70%;margin:15%}div.search-box{position:relative;display:flex}div.search-box>input[type=text]{flex-grow:1;background-color:var(--search-box-color);outline:none;border:none;border-radius:.25rem;height:1rem;padding:.7rem;padding-right:calc(1rem + 0.7rem);margin:.5rem;font-size:1rem;color:var(--text-color)}div.search-box>span.icon{display:flex;position:absolute;top:calc(50% - 1rem/2);right:1rem;width:1rem;height:1rem;box-sizing:border-box}div.settings-list{display:flex;flex-direction:column}div.settings-list>*{margin:.5rem}div.settings-list button{padding:.5rem;border-radius:.25rem}div.settings-list input{width:100%}
|
*{font-family:sans-serif}body{margin:0}h1{font-size:1rem}:root{--stickers-per-row: 4;--sticker-size: calc(100vw / var(--stickers-per-row))}main{color:var(--text-color)}main.spinner{margin-top:5rem}main.error,main.empty{margin:2rem}main.empty{text-align:center}main.has-content{position:fixed;top:0;left:0;right:0;bottom:0;display:grid;grid-template-rows:calc(12vw + 2px) min-content auto}main.theme-light{--highlight-color: #eee;--search-box-color: var(--highlight-color);--text-color: black;background-color:#fff}main.theme-dark{--highlight-color: #444;--search-box-color: #383e4b;--text-color: white;background-color:#22262e}main.theme-dark .icon.icon-giphy{background-image:url(../res/giphy-dark.svg)}main.theme-black{--highlight-color: #222;--search-box-color: var(--highlight-color);--text-color: white;background-color:#000}main.theme-black .icon.icon-giphy{background-image:url(../res/giphy-dark.svg)}div.powered-by-giphy{padding:1rem}div.powered-by-giphy>img{width:100%}.icon{width:100%;height:100%;background-color:var(--text-color);mask-size:contain;-webkit-mask-size:contain;mask-image:var(--icon-image);-webkit-mask-image:var(--icon-image)}.icon.icon-settings{--icon-image: url(../res/settings.svg)}.icon.icon-recent{--icon-image: url(../res/recent.svg)}.icon.icon.icon-search{--icon-image: url(../res/search.svg)}.icon.icon.icon-giphy{background:center/contain no-repeat url(../res/giphy-light.svg);mask:unset}nav{display:flex;overflow-x:auto}nav>a{border-bottom:2px solid transparent}nav>a.visible{border-bottom-color:green}nav>a>div.sticker{width:12vw;height:12vw}div.pack-list,nav{scrollbar-width:none}div.pack-list::-webkit-scrollbar,nav::-webkit-scrollbar{display:none}div.pack-list{overflow-y:auto}div.pack-list.ios-safari-hack{position:fixed;top:calc(calc(12vw + 2px) + calc(2 * 0.7rem + 2 * 0.5rem + 1rem));bottom:0;left:0;right:0;-webkit-overflow-scrolling:touch}div.search-error,div.search-empty{margin:1.2rem;text-align:center;font-weight:bold}div.search-error{color:#c43e3e}section.stickerpack{margin-top:.75rem}section.stickerpack>div.sticker-list{display:flex;flex-wrap:wrap}section.stickerpack>h1{margin:0 0 0 .75rem}section.stickerpack#pack-giphy{display:flex;justify-content:space-between;flex-direction:column;min-height:100%}div.sticker{display:flex;padding:4px;cursor:pointer;position:relative;width:var(--sticker-size);height:var(--sticker-size);box-sizing:border-box}div.sticker:hover{background-color:var(--highlight-color)}div.sticker>img{display:none;width:100%;object-fit:contain}div.sticker>img.visible{display:initial}div.sticker>.icon{width:70%;height:70%;margin:15%}div.search-box{position:relative;display:flex}div.search-box>input[type=text]{flex-grow:1;background-color:var(--search-box-color);outline:none;border:none;border-radius:.25rem;height:1rem;padding:.7rem;padding-right:calc(1rem + 0.7rem);margin:.5rem;font-size:1rem;color:var(--text-color)}div.search-box>.search-spinner,div.search-box>span.icon{display:flex;position:absolute;top:calc(50% - 1rem / 2);right:1rem;width:1rem;height:1rem;box-sizing:border-box}div.settings-list{display:flex;flex-direction:column}div.settings-list>*{margin:.5rem}div.settings-list button{padding:.5rem;border-radius:.25rem}div.settings-list input{width:100%}
|
||||||
|
@ -141,9 +141,14 @@ div.pack-list.ios-safari-hack
|
|||||||
right: 0
|
right: 0
|
||||||
-webkit-overflow-scrolling: touch
|
-webkit-overflow-scrolling: touch
|
||||||
|
|
||||||
|
div.search-error,
|
||||||
div.search-empty
|
div.search-empty
|
||||||
margin: 1.2rem
|
margin: 1.2rem
|
||||||
text-align: center
|
text-align: center
|
||||||
|
font-weight: bold
|
||||||
|
|
||||||
|
div.search-error
|
||||||
|
color: #c43e3e
|
||||||
|
|
||||||
section.stickerpack
|
section.stickerpack
|
||||||
margin-top: .75rem
|
margin-top: .75rem
|
||||||
@ -203,6 +208,7 @@ div.search-box
|
|||||||
font-size: 1rem
|
font-size: 1rem
|
||||||
color: var(--text-color)
|
color: var(--text-color)
|
||||||
|
|
||||||
|
>.search-spinner,
|
||||||
>span.icon
|
>span.icon
|
||||||
display: flex
|
display: flex
|
||||||
position: absolute
|
position: absolute
|
||||||
|
@ -1 +1 @@
|
|||||||
.sk-center-wrapper{width:100%;display:flex;justify-content:space-around}.sk-chase{position:relative;animation:sk-chase 2.5s infinite linear both}.sk-chase.green>.sk-chase-dot:before{background-color:#00c853}.sk-chase>.sk-chase-dot{width:100%;height:100%;position:absolute;left:0;top:0;animation:sk-chase-dot 2s infinite ease-in-out both}.sk-chase>.sk-chase-dot:before{content:"";display:block;width:25%;height:25%;border-radius:100%;animation:sk-chase-dot-before 2s infinite ease-in-out both;background-color:#fff}.sk-chase>.sk-chase-dot:nth-child(1){animation-delay:-1.1s}.sk-chase>.sk-chase-dot:nth-child(2){animation-delay:-1s}.sk-chase>.sk-chase-dot:nth-child(3){animation-delay:-0.9s}.sk-chase>.sk-chase-dot:nth-child(4){animation-delay:-0.8s}.sk-chase>.sk-chase-dot:nth-child(5){animation-delay:-0.7s}.sk-chase>.sk-chase-dot:nth-child(6){animation-delay:-0.6s}.sk-chase>.sk-chase-dot:nth-child(1):before{animation-delay:-1.1s}.sk-chase>.sk-chase-dot:nth-child(2):before{animation-delay:-1s}.sk-chase>.sk-chase-dot:nth-child(3):before{animation-delay:-0.9s}.sk-chase>.sk-chase-dot:nth-child(4):before{animation-delay:-0.8s}.sk-chase>.sk-chase-dot:nth-child(5):before{animation-delay:-0.7s}.sk-chase>.sk-chase-dot:nth-child(6):before{animation-delay:-0.6s}@keyframes sk-chase{100%{transform:rotate(360deg)}}@keyframes sk-chase-dot{80%,100%{transform:rotate(360deg)}}@keyframes sk-chase-dot-before{50%{transform:scale(0.4)}100%,0%{transform:scale(1)}}
|
.sk-center-wrapper{width:100%;display:flex;justify-content:space-around}.sk-chase{position:relative;animation:sk-chase 2.5s infinite linear both}.sk-chase.green>.sk-chase-dot:before{background-color:#00c853}.sk-chase>.sk-chase-dot{width:100%;height:100%;position:absolute;left:0;top:0;animation:sk-chase-dot 2s infinite ease-in-out both}.sk-chase>.sk-chase-dot:before{content:"";display:block;width:25%;height:25%;border-radius:100%;animation:sk-chase-dot-before 2s infinite ease-in-out both;background-color:var(--text-color)}.sk-chase>.sk-chase-dot:nth-child(1){animation-delay:-1.1s}.sk-chase>.sk-chase-dot:nth-child(2){animation-delay:-1s}.sk-chase>.sk-chase-dot:nth-child(3){animation-delay:-0.9s}.sk-chase>.sk-chase-dot:nth-child(4){animation-delay:-0.8s}.sk-chase>.sk-chase-dot:nth-child(5){animation-delay:-0.7s}.sk-chase>.sk-chase-dot:nth-child(6){animation-delay:-0.6s}.sk-chase>.sk-chase-dot:nth-child(1):before{animation-delay:-1.1s}.sk-chase>.sk-chase-dot:nth-child(2):before{animation-delay:-1s}.sk-chase>.sk-chase-dot:nth-child(3):before{animation-delay:-0.9s}.sk-chase>.sk-chase-dot:nth-child(4):before{animation-delay:-0.8s}.sk-chase>.sk-chase-dot:nth-child(5):before{animation-delay:-0.7s}.sk-chase>.sk-chase-dot:nth-child(6):before{animation-delay:-0.6s}@keyframes sk-chase{100%{transform:rotate(360deg)}}@keyframes sk-chase-dot{80%,100%{transform:rotate(360deg)}}@keyframes sk-chase-dot-before{50%{transform:scale(0.4)}100%,0%{transform:scale(1)}}
|
||||||
|
@ -26,7 +26,7 @@
|
|||||||
height: 25%
|
height: 25%
|
||||||
border-radius: 100%
|
border-radius: 100%
|
||||||
animation: sk-chase-dot-before 2.0s infinite ease-in-out both
|
animation: sk-chase-dot-before 2.0s infinite ease-in-out both
|
||||||
background-color: #FFF
|
background-color: var(--text-color)
|
||||||
|
|
||||||
&:nth-child(1)
|
&:nth-child(1)
|
||||||
animation-delay: -1.1s
|
animation-delay: -1.1s
|
||||||
|
Loading…
x
Reference in New Issue
Block a user