oipage 0.3.0 → 1.0.0-alpha.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.
Files changed (59) hide show
  1. package/CHANGELOG +15 -13
  2. package/README.md +1 -102
  3. package/bin/mineTypes.json +105 -0
  4. package/{nodejs/core → bin}/network.js +7 -4
  5. package/bin/resolve404.js +78 -0
  6. package/bin/run +8 -200
  7. package/bin/serve.js +64 -0
  8. package/images/file.png +0 -0
  9. package/images/folder.png +0 -0
  10. package/images/goback.png +0 -0
  11. package/{corejs → nodejs}/animation/index.js +8 -2
  12. package/nodejs/deeplog/index.d.ts +10 -0
  13. package/nodejs/deeplog/index.js +35 -0
  14. package/nodejs/linelog/index.d.ts +9 -0
  15. package/nodejs/{core/log.js → linelog/index.js} +12 -55
  16. package/{corejs → nodejs}/throttle/index.js +9 -3
  17. package/package.json +12 -5
  18. package/web/animation/index.d.ts +12 -0
  19. package/web/animation/index.js +108 -0
  20. package/{browserjs → web}/getStyle/index.js +8 -2
  21. package/{browserjs → web}/onReady/index.js +8 -2
  22. package/web/setStyle/index.js +11 -0
  23. package/web/throttle/index.d.ts +31 -0
  24. package/web/throttle/index.js +56 -0
  25. package/AUTHORS.txt +0 -6
  26. package/bin/options.js +0 -74
  27. package/browserjs/index.d.ts +0 -13
  28. package/browserjs/index.js +0 -9
  29. package/browserjs/setStyle/index.js +0 -5
  30. package/corejs/index.d.ts +0 -10
  31. package/corejs/index.js +0 -7
  32. package/nodejs/core/file.js +0 -163
  33. package/nodejs/core/image.js +0 -5
  34. package/nodejs/core/options.js +0 -49
  35. package/nodejs/core/remote.js +0 -60
  36. package/nodejs/core/responseFileList.js +0 -28
  37. package/nodejs/core/server.js +0 -190
  38. package/nodejs/data/404.js +0 -52
  39. package/nodejs/data/images/file.js +0 -1
  40. package/nodejs/data/images/folder.js +0 -1
  41. package/nodejs/data/mime.types.js +0 -112
  42. package/nodejs/form/common.js +0 -3
  43. package/nodejs/form/index.js +0 -80
  44. package/nodejs/form/select.js +0 -10
  45. package/nodejs/index.js +0 -58
  46. package/nodejs/loader/simpleScss.js +0 -248
  47. package/nodejs/loader/xhtml.js +0 -521
  48. package/nodejs/reader/plain.js +0 -20
  49. package/stylecss/index.css +0 -3
  50. package/stylecss/normalize.css +0 -94
  51. package/stylecss/rasterize.css +0 -318
  52. package/stylecss/skeleton.css +0 -16
  53. package/types/get-options.d.ts +0 -6
  54. package/types/index.d.ts +0 -187
  55. /package/{corejs → nodejs}/animation/index.d.ts +0 -0
  56. /package/{corejs → nodejs}/throttle/index.d.ts +0 -0
  57. /package/{browserjs → web}/getStyle/index.d.ts +0 -0
  58. /package/{browserjs → web}/onReady/index.d.ts +0 -0
  59. /package/{browserjs → web}/setStyle/index.d.ts +0 -0
