share-light 0.0.5 → 1.0.2

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/LICENSE ADDED
@@ -0,0 +1,9 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 novlan1
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
+
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md CHANGED
@@ -1,4 +1,13 @@
1
- ## 分享 SDK
1
+ # 分享 SDK
2
+
3
+ <p align="center">
4
+ <img src="https://img.shields.io/npm/dw/share-light">
5
+ <img src="https://img.shields.io/npm/unpacked-size/share-light">
6
+ <img src="https://img.shields.io/npm/v/share-light">
7
+ <img src="https://img.shields.io/npm/l/share-light">
8
+ <img src="https://img.shields.io/github/last-commit/novlan1/plugin-light">
9
+ <img src="https://img.shields.io/github/created-at/novlan1/plugin-light">
10
+ </p>
2
11
 
3
12
  轻量级的分享 SDK。支持以下渠道
4
13
 
@@ -7,11 +16,15 @@
7
16
  3. QQ、微信
8
17
  4. 其他,包括系统浏览器
9
18
 
10
- ### 1. 如何使用
19
+ ## 1. 作者
20
+
21
+ **novlan1**
22
+
23
+ ## 2. 如何使用
11
24
 
12
25
  可直接引入,也可异步加载。
13
26
 
14
- #### 1.1. 直接引入
27
+ ### 2.1. 直接引入
15
28
 
16
29
  安装:
17
30
 
