优化组件/更新

This commit is contained in:
gyq
2025-12-03 10:13:55 +08:00
parent 92f9776a35
commit 09b6e36a52
261 changed files with 22080 additions and 7238 deletions

View File

View File

@@ -0,0 +1,235 @@
/* #ifdef VUE3 */
@use "sass:math";
/* #endif */
/* #ifndef UNI-APP-X && APP || APP-NVUE */
$use-css-var: true !default;
/* #endif */
/* #ifdef UNI-APP-X && APP || APP-NVUE */
$use-css-var: false !default;
/* #endif */
@function div($dividend, $divisor) {
/* #ifdef VUE3 */
@return math.div($dividend, $divisor);
/* #endif */
/* #ifndef VUE3 */
@return $dividend / $divisor;
/* #endif */
}
@function rpx-to-px($value) {
// 递归处理列表
@if type-of($value) == list {
$new-list: ();
@each $item in $value {
$new-list: append($new-list, rpx-to-px($item));
}
@return $new-list;
}
// 处理数字类型 - 带 rpx 单位
@if type-of($value) == number and unit($value) == 'rpx' {
// 安全处理单位转换
@return calc-strip-unit($value) * 0.5 * 1px;
}
// 处理字符串类型
@if type-of($value) == string {
$string: $value;
$rpx-index: str-index($string, 'rpx');
// 如果字符串以数字开头并以 rpx 结尾,转换为数值
@if $rpx-index == (str-length($string) - 2) {
$num-str: str-slice($string, 1, $rpx-index - 1);
$number: to-number($num-str);
@if type-of($number) == number {
@return $number * 0.5 * 1px;
}
}
// 字符串中可能包含多个 rpx 值
@if $rpx-index {
$result: '';
@while $rpx-index {
// 找到数字部分起点
$num-end: $rpx-index - 1;
$num-start: $num-end;
@while $num-start > 0 and is-numeric-char(str-slice($string, $num-start, $num-start)) {
$num-start: $num-start - 1;
}
// 提取数字部分
$num-str: str-slice($string, $num-start + 1, $num-end);
$number: to-number($num-str);
// 转换为 px 数值
$px-value: $number * 0.5 * 1px;
// 构建结果字符串
$result: $result + str-slice($string, 1, $num_start) + '#{$px_value}';
// 更新剩余字符串
$string: str-slice($string, $rpx-index + 3);
$rpx-index: str-index($string, 'rpx');
}
@return #{$result + $string};
}
}
// 其他类型直接返回
@return $value;
}
// 辅助函数:安全去除单位并返回数值
@function calc-strip-unit($number) {
@if type-of($number) == number {
$unit: unit($number);
$units: ("px": 1px, "rpx": 1rpx, "em": 1em, "rem": 1rem, "%": 1%);
@if map-has-key($units, $unit) {
@return div($number , map-get($units, $unit));
}
@if unitless($number) {
@return $number;
}
}
@return $number;
}
// 辅助函数:检查字符是否为数字
@function is-numeric-char($char) {
$chars: "-.0123456789";
@return str-index($chars, $char) != null;
}
// 辅助函数:将字符串安全转换为数字
@function to-number($string) {
// 如果输入已经是数字,直接返回
@if type-of($string) == number {
@return $string;
}
// 处理带符号的数字
$is-negative: false;
$numeric: "";
$found-number: false;
// 提取所有数字字符
@for $i from 1 through str-length($string) {
$char: str-slice($string, $i, $i);
@if $char == "-" and $numeric == "" {
$is-negative: true;
}
@else if $char == "." and str-index($numeric, ".") == null {
$numeric: $numeric + $char;
}
@else if $char >= "0" and $char <= "9" {
$numeric: $numeric + $char;
$found-number: true;
}
}
// 如果有实际数字内容,转换为数值
@if $found-number {
$result: 0;
$decimal-index: str-index($numeric, ".");
@if $decimal-index {
// 处理带小数的数字
$integer-part: str-slice($numeric, 1, $decimal-index - 1);
$decimal-part: str-slice($numeric, $decimal-index + 1);
@if $integer-part == "" { $integer-part: "0"; }
$result: to-integer($integer-part);
$divisor: 1;
@for $i from 1 through str-length($decimal-part) {
$divisor: $divisor * 10;
$digit: to-integer(str-slice($decimal-part, $i, $i));
$result: $result + ($digit / $divisor);
}
} @else {
// 处理整数
$result: to-integer($numeric);
}
@return if($is-negative, -$result, $result);
}
// 无法转换则返回原字符串
@return $string;
}
// 辅助函数:将整数字符串转换为数字
@function to-integer($string) {
$result: 0;
@for $i from 1 through str-length($string) {
$char: str-slice($string, $i, $i);
$result: $result * 10 + (str-index("0123456789", $char) - 1);
}
@return $result;
}
@function create-var($name, $values...) {
// 将不定数量的参数转换为列表
$value-list: $values;
$css-value: null;
@if length($value-list) == 0 {
// @warn "The list must have at least 1 values.";
@return '';
} @else {
// 初始化CSS变量的值为列表中的第一个值
/* #ifndef VUE2 */
$css-value: nth($value-list, 1);
/* #endif */
/* #ifdef VUE2 */
$css-value: rpx-to-px(nth($value-list, 1));
/* #endif */
}
// 检查列表长度是否大于等于2
@if length($value-list) >= 2 {
// 使用@for循环遍历剩余的值并构建CSS变量的完整值
@for $i from 2 through length($value-list) {
/* #ifndef VUE2 */
$css-value: $css-value + ", " + nth($value-list, $i);
/* #endif */
/* #ifdef VUE2 */
$css-value: $css-value + ", " + rpx-to-px(nth($value-list, $i));
/* #endif */
}
}
// /* #ifndef UNI-APP-X */
// @return var(--l-#{$name}, #{$css-value});
// /* #endif */
// /* #ifdef UNI-APP-X && APP */
// @if $use-css-var {
// @return var(--l-#{$name}, #{$css-value});
// } @else {
// @return $css-value;
// }
// /* #endif */
// /* #ifdef APP-NVUE */
// @return $css-value;
// /* #endif */
// @return var(--l-#{$name}, #{$css-value});
@if $use-css-var {
@return var(--l-#{$name}, #{$css-value});
} @else {
@return $css-value;
}
}

View File

@@ -0,0 +1,401 @@
// =======================================================================
// 方向属性核心生成器 (支持所有方向相关属性)
// =======================================================================
@mixin directional-property(
$property,
$values,
$exclude: ()
) {
// 属性类型分组
$group-standard: padding, margin; // 标准方向属性
$group-radius: border-radius; // 圆角属性
$group-border: border, border-top, border-right, border-bottom, border-left; // 边框属性
$group-outline: outline, outline-top, outline-right, outline-bottom, outline-left; // 轮廓属性
$group-position: inset, inset-block, inset-inline, top, right, bottom, left; // 定位属性
$group-size: block-size, inline-size; // 块/行尺寸属性
// 定义每个方向的值
$top: null;
$right: null;
$bottom: null;
$left: null;
// 确定处理模式
$is-standard: index($group-standard, $property);
$is-radius: index($group-radius, $property);
$is-border: index($group-border, $property);
$is-outline: index($group-outline, $property);
$is-position: index($group-position, $property);
$is-size: index($group-size, $property);
// =====================================================================
// 解析输入值 - 根据属性类型处理
// =====================================================================
@if type-of($values) == 'list' {
$length: length($values);
// 单个值 - 所有方向相同值
@if $length == 1 {
$top: nth($values, 1);
$right: nth($values, 1);
$bottom: nth($values, 1);
$left: nth($values, 1);
}
// 两个值
@else if $length == 2 {
// 特殊处理border-radius
@if $is-radius {
$top: nth($values, 1);
$right: nth($values, 2);
$bottom: nth($values, 1);
$left: nth($values, 2);
}
// 标准处理:上下 | 左右
@else if $is-standard or $is-border or $is-outline or $is-position {
$top: nth($values, 1);
$bottom: nth($values, 1);
$right: nth($values, 2);
$left: nth($values, 2);
}
// 块/行尺寸处理
@else if $is-size {
$top: nth($values, 1);
$right: nth($values, 2);
}
}
// 三个值
@else if $length == 3 {
// border-radius特殊处理
@if $is-radius {
$top: nth($values, 1);
$right: nth($values, 2);
$bottom: nth($values, 3);
$left: nth($values, 2);
}
// 标准处理
@else if $is-standard or $is-border or $is-outline or $is-position {
$top: nth($values, 1);
$right: nth($values, 2);
$left: nth($values, 2);
$bottom: nth($values, 3);
}
}
// 四个值
@else if $length == 4 {
$top: nth($values, 1);
$right: nth($values, 2);
$bottom: nth($values, 3);
$left: nth($values, 4);
}
}
@else {
// 单个值传递
$top: $values;
$right: $values;
$bottom: $values;
$left: $values;
}
// =====================================================================
// 生成CSS属性排除指定方向
// =====================================================================
// 1. 圆角处理
@if $is-radius {
@if not index($exclude, top-left) and $top != null {
border-top-left-radius: $top;
}
@if not index($exclude, top-right) and $right != null {
border-top-right-radius: $right;
}
@if not index($exclude, bottom-right) and $bottom != null {
border-bottom-right-radius: $bottom;
}
@if not index($exclude, bottom-left) and $left != null {
border-bottom-left-radius: $left;
}
}
// 2. 标准方向处理 (padding, margin)
@else if $is-standard {
@if not index($exclude, top) and $top != null {
#{$property}-top: $top;
}
@if not index($exclude, right) and $right != null {
#{$property}-right: $right;
}
@if not index($exclude, bottom) and $bottom != null {
#{$property}-bottom: $bottom;
}
@if not index($exclude, left) and $left != null {
#{$property}-left: $left;
}
}
// 3. 边框处理
@else if $is-border {
// 完整边框设置
@if $property == 'border' {
@if not index($exclude, top) and $top != null {
border-top-width: nth($values, 1);
border-top-style: nth($values, 2);
border-top-color: nth($values, 3);
}
@if not index($exclude, right) and $right != null {
border-right-width: nth($values, 1);
border-right-style: nth($values, 2);
border-right-color: nth($values, 3);
}
@if not index($exclude, bottom) and $bottom != null {
// border-bottom: $bottom;
border-bottom-width: nth($values, 1);
border-bottom-style: nth($values, 2);
border-bottom-color: nth($values, 3);
}
@if not index($exclude, left) and $left != null {
// border-left: $left;
border-left-width: nth($values, 1);
border-left-style: nth($values, 2);
border-left-color: nth($values, 3);
}
}
// 单边边框
@else {
$direction: str-slice($property, 8); // 提取方向
@if not index($exclude, $direction) {
// #{$property}: $top;
#{$property}-width: nth($values, 1);
#{$property}-style: nth($values, 2);
#{$property}-color: nth($values, 3);
}
}
}
// 4. 轮廓处理
@else if $is-outline {
// 完整轮廓设置
@if $property == 'outline' {
@if not index($exclude, top) and $top != null {
outline-top: $top;
}
@if not index($exclude, right) and $right != null {
outline-right: $right;
}
@if not index($exclude, bottom) and $bottom != null {
outline-bottom: $bottom;
}
@if not index($exclude, left) and $left != null {
outline-left: $left;
}
}
// 单边轮廓
@else {
$direction: str-slice($property, 8); // 提取方向
@if not index($exclude, $direction) {
#{$property}: $top;
}
}
}
// 5. 定位处理
@else if $is-position {
// inset简写处理
@if $property == 'inset' {
@if not index($exclude, top) and $top != null {
top: $top;
}
@if not index($exclude, right) and $right != null {
right: $right;
}
@if not index($exclude, bottom) and $bottom != null {
bottom: $bottom;
}
@if not index($exclude, left) and $left != null {
left: $left;
}
}
// inset-block 和 inset-inline
@else if $property == 'inset-block' {
@if not index($exclude, top) and $top != null {
top: $top;
}
@if not index($exclude, bottom) and $bottom != null {
bottom: $bottom;
}
}
@else if $property == 'inset-inline' {
@if not index($exclude, left) and $left != null {
left: $left;
}
@if not index($exclude, right) and $right != null {
right: $right;
}
}
// 单一定位
@else {
@if not index($exclude, $property) {
#{$property}: $top;
}
}
}
// 6. 尺寸处理
@else if $is-size {
@if $property == 'block-size' {
@if not index($exclude, top) and $top != null {
height: $top;
}
}
@else if $property == 'inline-size' {
@if not index($exclude, left) and $left != null {
width: $left;
}
}
}
}
// =======================================================================
// 快捷混合宏:标准属性
// =======================================================================
@mixin padding($values, $exclude: ()) {
@include directional-property(padding, $values, $exclude);
}
@mixin margin($values, $exclude: ()) {
@include directional-property(margin, $values, $exclude);
}
@mixin border-radius($values, $exclude: ()) {
@include directional-property(border-radius, $values, $exclude);
}
// =======================================================================
// 快捷混合宏:边框属性
// =======================================================================
@mixin border($value, $exclude: ()) {
@include directional-property(border, $value, $exclude);
}
@mixin border-top($value, $exclude: ()) {
@include directional-property(border-top, $value, $exclude);
}
@mixin border-right($value, $exclude: ()) {
@include directional-property(border-right, $value, $exclude);
}
@mixin border-bottom($value, $exclude: ()) {
@include directional-property(border-bottom, $value, $exclude);
}
@mixin border-left($value, $exclude: ()) {
@include directional-property(border-left, $value, $exclude);
}
// =======================================================================
// 快捷混合宏:轮廓属性
// =======================================================================
@mixin outline($value, $exclude: ()) {
@include directional-property(outline, $value, $exclude);
}
@mixin outline-top($value, $exclude: ()) {
@include directional-property(outline-top, $value, $exclude);
}
@mixin outline-right($value, $exclude: ()) {
@include directional-property(outline-right, $value, $exclude);
}
@mixin outline-bottom($value, $exclude: ()) {
@include directional-property(outline-bottom, $value, $exclude);
}
@mixin outline-left($value, $exclude: ()) {
@include directional-property(outline-left, $value, $exclude);
}
// =======================================================================
// 快捷混合宏:定位属性
// =======================================================================
@mixin inset($values, $exclude: ()) {
@include directional-property(inset, $values, $exclude);
}
@mixin inset-block($values, $exclude: ()) {
@include directional-property(inset-block, $values, $exclude);
}
@mixin inset-inline($values, $exclude: ()) {
@include directional-property(inset-inline, $values, $exclude);
}
@mixin top($value, $exclude: ()) {
@include directional-property(top, $value, $exclude);
}
@mixin right($value, $exclude: ()) {
@include directional-property(right, $value, $exclude);
}
@mixin bottom($value, $exclude: ()) {
@include directional-property(bottom, $value, $exclude);
}
@mixin left($value, $exclude: ()) {
@include directional-property(left, $value, $exclude);
}
// =======================================================================
// 快捷混合宏:尺寸属性
// =======================================================================
@mixin block-size($value, $exclude: ()) {
@include directional-property(block-size, $value, $exclude);
}
@mixin inline-size($value, $exclude: ()) {
@include directional-property(inline-size, $value, $exclude);
}
// =======================================================================
// 组合混合宏
// =======================================================================
// 带圆角的边框
@mixin bordered($border-value, $radius-value) {
@include border($border-value);
@include border-radius($radius-value);
}
// 绝对定位容器
@mixin absolute-container($inset: 0) {
position: absolute;
@include inset($inset);
}
// 固定定位容器
@mixin fixed-container($inset: 0) {
position: fixed;
@include inset($inset);
}
// =======================================================================
// 圆角辅助混合宏
// =======================================================================
@mixin border-top-radius($value) {
@include border-radius($value 0 0, (bottom-right, bottom-left));
}
@mixin border-right-radius($value) {
@include border-radius(0 $value 0 0, (top-left, bottom-left));
}
@mixin border-bottom-radius($value) {
@include border-radius(0 0 $value, (top-right, top-left));
}
@mixin border-left-radius($value) {
@include border-radius(0 0 0 $value, (top-right, bottom-right));
}

View File

@@ -0,0 +1,22 @@
@mixin ellipsis {
// overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
/* #ifndef UNI-APP-X && APP || APP-NVUE */
word-wrap: normal;
/* #endif */
}
@mixin ellipsisLn($line) {
// overflow: hidden;
text-overflow: ellipsis;
/* #ifdef UNI-APP-X && APP || APP-NVUE */
lines: $line;
/* #endif */
/* #ifndef UNI-APP-X && APP || APP-NVUE */
-webkit-line-clamp: $line;
display: -webkit-box;
-webkit-box-orient: vertical;
/* #endif */
}

View File

@@ -0,0 +1,20 @@
@mixin flex {
/* #ifndef UNI-APP-X */
display: flex;
/* #endif */
}
@mixin flex-column {
/* #ifndef UNI-APP-X */
flex-direction: column;
/* #endif */
}
@mixin flex-row {
flex-direction: row;
}
@mixin universal {
position: relative;
box-sizing: border-box;
display: flex;
flex-direction: column;
}

View File

@@ -0,0 +1,66 @@
// @import '../theme/default.scss';
@mixin hairline-base {
position: absolute;
box-sizing: border-box;
content: ' ';
pointer-events: none;
transform-origin: center; /* cover wechat button:after default transforn-origin */
}
@mixin hairline($color: $border-color-2) {
@include hairline-base;
top: -50%;
right: -50%;
bottom: -50%;
left: -50%;
border: 1px solid $color;
transform: scale(.5);
}
@mixin hairline-top($color: $border-color-1, $left: 0, $right: 0) {
@include hairline-base;
top: 0;
right: $right;
left: $left;
border-top: 1px solid $color;
transform: scaleY(0.5);
}
@mixin hairline-bottom($color: $border-color-1, $left: 0, $right: 0) {
@include hairline-base;
right: $right;
bottom: 0;
left: $left;
border-bottom: 1px solid $color;
transform: scaleY(0.5);
}
@mixin hairline-left($color: $border-bolor-1) {
@include hairline-base;
top: 0;
bottom: 0;
left: 0;
border-left: 1px solid $color;
transform: scaleX(.5);
}
@mixin hairline-right($color: $border-bolor-1) {
@include hairline-base;
top: 0;
bottom: 0;
right: 0;
border-right: 1px solid $color;
transform: scaleX(.5);
}
// @mixin border {
// /* #ifndef UNI-APP-X && APP */
// &:after {
// @content;
// }
// /* #endif */
// /* #ifdef UNI-APP-X && APP */
// @content;
// /* #endif */
// }

View File

@@ -0,0 +1,17 @@
/* #ifdef APP-NVUE || UNI-APP-X && APP */
$is-app: true;
/* #endif */
/* #ifndef APP-NVUE || UNI-APP-X && APP */
$is-app: false;
/* #endif */
@mixin is-app {
@if $is-app {
@content;
}
}
@mixin not-app {
@if not($is-app) {
@content;
}
}

View File

@@ -0,0 +1,60 @@
$limeThemes: light, dark;
$theme: light;
@mixin use-theme($mode: null) {
@if $mode != null {
/* #ifndef UNI-APP-X && APP || APP-NVUE */
@media (prefers-color-scheme: $mode) {
@content;
}
/* #endif */
/* #ifdef UNI-APP-X && APP || APP-NVUE */
&.#{$mode} {
@content;
}
/* #endif */
} @else {
@each $mode in $limeThemes {
$theme: $mode !global;
/* #ifndef UNI-APP-X && APP || APP-NVUE */
@media (prefers-color-scheme: $mode) {
@content;
}
/* #endif */
/* #ifdef UNI-APP-X && APP || APP-NVUE */
&.#{$mode} {
@content;
}
/* #endif */
}
}
}
@mixin theme-dark {
/* #ifndef UNI-APP-X && APP || APP-NVUE */
@media (prefers-color-scheme: dark) {
page {
@content;
}
}
/* #endif */
/* #ifdef UNI-APP-X && APP || APP-NVUE */
.dark {
@content;
}
/* #endif */
/* #ifdef WEB */
:root[data-lime-theme='dark'] page {
@content;
}
/* #endif */
}
@function get-var($themes, $key) {
@return map-get($themes, $key)
}

View File

@@ -0,0 +1,7 @@
@import './flex';
@mixin resize-none {
/* #ifndef UNI-APP-X && APP */
resize: none;
/* #endif */
}