mirror of
https://github.com/BetterSEQTA/BetterSEQTA-Plus.git
synced 2026-12-06 19:56:45 +10:30
Compare commits
116
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fde375ecf2 | ||
|
|
9f80ba11f1 | ||
|
|
8ccddc1ae0 | ||
|
|
de75cb4666 | ||
|
|
e1408fe35d | ||
|
|
a93c3ccda7 | ||
|
|
7685df564d | ||
|
|
57a80d6b54 | ||
|
|
3c90498e4d | ||
|
|
4f10930f24 | ||
|
|
dde5096d1c | ||
|
|
a411d646ae | ||
|
|
6688a53acc | ||
|
|
d47658ed59 | ||
|
|
a8fe3e57f1 | ||
|
|
d4ff9d2567 | ||
|
|
8e453d3877 | ||
|
|
b7ee5a54da | ||
|
|
12833f9270 | ||
|
|
f0247428a0 | ||
|
|
f35b715f4e | ||
|
|
574de5ccbf | ||
|
|
0333f24a60 | ||
|
|
5d9821a642 | ||
|
|
b830f53069 | ||
|
|
eaf89d3f12 | ||
|
|
653b1d23c2 | ||
|
|
c2ddd67021 | ||
|
|
835620fd67 | ||
|
|
3b41fef253 | ||
|
|
07b29c8d31 | ||
|
|
ddbccecda2 | ||
|
|
defaf76144 | ||
|
|
d5882e2d66 | ||
|
|
318000009f | ||
|
|
fe7127a83c | ||
|
|
c5ab69ba82 | ||
|
|
88926aaee7 | ||
|
|
928f05ec8e | ||
|
|
b5347e2732 | ||
|
|
f926127687 | ||
|
|
17e077d531 | ||
|
|
87c320a1aa | ||
|
|
e732011f1e | ||
|
|
c439d8d88f | ||
|
|
c231a00db3 | ||
|
|
824cedca2f | ||
|
|
10db972ef4 | ||
|
|
a48d71ddd8 | ||
|
|
cf6e797510 | ||
|
|
c015c8a162 | ||
|
|
3ef1add585 | ||
|
|
3bac45032d | ||
|
|
b1fb8e8f10 | ||
|
|
fdf941b968 | ||
|
|
34c536c2d8 | ||
|
|
ef9d7cf7f8 | ||
|
|
27c8c3c24f | ||
|
|
b2187f4c61 | ||
|
|
1c3d1b745e | ||
|
|
2697b92981 | ||
|
|
5502f07721 | ||
|
|
4fda63dedd | ||
|
|
7779edb063 | ||
|
|
f4230e02b9 | ||
|
|
dcb4dd2f5e | ||
|
|
6c9bec4a99 | ||
|
|
6518999ac5 | ||
|
|
01223c466e | ||
|
|
95da84ff16 | ||
|
|
bdb1911e74 | ||
|
|
3213d0ca28 | ||
|
|
d34333ca38 | ||
|
|
2163f06de9 | ||
|
|
eae2e0587c | ||
|
|
fe1c2f0250 | ||
|
|
e6b8be6821 | ||
|
|
bd13042fe4 | ||
|
|
1045d38f47 | ||
|
|
9a9eb91a2d | ||
|
|
b4aca7277b | ||
|
|
e0ee41c270 | ||
|
|
e10c5fe2c4 | ||
|
|
174f47f8c2 | ||
|
|
006589ca76 | ||
|
|
abcbca3745 | ||
|
|
c368d89295 | ||
|
|
ca4cbea0f0 | ||
|
|
75c65b1d5e | ||
|
|
c02388750c | ||
|
|
e400890eee | ||
|
|
969c3bbdd5 | ||
|
|
670f9d73f3 | ||
|
|
fc124e71ed | ||
|
|
a409dc3f20 | ||
|
|
c9b9ad250e | ||
|
|
74a6ae5108 | ||
|
|
6b6a383159 | ||
|
|
410c953933 | ||
|
|
5df9169705 | ||
|
|
fadc06aa27 | ||
|
|
a106033b87 | ||
|
|
d99198ea12 | ||
|
|
79d68c812c | ||
|
|
37ae32be59 | ||
|
|
6f7788497a | ||
|
|
4b7aa8da75 | ||
|
|
2be27299a5 | ||
|
|
fadbca5969 | ||
|
|
f570e47e27 | ||
|
|
e3ec6c80d0 | ||
|
|
a3bdb0fe09 | ||
|
|
5d8cb55b94 | ||
|
|
d10fca6c0f | ||
|
|
62ed702e64 | ||
|
|
8a5424c5a4 |
No files matched your search
@@ -0,0 +1,3 @@
|
||||
# Optional OAuth client ID overrides (secrets live on accounts.betterseqta.org)
|
||||
# GOOGLE_OAUTH_CLIENT_ID=your-id.apps.googleusercontent.com
|
||||
# OUTLOOK_OAUTH_CLIENT_ID=your-azure-application-client-id
|
||||
@@ -33,14 +33,8 @@ outputs:
|
||||
runs:
|
||||
using: composite
|
||||
steps:
|
||||
- name: Use Node.js 20.x
|
||||
uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: 20.x
|
||||
|
||||
- name: Install dependencies
|
||||
shell: bash
|
||||
run: npm install --legacy-peer-deps
|
||||
- name: Setup Node and dependencies
|
||||
uses: ./.github/actions/setup-node-deps
|
||||
|
||||
- name: Read version
|
||||
id: version
|
||||
@@ -62,14 +56,4 @@ runs:
|
||||
env:
|
||||
UPDATE_CHANNEL: ${{ inputs.update_channel }}
|
||||
BUILD_LABEL: ${{ inputs.build_label }}
|
||||
run: |
|
||||
VERSION="${{ steps.version.outputs.version }}"
|
||||
if [ "$UPDATE_CHANNEL" = "nightly" ] && [ -n "$BUILD_LABEL" ]; then
|
||||
BASE="betterseqtaplus-nightly-${BUILD_LABEL}"
|
||||
else
|
||||
BASE="betterseqtaplus-${VERSION}"
|
||||
fi
|
||||
(cd dist/chrome && zip -r "../${BASE}-chrome.zip" .)
|
||||
(cd dist/firefox && zip -r "../${BASE}-firefox.zip" .)
|
||||
echo "chrome_zip=dist/${BASE}-chrome.zip" >> "$GITHUB_OUTPUT"
|
||||
echo "firefox_zip=dist/${BASE}-firefox.zip" >> "$GITHUB_OUTPUT"
|
||||
run: node scripts/package-extension-zips.mjs "${{ steps.version.outputs.version }}"
|
||||
@@ -0,0 +1,11 @@
|
||||
name: Run lint
|
||||
description: Run ESLint on src.
|
||||
|
||||
runs:
|
||||
using: composite
|
||||
steps:
|
||||
- name: Lint
|
||||
shell: bash
|
||||
run: npm run lint
|
||||
env:
|
||||
ESLINT_USE_FLAT_CONFIG: "false"
|
||||
@@ -0,0 +1,9 @@
|
||||
name: Run smoke tests
|
||||
description: Verify built extension dist output.
|
||||
|
||||
runs:
|
||||
using: composite
|
||||
steps:
|
||||
- name: Smoke tests
|
||||
shell: bash
|
||||
run: npm run test:smoke
|
||||
@@ -0,0 +1,9 @@
|
||||
name: Run unit tests
|
||||
description: Run Jest unit tests.
|
||||
|
||||
runs:
|
||||
using: composite
|
||||
steps:
|
||||
- name: Unit tests
|
||||
shell: bash
|
||||
run: npm run test:unit
|
||||
@@ -0,0 +1,14 @@
|
||||
name: Setup Node and dependencies
|
||||
description: Install Node.js 22.x and npm dependencies.
|
||||
|
||||
runs:
|
||||
using: composite
|
||||
steps:
|
||||
- name: Use Node.js 22.x
|
||||
uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: 22.x
|
||||
|
||||
- name: Install dependencies
|
||||
shell: bash
|
||||
run: npm install --legacy-peer-deps
|
||||
@@ -1,36 +0,0 @@
|
||||
name: NodeJS Build
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: ["main"]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
strategy:
|
||||
matrix:
|
||||
node-version: [20.x]
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Use Node.js ${{ matrix.node-version }}
|
||||
uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: ${{ matrix.node-version }}
|
||||
|
||||
- name: Build
|
||||
run: |
|
||||
npm install --legacy-peer-deps
|
||||
npm run build
|
||||
|
||||
- name: Zip dist folder
|
||||
run: |
|
||||
zip -r dist.zip dist
|
||||
|
||||
- name: Upload artifact
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: dist-zip
|
||||
path: dist.zip
|
||||
@@ -1,11 +1,18 @@
|
||||
# Nightly release workflow — updates the same "nightly" release with fresh builds from main.
|
||||
# Runs only on BetterSEQTA/BetterSEQTA-Plus. Uses the default GITHUB_TOKEN.
|
||||
#
|
||||
# Scheduled at midnight Australia/Adelaide (ACST/ACDT). GitHub cron is UTC-only, so we
|
||||
# trigger at 13:30 and 14:30 UTC and only proceed when Adelaide local time is 00:00.
|
||||
# Builds on windows-latest (matches local dev; Linux nightly builds were failing on Vite/Svelte).
|
||||
|
||||
name: Nightly Release
|
||||
|
||||
on:
|
||||
schedule:
|
||||
- cron: "0 3 * * *"
|
||||
# 13:30 UTC = 00:00 Adelaide during daylight saving (ACDT, UTC+10:30)
|
||||
- cron: "30 13 * * *"
|
||||
# 14:30 UTC = 00:00 Adelaide during standard time (ACST, UTC+9:30)
|
||||
- cron: "30 14 * * *"
|
||||
workflow_dispatch:
|
||||
|
||||
permissions:
|
||||
@@ -13,19 +20,42 @@ permissions:
|
||||
|
||||
env:
|
||||
NIGHTLY_TAG: nightly
|
||||
GH_TOKEN: ${{ github.token }}
|
||||
|
||||
jobs:
|
||||
nightly:
|
||||
runs-on: ubuntu-latest
|
||||
runs-on: windows-latest
|
||||
defaults:
|
||||
run:
|
||||
shell: bash
|
||||
steps:
|
||||
- name: Check Adelaide midnight
|
||||
id: time_check
|
||||
run: |
|
||||
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
|
||||
echo "proceed=true" >> "$GITHUB_OUTPUT"
|
||||
exit 0
|
||||
fi
|
||||
export TZ=Australia/Adelaide
|
||||
NOW="$(date +'%Y-%m-%d %H:%M %Z')"
|
||||
if [ "$(date +%H%M)" = "0000" ]; then
|
||||
echo "proceed=true" >> "$GITHUB_OUTPUT"
|
||||
else
|
||||
echo "proceed=false" >> "$GITHUB_OUTPUT"
|
||||
echo "Skipping: not midnight Australia/Adelaide ($NOW)"
|
||||
fi
|
||||
|
||||
- uses: actions/checkout@v4
|
||||
if: steps.time_check.outputs.proceed == 'true'
|
||||
|
||||
- name: Set build date
|
||||
id: build_date
|
||||
run: echo "date=$(date -u +'%Y-%m-%d')" >> "$GITHUB_OUTPUT"
|
||||
if: steps.time_check.outputs.proceed == 'true'
|
||||
run: echo "date=$(TZ=Australia/Adelaide date +'%Y-%m-%d')" >> "$GITHUB_OUTPUT"
|
||||
|
||||
- name: Build extension
|
||||
id: build
|
||||
if: steps.time_check.outputs.proceed == 'true'
|
||||
uses: ./.github/actions/build-extension
|
||||
with:
|
||||
gh_release_update_check: "true"
|
||||
@@ -34,6 +64,7 @@ jobs:
|
||||
release_repo: ${{ github.repository }}
|
||||
|
||||
- name: Ensure nightly release exists
|
||||
if: steps.time_check.outputs.proceed == 'true'
|
||||
run: |
|
||||
TITLE="Nightly (${{ steps.build_date.outputs.date }})"
|
||||
if ! gh release view "${{ env.NIGHTLY_TAG }}" 2>/dev/null; then
|
||||
@@ -46,6 +77,7 @@ jobs:
|
||||
fi
|
||||
|
||||
- name: Upload nightly assets
|
||||
if: steps.time_check.outputs.proceed == 'true'
|
||||
run: |
|
||||
gh release upload "${{ env.NIGHTLY_TAG }}" \
|
||||
--clobber \
|
||||
|
||||
+45
-17
@@ -1,35 +1,63 @@
|
||||
name: PR CI
|
||||
name: CI
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
branches: ["main"]
|
||||
push:
|
||||
branches: ["main"]
|
||||
|
||||
jobs:
|
||||
ci:
|
||||
runs-on: ubuntu-latest
|
||||
lint:
|
||||
# windows-latest: Vite/Svelte build fails on Linux CI for layerchart vendor .svelte (see nightly.yml).
|
||||
runs-on: windows-latest
|
||||
defaults:
|
||||
run:
|
||||
shell: bash
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Use Node.js 20.x
|
||||
uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: 20.x
|
||||
- name: Setup Node and dependencies
|
||||
uses: ./.github/actions/setup-node-deps
|
||||
|
||||
- name: Install dependencies
|
||||
run: npm install --legacy-peer-deps
|
||||
- name: Run lint
|
||||
uses: ./.github/actions/run-lint
|
||||
|
||||
- name: Lint
|
||||
run: npm run lint
|
||||
env:
|
||||
ESLINT_USE_FLAT_CONFIG: "false"
|
||||
unit-tests:
|
||||
runs-on: windows-latest
|
||||
defaults:
|
||||
run:
|
||||
shell: bash
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Unit tests
|
||||
run: npm test
|
||||
- name: Setup Node and dependencies
|
||||
uses: ./.github/actions/setup-node-deps
|
||||
|
||||
- name: Run unit tests
|
||||
uses: ./.github/actions/run-unit-tests
|
||||
|
||||
build-and-smoke:
|
||||
needs: [lint, unit-tests]
|
||||
runs-on: windows-latest
|
||||
defaults:
|
||||
run:
|
||||
shell: bash
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Build extension
|
||||
id: build
|
||||
uses: ./.github/actions/build-extension
|
||||
with:
|
||||
gh_release_update_check: "false"
|
||||
|
||||
- name: Smoke tests
|
||||
run: npm run test:smoke
|
||||
- name: Upload extension zips
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: extension-zips
|
||||
path: |
|
||||
${{ steps.build.outputs.chrome_zip }}
|
||||
${{ steps.build.outputs.firefox_zip }}
|
||||
|
||||
- name: Run smoke tests
|
||||
uses: ./.github/actions/run-smoke-tests
|
||||
@@ -16,6 +16,9 @@ on:
|
||||
permissions:
|
||||
contents: write
|
||||
|
||||
env:
|
||||
GH_TOKEN: ${{ github.token }}
|
||||
|
||||
jobs:
|
||||
release:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
@@ -9,6 +9,9 @@ bun.lock
|
||||
# PDF.js extension assets (copied by postinstall from pdfjs-dist)
|
||||
src/public/resources/pdfjs/pdf.worker.min.mjs
|
||||
src/public/resources/pdfjs/pdf.legacy.min.mjs
|
||||
# ONNX Runtime WASM assets (copied by postinstall from @huggingface/transformers)
|
||||
src/public/resources/ort/ort-wasm-simd-threaded.jsep.mjs
|
||||
src/public/resources/ort/ort-wasm-simd-threaded.jsep.wasm
|
||||
|
||||
# Build
|
||||
extension.zip
|
||||
@@ -25,3 +28,5 @@ betterseqtaplus-safari/
|
||||
.env.submit
|
||||
dependency-graph.svg
|
||||
|
||||
update-videos/
|
||||
|
||||
@@ -3,11 +3,11 @@
|
||||
</a>
|
||||
|
||||
<p align="center">
|
||||
A beautiful 🤩 Chrome Extension that adds additional features and gives an overall better experience for <a href="https://educationhorizons.com/solutions/seqta/">SEQTA Learn.</a> <strong>Currently looking for contributors</strong> 🔥
|
||||
A beautiful 🤩 browser extension that transforms <a href="https://www.tes.com/en-au/for-schools/seqta">SEQTA</a> with modern themes, powerful customization, productivity tools, and an improved user experience. Contributions are always welcome!
|
||||
</p>
|
||||
|
||||
<p align="center">
|
||||
<a target="_blank" href="https://chrome.google.com/webstore/detail/betterseqta%20/afdgaoaclhkhemfkkkonemoapeinchel"><img src="https://user-images.githubusercontent.com/95666457/149519713-159d7ef7-2c21-4034-a616-f037ff46d9a4.png" alt="ChromeDownload" width="250"></a>
|
||||
<a target="_blank" href="https://chromewebstore.google.com/detail/betterseqta+/afdgaoaclhkhemfkkkonemoapeinchel"><img src="https://user-images.githubusercontent.com/95666457/149519713-159d7ef7-2c21-4034-a616-f037ff46d9a4.png" alt="ChromeDownload" width="250"></a>
|
||||
<a target="_blank" href="https://discord.gg/YzmbnCDkat"><img src="https://github.com/BetterSEQTA/BetterSEQTA-Plus/assets/108050083/23055730-b16e-44c0-9bef-221d8545af92" width="240" style="border-radius:10%;" /></a>
|
||||
</p>
|
||||
|
||||
@@ -16,15 +16,16 @@
|
||||
<img src="https://img.shields.io/chrome-web-store/rating/afdgaoaclhkhemfkkkonemoapeinchel" />
|
||||
</div>
|
||||
|
||||
## 📚 Documentation
|
||||
All documentation has been moved to the [official docs site](https://docs.betterseqta.org):
|
||||
## Documentation
|
||||
|
||||
Everything you need to get started with BetterSEQTA+ can be found in the [official documentation](https://docs.betterseqta.org).
|
||||
|
||||
Includes:
|
||||
- Getting started
|
||||
- Development setup
|
||||
- Getting Started
|
||||
- Installation & Development
|
||||
- Architecture
|
||||
- Plugin system
|
||||
- Theme creation
|
||||
- Plugin System
|
||||
- Theme Creation
|
||||
|
||||
## Features
|
||||
|
||||
@@ -72,8 +73,7 @@ npm run dev
|
||||
Then load `dist` in `chrome://extensions` (Developer Mode → Load unpacked).
|
||||
|
||||
|
||||
Full setup guide:
|
||||
[https://betterseqta.github.io/BetterSEQTA-Docs/install/#for-developers-development-environment](https://betterseqta.github.io/BetterSEQTA-Docs/install/#for-developers-development-environment)
|
||||
Full development setup guide can be found [here](https://docs.betterseqta.org/install/#for-developers-development-environment).
|
||||
|
||||
## Contributors
|
||||
|
||||
@@ -85,10 +85,9 @@ Want to contribute? [Click Here!](https://docs.betterseqta.org/contributing/)
|
||||
|
||||
## Credits
|
||||
|
||||
This extension was initially developed by [Nulkem](https://github.com/Nulkem/betterseqta), was ported to manifest V3 by [MEGA-Dawg68](https://github.com/MEGA-Dawg68) and is currently under active development from lead developers [SethBurkart123](https://github.com/SethBurkart123) and [Crazypersonalph](https://github.com/Crazypersonalph) with help from other volunteers.
|
||||
Originally developed by [Nulkem](https://github.com/Nulkem/betterseqta)
|
||||
Ported to Manifest V3 by [MEGA-Dawg68](https://github.com/MEGA-Dawg68)
|
||||
Maintained by [SethBurkart123](https://github.com/SethBurkart123), [Crazypersonalph](https://github.com/Crazypersonalph) & the rest of the BetterSEQTA team!
|
||||
Originally developed by [Nulkem](https://github.com/Nulkem/betterseqta)
|
||||
Ported to Manifest V3 by [MEGA-Dawg68](https://github.com/MEGA-Dawg68)
|
||||
Maintained by [SethBurkart123](https://github.com/SethBurkart123), [Crazypersonalph](https://github.com/Crazypersonalph) & the rest of the BetterSEQTA team!
|
||||
|
||||
## Star History
|
||||
|
||||
|
||||
+6
-6
@@ -2,15 +2,15 @@
|
||||
|
||||
## Supported Versions
|
||||
|
||||
Below here is the supported versions of BetterSEQTA+. Anything older than this is not supported and contains bugs.
|
||||
The following versions of BetterSEQTA+ are currently supported.
|
||||
|
||||
| Version | Supported |
|
||||
| ------- | --------- |
|
||||
| 3.4.3 | ✅ |
|
||||
| < 3.4.3 | :x: |
|
||||
|
||||
`*` May not work on other devices.
|
||||
| 3.4.3 or later | ✅ |
|
||||
| Earlier than 3.4.3 | ❌ |
|
||||
|
||||
## Reporting a Vulnerability
|
||||
|
||||
If you find vulnerabilities, REPORT IT IMMEDIATELY. open the [advisories tab](https://github.com/BetterSEQTA/BetterSEQTA-Plus/security/advisories) on the left and click the green "report a vulnerability" button or use [this quick-link](https://github.com/BetterSEQTA/BetterSEQTA-Plus/security/advisories/new) to create a new report
|
||||
If you discover a security vulnerability, please report it responsibly through GitHub Security Advisories:
|
||||
|
||||
https://github.com/BetterSEQTA/BetterSEQTA-Plus/security/advisories/new
|
||||
Binary file not shown.
@@ -8,11 +8,17 @@ export default {
|
||||
],
|
||||
transform: {
|
||||
'^.+\\.ts$': 'ts-jest',
|
||||
'^.+\\.js$': ['ts-jest', { tsconfig: { allowJs: true } }],
|
||||
},
|
||||
transformIgnorePatterns: [
|
||||
'/node_modules/(?!(color|color-string|color-convert|color-name)/)',
|
||||
],
|
||||
moduleNameMapper: {
|
||||
'^@/(.*)$': '<rootDir>/src/$1',
|
||||
'^color$': '<rootDir>/src/test/mocks/color.ts',
|
||||
'^webextension-polyfill$': '<rootDir>/src/test/mocks/webextension-polyfill.ts',
|
||||
},
|
||||
setupFilesAfterEnv: ['<rootDir>/src/test/jest.setup.ts'],
|
||||
moduleFileExtensions: ['ts', 'js', 'json'],
|
||||
collectCoverageFrom: [
|
||||
'src/**/*.ts',
|
||||
|
||||
+6
-44
@@ -1,58 +1,20 @@
|
||||
// ref: https://stackoverflow.com/a/76920975
|
||||
import type { Plugin } from "vite";
|
||||
|
||||
/**
|
||||
* Creates a Vite plugin designed to gracefully handle the conclusion of the build process.
|
||||
* This plugin utilizes the `buildEnd` and `closeBundle` hooks provided by Vite.
|
||||
* It checks for errors at the end of the build:
|
||||
* - If an error occurred during the build (`buildEnd` hook receives an error), it logs the error
|
||||
* and explicitly exits the Node.js process with a status code of 1 (indicating failure).
|
||||
* - If the build completes without errors and the bundle is successfully generated
|
||||
* (`closeBundle` hook is called), it logs a success message and exits the process
|
||||
* with a status code of 0 (indicating success).
|
||||
* This explicit process exiting can be useful in CI/CD environments or scripts that
|
||||
* rely on the process status code to determine the build outcome.
|
||||
* The core logic for using these hooks to exit the process is inspired by
|
||||
* a solution found on StackOverflow (https://stackoverflow.com/a/76920975).
|
||||
*
|
||||
* @returns {Plugin} A Vite plugin object configured with `name`, `buildEnd`, and `closeBundle` hooks.
|
||||
*/
|
||||
/** Exit with code 1 on build failure; do not exit on success (multi-target builds). */
|
||||
export default function ClosePlugin(): Plugin {
|
||||
return {
|
||||
/**
|
||||
* The unique name of this Vite plugin. This name is used by Vite for identification
|
||||
* purposes and will appear in warnings, errors, and logs related to this plugin.
|
||||
* @type {string}
|
||||
*/
|
||||
name: "ClosePlugin", // required, will show up in warnings and errors
|
||||
|
||||
/**
|
||||
* A Vite hook that is called when the build process has finished, regardless of
|
||||
* whether it was successful or encountered an error.
|
||||
*
|
||||
* @param {Error} [error] An optional error object. If the build failed, this parameter
|
||||
* will contain the error that occurred. If the build was successful,
|
||||
* this parameter will be undefined or null.
|
||||
*/
|
||||
name: "ClosePlugin",
|
||||
buildEnd(error) {
|
||||
if (error) {
|
||||
console.error("Error bundling");
|
||||
console.error(error);
|
||||
process.exit(1); // Exit with status 1 indicating an error
|
||||
console.error("Error bundling", error);
|
||||
process.exit(1);
|
||||
} else {
|
||||
console.log("Build ended"); // Log successful completion of the build phase
|
||||
console.log("Build ended");
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* A Vite hook that is called after the `buildEnd` hook, but only if the build
|
||||
* was successful (i.e., no errors were passed to `buildEnd`) and all output
|
||||
* files have been generated and written to disk. This signifies the successful
|
||||
* completion of the entire bundling process.
|
||||
*/
|
||||
closeBundle() {
|
||||
console.log("Bundle closed"); // Log successful closure of the bundle
|
||||
process.exit(0); // Exit with status 0 indicating a successful build
|
||||
console.log("Bundle closed");
|
||||
},
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
import type { Plugin } from "vite";
|
||||
|
||||
/** Relative chunk/CSS URLs via chrome.runtime.getURL for content-script dynamic imports. */
|
||||
export function extensionChunkUrls(): Plugin {
|
||||
return {
|
||||
name: "extension-chunk-urls",
|
||||
config() {
|
||||
return {
|
||||
base: "./",
|
||||
experimental: {
|
||||
renderBuiltUrl(filename, { hostType, type }) {
|
||||
const path = filename.replace(/^\//, "");
|
||||
if (type === "chunk" && hostType === "js") {
|
||||
return { runtime: `chrome.runtime.getURL(${JSON.stringify(path)})` };
|
||||
}
|
||||
// JS-triggered CSS preloads only — extension HTML pages need static hrefs.
|
||||
if (type === "asset" && hostType === "js" && path.endsWith(".css")) {
|
||||
return { runtime: `chrome.runtime.getURL(${JSON.stringify(path)})` };
|
||||
}
|
||||
},
|
||||
},
|
||||
};
|
||||
},
|
||||
};
|
||||
}
|
||||
+20
-58
@@ -1,70 +1,32 @@
|
||||
// vite-plugin-inline-worker-dev.ts
|
||||
// vite-plugin-inline-worker-dev.ts
|
||||
import { Plugin } from "vite";
|
||||
import fs from "fs/promises";
|
||||
import { build } from "esbuild";
|
||||
|
||||
/**
|
||||
* Creates a Vite plugin designed for bundling and inlining web worker scripts during development.
|
||||
* This plugin specifically targets module imports that include a `?inlineWorker` query parameter.
|
||||
* When such an import is encountered, the plugin bundles the worker script using `esbuild`
|
||||
* and then generates JavaScript code that inlines this bundled worker as a Blob,
|
||||
* creating the worker instance via `URL.createObjectURL()`.
|
||||
* The name "vite:inline-worker-dev" suggests it's primarily intended for development builds.
|
||||
*
|
||||
* @returns {Plugin} A Vite plugin object with `name` and `load` properties.
|
||||
*/
|
||||
/** Bundle worker entry points imported with `?inlineWorker` as Blob-backed Workers in dev. */
|
||||
export default function InlineWorkerDevPlugin(): Plugin {
|
||||
return {
|
||||
/**
|
||||
* The unique name of this Vite plugin.
|
||||
* @type {string}
|
||||
*/
|
||||
name: "vite:inline-worker-dev",
|
||||
/**
|
||||
* The Vite hook responsible for loading and transforming modules.
|
||||
* This function intercepts modules imported with `?inlineWorker`.
|
||||
* For such modules, it bundles the worker script and returns JavaScript code
|
||||
* that, when executed, will create an instance of this worker from an inlined Blob.
|
||||
*
|
||||
* @async
|
||||
* @param {string} id The path or ID of the module Vite is attempting to load,
|
||||
* potentially including query parameters (e.g., "/path/to/worker.ts?inlineWorker").
|
||||
* @returns {Promise<string | null>} A promise that resolves to:
|
||||
* - `null` if the module ID does not include `?inlineWorker`.
|
||||
* - A string of JavaScript code if the module is an inline worker.
|
||||
* This code will define a default export function (e.g., `InlineWorker`)
|
||||
* that, when called, creates and returns a new `Worker` instance
|
||||
* from the bundled and inlined worker script.
|
||||
*/
|
||||
async load(id) {
|
||||
if (id.includes("?inlineWorker")) {
|
||||
const [cleanPath] = id.split("?");
|
||||
// Note: Original code had `await fs.readFile(cleanPath, "utf-8");` but `code` wasn't used.
|
||||
// `esbuild` directly takes `cleanPath` as an entry point.
|
||||
const result = await build({
|
||||
entryPoints: [cleanPath], // esbuild uses the file path directly
|
||||
bundle: true,
|
||||
write: false, // We want the output in memory, not written to disk
|
||||
platform: "browser", // Target environment for the worker code
|
||||
format: "iife", // Immediately Invoked Function Expression, suitable for workers
|
||||
target: "esnext", // Transpile to modern JavaScript
|
||||
});
|
||||
if (!id.includes("?inlineWorker")) return null;
|
||||
|
||||
const workerCode = result.outputFiles[0].text;
|
||||
const [cleanPath] = id.split("?");
|
||||
const result = await build({
|
||||
entryPoints: [cleanPath],
|
||||
bundle: true,
|
||||
write: false,
|
||||
platform: "browser",
|
||||
format: "iife",
|
||||
target: "esnext",
|
||||
external: ["webextension-polyfill"],
|
||||
});
|
||||
|
||||
// Construct JavaScript code that will create the worker from a Blob.
|
||||
// This code is what gets returned to Vite and replaces the original import.
|
||||
const workerBlobCode = `
|
||||
const code = ${JSON.stringify(workerCode)};
|
||||
export default function InlineWorker() {
|
||||
const blob = new Blob([code], { type: 'application/javascript' });
|
||||
return new Worker(URL.createObjectURL(blob), { type: 'module' });
|
||||
}
|
||||
`;
|
||||
return workerBlobCode;
|
||||
}
|
||||
return null; // Let Vite handle other modules normally
|
||||
const workerCode = result.outputFiles[0].text;
|
||||
return `
|
||||
const code = ${JSON.stringify(workerCode)};
|
||||
export default function InlineWorker() {
|
||||
const blob = new Blob([code], { type: 'application/javascript' });
|
||||
return new Worker(URL.createObjectURL(blob), { type: 'module' });
|
||||
}
|
||||
`;
|
||||
},
|
||||
};
|
||||
}
|
||||
+2
-2
@@ -11,7 +11,7 @@
|
||||
* or `node lib/publish.js --b firefox`
|
||||
*/
|
||||
|
||||
const glob = require("glob");
|
||||
const { globSync } = require("glob");
|
||||
const semver = require("semver");
|
||||
const { execSync } = require("child_process");
|
||||
const path = require("path");
|
||||
@@ -98,7 +98,7 @@ function getLatestFiles(browser) {
|
||||
const pattern = `dist/betterseqtaplus@*-*${browser}.zip`;
|
||||
console.log("Glob pattern:", pattern);
|
||||
|
||||
const files = glob.sync(pattern);
|
||||
const files = globSync(pattern);
|
||||
console.log("Files found for browser", browser, ":", files);
|
||||
|
||||
if (files.length === 0) {
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
import type { Plugin, ViteDevServer } from "vite";
|
||||
|
||||
/**
|
||||
* CRXJS + Vite 6 often corrupt content-script ESM bindings after HMR /
|
||||
* `[crx] runtime reload` — modules load but named/`default` exports are missing
|
||||
* until the dev server is restarted.
|
||||
*
|
||||
* Prefer invalidating the module graph + a full page reload over partial HMR.
|
||||
*/
|
||||
export default function stabilizeCrxDevHmr(): Plugin {
|
||||
let reloadTimer: ReturnType<typeof setTimeout> | null = null;
|
||||
|
||||
const scheduleFullReload = (s: ViteDevServer) => {
|
||||
if (reloadTimer) clearTimeout(reloadTimer);
|
||||
// Debounce cascading invalidations (e.g. many files in one save).
|
||||
reloadTimer = setTimeout(() => {
|
||||
reloadTimer = null;
|
||||
s.ws.send({ type: "full-reload", path: "*" });
|
||||
}, 50);
|
||||
};
|
||||
|
||||
return {
|
||||
name: "stabilize-crx-dev-hmr",
|
||||
apply: "serve",
|
||||
enforce: "pre",
|
||||
configureServer(s) {
|
||||
s.ws.on("bsplus:reset-module-graph", () => {
|
||||
s.moduleGraph.invalidateAll();
|
||||
scheduleFullReload(s);
|
||||
});
|
||||
},
|
||||
handleHotUpdate({ file, modules, server: viteServer }) {
|
||||
if (!file.replace(/\\/g, "/").includes("/src/")) return;
|
||||
if (file.includes("node_modules")) return;
|
||||
|
||||
const seen = new Set(modules);
|
||||
const queue = [...modules];
|
||||
while (queue.length) {
|
||||
const mod = queue.pop()!;
|
||||
viteServer.moduleGraph.invalidateModule(mod);
|
||||
for (const importer of mod.importers) {
|
||||
if (seen.has(importer)) continue;
|
||||
seen.add(importer);
|
||||
queue.push(importer);
|
||||
}
|
||||
}
|
||||
|
||||
scheduleFullReload(viteServer);
|
||||
// Skip Vite's partial HMR for these modules — it is what leaves exports empty.
|
||||
return [];
|
||||
},
|
||||
};
|
||||
}
|
||||
+7
-47
@@ -1,55 +1,15 @@
|
||||
import fs from "fs";
|
||||
import type { Plugin } from "vite";
|
||||
|
||||
/**
|
||||
* Creates a Vite plugin designed to improve the reliability of Hot Module Replacement (HMR)
|
||||
* for global CSS files.
|
||||
* Previously touched CSS mtimes on JS HMR to force style refresh.
|
||||
* That raced with CRXJS runtime reload and corrupted Vite's module graph
|
||||
* (missing named/`default` exports until `npm run dev` was restarted).
|
||||
*
|
||||
* When a JavaScript/TypeScript module that imports a CSS file is updated, Vite's HMR
|
||||
* might not always reliably update the styles injected by that global CSS. This plugin
|
||||
* attempts to mitigate this by listening for hot updates. If an updated module
|
||||
* has direct importers that are CSS files (e.g., a JS file imports a global CSS file),
|
||||
* this plugin will "touch" those CSS files by updating their access and modification
|
||||
* timestamps using `fs.utimesSync`. This action can help signal to Vite or the browser
|
||||
* that the CSS file has changed, potentially triggering a more reliable style reload.
|
||||
*
|
||||
* @returns {import('vite').Plugin} A Vite plugin object configured with `name` and `handleHotUpdate` hooks.
|
||||
* Style updates are now covered by `stabilizeCrxDevHmr` full reloads.
|
||||
*/
|
||||
export default function touchGlobalCSSPlugin() {
|
||||
export default function touchGlobalCSSPlugin(): Plugin {
|
||||
return {
|
||||
/**
|
||||
* The unique name of this Vite plugin.
|
||||
* This name is used by Vite for identification purposes and will appear in logs.
|
||||
* @type {string}
|
||||
*/
|
||||
name: "touch-global-css",
|
||||
/**
|
||||
* A Vite hook that is called when a module is hot-updated.
|
||||
* This function inspects the importers of the updated module. If any of these
|
||||
* importers are CSS files, their filesystem timestamps are updated ("touched").
|
||||
*
|
||||
* @param {object} context The context object provided by Vite's `handleHotUpdate` hook.
|
||||
* @param {Array<import('vite').ModuleNode>} context.modules An array of `ModuleNode` instances that have been updated.
|
||||
* This plugin specifically accesses `modules[0]._clientModule.importers`
|
||||
* to find CSS files that import the updated module.
|
||||
*/
|
||||
handleHotUpdate({ modules }) {
|
||||
// It's assumed `modules[0]` is the primary updated module of interest.
|
||||
// `_clientModule` and `importers` might be internal or less stable Vite APIs.
|
||||
const importers = modules[0]?._clientModule?.importers;
|
||||
if (importers) {
|
||||
importers.forEach((importer) => {
|
||||
// Check if the importer is a CSS file
|
||||
if (importer.file && importer.file.includes(".css")) {
|
||||
console.log("[touch-global-css] touching", importer.file);
|
||||
try {
|
||||
// Update the access and modification times of the CSS file to the current time
|
||||
fs.utimesSync(importer.file, new Date(), new Date());
|
||||
} catch (err) {
|
||||
console.error(`[touch-global-css] Error touching file ${importer.file}:`, err);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
apply: "serve",
|
||||
};
|
||||
}
|
||||
+36
-42
@@ -1,16 +1,17 @@
|
||||
{
|
||||
"name": "betterseqtaplus",
|
||||
"version": "3.7.2",
|
||||
"version": "3.7.3",
|
||||
"type": "module",
|
||||
"description": "Enhance SEQTA Learn's usability and aesthetics! A fork of BetterSEQTA to continue development and add heaps more features!",
|
||||
"browserslist": "> 0.5%, last 2 versions, not dead",
|
||||
"scripts": {
|
||||
"postinstall": "node scripts/copy-pdfjs-assets.mjs",
|
||||
"compile:layerchart": "node scripts/compile-layerchart-vendor.mjs",
|
||||
"postinstall": "node scripts/copy-pdfjs-assets.mjs && node scripts/copy-ort-wasm-assets.mjs && npm run compile:layerchart",
|
||||
"autoaudit": "npm audit && npm audit fix && npm run build",
|
||||
"dev": "cross-env MODE=chrome vite dev",
|
||||
"dev:firefox": "cross-env MODE=firefox vite build --watch",
|
||||
"compile": "npm i && npm run build",
|
||||
"build": "cross-env MODE=chrome vite build && cross-env MODE=firefox vite build",
|
||||
"build": "npm run compile:layerchart && cross-env MODE=chrome vite build && cross-env MODE=firefox vite build",
|
||||
"build:chrome": "cross-env MODE=chrome vite build",
|
||||
"build:firefox": "cross-env MODE=firefox vite build",
|
||||
"build:safari": "cross-env MODE=safari vite build",
|
||||
@@ -18,19 +19,14 @@
|
||||
"convert:safari": "xcrun safari-web-extension-converter dist/safari --project-location . --app-name $npm_package_name-safari",
|
||||
"dependency-graph": "depcruise src --include-only \"^src\" --output-type dot | dot -T svg > dependency-graph.svg",
|
||||
"lint": "cross-env ESLINT_USE_FLAT_CONFIG=false eslint \"src/**/*.{js,ts}\"",
|
||||
"test": "jest",
|
||||
"test": "npm run test:unit",
|
||||
"test:unit": "jest",
|
||||
"test:smoke": "node scripts/smoke-test.mjs",
|
||||
"test:ci": "npm run test:unit && npm run build && npm run test:smoke",
|
||||
"release": "gh release create $npm_package_version --repo BetterSEQTA/BetterSEQTA-Plus ./dist/*.zip --generate-notes",
|
||||
"publish": "bun lib/publish.js --b",
|
||||
"zip": "bedframe zip"
|
||||
},
|
||||
"targets": {
|
||||
"prod": {
|
||||
"sourceMap": {
|
||||
"inline": false
|
||||
}
|
||||
}
|
||||
},
|
||||
"keywords": [],
|
||||
"author": {
|
||||
"name": "SethBurkart123",
|
||||
@@ -39,34 +35,44 @@
|
||||
},
|
||||
"license": "MIT",
|
||||
"devDependencies": {
|
||||
"@babel/plugin-transform-runtime": "^7.26.9",
|
||||
"@babel/runtime": "^7.26.9",
|
||||
"@bedframe/cli": "^0.1.2",
|
||||
"@crxjs/vite-plugin": "^2.6.1",
|
||||
"@sveltejs/vite-plugin-svelte": "^5.0.3",
|
||||
"@tailwindcss/forms": "^0.5.10",
|
||||
"@tsconfig/svelte": "^5.0.4",
|
||||
"@types/chrome": "^0.1.4",
|
||||
"@types/color": "^4.2.0",
|
||||
"@types/d3-scale": "^4.0.9",
|
||||
"@types/d3-shape": "^3.1.8",
|
||||
"@types/jest": "^30.0.0",
|
||||
"@types/mime-types": "^3.0.1",
|
||||
"@types/react": "^19.0.10",
|
||||
"@types/react-dom": "^19.0.4",
|
||||
"@types/node": "^24.3.0",
|
||||
"@types/qrcode": "^1.5.6",
|
||||
"@types/react": "^17.0.0",
|
||||
"@types/react-dom": "^17.0.0",
|
||||
"@types/sortablejs": "^1.15.8",
|
||||
"@types/webextension-polyfill": "^0.12.3",
|
||||
"@typescript-eslint/eslint-plugin": "^8.60.1",
|
||||
"@typescript-eslint/parser": "^8.60.1",
|
||||
"autoprefixer": "^10.4.21",
|
||||
"cross-env": "^10.0.0",
|
||||
"dependency-cruiser": "^17.0.1",
|
||||
"esbuild": "^0.25.3",
|
||||
"eslint": "^9.33.0",
|
||||
"eslint-plugin-import": "^2.31.0",
|
||||
"glob": "^11.0.1",
|
||||
"glob": "^13.0.6",
|
||||
"jest": "^30.4.2",
|
||||
"jest-environment-jsdom": "^30.4.1",
|
||||
"mime-types": "^3.0.1",
|
||||
"postcss": "^8.5.3",
|
||||
"prettier": "^3.5.3",
|
||||
"process": "^0.11.10",
|
||||
"publish-browser-extension": "^4.0.4",
|
||||
"sass": "^1.85.1",
|
||||
"sass-loader": "^16.0.5",
|
||||
"semver": "^7.7.1",
|
||||
"tailwindcss": "3",
|
||||
"ts-jest": "^29.4.11",
|
||||
"url": "^0.11.4"
|
||||
"typescript": "^5.8.2",
|
||||
"vite": "^6.2.1"
|
||||
},
|
||||
"dependencies": {
|
||||
"@bedframe/core": "^0.1.0",
|
||||
@@ -77,22 +83,10 @@
|
||||
"@codemirror/search": "^6.5.10",
|
||||
"@codemirror/state": "^6.5.2",
|
||||
"@codemirror/view": "^6.36.4",
|
||||
"@sveltejs/vite-plugin-svelte": "^5.0.3",
|
||||
"@tailwindcss/forms": "^0.5.10",
|
||||
"@tsconfig/svelte": "^5.0.4",
|
||||
"@types/chrome": "^0.1.4",
|
||||
"@types/color": "^4.2.0",
|
||||
"@types/lodash": "^4.17.16",
|
||||
"@types/node": "^24.3.0",
|
||||
"@types/qrcode": "^1.5.6",
|
||||
"@types/sortablejs": "^1.15.8",
|
||||
"@types/uuid": "^10.0.0",
|
||||
"@types/webextension-polyfill": "^0.12.3",
|
||||
"@huggingface/transformers": "^3.8.1",
|
||||
"@uiw/codemirror-extensions-color": "^4.23.10",
|
||||
"@uiw/codemirror-theme-github": "^4.23.10",
|
||||
"autoprefixer": "^10.4.21",
|
||||
"canvas-confetti": "^1.9.3",
|
||||
"codemirror": "^6.0.1",
|
||||
"color": "^5.0.0",
|
||||
"d3-scale": "^4.0.2",
|
||||
"d3-shape": "^3.2.0",
|
||||
@@ -100,29 +94,29 @@
|
||||
"embeddia": "^1.3.0",
|
||||
"embla-carousel-autoplay": "^8.5.2",
|
||||
"embla-carousel-svelte": "^8.5.2",
|
||||
"esbuild": "^0.25.3",
|
||||
"events": "^3.3.0",
|
||||
"flexsearch": "^0.8.147",
|
||||
"fuse.js": "^7.1.0",
|
||||
"idb": "^8.0.2",
|
||||
"layerchart": "2.0.0-next.27",
|
||||
"localforage": "^1.10.0",
|
||||
"lodash": "^4.17.21",
|
||||
"mathjs": "^14.4.0",
|
||||
"million": "^3.1.11",
|
||||
"motion": "^12.4.12",
|
||||
"pdfjs-dist": "^5.4.530",
|
||||
"postcss": "^8.5.3",
|
||||
"qrcode": "^1.5.4",
|
||||
"react": "17",
|
||||
"react-best-gradient-color-picker": "3.0.11",
|
||||
"react-dom": "17",
|
||||
"rss-parser": "^3.13.0",
|
||||
"semver": "^7.7.1",
|
||||
"sortablejs": "^1.15.6",
|
||||
"svelte": "^5.46.4",
|
||||
"typescript": "^5.8.2",
|
||||
"uuid": "^11.1.0",
|
||||
"vite": "^6.2.1",
|
||||
"svelte-hero-icons": "^5.2.0",
|
||||
"webextension-polyfill": "^0.12.0"
|
||||
},
|
||||
"overrides": {
|
||||
"glob": "^13.0.6"
|
||||
},
|
||||
"pnpm": {
|
||||
"overrides": {
|
||||
"glob": "^13.0.6"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
/**
|
||||
* Pre-compile layerchart `.svelte` sources to `.js` so Rollup/Vite CI builds succeed.
|
||||
*/
|
||||
import { compile } from "svelte/compiler";
|
||||
import { readFileSync, readdirSync, statSync, writeFileSync } from "node:fs";
|
||||
import { dirname, join } from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
|
||||
const root = join(dirname(fileURLToPath(import.meta.url)), "..");
|
||||
const layerchartRoot = join(root, "node_modules", "layerchart");
|
||||
const layerchartDist = join(layerchartRoot, "dist");
|
||||
const stampPath = join(layerchartDist, ".bsplus-compiled");
|
||||
const COMPILE_ALGO_VERSION = "2";
|
||||
const importSuffixPattern = /\.svelte(?=['"])/g;
|
||||
|
||||
const exists = (path) => {
|
||||
try {
|
||||
statSync(path);
|
||||
return true;
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
if (!exists(layerchartDist)) {
|
||||
console.log("compile-layerchart-vendor: layerchart not installed, skipping");
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
const layerchartVersion = JSON.parse(
|
||||
readFileSync(join(layerchartRoot, "package.json"), "utf8"),
|
||||
).version;
|
||||
const stampContent = `${layerchartVersion}\n${COMPILE_ALGO_VERSION}`;
|
||||
|
||||
if (exists(stampPath) && readFileSync(stampPath, "utf8").trim() === stampContent) {
|
||||
console.log(`compile-layerchart-vendor: layerchart@${layerchartVersion} already compiled, skipping`);
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
const walkFiles = (dir, files = []) => {
|
||||
for (const name of readdirSync(dir)) {
|
||||
if (name === "node_modules") continue;
|
||||
const path = join(dir, name);
|
||||
if (statSync(path).isDirectory()) walkFiles(path, files);
|
||||
else files.push(path);
|
||||
}
|
||||
return files;
|
||||
};
|
||||
|
||||
const patchSvelteImports = (content) => content.replace(importSuffixPattern, ".js");
|
||||
const stripRollupBreakingSyntax = (code) =>
|
||||
code
|
||||
.replace(/(\w+)\?(?=\s*[,)\]])/g, "$1")
|
||||
.replace(/(\w+)\?(?=\s*:)/g, "$1");
|
||||
|
||||
const svelteFiles = walkFiles(layerchartDist).filter((f) => f.endsWith(".svelte"));
|
||||
|
||||
for (const sveltePath of svelteFiles) {
|
||||
const source = readFileSync(sveltePath, "utf8");
|
||||
if (!source.includes("<script")) continue;
|
||||
const compiled = compile(source, {
|
||||
filename: sveltePath,
|
||||
generate: "client",
|
||||
css: "injected",
|
||||
});
|
||||
writeFileSync(
|
||||
sveltePath.replace(/\.svelte$/, ".js"),
|
||||
stripRollupBreakingSyntax(patchSvelteImports(compiled.js.code)),
|
||||
);
|
||||
}
|
||||
|
||||
for (const filePath of walkFiles(layerchartDist).filter((f) => /\.(js|svelte|ts|mjs)$/.test(f))) {
|
||||
const content = readFileSync(filePath, "utf8");
|
||||
if (!content.includes(".svelte")) continue;
|
||||
const patched = patchSvelteImports(content);
|
||||
if (patched !== content) writeFileSync(filePath, patched);
|
||||
}
|
||||
|
||||
writeFileSync(stampPath, stampContent);
|
||||
console.log(`compile-layerchart-vendor: compiled ${svelteFiles.length} Svelte files`);
|
||||
@@ -0,0 +1,28 @@
|
||||
import { copyFileSync, existsSync, mkdirSync } from "node:fs";
|
||||
import { createRequire } from "node:module";
|
||||
import { dirname, join } from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
|
||||
const root = join(dirname(fileURLToPath(import.meta.url)), "..");
|
||||
const require = createRequire(import.meta.url);
|
||||
|
||||
const transformersDist = dirname(require.resolve("@huggingface/transformers"));
|
||||
const outDir = join(root, "src", "public", "resources", "ort");
|
||||
|
||||
mkdirSync(outDir, { recursive: true });
|
||||
|
||||
const ortFiles = [
|
||||
"ort-wasm-simd-threaded.jsep.mjs",
|
||||
"ort-wasm-simd-threaded.jsep.wasm",
|
||||
];
|
||||
|
||||
for (const file of ortFiles) {
|
||||
const src = join(transformersDist, file);
|
||||
if (!existsSync(src)) {
|
||||
throw new Error(
|
||||
`Missing ONNX Runtime WASM asset: ${src}\n` +
|
||||
"Ensure @huggingface/transformers is installed (direct dependency).",
|
||||
);
|
||||
}
|
||||
copyFileSync(src, join(outDir, file));
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
/**
|
||||
* Package Chrome/Firefox build folders into Windows-friendly zip files.
|
||||
*/
|
||||
import { execFileSync } from "node:child_process";
|
||||
import { appendFileSync, existsSync, mkdirSync, readFileSync, unlinkSync } from "node:fs";
|
||||
import { dirname, join } from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
|
||||
const root = join(dirname(fileURLToPath(import.meta.url)), "..");
|
||||
|
||||
function zipDirectory(sourceRel, outRel) {
|
||||
const sourceDir = join(root, sourceRel);
|
||||
const outZip = join(root, outRel);
|
||||
if (!existsSync(sourceDir)) throw new Error(`Missing build output: ${sourceRel}`);
|
||||
|
||||
mkdirSync(dirname(outZip), { recursive: true });
|
||||
if (existsSync(outZip)) unlinkSync(outZip);
|
||||
|
||||
if (process.platform === "win32") {
|
||||
const esc = (s) => s.replace(/'/g, "''");
|
||||
execFileSync(
|
||||
"powershell",
|
||||
[
|
||||
"-NoProfile",
|
||||
"-Command",
|
||||
[
|
||||
"Add-Type -AssemblyName System.IO.Compression.FileSystem",
|
||||
`[IO.Compression.ZipFile]::CreateFromDirectory('${esc(sourceDir)}', '${esc(outZip)}')`,
|
||||
].join("; "),
|
||||
],
|
||||
{ stdio: "inherit" },
|
||||
);
|
||||
} else {
|
||||
execFileSync("zip", ["-r", "-q", outZip, "."], { cwd: sourceDir, stdio: "inherit" });
|
||||
}
|
||||
}
|
||||
|
||||
const pkg = JSON.parse(readFileSync(join(root, "package.json"), "utf8"));
|
||||
const version = process.argv[2] || pkg.version;
|
||||
const updateChannel = process.env.UPDATE_CHANNEL || "stable";
|
||||
const buildLabel = process.env.BUILD_LABEL || "";
|
||||
const base =
|
||||
updateChannel === "nightly" && buildLabel
|
||||
? `betterseqtaplus-nightly-${buildLabel}`
|
||||
: `betterseqtaplus-${version}`;
|
||||
|
||||
const chromeZip = `dist/${base}-chrome.zip`;
|
||||
const firefoxZip = `dist/${base}-firefox.zip`;
|
||||
|
||||
zipDirectory("dist/chrome", chromeZip);
|
||||
zipDirectory("dist/firefox", firefoxZip);
|
||||
console.log(`Packaged ${chromeZip}\nPackaged ${firefoxZip}`);
|
||||
|
||||
if (process.env.GITHUB_OUTPUT) {
|
||||
appendFileSync(process.env.GITHUB_OUTPUT, `chrome_zip=${chromeZip}\nfirefox_zip=${firefoxZip}\n`);
|
||||
}
|
||||
+110
-11
@@ -6,10 +6,12 @@ import documentLoadCSS from "@/css/documentload.scss?inline";
|
||||
import icon48 from "@/resources/icons/icon-48.png?base64";
|
||||
import browser from "webextension-polyfill";
|
||||
|
||||
import * as plugins from "@/plugins";
|
||||
import { main } from "@/seqta/main";
|
||||
import { delay } from "./seqta/utils/delay";
|
||||
import { initializeHideSensitiveToggle } from "@/seqta/utils/hideSensitiveToggle";
|
||||
import { installSeqtaMenuColourPatch } from "@/seqta/utils/patchSeqtaMenuUpdateColours";
|
||||
import { installThemeImagePagePatch } from "@/seqta/utils/patchThemeImagesPageContext";
|
||||
import { initVerboseLogging, verboseInfo } from "@/utils/verboseLog";
|
||||
|
||||
function registerFetchSeqtaAppLinkListener() {
|
||||
browser.runtime.onMessage.addListener((request, _sender, sendResponse) => {
|
||||
@@ -35,8 +37,6 @@ function registerFetchSeqtaAppLinkListener() {
|
||||
});
|
||||
}
|
||||
|
||||
export let MenuOptionsOpen = false;
|
||||
|
||||
var IsSEQTAPage = false;
|
||||
let hasSEQTAText = false;
|
||||
|
||||
@@ -46,9 +46,22 @@ if (document.childNodes[1]) {
|
||||
document.childNodes[1].textContent?.includes(
|
||||
"Copyright (c) SEQTA Software",
|
||||
) ?? false;
|
||||
if (hasSEQTAText) {
|
||||
installSeqtaMenuColourPatch();
|
||||
installThemeImagePagePatch();
|
||||
}
|
||||
init();
|
||||
}
|
||||
|
||||
// Standalone 404 documents never pass the SEQTA SPA gate above.
|
||||
void bootErrorPage();
|
||||
|
||||
if (import.meta.env.DEV) {
|
||||
window.addEventListener("unhandledrejection", (event) => {
|
||||
recoverFromStaleDevModuleGraph(event.reason);
|
||||
});
|
||||
}
|
||||
|
||||
async function init() {
|
||||
if (
|
||||
hasSEQTAText &&
|
||||
@@ -57,11 +70,7 @@ async function init() {
|
||||
!IsSEQTAPage
|
||||
) {
|
||||
IsSEQTAPage = true;
|
||||
console.info("[BetterSEQTA+] Verified SEQTA Page");
|
||||
|
||||
if (typeof window !== "undefined" && window === window.top) {
|
||||
void browser.runtime.sendMessage({ type: "cloudSettingsPoll" }).catch(() => {});
|
||||
}
|
||||
verboseInfo("[BetterSEQTA+] Verified SEQTA Page");
|
||||
|
||||
registerFetchSeqtaAppLinkListener();
|
||||
|
||||
@@ -96,6 +105,7 @@ async function init() {
|
||||
|
||||
try {
|
||||
await initializeSettingsState();
|
||||
initVerboseLogging();
|
||||
|
||||
if (typeof settingsState.onoff === "undefined") {
|
||||
await browser.runtime.sendMessage({ type: "setDefaultStorage" });
|
||||
@@ -104,25 +114,91 @@ async function init() {
|
||||
}
|
||||
|
||||
await main();
|
||||
plugins.Monofile();
|
||||
|
||||
const { init: Monofile } = await import("@/plugins/monofile");
|
||||
Monofile();
|
||||
|
||||
if (settingsState.onoff) {
|
||||
await plugins.initializePlugins();
|
||||
const { initializePlugins } = await import("@/plugins/index");
|
||||
await initializePlugins();
|
||||
}
|
||||
|
||||
if (settingsState.devMode) {
|
||||
initializeHideSensitiveToggle();
|
||||
}
|
||||
|
||||
console.info(
|
||||
if (import.meta.env.DEV) {
|
||||
sessionStorage.removeItem("bsplus-dev-export-recovery");
|
||||
}
|
||||
|
||||
verboseInfo(
|
||||
"[BetterSEQTA+] Successfully initialised BetterSEQTA+, starting to load assets.",
|
||||
);
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
recoverFromStaleDevModuleGraph(error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Hide the rebranded 404 before the kitten card mounts (removed after boot). */
|
||||
function inject404FlashHide(): void {
|
||||
if (document.getElementById("bsplus-404-flash-hide")) return;
|
||||
const style = document.createElement("style");
|
||||
style.id = "bsplus-404-flash-hide";
|
||||
style.textContent =
|
||||
"html,body{background:#333!important}.message{display:none!important}";
|
||||
(document.head ?? document.documentElement).appendChild(style);
|
||||
}
|
||||
|
||||
async function bootErrorPage() {
|
||||
if (IsSEQTAPage) return;
|
||||
|
||||
const { isSeqta404Page, mountErrorPageKitten } = await import(
|
||||
"@/plugins/built-in/errorPageKitten"
|
||||
);
|
||||
|
||||
const storagePromise = browser.storage.local.get([
|
||||
"onoff",
|
||||
"plugin.error-page-kitten.settings",
|
||||
]);
|
||||
|
||||
const watchTitle = () => {
|
||||
if (isSeqta404Page()) inject404FlashHide();
|
||||
};
|
||||
watchTitle();
|
||||
if (document.readyState === "loading") {
|
||||
document.addEventListener("readystatechange", watchTitle);
|
||||
}
|
||||
|
||||
if (document.readyState === "loading") {
|
||||
await new Promise<void>((resolve) => {
|
||||
document.addEventListener("DOMContentLoaded", () => resolve(), { once: true });
|
||||
});
|
||||
}
|
||||
document.removeEventListener("readystatechange", watchTitle);
|
||||
|
||||
if (!isSeqta404Page()) return;
|
||||
|
||||
const stored = await storagePromise;
|
||||
if ((stored.onoff ?? true) === false) return;
|
||||
const kittenSettings = stored["plugin.error-page-kitten.settings"] as
|
||||
| { enabled?: boolean }
|
||||
| undefined;
|
||||
if (kittenSettings?.enabled === false) return;
|
||||
|
||||
try {
|
||||
mountErrorPageKitten();
|
||||
document.getElementById("bsplus-404-flash-hide")?.remove();
|
||||
} catch (error) {
|
||||
document.getElementById("bsplus-404-flash-hide")?.remove();
|
||||
document
|
||||
.querySelectorAll(".bsplus-kitten-404-hidden")
|
||||
.forEach((el) => el.classList.remove("bsplus-kitten-404-hidden"));
|
||||
console.error("[BetterSEQTA+] Failed to boot 404 page:", error);
|
||||
}
|
||||
}
|
||||
|
||||
function replaceIcons() {
|
||||
document
|
||||
.querySelectorAll<HTMLLinkElement>('link[rel*="icon"]')
|
||||
@@ -131,4 +207,27 @@ function replaceIcons() {
|
||||
link.href = icon48;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/** Vite/CRX HMR can leave modules with missing named exports until the graph is cleared. */
|
||||
function recoverFromStaleDevModuleGraph(error: unknown) {
|
||||
if (!import.meta.env.DEV) return;
|
||||
|
||||
const message = error instanceof Error ? error.message : String(error);
|
||||
if (!/does not provide an export named/.test(message)) return;
|
||||
|
||||
const key = "bsplus-dev-export-recovery";
|
||||
if (!sessionStorage.getItem(key)) {
|
||||
sessionStorage.setItem(key, "1");
|
||||
import.meta.hot?.send("bsplus:reset-module-graph");
|
||||
setTimeout(() => {
|
||||
location.reload();
|
||||
}, 80);
|
||||
return;
|
||||
}
|
||||
|
||||
sessionStorage.removeItem(key);
|
||||
console.error(
|
||||
"[BetterSEQTA+] Dev module graph is still stale after recovery. Restart `npm run dev`, then reload this page.",
|
||||
);
|
||||
}
|
||||
+193
-80
@@ -10,7 +10,19 @@ import {
|
||||
performCloudSettingsUploadWithRetry,
|
||||
requestCloudSettingsDebouncedUpload,
|
||||
runCloudSettingsPoll,
|
||||
withSuppressedCloudAutoUpload,
|
||||
} from "./background/cloudSettingsAutoSync";
|
||||
import { getBsplusDeviceName } from "@/seqta/utils/bsplusDeviceName";
|
||||
import { isAllowedFetchUrl } from "@/seqta/utils/allowedFetchUrl";
|
||||
import { initCalendarBackground } from "./background/calendarBackground";
|
||||
import {
|
||||
registerGoogleCalendarMessageHandlers,
|
||||
registerOutlookCalendarMessageHandlers,
|
||||
} from "./background/calendarBackground";
|
||||
import {
|
||||
handleAiModCreatorMessage,
|
||||
registerAiModCreatorStreaming,
|
||||
} from "./background/aiModCreator";
|
||||
|
||||
/**
|
||||
* Session-only dev-mode override of the content API base.
|
||||
@@ -45,6 +57,11 @@ function reloadSeqtaPages() {
|
||||
/** Callback for sending a response back to the message sender */
|
||||
type MessageSender = { (response?: unknown): void };
|
||||
|
||||
async function getAccessTokenFromStorage(): Promise<string | null> {
|
||||
const { bsplus_token } = await browser.storage.local.get("bsplus_token");
|
||||
return typeof bsplus_token === "string" && bsplus_token.length > 0 ? bsplus_token : null;
|
||||
}
|
||||
|
||||
/** Accept API + GitHub fallback shapes; always return `{ success, data?: { themes } }`. */
|
||||
function normalizeFetchThemesResponse(json: unknown): {
|
||||
success: boolean;
|
||||
@@ -79,66 +96,101 @@ function normalizeFetchThemesResponse(json: unknown): {
|
||||
}
|
||||
|
||||
function handleFetchThemes(request: any, sendResponse: MessageSender): boolean {
|
||||
const { token } = request;
|
||||
const apiUrl = `${apiBase()}/api/themes?type=betterseqta&limit=100&nocache=${Date.now()}`;
|
||||
const githubUrl = `https://raw.githubusercontent.com/BetterSEQTA/BetterSEQTA-Themes/main/store/themes.json?nocache=${Date.now()}`;
|
||||
const headers: Record<string, string> = {};
|
||||
if (token) headers["Authorization"] = `Bearer ${token}`;
|
||||
fetch(apiUrl, { cache: "no-store", headers })
|
||||
.then(async (r) => {
|
||||
const json = await r.json();
|
||||
if (!r.ok) {
|
||||
throw new Error(
|
||||
(json && typeof json === "object" && "error" in json && typeof (json as { error?: string }).error === "string"
|
||||
? (json as { error: string }).error
|
||||
: null) ?? `Themes API HTTP ${r.status}`,
|
||||
);
|
||||
}
|
||||
return normalizeFetchThemesResponse(json);
|
||||
})
|
||||
.then(sendResponse)
|
||||
.catch((err) => {
|
||||
console.warn("[Background] fetchThemes API failed, trying GitHub fallback:", err?.message);
|
||||
fetch(githubUrl, { cache: "no-store" })
|
||||
.then(async (r) => {
|
||||
if (!r.ok) throw new Error(`GitHub fallback HTTP ${r.status}`);
|
||||
const data = await r.json();
|
||||
const themes = Array.isArray(data) ? data : (data?.themes ?? []);
|
||||
return normalizeFetchThemesResponse({ success: true, data: { themes } });
|
||||
})
|
||||
.then(sendResponse)
|
||||
.catch((fallbackErr) => {
|
||||
console.error("[Background] fetchThemes GitHub fallback error:", fallbackErr);
|
||||
sendResponse({ success: false, error: fallbackErr?.message });
|
||||
});
|
||||
});
|
||||
void (async () => {
|
||||
const token = await getAccessTokenFromStorage();
|
||||
const apiUrl = `${apiBase()}/api/themes?type=betterseqta&limit=100&nocache=${Date.now()}`;
|
||||
const githubUrl = `https://raw.githubusercontent.com/BetterSEQTA/BetterSEQTA-Themes/main/store/themes.json?nocache=${Date.now()}`;
|
||||
const headers: Record<string, string> = {};
|
||||
if (token) headers["Authorization"] = `Bearer ${token}`;
|
||||
fetch(apiUrl, { cache: "no-store", headers })
|
||||
.then(async (r) => {
|
||||
const json = await r.json();
|
||||
if (!r.ok) {
|
||||
throw new Error(
|
||||
(json && typeof json === "object" && "error" in json && typeof (json as { error?: string }).error === "string"
|
||||
? (json as { error: string }).error
|
||||
: null) ?? `Themes API HTTP ${r.status}`,
|
||||
);
|
||||
}
|
||||
return normalizeFetchThemesResponse(json);
|
||||
})
|
||||
.then(sendResponse)
|
||||
.catch((err) => {
|
||||
console.warn("[Background] fetchThemes API failed, trying GitHub fallback:", err?.message);
|
||||
fetch(githubUrl, { cache: "no-store" })
|
||||
.then(async (r) => {
|
||||
if (!r.ok) throw new Error(`GitHub fallback HTTP ${r.status}`);
|
||||
const data = await r.json();
|
||||
const themes = Array.isArray(data) ? data : (data?.themes ?? []);
|
||||
return normalizeFetchThemesResponse({ success: true, data: { themes } });
|
||||
})
|
||||
.then(sendResponse)
|
||||
.catch((fallbackErr) => {
|
||||
console.error("[Background] fetchThemes GitHub fallback error:", fallbackErr);
|
||||
sendResponse({ success: false, error: fallbackErr?.message });
|
||||
});
|
||||
});
|
||||
})();
|
||||
return true;
|
||||
}
|
||||
|
||||
function handleFetchThemeDetails(request: any, sendResponse: MessageSender): boolean {
|
||||
const { themeId, token } = request;
|
||||
const { themeId } = request;
|
||||
if (!themeId || typeof themeId !== "string") {
|
||||
sendResponse({ success: false, error: "Missing themeId" });
|
||||
return false;
|
||||
}
|
||||
const headers: Record<string, string> = {};
|
||||
if (token) headers["Authorization"] = `Bearer ${token}`;
|
||||
fetch(`${apiBase()}/api/themes/${themeId}`, { cache: "no-store", headers })
|
||||
.then((r) => r.json())
|
||||
.then(sendResponse)
|
||||
.catch((err) => {
|
||||
console.error("[Background] fetchThemeDetails error:", err);
|
||||
sendResponse({ success: false, error: err?.message });
|
||||
});
|
||||
void (async () => {
|
||||
const token = await getAccessTokenFromStorage();
|
||||
const headers: Record<string, string> = {};
|
||||
if (token) headers["Authorization"] = `Bearer ${token}`;
|
||||
fetch(`${apiBase()}/api/themes/${themeId}`, { cache: "no-store", headers })
|
||||
.then((r) => r.json())
|
||||
.then(sendResponse)
|
||||
.catch((err) => {
|
||||
console.error("[Background] fetchThemeDetails error:", err);
|
||||
sendResponse({ success: false, error: err?.message });
|
||||
});
|
||||
})();
|
||||
return true;
|
||||
}
|
||||
|
||||
function handleFetchFromUrl(request: any, sendResponse: MessageSender): boolean {
|
||||
function isTrustedSender(sender?: browser.Runtime.MessageSender): boolean {
|
||||
if (!sender) return false;
|
||||
if (sender.id && sender.id !== browser.runtime.id) return false;
|
||||
|
||||
const urls = [sender.url, sender.tab?.url].filter(Boolean) as string[];
|
||||
for (const pageUrl of urls) {
|
||||
if (/^chrome-extension:\/\//.test(pageUrl) || /^moz-extension:\/\//.test(pageUrl)) {
|
||||
return true;
|
||||
}
|
||||
try {
|
||||
if (isSeqtaOrigin(new URL(pageUrl).origin)) return true;
|
||||
} catch {
|
||||
// try next URL
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function handleFetchFromUrl(
|
||||
request: any,
|
||||
sendResponse: MessageSender,
|
||||
sender?: browser.Runtime.MessageSender,
|
||||
): boolean {
|
||||
if (!isTrustedSender(sender)) {
|
||||
sendResponse({ error: "Unauthorized sender" });
|
||||
return false;
|
||||
}
|
||||
const { url } = request;
|
||||
if (!url || typeof url !== "string") {
|
||||
sendResponse({ error: "Missing url" });
|
||||
return false;
|
||||
}
|
||||
if (!isAllowedFetchUrl(url)) {
|
||||
sendResponse({ error: "URL not allowed" });
|
||||
return false;
|
||||
}
|
||||
fetch(url, { cache: "no-store" })
|
||||
.then((r) => r.json())
|
||||
.then((data) => sendResponse({ data }))
|
||||
@@ -177,26 +229,42 @@ function handleCloudReserveClient(request: any, sendResponse: MessageSender): bo
|
||||
return true;
|
||||
}
|
||||
|
||||
function handleCloudLogin(request: any, sendResponse: MessageSender): boolean {
|
||||
const { client_id, redirect_uri, login, password } = request;
|
||||
function handleCloudLogin(
|
||||
request: any,
|
||||
sendResponse: MessageSender,
|
||||
sender?: browser.Runtime.MessageSender,
|
||||
): boolean {
|
||||
if (!isTrustedSender(sender)) {
|
||||
sendResponse({ error: "Unauthorized sender" });
|
||||
return false;
|
||||
}
|
||||
const { client_id, redirect_uri, login, password, device_name } = request;
|
||||
if (!client_id || !redirect_uri || !login || !password) {
|
||||
sendResponse({ error: "Missing client_id, redirect_uri, login, or password" });
|
||||
return false;
|
||||
}
|
||||
fetch("https://accounts.betterseqta.org/api/bsplus/login", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ client_id, redirect_uri, login, password }),
|
||||
})
|
||||
.then(async (r) => {
|
||||
void (async () => {
|
||||
const loginBody: Record<string, string> = {
|
||||
client_id,
|
||||
redirect_uri,
|
||||
login,
|
||||
password,
|
||||
device_name: device_name ?? await getBsplusDeviceName(),
|
||||
};
|
||||
try {
|
||||
const r = await fetch("https://accounts.betterseqta.org/api/bsplus/login", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify(loginBody),
|
||||
});
|
||||
const data = await parseJsonResponse(r);
|
||||
if (!r.ok) sendResponse({ error: data?.error ?? "Login failed" });
|
||||
else sendResponse(data);
|
||||
})
|
||||
.catch((err) => {
|
||||
} catch (err) {
|
||||
console.error("[Background] cloudLogin error:", err);
|
||||
sendResponse({ error: err?.message ?? "Network error" });
|
||||
});
|
||||
sendResponse({ error: (err as Error)?.message ?? "Network error" });
|
||||
}
|
||||
})();
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -291,10 +359,18 @@ function handleCloudRefresh(request: any, sendResponse: MessageSender): boolean
|
||||
return true;
|
||||
}
|
||||
|
||||
function handleCloudSettingsUpload(request: any, sendResponse: MessageSender): boolean {
|
||||
function handleCloudSettingsUpload(
|
||||
request: any,
|
||||
sendResponse: MessageSender,
|
||||
sender?: browser.Runtime.MessageSender,
|
||||
): boolean {
|
||||
if (!isTrustedSender(sender)) {
|
||||
sendResponse({ success: false, error: "Unauthorized sender" });
|
||||
return false;
|
||||
}
|
||||
void (async () => {
|
||||
try {
|
||||
const token = request.token as string | undefined;
|
||||
const token = await getAccessTokenFromStorage();
|
||||
if (!token) {
|
||||
sendResponse({ success: false, error: "Not authenticated" });
|
||||
return;
|
||||
@@ -316,10 +392,18 @@ function handleCloudSettingsUpload(request: any, sendResponse: MessageSender): b
|
||||
return true;
|
||||
}
|
||||
|
||||
function handleCloudSettingsDownload(request: any, sendResponse: MessageSender): boolean {
|
||||
function handleCloudSettingsDownload(
|
||||
request: any,
|
||||
sendResponse: MessageSender,
|
||||
sender?: browser.Runtime.MessageSender,
|
||||
): boolean {
|
||||
if (!isTrustedSender(sender)) {
|
||||
sendResponse({ success: false, error: "Unauthorized sender" });
|
||||
return false;
|
||||
}
|
||||
void (async () => {
|
||||
try {
|
||||
const token = request.token as string | undefined;
|
||||
const token = await getAccessTokenFromStorage();
|
||||
if (!token) {
|
||||
sendResponse({ success: false, error: "Not authenticated" });
|
||||
return;
|
||||
@@ -343,22 +427,29 @@ function handleCloudSettingsDownload(request: any, sendResponse: MessageSender):
|
||||
}
|
||||
|
||||
function handleCloudFavorite(request: any, sendResponse: MessageSender): boolean {
|
||||
const { themeId, token, action } = request;
|
||||
if (!themeId || !token) {
|
||||
sendResponse({ success: false, error: "Theme ID and token required" });
|
||||
const { themeId, action } = request;
|
||||
if (!themeId) {
|
||||
sendResponse({ success: false, error: "Theme ID required" });
|
||||
return false;
|
||||
}
|
||||
const isFavorite = action === "favorite";
|
||||
fetch(`${apiBase()}/api/themes/${themeId}/favorite`, {
|
||||
method: isFavorite ? "POST" : "DELETE",
|
||||
headers: { Authorization: `Bearer ${token}` },
|
||||
})
|
||||
.then((r) => r.json())
|
||||
.then(sendResponse)
|
||||
.catch((err) => {
|
||||
console.error("[Background] cloudFavorite error:", err);
|
||||
sendResponse({ success: false, error: err?.message });
|
||||
});
|
||||
void (async () => {
|
||||
const token = await getAccessTokenFromStorage();
|
||||
if (!token) {
|
||||
sendResponse({ success: false, error: "Not authenticated" });
|
||||
return;
|
||||
}
|
||||
const isFavorite = action === "favorite";
|
||||
fetch(`${apiBase()}/api/themes/${themeId}/favorite`, {
|
||||
method: isFavorite ? "POST" : "DELETE",
|
||||
headers: { Authorization: `Bearer ${token}` },
|
||||
})
|
||||
.then((r) => r.json())
|
||||
.then(sendResponse)
|
||||
.catch((err) => {
|
||||
console.error("[Background] cloudFavorite error:", err);
|
||||
sendResponse({ success: false, error: err?.message });
|
||||
});
|
||||
})();
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -376,7 +467,12 @@ function isSeqtaOrigin(origin: string): boolean {
|
||||
}
|
||||
}
|
||||
|
||||
function handleSetDevApiBase(request: any): boolean {
|
||||
function handleSetDevApiBase(
|
||||
request: any,
|
||||
_sendResponse: MessageSender,
|
||||
sender?: browser.Runtime.MessageSender,
|
||||
): boolean {
|
||||
if (!isTrustedSender(sender)) return false;
|
||||
const url = typeof request?.url === "string" ? request.url.trim() : null;
|
||||
if (url && /^https?:\/\//.test(url)) {
|
||||
DEV_API_BASE = url.replace(/\/$/, "");
|
||||
@@ -415,7 +511,11 @@ const MESSAGE_HANDLERS: Record<string, MessageHandler> = {
|
||||
});
|
||||
return true;
|
||||
},
|
||||
sendNews: (req, sendResponse) => {
|
||||
sendNews: (req, sendResponse, sender) => {
|
||||
if (!isTrustedSender(sender)) {
|
||||
sendResponse({ error: "Unauthorized sender" });
|
||||
return false;
|
||||
}
|
||||
fetchNews(req.source ?? "australia", sendResponse);
|
||||
return true;
|
||||
},
|
||||
@@ -429,6 +529,13 @@ const MESSAGE_HANDLERS: Record<string, MessageHandler> = {
|
||||
cloudFavorite: handleCloudFavorite,
|
||||
cloudSettingsUpload: handleCloudSettingsUpload,
|
||||
cloudSettingsDownload: handleCloudSettingsDownload,
|
||||
aiModCreator: (request, sendResponse, sender) =>
|
||||
handleAiModCreatorMessage(
|
||||
request,
|
||||
sender ?? {},
|
||||
sendResponse,
|
||||
isTrustedSender,
|
||||
),
|
||||
cloudSettingsPoll: () => {
|
||||
void runCloudSettingsPoll();
|
||||
return false;
|
||||
@@ -475,6 +582,11 @@ const MESSAGE_HANDLERS: Record<string, MessageHandler> = {
|
||||
},
|
||||
};
|
||||
|
||||
registerGoogleCalendarMessageHandlers(MESSAGE_HANDLERS, isTrustedSender);
|
||||
registerOutlookCalendarMessageHandlers(MESSAGE_HANDLERS, isTrustedSender);
|
||||
registerAiModCreatorStreaming(isTrustedSender);
|
||||
initCalendarBackground();
|
||||
|
||||
browser.runtime.onMessage.addListener(
|
||||
// @ts-ignore - OnMessageListener expects literal true for async, we return boolean
|
||||
(request: any, sender: browser.Runtime.MessageSender, sendResponse: MessageSender) => {
|
||||
@@ -492,10 +604,10 @@ function getDefaultValues(): SettingsState {
|
||||
return getDefaultSettingsState();
|
||||
}
|
||||
|
||||
function SetStorageValue(object: any) {
|
||||
for (var i in object) {
|
||||
browser.storage.local.set({ [i]: object[i] });
|
||||
}
|
||||
function SetStorageValue(object: SettingsState) {
|
||||
void withSuppressedCloudAutoUpload(() =>
|
||||
browser.storage.local.set(object as Record<string, unknown>),
|
||||
);
|
||||
}
|
||||
|
||||
/** One-time migration for 3.6.5: opt upgraders into Global Search + indexing + transparency defaults. */
|
||||
@@ -626,6 +738,7 @@ browser.runtime.onInstalled.addListener(function (event) {
|
||||
void migrateGlobalSearchDefaultsFor365Upgrade(event.previousVersion);
|
||||
void resetThemeOfTheMonthDisabledFor366Upgrade(event.previousVersion);
|
||||
void resetThemeOfTheMonthDismissalFor370Upgrade(event.previousVersion);
|
||||
reloadSeqtaPages();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -0,0 +1,292 @@
|
||||
import browser from "webextension-polyfill";
|
||||
import {
|
||||
AI_MOD_CREATOR_MESSAGE_TYPE,
|
||||
createAiModCreatorService,
|
||||
formatOpenRouterError,
|
||||
handleAiModCreatorMessage,
|
||||
} from "./aiModCreator";
|
||||
import type { SelectedElementContext } from "@/plugins/built-in/aiModCreator/types";
|
||||
|
||||
const context: SelectedElementContext = {
|
||||
route: "assessments",
|
||||
rootSelector: "#selected",
|
||||
request: "Round this card",
|
||||
userContext: "Assessment summary",
|
||||
selectedHtml: '<section id="selected">Assessment</section>',
|
||||
domCatalog: [
|
||||
{
|
||||
selector: ":scope",
|
||||
tag: "section",
|
||||
classes: [],
|
||||
parentSelector: null,
|
||||
siblingIndex: 0,
|
||||
siblingCount: 1,
|
||||
layout: { display: "block" },
|
||||
},
|
||||
],
|
||||
tagName: "section",
|
||||
dimensions: { width: 400, height: 200 },
|
||||
computedStyle: { color: "rgb(0, 0, 0)" },
|
||||
};
|
||||
|
||||
describe("AI mod OpenRouter background service", () => {
|
||||
it("stores the key locally and reports only whether it exists", async () => {
|
||||
const service = createAiModCreatorService({
|
||||
fetchImpl: jest.fn(),
|
||||
now: () => 1_000,
|
||||
});
|
||||
|
||||
await service.saveKey(" sk-or-v1-test-key-123456 ");
|
||||
await expect(service.getKeyStatus()).resolves.toEqual({ configured: true });
|
||||
expect(await browser.storage.local.get("aiModCreator.openRouterApiKey")).toEqual({
|
||||
"aiModCreator.openRouterApiKey": "sk-or-v1-test-key-123456",
|
||||
});
|
||||
|
||||
await service.clearKey();
|
||||
await expect(service.getKeyStatus()).resolves.toEqual({ configured: false });
|
||||
});
|
||||
|
||||
it("calls the free model with json_object output and provider fallbacks", async () => {
|
||||
await browser.storage.local.set({
|
||||
"aiModCreator.openRouterApiKey": "sk-or-v1-test-key-123456",
|
||||
});
|
||||
const fetchImpl = jest.fn(async (_url: string, init?: RequestInit) => {
|
||||
const body = JSON.parse(String(init?.body));
|
||||
expect(body).toMatchObject({
|
||||
model: "minimax/minimax-m2.7:free",
|
||||
provider: { allow_fallbacks: true },
|
||||
response_format: { type: "json_object" },
|
||||
});
|
||||
expect(init?.headers).toMatchObject({
|
||||
Authorization: "Bearer sk-or-v1-test-key-123456",
|
||||
});
|
||||
return new Response(
|
||||
JSON.stringify({
|
||||
choices: [
|
||||
{
|
||||
message: {
|
||||
content: JSON.stringify({
|
||||
name: "Rounded card",
|
||||
description: "Rounds the selected card.",
|
||||
operations: [
|
||||
{
|
||||
type: "setStyle",
|
||||
selector: ":scope",
|
||||
property: "border-radius",
|
||||
value: "12px",
|
||||
},
|
||||
],
|
||||
}),
|
||||
},
|
||||
},
|
||||
],
|
||||
}),
|
||||
{ status: 200 },
|
||||
);
|
||||
});
|
||||
const service = createAiModCreatorService({
|
||||
fetchImpl,
|
||||
now: () => 10_000,
|
||||
});
|
||||
|
||||
await expect(service.generate(context)).resolves.toMatchObject({
|
||||
name: "Rounded card",
|
||||
operations: [{ type: "setStyle", property: "border-radius" }],
|
||||
});
|
||||
expect(fetchImpl).toHaveBeenCalledWith(
|
||||
"https://openrouter.ai/api/v1/chat/completions",
|
||||
expect.objectContaining({ method: "POST" }),
|
||||
);
|
||||
});
|
||||
|
||||
it("retries without structured output when OpenRouter routing fails", async () => {
|
||||
await browser.storage.local.set({
|
||||
"aiModCreator.openRouterApiKey": "sk-or-v1-test-key-123456",
|
||||
});
|
||||
const fetchImpl = jest
|
||||
.fn()
|
||||
.mockResolvedValueOnce(
|
||||
new Response(
|
||||
JSON.stringify({
|
||||
error: {
|
||||
message:
|
||||
"No endpoints found that can handle the requested parameters.",
|
||||
},
|
||||
}),
|
||||
{ status: 404 },
|
||||
),
|
||||
)
|
||||
.mockResolvedValueOnce(
|
||||
new Response(
|
||||
JSON.stringify({
|
||||
choices: [
|
||||
{
|
||||
message: {
|
||||
content: JSON.stringify({
|
||||
name: "Fallback mod",
|
||||
description: "Generated without structured output.",
|
||||
operations: [{ type: "hide", selector: ":scope .meta" }],
|
||||
}),
|
||||
},
|
||||
},
|
||||
],
|
||||
}),
|
||||
{ status: 200 },
|
||||
),
|
||||
);
|
||||
const service = createAiModCreatorService({
|
||||
fetchImpl,
|
||||
now: () => 10_000,
|
||||
});
|
||||
|
||||
await expect(service.generate(context)).resolves.toMatchObject({
|
||||
name: "Fallback mod",
|
||||
});
|
||||
expect(fetchImpl).toHaveBeenCalledTimes(2);
|
||||
const firstBody = JSON.parse(String(fetchImpl.mock.calls[0][1]?.body));
|
||||
const secondBody = JSON.parse(String(fetchImpl.mock.calls[1][1]?.body));
|
||||
expect(firstBody.response_format).toEqual({ type: "json_object" });
|
||||
expect(secondBody.response_format).toBeUndefined();
|
||||
});
|
||||
|
||||
it("streams partial recipe content and token usage", async () => {
|
||||
await browser.storage.local.set({
|
||||
"aiModCreator.openRouterApiKey": "sk-or-v1-test-key-123456",
|
||||
});
|
||||
const json = JSON.stringify({
|
||||
name: "Streamed mod",
|
||||
description: "Generated incrementally",
|
||||
operations: [{ type: "hide", selector: ":scope .metadata" }],
|
||||
});
|
||||
const first = json.slice(0, 35);
|
||||
const second = json.slice(35);
|
||||
const streamBody = [
|
||||
`data: ${JSON.stringify({ choices: [{ delta: { reasoning_details: [{}] } }] })}\n\n`,
|
||||
`data: ${JSON.stringify({ choices: [{ delta: { content: first } }] })}\n\n`,
|
||||
`data: ${JSON.stringify({ choices: [{ delta: { content: second } }], usage: { prompt_tokens: 20, completion_tokens: 30 } })}\n\n`,
|
||||
"data: [DONE]\n\n",
|
||||
].join("");
|
||||
const service = createAiModCreatorService({
|
||||
fetchImpl: jest.fn(async () =>
|
||||
new Response(streamBody, {
|
||||
status: 200,
|
||||
headers: { "Content-Type": "text/event-stream" },
|
||||
}),
|
||||
),
|
||||
now: () => 20_000,
|
||||
});
|
||||
const progress: unknown[] = [];
|
||||
|
||||
await expect(
|
||||
service.streamGenerate(context, (update) => progress.push(update)),
|
||||
).resolves.toMatchObject({ name: "Streamed mod" });
|
||||
expect(progress).toEqual(
|
||||
expect.arrayContaining([
|
||||
{ type: "status", text: "Connecting to MiniMax M2.7 (free)…" },
|
||||
{ type: "status", text: "Model is reasoning…" },
|
||||
{ type: "content", text: first },
|
||||
{
|
||||
type: "usage",
|
||||
promptTokens: 20,
|
||||
completionTokens: 30,
|
||||
},
|
||||
]),
|
||||
);
|
||||
});
|
||||
|
||||
it("surfaces stream rate-limit errors with actionable guidance", async () => {
|
||||
await browser.storage.local.set({
|
||||
"aiModCreator.openRouterApiKey": "sk-or-v1-test-key-123456",
|
||||
});
|
||||
const streamBody = [
|
||||
": OPENROUTER PROCESSING\n\n",
|
||||
`data: ${JSON.stringify({
|
||||
error: {
|
||||
code: 429,
|
||||
message: "Provider returned error",
|
||||
metadata: { error_type: "rate_limit_exceeded" },
|
||||
},
|
||||
})}\n\n`,
|
||||
].join("");
|
||||
const service = createAiModCreatorService({
|
||||
fetchImpl: jest.fn(async () =>
|
||||
new Response(streamBody, {
|
||||
status: 200,
|
||||
headers: { "Content-Type": "text/event-stream" },
|
||||
}),
|
||||
),
|
||||
now: () => 20_000,
|
||||
});
|
||||
|
||||
await expect(service.streamGenerate(context, () => {})).rejects.toThrow(
|
||||
/Rate limit reached for MiniMax M2\.7 \(free\)/,
|
||||
);
|
||||
});
|
||||
|
||||
it("formats free-tier rate-limit guidance", () => {
|
||||
expect(
|
||||
formatOpenRouterError(
|
||||
{
|
||||
code: 429,
|
||||
message: "Provider returned error",
|
||||
metadata: { error_type: "rate_limit_exceeded" },
|
||||
},
|
||||
"minimax/minimax-m2.7:free",
|
||||
),
|
||||
).toMatch(/switch model/i);
|
||||
});
|
||||
|
||||
it("rejects missing keys, oversized input, throttling, and provider errors", async () => {
|
||||
const service = createAiModCreatorService({
|
||||
fetchImpl: jest.fn(),
|
||||
now: () => 1_000,
|
||||
});
|
||||
await expect(service.generate(context)).rejects.toThrow("API key");
|
||||
|
||||
await service.saveKey("sk-or-v1-test-key-123456");
|
||||
await expect(
|
||||
service.generate({ ...context, request: "x".repeat(2_001) }),
|
||||
).rejects.toThrow("too long");
|
||||
|
||||
const failingService = createAiModCreatorService({
|
||||
fetchImpl: jest.fn(async () =>
|
||||
new Response(
|
||||
JSON.stringify({
|
||||
error: {
|
||||
message: "Free model rate limit reached",
|
||||
code: 429,
|
||||
metadata: { error_type: "rate_limit_exceeded" },
|
||||
},
|
||||
}),
|
||||
{ status: 429 },
|
||||
),
|
||||
),
|
||||
now: () => 10_000,
|
||||
});
|
||||
await expect(failingService.generate(context)).rejects.toThrow(
|
||||
/Rate limit reached for MiniMax M2\.7 \(free\)/,
|
||||
);
|
||||
await expect(failingService.generate(context)).rejects.toThrow(
|
||||
/Please wait \d+s/,
|
||||
);
|
||||
});
|
||||
|
||||
it("rejects untrusted runtime message senders", () => {
|
||||
const sendResponse = jest.fn();
|
||||
const handled = handleAiModCreatorMessage(
|
||||
{
|
||||
type: AI_MOD_CREATOR_MESSAGE_TYPE,
|
||||
action: "status",
|
||||
},
|
||||
{ id: "another-extension" } as browser.Runtime.MessageSender,
|
||||
sendResponse,
|
||||
() => false,
|
||||
);
|
||||
|
||||
expect(handled).toBe(false);
|
||||
expect(sendResponse).toHaveBeenCalledWith({
|
||||
success: false,
|
||||
error: "Unauthorized sender",
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,738 @@
|
||||
import browser from "webextension-polyfill";
|
||||
import {
|
||||
buildAiModMessages,
|
||||
} from "@/plugins/built-in/aiModCreator/prompt";
|
||||
import {
|
||||
formatRecipeValidationError,
|
||||
parseGeneratedModDraft,
|
||||
} from "@/plugins/built-in/aiModCreator/recipeSchema";
|
||||
import { aiModLog } from "@/plugins/built-in/aiModCreator/logger";
|
||||
import {
|
||||
DEFAULT_OPENROUTER_MODEL_ID,
|
||||
getModelOption,
|
||||
validateModelId,
|
||||
} from "@/plugins/built-in/aiModCreator/models";
|
||||
import {
|
||||
OPENROUTER_API_KEY_STORAGE_KEY,
|
||||
OPENROUTER_MODEL_STORAGE_KEY,
|
||||
} from "@/plugins/built-in/aiModCreator/storage";
|
||||
import {
|
||||
executeAdvancedMod,
|
||||
getAdvancedScriptSupport,
|
||||
stopAdvancedMod,
|
||||
} from "./aiModUserScripts";
|
||||
import type {
|
||||
GenerationProgress,
|
||||
GeneratedModDraft,
|
||||
KeyStatus,
|
||||
SelectedElementContext,
|
||||
StoredModRecipe,
|
||||
} from "@/plugins/built-in/aiModCreator/types";
|
||||
|
||||
export const AI_MOD_CREATOR_MESSAGE_TYPE = "aiModCreator";
|
||||
export const OPENROUTER_MODEL_ID = DEFAULT_OPENROUTER_MODEL_ID;
|
||||
const OPENROUTER_URL = "https://openrouter.ai/api/v1/chat/completions";
|
||||
const MIN_GENERATION_INTERVAL_MS = 5_000;
|
||||
const ROUTING_ERROR_PATTERN =
|
||||
/no endpoints found|can handle the requested parameters/i;
|
||||
|
||||
type ResponseFormatMode = "json_object" | "none";
|
||||
|
||||
type StorageArea = Pick<
|
||||
browser.Storage.StorageArea,
|
||||
"get" | "set" | "remove"
|
||||
>;
|
||||
type FetchLike = (input: string, init?: RequestInit) => Promise<Response>;
|
||||
type SendResponse = (response: unknown) => void;
|
||||
type TrustCheck = (sender?: browser.Runtime.MessageSender) => boolean;
|
||||
|
||||
function validateApiKey(value: unknown): string {
|
||||
if (typeof value !== "string") throw new Error("API key is required");
|
||||
const key = value.trim();
|
||||
if (key.length < 16 || key.length > 512) {
|
||||
throw new Error("API key must be between 16 and 512 characters");
|
||||
}
|
||||
return key;
|
||||
}
|
||||
|
||||
function validateContext(value: unknown): SelectedElementContext {
|
||||
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
||||
throw new Error("Selected element context is required");
|
||||
}
|
||||
const context = value as SelectedElementContext;
|
||||
const limits: Array<[keyof SelectedElementContext, number]> = [
|
||||
["route", 256],
|
||||
["rootSelector", 1_000],
|
||||
["request", 2_000],
|
||||
["userContext", 4_000],
|
||||
["selectedHtml", 24_000],
|
||||
["ancestorHtml", 6_000],
|
||||
["tagName", 80],
|
||||
];
|
||||
for (const [key, limit] of limits) {
|
||||
const field = context[key];
|
||||
if (field === undefined) continue;
|
||||
if (typeof field !== "string") throw new Error(`${key} must be text`);
|
||||
if (field.length > limit) throw new Error(`${key} is too long`);
|
||||
}
|
||||
if (!Array.isArray(context.domCatalog)) {
|
||||
throw new Error("domCatalog is required");
|
||||
}
|
||||
if (context.domCatalog.length > 100) {
|
||||
throw new Error("domCatalog must contain at most 100 entries");
|
||||
}
|
||||
for (const entry of context.domCatalog) {
|
||||
if (!entry || typeof entry !== "object") {
|
||||
throw new Error("domCatalog entries must be objects");
|
||||
}
|
||||
if (typeof entry.selector !== "string" || entry.selector.length > 500) {
|
||||
throw new Error("domCatalog selector is invalid");
|
||||
}
|
||||
if (typeof entry.tag !== "string" || entry.tag.length > 80) {
|
||||
throw new Error("domCatalog tag is invalid");
|
||||
}
|
||||
if (
|
||||
entry.layout &&
|
||||
(typeof entry.layout !== "object" ||
|
||||
Array.isArray(entry.layout) ||
|
||||
Object.keys(entry.layout).length > 24)
|
||||
) {
|
||||
throw new Error("domCatalog layout summary is invalid");
|
||||
}
|
||||
for (const countKey of ["rowCount", "columnCount", "itemCount"] as const) {
|
||||
const count = entry[countKey];
|
||||
if (count === undefined) continue;
|
||||
if (!Number.isFinite(count) || count < 0 || count > 10_000) {
|
||||
throw new Error(`domCatalog ${countKey} is invalid`);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (context.parentChain !== undefined) {
|
||||
if (!Array.isArray(context.parentChain)) {
|
||||
throw new Error("parentChain must be an array");
|
||||
}
|
||||
if (context.parentChain.length > 3) {
|
||||
throw new Error("parentChain must contain at most 3 entries");
|
||||
}
|
||||
for (const entry of context.parentChain) {
|
||||
if (!entry || typeof entry !== "object") {
|
||||
throw new Error("parentChain entries must be objects");
|
||||
}
|
||||
if (typeof entry.tag !== "string" || entry.tag.length > 80) {
|
||||
throw new Error("parentChain tag is invalid");
|
||||
}
|
||||
if (!Array.isArray(entry.classes) || entry.classes.length > 8) {
|
||||
throw new Error("parentChain classes are invalid");
|
||||
}
|
||||
for (const className of entry.classes) {
|
||||
if (typeof className !== "string" || className.length > 80) {
|
||||
throw new Error("parentChain class name is invalid");
|
||||
}
|
||||
}
|
||||
if (
|
||||
!entry.layout ||
|
||||
typeof entry.layout !== "object" ||
|
||||
Array.isArray(entry.layout) ||
|
||||
Object.keys(entry.layout).length > 24
|
||||
) {
|
||||
throw new Error("parentChain layout summary is invalid");
|
||||
}
|
||||
}
|
||||
}
|
||||
if (context.structuralHints !== undefined) {
|
||||
const hints = context.structuralHints;
|
||||
if (!hints || typeof hints !== "object" || Array.isArray(hints)) {
|
||||
throw new Error("structuralHints must be an object");
|
||||
}
|
||||
if (typeof hints.hasTable !== "boolean" || typeof hints.hasList !== "boolean") {
|
||||
throw new Error("structuralHints flags are invalid");
|
||||
}
|
||||
if (!Array.isArray(hints.primaryClasses) || hints.primaryClasses.length > 8) {
|
||||
throw new Error("structuralHints primaryClasses are invalid");
|
||||
}
|
||||
for (const className of hints.primaryClasses) {
|
||||
if (typeof className !== "string" || className.length > 80) {
|
||||
throw new Error("structuralHints class name is invalid");
|
||||
}
|
||||
}
|
||||
for (const countKey of ["rowCount", "columnCount", "itemCount"] as const) {
|
||||
const count = hints[countKey];
|
||||
if (count === undefined) continue;
|
||||
if (!Number.isFinite(count) || count < 0 || count > 10_000) {
|
||||
throw new Error(`structuralHints ${countKey} is invalid`);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!context.request.trim()) throw new Error("Change request is required");
|
||||
if (
|
||||
!context.dimensions ||
|
||||
!Number.isFinite(context.dimensions.width) ||
|
||||
!Number.isFinite(context.dimensions.height)
|
||||
) {
|
||||
throw new Error("Element dimensions are invalid");
|
||||
}
|
||||
if (
|
||||
!context.computedStyle ||
|
||||
typeof context.computedStyle !== "object" ||
|
||||
Array.isArray(context.computedStyle) ||
|
||||
Object.keys(context.computedStyle).length > 20
|
||||
) {
|
||||
throw new Error("Computed style summary is invalid");
|
||||
}
|
||||
return {
|
||||
...context,
|
||||
dimensions: { ...context.dimensions },
|
||||
computedStyle: { ...context.computedStyle },
|
||||
domCatalog: context.domCatalog.map((entry) => ({
|
||||
...entry,
|
||||
classes: [...entry.classes],
|
||||
layout: { ...entry.layout },
|
||||
})),
|
||||
...(context.parentChain
|
||||
? {
|
||||
parentChain: context.parentChain.map((entry) => ({
|
||||
...entry,
|
||||
classes: [...entry.classes],
|
||||
layout: { ...entry.layout },
|
||||
})),
|
||||
}
|
||||
: {}),
|
||||
...(context.structuralHints
|
||||
? {
|
||||
structuralHints: {
|
||||
...context.structuralHints,
|
||||
primaryClasses: [...context.structuralHints.primaryClasses],
|
||||
},
|
||||
}
|
||||
: {}),
|
||||
};
|
||||
}
|
||||
|
||||
function responseContent(payload: unknown): string {
|
||||
if (!payload || typeof payload !== "object") {
|
||||
throw new Error("OpenRouter returned an invalid response");
|
||||
}
|
||||
const choices = (payload as { choices?: unknown }).choices;
|
||||
if (!Array.isArray(choices) || choices.length === 0) {
|
||||
throw new Error("OpenRouter returned no choices");
|
||||
}
|
||||
const content = (
|
||||
choices[0] as { message?: { content?: unknown } }
|
||||
).message?.content;
|
||||
if (typeof content === "string") return content;
|
||||
if (Array.isArray(content)) {
|
||||
const combined = content
|
||||
.map((part) =>
|
||||
part &&
|
||||
typeof part === "object" &&
|
||||
"text" in part &&
|
||||
typeof part.text === "string"
|
||||
? part.text
|
||||
: "",
|
||||
)
|
||||
.join("");
|
||||
if (combined) return combined;
|
||||
}
|
||||
throw new Error("OpenRouter returned no generated recipe");
|
||||
}
|
||||
|
||||
async function providerError(
|
||||
response: Response,
|
||||
modelId: string,
|
||||
): Promise<string> {
|
||||
const fallback = `OpenRouter request failed (${response.status})`;
|
||||
try {
|
||||
const payload = (await response.json()) as {
|
||||
error?: { message?: unknown; code?: number; metadata?: { error_type?: string } } | string;
|
||||
};
|
||||
if (typeof payload.error === "string") {
|
||||
return formatOpenRouterError({ message: payload.error }, modelId);
|
||||
}
|
||||
if (payload.error && typeof payload.error === "object") {
|
||||
return formatOpenRouterError(payload.error, modelId);
|
||||
}
|
||||
} catch {
|
||||
// Use the status-only fallback without exposing response content.
|
||||
}
|
||||
if (response.status === 429) {
|
||||
return formatOpenRouterError({ code: 429 }, modelId);
|
||||
}
|
||||
return fallback;
|
||||
}
|
||||
|
||||
type OpenRouterErrorShape = {
|
||||
code?: number;
|
||||
message?: string;
|
||||
metadata?: { error_type?: string };
|
||||
};
|
||||
|
||||
export function formatOpenRouterError(
|
||||
error: OpenRouterErrorShape | undefined,
|
||||
modelId: string,
|
||||
): string {
|
||||
if (!error) return "OpenRouter request failed";
|
||||
|
||||
const errorType = error.metadata?.error_type;
|
||||
const message = typeof error.message === "string" ? error.message : "";
|
||||
const isRateLimit =
|
||||
error.code === 429 ||
|
||||
errorType === "rate_limit_exceeded" ||
|
||||
/rate limit/i.test(message);
|
||||
|
||||
if (isRateLimit) {
|
||||
const model = getModelOption(modelId);
|
||||
const tierHint =
|
||||
model?.tier === "free"
|
||||
? "Free models share strict provider limits — wait 1–2 minutes or switch model in the creator panel."
|
||||
: "Wait a minute and try again.";
|
||||
return `Rate limit reached for ${model?.label ?? modelId}. ${tierHint}`;
|
||||
}
|
||||
|
||||
return message || "OpenRouter request failed";
|
||||
}
|
||||
|
||||
function openRouterRequestBody(
|
||||
context: SelectedElementContext,
|
||||
stream: boolean,
|
||||
formatMode: ResponseFormatMode,
|
||||
modelId: string,
|
||||
): Record<string, unknown> {
|
||||
const body: Record<string, unknown> = {
|
||||
model: modelId,
|
||||
messages: buildAiModMessages(context),
|
||||
temperature: 0.2,
|
||||
max_tokens: 8_000,
|
||||
stream,
|
||||
provider: {
|
||||
allow_fallbacks: true,
|
||||
},
|
||||
};
|
||||
|
||||
if (formatMode === "json_object") {
|
||||
body.response_format = { type: "json_object" };
|
||||
}
|
||||
|
||||
return body;
|
||||
}
|
||||
|
||||
function openRouterRequestInit(
|
||||
apiKey: string,
|
||||
context: SelectedElementContext,
|
||||
stream: boolean,
|
||||
formatMode: ResponseFormatMode,
|
||||
modelId: string,
|
||||
): RequestInit {
|
||||
return {
|
||||
method: "POST",
|
||||
headers: {
|
||||
Authorization: `Bearer ${apiKey}`,
|
||||
"Content-Type": "application/json",
|
||||
"HTTP-Referer": "https://betterseqta.org",
|
||||
"X-Title": "BetterSEQTA+ AI Mod Creator",
|
||||
},
|
||||
body: JSON.stringify(
|
||||
openRouterRequestBody(context, stream, formatMode, modelId),
|
||||
),
|
||||
};
|
||||
}
|
||||
|
||||
function isRoutingError(message: string): boolean {
|
||||
return ROUTING_ERROR_PATTERN.test(message);
|
||||
}
|
||||
|
||||
function parseValidatedDraft(
|
||||
content: string | GeneratedModDraft,
|
||||
): GeneratedModDraft {
|
||||
try {
|
||||
return parseGeneratedModDraft(content);
|
||||
} catch (error) {
|
||||
throw new Error(formatRecipeValidationError(error));
|
||||
}
|
||||
}
|
||||
|
||||
async function requestGeneratedDraft(
|
||||
fetchImpl: FetchLike,
|
||||
apiKey: string,
|
||||
context: SelectedElementContext,
|
||||
stream: boolean,
|
||||
modelId: string,
|
||||
onProgress?: (progress: GenerationProgress) => void,
|
||||
): Promise<GeneratedModDraft> {
|
||||
const modes: ResponseFormatMode[] = ["json_object", "none"];
|
||||
let lastError = "OpenRouter request failed";
|
||||
const modelLabel = getModelOption(modelId)?.label ?? modelId;
|
||||
|
||||
for (const [index, mode] of modes.entries()) {
|
||||
if (index > 0) {
|
||||
aiModLog.warn("background", "Retrying OpenRouter request", { mode, lastError });
|
||||
onProgress?.({
|
||||
type: "status",
|
||||
text: "Retrying with a simpler OpenRouter request…",
|
||||
});
|
||||
} else if (stream) {
|
||||
onProgress?.({ type: "status", text: `Connecting to ${modelLabel}…` });
|
||||
}
|
||||
|
||||
aiModLog.info("background", "Sending OpenRouter request", {
|
||||
mode,
|
||||
stream,
|
||||
model: modelId,
|
||||
route: context.route,
|
||||
rootSelector: context.rootSelector,
|
||||
});
|
||||
|
||||
const response = await fetchImpl(
|
||||
OPENROUTER_URL,
|
||||
openRouterRequestInit(apiKey, context, stream, mode, modelId),
|
||||
);
|
||||
if (response.ok) {
|
||||
aiModLog.info("background", "OpenRouter request succeeded", {
|
||||
mode,
|
||||
stream,
|
||||
status: response.status,
|
||||
});
|
||||
if (stream) {
|
||||
return consumeOpenRouterStream(
|
||||
response,
|
||||
modelId,
|
||||
onProgress ?? (() => {}),
|
||||
);
|
||||
}
|
||||
const payload = await response.json();
|
||||
const content = responseContent(payload);
|
||||
aiModLog.debug("background", "OpenRouter non-stream content", content);
|
||||
return parseValidatedDraft(content);
|
||||
}
|
||||
|
||||
lastError = await providerError(response, modelId);
|
||||
aiModLog.warn("background", "OpenRouter request failed", {
|
||||
mode,
|
||||
stream,
|
||||
status: response.status,
|
||||
error: lastError,
|
||||
});
|
||||
if (!isRoutingError(lastError)) break;
|
||||
}
|
||||
|
||||
throw new Error(lastError);
|
||||
}
|
||||
|
||||
async function consumeOpenRouterStream(
|
||||
response: Response,
|
||||
modelId: string,
|
||||
onProgress: (progress: GenerationProgress) => void,
|
||||
): Promise<GeneratedModDraft> {
|
||||
if (!response.body) throw new Error("OpenRouter returned an empty stream");
|
||||
const reader = response.body.getReader();
|
||||
const decoder = new TextDecoder();
|
||||
let buffer = "";
|
||||
let generatedContent = "";
|
||||
let reasoningStarted = false;
|
||||
|
||||
const processEvent = (event: string) => {
|
||||
const data = event
|
||||
.split(/\r?\n/)
|
||||
.filter((line) => line.startsWith("data:"))
|
||||
.map((line) => line.slice(5).trim())
|
||||
.join("");
|
||||
if (!data || data === "[DONE]") return;
|
||||
|
||||
const chunk = JSON.parse(data) as {
|
||||
error?: OpenRouterErrorShape;
|
||||
choices?: Array<{
|
||||
delta?: {
|
||||
content?: string | null;
|
||||
reasoning_details?: unknown[];
|
||||
};
|
||||
error?: OpenRouterErrorShape;
|
||||
}>;
|
||||
usage?: {
|
||||
prompt_tokens?: number;
|
||||
completion_tokens?: number;
|
||||
};
|
||||
};
|
||||
const streamError = chunk.error ?? chunk.choices?.[0]?.error;
|
||||
if (streamError) {
|
||||
aiModLog.warn("background", "OpenRouter stream error chunk", streamError);
|
||||
throw new Error(formatOpenRouterError(streamError, modelId));
|
||||
}
|
||||
|
||||
const delta = chunk.choices?.[0]?.delta;
|
||||
if (Array.isArray(delta?.reasoning_details) && !reasoningStarted) {
|
||||
reasoningStarted = true;
|
||||
onProgress({ type: "status", text: "Model is reasoning…" });
|
||||
}
|
||||
if (typeof delta?.content === "string" && delta.content) {
|
||||
generatedContent += delta.content;
|
||||
onProgress({ type: "content", text: delta.content });
|
||||
}
|
||||
if (chunk.usage) {
|
||||
onProgress({
|
||||
type: "usage",
|
||||
promptTokens: chunk.usage.prompt_tokens,
|
||||
completionTokens: chunk.usage.completion_tokens,
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
while (true) {
|
||||
const { value, done } = await reader.read();
|
||||
buffer += decoder.decode(value, { stream: !done });
|
||||
const events = buffer.split(/\r?\n\r?\n/);
|
||||
buffer = events.pop() ?? "";
|
||||
for (const event of events) processEvent(event);
|
||||
if (done) break;
|
||||
}
|
||||
if (buffer.trim()) processEvent(buffer);
|
||||
aiModLog.debug("background", "Completed OpenRouter stream", {
|
||||
contentLength: generatedContent.length,
|
||||
preview: generatedContent.slice(0, 500),
|
||||
});
|
||||
return parseValidatedDraft(generatedContent);
|
||||
}
|
||||
|
||||
export function createAiModCreatorService(
|
||||
dependencies: {
|
||||
storage?: StorageArea;
|
||||
fetchImpl?: FetchLike;
|
||||
now?: () => number;
|
||||
} = {},
|
||||
) {
|
||||
const storage = dependencies.storage ?? browser.storage.local;
|
||||
const fetchImpl = dependencies.fetchImpl ?? fetch;
|
||||
const now = dependencies.now ?? Date.now;
|
||||
let inFlight = false;
|
||||
let lastGenerationAt = Number.NEGATIVE_INFINITY;
|
||||
|
||||
const getStoredKey = async (): Promise<string | null> => {
|
||||
const result = await storage.get(OPENROUTER_API_KEY_STORAGE_KEY);
|
||||
const value = result[OPENROUTER_API_KEY_STORAGE_KEY];
|
||||
return typeof value === "string" && value.length > 0 ? value : null;
|
||||
};
|
||||
|
||||
const getStoredModelId = async (): Promise<string> => {
|
||||
const result = await storage.get(OPENROUTER_MODEL_STORAGE_KEY);
|
||||
const value = result[OPENROUTER_MODEL_STORAGE_KEY];
|
||||
if (typeof value === "string" && value.length > 0) {
|
||||
try {
|
||||
return validateModelId(value);
|
||||
} catch {
|
||||
aiModLog.warn("background", "Ignoring invalid stored model id", value);
|
||||
}
|
||||
}
|
||||
return DEFAULT_OPENROUTER_MODEL_ID;
|
||||
};
|
||||
|
||||
const beginGeneration = () => {
|
||||
const currentTime = now();
|
||||
if (inFlight) {
|
||||
throw new Error("A generation is already in progress");
|
||||
}
|
||||
if (currentTime - lastGenerationAt < MIN_GENERATION_INTERVAL_MS) {
|
||||
const waitSeconds = Math.ceil(
|
||||
(MIN_GENERATION_INTERVAL_MS - (currentTime - lastGenerationAt)) / 1000,
|
||||
);
|
||||
throw new Error(
|
||||
`Please wait ${waitSeconds}s before generating another mod`,
|
||||
);
|
||||
}
|
||||
inFlight = true;
|
||||
lastGenerationAt = currentTime;
|
||||
};
|
||||
|
||||
return {
|
||||
async saveKey(apiKey: unknown): Promise<void> {
|
||||
await storage.set({
|
||||
[OPENROUTER_API_KEY_STORAGE_KEY]: validateApiKey(apiKey),
|
||||
});
|
||||
},
|
||||
|
||||
async clearKey(): Promise<void> {
|
||||
await storage.remove(OPENROUTER_API_KEY_STORAGE_KEY);
|
||||
},
|
||||
|
||||
async getKeyStatus(): Promise<KeyStatus> {
|
||||
return { configured: (await getStoredKey()) !== null };
|
||||
},
|
||||
|
||||
async getModelSettings() {
|
||||
return { modelId: await getStoredModelId() };
|
||||
},
|
||||
|
||||
async saveModel(modelId: unknown): Promise<void> {
|
||||
await storage.set({
|
||||
[OPENROUTER_MODEL_STORAGE_KEY]: validateModelId(modelId),
|
||||
});
|
||||
aiModLog.info("background", "Saved OpenRouter model", modelId);
|
||||
},
|
||||
|
||||
async generate(input: unknown): Promise<GeneratedModDraft> {
|
||||
const context = validateContext(input);
|
||||
const apiKey = await getStoredKey();
|
||||
if (!apiKey) throw new Error("OpenRouter API key is not configured");
|
||||
const modelId = await getStoredModelId();
|
||||
beginGeneration();
|
||||
|
||||
try {
|
||||
return await requestGeneratedDraft(
|
||||
fetchImpl,
|
||||
apiKey,
|
||||
context,
|
||||
false,
|
||||
modelId,
|
||||
);
|
||||
} finally {
|
||||
inFlight = false;
|
||||
}
|
||||
},
|
||||
|
||||
async streamGenerate(
|
||||
input: unknown,
|
||||
onProgress: (progress: GenerationProgress) => void,
|
||||
): Promise<GeneratedModDraft> {
|
||||
const context = validateContext(input);
|
||||
const apiKey = await getStoredKey();
|
||||
if (!apiKey) throw new Error("OpenRouter API key is not configured");
|
||||
const modelId = await getStoredModelId();
|
||||
beginGeneration();
|
||||
|
||||
try {
|
||||
return await requestGeneratedDraft(
|
||||
fetchImpl,
|
||||
apiKey,
|
||||
context,
|
||||
true,
|
||||
modelId,
|
||||
onProgress,
|
||||
);
|
||||
} finally {
|
||||
inFlight = false;
|
||||
}
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
const defaultService = createAiModCreatorService();
|
||||
|
||||
export function handleAiModCreatorMessage(
|
||||
request: {
|
||||
type?: string;
|
||||
action?: string;
|
||||
apiKey?: unknown;
|
||||
context?: unknown;
|
||||
recipe?: unknown;
|
||||
id?: unknown;
|
||||
modelId?: unknown;
|
||||
},
|
||||
sender: browser.Runtime.MessageSender,
|
||||
sendResponse: SendResponse,
|
||||
isTrustedSender: TrustCheck,
|
||||
): boolean {
|
||||
if (!isTrustedSender(sender)) {
|
||||
sendResponse({ success: false, error: "Unauthorized sender" });
|
||||
return false;
|
||||
}
|
||||
|
||||
const action = request.action;
|
||||
aiModLog.debug("background", "Handling message", {
|
||||
action,
|
||||
tabId: sender.tab?.id,
|
||||
senderId: sender.id,
|
||||
});
|
||||
void (async () => {
|
||||
try {
|
||||
let data: unknown;
|
||||
if (action === "saveKey") {
|
||||
await defaultService.saveKey(request.apiKey);
|
||||
} else if (action === "clearKey") {
|
||||
await defaultService.clearKey();
|
||||
} else if (action === "status") {
|
||||
data = await defaultService.getKeyStatus();
|
||||
} else if (action === "getModel") {
|
||||
data = await defaultService.getModelSettings();
|
||||
} else if (action === "saveModel") {
|
||||
await defaultService.saveModel(request.modelId);
|
||||
} else if (action === "advancedSupport") {
|
||||
data = getAdvancedScriptSupport();
|
||||
} else if (action === "generate") {
|
||||
data = await defaultService.generate(request.context);
|
||||
} else if (action === "executeAdvanced") {
|
||||
if (sender.tab?.id === undefined) {
|
||||
throw new Error("Advanced scripts require a SEQTA browser tab");
|
||||
}
|
||||
const { devMode } = await browser.storage.local.get("devMode");
|
||||
if (devMode !== true) {
|
||||
throw new Error("Advanced scripts are available only in developer mode");
|
||||
}
|
||||
await executeAdvancedMod(
|
||||
request.recipe as StoredModRecipe,
|
||||
sender.tab.id,
|
||||
);
|
||||
} else if (action === "stopAdvanced") {
|
||||
if (sender.tab?.id === undefined || typeof request.id !== "string") {
|
||||
throw new Error("Advanced script id or tab is missing");
|
||||
}
|
||||
await stopAdvancedMod(request.id, sender.tab.id);
|
||||
} else {
|
||||
throw new Error("Unsupported AI Mod Creator action");
|
||||
}
|
||||
sendResponse({ success: true, data });
|
||||
aiModLog.debug("background", "Message handled", { action });
|
||||
} catch (error) {
|
||||
const message =
|
||||
error instanceof Error ? error.message : "AI request failed";
|
||||
aiModLog.error("background", "Message failed", { action, error: message });
|
||||
sendResponse({
|
||||
success: false,
|
||||
error: message,
|
||||
});
|
||||
}
|
||||
})();
|
||||
return true;
|
||||
}
|
||||
|
||||
export function registerAiModCreatorStreaming(
|
||||
isTrustedSender: TrustCheck,
|
||||
): void {
|
||||
browser.runtime.onConnect.addListener((port) => {
|
||||
if (port.name !== "aiModCreator.stream") return;
|
||||
if (!isTrustedSender(port.sender)) {
|
||||
port.postMessage({ type: "error", error: "Unauthorized sender" });
|
||||
port.disconnect();
|
||||
return;
|
||||
}
|
||||
|
||||
let started = false;
|
||||
port.onMessage.addListener((message: unknown) => {
|
||||
if (started) return;
|
||||
started = true;
|
||||
const context =
|
||||
message && typeof message === "object" && "context" in message
|
||||
? (message as { context?: unknown }).context
|
||||
: undefined;
|
||||
aiModLog.info("background", "Starting streamed generation");
|
||||
void defaultService
|
||||
.streamGenerate(context, (progress) => {
|
||||
port.postMessage({ type: "progress", progress });
|
||||
})
|
||||
.then((draft) => {
|
||||
aiModLog.info("background", "Streamed generation complete", {
|
||||
name: draft.name,
|
||||
operationCount: draft.operations.length,
|
||||
});
|
||||
port.postMessage({ type: "done", draft });
|
||||
port.disconnect();
|
||||
})
|
||||
.catch((error) => {
|
||||
const message =
|
||||
error instanceof Error ? error.message : "AI streaming failed";
|
||||
aiModLog.error("background", "Streamed generation failed", message);
|
||||
port.postMessage({
|
||||
type: "error",
|
||||
error: message,
|
||||
});
|
||||
port.disconnect();
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
import { buildExecutionSource } from "./aiModUserScripts";
|
||||
import type { StoredModRecipe } from "@/plugins/built-in/aiModCreator/types";
|
||||
|
||||
const baseRecipe: StoredModRecipe = {
|
||||
schemaVersion: 1,
|
||||
id: "mod-test",
|
||||
enabled: true,
|
||||
route: "welcome",
|
||||
rootSelector: "#titlebar",
|
||||
name: "Test mod",
|
||||
description: "Test",
|
||||
operations: [],
|
||||
advancedScript: `
|
||||
const house = select('.userInfohouse');
|
||||
if (!house) throw new Error('Missing .userInfohouse inside selected root');
|
||||
return () => {};
|
||||
`,
|
||||
createdAt: 1,
|
||||
updatedAt: 1,
|
||||
};
|
||||
|
||||
describe("advanced user script injection source", () => {
|
||||
it("does not declare select twice in the generated runtime", () => {
|
||||
const source = buildExecutionSource(baseRecipe);
|
||||
expect(source.match(/\bconst select\b/g)?.length).toBe(1);
|
||||
expect(source.match(/\bconst selectAll\b/g)?.length).toBe(1);
|
||||
});
|
||||
|
||||
it("throws when the selected root is missing", () => {
|
||||
const source = buildExecutionSource(baseRecipe);
|
||||
expect(source).toContain("AI mod root not found on this page");
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,290 @@
|
||||
import {
|
||||
SAFE_ATTRIBUTE_NAMES,
|
||||
SAFE_INSERT_TAGS,
|
||||
SAFE_STYLE_PROPERTIES,
|
||||
validateStoredRecipes,
|
||||
} from "@/plugins/built-in/aiModCreator/recipeSchema";
|
||||
import { assertAdvancedScriptSafe } from "@/plugins/built-in/aiModCreator/scriptSafety";
|
||||
import type { StoredModRecipe } from "@/plugins/built-in/aiModCreator/types";
|
||||
|
||||
interface UserScriptsApi {
|
||||
configureWorld(details: {
|
||||
worldId: string;
|
||||
csp: string;
|
||||
messaging: boolean;
|
||||
}): Promise<void>;
|
||||
execute(details: {
|
||||
target: { tabId: number; allFrames: boolean };
|
||||
worldId: string;
|
||||
world: "USER_SCRIPT";
|
||||
injectImmediately: boolean;
|
||||
js: Array<{ code: string }>;
|
||||
}): Promise<unknown>;
|
||||
}
|
||||
|
||||
const USER_SCRIPT_CSP = [
|
||||
"default-src 'none'",
|
||||
"script-src 'self' 'unsafe-inline'",
|
||||
"connect-src 'none'",
|
||||
"img-src 'none'",
|
||||
"media-src 'none'",
|
||||
"font-src 'none'",
|
||||
"object-src 'none'",
|
||||
"frame-src 'none'",
|
||||
"child-src 'none'",
|
||||
"form-action 'none'",
|
||||
"base-uri 'none'",
|
||||
].join("; ");
|
||||
|
||||
function getUserScriptsApi(): UserScriptsApi {
|
||||
const globalApis = globalThis as unknown as {
|
||||
chrome?: { userScripts?: UserScriptsApi };
|
||||
browser?: { userScripts?: UserScriptsApi };
|
||||
};
|
||||
const api =
|
||||
globalApis.chrome?.userScripts ?? globalApis.browser?.userScripts;
|
||||
if (!api?.execute || !api.configureWorld) {
|
||||
throw new Error(
|
||||
"Advanced scripts require Chrome User Scripts support.",
|
||||
);
|
||||
}
|
||||
return api;
|
||||
}
|
||||
|
||||
export const ADVANCED_SCRIPT_SETUP_INSTRUCTIONS = [
|
||||
"Open chrome://extensions",
|
||||
"Find BetterSEQTA+ and open Details",
|
||||
'Enable "Allow User Scripts"',
|
||||
"Reload this SEQTA tab, then enable the mod again",
|
||||
].join("\n");
|
||||
|
||||
export function getAdvancedScriptSupport(): {
|
||||
supported: boolean;
|
||||
reason?: string;
|
||||
instructions?: string;
|
||||
} {
|
||||
try {
|
||||
getUserScriptsApi();
|
||||
return { supported: true };
|
||||
} catch (error) {
|
||||
return {
|
||||
supported: false,
|
||||
reason:
|
||||
error instanceof Error
|
||||
? error.message
|
||||
: "Advanced scripts are unavailable in this browser",
|
||||
instructions: ADVANCED_SCRIPT_SETUP_INSTRUCTIONS,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
function worldId(id: string): string {
|
||||
return `bsplus-${id}`.slice(0, 256);
|
||||
}
|
||||
|
||||
export function buildExecutionSource(recipe: StoredModRecipe): string {
|
||||
const script = assertAdvancedScriptSafe(recipe.advancedScript);
|
||||
const config = JSON.stringify({
|
||||
id: recipe.id,
|
||||
route: recipe.route,
|
||||
rootSelector: recipe.rootSelector,
|
||||
allowedAttributes: SAFE_ATTRIBUTE_NAMES,
|
||||
allowedStyles: SAFE_STYLE_PROPERTIES,
|
||||
allowedTags: SAFE_INSERT_TAGS,
|
||||
});
|
||||
|
||||
return `(() => {
|
||||
"use strict";
|
||||
const config = ${config};
|
||||
const registryKey = Symbol.for("betterseqta.aiModRuntime");
|
||||
const registry = globalThis[registryKey] ?? (globalThis[registryKey] = new Map());
|
||||
const previousCleanup = registry.get(config.id);
|
||||
if (typeof previousCleanup === "function") previousCleanup();
|
||||
|
||||
const route = (location.hash.split("?page=/")[1] ?? "").split(/[/?#]/)[0];
|
||||
if (config.route && route !== config.route) {
|
||||
throw new Error("AI mod route mismatch: expected " + config.route + " but page is " + route);
|
||||
}
|
||||
const root = document.querySelector(config.rootSelector);
|
||||
if (!(root instanceof HTMLElement)) {
|
||||
throw new Error("AI mod root not found on this page: " + config.rootSelector);
|
||||
}
|
||||
|
||||
const cleanups = [];
|
||||
const remember = (cleanup) => {
|
||||
if (typeof cleanup === "function") cleanups.push(cleanup);
|
||||
return cleanup;
|
||||
};
|
||||
const insideRoot = (element) =>
|
||||
element instanceof Element && (element === root || root.contains(element));
|
||||
const requireInsideRoot = (element) => {
|
||||
if (!insideRoot(element)) throw new Error("AI mod attempted to leave its selected root");
|
||||
return element;
|
||||
};
|
||||
const query = (selector = ":scope") =>
|
||||
selector === ":scope" ? root : root.querySelector(selector);
|
||||
const queryAll = (selector = ":scope") =>
|
||||
selector === ":scope" ? [root] : Array.from(root.querySelectorAll(selector));
|
||||
|
||||
const bsplus = Object.freeze({
|
||||
root,
|
||||
select: query,
|
||||
selectAll: queryAll,
|
||||
onCleanup: remember,
|
||||
setText(element, text) {
|
||||
requireInsideRoot(element);
|
||||
const previous = element.textContent;
|
||||
element.textContent = String(text);
|
||||
remember(() => { element.textContent = previous; });
|
||||
return element;
|
||||
},
|
||||
setStyle(element, property, value) {
|
||||
requireInsideRoot(element);
|
||||
if (!config.allowedStyles.includes(property)) throw new Error("Unsupported style property");
|
||||
const previous = element.style.getPropertyValue(property);
|
||||
const priority = element.style.getPropertyPriority(property);
|
||||
element.style.setProperty(property, String(value).replace(/\\s*!important\\s*$/i, "").trim(), "important");
|
||||
remember(() => previous
|
||||
? element.style.setProperty(property, previous, priority)
|
||||
: element.style.removeProperty(property));
|
||||
return element;
|
||||
},
|
||||
setAttribute(element, name, value) {
|
||||
requireInsideRoot(element);
|
||||
if (!config.allowedAttributes.includes(name)) throw new Error("Unsupported attribute");
|
||||
const hadAttribute = element.hasAttribute(name);
|
||||
const previous = element.getAttribute(name);
|
||||
element.setAttribute(name, String(value));
|
||||
remember(() => hadAttribute
|
||||
? element.setAttribute(name, previous ?? "")
|
||||
: element.removeAttribute(name));
|
||||
return element;
|
||||
},
|
||||
create(tag, text, parent = root) {
|
||||
requireInsideRoot(parent);
|
||||
if (!config.allowedTags.includes(tag)) throw new Error("Unsupported element tag");
|
||||
const element = document.createElement(tag);
|
||||
element.textContent = String(text);
|
||||
parent.append(element);
|
||||
remember(() => element.remove());
|
||||
return element;
|
||||
},
|
||||
on(element, event, handler, options) {
|
||||
requireInsideRoot(element);
|
||||
element.addEventListener(event, handler, options);
|
||||
remember(() => element.removeEventListener(event, handler, options));
|
||||
},
|
||||
observe(element, callback, options = { childList: true, subtree: true }) {
|
||||
requireInsideRoot(element);
|
||||
const observer = new MutationObserver(callback);
|
||||
observer.observe(element, options);
|
||||
remember(() => observer.disconnect());
|
||||
return observer;
|
||||
},
|
||||
});
|
||||
|
||||
const select = bsplus.select;
|
||||
const selectAll = bsplus.selectAll;
|
||||
|
||||
let disposed = false;
|
||||
const cleanup = () => {
|
||||
if (disposed) return;
|
||||
disposed = true;
|
||||
for (const callback of cleanups.reverse()) {
|
||||
try { callback(); } catch (error) { console.warn("[BetterSEQTA+ AI Mod] Cleanup failed", error); }
|
||||
}
|
||||
registry.delete(config.id);
|
||||
};
|
||||
|
||||
try {
|
||||
const userCleanup = (() => {
|
||||
${script}
|
||||
})();
|
||||
remember(userCleanup);
|
||||
registry.set(config.id, cleanup);
|
||||
return { ok: true };
|
||||
} catch (error) {
|
||||
cleanup();
|
||||
throw error;
|
||||
}
|
||||
})();`;
|
||||
}
|
||||
|
||||
function buildStopSource(id: string): string {
|
||||
return `(() => {
|
||||
const registry = globalThis[Symbol.for("betterseqta.aiModRuntime")];
|
||||
const cleanup = registry?.get(${JSON.stringify(id)});
|
||||
if (typeof cleanup === "function") cleanup();
|
||||
})();`;
|
||||
}
|
||||
|
||||
async function configureWorld(api: UserScriptsApi, id: string): Promise<void> {
|
||||
try {
|
||||
await api.configureWorld({
|
||||
worldId: worldId(id),
|
||||
csp: USER_SCRIPT_CSP,
|
||||
messaging: false,
|
||||
});
|
||||
} catch (error) {
|
||||
throw new Error(
|
||||
`Could not configure the isolated script world: ${
|
||||
error instanceof Error ? error.message : "browser rejected it"
|
||||
}`,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
async function executeSource(
|
||||
api: UserScriptsApi,
|
||||
id: string,
|
||||
tabId: number,
|
||||
source: string,
|
||||
): Promise<void> {
|
||||
await configureWorld(api, id);
|
||||
const results = (await api.execute({
|
||||
target: { tabId, allFrames: false },
|
||||
world: "USER_SCRIPT",
|
||||
worldId: worldId(id),
|
||||
injectImmediately: true,
|
||||
js: [{ code: source }],
|
||||
})) as Array<{ result?: unknown; error?: unknown }> | undefined;
|
||||
|
||||
const injectionError = results?.find((entry) => entry.error)?.error;
|
||||
if (injectionError) {
|
||||
throw new Error(
|
||||
injectionError instanceof Error
|
||||
? injectionError.message
|
||||
: String(injectionError),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export async function executeAdvancedMod(
|
||||
input: StoredModRecipe,
|
||||
tabId: number,
|
||||
): Promise<void> {
|
||||
const support = getAdvancedScriptSupport();
|
||||
if (!support.supported) {
|
||||
throw new Error(
|
||||
`${support.reason ?? "Advanced scripts are unavailable"}\n\n${support.instructions ?? ADVANCED_SCRIPT_SETUP_INSTRUCTIONS}`,
|
||||
);
|
||||
}
|
||||
const [recipe] = validateStoredRecipes([input]);
|
||||
if (!recipe.advancedScript) return;
|
||||
await executeSource(
|
||||
getUserScriptsApi(),
|
||||
recipe.id,
|
||||
tabId,
|
||||
buildExecutionSource(recipe),
|
||||
);
|
||||
}
|
||||
|
||||
export async function stopAdvancedMod(
|
||||
id: string,
|
||||
tabId: number,
|
||||
): Promise<void> {
|
||||
const support = getAdvancedScriptSupport();
|
||||
if (!support.supported) return;
|
||||
if (!/^[A-Za-z0-9_-]{1,160}$/.test(id)) throw new Error("Invalid mod id");
|
||||
await executeSource(getUserScriptsApi(), id, tabId, buildStopSource(id));
|
||||
}
|
||||
@@ -0,0 +1,544 @@
|
||||
import {
|
||||
GOOGLE_AUTH_URL,
|
||||
GOOGLE_CALENDAR_ACCOUNTS_NOT_READY_HINT,
|
||||
GOOGLE_CALENDAR_OAUTH_CALLBACK,
|
||||
GOOGLE_CALENDAR_REFRESH_URL,
|
||||
GOOGLE_CALENDAR_SCOPE,
|
||||
GOOGLE_CALENDAR_TOKEN_URL,
|
||||
GOOGLE_OAUTH_CLIENT_ID,
|
||||
googleOAuthRedirectUriHint,
|
||||
isGoogleCalendarConfigured,
|
||||
} from "@/config/googleCalendar";
|
||||
import {
|
||||
OUTLOOK_AUTH_URL,
|
||||
OUTLOOK_CALENDAR_ACCOUNTS_NOT_READY_HINT,
|
||||
OUTLOOK_CALENDAR_OAUTH_CALLBACK,
|
||||
OUTLOOK_CALENDAR_REFRESH_URL,
|
||||
OUTLOOK_CALENDAR_SCOPE,
|
||||
OUTLOOK_CALENDAR_TOKEN_URL,
|
||||
OUTLOOK_OAUTH_CLIENT_ID,
|
||||
isOutlookCalendarConfigured,
|
||||
outlookOAuthRedirectUriHint,
|
||||
} from "@/config/outlookCalendar";
|
||||
import {
|
||||
exchangeAccountsCode,
|
||||
refreshAccountsToken,
|
||||
type AccountsTokenPayload,
|
||||
} from "@/seqta/utils/calendarSync/accountsToken";
|
||||
import {
|
||||
CALENDAR_WEEKLY_ALARM,
|
||||
clampSyncWeeks,
|
||||
getAutoSyncWeekly,
|
||||
getSyncWeeksAhead,
|
||||
isAnyCalendarConnected,
|
||||
markWeeklySyncPending,
|
||||
readSharedCalendarSyncSettings,
|
||||
writeSharedCalendarSyncSettings,
|
||||
} from "@/seqta/utils/calendarSync/settings";
|
||||
import {
|
||||
clearGoogleCalendarState,
|
||||
readGoogleCalendarState,
|
||||
writeGoogleCalendarState,
|
||||
} from "@/seqta/utils/calendarSync/providerStorage";
|
||||
import { ensureGoogleAppCalendar } from "@/seqta/utils/googleCalendar/calendarProvisioning";
|
||||
import type {
|
||||
GoogleCalendarStatus,
|
||||
GoogleCalendarSyncResult,
|
||||
} from "@/seqta/utils/googleCalendar/types";
|
||||
import {
|
||||
clearOutlookCalendarState,
|
||||
readOutlookCalendarState,
|
||||
writeOutlookCalendarState,
|
||||
type OutlookCalendarStatus,
|
||||
} from "@/seqta/utils/calendarSync/providerStorage";
|
||||
import browser from "webextension-polyfill";
|
||||
|
||||
const WEEKLY_PERIOD_MINUTES = 7 * 24 * 60;
|
||||
|
||||
export type CalendarMessageHandler = (
|
||||
request: unknown,
|
||||
sendResponse: (response?: unknown) => void,
|
||||
sender?: browser.Runtime.MessageSender,
|
||||
) => boolean | void;
|
||||
|
||||
export type CalendarMessageHandlerMap = Record<string, CalendarMessageHandler>;
|
||||
|
||||
type StoredTokens = {
|
||||
accessToken?: string;
|
||||
refreshToken?: string;
|
||||
expiresAt?: number;
|
||||
lastSyncAt?: number;
|
||||
lastSyncOrigin?: string;
|
||||
};
|
||||
|
||||
type OAuthTabFlowOptions = {
|
||||
callbackPrefix: string;
|
||||
timeoutMessage: string;
|
||||
cancelledMessage: string;
|
||||
tabOpenErrorMessage: string;
|
||||
timeoutMs?: number;
|
||||
};
|
||||
|
||||
type CalendarProviderBackend = {
|
||||
label: string;
|
||||
isConfigured: () => boolean;
|
||||
redirectHint: () => string;
|
||||
mismatchRe: RegExp;
|
||||
authUrl: string;
|
||||
clientId: string;
|
||||
scope: string;
|
||||
callback: string;
|
||||
tabOpts: Omit<OAuthTabFlowOptions, "callbackPrefix">;
|
||||
notConfiguredError: string;
|
||||
notConnectedError: string;
|
||||
signInFailed: string;
|
||||
read: () => Promise<StoredTokens>;
|
||||
write: (patch: Partial<StoredTokens> & { connectedAt?: number }) => Promise<unknown>;
|
||||
clear: () => Promise<unknown>;
|
||||
exchange: (code: string, redirectUri: string, verifier: string) => Promise<AccountsTokenPayload>;
|
||||
refresh: (refreshToken: string) => Promise<AccountsTokenPayload>;
|
||||
applyAuthParams: (authUrl: URL) => void;
|
||||
messagePrefix: string;
|
||||
afterConnect?: (accessToken: string) => Promise<Partial<StoredTokens>>;
|
||||
};
|
||||
|
||||
function createProviderBackend(
|
||||
config: Omit<CalendarProviderBackend, "exchange" | "refresh"> & {
|
||||
tokenUrl: string;
|
||||
refreshUrl: string;
|
||||
notReadyHint: string;
|
||||
includeErrorDescription?: boolean;
|
||||
},
|
||||
): CalendarProviderBackend {
|
||||
const { tokenUrl, refreshUrl, notReadyHint, includeErrorDescription, ...backend } = config;
|
||||
return {
|
||||
...backend,
|
||||
exchange: (code, redirectUri, verifier) =>
|
||||
exchangeAccountsCode(tokenUrl, code, redirectUri, verifier, notReadyHint, includeErrorDescription),
|
||||
refresh: (refreshToken) =>
|
||||
refreshAccountsToken(refreshUrl, refreshToken, notReadyHint, includeErrorDescription),
|
||||
};
|
||||
}
|
||||
|
||||
const GOOGLE_BACKEND = createProviderBackend({
|
||||
label: "Google",
|
||||
isConfigured: isGoogleCalendarConfigured,
|
||||
redirectHint: googleOAuthRedirectUriHint,
|
||||
mismatchRe: /redirect_uri_mismatch|invalid_request/i,
|
||||
authUrl: GOOGLE_AUTH_URL,
|
||||
clientId: GOOGLE_OAUTH_CLIENT_ID,
|
||||
scope: GOOGLE_CALENDAR_SCOPE,
|
||||
callback: GOOGLE_CALENDAR_OAUTH_CALLBACK,
|
||||
tabOpts: {
|
||||
timeoutMessage: "Google sign-in timed out. Close the tab and try again.",
|
||||
cancelledMessage: "Google sign-in was cancelled.",
|
||||
tabOpenErrorMessage: "Could not open Google sign-in tab.",
|
||||
},
|
||||
notConfiguredError: "Google Calendar is not configured in this extension build.",
|
||||
notConnectedError: "Not connected to Google Calendar.",
|
||||
signInFailed: "Google sign-in failed",
|
||||
read: readGoogleCalendarState,
|
||||
write: writeGoogleCalendarState,
|
||||
clear: clearGoogleCalendarState,
|
||||
applyAuthParams(authUrl) {
|
||||
authUrl.searchParams.set("access_type", "offline");
|
||||
},
|
||||
messagePrefix: "googleCalendar",
|
||||
tokenUrl: GOOGLE_CALENDAR_TOKEN_URL,
|
||||
refreshUrl: GOOGLE_CALENDAR_REFRESH_URL,
|
||||
notReadyHint: GOOGLE_CALENDAR_ACCOUNTS_NOT_READY_HINT,
|
||||
async afterConnect(accessToken) {
|
||||
const state = await readGoogleCalendarState();
|
||||
const calendarId = await ensureGoogleAppCalendar(accessToken, state.calendarId);
|
||||
return { calendarId };
|
||||
},
|
||||
});
|
||||
|
||||
const OUTLOOK_BACKEND = createProviderBackend({
|
||||
label: "Microsoft",
|
||||
isConfigured: isOutlookCalendarConfigured,
|
||||
redirectHint: outlookOAuthRedirectUriHint,
|
||||
mismatchRe: /redirect_uri|invalid_request|AADSTS50011/i,
|
||||
authUrl: OUTLOOK_AUTH_URL,
|
||||
clientId: OUTLOOK_OAUTH_CLIENT_ID,
|
||||
scope: OUTLOOK_CALENDAR_SCOPE,
|
||||
callback: OUTLOOK_CALENDAR_OAUTH_CALLBACK,
|
||||
tabOpts: {
|
||||
timeoutMessage: "Microsoft sign-in timed out. Close the tab and try again.",
|
||||
cancelledMessage: "Microsoft sign-in was cancelled.",
|
||||
tabOpenErrorMessage: "Could not open Microsoft sign-in tab.",
|
||||
},
|
||||
notConfiguredError: "Outlook Calendar is not configured in this extension build.",
|
||||
notConnectedError: "Not connected to Outlook Calendar.",
|
||||
signInFailed: "Microsoft sign-in failed",
|
||||
read: readOutlookCalendarState,
|
||||
write: writeOutlookCalendarState,
|
||||
clear: clearOutlookCalendarState,
|
||||
applyAuthParams(authUrl) {
|
||||
authUrl.searchParams.set("response_mode", "query");
|
||||
},
|
||||
messagePrefix: "outlookCalendar",
|
||||
tokenUrl: OUTLOOK_CALENDAR_TOKEN_URL,
|
||||
refreshUrl: OUTLOOK_CALENDAR_REFRESH_URL,
|
||||
notReadyHint: OUTLOOK_CALENDAR_ACCOUNTS_NOT_READY_HINT,
|
||||
includeErrorDescription: true,
|
||||
});
|
||||
|
||||
function base64UrlEncode(buffer: ArrayBuffer): string {
|
||||
const bytes = new Uint8Array(buffer);
|
||||
let binary = "";
|
||||
for (const b of bytes) binary += String.fromCharCode(b);
|
||||
return btoa(binary).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/g, "");
|
||||
}
|
||||
|
||||
function randomPkceVerifier(): string {
|
||||
const bytes = new Uint8Array(32);
|
||||
crypto.getRandomValues(bytes);
|
||||
return base64UrlEncode(bytes.buffer);
|
||||
}
|
||||
|
||||
async function pkceChallenge(verifier: string): Promise<string> {
|
||||
const data = new TextEncoder().encode(verifier);
|
||||
const digest = await crypto.subtle.digest("SHA-256", data);
|
||||
return base64UrlEncode(digest);
|
||||
}
|
||||
|
||||
function parseOAuthRedirectCode(responseUrl: string, providerLabel: string): string {
|
||||
const url = new URL(responseUrl);
|
||||
const err = url.searchParams.get("error");
|
||||
if (err) throw new Error(url.searchParams.get("error_description") ?? err);
|
||||
const code = url.searchParams.get("code");
|
||||
if (!code) throw new Error(`${providerLabel} sign-in did not return an authorization code.`);
|
||||
return code;
|
||||
}
|
||||
|
||||
function isOAuthCallbackUrl(url: string, callbackPrefix: string): boolean {
|
||||
if (!url.startsWith(callbackPrefix)) return false;
|
||||
const parsed = new URL(url);
|
||||
return parsed.searchParams.has("code") || parsed.searchParams.has("error");
|
||||
}
|
||||
|
||||
function waitForOAuthCallback(authTabId: number, opts: OAuthTabFlowOptions): Promise<string> {
|
||||
const timeoutMs = opts.timeoutMs ?? 10 * 60 * 1000;
|
||||
return new Promise((resolve, reject) => {
|
||||
const timeoutId = setTimeout(() => {
|
||||
cleanup();
|
||||
reject(new Error(opts.timeoutMessage));
|
||||
}, timeoutMs);
|
||||
|
||||
const cleanup = () => {
|
||||
clearTimeout(timeoutId);
|
||||
browser.tabs.onUpdated.removeListener(onUpdated);
|
||||
browser.tabs.onRemoved.removeListener(onRemoved);
|
||||
};
|
||||
|
||||
const finishFromUrl = (url: string, tabId: number) => {
|
||||
if (!isOAuthCallbackUrl(url, opts.callbackPrefix)) return false;
|
||||
cleanup();
|
||||
void browser.tabs.remove(tabId).catch(() => {});
|
||||
resolve(url);
|
||||
return true;
|
||||
};
|
||||
|
||||
const onRemoved = (tabId: number) => {
|
||||
if (tabId !== authTabId) return;
|
||||
cleanup();
|
||||
reject(new Error(opts.cancelledMessage));
|
||||
};
|
||||
|
||||
const onUpdated = (
|
||||
tabId: number,
|
||||
changeInfo: browser.Tabs.OnUpdatedChangeInfoType,
|
||||
tab: browser.Tabs.Tab,
|
||||
) => {
|
||||
if (tabId !== authTabId) return;
|
||||
const url =
|
||||
changeInfo.url ?? (changeInfo.status === "complete" ? tab.url : undefined);
|
||||
if (url) finishFromUrl(url, tabId);
|
||||
};
|
||||
|
||||
browser.tabs.onUpdated.addListener(onUpdated);
|
||||
browser.tabs.onRemoved.addListener(onRemoved);
|
||||
|
||||
void browser.tabs
|
||||
.get(authTabId)
|
||||
.then((tab) => {
|
||||
if (tab.url) finishFromUrl(tab.url, authTabId);
|
||||
})
|
||||
.catch(() => {});
|
||||
});
|
||||
}
|
||||
|
||||
async function openOAuthTab(authUrl: string, opts: OAuthTabFlowOptions): Promise<string> {
|
||||
const tab = await browser.tabs.create({ url: authUrl, active: true });
|
||||
if (tab.id === undefined) throw new Error(opts.tabOpenErrorMessage);
|
||||
return waitForOAuthCallback(tab.id, opts);
|
||||
}
|
||||
|
||||
function tokenExpiresAt(expiresIn?: number): number {
|
||||
return expiresIn ? Date.now() + expiresIn * 1000 : Date.now() + 3_600_000;
|
||||
}
|
||||
|
||||
async function getValidStoredAccessToken(
|
||||
provider: CalendarProviderBackend,
|
||||
): Promise<string> {
|
||||
const state = await provider.read();
|
||||
const now = Date.now();
|
||||
if (state.accessToken && state.expiresAt && state.expiresAt > now + 60_000) {
|
||||
return state.accessToken;
|
||||
}
|
||||
if (!state.refreshToken) throw new Error(provider.notConnectedError);
|
||||
const refreshed = await provider.refresh(state.refreshToken);
|
||||
await provider.write({
|
||||
accessToken: refreshed.access_token,
|
||||
refreshToken: refreshed.refresh_token ?? state.refreshToken,
|
||||
expiresAt: tokenExpiresAt(refreshed.expires_in),
|
||||
});
|
||||
return refreshed.access_token;
|
||||
}
|
||||
|
||||
export function registerTrustedAsyncHandler(
|
||||
handlers: CalendarMessageHandlerMap,
|
||||
isTrustedSender: (sender?: browser.Runtime.MessageSender) => boolean,
|
||||
key: string,
|
||||
fn: (request: unknown) => Promise<unknown>,
|
||||
onError?: (err: unknown) => unknown,
|
||||
): void {
|
||||
handlers[key] = (request, sendResponse, sender) => {
|
||||
if (!isTrustedSender(sender)) {
|
||||
sendResponse({ success: false, error: "Unauthorized sender" });
|
||||
return false;
|
||||
}
|
||||
void fn(request)
|
||||
.then(sendResponse)
|
||||
.catch((err) => {
|
||||
sendResponse(
|
||||
onError?.(err) ?? {
|
||||
success: false,
|
||||
error: err instanceof Error ? err.message : "Request failed",
|
||||
},
|
||||
);
|
||||
});
|
||||
return true;
|
||||
};
|
||||
}
|
||||
|
||||
async function getGoogleCalendarStatus(): Promise<GoogleCalendarStatus> {
|
||||
const [state, shared, syncWeeksAhead, autoSyncWeekly] = await Promise.all([
|
||||
readGoogleCalendarState(),
|
||||
readSharedCalendarSyncSettings(),
|
||||
getSyncWeeksAhead(),
|
||||
getAutoSyncWeekly(),
|
||||
]);
|
||||
return {
|
||||
configured: isGoogleCalendarConfigured(),
|
||||
connected: !!(state.refreshToken || state.accessToken),
|
||||
lastSyncAt: state.lastSyncAt,
|
||||
lastWeeklySyncAt: shared.lastWeeklySyncAt,
|
||||
lastSyncOrigin: state.lastSyncOrigin,
|
||||
syncWeeksAhead,
|
||||
autoSyncWeekly,
|
||||
};
|
||||
}
|
||||
|
||||
async function getOutlookCalendarStatus(): Promise<OutlookCalendarStatus> {
|
||||
const state = await readOutlookCalendarState();
|
||||
return {
|
||||
configured: isOutlookCalendarConfigured(),
|
||||
connected: !!(state.refreshToken || state.accessToken),
|
||||
lastSyncAt: state.lastSyncAt,
|
||||
lastSyncOrigin: state.lastSyncOrigin,
|
||||
};
|
||||
}
|
||||
|
||||
async function connectCalendar(provider: CalendarProviderBackend): Promise<GoogleCalendarSyncResult> {
|
||||
if (!provider.isConfigured()) {
|
||||
return { success: false, configured: false, error: provider.notConfiguredError };
|
||||
}
|
||||
|
||||
const redirectUri = provider.callback;
|
||||
const verifier = randomPkceVerifier();
|
||||
const challenge = await pkceChallenge(verifier);
|
||||
const authUrl = new URL(provider.authUrl);
|
||||
authUrl.searchParams.set("client_id", provider.clientId);
|
||||
authUrl.searchParams.set("response_type", "code");
|
||||
authUrl.searchParams.set("redirect_uri", redirectUri);
|
||||
authUrl.searchParams.set("scope", provider.scope);
|
||||
authUrl.searchParams.set("prompt", "consent");
|
||||
authUrl.searchParams.set("code_challenge", challenge);
|
||||
authUrl.searchParams.set("code_challenge_method", "S256");
|
||||
provider.applyAuthParams(authUrl);
|
||||
|
||||
let responseUrl: string;
|
||||
try {
|
||||
responseUrl = await openOAuthTab(authUrl.toString(), {
|
||||
callbackPrefix: provider.callback,
|
||||
...provider.tabOpts,
|
||||
});
|
||||
} catch (err) {
|
||||
const message = err instanceof Error ? err.message : provider.signInFailed;
|
||||
const mismatch =
|
||||
provider.mismatchRe.test(message) || provider.mismatchRe.test(String(err));
|
||||
return {
|
||||
success: false,
|
||||
configured: true,
|
||||
error: mismatch
|
||||
? `${provider.label} redirect URI mismatch. ${provider.redirectHint()}`
|
||||
: message.includes("cancel")
|
||||
? provider.tabOpts.cancelledMessage
|
||||
: message,
|
||||
};
|
||||
}
|
||||
|
||||
try {
|
||||
const code = parseOAuthRedirectCode(responseUrl, provider.label);
|
||||
const tokens = await provider.exchange(code, redirectUri, verifier);
|
||||
const existing = await provider.read();
|
||||
await provider.write({
|
||||
accessToken: tokens.access_token,
|
||||
refreshToken: tokens.refresh_token ?? existing.refreshToken,
|
||||
expiresAt: tokenExpiresAt(tokens.expires_in),
|
||||
connectedAt: Date.now(),
|
||||
});
|
||||
if (provider.afterConnect) {
|
||||
const patch = await provider.afterConnect(tokens.access_token);
|
||||
if (patch && Object.keys(patch).length > 0) {
|
||||
await provider.write(patch);
|
||||
}
|
||||
}
|
||||
await ensureWeeklySyncAlarm();
|
||||
return { success: true, configured: true, connected: true };
|
||||
} catch (err) {
|
||||
return {
|
||||
success: false,
|
||||
configured: true,
|
||||
error: err instanceof Error ? err.message : provider.signInFailed,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
function registerProviderHandlers(
|
||||
handlers: CalendarMessageHandlerMap,
|
||||
isTrustedSender: (sender?: browser.Runtime.MessageSender) => boolean,
|
||||
provider: CalendarProviderBackend,
|
||||
getStatus: () => Promise<unknown>,
|
||||
): void {
|
||||
const { messagePrefix, signInFailed } = provider;
|
||||
const errMsg = (err: unknown, fallback: string) =>
|
||||
err instanceof Error ? err.message : fallback;
|
||||
|
||||
registerTrustedAsyncHandler(
|
||||
handlers,
|
||||
isTrustedSender,
|
||||
`${messagePrefix}Connect`,
|
||||
() => connectCalendar(provider),
|
||||
(err) => ({ success: false, error: errMsg(err, signInFailed) }),
|
||||
);
|
||||
|
||||
registerTrustedAsyncHandler(
|
||||
handlers,
|
||||
isTrustedSender,
|
||||
`${messagePrefix}Disconnect`,
|
||||
async () => {
|
||||
await provider.clear();
|
||||
await ensureWeeklySyncAlarm();
|
||||
return { success: true };
|
||||
},
|
||||
(err) => ({ success: false, error: errMsg(err, "Disconnect failed") }),
|
||||
);
|
||||
|
||||
registerTrustedAsyncHandler(
|
||||
handlers,
|
||||
isTrustedSender,
|
||||
`${messagePrefix}Status`,
|
||||
getStatus,
|
||||
() => ({ configured: provider.isConfigured(), connected: false }),
|
||||
);
|
||||
|
||||
registerTrustedAsyncHandler(
|
||||
handlers,
|
||||
isTrustedSender,
|
||||
`${messagePrefix}GetAccessToken`,
|
||||
() => getValidStoredAccessToken(provider).then((accessToken) => ({ success: true, accessToken })),
|
||||
(err) => ({ success: false, error: errMsg(err, "Token refresh failed") }),
|
||||
);
|
||||
}
|
||||
|
||||
export function registerGoogleCalendarMessageHandlers(
|
||||
handlers: CalendarMessageHandlerMap,
|
||||
isTrustedSender: (sender?: browser.Runtime.MessageSender) => boolean,
|
||||
): void {
|
||||
registerProviderHandlers(handlers, isTrustedSender, GOOGLE_BACKEND, getGoogleCalendarStatus);
|
||||
|
||||
registerTrustedAsyncHandler(handlers, isTrustedSender, "googleCalendarEnsureWeeklyAlarm", async () => {
|
||||
await ensureWeeklySyncAlarm();
|
||||
return { success: true };
|
||||
}, (err) => ({
|
||||
success: false,
|
||||
error: err instanceof Error ? err.message : "Could not schedule weekly sync",
|
||||
}));
|
||||
|
||||
registerTrustedAsyncHandler(handlers, isTrustedSender, "googleCalendarUpdateSyncSettings", async (request) => {
|
||||
const body = request as { syncWeeksAhead?: number; autoSyncWeekly?: boolean };
|
||||
const patch: Record<string, unknown> = {};
|
||||
if (body.syncWeeksAhead != null) patch.syncWeeksAhead = clampSyncWeeks(body.syncWeeksAhead);
|
||||
if (body.autoSyncWeekly != null) patch.autoSyncWeekly = !!body.autoSyncWeekly;
|
||||
if (Object.keys(patch).length > 0) await writeSharedCalendarSyncSettings(patch);
|
||||
await ensureWeeklySyncAlarm();
|
||||
return { success: true, ...(await getGoogleCalendarStatus()) };
|
||||
}, (err) => ({
|
||||
success: false,
|
||||
error: err instanceof Error ? err.message : "Could not update sync settings",
|
||||
}));
|
||||
}
|
||||
|
||||
export function registerOutlookCalendarMessageHandlers(
|
||||
handlers: CalendarMessageHandlerMap,
|
||||
isTrustedSender: (sender?: browser.Runtime.MessageSender) => boolean,
|
||||
): void {
|
||||
registerProviderHandlers(handlers, isTrustedSender, OUTLOOK_BACKEND, getOutlookCalendarStatus);
|
||||
}
|
||||
|
||||
function isSeqtaTab(tab: browser.Tabs.Tab): boolean {
|
||||
const title = tab.title ?? "";
|
||||
return title.includes("SEQTA Learn") || title.includes("SEQTA Engage");
|
||||
}
|
||||
|
||||
export async function ensureWeeklySyncAlarm(): Promise<void> {
|
||||
const [connected, enabled] = await Promise.all([isAnyCalendarConnected(), getAutoSyncWeekly()]);
|
||||
if (!connected || !enabled) {
|
||||
await browser.alarms.clear(CALENDAR_WEEKLY_ALARM);
|
||||
return;
|
||||
}
|
||||
const existing = await browser.alarms.get(CALENDAR_WEEKLY_ALARM);
|
||||
if (!existing) {
|
||||
await browser.alarms.create(CALENDAR_WEEKLY_ALARM, { periodInMinutes: WEEKLY_PERIOD_MINUTES });
|
||||
}
|
||||
}
|
||||
|
||||
async function triggerWeeklySyncOnSeqtaTabs(): Promise<boolean> {
|
||||
const tabs = await browser.tabs.query({});
|
||||
let delivered = false;
|
||||
for (const tab of tabs) {
|
||||
if (tab.id == null || !isSeqtaTab(tab)) continue;
|
||||
try {
|
||||
await browser.tabs.sendMessage(tab.id, { type: "calendarRunWeeklySync" });
|
||||
delivered = true;
|
||||
} catch {
|
||||
// Tab may not have content script yet.
|
||||
}
|
||||
}
|
||||
return delivered;
|
||||
}
|
||||
|
||||
async function handleWeeklySyncAlarm(): Promise<void> {
|
||||
if (!(await isAnyCalendarConnected()) || !(await getAutoSyncWeekly())) return;
|
||||
if (!(await triggerWeeklySyncOnSeqtaTabs())) await markWeeklySyncPending();
|
||||
}
|
||||
|
||||
export function initCalendarBackground(): void {
|
||||
browser.alarms.onAlarm.addListener((alarm) => {
|
||||
if (alarm.name === CALENDAR_WEEKLY_ALARM) void handleWeeklySyncAlarm();
|
||||
});
|
||||
void ensureWeeklySyncAlarm();
|
||||
}
|
||||
@@ -25,6 +25,11 @@ const REFRESH_URL = `${ACCOUNTS_BASE}/api/bsplus/refresh`;
|
||||
const UPLOAD_DEBOUNCE_MS = 2000;
|
||||
const POLL_THROTTLE_MS = 24 * 60 * 60 * 1000;
|
||||
const POLL_THROTTLE_KEY = "bsplus_lastCloudPoll";
|
||||
const FETCH_TIMEOUT_MS = 30_000;
|
||||
|
||||
function fetchWithTimeout(url: string, init?: RequestInit): Promise<Response> {
|
||||
return fetch(url, { ...init, signal: AbortSignal.timeout(FETCH_TIMEOUT_MS) });
|
||||
}
|
||||
|
||||
type CloudSummaryResponse = {
|
||||
desqta?: unknown;
|
||||
@@ -35,6 +40,7 @@ let reloadSeqtaPagesFn: (() => void) | null = null;
|
||||
let suppressAutoUploadDuringRestore = false;
|
||||
let debounceTimer: ReturnType<typeof setTimeout> | null = null;
|
||||
let pollInFlight: Promise<void> | null = null;
|
||||
let autoSyncInitialized = false;
|
||||
|
||||
function isAutoCloudSyncEnabled(all: Record<string, unknown>): boolean {
|
||||
return all.autoCloudSettingsSync !== false;
|
||||
@@ -65,7 +71,7 @@ async function tryRefreshTokens(): Promise<boolean> {
|
||||
if (!refresh_token || !client_id) return false;
|
||||
|
||||
try {
|
||||
const r = await fetch(REFRESH_URL, {
|
||||
const r = await fetchWithTimeout(REFRESH_URL, {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ refresh_token, client_id }),
|
||||
@@ -100,7 +106,7 @@ async function fetchCloudSummaryOnce(
|
||||
| { ok: false; unauthorized: boolean; error?: string }
|
||||
> {
|
||||
try {
|
||||
const r = await fetch(CLOUD_SUMMARY_URL, {
|
||||
const r = await fetchWithTimeout(CLOUD_SUMMARY_URL, {
|
||||
headers: { Authorization: `Bearer ${token}` },
|
||||
cache: "no-store",
|
||||
});
|
||||
@@ -177,7 +183,7 @@ async function putSettingsOnce(token: string): Promise<PutResult> {
|
||||
return { ok: true, skipped: true };
|
||||
}
|
||||
|
||||
const r = await fetch(CLOUD_SETTINGS_SYNC_URL, {
|
||||
const r = await fetchWithTimeout(CLOUD_SETTINGS_SYNC_URL, {
|
||||
method: "PUT",
|
||||
headers: {
|
||||
Authorization: `Bearer ${token}`,
|
||||
@@ -235,7 +241,7 @@ type GetResult =
|
||||
|
||||
async function getSettingsAndApplyOnce(token: string): Promise<GetResult> {
|
||||
try {
|
||||
const r = await fetch(CLOUD_SETTINGS_SYNC_URL, {
|
||||
const r = await fetchWithTimeout(CLOUD_SETTINGS_SYNC_URL, {
|
||||
method: "GET",
|
||||
headers: { Authorization: `Bearer ${token}` },
|
||||
cache: "no-store",
|
||||
@@ -373,8 +379,8 @@ export function runCloudSettingsPoll(): Promise<void> {
|
||||
try {
|
||||
const { [POLL_THROTTLE_KEY]: last } = await browser.storage.local.get(POLL_THROTTLE_KEY);
|
||||
if (Date.now() - (Number(last) || 0) < POLL_THROTTLE_MS) return;
|
||||
await browser.storage.local.set({ [POLL_THROTTLE_KEY]: Date.now() });
|
||||
await runCloudSettingsPollInner();
|
||||
await browser.storage.local.set({ [POLL_THROTTLE_KEY]: Date.now() });
|
||||
} catch (e) {
|
||||
console.error("[BS+ cloud sync] Poll error:", e);
|
||||
} finally {
|
||||
@@ -451,8 +457,22 @@ function onStorageChanged(
|
||||
})();
|
||||
}
|
||||
|
||||
export async function withSuppressedCloudAutoUpload<T>(
|
||||
operation: () => T | Promise<T>,
|
||||
): Promise<T> {
|
||||
suppressAutoUploadDuringRestore = true;
|
||||
try {
|
||||
return await operation();
|
||||
} finally {
|
||||
suppressAutoUploadDuringRestore = false;
|
||||
}
|
||||
}
|
||||
|
||||
export function initCloudSettingsAutoSync(deps: { reloadSeqtaPages: () => void }): void {
|
||||
reloadSeqtaPagesFn = deps.reloadSeqtaPages;
|
||||
if (autoSyncInitialized) return;
|
||||
autoSyncInitialized = true;
|
||||
browser.storage.onChanged.addListener(onStorageChanged);
|
||||
void runCloudSettingsPoll();
|
||||
}
|
||||
|
||||
+20
-6
@@ -1,5 +1,7 @@
|
||||
import Parser from "rss-parser";
|
||||
|
||||
const MAX_RATE_LIMIT_RETRIES = 3;
|
||||
|
||||
/**
|
||||
* Fetches news articles specifically for Australia from the NewsAPI.
|
||||
*
|
||||
@@ -13,15 +15,23 @@ import Parser from "rss-parser";
|
||||
* to send the fetched news data back to the caller.
|
||||
* It's called with an object like `{ news: responseData }`.
|
||||
*/
|
||||
const fetchAustraliaNews = async (url: string, sendResponse: any) => {
|
||||
const fetchAustraliaNews = async (
|
||||
url: string,
|
||||
sendResponse: any,
|
||||
rateLimitRetryCount = 0,
|
||||
) => {
|
||||
fetch(url)
|
||||
.then((result) => result.json())
|
||||
.then((response) => {
|
||||
if (response.code == "rateLimited") {
|
||||
fetchAustraliaNews((url += "%00"), sendResponse);
|
||||
if (response.code == "rateLimited" && rateLimitRetryCount < MAX_RATE_LIMIT_RETRIES) {
|
||||
fetchAustraliaNews(`${url}%00`, sendResponse, rateLimitRetryCount + 1);
|
||||
} else {
|
||||
sendResponse({ news: response });
|
||||
}
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error("[BetterSEQTA+] Failed to fetch Australia news", error);
|
||||
sendResponse({ news: { articles: [] } });
|
||||
});
|
||||
};
|
||||
|
||||
@@ -99,13 +109,14 @@ export async function fetchNews(source: string | undefined, sendResponse: any) {
|
||||
|
||||
if (normalizedSource === "australia") {
|
||||
const date = new Date();
|
||||
date.setDate(date.getDate() - 5);
|
||||
|
||||
const from =
|
||||
date.getFullYear() +
|
||||
"-" +
|
||||
(date.getMonth() + 1) +
|
||||
String(date.getMonth() + 1).padStart(2, "0") +
|
||||
"-" +
|
||||
(date.getDate() - 5);
|
||||
String(date.getDate()).padStart(2, "0");
|
||||
|
||||
const url = `https://newsapi.org/v2/everything?domains=abc.net.au&from=${from}&apiKey=17c0da766ba347c89d094449504e3080`;
|
||||
fetchAustraliaNews(url, sendResponse);
|
||||
@@ -115,7 +126,6 @@ export async function fetchNews(source: string | undefined, sendResponse: any) {
|
||||
|
||||
const parser = new Parser();
|
||||
let feeds: string[];
|
||||
console.log("fetchNews", normalizedSource);
|
||||
|
||||
if (rssFeedsByCountry[normalizedSource.toLowerCase()]) {
|
||||
feeds = rssFeedsByCountry[normalizedSource.toLowerCase()];
|
||||
@@ -129,6 +139,10 @@ export async function fetchNews(source: string | undefined, sendResponse: any) {
|
||||
const articlesPromises = feeds.map(async (feedUrl) => {
|
||||
try {
|
||||
const response = await fetch(feedUrl);
|
||||
if (!response.ok) {
|
||||
console.error(`Failed to fetch RSS feed: ${feedUrl} (${response.status})`);
|
||||
return [];
|
||||
}
|
||||
const feedString = await response.text();
|
||||
const feed = await parser.parseString(feedString);
|
||||
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
/** Google Calendar OAuth — public client config. Token exchange is on accounts.betterseqta.org. */
|
||||
|
||||
const HARDCODED_GOOGLE_OAUTH_CLIENT_ID =
|
||||
"270834969641-f6t7jtpu6j0cemse8updj3rkos7nl0hf.apps.googleusercontent.com";
|
||||
|
||||
const envClientId =
|
||||
typeof __GOOGLE_OAUTH_CLIENT_ID__ !== "undefined" ? __GOOGLE_OAUTH_CLIENT_ID__ : "";
|
||||
|
||||
export const GOOGLE_OAUTH_CLIENT_ID: string =
|
||||
envClientId.trim() || HARDCODED_GOOGLE_OAUTH_CLIENT_ID.trim();
|
||||
|
||||
export const ACCOUNTS_BASE = "https://accounts.betterseqta.org";
|
||||
|
||||
export const GOOGLE_CALENDAR_OAUTH_CALLBACK = `${ACCOUNTS_BASE}/auth/google/calendar/callback`;
|
||||
export const GOOGLE_CALENDAR_TOKEN_URL = `${ACCOUNTS_BASE}/api/bsplus/google/calendar/token`;
|
||||
export const GOOGLE_CALENDAR_REFRESH_URL = `${ACCOUNTS_BASE}/api/bsplus/google/calendar/refresh`;
|
||||
|
||||
/** App-owned secondary calendar only — cannot read or modify the user's other calendars. */
|
||||
export const GOOGLE_CALENDAR_SCOPE = "https://www.googleapis.com/auth/calendar.app.created";
|
||||
|
||||
export const GOOGLE_AUTH_URL = "https://accounts.google.com/o/oauth2/v2/auth";
|
||||
export const GOOGLE_CALENDAR_API = "https://www.googleapis.com/calendar/v3";
|
||||
|
||||
export const BSPLUS_GOOGLE_CALENDAR_NAME = "BetterSEQTA+ Timetable";
|
||||
export const BSPLUS_GOOGLE_CALENDAR_DESCRIPTION =
|
||||
"School timetable lessons synced by the BetterSEQTA+ extension.";
|
||||
|
||||
export const BSPLUS_GOOGLE_CALENDAR_EVENT_PROP = "bsplusSeqtaKey";
|
||||
|
||||
export const GOOGLE_CALENDAR_SYNC_WEEKS = 12;
|
||||
export const GOOGLE_CALENDAR_SYNC_WEEKS_MIN = 1;
|
||||
export const GOOGLE_CALENDAR_SYNC_WEEKS_MAX = 52;
|
||||
|
||||
export function isGoogleCalendarConfigured(): boolean {
|
||||
return GOOGLE_OAUTH_CLIENT_ID.length > 0;
|
||||
}
|
||||
|
||||
export const GOOGLE_CALENDAR_ACCOUNTS_NOT_READY_HINT =
|
||||
"Google Calendar connect requires accounts.betterseqta.org — see docs/GOOGLE_CALENDAR_ACCOUNTS_CALLBACK.md";
|
||||
|
||||
export function googleOAuthRedirectUriHint(): string {
|
||||
return `Authorized redirect URI in Google Cloud Console must be: ${GOOGLE_CALENDAR_OAUTH_CALLBACK}`;
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
/** Outlook Calendar OAuth — public client config. Token exchange is on accounts.betterseqta.org. */
|
||||
|
||||
import { ACCOUNTS_BASE } from "@/config/googleCalendar";
|
||||
|
||||
const HARDCODED_OUTLOOK_OAUTH_CLIENT_ID = "0b55168c-916c-4323-8f67-b3dd30af3c9e";
|
||||
|
||||
const envClientId =
|
||||
typeof __OUTLOOK_OAUTH_CLIENT_ID__ !== "undefined" ? __OUTLOOK_OAUTH_CLIENT_ID__ : "";
|
||||
|
||||
export const OUTLOOK_OAUTH_CLIENT_ID: string =
|
||||
envClientId.trim() || HARDCODED_OUTLOOK_OAUTH_CLIENT_ID.trim();
|
||||
|
||||
export const OUTLOOK_CALENDAR_OAUTH_CALLBACK = `${ACCOUNTS_BASE}/auth/microsoft/calendar/callback`;
|
||||
export const OUTLOOK_CALENDAR_TOKEN_URL = `${ACCOUNTS_BASE}/api/bsplus/microsoft/calendar/token`;
|
||||
export const OUTLOOK_CALENDAR_REFRESH_URL = `${ACCOUNTS_BASE}/api/bsplus/microsoft/calendar/refresh`;
|
||||
|
||||
export const OUTLOOK_CALENDAR_SCOPE = "offline_access Calendars.ReadWrite User.Read";
|
||||
|
||||
export const OUTLOOK_AUTH_URL =
|
||||
"https://login.microsoftonline.com/common/oauth2/v2.0/authorize";
|
||||
|
||||
export const OUTLOOK_GRAPH_API = "https://graph.microsoft.com/v1.0";
|
||||
|
||||
export const BSPLUS_OUTLOOK_CALENDAR_EVENT_CATEGORY = "BetterSEQTA+";
|
||||
|
||||
export function isOutlookCalendarConfigured(): boolean {
|
||||
return OUTLOOK_OAUTH_CLIENT_ID.length > 0;
|
||||
}
|
||||
|
||||
export const OUTLOOK_CALENDAR_ACCOUNTS_NOT_READY_HINT =
|
||||
"Outlook Calendar connect requires accounts.betterseqta.org — see docs/OUTLOOK_CALENDAR_ACCOUNTS_CALLBACK.md";
|
||||
|
||||
export function outlookOAuthRedirectUriHint(): string {
|
||||
return `Authorized redirect URI in Azure must be: ${OUTLOOK_CALENDAR_OAUTH_CALLBACK}`;
|
||||
}
|
||||
+469
-102
@@ -13,6 +13,7 @@
|
||||
}
|
||||
|
||||
@include meta.load-css("injected/sidebar-animation.scss");
|
||||
@include meta.load-css("injected/sidebar-styles.scss");
|
||||
@include meta.load-css("injected/theme.scss");
|
||||
@include meta.load-css("injected/transparency.scss");
|
||||
|
||||
@@ -34,7 +35,8 @@
|
||||
display: none;
|
||||
}
|
||||
|
||||
button.uiButton.timetable-zoom.iconFamily,
|
||||
button.timetable-zoom.iconFamily,
|
||||
button.bsplus-timetable-control.iconFamily,
|
||||
.iconFamily {
|
||||
font-family: "IconFamily" !important;
|
||||
}
|
||||
@@ -63,9 +65,13 @@ body {
|
||||
|
||||
select {
|
||||
border-radius: 16px !important;
|
||||
border: 1px solid color-mix(in srgb, var(--theme-offset-bg, var(--background-secondary)) 78%, transparent) !important;
|
||||
background: color-mix(in srgb, var(--background-primary) 90%, transparent) !important;
|
||||
border: 1px solid var(--theme-offset-bg, var(--theme-secondary, var(--background-secondary))) !important;
|
||||
background: var(--theme-primary, var(--background-primary)) !important;
|
||||
color: var(--text-primary) !important;
|
||||
padding: 0.5rem 1rem !important;
|
||||
min-height: 2.5rem !important;
|
||||
font-size: 0.875rem !important;
|
||||
line-height: 1.25 !important;
|
||||
transition:
|
||||
background-color 180ms ease,
|
||||
border-color 180ms ease,
|
||||
@@ -73,14 +79,14 @@ select {
|
||||
}
|
||||
|
||||
select:hover {
|
||||
background: color-mix(in srgb, var(--background-primary) 94%, var(--background-secondary) 6%) !important;
|
||||
border-color: color-mix(in srgb, var(--theme-offset-bg, var(--background-secondary)) 92%, transparent) !important;
|
||||
background: var(--theme-secondary, var(--background-secondary)) !important;
|
||||
border-color: var(--theme-offset-bg, var(--theme-secondary, var(--background-secondary))) !important;
|
||||
}
|
||||
|
||||
select:focus {
|
||||
outline: none !important;
|
||||
background: color-mix(in srgb, var(--background-primary) 96%, var(--background-secondary) 4%) !important;
|
||||
border-color: color-mix(in srgb, var(--text-primary) 18%, var(--theme-offset-bg, var(--background-secondary)) 82%) !important;
|
||||
background: var(--theme-secondary, var(--background-secondary)) !important;
|
||||
border-color: color-mix(in srgb, var(--text-primary) 18%, var(--theme-offset-bg, var(--theme-secondary, var(--background-secondary))) 82%) !important;
|
||||
box-shadow: 0 0 0 1px color-mix(in srgb, var(--text-primary) 12%, transparent) !important;
|
||||
}
|
||||
|
||||
@@ -89,12 +95,12 @@ select[size="1"] {
|
||||
appearance: none;
|
||||
-webkit-appearance: none;
|
||||
-moz-appearance: none;
|
||||
color-scheme: light;
|
||||
background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='%23999'%3E%3Cpath fill-rule='evenodd' d='M5.23 7.21a.75.75 0 0 1 1.06.02L10 11.168l3.71-3.938a.75.75 0 1 1 1.08 1.04l-4.25 4.5a.75.75 0 0 1-1.08 0l-4.25-4.5a.75.75 0 0 1 .02-1.06Z' clip-rule='evenodd'/%3E%3C/svg%3E") !important;
|
||||
background-position: right 0.9rem center !important;
|
||||
background-repeat: no-repeat !important;
|
||||
background-size: 1rem !important;
|
||||
padding-right: 2.6rem !important;
|
||||
color-scheme: light;
|
||||
}
|
||||
|
||||
select::-ms-expand {
|
||||
@@ -102,19 +108,19 @@ select::-ms-expand {
|
||||
}
|
||||
|
||||
select option {
|
||||
background: var(--background-primary) !important;
|
||||
color: var(--text-primary) !important;
|
||||
background-color: #ffffff !important;
|
||||
color: #18181b !important;
|
||||
}
|
||||
|
||||
.dark select option {
|
||||
background-color: #1a1a1a !important;
|
||||
color: #ffffff !important;
|
||||
}
|
||||
|
||||
.dark select:not([multiple]):not([size]),
|
||||
.dark select[size="1"] {
|
||||
background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='%23c9c9c9'%3E%3Cpath fill-rule='evenodd' d='M5.23 7.21a.75.75 0 0 1 1.06.02L10 11.168l3.71-3.938a.75.75 0 1 1 1.08 1.04l-4.25 4.5a.75.75 0 0 1-1.08 0l-4.25-4.5a.75.75 0 0 1 .02-1.06Z' clip-rule='evenodd'/%3E%3C/svg%3E") !important;
|
||||
color-scheme: dark;
|
||||
}
|
||||
|
||||
.dark select option {
|
||||
background: var(--background-primary) !important;
|
||||
color: var(--text-primary) !important;
|
||||
background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='%23c9c9c9'%3E%3Cpath fill-rule='evenodd' d='M5.23 7.21a.75.75 0 0 1 1.06.02L10 11.168l3.71-3.938a.75.75 0 1 1 1.08 1.04l-4.25 4.5a.75.75 0 0 1-1.08 0l-4.25-4.5a.75.75 0 0 1 .02-1.06Z' clip-rule='evenodd'/%3E%3C/svg%3E") !important;
|
||||
}
|
||||
#container {
|
||||
background: var(--auto-background) !important;
|
||||
@@ -156,40 +162,6 @@ select option {
|
||||
}
|
||||
}
|
||||
|
||||
#store {
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 100vw;
|
||||
height: 100vh;
|
||||
z-index: 9998;
|
||||
animation: fadeIn 500ms forwards;
|
||||
animation-delay: 200ms;
|
||||
opacity: 0;
|
||||
|
||||
&.hide {
|
||||
animation: fadeOut 500ms forwards;
|
||||
}
|
||||
}
|
||||
|
||||
@keyframes fadeIn {
|
||||
from {
|
||||
opacity: 0;
|
||||
}
|
||||
to {
|
||||
opacity: 1;
|
||||
}
|
||||
}
|
||||
|
||||
@keyframes fadeOut {
|
||||
from {
|
||||
opacity: 1;
|
||||
}
|
||||
to {
|
||||
opacity: 0;
|
||||
}
|
||||
}
|
||||
|
||||
.dark .resizeBar {
|
||||
background-color: rgb(28 28 30);
|
||||
}
|
||||
@@ -215,6 +187,13 @@ select option {
|
||||
pointer-events: none !important;
|
||||
}
|
||||
|
||||
/* Colour picker dialog teardown can leave an empty shell that blocks clicks */
|
||||
.modaliser-container:not(:has(.modaliser > *)) {
|
||||
display: none !important;
|
||||
visibility: hidden !important;
|
||||
pointer-events: none !important;
|
||||
}
|
||||
|
||||
.connectedNotificationsWrapper > div > button > svg > g {
|
||||
fill: var(--theme-primary) !important;
|
||||
}
|
||||
@@ -262,6 +241,14 @@ select option {
|
||||
justify-content: center;
|
||||
width: 35px !important;
|
||||
}
|
||||
|
||||
/* Engage toolbar: keep settings/theme buttons above React chrome */
|
||||
.connectedNotificationsWrapper .addedButton,
|
||||
.connectedNotificationsWrapper #AddedSettings,
|
||||
.connectedNotificationsWrapper #LightDarkModeButton {
|
||||
z-index: 50 !important;
|
||||
pointer-events: auto !important;
|
||||
}
|
||||
[style="background-color: rgb(255, 255, 255);"] {
|
||||
color: black;
|
||||
}
|
||||
@@ -331,12 +318,18 @@ select option {
|
||||
}
|
||||
|
||||
.timetable-zoom,
|
||||
.timetable-hide {
|
||||
.timetable-hide,
|
||||
.bsplus-timetable-control {
|
||||
font-size: 14px !important;
|
||||
line-height: 1 !important;
|
||||
display: inline-flex !important;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
background: transparent;
|
||||
border: none;
|
||||
color: var(--text-primary);
|
||||
cursor: pointer;
|
||||
padding: 4px 8px;
|
||||
}
|
||||
|
||||
#main > .dashboard {
|
||||
@@ -421,6 +414,7 @@ ul.magicDelete > li.deleting {
|
||||
.addedButton svg {
|
||||
margin: 6px;
|
||||
fill: var(--theme-primary);
|
||||
color: var(--theme-primary);
|
||||
}
|
||||
#menu,
|
||||
.sub,
|
||||
@@ -453,7 +447,7 @@ ul.magicDelete > li.deleting {
|
||||
place-items: center;
|
||||
}
|
||||
#menu .sub {
|
||||
top: 71.5px;
|
||||
top: 71px;
|
||||
margin-top: -2px;
|
||||
}
|
||||
|
||||
@@ -508,6 +502,83 @@ ul.magicDelete > li.deleting {
|
||||
#menu:has(> ul > li.hasChildren.active) > ul > li:not(.hasChildren.active) {
|
||||
pointer-events: none !important;
|
||||
}
|
||||
|
||||
/* Edit Sidebar: every row + toggle must stay clickable (drill stack disables siblings). */
|
||||
#menu.bsplus-sidebar-edit-mode li.item,
|
||||
#menu.bsplus-sidebar-edit-mode section.item,
|
||||
#menu.bsplus-sidebar-edit-mode .bsplus-sidebar-offscreen,
|
||||
#menu.bsplus-sidebar-edit-mode .bsplus-sidebar-offscreen * {
|
||||
pointer-events: auto !important;
|
||||
user-select: auto !important;
|
||||
}
|
||||
|
||||
#menu.bsplus-sidebar-edit-mode:has(> ul > li.hasChildren.active)
|
||||
> ul
|
||||
> li:not(.hasChildren.active) {
|
||||
pointer-events: auto !important;
|
||||
}
|
||||
|
||||
#menu.bsplus-sidebar-edit-mode > ul > .bsplus-sidebar-offscreen:not(.hasChildren.active),
|
||||
#menu.bsplus-sidebar-edit-mode .sub .bsplus-sidebar-offscreen:not(.hasChildren.active) {
|
||||
position: relative !important;
|
||||
left: auto !important;
|
||||
width: auto !important;
|
||||
height: auto !important;
|
||||
margin: inherit !important;
|
||||
padding: inherit !important;
|
||||
overflow: visible !important;
|
||||
clip: auto !important;
|
||||
opacity: 1 !important;
|
||||
visibility: visible !important;
|
||||
}
|
||||
|
||||
/* Edit rows should match normal custom-sidebar item size (not shrunk). */
|
||||
#menu.bsplus-sidebar-edit-mode > #bsplus-sidebar-root > li.item.draggable,
|
||||
#menu.bsplus-sidebar-edit-mode .item.draggable {
|
||||
display: flex !important;
|
||||
align-items: center !important;
|
||||
width: auto !important;
|
||||
max-width: none !important;
|
||||
box-sizing: border-box !important;
|
||||
padding: 0 !important;
|
||||
margin: 0 6px 8px !important;
|
||||
}
|
||||
|
||||
#menu.bsplus-sidebar-edit-mode .item.draggable > label:not(.toggle) {
|
||||
flex: 1 1 auto !important;
|
||||
width: auto !important;
|
||||
min-width: 0 !important;
|
||||
max-width: none !important;
|
||||
padding: 12px !important;
|
||||
padding-left: 4px !important;
|
||||
box-sizing: border-box !important;
|
||||
}
|
||||
|
||||
#menu.bsplus-sidebar-edit-mode .item.draggable .label {
|
||||
white-space: nowrap !important;
|
||||
overflow: hidden !important;
|
||||
text-overflow: ellipsis !important;
|
||||
overflow-wrap: normal !important;
|
||||
font-size: inherit !important;
|
||||
line-height: 1.2 !important;
|
||||
}
|
||||
|
||||
#menu.bsplus-sidebar-edit-mode .item.draggable > label:not(.toggle) > svg {
|
||||
width: 24px !important;
|
||||
height: 24px !important;
|
||||
flex-shrink: 0 !important;
|
||||
}
|
||||
|
||||
#menu.bsplus-sidebar-edit-mode .item.draggable > .toggle,
|
||||
#menu.bsplus-sidebar-edit-mode .onoffswitch {
|
||||
pointer-events: auto !important;
|
||||
flex: 0 0 auto !important;
|
||||
width: auto !important;
|
||||
margin: 0 12px 0 0 !important;
|
||||
position: relative;
|
||||
z-index: 2;
|
||||
}
|
||||
|
||||
#menu section > label {
|
||||
align-items: center;
|
||||
box-sizing: border-box;
|
||||
@@ -540,13 +611,224 @@ ul.magicDelete > li.deleting {
|
||||
}
|
||||
|
||||
#menu {
|
||||
width: 270px;
|
||||
width: var(--bsplus-sidebar-width, 270px);
|
||||
z-index: 19;
|
||||
background: var(--better-main) !important;
|
||||
color: var(--text-color);
|
||||
border-right: none;
|
||||
transition: width 0.4s cubic-bezier(0.4, 0, 0.2, 1);
|
||||
}
|
||||
|
||||
/* Hide native menu as soon as possible (during loading), before Svelte mounts.
|
||||
Keep `#bsplus-sidebar-root` visible — themes target `#menu > ul > li.item` on it. */
|
||||
html.bsplus-custom-sidebar-pending #menu > ul:not(#bsplus-sidebar-root),
|
||||
html.bsplus-custom-sidebar-pending #menu > #userInfo,
|
||||
html.bsplus-custom-sidebar-pending #menu > .icon-cover,
|
||||
#menu.bsplus-custom-sidebar > ul:not(#bsplus-sidebar-root),
|
||||
#menu.bsplus-custom-sidebar > #userInfo,
|
||||
#menu.bsplus-custom-sidebar > .icon-cover {
|
||||
position: absolute !important;
|
||||
left: -10000px !important;
|
||||
width: 1px !important;
|
||||
height: 1px !important;
|
||||
margin: 0 !important;
|
||||
padding: 0 !important;
|
||||
overflow: hidden !important;
|
||||
opacity: 0 !important;
|
||||
pointer-events: none !important;
|
||||
clip: rect(0, 0, 0, 0) !important;
|
||||
}
|
||||
|
||||
/* Custom title bar: keep native `#title` children for sync, hide them visually.
|
||||
Loading overlay stays until waitForCustomTitleBarReady() so this is ready underneath. */
|
||||
html.bsplus-custom-title-pending #title > :not(#bsplus-title-root),
|
||||
#title.bsplus-custom-title > :not(#bsplus-title-root) {
|
||||
position: absolute !important;
|
||||
left: -10000px !important;
|
||||
width: 1px !important;
|
||||
height: 1px !important;
|
||||
margin: 0 !important;
|
||||
padding: 0 !important;
|
||||
overflow: hidden !important;
|
||||
opacity: 0 !important;
|
||||
pointer-events: none !important;
|
||||
clip: rect(0, 0, 0, 0) !important;
|
||||
}
|
||||
|
||||
#bsplus-title-root {
|
||||
display: contents;
|
||||
}
|
||||
|
||||
/* `#title span { display: none }` hides the page title; keep search chip icons visible. */
|
||||
#title.bsplus-custom-title .search-trigger > span {
|
||||
display: inline-flex !important;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
/* Custom Svelte sidebar: keep `#menu > ul > li.item` / `.sub` shape for theme CSS. */
|
||||
#menu.bsplus-custom-sidebar {
|
||||
position: absolute !important;
|
||||
top: 0 !important;
|
||||
bottom: 0 !important;
|
||||
left: 0 !important;
|
||||
display: flex !important;
|
||||
flex-direction: column !important;
|
||||
box-sizing: border-box !important;
|
||||
height: auto !important;
|
||||
max-height: none !important;
|
||||
overflow: hidden !important;
|
||||
|
||||
> #bsplus-sidebar-root {
|
||||
flex: 1 1 auto;
|
||||
min-height: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
z-index: 2;
|
||||
position: relative;
|
||||
padding-top: 0 !important;
|
||||
|
||||
/*
|
||||
* Extend the logo spacer for the same gap as between items.
|
||||
* SEQTA's #menu>ul::before border-bottom is the hairline under the logo.
|
||||
*/
|
||||
&::before {
|
||||
box-shadow: none !important;
|
||||
border-bottom: none !important;
|
||||
height: calc(71px + 8px) !important;
|
||||
}
|
||||
}
|
||||
|
||||
li.hasChildren {
|
||||
position: static !important;
|
||||
}
|
||||
|
||||
/* Native list may keep `.active` after click-through; force our rows clickable,
|
||||
then lock siblings only while a custom drill `.sub` is open. */
|
||||
> #bsplus-sidebar-root .bsplus-sidebar-item {
|
||||
width: auto !important;
|
||||
max-width: none !important;
|
||||
margin: 0 6px 8px !important;
|
||||
box-sizing: border-box !important;
|
||||
}
|
||||
|
||||
> #bsplus-sidebar-root > li.item {
|
||||
pointer-events: auto !important;
|
||||
}
|
||||
|
||||
&:has(> #bsplus-sidebar-root > li.hasChildren.bsplus-active > .sub)
|
||||
> #bsplus-sidebar-root
|
||||
> li:not(.hasChildren.bsplus-active),
|
||||
&:has(> #bsplus-sidebar-root > li.hasChildren.bsplus-active > .sub)
|
||||
> #bsplus-sidebar-root
|
||||
> li:not(.hasChildren.bsplus-active)
|
||||
* {
|
||||
pointer-events: none !important;
|
||||
}
|
||||
|
||||
/* Same locks keyed off `.drilling` so nested leaf clicks do not flicker when
|
||||
SEQTA briefly strips `.active` from folder rows. */
|
||||
> #bsplus-sidebar-root.drilling > li:not(.hasChildren),
|
||||
> #bsplus-sidebar-root.drilling > li:not(.hasChildren) * {
|
||||
pointer-events: none !important;
|
||||
}
|
||||
|
||||
> #bsplus-sidebar-root .sub {
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
> #bsplus-sidebar-root li.hasChildren.bsplus-active > .sub {
|
||||
pointer-events: auto;
|
||||
transform: none;
|
||||
background: transparent !important;
|
||||
background-image: none !important;
|
||||
}
|
||||
|
||||
> #bsplus-sidebar-root li.hasChildren.bsplus-active
|
||||
> .sub:has(.hasChildren.bsplus-active) {
|
||||
pointer-events: none !important;
|
||||
}
|
||||
|
||||
> #bsplus-sidebar-root li.hasChildren.bsplus-active
|
||||
.hasChildren.bsplus-active
|
||||
> .sub {
|
||||
pointer-events: auto !important;
|
||||
background: transparent !important;
|
||||
background-image: none !important;
|
||||
}
|
||||
|
||||
> #bsplus-sidebar-root.drilling li.hasChildren > .sub:not(:has(.sub)) {
|
||||
pointer-events: auto !important;
|
||||
background: transparent !important;
|
||||
background-image: none !important;
|
||||
}
|
||||
|
||||
> #bsplus-sidebar-root.drilling li.hasChildren > .sub:has(.sub) {
|
||||
pointer-events: none !important;
|
||||
}
|
||||
|
||||
> #bsplus-sidebar-root.drilling li.hasChildren > .sub .sub {
|
||||
pointer-events: auto !important;
|
||||
background: transparent !important;
|
||||
background-image: none !important;
|
||||
}
|
||||
|
||||
> #bsplus-sidebar-root.drilling .sub ul .bsplus-sidebar-item,
|
||||
> #bsplus-sidebar-root.drilling .sub ul .bsplus-sidebar-item * {
|
||||
pointer-events: auto !important;
|
||||
}
|
||||
|
||||
> #bsplus-sidebar-root > li.hasChildren.bsplus-active > label,
|
||||
> #bsplus-sidebar-root.drilling > li.hasChildren > label {
|
||||
pointer-events: none !important;
|
||||
}
|
||||
|
||||
/* Theme decorations on root leaves (Beach palm/sand) must not show through
|
||||
the transparent drill `.sub` panel. */
|
||||
> #bsplus-sidebar-root:has(> li.hasChildren.bsplus-active > .sub)
|
||||
> li:not(.hasChildren.bsplus-active)::before,
|
||||
> #bsplus-sidebar-root:has(> li.hasChildren.bsplus-active > .sub)
|
||||
> li:not(.hasChildren.bsplus-active)::after {
|
||||
content: none !important;
|
||||
display: none !important;
|
||||
animation: none !important;
|
||||
opacity: 0 !important;
|
||||
}
|
||||
|
||||
> #bsplus-sidebar-root.drilling > li:not(.hasChildren)::before,
|
||||
> #bsplus-sidebar-root.drilling > li:not(.hasChildren)::after {
|
||||
content: none !important;
|
||||
display: none !important;
|
||||
animation: none !important;
|
||||
opacity: 0 !important;
|
||||
}
|
||||
|
||||
#bsplus-sidebar-root .sub .back {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 4px;
|
||||
padding: 12px 16px 8px;
|
||||
cursor: pointer;
|
||||
font-weight: 700;
|
||||
color: inherit;
|
||||
}
|
||||
|
||||
#bsplus-sidebar-root .sub .back:hover {
|
||||
opacity: 0.9;
|
||||
}
|
||||
|
||||
#bsplus-sidebar-root .sub .backLabel {
|
||||
font-size: 16px;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
#bsplus-sidebar-root .sub > ul {
|
||||
list-style: none;
|
||||
margin: 0;
|
||||
padding: 8px 0 16px;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#menu li > label > svg,
|
||||
#menu section > label > svg {
|
||||
margin: 0 10px 0 4px;
|
||||
@@ -634,6 +916,12 @@ body.icon-only-sidebar:not(:has(#menu li.hasChildren.active)) {
|
||||
display: none !important;
|
||||
}
|
||||
|
||||
/* Compact BetterSEQTA mark instead of the full wordmark. */
|
||||
&.student #menu > ul::before {
|
||||
background-size: 36px 36px !important;
|
||||
background-position: center center !important;
|
||||
}
|
||||
|
||||
}
|
||||
[class*="notifications__items___"] {
|
||||
-ms-overflow-style: none !important;
|
||||
@@ -654,7 +942,9 @@ body.icon-only-sidebar:not(:has(#menu li.hasChildren.active)) {
|
||||
margin-bottom: 8px !important;
|
||||
width: 85% !important;
|
||||
}
|
||||
.item.draggable {
|
||||
/* Keep width scoped to #menu — fallback drag clones append to body, and
|
||||
width:100% there stretches across the viewport. */
|
||||
#menu .item.draggable {
|
||||
width: 100% !important;
|
||||
cursor: grab;
|
||||
|
||||
@@ -668,6 +958,19 @@ body.icon-only-sidebar:not(:has(#menu li.hasChildren.active)) {
|
||||
}
|
||||
}
|
||||
|
||||
/* Sortable forceFallback clone (on body) — match source row size. */
|
||||
body > .bsplus-sortable-drag,
|
||||
body > .sortable-fallback.bsplus-sortable-drag,
|
||||
.bsplus-sortable-drag.sortable-fallback {
|
||||
width: var(--bsplus-drag-width, 240px) !important;
|
||||
max-width: var(--bsplus-drag-width, 240px) !important;
|
||||
min-width: 0 !important;
|
||||
box-sizing: border-box !important;
|
||||
margin: 0 !important;
|
||||
pointer-events: none !important;
|
||||
list-style: none !important;
|
||||
}
|
||||
|
||||
#menu {
|
||||
li.active > .sub > ul > .item:not(.hasChildren) {
|
||||
position: relative;
|
||||
@@ -796,6 +1099,11 @@ ol:has([class*="MessageList__avatar___"] svg) {
|
||||
.quickbar .actions [title="Choose a colour"] > svg {
|
||||
scale: 0.9;
|
||||
}
|
||||
|
||||
.quickbar .actions .timetable-edit-quickbar-btn > svg {
|
||||
scale: 0.9;
|
||||
padding-top: 1px;
|
||||
}
|
||||
.quickbar[data-yiq="light"] .actions {
|
||||
color: white !important;
|
||||
}
|
||||
@@ -810,7 +1118,7 @@ ol:has([class*="MessageList__avatar___"] svg) {
|
||||
}
|
||||
#container #content::before {
|
||||
content: "";
|
||||
height: 69.5px;
|
||||
height: 71px;
|
||||
width: 100%;
|
||||
}
|
||||
.menuShown #container #content #title {
|
||||
@@ -821,6 +1129,12 @@ ol:has([class*="MessageList__avatar___"] svg) {
|
||||
-webkit-box-shadow: 0px 5px 16px 6px rgba(0, 0, 0, 0.2) !important;
|
||||
box-shadow: 0px 0px 4px 2px rgba(0, 0, 0, 0.2) !important;
|
||||
}
|
||||
/* Custom sidebar: keep title depth to the right, not a hairline under the logo into the menu. */
|
||||
body:has(#menu.bsplus-custom-sidebar) #container #content #title,
|
||||
body:has(#menu.bsplus-custom-sidebar).menuShown #container #content #title {
|
||||
-webkit-box-shadow: 6px 0 8px -4px rgba(0, 0, 0, 0.25) !important;
|
||||
box-shadow: 6px 0 8px -4px rgba(0, 0, 0, 0.25) !important;
|
||||
}
|
||||
#main .timetablepage .quickbar {
|
||||
border: none;
|
||||
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.5);
|
||||
@@ -1026,12 +1340,18 @@ div > ol:has(.uiFileHandlerWrapper) {
|
||||
min-height: 128px !important;
|
||||
}
|
||||
body.student #menu > ul::before {
|
||||
content: "";
|
||||
display: block;
|
||||
width: 100%;
|
||||
background-image: var(--betterseqta-logo) !important;
|
||||
background-position: center;
|
||||
background-repeat: no-repeat;
|
||||
background-size: auto 48px;
|
||||
position: -webkit-sticky;
|
||||
position: sticky;
|
||||
top: 0;
|
||||
background-color: transparent;
|
||||
height: 69.5px;
|
||||
height: 71px;
|
||||
box-shadow: 0px 0px 4px 2px rgba(0, 0, 0, 0.2);
|
||||
}
|
||||
|
||||
@@ -1050,9 +1370,12 @@ html.transparencyEffects
|
||||
.assessmentsWrapper .message {
|
||||
display: none;
|
||||
}
|
||||
#menu li:hover {
|
||||
#menu li:hover:not(.active) {
|
||||
background: rgba(0, 0, 0, 0.15) !important;
|
||||
}
|
||||
#menu li.active:hover {
|
||||
background: rgba(0, 0, 0, 0.35) !important;
|
||||
}
|
||||
|
||||
#menu li:focus-visible,
|
||||
#menu section:focus-visible {
|
||||
@@ -1067,7 +1390,7 @@ html.transparencyEffects
|
||||
|
||||
#content {
|
||||
transition: left 0.4s cubic-bezier(0.4, 0, 0.2, 1), transform 0.4s ease;
|
||||
left: 270px;
|
||||
left: var(--bsplus-sidebar-width, 270px);
|
||||
background: unset;
|
||||
}
|
||||
|
||||
@@ -1095,8 +1418,8 @@ html.transparencyEffects
|
||||
display: none;
|
||||
}
|
||||
#menu {
|
||||
-webkit-transform: translatex(-270px);
|
||||
transform: translatex(-270px);
|
||||
-webkit-transform: translatex(calc(-1 * var(--bsplus-sidebar-width, 270px)));
|
||||
transform: translatex(calc(-1 * var(--bsplus-sidebar-width, 270px)));
|
||||
}
|
||||
.menuShown #menu {
|
||||
-webkit-transform: translatex(0);
|
||||
@@ -1106,8 +1429,8 @@ html.transparencyEffects
|
||||
left: 0;
|
||||
}
|
||||
.menuShown #content {
|
||||
-webkit-transform: translatex(270px);
|
||||
transform: translatex(270px);
|
||||
-webkit-transform: translatex(var(--bsplus-sidebar-width, 270px));
|
||||
transform: translatex(var(--bsplus-sidebar-width, 270px));
|
||||
}
|
||||
|
||||
body.icon-only-sidebar:not(:has(#menu li.hasChildren.active)) {
|
||||
@@ -1175,6 +1498,35 @@ html.transparencyEffects
|
||||
color: var(--text-primary) !important;
|
||||
box-shadow: none;
|
||||
}
|
||||
|
||||
// Engage lesson/course Lexical editor ships inline light-mode colours on canvas + text nodes.
|
||||
[class*="Canvas__canvas___"] {
|
||||
background-color: transparent !important;
|
||||
background-image: none !important;
|
||||
color: var(--text-primary) !important;
|
||||
}
|
||||
|
||||
[class*="LexicalEditor__editor-container___"],
|
||||
[class*="LexicalEditor__editor-inner___"],
|
||||
[class*="LexicalEditor__editor-input___"],
|
||||
[class*="LexicalEditor__editor-paragraph___"],
|
||||
[class*="LexicalEditor__editor-text-bold___"],
|
||||
[class*="LexicalEditor__editor-text-italic___"],
|
||||
[class*="LexicalEditor__editor-text-underline___"],
|
||||
[class*="TextModuleBody__lexicalEditor___"] {
|
||||
color: var(--text-primary) !important;
|
||||
}
|
||||
|
||||
[class*="Module__module___"],
|
||||
[class*="Module__content___"] {
|
||||
background: transparent !important;
|
||||
color: inherit !important;
|
||||
}
|
||||
|
||||
.dark [class*="LexicalEditor__editor-input___"] img[data-lexical-decorator] {
|
||||
filter: invert(1) hue-rotate(180deg);
|
||||
}
|
||||
|
||||
.course .composer {
|
||||
background: transparent !important;
|
||||
overflow: hidden;
|
||||
@@ -1277,9 +1629,14 @@ html.transparencyEffects
|
||||
color: var(--text-primary) !important;
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
box-sizing: border-box;
|
||||
padding-right: 56px !important;
|
||||
height: 54px;
|
||||
min-height: 48px;
|
||||
/* Must match logo/`#content` spacer (~71px). A 54px height only "looked"
|
||||
taller in DEV (content-box); production content-script Tailwind forces
|
||||
border-box and collapses the bar to 54px. */
|
||||
height: 71px;
|
||||
min-height: 71px;
|
||||
box-shadow: rgba(0, 0, 0, 0.35) 0px 0px 10px;
|
||||
border-bottom: 1px solid rgba(255, 255, 255, 0.1);
|
||||
font-weight: 500 !important;
|
||||
@@ -1292,12 +1649,13 @@ html.transparencyEffects
|
||||
|
||||
#title::before {
|
||||
background-image: var(--betterseqta-logo);
|
||||
background-position: left;
|
||||
background-position: left center;
|
||||
background-repeat: no-repeat;
|
||||
background-size: auto 48px;
|
||||
height: 69.5px;
|
||||
content: "";
|
||||
width: 184px;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
.rightElements {
|
||||
display: flex;
|
||||
@@ -1320,10 +1678,20 @@ html.transparencyEffects
|
||||
color: var(--text-color);
|
||||
}
|
||||
.timetable-arrows {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
align-items: center;
|
||||
flex-shrink: 0;
|
||||
gap: 4px;
|
||||
padding: 5px;
|
||||
}
|
||||
.timetable-arrows svg {
|
||||
margin: 0 5px;
|
||||
display: block;
|
||||
flex-shrink: 0;
|
||||
width: 24px;
|
||||
height: 24px;
|
||||
margin: 0;
|
||||
position: static;
|
||||
cursor: pointer;
|
||||
}
|
||||
.timetable-arrows svg:hover {
|
||||
@@ -1473,7 +1841,8 @@ html.transparencyEffects
|
||||
-webkit-box-shadow: 0px 5px 16px 6px rgba(0, 0, 0, 0.3);
|
||||
box-shadow: 0px 5px 16px 6px rgba(0, 0, 0, 0.3);
|
||||
}
|
||||
.border {
|
||||
/* `.border` is also a public hook used by existing themes. */
|
||||
.home-container .border {
|
||||
border-radius: 16px;
|
||||
overflow: clip;
|
||||
}
|
||||
@@ -2660,11 +3029,24 @@ body {
|
||||
.days {
|
||||
width: 100%;
|
||||
}
|
||||
.modaliser {
|
||||
display: none;
|
||||
/* Do not hide .modaliser globally — SEQTA Modaliser relies on transitionend to
|
||||
dispose; display:none prevents that and leaves empty shells that block clicks. */
|
||||
.modaliser-container:not(.visible) {
|
||||
display: none !important;
|
||||
pointer-events: none !important;
|
||||
}
|
||||
|
||||
.modaliser-container.visible .modaliser {
|
||||
background: var(--better-main);
|
||||
}
|
||||
|
||||
/* ColourChooser teardown can leave a full-screen uiSlidePane that blocks entry clicks */
|
||||
.uiSlidePane:not(.shown):has(.pane.colourChooser) {
|
||||
display: none !important;
|
||||
pointer-events: none !important;
|
||||
visibility: hidden !important;
|
||||
}
|
||||
|
||||
[class*="MessageList__unread___"] {
|
||||
position: relative;
|
||||
background: var(--background-secondary, rgb(228 225 225));
|
||||
@@ -2742,39 +3124,9 @@ body {
|
||||
.defaultWelcomeWrapper {
|
||||
background: unset !important;
|
||||
}
|
||||
.clr-swatches button::after,
|
||||
.clr-dark .clr-preview::after,
|
||||
.clr-field button::after {
|
||||
opacity: unset;
|
||||
padding-top: unset;
|
||||
-webkit-transform: unset;
|
||||
transform: unset;
|
||||
-webkit-transform-origin: unset;
|
||||
transform-origin: unset;
|
||||
visibility: unset;
|
||||
-webkit-animation-name: unset !important;
|
||||
animation-name: unset !important;
|
||||
background-color: currentColor !important;
|
||||
}
|
||||
.clr-swatches button {
|
||||
align-items: unset;
|
||||
display: block;
|
||||
padding: unset;
|
||||
transition: none;
|
||||
}
|
||||
.clr-clear {
|
||||
display: none !important;
|
||||
}
|
||||
.clr-preview::before,
|
||||
.clr-preview::after {
|
||||
visibility: unset;
|
||||
-webkit-transform-origin: unset;
|
||||
transform-origin: unset;
|
||||
-webkit-transform: unset;
|
||||
transform: unset;
|
||||
padding-top: unset;
|
||||
opacity: unset;
|
||||
}
|
||||
|
||||
/* Coloris (timetable subject colours): cosmetic only — do not unset
|
||||
transforms/animations on ::after (breaks picker reopen). */
|
||||
#clr-color-preview {
|
||||
margin: 15px 0 20px 20px;
|
||||
border: 0;
|
||||
@@ -2783,6 +3135,18 @@ body {
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.clr-swatches button {
|
||||
border-radius: 4px;
|
||||
}
|
||||
|
||||
/* Never let a closed Coloris picker intercept timetable clicks */
|
||||
body:not(.clr-open) .clr-picker,
|
||||
.clr-picker:not(.clr-open) {
|
||||
display: none !important;
|
||||
pointer-events: none !important;
|
||||
visibility: hidden !important;
|
||||
}
|
||||
|
||||
.dark
|
||||
[class*="MessageList__MessageList___"]
|
||||
> ol
|
||||
@@ -3638,6 +4002,9 @@ div.day-empty {
|
||||
aspect-ratio: 16 / 9;
|
||||
border-radius: 16px;
|
||||
box-shadow: 0px 0px 10px 0px rgba(0, 0, 0, 0.3);
|
||||
object-fit: cover;
|
||||
display: block;
|
||||
background: #000;
|
||||
}
|
||||
.whatsnewTextContainer {
|
||||
display: flex;
|
||||
|
||||
+13
-13
@@ -14,11 +14,12 @@
|
||||
.outside-container {
|
||||
margin: 0;
|
||||
overflow: hidden;
|
||||
position: absolute;
|
||||
right: 10px;
|
||||
top: 80px;
|
||||
height: 590px;
|
||||
z-index: 100;
|
||||
position: fixed;
|
||||
inset: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
/* Above Engage React chrome / MUI layers; below rare fullscreen media overlays */
|
||||
z-index: 200000;
|
||||
transition-duration: 100ms;
|
||||
}
|
||||
|
||||
@@ -31,12 +32,11 @@
|
||||
}
|
||||
|
||||
#ExtensionPopup {
|
||||
border-radius: 1rem;
|
||||
filter: drop-shadow(0px 0px 20px rgba(0, 0, 0, 0.6));
|
||||
transform-origin: 70% 0;
|
||||
will-change: opacity, transform;
|
||||
transform: translateZ(0); // promotes GPU rendering
|
||||
transition:
|
||||
opacity 0.05s,
|
||||
transform 0.05s;
|
||||
border-radius: 0;
|
||||
filter: none;
|
||||
/* Avoid transform on the host — it makes shadow `position: fixed` children
|
||||
size to the host instead of the viewport on Engage stacking contexts. */
|
||||
transform-origin: center center;
|
||||
will-change: opacity;
|
||||
transition: opacity 0.05s;
|
||||
}
|
||||
@@ -1,32 +1,24 @@
|
||||
#menu ul:has(li.hasChildren.active) li.hasChildren.active {
|
||||
#menu ul:has(li.hasChildren:is(.active, .bsplus-active))
|
||||
li.hasChildren:is(.active, .bsplus-active) {
|
||||
box-shadow: inset 0px 0 var(--item-colour, transparent) !important;
|
||||
background: transparent !important;
|
||||
}
|
||||
|
||||
#menu ul:not(:has(li.hasChildren.active)) {
|
||||
#menu ul:not(:has(li.hasChildren:is(.active, .bsplus-active))) {
|
||||
overflow-y: scroll !important;
|
||||
}
|
||||
|
||||
#menu > ul:has(li.hasChildren.active) > li::before,
|
||||
#menu > ul ul:has(li.hasChildren.active) > li::before,
|
||||
#menu > ul:has(li.hasChildren.active) > li > label,
|
||||
#menu > ul:has(li.hasChildren.active) > li > svg,
|
||||
#menu > ul ul:has(li.hasChildren.active) > li > label,
|
||||
#menu > ul ul:has(li.hasChildren.active) > li > svg {
|
||||
transform: translateX(-320px);
|
||||
}
|
||||
|
||||
#menu li.hasChildren:not(.active) li .sub {
|
||||
display: none; // improves performance
|
||||
}
|
||||
|
||||
.sub .sub {
|
||||
top: 0 !important;
|
||||
padding-top: 2px;
|
||||
}
|
||||
|
||||
.sub:has(ul > li.hasChildren.active) > .nav > .back {
|
||||
display: none !important;
|
||||
#menu > ul:has(li.hasChildren:is(.active, .bsplus-active)) > li::before,
|
||||
#menu > ul:has(li.hasChildren:is(.active, .bsplus-active)) > li::after,
|
||||
#menu > ul ul:has(li.hasChildren:is(.active, .bsplus-active)) > li::before,
|
||||
#menu > ul ul:has(li.hasChildren:is(.active, .bsplus-active)) > li::after,
|
||||
#menu > ul:has(li.hasChildren:is(.active, .bsplus-active)) > li > label,
|
||||
#menu > ul:has(li.hasChildren:is(.active, .bsplus-active)) > li > svg,
|
||||
#menu > ul ul:has(li.hasChildren:is(.active, .bsplus-active)) > li > label,
|
||||
#menu > ul ul:has(li.hasChildren:is(.active, .bsplus-active)) > li > svg {
|
||||
/* !important beats theme animations (e.g. Beach palm-slide forwards). */
|
||||
transform: translateX(-320px) !important;
|
||||
animation: none !important;
|
||||
}
|
||||
|
||||
#menu ul > li > label,
|
||||
@@ -38,16 +30,145 @@
|
||||
transition: transform 0.3s ease, left 0.4s cubic-bezier(0.4, 0, 0.2, 1);
|
||||
}
|
||||
|
||||
#menu > ul:has(li.hasChildren.active) > li.active {
|
||||
#menu > ul:has(li.hasChildren:is(.active, .bsplus-active))
|
||||
> li:is(.active, .bsplus-active) {
|
||||
background: transparent !important;
|
||||
}
|
||||
|
||||
#menu li.hasChildren:not(:is(.active, .bsplus-active)) li .sub {
|
||||
display: none; // improves performance
|
||||
}
|
||||
|
||||
.sub .sub {
|
||||
top: 0 !important;
|
||||
padding-top: 2px;
|
||||
}
|
||||
|
||||
.sub:has(ul > li.hasChildren:is(.active, .bsplus-active)) > .nav > .back {
|
||||
display: none !important;
|
||||
}
|
||||
|
||||
/* Icon-only collapsed: submenu slides over narrow icons */
|
||||
body.icon-only-sidebar:not(:has(#menu li.hasChildren.active)) #menu > ul:has(li.hasChildren.active) > li::before,
|
||||
body.icon-only-sidebar:not(:has(#menu li.hasChildren.active)) #menu > ul ul:has(li.hasChildren.active) > li::before,
|
||||
body.icon-only-sidebar:not(:has(#menu li.hasChildren.active)) #menu > ul:has(li.hasChildren.active) > li > label,
|
||||
body.icon-only-sidebar:not(:has(#menu li.hasChildren.active)) #menu > ul:has(li.hasChildren.active) > li > svg,
|
||||
body.icon-only-sidebar:not(:has(#menu li.hasChildren.active)) #menu > ul ul:has(li.hasChildren.active) > li > label,
|
||||
body.icon-only-sidebar:not(:has(#menu li.hasChildren.active)) #menu > ul ul:has(li.hasChildren.active) > li > svg {
|
||||
body.icon-only-sidebar:not(:has(#menu li.hasChildren:is(.active, .bsplus-active)))
|
||||
#menu
|
||||
> ul:has(li.hasChildren:is(.active, .bsplus-active))
|
||||
> li::before,
|
||||
body.icon-only-sidebar:not(:has(#menu li.hasChildren:is(.active, .bsplus-active)))
|
||||
#menu
|
||||
> ul
|
||||
ul:has(li.hasChildren:is(.active, .bsplus-active))
|
||||
> li::before,
|
||||
body.icon-only-sidebar:not(:has(#menu li.hasChildren:is(.active, .bsplus-active)))
|
||||
#menu
|
||||
> ul:has(li.hasChildren:is(.active, .bsplus-active))
|
||||
> li
|
||||
> label,
|
||||
body.icon-only-sidebar:not(:has(#menu li.hasChildren:is(.active, .bsplus-active)))
|
||||
#menu
|
||||
> ul:has(li.hasChildren:is(.active, .bsplus-active))
|
||||
> li
|
||||
> svg,
|
||||
body.icon-only-sidebar:not(:has(#menu li.hasChildren:is(.active, .bsplus-active)))
|
||||
#menu
|
||||
> ul
|
||||
ul:has(li.hasChildren:is(.active, .bsplus-active))
|
||||
> li
|
||||
> label,
|
||||
body.icon-only-sidebar:not(:has(#menu li.hasChildren:is(.active, .bsplus-active)))
|
||||
#menu
|
||||
> ul
|
||||
ul:has(li.hasChildren:is(.active, .bsplus-active))
|
||||
> li
|
||||
> svg {
|
||||
transform: translateX(-70px);
|
||||
}
|
||||
|
||||
/*
|
||||
* Custom sidebar drill slides — use `.drilling` / `.drill-entering` / `.drill-returning`,
|
||||
* not `:has(.active)` (SEQTA strips `.active` on nested clicks).
|
||||
*/
|
||||
#menu.bsplus-custom-sidebar #bsplus-sidebar-root {
|
||||
--bsplus-slide-off: -320px;
|
||||
|
||||
.sub {
|
||||
transition: none !important;
|
||||
}
|
||||
|
||||
&.drilling {
|
||||
overflow: hidden !important;
|
||||
|
||||
&:not(.drill-returning) > li::before,
|
||||
&:not(.drill-returning) > li::after,
|
||||
&:not(.drill-returning) > li > label,
|
||||
&:not(.drill-returning) > li > svg,
|
||||
&:not(.drill-returning) .sub:has(.sub) > ul > li::before,
|
||||
&:not(.drill-returning) .sub:has(.sub) > ul > li::after,
|
||||
&:not(.drill-returning) .sub:has(.sub) > ul > li > label,
|
||||
&:not(.drill-returning) .sub:has(.sub) > ul > li > svg {
|
||||
transform: translateX(var(--bsplus-slide-off)) !important;
|
||||
animation: none !important;
|
||||
}
|
||||
|
||||
&:not(.drill-entering):not(.drill-returning) {
|
||||
> li::before,
|
||||
> li::after,
|
||||
> li > label,
|
||||
> li > svg,
|
||||
.sub:has(.sub) > ul > li::before,
|
||||
.sub:has(.sub) > ul > li::after,
|
||||
.sub:has(.sub) > ul > li > label,
|
||||
.sub:has(.sub) > ul > li > svg {
|
||||
transition: none !important;
|
||||
}
|
||||
|
||||
.sub {
|
||||
transform: translateX(0) !important;
|
||||
opacity: 1 !important;
|
||||
}
|
||||
}
|
||||
|
||||
.sub:has(.sub) > .nav > .back {
|
||||
display: none !important;
|
||||
}
|
||||
}
|
||||
|
||||
&.drill-entering .sub.bsplus-sub-enter {
|
||||
animation: bsplus-submenu-enter 0.32s cubic-bezier(0.22, 1, 0.36, 1);
|
||||
}
|
||||
|
||||
&.drill-returning:not(.drilling) > li::before,
|
||||
&.drill-returning:not(.drilling) > li::after,
|
||||
&.drill-returning:not(.drilling) > li > label,
|
||||
&.drill-returning:not(.drilling) > li > svg,
|
||||
&.drilling.drill-returning > li.hasChildren > .sub > ul > li::before,
|
||||
&.drilling.drill-returning > li.hasChildren > .sub > ul > li::after,
|
||||
&.drilling.drill-returning > li.hasChildren > .sub > ul > li > label,
|
||||
&.drilling.drill-returning > li.hasChildren > .sub > ul > li > svg {
|
||||
transition: none !important;
|
||||
animation: bsplus-sidebar-return 0.32s cubic-bezier(0.22, 1, 0.36, 1) both !important;
|
||||
}
|
||||
}
|
||||
|
||||
body.icon-only-sidebar #menu.bsplus-custom-sidebar #bsplus-sidebar-root {
|
||||
--bsplus-slide-off: -70px;
|
||||
}
|
||||
|
||||
@keyframes bsplus-sidebar-return {
|
||||
from {
|
||||
transform: translateX(var(--bsplus-slide-off, -320px));
|
||||
}
|
||||
to {
|
||||
transform: translateX(0);
|
||||
}
|
||||
}
|
||||
|
||||
@keyframes bsplus-submenu-enter {
|
||||
from {
|
||||
opacity: 0.35;
|
||||
transform: translateX(28px);
|
||||
}
|
||||
to {
|
||||
opacity: 1;
|
||||
transform: translateX(0);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,222 @@
|
||||
/* Custom sidebar style presets + Look (density / radius / indicator). */
|
||||
|
||||
$sidebar-motion: 0.4s cubic-bezier(0.4, 0, 0.2, 1);
|
||||
|
||||
@mixin accent-bar($shadow: 0.55) {
|
||||
content: "" !important;
|
||||
position: absolute !important;
|
||||
left: 0 !important;
|
||||
top: 10px !important;
|
||||
bottom: 10px !important;
|
||||
width: 4px !important;
|
||||
border-radius: 2px !important;
|
||||
background: #fff !important;
|
||||
box-shadow: 0 0 10px rgba(255, 255, 255, $shadow) !important;
|
||||
pointer-events: none !important;
|
||||
z-index: 3 !important;
|
||||
opacity: 1 !important;
|
||||
display: block !important;
|
||||
}
|
||||
|
||||
#menu.bsplus-custom-sidebar {
|
||||
$item: "> #bsplus-sidebar-root .bsplus-sidebar-item";
|
||||
$label: "> #bsplus-sidebar-root .bsplus-sidebar-item > label:not(.toggle)";
|
||||
$active: "> #bsplus-sidebar-root .bsplus-sidebar-item.bsplus-active:not(.hasChildren)";
|
||||
|
||||
/* Look: base radius (pill / sharp / strip override).
|
||||
Density/radius animate with the same easing as sidebar width. */
|
||||
#{$item} {
|
||||
border-radius: var(--bsplus-sidebar-radius, 12px) !important;
|
||||
transition:
|
||||
padding $sidebar-motion,
|
||||
margin $sidebar-motion,
|
||||
border-radius $sidebar-motion,
|
||||
background-color 0.2s ease,
|
||||
box-shadow 0.2s ease,
|
||||
opacity 0.2s ease;
|
||||
}
|
||||
|
||||
#{$label} {
|
||||
min-height: 28px !important;
|
||||
transition:
|
||||
font-size $sidebar-motion,
|
||||
line-height $sidebar-motion,
|
||||
padding $sidebar-motion,
|
||||
margin $sidebar-motion;
|
||||
|
||||
> svg {
|
||||
transition:
|
||||
width $sidebar-motion,
|
||||
height $sidebar-motion,
|
||||
margin $sidebar-motion;
|
||||
}
|
||||
}
|
||||
|
||||
/* —— Style presets —— */
|
||||
&.bsplus-sidebar-style-soft {
|
||||
#{$item} {
|
||||
margin: 0 8px 10px !important;
|
||||
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.12);
|
||||
}
|
||||
#{$active} {
|
||||
box-shadow: 0 6px 18px rgba(0, 0, 0, 0.22);
|
||||
background: rgba(0, 0, 0, 0.38) !important;
|
||||
}
|
||||
}
|
||||
|
||||
&.bsplus-sidebar-style-pill {
|
||||
#{$item} {
|
||||
margin: 0 10px 8px !important;
|
||||
border-radius: 999px !important;
|
||||
}
|
||||
#{$active} {
|
||||
background: rgba(0, 0, 0, 0.4) !important;
|
||||
}
|
||||
}
|
||||
|
||||
&.bsplus-sidebar-style-glass {
|
||||
#{$item} {
|
||||
margin: 0 8px 8px !important;
|
||||
background: rgba(255, 255, 255, 0.1) !important;
|
||||
backdrop-filter: blur(10px);
|
||||
-webkit-backdrop-filter: blur(10px);
|
||||
box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.14);
|
||||
}
|
||||
#{$active} {
|
||||
background: rgba(255, 255, 255, 0.2) !important;
|
||||
box-shadow:
|
||||
inset 0 0 0 1px rgba(255, 255, 255, 0.28),
|
||||
0 8px 20px rgba(0, 0, 0, 0.2);
|
||||
}
|
||||
}
|
||||
|
||||
&.bsplus-sidebar-style-sharp {
|
||||
#{$item},
|
||||
#{$active} {
|
||||
border-radius: 4px !important;
|
||||
}
|
||||
#{$item} {
|
||||
margin: 0 4px 4px !important;
|
||||
}
|
||||
#{$active} {
|
||||
background: rgba(0, 0, 0, 0.42) !important;
|
||||
}
|
||||
}
|
||||
|
||||
&.bsplus-sidebar-style-strip {
|
||||
#{$item} {
|
||||
margin: 0 0 2px !important;
|
||||
border-radius: 0 !important;
|
||||
background: transparent !important;
|
||||
box-shadow: none !important;
|
||||
}
|
||||
#{$active} {
|
||||
position: relative !important;
|
||||
background: rgba(255, 255, 255, 0.12) !important;
|
||||
box-shadow: none !important;
|
||||
&::after {
|
||||
@include accent-bar(0.55);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
&.bsplus-sidebar-style-neon #{$active} {
|
||||
background: rgba(255, 255, 255, 0.1) !important;
|
||||
box-shadow:
|
||||
0 0 0 1px rgba(255, 255, 255, 0.55),
|
||||
0 0 14px rgba(255, 255, 255, 0.4),
|
||||
0 0 28px rgba(255, 255, 255, 0.22) !important;
|
||||
}
|
||||
|
||||
&.bsplus-sidebar-style-neon #{$item} {
|
||||
margin: 0 8px 8px !important;
|
||||
}
|
||||
|
||||
/* —— Density (comfortable = no class / no overrides) —— */
|
||||
&.bsplus-sidebar-density-compact {
|
||||
#{$item},
|
||||
#{$active} {
|
||||
padding: 6px 8px !important;
|
||||
min-height: 0 !important;
|
||||
}
|
||||
#{$item} {
|
||||
margin: 0 6px 4px !important;
|
||||
height: auto !important;
|
||||
}
|
||||
#{$label} {
|
||||
padding: 0 !important;
|
||||
margin: 0 !important;
|
||||
font-size: 13px !important;
|
||||
line-height: 1.2 !important;
|
||||
min-height: 20px !important;
|
||||
height: auto !important;
|
||||
white-space: nowrap !important;
|
||||
|
||||
> svg {
|
||||
width: 20px !important;
|
||||
height: 20px !important;
|
||||
margin: 0 8px 0 2px !important;
|
||||
flex-shrink: 0 !important;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
&.bsplus-sidebar-density-large {
|
||||
#{$item} {
|
||||
margin: 0 8px 10px !important;
|
||||
padding: 14px 12px !important;
|
||||
}
|
||||
#{$label} {
|
||||
padding: 0 !important;
|
||||
font-size: 17px !important;
|
||||
line-height: 1.25 !important;
|
||||
min-height: 30px !important;
|
||||
|
||||
> svg {
|
||||
width: 30px !important;
|
||||
height: 30px !important;
|
||||
margin: 0 10px 0 4px !important;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* —— Active indicator (fill = default, no class) —— */
|
||||
&.bsplus-sidebar-indicator-bar:not(.bsplus-sidebar-style-strip) #{$active} {
|
||||
position: relative !important;
|
||||
background: rgba(255, 255, 255, 0.1) !important;
|
||||
box-shadow: none !important;
|
||||
&::after {
|
||||
@include accent-bar(0.45);
|
||||
}
|
||||
}
|
||||
|
||||
&.bsplus-sidebar-indicator-outline #{$active} {
|
||||
background: transparent !important;
|
||||
box-shadow:
|
||||
inset 0 0 0 2px rgba(255, 255, 255, 0.55),
|
||||
0 0 0 1px rgba(255, 255, 255, 0.12) !important;
|
||||
}
|
||||
|
||||
&.bsplus-sidebar-indicator-underline:not(.bsplus-sidebar-style-strip) #{$active} {
|
||||
position: relative !important;
|
||||
background: transparent !important;
|
||||
box-shadow: none !important;
|
||||
&::after {
|
||||
content: "" !important;
|
||||
position: absolute !important;
|
||||
left: 14px !important;
|
||||
right: 14px !important;
|
||||
bottom: 6px !important;
|
||||
top: auto !important;
|
||||
width: auto !important;
|
||||
height: 3px !important;
|
||||
border-radius: 999px !important;
|
||||
background: #fff !important;
|
||||
box-shadow: 0 0 8px rgba(255, 255, 255, 0.4) !important;
|
||||
pointer-events: none !important;
|
||||
z-index: 3 !important;
|
||||
opacity: 1 !important;
|
||||
display: block !important;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -23,7 +23,7 @@ html.transparencyEffects {
|
||||
/* Blurs */
|
||||
.search,
|
||||
.document,
|
||||
.border,
|
||||
.bsplus-rounded,
|
||||
.draggable,
|
||||
.notice,
|
||||
[class*="BasicPanel__BasicPanel___"],
|
||||
@@ -51,7 +51,10 @@ html.transparencyEffects {
|
||||
backdrop-filter: blur(10px) !important;
|
||||
}
|
||||
|
||||
#menu,
|
||||
#menu {
|
||||
backdrop-filter: blur(var(--bsplus-sidebar-blur, 50px));
|
||||
}
|
||||
|
||||
.kanban-column,
|
||||
.whatsnewContainer,
|
||||
[class*="Message__Message___"] {
|
||||
|
||||
Vendored
+17
@@ -1,4 +1,5 @@
|
||||
declare module "*.mp4";
|
||||
declare module "*.webm";
|
||||
declare module "*.woff";
|
||||
declare module "*.scss";
|
||||
declare module "*.png";
|
||||
@@ -10,6 +11,22 @@ declare module "*?inlineWorker" {
|
||||
export default value;
|
||||
}
|
||||
|
||||
/** CRXJS dynamic content / main-world script path (relative to extension root). */
|
||||
declare module "*?script" {
|
||||
const path: string;
|
||||
export default path;
|
||||
}
|
||||
|
||||
declare module "*?script&iife" {
|
||||
const path: string;
|
||||
export default path;
|
||||
}
|
||||
|
||||
declare module "*?script&module" {
|
||||
const path: string;
|
||||
export default path;
|
||||
}
|
||||
|
||||
declare module "*.png?base64" {
|
||||
const value: string;
|
||||
export default value;
|
||||
|
||||
Vendored
+2
@@ -2,3 +2,5 @@ declare const __ENABLE_GH_RELEASE_UPDATE_CHECK__: boolean;
|
||||
declare const __GH_RELEASE_REPO__: string;
|
||||
declare const __UPDATE_CHANNEL__: "stable" | "nightly";
|
||||
declare const __BUILD_LABEL__: string;
|
||||
declare const __GOOGLE_OAUTH_CLIENT_ID__: string;
|
||||
declare const __OUTLOOK_OAUTH_CLIENT_ID__: string;
|
||||
@@ -92,7 +92,7 @@
|
||||
bind:this={background}
|
||||
class="flex absolute top-0 left-0 z-50 justify-center items-center w-full h-full cursor-pointer bg-black/50"
|
||||
onclick={handleBackgroundClick}
|
||||
onkeydown={(e) => { if (e.key === "Enter") handleBackgroundClick; }}
|
||||
onkeydown={(e) => { if (e.key === "Enter") handleBackgroundClick(e as unknown as MouseEvent) }}
|
||||
>
|
||||
<div
|
||||
bind:this={content}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<script lang="ts">
|
||||
import { resolveCloudPfp } from "@/seqta/utils/cloudPfpCache";
|
||||
import { resolveCloudPfp, defaultAccountsPfpUrl } from "@/seqta/utils/cloudPfpCache";
|
||||
import type { CloudUser } from "@/seqta/utils/CloudAuth";
|
||||
|
||||
const { user, class: className = "" } = $props<{
|
||||
@@ -18,10 +18,12 @@
|
||||
}
|
||||
avatarSrc = undefined;
|
||||
|
||||
if (!u?.pfpUrl || !u.id) return;
|
||||
if (!u?.id) return;
|
||||
|
||||
const pfpUrl = u.pfpUrl ?? defaultAccountsPfpUrl(u.id);
|
||||
|
||||
let cancelled = false;
|
||||
void resolveCloudPfp(u.id, u.pfpUrl).then((resolved) => {
|
||||
void resolveCloudPfp(u.id, pfpUrl).then((resolved) => {
|
||||
if (cancelled || !resolved) return;
|
||||
if (resolved.fromCache) {
|
||||
revokeUrl = resolved.src;
|
||||
|
||||
@@ -22,15 +22,13 @@
|
||||
});
|
||||
|
||||
async function upload() {
|
||||
const token = await cloudAuth.getStoredToken();
|
||||
if (!token) return;
|
||||
if (!cloudState.isLoggedIn) return;
|
||||
busy = true;
|
||||
statusError = null;
|
||||
statusMessage = null;
|
||||
try {
|
||||
const res = (await browser.runtime.sendMessage({
|
||||
type: "cloudSettingsUpload",
|
||||
token,
|
||||
})) as { success?: boolean; error?: string };
|
||||
if (res?.success) {
|
||||
statusMessage = "Settings uploaded.";
|
||||
@@ -49,15 +47,13 @@
|
||||
}
|
||||
|
||||
async function confirmDownload() {
|
||||
const token = await cloudAuth.getStoredToken();
|
||||
if (!token) return;
|
||||
if (!cloudState.isLoggedIn) return;
|
||||
busy = true;
|
||||
statusError = null;
|
||||
statusMessage = null;
|
||||
try {
|
||||
const res = (await browser.runtime.sendMessage({
|
||||
type: "cloudSettingsDownload",
|
||||
token,
|
||||
})) as { success?: boolean; error?: string; notFound?: boolean };
|
||||
if (res?.success) {
|
||||
statusMessage = "Settings restored.";
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
|
||||
let editor = $state<HTMLDivElement | null>(null)
|
||||
let view: EditorView | null = null;
|
||||
let unsubSettings: (() => void) | undefined;
|
||||
let editorTheme = new Compartment();
|
||||
let { value, onChange, className } = $props<{value: string, onChange: (value: string) => void, className?: string}>()
|
||||
|
||||
@@ -73,7 +74,7 @@
|
||||
view = createEditorView(state, editor as HTMLElement);
|
||||
}
|
||||
|
||||
settingsState.subscribe((settings) => {
|
||||
unsubSettings = settingsState.subscribe((settings) => {
|
||||
if (view) {
|
||||
view.dispatch({
|
||||
effects: editorTheme.reconfigure(
|
||||
@@ -85,6 +86,7 @@
|
||||
});
|
||||
|
||||
onDestroy(() => {
|
||||
unsubSettings?.();
|
||||
if (view) {
|
||||
view.destroy();
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
<script lang="ts">
|
||||
import { onMount } from 'svelte'
|
||||
import ColourPicker from './ColourPicker.tsx';
|
||||
import ReactAdapter from './utils/ReactAdapter.svelte';
|
||||
import type { Component } from 'svelte'
|
||||
import { animate } from 'motion';
|
||||
import { delay } from '@/seqta/utils/delay.ts'
|
||||
import { settingsState } from '@/seqta/utils/listeners/SettingsState.ts'
|
||||
|
||||
const { hidePicker, standalone = false, savePresets = true, customOnChange = null, customState = null } = $props<{
|
||||
hidePicker?: () => void,
|
||||
@@ -15,6 +15,19 @@
|
||||
|
||||
let background = $state<HTMLDivElement | null>(null);
|
||||
let content = $state<HTMLDivElement | null>(null);
|
||||
let ReactAdapter = $state<Component | null>(null);
|
||||
let ColourPickerEl = $state<unknown>(null);
|
||||
let pickerReady = $state(false);
|
||||
|
||||
const loadPicker = async () => {
|
||||
const [adapterMod, pickerMod] = await Promise.all([
|
||||
import('./utils/ReactAdapter.svelte'),
|
||||
import('./ColourPicker.tsx'),
|
||||
]);
|
||||
ReactAdapter = adapterMod.default;
|
||||
ColourPickerEl = pickerMod.default;
|
||||
pickerReady = true;
|
||||
};
|
||||
|
||||
const closePicker = async () => {
|
||||
if (standalone) return;
|
||||
@@ -37,28 +50,30 @@
|
||||
);
|
||||
|
||||
await delay(400);
|
||||
hidePicker();
|
||||
hidePicker?.();
|
||||
}
|
||||
|
||||
onMount(() => {
|
||||
if (standalone) return;
|
||||
if (!background || !content) return;
|
||||
void loadPicker().then(() => {
|
||||
if (standalone) return;
|
||||
if (!background || !content) return;
|
||||
|
||||
animate(
|
||||
background,
|
||||
{ opacity: [0, 1] },
|
||||
{ duration: 0.3, ease: [0.4, 0, 0.2, 1] }
|
||||
);
|
||||
animate(
|
||||
background,
|
||||
{ opacity: [0, 1] },
|
||||
{ duration: 0.3, ease: [0.4, 0, 0.2, 1] }
|
||||
);
|
||||
|
||||
animate(
|
||||
content,
|
||||
{ scale: [0.4, 1], opacity: [0, 1] },
|
||||
{
|
||||
type: 'spring',
|
||||
stiffness: 400,
|
||||
damping: 30
|
||||
}
|
||||
);
|
||||
animate(
|
||||
content,
|
||||
{ scale: [0.4, 1], opacity: [0, 1] },
|
||||
{
|
||||
type: 'spring',
|
||||
stiffness: 400,
|
||||
damping: 30
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
const handleEscapeKey = (e: KeyboardEvent) => {
|
||||
if (e.key === 'Escape') {
|
||||
@@ -81,22 +96,26 @@
|
||||
</script>
|
||||
|
||||
{#if standalone}
|
||||
<div class="h-auto overflow-clip rounded-xl">
|
||||
<ReactAdapter customOnChange={customOnChange} customState={customState} savePresets={savePresets} el={ColourPicker} />
|
||||
<div class="h-auto overflow-clip rounded-xl {$settingsState.DarkMode ? 'dark' : ''}">
|
||||
{#if pickerReady && ReactAdapter && ColourPickerEl}
|
||||
<ReactAdapter customOnChange={customOnChange} customState={customState} savePresets={savePresets} el={ColourPickerEl} />
|
||||
{/if}
|
||||
</div>
|
||||
{:else}
|
||||
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
||||
<div
|
||||
bind:this={background}
|
||||
class="flex absolute top-0 left-0 z-50 justify-center items-center w-full h-full shadow-2xl cursor-pointer bg-black/20 border border-[#DDDDDD]/30 dark:border-[#38373D]/30"
|
||||
class="flex absolute top-0 left-0 z-50 justify-center items-center w-full h-full shadow-2xl cursor-pointer bg-black/20 border border-[#DDDDDD]/30 dark:border-[#38373D]/30 {$settingsState.DarkMode ? 'dark' : ''}"
|
||||
onclick={handleBackgroundClick}
|
||||
onkeydown={(e) => { e.key === 'Enter' && handleBackgroundClick }}
|
||||
onkeydown={(e) => { if (e.key === 'Enter') handleBackgroundClick(e as unknown as MouseEvent) }}
|
||||
>
|
||||
<div
|
||||
bind:this={content}
|
||||
class="p-4 h-auto bg-white rounded-xl border shadow-lg cursor-auto dark:bg-zinc-800 border-zinc-100 dark:border-zinc-700"
|
||||
>
|
||||
<ReactAdapter customOnChange={customOnChange} customState={customState} savePresets={savePresets} el={ColourPicker} />
|
||||
{#if pickerReady && ReactAdapter && ColourPickerEl}
|
||||
<ReactAdapter customOnChange={customOnChange} customState={customState} savePresets={savePresets} el={ColourPickerEl} />
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
@@ -0,0 +1,489 @@
|
||||
<script lang="ts">
|
||||
import { fade, scale } from "svelte/transition";
|
||||
import { onMount, tick } from "svelte";
|
||||
import Switch from "./Switch.svelte";
|
||||
import {
|
||||
FEEDBACK_CATEGORIES,
|
||||
FEEDBACK_MESSAGE_MAX,
|
||||
FEEDBACK_MESSAGE_MIN,
|
||||
type FeedbackCategory,
|
||||
} from "@/seqta/utils/feedback/constants";
|
||||
import {
|
||||
FeedbackApiError,
|
||||
addPendingFeedbackId,
|
||||
categoryLabel,
|
||||
fetchFeedbackStatusItem,
|
||||
fetchFeedbackStatusList,
|
||||
formatStatus,
|
||||
getInstanceHostname,
|
||||
hasReply,
|
||||
removePendingFeedbackIds,
|
||||
submitFeedback,
|
||||
validateFeedbackForm,
|
||||
type FeedbackStatusItem,
|
||||
} from "@/seqta/utils/feedback/client";
|
||||
import { settingsState } from "@/seqta/utils/listeners/SettingsState";
|
||||
import Spinner from "./Spinner.svelte";
|
||||
|
||||
let { onClose, initialFeedbackId = null } = $props<{
|
||||
onClose: () => void;
|
||||
initialFeedbackId?: string | null;
|
||||
}>();
|
||||
|
||||
let tab = $state<"send" | "status">(
|
||||
typeof initialFeedbackId === "string" && initialFeedbackId ? "status" : "send",
|
||||
);
|
||||
let category = $state<FeedbackCategory>("bug");
|
||||
let subject = $state("");
|
||||
let message = $state("");
|
||||
let includeContact = $state(false);
|
||||
let contactName = $state("");
|
||||
let contactEmail = $state("");
|
||||
let includeInstance = $state(false);
|
||||
let submitting = $state(false);
|
||||
let errorMessage = $state<string | null>(null);
|
||||
let successId = $state<string | null>(null);
|
||||
let statusLoading = $state(false);
|
||||
let statusError = $state<string | null>(null);
|
||||
let statusItems = $state<FeedbackStatusItem[]>([]);
|
||||
let selectedItem = $state<FeedbackStatusItem | null>(null);
|
||||
|
||||
const instanceHostname = getInstanceHostname();
|
||||
const isDark = $derived(!!$settingsState.DarkMode);
|
||||
const busy = $derived(submitting || statusLoading);
|
||||
const fieldStyle = $derived(
|
||||
isDark
|
||||
? "background-color:#18181b;color:#fafafa;border-color:#52525b;color-scheme:dark"
|
||||
: "background-color:#fff;color:#18181b;border-color:#e4e4e7;color-scheme:light",
|
||||
);
|
||||
const field =
|
||||
"feedback-field w-full px-3 py-2.5 text-[18px] rounded-lg border focus:outline-none focus:ring-2 focus:ring-zinc-400";
|
||||
const btn =
|
||||
"px-4 py-2 text-[18px] font-medium rounded-lg transition-all duration-200 hover:scale-105 active:scale-95 focus:outline-none focus:ring-2 focus:ring-zinc-400 disabled:opacity-50";
|
||||
const btnMuted = $derived(
|
||||
`${btn} ${isDark ? "bg-zinc-700 text-zinc-200" : "bg-zinc-200 text-zinc-700"}`,
|
||||
);
|
||||
const btnPrimary = $derived(
|
||||
`${btn} ${isDark ? "bg-zinc-200 text-zinc-900" : "bg-zinc-800 text-white"}`,
|
||||
);
|
||||
const panelKey = $derived(
|
||||
tab === "send"
|
||||
? successId
|
||||
? "send-success"
|
||||
: "send-form"
|
||||
: selectedItem
|
||||
? `status-${selectedItem.id}`
|
||||
: "status-list",
|
||||
);
|
||||
|
||||
let panelBodyEl = $state<HTMLDivElement | null>(null);
|
||||
let panelHeightPx = $state<number | null>(null);
|
||||
|
||||
const panelHeightEase = "cubic-bezier(0.22, 1, 0.36, 1)";
|
||||
const panelHeightMotion = $derived(
|
||||
$settingsState.animations && panelHeightPx !== null
|
||||
? `height 280ms ${panelHeightEase}`
|
||||
: "none",
|
||||
);
|
||||
|
||||
function measurePanelHeight() {
|
||||
if (!panelBodyEl) return;
|
||||
panelHeightPx = panelBodyEl.scrollHeight;
|
||||
}
|
||||
|
||||
function panelMeasure(node: HTMLDivElement) {
|
||||
panelBodyEl = node;
|
||||
|
||||
const update = () => {
|
||||
panelHeightPx = node.scrollHeight;
|
||||
};
|
||||
|
||||
update();
|
||||
const ro = new ResizeObserver(() => update());
|
||||
ro.observe(node);
|
||||
|
||||
return {
|
||||
destroy() {
|
||||
ro.disconnect();
|
||||
if (panelBodyEl === node) panelBodyEl = null;
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
$effect(() => {
|
||||
panelKey;
|
||||
includeContact;
|
||||
errorMessage;
|
||||
statusLoading;
|
||||
statusItems.length;
|
||||
selectedItem;
|
||||
void tick().then(() => measurePanelHeight());
|
||||
});
|
||||
|
||||
function isStatusDetailKey(key: string): boolean {
|
||||
return key.startsWith("status-") && key !== "status-list";
|
||||
}
|
||||
|
||||
function errText(e: unknown): string {
|
||||
if (e instanceof FeedbackApiError) return e.message;
|
||||
return e instanceof Error ? e.message : "Something went wrong.";
|
||||
}
|
||||
|
||||
async function loadStatusList() {
|
||||
statusLoading = true;
|
||||
statusError = null;
|
||||
selectedItem = null;
|
||||
try {
|
||||
statusItems = await fetchFeedbackStatusList(10);
|
||||
} catch (e) {
|
||||
statusItems = [];
|
||||
statusError = errText(e);
|
||||
} finally {
|
||||
statusLoading = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function openStatusItem(id: string) {
|
||||
statusLoading = true;
|
||||
statusError = null;
|
||||
try {
|
||||
selectedItem = await fetchFeedbackStatusItem(id);
|
||||
tab = "status";
|
||||
successId = null;
|
||||
if (selectedItem && hasReply(selectedItem)) {
|
||||
void removePendingFeedbackIds([selectedItem.id]);
|
||||
}
|
||||
} catch (e) {
|
||||
statusError = errText(e);
|
||||
} finally {
|
||||
statusLoading = false;
|
||||
}
|
||||
}
|
||||
|
||||
function selectTab(next: "send" | "status") {
|
||||
tab = next;
|
||||
errorMessage = null;
|
||||
statusError = null;
|
||||
successId = null;
|
||||
selectedItem = null;
|
||||
if (next === "status") void loadStatusList();
|
||||
}
|
||||
|
||||
onMount(() => {
|
||||
void tick().then(() => measurePanelHeight());
|
||||
if (typeof initialFeedbackId === "string" && initialFeedbackId) {
|
||||
void openStatusItem(initialFeedbackId);
|
||||
}
|
||||
});
|
||||
|
||||
async function handleSubmit() {
|
||||
const form = {
|
||||
category,
|
||||
subject,
|
||||
message,
|
||||
includeContact,
|
||||
contactName,
|
||||
contactEmail,
|
||||
includeInstance,
|
||||
};
|
||||
errorMessage = validateFeedbackForm(form);
|
||||
if (errorMessage) return;
|
||||
|
||||
submitting = true;
|
||||
try {
|
||||
const result = await submitFeedback(form);
|
||||
successId = result.id;
|
||||
void addPendingFeedbackId(result.id);
|
||||
} catch (e) {
|
||||
errorMessage = errText(e);
|
||||
} finally {
|
||||
submitting = false;
|
||||
}
|
||||
}
|
||||
|
||||
function tabClass(active: boolean): string {
|
||||
if (active) {
|
||||
return isDark
|
||||
? "bg-zinc-700 text-white font-semibold shadow-sm"
|
||||
: "bg-white text-zinc-900 font-semibold shadow-sm";
|
||||
}
|
||||
return isDark
|
||||
? "bg-transparent text-zinc-400 hover:text-zinc-200"
|
||||
: "bg-transparent text-zinc-500 hover:text-zinc-800";
|
||||
}
|
||||
</script>
|
||||
|
||||
<div
|
||||
class="flex fixed inset-0 z-[99999] justify-center items-center bg-black/50 backdrop-blur-sm {isDark
|
||||
? 'dark'
|
||||
: ''}"
|
||||
onclick={(e) => {
|
||||
if (e.target === e.currentTarget && !busy) onClose();
|
||||
}}
|
||||
onkeydown={(e) => {
|
||||
if (e.key === "Escape" && !busy) onClose();
|
||||
}}
|
||||
role="button"
|
||||
tabindex="-1"
|
||||
transition:fade={{ duration: $settingsState.animations ? 200 : 0 }}
|
||||
>
|
||||
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
||||
<div
|
||||
class="feedback-dialog p-5 mx-4 w-full max-w-lg max-h-[90vh] overflow-y-auto rounded-2xl shadow-2xl border text-[18px] {isDark
|
||||
? 'bg-zinc-800 text-white border-zinc-700'
|
||||
: 'bg-white text-zinc-900 border-zinc-200'}"
|
||||
onclick={(e) => e.stopPropagation()}
|
||||
onkeydown={(e) => e.stopPropagation()}
|
||||
role="dialog"
|
||||
aria-modal="true"
|
||||
aria-labelledby="feedback-modal-title"
|
||||
tabindex="-1"
|
||||
in:scale={{
|
||||
duration: $settingsState.animations ? 280 : 0,
|
||||
start: 0.92,
|
||||
opacity: 0,
|
||||
easing: (t) => 1 - Math.pow(1 - t, 3),
|
||||
}}
|
||||
>
|
||||
<div
|
||||
class="flex gap-1 p-1 mb-4 rounded-full {isDark ? 'bg-zinc-900' : 'bg-zinc-100'}"
|
||||
role="tablist"
|
||||
aria-label="Feedback views"
|
||||
>
|
||||
<button type="button" role="tab" aria-selected={tab === "send"} onclick={() => selectTab("send")} class="flex-1 px-3 py-2.5 rounded-full transition-all duration-200 {tabClass(tab === 'send')}">
|
||||
Send
|
||||
</button>
|
||||
<button type="button" role="tab" aria-selected={tab === "status"} onclick={() => selectTab("status")} class="flex-1 px-3 py-2.5 rounded-full transition-all duration-200 {tabClass(tab === 'status')}">
|
||||
My feedback
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div
|
||||
class="feedback-panel"
|
||||
style:height={panelHeightPx === null ? "auto" : `${panelHeightPx}px`}
|
||||
style:transition={panelHeightMotion}
|
||||
>
|
||||
<div class="feedback-panel__body" use:panelMeasure>
|
||||
{#if panelKey === "send-success" && successId}
|
||||
<h2 id="feedback-modal-title" class="mb-3 text-xl font-bold">Thanks for the feedback</h2>
|
||||
<p class="mb-2 text-zinc-600 dark:text-zinc-300">Reference ID:</p>
|
||||
<p class="mb-4 px-3 py-2 font-mono text-base rounded-lg {isDark ? 'bg-zinc-900' : 'bg-zinc-100'} break-all">{successId}</p>
|
||||
<div class="flex gap-3 justify-end">
|
||||
<button type="button" class={btnMuted} onclick={() => successId && openStatusItem(successId)}>Check status</button>
|
||||
<button type="button" class={btnPrimary} onclick={onClose}>Done</button>
|
||||
</div>
|
||||
{:else if panelKey === "send-form"}
|
||||
<h2 id="feedback-modal-title" class="mb-1 text-xl font-bold">Send feedback</h2>
|
||||
<p class="mb-4 text-zinc-600 dark:text-zinc-400">Anonymous by default. Contact and school details are optional.</p>
|
||||
|
||||
<div class="flex flex-col gap-4">
|
||||
<label class="flex flex-col gap-1.5 font-medium">
|
||||
Category
|
||||
<select id="feedback-category" bind:value={category} class={field} style={fieldStyle}>
|
||||
{#each FEEDBACK_CATEGORIES as value (value)}
|
||||
<option {value} style={fieldStyle}>{categoryLabel(value)}</option>
|
||||
{/each}
|
||||
</select>
|
||||
</label>
|
||||
|
||||
<label class="flex flex-col gap-1.5 font-medium">
|
||||
Subject <span class="font-normal text-zinc-500">(optional)</span>
|
||||
<input type="text" maxlength={120} bind:value={subject} placeholder="Short summary" class={field} style={fieldStyle} />
|
||||
</label>
|
||||
|
||||
<label class="flex flex-col gap-1.5 font-medium">
|
||||
Message
|
||||
<textarea rows={5} maxlength={FEEDBACK_MESSAGE_MAX} bind:value={message} placeholder="What happened, or what would you like to see?" class="{field} resize-y min-h-[120px]" style={fieldStyle}></textarea>
|
||||
<span class="text-base font-normal text-zinc-500">{message.trim().length}/{FEEDBACK_MESSAGE_MAX} (min {FEEDBACK_MESSAGE_MIN})</span>
|
||||
</label>
|
||||
|
||||
<div class="flex justify-between items-center gap-3">
|
||||
<div>
|
||||
<p class="font-medium">Include contact details</p>
|
||||
<p class="text-base text-zinc-500">Name and email so we can reply</p>
|
||||
</div>
|
||||
<Switch state={includeContact} onChange={(v) => (includeContact = v)} />
|
||||
</div>
|
||||
{#if includeContact}
|
||||
<input type="text" maxlength={80} bind:value={contactName} placeholder="Name" class={field} style={fieldStyle} />
|
||||
<input type="email" maxlength={254} bind:value={contactEmail} placeholder="Email" class={field} style={fieldStyle} />
|
||||
{/if}
|
||||
|
||||
<div class="flex justify-between items-center gap-3">
|
||||
<div>
|
||||
<p class="font-medium">Include SEQTA instance</p>
|
||||
<p class="text-base text-zinc-500">
|
||||
{#if instanceHostname}
|
||||
Hostname only: <span class="font-mono">{instanceHostname}</span>
|
||||
{:else}
|
||||
Open SEQTA first to detect hostname
|
||||
{/if}
|
||||
</p>
|
||||
</div>
|
||||
<Switch
|
||||
state={includeInstance && !!instanceHostname}
|
||||
onChange={(v) => {
|
||||
if (instanceHostname) includeInstance = v;
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
|
||||
{#if errorMessage}
|
||||
<p class="text-red-600 dark:text-red-400" role="alert">{errorMessage}</p>
|
||||
{/if}
|
||||
|
||||
<p class="text-base text-zinc-500">
|
||||
Sent to betterseqta.org.
|
||||
<a href="https://betterseqta.org/privacy" target="_blank" rel="noopener noreferrer" class="underline">Privacy</a>
|
||||
</p>
|
||||
|
||||
<div class="flex gap-3 justify-end">
|
||||
<button type="button" class={btnMuted} onclick={onClose} disabled={submitting}>Cancel</button>
|
||||
<button type="button" class={btnPrimary} onclick={handleSubmit} disabled={submitting}>
|
||||
{submitting ? "Sending…" : "Send feedback"}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
{:else if isStatusDetailKey(panelKey) && selectedItem}
|
||||
<div class="flex items-start justify-between gap-3 mb-3">
|
||||
<h2 id="feedback-modal-title" class="text-xl font-bold">Feedback status</h2>
|
||||
<button type="button" class="{btnMuted} !text-base !px-3 !py-1.5" onclick={() => { selectedItem = null; void loadStatusList(); }}>Back</button>
|
||||
</div>
|
||||
<p class="mb-1 font-medium">{selectedItem.subject || "Untitled"} · {formatStatus(selectedItem.status)}</p>
|
||||
<p class="mb-4 font-mono text-base text-zinc-500 break-all">{selectedItem.id}</p>
|
||||
{#if hasReply(selectedItem)}
|
||||
<div class="p-3 mb-4 rounded-lg border {isDark ? 'border-zinc-700 bg-zinc-900/50' : 'border-zinc-200 bg-zinc-50'}">
|
||||
<p class="mb-1 text-base font-semibold uppercase tracking-wide text-zinc-500">Response</p>
|
||||
<p class="whitespace-pre-wrap">{selectedItem.response}</p>
|
||||
</div>
|
||||
{:else}
|
||||
<p class="mb-4 text-zinc-500">No response yet.</p>
|
||||
{/if}
|
||||
{#if statusError}<p class="mb-3 text-red-600 dark:text-red-400" role="alert">{statusError}</p>{/if}
|
||||
<div class="flex gap-3 justify-end">
|
||||
<button type="button" class={btnMuted} onclick={() => openStatusItem(selectedItem!.id)} disabled={statusLoading}>
|
||||
{statusLoading ? "Refreshing…" : "Refresh"}
|
||||
</button>
|
||||
<button type="button" class={btnPrimary} onclick={onClose}>Close</button>
|
||||
</div>
|
||||
{:else}
|
||||
<div class="flex items-start justify-between gap-3 mb-3">
|
||||
<h2 id="feedback-modal-title" class="text-xl font-bold">My feedback</h2>
|
||||
<button type="button" class="{btnMuted} !text-base !px-3 !py-1.5" onclick={() => void loadStatusList()} disabled={statusLoading}>
|
||||
{statusLoading ? "…" : "Refresh"}
|
||||
</button>
|
||||
</div>
|
||||
{#if statusError}<p class="mb-3 text-red-600 dark:text-red-400" role="alert">{statusError}</p>{/if}
|
||||
{#if statusLoading && !statusItems.length}
|
||||
<div class="feedback-loading" aria-busy="true" aria-live="polite">
|
||||
<Spinner size="md" />
|
||||
<p class="text-zinc-500">Checking your feedback…</p>
|
||||
<div class="feedback-loading__skeleton" aria-hidden="true">
|
||||
<span></span>
|
||||
<span></span>
|
||||
<span></span>
|
||||
</div>
|
||||
</div>
|
||||
{:else if !statusItems.length}
|
||||
<p class="mb-4 text-zinc-500">No feedback yet.</p>
|
||||
<button type="button" class={btnPrimary} onclick={() => selectTab("send")}>Send feedback</button>
|
||||
{:else}
|
||||
<ul class="flex flex-col gap-2 mb-4">
|
||||
{#each statusItems as item (item.id)}
|
||||
<li>
|
||||
<button
|
||||
type="button"
|
||||
onclick={() => openStatusItem(item.id)}
|
||||
class="w-full p-3 text-left rounded-lg border transition-all duration-200 hover:scale-[1.01] focus:outline-none focus:ring-2 focus:ring-zinc-400 {isDark
|
||||
? 'border-zinc-700 bg-zinc-900/40'
|
||||
: 'border-zinc-200 bg-white'}"
|
||||
>
|
||||
<p class="text-base text-zinc-500 mb-0.5">
|
||||
{formatStatus(item.status)}{#if hasReply(item)} · Reply{/if} · {categoryLabel(item.category)}
|
||||
</p>
|
||||
<p class="font-medium truncate">{item.subject || "Untitled"}</p>
|
||||
</button>
|
||||
</li>
|
||||
{/each}
|
||||
</ul>
|
||||
{/if}
|
||||
<div class="flex justify-end">
|
||||
<button type="button" class={btnMuted} onclick={onClose}>Close</button>
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<style>
|
||||
.feedback-dialog {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.feedback-panel {
|
||||
position: relative;
|
||||
overflow: hidden;
|
||||
min-height: 0;
|
||||
}
|
||||
|
||||
.feedback-panel__body {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.feedback-loading {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 0.75rem;
|
||||
min-height: 14rem;
|
||||
padding: 1rem 0 1.5rem;
|
||||
}
|
||||
|
||||
.feedback-loading__skeleton {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.5rem;
|
||||
width: 100%;
|
||||
margin-top: 0.5rem;
|
||||
}
|
||||
|
||||
.feedback-loading__skeleton span {
|
||||
display: block;
|
||||
height: 3.5rem;
|
||||
border-radius: 0.5rem;
|
||||
background: color-mix(in srgb, currentColor 8%, transparent);
|
||||
animation: feedback-skeleton-pulse 1.2s ease-in-out infinite;
|
||||
}
|
||||
|
||||
.feedback-loading__skeleton span:nth-child(2) {
|
||||
animation-delay: 0.15s;
|
||||
}
|
||||
|
||||
.feedback-loading__skeleton span:nth-child(3) {
|
||||
animation-delay: 0.3s;
|
||||
}
|
||||
|
||||
@keyframes feedback-skeleton-pulse {
|
||||
0%,
|
||||
100% {
|
||||
opacity: 0.45;
|
||||
}
|
||||
50% {
|
||||
opacity: 0.9;
|
||||
}
|
||||
}
|
||||
|
||||
:global(.feedback-field),
|
||||
:global(.feedback-field option) {
|
||||
-webkit-text-fill-color: currentColor !important;
|
||||
caret-color: currentColor !important;
|
||||
}
|
||||
:global(.feedback-field::placeholder) {
|
||||
-webkit-text-fill-color: #a1a1aa !important;
|
||||
color: #a1a1aa !important;
|
||||
opacity: 1;
|
||||
}
|
||||
</style>
|
||||
@@ -129,7 +129,12 @@
|
||||
data-font-id={preset.id}
|
||||
>
|
||||
<div class="bsplus-font-picker-option-head">
|
||||
<span class="bsplus-font-picker-option-name">{preset.name}</span>
|
||||
<span
|
||||
class="bsplus-font-picker-option-name"
|
||||
style="font-family: {preset.stack} !important;"
|
||||
>
|
||||
{preset.name}
|
||||
</span>
|
||||
{#if selectedId === preset.id}
|
||||
<span class="bsplus-font-picker-badge">Selected</span>
|
||||
{/if}
|
||||
|
||||
@@ -78,7 +78,7 @@
|
||||
|
||||
const startRecording = () => {
|
||||
isRecording = true;
|
||||
recordedKeys.clear();
|
||||
recordedKeys = new Set();
|
||||
inputElement?.focus();
|
||||
};
|
||||
|
||||
@@ -87,7 +87,7 @@
|
||||
if (recordedKeys.has('esc')) {
|
||||
onChange('');
|
||||
isRecording = false;
|
||||
recordedKeys.clear();
|
||||
recordedKeys = new Set();
|
||||
inputElement?.blur();
|
||||
return;
|
||||
}
|
||||
@@ -113,10 +113,16 @@
|
||||
}
|
||||
|
||||
isRecording = false;
|
||||
recordedKeys.clear();
|
||||
recordedKeys = new Set();
|
||||
inputElement?.blur();
|
||||
};
|
||||
|
||||
const addRecordedKey = (key: string) => {
|
||||
const next = new Set(recordedKeys);
|
||||
next.add(key);
|
||||
recordedKeys = next;
|
||||
};
|
||||
|
||||
const handleKeyDown = (e: KeyboardEvent) => {
|
||||
if (!isRecording) return;
|
||||
|
||||
@@ -126,14 +132,14 @@
|
||||
const key = formatKeyForHotkey(e.key);
|
||||
|
||||
// Add modifiers
|
||||
if (e.ctrlKey) recordedKeys.add('ctrl');
|
||||
if (e.metaKey) recordedKeys.add('cmd');
|
||||
if (e.altKey) recordedKeys.add('alt');
|
||||
if (e.shiftKey) recordedKeys.add('shift');
|
||||
if (e.ctrlKey) addRecordedKey('ctrl');
|
||||
if (e.metaKey) addRecordedKey('cmd');
|
||||
if (e.altKey) addRecordedKey('alt');
|
||||
if (e.shiftKey) addRecordedKey('shift');
|
||||
|
||||
// Add the main key (ignore modifier keys themselves)
|
||||
if (!['ctrl', 'cmd', 'alt', 'shift'].includes(key)) {
|
||||
recordedKeys.add(key);
|
||||
addRecordedKey(key);
|
||||
}
|
||||
|
||||
// Auto-stop recording if we have a main key
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
<script lang="ts">
|
||||
let { onclick, label = "Close" } = $props<{
|
||||
onclick: () => void;
|
||||
label?: string;
|
||||
}>();
|
||||
</script>
|
||||
|
||||
<button
|
||||
type="button"
|
||||
{onclick}
|
||||
class="flex h-10 w-10 shrink-0 items-center justify-center text-zinc-500 transition-[color,transform] duration-150 hover:text-zinc-950 active:scale-[0.96] focus:outline-none dark:text-zinc-400 dark:hover:text-white"
|
||||
aria-label={label}
|
||||
>
|
||||
<svg
|
||||
class="h-6 w-6"
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
stroke-width="2"
|
||||
stroke-linecap="round"
|
||||
aria-hidden="true"
|
||||
>
|
||||
<path d="M6 6l12 12M18 6 6 18" />
|
||||
</svg>
|
||||
</button>
|
||||
@@ -1,82 +1,203 @@
|
||||
<script lang="ts">
|
||||
let { state, onChange, options } = $props<{
|
||||
state: string,
|
||||
onChange: (newState: string) => void,
|
||||
let { value, onChange, options } = $props<{
|
||||
value: string,
|
||||
onChange: (newValue: string) => void,
|
||||
options: Array<{ value: string, label: string }>
|
||||
}>();
|
||||
|
||||
let select: HTMLSelectElement;
|
||||
const listboxId = `select-listbox-${Math.random().toString(36).slice(2, 9)}`;
|
||||
|
||||
let isOpen = $state(false);
|
||||
let activeIndex = $state(0);
|
||||
let trigger = $state<HTMLButtonElement>();
|
||||
|
||||
function openMenu(preferredIndex?: number) {
|
||||
isOpen = true;
|
||||
const selectedIndex = options.findIndex((option) => option.value === value);
|
||||
activeIndex = preferredIndex ?? (selectedIndex >= 0 ? selectedIndex : 0);
|
||||
}
|
||||
|
||||
function closeMenu(returnFocus = true) {
|
||||
isOpen = false;
|
||||
if (returnFocus) trigger?.focus();
|
||||
}
|
||||
|
||||
function selectValue(nextValue: string) {
|
||||
onChange(nextValue);
|
||||
closeMenu();
|
||||
}
|
||||
|
||||
function onKeydown(event: KeyboardEvent, inListbox = false) {
|
||||
const { key } = event;
|
||||
|
||||
if (key === "ArrowDown" || key === "ArrowUp") {
|
||||
event.preventDefault();
|
||||
const count = options.length;
|
||||
if (!count) return;
|
||||
if (isOpen || inListbox) {
|
||||
activeIndex = (activeIndex + (key === "ArrowDown" ? 1 : -1) + count) % count;
|
||||
} else {
|
||||
openMenu();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (key === "Enter" || key === " ") {
|
||||
event.preventDefault();
|
||||
if (isOpen) {
|
||||
const option = options[activeIndex];
|
||||
if (option) selectValue(option.value);
|
||||
} else {
|
||||
openMenu();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (key === "Escape" && isOpen) {
|
||||
event.preventDefault();
|
||||
closeMenu();
|
||||
return;
|
||||
}
|
||||
|
||||
if (!inListbox) return;
|
||||
|
||||
if (key === "Home") {
|
||||
event.preventDefault();
|
||||
activeIndex = 0;
|
||||
} else if (key === "End") {
|
||||
event.preventDefault();
|
||||
activeIndex = Math.max(0, options.length - 1);
|
||||
} else if (key === "Tab") {
|
||||
closeMenu(false);
|
||||
}
|
||||
}
|
||||
|
||||
$effect(() => {
|
||||
if (!isOpen) return;
|
||||
|
||||
queueMicrotask(() => document.getElementById(listboxId)?.focus());
|
||||
|
||||
const wrapper = trigger?.parentElement;
|
||||
const onPointerDown = (event: PointerEvent) => {
|
||||
if (wrapper && event.composedPath().includes(wrapper)) return;
|
||||
closeMenu(false);
|
||||
};
|
||||
|
||||
document.addEventListener("pointerdown", onPointerDown, true);
|
||||
return () => document.removeEventListener("pointerdown", onPointerDown, true);
|
||||
});
|
||||
</script>
|
||||
|
||||
<div class="select-wrapper relative w-full overflow-hidden rounded-2xl border shadow-2xl">
|
||||
<select
|
||||
bind:this={select}
|
||||
value={state}
|
||||
onchange={() => onChange(select.value)}
|
||||
class="select-input w-full appearance-none border-none bg-transparent px-4 py-2.5 pr-10 text-[0.875rem] font-medium transition-colors"
|
||||
<div class="select relative w-full">
|
||||
<button
|
||||
bind:this={trigger}
|
||||
type="button"
|
||||
class="select-trigger flex w-full items-center justify-between gap-3 rounded-[18px] border px-4 py-2.5 text-sm font-medium leading-tight shadow-2xl transition-[background-color,border-color,box-shadow] duration-200 cursor-pointer"
|
||||
aria-haspopup="listbox"
|
||||
aria-expanded={isOpen}
|
||||
aria-controls={listboxId}
|
||||
onclick={() => (isOpen ? closeMenu() : openMenu())}
|
||||
onkeydown={onKeydown}
|
||||
>
|
||||
{#each options as option}
|
||||
<option value={option.value}>
|
||||
{option.label}
|
||||
</option>
|
||||
{/each}
|
||||
</select>
|
||||
<span class="select-icon pointer-events-none absolute inset-y-0 right-0 flex items-center pr-3" aria-hidden="true">
|
||||
<svg viewBox="0 0 20 20" fill="currentColor" class="h-4 w-4">
|
||||
<path fill-rule="evenodd" d="M5.23 7.21a.75.75 0 0 1 1.06.02L10 11.168l3.71-3.938a.75.75 0 1 1 1.08 1.04l-4.25 4.5a.75.75 0 0 1-1.08 0l-4.25-4.5a.75.75 0 0 1 .02-1.06Z" clip-rule="evenodd"></path>
|
||||
</svg>
|
||||
</span>
|
||||
<span class="truncate">
|
||||
{options.find((option) => option.value === value)?.label ?? value}
|
||||
</span>
|
||||
<span class="select-icon shrink-0" aria-hidden="true">
|
||||
<svg viewBox="0 0 20 20" fill="currentColor" class="h-4 w-4">
|
||||
<path
|
||||
fill-rule="evenodd"
|
||||
d="M5.23 7.21a.75.75 0 0 1 1.06.02L10 11.168l3.71-3.938a.75.75 0 1 1 1.08 1.04l-4.25 4.5a.75.75 0 0 1-1.08 0l-4.25-4.5a.75.75 0 0 1 .02-1.06Z"
|
||||
clip-rule="evenodd"
|
||||
/>
|
||||
</svg>
|
||||
</span>
|
||||
</button>
|
||||
|
||||
{#if isOpen}
|
||||
<div
|
||||
id={listboxId}
|
||||
class="select-menu absolute inset-x-0 top-[calc(100%+0.35rem)] z-50 flex max-h-72 flex-col gap-0.5 p-2"
|
||||
role="listbox"
|
||||
tabindex="-1"
|
||||
aria-activedescendant={options[activeIndex] ? `${listboxId}-opt-${activeIndex}` : undefined}
|
||||
onkeydown={(event) => onKeydown(event, true)}
|
||||
>
|
||||
{#each options as option, index (option.value)}
|
||||
<button
|
||||
type="button"
|
||||
id={`${listboxId}-opt-${index}`}
|
||||
role="option"
|
||||
aria-selected={option.value === value}
|
||||
class="select-option block w-full rounded-[10px] border-none px-3.5 py-2.5 text-left text-sm font-medium leading-snug transition-colors duration-150 cursor-pointer"
|
||||
class:is-selected={option.value === value}
|
||||
class:is-active={index === activeIndex}
|
||||
tabindex="-1"
|
||||
onclick={() => selectValue(option.value)}
|
||||
onmouseenter={() => (activeIndex = index)}
|
||||
>
|
||||
{option.label}
|
||||
</button>
|
||||
{/each}
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
<style>
|
||||
.select-wrapper {
|
||||
background: color-mix(in srgb, var(--background-primary) 88%, transparent);
|
||||
border-color: color-mix(in srgb, var(--theme-offset-bg, var(--background-secondary)) 72%, transparent);
|
||||
border-radius: 18px;
|
||||
.select {
|
||||
--sel-border: var(--theme-offset-bg, var(--theme-secondary, #e5e7eb));
|
||||
--sel-bg: var(--theme-primary, #ffffff);
|
||||
--sel-surface: var(--theme-secondary, #e5e7eb);
|
||||
--sel-focus-border: color-mix(in srgb, var(--text-primary) 22%, var(--theme-secondary, #e5e7eb) 78%);
|
||||
--sel-ring: 0 0 0 1px color-mix(in srgb, var(--text-primary) 12%, transparent);
|
||||
--sel-menu-shadow:
|
||||
0 10px 25px -5px rgb(0 0 0 / 0.25),
|
||||
0 8px 10px -6px rgb(0 0 0 / 0.2);
|
||||
}
|
||||
|
||||
.select-trigger {
|
||||
border-color: var(--sel-border);
|
||||
background: var(--sel-bg);
|
||||
color: var(--text-primary);
|
||||
transition:
|
||||
background-color 180ms ease,
|
||||
border-color 180ms ease,
|
||||
box-shadow 180ms ease,
|
||||
transform 180ms ease;
|
||||
}
|
||||
|
||||
.select-wrapper:hover {
|
||||
background: color-mix(in srgb, var(--background-primary) 94%, var(--background-secondary) 6%);
|
||||
border-color: color-mix(in srgb, var(--theme-offset-bg, var(--background-secondary)) 88%, transparent);
|
||||
}
|
||||
|
||||
.select-wrapper:focus-within {
|
||||
background: color-mix(in srgb, var(--background-primary) 96%, var(--background-secondary) 4%);
|
||||
border-color: color-mix(in srgb, var(--text-primary) 22%, var(--theme-offset-bg, var(--background-secondary)) 78%);
|
||||
box-shadow: 0 0 0 1px color-mix(in srgb, var(--text-primary) 12%, transparent);
|
||||
}
|
||||
|
||||
.select-input {
|
||||
color: var(--text-primary);
|
||||
.select-trigger:hover,
|
||||
.select-trigger:focus-visible {
|
||||
outline: none;
|
||||
text-overflow: ellipsis;
|
||||
background: var(--sel-surface);
|
||||
border-color: var(--sel-border);
|
||||
}
|
||||
|
||||
.select-input:hover,
|
||||
.select-input:focus {
|
||||
background: transparent;
|
||||
}
|
||||
|
||||
.select-input option {
|
||||
background: var(--background-primary);
|
||||
color: var(--text-primary);
|
||||
.select-trigger:focus-visible {
|
||||
border-color: var(--sel-focus-border);
|
||||
box-shadow: var(--sel-ring);
|
||||
}
|
||||
|
||||
.select-icon {
|
||||
color: color-mix(in srgb, var(--text-primary) 60%, transparent);
|
||||
}
|
||||
|
||||
.select-input {
|
||||
color-scheme: light;
|
||||
.select-menu {
|
||||
border: 1px solid var(--sel-border);
|
||||
border-radius: 14px;
|
||||
background: var(--sel-bg);
|
||||
box-shadow: var(--sel-menu-shadow);
|
||||
}
|
||||
|
||||
:global(.dark) .select-input {
|
||||
color-scheme: dark;
|
||||
.select-menu:focus-visible {
|
||||
outline: none;
|
||||
box-shadow: var(--sel-menu-shadow), var(--sel-ring);
|
||||
}
|
||||
|
||||
.select-option {
|
||||
background: transparent;
|
||||
color: var(--text-primary);
|
||||
}
|
||||
|
||||
.select-option:hover,
|
||||
.select-option:focus-visible,
|
||||
.select-option.is-active,
|
||||
.select-option.is-selected {
|
||||
outline: none;
|
||||
background: var(--sel-surface);
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,588 @@
|
||||
<script lang="ts">
|
||||
import Select from "@/interface/components/Select.svelte";
|
||||
import Slider from "@/interface/components/Slider.svelte";
|
||||
import Switch from "@/interface/components/Switch.svelte";
|
||||
import { settingsState } from "@/seqta/utils/listeners/SettingsState";
|
||||
import {
|
||||
DEFAULT_SIDEBAR_BLUR,
|
||||
DEFAULT_SIDEBAR_RADIUS,
|
||||
getSidebarStyle,
|
||||
normalizeSidebarBlur,
|
||||
normalizeSidebarDensity,
|
||||
normalizeSidebarIndicator,
|
||||
normalizeSidebarRadius,
|
||||
normalizeSidebarStyleId,
|
||||
normalizeSidebarWidth,
|
||||
SIDEBAR_STYLES,
|
||||
type SidebarStyleId,
|
||||
} from "@/seqta/ui/sidebar/sidebarStyles";
|
||||
|
||||
const PREVIEW_ITEMS = [
|
||||
{ label: "Home", active: true },
|
||||
{ label: "Timetable", active: false },
|
||||
{ label: "Assessments", active: false },
|
||||
{ label: "Messages", active: false },
|
||||
{ label: "Documents", active: false },
|
||||
] as const;
|
||||
|
||||
const selectedId = $derived(
|
||||
normalizeSidebarStyleId($settingsState.sidebarStyle),
|
||||
);
|
||||
const selected = $derived(getSidebarStyle(selectedId));
|
||||
const density = $derived(
|
||||
normalizeSidebarDensity($settingsState.sidebarDensity),
|
||||
);
|
||||
const indicator = $derived(
|
||||
normalizeSidebarIndicator($settingsState.sidebarActiveIndicator),
|
||||
);
|
||||
const width = $derived(normalizeSidebarWidth($settingsState.sidebarWidth));
|
||||
const radius = $derived(
|
||||
normalizeSidebarRadius(
|
||||
$settingsState.sidebarCornerRadius ?? DEFAULT_SIDEBAR_RADIUS,
|
||||
),
|
||||
);
|
||||
const blur = $derived(
|
||||
normalizeSidebarBlur($settingsState.sidebarBlur ?? DEFAULT_SIDEBAR_BLUR),
|
||||
);
|
||||
const transparencyOn = $derived($settingsState.transparencyEffects === true);
|
||||
|
||||
function selectStyle(id: SidebarStyleId) {
|
||||
if (selectedId !== id) settingsState.sidebarStyle = id;
|
||||
}
|
||||
</script>
|
||||
|
||||
<div class="card">
|
||||
<header class="card-header split">
|
||||
<div>
|
||||
<h2 class="title">Sidebar Style</h2>
|
||||
<p class="subtitle">Choose how the navigation menu looks</p>
|
||||
</div>
|
||||
<div class="selected-meta" aria-live="polite">
|
||||
<span class="selected-label">{selected.label}</span>
|
||||
<span class="selected-desc">{selected.description}</span>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<div class="picker-body">
|
||||
<div class="preview-pane" aria-hidden="true">
|
||||
<div class={`preview style-${selectedId}`}>
|
||||
<div class="preview-chrome">
|
||||
<div class="preview-logo"></div>
|
||||
{#each PREVIEW_ITEMS as item (item.label)}
|
||||
<div class="preview-item" class:active={item.active}>
|
||||
<span class="preview-dot"></span>
|
||||
<span class="preview-label">{item.label}</span>
|
||||
</div>
|
||||
{/each}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div
|
||||
class="options"
|
||||
role="listbox"
|
||||
tabindex="0"
|
||||
aria-label="Sidebar styles"
|
||||
aria-activedescendant={`sidebar-style-${selectedId}`}
|
||||
>
|
||||
{#each SIDEBAR_STYLES as style (style.id)}
|
||||
{@const active = style.id === selectedId}
|
||||
<button
|
||||
type="button"
|
||||
id={`sidebar-style-${style.id}`}
|
||||
class="option"
|
||||
class:active
|
||||
role="option"
|
||||
aria-selected={active}
|
||||
onclick={() => selectStyle(style.id)}
|
||||
>
|
||||
<div class={`thumb style-${style.id}`}>
|
||||
<div class="thumb-chrome">
|
||||
{#each PREVIEW_ITEMS.slice(0, 3) as item (item.label)}
|
||||
<div class="thumb-item" class:active={item.active}></div>
|
||||
{/each}
|
||||
</div>
|
||||
</div>
|
||||
<span class="option-label">{style.label}</span>
|
||||
</button>
|
||||
{/each}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card">
|
||||
<header class="card-header">
|
||||
<h2 class="title">Sidebar Look</h2>
|
||||
<p class="subtitle">Density, size, and active-state details</p>
|
||||
</header>
|
||||
|
||||
<div class="rows">
|
||||
<div class="row">
|
||||
<div class="copy">
|
||||
<h3 class="row-title">Item Size</h3>
|
||||
<p class="row-desc">Spacing and type size for menu rows</p>
|
||||
</div>
|
||||
<div class="control">
|
||||
<Select
|
||||
value={density}
|
||||
onChange={(value) => (settingsState.sidebarDensity = value)}
|
||||
options={[
|
||||
{ value: "compact", label: "Compact" },
|
||||
{ value: "comfortable", label: "Comfortable" },
|
||||
{ value: "large", label: "Large" },
|
||||
]}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="copy">
|
||||
<h3 class="row-title">Corner Radius</h3>
|
||||
<p class="row-desc">Roundness of menu items ({radius}px)</p>
|
||||
</div>
|
||||
<div class="control slider">
|
||||
<Slider
|
||||
state={radius}
|
||||
min={0}
|
||||
max={24}
|
||||
step={1}
|
||||
onChange={(value) => (settingsState.sidebarCornerRadius = value)}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="copy">
|
||||
<h3 class="row-title">Active Indicator</h3>
|
||||
<p class="row-desc">How the current page is highlighted</p>
|
||||
</div>
|
||||
<div class="control">
|
||||
<Select
|
||||
value={indicator}
|
||||
onChange={(value) => (settingsState.sidebarActiveIndicator = value)}
|
||||
options={[
|
||||
{ value: "fill", label: "Fill" },
|
||||
{ value: "bar", label: "Left bar" },
|
||||
{ value: "outline", label: "Outline" },
|
||||
{ value: "underline", label: "Underline" },
|
||||
]}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="copy">
|
||||
<h3 class="row-title">Sidebar Width</h3>
|
||||
<p class="row-desc">Overall navigation column width</p>
|
||||
</div>
|
||||
<div class="control">
|
||||
<Select
|
||||
value={width}
|
||||
onChange={(value) => (settingsState.sidebarWidth = value)}
|
||||
options={[
|
||||
{ value: "narrow", label: "Narrow" },
|
||||
{ value: "default", label: "Default" },
|
||||
{ value: "wide", label: "Wide" },
|
||||
]}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="copy">
|
||||
<h3 class="row-title">Transparency Effects</h3>
|
||||
<p class="row-desc">Use glass effects on supported surfaces (may impact battery life)</p>
|
||||
</div>
|
||||
<div class="control toggle">
|
||||
<Switch
|
||||
state={transparencyOn}
|
||||
onChange={(value) => (settingsState.transparencyEffects = value)}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{#if transparencyOn}
|
||||
<div class="row">
|
||||
<div class="copy">
|
||||
<h3 class="row-title">Blur Strength</h3>
|
||||
<p class="row-desc">Glass blur on the sidebar ({blur}px)</p>
|
||||
</div>
|
||||
<div class="control slider">
|
||||
<Slider
|
||||
state={blur}
|
||||
min={0}
|
||||
max={80}
|
||||
step={1}
|
||||
onChange={(value) => (settingsState.sidebarBlur = value)}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<style>
|
||||
.card {
|
||||
margin: 4px 0;
|
||||
padding: 4px;
|
||||
border-radius: 0.75rem;
|
||||
border: 1px solid rgb(228 228 231 / 0.5);
|
||||
background: linear-gradient(to bottom right, white, rgb(244 244 245));
|
||||
box-shadow: 0 1px 2px rgb(0 0 0 / 0.05);
|
||||
}
|
||||
|
||||
:global(.dark) .card {
|
||||
border-color: rgb(63 63 70 / 0.4);
|
||||
background: linear-gradient(
|
||||
to bottom right,
|
||||
rgb(24 24 27 / 0.4),
|
||||
rgb(24 24 27 / 0.5)
|
||||
);
|
||||
}
|
||||
|
||||
.card-header {
|
||||
padding: 1rem 1.25rem 0.5rem;
|
||||
}
|
||||
|
||||
.card-header.split {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
gap: 1rem;
|
||||
align-items: flex-start;
|
||||
}
|
||||
|
||||
.title {
|
||||
font-size: 1.25rem;
|
||||
font-weight: 700;
|
||||
line-height: 1.3;
|
||||
}
|
||||
|
||||
.subtitle {
|
||||
margin-top: 0.15rem;
|
||||
font-size: 1rem;
|
||||
color: rgb(82 82 91);
|
||||
}
|
||||
|
||||
:global(.dark) .subtitle {
|
||||
color: rgb(212 212 216);
|
||||
}
|
||||
|
||||
.selected-meta {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: flex-end;
|
||||
text-align: right;
|
||||
max-width: 14rem;
|
||||
gap: 0.15rem;
|
||||
}
|
||||
|
||||
.selected-label {
|
||||
font-size: 0.95rem;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.selected-desc {
|
||||
font-size: 0.8rem;
|
||||
line-height: 1.35;
|
||||
color: rgb(113 113 122);
|
||||
}
|
||||
|
||||
:global(.dark) .selected-desc {
|
||||
color: rgb(161 161 170);
|
||||
}
|
||||
|
||||
.picker-body {
|
||||
display: grid;
|
||||
grid-template-columns: minmax(160px, 210px) 1fr;
|
||||
gap: 1rem;
|
||||
padding: 0.5rem 1rem 1rem;
|
||||
}
|
||||
|
||||
@media (max-width: 720px) {
|
||||
.picker-body {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
}
|
||||
|
||||
.preview-pane {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.preview {
|
||||
width: 100%;
|
||||
max-width: 196px;
|
||||
height: 280px;
|
||||
border-radius: 18px;
|
||||
overflow: hidden;
|
||||
box-shadow: 0 14px 32px rgb(0 0 0 / 0.22);
|
||||
background: linear-gradient(160deg, #aa053a, #141414 70%);
|
||||
}
|
||||
|
||||
.preview-chrome {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
height: 100%;
|
||||
padding: 14px 0 10px;
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.preview-logo {
|
||||
width: 42%;
|
||||
height: 10px;
|
||||
margin: 0 16px 14px;
|
||||
border-radius: 999px;
|
||||
background: rgb(255 255 255 / 0.35);
|
||||
}
|
||||
|
||||
.preview-item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
margin: 0 8px 6px;
|
||||
padding: 8px 10px;
|
||||
border-radius: 12px;
|
||||
}
|
||||
|
||||
.preview-item.active {
|
||||
background: rgba(0, 0, 0, 0.35);
|
||||
}
|
||||
|
||||
.preview.style-soft .preview-item {
|
||||
margin: 0 10px 8px;
|
||||
border-radius: 16px;
|
||||
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.18);
|
||||
}
|
||||
|
||||
.preview.style-pill .preview-item {
|
||||
margin: 0 12px 7px;
|
||||
border-radius: 999px;
|
||||
}
|
||||
|
||||
.preview.style-glass .preview-item {
|
||||
margin: 0 10px 7px;
|
||||
background: rgba(255, 255, 255, 0.12);
|
||||
box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.16);
|
||||
}
|
||||
|
||||
.preview.style-glass .preview-item.active {
|
||||
background: rgba(255, 255, 255, 0.22);
|
||||
}
|
||||
|
||||
.preview.style-sharp .preview-item {
|
||||
margin: 0 6px 4px;
|
||||
border-radius: 4px;
|
||||
}
|
||||
|
||||
.preview.style-strip .preview-item {
|
||||
margin: 0;
|
||||
border-radius: 0;
|
||||
background: transparent;
|
||||
}
|
||||
|
||||
.preview.style-strip .preview-item.active {
|
||||
position: relative;
|
||||
background: rgba(255, 255, 255, 0.12);
|
||||
}
|
||||
|
||||
.preview.style-strip .preview-item.active::after {
|
||||
content: "";
|
||||
position: absolute;
|
||||
left: 0;
|
||||
top: 6px;
|
||||
bottom: 6px;
|
||||
width: 3px;
|
||||
border-radius: 2px;
|
||||
background: #fff;
|
||||
box-shadow: 0 0 8px rgba(255, 255, 255, 0.55);
|
||||
}
|
||||
|
||||
.preview.style-neon .preview-item.active {
|
||||
background: rgba(255, 255, 255, 0.1);
|
||||
box-shadow:
|
||||
0 0 0 1px rgba(255, 255, 255, 0.55),
|
||||
0 0 12px rgba(255, 255, 255, 0.4),
|
||||
0 0 22px rgba(255, 255, 255, 0.22);
|
||||
}
|
||||
|
||||
.preview-dot {
|
||||
width: 10px;
|
||||
height: 10px;
|
||||
border-radius: 999px;
|
||||
background: rgb(255 255 255 / 0.75);
|
||||
flex: 0 0 auto;
|
||||
}
|
||||
|
||||
.preview-label {
|
||||
font-size: 11px;
|
||||
font-weight: 600;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.options {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
|
||||
gap: 0.65rem;
|
||||
align-content: start;
|
||||
}
|
||||
|
||||
.option {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
gap: 0.4rem;
|
||||
padding: 0.45rem;
|
||||
border: 1px solid transparent;
|
||||
border-radius: 0.75rem;
|
||||
background: rgb(255 255 255 / 0.55);
|
||||
color: inherit;
|
||||
cursor: pointer;
|
||||
transition:
|
||||
transform 0.2s ease,
|
||||
border-color 0.2s ease,
|
||||
box-shadow 0.2s ease;
|
||||
}
|
||||
|
||||
:global(.dark) .option {
|
||||
background: rgb(39 39 42 / 0.55);
|
||||
}
|
||||
|
||||
.option:hover {
|
||||
transform: scale(1.02);
|
||||
}
|
||||
|
||||
.option:active {
|
||||
transform: scale(0.98);
|
||||
}
|
||||
|
||||
.option.active {
|
||||
border-color: var(--theme-primary, #f43f5e);
|
||||
box-shadow: 0 0 0 1px var(--theme-primary, #f43f5e);
|
||||
}
|
||||
|
||||
.option:focus-visible {
|
||||
outline: none;
|
||||
box-shadow: 0 0 0 2px var(--theme-primary, #f43f5e);
|
||||
}
|
||||
|
||||
.thumb {
|
||||
width: 100%;
|
||||
aspect-ratio: 3 / 4;
|
||||
border-radius: 10px;
|
||||
overflow: hidden;
|
||||
background: linear-gradient(160deg, #aa053a, #141414 70%);
|
||||
}
|
||||
|
||||
.thumb-chrome {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
gap: 4px;
|
||||
height: 100%;
|
||||
padding: 8px 6px;
|
||||
}
|
||||
|
||||
.thumb-item {
|
||||
height: 10px;
|
||||
border-radius: 6px;
|
||||
background: rgba(255, 255, 255, 0.18);
|
||||
}
|
||||
|
||||
.thumb-item.active {
|
||||
background: rgba(0, 0, 0, 0.4);
|
||||
}
|
||||
|
||||
.thumb.style-pill .thumb-item {
|
||||
border-radius: 999px;
|
||||
}
|
||||
|
||||
.thumb.style-sharp .thumb-item {
|
||||
border-radius: 2px;
|
||||
}
|
||||
|
||||
.thumb.style-strip .thumb-item {
|
||||
border-radius: 0;
|
||||
}
|
||||
|
||||
.thumb.style-strip .thumb-item.active {
|
||||
background: rgba(255, 255, 255, 0.22);
|
||||
box-shadow: inset 3px 0 0 #fff;
|
||||
}
|
||||
|
||||
.thumb.style-glass .thumb-item {
|
||||
background: rgba(255, 255, 255, 0.22);
|
||||
}
|
||||
|
||||
.thumb.style-neon .thumb-item.active {
|
||||
background: rgba(255, 255, 255, 0.2);
|
||||
box-shadow:
|
||||
0 0 0 1px rgba(255, 255, 255, 0.5),
|
||||
0 0 8px rgba(255, 255, 255, 0.55);
|
||||
}
|
||||
|
||||
.option-label {
|
||||
font-size: 0.8rem;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.rows {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
padding: 0.25rem 0.5rem 0.75rem;
|
||||
}
|
||||
|
||||
.row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 1rem;
|
||||
padding: 0.85rem 0.75rem;
|
||||
border-top: 1px solid rgb(244 244 245);
|
||||
}
|
||||
|
||||
:global(.dark) .row {
|
||||
border-top-color: rgb(63 63 70 / 0.5);
|
||||
}
|
||||
|
||||
.row:first-child {
|
||||
border-top: none;
|
||||
}
|
||||
|
||||
.copy {
|
||||
min-width: 0;
|
||||
flex: 1 1 auto;
|
||||
padding-right: 0.5rem;
|
||||
}
|
||||
|
||||
.row-title {
|
||||
font-size: 1.125rem;
|
||||
font-weight: 700;
|
||||
line-height: 1.3;
|
||||
}
|
||||
|
||||
.row-desc {
|
||||
margin-top: 0.1rem;
|
||||
font-size: 0.95rem;
|
||||
color: rgb(82 82 91);
|
||||
}
|
||||
|
||||
:global(.dark) .row-desc {
|
||||
color: rgb(212 212 216);
|
||||
}
|
||||
|
||||
.control {
|
||||
flex: 0 0 auto;
|
||||
min-width: 9.5rem;
|
||||
max-width: 12rem;
|
||||
}
|
||||
|
||||
.control.slider {
|
||||
min-width: 10rem;
|
||||
width: 11rem;
|
||||
}
|
||||
|
||||
.control.toggle {
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,87 @@
|
||||
<script lang="ts">
|
||||
import { settingsState } from "@/seqta/utils/listeners/SettingsState";
|
||||
import SidebarNavItem from "./SidebarNavItem.svelte";
|
||||
|
||||
type NavGroup = {
|
||||
label?: string;
|
||||
items: {
|
||||
id: string;
|
||||
label: string;
|
||||
divided?: boolean;
|
||||
nested?: boolean;
|
||||
expanded?: boolean;
|
||||
}[];
|
||||
};
|
||||
|
||||
let { groups, selectedId, onselect } = $props<{
|
||||
groups: NavGroup[];
|
||||
selectedId: string;
|
||||
onselect: (id: string) => void;
|
||||
}>();
|
||||
|
||||
let trackEl = $state<HTMLElement | null>(null);
|
||||
let indicatorX = $state(0);
|
||||
let indicatorY = $state(0);
|
||||
let indicatorW = $state(0);
|
||||
let indicatorH = $state(40);
|
||||
let indicatorReady = $state(false);
|
||||
|
||||
const updateIndicator = () => {
|
||||
if (!trackEl) return;
|
||||
const item = trackEl.querySelector<HTMLElement>(`[data-nav-section="${selectedId}"]`);
|
||||
if (!item) return;
|
||||
const trackRect = trackEl.getBoundingClientRect();
|
||||
const itemRect = item.getBoundingClientRect();
|
||||
indicatorX = itemRect.left - trackRect.left;
|
||||
indicatorY = itemRect.top - trackRect.top + trackEl.scrollTop;
|
||||
indicatorW = itemRect.width;
|
||||
indicatorH = itemRect.height;
|
||||
indicatorReady = true;
|
||||
};
|
||||
|
||||
$effect(() => {
|
||||
selectedId;
|
||||
groups;
|
||||
trackEl;
|
||||
queueMicrotask(updateIndicator);
|
||||
});
|
||||
</script>
|
||||
|
||||
<div
|
||||
class="relative flex min-h-0 flex-1 flex-col gap-5 overflow-y-auto no-scrollbar"
|
||||
bind:this={trackEl}
|
||||
>
|
||||
{#if indicatorReady}
|
||||
<div
|
||||
class="pointer-events-none absolute left-0 top-0 z-0 rounded-lg bg-zinc-200/90 dark:bg-zinc-700/90"
|
||||
style="transform: translate({indicatorX}px, {indicatorY}px); width: {indicatorW}px; height: {indicatorH}px; transition: {$settingsState.animations
|
||||
? 'transform 0.28s cubic-bezier(0.22, 1, 0.36, 1), width 0.28s cubic-bezier(0.22, 1, 0.36, 1), height 0.28s cubic-bezier(0.22, 1, 0.36, 1)'
|
||||
: 'none'};"
|
||||
></div>
|
||||
{/if}
|
||||
|
||||
{#each groups as group}
|
||||
<div class="relative flex flex-col gap-1">
|
||||
{#if group.label}
|
||||
<p
|
||||
class="relative z-10 mb-1.5 px-3 text-sm font-semibold uppercase tracking-wider text-zinc-400 dark:text-zinc-500"
|
||||
>
|
||||
{group.label}
|
||||
</p>
|
||||
{/if}
|
||||
{#each group.items as item (item.id)}
|
||||
{#if item.divided}
|
||||
<div class="my-2 border-t border-zinc-200 dark:border-zinc-700 {item.nested ? 'ml-4' : ''}"></div>
|
||||
{/if}
|
||||
<SidebarNavItem
|
||||
label={item.label}
|
||||
active={selectedId === item.id}
|
||||
nested={item.nested}
|
||||
emphasized={item.expanded}
|
||||
trackId={item.id}
|
||||
onclick={() => onselect(item.id)}
|
||||
/>
|
||||
{/each}
|
||||
</div>
|
||||
{/each}
|
||||
</div>
|
||||
@@ -0,0 +1,33 @@
|
||||
<script lang="ts">
|
||||
let {
|
||||
label,
|
||||
active = false,
|
||||
nested = false,
|
||||
emphasized = false,
|
||||
trackId,
|
||||
onclick,
|
||||
} = $props<{
|
||||
label: string;
|
||||
active?: boolean;
|
||||
nested?: boolean;
|
||||
emphasized?: boolean;
|
||||
trackId?: string;
|
||||
onclick: () => void;
|
||||
}>();
|
||||
</script>
|
||||
|
||||
<button
|
||||
type="button"
|
||||
data-nav-section={trackId}
|
||||
{onclick}
|
||||
class="relative z-10 rounded-lg text-left transition-[color,background-color] duration-200
|
||||
{nested
|
||||
? 'ml-4 w-[calc(100%-1rem)] px-3 py-2 text-base'
|
||||
: 'w-full px-3 py-2.5 text-lg'}
|
||||
{active || emphasized
|
||||
? 'font-medium text-zinc-900 dark:text-white'
|
||||
: 'text-zinc-600 hover:text-zinc-900 dark:text-zinc-300 dark:hover:text-white'}"
|
||||
aria-current={active ? "page" : undefined}
|
||||
>
|
||||
{label}
|
||||
</button>
|
||||
@@ -1,5 +1,5 @@
|
||||
<script lang="ts">
|
||||
let { state, onChange, min = 0, max = 100, step = 1 } = $props<{
|
||||
let { state = $bindable(), onChange, min = 0, max = 100, step = 1 } = $props<{
|
||||
state: number,
|
||||
onChange: (value: number) => void,
|
||||
min?: number,
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
.tab-width {
|
||||
width: var(--tab-width);
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
<script lang="ts">
|
||||
import MotionDiv from './MotionDiv.svelte';
|
||||
import './TabbedContainer.css';
|
||||
import { onMount } from 'svelte';
|
||||
|
||||
let { tabs, activeTab = $bindable(0) } = $props<{ tabs: { title: string, Content: any, props?: any }[]; activeTab?: number }>();
|
||||
@@ -38,8 +37,8 @@
|
||||
});
|
||||
</script>
|
||||
|
||||
<div class="flex flex-col h-full">
|
||||
<div class="top-0 z-10 text-[0.875rem] pb-0.5 mx-4 px-2 tab-width-container">
|
||||
<div class="flex flex-col h-full min-h-0">
|
||||
<div class="top-0 z-10 shrink-0 text-[0.875rem] pb-0.5 mx-4 px-2 tab-width-container" role="tablist">
|
||||
<div bind:this={containerRef} class="flex relative">
|
||||
<MotionDiv
|
||||
class="absolute top-0 left-0 z-0 h-full bg-gradient-to-tr dark:from-[#38373D]/80 dark:to-[#38373D] from-[#DDDDDD]/80 to-[#DDDDDD] rounded-full opacity-40 tab-width"
|
||||
@@ -48,6 +47,8 @@
|
||||
/>
|
||||
{#each tabs as { title }, index}
|
||||
<button
|
||||
role="tab"
|
||||
aria-selected={activeTab === index}
|
||||
class="relative z-10 flex-1 px-4 py-2 focus-visible:outline-none"
|
||||
onclick={() => activeTab = index}
|
||||
>
|
||||
@@ -56,21 +57,20 @@
|
||||
{/each}
|
||||
</div>
|
||||
</div>
|
||||
<div class="overflow-hidden px-4 h-full">
|
||||
<MotionDiv
|
||||
class="h-full"
|
||||
animate={{ x: `${-activeTab * 100}%` }}
|
||||
transition={springTransition}
|
||||
>
|
||||
<div class="flex">
|
||||
{#each tabs as { Content, props }, index}
|
||||
<div class="absolute focus:outline-none w-full pt-2 transition-opacity duration-300 overflow-y-scroll no-scrollbar pb-2 h-full tab {activeTab === index ? 'opacity-100 active' : 'opacity-0'}"
|
||||
style="left: {index * 100}%;">
|
||||
<div style="left: {index * 100}%;" class="fixed top-0 w-full h-8 bg-gradient-to-b to-transparent pointer-events-none z-[100] from-white dark:from-zinc-800 dark:to-transparent"></div>
|
||||
<Content {...props} />
|
||||
</div>
|
||||
{/each}
|
||||
</div>
|
||||
</MotionDiv>
|
||||
<div class="overflow-hidden px-4 flex-1 min-h-0">
|
||||
{#each tabs as { Content, props }, index (index)}
|
||||
{#if activeTab === index}
|
||||
<div
|
||||
role="tabpanel"
|
||||
class="focus:outline-none w-full h-full min-h-0 pt-2 overflow-y-auto no-scrollbar pb-6 tab active relative"
|
||||
>
|
||||
<div
|
||||
class="sticky top-0 w-full h-3 -mb-3 bg-gradient-to-b from-white/80 dark:from-zinc-800/80 to-transparent pointer-events-none z-[1]"
|
||||
aria-hidden="true"
|
||||
></div>
|
||||
<Content {...props} />
|
||||
</div>
|
||||
{/if}
|
||||
{/each}
|
||||
</div>
|
||||
</div>
|
||||
@@ -3,7 +3,7 @@
|
||||
.bsplus-font-picker-overlay {
|
||||
position: fixed;
|
||||
inset: 0;
|
||||
z-index: 50000;
|
||||
z-index: 200001;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
<script lang="ts">
|
||||
import { LUCIDE_MOON_PATH } from "@/lib/icons/lucideMoon";
|
||||
|
||||
let { class: className = "w-5 h-5" }: { class?: string } = $props();
|
||||
</script>
|
||||
|
||||
<svg
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
viewBox="0 0 24 24"
|
||||
fill="currentColor"
|
||||
class={className}
|
||||
aria-hidden="true"
|
||||
>
|
||||
<path d={LUCIDE_MOON_PATH} />
|
||||
</svg>
|
||||
@@ -0,0 +1,15 @@
|
||||
<script lang="ts">
|
||||
import { LUCIDE_SUN_PATH } from "@/lib/icons/lucideSun";
|
||||
|
||||
let { class: className = "w-5 h-5" }: { class?: string } = $props();
|
||||
</script>
|
||||
|
||||
<svg
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
viewBox="0 0 24 24"
|
||||
fill="currentColor"
|
||||
class={className}
|
||||
aria-hidden="true"
|
||||
>
|
||||
<path d={LUCIDE_SUN_PATH} />
|
||||
</svg>
|
||||
@@ -2,26 +2,26 @@
|
||||
import { hasEnoughStorageSpace, isIndexedDBSupported, writeData, openDatabase, readAllData, deleteData } from '@/interface/hooks/BackgroundDataLoader';
|
||||
import Spinner from '../Spinner.svelte';
|
||||
import { settingsState } from '@/seqta/utils/listeners/SettingsState'
|
||||
import { Index } from 'flexsearch';
|
||||
import { backgroundUpdates } from '@/interface/hooks/BackgroundUpdates'
|
||||
import { ThemeManager } from '@/plugins/built-in/themes/theme-manager'
|
||||
|
||||
const themeManager = ThemeManager.getInstance();
|
||||
|
||||
type Background = { id: string; category: string; type: string; lowResUrl: string; highResUrl: string; name: string; description: string; featured?: boolean };
|
||||
let { searchTerm } = $props<{ searchTerm: string }>();
|
||||
let { searchTerm, selectedCategory, onCategoriesChange } = $props<{
|
||||
searchTerm: string;
|
||||
selectedCategory: string;
|
||||
onCategoriesChange: (categories: string[]) => void;
|
||||
}>();
|
||||
|
||||
// Existing states
|
||||
let backgrounds = $state<Background[]>([]);
|
||||
let selectedCategory = $state<string>('All');
|
||||
let error = $state<string | null>(null);
|
||||
let selectedBackground = $state<string | null>(null);
|
||||
let isLoading = $state<boolean>(true);
|
||||
let savedBackgrounds = $state<string[]>([]);
|
||||
let installingBackgrounds = $state<Set<string>>(new Set());
|
||||
let debugInfo = $state<string>('');
|
||||
let searchIndex = $state<Index | null>(null);
|
||||
|
||||
// New state variables
|
||||
let activeTab = $state<'all' | 'installed' | 'photos' | 'videos'>('all');
|
||||
let sortBy = $state<'newest' | 'popular' | 'name'>('newest');
|
||||
@@ -36,19 +36,7 @@
|
||||
}
|
||||
const data = await response.json();
|
||||
backgrounds = data.backgrounds;
|
||||
|
||||
// Initialize FlexSearch index
|
||||
const index = new Index({
|
||||
tokenize: "forward",
|
||||
preset: "score"
|
||||
});
|
||||
|
||||
// Add backgrounds to the index
|
||||
backgrounds.forEach((bg, i) => {
|
||||
index.add(i, bg.name + " " + bg.description);
|
||||
});
|
||||
|
||||
searchIndex = index;
|
||||
onCategoriesChange([...new Set(backgrounds.map((background) => background.category))]);
|
||||
debugInfo = `Loaded ${backgrounds.length} backgrounds`;
|
||||
await loadSavedBackgrounds();
|
||||
} catch (e) {
|
||||
@@ -79,10 +67,11 @@
|
||||
let filteredBackgrounds = $derived((() => {
|
||||
let filtered = backgrounds;
|
||||
|
||||
// Use FlexSearch if there's a search term
|
||||
if (searchTerm.trim() && searchIndex) {
|
||||
const results = searchIndex.search(searchTerm) as number[];
|
||||
filtered = results.map(i => backgrounds[i]);
|
||||
if (searchTerm.trim()) {
|
||||
const q = searchTerm.trim().toLowerCase();
|
||||
filtered = backgrounds.filter((bg) =>
|
||||
`${bg.name} ${bg.description}`.toLowerCase().includes(q),
|
||||
);
|
||||
}
|
||||
|
||||
// Apply category filtering
|
||||
@@ -112,7 +101,6 @@
|
||||
})());
|
||||
|
||||
let categories = $derived([...new Set(backgrounds.map(bg => bg.category))]);
|
||||
|
||||
// Background management functions
|
||||
async function saveBackgroundFromUrl(url: string, id: string, fileType: string): Promise<void> {
|
||||
try {
|
||||
@@ -177,41 +165,7 @@
|
||||
}
|
||||
</script>
|
||||
|
||||
<div class="flex h-full">
|
||||
<!-- Sidebar -->
|
||||
<div class="p-4 w-64 h-full border-r border-zinc-200 dark:border-zinc-700">
|
||||
<div class="mb-8">
|
||||
<h2 class="mb-4 text-lg font-semibold">Categories</h2>
|
||||
<nav class="space-y-2">
|
||||
<button
|
||||
class={`w-full px-4 py-2 text-left bg-transparent rounded-full hover:bg-zinc-100 dark:hover:bg-zinc-800 transition ${selectedCategory === 'All' ? 'bg-blue-100 dark:bg-zinc-800' : ''}`}
|
||||
onclick={() => selectedCategory = 'All'}
|
||||
>
|
||||
All
|
||||
</button>
|
||||
<button
|
||||
class={`w-full px-4 py-2 text-left bg-transparent rounded-full hover:bg-zinc-100 dark:hover:bg-zinc-800 transition ${selectedCategory === 'Featured' ? 'bg-blue-100 dark:bg-zinc-800' : ''}`}
|
||||
onclick={() => selectedCategory = 'Featured'}
|
||||
>
|
||||
Featured
|
||||
</button>
|
||||
|
||||
<div class="my-2 border-b border-zinc-200 dark:border-zinc-700"></div>
|
||||
|
||||
{#each categories as category}
|
||||
<button
|
||||
class={`w-full px-4 py-2 text-left bg-transparent rounded-full hover:bg-zinc-100 dark:hover:bg-zinc-800 transition ${selectedCategory === category ? 'bg-blue-100 dark:bg-zinc-800' : ''}`}
|
||||
onclick={() => selectedCategory = category}
|
||||
>
|
||||
{category}
|
||||
</button>
|
||||
{/each}
|
||||
</nav>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Main Content -->
|
||||
<div class="overflow-auto flex-1">
|
||||
<div class="h-full overflow-auto">
|
||||
<!-- Header -->
|
||||
<div class="sticky top-0 z-10 p-4 border-b bg-[#F1F1F3] dark:bg-zinc-900 dark:border-zinc-700">
|
||||
<div class="flex justify-between items-center mb-4">
|
||||
@@ -309,7 +263,6 @@
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{#if settingsState.devMode}
|
||||
@@ -322,4 +275,3 @@
|
||||
<p>Selected Category: {selectedCategory}</p>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
import { onMount } from "svelte";
|
||||
import { cloudAuth } from "@/seqta/utils/CloudAuth";
|
||||
import CloudPfpAvatar from "@/interface/components/CloudPfpAvatar.svelte";
|
||||
import { settingsState } from "@/seqta/utils/listeners/SettingsState";
|
||||
|
||||
let { alwaysShowUserName = false, onClick = undefined } = $props<{
|
||||
alwaysShowUserName?: boolean;
|
||||
@@ -19,7 +20,7 @@
|
||||
return unsubscribe;
|
||||
});
|
||||
|
||||
function handleClickOutside(e: MouseEvent) {
|
||||
function handleClickOutside(e: PointerEvent) {
|
||||
if (dropdownEl && !dropdownEl.contains(e.target as Node)) {
|
||||
open = false;
|
||||
}
|
||||
@@ -28,11 +29,11 @@
|
||||
$effect(() => {
|
||||
if (open) {
|
||||
const timer = setTimeout(() => {
|
||||
document.addEventListener("click", handleClickOutside);
|
||||
document.addEventListener("pointerdown", handleClickOutside);
|
||||
}, 0);
|
||||
return () => {
|
||||
clearTimeout(timer);
|
||||
document.removeEventListener("click", handleClickOutside);
|
||||
document.removeEventListener("pointerdown", handleClickOutside);
|
||||
};
|
||||
}
|
||||
});
|
||||
@@ -47,7 +48,8 @@
|
||||
open = false;
|
||||
}
|
||||
|
||||
function handleButtonClick() {
|
||||
function handleButtonClick(event: MouseEvent) {
|
||||
event.stopPropagation();
|
||||
if (onClick) {
|
||||
onClick();
|
||||
} else {
|
||||
@@ -65,11 +67,11 @@
|
||||
}
|
||||
</script>
|
||||
|
||||
<div class="relative flex items-center" bind:this={dropdownEl}>
|
||||
<div class="relative z-20 flex shrink-0 items-center" bind:this={dropdownEl}>
|
||||
<button
|
||||
type="button"
|
||||
onclick={handleButtonClick}
|
||||
class="flex items-center gap-2 px-3 py-1.5 text-[0.75rem] rounded-lg shadow-2xl border dark:bg-[#38373D]/50 bg-[#DDDDDD]/50 border-[#DDDDDD]/30 dark:border-[#38373D]/30 dark:text-white transition-colors duration-200"
|
||||
class="flex h-12 items-center gap-2 rounded-full bg-zinc-100/80 px-4 text-sm font-medium text-zinc-700 transition-colors duration-150 hover:bg-zinc-200 hover:text-zinc-950 focus:outline-none dark:bg-zinc-900/50 dark:text-zinc-200 dark:hover:bg-zinc-700 dark:hover:text-white"
|
||||
>
|
||||
{#if cloudState.isLoggedIn}
|
||||
{#if cloudState.user?.pfpUrl}
|
||||
@@ -85,14 +87,14 @@
|
||||
{/if}
|
||||
<span
|
||||
class={alwaysShowUserName
|
||||
? "inline max-w-[10rem] truncate text-[0.75rem]"
|
||||
: "hidden max-w-24 truncate sm:inline text-[0.75rem]"}
|
||||
? "inline max-w-[10rem] truncate"
|
||||
: "hidden max-w-24 truncate sm:inline"}
|
||||
>
|
||||
{cloudState.user?.displayName || cloudState.user?.username || cloudState.user?.email || "User"}
|
||||
</span>
|
||||
{:else}
|
||||
<span class="text-sm font-IconFamily" aria-hidden="true">{'\ued53'}</span>
|
||||
<span class="text-[0.75rem]">Sign in</span>
|
||||
<span>Sign in</span>
|
||||
{/if}
|
||||
</button>
|
||||
|
||||
@@ -100,7 +102,8 @@
|
||||
<!-- svelte-ignore a11y_click_events_have_key_events -->
|
||||
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
||||
<div
|
||||
class="absolute right-0 top-full mt-2 w-80 rounded-xl border border-zinc-200 dark:border-zinc-600 bg-white dark:bg-zinc-800 shadow-xl z-[100] overflow-hidden"
|
||||
class="cloud-dropdown absolute right-0 top-full mt-2 w-80 rounded-xl border border-zinc-200 dark:border-zinc-600 bg-white dark:bg-zinc-800 shadow-xl z-[100] overflow-hidden"
|
||||
class:cloud-dropdown--motion={$settingsState.animations}
|
||||
onclick={(e) => e.stopPropagation()}
|
||||
>
|
||||
<div class="p-4 border-b border-zinc-200 dark:border-zinc-600">
|
||||
@@ -160,3 +163,21 @@
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
<style>
|
||||
.cloud-dropdown--motion {
|
||||
transform-origin: top right;
|
||||
animation: cloud-dropdown-in 0.22s cubic-bezier(0.22, 1, 0.36, 1) forwards;
|
||||
}
|
||||
|
||||
@keyframes cloud-dropdown-in {
|
||||
from {
|
||||
opacity: 0;
|
||||
transform: scale(0.94) translateY(-6px);
|
||||
}
|
||||
to {
|
||||
opacity: 1;
|
||||
transform: scale(1) translateY(0);
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -34,16 +34,16 @@
|
||||
</script>
|
||||
|
||||
{#if slides.length > 0}
|
||||
<div class="relative w-full overflow-clip rounded-xl transition-opacity" transition:fade>
|
||||
<div class="relative w-full overflow-clip rounded-xl ring-1 ring-black/10 transition-opacity dark:ring-white/10" transition:fade>
|
||||
<div
|
||||
class="w-full aspect-[5/1] max-h-[500px]"
|
||||
class="w-full overflow-hidden"
|
||||
use:emblaCarouselSvelte={{ options, plugins }}
|
||||
onemblaInit={onInit}
|
||||
>
|
||||
<div class="flex">
|
||||
{#each slides as slide (slide.imageUrl + slide.title + (slide.subtitle ?? ''))}
|
||||
<div
|
||||
class="relative flex-[0_0_100%] cursor-pointer rounded-xl overflow-clip"
|
||||
class="cover-slide relative isolate min-w-0 flex-[0_0_100%] cursor-pointer overflow-hidden"
|
||||
role="button"
|
||||
tabindex="0"
|
||||
onkeydown={(e) => {
|
||||
@@ -51,7 +51,7 @@
|
||||
}}
|
||||
onclick={() => setDisplayTheme(slide.openTheme)}
|
||||
>
|
||||
<img src={slide.imageUrl} alt="" class="object-cover w-full h-full" />
|
||||
<img src={slide.imageUrl} alt="" class="absolute inset-0 z-0 h-full w-full object-cover" />
|
||||
{#if slide.badgeFeatured === true}
|
||||
<div class="absolute top-4 left-4 z-[2] pointer-events-none">
|
||||
<span
|
||||
@@ -69,7 +69,7 @@
|
||||
</span>
|
||||
</div>
|
||||
{/if}
|
||||
<div class="absolute bottom-0 left-0 p-8 z-[1]">
|
||||
<div class="absolute bottom-0 left-0 z-[2] p-8">
|
||||
<h2 class="text-4xl font-bold text-white">{slide.title}</h2>
|
||||
{#if slide.subtitle}
|
||||
<p class="text-lg font-medium text-white/95 mt-1 line-clamp-2">{slide.subtitle}</p>
|
||||
@@ -81,7 +81,6 @@
|
||||
<p class="text-lg text-white line-clamp-3">{slide.openTheme.description}</p>
|
||||
{/if}
|
||||
</div>
|
||||
<div class="absolute bottom-0 left-0 w-full h-1/2 to-transparent bg-linear-to-t from-black/80"></div>
|
||||
</div>
|
||||
{/each}
|
||||
</div>
|
||||
@@ -111,3 +110,26 @@
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<style>
|
||||
.cover-slide {
|
||||
aspect-ratio: 3 / 1;
|
||||
}
|
||||
|
||||
.cover-slide::after {
|
||||
position: absolute;
|
||||
z-index: 1;
|
||||
inset: 0;
|
||||
background: linear-gradient(
|
||||
to top,
|
||||
rgb(0 0 0 / 46%) 0%,
|
||||
rgb(0 0 0 / 42.5%) 18%,
|
||||
rgb(0 0 0 / 34%) 36%,
|
||||
rgb(0 0 0 / 21%) 54%,
|
||||
rgb(0 0 0 / 8%) 72%,
|
||||
transparent 88%
|
||||
);
|
||||
content: '';
|
||||
pointer-events: none;
|
||||
}
|
||||
</style>
|
||||
@@ -1,74 +1,152 @@
|
||||
<script lang="ts">
|
||||
import logo from '@/resources/icons/betterseqta-dark-full.png';
|
||||
import logoDark from '@/resources/icons/betterseqta-light-full.png';
|
||||
import { closeStore } from '@/seqta/ui/renderStore'
|
||||
import browser from 'webextension-polyfill';
|
||||
import CloudHeader from './CloudHeader.svelte';
|
||||
import darkLogo from "@/resources/icons/betterseqta-dark-full.png";
|
||||
import lightLogo from "@/resources/icons/betterseqta-light-full.png";
|
||||
import { resolveExtensionAssetUrl } from "@/lib/extensionAssetUrl";
|
||||
import MotionDiv from "../MotionDiv.svelte";
|
||||
import PlainCloseButton from "../PlainCloseButton.svelte";
|
||||
import CloudHeader from "./CloudHeader.svelte";
|
||||
import { settingsState } from "@/seqta/utils/listeners/SettingsState";
|
||||
|
||||
// Props
|
||||
let { searchTerm, setSearchTerm, darkMode, activeTab, setActiveTab } = $props<{
|
||||
searchTerm: string,
|
||||
setSearchTerm: (term: string) => void,
|
||||
darkMode: boolean,
|
||||
activeTab: string,
|
||||
setActiveTab: (tab: string) => void
|
||||
type SettingsPage = "settings" | "themes" | "backgrounds";
|
||||
|
||||
let {
|
||||
searchTerm,
|
||||
setSearchTerm,
|
||||
activePage,
|
||||
setActivePage,
|
||||
showStoreTools,
|
||||
onLogoClick,
|
||||
onClose,
|
||||
} = $props<{
|
||||
searchTerm: string;
|
||||
setSearchTerm: (term: string) => void;
|
||||
activePage: SettingsPage;
|
||||
setActivePage: (page: SettingsPage) => void;
|
||||
showStoreTools: boolean;
|
||||
onLogoClick: () => void;
|
||||
onClose: () => void;
|
||||
}>();
|
||||
|
||||
// Clear search input function
|
||||
const clearSearch = () => {
|
||||
setSearchTerm('');
|
||||
};
|
||||
const tabs: { id: SettingsPage; title: string }[] = [
|
||||
{ id: "settings", title: "Settings" },
|
||||
{ id: "themes", title: "Themes" },
|
||||
{ id: "backgrounds", title: "Backgrounds" },
|
||||
];
|
||||
|
||||
const activeIndex = $derived(tabs.findIndex((tab) => tab.id === activePage));
|
||||
const motion = $derived($settingsState.animations ? "var(--bs-settings-ease)" : "0s");
|
||||
</script>
|
||||
|
||||
<header class="fixed top-0 z-50 w-full h-[4.25rem] bg-white border-b shadow-md border-b-white/10 dark:bg-zinc-950/90 backdrop-blur-xl dark:text-white">
|
||||
<div class="flex justify-between items-center px-4 py-1">
|
||||
<div class="flex gap-4 place-items-center cursor-pointer" onkeydown={(e) => { if (e.key === 'Enter') clearSearch() }} onclick={clearSearch} role="button" tabindex="0">
|
||||
<img src={browser.runtime.getURL(logo)} class="h-14 {darkMode ? 'hidden' : ''}" alt="Logo" />
|
||||
<img src={browser.runtime.getURL(logoDark)} class="h-14 {darkMode ? '' : 'hidden'}" alt="Dark Logo" />
|
||||
<header
|
||||
class="flex shrink-0 items-center gap-4 border-b border-zinc-200/60 px-5 py-4 dark:border-zinc-700/50"
|
||||
style="--bs-settings-ease: 0.28s cubic-bezier(0.22, 1, 0.36, 1)"
|
||||
>
|
||||
<button type="button" class="hidden shrink-0 lg:block" onclick={onLogoClick}>
|
||||
<img
|
||||
src={resolveExtensionAssetUrl(darkLogo)}
|
||||
class="h-11 w-52 object-cover dark:hidden"
|
||||
alt="BetterSEQTA+"
|
||||
/>
|
||||
<img
|
||||
src={resolveExtensionAssetUrl(lightLogo)}
|
||||
class="hidden h-11 w-52 object-cover dark:block"
|
||||
alt="BetterSEQTA+"
|
||||
/>
|
||||
</button>
|
||||
|
||||
<div class="w-[1px] h-10 my-auto bg-zinc-400 dark:bg-zinc-600"></div>
|
||||
|
||||
<button
|
||||
class="px-4 py-2 font-semibold text-lg transition-colors duration-200 {activeTab === 'themes' ? 'text-blue-600 border-b-2 border-blue-600' : 'text-gray-600 dark:text-gray-300 hover:text-blue-500 dark:hover:text-blue-400'}"
|
||||
onclick={() => setActiveTab('themes')}
|
||||
>
|
||||
Themes
|
||||
</button>
|
||||
<button
|
||||
class="px-4 py-2 font-semibold text-lg transition-colors duration-200 {activeTab === 'backgrounds' ? 'text-blue-600 border-b-2 border-blue-600' : 'text-gray-600 dark:text-gray-300 hover:text-blue-500 dark:hover:text-blue-400'}"
|
||||
onclick={() => setActiveTab('backgrounds')}
|
||||
>
|
||||
Backgrounds
|
||||
</button>
|
||||
|
||||
<CloudHeader />
|
||||
</div>
|
||||
|
||||
<div class="flex relative gap-2">
|
||||
<input
|
||||
type="text"
|
||||
placeholder="Search themes..."
|
||||
value={searchTerm}
|
||||
oninput={(e: any) => setSearchTerm(e.target.value)}
|
||||
class="px-4 py-2 pl-10 text-lg transition bg-gray-100/80 rounded-lg ring-0 focus:bg-gray-100/0 dark:focus:bg-zinc-700/50 focus:ring-[1px] ring-zinc-200 dark:ring-zinc-600 dark:bg-zinc-700/80 dark:text-gray-100 focus:outline-none focus:border-transparent" />
|
||||
<svg
|
||||
class="absolute left-3 top-1/2 w-5 h-5 text-gray-400 transform -translate-y-1/2 dark:text-gray-200"
|
||||
fill="none"
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round"
|
||||
stroke-width="2"
|
||||
viewBox="0 0 24 24"
|
||||
stroke="currentColor">
|
||||
<path d="M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z"></path>
|
||||
</svg>
|
||||
|
||||
<!-- Close Button -->
|
||||
<button
|
||||
onclick={closeStore}
|
||||
class="p-1 px-3"
|
||||
>
|
||||
<span class="text-2xl font-IconFamily"></span>
|
||||
</button>
|
||||
<div
|
||||
class="tab-track h-12 min-w-0 flex-1 rounded-full bg-zinc-100/80 p-1 dark:bg-zinc-900/50"
|
||||
role="tablist"
|
||||
aria-label="Settings pages"
|
||||
>
|
||||
<div class="relative flex">
|
||||
<MotionDiv
|
||||
class="absolute inset-y-0 left-0 z-0 w-1/3 rounded-full bg-white shadow-sm dark:bg-zinc-700"
|
||||
animate={{ x: `${activeIndex * 100}%` }}
|
||||
transition={{ type: "spring", stiffness: 250, damping: 25 }}
|
||||
/>
|
||||
{#each tabs as tab (tab.id)}
|
||||
<button
|
||||
type="button"
|
||||
role="tab"
|
||||
aria-selected={activePage === tab.id}
|
||||
onclick={() => setActivePage(tab.id)}
|
||||
class="relative z-10 h-10 flex-1 whitespace-nowrap rounded-full px-4 text-base transition-colors duration-200
|
||||
{activePage === tab.id
|
||||
? 'font-semibold text-zinc-900 dark:text-white'
|
||||
: 'text-zinc-500 hover:text-zinc-900 dark:text-zinc-400 dark:hover:text-white'}"
|
||||
>
|
||||
{tab.title}
|
||||
</button>
|
||||
{/each}
|
||||
</div>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<div class="flex shrink-0 items-center gap-2">
|
||||
<div
|
||||
class="store-search-wrap hidden md:block"
|
||||
class:store-search-wrap--open={showStoreTools}
|
||||
style="transition: max-width {motion}, opacity {motion}, transform {motion}"
|
||||
aria-hidden={!showStoreTools}
|
||||
>
|
||||
<label class="relative block w-40 md:w-48 xl:w-56">
|
||||
<span class="sr-only">Search {activePage}</span>
|
||||
<svg
|
||||
class="pointer-events-none absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-zinc-400"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
viewBox="0 0 24 24"
|
||||
aria-hidden="true"
|
||||
>
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="m21 21-4.35-4.35m1.35-5.65a7 7 0 1 1-14 0 7 7 0 0 1 14 0Z" />
|
||||
</svg>
|
||||
<input
|
||||
type="search"
|
||||
placeholder={activePage === "themes" ? "Search themes" : "Search backgrounds"}
|
||||
value={searchTerm}
|
||||
tabindex={showStoreTools ? undefined : -1}
|
||||
oninput={(event) => setSearchTerm(event.currentTarget.value)}
|
||||
class="store-search h-12 w-full rounded-full bg-zinc-100/80 pl-9 pr-4 text-sm text-zinc-900 transition-colors duration-150 placeholder:text-zinc-400 focus:bg-zinc-200/70 dark:bg-zinc-900/50 dark:text-white dark:focus:bg-zinc-700"
|
||||
/>
|
||||
</label>
|
||||
</div>
|
||||
|
||||
{#if showStoreTools}
|
||||
<CloudHeader />
|
||||
{/if}
|
||||
|
||||
<PlainCloseButton onclick={onClose} label="Close settings" />
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<style>
|
||||
.store-search-wrap {
|
||||
overflow: hidden;
|
||||
max-width: 0;
|
||||
opacity: 0;
|
||||
transform: translateX(8px);
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
.store-search-wrap--open {
|
||||
max-width: 10rem;
|
||||
opacity: 1;
|
||||
transform: translateX(0);
|
||||
pointer-events: auto;
|
||||
}
|
||||
|
||||
@media (min-width: 1280px) {
|
||||
.store-search-wrap--open {
|
||||
max-width: 14rem;
|
||||
}
|
||||
}
|
||||
|
||||
.store-search,
|
||||
.store-search:focus,
|
||||
.store-search:focus-visible {
|
||||
appearance: none;
|
||||
border: 0 !important;
|
||||
outline: 0 !important;
|
||||
box-shadow: none !important;
|
||||
}
|
||||
</style>
|
||||
@@ -4,8 +4,6 @@
|
||||
masterGridDisplayDownloadCount,
|
||||
gridCardPreviewImageUrls,
|
||||
} from '@/interface/utils/themeStoreFlavours'
|
||||
import { fade } from 'svelte/transition';
|
||||
import { onMount } from 'svelte';
|
||||
import emblaCarouselSvelte from 'embla-carousel-svelte';
|
||||
import Autoplay from 'embla-carousel-autoplay';
|
||||
let { theme, onClick, toggleFavorite, isLoggedIn, onRequestSignIn, allStoreThemeRows } = $props<{
|
||||
@@ -49,21 +47,8 @@
|
||||
];
|
||||
});
|
||||
|
||||
let menuOpen = $state(false);
|
||||
let menuRef: HTMLDivElement;
|
||||
|
||||
onMount(() => {
|
||||
const closeMenu = (e: MouseEvent) => {
|
||||
if (menuOpen && menuRef && !menuRef.contains(e.target as Node)) {
|
||||
menuOpen = false;
|
||||
}
|
||||
};
|
||||
document.addEventListener('click', closeMenu);
|
||||
return () => document.removeEventListener('click', closeMenu);
|
||||
});
|
||||
|
||||
function handleCardClick(e: MouseEvent) {
|
||||
if ((e.target as HTMLElement).closest('[data-theme-menu]')) return;
|
||||
if ((e.target as HTMLElement).closest('[data-theme-favorite]')) return;
|
||||
onClick();
|
||||
}
|
||||
|
||||
@@ -74,7 +59,6 @@
|
||||
} else {
|
||||
onRequestSignIn?.();
|
||||
}
|
||||
menuOpen = false;
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -86,8 +70,7 @@
|
||||
onclick={handleCardClick}
|
||||
>
|
||||
<div
|
||||
class="bg-gray-50 w-full transition-all duration-500 ease-out relative group flex flex-col rounded-xl overflow-clip border hover:scale-105 hover:shadow-2xl dark:hover:shadow-white/[0.1] dark:hover:shadow-white/[0.8] dark:bg-zinc-800 dark:border-white/[0.1] h-auto"
|
||||
transition:fade
|
||||
class="theme-card isolate bg-gray-50 w-full transition-[transform,box-shadow,border-color] duration-300 ease-out relative group flex flex-col rounded-xl overflow-clip border hover:scale-[1.02] hover:shadow-xl dark:hover:shadow-black/60 dark:bg-zinc-800 dark:border-white/[0.1] h-auto"
|
||||
>
|
||||
{#if theme.featured === true}
|
||||
<div class="absolute top-2 left-2 z-20 pointer-events-none">
|
||||
@@ -102,45 +85,34 @@
|
||||
</span>
|
||||
</div>
|
||||
{/if}
|
||||
<!-- Menu dropdown -->
|
||||
<div class="absolute top-2 right-2 z-20" data-theme-menu bind:this={menuRef}>
|
||||
<button
|
||||
type="button"
|
||||
class="flex justify-center items-center w-8 h-8 rounded-lg bg-black/40 hover:bg-black/60 text-white transition-all"
|
||||
onclick={(e) => { e.stopPropagation(); menuOpen = !menuOpen; }}
|
||||
aria-label="Theme options"
|
||||
<button
|
||||
type="button"
|
||||
data-theme-favorite
|
||||
class="pointer-events-none absolute right-2 top-2 z-20 flex h-10 w-10 scAle-[0.25] items-center justify-center rounded-full bg-black/50 text-white opacity-0 blur-[4px] transition-[opacity,transform,filter,background-color] duration-200 ease-[cubic-bezier(0.2,0,0,1)] hover:bg-black/70 active:scale-[0.96] group-hover:pointer-events-auto group-hover:scale-100 group-hover:opacity-100 group-hover:blur-0 focus-visible:pointer-events-auto focus-visible:scale-100 focus-visible:opacity-100 focus-visible:blur-0 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-white"
|
||||
onclick={handleFavoriteClick}
|
||||
aria-label={isLoggedIn
|
||||
? theme.is_favorited
|
||||
? 'Remove from favourites'
|
||||
: 'Add to favourites'
|
||||
: 'Sign in to favourite themes'}
|
||||
title={isLoggedIn
|
||||
? theme.is_favorited
|
||||
? 'Remove from favourites'
|
||||
: 'Add to favourites'
|
||||
: 'Sign in to favourite themes'}
|
||||
>
|
||||
<svg
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
viewBox="0 0 24 24"
|
||||
fill={theme.is_favorited ? 'currentColor' : 'none'}
|
||||
stroke="currentColor"
|
||||
stroke-width="2"
|
||||
class="h-5 w-5 {theme.is_favorited ? 'text-red-500' : ''}"
|
||||
aria-hidden="true"
|
||||
>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" fill="currentColor" viewBox="0 0 24 24" class="w-5 h-5">
|
||||
<path d="M12 8c1.1 0 2-.9 2-2s-.9-2-2-2-2 .9-2 2 .9 2 2 2zm0 2c-1.1 0-2 .9-2 2s.9 2 2 2 2-.9 2-2-.9-2-2-2zm0 6c-1.1 0-2 .9-2 2s.9 2 2 2 2-.9 2-2-.9-2-2-2z"/>
|
||||
</svg>
|
||||
</button>
|
||||
{#if menuOpen}
|
||||
<div
|
||||
class="absolute right-0 top-full mt-1 py-1 min-w-[140px] rounded-lg bg-white dark:bg-zinc-800 shadow-lg border border-zinc-200 dark:border-zinc-700"
|
||||
role="menu"
|
||||
>
|
||||
<button
|
||||
type="button"
|
||||
class="flex gap-2 items-center w-full px-3 py-2 text-left text-sm hover:bg-zinc-100 dark:hover:bg-zinc-700"
|
||||
role="menuitem"
|
||||
onclick={handleFavoriteClick}
|
||||
title={isLoggedIn ? (theme.is_favorited ? 'Remove from favorites' : 'Add to favorites') : 'Sign in to favorite themes'}
|
||||
>
|
||||
<svg
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
viewBox="0 0 24 24"
|
||||
fill={theme.is_favorited ? 'currentColor' : 'none'}
|
||||
stroke="currentColor"
|
||||
stroke-width="2"
|
||||
class="w-5 h-5 {theme.is_favorited ? 'text-red-500' : ''}"
|
||||
>
|
||||
<path stroke-linecap="round" stroke-linejoin="round" d="M4.318 6.318a4.5 4.5 0 000 6.364L12 20.364l7.682-7.682a4.5 4.5 0 00-6.364-6.364L12 7.636l-1.318-1.318a4.5 4.5 0 00-6.364 0z" />
|
||||
</svg>
|
||||
{theme.is_favorited ? 'Favorited' : 'Favorite'}
|
||||
</button>
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
<path stroke-linecap="round" stroke-linejoin="round" d="M4.318 6.318a4.5 4.5 0 0 1 6.364 0L12 7.636l1.318-1.318a4.5 4.5 0 0 1 6.364 6.364L12 20.364l-7.682-7.682a4.5 4.5 0 0 1 0-6.364Z" />
|
||||
</svg>
|
||||
</button>
|
||||
<div class="absolute bottom-1 left-3 right-3 z-10 mb-1 flex flex-col gap-0.5">
|
||||
<span class="text-xl font-bold text-white drop-shadow-md">{theme.name}</span>
|
||||
{#if theme.author}
|
||||
@@ -161,7 +133,6 @@
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class='absolute bottom-0 z-0 w-full h-3/4 bg-linear-to-t to-transparent from-black/80'></div>
|
||||
{#if gridRotatorUrls.length === 0}
|
||||
<div class="relative w-full h-48 overflow-hidden rounded-md bg-zinc-200 dark:bg-zinc-700" aria-hidden="true"></div>
|
||||
{:else if !allowSlideAutoplay || gridRotatorUrls.length === 1}
|
||||
@@ -199,3 +170,22 @@
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<style>
|
||||
.theme-card::after {
|
||||
position: absolute;
|
||||
z-index: 1;
|
||||
inset: 0;
|
||||
background: linear-gradient(
|
||||
to top,
|
||||
rgb(0 0 0 / 92%) 0%,
|
||||
rgb(0 0 0 / 85%) 18%,
|
||||
rgb(0 0 0 / 68%) 36%,
|
||||
rgb(0 0 0 / 42%) 54%,
|
||||
rgb(0 0 0 / 16%) 72%,
|
||||
transparent 88%
|
||||
);
|
||||
content: '';
|
||||
pointer-events: none;
|
||||
}
|
||||
</style>
|
||||
@@ -30,7 +30,7 @@
|
||||
</script>
|
||||
|
||||
<div class="relative" >
|
||||
<div class="grid grid-cols-1 gap-4 py-12 mx-auto sm:grid-cols-2 lg:grid-cols-3">
|
||||
<div class="grid grid-cols-1 gap-4 py-6 mx-auto sm:grid-cols-2 lg:grid-cols-3">
|
||||
{#each filteredThemes as theme (theme.id)}
|
||||
<ThemeCard
|
||||
{theme}
|
||||
@@ -44,7 +44,7 @@
|
||||
|
||||
{#if filteredThemes.length !== 0}
|
||||
<a href="https://docs.betterseqta.org/theme-creation/" class="block relative z-0 hover:z-20 w-full cursor-pointer">
|
||||
<div class="bg-zinc-50 h-48 w-full transition-all duration-500 ease-out relative overflow-clip rounded-xl border group group/card flex flex-col justify-center items-center hover:scale-105 hover:shadow-2xl dark:hover:shadow-white/[0.1] hover:shadow-white/[0.8] dark:bg-zinc-800 dark:border-white/[0.1]">
|
||||
<div class="bg-zinc-50 h-48 w-full transition-[transform,box-shadow,border-color] duration-300 ease-out relative overflow-clip rounded-xl border group group/card flex flex-col justify-center items-center hover:scale-[1.02] hover:shadow-xl dark:hover:shadow-black/60 dark:bg-zinc-800 dark:border-white/[0.1]">
|
||||
<div class="text-2xl font-IconFamily">{'\uecb3'}</div>
|
||||
<div class="text-xl font-bold text-center transition-all duration-500 dark:text-white">
|
||||
Got a Theme Idea?
|
||||
@@ -64,4 +64,4 @@
|
||||
</a>
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
File diff suppressed because it is too large.
Load diff
@@ -12,18 +12,18 @@
|
||||
|
||||
<div
|
||||
onclick={onClick}
|
||||
onkeydown={onClick}
|
||||
tabindex="-1"
|
||||
onkeydown={(e) => { if (e.key === 'Enter' || e.key === ' ') onClick() }}
|
||||
tabindex="0"
|
||||
role="button"
|
||||
class="relative w-16 h-16 cursor-pointer rounded-xl transition ring-3 dark:ring-zinc-500/50 ring-zinc-300 {isEditMode ? 'animate-shake' : ''} {isSelected ? 'dark:ring-4 ring-4' : 'ring-0'}"
|
||||
>
|
||||
{#if isEditMode}
|
||||
<div
|
||||
tabindex="-1"
|
||||
tabindex="0"
|
||||
role="button"
|
||||
class="absolute top-0 right-0 z-10 flex w-6 h-6 p-2 text-white translate-x-1/2 -translate-y-1/2 bg-red-600 rounded-full place-items-center"
|
||||
onclick={onDelete}
|
||||
onkeydown={onDelete}
|
||||
onclick={(e) => { e.stopPropagation(); onDelete() }}
|
||||
onkeydown={(e) => { if (e.key === 'Enter' || e.key === ' ') { e.stopPropagation(); onDelete() } }}
|
||||
>
|
||||
<div class="w-4 h-0.5 bg-white"></div>
|
||||
</div>
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
<script lang="ts">
|
||||
import { hasEnoughStorageSpace, isIndexedDBSupported, writeData, openDatabase, readAllData, deleteData } from '@/interface/hooks/BackgroundDataLoader'
|
||||
import { hasEnoughStorageSpace, isIndexedDBSupported, writeData, readAllData, deleteData } from '@/interface/hooks/BackgroundDataLoader'
|
||||
import BackgroundUploader from './BackgroundUploader.svelte';
|
||||
import BackgroundItem from './BackgroundItem.svelte'
|
||||
import { onMount, onDestroy } from 'svelte'
|
||||
import { loadBackground } from '@/seqta/ui/ImageBackgrounds'
|
||||
import { delay } from 'lodash'
|
||||
import { backgroundUpdates } from '@/interface/hooks/BackgroundUpdates'
|
||||
|
||||
let { isEditMode, selectNoBackground = $bindable(), selectedBackground = $bindable() } = $props<{ isEditMode: boolean, selectNoBackground: () => void, selectedBackground: string | null }>();
|
||||
@@ -14,10 +13,9 @@
|
||||
let imageBackgrounds = $derived(backgrounds.filter(bg => bg.type === 'image'));
|
||||
let videoBackgrounds = $derived(backgrounds.filter(bg => bg.type === 'video'));
|
||||
|
||||
let isVisible = $state(false);
|
||||
let element: HTMLElement;
|
||||
let observer: MutationObserver;
|
||||
let parentElement: HTMLElement | null = null;
|
||||
function setError(e: unknown) {
|
||||
error = e instanceof Error ? e.message : 'An unknown error occurred';
|
||||
}
|
||||
|
||||
async function getTheme() {
|
||||
return localStorage.getItem('selectedBackground');
|
||||
@@ -47,34 +45,7 @@
|
||||
await writeData(fileId, fileType, blob);
|
||||
backgrounds = [...backgrounds, { id: fileId, type: fileType, blob, url: URL.createObjectURL(blob) }];
|
||||
} catch (e) {
|
||||
if (e instanceof Error) {
|
||||
error = e.message;
|
||||
} else {
|
||||
error = 'An unknown error occurred';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function loadBackgroundMetadata(): Promise<void> {
|
||||
try {
|
||||
error = null;
|
||||
|
||||
if (!isIndexedDBSupported()) {
|
||||
throw new Error("Your browser doesn't support IndexedDB. Unable to load backgrounds.");
|
||||
}
|
||||
|
||||
await openDatabase();
|
||||
const data = await readAllData();
|
||||
selectedBackground = await getTheme();
|
||||
|
||||
// Only load metadata (id and type) for placeholders
|
||||
backgrounds = data.map(({ id, type }) => ({ id, type, blob: null }));
|
||||
} catch (e) {
|
||||
if (e instanceof Error) {
|
||||
error = e.message;
|
||||
} else {
|
||||
error = 'An unknown error occurred';
|
||||
}
|
||||
setError(e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -86,8 +57,9 @@
|
||||
throw new Error("Your browser doesn't support IndexedDB. Unable to load backgrounds.");
|
||||
}
|
||||
|
||||
selectedBackground = await getTheme();
|
||||
const dbData = await readAllData();
|
||||
|
||||
|
||||
// Release existing object URLs to prevent memory leaks
|
||||
backgrounds.forEach(bg => {
|
||||
if (bg.url) URL.revokeObjectURL(bg.url);
|
||||
@@ -106,11 +78,7 @@
|
||||
selectNoBackground();
|
||||
}
|
||||
} catch (e) {
|
||||
if (e instanceof Error) {
|
||||
error = e.message;
|
||||
} else {
|
||||
error = 'An unknown error occurred';
|
||||
}
|
||||
setError(e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -119,7 +87,7 @@
|
||||
selectNoBackground();
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
selectedBackground = fileId;
|
||||
setTheme(fileId);
|
||||
}
|
||||
@@ -133,11 +101,7 @@
|
||||
selectNoBackground();
|
||||
}
|
||||
} catch (e) {
|
||||
if (e instanceof Error) {
|
||||
error = `Failed to delete background: ${e.message}`;
|
||||
} else {
|
||||
error = 'An unknown error occurred';
|
||||
}
|
||||
error = e instanceof Error ? `Failed to delete background: ${e.message}` : 'An unknown error occurred';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -157,39 +121,23 @@
|
||||
}
|
||||
});
|
||||
|
||||
function checkActiveClass() {
|
||||
if (parentElement?.classList.contains('active')) {
|
||||
delay(() => {
|
||||
isVisible = true;
|
||||
syncBackgrounds();
|
||||
}, 600);
|
||||
}
|
||||
}
|
||||
|
||||
onMount(() => {
|
||||
loadBackgroundMetadata();
|
||||
syncBackgrounds();
|
||||
backgroundUpdates.addListener(syncBackgrounds);
|
||||
|
||||
parentElement = element.closest('.tab');
|
||||
if (parentElement) {
|
||||
observer = new MutationObserver(checkActiveClass);
|
||||
observer.observe(parentElement, { attributes: true, attributeFilter: ['class'] });
|
||||
|
||||
return () => {
|
||||
observer.disconnect();
|
||||
backgroundUpdates.removeListener(syncBackgrounds);
|
||||
};
|
||||
}
|
||||
return () => {
|
||||
backgroundUpdates.removeListener(syncBackgrounds);
|
||||
};
|
||||
});
|
||||
|
||||
onDestroy(() => {
|
||||
if (observer) {
|
||||
observer.disconnect();
|
||||
}
|
||||
backgrounds.forEach((bg) => {
|
||||
if (bg.url) URL.revokeObjectURL(bg.url);
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
<div bind:this={element} class="relative px-1 { !( isEditMode && imageBackgrounds.length === 0 && videoBackgrounds.length === 0 ) && 'pt-2' }">
|
||||
<div class="relative px-1 { !( isEditMode && imageBackgrounds.length === 0 && videoBackgrounds.length === 0 ) && 'pt-2' }">
|
||||
{#if !(imageBackgrounds.length === 0 && isEditMode)}
|
||||
<h2 class="pb-2 text-lg font-bold">Background Images</h2>
|
||||
<div class="flex flex-wrap gap-4 mb-4">
|
||||
@@ -197,7 +145,7 @@
|
||||
<BackgroundUploader on:fileChange={e => handleFileChange(e.detail)} />
|
||||
{/if}
|
||||
{#each imageBackgrounds as bg (bg.id)}
|
||||
{#if isVisible && bg.blob}
|
||||
{#if bg.url}
|
||||
<BackgroundItem
|
||||
bg={bg}
|
||||
isSelected={selectedBackground === bg.id}
|
||||
@@ -218,7 +166,7 @@
|
||||
<BackgroundUploader on:fileChange={e => handleFileChange(e.detail)} />
|
||||
{/if}
|
||||
{#each videoBackgrounds as bg (bg.id)}
|
||||
{#if isVisible && bg.blob}
|
||||
{#if bg.url}
|
||||
<BackgroundItem
|
||||
bg={bg}
|
||||
isSelected={selectedBackground === bg.id}
|
||||
@@ -232,4 +180,4 @@
|
||||
{/each}
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
@@ -0,0 +1,34 @@
|
||||
<script lang="ts">
|
||||
import { blobToDataUrl } from '@/plugins/built-in/themes/themeImageUrl'
|
||||
|
||||
let { source, alt = '', class: className = '' } = $props<{
|
||||
source: string | Blob | null | undefined
|
||||
alt?: string
|
||||
class?: string
|
||||
}>()
|
||||
|
||||
let src = $state('')
|
||||
|
||||
$effect(() => {
|
||||
const value = source
|
||||
if (!value) {
|
||||
src = ''
|
||||
return
|
||||
}
|
||||
if (typeof value === 'string') {
|
||||
src = value
|
||||
return
|
||||
}
|
||||
let cancelled = false
|
||||
void blobToDataUrl(value).then((url) => {
|
||||
if (!cancelled) src = url
|
||||
})
|
||||
return () => {
|
||||
cancelled = true
|
||||
}
|
||||
})
|
||||
</script>
|
||||
|
||||
{#if src}
|
||||
<img {src} {alt} class={className} />
|
||||
{/if}
|
||||
@@ -2,18 +2,20 @@
|
||||
import type { CustomTheme, ThemeList } from '@/types/CustomThemes'
|
||||
import { onDestroy, onMount } from 'svelte'
|
||||
import browser from 'webextension-polyfill'
|
||||
import { OpenThemeCreator } from '@/plugins/built-in/themes/ThemeCreator'
|
||||
import { OpenStorePage } from '@/seqta/ui/renderStore'
|
||||
import { themeUpdates } from '@/interface/hooks/ThemeUpdates'
|
||||
import { closeExtensionPopup } from '@/seqta/utils/Closers/closeExtensionPopup'
|
||||
import { ThemeManager } from '@/plugins/built-in/themes/theme-manager'
|
||||
import { cloudAuth } from '@/seqta/utils/CloudAuth'
|
||||
import SignInToFavoriteModal from '@/interface/components/SignInToFavoriteModal.svelte'
|
||||
import ThemeBlobImage from '@/interface/components/themes/ThemeBlobImage.svelte'
|
||||
|
||||
const themeManager = ThemeManager.getInstance();
|
||||
|
||||
let themes = $state<ThemeList | null>(null);
|
||||
let { isEditMode } = $props<{ isEditMode: boolean }>();
|
||||
let { isEditMode, showNavigation = true } = $props<{
|
||||
isEditMode: boolean;
|
||||
showNavigation?: boolean;
|
||||
}>();
|
||||
let isDragging = $state(false);
|
||||
let tempTheme = $state(null);
|
||||
let favoriteStatus = $state<Record<string, boolean>>({});
|
||||
@@ -21,11 +23,14 @@
|
||||
let prevLoggedIn = $state(false);
|
||||
let showSignInModal = $state(false);
|
||||
|
||||
cloudAuth.subscribe((s) => {
|
||||
const now = s.isLoggedIn;
|
||||
if (now && !prevLoggedIn && themes) void fetchThemes();
|
||||
prevLoggedIn = now;
|
||||
cloudLoggedIn = now;
|
||||
$effect(() => {
|
||||
const unsub = cloudAuth.subscribe((s) => {
|
||||
const now = s.isLoggedIn;
|
||||
if (now && !prevLoggedIn && themes) void fetchThemes();
|
||||
prevLoggedIn = now;
|
||||
cloudLoggedIn = now;
|
||||
});
|
||||
return unsub;
|
||||
});
|
||||
|
||||
const handleThemeClick = async (theme: CustomTheme, e: MouseEvent) => {
|
||||
@@ -102,17 +107,14 @@
|
||||
selectedTheme: themeManager.getSelectedThemeId() || '',
|
||||
}
|
||||
if (themes && cloudLoggedIn) {
|
||||
const token = await cloudAuth.getStoredToken();
|
||||
if (token) {
|
||||
const status: Record<string, boolean> = {};
|
||||
await Promise.all(
|
||||
themes.themes.map(async (t) => {
|
||||
try {
|
||||
const res = (await browser.runtime.sendMessage({
|
||||
type: 'fetchThemeDetails',
|
||||
themeId: t.id,
|
||||
token,
|
||||
})) as { success?: boolean; data?: { theme?: { is_favorited?: boolean } } };
|
||||
const status: Record<string, boolean> = {};
|
||||
await Promise.all(
|
||||
themes.themes.map(async (t) => {
|
||||
try {
|
||||
const res = (await browser.runtime.sendMessage({
|
||||
type: 'fetchThemeDetails',
|
||||
themeId: t.id,
|
||||
})) as { success?: boolean; data?: { theme?: { is_favorited?: boolean } } };
|
||||
if (res?.success && res?.data?.theme) {
|
||||
status[t.id] = !!res.data.theme.is_favorited;
|
||||
}
|
||||
@@ -122,25 +124,32 @@
|
||||
})
|
||||
);
|
||||
favoriteStatus = status;
|
||||
}
|
||||
} else {
|
||||
favoriteStatus = {};
|
||||
}
|
||||
}
|
||||
|
||||
const openStorePage = async () => {
|
||||
const { OpenStorePage } = await import('@/seqta/ui/renderStore')
|
||||
await OpenStorePage()
|
||||
}
|
||||
|
||||
const openThemeCreator = async (themeId?: string) => {
|
||||
const { OpenThemeCreator } = await import('@/plugins/built-in/themes/ThemeCreator')
|
||||
OpenThemeCreator(themeId)
|
||||
closeExtensionPopup()
|
||||
}
|
||||
|
||||
const handleToggleFavorite = async (theme: CustomTheme, e: MouseEvent) => {
|
||||
e.stopPropagation();
|
||||
if (!cloudLoggedIn) {
|
||||
showSignInModal = true;
|
||||
return;
|
||||
}
|
||||
const token = await cloudAuth.getStoredToken();
|
||||
if (!token) return;
|
||||
const isFavorite = !favoriteStatus[theme.id];
|
||||
const result = (await browser.runtime.sendMessage({
|
||||
type: 'cloudFavorite',
|
||||
themeId: theme.id,
|
||||
token,
|
||||
action: isFavorite ? 'favorite' : 'unfavorite',
|
||||
})) as { success?: boolean };
|
||||
if (result?.success) {
|
||||
@@ -159,7 +168,7 @@
|
||||
</script>
|
||||
|
||||
<div
|
||||
class="pt-5 mb-1 w-full"
|
||||
class="pt-5 mb-1 w-full max-w-lg mx-auto"
|
||||
role="list"
|
||||
tabindex="-1"
|
||||
ondragover={handleDragOver}
|
||||
@@ -181,7 +190,6 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<h2 class="pb-2 text-lg font-bold">Themes</h2>
|
||||
<div class="flex flex-col gap-2 px-2">
|
||||
{#if themes}
|
||||
{#each themes.themes as theme (theme.id)}
|
||||
@@ -216,8 +224,8 @@
|
||||
</div>
|
||||
<div
|
||||
class="absolute z-20 flex w-8 h-8 p-2 text-white transition-all rounded-full delay-[20ms] opacity-0 top-1/4 right-2 bg-black/50 place-items-center group-hover:opacity-100 group-hover:top-1/2 -translate-y-1/2"
|
||||
onclick={(event) => { event.stopPropagation(); OpenThemeCreator(theme.id); closeExtensionPopup() }}
|
||||
onkeydown={(event) => { if (event.key === 'Enter' || event.key === ' ') OpenThemeCreator(theme.id); closeExtensionPopup() }}
|
||||
onclick={(event) => { event.stopPropagation(); void openThemeCreator(theme.id) }}
|
||||
onkeydown={(event) => { if (event.key === 'Enter' || event.key === ' ') void openThemeCreator(theme.id) }}
|
||||
role="button"
|
||||
tabindex="-1"
|
||||
>
|
||||
@@ -237,8 +245,8 @@
|
||||
|
||||
<div class="relative top-0 z-10 flex justify-center w-full h-full overflow-hidden transition dark:text-white rounded-xl group place-items-center bg-zinc-100 dark:bg-zinc-900 { isEditMode ? 'animate-shake brightness-90' : ''}">
|
||||
{#if theme.coverImage}
|
||||
<img
|
||||
src={typeof theme.coverImage === 'string' ? theme.coverImage : URL.createObjectURL(theme.coverImage)}
|
||||
<ThemeBlobImage
|
||||
source={theme.coverImage}
|
||||
alt={theme.name}
|
||||
class="object-cover absolute inset-0 z-0 w-full h-full pointer-events-none"
|
||||
/>
|
||||
@@ -260,25 +268,54 @@
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
{#if themes && themes.themes.length > 0}
|
||||
<div id="divider" class="w-full h-[1px] my-2 bg-zinc-100 dark:bg-zinc-600"></div>
|
||||
{#if themes && themes.themes.length === 0 && !tempTheme}
|
||||
<div class="flex min-h-56 flex-col items-center justify-center px-4 py-10 text-center">
|
||||
<h3 class="text-xl font-semibold text-zinc-900 dark:text-white" style="text-wrap: balance">
|
||||
No themes installed
|
||||
</h3>
|
||||
<p class="mt-2 max-w-md text-base text-zinc-500 dark:text-zinc-400" style="text-wrap: pretty">
|
||||
Install a theme from the store or create one of your own.
|
||||
</p>
|
||||
<div class="mt-6 grid w-full max-w-md grid-cols-1 gap-2 sm:grid-cols-2">
|
||||
<button
|
||||
type="button"
|
||||
onclick={() => void openStorePage()}
|
||||
class="flex h-11 items-center justify-center gap-2 rounded-lg bg-zinc-200 px-4 font-medium text-zinc-900 transition-[background-color,color,transform] duration-150 hover:bg-zinc-300 active:scale-[0.96] focus:outline-none focus:ring-2 focus:ring-zinc-400 dark:bg-zinc-700 dark:text-white dark:hover:bg-zinc-600"
|
||||
>
|
||||
<span class="font-IconFamily text-lg" aria-hidden="true"></span>
|
||||
Install a theme
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
onclick={() => void openThemeCreator()}
|
||||
class="flex h-11 items-center justify-center gap-2 rounded-lg bg-zinc-200 px-4 font-medium text-zinc-900 transition-[background-color,color,transform] duration-150 hover:bg-zinc-300 active:scale-[0.96] focus:outline-none focus:ring-2 focus:ring-zinc-400 dark:bg-zinc-700 dark:text-white dark:hover:bg-zinc-600"
|
||||
>
|
||||
<span class="font-IconFamily text-lg" aria-hidden="true"></span>
|
||||
Create a theme
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<button
|
||||
onclick={() => OpenStorePage()}
|
||||
class="flex justify-center items-center w-full rounded-xl transition aspect-theme bg-zinc-100 dark:bg-zinc-900 dark:text-white"
|
||||
>
|
||||
<span class="text-xl font-IconFamily"></span>
|
||||
<span class="ml-2">Theme Store</span>
|
||||
</button>
|
||||
{#if showNavigation && themes && themes.themes.length > 0}
|
||||
<div id="divider" class="w-full h-[1px] my-2 bg-zinc-100 dark:bg-zinc-600"></div>
|
||||
|
||||
<button
|
||||
onclick={() => { OpenThemeCreator(); closeExtensionPopup() }}
|
||||
class="flex justify-center items-center w-full rounded-xl transition aspect-theme bg-zinc-100 dark:bg-zinc-900 dark:text-white"
|
||||
>
|
||||
<span class="text-xl font-IconFamily"></span>
|
||||
<span class="ml-2">Create your own</span>
|
||||
</button>
|
||||
<button
|
||||
onclick={() => void openStorePage()}
|
||||
class="flex justify-center items-center w-full rounded-xl transition aspect-theme bg-zinc-100 dark:bg-zinc-900 dark:text-white"
|
||||
>
|
||||
<span class="text-xl font-IconFamily"></span>
|
||||
<span class="ml-2">Theme Store</span>
|
||||
</button>
|
||||
|
||||
<button
|
||||
onclick={() => void openThemeCreator()}
|
||||
class="flex justify-center items-center w-full rounded-xl transition aspect-theme bg-zinc-100 dark:bg-zinc-900 dark:text-white"
|
||||
>
|
||||
<span class="text-xl font-IconFamily"></span>
|
||||
<span class="ml-2">Create your own</span>
|
||||
</button>
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -1,21 +1,25 @@
|
||||
<script lang="ts">
|
||||
import React from "react";
|
||||
import ReactDOM from "react-dom";
|
||||
import { onDestroy, onMount } from "svelte";
|
||||
import { onDestroy } from "svelte";
|
||||
|
||||
const e = React.createElement;
|
||||
let container: HTMLDivElement;
|
||||
let adapterProps = $props();
|
||||
let container = $state<HTMLDivElement | null>(null);
|
||||
|
||||
onMount(() => {
|
||||
const { el, children, class: _, ...props } = $$props;
|
||||
$effect(() => {
|
||||
if (!container) return;
|
||||
|
||||
const { el, children, class: className, ...rest } = adapterProps;
|
||||
try {
|
||||
ReactDOM.render(e(el, props, children), container);
|
||||
ReactDOM.render(e(el, rest, children), container);
|
||||
} catch (err) {
|
||||
console.warn(`react-adapter failed to mount.`, { err });
|
||||
}
|
||||
});
|
||||
|
||||
onDestroy(() => {
|
||||
if (!container) return;
|
||||
try {
|
||||
ReactDOM.unmountComponentAtNode(container);
|
||||
} catch (err) {
|
||||
@@ -24,4 +28,4 @@
|
||||
});
|
||||
</script>
|
||||
|
||||
<div bind:this={container} class={$$props.class}></div>
|
||||
<div bind:this={container} class={adapterProps.class}></div>
|
||||
@@ -0,0 +1,21 @@
|
||||
@tailwind base;
|
||||
@tailwind components;
|
||||
@tailwind utilities;
|
||||
|
||||
button {
|
||||
@apply cursor-pointer;
|
||||
}
|
||||
|
||||
::-webkit-scrollbar {
|
||||
display: none;
|
||||
}
|
||||
|
||||
input {
|
||||
&:focus {
|
||||
box-shadow: unset !important;
|
||||
}
|
||||
}
|
||||
|
||||
.no-scrollbar {
|
||||
scrollbar-width: none !important;
|
||||
}
|
||||
@@ -1,149 +1,55 @@
|
||||
import { type DBSchema, type IDBPDatabase, openDB } from "idb";
|
||||
import localforage from "localforage";
|
||||
|
||||
/**
|
||||
* Defines the schema for the IndexedDB database used for storing background image data.
|
||||
*
|
||||
* @interface BackgroundDB
|
||||
* @extends {DBSchema}
|
||||
* @property {object} backgrounds - The object store for background images.
|
||||
* @property {string} backgrounds.key - The type of the key for the object store (in this case, it's `id` as defined in `keyPath`).
|
||||
* @property {object} backgrounds.value - The structure of the objects stored.
|
||||
* @property {string} backgrounds.value.id - The unique identifier for the background image record.
|
||||
* @property {string} backgrounds.value.type - The MIME type of the image (e.g., "image/png", "image/jpeg").
|
||||
* @property {Blob} backgrounds.value.blob - The binary large object (Blob) containing the image data.
|
||||
*/
|
||||
interface BackgroundDB extends DBSchema {
|
||||
backgrounds: {
|
||||
key: string; // Corresponds to the 'id' property due to keyPath: "id"
|
||||
value: {
|
||||
id: string;
|
||||
type: string;
|
||||
blob: Blob;
|
||||
};
|
||||
};
|
||||
type BackgroundRecord = { id: string; type: string; blob: Blob };
|
||||
|
||||
const store = localforage.createInstance({
|
||||
name: "BackgroundDB",
|
||||
storeName: "backgrounds",
|
||||
});
|
||||
|
||||
export async function openDatabase(): Promise<typeof store> {
|
||||
await store.ready();
|
||||
return store;
|
||||
}
|
||||
|
||||
let db: IDBPDatabase<BackgroundDB> | null = null;
|
||||
|
||||
/**
|
||||
* Initializes and opens an IndexedDB connection or returns an existing one.
|
||||
* If the database doesn't exist or needs an upgrade, the `upgrade` callback
|
||||
* creates the 'backgrounds' object store with 'id' as the keyPath.
|
||||
*
|
||||
* @async
|
||||
* @returns {Promise<IDBPDatabase<BackgroundDB>>} A promise that resolves with the database instance.
|
||||
*/
|
||||
export async function openDatabase(): Promise<IDBPDatabase<BackgroundDB>> {
|
||||
if (db) return db;
|
||||
|
||||
db = await openDB<BackgroundDB>("BackgroundDB", 1, {
|
||||
upgrade(db: IDBPDatabase<BackgroundDB>) {
|
||||
db.createObjectStore("backgrounds", { keyPath: "id" });
|
||||
},
|
||||
export async function readAllData(): Promise<BackgroundRecord[]> {
|
||||
await store.ready();
|
||||
const items: BackgroundRecord[] = [];
|
||||
await store.iterate<BackgroundRecord, void>((value) => {
|
||||
if (value?.id && value.blob) items.push(value);
|
||||
});
|
||||
|
||||
return db;
|
||||
return items;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves all background image records from the 'backgrounds' object store in IndexedDB.
|
||||
*
|
||||
* @async
|
||||
* @returns {Promise<Array<{id: string, type: string, blob: Blob}>>} A promise that resolves with an array of all background image records.
|
||||
*/
|
||||
export async function readAllData(): Promise<
|
||||
Array<{ id: string; type: string; blob: Blob }>
|
||||
> {
|
||||
const db = await openDatabase();
|
||||
return db.getAll("backgrounds");
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes or updates a background image record in the 'backgrounds' object store.
|
||||
* If a record with the given `id` already exists, it will be updated. Otherwise, a new record is created.
|
||||
*
|
||||
* @async
|
||||
* @param {string} id - The unique identifier for the background image record.
|
||||
* @param {string} type - The MIME type of the image (e.g., "image/png").
|
||||
* @param {Blob} blob - The Blob object containing the image data.
|
||||
* @returns {Promise<void>} A promise that resolves when the data has been successfully written.
|
||||
*/
|
||||
export async function writeData(
|
||||
id: string,
|
||||
type: string,
|
||||
blob: Blob,
|
||||
): Promise<void> {
|
||||
const db = await openDatabase();
|
||||
await db.put("backgrounds", { id, type, blob });
|
||||
await store.setItem(id, { id, type, blob });
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes a background image record from the 'backgrounds' object store by its ID.
|
||||
*
|
||||
* @async
|
||||
* @param {string} id - The unique identifier of the background image record to delete.
|
||||
* @returns {Promise<void>} A promise that resolves when the data has been successfully deleted.
|
||||
*/
|
||||
export async function deleteData(id: string): Promise<void> {
|
||||
const db = await openDatabase();
|
||||
await db.delete("backgrounds", id);
|
||||
await store.removeItem(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears all records from the 'backgrounds' object store in IndexedDB.
|
||||
*
|
||||
* @async
|
||||
* @returns {Promise<void>} A promise that resolves when all data has been successfully cleared.
|
||||
*/
|
||||
export async function clearAllData(): Promise<void> {
|
||||
const db = await openDatabase();
|
||||
await db.clear("backgrounds");
|
||||
await store.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves a single background image record from the 'backgrounds' object store by its ID.
|
||||
*
|
||||
* @async
|
||||
* @param {string} id - The unique identifier of the background image record to retrieve.
|
||||
* @returns {Promise<{id: string, type: string, blob: Blob} | undefined>} A promise that resolves with the
|
||||
* background image record if found, or undefined otherwise.
|
||||
*/
|
||||
export async function getDataById(
|
||||
id: string,
|
||||
): Promise<{ id: string; type: string; blob: Blob } | undefined> {
|
||||
const db = await openDatabase();
|
||||
return db.get("backgrounds", id);
|
||||
): Promise<BackgroundRecord | undefined> {
|
||||
const item = await store.getItem<BackgroundRecord>(id);
|
||||
return item ?? undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
* Closes the active IndexedDB connection and nullifies the global `db` variable.
|
||||
* This is important to release resources and allow for proper database management.
|
||||
*/
|
||||
export function closeDatabase(): void {
|
||||
if (db) {
|
||||
db.close();
|
||||
db = null;
|
||||
}
|
||||
}
|
||||
export function closeDatabase(): void {}
|
||||
|
||||
/**
|
||||
* Checks if IndexedDB is supported by the current browser environment.
|
||||
*
|
||||
* @returns {boolean} True if IndexedDB is supported, false otherwise.
|
||||
*/
|
||||
export function isIndexedDBSupported(): boolean {
|
||||
return "indexedDB" in window;
|
||||
}
|
||||
|
||||
/**
|
||||
* Estimates available storage space and checks if it's sufficient for the specified `requiredSpace`.
|
||||
* Uses the `navigator.storage.estimate()` API if available.
|
||||
* If the API is not available or cannot determine space, it defaults to assuming enough space is available.
|
||||
*
|
||||
* @async
|
||||
* @param {number} requiredSpace - The amount of storage space required, in bytes.
|
||||
* @returns {Promise<boolean>} A promise that resolves with true if enough space is estimated to be available, false otherwise.
|
||||
*/
|
||||
export async function hasEnoughStorageSpace(
|
||||
requiredSpace: number,
|
||||
): Promise<boolean> {
|
||||
@@ -153,6 +59,5 @@ export async function hasEnoughStorageSpace(
|
||||
return quota - usage > requiredSpace;
|
||||
}
|
||||
}
|
||||
// If we can't determine, assume there's enough space
|
||||
return true;
|
||||
}
|
||||
@@ -1,53 +1 @@
|
||||
type SettingsPopupCallback = () => void;
|
||||
|
||||
/**
|
||||
* This is a singleton that triggers an update when the settings popup is closed.
|
||||
* This is used to close the colour picker.
|
||||
* Usage:
|
||||
* settingsPopup.addListener(() => {
|
||||
* console.log('Settings popup closed');
|
||||
* });
|
||||
*/
|
||||
class SettingsPopup {
|
||||
private static instance: SettingsPopup;
|
||||
private listeners: Set<SettingsPopupCallback> = new Set();
|
||||
|
||||
private constructor() {}
|
||||
|
||||
public static getInstance(): SettingsPopup {
|
||||
if (!SettingsPopup.instance) {
|
||||
SettingsPopup.instance = new SettingsPopup();
|
||||
}
|
||||
return SettingsPopup.instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a callback function to be invoked when the settings popup is closed.
|
||||
*
|
||||
* @param {SettingsPopupCallback} callback The function to call when the settings popup closes.
|
||||
* This callback takes no arguments and returns void.
|
||||
*/
|
||||
public addListener(callback: SettingsPopupCallback): void {
|
||||
this.listeners.add(callback);
|
||||
}
|
||||
|
||||
/**
|
||||
* Unregisters a previously added callback function.
|
||||
* After calling this method, the provided callback will no longer be invoked when the settings popup closes.
|
||||
*
|
||||
* @param {SettingsPopupCallback} callback The callback function to remove from the listeners.
|
||||
*/
|
||||
public removeListener(callback: SettingsPopupCallback): void {
|
||||
this.listeners.delete(callback);
|
||||
}
|
||||
|
||||
/**
|
||||
* Invokes all registered listener callbacks.
|
||||
* This method should be called when the settings popup is closed to notify all subscribed components or services.
|
||||
*/
|
||||
public triggerClose(): void {
|
||||
this.listeners.forEach((callback) => callback());
|
||||
}
|
||||
}
|
||||
|
||||
export const settingsPopup = SettingsPopup.getInstance();
|
||||
export { settingsPopup } from "@/seqta/utils/settingsPopup";
|
||||
+18
-13
@@ -1,19 +1,19 @@
|
||||
import "./index.css";
|
||||
import Settings from "./pages/settings.svelte";
|
||||
import IconFamily from "@/resources/fonts/IconFamily.woff";
|
||||
import browser from "webextension-polyfill";
|
||||
import { resolveExtensionAssetUrl } from "@/lib/extensionAssetUrl";
|
||||
import renderSvelte from "./main";
|
||||
import { initializeSettingsState } from "@/seqta/utils/listeners/SettingsState";
|
||||
import { initVerboseLogging, verboseInfo } from "@/utils/verboseLog";
|
||||
|
||||
function InjectCustomIcons() {
|
||||
console.info("[BetterSEQTA+] Injecting Icons");
|
||||
verboseInfo("[BetterSEQTA+] Injecting Icons");
|
||||
|
||||
const style = document.createElement("style");
|
||||
style.setAttribute("type", "text/css");
|
||||
style.innerHTML = `
|
||||
@font-face {
|
||||
font-family: 'IconFamily';
|
||||
src: url('${browser.runtime.getURL(IconFamily)}') format('woff');
|
||||
src: url('${resolveExtensionAssetUrl(IconFamily)}') format('woff');
|
||||
font-weight: normal;
|
||||
font-style: normal;
|
||||
}`;
|
||||
@@ -22,13 +22,18 @@ function InjectCustomIcons() {
|
||||
|
||||
const mountPoint = document.getElementById("app");
|
||||
if (!mountPoint) {
|
||||
console.error("Mount point #app not found");
|
||||
throw new Error("Mount point #app not found");
|
||||
// In production, Rollup may put this entry in a shared chunk that content
|
||||
// scripts load via `import("@/interface/main")`. Only the settings page
|
||||
// has `#app` — never throw on SEQTA tabs.
|
||||
verboseInfo(
|
||||
"[BetterSEQTA+] Settings bootstrap skipped (no #app — not the settings page)",
|
||||
);
|
||||
} else {
|
||||
InjectCustomIcons();
|
||||
|
||||
void (async () => {
|
||||
await initializeSettingsState();
|
||||
initVerboseLogging();
|
||||
renderSvelte(Settings, mountPoint, { standalone: true });
|
||||
})();
|
||||
}
|
||||
|
||||
InjectCustomIcons();
|
||||
|
||||
(async () => {
|
||||
await initializeSettingsState();
|
||||
renderSvelte(Settings, mountPoint, { standalone: true });
|
||||
})();
|
||||
Vendored
-2
@@ -1,5 +1,3 @@
|
||||
import "./index.css";
|
||||
|
||||
declare module "*.png";
|
||||
declare module "*.svg";
|
||||
declare module "*.jpeg";
|
||||
|
||||
+18
-7
@@ -1,12 +1,29 @@
|
||||
import { mount } from "svelte";
|
||||
import type { SvelteComponent } from "svelte";
|
||||
import style from "./index.css?inline";
|
||||
import settingsStyle from "./index.css?inline";
|
||||
import contentShadowStyle from "./contentShadow.css?inline";
|
||||
|
||||
const shadowStyles = {
|
||||
settings: settingsStyle,
|
||||
content: contentShadowStyle,
|
||||
} as const;
|
||||
|
||||
export type ShadowStyleVariant = keyof typeof shadowStyles;
|
||||
|
||||
export default function renderSvelte(
|
||||
Component: SvelteComponent | any,
|
||||
mountPoint: ShadowRoot | HTMLElement,
|
||||
props: Record<string, any> = {},
|
||||
shadowStyle: ShadowStyleVariant = "settings",
|
||||
) {
|
||||
if (mountPoint instanceof ShadowRoot || props.standalone === true) {
|
||||
const styleElement = document.createElement("style");
|
||||
styleElement.textContent = shadowStyles[shadowStyle];
|
||||
(mountPoint instanceof ShadowRoot ? mountPoint : document.head).appendChild(
|
||||
styleElement,
|
||||
);
|
||||
}
|
||||
|
||||
const app = mount(Component, {
|
||||
target: mountPoint,
|
||||
props: {
|
||||
@@ -15,11 +32,5 @@ export default function renderSvelte(
|
||||
},
|
||||
});
|
||||
|
||||
if (mountPoint instanceof ShadowRoot) {
|
||||
const styleElement = document.createElement("style");
|
||||
styleElement.textContent = style;
|
||||
mountPoint.appendChild(styleElement);
|
||||
}
|
||||
|
||||
return app;
|
||||
}
|
||||
+488
-243
@@ -1,24 +1,35 @@
|
||||
<script lang="ts">
|
||||
import TabbedContainer from "../components/TabbedContainer.svelte";
|
||||
import Settings from "./settings/general.svelte";
|
||||
import Shortcuts from "./settings/shortcuts.svelte";
|
||||
import Theme from "./settings/theme.svelte";
|
||||
import browser from "webextension-polyfill";
|
||||
import Store from "./store.svelte";
|
||||
import TabbedContainer from "../components/TabbedContainer.svelte";
|
||||
import darkLogo from "@/resources/icons/betterseqta-dark-full.png";
|
||||
import lightLogo from "@/resources/icons/betterseqta-light-full.png";
|
||||
import { resolveExtensionAssetUrl } from "@/lib/extensionAssetUrl";
|
||||
|
||||
import { standalone as StandaloneStore } from "../utils/standalone.svelte";
|
||||
import { onMount } from "svelte";
|
||||
import { onMount, onDestroy } from "svelte";
|
||||
import { settingsState } from "@/seqta/utils/listeners/SettingsState";
|
||||
|
||||
import { closeExtensionPopup } from "@/seqta/utils/Closers/closeExtensionPopup";
|
||||
import { OpenAboutPage } from "@/seqta/utils/Openers/OpenAboutPage";
|
||||
import { OpenWhatsNewPopup } from "@/seqta/utils/Openers/OpenWhatsNewPopup";
|
||||
//import { OpenMinecraftServerPopup } from "@/seqta/utils/Openers/OpenMinecraftServerPopup";
|
||||
|
||||
import ColourPicker from "../components/ColourPicker.svelte";
|
||||
import type { Component } from "svelte";
|
||||
import FontPickerModal from "../components/FontPickerModal.svelte";
|
||||
import CloudPanel from "../components/CloudPanel.svelte";
|
||||
import DisclaimerModal from "../components/DisclaimerModal.svelte";
|
||||
import { settingsPopup } from "../hooks/SettingsPopup";
|
||||
import FeedbackModal from "../components/FeedbackModal.svelte";
|
||||
import SidebarNav from "../components/SidebarNav.svelte";
|
||||
import StoreHeader from "../components/store/Header.svelte";
|
||||
import { settingsPopup } from "@/seqta/utils/settingsPopup";
|
||||
import { consumeOpenFeedbackRequest } from "@/seqta/utils/feedback/client";
|
||||
import {
|
||||
consumeSettingsDestination,
|
||||
SETTINGS_NAVIGATION_EVENT,
|
||||
type SettingsDestination,
|
||||
} from "@/seqta/utils/settingsNavigation";
|
||||
import {
|
||||
checkGithubReleaseUpdate,
|
||||
dismissNightlyUpdate,
|
||||
@@ -26,20 +37,126 @@
|
||||
isGhReleaseUpdateCheckEnabled,
|
||||
type GhReleaseUpdateInfo,
|
||||
} from "@/utils/githubReleaseUpdate";
|
||||
type PageId = "settings" | "themes" | "backgrounds";
|
||||
type StoreTab = "themes" | "backgrounds";
|
||||
type ThemeView = "theme-settings" | "theme-store";
|
||||
type BackgroundView = "background-settings" | "background-store";
|
||||
|
||||
type NavItem = {
|
||||
id: string;
|
||||
label: string;
|
||||
divided?: boolean;
|
||||
nested?: boolean;
|
||||
expanded?: boolean;
|
||||
};
|
||||
|
||||
const BACKGROUND_CATEGORY_PREFIX = "background-category:";
|
||||
|
||||
let devModeSequence = "";
|
||||
let settingsActiveTab = $state(0);
|
||||
let compactActiveTab = $state(0);
|
||||
let activePage = $state<PageId>("settings");
|
||||
let activeSection = $state("general");
|
||||
let activeThemeView = $state<ThemeView>("theme-store");
|
||||
let activeBackgroundView = $state<BackgroundView>("background-settings");
|
||||
let selectedBackgroundCategory = $state("All");
|
||||
let backgroundCategories = $state<string[]>([]);
|
||||
let storeSearchTerm = $state("");
|
||||
let settingsSearch = $state("");
|
||||
|
||||
let showDisclaimerModal = $state(false);
|
||||
let disclaimerCallbacks = $state<{ onConfirm: () => void, onCancel: () => void } | null>(null);
|
||||
let disclaimerCallbacks = $state<{ onConfirm: () => void; onCancel: () => void } | null>(null);
|
||||
let disclaimerTitle = $state("Confirm");
|
||||
let disclaimerMessage = $state("");
|
||||
const ghReleaseUpdateEnabled = isGhReleaseUpdateCheckEnabled();
|
||||
const ghReleaseChannelLabel = getInstalledGhReleaseChannelLabel();
|
||||
let ghReleaseUpdate = $state<GhReleaseUpdateInfo | null>(null);
|
||||
|
||||
const userNav: NavItem[] = [
|
||||
{ id: "account", label: "My Account" },
|
||||
{ id: "general", label: "General" },
|
||||
{ id: "appearance", label: "Appearance" },
|
||||
];
|
||||
|
||||
const appNav: NavItem[] = [
|
||||
{ id: "timetable", label: "Timetable" },
|
||||
{ id: "assessments", label: "Assessments" },
|
||||
{ id: "features", label: "Features" },
|
||||
{ id: "advanced", label: "Advanced" },
|
||||
{ id: "shortcuts", label: "Shortcuts" },
|
||||
];
|
||||
|
||||
const settingsNavGroups = [
|
||||
{ label: "User Settings", items: userNav },
|
||||
{ label: "App Settings", items: appNav },
|
||||
];
|
||||
|
||||
const themeNavGroups = [
|
||||
{
|
||||
label: "Themes",
|
||||
items: [
|
||||
{ id: "theme-store", label: "Store" },
|
||||
{ id: "theme-settings", label: "Theme settings" },
|
||||
{ id: "create-theme", label: "Create theme" },
|
||||
],
|
||||
},
|
||||
];
|
||||
|
||||
const backgroundNavGroups = $derived.by(() => {
|
||||
const storeOpen = activeBackgroundView === "background-store";
|
||||
const categoryItems: NavItem[] = storeOpen
|
||||
? ["All", "Featured", ...backgroundCategories].map((category, index) => ({
|
||||
id: `${BACKGROUND_CATEGORY_PREFIX}${category}`,
|
||||
label: category,
|
||||
nested: true,
|
||||
divided: index === 2,
|
||||
}))
|
||||
: [];
|
||||
|
||||
return [
|
||||
{
|
||||
label: "Backgrounds",
|
||||
items: [
|
||||
{ id: "background-settings", label: "Background settings" },
|
||||
{ id: "background-store", label: "Store", expanded: storeOpen },
|
||||
...categoryItems,
|
||||
],
|
||||
},
|
||||
];
|
||||
});
|
||||
|
||||
const navGroups = $derived(
|
||||
activePage === "settings"
|
||||
? settingsNavGroups
|
||||
: activePage === "themes"
|
||||
? themeNavGroups
|
||||
: backgroundNavGroups,
|
||||
);
|
||||
|
||||
const selectedNavId = $derived(
|
||||
activePage === "settings"
|
||||
? activeSection
|
||||
: activePage === "themes"
|
||||
? activeThemeView
|
||||
: activeBackgroundView === "background-store"
|
||||
? `${BACKGROUND_CATEGORY_PREFIX}${selectedBackgroundCategory}`
|
||||
: activeBackgroundView,
|
||||
);
|
||||
|
||||
const sectionTitle = $derived.by(() => {
|
||||
if (activePage === "settings" && settingsSearch.trim()) return "Search results";
|
||||
if (activePage === "themes") return "Themes";
|
||||
if (activePage === "backgrounds") return "Backgrounds";
|
||||
return [...userNav, ...appNav].find((item) => item.id === activeSection)?.label ?? "Settings";
|
||||
});
|
||||
|
||||
const isStoreView = $derived(
|
||||
(activePage === "themes" && activeThemeView === "theme-store") ||
|
||||
(activePage === "backgrounds" && activeBackgroundView === "background-store"),
|
||||
);
|
||||
|
||||
const openGhRelease = () => {
|
||||
const url = ghReleaseUpdate?.url
|
||||
?? "https://github.com/BetterSEQTA/BetterSEQTA-Plus/releases";
|
||||
const url =
|
||||
ghReleaseUpdate?.url ?? "https://github.com/BetterSEQTA/BetterSEQTA-Plus/releases";
|
||||
if (ghReleaseUpdate?.available) {
|
||||
dismissNightlyUpdate();
|
||||
}
|
||||
@@ -64,7 +181,12 @@
|
||||
}, 10000);
|
||||
};
|
||||
|
||||
const openColourPicker = () => {
|
||||
let ColourPickerComponent = $state<Component | null>(null);
|
||||
|
||||
const openColourPicker = async () => {
|
||||
if (!ColourPickerComponent) {
|
||||
ColourPickerComponent = (await import("../components/ColourPicker.svelte")).default;
|
||||
}
|
||||
showColourPicker = true;
|
||||
};
|
||||
|
||||
@@ -82,11 +204,6 @@
|
||||
closeExtensionPopup();
|
||||
};
|
||||
|
||||
/* const openMinecraftServer = () => {
|
||||
OpenMinecraftServerPopup();
|
||||
closeExtensionPopup();
|
||||
}; */
|
||||
|
||||
const openPrivacyStatement = () => {
|
||||
window.open("https://betterseqta.org/privacy", "_blank");
|
||||
closeExtensionPopup();
|
||||
@@ -96,24 +213,94 @@
|
||||
let showColourPicker = $state<boolean>(false);
|
||||
let showFontPicker = $state<boolean>(false);
|
||||
let showCloudPanel = $state<boolean>(false);
|
||||
let showFeedbackModal = $state<boolean>(false);
|
||||
let feedbackFocusId = $state<string | null>(null);
|
||||
|
||||
const openCloudPanel = () => {
|
||||
showCloudPanel = true;
|
||||
};
|
||||
|
||||
const showDisclaimer = (onConfirm: () => void, onCancel: () => void, title?: string, message?: string) => {
|
||||
const openFeedback = (feedbackId?: string | null) => {
|
||||
feedbackFocusId = typeof feedbackId === "string" && feedbackId ? feedbackId : null;
|
||||
showFeedbackModal = true;
|
||||
};
|
||||
|
||||
const showDisclaimer = (
|
||||
onConfirm: () => void,
|
||||
onCancel: () => void,
|
||||
title = "Confirm",
|
||||
message = "",
|
||||
) => {
|
||||
disclaimerCallbacks = { onConfirm, onCancel };
|
||||
disclaimerTitle = title ?? "Confirm";
|
||||
disclaimerMessage = message ?? "";
|
||||
disclaimerTitle = title;
|
||||
disclaimerMessage = message;
|
||||
showDisclaimerModal = true;
|
||||
};
|
||||
|
||||
const closePopupsOnSettingsClose = () => {
|
||||
showColourPicker = false;
|
||||
showFontPicker = false;
|
||||
showCloudPanel = false;
|
||||
showFeedbackModal = false;
|
||||
feedbackFocusId = null;
|
||||
};
|
||||
|
||||
const handleClose = () => {
|
||||
if (!standalone) {
|
||||
closeExtensionPopup();
|
||||
}
|
||||
};
|
||||
|
||||
const selectNavItem = (id: string) => {
|
||||
if (activePage === "settings") {
|
||||
settingsSearch = "";
|
||||
activeSection = id;
|
||||
return;
|
||||
}
|
||||
|
||||
if (activePage === "themes") {
|
||||
if (id === "create-theme") {
|
||||
void openThemeCreator();
|
||||
} else {
|
||||
activeThemeView = id as ThemeView;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (id.startsWith(BACKGROUND_CATEGORY_PREFIX)) {
|
||||
activeBackgroundView = "background-store";
|
||||
selectedBackgroundCategory = id.slice(BACKGROUND_CATEGORY_PREFIX.length);
|
||||
} else {
|
||||
activeBackgroundView = id as BackgroundView;
|
||||
}
|
||||
};
|
||||
|
||||
const openThemeCreator = async () => {
|
||||
const { OpenThemeCreator } = await import("@/plugins/built-in/themes/ThemeCreator");
|
||||
OpenThemeCreator();
|
||||
closeExtensionPopup();
|
||||
};
|
||||
|
||||
const applyDestination = (destination: SettingsDestination) => {
|
||||
activePage = destination.page;
|
||||
if (destination.page === "settings" && destination.section) {
|
||||
settingsSearch = "";
|
||||
activeSection = destination.section;
|
||||
} else if (destination.page === "themes" && destination.view) {
|
||||
activeThemeView = destination.view === "store" ? "theme-store" : "theme-settings";
|
||||
} else if (destination.page === "backgrounds" && destination.view) {
|
||||
activeBackgroundView = destination.view === "store" ? "background-store" : "background-settings";
|
||||
}
|
||||
};
|
||||
|
||||
const utilityActions = [
|
||||
{ label: "About", icon: "\ueb73", onclick: openAbout },
|
||||
{ label: "What's new", icon: "\ue929", onclick: openChangelog },
|
||||
{ label: "Privacy", icon: "\uecba", onclick: openPrivacyStatement },
|
||||
] as const;
|
||||
|
||||
onMount(() => {
|
||||
settingsPopup.addListener(() => {
|
||||
showColourPicker = false;
|
||||
showFontPicker = false;
|
||||
showCloudPanel = false;
|
||||
});
|
||||
settingsPopup.addListener(closePopupsOnSettingsClose);
|
||||
|
||||
if (standalone) {
|
||||
StandaloneStore.setStandalone(true);
|
||||
@@ -124,255 +311,303 @@
|
||||
ghReleaseUpdate = info;
|
||||
});
|
||||
}
|
||||
|
||||
const pendingFeedbackId = consumeOpenFeedbackRequest();
|
||||
if (pendingFeedbackId) {
|
||||
openFeedback(pendingFeedbackId);
|
||||
}
|
||||
|
||||
const onOpenFeedback = (event: Event) => {
|
||||
const id = (event as CustomEvent<{ id?: string }>).detail?.id;
|
||||
if (typeof id === "string" && id) openFeedback(id);
|
||||
};
|
||||
window.addEventListener("bsplus:open-feedback", onOpenFeedback);
|
||||
|
||||
const onNavigateSettings = (event: Event) => {
|
||||
applyDestination((event as CustomEvent<SettingsDestination>).detail);
|
||||
consumeSettingsDestination();
|
||||
};
|
||||
window.addEventListener(SETTINGS_NAVIGATION_EVENT, onNavigateSettings);
|
||||
const pendingDestination = consumeSettingsDestination();
|
||||
if (pendingDestination) applyDestination(pendingDestination);
|
||||
|
||||
const onKeyDown = (event: KeyboardEvent) => {
|
||||
if (event.key === "Escape" && !standalone) {
|
||||
closeExtensionPopup();
|
||||
}
|
||||
};
|
||||
window.addEventListener("keydown", onKeyDown);
|
||||
|
||||
return () => {
|
||||
window.removeEventListener("keydown", onKeyDown);
|
||||
window.removeEventListener("bsplus:open-feedback", onOpenFeedback);
|
||||
window.removeEventListener(SETTINGS_NAVIGATION_EVENT, onNavigateSettings);
|
||||
};
|
||||
});
|
||||
|
||||
onDestroy(() => {
|
||||
settingsPopup.removeListener(closePopupsOnSettingsClose);
|
||||
});
|
||||
</script>
|
||||
|
||||
<div
|
||||
class="relative w-[384px] no-scrollbar shadow-2xl {$settingsState.DarkMode
|
||||
? 'dark'
|
||||
: ''} {standalone ? 'h-[600px]' : 'h-full rounded-xl'} overflow-clip"
|
||||
>
|
||||
{#snippet settingsShell()}
|
||||
<div
|
||||
class="flex relative flex-col gap-2 h-full overflow-clip bg-white dark:bg-zinc-800 dark:text-white"
|
||||
class="flex flex-col h-full min-h-0 overflow-hidden bg-white dark:bg-zinc-800 dark:text-white text-[18px] {standalone
|
||||
? ''
|
||||
: 'rounded-xl shadow-2xl border border-zinc-200/60 dark:border-zinc-700/60'}"
|
||||
>
|
||||
<div
|
||||
class="grid place-items-center border-b border-b-zinc-200/40 dark:border-b-zinc-700/40"
|
||||
>
|
||||
<!-- svelte-ignore a11y_no_noninteractive_element_interactions -->
|
||||
<!-- svelte-ignore a11y_click_events_have_key_events -->
|
||||
<img
|
||||
src={browser.runtime.getURL(
|
||||
"resources/icons/betterseqta-dark-full.png",
|
||||
)}
|
||||
class="w-4/5 dark:hidden"
|
||||
alt="Light logo"
|
||||
onclick={handleDevModeToggle}
|
||||
/>
|
||||
<!-- svelte-ignore a11y_no_noninteractive_element_interactions -->
|
||||
<!-- svelte-ignore a11y_click_events_have_key_events -->
|
||||
<img
|
||||
src={browser.runtime.getURL(
|
||||
"resources/icons/betterseqta-light-full.png",
|
||||
)}
|
||||
class="hidden w-4/5 dark:block"
|
||||
alt="Dark logo"
|
||||
onclick={handleDevModeToggle}
|
||||
/>
|
||||
<StoreHeader
|
||||
searchTerm={storeSearchTerm}
|
||||
setSearchTerm={(term) => (storeSearchTerm = term)}
|
||||
{activePage}
|
||||
setActivePage={(page) => {
|
||||
activePage = page;
|
||||
if (page === "themes") activeThemeView = "theme-store";
|
||||
}}
|
||||
showStoreTools={isStoreView}
|
||||
onLogoClick={handleDevModeToggle}
|
||||
onClose={handleClose}
|
||||
/>
|
||||
|
||||
{#if !standalone}
|
||||
<div class="flex absolute top-1 right-1 gap-1 items-start">
|
||||
<!-- Body: left nav + content -->
|
||||
<div class="flex flex-1 min-h-0 overflow-hidden">
|
||||
<nav
|
||||
class="flex flex-col shrink-0 min-h-0 border-r border-zinc-200/60 dark:border-zinc-700/50 bg-zinc-50/80 dark:bg-zinc-900/40 {standalone
|
||||
? 'w-[140px] px-2 py-3'
|
||||
: 'w-[260px] px-4 py-5'}"
|
||||
aria-label="Settings categories"
|
||||
>
|
||||
{#if activePage === "settings"}
|
||||
<label class="relative mb-4 block shrink-0">
|
||||
<span class="sr-only">Search settings</span>
|
||||
<svg
|
||||
class="pointer-events-none absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-zinc-400"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
viewBox="0 0 24 24"
|
||||
aria-hidden="true"
|
||||
>
|
||||
<path
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round"
|
||||
stroke-width="2"
|
||||
d="m21 21-4.35-4.35m1.35-5.65a7 7 0 1 1-14 0 7 7 0 0 1 14 0Z"
|
||||
/>
|
||||
</svg>
|
||||
<input
|
||||
type="search"
|
||||
placeholder="Search settings"
|
||||
bind:value={settingsSearch}
|
||||
class="h-10 w-full rounded-lg bg-zinc-200/70 pl-9 pr-3 text-sm text-zinc-900 placeholder:text-zinc-400 transition-colors duration-200 focus:bg-white focus:outline-none focus:ring-2 focus:ring-zinc-400 focus:ring-offset-2 dark:bg-zinc-800/80 dark:text-white dark:placeholder:text-zinc-500 dark:focus:bg-zinc-800 dark:focus:ring-offset-zinc-900"
|
||||
/>
|
||||
</label>
|
||||
{/if}
|
||||
|
||||
<SidebarNav
|
||||
groups={navGroups}
|
||||
selectedId={selectedNavId}
|
||||
onselect={selectNavItem}
|
||||
/>
|
||||
|
||||
<div class="mt-4 flex shrink-0 flex-col gap-1 border-t border-zinc-200/60 pt-4 dark:border-zinc-700/50">
|
||||
{#if ghReleaseUpdateEnabled}
|
||||
<div class="flex flex-col items-end gap-0.5 max-w-[9rem] mr-0.5">
|
||||
<div class="px-3 pb-2">
|
||||
{#if ghReleaseUpdate?.available}
|
||||
<button
|
||||
type="button"
|
||||
onclick={openGhRelease}
|
||||
class="px-1.5 py-0.5 text-[10px] font-semibold leading-tight text-white rounded-full bg-amber-500 hover:bg-amber-600 dark:bg-amber-600 dark:hover:bg-amber-500"
|
||||
class="mb-1 px-1.5 py-0.5 text-[10px] font-semibold leading-tight text-white rounded-full bg-amber-500 hover:bg-amber-600 dark:bg-amber-600 dark:hover:bg-amber-500 transition-colors duration-200"
|
||||
title="Open GitHub release"
|
||||
>
|
||||
Update available — {ghReleaseUpdate.label}
|
||||
Update — {ghReleaseUpdate.label}
|
||||
</button>
|
||||
{/if}
|
||||
<p class="text-[9px] leading-tight text-right text-zinc-500 dark:text-zinc-400">
|
||||
{#if ghReleaseChannelLabel}
|
||||
{ghReleaseChannelLabel} — do not upload to extension stores.
|
||||
{:else}
|
||||
GitHub release build — do not upload to extension stores.
|
||||
{/if}
|
||||
<p class="text-[9px] leading-tight text-zinc-500 dark:text-zinc-400">
|
||||
{ghReleaseChannelLabel ?? "GitHub build"} — do not upload to stores.
|
||||
</p>
|
||||
</div>
|
||||
{/if}
|
||||
<div class="flex gap-1 items-center">
|
||||
<button
|
||||
onclick={openAbout}
|
||||
class="flex justify-center items-center w-8 h-8 text-lg rounded-xl font-IconFamily bg-zinc-100 dark:bg-zinc-700"
|
||||
>
|
||||
{"\ueb73"}
|
||||
</button>
|
||||
|
||||
{#each utilityActions as action (action.label)}
|
||||
<button
|
||||
type="button"
|
||||
onclick={action.onclick}
|
||||
class="flex h-10 w-full items-center gap-3 rounded-lg px-3 text-left text-[16px] font-medium text-zinc-600 transition-[color,background-color,transform] duration-150 hover:bg-zinc-200/70 hover:text-zinc-950 active:scale-[0.96] focus:outline-none focus:ring-2 focus:ring-zinc-400 focus:ring-offset-2 dark:text-zinc-300 dark:hover:bg-zinc-700/70 dark:hover:text-white dark:focus:ring-offset-zinc-900"
|
||||
>
|
||||
<span class="w-5 text-center font-IconFamily text-[18px]" aria-hidden="true">{action.icon}</span>
|
||||
<span>{action.label}</span>
|
||||
</button>
|
||||
{/each}
|
||||
|
||||
<button
|
||||
onclick={openChangelog}
|
||||
class="flex justify-center items-center w-8 h-8 text-lg rounded-xl font-IconFamily bg-zinc-100 dark:bg-zinc-700"
|
||||
type="button"
|
||||
onclick={() => openFeedback()}
|
||||
class="mt-2 flex w-full items-center gap-3 rounded-lg bg-zinc-200/70 px-3 py-2.5 text-left text-[16px] font-medium text-zinc-700 transition-[color,background-color,transform] duration-150 hover:bg-zinc-300/80 active:scale-[0.96] focus:outline-none focus:ring-2 focus:ring-zinc-400 focus:ring-offset-2 dark:bg-zinc-800/80 dark:text-zinc-200 dark:hover:bg-zinc-700 dark:focus:ring-offset-zinc-900"
|
||||
>
|
||||
{"\ue929"}
|
||||
<svg
|
||||
class="w-5 h-5 shrink-0"
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
stroke-width="2"
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round"
|
||||
aria-hidden="true"
|
||||
>
|
||||
<path d="M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z" />
|
||||
</svg>
|
||||
<span>Send us feedback!</span>
|
||||
</button>
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
<button
|
||||
onclick={openPrivacyStatement}
|
||||
class="flex justify-center items-center w-8 h-8 text-lg rounded-xl font-IconFamily bg-zinc-100 dark:bg-zinc-700"
|
||||
aria-label="Privacy Statement"
|
||||
>
|
||||
{"\uecba"}
|
||||
</button>
|
||||
{#if isStoreView}
|
||||
<div class="min-w-0 min-h-0 flex-1">
|
||||
<Store
|
||||
activeTab={activePage as StoreTab}
|
||||
searchTerm={storeSearchTerm}
|
||||
{selectedBackgroundCategory}
|
||||
setActiveTab={(tab) => {
|
||||
activePage = tab;
|
||||
if (tab === "themes") activeThemeView = "theme-store";
|
||||
else activeBackgroundView = "background-store";
|
||||
}}
|
||||
setSearchTerm={(term) => (storeSearchTerm = term)}
|
||||
setBackgroundCategories={(categories) => (backgroundCategories = categories)}
|
||||
/>
|
||||
</div>
|
||||
{:else}
|
||||
<div class="flex flex-col flex-1 min-w-0 min-h-0">
|
||||
<div class="shrink-0 px-6 pt-5 pb-3">
|
||||
<h1 class="text-3xl font-semibold tracking-tight text-zinc-900 dark:text-white">
|
||||
{sectionTitle}
|
||||
</h1>
|
||||
</div>
|
||||
<div class="flex-1 min-h-0 px-4 pb-8 overflow-y-auto no-scrollbar">
|
||||
{#if activePage === "settings"}
|
||||
{#if activeSection === "shortcuts" && !settingsSearch.trim()}
|
||||
<Shortcuts />
|
||||
{:else}
|
||||
<Settings
|
||||
showColourPicker={openColourPicker}
|
||||
showFontPicker={openFontPicker}
|
||||
{showDisclaimer}
|
||||
showCloudPanel={openCloudPanel}
|
||||
activeSection={settingsSearch.trim() ? "all" : activeSection}
|
||||
searchQuery={settingsSearch}
|
||||
/>
|
||||
{#if settingsSearch.trim()}
|
||||
<Shortcuts searchQuery={settingsSearch} />
|
||||
{/if}
|
||||
{/if}
|
||||
{:else if activePage === "themes"}
|
||||
<Theme section="themes" />
|
||||
{:else}
|
||||
<Theme section="backgrounds" />
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
<!-- <button
|
||||
onclick={openMinecraftServer}
|
||||
class="flex justify-center items-center p-1 w-8 h-8 rounded-xl bg-zinc-100 dark:bg-zinc-700"
|
||||
aria-label="Open Minecraft Server"
|
||||
>
|
||||
<svg
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
viewBox="0 0 64 70"
|
||||
fill="none"
|
||||
class="w-full h-full"
|
||||
>
|
||||
<path
|
||||
d="M0 0 C3.96 0 7.92 0 12 0 C12 3.96 12 7.92 12 12 C10.68 12 9.36 12 8 12 C8 10.68 8 9.36 8 8 C6.68 8 5.36 8 4 8 C4 6.68 4 5.36 4 4 C2.68 4 1.36 4 0 4 C0 2.68 0 1.36 0 0 Z "
|
||||
fill="currentColor"
|
||||
transform="translate(42,10)"
|
||||
/>
|
||||
<path
|
||||
d="M0 0 C1.32 0 2.64 0 4 0 C4 6.6 4 13.2 4 20 C2.68 20 1.36 20 0 20 C0 13.4 0 6.8 0 0 Z "
|
||||
fill="currentColor"
|
||||
transform="translate(54,22)"
|
||||
/>
|
||||
<path
|
||||
d="M0 0 C6.6 0 13.2 0 20 0 C20 1.32 20 2.64 20 4 C13.4 4 6.8 4 0 4 C0 2.68 0 1.36 0 0 Z "
|
||||
fill="currentColor"
|
||||
transform="translate(22,6)"
|
||||
/>
|
||||
<path
|
||||
d="M0 0 C1.32 0 2.64 0 4 0 C4 5.28 4 10.56 4 16 C2.68 16 1.36 16 0 16 C0 10.72 0 5.44 0 0 Z "
|
||||
fill="currentColor"
|
||||
transform="translate(46,26)"
|
||||
/>
|
||||
<path
|
||||
d="M0 0 C5.28 0 10.56 0 16 0 C16 1.32 16 2.64 16 4 C10.72 4 5.44 4 0 4 C0 2.68 0 1.36 0 0 Z "
|
||||
fill="currentColor"
|
||||
transform="translate(22,14)"
|
||||
/>
|
||||
<path
|
||||
d="M0 0 C1.32 0 2.64 0 4 0 C4 1.32 4 2.64 4 4 C5.32 4 6.64 4 8 4 C8 5.32 8 6.64 8 8 C5.36 8 2.72 8 0 8 C0 5.36 0 2.72 0 0 Z "
|
||||
fill="currentColor"
|
||||
transform="translate(6,50)"
|
||||
/>
|
||||
<path
|
||||
d="M0 0 C1.32 0 2.64 0 4 0 C4 1.32 4 2.64 4 4 C2.68 4 1.36 4 0 4 C0 2.68 0 1.36 0 0 Z "
|
||||
fill="currentColor"
|
||||
transform="translate(14,50)"
|
||||
/>
|
||||
<path
|
||||
d="M0 0 C1.32 0 2.64 0 4 0 C4 1.32 4 2.64 4 4 C2.68 4 1.36 4 0 4 C0 2.68 0 1.36 0 0 Z "
|
||||
fill="currentColor"
|
||||
transform="translate(18,46)"
|
||||
/>
|
||||
<path
|
||||
d="M0 0 C1.32 0 2.64 0 4 0 C4 1.32 4 2.64 4 4 C2.68 4 1.36 4 0 4 C0 2.68 0 1.36 0 0 Z "
|
||||
fill="currentColor"
|
||||
transform="translate(10,46)"
|
||||
/>
|
||||
<path
|
||||
d="M0 0 C1.32 0 2.64 0 4 0 C4 1.32 4 2.64 4 4 C2.68 4 1.36 4 0 4 C0 2.68 0 1.36 0 0 Z "
|
||||
fill="currentColor"
|
||||
transform="translate(50,42)"
|
||||
/>
|
||||
<path
|
||||
d="M0 0 C1.32 0 2.64 0 4 0 C4 1.32 4 2.64 4 4 C2.68 4 1.36 4 0 4 C0 2.68 0 1.36 0 0 Z "
|
||||
fill="currentColor"
|
||||
transform="translate(22,42)"
|
||||
/>
|
||||
<path
|
||||
d="M0 0 C1.32 0 2.64 0 4 0 C4 1.32 4 2.64 4 4 C2.68 4 1.36 4 0 4 C0 2.68 0 1.36 0 0 Z "
|
||||
fill="currentColor"
|
||||
transform="translate(14,42)"
|
||||
/>
|
||||
<path
|
||||
d="M0 0 C1.32 0 2.64 0 4 0 C4 1.32 4 2.64 4 4 C2.68 4 1.36 4 0 4 C0 2.68 0 1.36 0 0 Z "
|
||||
fill="currentColor"
|
||||
transform="translate(26,38)"
|
||||
/>
|
||||
<path
|
||||
d="M0 0 C1.32 0 2.64 0 4 0 C4 1.32 4 2.64 4 4 C2.68 4 1.36 4 0 4 C0 2.68 0 1.36 0 0 Z "
|
||||
fill="currentColor"
|
||||
transform="translate(18,38)"
|
||||
/>
|
||||
<path
|
||||
d="M0 0 C1.32 0 2.64 0 4 0 C4 1.32 4 2.64 4 4 C2.68 4 1.36 4 0 4 C0 2.68 0 1.36 0 0 Z "
|
||||
fill="currentColor"
|
||||
transform="translate(30,34)"
|
||||
/>
|
||||
<path
|
||||
d="M0 0 C1.32 0 2.64 0 4 0 C4 1.32 4 2.64 4 4 C2.68 4 1.36 4 0 4 C0 2.68 0 1.36 0 0 Z "
|
||||
fill="currentColor"
|
||||
transform="translate(22,34)"
|
||||
/>
|
||||
<path
|
||||
d="M0 0 C1.32 0 2.64 0 4 0 C4 1.32 4 2.64 4 4 C2.68 4 1.36 4 0 4 C0 2.68 0 1.36 0 0 Z "
|
||||
fill="currentColor"
|
||||
transform="translate(34,30)"
|
||||
/>
|
||||
<path
|
||||
d="M0 0 C1.32 0 2.64 0 4 0 C4 1.32 4 2.64 4 4 C2.68 4 1.36 4 0 4 C0 2.68 0 1.36 0 0 Z "
|
||||
fill="currentColor"
|
||||
transform="translate(26,30)"
|
||||
/>
|
||||
<path
|
||||
d="M0 0 C1.32 0 2.64 0 4 0 C4 1.32 4 2.64 4 4 C2.68 4 1.36 4 0 4 C0 2.68 0 1.36 0 0 Z "
|
||||
fill="currentColor"
|
||||
transform="translate(38,26)"
|
||||
/>
|
||||
<path
|
||||
d="M0 0 C1.32 0 2.64 0 4 0 C4 1.32 4 2.64 4 4 C2.68 4 1.36 4 0 4 C0 2.68 0 1.36 0 0 Z "
|
||||
fill="currentColor"
|
||||
transform="translate(30,26)"
|
||||
/>
|
||||
<path
|
||||
d="M0 0 C1.32 0 2.64 0 4 0 C4 1.32 4 2.64 4 4 C2.68 4 1.36 4 0 4 C0 2.68 0 1.36 0 0 Z "
|
||||
fill="currentColor"
|
||||
transform="translate(42,22)"
|
||||
/>
|
||||
<path
|
||||
d="M0 0 C1.32 0 2.64 0 4 0 C4 1.32 4 2.64 4 4 C2.68 4 1.36 4 0 4 C0 2.68 0 1.36 0 0 Z "
|
||||
fill="currentColor"
|
||||
transform="translate(34,22)"
|
||||
/>
|
||||
<path
|
||||
d="M0 0 C1.32 0 2.64 0 4 0 C4 1.32 4 2.64 4 4 C2.68 4 1.36 4 0 4 C0 2.68 0 1.36 0 0 Z "
|
||||
fill="currentColor"
|
||||
transform="translate(38,18)"
|
||||
/>
|
||||
<path
|
||||
d="M0 0 C1.32 0 2.64 0 4 0 C4 1.32 4 2.64 4 4 C2.68 4 1.36 4 0 4 C0 2.68 0 1.36 0 0 Z "
|
||||
fill="currentColor"
|
||||
transform="translate(18,10)"
|
||||
/>
|
||||
</svg>
|
||||
</button> -->
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
<TabbedContainer
|
||||
bind:activeTab={settingsActiveTab}
|
||||
tabs={[
|
||||
{
|
||||
title: "Settings",
|
||||
Content: Settings,
|
||||
props: { showColourPicker: openColourPicker, showFontPicker: openFontPicker, showDisclaimer, showCloudPanel: openCloudPanel },
|
||||
},
|
||||
{ title: "Shortcuts", Content: Shortcuts },
|
||||
{ title: "Themes", Content: Theme },
|
||||
]}
|
||||
/>
|
||||
</div>
|
||||
{/snippet}
|
||||
|
||||
{#if showColourPicker}
|
||||
<ColourPicker
|
||||
hidePicker={() => {
|
||||
showColourPicker = false;
|
||||
}}
|
||||
/>
|
||||
{/if}
|
||||
{#snippet compactSettings()}
|
||||
<div
|
||||
class="flex h-full min-h-0 flex-col gap-2 overflow-hidden bg-white dark:bg-zinc-800 dark:text-white"
|
||||
>
|
||||
<div
|
||||
class="grid shrink-0 place-items-center border-b border-zinc-200/40 dark:border-zinc-700/40"
|
||||
>
|
||||
<!-- svelte-ignore a11y_no_noninteractive_element_interactions -->
|
||||
<!-- svelte-ignore a11y_click_events_have_key_events -->
|
||||
<img
|
||||
src={resolveExtensionAssetUrl(darkLogo)}
|
||||
class="w-4/5 dark:hidden"
|
||||
alt="BetterSEQTA+"
|
||||
onclick={handleDevModeToggle}
|
||||
/>
|
||||
<!-- svelte-ignore a11y_no_noninteractive_element_interactions -->
|
||||
<!-- svelte-ignore a11y_click_events_have_key_events -->
|
||||
<img
|
||||
src={resolveExtensionAssetUrl(lightLogo)}
|
||||
class="hidden w-4/5 dark:block"
|
||||
alt="BetterSEQTA+"
|
||||
onclick={handleDevModeToggle}
|
||||
/>
|
||||
</div>
|
||||
|
||||
{#if showCloudPanel}
|
||||
<CloudPanel
|
||||
hidePanel={() => {
|
||||
showCloudPanel = false;
|
||||
}}
|
||||
/>
|
||||
{/if}
|
||||
</div>
|
||||
<div class="min-h-0 flex-1 overflow-hidden">
|
||||
<TabbedContainer
|
||||
bind:activeTab={compactActiveTab}
|
||||
tabs={[
|
||||
{
|
||||
title: "Settings",
|
||||
Content: Settings,
|
||||
props: {
|
||||
showColourPicker: openColourPicker,
|
||||
showFontPicker: openFontPicker,
|
||||
showDisclaimer,
|
||||
showCloudPanel: openCloudPanel,
|
||||
activeSection: "all",
|
||||
},
|
||||
},
|
||||
{ title: "Shortcuts", Content: Shortcuts },
|
||||
{ title: "Themes", Content: Theme },
|
||||
]}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
{/snippet}
|
||||
|
||||
{#if standalone}
|
||||
<div
|
||||
class="relative w-[384px] h-[600px] no-scrollbar shadow-2xl overflow-clip {$settingsState.DarkMode
|
||||
? 'dark'
|
||||
: ''}"
|
||||
>
|
||||
{@render compactSettings()}
|
||||
</div>
|
||||
{:else}
|
||||
<div
|
||||
class="absolute inset-0 z-50 flex items-center justify-center p-4 sm:p-6 {$settingsState.DarkMode
|
||||
? 'dark'
|
||||
: ''}"
|
||||
role="dialog"
|
||||
aria-modal="true"
|
||||
aria-label="BetterSEQTA+ settings"
|
||||
>
|
||||
<button
|
||||
type="button"
|
||||
class="absolute inset-0 bg-black/60 backdrop-blur-sm transition-colors duration-200"
|
||||
aria-label="Close settings"
|
||||
onclick={handleClose}
|
||||
></button>
|
||||
|
||||
<div
|
||||
class="relative z-10 w-[min(1180px,96vw)] h-[min(860px,92vh)] no-scrollbar overflow-clip"
|
||||
data-settings-panel
|
||||
>
|
||||
{@render settingsShell()}
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
{#if showColourPicker && ColourPickerComponent}
|
||||
<ColourPickerComponent
|
||||
hidePicker={() => {
|
||||
showColourPicker = false;
|
||||
}}
|
||||
/>
|
||||
{/if}
|
||||
|
||||
{#if showCloudPanel}
|
||||
<CloudPanel
|
||||
hidePanel={() => {
|
||||
showCloudPanel = false;
|
||||
}}
|
||||
/>
|
||||
{/if}
|
||||
|
||||
{#if showFontPicker}
|
||||
<FontPickerModal
|
||||
@@ -398,3 +633,13 @@
|
||||
}}
|
||||
/>
|
||||
{/if}
|
||||
|
||||
{#if showFeedbackModal}
|
||||
<FeedbackModal
|
||||
initialFeedbackId={feedbackFocusId}
|
||||
onClose={() => {
|
||||
showFeedbackModal = false;
|
||||
feedbackFocusId = null;
|
||||
}}
|
||||
/>
|
||||
{/if}
|
||||
@@ -10,6 +10,7 @@
|
||||
import type { SettingsList } from "@/interface/types/SettingsProps"
|
||||
import { settingsState } from "@/seqta/utils/listeners/SettingsState.ts"
|
||||
import PickerSwatch from "@/interface/components/PickerSwatch.svelte"
|
||||
import SidebarAppearance from "@/interface/components/SidebarAppearance.svelte"
|
||||
import ConnectMobileApp from "@/interface/components/ConnectMobileApp.svelte"
|
||||
import CloudSettingsSync from "@/interface/components/CloudSettingsSync.svelte"
|
||||
import CloudHeader from "@/interface/components/store/CloudHeader.svelte"
|
||||
@@ -19,6 +20,7 @@
|
||||
import { closeExtensionPopup } from "@/seqta/utils/Closers/closeExtensionPopup"
|
||||
import { getSnapshotForUpload } from "@/seqta/utils/cloudSettingsSync"
|
||||
import { getStoredOverride, setApiBase } from "@/seqta/utils/DevApiBase"
|
||||
import { onMount } from "svelte"
|
||||
|
||||
let devApiBaseInput = $state<string>(getStoredOverride() ?? "")
|
||||
let devApiBaseActive = $state<string | null>(getStoredOverride())
|
||||
@@ -46,6 +48,8 @@
|
||||
|
||||
import { getAllPluginSettings } from "@/plugins"
|
||||
import { isSeqtaEngageExperience } from "@/seqta/utils/isSeqtaEngage"
|
||||
|
||||
const isEngage = isSeqtaEngageExperience();
|
||||
import type { BooleanSetting, StringSetting, NumberSetting, SelectSetting, ButtonSetting, HotkeySetting, ComponentSetting } from "@/plugins/core/types"
|
||||
|
||||
// Union type representing all possible settings
|
||||
@@ -128,17 +132,50 @@
|
||||
await browser.storage.local.set({ [storageKey]: currentSettings });
|
||||
}
|
||||
|
||||
$effect(() => {
|
||||
loadPluginSettings();
|
||||
})
|
||||
onMount(() => {
|
||||
void loadPluginSettings();
|
||||
});
|
||||
|
||||
const { showColourPicker, showFontPicker, showDisclaimer, showCloudPanel } = $props<{
|
||||
const { showColourPicker, showFontPicker, showDisclaimer, showCloudPanel, activeSection = "general", searchQuery = "" } = $props<{
|
||||
showColourPicker: () => void;
|
||||
showFontPicker: () => void;
|
||||
showDisclaimer: (onConfirm: () => void, onCancel: () => void, title?: string, message?: string) => void;
|
||||
showCloudPanel: () => void;
|
||||
activeSection?: string;
|
||||
searchQuery?: string;
|
||||
}>();
|
||||
|
||||
/** Map each plugin into the settings sidebar category that fits its purpose. */
|
||||
const pluginSectionById: Record<string, string> = {
|
||||
"profile-picture": "account",
|
||||
"animated-background": "appearance",
|
||||
"background-music": "appearance",
|
||||
timetable: "timetable",
|
||||
timetableEdit: "timetable",
|
||||
"assessments-overview": "assessments",
|
||||
"assessments-average": "assessments",
|
||||
"grade-analytics": "assessments",
|
||||
"global-search": "features",
|
||||
"enhanced-navigation": "features",
|
||||
messageFolders: "features",
|
||||
notificationCollector: "features",
|
||||
};
|
||||
|
||||
const showsSection = (section: string) =>
|
||||
activeSection === "all" || activeSection === section;
|
||||
|
||||
const pluginBelongsInSection = (pluginId: string) =>
|
||||
activeSection === "all" ||
|
||||
(pluginSectionById[pluginId] ?? "features") === activeSection;
|
||||
|
||||
const matchesSearch = (...parts: Array<string | undefined>) => {
|
||||
const q = searchQuery.trim().toLowerCase();
|
||||
return !q || parts.some((part) => part?.toLowerCase().includes(q));
|
||||
};
|
||||
|
||||
const pluginHit = (plugin: Plugin) =>
|
||||
matchesSearch(plugin.name, plugin.description, ...Object.values(plugin.settings).flatMap((s) => [s.title, s.description]));
|
||||
|
||||
async function exportCloudSettingsJsonToFile() {
|
||||
const payload = await getSnapshotForUpload();
|
||||
const blob = new Blob([JSON.stringify(payload, null, 2)], {
|
||||
@@ -154,192 +191,305 @@
|
||||
</script>
|
||||
|
||||
{#snippet Setting({ title, description, Component, props }: SettingsList) }
|
||||
<div class="flex justify-between items-center px-4 py-3">
|
||||
<div class="pr-4">
|
||||
<h2 class="text-sm font-bold">{title}</h2>
|
||||
<p class="text-xs">{description}</p>
|
||||
{#if matchesSearch(title, description)}
|
||||
<div class="flex justify-between items-center px-5 py-5">
|
||||
<div class="pr-5">
|
||||
<h2 class="text-xl font-bold">{title}</h2>
|
||||
<p class="text-base text-zinc-600 dark:text-zinc-300">{description}</p>
|
||||
</div>
|
||||
<div>
|
||||
<div class="shrink-0">
|
||||
<Component {...props} />
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
{/snippet}
|
||||
|
||||
<div class="flex flex-col divide-y divide-zinc-100 dark:divide-zinc-700">
|
||||
{#each [
|
||||
{
|
||||
{#if showsSection("account")}
|
||||
{@render Setting({
|
||||
title: "Connect Mobile App",
|
||||
description: "Link your SEQTA session to DesQTA — the modern desktop and mobile app for SEQTA Learn",
|
||||
id: 0,
|
||||
Component: ConnectMobileApp,
|
||||
props: {}
|
||||
},
|
||||
{
|
||||
title: "Edit Sidebar Layout",
|
||||
description: "Reorder pages on the sidebar",
|
||||
id: 5,
|
||||
Component: Button,
|
||||
props: {
|
||||
onClick: () => browser.runtime.sendMessage({ type: 'currentTab', info: 'EditSidebar' }),
|
||||
text: "Edit"
|
||||
}
|
||||
},
|
||||
{
|
||||
title: "Custom Theme Colour",
|
||||
description: "Customise the overall theme colour of SEQTA Learn",
|
||||
id: 4,
|
||||
Component: PickerSwatch,
|
||||
props: {
|
||||
onClick: showColourPicker
|
||||
}
|
||||
},
|
||||
{
|
||||
title: "Interface Font",
|
||||
description: "Choose the typeface used across SEQTA Learn",
|
||||
id: 16,
|
||||
Component: Button,
|
||||
props: {
|
||||
onClick: showFontPicker,
|
||||
text: "Change"
|
||||
}
|
||||
},
|
||||
{
|
||||
title: "Icon Only Sidebar",
|
||||
description: "Show only icons in the sidebar for a compact layout",
|
||||
id: 14,
|
||||
Component: Switch,
|
||||
props: {
|
||||
state: $settingsState.iconOnlySidebar ?? false,
|
||||
onChange: (isOn: boolean) => settingsState.iconOnlySidebar = isOn
|
||||
}
|
||||
},
|
||||
{
|
||||
title: "Animations",
|
||||
description: "Enable animations on certain pages",
|
||||
id: 6,
|
||||
Component: Switch,
|
||||
props: {
|
||||
state: $settingsState.animations,
|
||||
onChange: (isOn: boolean) => settingsState.animations = isOn
|
||||
}
|
||||
},
|
||||
{
|
||||
title: "12 Hour Time",
|
||||
description: "Prefer 12 hour time format for SEQTA",
|
||||
id: 9,
|
||||
Component: Switch,
|
||||
props: {
|
||||
state: $settingsState.timeFormat === "12",
|
||||
onChange: (isOn: boolean) => settingsState.timeFormat = isOn ? "12" : "24"
|
||||
}
|
||||
},
|
||||
{
|
||||
title: "Transparency Effects",
|
||||
description: "Enable transparency effects on certain elements, such as blur (May impact battery life)",
|
||||
id: 1,
|
||||
Component: Switch,
|
||||
props: {
|
||||
state: $settingsState.transparencyEffects,
|
||||
onChange: (isOn: boolean) => settingsState.transparencyEffects = isOn
|
||||
}
|
||||
},
|
||||
{
|
||||
title: "Default Page",
|
||||
description: "Choose which page loads first when you open SEQTA",
|
||||
id: 10,
|
||||
Component: Select,
|
||||
props: {
|
||||
state: $settingsState.defaultPage ?? "home",
|
||||
onChange: (value: string) => (settingsState.defaultPage = value),
|
||||
options: [
|
||||
{ value: "home", label: "Home" },
|
||||
{ value: "dashboard", label: "Dashboard" },
|
||||
{ value: "timetable", label: "Timetable" },
|
||||
{ value: "welcome", label: "Welcome" },
|
||||
{ value: "messages", label: "Messages" },
|
||||
{ value: "documents", label: "Documents" },
|
||||
{ value: "reports", label: "Reports" },
|
||||
],
|
||||
})}
|
||||
|
||||
{#if matchesSearch("BetterSEQTA Cloud", "Account & sync")}
|
||||
<div class="border-none">
|
||||
<div class="p-1 my-1 from-white to-zinc-100 bg-gradient-to-br rounded-xl border shadow-sm border-zinc-200/50 dark:border-zinc-700/40 dark:to-zinc-900/50 dark:from-zinc-900/40">
|
||||
<div class="flex justify-between items-center px-5 py-4">
|
||||
<div class="pr-4">
|
||||
<h2 class="text-xl font-bold">BetterSEQTA Cloud</h2>
|
||||
<p class="text-base text-zinc-600 dark:text-zinc-300">Account & sync</p>
|
||||
</div>
|
||||
<div>
|
||||
<CloudHeader alwaysShowUserName onClick={showCloudPanel} />
|
||||
</div>
|
||||
</div>
|
||||
{#if cloudState.isLoggedIn}
|
||||
<div class="px-3 pb-3">
|
||||
<CloudSettingsSync showDisclaimer={(onConfirm, onCancel) => showDisclaimer(onConfirm, onCancel, "Restore from cloud?", "This will replace your local settings with the cloud backup. Continue?")} />
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
{/if}
|
||||
|
||||
{#if showsSection("general")}
|
||||
{#each [
|
||||
...(!isEngage
|
||||
? [
|
||||
{
|
||||
title: "Edit Sidebar Layout",
|
||||
description: "Reorder pages on the sidebar",
|
||||
id: 5,
|
||||
Component: Button,
|
||||
props: {
|
||||
onClick: () => browser.runtime.sendMessage({ type: 'currentTab', info: 'EditSidebar' }),
|
||||
text: "Edit"
|
||||
}
|
||||
},
|
||||
{
|
||||
title: "Icon Only Sidebar",
|
||||
description: "Show only icons in the sidebar for a compact layout",
|
||||
id: 14,
|
||||
Component: Switch,
|
||||
props: {
|
||||
state: $settingsState.iconOnlySidebar ?? false,
|
||||
onChange: (isOn: boolean) => settingsState.iconOnlySidebar = isOn
|
||||
}
|
||||
},
|
||||
]
|
||||
: []),
|
||||
{
|
||||
title: "Animations",
|
||||
description: "Enable animations on certain pages",
|
||||
id: 6,
|
||||
Component: Switch,
|
||||
props: {
|
||||
state: $settingsState.animations,
|
||||
onChange: (isOn: boolean) => settingsState.animations = isOn
|
||||
}
|
||||
},
|
||||
},
|
||||
{
|
||||
title: "News Feed Source",
|
||||
description: "Choose the sources for your news feed",
|
||||
id: 11,
|
||||
Component: Select,
|
||||
props: {
|
||||
state: $settingsState.newsSource,
|
||||
onChange: (value: string) => settingsState.newsSource = value,
|
||||
options: [
|
||||
{ value: "australia", label: "Australia" },
|
||||
{ value: "usa", label: "USA" },
|
||||
{ value: "uk", label: "UK" },
|
||||
{ value: "taiwan", label: "Taiwan" },
|
||||
{ value: "hong_kong", label: "Hong Kong" },
|
||||
{ value: "panama", label: "Panama" },
|
||||
{ value: "canada", label: "Canada" },
|
||||
{ value: "singapore", label: "Singapore" },
|
||||
{ value: "japan", label: "Japan" },
|
||||
{ value: "netherlands", label: "Netherlands" }
|
||||
]
|
||||
{
|
||||
title: "12 Hour Time",
|
||||
description: "Prefer 12 hour time format for SEQTA",
|
||||
id: 9,
|
||||
Component: Switch,
|
||||
props: {
|
||||
state: $settingsState.timeFormat === "12",
|
||||
onChange: (isOn: boolean) => settingsState.timeFormat = isOn ? "12" : "24"
|
||||
}
|
||||
},
|
||||
{
|
||||
title: "Default Page",
|
||||
description: "Choose which page loads first when you open SEQTA",
|
||||
id: 10,
|
||||
Component: Select,
|
||||
props: {
|
||||
value: $settingsState.defaultPage ?? "home",
|
||||
onChange: (value: string) => (settingsState.defaultPage = value),
|
||||
options: isEngage
|
||||
? [
|
||||
{ value: "home", label: "Home" },
|
||||
{ value: "dashboard", label: "Dashboard" },
|
||||
{ value: "timetable", label: "Timetable" },
|
||||
{ value: "messages", label: "Messages" },
|
||||
{ value: "documents", label: "Documents" },
|
||||
{ value: "reports", label: "Reports" },
|
||||
]
|
||||
: [
|
||||
{ value: "home", label: "Home" },
|
||||
{ value: "dashboard", label: "Dashboard" },
|
||||
{ value: "timetable", label: "Timetable" },
|
||||
{ value: "welcome", label: "Welcome" },
|
||||
{ value: "messages", label: "Messages" },
|
||||
{ value: "documents", label: "Documents" },
|
||||
{ value: "reports", label: "Reports" },
|
||||
],
|
||||
},
|
||||
},
|
||||
...(!isEngage
|
||||
? [
|
||||
{
|
||||
title: "News Feed Source",
|
||||
description: "Choose the sources for your news feed",
|
||||
id: 11,
|
||||
Component: Select,
|
||||
props: {
|
||||
value: $settingsState.newsSource,
|
||||
onChange: (value: string) => settingsState.newsSource = value,
|
||||
options: [
|
||||
{ value: "australia", label: "Australia" },
|
||||
{ value: "usa", label: "USA" },
|
||||
{ value: "uk", label: "UK" },
|
||||
{ value: "taiwan", label: "Taiwan" },
|
||||
{ value: "hong_kong", label: "Hong Kong" },
|
||||
{ value: "panama", label: "Panama" },
|
||||
{ value: "canada", label: "Canada" },
|
||||
{ value: "singapore", label: "Singapore" },
|
||||
{ value: "japan", label: "Japan" },
|
||||
{ value: "netherlands", label: "Netherlands" },
|
||||
],
|
||||
},
|
||||
},
|
||||
]
|
||||
: []),
|
||||
] as option (option.id)}
|
||||
{@render Setting(option)}
|
||||
{/each}
|
||||
{/if}
|
||||
|
||||
}
|
||||
}
|
||||
] as option}
|
||||
{@render Setting(option)}
|
||||
{/each}
|
||||
{#if showsSection("appearance")}
|
||||
{#each [
|
||||
{
|
||||
title: "Custom Theme Colour",
|
||||
description: "Customise the overall theme colour of SEQTA Learn",
|
||||
id: 4,
|
||||
Component: PickerSwatch,
|
||||
props: {
|
||||
onClick: showColourPicker
|
||||
}
|
||||
},
|
||||
{
|
||||
title: "Interface Font",
|
||||
description: "Choose the typeface used across SEQTA Learn",
|
||||
id: 16,
|
||||
Component: Button,
|
||||
props: {
|
||||
onClick: showFontPicker,
|
||||
text: "Change"
|
||||
}
|
||||
},
|
||||
] as option (option.id)}
|
||||
{@render Setting(option)}
|
||||
{/each}
|
||||
|
||||
{#if !isEngage && matchesSearch("Sidebar Style", "Item Size", "Corner Radius", "Active Indicator", "Sidebar Width", "Transparency Effects", "Blur Strength")}
|
||||
<div class="border-none">
|
||||
<SidebarAppearance />
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
{#if matchesSearch("Adaptive Theme Colour", "Soft Gradient", "Smooth colour transition")}
|
||||
<div class="border-none">
|
||||
<div class="p-1 my-1 from-white to-zinc-100 bg-gradient-to-br rounded-xl border shadow-sm border-zinc-200/50 dark:border-zinc-700/40 dark:to-zinc-900/50 dark:from-zinc-900/40">
|
||||
<div class="flex justify-between items-center px-5 py-4">
|
||||
<div class="pr-4">
|
||||
<h2 class="text-xl font-bold">Adaptive Theme Colour</h2>
|
||||
<p class="text-base text-zinc-600 dark:text-zinc-300">Change the theme colour based on the current class (e.g. when viewing a course or assessments page)</p>
|
||||
</div>
|
||||
<div>
|
||||
<Switch
|
||||
state={$settingsState.adaptiveThemeColour ?? false}
|
||||
onChange={(isOn: boolean) => settingsState.adaptiveThemeColour = isOn}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
{#if $settingsState.adaptiveThemeColour}
|
||||
<div class="flex justify-between items-center px-5 py-4 pl-7 border-t border-zinc-100 dark:border-zinc-700/50">
|
||||
<div class="pr-4">
|
||||
<h2 class="text-xl font-bold">Soft Gradient</h2>
|
||||
<p class="text-base text-zinc-600 dark:text-zinc-300">Use a soft gradient instead of a solid colour when viewing a class</p>
|
||||
</div>
|
||||
<div>
|
||||
<Switch
|
||||
state={$settingsState.adaptiveThemeGradient ?? false}
|
||||
onChange={(isOn: boolean) => settingsState.adaptiveThemeGradient = isOn}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<div class="flex justify-between items-center px-5 py-4 pl-7 border-t border-zinc-100 dark:border-zinc-700/50">
|
||||
<div class="pr-4">
|
||||
<h2 class="text-xl font-bold">Smooth colour transition</h2>
|
||||
<p class="text-base text-zinc-600 dark:text-zinc-300">Ease between class/subject colours when navigating instead of switching instantly</p>
|
||||
</div>
|
||||
<div>
|
||||
<Switch
|
||||
state={$settingsState.adaptiveThemeColourTransition ?? true}
|
||||
onChange={(isOn: boolean) => settingsState.adaptiveThemeColourTransition = isOn}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
{/if}
|
||||
|
||||
{#if showsSection("general")}
|
||||
{#if matchesSearch("Home Page Assessments", "Include Past Assessments", "Maximum Subjects", "Maximum Assessments per Subject")}
|
||||
<div class="border-none">
|
||||
<div class="p-1 my-1 from-white to-zinc-100 bg-gradient-to-br rounded-xl border shadow-sm border-zinc-200/50 dark:border-zinc-700/40 dark:to-zinc-900/50 dark:from-zinc-900/40">
|
||||
<div class="flex justify-between items-center px-4 py-3">
|
||||
<div class="flex justify-between items-center px-5 py-4">
|
||||
<div class="pr-4">
|
||||
<h2 class="text-sm font-bold">Adaptive Theme Colour</h2>
|
||||
<p class="text-xs">Change the theme colour based on the current class (e.g. when viewing a course or assessments page)</p>
|
||||
<h2 class="text-xl font-bold">Home Page Assessments</h2>
|
||||
<p class="text-base text-zinc-600 dark:text-zinc-300">Limit upcoming assessments shown on the home page by subject</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="flex justify-between items-center px-5 py-4 pl-7 border-t border-zinc-100 dark:border-zinc-700/50">
|
||||
<div class="pr-4">
|
||||
<h2 class="text-xl font-bold">Include Past Assessments</h2>
|
||||
<p class="text-base text-zinc-600 dark:text-zinc-300">Show past-due assessments from the upcoming list, matching the Assessments page</p>
|
||||
</div>
|
||||
<div>
|
||||
<Switch
|
||||
state={$settingsState.adaptiveThemeColour ?? false}
|
||||
onChange={(isOn: boolean) => settingsState.adaptiveThemeColour = isOn}
|
||||
state={$settingsState.homeUpcomingIncludePast ?? true}
|
||||
onChange={(isOn: boolean) => (settingsState.homeUpcomingIncludePast = isOn)}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
{#if $settingsState.adaptiveThemeColour}
|
||||
<div class="flex justify-between items-center px-4 py-3 pl-6 border-t border-zinc-100 dark:border-zinc-700/50">
|
||||
<div class="pr-4">
|
||||
<h2 class="text-sm font-bold">Soft Gradient</h2>
|
||||
<p class="text-xs">Use a soft gradient instead of a solid colour when viewing a class</p>
|
||||
</div>
|
||||
<div>
|
||||
<Switch
|
||||
state={$settingsState.adaptiveThemeGradient ?? false}
|
||||
onChange={(isOn: boolean) => settingsState.adaptiveThemeGradient = isOn}
|
||||
/>
|
||||
</div>
|
||||
<div class="flex justify-between items-center px-5 py-4 pl-7 border-t border-zinc-100 dark:border-zinc-700/50">
|
||||
<div class="pr-4">
|
||||
<h2 class="text-xl font-bold">Maximum Subjects</h2>
|
||||
<p class="text-base text-zinc-600 dark:text-zinc-300">Number of subjects to include, ordered by soonest due date</p>
|
||||
</div>
|
||||
<div class="flex justify-between items-center px-4 py-3 pl-6 border-t border-zinc-100 dark:border-zinc-700/50">
|
||||
<div class="pr-4">
|
||||
<h2 class="text-sm font-bold">Smooth colour transition</h2>
|
||||
<p class="text-xs">Ease between class/subject colours when navigating instead of switching instantly</p>
|
||||
</div>
|
||||
<div>
|
||||
<Switch
|
||||
state={$settingsState.adaptiveThemeColourTransition ?? true}
|
||||
onChange={(isOn: boolean) => settingsState.adaptiveThemeColourTransition = isOn}
|
||||
/>
|
||||
</div>
|
||||
<Select
|
||||
value={String($settingsState.homeUpcomingSubjectsMax ?? 5)}
|
||||
onChange={(value: string) => (settingsState.homeUpcomingSubjectsMax = Number(value))}
|
||||
options={[
|
||||
{ value: "0", label: "All" },
|
||||
{ value: "3", label: "3" },
|
||||
{ value: "5", label: "5" },
|
||||
{ value: "7", label: "7" },
|
||||
{ value: "10", label: "10" },
|
||||
{ value: "15", label: "15" },
|
||||
]}
|
||||
/>
|
||||
</div>
|
||||
<div class="flex justify-between items-center px-5 py-4 pl-7 border-t border-zinc-100 dark:border-zinc-700/50">
|
||||
<div class="pr-4">
|
||||
<h2 class="text-xl font-bold">Maximum Assessments per Subject</h2>
|
||||
<p class="text-base text-zinc-600 dark:text-zinc-300">Assessments shown for each included subject</p>
|
||||
</div>
|
||||
{/if}
|
||||
<Select
|
||||
value={String($settingsState.homeUpcomingAssessmentsPerSubjectMax ?? 0)}
|
||||
onChange={(value: string) => (settingsState.homeUpcomingAssessmentsPerSubjectMax = Number(value))}
|
||||
options={[
|
||||
{ value: "0", label: "All" },
|
||||
{ value: "1", label: "1" },
|
||||
{ value: "2", label: "2" },
|
||||
{ value: "3", label: "3" },
|
||||
{ value: "5", label: "5" },
|
||||
{ value: "10", label: "10" },
|
||||
]}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
{/if}
|
||||
|
||||
{#each pluginSettings as plugin}
|
||||
{#each pluginSettings as plugin (plugin.pluginId)}
|
||||
{#if pluginBelongsInSection(plugin.pluginId) && pluginHit(plugin)}
|
||||
<div class="border-none">
|
||||
<div class="p-1 my-1 from-white to-zinc-100 bg-gradient-to-br rounded-xl border shadow-sm border-zinc-200/50 dark:border-zinc-700/40 dark:to-zinc-900/50 dark:from-zinc-900/40 {!(plugin as any).disableToggle && Object.keys(plugin.settings).length === 0 ? 'hidden' : ''}">
|
||||
<!-- Always show enable toggle if disableToggle is true -->
|
||||
{#if (plugin as any).disableToggle}
|
||||
<div class="flex justify-between items-center px-4 py-3">
|
||||
<div class="flex justify-between items-center px-5 py-4">
|
||||
<div class="pr-4">
|
||||
<h2 class="flex gap-2 items-center text-sm font-bold">
|
||||
<h2 class="flex gap-2 items-center text-xl font-bold">
|
||||
Enable {plugin.name}
|
||||
{#if plugin.beta}
|
||||
<span class="px-2 py-0.5 text-xs font-medium text-orange-800 bg-orange-100 rounded-full border border-orange-300/30 dark:bg-orange-900/30 dark:text-orange-300 dark:border-orange-900/30">
|
||||
@@ -347,7 +497,7 @@
|
||||
</span>
|
||||
{/if}
|
||||
</h2>
|
||||
<p class="text-xs">{plugin.description}</p>
|
||||
<p class="text-base text-zinc-600 dark:text-zinc-300">{plugin.description}</p>
|
||||
</div>
|
||||
<div>
|
||||
<Switch
|
||||
@@ -372,13 +522,13 @@
|
||||
{/if}
|
||||
|
||||
{#if !((plugin as any).disableToggle) || (pluginSettingsValues[plugin.pluginId]?.enabled ?? true)}
|
||||
{#each Object.entries(plugin.settings) as [key, setting]}
|
||||
{#each Object.entries(plugin.settings) as [key, setting] (key)}
|
||||
<!-- Skip the 'enabled' setting and hide cloud-only settings when not signed in -->
|
||||
{#if key !== 'enabled' && !(key === 'useCloudPfp' && !cloudState.isLoggedIn)}
|
||||
<div class="flex justify-between items-center px-4 py-3">
|
||||
<div class="flex justify-between items-center px-5 py-4">
|
||||
<div class="pr-4">
|
||||
<h2 class="text-sm font-bold">{setting.title || key}</h2>
|
||||
<p class="text-xs">{setting.description || ''}</p>
|
||||
<h2 class="text-xl font-bold">{setting.title || key}</h2>
|
||||
<p class="text-base text-zinc-600 dark:text-zinc-300">{setting.description || ''}</p>
|
||||
</div>
|
||||
<div>
|
||||
{#if setting.type === 'boolean'}
|
||||
@@ -405,7 +555,7 @@
|
||||
/>
|
||||
{:else if setting.type === 'select'}
|
||||
<Select
|
||||
state={pluginSettingsValues[plugin.pluginId]?.[key] ?? setting.default}
|
||||
value={pluginSettingsValues[plugin.pluginId]?.[key] ?? setting.default}
|
||||
onChange={(value) => updatePluginSetting(plugin.pluginId, key, value)}
|
||||
options={(setting.options as string[]).map(opt => ({
|
||||
value: opt,
|
||||
@@ -447,29 +597,10 @@
|
||||
})}
|
||||
{/if}
|
||||
</div>
|
||||
{/if}
|
||||
{/each}
|
||||
|
||||
<div class="border-none">
|
||||
<div class="p-1 my-1 from-white to-zinc-100 bg-gradient-to-br rounded-xl border shadow-sm border-zinc-200/50 dark:border-zinc-700/40 dark:to-zinc-900/50 dark:from-zinc-900/40">
|
||||
<div class="flex justify-between items-center px-4 py-3">
|
||||
<div class="pr-4">
|
||||
<h2 class="text-sm font-bold">BetterSEQTA Cloud</h2>
|
||||
<p class="text-xs">Account & sync</p>
|
||||
</div>
|
||||
<div>
|
||||
<CloudHeader alwaysShowUserName onClick={showCloudPanel} />
|
||||
</div>
|
||||
</div>
|
||||
{#if cloudState.isLoggedIn}
|
||||
<div class="px-3 pb-3">
|
||||
<CloudSettingsSync showDisclaimer={(onConfirm, onCancel) => showDisclaimer(onConfirm, onCancel, "Restore from cloud?", "This will replace your local settings with the cloud backup. Continue?")} />
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="p-1 border-none"></div>
|
||||
|
||||
{#if showsSection("advanced")}
|
||||
{@render Setting({
|
||||
title: "BetterSEQTA+",
|
||||
description: "Enables BetterSEQTA+ features",
|
||||
@@ -481,21 +612,56 @@
|
||||
}
|
||||
})}
|
||||
|
||||
{#if $settingsState.devMode}
|
||||
{#if $settingsState.devMode && matchesSearch(
|
||||
"Developer Mode",
|
||||
"Verbose logging",
|
||||
"Delay loading screen",
|
||||
"Sensitive Hider",
|
||||
"Mock Notices",
|
||||
"Show Privacy Notification",
|
||||
"Show Theme of the Month",
|
||||
"Export cloud settings JSON",
|
||||
"API Base URL",
|
||||
"GitHub latest version override",
|
||||
)}
|
||||
<div class="flex-col p-1 my-1 bg-gradient-to-br from-white rounded-xl border shadow-sm to-zinc-100 border-zinc-200/50 dark:border-zinc-700/40 dark:to-zinc-900/50 dark:from-zinc-900/40">
|
||||
<div class="flex justify-between items-center px-4 py-3">
|
||||
<div class="flex justify-between items-center px-5 py-4">
|
||||
<div class="pr-4">
|
||||
<h2 class="text-sm font-bold">Developer Mode</h2>
|
||||
<p class="text-xs">Enables developer mode, allowing you to test new features and changes.</p>
|
||||
<h2 class="text-xl font-bold">Developer Mode</h2>
|
||||
<p class="text-base text-zinc-600 dark:text-zinc-300">Enables developer mode, allowing you to test new features and changes.</p>
|
||||
</div>
|
||||
<div>
|
||||
<Switch state={$settingsState.devMode} onChange={(isOn: boolean) => settingsState.devMode = isOn} />
|
||||
</div>
|
||||
</div>
|
||||
<div class="flex justify-between items-center px-4 py-3">
|
||||
<div class="flex justify-between items-center px-5 py-4">
|
||||
<div class="pr-4">
|
||||
<h2 class="text-sm font-bold">Sensitive Hider</h2>
|
||||
<p class="text-xs">Replace sensitive content with mock data</p>
|
||||
<h2 class="text-xl font-bold">Verbose logging</h2>
|
||||
<p class="text-base text-zinc-600 dark:text-zinc-300">Show diagnostic console output (indexer, theme manager, timetable colour patch, etc.)</p>
|
||||
</div>
|
||||
<div>
|
||||
<Switch
|
||||
state={$settingsState.verboseLogging ?? false}
|
||||
onChange={(isOn: boolean) => settingsState.verboseLogging = isOn}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<div class="flex justify-between items-center px-5 py-4">
|
||||
<div class="pr-4">
|
||||
<h2 class="text-xl font-bold">Delay loading screen</h2>
|
||||
<p class="text-base text-zinc-600 dark:text-zinc-300">Keep the loading overlay visible for 5 extra seconds so you can preview canvas variants.</p>
|
||||
</div>
|
||||
<div>
|
||||
<Switch
|
||||
state={$settingsState.devDelayLoadingScreen ?? false}
|
||||
onChange={(isOn: boolean) => settingsState.devDelayLoadingScreen = isOn}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<div class="flex justify-between items-center px-5 py-4">
|
||||
<div class="pr-4">
|
||||
<h2 class="text-xl font-bold">Sensitive Hider</h2>
|
||||
<p class="text-base text-zinc-600 dark:text-zinc-300">Replace sensitive content with mock data</p>
|
||||
</div>
|
||||
<div>
|
||||
<Switch
|
||||
@@ -504,10 +670,10 @@
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<div class="flex justify-between items-center px-4 py-3">
|
||||
<div class="flex justify-between items-center px-5 py-4">
|
||||
<div class="pr-4">
|
||||
<h2 class="text-sm font-bold">Mock Notices</h2>
|
||||
<p class="text-xs">Use fake notice data on homepage instead of real data</p>
|
||||
<h2 class="text-xl font-bold">Mock Notices</h2>
|
||||
<p class="text-base text-zinc-600 dark:text-zinc-300">Use fake notice data on homepage instead of real data</p>
|
||||
</div>
|
||||
<div>
|
||||
<Switch
|
||||
@@ -516,10 +682,10 @@
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<div class="flex justify-between items-center px-4 py-3">
|
||||
<div class="flex justify-between items-center px-5 py-4">
|
||||
<div class="pr-4">
|
||||
<h2 class="text-sm font-bold">Show Privacy Notification</h2>
|
||||
<p class="text-xs">Show the privacy notification popup on next page load</p>
|
||||
<h2 class="text-xl font-bold">Show Privacy Notification</h2>
|
||||
<p class="text-base text-zinc-600 dark:text-zinc-300">Show the privacy notification popup on next page load</p>
|
||||
</div>
|
||||
<div>
|
||||
<Button
|
||||
@@ -535,10 +701,10 @@
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<div class="flex justify-between items-center px-4 py-3">
|
||||
<div class="flex justify-between items-center px-5 py-4">
|
||||
<div class="pr-4">
|
||||
<h2 class="text-sm font-bold">Show Theme of the Month</h2>
|
||||
<p class="text-xs">Fetch and show the current month's popup now (ignores dismissed state)</p>
|
||||
<h2 class="text-xl font-bold">Show Theme of the Month</h2>
|
||||
<p class="text-base text-zinc-600 dark:text-zinc-300">Fetch and show the current month's popup now (ignores dismissed state)</p>
|
||||
</div>
|
||||
<div>
|
||||
<Button
|
||||
@@ -551,10 +717,10 @@
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<div class="flex justify-between items-center px-4 py-3">
|
||||
<div class="flex justify-between items-center px-5 py-4">
|
||||
<div class="pr-4">
|
||||
<h2 class="text-sm font-bold">Export cloud settings JSON</h2>
|
||||
<p class="text-xs">Download the same payload as cloud sync (OAuth tokens stripped). For debugging and server testing.</p>
|
||||
<h2 class="text-xl font-bold">Export cloud settings JSON</h2>
|
||||
<p class="text-base text-zinc-600 dark:text-zinc-300">Download the same payload as cloud sync (OAuth tokens stripped). For debugging and server testing.</p>
|
||||
</div>
|
||||
<div>
|
||||
<Button onClick={exportCloudSettingsJsonToFile} text="Export to file" />
|
||||
@@ -563,8 +729,8 @@
|
||||
<div class="flex flex-col gap-2 px-4 py-3">
|
||||
<div class="flex justify-between items-start gap-3">
|
||||
<div class="pr-4">
|
||||
<h2 class="text-sm font-bold">API Base URL (session only)</h2>
|
||||
<p class="text-xs">Override the content API host for this browser session. Cleared on restart. Affects themes, theme of the month, and other server-driven content.</p>
|
||||
<h2 class="text-xl font-bold">API Base URL (session only)</h2>
|
||||
<p class="text-base text-zinc-600 dark:text-zinc-300">Override the content API host for this browser session. Cleared on restart. Affects themes, theme of the month, and other server-driven content.</p>
|
||||
{#if devApiBaseActive}
|
||||
<p class="text-xs mt-1 text-amber-600 dark:text-amber-400">
|
||||
Override active: <span class="font-mono">{devApiBaseActive}</span>
|
||||
@@ -587,8 +753,8 @@
|
||||
</div>
|
||||
<div class="flex flex-col gap-2 px-4 py-3">
|
||||
<div>
|
||||
<h2 class="text-sm font-bold">GitHub latest version override</h2>
|
||||
<p class="text-xs">Pretend a newer GitHub release exists to test the update badge. Only applies when dev mode is on.</p>
|
||||
<h2 class="text-xl font-bold">GitHub latest version override</h2>
|
||||
<p class="text-base text-zinc-600 dark:text-zinc-300">Pretend a newer GitHub release exists to test the update badge. Only applies when dev mode is on.</p>
|
||||
</div>
|
||||
<input
|
||||
type="text"
|
||||
@@ -602,4 +768,5 @@
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
{/if}
|
||||
</div>
|
||||
@@ -5,6 +5,9 @@
|
||||
import { onMount } from 'svelte';
|
||||
import Shortcuts from "@/seqta/content/links.json"
|
||||
|
||||
let { searchQuery = "" } = $props<{ searchQuery?: string }>();
|
||||
const q = $derived(searchQuery.trim().toLowerCase());
|
||||
|
||||
let isLoaded = $state(false);
|
||||
let fileInput = $state<HTMLInputElement | null>(null);
|
||||
|
||||
@@ -106,6 +109,7 @@
|
||||
|
||||
<div class="flex flex-col pt-4 divide-y divide-zinc-100 dark:divide-zinc-700">
|
||||
{#if isLoaded}
|
||||
{#if !q}
|
||||
<div>
|
||||
<MotionDiv
|
||||
initial={{ opacity: 0, height: 0 }}
|
||||
@@ -196,7 +200,7 @@
|
||||
transition={{ duration: 0.3 }}
|
||||
>
|
||||
<button
|
||||
class="w-full px-4 py-2 mb-4 text-[13px] dark:text-white transition rounded-xl bg-zinc-200 dark:bg-zinc-700/50"
|
||||
class="w-full px-4 py-3 mb-4 text-base dark:text-white transition rounded-xl bg-zinc-200 dark:bg-zinc-700/50"
|
||||
onclick={isFormVisible ? addNewCustomShortcut : toggleForm}
|
||||
>
|
||||
{#if isFormVisible}
|
||||
@@ -207,9 +211,11 @@
|
||||
</button>
|
||||
</MotionDiv>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<!-- Custom Shortcuts Section -->
|
||||
{#each ($settingsState.customshortcuts ?? []) as shortcut, index}
|
||||
{#if !q || shortcut.name.toLowerCase().includes(q)}
|
||||
<div class="flex justify-between items-center px-4 py-3">
|
||||
{shortcut.name}
|
||||
<button aria-label="Delete Shortcut" onclick={() => deleteCustomShortcut(index)}>
|
||||
@@ -218,16 +224,19 @@
|
||||
</svg>
|
||||
</button>
|
||||
</div>
|
||||
{/if}
|
||||
{/each}
|
||||
|
||||
{#each Object.entries(Shortcuts) as shortcut}
|
||||
{#if !q || shortcut[1].DisplayName?.toLowerCase().includes(q) || shortcut[0].toLowerCase().includes(q)}
|
||||
<div class="flex justify-between items-center px-4 py-3">
|
||||
<div class="pr-4">
|
||||
<!-- Use DisplayName if it exists, otherwise use the key (shortcut[0]) as a fallback -->
|
||||
<h2 class="text-sm">{shortcut[1].DisplayName || shortcut[0]}</h2>
|
||||
<h2 class="text-lg font-medium">{shortcut[1].DisplayName || shortcut[0]}</h2>
|
||||
</div>
|
||||
<Switch state={$settingsState.shortcuts.find(s => s.name === shortcut[0])?.enabled ?? false} onChange={() => switchChange(shortcut[0])} />
|
||||
</div>
|
||||
{/if}
|
||||
{/each}
|
||||
{:else}
|
||||
<div class="p-4 text-center">
|
||||
|
||||
@@ -2,6 +2,10 @@
|
||||
import BackgroundSelector from "@/interface/components/themes/BackgroundSelector.svelte"
|
||||
import ThemeSelector from "@/interface/components/themes/ThemeSelector.svelte"
|
||||
import { standalone } from "@/interface/utils/standalone.svelte"
|
||||
|
||||
let { section = "all" } = $props<{
|
||||
section?: "all" | "themes" | "backgrounds";
|
||||
}>();
|
||||
|
||||
// backgrounds
|
||||
let selectedBackground = $state<string | null>(null);
|
||||
@@ -9,15 +13,22 @@
|
||||
|
||||
let clearTheme = $derived(selectedBackground !== null);
|
||||
let editMode = $state<boolean>(false);
|
||||
let showBackgrounds = $derived(section !== "themes");
|
||||
let showThemes = $derived(section !== "backgrounds");
|
||||
</script>
|
||||
|
||||
<div class="py-4">
|
||||
{#if !standalone.standalone}
|
||||
<button
|
||||
onclick={() => selectNoBackground()}
|
||||
class="w-full px-4 py-2 mb-4 text-[13px] dark:text-white transition rounded-xl bg-zinc-200 dark:bg-zinc-700/50">
|
||||
{ clearTheme ? 'Clear Theme' : 'Select a Theme' }
|
||||
</button>
|
||||
{#if showBackgrounds}
|
||||
<button
|
||||
onclick={() => selectNoBackground()}
|
||||
disabled={section === "backgrounds" && !clearTheme}
|
||||
class="w-full px-4 py-3 mb-4 text-base dark:text-white transition rounded-xl bg-zinc-200 dark:bg-zinc-700/50 disabled:opacity-50">
|
||||
{section === "all"
|
||||
? clearTheme ? 'Clear Theme' : 'Select a Theme'
|
||||
: clearTheme ? 'Clear Background' : 'No Background Selected'}
|
||||
</button>
|
||||
{/if}
|
||||
<div class="relative w-full">
|
||||
<button
|
||||
onclick={() => editMode = !editMode}
|
||||
@@ -26,8 +37,12 @@
|
||||
<span class="font-IconFamily">{editMode ? '\ue9e4' : '\uec38'}</span>
|
||||
</button>
|
||||
|
||||
<BackgroundSelector isEditMode={editMode} bind:selectedBackground={selectedBackground} bind:selectNoBackground={selectNoBackground} />
|
||||
<ThemeSelector isEditMode={editMode} />
|
||||
{#if showBackgrounds}
|
||||
<BackgroundSelector isEditMode={editMode} bind:selectedBackground={selectedBackground} bind:selectNoBackground={selectNoBackground} />
|
||||
{/if}
|
||||
{#if showThemes}
|
||||
<ThemeSelector isEditMode={editMode} showNavigation={section === "all"} />
|
||||
{/if}
|
||||
</div>
|
||||
{:else}
|
||||
<div class="flex justify-center items-center w-full h-full">
|
||||
|
||||
@@ -5,12 +5,10 @@
|
||||
import CoverSwiper from '../components/store/CoverSwiper.svelte';
|
||||
import ThemeGrid from '../components/store/ThemeGrid.svelte';
|
||||
import SkeletonLoader from '../components/SkeletonLoader.svelte';
|
||||
import { settingsState } from '@/seqta/utils/listeners/SettingsState'
|
||||
import type { Theme } from '../types/Theme'
|
||||
import { visibleStoreThemes, buildCoverSlidesForThemes, normalizeStoreTheme } from '@/interface/utils/themeStoreFlavours'
|
||||
import browser from 'webextension-polyfill'
|
||||
import ThemeModal from '../components/store/ThemeModal.svelte'
|
||||
import Header from '../components/store/Header.svelte'
|
||||
import { themeUpdates } from '../hooks/ThemeUpdates'
|
||||
import { ThemeManager } from '@/plugins/built-in/themes/theme-manager'
|
||||
|
||||
@@ -21,12 +19,30 @@
|
||||
import { consumePendingHighlightThemeId } from '@/seqta/utils/openThemeStoreWithHighlight'
|
||||
|
||||
const themeManager = ThemeManager.getInstance();
|
||||
type StoreTab = 'themes' | 'backgrounds';
|
||||
let {
|
||||
activeTab,
|
||||
searchTerm,
|
||||
selectedBackgroundCategory,
|
||||
setActiveTab,
|
||||
setSearchTerm,
|
||||
setBackgroundCategories,
|
||||
} = $props<{
|
||||
activeTab: StoreTab;
|
||||
searchTerm: string;
|
||||
selectedBackgroundCategory: string;
|
||||
setActiveTab: (tab: StoreTab) => void;
|
||||
setSearchTerm: (term: string) => void;
|
||||
setBackgroundCategories: (categories: string[]) => void;
|
||||
}>();
|
||||
let cloudLoggedIn = $state(cloudAuth.state.isLoggedIn);
|
||||
|
||||
cloudAuth.subscribe((s) => { cloudLoggedIn = s.isLoggedIn; });
|
||||
$effect(() => {
|
||||
const unsub = cloudAuth.subscribe((s) => { cloudLoggedIn = s.isLoggedIn; });
|
||||
return unsub;
|
||||
});
|
||||
|
||||
// State variables
|
||||
let searchTerm = $state('');
|
||||
let themes = $state<Theme[]>([]);
|
||||
|
||||
/** Grid/search/cover: hides flat-listed slaves when API sends them */
|
||||
@@ -35,10 +51,8 @@
|
||||
/** Cover marquee slides (master + flavour imagery for top masters) */
|
||||
let coverSlides = $derived(buildCoverSlidesForThemes(listThemes.slice(0, 3)));
|
||||
let loading = $state(true);
|
||||
let darkMode = $state(false);
|
||||
let displayTheme = $state<Theme | null>(null);
|
||||
let currentThemes = $state<string[]>([]);
|
||||
let activeTab = $state('themes');
|
||||
|
||||
let error = $state<string | null>(null);
|
||||
let fetchAttempt = $state(0);
|
||||
@@ -66,14 +80,6 @@
|
||||
displayTheme = theme;
|
||||
};
|
||||
|
||||
const setSearchTerm = (term: string) => {
|
||||
searchTerm = term;
|
||||
};
|
||||
|
||||
const setActiveTab = (tab: string) => {
|
||||
activeTab = tab;
|
||||
};
|
||||
|
||||
/** Featured themes first; within each group, newest by `created_at` (API: Unix seconds). */
|
||||
function compareStoreThemes(a: Theme, b: Theme): number {
|
||||
const fa = a.featured === true ? 1 : 0;
|
||||
@@ -86,13 +92,11 @@
|
||||
}
|
||||
|
||||
const toggleFavorite = async (theme: Theme) => {
|
||||
const token = await cloudAuth.getStoredToken();
|
||||
if (!token) return;
|
||||
if (!cloudLoggedIn) return;
|
||||
const isFavorite = !theme.is_favorited;
|
||||
const result = (await browser.runtime.sendMessage({
|
||||
type: 'cloudFavorite',
|
||||
themeId: theme.id,
|
||||
token,
|
||||
action: isFavorite ? 'favorite' : 'unfavorite',
|
||||
})) as { success?: boolean };
|
||||
if (result?.success) {
|
||||
@@ -119,14 +123,12 @@
|
||||
error = null;
|
||||
}
|
||||
try {
|
||||
const token = await cloudAuth.getStoredToken();
|
||||
const data = await sendMessageWithTimeout<{
|
||||
success?: boolean;
|
||||
data?: { themes: unknown[] };
|
||||
error?: string;
|
||||
}>({
|
||||
type: 'fetchThemes',
|
||||
token: token ?? undefined,
|
||||
});
|
||||
if (!data?.success || !Array.isArray(data?.data?.themes)) {
|
||||
throw new Error(data?.error || 'Failed to fetch themes');
|
||||
@@ -156,8 +158,8 @@
|
||||
const match = themes.find((t) => t.id === themeId)
|
||||
?? themes.find((t) => t.flavours?.some((f) => f.id === themeId));
|
||||
if (match) {
|
||||
activeTab = 'themes';
|
||||
searchTerm = '';
|
||||
setActiveTab('themes');
|
||||
setSearchTerm('');
|
||||
displayTheme = match;
|
||||
}
|
||||
}
|
||||
@@ -176,9 +178,6 @@
|
||||
await fetchThemes();
|
||||
await fetchCurrentThemes();
|
||||
|
||||
darkMode = (await browser.storage.local.get('DarkMode')).DarkMode === 'true';
|
||||
darkMode = $settingsState.DarkMode;
|
||||
|
||||
const pending = consumePendingHighlightThemeId();
|
||||
if (pending) focusThemeById(pending);
|
||||
|
||||
@@ -243,13 +242,11 @@
|
||||
});
|
||||
</script>
|
||||
|
||||
<div class="w-screen h-screen bg-white {darkMode ? 'dark' : ''}">
|
||||
<div class="h-full overflow-y-scroll bg-zinc-200/50 dark:bg-zinc-900 dark:text-white pt-[4.25rem]">
|
||||
<Header {searchTerm} {setSearchTerm} {darkMode} {activeTab} {setActiveTab} />
|
||||
|
||||
<div class={`px-12 h-full ${activeTab === 'backgrounds' ? 'pt-0' : 'pt-6 md:px-24 lg:px-48'}`}>
|
||||
<!-- Loading State -->
|
||||
{#if loading}
|
||||
<div class="relative flex h-full min-h-0 flex-col overflow-hidden text-zinc-900 dark:text-white">
|
||||
<main class="min-h-0 flex-1 overflow-y-auto bg-zinc-50/80 dark:bg-zinc-900/40">
|
||||
<div class={activeTab === 'backgrounds' ? 'h-full' : 'px-6 py-6 md:px-8 lg:px-10'}>
|
||||
<!-- Loading State -->
|
||||
{#if loading}
|
||||
<div class="grid grid-cols-1 gap-4 py-12 mx-auto sm:grid-cols-2 lg:grid-cols-3">
|
||||
{#each Array(6) as _, i (i)}
|
||||
<SkeletonLoader width="100%" height="200px" />
|
||||
@@ -264,7 +261,7 @@
|
||||
</p>
|
||||
<button
|
||||
type="button"
|
||||
class="mt-6 px-4 py-2 rounded-lg bg-blue-600 text-white font-medium hover:bg-blue-700"
|
||||
class="mt-6 rounded-lg bg-zinc-900 px-4 py-2 font-medium text-white transition-colors duration-200 hover:bg-zinc-700 dark:bg-zinc-100 dark:text-zinc-900 dark:hover:bg-white"
|
||||
onclick={() => {
|
||||
loading = true;
|
||||
error = null;
|
||||
@@ -313,13 +310,17 @@
|
||||
/>
|
||||
{/if}
|
||||
{:else if activeTab === 'backgrounds'}
|
||||
<Backgrounds {searchTerm} />
|
||||
<Backgrounds
|
||||
{searchTerm}
|
||||
selectedCategory={selectedBackgroundCategory}
|
||||
onCategoriesChange={setBackgroundCategories}
|
||||
/>
|
||||
{/if}
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
</main>
|
||||
|
||||
{#if showSignInOverlay}
|
||||
<SignInToFavoriteModal onClose={() => (showSignInOverlay = false)} />
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
@@ -1,5 +1,4 @@
|
||||
<script lang="ts">
|
||||
import { v4 as uuidv4 } from 'uuid';
|
||||
import { onMount } from 'svelte';
|
||||
import { slide } from 'svelte/transition';
|
||||
import { fade } from 'svelte/transition';
|
||||
@@ -27,12 +26,15 @@
|
||||
import { ThemeManager } from '@/plugins/built-in/themes/theme-manager'
|
||||
import { themeUpdates } from '../hooks/ThemeUpdates'
|
||||
import { CloseThemeCreator } from '@/plugins/built-in/themes/ThemeCreator'
|
||||
import ThemeBlobImage from '@/interface/components/themes/ThemeBlobImage.svelte'
|
||||
import LucideMoon from '@/interface/components/icons/LucideMoon.svelte'
|
||||
import LucideSun from '@/interface/components/icons/LucideSun.svelte'
|
||||
|
||||
const { themeID } = $props<{ themeID: string }>()
|
||||
const themeManager = ThemeManager.getInstance();
|
||||
|
||||
let theme = $state<LoadedCustomTheme>({
|
||||
id: uuidv4(),
|
||||
id: crypto.randomUUID(),
|
||||
name: '',
|
||||
description: '',
|
||||
defaultColour: 'blue',
|
||||
@@ -73,26 +75,17 @@
|
||||
await themeManager.disableTheme();
|
||||
|
||||
if (themeID) {
|
||||
const tempTheme = await themeManager.getTheme(themeID)
|
||||
|
||||
if (!tempTheme) return
|
||||
|
||||
// convert temptheme to LoadedCustomTheme
|
||||
const loadedTheme = {
|
||||
...tempTheme,
|
||||
CustomImages: tempTheme.CustomImages.map(image => ({
|
||||
...image
|
||||
}))
|
||||
}
|
||||
const tempTheme = await themeManager.getTheme(themeID);
|
||||
if (!tempTheme) return;
|
||||
|
||||
theme = {
|
||||
...loadedTheme,
|
||||
adaptiveCssVariables: loadedTheme.adaptiveCssVariables ?? [],
|
||||
...tempTheme,
|
||||
adaptiveCssVariables: tempTheme.adaptiveCssVariables ?? [],
|
||||
forceTheme:
|
||||
loadedTheme.forceTheme ??
|
||||
(loadedTheme.forceDark !== undefined ? true : undefined),
|
||||
}
|
||||
themeLoaded = true
|
||||
tempTheme.forceTheme ??
|
||||
(tempTheme.forceDark !== undefined ? true : undefined),
|
||||
};
|
||||
themeLoaded = true;
|
||||
} else {
|
||||
themeLoaded = true
|
||||
}
|
||||
@@ -230,7 +223,7 @@
|
||||
{#each theme.CustomImages as image (image.id)}
|
||||
<div class="flex gap-2 items-center px-2 py-2 mb-4 h-16 bg-white rounded-lg shadow-lg dark:bg-zinc-700">
|
||||
<div class="h-full">
|
||||
<img src={URL.createObjectURL(image.blob)} alt={image.variableName} class="object-contain h-full rounded" />
|
||||
<ThemeBlobImage source={image.blob} alt={image.variableName} class="object-contain h-full rounded" />
|
||||
</div>
|
||||
<input
|
||||
type="text"
|
||||
@@ -252,19 +245,23 @@
|
||||
</div>
|
||||
{:else if item.type === 'lightDarkToggle'}
|
||||
<button
|
||||
class="overflow-hidden relative px-4 py-1 text-xl font-medium rounded-lg transition bg-zinc-200 dark:bg-zinc-700 hover:bg-zinc-300 dark:hover:bg-zinc-600 font-IconFamily"
|
||||
class="overflow-hidden relative flex justify-center items-center px-4 py-1 text-xl font-medium rounded-lg transition bg-zinc-200 dark:bg-zinc-700 hover:bg-zinc-300 dark:hover:bg-zinc-600"
|
||||
onclick={() => (item.props as LightDarkToggleProps).onChange(!(item.props as LightDarkToggleProps).state)}
|
||||
>
|
||||
{#key (item.props as LightDarkToggleProps).state}
|
||||
<span
|
||||
class="absolute"
|
||||
class="absolute flex items-center justify-center"
|
||||
in:fade={{ duration: 150 }}
|
||||
out:fade={{ duration: 150 }}
|
||||
>
|
||||
{(item.props as LightDarkToggleProps).state ? '\uec12' : '\uecfe'}
|
||||
{#if (item.props as LightDarkToggleProps).state}
|
||||
<LucideMoon class="w-5 h-5" />
|
||||
{:else}
|
||||
<LucideSun class="w-5 h-5" />
|
||||
{/if}
|
||||
</span>
|
||||
{/key}
|
||||
<span class='opacity-0'>{'\uec12'}</span>
|
||||
<span class="opacity-0 inline-flex"><LucideMoon class="w-5 h-5" /></span>
|
||||
</button>
|
||||
{/if}
|
||||
</div>
|
||||
@@ -330,7 +327,7 @@
|
||||
{/if}
|
||||
{#if theme.coverImage}
|
||||
<div class="absolute z-20 w-full h-full opacity-0 transition-opacity pointer-events-none group-hover:opacity-100 bg-black/20"></div>
|
||||
<img src="{typeof theme.coverImage === 'string' ? theme.coverImage : URL.createObjectURL(theme.coverImage)}" alt='Cover' class="object-cover absolute z-0 w-full h-full rounded" />
|
||||
<ThemeBlobImage source={theme.coverImage} alt="Cover" class="object-cover absolute z-0 w-full h-full rounded" />
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
|
||||
@@ -7,6 +7,8 @@ const THEME_CSS_VARS = [
|
||||
"--text-color",
|
||||
"--background-primary",
|
||||
"--background-secondary",
|
||||
"--theme-primary",
|
||||
"--theme-secondary",
|
||||
"--text-primary",
|
||||
"--theme-offset-bg",
|
||||
"--better-sub",
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
import { describe, expect, it } from "@jest/globals";
|
||||
import { resolveExtensionAssetUrl } from "./extensionAssetUrl";
|
||||
|
||||
describe("resolveExtensionAssetUrl", () => {
|
||||
it("returns already-resolved extension URLs unchanged", () => {
|
||||
const url =
|
||||
"chrome-extension://abc/assets/IconFamily-B8lopphU.woff";
|
||||
expect(resolveExtensionAssetUrl(url)).toBe(url);
|
||||
});
|
||||
|
||||
it("repairs accidental double extension URL prefix", () => {
|
||||
const doubled =
|
||||
"chrome-extension://abc/chrome-extension://abc/assets/IconFamily-B8lopphU.woff";
|
||||
expect(resolveExtensionAssetUrl(doubled)).toBe(
|
||||
"chrome-extension://abc/assets/IconFamily-B8lopphU.woff",
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,10 @@
|
||||
import browser from "webextension-polyfill";
|
||||
|
||||
/** Resolve Vite asset imports to a usable extension URL. */
|
||||
export function resolveExtensionAssetUrl(url: string): string {
|
||||
const doubled = url.match(/^((?:chrome|moz)-extension:\/\/[^/]+)\/\1\/(.+)$/);
|
||||
if (doubled) return `${doubled[1]}/${doubled[2]}`;
|
||||
if (/^(?:chrome|moz)-extension:\/\/|https?:|data:/.test(url)) return url;
|
||||
return browser.runtime.getURL(url.replace(/^\/+/, ""));
|
||||
}
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
import { describe, expect, it, jest } from "@jest/globals";
|
||||
|
||||
jest.mock("webextension-polyfill", () => ({
|
||||
__esModule: true,
|
||||
default: {
|
||||
runtime: {
|
||||
getURL: (path: string) => `chrome-extension://testid/${path}`,
|
||||
},
|
||||
},
|
||||
}));
|
||||
|
||||
import { extensionPageScriptUrl } from "./extensionPageScriptUrl";
|
||||
|
||||
describe("extensionPageScriptUrl", () => {
|
||||
it("prefixes chrome.runtime.getURL and strips a leading slash", () => {
|
||||
expect(extensionPageScriptUrl("assets/pageState.js")).toBe(
|
||||
"chrome-extension://testid/assets/pageState.js",
|
||||
);
|
||||
expect(extensionPageScriptUrl("/assets/pageState.js")).toBe(
|
||||
"chrome-extension://testid/assets/pageState.js",
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,10 @@
|
||||
import browser from "webextension-polyfill";
|
||||
|
||||
/**
|
||||
* Resolve a CRXJS `?script` / `?script&iife` import to a web-accessible
|
||||
* chrome-extension:// URL. Works in both `vite build` and `vite dev`
|
||||
* (plain `?url` imports 404 in CRXJS serve because they are not packaged).
|
||||
*/
|
||||
export function extensionPageScriptUrl(scriptPath: string): string {
|
||||
return browser.runtime.getURL(scriptPath.replace(/^\/+/, ""));
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
/** Material "dark_mode" moon icon — filled style to match SEQTA menu bar icons. */
|
||||
export const LUCIDE_MOON_PATH =
|
||||
"M12,3C7.03,3 3,7.03 3,12C3,16.97 7.03,21 12,21C16.97,21 21,16.97 21,12C21,11.54 20.96,11.08 20.9,10.64C19.92,12.01 18.32,12.9 16.5,12.9C13.52,12.9 11.1,10.48 11.1,7.5C11.1,5.68 11.99,4.08 13.36,3.1C12.92,3.04 12.46,3 12,3Z";
|
||||
|
||||
export const LUCIDE_MOON_ICON_SVG =
|
||||
`<path fill="currentColor" d="${LUCIDE_MOON_PATH}"/>`;
|
||||
@@ -0,0 +1,6 @@
|
||||
/** Material "light_mode" sun icon — filled style to match SEQTA menu bar icons. */
|
||||
export const LUCIDE_SUN_PATH =
|
||||
"M12,7C9.24,7 7,9.24 7,12C7,14.76 9.24,17 12,17C14.76,17 17,14.76 17,12C17,9.24 14.76,7 12,7M2,13H4C4.55,13 5,12.55 5,12C5,11.45 4.55,11 4,11H2C1.45,11 1,11.45 1,12C1,12.55 1.45,13 2,13M20,13H22C22.55,13 23,12.55 23,12C23,11.45 22.55,11 22,11H20C19.45,11 19,11.45 19,12C19,12.55 19.45,13 20,13M11,2V4C11,4.55 11.45,5 12,5C12.55,5 13,4.55 13,4V2C13,1.45 12.55,1 12,1C11.45,1 11,1.45 11,2M11,20V22C11,22.55 11.45,23 12,23C12.55,23 13,22.55 13,22V20C13,19.45 12.55,19 12,19C11.45,19 11,19.45 11,20M5.99,4.58C5.6,4.19 4.96,4.19 4.58,4.58C4.19,4.96 4.19,5.6 4.58,5.99L5.64,7.05C6.03,7.44 6.67,7.44 7.05,7.05C7.44,6.67 7.44,6.03 7.05,5.64L5.99,4.58M18.36,16.95C17.97,16.56 17.33,16.56 16.95,16.95C16.56,17.33 16.56,17.97 16.95,18.36L18.01,19.42C18.4,19.81 19.04,19.81 19.42,19.42C19.81,19.04 19.81,18.4 19.42,18.01L18.36,16.95M19.42,5.99C19.81,5.6 19.81,4.96 19.42,4.58C19.04,4.19 18.4,4.19 18.01,4.58L16.95,5.64C16.56,6.03 16.56,6.67 16.95,7.05C17.33,7.44 17.97,7.44 18.36,7.05L19.42,5.99M7.05,18.36C7.44,17.97 7.44,17.33 7.05,16.95C6.67,16.56 6.03,16.56 5.64,16.95L4.58,18.01C4.19,18.4 4.19,19.04 4.58,19.42C4.96,19.81 5.6,19.81 5.99,19.42L7.05,18.36Z";
|
||||
|
||||
export const LUCIDE_SUN_ICON_SVG =
|
||||
`<path fill="currentColor" d="${LUCIDE_SUN_PATH}"/>`;
|
||||
@@ -0,0 +1,43 @@
|
||||
import browser from "webextension-polyfill";
|
||||
|
||||
const ORT_RESOURCE_DIR = "resources/ort/";
|
||||
|
||||
let configured = false;
|
||||
|
||||
function extensionAssetUrl(relativePath: string): string {
|
||||
return browser.runtime.getURL(relativePath.replace(/^\/+/, ""));
|
||||
}
|
||||
|
||||
/**
|
||||
* Point HuggingFace transformers / onnxruntime at extension-local WASM files
|
||||
* instead of CDN (required on SEQTA pages where page CSP blocks jsdelivr).
|
||||
* Safe to call multiple times; must run before embeddia `initializeModel()`.
|
||||
*/
|
||||
export async function ensureTransformersEnv(
|
||||
ortWasmBase?: string,
|
||||
): Promise<void> {
|
||||
if (configured) return;
|
||||
|
||||
const { env } = await import("@huggingface/transformers");
|
||||
const base = ortWasmBase ?? extensionAssetUrl(ORT_RESOURCE_DIR);
|
||||
|
||||
env.backends.onnx.wasm = env.backends.onnx.wasm ?? {};
|
||||
env.backends.onnx.wasm.wasmPaths = base.endsWith("/") ? base : `${base}/`;
|
||||
|
||||
configured = true;
|
||||
}
|
||||
|
||||
export function getOrtWasmBaseUrl(): string {
|
||||
const base = extensionAssetUrl(ORT_RESOURCE_DIR);
|
||||
return base.endsWith("/") ? base : `${base}/`;
|
||||
}
|
||||
|
||||
/** For page-origin blob workers that cannot call `browser.runtime.getURL`. */
|
||||
export async function configureTransformersEnvForBase(
|
||||
ortWasmBase: string,
|
||||
): Promise<void> {
|
||||
configured = false;
|
||||
await ensureTransformersEnv(ortWasmBase);
|
||||
}
|
||||
|
||||
export { ORT_RESOURCE_DIR };
|
||||
@@ -15,17 +15,27 @@
|
||||
"64": "resources/icons/icon-64.png"
|
||||
}
|
||||
},
|
||||
"permissions": ["tabs", "notifications", "storage"],
|
||||
"host_permissions": ["https://newsapi.org/", "https://betterseqta.org/", "https://accounts.betterseqta.org/", "*://*/*"],
|
||||
"permissions": ["tabs", "notifications", "storage", "identity", "alarms", "userScripts"],
|
||||
"host_permissions": [
|
||||
"https://newsapi.org/",
|
||||
"https://betterseqta.org/",
|
||||
"https://accounts.betterseqta.org/",
|
||||
"https://www.googleapis.com/",
|
||||
"https://oauth2.googleapis.com/",
|
||||
"https://graph.microsoft.com/",
|
||||
"https://login.microsoftonline.com/",
|
||||
"*://*/*"
|
||||
],
|
||||
"background": {
|
||||
"service_worker": "background.ts"
|
||||
},
|
||||
"content_security_policy": {
|
||||
"extension_pages": "script-src 'self'; object-src 'self'; connect-src 'self' http: https: https://betterseqta.org https://accounts.betterseqta.org https://raw.githubusercontent.com https://newsapi.org"
|
||||
"extension_pages": "script-src 'self'; object-src 'self'; connect-src 'self' http: https: https://betterseqta.org https://accounts.betterseqta.org https://raw.githubusercontent.com https://newsapi.org https://www.googleapis.com https://oauth2.googleapis.com https://graph.microsoft.com https://login.microsoftonline.com"
|
||||
},
|
||||
"content_scripts": [
|
||||
{
|
||||
"matches": ["*://*/*"],
|
||||
"exclude_matches": ["*://accounts.betterseqta.org/*"],
|
||||
"js": ["SEQTA.ts"],
|
||||
"run_at": "document_start"
|
||||
}
|
||||
@@ -33,10 +43,14 @@
|
||||
"web_accessible_resources": [
|
||||
{
|
||||
"resources": [
|
||||
"resources/error-page/*",
|
||||
"resources/icons/*",
|
||||
"resources/update-image.webp",
|
||||
"resources/pdfjs/pdf.worker.min.mjs",
|
||||
"resources/pdfjs/pdf.legacy.min.mjs"
|
||||
"resources/pdfjs/pdf.legacy.min.mjs",
|
||||
"resources/ort/*",
|
||||
"assets/*.css",
|
||||
"assets/*"
|
||||
],
|
||||
"matches": ["*://*/*"]
|
||||
}
|
||||
|
||||
+99
-87
@@ -509,96 +509,108 @@ function deepFunctionCheck(obj, path = "") {
|
||||
}
|
||||
}
|
||||
|
||||
window.addEventListener("message", (event) => {
|
||||
if (event.data.type === "reactFiberRequest") {
|
||||
const { selector, action, payload, debug, messageId } = event.data;
|
||||
const fiberInstance = ReactFiber.find(selector, {
|
||||
debug,
|
||||
});
|
||||
function isTrustedMessage(event) {
|
||||
return event.source === window && event.origin === window.location.origin;
|
||||
}
|
||||
|
||||
let response;
|
||||
switch (action) {
|
||||
case "getState":
|
||||
response = fiberInstance.getState(payload.key);
|
||||
break;
|
||||
case "setState":
|
||||
// Handle both function and object updates
|
||||
if (payload.updateFn) {
|
||||
const updateFn = new Function('return ' + payload.updateFn)();
|
||||
fiberInstance.setState(updateFn);
|
||||
} else {
|
||||
fiberInstance.setState(payload.updateObject);
|
||||
}
|
||||
response = {};
|
||||
break;
|
||||
|
||||
case "getProp":
|
||||
response = fiberInstance.getProp(payload.propName);
|
||||
break;
|
||||
case "setProp":
|
||||
fiberInstance.setProp(payload.propName, payload.value);
|
||||
response = {};
|
||||
break;
|
||||
case "forceUpdate":
|
||||
fiberInstance.forceUpdate();
|
||||
response = {};
|
||||
break;
|
||||
default:
|
||||
console.warn(`[pageState] Unknown action: ${action}`);
|
||||
response = null;
|
||||
}
|
||||
|
||||
if (response !== null && typeof response === "object") {
|
||||
response = makeSerializable(response);
|
||||
}
|
||||
|
||||
// Final safety check before postMessage
|
||||
try {
|
||||
deepFunctionCheck(response);
|
||||
} catch (functionError) {
|
||||
console.warn("[pageState] Function detected in response, cleaning:", functionError.message);
|
||||
response = `[Cleaned Response - Function found at: ${functionError.message}]`;
|
||||
}
|
||||
|
||||
// Additional structured clone test
|
||||
try {
|
||||
// Test if the object can be cloned (same algorithm as postMessage)
|
||||
if (typeof structuredClone === 'function') {
|
||||
structuredClone(response);
|
||||
function executeReactFiberAction(fiberInstance, action, payload) {
|
||||
switch (action) {
|
||||
case "getState":
|
||||
return fiberInstance.getState(payload.key);
|
||||
case "setState":
|
||||
if (
|
||||
payload.updateObject &&
|
||||
typeof payload.updateObject === "object" &&
|
||||
!Array.isArray(payload.updateObject)
|
||||
) {
|
||||
fiberInstance.setState(payload.updateObject);
|
||||
} else {
|
||||
// Fallback for older browsers - try JSON round-trip
|
||||
JSON.parse(JSON.stringify(response));
|
||||
console.warn("[pageState] setState rejected: only plain objects are allowed");
|
||||
}
|
||||
} catch (cloneError) {
|
||||
console.warn("[pageState] Response not cloneable, fallback:", cloneError.message);
|
||||
response = `[Uncloneable Response: ${cloneError.message}]`;
|
||||
}
|
||||
return {};
|
||||
case "getProp":
|
||||
return fiberInstance.getProp(payload.propName);
|
||||
case "setProp":
|
||||
fiberInstance.setProp(payload.propName, payload.value);
|
||||
return {};
|
||||
case "forceUpdate":
|
||||
fiberInstance.forceUpdate();
|
||||
return {};
|
||||
default:
|
||||
console.warn(`[pageState] Unknown action: ${action}`);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
window.postMessage(
|
||||
{
|
||||
type: "reactFiberResponse",
|
||||
response,
|
||||
messageId,
|
||||
},
|
||||
"*",
|
||||
);
|
||||
} else if (event.data.type === "triggerKeyboardEvent") {
|
||||
// Handle keyboard event triggering from content script
|
||||
const { key, code, altKey, ctrlKey, metaKey, shiftKey, keyCode } = event.data;
|
||||
|
||||
const keyboardEvent = new KeyboardEvent('keydown', {
|
||||
key,
|
||||
code,
|
||||
keyCode: keyCode || 0,
|
||||
which: keyCode || 0,
|
||||
altKey: altKey || false,
|
||||
ctrlKey: ctrlKey || false,
|
||||
metaKey: metaKey || false,
|
||||
shiftKey: shiftKey || false,
|
||||
bubbles: true,
|
||||
cancelable: true
|
||||
});
|
||||
|
||||
document.dispatchEvent(keyboardEvent);
|
||||
function sanitizeResponseForPostMessage(response) {
|
||||
if (response !== null && typeof response === "object") {
|
||||
response = makeSerializable(response);
|
||||
}
|
||||
|
||||
try {
|
||||
deepFunctionCheck(response);
|
||||
} catch (functionError) {
|
||||
console.warn("[pageState] Function detected in response, cleaning:", functionError.message);
|
||||
return `[Cleaned Response - Function found at: ${functionError.message}]`;
|
||||
}
|
||||
|
||||
try {
|
||||
if (typeof structuredClone === "function") {
|
||||
structuredClone(response);
|
||||
} else {
|
||||
JSON.parse(JSON.stringify(response));
|
||||
}
|
||||
} catch (cloneError) {
|
||||
console.warn("[pageState] Response not cloneable, fallback:", cloneError.message);
|
||||
return `[Uncloneable Response: ${cloneError.message}]`;
|
||||
}
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
function handleReactFiberRequest(data) {
|
||||
const { selector, action, payload, debug, messageId } = data;
|
||||
const fiberInstance = ReactFiber.find(selector, { debug });
|
||||
const response = sanitizeResponseForPostMessage(
|
||||
executeReactFiberAction(fiberInstance, action, payload),
|
||||
);
|
||||
|
||||
window.postMessage(
|
||||
{
|
||||
type: "reactFiberResponse",
|
||||
response,
|
||||
messageId,
|
||||
},
|
||||
window.location.origin,
|
||||
);
|
||||
}
|
||||
|
||||
function handleTriggerKeyboardEvent(data) {
|
||||
const { key, code, altKey, ctrlKey, metaKey, shiftKey, keyCode } = data;
|
||||
const keyboardEvent = new KeyboardEvent("keydown", {
|
||||
key,
|
||||
code,
|
||||
keyCode: keyCode || 0,
|
||||
which: keyCode || 0,
|
||||
altKey: altKey || false,
|
||||
ctrlKey: ctrlKey || false,
|
||||
metaKey: metaKey || false,
|
||||
shiftKey: shiftKey || false,
|
||||
bubbles: true,
|
||||
cancelable: true,
|
||||
});
|
||||
document.dispatchEvent(keyboardEvent);
|
||||
}
|
||||
|
||||
window.addEventListener("message", (event) => {
|
||||
if (!isTrustedMessage(event)) return;
|
||||
|
||||
if (event.data.type === "reactFiberRequest") {
|
||||
handleReactFiberRequest(event.data);
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.data.type === "triggerKeyboardEvent") {
|
||||
handleTriggerKeyboardEvent(event.data);
|
||||
}
|
||||
});
|
||||
@@ -0,0 +1,104 @@
|
||||
<script lang="ts">
|
||||
type TabId = "create" | "mods" | "settings";
|
||||
|
||||
let {
|
||||
tabs,
|
||||
activeTab = $bindable("create" as TabId),
|
||||
disabled = false,
|
||||
}: {
|
||||
tabs: { id: TabId; label: string }[];
|
||||
activeTab?: TabId;
|
||||
disabled?: boolean;
|
||||
} = $props();
|
||||
|
||||
const activeIndex = $derived(
|
||||
Math.max(
|
||||
0,
|
||||
tabs.findIndex((tab) => tab.id === activeTab),
|
||||
),
|
||||
);
|
||||
</script>
|
||||
|
||||
<div class="tab-nav" aria-label="Creator sections">
|
||||
<div class="tab-track" role="tablist">
|
||||
<div
|
||||
class="tab-indicator"
|
||||
style="width: {100 / tabs.length}%; transform: translateX({activeIndex * 100}%)"
|
||||
aria-hidden="true"
|
||||
></div>
|
||||
{#each tabs as tab (tab.id)}
|
||||
<button
|
||||
type="button"
|
||||
class="tab-button accent-ring"
|
||||
role="tab"
|
||||
aria-selected={activeTab === tab.id}
|
||||
disabled={disabled}
|
||||
onclick={() => (activeTab = tab.id)}
|
||||
>
|
||||
{tab.label}
|
||||
</button>
|
||||
{/each}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<style>
|
||||
.tab-nav {
|
||||
padding: 12px 16px 0;
|
||||
font-size: 0.75rem;
|
||||
}
|
||||
|
||||
.tab-track {
|
||||
position: relative;
|
||||
display: flex;
|
||||
}
|
||||
|
||||
.tab-indicator {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
height: 100%;
|
||||
border-radius: 9999px;
|
||||
background: linear-gradient(
|
||||
to top right,
|
||||
rgb(56 55 61 / 0.8),
|
||||
rgb(56 55 61)
|
||||
);
|
||||
opacity: 0.45;
|
||||
pointer-events: none;
|
||||
transition: transform 380ms cubic-bezier(0.34, 1.45, 0.64, 1);
|
||||
will-change: transform;
|
||||
}
|
||||
|
||||
.tab-button {
|
||||
position: relative;
|
||||
z-index: 1;
|
||||
flex: 1;
|
||||
padding: 8px 12px;
|
||||
border: 0;
|
||||
border-radius: 9999px;
|
||||
background: transparent;
|
||||
color: inherit;
|
||||
font-size: inherit;
|
||||
font-weight: 600;
|
||||
transition: opacity 180ms ease;
|
||||
}
|
||||
|
||||
.tab-button[aria-selected="true"] {
|
||||
color: #f4f4f5;
|
||||
}
|
||||
|
||||
.tab-button[aria-selected="false"] {
|
||||
opacity: 0.72;
|
||||
}
|
||||
|
||||
.tab-button:disabled {
|
||||
cursor: not-allowed;
|
||||
opacity: 0.45;
|
||||
}
|
||||
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
.tab-indicator {
|
||||
transition: none;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,326 @@
|
||||
<script lang="ts">
|
||||
import { tick } from "svelte";
|
||||
import { fade, fly } from "svelte/transition";
|
||||
import LoadingSpinnerMini from "./LoadingSpinnerMini.svelte";
|
||||
|
||||
let {
|
||||
status = "",
|
||||
tokenUsage = "",
|
||||
streamChunks = [],
|
||||
error = "",
|
||||
onBack,
|
||||
}: {
|
||||
status?: string;
|
||||
tokenUsage?: string;
|
||||
streamChunks?: string[];
|
||||
error?: string;
|
||||
onBack: () => void;
|
||||
} = $props();
|
||||
|
||||
let streamContainer = $state<HTMLElement | null>(null);
|
||||
|
||||
$effect(() => {
|
||||
if (streamChunks.length === 0 || !streamContainer) return;
|
||||
void tick().then(() => {
|
||||
streamContainer?.scrollTo({
|
||||
top: streamContainer.scrollHeight,
|
||||
behavior: "smooth",
|
||||
});
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
<div
|
||||
class="generating-view"
|
||||
aria-live="polite"
|
||||
aria-busy={!error}
|
||||
>
|
||||
{#if error}
|
||||
<div
|
||||
class="error-card"
|
||||
role="alert"
|
||||
in:fly={{ y: 10, duration: 420, easing: (t) => 1 + 0.36 * Math.pow(t - 1, 3) + 0.22 * Math.pow(t - 1, 2) }}
|
||||
>
|
||||
<p class="error-title">Generation failed</p>
|
||||
<p class="error-message">{error}</p>
|
||||
<button class="secondary-button w-full accent-ring" type="button" onclick={onBack}>
|
||||
Go back and try again
|
||||
</button>
|
||||
</div>
|
||||
{:else}
|
||||
<div class="generating-header">
|
||||
<LoadingSpinnerMini />
|
||||
<div class="min-w-0">
|
||||
<h3 class="generating-title">Generating mod recipe</h3>
|
||||
{#key status}
|
||||
<p class="generating-status" in:fade={{ duration: 280 }}>
|
||||
{status || "Connecting to model…"}
|
||||
</p>
|
||||
{/key}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="generating-meta">
|
||||
<span class="pulse-dot" aria-hidden="true"></span>
|
||||
<span class="meta-label">Streaming response</span>
|
||||
{#if tokenUsage}
|
||||
<span class="token-badge" in:fly={{ y: 6, duration: 280 }}>
|
||||
{tokenUsage}
|
||||
</span>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
<div
|
||||
bind:this={streamContainer}
|
||||
class="stream-panel"
|
||||
data-testid="generation-stream"
|
||||
>
|
||||
{#if streamChunks.length === 0}
|
||||
<div class="stream-placeholder" in:fade={{ duration: 320 }}>
|
||||
<span class="skeleton-line"></span>
|
||||
<span class="skeleton-line skeleton-line--short"></span>
|
||||
<span class="skeleton-line skeleton-line--medium"></span>
|
||||
</div>
|
||||
{:else}
|
||||
<pre class="stream-output">
|
||||
{#each streamChunks as chunk, index (index)}
|
||||
<span class="stream-chunk" in:fly={{ y: 8, duration: 220, delay: 16 }}>
|
||||
{chunk}
|
||||
</span>
|
||||
{/each}
|
||||
<span class="stream-cursor" aria-hidden="true"></span>
|
||||
</pre>
|
||||
{/if}
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
<style>
|
||||
.generating-view {
|
||||
display: flex;
|
||||
min-height: 320px;
|
||||
flex-direction: column;
|
||||
gap: 16px;
|
||||
}
|
||||
|
||||
.generating-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 14px;
|
||||
}
|
||||
|
||||
.generating-title {
|
||||
font-size: 1rem;
|
||||
font-weight: 600;
|
||||
line-height: 1.4;
|
||||
color: #f4f4f5;
|
||||
}
|
||||
|
||||
.generating-status {
|
||||
margin-top: 2px;
|
||||
font-size: 0.875rem;
|
||||
line-height: 1.5;
|
||||
color: rgba(244, 244, 245, 0.62);
|
||||
}
|
||||
|
||||
.generating-meta {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
font-size: 0.75rem;
|
||||
font-weight: 600;
|
||||
letter-spacing: 0.04em;
|
||||
text-transform: uppercase;
|
||||
color: rgba(244, 244, 245, 0.52);
|
||||
}
|
||||
|
||||
.pulse-dot {
|
||||
width: 8px;
|
||||
height: 8px;
|
||||
border-radius: 9999px;
|
||||
background: var(--better-main, #8b5cf6);
|
||||
animation: pulse-dot 1.4s ease-in-out infinite;
|
||||
}
|
||||
|
||||
.token-badge {
|
||||
margin-left: auto;
|
||||
padding: 4px 10px;
|
||||
border: 1px solid rgba(255, 255, 255, 0.12);
|
||||
border-radius: 9999px;
|
||||
font-size: 0.6875rem;
|
||||
font-weight: 600;
|
||||
letter-spacing: 0;
|
||||
text-transform: none;
|
||||
color: rgba(244, 244, 245, 0.82);
|
||||
background: rgba(255, 255, 255, 0.06);
|
||||
}
|
||||
|
||||
.stream-panel {
|
||||
flex: 1;
|
||||
min-height: 220px;
|
||||
max-height: 360px;
|
||||
overflow: auto;
|
||||
padding: 14px;
|
||||
border: 1px solid rgba(255, 255, 255, 0.1);
|
||||
border-radius: 12px;
|
||||
background:
|
||||
linear-gradient(180deg, rgb(255 255 255 / 0.03) 0%, transparent 100%),
|
||||
rgb(0 0 0 / 0.35);
|
||||
box-shadow: inset 0 1px 0 rgb(255 255 255 / 0.04);
|
||||
scroll-behavior: smooth;
|
||||
}
|
||||
|
||||
.stream-panel::-webkit-scrollbar {
|
||||
width: 6px;
|
||||
}
|
||||
|
||||
.stream-panel::-webkit-scrollbar-thumb {
|
||||
border-radius: 9999px;
|
||||
background: rgb(255 255 255 / 0.14);
|
||||
}
|
||||
|
||||
.stream-placeholder {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.skeleton-line {
|
||||
display: block;
|
||||
height: 10px;
|
||||
border-radius: 9999px;
|
||||
background: linear-gradient(
|
||||
90deg,
|
||||
rgb(255 255 255 / 0.06) 0%,
|
||||
rgb(255 255 255 / 0.12) 50%,
|
||||
rgb(255 255 255 / 0.06) 100%
|
||||
);
|
||||
background-size: 200% 100%;
|
||||
animation: skeleton-shimmer 1.6s ease-in-out infinite;
|
||||
}
|
||||
|
||||
.skeleton-line--short {
|
||||
width: 55%;
|
||||
}
|
||||
|
||||
.skeleton-line--medium {
|
||||
width: 78%;
|
||||
}
|
||||
|
||||
.stream-output {
|
||||
margin: 0;
|
||||
overflow-wrap: anywhere;
|
||||
white-space: pre-wrap;
|
||||
word-break: break-word;
|
||||
font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
|
||||
font-size: 0.8125rem;
|
||||
line-height: 1.55;
|
||||
color: #e4e4e7;
|
||||
}
|
||||
|
||||
.stream-chunk {
|
||||
display: inline;
|
||||
}
|
||||
|
||||
.stream-cursor {
|
||||
display: inline-block;
|
||||
width: 2px;
|
||||
height: 1em;
|
||||
margin-left: 1px;
|
||||
vertical-align: text-bottom;
|
||||
background: var(--better-main, #8b5cf6);
|
||||
animation: cursor-blink 1s step-end infinite;
|
||||
}
|
||||
|
||||
.error-card {
|
||||
display: flex;
|
||||
flex: 1;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
gap: 12px;
|
||||
padding: 20px;
|
||||
border: 1px solid rgb(248 113 113 / 0.4);
|
||||
border-radius: 12px;
|
||||
background: rgb(127 29 29 / 0.28);
|
||||
backdrop-filter: blur(6px);
|
||||
}
|
||||
|
||||
.error-title {
|
||||
font-size: 1rem;
|
||||
font-weight: 600;
|
||||
color: rgb(252 165 165);
|
||||
}
|
||||
|
||||
.error-message {
|
||||
font-size: 0.875rem;
|
||||
line-height: 1.6;
|
||||
color: rgb(254 202 202);
|
||||
}
|
||||
|
||||
.secondary-button {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 8px;
|
||||
padding: 8px 16px;
|
||||
border: 1px solid rgba(255, 255, 255, 0.12);
|
||||
border-radius: 10px;
|
||||
font-size: 0.775rem;
|
||||
font-weight: 600;
|
||||
color: inherit;
|
||||
background: rgb(255 255 255 / 0.05);
|
||||
transition: all 220ms cubic-bezier(0.22, 1, 0.36, 1);
|
||||
}
|
||||
|
||||
.secondary-button:hover {
|
||||
transform: scale(1.03);
|
||||
border-color: rgb(96 165 250 / 0.28);
|
||||
}
|
||||
|
||||
.secondary-button:active {
|
||||
transform: scale(0.97);
|
||||
}
|
||||
|
||||
@keyframes pulse-dot {
|
||||
0%,
|
||||
100% {
|
||||
opacity: 1;
|
||||
transform: scale(1);
|
||||
}
|
||||
|
||||
50% {
|
||||
opacity: 0.45;
|
||||
transform: scale(0.85);
|
||||
}
|
||||
}
|
||||
|
||||
@keyframes skeleton-shimmer {
|
||||
0% {
|
||||
background-position: 200% 0;
|
||||
}
|
||||
|
||||
100% {
|
||||
background-position: -200% 0;
|
||||
}
|
||||
}
|
||||
|
||||
@keyframes cursor-blink {
|
||||
0%,
|
||||
100% {
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
50% {
|
||||
opacity: 0;
|
||||
}
|
||||
}
|
||||
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
.pulse-dot,
|
||||
.skeleton-line,
|
||||
.stream-cursor {
|
||||
animation: none;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
Loaded 100 of 369 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user