@d-matrix/utils 1.2.3 → 1.2.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.
package/dist/clipboard.js CHANGED
@@ -49,33 +49,33 @@ function writeImage(element) {
49
49
  reject('canvas 2d context初始化失败');
50
50
  return;
51
51
  }
52
- // const img = new Image();
52
+ var img = new Image();
53
53
  //浏览器在加载图像时要使用匿名身份验证,以允许跨域资源共享(CORS)。
54
- element.crossOrigin = 'Anonymous';
55
- // img.src = element.src;
56
- // img.onload = () => {
57
- //创建一个画布,赋予画布宽高为图片的原始宽高
58
- canvas.width = element.naturalWidth;
59
- canvas.height = element.naturalHeight;
60
- //防止有缓存,绘制之前先清除画布
61
- ctx.clearRect(0, 0, ctx.canvas.width, ctx.canvas.height);
62
- ctx.drawImage(element, 0, 0);
63
- //将canvas转为blob
64
- canvas.toBlob(function (blob) {
65
- var _a;
66
- if (blob === null) {
67
- reject('canvas to blob失败');
68
- return;
69
- }
70
- navigator.clipboard
71
- .write([
72
- new ClipboardItem((_a = {},
73
- _a[blob.type] = blob,
74
- _a)),
75
- ])
76
- .then(resolve, reject);
77
- });
78
- // };
54
+ img.crossOrigin = 'anonymous';
55
+ img.src = element.src;
56
+ img.onload = function () {
57
+ //创建一个画布,赋予画布宽高为图片的原始宽高
58
+ canvas.width = element.naturalWidth;
59
+ canvas.height = element.naturalHeight;
60
+ //防止有缓存,绘制之前先清除画布
61
+ ctx.clearRect(0, 0, ctx.canvas.width, ctx.canvas.height);
62
+ ctx.drawImage(img, 0, 0);
63
+ //将canvas转为blob
64
+ canvas.toBlob(function (blob) {
65
+ var _a;
66
+ if (blob === null) {
67
+ reject('canvas to blob失败');
68
+ return;
69
+ }
70
+ navigator.clipboard
71
+ .write([
72
+ new ClipboardItem((_a = {},
73
+ _a[blob.type] = blob,
74
+ _a)),
75
+ ])
76
+ .then(resolve, reject);
77
+ });
78
+ };
79
79
  })];
80
80
  });
81
81
  });
package/dist/index.d.ts CHANGED
@@ -2,3 +2,4 @@ export * as clipboard from './clipboard';
2
2
  export * as react from './react';
3
3
  export * as dom from './dom';
4
4
  export * as date from './date';
5
+ export * as types from './types';
package/dist/index.js CHANGED
@@ -19,8 +19,9 @@ var __importStar = (this && this.__importStar) || function (mod) {
19
19
  return result;
20
20
  };
21
21
  Object.defineProperty(exports, "__esModule", { value: true });
22
- exports.date = exports.dom = exports.react = exports.clipboard = void 0;
22
+ exports.types = exports.date = exports.dom = exports.react = exports.clipboard = void 0;
23
23
  exports.clipboard = __importStar(require("./clipboard"));
24
24
  exports.react = __importStar(require("./react"));
25
25
  exports.dom = __importStar(require("./dom"));
26
26
  exports.date = __importStar(require("./date"));
27
+ exports.types = __importStar(require("./types"));
@@ -0,0 +1 @@
1
+ export declare type WithOptional<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
package/dist/types.js ADDED
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@d-matrix/utils",
3
- "version": "1.2.3",
3
+ "version": "1.2.5",
4
4
  "description": "A dozen of utils for Front-End Development",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
package/readme.md CHANGED
@@ -11,6 +11,7 @@ A dozen of utils for Front-End Development
11
11
  - [react](#react)
12
12
  - [dom](#dom)
13
13
  - [date](#date)
14
+ - [types](#types)
14
15
 
15
16
  ### clipboard
16
17
 
@@ -70,6 +71,15 @@ const TestComp = () => {
70
71
 
71
72
  创建`start`和`end`之间的年份数组。
72
73
 
74
+ ### types
75
+
76
+ - `WithOptional<T, K extends keyof T>`
77
+
78
+ ```ts
79
+ type A = { a: number; b: number; c: number; };
80
+ type T0 = WithOptional<A, 'b' | 'c'>; // { a: number; b?: number; c?: number }
81
+ ```
82
+
73
83
  ## 测试
74
84
 
75
85
  运行全部组件测试