@@ -36,7 +49,7 @@ initShare({
36
49
  openShareUI();
37
50
  ```
38
51
 
39
- #### 1.2. 异步加载
52
+ ### 2.2. 异步加载
40
53
 
41
54
  也可异步加载,并使用其提供的全局变量 `shareLightSDK`,性能更佳。
42
55
 
@@ -101,8 +114,7 @@ export function setupWzydShare(url: string) {
101
114
  }
102
115
  ```
103
116
 
104
-
105
- ### 2. 类型
117
+ ## 3. 类型
106
118
 
107
119
  ```ts
108
120
  export const SHARE_TYPE_MAP = {
@@ -164,8 +176,7 @@ export interface ShareUIObject {
164
176
  }
165
177
  ```
166
178
 
167
-
168
- ### 3. 内部配置
179
+ ## 4. 内部配置
169
180
 
170
181
  默认分享图片和提示文案等,可通过 `initShare` 参数覆盖。
171
182
 
@@ -181,71 +192,15 @@ export const DEFAULT_TIP_MAP = {
181
192
  };
182
193
  ```
183
194
 
184
- ### 4. 更新日志
195
+ ## 5. 更新日志
185
196
 
186
197
  [点此查看](./CHANGELOG.md)
187
198
 
199
+ ## 6. 制作背景
188
200
 
189
- ### 5. 制作背景
190
-
191
-
192
- #### 5.1. 当前痛点
193
-
194
- 1. 引入了`jsapi`,体积太大,文件太多,可读性、可维护性太差。本来就是非常简单的东西,加载`sdk`、调用全局变量即可,现在变得非常麻烦
195
- 2. 类型缺失,使用、阅读、开发、调试困难
196
- - 多个全局对象 `shareObject`、`shareUiObject` 没有类型
197
- - 分享类别 `shareType` 没有类型,都是`1234`的魔法字符串
198
- - 对外的API,比如 `initShare` 没有类型
199
- 3. 最关键的一点,分享根本不是首屏所需资源,不是必要路径,完全可以异步加载
200
-
201
- 当前 `pmd` 体积:
202
-
203
- <img src="https://mike-1255355338.cos.ap-guangzhou.myqcloud.com/article/2025/3/own_mike_1ee0e93a76cf00acf0.png" width="600">
204
-
205
- 把分享重定向到一个伪文件,即去掉分享后的 `pmd` 体积:
206
-
207
- <img src="https://mike-1255355338.cos.ap-guangzhou.myqcloud.com/article/2025/3/own_mike_43a0c42a4cb653343a.png" width="600">
208
-
209
- 可见分享模块的体积已经达到了 `97.49KB`,亟需优化。
210
-
211
- 光 `jsapi` 就有 `58.34KB`。
212
-
213
- <img src="https://mike-1255355338.cos.ap-guangzhou.myqcloud.com/article/2025/3/own_mike_d45c10acbf304f3975.png" width="600">
214
-
215
-
216
- #### 5.2. 优化思路
217
-
218
- 1. 去掉 `jsapi`
219
- 2. 补充类型提示
220
- 3. 封装异步加载逻辑,业务不关心
221
-
222
- 其他:
223
-
224
- 1. `Toast`, `Dialog` 改为外部传入,方便切换组件库
225
- - `Toast.show` => `showToast`
226
- - `Dialog.confirm` => `showConfirmDialog`
227
- 2. `toast` 和 `dialog` 文案支持自定义
228
- 3. `postGetMiniProgramOpenLink` 改为外部传入,可以充分自定义。传入的时候,就应该封装好参数,`share` 内部不关心。另外,这里真的需要这么做吗,很多业务已经改成明文 `scheme` 了,根本不用传了
229
- 4. `configWx` 改为外部传入,适应任意业务
230
- 5. 支持隐藏任意分享渠道,传入 `hideShareType` 参数即可,并把之前内部的账号判断移出 `share` 核心逻辑
231
- 6. `getEnvVersion` 去掉,没找到需要它的地方
232
- 7. `isTestEnv`,同样去掉
233
-
234
- ### 6. 效果
235
-
236
- 减少 `85KB`。
237
-
238
- 之前:
239
-
240
- <img src="https://mike-1255355338.cos.ap-guangzhou.myqcloud.com/article/2025/3/own_mike_0ce48c3b497a47cc7b.png" width="600">
241
-
242
- 之后:
243
-
244
- <img src="https://mike-1255355338.cos.ap-guangzhou.myqcloud.com/article/2025/3/own_mike_8f266681fa965b8410.png" width="600">
245
-
246
-
201
+ 参考 [分享模块重构](../work/23.share-refactor.html)
247
202
 
248
- ### 7. 其他
203
+ ## 7. 其他
249
204
 
250
205
  更新为异步后,每次修改 `share-light`,需要:
251
206
 
package/lib/config.d.ts CHANGED
@@ -1,4 +1,5 @@
1
- export declare const DEFAULT_SHARE_ICON = "http://ossweb-img.qq.com/images/pmd/igameapp/logo/log_igame_3.0.png";
1
+ export declare const MQQ_SOURCE = "igame_source";
2
+ export declare const DEFAULT_SHARE_ICON = "";
2
3
  export declare const DEFAULT_TIP_MAP: {
3
4
  copyTextSuccess: string;
4
5
  copyTextFail: string;
package/lib/config.js CHANGED
@@ -1 +1 @@
1
- const o="http://ossweb-img.qq.com/images/pmd/igameapp/logo/log_igame_3.0.png",e={copyTextSuccess:"复制链接成功,快去粘贴吧!",copyTextFail:"该浏览器不支持自动复制",dialogTitle:"温馨提示",dialogMessage:"请复制链接到微信或手机QQ内打开参与活动",dialogConfirmButton:"我知道了"};export{o as DEFAULT_SHARE_ICON,e as DEFAULT_TIP_MAP};
1
+ const o="igame_source",e="",i={copyTextSuccess:"复制链接成功,快去粘贴吧!",copyTextFail:"该浏览器不支持自动复制",dialogTitle:"温馨提示",dialogMessage:"请复制链接到微信或手机QQ内打开参与活动",dialogConfirmButton:"我知道了"};export{e as DEFAULT_SHARE_ICON,i as DEFAULT_TIP_MAP,o as MQQ_SOURCE};