nextemos 3.6.3 → 3.7.0

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.
@@ -0,0 +1,18 @@
1
+ interface IThumbImage {
2
+ width?: number;
3
+ height?: number;
4
+ path: string;
5
+ quality?: number;
6
+ format?: string;
7
+ options?: {
8
+ service?: string;
9
+ backColor?: string;
10
+ quality?: number;
11
+ customOptions?: string;
12
+ };
13
+ }
14
+ declare const cdn: {
15
+ url: string;
16
+ thumbImage: (props: IThumbImage) => string;
17
+ };
18
+ export default cdn;
@@ -0,0 +1,92 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ // Ortam değişkenlerinden CDN URL'si alınıyor, tanımlı değilse varsayılan olarak 'https://images.proj-e.com' kullanılıyor
4
+ const CDN_URL = process.env.CDN_URL || 'https://images.proj-e.com';
5
+ // Ortam değişkenlerinden CDN sağlayıcısı alınıyor
6
+ const CDN_PROVIDER = process.env.CDN_PROVIDER;
7
+ // CDN işlemleri için kullanılan nesne
8
+ const cdn = {
9
+ // CDN URL'sini döndüren özellik
10
+ url: CDN_URL,
11
+ // Thumbnail URL'si oluşturan fonksiyon
12
+ thumbImage: function (props) {
13
+ switch (CDN_PROVIDER) { // CDN sağlayıcısına göre işlemci fonksiyonunu seçiyor
14
+ case 'huawei':
15
+ return huaweiImageProcessor(props); // Huawei işlemcisi kullanılıyor
16
+ case 'medianova':
17
+ return medianovaImageProcessor(props); // Medianova işlemcisi kullanılıyor
18
+ default:
19
+ return thumborImageProcessor(props); // Varsayılan olarak Thumbor işlemcisi kullanılıyor
20
+ }
21
+ }
22
+ };
23
+ // Değerin geçerli olup olmadığını kontrol eden ve string olarak döndüren yardımcı fonksiyon
24
+ const getValueOrDefault = (value) => (!value || value <= 0) ? "-" : value.toString(); // Geçerli değilse "-" döner, aksi halde değeri string olarak döner
25
+ // Huawei CDN sağlayıcısı için thumbnail URL'si oluşturan fonksiyon
26
+ const huaweiImageProcessor = (props) => {
27
+ var _a, _b, _c, _d, _e, _f;
28
+ // Varsayılan servis türü "mnresize" olarak ayarlanıyor
29
+ let service = "mnresize";
30
+ // Varsayılan genişlik ve yükseklik 0 olarak atanıyor
31
+ const width = (_a = props.width) !== null && _a !== void 0 ? _a : 0;
32
+ const height = (_b = props.height) !== null && _b !== void 0 ? _b : 0;
33
+ // Eğer props içinde servis belirtilmişse, o servis kullanılıyor
34
+ if ((_c = props.options) === null || _c === void 0 ? void 0 : _c.service)
35
+ service = (_d = props.options) === null || _d === void 0 ? void 0 : _d.service;
36
+ // Thumbnail URL'si oluşturmak için bir dizi başlatılıyor
37
+ const thumbUrl = new Array();
38
+ thumbUrl.push(CDN_URL); // CDN URL'si ekleniyor
39
+ thumbUrl.push(service); // Seçilen servis türü ekleniyor
40
+ thumbUrl.push(getValueOrDefault(width)); // Genişlik ekleniyor
41
+ thumbUrl.push(getValueOrDefault(height)); // Yükseklik ekleniyor
42
+ // Eğer arka plan rengi belirtilmişse, o da ekleniyor
43
+ if ((_e = props.options) === null || _e === void 0 ? void 0 : _e.backColor)
44
+ thumbUrl.push((_f = props.options) === null || _f === void 0 ? void 0 : _f.backColor);
45
+ // Görüntü yolu ekleniyor
46
+ thumbUrl.push(props.path);
47
+ // Sonuç olarak oluşturulan URL döndürülüyor
48
+ return thumbUrl.join('/');
49
+ };
50
+ // Medianova CDN sağlayıcısı için thumbnail URL'si oluşturan fonksiyon
51
+ const medianovaImageProcessor = (props) => {
52
+ // Şu an için Huawei işlemcisi ile aynı işlevi görüyor
53
+ return huaweiImageProcessor(props);
54
+ };
55
+ // Thumbor CDN sağlayıcısı için thumbnail URL'si oluşturan fonksiyon
56
+ const thumborImageProcessor = (props) => {
57
+ var _a, _b, _c, _d, _e, _f;
58
+ // Varsayılan hash değeri "unsafe" olarak ayarlanıyor
59
+ let hash = "unsafe";
60
+ // Varsayılan genişlik ve yükseklik 0 olarak atanıyor
61
+ const width = (_a = props.width) !== null && _a !== void 0 ? _a : 0;
62
+ const height = (_b = props.height) !== null && _b !== void 0 ? _b : 0;
63
+ // Thumbnail URL'si oluşturmak için bir dizi başlatılıyor
64
+ const thumbUrl = new Array();
65
+ thumbUrl.push(CDN_URL); // CDN URL'si ekleniyor
66
+ thumbUrl.push(hash); // Hash ekleniyor
67
+ // Genişlik veya yükseklik tanımlıysa, boyutlar ekleniyor
68
+ if (width > 0 || height > 0)
69
+ thumbUrl.push(`${props.width}x${props.height}`);
70
+ // Filtreler için bir dizi başlatılıyor
71
+ const filters = new Array();
72
+ // Kalite tanımlıysa ve 0'dan büyükse, kalite filtresi ekleniyor
73
+ if (((_c = props.options) === null || _c === void 0 ? void 0 : _c.quality) && ((_d = props.options) === null || _d === void 0 ? void 0 : _d.quality) > 0)
74
+ filters.push(`:quality(${props.options.quality})`);
75
+ // Arka plan rengi tanımlıysa, arka plan rengi filtresi ekleniyor
76
+ if ((_e = props.options) === null || _e === void 0 ? void 0 : _e.backColor)
77
+ filters.push(`:background_color(${props.options.backColor})`);
78
+ // Özelleştirilmiş diğer seçenekler tanımlıysa, onlar da ekleniyor
79
+ if ((_f = props.options) === null || _f === void 0 ? void 0 : _f.customOptions)
80
+ filters.push(`:(${props.options.customOptions})`);
81
+ // Filtreler birleştirilerek URL'ye ekleniyor
82
+ thumbUrl.push(filters.join(''));
83
+ // Ortam değişkeninden Thumbor kaynağı alınıyor, eğer tanımlıysa URL'ye ekleniyor
84
+ const source = process.env.THUMBOR_SOURCE || '';
85
+ if (source)
86
+ thumbUrl.push(source);
87
+ // Görüntü yolu ekleniyor
88
+ thumbUrl.push(props.path);
89
+ // Sonuç olarak oluşturulan URL döndürülüyor
90
+ return thumbUrl.join('/');
91
+ };
92
+ exports.default = cdn;
@@ -1,3 +1,4 @@
1
1
  export { default as fetchRequest } from './fetchRequest';
