@hlw-uni/mp-vue 1.0.34 → 1.0.35

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.
@@ -0,0 +1,9 @@
1
+ export type FontScale = "small" | "normal" | "large" | "xlarge";
2
+ export interface FontPreset {
3
+ label: string;
4
+ vars: Record<string, string>;
5
+ }
6
+ export declare const FONT_SCALE_KEY = "hlw_font_scale";
7
+ export declare const FONT_PRESETS: Record<FontScale, FontPreset>;
8
+ export declare function getCurrentFontScale(): FontScale;
9
+ export declare function getCurrentFontVars(): Record<string, string>;
@@ -0,0 +1,9 @@
1
+ export declare const THEME_CHANGE_EVENT = "hlw:theme-change";
2
+ export declare function buildThemeStyle(): string;
3
+ export declare function useThemePageStyle(): {
4
+ themePageStyle: any;
5
+ };
6
+ export type { FontScale, FontPreset } from './font';
7
+ export { FONT_SCALE_KEY, FONT_PRESETS, getCurrentFontScale, getCurrentFontVars } from './font';
8
+ export type { ThemeColor } from './palette';
9
+ export { THEME_COLOR_KEY, DEFAULT_THEMES, getCurrentThemeColor, getCurrentThemeVars } from './palette';
@@ -0,0 +1,8 @@
1
+ export interface ThemeColor {
2
+ label: string;
3
+ value: string;
4
+ }
5
+ export declare const THEME_COLOR_KEY = "hlw_theme_color";
6
+ export declare const DEFAULT_THEMES: ThemeColor[];
7
+ export declare function getCurrentThemeColor(): string;
8
+ export declare function getCurrentThemeVars(): Record<string, string>;
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  (function(global, factory) {
2
- typeof exports === "object" && typeof module !== "undefined" ? factory(exports, require("vue"), require("pinia")) : typeof define === "function" && define.amd ? define(["exports", "vue", "pinia"], factory) : (global = typeof globalThis !== "undefined" ? globalThis : global || self, factory(global.HlwUniVue = {}, global.vue, global.pinia));
3
- })(this, function(exports2, vue, pinia) {
2
+ typeof exports === "object" && typeof module !== "undefined" ? factory(exports, require("vue"), require("@hlw-uni/mp-core"), require("pinia")) : typeof define === "function" && define.amd ? define(["exports", "vue", "@hlw-uni/mp-core", "pinia"], factory) : (global = typeof globalThis !== "undefined" ? globalThis : global || self, factory(global.HlwUniVue = {}, global.vue, global.mpCore, global.pinia));
3
+ })(this, function(exports2, vue, mpCore, pinia) {
4
4
  "use strict";
5
5
  const _sfc_main$7 = /* @__PURE__ */ vue.defineComponent({
6
6
  ...{ name: "HlwAd" },
@@ -564,24 +564,7 @@
564
564
  }
565
565
  });
566
566
  const index = /* @__PURE__ */ _export_sfc(_sfc_main, [["__scopeId", "data-v-d8833363"]]);
567
- function varsToStyle(vars) {
568
- return Object.entries(vars).map(([k, v]) => `${k}:${v}`).join(";") + ";";
569
- }
570
- function hexToRgba(hex, alpha) {
571
- const r = parseInt(hex.slice(1, 3), 16);
572
- const g = parseInt(hex.slice(3, 5), 16);
573
- const b = parseInt(hex.slice(5, 7), 16);
574
- return `rgba(${r},${g},${b},${alpha})`;
575
- }
576
- function darkenHex(hex, amount = 0.15) {
577
- const r = Math.max(0, Math.round(parseInt(hex.slice(1, 3), 16) * (1 - amount)));
578
- const g = Math.max(0, Math.round(parseInt(hex.slice(3, 5), 16) * (1 - amount)));
579
- const b = Math.max(0, Math.round(parseInt(hex.slice(5, 7), 16) * (1 - amount)));
580
- return `#${r.toString(16).padStart(2, "0")}${g.toString(16).padStart(2, "0")}${b.toString(16).padStart(2, "0")}`;
581
- }
582
567
  const FONT_SCALE_KEY = "hlw_font_scale";
583
- const THEME_COLOR_KEY = "hlw_theme_color";
584
- const THEME_CHANGE_EVENT = "hlw:theme-change";
585
568
  const FONT_PRESETS = {
586
569
  small: {
587
570
  label: "小字体",
@@ -640,6 +623,8 @@
640
623
  function getCurrentFontVars() {
641
624
  return FONT_PRESETS[getCurrentFontScale()].vars;
642
625
  }
626
+ const { hexToRgba, darkenHex } = mpCore.useColor();
627
+ const THEME_COLOR_KEY = "hlw_theme_color";
643
628
  const DEFAULT_THEMES = [
644
629
  { label: "默认蓝", value: "#3b82f6" },
645
630
  { label: "活力橙", value: "#f97316" },
@@ -665,6 +650,8 @@
665
650
  "--primary-dark": darkenHex(color)
666
651
  };
667
652
  }
653
+ const { varsToStyle } = mpCore.useColor();
654
+ const THEME_CHANGE_EVENT = "hlw:theme-change";
668
655
  function buildThemeStyle() {
669
656
  return varsToStyle({
670
657
  ...getCurrentFontVars(),
package/dist/index.mjs CHANGED
@@ -1,4 +1,5 @@
1
1
  import { defineComponent, resolveComponent, openBlock, createBlock, ref, computed, createElementBlock, normalizeClass, createElementVNode, toDisplayString, useSlots, renderSlot, createCommentVNode, normalizeStyle, unref, Fragment, renderList, withCtx, createVNode, onMounted, onUnmounted } from "vue";
2
+ import { useColor } from "@hlw-uni/mp-core";
2
3
  import { defineStore } from "pinia";
3
4
  const _sfc_main$7 = /* @__PURE__ */ defineComponent({
4
5
  ...{ name: "HlwAd" },
@@ -562,24 +563,7 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
562
563
  }
563
564
  });
564
565
  const index = /* @__PURE__ */ _export_sfc(_sfc_main, [["__scopeId", "data-v-d8833363"]]);
565
- function varsToStyle(vars) {
566
- return Object.entries(vars).map(([k, v]) => `${k}:${v}`).join(";") + ";";
567
- }
568
- function hexToRgba(hex, alpha) {
569
- const r = parseInt(hex.slice(1, 3), 16);
570
- const g = parseInt(hex.slice(3, 5), 16);
571
- const b = parseInt(hex.slice(5, 7), 16);
572
- return `rgba(${r},${g},${b},${alpha})`;
573
- }
574
- function darkenHex(hex, amount = 0.15) {
575
- const r = Math.max(0, Math.round(parseInt(hex.slice(1, 3), 16) * (1 - amount)));
576
- const g = Math.max(0, Math.round(parseInt(hex.slice(3, 5), 16) * (1 - amount)));
577
- const b = Math.max(0, Math.round(parseInt(hex.slice(5, 7), 16) * (1 - amount)));
578
- return `#${r.toString(16).padStart(2, "0")}${g.toString(16).padStart(2, "0")}${b.toString(16).padStart(2, "0")}`;
579
- }
580
566
  const FONT_SCALE_KEY = "hlw_font_scale";
581
- const THEME_COLOR_KEY = "hlw_theme_color";
582
- const THEME_CHANGE_EVENT = "hlw:theme-change";
583
567
  const FONT_PRESETS = {
584
568
  small: {
585
569
  label: "小字体",
@@ -638,6 +622,8 @@ function getCurrentFontScale() {
638
622
  function getCurrentFontVars() {
639
623
  return FONT_PRESETS[getCurrentFontScale()].vars;
640
624
  }
625
+ const { hexToRgba, darkenHex } = useColor();
626
+ const THEME_COLOR_KEY = "hlw_theme_color";
641
627
  const DEFAULT_THEMES = [
642
628
  { label: "默认蓝", value: "#3b82f6" },
643
629
  { label: "活力橙", value: "#f97316" },
@@ -663,6 +649,8 @@ function getCurrentThemeVars() {
663
649
  "--primary-dark": darkenHex(color)
664
650
  };
665
651
  }
652
+ const { varsToStyle } = useColor();
653
+ const THEME_CHANGE_EVENT = "hlw:theme-change";
666
654
  function buildThemeStyle() {
667
655
  return varsToStyle({
668
656
  ...getCurrentFontVars(),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hlw-uni/mp-vue",
3
- "version": "1.0.34",
3
+ "version": "1.0.35",
4
4
  "description": "hlw-uni Vue 组件库 — 供小程序业务方使用的 UI 组件集合",
5
5
  "main": "src/index.ts",
6
6
  "module": "src/index.ts",
@@ -26,19 +26,19 @@
26
26
  "access": "public"
27
27
  },
28
28
  "peerDependencies": {
29
- "vue": ">=3.4.0",
30
- "pinia": ">=2.0.0"
29
+ "pinia": ">=2.0.0",
30
+ "vue": ">=3.4.0"
31
31
  },
32
32
  "devDependencies": {
33
- "@dcloudio/types": "^3.4.8",
34
- "@types/node": "^20.11.0",
35
- "@vitejs/plugin-vue": "^5.0.0",
36
- "typescript": "^4.9.4",
33
+ "@dcloudio/types": "^3.4.30",
34
+ "@types/node": "^20.19.39",
35
+ "@vitejs/plugin-vue": "^5.2.4",
36
+ "typescript": "^4.9.5",
37
37
  "vite": "5.2.8",
38
38
  "vite-plugin-dts": "^4.5.4",
39
- "vue": "^3.4.0"
39
+ "vue": "^3.5.32"
40
40
  },
41
41
  "dependencies": {
42
- "@hlw-uni/mp-core": "^1.0.10"
42
+ "@hlw-uni/mp-core": "^1.0.28"
43
43
  }
44
44
  }
@@ -0,0 +1,51 @@
1
+ export type FontScale = "small" | "normal" | "large" | "xlarge";
2
+
3
+ export interface FontPreset {
4
+ label: string;
5
+ vars: Record<string, string>;
6
+ }
7
+
8
+ export const FONT_SCALE_KEY = "hlw_font_scale";
9
+
10
+ export const FONT_PRESETS: Record<FontScale, FontPreset> = {
11
+ small: {
12
+ label: "小字体",
13
+ vars: {
14
+ "--font-xs": "16rpx", "--font-sm": "20rpx", "--font-base": "24rpx",
15
+ "--font-md": "28rpx", "--font-lg": "32rpx", "--font-xl": "36rpx",
16
+ },
17
+ },
18
+ normal: {
19
+ label: "标准",
20
+ vars: {
21
+ "--font-xs": "20rpx", "--font-sm": "24rpx", "--font-base": "28rpx",
22
+ "--font-md": "32rpx", "--font-lg": "36rpx", "--font-xl": "40rpx",
23
+ },
24
+ },
25
+ large: {
26
+ label: "大字体",
27
+ vars: {
28
+ "--font-xs": "24rpx", "--font-sm": "30rpx", "--font-base": "34rpx",
29
+ "--font-md": "40rpx", "--font-lg": "46rpx", "--font-xl": "52rpx",
30
+ },
31
+ },
32
+ xlarge: {
33
+ label: "超大字体",
34
+ vars: {
35
+ "--font-xs": "28rpx", "--font-sm": "36rpx", "--font-base": "42rpx",
36
+ "--font-md": "48rpx", "--font-lg": "56rpx", "--font-xl": "64rpx",
37
+ },
38
+ },
39
+ };
40
+
41
+ export function getCurrentFontScale(): FontScale {
42
+ try {
43
+ const v = uni.getStorageSync(FONT_SCALE_KEY);
44
+ if (v === "small" || v === "large" || v === "xlarge") return v;
45
+ } catch {}
46
+ return "normal";
47
+ }
48
+
49
+ export function getCurrentFontVars(): Record<string, string> {
50
+ return FONT_PRESETS[getCurrentFontScale()].vars;
51
+ }
@@ -0,0 +1,33 @@
1
+ import { ref, onMounted, onUnmounted } from "vue";
2
+ import { useColor } from "@hlw-uni/mp-core";
3
+
4
+ const { varsToStyle } = useColor();
5
+ import { getCurrentFontVars } from "./font";
6
+ import { getCurrentThemeVars } from "./palette";
7
+
8
+ export const THEME_CHANGE_EVENT = "hlw:theme-change";
9
+
10
+ export function buildThemeStyle(): string {
11
+ return varsToStyle({
12
+ ...getCurrentFontVars(),
13
+ ...getCurrentThemeVars(),
14
+ });
15
+ }
16
+
17
+ export function useThemePageStyle() {
18
+ const themePageStyle = ref(buildThemeStyle());
19
+
20
+ const onThemeChange = () => {
21
+ themePageStyle.value = buildThemeStyle();
22
+ };
23
+
24
+ onMounted(() => uni.$on(THEME_CHANGE_EVENT, onThemeChange));
25
+ onUnmounted(() => uni.$off(THEME_CHANGE_EVENT, onThemeChange));
26
+
27
+ return { themePageStyle };
28
+ }
29
+
30
+ export type { FontScale, FontPreset } from "./font";
31
+ export { FONT_SCALE_KEY, FONT_PRESETS, getCurrentFontScale, getCurrentFontVars } from "./font";
32
+ export type { ThemeColor } from "./palette";
33
+ export { THEME_COLOR_KEY, DEFAULT_THEMES, getCurrentThemeColor, getCurrentThemeVars } from "./palette";
@@ -0,0 +1,36 @@
1
+ import { useColor } from "@hlw-uni/mp-core";
2
+
3
+ const { hexToRgba, darkenHex } = useColor();
4
+
5
+ export interface ThemeColor {
6
+ label: string;
7
+ value: string;
8
+ }
9
+
10
+ export const THEME_COLOR_KEY = "hlw_theme_color";
11
+
12
+ export const DEFAULT_THEMES: ThemeColor[] = [
13
+ { label: "默认蓝", value: "#3b82f6" },
14
+ { label: "活力橙", value: "#f97316" },
15
+ { label: "翡翠绿", value: "#10b981" },
16
+ { label: "玫瑰红", value: "#f43f5e" },
17
+ { label: "紫罗兰", value: "#8b5cf6" },
18
+ { label: "青石灰", value: "#64748b" },
19
+ ];
20
+
21
+ export function getCurrentThemeColor(): string {
22
+ try {
23
+ const v = uni.getStorageSync(THEME_COLOR_KEY);
24
+ if (v && typeof v === "string") return v;
25
+ } catch {}
26
+ return DEFAULT_THEMES[0].value;
27
+ }
28
+
29
+ export function getCurrentThemeVars(): Record<string, string> {
30
+ const color = getCurrentThemeColor();
31
+ return {
32
+ "--primary-color": color,
33
+ "--primary-light": hexToRgba(color, 0.12),
34
+ "--primary-dark": darkenHex(color),
35
+ };
36
+ }
@@ -1,22 +0,0 @@
1
- export type FontScale = "small" | "normal" | "large" | "xlarge";
2
- export interface FontPreset {
3
- label: string;
4
- vars: Record<string, string>;
5
- }
6
- export interface ThemeColor {
7
- label: string;
8
- value: string;
9
- }
10
- export declare const FONT_SCALE_KEY = "hlw_font_scale";
11
- export declare const THEME_COLOR_KEY = "hlw_theme_color";
12
- export declare const THEME_CHANGE_EVENT = "hlw:theme-change";
13
- export declare const FONT_PRESETS: Record<FontScale, FontPreset>;
14
- export declare function getCurrentFontScale(): FontScale;
15
- export declare function getCurrentFontVars(): Record<string, string>;
16
- export declare const DEFAULT_THEMES: ThemeColor[];
17
- export declare function getCurrentThemeColor(): string;
18
- export declare function getCurrentThemeVars(): Record<string, string>;
19
- export declare function buildThemeStyle(): string;
20
- export declare function useThemePageStyle(): {
21
- themePageStyle: any;
22
- };
@@ -1,142 +0,0 @@
1
- import { ref, onMounted, onUnmounted } from "vue";
2
-
3
- // ─── 工具函数 ───────────────────────────────────
4
-
5
- function varsToStyle(vars: Record<string, string>): string {
6
- return Object.entries(vars).map(([k, v]) => `${k}:${v}`).join(";") + ";";
7
- }
8
-
9
- function hexToRgba(hex: string, alpha: number): string {
10
- const r = parseInt(hex.slice(1, 3), 16);
11
- const g = parseInt(hex.slice(3, 5), 16);
12
- const b = parseInt(hex.slice(5, 7), 16);
13
- return `rgba(${r},${g},${b},${alpha})`;
14
- }
15
-
16
- function darkenHex(hex: string, amount = 0.15): string {
17
- const r = Math.max(0, Math.round(parseInt(hex.slice(1, 3), 16) * (1 - amount)));
18
- const g = Math.max(0, Math.round(parseInt(hex.slice(3, 5), 16) * (1 - amount)));
19
- const b = Math.max(0, Math.round(parseInt(hex.slice(5, 7), 16) * (1 - amount)));
20
- return `#${r.toString(16).padStart(2, "0")}${g.toString(16).padStart(2, "0")}${b.toString(16).padStart(2, "0")}`;
21
- }
22
-
23
- // ─── 类型 ──────────────────────────────────────
24
-
25
- export type FontScale = "small" | "normal" | "large" | "xlarge";
26
-
27
- export interface FontPreset {
28
- label: string;
29
- vars: Record<string, string>;
30
- }
31
-
32
- export interface ThemeColor {
33
- label: string;
34
- value: string;
35
- }
36
-
37
- // ─── 存储 Key ──────────────────────────────────
38
-
39
- export const FONT_SCALE_KEY = "hlw_font_scale";
40
- export const THEME_COLOR_KEY = "hlw_theme_color";
41
-
42
- // ─── 事件 ──────────────────────────────────────
43
-
44
- export const THEME_CHANGE_EVENT = "hlw:theme-change";
45
-
46
- // ─── 字体档位 ──────────────────────────────────
47
-
48
- export const FONT_PRESETS: Record<FontScale, FontPreset> = {
49
- small: {
50
- label: "小字体",
51
- vars: {
52
- "--font-xs": "16rpx", "--font-sm": "20rpx", "--font-base": "24rpx",
53
- "--font-md": "28rpx", "--font-lg": "32rpx", "--font-xl": "36rpx",
54
- },
55
- },
56
- normal: {
57
- label: "标准",
58
- vars: {
59
- "--font-xs": "20rpx", "--font-sm": "24rpx", "--font-base": "28rpx",
60
- "--font-md": "32rpx", "--font-lg": "36rpx", "--font-xl": "40rpx",
61
- },
62
- },
63
- large: {
64
- label: "大字体",
65
- vars: {
66
- "--font-xs": "24rpx", "--font-sm": "30rpx", "--font-base": "34rpx",
67
- "--font-md": "40rpx", "--font-lg": "46rpx", "--font-xl": "52rpx",
68
- },
69
- },
70
- xlarge: {
71
- label: "超大字体",
72
- vars: {
73
- "--font-xs": "28rpx", "--font-sm": "36rpx", "--font-base": "42rpx",
74
- "--font-md": "48rpx", "--font-lg": "56rpx", "--font-xl": "64rpx",
75
- },
76
- },
77
- };
78
-
79
- export function getCurrentFontScale(): FontScale {
80
- try {
81
- const v = uni.getStorageSync(FONT_SCALE_KEY);
82
- if (v === "small" || v === "large" || v === "xlarge") return v;
83
- } catch {}
84
- return "normal";
85
- }
86
-
87
- export function getCurrentFontVars(): Record<string, string> {
88
- return FONT_PRESETS[getCurrentFontScale()].vars;
89
- }
90
-
91
- // ─── 主题色 ────────────────────────────────────
92
-
93
- export const DEFAULT_THEMES: ThemeColor[] = [
94
- { label: "默认蓝", value: "#3b82f6" },
95
- { label: "活力橙", value: "#f97316" },
96
- { label: "翡翠绿", value: "#10b981" },
97
- { label: "玫瑰红", value: "#f43f5e" },
98
- { label: "紫罗兰", value: "#8b5cf6" },
99
- { label: "青石灰", value: "#64748b" },
100
- ];
101
-
102
- export function getCurrentThemeColor(): string {
103
- try {
104
- const v = uni.getStorageSync(THEME_COLOR_KEY);
105
- if (v && typeof v === "string") return v;
106
- } catch {}
107
- return DEFAULT_THEMES[0].value;
108
- }
109
-
110
- export function getCurrentThemeVars(): Record<string, string> {
111
- const color = getCurrentThemeColor();
112
- return {
113
- "--primary-color": color,
114
- "--primary-light": hexToRgba(color, 0.12),
115
- "--primary-dark": darkenHex(color),
116
- };
117
- }
118
-
119
- // ─── 统一样式构建 ──────────────────────────────
120
- // 后续新增主题维度时,只需添加 getCurrentXxxVars() 并在此展开
121
-
122
- export function buildThemeStyle(): string {
123
- return varsToStyle({
124
- ...getCurrentFontVars(),
125
- ...getCurrentThemeVars(),
126
- });
127
- }
128
-
129
- // ─── 组合式函数 ────────────────────────────────
130
-
131
- export function useThemePageStyle() {
132
- const themePageStyle = ref(buildThemeStyle());
133
-
134
- const onThemeChange = () => {
135
- themePageStyle.value = buildThemeStyle();
136
- };
137
-
138
- onMounted(() => uni.$on(THEME_CHANGE_EVENT, onThemeChange));
139
- onUnmounted(() => uni.$off(THEME_CHANGE_EVENT, onThemeChange));
140
-
141
- return { themePageStyle };
142
- }