Skip to content
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,195 changes: 1,177 additions & 18 deletions bun.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@
"markdown-it-texmath": "^1.0.0",
"mermaid": "^11.14.0",
"mime-types": "^3.0.2",
"motion": "^12.42.0",
"mustache": "^4.2.0",
"picomatch": "^4.0.4",
"url-parse": "^1.5.10",
Expand Down
61 changes: 57 additions & 4 deletions src/components/WebComponents/wcPage.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { animate, press } from "motion";
import tile from "../tile";

export default class WCPage extends HTMLElement {
Expand Down Expand Up @@ -53,6 +54,21 @@ export default class WCPage extends HTMLElement {
></span>
);

press(this.#leadBtn, (element) => {
animate(
element,
{ scale: 0.85 },
{ type: "spring", stiffness: 400, damping: 20 },
);
return () => {
animate(
element,
{ scale: 1 },
{ type: "spring", stiffness: 400, damping: 20 },
);
};
});

this.#header = tile({
type: "header",
text: title || "Page",
Expand Down Expand Up @@ -80,6 +96,25 @@ export default class WCPage extends HTMLElement {

connectedCallback() {
this.classList.remove("hide");
const isPrimary = this.classList.contains("primary");
const isNoTransition = this.classList.contains("no-transition");

if (!isPrimary) {
this.style.opacity = "0";
animate(
this,
{
opacity: 1,
},
{
duration: isNoTransition ? 0.08 : 0.14,
ease: "easeOut",
},
).then(() => {
this.style.opacity = "";
});
}
Comment thread
greptile-apps[bot] marked this conversation as resolved.

if (typeof this.onconnect === "function") this.onconnect();
this.#on.show.forEach((cb) => cb.call(this));
}
Expand Down Expand Up @@ -120,12 +155,29 @@ export default class WCPage extends HTMLElement {
}

hide() {
this.classList.add("hide");
if (typeof this.onhide === "function") this.onhide();
setTimeout(() => {

const isPrimary = this.classList.contains("primary");
const isNoTransition = this.classList.contains("no-transition");

if (isPrimary) {
this.remove();
this.handler.remove();
}, 150);
} else {
animate(
this,
{
opacity: 0,
},
{
duration: isNoTransition ? 0.08 : 0.12,
ease: "easeIn",
},
).then(() => {
this.remove();
this.handler.remove();
});
}
}

get body() {
Expand Down Expand Up @@ -239,6 +291,7 @@ class PageHandler {
* Replace current element with a replacement element
*/
replaceEl() {
if (this.$el.classList.contains("primary")) return;
this.$el.off("hide", this.onhide);
if (!this.$el.isConnected || this.$replacement.isConnected) return;
if (typeof this.onReplace === "function") this.onReplace();
Expand Down Expand Up @@ -285,7 +338,7 @@ class PageHandler {
*/
function handlePagesForSmoothExperience() {
const $pages = [...tag.getAll("wc-page")];
for (let $page of $pages.slice(0, -1)) {
for (let $page of $pages.slice(0, -2)) {
$page.handler.replaceEl();
}
}
Expand Down
55 changes: 51 additions & 4 deletions src/components/checkbox/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import "./styles.scss";
import Ref from "html-tag-js/ref";
import { animate } from "motion";

/**
* @typedef {Object} Checkbox
Expand All @@ -23,35 +24,81 @@ import Ref from "html-tag-js/ref";
* @param {string} [size] Size of checkbox
* @returns {Checkbox & HTMLLabelElement}
*/
function Checkbox(text, checked, name, id, type, ref, size) {
function Checkbox(text, checked, name, id, type, ref, size, isSwitch) {
if (typeof text === "object") {
({ text, checked, name, id, type, ref, size } = text);
({ text, checked, name, id, type, ref, size, isSwitch } = text);
}

size = size || "1rem";

const $input = ref || Ref();
const $handle = Ref();
const $checkbox = (
<label className="input-checkbox">
<label className={`input-checkbox ${isSwitch ? "switch" : ""}`}>
<input
ref={$input}
checked={checked}
type={type || "checkbox"}
name={name}
id={id}
onchange={handleChange}
/>
<span style={{ height: size, width: size }} className="box"></span>
<span style={{ height: size, width: size }} className="box">
<span ref={$handle} className="handle"></span>
</span>
<span>{text}</span>
</label>
);

function updateToggle(animateToggle = true) {
const isSwitch =
$checkbox.classList.contains("switch") ||
$checkbox.closest(
".detail-settings-list, .main-settings-list, .settings-search-section",
) !== null;

if (isSwitch && $handle.el) {
const isChecked = !!$input.el.checked;
const targetTransform = isChecked
? "translate3d(1.12rem, 0, 0)"
: "translate3d(0, 0, 0)";

if (animateToggle) {
animate(
$handle.el,
{
transform: targetTransform,
},
{
type: "spring",
stiffness: 500,
damping: 28,
},
).then(() => {
$handle.el.style.transform = targetTransform;
});
} else {
$handle.el.style.transform = targetTransform;
}
}
}

function handleChange() {
updateToggle(true);
}

requestAnimationFrame(() => {
updateToggle(false);
});

Object.defineProperties($checkbox, {
checked: {
get() {
return !!$input.el.checked;
},
set(value) {
$input.el.checked = value;
updateToggle(true);
},
},
onclick: {
Expand Down
14 changes: 8 additions & 6 deletions src/components/checkbox/styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,29 @@
border: solid 1px var(--secondary-text-color);
margin: 0 5px;

&::after {
content: '';
.handle {
display: block;
height: 80%;
width: 80%;
background-color: #3399ff;
background-color: var(--button-background-color);
margin: auto;
border-radius: 2px;
transition: opacity 140ms ease;
}
}

input:checked {
&+.box::after {
&+.box .handle {
opacity: 1;
}
}

input:not(:checked) {
&+.box::after {
opacity: 0;
&:not(.switch) {
input:not(:checked) {
&+.box .handle {
opacity: 0;
}
}
}
}
53 changes: 52 additions & 1 deletion src/components/settingsPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import Ref from "html-tag-js/ref";
import actionStack from "lib/actionStack";
import appSettings from "lib/settings";
import { hideAd } from "lib/startAd";
import { animate, hover, press } from "motion";
import FileBrowser from "pages/fileBrowser";
import { isValidColor } from "utils/color/regex";
import helpers from "utils/helpers";
Expand Down Expand Up @@ -372,7 +373,17 @@ function createListItemElement(item, options, useInfoAsDescription) {
}

if (isCheckboxItem) {
const $checkbox = Checkbox("", item.checkbox || item.value);
const $checkbox = Checkbox(
"",
item.checkbox || item.value,
undefined,
undefined,
undefined,
undefined,
undefined,
true,
);
$checkbox.classList.add("switch");
$tail.el.appendChild($checkbox);
}

Expand Down Expand Up @@ -405,9 +416,49 @@ function createListItemElement(item, options, useInfoAsDescription) {
$tail.el.remove();
}

// Register high-performance press transitions
press($item, (element) => {
animate(
element,
{ scale: 0.985 },
{ type: "spring", stiffness: 450, damping: 25 },
);
return () => {
animate(
element,
{ scale: 1 },
{ type: "spring", stiffness: 450, damping: 25 },
);
};
});

if (supportsPrimaryHoverInput()) {
hover($item, (element) => {
animate(
element,
{
backgroundColor:
"color-mix(in srgb, var(--secondary-color), var(--popup-text-color) 4%)",
},
{ duration: 0.15 },
);
return () => {
animate(
element,
{ backgroundColor: "transparent" },
{ duration: 0.15 },
);
};
});
}

return $item;
}

function supportsPrimaryHoverInput() {
return globalThis.matchMedia?.("(hover: hover)").matches === true;
}

function isBooleanSetting(item) {
return item.checkbox !== undefined || typeof item.value === "boolean";
}
Expand Down
Loading