@@ -0,0 +1,10 @@
1
+ /**
2
+ * 进度打印
3
+ * @param percentum 进度0-100
4
+ * @param stream 说明文字,可选
5
+ */
6
+ export interface deeplogType {
7
+ (percentum: number, stream?: string): void
8
+ }
9
+
10
+ export let deeplog: deeplogType
@@ -0,0 +1,35 @@
1
+ /*!
2
+ * deeplog of OIPage v1.0.0-alpha.0
3
+ * git+https://github.com/oi-contrib/OIPage.git
4
+ */
5
+ const {linelog} = require("../linelog/index.js");
6
+ /**
7
+ * 进度打印
8
+ *
9
+ * @param {number} percentum 进度0-100
10
+ * @param {string} stream 说明文字,可选
11
+ */
12
+ function deeplog (percentum, stream) {
13
+ if (arguments.length == 0) {
14
+ linelog();
15
+ return;
16
+ }
17
+
18
+ if (arguments.length <= 1) stream = "";
19
+
20
+ let txt = "",
21
+ i = 0;
22
+
23
+ // 补充已经有的进度
24
+ for (; i <= percentum && i <= 100; i += 5) {
25
+ txt += "█";
26
+ }
27
+
28
+ // 补充余下的空白
29
+ for (; i <= 100; i += 5) {
30
+ txt += "░";
31
+ }
32
+
33
+ linelog(percentum.toFixed(2) + "%[" + txt + "]" + stream);
34
+ };
35
+ exports.deeplog = deeplog;
@@ -0,0 +1,9 @@
1
+ /**
2
+ * 单行打印
3
+ * @param stream 打印的内容
4
+ */
5
+ export interface linelogType {
6
+ (stream: string): void
7
+ }
8
+
9
+ export let linelog: linelogType
@@ -1,31 +1,18 @@
1
- // 日志
2
- exports.log = function (txt) {
3
- console.log("\x1B[32m" + txt + "\x1B[39m");
4
- };
5
-
6
- // 警告
7
- exports.warn = function (txt) {
8
- console.log("\x1B[33m" + txt + "\x1B[39m");
9
- };
10
-
11
- // 错误
12
- exports.error = function (txt) {
13
- console.log("\x1B[35m" + txt + "\x1B[39m");
14
- };
15
-
16
-
17
- // 计算字符串长度的方法
18
- const stringwidth = function (str) {
19
- return str.length;
20
- };
21
-
1
+ /*!
2
+ * linelog of OIPage v1.0.0-alpha.0
3
+ * git+https://github.com/oi-contrib/OIPage.git
4
+ */
5
+
22
6
  // 预定义的常量
23
7
  const MOVE_LEFT = Buffer.from('1b5b3130303044', 'hex').toString();
24
8
  const MOVE_UP = Buffer.from('1b5b3141', 'hex').toString();
25
9
  const CLEAR_LINE = Buffer.from('1b5b304b', 'hex').toString();
26
10
 
