@zfqh/uview-x 0.0.3 → 0.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/README.md +83 -127
  3. package/components/uv-badge/uv-badge.vue +5 -3
  4. package/components/uv-button/uv-button.vue +4 -2
  5. package/components/uv-checkbox/uv-checkbox.vue +1 -3
  6. package/components/uv-checkbox-group/uv-checkbox-group.vue +0 -3
  7. package/components/uv-dialog/uv-dialog.vue +3 -3
  8. package/components/uv-form/uv-form.vue +0 -2
  9. package/components/uv-form-item/uv-form-item.vue +4 -2
  10. package/components/uv-icon/uv-icon.vue +6 -6
  11. package/components/uv-input/uv-input.vue +2 -2
  12. package/components/uv-line-progress/uv-line-progress.vue +0 -2
  13. package/components/uv-loading-icon/uv-loading-icon.vue +1 -2
  14. package/components/uv-overlay/uv-overlay.vue +1 -2
  15. package/components/uv-popup/uv-popup.vue +5 -2
  16. package/components/uv-safe-bottom/uv-safe-bottom.vue +0 -2
  17. package/components/uv-status-bar/uv-status-bar.vue +0 -2
  18. package/components/uv-tabs/uv-tabs.vue +2 -2
  19. package/hooks/useI18n.ts +1 -1
  20. package/index.ts +10 -3
  21. package/locales/en.ts +4 -3
  22. package/locales/es.ts +79 -0
  23. package/locales/fr.ts +79 -0
  24. package/locales/index.ts +166 -169
  25. package/locales/ru.ts +79 -0
  26. package/locales/zh-Hans.ts +3 -2
  27. package/locales/zh-Hant.ts +79 -0
  28. package/package.json +2 -3
  29. package/styles/common.scss +148 -134
  30. package/styles/index.scss +4 -7
  31. package/styles/reset.scss +25 -0
  32. package/styles/theme.scss +40 -44
  33. package/styles/var.module.scss +1 -1
  34. package/types/index.d.ts +4 -4
  35. package/utils/config.ts +18 -13
  36. package/utils/function.ts +12 -11
  37. package/utils/index.ts +1 -0
  38. package/utils/locale.ts +14 -6
  39. package/utils/scrollbar.ts +181 -0
  40. package/styles/color.scss +0 -33
  41. package/styles/components.scss +0 -19
  42. package/styles/vue.scss +0 -39
  43. package/theme.scss +0 -2
