clxx 2.0.8 → 2.1.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/README.md CHANGED
@@ -1,2 +1,35 @@
1
- # v2.0.0
1
+ # v2.0.8
2
2
 
3
+ ## 功能函数
4
+
5
+ - [`ago`](./src/Ago/index.tsx):显示多久以前
6
+ - [`calendarTable`](./src/utils/calendarTable.ts):创建一个月历视图的原始数据表
7
+ - [`Countdown`](./src/utils/Countdown.ts):倒计时器,最大可以到天
8
+ - [`createApp`](./src/utils/createApp.tsx):创建一个带路由的 APP 对象,这是个非常实用的功能函数
9
+ - [`defaultScroll`](./src/utils/defaultScroll.ts):禁用和启用默认滚动
10
+ - [`createPortalDOM`](./src/utils/dom.tsx):任意位置创建一个 DOM 节点,用来挂载和卸载 React 组件
11
+ - [`is`](./src/utils/is.ts):一些简单的环境判断
12
+ - [`jsonp`](./src/utils/jsonp.ts):发送一个 jsonp 请求
13
+ - [`GET,POST`](./src/utils/request.ts):ajax 请求的简单封装
14
+ - [`Tick`](./src/utils/tick.ts):嘀嗒器,每帧都会执行
15
+ - [`uniqKey`](./src/utils/uniqKey.ts):生成一个全局唯一的 key
16
+ - [`waitUntil`](./src/utils/wait.ts):执行某种检测,直接条件为真或者超时才返回
17
+
18
+ ## 基础组件
19
+
20
+ - [`<Ago>`](./src/Ago/index.tsx):显示多久以前
21
+ - [`<AutoGrid>`](./src/AutoGrid/index.tsx):里面的对象会自动网格排列
22
+ - [`<CarouselNotice>`](./src/CarouselNotice/index.tsx):滚动走马灯
23
+ - [`<Clickable>`](./src/Clickable/index.tsx):一个可点击的对象
24
+ - [`<Container>`](./src/Container/index.tsx):这是一个全局容器,主要设置移动端环境,自适应等逻辑
25
+ - [`<Countdowner>`](./src/Countdowner/index.tsx):倒计时器
26
+ - [`<Row>|<RowStart>|<RowEnd>|<RowBetween>|<RowCenter>|<RowAround>|<RowEvenly>`](./src/Flex/Row.tsx):水平弹性布局
27
+ - [`<Col>|<ColStart>|<ColEnd>|<ColBetween>|<ColCenter>|<ColAround>|<ColEvenly>`](./src/Flex/Col.tsx):垂直弹性布局
28
+ - [`<Indicator>`](./src/Indicator/index.tsx):转动的菊花,用来作为Loading组件的一部分
29
+ - [`<Overlay>`](./src/Overlay/index.tsx):一个全屏覆盖框,会覆盖可操作区域
30
+ - [`<SafeArea>`](./src/SafeArea/index.tsx):这个组件会自动剔除手机的非操作区域
31
+ - [`<ScrollView>`](./src/ScrollView/index.tsx):滚动容器,自带原生滚动条
32
+ - [`showDialog`](./src/Dialog/index.tsx):函数式调用,显示一个弹框组件
33
+ - [`showAlert`](./src/Alert/index.tsx):函数式调用,模拟`window.alert`,但UI可定制
34
+ - [`showToast|showUniqToast`](./src/Toast/index.tsx):函数式调用,显示一个Toast组件
35
+ - [`showLoading|showLoadingAtLeast`](./src/Loading/index.tsx):函数式调用,显示一个Loading组件
@@ -1,5 +1,5 @@
1
- import { Tick } from "../utils/tick";
2
- import { useEffect, useRef } from "react";
1
+ import { tick } from '../utils/tick';
2
+ import { useEffect, useRef } from 'react';
3
3
  /**
4
4
  * 逐帧执行的ticker
5
5
  * @param frame 帧函数
@@ -9,8 +9,7 @@ export function useTick(frame) {
9
9
  const framer = useRef(frame);
10
10
  framer.current = frame;
11
11
  useEffect(() => {
12
- const tick = new Tick(() => framer.current());
13
- tick.start();
14
- return () => tick.destroy();
12
+ const stop = tick(() => framer.current());
13
+ return () => stop();
15
14
  }, []);
16
15
  }
package/build/index.d.ts CHANGED
@@ -1,32 +1,32 @@
1
- export { Tick } from "./utils/tick";
2
- export { setContextValue, getContextValue } from "./context";
3
- export { jsonp } from "./utils/jsonp";
4
- export { uniqKey } from "./utils/uniqKey";
5
- export { ago } from "./utils/ago";
6
- export { GET, POST, sendJSON, sugarSend, sendRequest, buildUrlByOption, registerHostAlias } from "./utils/request";
7
- export { calendarTable } from "./utils/calendarTable";
8
- export { Countdown } from "./utils/Countdown";
9
- export { defaultScroll } from "./utils/defaultScroll";
10
- export { is } from "./utils/is";
11
- export { waitFor, waitUntil } from "./utils/wait";
12
- export { normalizeUnit, splitValue } from "./utils/cssUtil";
13
- export { createApp, history, getHistory } from "./utils/createApp";
14
- export { useInterval } from "./Effect/useInterval";
15
- export { useTick } from "./Effect/useTick";
16
- export { Ago } from "./Ago";
17
- export { Container } from "./Container";
18
- export { Flex, FlexItem } from "./Flex";
19
- export { Row, RowAround, RowBetween, RowCenter, RowEnd, RowEvenly, RowStart } from "./Flex/Row";
20
- export { Col, ColAround, ColBetween, ColCenter, ColEnd, ColEvenly, ColStart } from "./Flex/Col";
21
- export { Countdowner } from "./Countdowner";
22
- export { Overlay } from "./Overlay";
23
- export { showToast, showUniqToast } from "./Toast";
24
- export { showDialog } from "./Dialog";
25
- export { Clickable } from "./Clickable";
26
- export { Indicator } from "./Indicator";
27
- export { showLoading, showLoadingAtLeast } from "./Loading";
28
- export { SafeArea } from "./SafeArea";
29
- export { AutoGrid } from "./AutoGrid";
30
- export { showAlert } from "./Alert";
31
- export { ScrollView } from "./ScrollView";
32
- export { CarouselNotice } from "./CarouselNotice";
1
+ export { tick } from './utils/tick';
2
+ export { setContextValue, getContextValue } from './context';
3
+ export { jsonp } from './utils/jsonp';
4
+ export { uniqKey } from './utils/uniqKey';
5
+ export { ago } from './utils/ago';
6
+ export { GET, POST, sendJSON, sugarSend, sendRequest, buildUrlByOption, registerHostAlias, } from './utils/request';
7
+ export { calendarTable } from './utils/calendarTable';
8
+ export { Countdown } from './utils/Countdown';
9
+ export { defaultScroll } from './utils/defaultScroll';
10
+ export { is } from './utils/is';
11
+ export { waitFor, waitUntil } from './utils/wait';
12
+ export { normalizeUnit, splitValue, adaptive } from './utils/cssUtil';
13
+ export { createApp, history, getHistory } from './utils/createApp';
14
+ export { useInterval } from './Effect/useInterval';
15
+ export { useTick } from './Effect/useTick';
16
+ export { Ago } from './Ago';
17
+ export { Container } from './Container';
18
+ export { Flex, FlexItem } from './Flex';
19
+ export { Row, RowAround, RowBetween, RowCenter, RowEnd, RowEvenly, RowStart, } from './Flex/Row';
20
+ export { Col, ColAround, ColBetween, ColCenter, ColEnd, ColEvenly, ColStart, } from './Flex/Col';
21
+ export { Countdowner } from './Countdowner';
22
+ export { Overlay } from './Overlay';
23
+ export { showToast, showUniqToast } from './Toast';
24
+ export { showDialog } from './Dialog';
25
+ export { Clickable } from './Clickable';
26
+ export { Indicator } from './Indicator';
27
+ export { showLoading, showLoadingAtLeast } from './Loading';
28
+ export { SafeArea } from './SafeArea';
29
+ export { AutoGrid } from './AutoGrid';
30
+ export { showAlert } from './Alert';
31
+ export { ScrollView } from './ScrollView';
32
+ export { CarouselNotice } from './CarouselNotice';
package/build/index.js CHANGED
@@ -1,32 +1,32 @@
1
- export { Tick } from "./utils/tick";
2
- export { setContextValue, getContextValue } from "./context";
3
- export { jsonp } from "./utils/jsonp";
4
- export { uniqKey } from "./utils/uniqKey";
5
- export { ago } from "./utils/ago";
6
- export { GET, POST, sendJSON, sugarSend, sendRequest, buildUrlByOption, registerHostAlias } from "./utils/request";
7
- export { calendarTable } from "./utils/calendarTable";
8
- export { Countdown } from "./utils/Countdown";
9
- export { defaultScroll } from "./utils/defaultScroll";
10
- export { is } from "./utils/is";
11
- export { waitFor, waitUntil } from "./utils/wait";
12
- export { normalizeUnit, splitValue } from "./utils/cssUtil";
13
- export { createApp, history, getHistory } from "./utils/createApp";
14
- export { useInterval } from "./Effect/useInterval";
15
- export { useTick } from "./Effect/useTick";
16
- export { Ago } from "./Ago";
17
- export { Container } from "./Container";
18
- export { Flex, FlexItem } from "./Flex";
19
- export { Row, RowAround, RowBetween, RowCenter, RowEnd, RowEvenly, RowStart } from "./Flex/Row";
20
- export { Col, ColAround, ColBetween, ColCenter, ColEnd, ColEvenly, ColStart } from "./Flex/Col";
21
- export { Countdowner } from "./Countdowner";
22
- export { Overlay } from "./Overlay";
23
- export { showToast, showUniqToast } from "./Toast";
24
- export { showDialog } from "./Dialog";
25
- export { Clickable } from "./Clickable";
26
- export { Indicator } from "./Indicator";
27
- export { showLoading, showLoadingAtLeast } from "./Loading";
28
- export { SafeArea } from "./SafeArea";
29
- export { AutoGrid } from "./AutoGrid";
30
- export { showAlert } from "./Alert";
31
- export { ScrollView } from "./ScrollView";
32
- export { CarouselNotice } from "./CarouselNotice";
1
+ export { tick } from './utils/tick';
2
+ export { setContextValue, getContextValue } from './context';
3
+ export { jsonp } from './utils/jsonp';
4
+ export { uniqKey } from './utils/uniqKey';
5
+ export { ago } from './utils/ago';
6
+ export { GET, POST, sendJSON, sugarSend, sendRequest, buildUrlByOption, registerHostAlias, } from './utils/request';
7
+ export { calendarTable } from './utils/calendarTable';
8
+ export { Countdown } from './utils/Countdown';
9
+ export { defaultScroll } from './utils/defaultScroll';
10
+ export { is } from './utils/is';
11
+ export { waitFor, waitUntil } from './utils/wait';
12
+ export { normalizeUnit, splitValue, adaptive } from './utils/cssUtil';
13
+ export { createApp, history, getHistory } from './utils/createApp';
14
+ export { useInterval } from './Effect/useInterval';
15
+ export { useTick } from './Effect/useTick';
16
+ export { Ago } from './Ago';
17
+ export { Container } from './Container';
18
+ export { Flex, FlexItem } from './Flex';
19
+ export { Row, RowAround, RowBetween, RowCenter, RowEnd, RowEvenly, RowStart, } from './Flex/Row';
20
+ export { Col, ColAround, ColBetween, ColCenter, ColEnd, ColEvenly, ColStart, } from './Flex/Col';
21
+ export { Countdowner } from './Countdowner';
22
+ export { Overlay } from './Overlay';
23
+ export { showToast, showUniqToast } from './Toast';
24
+ export { showDialog } from './Dialog';
25
+ export { Clickable } from './Clickable';
26
+ export { Indicator } from './Indicator';
27
+ export { showLoading, showLoadingAtLeast } from './Loading';
28
+ export { SafeArea } from './SafeArea';
29
+ export { AutoGrid } from './AutoGrid';
30
+ export { showAlert } from './Alert';
31
+ export { ScrollView } from './ScrollView';
32
+ export { CarouselNotice } from './CarouselNotice';
@@ -1,4 +1,4 @@
1
- export type CountdownValueIndex = "d" | "h" | "i" | "s";
1
+ export type CountdownValueIndex = 'd' | 'h' | 'i' | 's';
2
2
  export type CountdownValue = {
3
3
  [key in CountdownValueIndex]?: number;
4
4
  };
@@ -1,4 +1,4 @@
1
- import { Tick } from "./tick";
1
+ import { tick } from './tick';
2
2
  export class Countdown {
3
3
  constructor(option) {
4
4
  /**
@@ -13,13 +13,13 @@ export class Countdown {
13
13
  * i:分
14
14
  * s:秒
15
15
  */