2
2
  export { default as toIntArray } from './toIntArray';
3
3
  export { default as toQueryString } from './toQueryString';
4
+ export { default as cdn } from './cdn';
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.toQueryString = exports.toIntArray = exports.fetchRequest = void 0;
6
+ exports.cdn = exports.toQueryString = exports.toIntArray = exports.fetchRequest = void 0;
7
7
  /// helpers
8
8
  var fetchRequest_1 = require("./fetchRequest");
9
9
  Object.defineProperty(exports, "fetchRequest", { enumerable: true, get: function () { return __importDefault(fetchRequest_1).default; } });
@@ -11,3 +11,5 @@ var toIntArray_1 = require("./toIntArray");
11
11
  Object.defineProperty(exports, "toIntArray", { enumerable: true, get: function () { return __importDefault(toIntArray_1).default; } });
12
12
  var toQueryString_1 = require("./toQueryString");
13
13
  Object.defineProperty(exports, "toQueryString", { enumerable: true, get: function () { return __importDefault(toQueryString_1).default; } });
14
+ var cdn_1 = require("./cdn");
15
+ Object.defineProperty(exports, "cdn", { enumerable: true, get: function () { return __importDefault(cdn_1).default; } });
@@ -1,3 +1,3 @@
1
1
  export { default as useFetch } from './useFetch';