@@ -0,0 +1,181 @@
1
+ /**
2
+ * H5 全局滚动条样式(仅 H5 运行时注入)。
3
+ *
4
+ * - `false`(默认):隐藏滚动条(保持原 reset 的默认效果);
5
+ * - `true`:使用默认滚动条样式;
6
+ * - 对象:在默认样式基础上覆盖 `::-webkit-scrollbar` 及其 thumb / track。
7
+ *
8
+ * 注入入口见 `index.ts` 的 `install`(H5 条件编译)。
9
+ */
10
+
11
+ /** 单组滚动条 CSS 样式:camelCase / kebab-case 均可;number 默认按 px 处理(无单位属性除外) */
12
+ export type UviewXScrollbarStyle = Record<string, string | number>;
13
+
14
+ /** 滚动条自定义样式:默认合并 / 扩展 ::-webkit-scrollbar 及其 thumb / track */
15
+ export interface UviewXScrollbarOptions {
16
+ /** ::-webkit-scrollbar-thumb 样式,覆盖默认 thumb 样式 */
17
+ thumb?: UviewXScrollbarStyle;
18
+ /** ::-webkit-scrollbar-track 样式,覆盖默认 track 样式 */
19
+ track?: UviewXScrollbarStyle;
20
+ /** 其余键作为 ::-webkit-scrollbar 样式,覆盖默认宽高 */
21
+ [property: string]: string | number | UviewXScrollbarStyle | undefined;
22
+ }
23
+
24
+ export type UviewXScrollbar = boolean | UviewXScrollbarOptions;
25
+
26
+ /** 注入到 `<style>` 的元素 id;重复设置时替换同一节点 */
27
+ const SCROLLBAR_STYLE_ID = 'uv-scrollbar-style';
28
+
29
+ /** `false`:隐藏滚动条 */
30
+ const HIDDEN_SCROLLBAR_STYLE: UviewXScrollbarStyle = {
31
+ display: 'none',
32
+ width: '0 !important',
33
+ height: '0 !important',
34
+ WebkitAppearance: 'none',
35
+ background: 'transparent',
36
+ };
37
+
38
+ /** `true` / 对象的默认基础样式 */
39
+ const DEFAULT_SCROLLBAR_STYLE: UviewXScrollbarStyle = {
40
+ width: 6,
41
+ height: 6,
42
+ };
43
+
44
+ const DEFAULT_SCROLLBAR_THUMB_STYLE: UviewXScrollbarStyle = {
45
+ background: '#c0c4cc',
46
+ borderRadius: 3,
47
+ };
48
+
49
+ const DEFAULT_SCROLLBAR_TRACK_STYLE: UviewXScrollbarStyle = {
50
+ background: 'transparent',
51
+ };
52
+
53
+ /** 数值不补 px 的 CSS 属性(已转换为 kebab-case) */
54
+ const UNITLESS_PROPERTIES = new Set([
55
+ 'opacity',
56
+ 'z-index',
57
+ 'font-weight',
58
+ 'line-height',
59
+ 'flex',
60
+ 'flex-grow',
61
+ 'flex-shrink',
62
+ 'order',
63
+ 'zoom',
64
+ 'animation-iteration-count',
65
+ 'column-count',
66
+ 'tab-size',
67
+ ]);
68
+
69
+ /** camelCase → kebab-case;已是 kebab-case 的属性保持不变 */
70
+ function toKebabCase(property: string): string {
71
+ return property.replace(/[A-Z]/g, (match) => `-${match.toLowerCase()}`);
72
+ }
73
+
74
+ function formatStyleValue(property: string, value: string | number): string {
75
+ if (typeof value === 'number' && !UNITLESS_PROPERTIES.has(toKebabCase(property))) {
76
+ return `${value}px`;
77
+ }
78
+ return String(value);
79
+ }
80
+
81
+ /** 把样式对象转换为 CSS 声明串 */
82
+ function styleToDeclarations(style: UviewXScrollbarStyle): string {
83
+ const declarations: string[] = [];
84
+ for (const property of Object.keys(style)) {
85
+ const value = style[property];
86
+ if (typeof value !== 'string' && typeof value !== 'number') {
87
+ continue;
88
+ }
89
+ declarations.push(`${toKebabCase(property)}: ${formatStyleValue(property, value)};`);
90
+ }
91
+ return declarations.join(' ');
92
+ }
93
+
94
+ function toRule(selector: string, style: UviewXScrollbarStyle): string {
95
+ const declarations = styleToDeclarations(style);
96
+ return declarations ? `${selector} { ${declarations} }` : '';
97
+ }
98
+
99
+ function isScrollbarStyle(value: unknown): value is UviewXScrollbarStyle {
100
+ return typeof value === 'object' && value !== null && !Array.isArray(value);
101
+ }
102
+
103
+ function mergeScrollbarStyle(base: UviewXScrollbarStyle, override?: UviewXScrollbarStyle): UviewXScrollbarStyle {
104
+ return override ? { ...base, ...override } : { ...base };
105
+ }
106
+
107
+ /**
108
+ * 生成滚动条 CSS。
109
+ *
110
+ * - `false` / `undefined`:隐藏滚动条;
111
+ * - `true`:默认滚动条样式;
112
+ * - 对象:默认样式 + 用户覆盖;空对象等价 `true`。
113
+ */
114
+ export function buildScrollbarCss(scrollbar: UviewXScrollbar): string {
115
+ if (!scrollbar) {
116
+ return toRule('::-webkit-scrollbar', HIDDEN_SCROLLBAR_STYLE);
117
+ }
118
+ if (scrollbar === true) {
119
+ return [
120
+ toRule('::-webkit-scrollbar', DEFAULT_SCROLLBAR_STYLE),
121
+ toRule('::-webkit-scrollbar-thumb', DEFAULT_SCROLLBAR_THUMB_STYLE),
122
+ toRule('::-webkit-scrollbar-track', DEFAULT_SCROLLBAR_TRACK_STYLE),
123
+ ]
124
+ .filter(Boolean)
125
+ .join('\n');
126
+ }
127
+
128
+ // 自定义样式:`thumb` / `track` 之外的键作为基础样式
129
+ const baseOverride: UviewXScrollbarStyle = {};
130
+ let thumbOverride: UviewXScrollbarStyle | undefined;
131
+ let trackOverride: UviewXScrollbarStyle | undefined;
132
+ for (const property of Object.keys(scrollbar)) {
133
+ const value = scrollbar[property];
134
+ if (property === 'thumb' || property === 'track') {
135
+ if (isScrollbarStyle(value)) {
136
+ if (property === 'thumb') {
137
+ thumbOverride = value;
138
+ } else {
139
+ trackOverride = value;
140
+ }
141
+ }
142
+ continue;
143
+ }
144
+ if (typeof value === 'string' || typeof value === 'number') {
145
+ baseOverride[property] = value;
146
+ }
147
+ }
148
+
149
+ return [
150
+ toRule('::-webkit-scrollbar', mergeScrollbarStyle(DEFAULT_SCROLLBAR_STYLE, baseOverride)),
151
+ toRule('::-webkit-scrollbar-thumb', mergeScrollbarStyle(DEFAULT_SCROLLBAR_THUMB_STYLE, thumbOverride)),
152
+ toRule('::-webkit-scrollbar-track', mergeScrollbarStyle(DEFAULT_SCROLLBAR_TRACK_STYLE, trackOverride)),
153
+ ]
154
+ .filter(Boolean)
155
+ .join('\n');
156
+ }
157
+
158
+ /**
159
+ * 应用 H5 滚动条样式:替换 `#uv-scrollbar-style` 节点;其它平台不会注入任何代码。
160
+ *
161
+ * `document` 不存在(SSR / Node 单测)时静默返回。
162
+ */
163
+ export function applyScrollbar(scrollbar: UviewXScrollbar): void {
164
+ // #ifdef WEB || H5
165
+ if (typeof document === 'undefined' || !document.head) {
166
+ return;
167
+ }
168
+ const existing = document.getElementById(SCROLLBAR_STYLE_ID);
169
+ if (existing && existing.parentNode) {
170
+ existing.parentNode.removeChild(existing);
171
+ }
172
+ const css = buildScrollbarCss(scrollbar);
173
+ if (!css) {
174
+ return;
175
+ }
176
+ const styleElement = document.createElement('style');
177
+ styleElement.id = SCROLLBAR_STYLE_ID;
178
+ styleElement.textContent = css;
179
+ document.head.appendChild(styleElement);
180
+ // #endif
181
+ }
package/styles/color.scss DELETED
@@ -1,33 +0,0 @@
1
- $uv-main-color: #333333 !default;
2
- $uv-content-color: #7a7a7a !default;
3
- $uv-tips-color: #9a9a9a !default;
4
- $uv-light-color: #c0c4cc !default;
5
- $uv-border-color: #eeeeee !default;
6
- $uv-bg-color: #f5f5f5 !default;
7
- $uv-bg-light-color: #fffbf4 !default;
8
- $uv-disabled-color: #c8c9cc !default;
9
-
10
- $uv-primary: #00b4c3 !default;
11
- $uv-primary-dark: #157572 !default;
12
- $uv-primary-disabled: #b4e3d9 !default;
13
- $uv-primary-light: #dff3f9 !default;
14
-
15
- $uv-warning: #ff9a05 !default;
16
- $uv-warning-dark: #ed6c04 !default;
17
- $uv-warning-disabled: #f9d39b !default;
18
- $uv-warning-light: #fdf6ec !default;
19
-
20
- $uv-success: #5ac725 !default;
21
- $uv-success-dark: #53c21d !default;
22
- $uv-success-disabled: #a9e08f !default;
23
- $uv-success-light: #f5fff0 !default;
24
-
25
- $uv-error: #ff4d4f !default;
26
- $uv-error-dark: #e45656 !default;
27
- $uv-error-disabled: #f7b2b2 !default;
28
- $uv-error-light: #fef0f0 !default;
29
-
30
- $uv-info: #909399 !default;
31
- $uv-info-dark: #767a82 !default;
32
- $uv-info-disabled: #c4c6c9 !default;
33
- $uv-info-light: #f4f4f5 !default;
@@ -1,19 +0,0 @@
1
- // uview-x 组件样式基础 mixin。
2
- //
3
- // 注意:这里只允许输出“编译期可消解”的 SCSS 或扁平 class 规则。
4
- // uni-app x App 蒸汽模式不支持元素选择器、后代选择器、伪类/伪元素,
5
- // 因此原 uv-ui 中的 view/scroll-view 全局重置必须放在 index.scss 的
6
- // WEB / MP 条件块中,不能出现在每个组件的 style 里。
7
- @mixin flex($direction: row) {
8
- /* #ifndef APP-NVUE */
9
- display: flex;
10
- /* #endif */
11
- flex-direction: $direction;
12
- }
13
-
14
- // 细边框(用于需要显式声明边框的场景,调用方自行控制 class)
15
- @mixin border-1px($color: #dadbde) {
16
- border-width: 0.5px;
17
- border-color: $color;
18
- border-style: solid;
19
- }
package/styles/vue.scss DELETED
@@ -1,39 +0,0 @@
1
- // 全局辅助样式(x-safe)。
2
- //
3
- // App 蒸汽模式不支持元素选择器、伪元素、后代选择器;
4
- // Web/小程序不需要这些限制,相关规则保留在条件编译块中。
5
-
6
- // 四个方向的安全区
7
- @each $d in top, right, bottom, left {
8
- .uv-safe-area-inset-#{$d} {
9
- padding-#{$d}: 0;
10
- /* #ifdef APP */
11
- padding-#{$d}: var(--uni-safe-area-inset-#{$d}, 0px);
12
- /* #endif */
13
- /* #ifdef WEB || H5 || MP */
14
- padding-#{$d}: constant(safe-area-inset-#{$d});
15
- padding-#{$d}: env(safe-area-inset-#{$d});
16
- /* #endif */
17
- }
18
- }
19
-
20
- /* #ifdef WEB || H5 */
21
- // 提升 H5 端 uni.toast() 的层级,避免被弹层遮盖
22
- uni-toast {
23
- z-index: 10090;
24
- }
25
- uni-toast .uni-toast {
26
- z-index: 10090;
27
- }
28
-
29
- // 隐藏 scroll-view 滚动条
30
- ::-webkit-scrollbar {
31
- display: none;
32
- width: 0 !important;
33
- height: 0 !important;
34
- -webkit-appearance: none;
35
- background: transparent;
36
- }
37
- /* #endif */
38
-
39
-
package/theme.scss DELETED
@@ -1,2 +0,0 @@
1
- // 主题变量入口(兼容旧路径):源文件位于 styles/theme.scss
2
- @import "./styles/theme.scss";