@bouzu/shared 0.0.1 → 0.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,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) zhong666 <hi@zhong666.me> and bouzu contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,57 @@
1
+ # @bouzu/shared
2
+
3
+ [![npm version][npm-version-src]][npm-version-href]
4
+ [![npm downloads][npm-downloads-src]][npm-downloads-href]
5
+ [![bundle][bundle-src]][bundle-href]
6
+ [![JSDocs][jsdocs-src]][jsdocs-href]
7
+
8
+ ## Usage
9
+
10
+ Install package:
11
+
12
+ ```sh
13
+ # npm
14
+ npm install @bouzu/shared
15
+
16
+ # yarn
17
+ yarn add @bouzu/shared
18
+
19
+ # pnpm
20
+ pnpm install @bouzu/shared
21
+ ```
22
+
23
+ Import:
24
+
25
+ ```js
26
+ // ESM
27
+ import * as shared from '@bouzu/shared'
28
+
29
+ // CommonJS
30
+ const shared = require('@bouzu/shared')
31
+ ```
32
+
33
+ ## Development
34
+
35
+ - Clone this repository
36
+ - Install latest LTS version of [Node.js](https://nodejs.org/en/)
37
+ - Enable [Corepack](https://github.com/nodejs/corepack) using `corepack enable`
38
+ - Install dependencies using `pnpm install`
39
+ - Run interactive tests using `pnpm dev`
40
+
41
+ ## License
42
+
43
+ Made with 💛
44
+
45
+ Published under [MIT License](./LICENSE).
46
+
47
+
48
+ <!-- Badges -->
49
+
50
+ [npm-version-src]: https://img.shields.io/npm/v/@bouzu/shared?style=flat&colorA=18181B&colorB=F0DB4F
51
+ [npm-version-href]: https://npmjs.com/package/@bouzu/shared
52
+ [npm-downloads-src]: https://img.shields.io/npm/dm/@bouzu/shared?style=flat&colorA=18181B&colorB=F0DB4F
53
+ [npm-downloads-href]: https://npmjs.com/package/@bouzu/shared
54
+ [bundle-src]: https://img.shields.io/bundlephobia/minzip/@bouzu/shared?style=flat&colorA=18181B&colorB=F0DB4F
55
+ [bundle-href]: https://bundlephobia.com/result?p=@bouzu/shared
56
+ [jsdocs-src]: https://img.shields.io/badge/jsDocs.io-reference-18181B?style=flat&colorA=18181B&colorB=F0DB4F
57
+ [jsdocs-href]: https://www.jsdocs.io/package/@bouzu/shared
package/dist/index.cjs CHANGED
@@ -54,13 +54,12 @@ function checkSizeEqual(a, b) {
54
54
  return a.width === b.width && a.height === b.height;
55
55
  }
56
56
 
57
- var RectCorner = /* @__PURE__ */ ((RectCorner2) => {
58
- RectCorner2["TopLeft"] = "TopLeft";
59
- RectCorner2["TopRight"] = "TopRight";
60
- RectCorner2["BottomLeft"] = "BottomLeft";
61
- RectCorner2["BottomRight"] = "BottomRight";
62
- return RectCorner2;
63
- })(RectCorner || {});
57
+ const RectCorner = {
58
+ TopLeft: "TopLeft",
59
+ TopRight: "TopRight",
60
+ BottomLeft: "BottomLeft",
61
+ BottomRight: "BottomRight"
62
+ };
64
63
  function createRect(x = 0, y = 0, width = 0, height = 0) {
65
64
  return {
66
65
  ...createPoint(x, y),
@@ -93,13 +92,13 @@ function getRectBottomRight(rect) {
93
92
  }
94
93
  function getRectPointByRectCorner(rect, corner) {
95
94
  switch (corner) {
96
- case "TopLeft" /* TopLeft */:
95
+ case RectCorner.TopLeft:
97
96
  return getRectTopLeft(rect);
98
- case "TopRight" /* TopRight */:
97
+ case RectCorner.TopRight:
99
98
  return getRectTopRight(rect);
100
- case "BottomLeft" /* BottomLeft */:
99
+ case RectCorner.BottomLeft:
101
100
  return getRectBottomLeft(rect);
102
- case "BottomRight" /* BottomRight */:
101
+ case RectCorner.BottomRight:
103
102
  return getRectBottomRight(rect);
104
103
  default:
105
104
  throw new TypeError(`Not match corner: ${corner}`);
@@ -147,6 +146,10 @@ function toPoint(rect) {
147
146
  return createPoint(rect.x, rect.y);
148
147
  }
149
148
 
149
+ function isObject(val) {
150
+ return Object.prototype.toString.call(val) === "[object Object]";
151
+ }
152
+
150
153
  exports.RectCorner = RectCorner;
151
154
  exports.checkLayoutInvalidate = checkLayoutInvalidate;
152
155
  exports.checkPointEqual = checkPointEqual;
@@ -174,6 +177,7 @@ exports.getRectMaxY = getRectMaxY;
174
177
  exports.getRectPointByRectCorner = getRectPointByRectCorner;
175
178
  exports.getRectTopLeft = getRectTopLeft;
176
179
  exports.getRectTopRight = getRectTopRight;
180
+ exports.isObject = isObject;
177
181
  exports.noop = noop;
178
182
  exports.toPoint = toPoint;
179
183
  exports.toSize = toSize;
@@ -0,0 +1,65 @@
1
+ import { ValueOf } from 'type-fest';
2
+
3
+ declare function noop(): void;
4
+
5
+ type Previous<T> = [
6
+ {
7
+ readonly curr: T | undefined;
8
+ readonly prev: T | undefined;
9
+ },
10
+ (val: T) => void
11
+ ];
12
+ declare function usePrevious<T>(val?: T): Previous<T>;
13
+
14
+ type WithoutFirstParameter<T> = T extends (arg1: any, ...args: infer U) => any ? U : any;
15
+ declare function execLastTick<TTickFn extends typeof setTimeout | typeof queueMicrotask | typeof requestAnimationFrame, TFn extends (...args: any) => any>(tickFn: TTickFn, fn: TFn, ...tickFnArgs: WithoutFirstParameter<TTickFn>): (...args: Parameters<TFn>) => void;
16
+
17
+ interface Point {
18
+ x: number;
19
+ y: number;
20
+ }
21
+ declare function createPoint(x?: number, y?: number): Point;
22
+ declare function checkPointOrigin(p: Point): boolean;
23
+ declare function checkPointEqual(a: Point, b: Point): boolean;
24
+
25
+ interface Size {
26
+ width: number;
27
+ height: number;
28
+ }
29
+ declare function createSize(width?: number, height?: number): Size;
30
+ declare function checkSizeEqual(a: Size, b: Size): boolean;
31
+
32
+ type Rect = Size & Point;
33
+ declare const RectCorner: {
34
+ readonly TopLeft: "TopLeft";
35
+ readonly TopRight: "TopRight";
36
+ readonly BottomLeft: "BottomLeft";
37
+ readonly BottomRight: "BottomRight";
38
+ };
39
+ type RectCornerValue = ValueOf<typeof RectCorner>;
40
+ declare function createRect(x?: number, y?: number, width?: number, height?: number): Rect;
41
+ declare function cloneRect(rect: Rect): Rect;
42
+ declare function getRectMaxX(rect: Rect): number;
43
+ declare function getRectMaxY(rect: Rect): number;
44
+ declare function getRectArea(rect: Rect): number;
45
+ declare function getRectTopLeft(rect: Rect): Point;
46
+ declare function getRectTopRight(rect: Rect): Point;
47
+ declare function getRectBottomLeft(rect: Rect): Point;
48
+ declare function getRectBottomRight(rect: Rect): Point;
49
+ declare function getRectPointByRectCorner(rect: Rect, corner: RectCornerValue): Point;
50
+ declare function checkRectIntersectsX(a: Rect, b: Rect): boolean;
51
+ declare function checkRectIntersectsY(a: Rect, b: Rect): boolean;
52
+ declare function checkRectIntersects(a: Rect, b: Rect): boolean;
53
+ declare function checkRectContains(a: Rect, b: Rect): boolean;
54
+ declare function checkRectContainsPoint(a: Rect, p: Point): boolean;
55
+ declare function getRectCornerInOther(a: Rect, b: Rect): RectCornerValue | null;
56
+ declare function checkRectEqual(a: Rect, b: Rect): boolean;
57
+ declare function checkRectEqualPoint(r: Rect, p: Point | Rect): boolean;
58
+ declare function checkRectEqualSize(r: Rect, s: Size | Rect): boolean;
59
+ declare function checkLayoutInvalidate(newRect: Rect, oldRect: Rect): boolean;
60
+ declare function toSize(rect: Rect): Size;
61
+ declare function toPoint(rect: Rect): Point;
62
+
63
+ declare function isObject(val: unknown): val is Record<PropertyKey, any>;
64
+
65
+ export { type Point, type Previous, type Rect, RectCorner, type RectCornerValue, type Size, checkLayoutInvalidate, checkPointEqual, checkPointOrigin, checkRectContains, checkRectContainsPoint, checkRectEqual, checkRectEqualPoint, checkRectEqualSize, checkRectIntersects, checkRectIntersectsX, checkRectIntersectsY, checkSizeEqual, cloneRect, createPoint, createRect, createSize, execLastTick, getRectArea, getRectBottomLeft, getRectBottomRight, getRectCornerInOther, getRectMaxX, getRectMaxY, getRectPointByRectCorner, getRectTopLeft, getRectTopRight, isObject, noop, toPoint, toSize, usePrevious };
@@ -0,0 +1,65 @@
1
+ import { ValueOf } from 'type-fest';
2
+
3
+ declare function noop(): void;
4
+
5
+ type Previous<T> = [
6
+ {
7
+ readonly curr: T | undefined;
8
+ readonly prev: T | undefined;
9
+ },
10
+ (val: T) => void
11
+ ];
12
+ declare function usePrevious<T>(val?: T): Previous<T>;
13
+
14
+ type WithoutFirstParameter<T> = T extends (arg1: any, ...args: infer U) => any ? U : any;
15
+ declare function execLastTick<TTickFn extends typeof setTimeout | typeof queueMicrotask | typeof requestAnimationFrame, TFn extends (...args: any) => any>(tickFn: TTickFn, fn: TFn, ...tickFnArgs: WithoutFirstParameter<TTickFn>): (...args: Parameters<TFn>) => void;
16
+
17
+ interface Point {
18
+ x: number;
19
+ y: number;
20
+ }
21
+ declare function createPoint(x?: number, y?: number): Point;
22
+ declare function checkPointOrigin(p: Point): boolean;
23
+ declare function checkPointEqual(a: Point, b: Point): boolean;
24
+
25
+ interface Size {
26
+ width: number;
27
+ height: number;
28
+ }
29
+ declare function createSize(width?: number, height?: number): Size;
30
+ declare function checkSizeEqual(a: Size, b: Size): boolean;
31
+
32
+ type Rect = Size & Point;
33
+ declare const RectCorner: {
34
+ readonly TopLeft: "TopLeft";
35
+ readonly TopRight: "TopRight";
36
+ readonly BottomLeft: "BottomLeft";
37
+ readonly BottomRight: "BottomRight";
38
+ };
39
+ type RectCornerValue = ValueOf<typeof RectCorner>;
40
+ declare function createRect(x?: number, y?: number, width?: number, height?: number): Rect;
41
+ declare function cloneRect(rect: Rect): Rect;
42
+ declare function getRectMaxX(rect: Rect): number;
43
+ declare function getRectMaxY(rect: Rect): number;
44
+ declare function getRectArea(rect: Rect): number;
45
+ declare function getRectTopLeft(rect: Rect): Point;
46
+ declare function getRectTopRight(rect: Rect): Point;
47
+ declare function getRectBottomLeft(rect: Rect): Point;
48
+ declare function getRectBottomRight(rect: Rect): Point;
49
+ declare function getRectPointByRectCorner(rect: Rect, corner: RectCornerValue): Point;
50
+ declare function checkRectIntersectsX(a: Rect, b: Rect): boolean;
51
+ declare function checkRectIntersectsY(a: Rect, b: Rect): boolean;
52
+ declare function checkRectIntersects(a: Rect, b: Rect): boolean;
53
+ declare function checkRectContains(a: Rect, b: Rect): boolean;
54
+ declare function checkRectContainsPoint(a: Rect, p: Point): boolean;
55
+ declare function getRectCornerInOther(a: Rect, b: Rect): RectCornerValue | null;
56
+ declare function checkRectEqual(a: Rect, b: Rect): boolean;
57
+ declare function checkRectEqualPoint(r: Rect, p: Point | Rect): boolean;
58
+ declare function checkRectEqualSize(r: Rect, s: Size | Rect): boolean;
59
+ declare function checkLayoutInvalidate(newRect: Rect, oldRect: Rect): boolean;
60
+ declare function toSize(rect: Rect): Size;
61
+ declare function toPoint(rect: Rect): Point;
62
+
63
+ declare function isObject(val: unknown): val is Record<PropertyKey, any>;
64
+
65
+ export { type Point, type Previous, type Rect, RectCorner, type RectCornerValue, type Size, checkLayoutInvalidate, checkPointEqual, checkPointOrigin, checkRectContains, checkRectContainsPoint, checkRectEqual, checkRectEqualPoint, checkRectEqualSize, checkRectIntersects, checkRectIntersectsX, checkRectIntersectsY, checkSizeEqual, cloneRect, createPoint, createRect, createSize, execLastTick, getRectArea, getRectBottomLeft, getRectBottomRight, getRectCornerInOther, getRectMaxX, getRectMaxY, getRectPointByRectCorner, getRectTopLeft, getRectTopRight, isObject, noop, toPoint, toSize, usePrevious };
package/dist/index.d.ts CHANGED
@@ -1,3 +1,5 @@
1
+ import { ValueOf } from 'type-fest';
2
+
1
3
  declare function noop(): void;
2
4
 
3
5
  type Previous<T> = [
@@ -28,12 +30,13 @@ declare function createSize(width?: number, height?: number): Size;
28
30
  declare function checkSizeEqual(a: Size, b: Size): boolean;
29
31
 
30
32
  type Rect = Size & Point;
31
- declare enum RectCorner {
32
- TopLeft = "TopLeft",
33
- TopRight = "TopRight",
34
- BottomLeft = "BottomLeft",
35
- BottomRight = "BottomRight"
36
- }
33
+ declare const RectCorner: {
34
+ readonly TopLeft: "TopLeft";
35
+ readonly TopRight: "TopRight";
36
+ readonly BottomLeft: "BottomLeft";
37
+ readonly BottomRight: "BottomRight";
38
+ };
39
+ type RectCornerValue = ValueOf<typeof RectCorner>;
37
40
  declare function createRect(x?: number, y?: number, width?: number, height?: number): Rect;
38
41
  declare function cloneRect(rect: Rect): Rect;
39
42
  declare function getRectMaxX(rect: Rect): number;
@@ -43,13 +46,13 @@ declare function getRectTopLeft(rect: Rect): Point;
43
46
  declare function getRectTopRight(rect: Rect): Point;
44
47
  declare function getRectBottomLeft(rect: Rect): Point;
45
48
  declare function getRectBottomRight(rect: Rect): Point;
46
- declare function getRectPointByRectCorner(rect: Rect, corner: RectCorner): Point;
49
+ declare function getRectPointByRectCorner(rect: Rect, corner: RectCornerValue): Point;
47
50
  declare function checkRectIntersectsX(a: Rect, b: Rect): boolean;
48
51
  declare function checkRectIntersectsY(a: Rect, b: Rect): boolean;
49
52
  declare function checkRectIntersects(a: Rect, b: Rect): boolean;
50
53
  declare function checkRectContains(a: Rect, b: Rect): boolean;
51
54
  declare function checkRectContainsPoint(a: Rect, p: Point): boolean;
52
- declare function getRectCornerInOther(a: Rect, b: Rect): RectCorner | null;
55
+ declare function getRectCornerInOther(a: Rect, b: Rect): RectCornerValue | null;
53
56
  declare function checkRectEqual(a: Rect, b: Rect): boolean;
54
57
  declare function checkRectEqualPoint(r: Rect, p: Point | Rect): boolean;
55
58
  declare function checkRectEqualSize(r: Rect, s: Size | Rect): boolean;
@@ -57,4 +60,6 @@ declare function checkLayoutInvalidate(newRect: Rect, oldRect: Rect): boolean;
57
60
  declare function toSize(rect: Rect): Size;
58
61
  declare function toPoint(rect: Rect): Point;
59
62
 
60
- export { Point, Previous, Rect, RectCorner, Size, checkLayoutInvalidate, checkPointEqual, checkPointOrigin, checkRectContains, checkRectContainsPoint, checkRectEqual, checkRectEqualPoint, checkRectEqualSize, checkRectIntersects, checkRectIntersectsX, checkRectIntersectsY, checkSizeEqual, cloneRect, createPoint, createRect, createSize, execLastTick, getRectArea, getRectBottomLeft, getRectBottomRight, getRectCornerInOther, getRectMaxX, getRectMaxY, getRectPointByRectCorner, getRectTopLeft, getRectTopRight, noop, toPoint, toSize, usePrevious };
63
+ declare function isObject(val: unknown): val is Record<PropertyKey, any>;
64
+
65
+ export { type Point, type Previous, type Rect, RectCorner, type RectCornerValue, type Size, checkLayoutInvalidate, checkPointEqual, checkPointOrigin, checkRectContains, checkRectContainsPoint, checkRectEqual, checkRectEqualPoint, checkRectEqualSize, checkRectIntersects, checkRectIntersectsX, checkRectIntersectsY, checkSizeEqual, cloneRect, createPoint, createRect, createSize, execLastTick, getRectArea, getRectBottomLeft, getRectBottomRight, getRectCornerInOther, getRectMaxX, getRectMaxY, getRectPointByRectCorner, getRectTopLeft, getRectTopRight, isObject, noop, toPoint, toSize, usePrevious };
package/dist/index.mjs CHANGED
@@ -52,13 +52,12 @@ function checkSizeEqual(a, b) {
52
52
  return a.width === b.width && a.height === b.height;
53
53
  }
54
54
 
55
- var RectCorner = /* @__PURE__ */ ((RectCorner2) => {
56
- RectCorner2["TopLeft"] = "TopLeft";
57
- RectCorner2["TopRight"] = "TopRight";
58
- RectCorner2["BottomLeft"] = "BottomLeft";
59
- RectCorner2["BottomRight"] = "BottomRight";
60
- return RectCorner2;
61
- })(RectCorner || {});
55
+ const RectCorner = {
56
+ TopLeft: "TopLeft",
57
+ TopRight: "TopRight",
58
+ BottomLeft: "BottomLeft",
59
+ BottomRight: "BottomRight"
60
+ };
62
61
  function createRect(x = 0, y = 0, width = 0, height = 0) {
63
62
  return {
64
63
  ...createPoint(x, y),
@@ -91,13 +90,13 @@ function getRectBottomRight(rect) {
91
90
  }
92
91
  function getRectPointByRectCorner(rect, corner) {
93
92
  switch (corner) {
94
- case "TopLeft" /* TopLeft */:
93
+ case RectCorner.TopLeft:
95
94
  return getRectTopLeft(rect);
96
- case "TopRight" /* TopRight */:
95
+ case RectCorner.TopRight:
97
96
  return getRectTopRight(rect);
98
- case "BottomLeft" /* BottomLeft */:
97
+ case RectCorner.BottomLeft:
99
98
  return getRectBottomLeft(rect);
100
- case "BottomRight" /* BottomRight */:
99
+ case RectCorner.BottomRight:
101
100
  return getRectBottomRight(rect);
102
101
  default:
103
102
  throw new TypeError(`Not match corner: ${corner}`);
@@ -145,4 +144,8 @@ function toPoint(rect) {
145
144
  return createPoint(rect.x, rect.y);
146
145
  }
147
146
 
148
- export { RectCorner, checkLayoutInvalidate, checkPointEqual, checkPointOrigin, checkRectContains, checkRectContainsPoint, checkRectEqual, checkRectEqualPoint, checkRectEqualSize, checkRectIntersects, checkRectIntersectsX, checkRectIntersectsY, checkSizeEqual, cloneRect, createPoint, createRect, createSize, execLastTick, getRectArea, getRectBottomLeft, getRectBottomRight, getRectCornerInOther, getRectMaxX, getRectMaxY, getRectPointByRectCorner, getRectTopLeft, getRectTopRight, noop, toPoint, toSize, usePrevious };
147
+ function isObject(val) {
148
+ return Object.prototype.toString.call(val) === "[object Object]";
149
+ }
150
+
151
+ export { RectCorner, checkLayoutInvalidate, checkPointEqual, checkPointOrigin, checkRectContains, checkRectContainsPoint, checkRectEqual, checkRectEqualPoint, checkRectEqualSize, checkRectIntersects, checkRectIntersectsX, checkRectIntersectsY, checkSizeEqual, cloneRect, createPoint, createRect, createSize, execLastTick, getRectArea, getRectBottomLeft, getRectBottomRight, getRectCornerInOther, getRectMaxX, getRectMaxY, getRectPointByRectCorner, getRectTopLeft, getRectTopRight, isObject, noop, toPoint, toSize, usePrevious };
package/package.json CHANGED
@@ -1,15 +1,23 @@
1
1
  {
2
2
  "name": "@bouzu/shared",
3
- "version": "0.0.1",
3
+ "version": "0.0.2",
4
4
  "private": false,
5
5
  "author": "zhong666 <hi@zhong666.me>",
6
6
  "license": "MIT",
7
+ "homepage": "https://bouzu.zhong666.me",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "https://github.com/aa900031/bouzu"
11
+ },
12
+ "bugs": {
13
+ "url": "https://github.com/aa900031/bouzu/issues"
14
+ },
7
15
  "sideEffects": false,
8
16
  "exports": {
9
17
  ".": {
10
18
  "types": "./dist/index.d.ts",
11
- "require": "./dist/index.cjs",
12
- "import": "./dist/index.mjs"
19
+ "import": "./dist/index.mjs",
20
+ "require": "./dist/index.cjs"
13
21
  }
14
22
  },
15
23
  "main": "./dist/index.cjs",
@@ -21,7 +29,15 @@
21
29
  "publishConfig": {
22
30
  "access": "public"
23
31
  },
32
+ "dependencies": {
33
+ "type-fest": "^3.13.1"
34
+ },
35
+ "devDependencies": {
36
+ "@bouzu/release-it-config": "0.1.0",
37
+ "@bouzu/tsconfig": "0.1.0"
38
+ },
24
39
  "scripts": {
25
- "build": "unbuild"
40
+ "build": "unbuild",
41
+ "release": "release-it --ci"
26
42
  }
27
43
  }