@foundbyte/uni-libs 1.0.7 → 1.0.8

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/es/index.d.ts CHANGED
@@ -16,5 +16,6 @@ import { getMoviePage } from "./utils/pages/movie/index.js";
16
16
  import { EMessagesType, IShareParam, isAlipay, isAndroid, isHarmony, isIOSOrAndroid, isWeixin, isiOS, navigateBack, navigateTo, postMessage, redirectTo, setShareParam, toPay } from "./utils/web-view/index.js";
17
17
  import { isAlipayEnv, isAndroidEnv, isAppEnv, isH5Env, isHarmonyEnv, isToutiaoEnv, isWeixinEnv, isiOSEnv } from "./utils/uni-env/index.js";
18
18
  import { checkAndRequestNativeAppPermission } from "./utils/native-app/index.js";
19
+ import { CompressOptions, EObsSource, compressHuaweiObsImg, compressObsImg } from "./utils/obs/image.js";
19
20
  import { OneTravelSDK } from "./entry.js";
20
- export { ActivityCalendarDetailPageParams, BusinessLineDict, EAppEnv, EBusinessLine, ECaller, EFoodPackageType, EFoodsModuleType, EHotelType, EMessagesType, ESubBizType, EUniPlatform, EVenueSimpleTypes, EVenueTypes, IOneTravelSDKConfig, IShareParam, OneTravelSDK, WebviewPageParams, app_permission, checkAndRequestNativeAppPermission, getActivityCalendarDetailPage, getFoodPackagePage, getFoodStorePage, getMoviePage, getQueryParameters, getWebviewPage, isAlipay, isAlipayEnv, isAndroid, isAndroidEnv, isAppEnv, isEmpty, isH5Env, isHarmony, isHarmonyEnv, isIOSOrAndroid, isToutiaoEnv, isWeixin, isWeixinEnv, isiOS, isiOSEnv, navigateBack, navigateTo, postMessage, query2url, redirectTo, routePrefix, routes, setShareParam, toPay };
21
+ export { ActivityCalendarDetailPageParams, BusinessLineDict, CompressOptions, EAppEnv, EBusinessLine, ECaller, EFoodPackageType, EFoodsModuleType, EHotelType, EMessagesType, EObsSource, ESubBizType, EUniPlatform, EVenueSimpleTypes, EVenueTypes, IOneTravelSDKConfig, IShareParam, OneTravelSDK, WebviewPageParams, app_permission, checkAndRequestNativeAppPermission, compressHuaweiObsImg, compressObsImg, getActivityCalendarDetailPage, getFoodPackagePage, getFoodStorePage, getMoviePage, getQueryParameters, getWebviewPage, isAlipay, isAlipayEnv, isAndroid, isAndroidEnv, isAppEnv, isEmpty, isH5Env, isHarmony, isHarmonyEnv, isIOSOrAndroid, isToutiaoEnv, isWeixin, isWeixinEnv, isiOS, isiOSEnv, navigateBack, navigateTo, postMessage, query2url, redirectTo, routePrefix, routes, setShareParam, toPay };
package/es/index.js CHANGED
@@ -15,5 +15,6 @@ import { getMoviePage } from "./utils/pages/movie/index.js";
15
15
  import { EMessagesType, isAlipay, isAndroid, isHarmony, isIOSOrAndroid, isWeixin, isiOS, navigateBack, navigateTo, postMessage, redirectTo, setShareParam, toPay } from "./utils/web-view/index.js";
16
16
  import { isAlipayEnv, isAndroidEnv, isAppEnv, isH5Env, isHarmonyEnv, isToutiaoEnv, isWeixinEnv, isiOSEnv } from "./utils/uni-env/index.js";
17
17
  import { checkAndRequestNativeAppPermission } from "./utils/native-app/index.js";
18
+ import { EObsSource, compressHuaweiObsImg, compressObsImg } from "./utils/obs/image.js";
18
19
  import { OneTravelSDK } from "./entry.js";
