@hlw-uni-mp/use 1.0.0 → 1.0.1

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.
package/dist/index.js CHANGED
@@ -26,6 +26,7 @@ __export(index_exports, {
26
26
  fontFamilyPresets: () => fontFamilyPresets,
27
27
  fontSizePresets: () => fontSizePresets,
28
28
  getTheme: () => getTheme,
29
+ hlw: () => hlw,
29
30
  initTheme: () => initTheme,
30
31
  showShareMenu: () => showShareMenu,
31
32
  useMsg: () => useMsg,
@@ -132,6 +133,13 @@ function useMsg() {
132
133
  setLoadingBar
133
134
  };
134
135
  }
136
+ var _msg = null;
137
+ var hlw = {
138
+ /** 统一提示门面 */
139
+ get $msg() {
140
+ return _msg ?? (_msg = useMsg());
141
+ }
142
+ };
135
143
 
136
144
  // src/theme/index.ts
137
145
  var import_vue = require("vue");
@@ -341,6 +349,7 @@ function useRefs() {
341
349
  fontFamilyPresets,
342
350
  fontSizePresets,
343
351
  getTheme,
352
+ hlw,
344
353
  initTheme,
345
354
  showShareMenu,
346
355
  useMsg,
package/dist/index.mjs CHANGED
@@ -94,6 +94,13 @@ function useMsg() {
94
94
  setLoadingBar
95
95
  };
96
96
  }
97
+ var _msg = null;
98
+ var hlw = {
99
+ /** 统一提示门面 */
100
+ get $msg() {
101
+ return _msg ?? (_msg = useMsg());
102
+ }
103
+ };
97
104
 
98
105
  // src/theme/index.ts
99
106
  import { computed, toRef } from "vue";
@@ -302,6 +309,7 @@ export {
302
309
  fontFamilyPresets,
303
310
  fontSizePresets,
304
311
  getTheme,
312
+ hlw,
305
313
  initTheme,
306
314
  showShareMenu,
307
315
  useMsg,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hlw-uni-mp/use",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "Universal Uni-App Vue 3 stateful composables library",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",
package/dist/index.d.mts DELETED
@@ -1,233 +0,0 @@
1
- import { ApiRes } from '@hlw-uni-mp/request';
2
- import * as pinia from 'pinia';
3
- import { App, Ref, ComputedRef } from 'vue';
4
-
5
- /**
6
- * 提示回调函数类型 (confirm 为 true 表示确定,false 为取消)
7
- */
8
- type ToastCallback = (confirm: boolean) => void;
9
-
10
- /**
11
- * 消息门面体
12
- */
13
- interface HlwMsg {
14
- /** 显示轻提示或模态确认框 (支持回调与 Promise) */
15
- toast<T = unknown>(opts: UniApp.ShowToastOptions | ApiRes<T> | string, callback?: ToastCallback): Promise<boolean>;
16
- /** 成功提示框 */
17
- success(msg: string): void;
18
- /** 失败提示框 */
19
- error(msg: string): void;
20
- /** 显全局加载 */
21
- showLoading(msg?: string): void;
22
- /** 隐全局加载 */
23
- hideLoading(): void;
24
- /** 弹出确认框 */
25
- modal(opts?: UniApp.ShowModalOptions): Promise<boolean>;
26
- /** 标题进度条 */
27
- setLoadingBar(progress: number): void;
28
- }
29
-
30
- /**
31
- * 统一的消息提示与弹窗能力 hook。
32
- *
33
- * @example
34
- * ```ts
35
- * const msg = useMsg();
36
- * msg.toast('操作成功');
37
- * msg.toast(res, (confirm) => {
38
- * if (confirm) console.log('点击确定');
39
- * else console.log('点击取消');
40
- * });
41
- * const ok = await msg.modal({ content: '确定删除吗?' });
42
- * ```
43
- */
44
- declare function useMsg(): HlwMsg;
45
-
46
- /**
47
- * 外观模式型
48
- */
49
- type ThemeMode = "light" | "dark" | "system";
50
-
51
- /**
52
- * 字体大小型
53
- */
54
- type FontSize = "small" | "standard" | "large" | "extra-large";
55
-
56
- /**
57
- * 字体样式型
58
- */
59
- type FontFamily = "system" | "sans" | "serif" | "kaiti";
60
-
61
- /**
62
- * 主题色彩项
63
- */
64
- interface ThemeColor {
65
- name: string;
66
- value: string;
67
- }
68
-
69
- /**
70
- * 主题状态表
71
- */
72
- interface ThemeState {
73
- mode: ThemeMode;
74
- color: string;
75
- fontSize: FontSize;
76
- fontFamily: FontFamily;
77
- }
78
-
79
- /**
80
- * 初始配置项
81
- */
82
- interface InitThemeOptions {
83
- sync?: boolean;
84
- defaultTheme?: Partial<ThemeState>;
85
- }
86
-
87
- /**
88
- * 字体大小项
89
- */
90
- interface FontSizePreset {
91
- id: string;
92
- name: string;
93
- class: string;
94
- }
95
-
96
- /**
97
- * 字体样式项
98
- */
99
- interface FontFamilyPreset {
100
- id: string;
101
- name: string;
102
- class: string;
103
- }
104
-
105
- /**
106
- * 字体大小表
107
- */
108
- declare const fontSizePresets: FontSizePreset[];
109
- /**
110
- * 字体样式表
111
- */
112
- declare const fontFamilyPresets: FontFamilyPreset[];
113
- /**
114
- * 主题状态库
115
- */
116
- declare const useThemeStore: pinia.StoreDefinition<"theme", {
117
- mode: string;
118
- color: string;
119
- fontSize: string;
120
- fontFamily: string;
121
- }, {}, {}>;
122
-
123
- /**
124
- * 默认主题配置
125
- */
126
- declare const DEFAULT_THEME: ThemeState;
127
- /**
128
- * 预设色彩库
129
- */
130
- declare const THEME_COLORS: ThemeColor[];
131
- /**
132
- * 获取存储配置
133
- */
134
- declare function getTheme(): ThemeState;
135
- /**
136
- * 应用主题状态
137
- */
138
- declare function applyTheme(themeState: Partial<ThemeState>): void;
139
- /**
140
- * 注册主题器
141
- */
142
- declare function initTheme(app: App, options?: InitThemeOptions): void;
143
- /**
144
- * 主题组合钩子
145
- */
146
- declare function useTheme(): {
147
- mode: Ref<ThemeMode, ThemeMode>;
148
- color: Ref<string, string>;
149
- fontSize: Ref<string, string>;
150
- fontSizeClass: ComputedRef<string>;
151
- fontFamily: Ref<string, string>;
152
- fontFamilyClass: ComputedRef<string>;
153
- colors: ThemeColor[];
154
- fontSizePresets: FontSizePreset[];
155
- fontFamilyPresets: FontFamilyPreset[];
156
- setMode: (targetMode: ThemeMode) => void;
157
- setColor: (hexColor: string) => void;
158
- setFontSize: (targetSize: string) => void;
159
- setFontFamily: (targetFont: string) => void;
160
- resetTheme: () => void;
161
- applyTheme: typeof applyTheme;
162
- getTheme: typeof getTheme;
163
- initTheme: typeof initTheme;
164
- store: pinia.Store<"theme", {
165
- mode: string;
166
- color: string;
167
- fontSize: string;
168
- fontFamily: string;
169
- }, {}, {}>;
170
- };
171
-
172
- /**
173
- * 分享卡片配置项
174
- */
175
- interface ShareConfig {
176
- /** 分享标题 */
177
- title?: string;
178
- /** 分享页面路径 */
179
- path?: string;
180
- /** 分享卡片封面图 */
181
- imageUrl?: string;
182
- }
183
-
184
- /**
185
- * 分享操作句柄
186
- */
187
- interface ShareHandlers {
188
- /** 显式调起分享菜单 */
189
- showShareMenu: () => void;
190
- }
191
-
192
- /**
193
- * 显式调起分享菜单
194
- */
195
- declare function showShareMenu(): void;
196
- /**
197
- * 分享组合式函数
198
- */
199
- declare function useShare(config?: ShareConfig): ShareHandlers;
200
-
201
- /**
202
- * useRefs - 模板 Ref 批量管理
203
- *
204
- * 主要用于在 v-for 循环场景下,动态收集一组子元素或子组件的引用实例。
205
- * 规避了 Vue3 在 v-for 中绑定 ref 时需要手动处理数组收集和清理的冗余逻辑。
206
- */
207
-
208
- interface UseRefsReturn<T = unknown> {
209
- /** 存放动态收集到的所有组件或 DOM 实例的 Key-Value 映射对象 */
210
- refs: Ref<Record<string, T>>;
211
- /** 按 key 生成一个 ref 绑定回调函数 */
212
- setRefs: (key: string) => (element: T | null) => void;
213
- }
214
- /**
215
- * 管理动态 ref 集合的 hook,尤其适合 v-for 列表场景。
216
- *
217
- * @example
218
- * ```vue
219
- * <template>
220
- * <view v-for="item in list" :key="item.id" :ref="setRefs(item.id)">
221
- * {{ item.name }}
222
- * </view>
223
- * </template>
224
- *
225
- * <script setup>
226
- * const { refs, setRefs } = useRefs();
227
- * // 访问特定子项的 DOM/实例: refs.value[itemId]
228
- * </script>
229
- * ```
230
- */
231
- declare function useRefs<T = unknown>(): UseRefsReturn<T>;
232
-
233
- export { DEFAULT_THEME, type FontFamily, type FontFamilyPreset, type FontSize, type FontSizePreset, type HlwMsg, type InitThemeOptions, type ShareConfig, type ShareHandlers, THEME_COLORS, type ThemeColor, type ThemeMode, type ThemeState, type ToastCallback, type UseRefsReturn, applyTheme, fontFamilyPresets, fontSizePresets, getTheme, initTheme, showShareMenu, useMsg, useRefs, useShare, useTheme, useThemeStore };
package/dist/index.d.ts DELETED
@@ -1,233 +0,0 @@
1
- import { ApiRes } from '@hlw-uni-mp/request';
2
- import * as pinia from 'pinia';
3
- import { App, Ref, ComputedRef } from 'vue';
4
-
5
- /**
6
- * 提示回调函数类型 (confirm 为 true 表示确定,false 为取消)
7
- */
8
- type ToastCallback = (confirm: boolean) => void;
9
-
10
- /**
11
- * 消息门面体
12
- */
13
- interface HlwMsg {
14
- /** 显示轻提示或模态确认框 (支持回调与 Promise) */
15
- toast<T = unknown>(opts: UniApp.ShowToastOptions | ApiRes<T> | string, callback?: ToastCallback): Promise<boolean>;
16
- /** 成功提示框 */
17
- success(msg: string): void;
18
- /** 失败提示框 */
19
- error(msg: string): void;
20
- /** 显全局加载 */
21
- showLoading(msg?: string): void;
22
- /** 隐全局加载 */
23
- hideLoading(): void;
24
- /** 弹出确认框 */
25
- modal(opts?: UniApp.ShowModalOptions): Promise<boolean>;
26
- /** 标题进度条 */
27
- setLoadingBar(progress: number): void;
28
- }
29
-
30
- /**
31
- * 统一的消息提示与弹窗能力 hook。
32
- *
33
- * @example
34
- * ```ts
35
- * const msg = useMsg();
36
- * msg.toast('操作成功');
37
- * msg.toast(res, (confirm) => {
38
- * if (confirm) console.log('点击确定');
39
- * else console.log('点击取消');
40
- * });
41
- * const ok = await msg.modal({ content: '确定删除吗?' });
42
- * ```
43
- */
44
- declare function useMsg(): HlwMsg;
45
-
46
- /**
47
- * 外观模式型
48
- */
49
- type ThemeMode = "light" | "dark" | "system";
50
-
51
- /**
52
- * 字体大小型
53
- */
54
- type FontSize = "small" | "standard" | "large" | "extra-large";
55
-
56
- /**
57
- * 字体样式型
58
- */
59
- type FontFamily = "system" | "sans" | "serif" | "kaiti";
60
-
61
- /**
62
- * 主题色彩项
63
- */
64
- interface ThemeColor {
65
- name: string;
66
- value: string;
67
- }
68
-
69
- /**
70
- * 主题状态表
71
- */
72
- interface ThemeState {
73
- mode: ThemeMode;
74
- color: string;
75
- fontSize: FontSize;
76
- fontFamily: FontFamily;
77
- }
78
-
79
- /**
80
- * 初始配置项
81
- */
82
- interface InitThemeOptions {
83
- sync?: boolean;
84
- defaultTheme?: Partial<ThemeState>;
85
- }
86
-
87
- /**
88
- * 字体大小项
89
- */
90
- interface FontSizePreset {
91
- id: string;
92
- name: string;
93
- class: string;
94
- }
95
-
96
- /**
97
- * 字体样式项
98
- */
99
- interface FontFamilyPreset {
100
- id: string;
101
- name: string;
102
- class: string;
103
- }
104
-
105
- /**
106
- * 字体大小表
107
- */
108
- declare const fontSizePresets: FontSizePreset[];
109
- /**
110
- * 字体样式表
111
- */
112
- declare const fontFamilyPresets: FontFamilyPreset[];
113
- /**
114
- * 主题状态库
115
- */
116
- declare const useThemeStore: pinia.StoreDefinition<"theme", {
117
- mode: string;
118
- color: string;
119
- fontSize: string;
120
- fontFamily: string;
121
- }, {}, {}>;
122
-
123
- /**
124
- * 默认主题配置
125
- */
126
- declare const DEFAULT_THEME: ThemeState;
127
- /**
128
- * 预设色彩库
129
- */
130
- declare const THEME_COLORS: ThemeColor[];
131
- /**
132
- * 获取存储配置
133
- */
134
- declare function getTheme(): ThemeState;
135
- /**
136
- * 应用主题状态
137
- */
138
- declare function applyTheme(themeState: Partial<ThemeState>): void;
139
- /**
140
- * 注册主题器
141
- */
142
- declare function initTheme(app: App, options?: InitThemeOptions): void;
143
- /**
144
- * 主题组合钩子
145
- */
146
- declare function useTheme(): {
147
- mode: Ref<ThemeMode, ThemeMode>;
148
- color: Ref<string, string>;
149
- fontSize: Ref<string, string>;
150
- fontSizeClass: ComputedRef<string>;
151
- fontFamily: Ref<string, string>;
152
- fontFamilyClass: ComputedRef<string>;
153
- colors: ThemeColor[];
154
- fontSizePresets: FontSizePreset[];
155
- fontFamilyPresets: FontFamilyPreset[];
156
- setMode: (targetMode: ThemeMode) => void;
157
- setColor: (hexColor: string) => void;
158
- setFontSize: (targetSize: string) => void;
159
- setFontFamily: (targetFont: string) => void;
160
- resetTheme: () => void;
161
- applyTheme: typeof applyTheme;
162
- getTheme: typeof getTheme;
163
- initTheme: typeof initTheme;
164
- store: pinia.Store<"theme", {
165
- mode: string;
166
- color: string;
167
- fontSize: string;
168
- fontFamily: string;
169
- }, {}, {}>;
170
- };
171
-
172
- /**
173
- * 分享卡片配置项
174
- */
175
- interface ShareConfig {
176
- /** 分享标题 */
177
- title?: string;
178
- /** 分享页面路径 */
179
- path?: string;
180
- /** 分享卡片封面图 */
181
- imageUrl?: string;
182
- }
183
-
184
- /**
185
- * 分享操作句柄
186
- */
187
- interface ShareHandlers {
188
- /** 显式调起分享菜单 */
189
- showShareMenu: () => void;
190
- }
191
-
192
- /**
193
- * 显式调起分享菜单
194
- */
195
- declare function showShareMenu(): void;
196
- /**
197
- * 分享组合式函数
198
- */
199
- declare function useShare(config?: ShareConfig): ShareHandlers;
200
-
201
- /**
202
- * useRefs - 模板 Ref 批量管理
203
- *
204
- * 主要用于在 v-for 循环场景下,动态收集一组子元素或子组件的引用实例。
205
- * 规避了 Vue3 在 v-for 中绑定 ref 时需要手动处理数组收集和清理的冗余逻辑。
206
- */
207
-
208
- interface UseRefsReturn<T = unknown> {
209
- /** 存放动态收集到的所有组件或 DOM 实例的 Key-Value 映射对象 */
210
- refs: Ref<Record<string, T>>;
211
- /** 按 key 生成一个 ref 绑定回调函数 */
212
- setRefs: (key: string) => (element: T | null) => void;
213
- }
214
- /**
215
- * 管理动态 ref 集合的 hook,尤其适合 v-for 列表场景。
216
- *
217
- * @example
218
- * ```vue
219
- * <template>
220
- * <view v-for="item in list" :key="item.id" :ref="setRefs(item.id)">
221
- * {{ item.name }}
222
- * </view>
223
- * </template>
224
- *
225
- * <script setup>
226
- * const { refs, setRefs } = useRefs();
227
- * // 访问特定子项的 DOM/实例: refs.value[itemId]
228
- * </script>
229
- * ```
230
- */
231
- declare function useRefs<T = unknown>(): UseRefsReturn<T>;
232
-
233
- export { DEFAULT_THEME, type FontFamily, type FontFamilyPreset, type FontSize, type FontSizePreset, type HlwMsg, type InitThemeOptions, type ShareConfig, type ShareHandlers, THEME_COLORS, type ThemeColor, type ThemeMode, type ThemeState, type ToastCallback, type UseRefsReturn, applyTheme, fontFamilyPresets, fontSizePresets, getTheme, initTheme, showShareMenu, useMsg, useRefs, useShare, useTheme, useThemeStore };