16
- this.format = ["d", "h", "i", "s"];
17
- if (typeof option.remain === "number" && option.remain >= 0) {
16
+ this.format = ['d', 'h', 'i', 's'];
17
+ if (typeof option.remain === 'number' && option.remain >= 0) {
18
18
  this.total = this.remain = option.remain;
19
19
  }
20
20
  // 倒计时需要展示的时间格式
21
- if (typeof option.format === "string") {
22
- const parts = option.format.split("");
21
+ if (typeof option.format === 'string') {
22
+ const parts = option.format.split('');
23
23
  const output = [];
24
24
  this.format.forEach((item) => {
25
25
  if (parts.includes(item)) {
@@ -30,7 +30,7 @@ export class Countdown {
30
30
  }
31
31
  else {
32
32
  // 设置默认的倒计时格式
33
- this.format = ["h", "i", "s"];
33
+ this.format = ['h', 'i', 's'];
34
34
  }
35
35
  this._onUpdate = option.onUpdate;
36
36
  this._onEnd = option.onEnd;
@@ -54,7 +54,7 @@ export class Countdown {
54
54
  (_d = this._onUpdate) === null || _d === void 0 ? void 0 : _d.call(this, this.formatValue());
55
55
  // 记录倒计时开启时的时间
56
56
  const start = Date.now();
57
- const tickInstance = new Tick(() => {
57
+ this._stopTick = tick(() => {
58
58
  var _a, _b, _c, _d;
59
59
  // 获取倒计时已经持续的时间
60
60
  const duration = Math.floor((Date.now() - start) / 1000);
@@ -73,8 +73,6 @@ export class Countdown {
73
73
  (_d = this._onUpdate) === null || _d === void 0 ? void 0 : _d.call(this, this.formatValue());
74
74
  }
75
75
  });
76
- tickInstance.start();
77
- this._stopTick = () => tickInstance.destroy();
78
76
  }
79
77
  // 停止倒计时
80
78
  stop() {
@@ -91,19 +89,19 @@ export class Countdown {
91
89
  const result = {};
92
90
  this.format.forEach((key) => {
93
91
  switch (key) {
94
- case "d":
92
+ case 'd':
95
93
  result.d = Math.floor(remainTime / 86400);
96
94
  remainTime = remainTime - result.d * 86400;
97
95
  break;
98
- case "h":
96
+ case 'h':
99
97
  result.h = Math.floor(remainTime / 3600);
100
98
  remainTime = remainTime - result.h * 3600;
101
99
  break;
102
- case "i":
100
+ case 'i':
103
101
  result.i = Math.floor(remainTime / 60);
104
102
  remainTime = remainTime - result.i * 60;
105
103
  break;
106
- case "s":
104
+ case 's':
107
105
  result.s = remainTime;
108
106
  break;
109
107
  default:
@@ -1,13 +1,7 @@
1
+ export type StopTick = () => void;
1
2
  /**
2
- * tick类,初始化后使用start开始tick,使用destroy终止tick
3
- * @constructor
4
- * @param {function} callback start后每一帧都会调用的回调函数
3
+ * 逐帧执行的工具函数,返回一个方法,调用该方法,停止执行
4
+ * @param callback
5
+ * @param interval
5
6
  */
6
- export declare class Tick {
7
- callback?: (() => void) | undefined;
8
- frameId: number | undefined;
9
- isRun: boolean;
10
- constructor(callback?: (() => void) | undefined);
11
- start(): void;
12
- destroy(): void;
13
- }
7
+ export declare function tick(callback: () => void, interval?: number): StopTick;
@@ -1,32 +1,47 @@
1
1
  /**
2
- * tick类,初始化后使用start开始tick,使用destroy终止tick
3
- * @constructor
4
- * @param {function} callback start后每一帧都会调用的回调函数
2
+ * 逐帧执行的工具函数,返回一个方法,调用该方法,停止执行
3
+ * @param callback
4
+ * @param interval
5
5
  */
6
- export class Tick {
7
- constructor(callback) {
8
- this.callback = callback;
9
- this.frameId = undefined;
10
- this.isRun = true;
11
- }
12
- start() {
13
- // 每一帧执行的任务
14
- const frame = () => {
15
- var _a;
16
- if (!this.isRun)
6
+ export function tick(callback, interval) {
7
+ // 执行状态,是否正在执行
8
+ let isRunning;
9
+ let frame;
10
+ let frameId;
11
+ // 设置了tick的间隔
12
+ if (interval && typeof interval === 'number') {
13
+ let lastTick = Date.now();
14
+ frame = () => {
15
+ if (!isRunning) {
17
16
  return;
18
- // 在回调执行之前预约下一帧
19
- this.frameId = requestAnimationFrame(frame);
20
- // 执行回调
21
- (_a = this.callback) === null || _a === void 0 ? void 0 : _a.call(this);
17
+ }
18
+ frameId = requestAnimationFrame(frame);
19
+ const now = Date.now();
20
+ // 每次间隔频率逻辑上保持一致,即使帧频不一致
21
+ if (now - lastTick >= interval) {
22
+ // 本次tick的时间为上次的时间加上频率间隔
23
+ lastTick = lastTick + interval;
24
+ callback();
25
+ }
22
26
  };
23
- // 执行起始帧
24
- frame();
25
27
  }
26
- destroy() {
27
- if (typeof this.frameId === "number") {
28
- cancelAnimationFrame(this.frameId);
29
- }
30
- this.isRun = false;
28
+ // 没有设置tick的间隔
29
+ else {
30
+ frame = () => {
31
+ if (!isRunning) {
32
+ return;
33
+ }
34
+ frameId = requestAnimationFrame(frame);
35
+ // 没有设置interval时,每帧都执行
36
+ callback();
37
+ };
31
38
  }
39
+ // 开始执行
40
+ isRunning = true;
41
+ frameId = requestAnimationFrame(frame);
42
+ // 返回一个可以立即停止的函数
43
+ return () => {
44
+ isRunning = false;
45
+ cancelAnimationFrame(frameId);
46
+ };
32
47
  }
@@ -7,7 +7,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
7
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
8
8
  });
9
9
  };
10
- import { Tick } from "./tick";
10
+ import { tick } from './tick';
11
11
  /**
12
12
  * 直接条件为真或者超时才返回结果
13
13
  *
@@ -21,27 +21,27 @@ export function waitUntil(condition, maxTime) {
21
21
  // 记录检测开始时间
22
22
  const start = Date.now();
23
23
  // 如果检测条件不为函数,直接返回结果
24
- if (typeof condition !== "function") {
24
+ if (typeof condition !== 'function') {
25
25
  return !!condition;
26
26
  }
27
27
  // 设置默认检测时间的最大值,如果没有设置,则一直检测
28
- if (!maxTime || typeof maxTime !== "number") {
28
+ if (!maxTime || typeof maxTime !== 'number') {
29
29
  maxTime = Infinity;
30
30
  }
31
31
  return new Promise((resolve) => {
32
- const tick = new Tick(() => {
32
+ const stop = tick(() => {
33
33
  const now = Date.now();
34
34
  const result = condition();
35
35
  // 超时返回false
36
36
  if (now - start >= maxTime) {
37
- tick.destroy();
37
+ stop();
38
38
  resolve(false);
39
39
  return;
40
40
  }
41
41
  // 处理结果
42
42
  const handle = (res) => {
43
43
  if (res) {
44
- tick.destroy();
44
+ stop();
45
45
  resolve(true);
46
46
  }
47
47
  };
@@ -53,7 +53,6 @@ export function waitUntil(condition, maxTime) {
53
53
  // 普通一般的结果
54
54
  handle(result);
55
55
  });
56
- tick.start();
57
56
  });
58
57
  });
59
58
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "clxx",
3
- "version": "2.0.8",
3
+ "version": "2.1.1",
4
4
  "description": "Basic JS library for mobile devices",
5
5
  "main": "./build/index.js",
6
6
  "module": "./build/index.js",
@@ -9,7 +9,8 @@
9
9
  },
10
10
  "scripts": {
11
11
  "start": "tsc -w --pretty",
12
- "build": "rm -rfv ./build && tsc"
12
+ "build": "rm -rfv ./build && tsc",
13
+ "pub": "npm run build && npm publish"
13
14
  },
14
15
  "repository": {
15
16
  "type": "git",