19
- export { BusinessLineDict, EAppEnv, EBusinessLine, ECaller, EFoodPackageType, EFoodsModuleType, EHotelType, EMessagesType, ESubBizType, EUniPlatform, EVenueSimpleTypes, EVenueTypes, OneTravelSDK, app_permission, checkAndRequestNativeAppPermission, getActivityCalendarDetailPage, getFoodPackagePage, getFoodStorePage, getMoviePage, getQueryParameters, getWebviewPage, isAlipay, isAlipayEnv, isAndroid, isAndroidEnv, isAppEnv, isEmpty, isH5Env, isHarmony, isHarmonyEnv, isIOSOrAndroid, isToutiaoEnv, isWeixin, isWeixinEnv, isiOS, isiOSEnv, navigateBack, navigateTo, postMessage, query2url, redirectTo, routePrefix, routes, setShareParam, toPay };
20
+ export { BusinessLineDict, EAppEnv, EBusinessLine, ECaller, EFoodPackageType, EFoodsModuleType, EHotelType, EMessagesType, EObsSource, ESubBizType, EUniPlatform, EVenueSimpleTypes, EVenueTypes, OneTravelSDK, app_permission, checkAndRequestNativeAppPermission, compressHuaweiObsImg, compressObsImg, getActivityCalendarDetailPage, getFoodPackagePage, getFoodStorePage, getMoviePage, getQueryParameters, getWebviewPage, isAlipay, isAlipayEnv, isAndroid, isAndroidEnv, isAppEnv, isEmpty, isH5Env, isHarmony, isHarmonyEnv, isIOSOrAndroid, isToutiaoEnv, isWeixin, isWeixinEnv, isiOS, isiOSEnv, navigateBack, navigateTo, postMessage, query2url, redirectTo, routePrefix, routes, setShareParam, toPay };
@@ -0,0 +1,45 @@
1
+ //#region src/utils/obs/image.d.ts
2
+ declare enum EObsSource {
3
+ /** 华为 */
4
+ Huawei = 1,
5
+ /** 腾讯 */
6
+ Tencent = 2,
7
+ /** ali */
8
+ Ali = 2,
9
+ }
10
+ /**
11
+ * 参考 https://support.huaweicloud.com/intl/zh-cn/fg-obs/obs_01_0430.html
12
+ */
13
+ type CompressOptions = {
14
+ w?: number;
15
+ h?: number;
16
+ /**
17
+ * 缩率类型,默认 'lfit'
18
+ * - `lfit`: 等比缩放,限制在容器内
19
+ * - `mfit`: 等比缩放,覆盖容器
20
+ * - `fill`: 等比缩放,裁剪填充容器
21
+ */
22
+ m?: 'lfit' | 'mfit' | 'fill';
23
+ p?: number;
24
+ l?: number;
25
+ s?: number;
26
+ color?: string;
27
+ /** 默认为 1,限制图片放大 */
28
+ limit?: 0 | 1;
29
+ q?: number;
30
+ Q?: number;
31
+ /** 是否开启图片瘦身 */
32
+ imageslim?: boolean;
33
+ /** obs 源 (huawei-华为; tencent-腾讯) */
34
+ source?: EObsSource;
35
+ };
36
+ /**
37
+ * 华为 obs 压缩
38
+ * @param url
39
+ * @param opts
40
+ * @returns
41
+ */
42
+ declare function compressHuaweiObsImg(url: string, opts: CompressOptions): string;
43
+ declare function compressObsImg(url: string, opts: CompressOptions): string;
44
+ //#endregion
45
+ export { CompressOptions, EObsSource, compressHuaweiObsImg, compressObsImg };
@@ -0,0 +1,85 @@
1
+ import { _objectSpread2 } from "../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js";
2
+ //#region src/utils/obs/image.ts
3
+ let EObsSource = /* @__PURE__ */ function(EObsSource) {
4
+ /** 华为 */
5
+ EObsSource[EObsSource["Huawei"] = 1] = "Huawei";
6
+ /** 腾讯 */
7
+ EObsSource[EObsSource["Tencent"] = 2] = "Tencent";
8
+ /** ali */
9
+ EObsSource[EObsSource["Ali"] = 2] = "Ali";
10
+ return EObsSource;
11
+ }({});
12
+ function filterEmptyValue(obj) {
13
+ return (key) => {
14
+ return ![
15
+ void 0,
16
+ null,
17
+ "",
18
+ NaN
19
+ ].includes(obj[key]);
20
+ };
21
+ }
22
+ function getValues(keys, obj) {
23
+ return keys.filter(filterEmptyValue(obj)).map((key) => `${key}_${obj[key]}`);
24
+ }
25
+ /**
26
+ * 华为 obs 压缩
27
+ * @param url
28
+ * @param opts
29
+ * @returns
30
+ */
31
+ function compressHuaweiObsImg(url, opts) {
32
+ if (opts === null || opts === void 0 ? void 0 : opts.w) opts = _objectSpread2(_objectSpread2({}, opts), {}, { w: Math.floor(opts.w) });
33
+ if (opts === null || opts === void 0 ? void 0 : opts.h) opts = _objectSpread2(_objectSpread2({}, opts), {}, { h: Math.floor(opts.h) });
34
+ const { imageslim = true } = opts;
35
+ if (url && [
36
+ ".jpg",
37
+ ".jpeg",
38
+ ".png",
39
+ ".bmp"
40
+ ].some((suffix) => url.toLowerCase().endsWith(suffix))) {
41
+ const actions = ["x-image-process=image"];
42
+ const resize = getValues([
43
+ "w",
44
+ "h",
45
+ "m",
46
+ "p",
47
+ "l",
48
+ "s",
49
+ "color",
50
+ "limit"
51
+ ], opts);
52
+ if (resize.length) {
53
+ resize.splice(0, 0, "resize");
54
+ actions.push(resize.join(","));
55
+ }
56
+ const quality = getValues(["q", "Q"], opts);
57
+ if (quality.length) {
58
+ quality.splice(0, 0, "quality");
59
+ actions.push(quality.join(","));
60
+ }
61
+ if (imageslim) actions.push("imageslim");
62
+ return `${url}?${actions.join("/")}`;
63
+ }
64
+ return url;
65
+ }
66
+ /**
67
+ * 腾讯 obs 压缩
68
+ * https://cloud.tencent.com/document/product/436/113295
69
+ * @param url
70
+ * @param opts
71
+ * @returns
72
+ */
73
+ function compressTencentObsImg(url, opts) {
74
+ if (opts.w || opts.h) return `${url}?imageMogr2/thumbnail/!${opts.w || ""}x${opts.h || ""}r`;
75
+ return url;
76
+ }
77
+ function compressObsImg(url, opts) {
78
+ switch (opts.source) {
79
+ case EObsSource.Huawei: return compressHuaweiObsImg(url, opts);
80
+ case EObsSource.Ali: return compressHuaweiObsImg(url, opts);
81
+ default: return compressTencentObsImg(url, opts);
82
+ }
83
+ }
84
+ //#endregion
85
+ export { EObsSource, compressHuaweiObsImg, compressObsImg };
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@foundbyte/uni-libs",
3
3
  "description": "FoundByte Uni Libs",
4
4
  "author": "yangshuai <704807396@qq.com>",
5
- "version": "1.0.7",
5
+ "version": "1.0.8",
6
6
  "private": false,
7
7
  "type": "module",
8
8
  "main": "es/index.js",
@@ -19,7 +19,7 @@
19
19
  "sideEffects": false,
20
20
  "dependencies": {
21
21
  "weixin-js-sdk": "^1.6.5",
22
- "@foundbyte/uni-hooks": "^1.0.4"
22
+ "@foundbyte/uni-hooks": "^1.0.6"
23
23
  },
24
24
  "devDependencies": {
25
25
  "typescript": "~5.7.2",