2
2
  export { default as useLocalStorage } from './useLocalStorage';
3
- export { default as useWindowSize } from './useWindowSize';
3
+ export { default as useMediaQuery } from './useMediaQuery';
@@ -3,11 +3,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.useWindowSize = exports.useLocalStorage = exports.useFetch = void 0;
6
+ exports.useMediaQuery = exports.useLocalStorage = exports.useFetch = void 0;
7
7
  /// hooks
8
8
  var useFetch_1 = require("./useFetch");
9
9
  Object.defineProperty(exports, "useFetch", { enumerable: true, get: function () { return __importDefault(useFetch_1).default; } });
10
10
  var useLocalStorage_1 = require("./useLocalStorage");
11
11
  Object.defineProperty(exports, "useLocalStorage", { enumerable: true, get: function () { return __importDefault(useLocalStorage_1).default; } });
12
- var useWindowSize_1 = require("./useWindowSize");
13
- Object.defineProperty(exports, "useWindowSize", { enumerable: true, get: function () { return __importDefault(useWindowSize_1).default; } });
12
+ var useMediaQuery_1 = require("./useMediaQuery");
13
+ Object.defineProperty(exports, "useMediaQuery", { enumerable: true, get: function () { return __importDefault(useMediaQuery_1).default; } });
@@ -0,0 +1,37 @@
1
+ interface IWindowSize {
2
+ width: number;
3
+ height: number;
4
+ }
5
+ /**
6
+ * useMediaQuery Hook
7
+ *
8
+ * @description
9
+ * A custom React hook that listens for the window size and checks if it matches a specified media query.
10
+ *
11
+ * This hook is particularly useful in responsive design scenarios where you need to render different components
12
+ * or apply different styles based on the screen size (e.g., mobile vs desktop).
13
+ *
14
+ * @param {Object} options - The options for the hook.
15
+ * @param {string} options.query - The media query string to be matched (e.g., '(max-width: 960px)').
16
+ * If not provided, it defaults to a common mobile screen width.
17
+ *
18
+ * @returns {Object} An object containing:
19
+ * - `width` (number): The current width of the window.
20
+ * - `height` (number): The current height of the window.
21
+ * - `isMobile` (boolean): Whether the screen matches the provided media query (typically for mobile screens).
22
+ *
23
+ * @example
24
+ * const { width, height, isMobile } = useMediaQuery({ query: '(max-width: 768px)' });
25
+ *
26
+ * if (isMobile) {
27
+ * // Render mobile-specific component or apply mobile-specific styles
28
+ * } else {
29
+ * // Render desktop-specific component or apply desktop-specific styles
30
+ * }
31
+ */
32
+ declare const useMediaQuery: ({ query }?: {
33
+ query?: string;
34
+ }) => IWindowSize & {
35
+ isMobile: boolean;
36
+ };
37
+ export default useMediaQuery;
@@ -0,0 +1,71 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const react_1 = require("react");
4
+ /**
5
+ * useMediaQuery Hook
6
+ *
7
+ * @description
8
+ * A custom React hook that listens for the window size and checks if it matches a specified media query.
9
+ *
10
+ * This hook is particularly useful in responsive design scenarios where you need to render different components
11
+ * or apply different styles based on the screen size (e.g., mobile vs desktop).
12
+ *
13
+ * @param {Object} options - The options for the hook.
14
+ * @param {string} options.query - The media query string to be matched (e.g., '(max-width: 960px)').
15
+ * If not provided, it defaults to a common mobile screen width.
16
+ *
17
+ * @returns {Object} An object containing:
18
+ * - `width` (number): The current width of the window.
19
+ * - `height` (number): The current height of the window.
20
+ * - `isMobile` (boolean): Whether the screen matches the provided media query (typically for mobile screens).
21
+ *
22
+ * @example
23
+ * const { width, height, isMobile } = useMediaQuery({ query: '(max-width: 768px)' });
24
+ *
25
+ * if (isMobile) {
26
+ * // Render mobile-specific component or apply mobile-specific styles
27
+ * } else {
28
+ * // Render desktop-specific component or apply desktop-specific styles
29
+ * }
30
+ */
31
+ const useMediaQuery = ({ query = process.env.NEXT_PUBLIC_MAX_MATCHES || '(max-width: 960px)' } = {}) => {
32
+ const [windowSize, setWindowSize] = (0, react_1.useState)({ width: 0, height: 0 });
33
+ const [isMobile, setIsMobile] = (0, react_1.useState)(false);
34
+ /**
35
+ * handleResize
36
+ *
37
+ * @description
38
+ * Updates the window size state when the window is resized.
39
+ */
40
+ const handleResize = () => {
41
+ const { innerWidth, innerHeight } = window;
42
+ setWindowSize({ width: innerWidth, height: innerHeight });
43
+ };
44
+ /**
45
+ * handleChange
46
+ *
47
+ * @description
48
+ * Updates the isMobile state when the media query status changes.
49
+ */
50
+ const handleChange = (event) => {
51
+ setIsMobile(event.matches);
52
+ };
53
+ (0, react_1.useEffect)(() => {
54
+ if (typeof window !== 'undefined') {
55
+ // Initialize window size and media query match
56
+ handleResize();
57
+ const mediaQuery = window.matchMedia(query);
58
+ setIsMobile(mediaQuery.matches);
59
+ // Add event listeners
60
+ mediaQuery.addEventListener('change', handleChange);
61
+ window.addEventListener('resize', handleResize);
62
+ // Cleanup event listeners on component unmount
63
+ return () => {
64
+ mediaQuery.removeEventListener('change', handleChange);
65
+ window.removeEventListener('resize', handleResize);
66
+ };
67
+ }
68
+ }, [query]);
69
+ return Object.assign(Object.assign({}, windowSize), { isMobile });
70
+ };
71
+ exports.default = useMediaQuery;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nextemos",
3
- "version": "3.6.3",
3
+ "version": "3.7.0",
4
4
  "description": "For helpers and hooks used in NextJS projects",
