Components/BaseSurface

BaseSurface

Unified background rendering component supporting pure/mask/blur/glass/refraction modes with motion-degradation fallback for backdrop-filter + transform issues.

VerifiedSince 0.3.4

Usage

Best Practices

  • Prefer TxCard for normal product containers; reach for TxBaseSurface only when a page needs direct material or fallback tuning.
  • Use moving when the parent already owns animation state. Use autoDetect for legacy transform transitions where explicit state is unavailable.
  • Keep fallbackMode="mask" for readable blur/glass content during motion; use pure only when a flat color is visually acceptable.
  • Treat refractionStrength, refractionProfile, and refractionTone as the high-level API. Touch raw channel offsets only for visual experiments.
  • Use refractionRenderer="css" only when the page can tolerate the CSS renderer's lower optical fidelity; keep svg for the default premium material.
  • Use fake when matching existing .fake-background layering; otherwise keep normal layer rendering for clearer DOM/debugging.

API Reference

TxBaseSurface Props

PropTypeDefaultDescription
mode'pure' | 'mask' | 'blur' | 'glass' | 'refraction''pure'Surface mode: pure / mask / filter / glass / refraction.
radiusstring | number-Custom border radius (inherits from parent if unset).
colorstring-Base color for pure/mask layers.
opacitynumber0.75Opacity in mask mode (0-1).
fallbackMaskOpacitynumber-Overrides opacity when degraded to mask (0-1).
blurnumber10Blur intensity for the filter layer (px).
filterSaturationnumber1.5Filter-layer saturation (low-level tuning).
filterContrastnumber1Filter-layer contrast (low-level tuning).
filterBrightnessnumber1Filter-layer brightness (low-level tuning).
saturationnumber1.8Glass-layer saturation for glass/refraction.
brightnessnumber70Glass-layer brightness for glass/refraction.
backgroundOpacitynumber0Background opacity of the glass layer.
borderWidthnumber0.07Edge width factor for the glass layer.
displacenumber0.5Refraction displacement amount.
distortionScalenumber-180Refraction distortion scale.
redOffset / greenOffset / blueOffsetnumber0 / 10 / 20RGB channel offsets for spectral separation.
xChannel / yChannel'R' | 'G' | 'B''R' / 'G'Sampling channels used by displacement maps.
mixBlendModestring'difference'Blend mode used in refraction rendering.
refractionStrengthnumber62Unified refraction strength 0-100 (effective fallback when the refraction model is active).
refractionProfile'soft' | 'filmic' | 'cinematic''filmic'Refraction style preset (computed as 'filmic' when not set explicitly).
refractionTone'mist' | 'balanced' | 'vivid''balanced'Refraction tone preset (vivid is clearer, mist is softer).
refractionAnglenumber-24Main dispersion angle in degrees (computed as -24 when not set explicitly).
refractionLightX / refractionLightYnumber-Light anchor coordinates (0-1).
refractionHaloOpacitynumber-Halo opacity override (0-1). If unset, uses the internal filmic model.
overlayOpacitynumber0Optional extra mask opacity for non-mask modes.
preset'default' | 'card''default'Visual preset (card applies card-focused tuning).
refractionRenderer'svg' | 'css''svg'Renderer type for refraction mode.
movingbooleanfalseManual motion flag for degradation fallback.
fallbackMode'pure' | 'mask''mask'Target mode while moving.
settleDelaynumber150Delay before recovery after motion ends (ms).
autoDetectbooleanfalseAuto detect transform motion and fallback.
transitionDurationnumber299Recovery transition duration (ms).
fakebooleanfalseEnable fake pseudo-element rendering mode.
fakeIndexnumber0z-index for fake layer.
tagstring'div'Root element tag name.

Slots

SlotPropsDescription
default-Surface content. It is rendered in .tx-base-surface__content above glass, filter, mask, motion-cover, and refraction-edge layers.

Events

None. TxBaseSurface is a visual primitive and does not emit interaction or lifecycle events.

Exposed Methods

None. Drive motion fallback with moving or autoDetect, and update visual state through props.

CSS Variables

