feat(user-apps): appearance settings (dark mode + reduced motion), product morph, filter sheet

Applies to both user-app and user-app-v2. Logic and structure are shared;
each app keeps its own look.

Appearance settings
- New "تنظیمات ظاهری" page (/settings/appearance), opened from the
  dashboard and available without login. It offers a light/dark/system
  theme and a "fast & light" motion switch.
- appearanceStore saves the choice to localStorage. A small inline boot
  script in index.html applies it before first paint so there is no
  white flash. The "system" option follows OS changes live.
- New ToggleSwitch component.

Dark mode
- Theme LESS tokens now compile to CSS custom properties. Light/dark
  values come from a generated virtual:palette.css (themeConfig/
  appearance.ts, with colors.json + new colors.dark.json).
- New LESS alpha() plugin replaces fade() on theme tokens.
- New semantic tokens: page, onInk, heroSurface, hairlineStrong,
  photoMat, photoStage.
- The dark palette is layered (page < card < panel < border) so
  surfaces separate without shadows.
- Hard-coded colors were replaced by tokens according to their role.
- antd inputs/text get dark overrides; vant uses its own
  .van-theme-dark.
- Light mode looks the same as before.

Reduced motion
- With html.motion-reduced, transitions are capped at 120ms, keyframe
  loops stop, and backdrop blurs and permanent will-change are dropped.
- Spinners and the toast progress bar (which closes the toast) are
  exempt via .keep-motion.
- Carousel autoplay, the v1 Lottie and the product morph honor the
  setting.

Product detail
- Opening a product is now a container-transform morph from the tapped
  card (ProductMorph). It replaces the bottom Drawer and uses composited
  transform/opacity only.
- The detail view is seeded with the card's data, so it no longer
  opens blank and jumps.

Filters and sheets
- Filters are now a full-width bottom sheet. Selections stay a draft
  until applied, so the result list no longer re-renders while
  dragging the slider.
- DropDown collapse animates grid-template-rows instead of a capped
  max-height.
- v2 IslandSheet is restyled to the v2 design language (API unchanged).

Fixes
- filtersStore.reset() shallow-copied shared arrays, so clearing the
  filters never cleared the selected brands.
