@aiszlab/relax 1.0.0-beta.1

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) 2023 aiszlab
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,5 @@
1
+ # relax
2
+ favorite and easy hooks for react
3
+
4
+ ## i alaways like writting many hooks for mine project
5
+ ## so i need a hooks project to support me
package/dist/main.mjs ADDED
@@ -0,0 +1,90 @@
1
+ import * as __WEBPACK_EXTERNAL_MODULE_react__ from "react";
2
+ import * as __WEBPACK_EXTERNAL_MODULE_rxjs__ from "rxjs";
3
+ /******/ // The require scope
4
+ /******/ var __webpack_require__ = {};
5
+ /******/
6
+ /************************************************************************/
7
+ /******/ /* webpack/runtime/define property getters */
8
+ /******/ (() => {
9
+ /******/ // define getter functions for harmony exports
10
+ /******/ __webpack_require__.d = (exports, definition) => {
11
+ /******/ for(var key in definition) {
12
+ /******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
13
+ /******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
14
+ /******/ }
15
+ /******/ }
16
+ /******/ };
17
+ /******/ })();
18
+ /******/
19
+ /******/ /* webpack/runtime/hasOwnProperty shorthand */
20
+ /******/ (() => {
21
+ /******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
22
+ /******/ })();
23
+ /******/
24
+ /************************************************************************/
25
+ var __webpack_exports__ = {};
26
+
27
+ // EXPORTS
28
+ __webpack_require__.d(__webpack_exports__, {
29
+ e: () => (/* reexport */ useImageLoader)
30
+ });
31
+
32
+ ;// CONCATENATED MODULE: external "react"
33
+ var x = y => { var x = {}; __webpack_require__.d(x, y); return x; }
34
+ var y = x => () => x
35
+ const external_react_namespaceObject = x({ ["useEffect"]: () => __WEBPACK_EXTERNAL_MODULE_react__.useEffect, ["useState"]: () => __WEBPACK_EXTERNAL_MODULE_react__.useState });
36
+ ;// CONCATENATED MODULE: external "rxjs"
37
+ var external_rxjs_x = y => { var x = {}; __webpack_require__.d(x, y); return x; }
38
+ var external_rxjs_y = x => () => x
39
+ const external_rxjs_namespaceObject = external_rxjs_x({ ["Subject"]: () => __WEBPACK_EXTERNAL_MODULE_rxjs__.Subject });
40
+ ;// CONCATENATED MODULE: ./src/use-image-loader.ts
41
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
42
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
43
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
44
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
45
+ function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i["return"] && (_r = _i["return"](), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
46
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
47
+
48
+
49
+ var Status = /*#__PURE__*/function (Status) {
50
+ Status["Undo"] = "undo";
51
+ Status["Unload"] = "unload";
52
+ Status["Error"] = "error";
53
+ Status["Loaded"] = "loaded";
54
+ return Status;
55
+ }(Status || {});
56
+ var useImageLoader = function useImageLoader(_ref) {
57
+ var src = _ref.src;
58
+ var _useState = (0,external_react_namespaceObject.useState)(Status.Undo),
59
+ _useState2 = _slicedToArray(_useState, 2),
60
+ status = _useState2[0],
61
+ setStatus = _useState2[1];
62
+ (0,external_react_namespaceObject.useEffect)(function () {
63
+ if (!src) {
64
+ return setStatus(Status.Undo);
65
+ }
66
+ setStatus(Status.Unload);
67
+ var $loader = new external_rxjs_namespaceObject.Subject();
68
+ $loader.subscribe({
69
+ complete: function complete() {
70
+ return setStatus(Status.Loaded);
71
+ },
72
+ error: function error() {
73
+ return setStatus(Status.Error);
74
+ }
75
+ });
76
+ var image = new Image();
77
+ image.addEventListener('load', function () {
78
+ $loader.complete();
79
+ });
80
+ image.addEventListener('error', function () {
81
+ $loader.error(null);
82
+ });
83
+ image.src = src;
84
+ }, [src]);
85
+ return status;
86
+ };
87
+ ;// CONCATENATED MODULE: ./src/index.ts
88
+
89
+ var __webpack_exports__useImageLoader = __webpack_exports__.e;
90
+ export { __webpack_exports__useImageLoader as useImageLoader };
package/package.json ADDED
@@ -0,0 +1,46 @@
1
+ {
2
+ "name": "@aiszlab/relax",
3
+ "version": "1.0.0-beta.1",
4
+ "description": "react utils collection",
5
+ "type": "module",
6
+ "main": "./dist/main.mjs",
7
+ "types": "./typings",
8
+ "scripts": {
9
+ "build": "webpack",
10
+ "clean:build": "rm -rf dist && rm -rf typings",
11
+ "tsc": "tsc"
12
+ },
13
+ "dependencies": {
14
+ "rxjs": "^7.8.1"
15
+ },
16
+ "devDependencies": {
17
+ "@babel/core": "^7.22.5",
18
+ "@babel/preset-env": "^7.22.5",
19
+ "@babel/preset-typescript": "^7.22.5",
20
+ "@types/react": "^18.2.12",
21
+ "@types/react-dom": "^18.2.5",
22
+ "babel-loader": "^9.1.2",
23
+ "fork-ts-checker-webpack-plugin": "^8.0.0",
24
+ "react": "^18.2.0",
25
+ "react-dom": "^18.2.0",
26
+ "typescript": "^5.1.3",
27
+ "webpack": "^5.86.0",
28
+ "webpack-cli": "^5.1.4"
29
+ },
30
+ "peerDependencies": {
31
+ "react": "^18",
32
+ "react-dom": "^18"
33
+ },
34
+ "files": [
35
+ "dist/",
36
+ "typings/"
37
+ ],
38
+ "keywords": [
39
+ "react"
40
+ ],
41
+ "author": "tutu@fantufantu.com",
42
+ "license": "MIT",
43
+ "publishConfig": {
44
+ "access": "public"
45
+ }
46
+ }
@@ -0,0 +1 @@
1
+ export { useImageLoader } from './use-image-loader';
@@ -0,0 +1,11 @@
1
+ declare enum Status {
2
+ Undo = "undo",
3
+ Unload = "unload",
4
+ Error = "error",
5
+ Loaded = "loaded"
6
+ }
7
+ interface Dependencies {
8
+ src: string;
9
+ }
10
+ export declare const useImageLoader: ({ src }: Dependencies) => Status;
11
+ export {};