VariableSourceDescription
--tx-surface-colorcolor prop or theme fallbackSolid/mask background color. Falls back to var(--tx-fill-color-lighter, #fafafa).
--tx-surface-radiusradius propRoot and layer border radius; numeric values become px.
--tx-surface-transitiontransitionDuration propLayer fade, background, and backdrop-filter transition duration.
--tx-surface-filter-blurblur propBackdrop blur radius for filter and refraction filter layers.
--tx-surface-filter-saturationfilterSaturation propFilter-layer saturation multiplier.
--tx-surface-filter-contrastfilterContrast propFilter-layer contrast multiplier.
--tx-surface-filter-brightnessfilterBrightness propFilter-layer brightness multiplier.
--tx-surface-mask-opacityopacity, fallbackMaskOpacity, or overlayOpacityActive mask opacity after clamping to 0..1.
--tx-surface-refraction-light-x / --tx-surface-refraction-light-yrefractionLightX / refractionLightY or angle modelRefraction light anchor in percentages.
--tx-surface-refraction-strengthrefractionStrength modelBlended optical strength during rest, motion, and recovery.
--tx-surface-fake-indexfakeIndex propz-index for fake pseudo-element rendering.
--tx-surface-fake-bgcolor prop or theme fallbackBackground color of the fake-mode pseudo element.
--tx-surface-fake-opacitymask opacity modelOpacity of the fake-mode pseudo element.
--tx-surface-mask-opacity-percentmask opacity modelPercentage form of the mask opacity (internal interpolation output, do not override).
--tx-surface-motion-cover-opacitymotion state modelRefraction motion-cover layer opacity (internal).
--tx-surface-refraction-edge-opacityoptics modelRefraction edge highlight opacity (internal).
--tx-surface-refraction-streak-anglerefractionAngle modelRefraction streak angle (angle model +92deg, internal).
--tx-surface-refraction-{filter,mask}-{base,primary,secondary,veil}-weight / --tx-surface-refraction-streak-weightprofile/tone weight modelBlend-weight family for the optical layers (internal).
--tx-surface-refraction-*-gain / -boost / -base, --tx-surface-refraction-halo-opacity, --tx-surface-refraction-mask-effective-opacityprofile/tone derived valuesDerived optical interpolation outputs (internal).
--tx-surface-refraction-mask-colortheming hook (consumed)Base color of the refraction gradient layers; overridable in themes (falls back to #fff-family defaults).

Relationship with TxCard

  • Use TxCard for out-of-the-box product usage (header/footer/loading/inertial/interaction states).
  • Use TxBaseSurface for low-level material tuning (filter/refraction/glass parameter matrix).
  • Recommended split: TxCard handles container semantics + interaction, TxBaseSurface handles material rendering.

Background Modes

Five modes compared: pure solid color, mask semi-transparent overlay, blur backdrop blur, glass glass layer, and refraction glass+filter refraction.

Mode Comparison

Loading demo...

Advanced Parameter Lab

Use this low-level lab to tune material parameters in filter / refraction workflows. For product-facing card usage, TxCard is still the recommended first choice.

Advanced Lab

Loading demo...

Fake Pseudo-Element Mode

Enable pseudo-element background rendering via the fake prop. Slot content naturally sits above the background without extra z-index management. Useful when you need consistency with the existing .fake-background pattern.

Fake Mode

Loading demo...

Motion Fallback

When blur or glass mode elements are in a CSS transform animation, backdrop-filter becomes invalidated (known Chromium bug).

Use the moving prop for manual control, or auto-detect for automatic transform detection. The component degrades to fallbackMode (default mask) during motion and smoothly recovers afterward. Refraction degrades per layer: the sampling-stale glass / blur layers fade themselves out while a translucent motion cover holds the visual weight, then cross-fade back on settle — nothing near-opaque ever covers the surface.

Click the button to trigger real transform movement on both blur and glass cards. The cards contain scrollable content inside.

Multi-Mode Motion Fallback

Loading demo...

Raw vs BaseSurface Comparison

Left side uses raw backdrop-filter — blur breaks completely during transform motion. Right side uses BaseSurface — gracefully degrades to mask during motion, then smoothly recovers to glass when stopped.

Motion Comparison

Loading demo...

Overview

  • tag controls the root element and the default slot is rendered above all material layers.
  • pure mode renders only the root background; mask renders the mask layer and clamps opacity to 0..1.
  • blur and glass degrade while moving=true or auto-detected transform motion is active. fallbackMode='mask' uses fallbackMaskOpacity when provided; fallbackMode='pure' renders no mask layer.
  • glass and refraction forward normalized geometry and optical props to TxGlassSurface; brightness <= 3 is treated as a multiplier and converted to a percentage.
  • refraction renders glass, filter, mask, optional motion-cover, and edge layers, plus renderer/profile/tone classes and light/strength CSS variables.
  • Passing any of refractionStrength / refractionAngle / refractionProfile switches to the derived refraction model (shouldUseRefractionModel); unset ones fall back to 62 / -24 / 'filmic'.
  • autoDetect observes the root and ancestor style mutations plus transitionstart, transitionend, and transitioncancel; listeners and observers are removed on unmount.
  • settleDelay and transitionDuration both affect fallback recovery. The actual settle timer is at least the transition duration.
  • refraction keeps the refraction renderer active during motion, but blends optical parameters down while moving and back up during recovery.

Technologies

  • Reviewed against packages/tuffex/packages/components/src/base-surface/src/TxBaseSurface.vue, types.ts, base-surface-motion.ts, base-surface-math.ts, and style/index.scss.
  • The CSS-variable table covers every runtime variable the component emits (rows marked internal are interpolation outputs, not override points) plus the consumed theming hook --tx-surface-refraction-mask-color.
  • Existing tests cover root tag/radius/color variables, mask opacity clamping, blur fallback, pure fallback, normalized TxGlassSurface props, refraction classes/light variables, and auto-detect teardown.
  • No events or exposed methods exist in source; visual state is controlled through props and CSS variables.
  • Component source: packages/tuffex/packages/components/src/base-surface/src/TxBaseSurface.vue.
  • Types: packages/tuffex/packages/components/src/base-surface/src/types.ts.
  • Motion helper: packages/tuffex/packages/components/src/base-surface/src/base-surface-motion.ts.
  • Math helper: packages/tuffex/packages/components/src/base-surface/src/base-surface-math.ts.
  • Styles: packages/tuffex/packages/components/src/base-surface/src/style/index.scss.
  • Verified coverage: packages/tuffex/packages/components/src/base-surface/__tests__/base-surface.test.ts verifies mode rendering, fallback behavior, refraction parameters, and observer cleanup.
查看源码
packages/tuffex/packages/components/src/base-surface/index.ts