This commit is contained in:
s.esmaeili
2026-10-04 16:18:56 +03:30
parent c05352d6fd
commit f441ca8289
102 changed files with 4602 additions and 1053 deletions
+474 -179
View File
@@ -13,7 +13,7 @@
- Gram-range filter: real, bounds derived from the actual min/max
rashWeightGrams across all variants (rather than a customer-specific
server-provided bound). Still uses ant-design-vue's Slider for the actual
drag/range behaviour, restyled via :deep() to the wine accent.
drag/range behaviour, restyled to the app's accent.
- DROPPED: color filter — no color concept exists anywhere in the new
Product/ProductVariant schema, not a stubbed-off feature like promotions,
genuinely nothing to filter by.
@@ -23,72 +23,139 @@
concept in the new Customer model).
- DROPPED: discount toggle — no promotions data exists (see useProduct.ts).
Top padding (120px) accounts for PageBar + the search input row with no
chips row below it (chips are hidden while this sheet is open) — same
bar-chrome math SearchView/OrdersView use for their own #below content.
Presentation: a bottom sheet over a dimmed, see-through backdrop. Full width
and attached to the bottom edge — not a floating island, so it has room to
take more filters later — and only as tall as its content, up to 88% of the
screen, past which the body scrolls under a fixed header and action bar.
It replaced an in-place swap of the search page's body (results hidden with
v-show, the bar retitled and its back button hijacked, the tab bar hidden),
which was neither a page nor a modal. Closes on the backdrop, a swipe down
on its header, the × button, or the hardware/browser back
(close-on-popstate).
STRUCTURE IS SHARED, LOOK IS NOT. The template and script here are kept
identical to user-app's Filters.vue; each app styles the same markup in its
own design language (this one: white sheet with the 32px top radius the
detail page's sheet uses, borderless @hairlineSoft panels via DropDown, @ink
pill buttons and chips, squircle controls, @wine accent).
Choices are a DRAFT until "اعمال فیلتر": nothing touches the filters store
while the sheet is open, so dragging the gram slider no longer re-filters and
re-renders the whole result grid behind it on every pointer move (it did, and
that was most of the lag). Dismissing without applying discards the draft.
"پاک کردن فیلتر‌ها" clears only what this sheet owns (brands, gram range) —
it used to reset the whole query, wiping the search text and the category
chip along with it.
-->
<template>
<section class="filt">
<div class="filt__body">
<DropDown text="فیلتر بر اساس برند">
<div v-if="availableBrands.length" class="filt__chips">
<button
v-for="item in availableBrands"
:key="item.id"
type="button"
class="filt__chip"
:class="{ 'is-on': modelValue.brands.includes(item.id) }"
@click="toggleBrand(item.id)"
>
{{ item.title }}
<Popup
:show="show"
position="bottom"
teleport="body"
transition="fSheet-slide"
class="fSheet"
overlay-class="fSheet__overlay"
close-on-popstate
@update:show="emit('update:show', $event)"
@closed="dragY = 0"
>
<div
class="fSheet__card"
:class="{ 'is-dragging': dragging }"
:style="cardStyle"
dir="rtl"
role="dialog"
aria-modal="true"
aria-labelledby="fSheet-title"
>
<!-- The drag handle area. Swipe-to-dismiss starts only here, so a
vertical swipe on the body still scrolls the filters. -->
<header
class="fSheet__head"
@touchstart.passive="onTouchStart"
@touchmove.passive="onTouchMove"
@touchend="onTouchEnd"
@touchcancel="onTouchEnd"
>
<span class="fSheet__grip" aria-hidden="true"></span>
<div class="fSheet__headRow">
<h3 id="fSheet-title" class="fSheet__title">
فیلترها
<span v-if="draftCount" class="fSheet__count">{{ draftCount }}</span>
</h3>
<button type="button" class="fSheet__close" aria-label="بستن" @click="close">
<Icon icon="vuesax-linear:add" size="18" />
</button>
</div>
<p v-else class="filt__empty">برندی برای فیلتر موجود نیست.</p>
</DropDown>
</header>
<DropDown text="فیلتر بر اساس گرم">
<div class="filt__gram">
<Slider
v-model:value="(modelValue.limit_gram as unknown as [number, number])"
:step="0.01"
range
reverse
:min="gramBounds[0]"
:max="gramBounds[1]"
/>
<div class="filt__gramFigures" v-if="modelValue.limit_gram.length > 0">
<span class="filt__gramFigure">
<i>کمترین</i>
{{ modelValue.limit_gram[0] }} گرم
</span>
<span class="filt__gramFigure">
<i>بیشترین</i>
{{ modelValue.limit_gram[1] }} گرم
</span>
<div class="fSheet__body">
<DropDown text="برند" default-open>
<div v-if="availableBrands.length" class="fSheet__chips">
<button
v-for="item in availableBrands"
:key="item.id"
type="button"
class="fSheet__chip"
:class="{ 'is-on': draftBrands.includes(item.id) }"
:aria-pressed="draftBrands.includes(item.id)"
@click="toggleBrand(item.id)"
>
{{ item.title }}
</button>
</div>
</div>
</DropDown>
</div>
<p v-else class="fSheet__empty">برندی برای فیلتر موجود نیست.</p>
</DropDown>
<div class="filt__bar">
<div class="filt__barInner">
<button type="button" class="filt__clear" @click="closeFilters(false)">پاک کردن فیلتر‌ها</button>
<button type="button" class="filt__apply" @click="closeFilters(true)">اعمال فیلتر</button>
<DropDown text="وزن (گرم)" default-open>
<div class="fSheet__gram">
<!-- Tooltips off: they render in ant's own layer (z-index 1070),
underneath this sheet (vant's 2000+), and the figures below
already show both values live. -->
<Slider
:value="draftGram"
:step="0.01"
range
reverse
:min="gramBounds[0]"
:max="gramBounds[1]"
:tooltip-visible="false"
@update:value="onGram"
/>
<div class="fSheet__gramFigures">
<span class="fSheet__gramFigure">
<i>کمترین</i>
<b>{{ fmt(draftGram[0]) }}</b> گرم
</span>
<span class="fSheet__gramFigure">
<i>بیشترین</i>
<b>{{ fmt(draftGram[1]) }}</b> گرم
</span>
</div>
</div>
</DropDown>
</div>
<footer class="fSheet__bar">
<button type="button" class="fSheet__clear" @click="clear">پاک کردن</button>
<button type="button" class="fSheet__apply" @click="apply">اعمال فیلتر</button>
</footer>
</div>
</section>
</Popup>
</template>
<script setup lang="ts">
import { computed, watch } from 'vue'
import { computed, ref, watch } from 'vue'
import { Popup } from 'vant'
import { Slider } from 'ant-design-vue'
import Icon from '../icon/Icon.vue'
import DropDown from '../ui/DropDown.vue'
import type { FiltersQuery } from '../../stores/filtersStore'
import type { ProductSummary } from '../../api/client'
const props = withDefaults(defineProps<{ modelValue: FiltersQuery; filterKeys: string[]; products: ProductSummary[] }>(), {})
const props = defineProps<{ show: boolean; modelValue: FiltersQuery; filterKeys: string[]; products: ProductSummary[] }>()
const emit = defineEmits<{
(e: 'change', value: { resetFilters: boolean }): void
(e: 'update:show', value: boolean): void
(e: 'update:filterKeys', value: string[]): void
}>()
@@ -106,185 +173,413 @@ const gramBounds = computed((): [number, number] => {
return [Math.floor(Math.min(...weights)), Math.ceil(Math.max(...weights))]
})
// The Slider's `range` mode needs a real [start, end] value to place its two
// handles — filtersStore's default `limit_gram: []` has neither, so until
// this seeds it, ant-design-vue's Slider has nothing to derive handle
// positions from and renders no handles at all. Only seeds while still
// empty, so it never clobbers a value the user already dragged.
// ── Draft ─────────────────────────────────────────────────────
const draftBrands = ref<string[]>([])
// Always a real [start, end] pair: ant-design-vue's range Slider places no
// handles at all without one.
const draftGram = ref<[number, number]>([...gramBounds.value])
// Until the user drags, the range follows the catalogue's bounds (they can
// still arrive after the sheet first opens, while the list is loading).
let gramTouched = false
function loadDraft() {
draftBrands.value = [...props.modelValue.brands]
const g = props.modelValue.limit_gram
gramTouched = g.length === 2
draftGram.value = g.length === 2 ? [g[0], g[1]] : [...gramBounds.value]
}
watch(
gramBounds,
(bounds) => {
if (props.modelValue.limit_gram.length === 0) {
props.modelValue.limit_gram = [...bounds]
}
() => props.show,
(open) => {
if (open) loadDraft()
},
{ immediate: true },
)
const toggleBrand = (id: string) => {
const brands = props.modelValue.brands
const index = brands.indexOf(id)
if (index === -1) brands.push(id)
else brands.splice(index, 1)
watch(gramBounds, (bounds) => {
if (!gramTouched) draftGram.value = [...bounds]
})
function onGram(value: [number, number] | number) {
if (!Array.isArray(value)) return
draftGram.value = [value[0], value[1]]
gramTouched = true
}
const closeFilters = (sendQuery: boolean): void => {
const filterKeys: string[] = []
if (sendQuery) {
if (props.modelValue.brands.length > 0) filterKeys.push('brands')
if (
props.modelValue.limit_gram[0] !== undefined &&
props.modelValue.limit_gram[1] !== undefined &&
(props.modelValue.limit_gram[0] !== gramBounds.value[0] || props.modelValue.limit_gram[1] !== gramBounds.value[1])
) {
filterKeys.push('limit_gram')
}
}
if (sendQuery && filterKeys.length > 0) {
emit('update:filterKeys', filterKeys)
emit('change', { resetFilters: false })
} else {
emit('update:filterKeys', [])
emit('change', { resetFilters: true })
}
// A range that still spans the whole catalogue filters nothing out, so it is
// not counted as a filter (and is stored as "no range" on apply).
const gramActive = computed(() => {
const [lo, hi] = draftGram.value
const [min, max] = gramBounds.value
return Math.abs(lo - min) > 0.001 || Math.abs(hi - max) > 0.001
})
const draftCount = computed(() => draftBrands.value.length + (gramActive.value ? 1 : 0))
function toggleBrand(id: string) {
const i = draftBrands.value.indexOf(id)
draftBrands.value = i === -1 ? [...draftBrands.value, id] : draftBrands.value.filter((b) => b !== id)
}
function fmt(n: number) {
return n % 1 === 0 ? String(n) : String(+n.toFixed(2))
}
// ── Commit ────────────────────────────────────────────────────
// Always assigns fresh arrays rather than mutating the store's in place — see
// filtersStore's reset() for why sharing them went wrong.
function apply() {
const q = props.modelValue
q.brands = [...draftBrands.value]
q.limit_gram = gramActive.value ? [...draftGram.value] : []
const keys: string[] = []
if (q.brands.length) keys.push('brands')
if (q.limit_gram.length) keys.push('limit_gram')
emit('update:filterKeys', keys)
close()
}
function clear() {
draftBrands.value = []
draftGram.value = [...gramBounds.value]
gramTouched = false
apply()
}
function close() {
emit('update:show', false)
}
// ── Swipe down to dismiss (header only) ───────────────────────
// The sheet follows the finger down, rubber-bands up, and on release either
// springs back or leaves from where it was let go.
const DISMISS_DISTANCE = 90
const DISMISS_VELOCITY = 0.5 // px per ms
const dragY = ref(0)
const dragging = ref(false)
let startY = 0
let startTime = 0
const cardStyle = computed(() => (dragY.value ? { transform: `translate3d(0, ${dragY.value}px, 0)` } : undefined))
function onTouchStart(e: TouchEvent) {
if ((e.target as HTMLElement).closest('button')) return
startY = e.touches[0].clientY
startTime = Date.now()
dragging.value = true
}
function onTouchMove(e: TouchEvent) {
if (!dragging.value) return
const dy = e.touches[0].clientY - startY
dragY.value = dy > 0 ? dy : dy * 0.12
}
function onTouchEnd() {
if (!dragging.value) return
dragging.value = false
const velocity = dragY.value / Math.max(1, Date.now() - startTime)
if (dragY.value > DISMISS_DISTANCE || (dragY.value > 30 && velocity > DISMISS_VELOCITY)) close()
else dragY.value = 0
}
</script>
<style scoped lang="less">
.filt {
background: @canvas;
min-height: 100vh;
<style lang="less">
// Global, not scoped: the popup is teleported to <body>. Everything is under
// the fSheet prefix.
/* ── Shell (same in both apps) ──────────────────────────────── */
// See-through dim, no blur: blurring the page behind a fading overlay is
// recomputed every frame and is what made sheets janky on phones.
.fSheet__overlay {
background: rgba(20, 22, 26, 0.42);
}
.filt__body {
.fSheet.van-popup {
background: transparent;
overflow: visible;
}
// The iOS sheet curve: fast out of the gate, long soft landing. Transform only.
.fSheet-slide-enter-active,
.fSheet-slide-leave-active {
will-change: transform;
}
.fSheet-slide-enter-active {
transition: transform 0.42s cubic-bezier(0.32, 0.72, 0, 1);
}
.fSheet-slide-leave-active {
transition: transform 0.24s cubic-bezier(0.4, 0, 1, 1);
}
.fSheet-slide-enter-from,
.fSheet-slide-leave-to {
transform: translate3d(0, 100%, 0);
}
.fSheet__card {
position: relative;
// Phone: edge to edge. Wider screens: a centred column, same max width the
// app's pages use.
max-width: 768px;
margin: 0 auto;
padding: 120px 16px 110px;
max-height: 88vh;
max-height: 88dvh;
display: flex;
flex-direction: column;
overflow: hidden;
transition: transform 0.38s cubic-bezier(0.22, 1, 0.36, 1);
&.is-dragging {
transition: none;
}
}
.fSheet__head {
flex: none;
touch-action: none;
}
.fSheet__grip {
display: block;
margin: 0 auto;
}
.fSheet__headRow {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
}
.filt__chips {
.fSheet__title {
display: flex;
align-items: center;
gap: 8px;
margin: 0;
}
.fSheet__count {
min-width: 20px;
height: 20px;
padding: 0 6px;
display: inline-grid;
place-items: center;
border-radius: 999px;
font-size: 11px;
font-weight: 800;
color: #fff;
}
.fSheet__close {
display: grid;
place-items: center;
border: 0;
cursor: pointer;
transform: rotate(45deg);
transition: transform 0.15s ease;
}
.fSheet__close:active {
transform: rotate(45deg) scale(0.92);
}
.fSheet__body {
flex: 1 1 auto;
min-height: 0;
overflow-y: auto;
overscroll-behavior: contain;
-webkit-overflow-scrolling: touch;
display: flex;
flex-direction: column;
}
.fSheet__chips {
display: flex;
flex-wrap: wrap;
gap: 8px;
}
.filt__chip {
padding: 8px 14px;
border-radius: 999px;
.fSheet__chip {
cursor: pointer;
font-family: inherit;
font-size: 12px;
font-weight: 600;
color: @inkSoft;
background: @canvas;
border: 1px solid @hairline;
transition: all 0.2s ease;
white-space: nowrap;
-webkit-tap-highlight-color: transparent;
transition: color 0.18s ease, background-color 0.18s ease, border-color 0.18s ease, transform 0.15s ease;
}
.fSheet__chip:active {
transform: scale(0.96);
}
.filt__chip.is-on {
color: #fff;
background: @ink;
border-color: @ink;
}
.filt__chip:active {
transform: scale(0.97);
}
.filt__empty {
.fSheet__empty {
margin: 0;
font-size: 12px;
color: @inkFaint;
}
.filt__gram {
padding: 4px 6px 0;
}
.filt__gram :deep(.ant-slider-track) {
background-color: @wine;
}
.filt__gram :deep(.ant-slider-handle) {
border-color: @wine;
}
.filt__gram :deep(.ant-slider-rail) {
background-color: @hairline;
}
.filt__gramFigures {
.fSheet__gramFigures {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
padding-top: 18px;
}
.filt__gramFigure {
font-size: 12px;
.fSheet__gramFigure i {
font-style: normal;
}
.fSheet__bar {
flex: none;
display: flex;
align-items: center;
gap: 10px;
padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
}
.fSheet__clear,
.fSheet__apply {
cursor: pointer;
font-family: inherit;
white-space: nowrap;
transition: transform 0.15s ease;
}
.fSheet__clear:active,
.fSheet__apply:active {
transform: scale(0.98);
}
/* ── Look: user-app-v2 ──────────────────────────────────────── */
// The detail page's sheet: white, 32px top radius, the same grip.
.fSheet__card {
border-radius: 32px 32px 0 0;
background: @canvas;
box-shadow: 0 -18px 40px -30px rgba(20, 22, 26, 0.55);
}
.fSheet__head {
padding: 8px 18px 12px;
}
.fSheet__grip {
width: 38px;
height: 4px;
margin-bottom: 12px;
border-radius: 999px;
background: @hairline;
}
.fSheet__title {
font-size: 16px;
font-weight: 700;
color: @ink;
}
.filt__gramFigure i {
font-style: normal;
font-size: 11px;
font-weight: 600;
color: @inkFaint;
padding-inline-end: 4px;
.fSheet__count {
background: @wine;
}
.filt__bar {
position: fixed;
bottom: 0;
left: 0;
right: 0;
z-index: 5;
background: rgba(255, 255, 255, 0.92);
backdrop-filter: blur(14px);
border-top: 1px solid @hairline;
padding-bottom: 16px;
}
.filt__barInner {
max-width: 768px;
margin: 0 auto;
padding: 12px 16px;
display: flex;
align-items: center;
gap: 10px;
}
.filt__clear,
.filt__apply {
flex: 1;
padding: 13px 18px;
border: 0;
cursor: pointer;
border-radius: 14px;
font-family: inherit;
font-size: 13px;
font-weight: 700;
transition: transform 0.15s ease;
}
.filt__clear {
color: @inkSoft;
// PageBar's / the detail header's squircle control.
.fSheet__close {
width: 38px;
height: 38px;
border-radius: 12px;
color: @ink;
background: @hairlineSoft;
}
.fSheet__body {
gap: 10px;
padding: 2px 16px 16px;
}
// The detail page's variant chips.
.fSheet__chip {
height: 34px;
padding: 0 14px;
border-radius: 999px;
font-size: 12.5px;
font-weight: 700;
color: @inkMuted;
background: @canvas;
border: 1px solid @hairline;
}
.fSheet__chip.is-on {
color: @onInk;
background: @ink;
border-color: @ink;
}
.fSheet__gram {
padding: 2px 4px 0;
}
// A step darker than @hairline: the rail sits on DropDown's @hairlineSoft panel.
.fSheet__gram .ant-slider-rail {
background-color: @hairlineStrong;
}
.fSheet__gram .ant-slider-track {
background-color: @wine;
}
.fSheet__gram .ant-slider-handle {
border-color: @wine;
}
.fSheet__gramFigures {
padding-top: 12px;
}
// The detail page's figure tiles, on white since they sit on a grey panel.
.fSheet__gramFigure {
flex: 1;
display: flex;
align-items: baseline;
justify-content: center;
gap: 5px;
padding: 9px 12px;
border-radius: 13px;
background: @canvas;
font-size: 11px;
color: @inkFaint;
}
.fSheet__gramFigure i {
font-size: 10.5px;
font-weight: 500;
}
.fSheet__gramFigure b {
font-size: 14px;
font-weight: 800;
color: @ink;
direction: ltr;
}
// The detail page's action bar: an outlined pill beside the dark primary pill.
.fSheet__bar {
padding: 12px 16px;
padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
background: @canvas;
border-top: 1px solid @hairline;
}
.fSheet__clear,
.fSheet__apply {
height: 48px;
border-radius: 999px;
font-size: 13.5px;
font-weight: 800;
}
.fSheet__clear {
flex: 0 0 auto;
padding: 0 22px;
color: @ink;
background: @canvas;
border: 1px solid @hairline;
}
.filt__apply {
color: #fff;
.fSheet__apply {
flex: 1;
border: 0;
color: @onInk;
background: @ink;
}
.filt__clear:active,
.filt__apply:active {
transform: scale(0.98);
box-shadow: 0 14px 30px -18px rgba(20, 22, 26, 0.9);
}
</style>