5
5
  "main": "dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -1,14 +0,0 @@
1
- interface IWindowSize {
2
- width: number;
3
- height: number;
4
- }
5
- /**
6
- * useWindowSize Hook
7
- *
8
- * @description
9
- * A custom React hook that listens for the window size and returns it.
10
- *
11
- * @returns {Object} An object containing the width and height of the window window.
12
- */
13
- declare const useWindowSize: () => IWindowSize;
14
- export default useWindowSize;
@@ -1,52 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const react_1 = require("react");
4
- /**
5
- * useWindowSize Hook
6
- *
7
- * @description
8
- * A custom React hook that listens for the window size and returns it.
9
- *
10
- * @returns {Object} An object containing the width and height of the window window.
11
- */
12
- const useWindowSize = () => {
13
- const [windowSize, setWindowSize] = (0, react_1.useState)({
14
- width: 0,
15
- height: 0,
16
- });
17
- /**
18
- * handleResize
19
- *
20
- * @description
21
- * A function to update the window size state when the window is resized.
22
- */
23
- const handleResize = () => {
24
- setWindowSize({
25
- width: window.innerWidth,
26
- height: window.innerHeight,
27
- });
28
- };
29
- /**
30
- * useEffect Hook
31
- *
32
- * @description
33
- * A React hook that is used for side-effects in functional components.
34
- *
35
- * @params {Function} () => {} A callback function that contains the side-effect logic.
36
- * @params {Array} [] An array of dependencies. When empty, it means the useEffect runs once after the initial render.
37
- */
38
- (0, react_1.useEffect)(() => {
39
- if (typeof window !== 'undefined') {
40
- setWindowSize({
41
- width: window.innerWidth,
42
- height: window.innerHeight,
43
- });
44
- window.addEventListener('resize', handleResize);
45
- return () => {
46
- window.removeEventListener('resize', handleResize);
47
- };
48
- }
49
- }, []);
50
- return windowSize;
51
- };
52
- exports.default = useWindowSize;