27
- // 不换行打印
28
- const linelog = (function (stream) {
11
+ /**
12
+ * 不换行打印
13
+ * @param {string} stream 打印的内容
14
+ */
15
+ let linelog = (function (stream) {
29
16
 
30
17
  // 用来记录前置有多少行需要回退
31
18
  let prevLineCount = 0;
@@ -56,35 +43,5 @@ const linelog = (function (stream) {
56
43
 
57
44
  };
58
45
  })(process.stdout);
59
-
60
- exports.linelog = linelog;
61
-
62
- /**
63
- * 进度打印
64
- *
65
- * @param {number} percentum 进度0-100
66
- * @param {string} stream 说明文字,可选择
67
- */
68
- exports.deeplog = function (percentum, stream) {
69
- if (arguments.length == 0) {
70
- linelog();
71
- return;
72
- }
73
-
74
- if (arguments.length <= 1) stream = "";
75
-
76
- let txt = "",
77
- i = 0;
78
-
79
- // 补充已经有的进度
80
- for (; i <= percentum && i <= 100; i += 5) {
81
- txt += "█";
82
- }
83
-
84
- // 补充余下的空白
85
- for (; i <= 100; i += 5) {
86
- txt += "░";
87
- }
88
-
89
- linelog(percentum.toFixed(2) + "%[" + txt + "]" + stream);
90
- };
46
+
47
+ exports.linelog = linelog;
@@ -1,4 +1,9 @@
1
- export function throttle(callback, _option) {
1
+ /*!
2
+ * throttle of OIPage v1.0.0-alpha.0
3
+ * git+https://github.com/oi-contrib/OIPage.git
4
+ */
5
+
6
+ function throttle(callback, _option) {
2
7
 
3
8
  // 缺省值
4
9
  var option = {
@@ -6,7 +11,7 @@ export function throttle(callback, _option) {
6
11
  keep: false,
7
12
  opportunity: "end"
8
13
  };
9
-
14
+
10
15
  // 校对
11
16
  if (_option) {
12
17
  for (var key in _option) {
@@ -47,4 +52,5 @@ export function throttle(callback, _option) {
47
52
  }
48
53
 
49
54
  };
50
- };
55
+ };
56
+ exports.throttle = throttle;
package/package.json CHANGED
@@ -1,10 +1,14 @@
1
1
  {
2
2
  "name": "oipage",
3
- "version": "0.3.0",
4
- "description": "OI页面快速开发辅助库,包括核心包、Nodejs、浏览器、样式文件等",
5
- "main": "./nodejs/index.js",
6
- "typings": "./types/index.d.ts",
3
+ "version": "1.0.0-alpha.1",
4
+ "description": "前端网页或应用快速开发助手,包括开发服务器、辅助命令、实用API等",
7
5
  "sideEffects": false,
6
+ "scripts": {
7
+ "dev": "node ./build/index.js watch",
8
+ "build": "node ./build/index.js",
9
+ "serve": "node ./bin/run serve",
10
+ "doc": ""
11
+ },
8
12
  "bin": {
9
13
  "oipage-cli": "bin/run"
10
14
  },
@@ -30,5 +34,8 @@
30
34
  "bugs": {
31
35
  "url": "https://github.com/oi-contrib/OIPage/issues"
32
36
  },
33
- "homepage": "https://github.com/oi-contrib/OIPage"
37
+ "homepage": "https://github.com/oi-contrib/OIPage",
38
+ "devDependencies": {
39
+ "oipage": "^0.2.0"
40
+ }
34
41
  }
@@ -0,0 +1,12 @@
1
+ interface animationFun {
2
+ (deep: number): void
3
+ }
4
+
5
+ /**
6
+ * 轮询动画,返回一个函数,调用该函数,可以提前结束动画
7
+ */
8
+ export interface animationType {
9
+ (doback: animationFun, duration?: number, callback?: animationFun): Function
10
+ }
11
+
12
+ export let animation: animationType
@@ -0,0 +1,108 @@
1
+ /*!
2
+ * animation of OIPage v1.0.0-alpha.0
3
+ * git+https://github.com/oi-contrib/OIPage.git
4
+ */
5
+
6
+ //当前正在运动的动画的tick函数堆栈
7
+ var $timers = [];
8
+ //唯一定时器的定时间隔
9
+ var $interval = 13;
10
+ //定时器ID
11
+ var $timerId;
12
+
13
+ /**
14
+ * 动画轮播
15
+ * @param {function} doback 轮询函数,有一个形参deep,0-1,表示执行进度
16
+ * @param {number} duration 动画时长,可选
17
+ * @param {function} callback 动画结束回调,可选,有一个形参deep,0-1,表示执行进度
18
+ *
19
+ * @returns {function} 返回一个函数,调用该函数,可以提前结束动画
20
+ */
21
+ function animation(doback, duration, callback) {
22
+ if (arguments.length < 2) duration = 400;
23
+ if (arguments.length < 3) callback = function () { };
24
+
25
+ var clock = {
26
+ //把tick函数推入堆栈
27
+ "timer": function (tick, duration, callback) {
28
+ if (!tick) {
29
+ throw new Error('Tick is required!');
30
+ }
31
+ var id = new Date().valueOf() + "_" + (Math.random() * 1000).toFixed(0);
32
+ $timers.push({
33
+ "id": id,
34
+ "createTime": new Date(),
35
+ "tick": tick,
36
+ "duration": duration,
37
+ "callback": callback
38
+ });
39
+ clock.start();
40
+ return id;
41
+ },
42
+
43
+ //开启唯一的定时器timerId
44
+ "start": function () {
45
+ if (!$timerId) {
46
+ $timerId = setInterval(clock.tick, $interval);
47
+ }
48
+ },
49
+
50
+ //被定时器调用,遍历timers堆栈
51
+ "tick": function () {
52
+ var createTime, flag, tick, callback, timer, duration, passTime, timers = $timers;
53
+
54
+ $timers = [];
55
+ $timers.length = 0;
56
+
57
+ for (flag = 0; flag < timers.length; flag++) {
58
+ //初始化数据
59
+ timer = timers[flag];
60
+ createTime = timer.createTime;
61
+ tick = timer.tick;
62
+ duration = timer.duration;
63
+ callback = timer.callback;
64
+
65
+ //执行
66
+ passTime = (+new Date().valueOf() - createTime.valueOf()) / duration;
67
+ passTime = passTime > 1 ? 1 : passTime;
68
+ tick(passTime);
69
+ if (passTime < 1 && timer.id) {
70
+ //动画没有结束再添加
71
+ $timers.push(timer);
72
+ } else {
73
+ callback(passTime);
74
+ }
75
+ }
76
+ if ($timers.length <= 0) {
77
+ clock.stop();
78
+ }
79
+ },
80
+
81
+ //停止定时器,重置timerId=null
82
+ "stop": function () {
83
+ if ($timerId) {
84
+ clearInterval($timerId);
85
+ $timerId = null;
86
+ }
87
+ }
88
+ };
89
+
90
+ var id = clock.timer(function (deep) {
91
+ //其中deep为0-1,表示改变的程度
92
+ doback(deep);
93
+ }, duration, callback);
94
+
95
+ // 返回一个函数
96
+ // 用于在动画结束前结束动画
97
+ return function () {
98
+ var i;
99
+ for (i in $timers) {
100
+ if ($timers[i].id == id) {
101
+ $timers[i].id = void 0;
102
+ return;
103
+ }
104
+ }
105
+ };
106
+
107
+ };
108
+ export let animation = animation;
@@ -1,4 +1,9 @@
1
- export function getStyle(el, name) {
1
+ /*!
2
+ * getStyle of OIPage v1.0.0-alpha.0
3
+ * git+https://github.com/oi-contrib/OIPage.git
4
+ */
5
+
6
+ function getStyle(el, name) {
2
7
 
3
8
  // 获取结点的全部样式
4
9
  var allStyle = document.defaultView && document.defaultView.getComputedStyle ?
@@ -10,4 +15,5 @@ export function getStyle(el, name) {
10
15
  allStyle.getPropertyValue(name) :
11
16
  allStyle;
12
17
 
13
- };
18
+ };
19
+ export let getStyle = getStyle;
@@ -1,8 +1,14 @@
1
- export function onReady(callback) {
1
+ /*!
2
+ * onReady of OIPage v1.0.0-alpha.0
3
+ * git+https://github.com/oi-contrib/OIPage.git
4
+ */
5
+
6
+ function onReady(callback) {
2
7
  var readyState = document.readyState;
3
8
  if (readyState === 'interactive' || readyState === 'complete') {
4
9
  callback();
5
10
  } else {
6
11
  window.addEventListener("DOMContentLoaded", callback);
7
12
  }
8
- };
13
+ };
14
+ export let onReady = onReady;
@@ -0,0 +1,11 @@
1
+ /*!
2
+ * setStyle of OIPage v1.0.0-alpha.0
3
+ * git+https://github.com/oi-contrib/OIPage.git
4
+ */
5
+
6
+ function setStyle(el, styles) {
7
+ for (var key in styles) {
8
+ el.style[key] = styles[key];
9
+ }
10
+ };
11
+ export let setStyle = setStyle;
@@ -0,0 +1,31 @@
1
+ export type throttleOpportunityType = "begin" | "end" | "wide"
2
+
3
+ export interface throttleOptionType {
4
+
5
+ /**
6
+ * 节流时长
7
+ */
8
+ time?: number
9
+
10
+ /**
11
+ * 是否持续节流
12
+ */
13
+ keep?: boolean
14
+
15
+ /**
16
+ * 执行时机
17
+ *
18
+ * begin(开始触发)、end(结束触发)、wide(第一次开始触发,其余结束触发)
19
+ */
20
+ opportunity?: throttleOpportunityType
21
+
22
+ }
23
+
24
+ /**
25
+ * 节流函数
26
+ */
27
+ export interface throttleType {
28
+ (callback: Function, option?: throttleOptionType): Function
29
+ }
30
+
31
+ export let throttle: throttleType
@@ -0,0 +1,56 @@
1
+ /*!
2
+ * throttle of OIPage v1.0.0-alpha.0
3
+ * git+https://github.com/oi-contrib/OIPage.git
4
+ */
5
+
6
+ function throttle(callback, _option) {
7
+
8
+ // 缺省值
9
+ var option = {
10
+ time: 200,
11
+ keep: false,
12
+ opportunity: "end"
13
+ };
14
+
15
+ // 校对
16
+ if (_option) {
17
+ for (var key in _option) {
18
+ option[key] = _option[key];
19
+ }
20
+ }
21
+
22
+ var hadInterval = false, hadClick = false, oneClick = false, arg;
23
+ return function () {
24
+ const _this = this;
25
+ arg = arguments;
26
+
27
+ // 如果前置任务都完成了
28
+ if (!hadInterval) {
29
+ if (option.opportunity != 'end') {
30
+ callback.apply(_this, arg);
31
+ }
32
+ hadInterval = true;
33
+
34
+ var interval = setInterval(() => {
35
+ if (hadClick) {
36
+ if (!option.keep) {
37
+ callback.apply(_this, arg);
38
+ }
39
+ } else {
40
+ if (option.opportunity != 'begin') {
41
+ if (oneClick || option.opportunity == 'end') callback.apply(_this, arg);
42
+ }
43
+ hadInterval = false;
44
+ oneClick = false;
45
+ clearInterval(interval);
46
+ }
47
+ hadClick = false;
48
+ }, option.time);
49
+ } else {
50
+ hadClick = true;
51
+ oneClick = true;
52
+ }
53
+
54
+ };
55
+ };
56
+ export let throttle = throttle;
package/AUTHORS.txt DELETED
@@ -1,6 +0,0 @@
1
- Authors ordered by first contribution.
2
-
3
- zxl20070701 <1904314465@qq.com> <https://github.com/zxl20070701>
4
-
5
- -----------------------------------------------------
6
- We thank all of them for their contributions!
package/bin/options.js DELETED
@@ -1,74 +0,0 @@
1
- module.exports = {
2
-
3
- // 命令参数配置
4
- "options": {
5
- version: {
6
- short: 'v',
7
- info: '[0]Display the version of OIPage.',
8
- demo: 'oipage-cli --version|-v'
9
- },
10
- help: {
11
- short: 'h',
12
- info: '[1]Display this help text.',
13
- demo: 'oipage-cli --help|-h <term>'
14
- },
15
- server: {
16
- short: 's',
17
- info: '[2]Render source server.',
18
- demo: 'oipage-cli --server|-s [port|20000] [basePath|./]'
19
- },
20
- config: {
21
- short: 'c',
22
- info: '[3]Specify a configuration file.',
23
- demo: 'oipage-cli --config|-c ./OIPage.config.js'
24
- },
25
- delete: {
26
- info: '[4]Delete file or folder.',
27
- demo: 'oipage-cli --delete targetPath'
28
- },
29
- copy: {
30
- info: '[5]Copy file or folder.',
31
- demo: 'oipage-cli --copy sourcePath targetPath'
32
- },
33
- pick: {
34
- info: '[6]Copy all files in the folder to the specified location.',
35
- demo: 'oipage-cli --pick sourcePath targetPath'
36
- },
37
- move: {
38
- info: '[7]Move file or folder.',
39
- demo: 'oipage-cli --move sourcePath targetPath'
40
- },
41
- network: {
42
- info: '[8]Display network information.',
43
- demo: 'oipage-cli --network'
44
- },
45
- get: {
46
- info: '[9]HTTP GET.',
47
- demo: 'oipage-cli --get url'
48
- },
49
- post: {
50
- info: '[10]HTTP POST.',
51
- demo: 'oipage-cli --post url'
52
- },
53
- cat: {
54
- info: '[11]Show file.',
55
- demo: 'oipage-cli --cat path'
56
- },
57
- run: {
58
- info: '[12]Run multiple commands.',
59
- demo: 'oipage-cli --run \"commands1\" \"commands2\" \"commands3\"'
60
- }
61
- },
62
-
63
- // 帮助信息
64
- "help": `
65
- Usage: oipage-cli <command>
66
-
67
- Where <command> is one of:
68
- --help, -h, --server, -s, --version, -v, --config, -c, --delete, --copy, --pick, --move, --network, --get, --post, --cat
69
-
70
- oipage-cli --help|-h <term> search for help on <term>
71
- oipage-cli --help|-h involved overview
72
- `
73
-
74
- };
@@ -1,13 +0,0 @@
1
- import { getStyleType } from "./getStyle"
2
- import { setStyleType } from "./setStyle"
3
- import { onReadyType } from "./onReady"
4
-
5
- export default class Corejs {
6
- static getStyle: getStyleType
7
- static setStyle: setStyleType
8
- static onReady: onReadyType
9
- }
10
-
11
- export let getStyle: getStyleType
12
- export let setStyle: setStyleType
13
- export let onReady: onReadyType
@@ -1,9 +0,0 @@
1
- import { getStyle } from "./getStyle/index.js";
2
- import { setStyle } from "./setStyle/index.js";
3
- import { onReady } from "./onReady/index.js";
4
-
5
- export default {
6
- getStyle: getStyle,
7
- setStyle: setStyle,
8
- onReady: onReady
9
- };
@@ -1,5 +0,0 @@
1
- export function setStyle(el, styles) {
2
- for (var key in styles) {
3
- el.style[key] = styles[key];
4
- }
5
- };
package/corejs/index.d.ts DELETED
@@ -1,10 +0,0 @@
1
- import { animationType } from "./animation"
2
- import { throttleType } from "./throttle"
3
-
4
- export default class Corejs {
5
- static animation: animationType
6
- static throttle: throttleType
7
- }
8
-
9
- export let animation: animationType
10
- export let throttle: throttleType
package/corejs/index.js DELETED
@@ -1,7 +0,0 @@
1
- import { animation } from "./animation/index.js";
2
- import { throttle } from "./throttle/index.js";
3
-
4
- export default {
5
- animation: animation,
6
- throttle: throttle
7
- };