oipage 1.5.0-alpha.0 → 1.5.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.
@@ -0,0 +1,55 @@
1
+ <h2 z-bind="title"></h2>
2
+ <div class="right-btn">
3
+ <div>
4
+ <fieldset>
5
+ <legend>
6
+ 当前大小
7
+ </legend>
8
+ <ul z-bind:lock="title=='图像大小'?'yes':'no'">
9
+ <li>
10
+ <label>宽度:</label>
11
+ <span z-bind="width"></span>px
12
+ </li>
13
+ <li>
14
+ <label>宽度:</label>
15
+ <span z-bind="height"></span>px
16
+ </li>
17
+ </ul>
18
+ </fieldset>
19
+ <fieldset>
20
+ <legend>
21
+ 新建大小
22
+ </legend>
23
+ <ul z-bind:lock="title=='图像大小'?'yes':'no'">
24
+ <li>
25
+ <label>宽度(W):</label>
26
+ <input type="text" z-model="newWidth" z-on:input="calcHeight">
27
+ px
28
+ </li>
29
+ <li>
30
+ <label>高度(H):</label>
31
+ <input type="text" z-model="newHeight" z-on:input="calcWidth">
32
+ px
33
+ </li>
34
+ <li z-bind:active="title=='画布大小'?'yes':'no'">
35
+ <label>定位:</label>
36
+ <div class="change-type" z-bind:type="changeType">
37
+ <span z-on:click="doChangeType" val="left-top"></span>
38
+ <span z-on:click="doChangeType" val="center-top"></span>
39
+ <span z-on:click="doChangeType" val="right-top"></span>
40
+ <span z-on:click="doChangeType" val="left-middle"></span>
41
+ <span z-on:click="doChangeType" val="center-middle"></span>
42
+ <span z-on:click="doChangeType" val="right-middle"></span>
43
+ <span z-on:click="doChangeType" val="left-bottom"></span>
44
+ <span z-on:click="doChangeType" val="center-bottom"></span>
45
+ <span z-on:click="doChangeType" val="right-bottom"></span>
46
+ </div>
47
+ </li>
48
+ </ul>
49
+ </fieldset>
50
+ </div>
51
+ <div>
52
+ <button z-on:click="doSubmit">确定</button>
53
+ <button z-on:click="doClose">取消</button>
54
+ </div>
55
+ </div>
@@ -0,0 +1,53 @@
1
+ import { defineElement, ref } from "zipaper"
2
+ import template from "./index.html"
3
+ import style from "./index.scss";
4
+
5
+ export default defineElement({
6
+ template,
7
+ data() {
8
+ return {
9
+ title: this._props.title,
10
+ width: this._props.width,
11
+ height: this._props.height,
12
+
13
+ newWidth: ref(this._props.width),
14
+ newHeight: ref(this._props.height),
15
+
16
+ changeType: ref('center-middle')
17
+ }
18
+ },
19
+ methods: {
20
+ calcHeight() {
21
+ if (this.title == '图像大小') {
22
+ this.newHeight = +(this.newWidth * this.height / this.width).toFixed(0);
23
+ }
24
+ },
25
+
26
+ calcWidth() {
27
+ if (this.title == '图像大小') {
28
+ this.newWidth = +(this.newHeight * this.width / this.height).toFixed(0);
29
+ }
30
+ },
31
+
32
+ doChangeType: function (event, target) {
33
+ this.changeType = target.getAttribute('val');
34
+ },
35
+
36
+ // 确定
37
+ doSubmit: function () {
38
+ this.$closeDialog({
39
+ width: +this.newWidth,
40
+ height: +this.newHeight,
41
+ changeType: this.changeType
42
+ });
43
+ },
44
+
45
+ // 取消
46
+ doClose: function () {
47
+ this.$closeDialog();
48
+ }
49
+ },
50
+ style: {
51
+ content: style
52
+ }
53
+ })
@@ -0,0 +1,139 @@
1
+ #dialog-root>.content.imageSize {
2
+ border: 1px solid gray;
3
+ min-height: 300px;
4
+ width: 300px;
5
+ background-color: white;
6
+
7
+ &>h2 {
8
+ font-size: 12px;
9
+ padding-left: 30px;
10
+ background-image: url('./images/image-editor.png');
11
+ background-size: auto 80%;
12
+ background-repeat: no-repeat;
13
+ background-position: 3px center;
14
+ border-bottom: 1px solid gray;
15
+ line-height: 30px;
16
+ height: 30px;
17
+ user-select: none;
18
+ }
19
+
20
+ &>div.right-btn {
21
+ display: flex;
22
+
23
+ &>div {
24
+ &:first-child {
25
+ flex-grow: 1;
26
+ padding: 10px 0 10px 10px;
27
+ }
28
+
29
+ &:last-child {
30
+ text-align: center;
31
+ flex-grow: 0;
32
+ flex-shrink: 0;
33
+ flex-basis: 70px;
34
+
35
+ &>button {
36
+ height: 30px;
37
+ border-radius: 15px;
38
+ width: 50px;
39
+ margin-top: 10px;
40
+
41
+ &:hover {
42
+ background-color: rgb(127, 131, 131);
43
+ cursor: pointer;
44
+ }
45
+ }
46
+
47
+ }
48
+ }
49
+ }
50
+
51
+ fieldset {
52
+ margin-top: 10px;
53
+ font-size: 12px;
54
+ }
55
+
56
+ ul {
57
+
58
+ &[lock='yes'] {
59
+ background-image: url('./images/lock.png');
60
+ background-repeat: no-repeat;
61
+ background-position: right;
62
+ }
63
+
64
+ &>li {
65
+ line-height: 2em;
66
+ margin-top: 5px;
67
+
68
+ &[active='no'] {
69
+ display: none;
70
+ }
71
+
72
+ &>label {
73
+ width: 70px;
74
+ display: inline-block;
75
+ text-align: right;
76
+ }
77
+
78
+ &>input {
79
+ width: 50px;
80
+ margin-right: 5px;
81
+ }
82
+
83
+ .change-type {
84
+ font-size: 0;
85
+ width: 90px;
86
+ display: inline-block;
87
+ line-height: 0;
88
+ vertical-align: top;
89
+ background-image: url('./images/size.png');
90
+ background-size: 100% auto;
91
+ background-repeat: no-repeat;
92
+
93
+ &>span {
94
+ display: inline-block;
95
+ width: 30px;
96
+ height: 30px;
97
+ cursor: pointer;
98
+ outline: 1px solid #dedede;
99
+ }
100
+
101
+ &[type='left-top'] {
102
+ background-position: -29px -32px;
103
+ }
104
+
105
+ &[type='center-top'] {
106
+ background-position: 1px -32px;
107
+ }
108
+
109
+ &[type='right-top'] {
110
+ background-position: 30px -32px;
111
+ }
112
+
113
+ &[type='left-middle'] {
114
+ background-position: -29px -1px;
115
+ }
116
+
117
+ &[type='center-middle'] {
118
+ background-position: 1px -1px;
119
+ }
120
+
121
+ &[type='right-middle'] {
122
+ background-position: 30px -1px;
123
+ }
124
+
125
+ &[type='left-bottom'] {
126
+ background-position: -29px 30px;
127
+ }
128
+
129
+ &[type='center-bottom'] {
130
+ background-position: 1px 30px;
131
+ }
132
+
133
+ &[type='right-bottom'] {
134
+ background-position: 30px 30px;
135
+ }
136
+ }
137
+ }
138
+ }
139
+ }
@@ -1,43 +1,53 @@
1
- import { createApp } from "zipaper"
1
+ import { createApp } from "zipaper";
2
2
 
3
3
  const dialogs = {
4
+ imageSize: () => import("./imageSize/index.js")
5
+ };
4
6
 
5
- // xxx
6
- xxx: () => import("./xxx/index.js")
7
- }
8
-
9
- let dialogsResolve = []
7
+ let dialogsResolve = [];
10
8
  export default {
11
9
  install(Zipaper) {
12
10
 
13
11
  // 打开弹框
14
- Zipaper.prototype.$openDialog = function (dialogName, callback) {
15
- let el = document.createElement("div")
12
+ Zipaper.prototype.$openDialog = function (dialogName, data) {
13
+ let el = document.createElement("div");
16
14
 
17
15
  dialogs[dialogName]().then(App => {
18
16
 
19
17
  // 准备好挂载点
20
- el.setAttribute("class", "content " + dialogName)
18
+ el.setAttribute("class", "content " + dialogName);
21
19
 
22
20
  // 创建并挂载
23
- document.getElementById("dialog-root").appendChild(el)
24
- createApp(App.default).mount(el)
25
- if (callback) callback()
26
- })
21
+ document.getElementById("dialog-root").appendChild(el);
22
+
23
+ if (data) {
24
+ let props = {};
25
+ for (let key in data) {
26
+ props[key] = {
27
+ default: data[key]
28
+ };
29
+ }
30
+ App.default.props = props;
31
+ } else {
32
+ App.default.props = {};
33
+ }
34
+
35
+ createApp(App.default).mount(el);
36
+ });
27
37
 
28
38
  return new Promise((resolve) => {
29
39
  dialogsResolve.push({
30
40
  resolve,
31
41
  el
32
- })
33
- })
34
- }
42
+ });
43
+ });
44
+ };
35
45
 
36
46
  // 关闭弹框
37
47
  Zipaper.prototype.$closeDialog = function (data) {
38
- let dialog = dialogsResolve.pop()
48
+ let dialog = dialogsResolve.pop();
39
49
  dialog.el.parentNode.removeChild(dialog.el);
40
- dialog.resolve(data)
41
- }
50
+ dialog.resolve(data);
51
+ };
42
52
  }
43
53
  }
@@ -12,7 +12,7 @@ export default defineElement({
12
12
  },
13
13
  created() {
14
14
 
15
- var ws = new WebSocket('ws://' + window.location.hostname + ':' + (+window.location.port + 1) + '/');
15
+ let ws = new WebSocket('ws://' + window.location.hostname + ':' + (+window.location.port + 1) + '/');
16
16
 
17
17
  // 连接成功
18
18
  ws.addEventListener('open', () => {
@@ -1,19 +1,28 @@
1
1
  <div class="image-editor-view">
2
2
  <ul class="menu">
3
3
  <li>
4
- 打开
4
+ <label for="openImage">打开</label>
5
5
  </li>
6
6
  <li>
7
- 画布大小
7
+ <label z-on:click="changeSize">画布大小</label>
8
8
  </li>
9
9
  <li>
10
- 图像大小
10
+ <label z-on:click="changeSize">图像大小</label>
11
11
  </li>
12
12
  <li>
13
- 保存
13
+ <label z-on:click="download" type="jpeg">下载JPEG</label>
14
+ </li>
15
+ <li>
16
+ <label z-on:click="download" type="png">下载PNG</label>
14
17
  </li>
15
18
  </ul>
16
19
  <div class="content">
17
- <canvas style="width:700px;height:400px"></canvas>
20
+ <div id="drawId"></div>
21
+ </div>
22
+ <div class="no-view">
23
+
24
+ <!-- 选择图片 -->
25
+ <input type="file" id="openImage" z-on:change="openImage" accept="image/*" />
26
+
18
27
  </div>
19
28
  </div>
@@ -1,18 +1,105 @@
1
- import { defineElement } from "zipaper"
2
- import template from "./index.html"
3
- import style from "./index.scss"
1
+ import { defineElement } from "zipaper";
2
+ import template from "./index.html";
3
+ import style from "./index.scss";
4
+ import { Canvas } from "vislite";
4
5
 
5
6
  export default defineElement({
6
7
  template,
7
8
  data() {
8
9
  return {
9
-
10
+ painter: null,
11
+ drawEl: null
10
12
  }
11
13
  },
14
+ created() {
15
+ this.drawEl = document.getElementById("drawId");
16
+ this.painter = new Canvas(this.drawEl, {
17
+ scale: 1
18
+ }, 700, 400);
19
+ },
12
20
  methods: {
21
+ openImage(event, target) {
22
+ let file = target.files[0];
23
+ if (file) {
24
+ let reader = new FileReader();
25
+
26
+ reader.onload = () => {
27
+ let image = new Image();
28
+
29
+ image.onload = () => {
30
+
31
+ // 调整画布大小
32
+ this.painter = new Canvas(this.drawEl, {
33
+ scale: 1
34
+ }, image.width, image.height);
35
+
36
+ // 绘制图片
37
+ this.painter.clearRect(0, 0, image.width, image.height).drawImage(image, 0, 0, image.width, image.height);
38
+ }
39
+
40
+ image.src = reader.result;
41
+ }
42
+ reader.readAsDataURL(file);
43
+ }
44
+ },
45
+ download(event, target) {
46
+ let btn = document.createElement('a');
47
+ btn.href = this.painter.__canvas.toDataURL("image/" + target.getAttribute("type"));
48
+ btn.download = "图片." + target.getAttribute("type");
49
+ btn.click();
50
+ },
51
+ changeSize(event, target) {
52
+ let canvasInfo = this.painter.getInfo();
53
+ this.$openDialog("imageSize", {
54
+ title: target.innerText.trim(),
55
+ width: canvasInfo.width,
56
+ height: canvasInfo.height
57
+ }).then(data => {
58
+ if (data) {
59
+ let base64 = this.painter.__canvas.toDataURL();
13
60
 
14
-
61
+ // 调整画布大小
62
+ this.painter = new Canvas(this.drawEl, {
63
+ scale: 1
64
+ }, data.width, data.height).clearRect(0, 0, data.width, data.height);
15
65
 
66
+ if (target.innerText.trim() === "画布大小") {
67
+
68
+ // 计算图片的对齐方式
69
+
70
+ let _left, _top;
71
+ let changeType = data.changeType.split('-');
72
+
73
+ // 水平方向
74
+ if (changeType[0] == 'left') {
75
+ _left = 0;
76
+ } else if (changeType[0] == 'right') {
77
+ _left = data.width - canvasInfo.width;
78
+ } else {
79
+ _left = (data.width - canvasInfo.width) * 0.5;
80
+ }
81
+
82
+ // 垂直方向
83
+ if (changeType[1] == 'top') {
84
+ _top = 0;
85
+ } else if (changeType[1] == 'bottom') {
86
+ _top = data.height - canvasInfo.height;
87
+ } else {
88
+ _top = (data.height - canvasInfo.height) * 0.5;
89
+ }
90
+
91
+ const img = new Image();
92
+ img.onload = () => {
93
+ this.painter.getContext().drawImage(img, 0, 0, canvasInfo.width, canvasInfo.height, _left, _top, canvasInfo.width, canvasInfo.height);
94
+ };
95
+ img.src = base64;
96
+
97
+ } else {
98
+ this.painter.drawImage(base64, 0, 0, data.width, data.height);
99
+ }
100
+ }
101
+ });
102
+ }
16
103
  },
17
104
  style: {
18
105
  content: style
@@ -4,16 +4,22 @@
4
4
  left: 50%;
5
5
  top: 5px;
6
6
  transform: translateX(-50%);
7
+ white-space: nowrap;
7
8
 
8
9
  &>li {
9
10
  display: inline-block;
10
- padding: 5px 10px;
11
- cursor: pointer;
12
11
  background-color: #FF5722;
13
12
  color: white;
14
13
  margin: 0 5px;
15
14
  border-radius: 5px;
16
15
 
16
+ &>label {
17
+ line-height: 30px;
18
+ padding: 0 5px;
19
+ display: inline-block;
20
+ cursor: pointer;
21
+ }
22
+
17
23
  &:hover {
18
24
  text-decoration: underline;
19
25
  }
@@ -24,9 +30,17 @@
24
30
  text-align: center;
25
31
  margin-top: 100px;
26
32
 
27
- canvas {
28
- background-image: url("./images/mosaic.png");
29
- outline: 2px solid #CDDC39;
33
+ #drawId {
34
+ display: inline-block;
35
+
36
+ &>canvas {
37
+ background-image: url("./images/mosaic.png");
38
+ outline: 2px solid #CDDC39;
39
+ }
30
40
  }
31
41
  }
42
+
43
+ &>.no-view {
44
+ display: none;
45
+ }
32
46
  }
@@ -1,7 +1,9 @@
1
1
  const OIPageZipaperIntercept = require("./oipage-zipaper-intercept.js");
2
+ const OIPageVISLiteIntercept = require("./oipage-vislite-intercept.js");
2
3
  const ChartIntercept = require("./chart.js");
3
4
 
4
5
  module.exports = [
5
6
  OIPageZipaperIntercept,
7
+ OIPageVISLiteIntercept,
6
8
  ChartIntercept
7
9
  ];
@@ -0,0 +1,34 @@
1
+ const { readFileSync } = require("fs");
2
+ const { join } = require("path");
3
+ const headFactory = require("./head.js");
4
+
5
+ const head = headFactory();
6
+
7
+ // VISLite库
8
+ module.exports = {
9
+ test: /^vislite$/,
10
+ handler(request, response) {
11
+ head["Content-Type"] = "application/javascript;charset=utf-8";
12
+ head["ETag"] = "VISLite@v" + require("vislite/package.json").version;
13
+
14
+ if (request.headers["if-none-match"] === head["ETag"]) {
15
+ response.writeHead('304', head);
16
+ response.end();
17
+ console.log("<i> \x1b[1m\x1b[32m[OIPage-dev-server] Cache File: VISLite\x1b[0m " + new Date().toLocaleString() + "\x1b[33m\x1b[1m 304\x1b[0m");;
18
+ return;
19
+ }
20
+
21
+ response.writeHead(200, head);
22
+
23
+ let source = readFileSync(join(__dirname, "../../../node_modules/vislite/lib/index.umd.min.js"), {
24
+ encoding: "utf8"
25
+ });
26
+
27
+ response.write(`let module = { exports: {} };
28
+ let exports = module.exports;
29
+ ${source}
30
+ export let Canvas = module.exports.Canvas;
31
+ `);
32
+ response.end();
33
+ }
34
+ };
@@ -24,7 +24,7 @@ module.exports = {
24
24
  encoding: "utf8"
25
25
  });
26
26
 
27
- response.write(`let module = { exports: {}};
27
+ response.write(`let module = { exports: {} };
28
28
  let exports = module.exports;
29
29
  ${source}
30
30
  export let createApp = exports.createApp;
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * animation of OIPage v1.5.0-alpha.0
2
+ * animation of OIPage v1.5.0-alpha.1
3
3
  * git+https://github.com/oi-contrib/OIPage.git
4
4
  */
5
5
 
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * cmdlog of OIPage v1.5.0-alpha.0
2
+ * cmdlog of OIPage v1.5.0-alpha.1
3
3
  * git+https://github.com/oi-contrib/OIPage.git
4
4
  */
5
5
 
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * disk of OIPage v1.5.0-alpha.0
2
+ * disk of OIPage v1.5.0-alpha.1
3
3
  * git+https://github.com/oi-contrib/OIPage.git
4
4
  */
5
5
 
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * format of OIPage v1.5.0-alpha.0
2
+ * format of OIPage v1.5.0-alpha.1
3
3
  * git+https://github.com/oi-contrib/OIPage.git
4
4
  */
5
5
 
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * json of OIPage v1.5.0-alpha.0
2
+ * json of OIPage v1.5.0-alpha.1
3
3
  * git+https://github.com/oi-contrib/OIPage.git
4
4
  */
5
5
  const {reader} = require("../reader/index.js");
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * logform of OIPage v1.5.0-alpha.0
2
+ * logform of OIPage v1.5.0-alpha.1
3
3
  * git+https://github.com/oi-contrib/OIPage.git
4
4
  */
5
5
  const {linelog} = require("../cmdlog/index.js");
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * reader of OIPage v1.5.0-alpha.0
2
+ * reader of OIPage v1.5.0-alpha.1
3
3
  * git+https://github.com/oi-contrib/OIPage.git
4
4
  */
5
5
 
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * throttle of OIPage v1.5.0-alpha.0
2
+ * throttle of OIPage v1.5.0-alpha.1
3
3
  * git+https://github.com/oi-contrib/OIPage.git
4
4
  */
5
5
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "oipage",
3
- "version": "1.5.0-alpha.0",
3
+ "version": "1.5.0-alpha.1",
4
4
  "description": "前端网页或应用快速开发助手,包括开发服务器、辅助命令、实用API等",
5
5
  "sideEffects": false,
6
6
  "scripts": {
@@ -35,7 +35,7 @@
35
35
  },
36
36
  "homepage": "https://oi-contrib.github.io/OIPage",
37
37
  "dependencies": {
38
- "vislite": "^1.4.0",
38
+ "vislite": "^1.5.0",
39
39
  "xhtml-to-json": "^0.1.0",
40
40
  "zipaper": "^0.2.0"
41
41
  }
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * XMLHttpRequest of OIPage v1.5.0-alpha.0
2
+ * XMLHttpRequest of OIPage v1.5.0-alpha.1
3
3
  * git+https://github.com/oi-contrib/OIPage.git
4
4
  */
5
5
 
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * animation of OIPage v1.5.0-alpha.0
2
+ * animation of OIPage v1.5.0-alpha.1
3
3
  * git+https://github.com/oi-contrib/OIPage.git
4
4
  */
5
5
 
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * format of OIPage v1.5.0-alpha.0
2
+ * format of OIPage v1.5.0-alpha.1
3
3
  * git+https://github.com/oi-contrib/OIPage.git
4
4
  */
5
5
 
package/web/json/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * json of OIPage v1.5.0-alpha.0
2
+ * json of OIPage v1.5.0-alpha.1
3
3
  * git+https://github.com/oi-contrib/OIPage.git
4
4
  */
5
5
  import {reader} from "../reader/index.js";
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * onReady of OIPage v1.5.0-alpha.0
2
+ * onReady of OIPage v1.5.0-alpha.1
3
3
  * git+https://github.com/oi-contrib/OIPage.git
4
4
  */
5
5
 
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * performChunk of OIPage v1.5.0-alpha.0
2
+ * performChunk of OIPage v1.5.0-alpha.1
3
3
  * git+https://github.com/oi-contrib/OIPage.git
4
4
  */
5
5
 
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * reader of OIPage v1.5.0-alpha.0
2
+ * reader of OIPage v1.5.0-alpha.1
3
3
  * git+https://github.com/oi-contrib/OIPage.git
4
4
  */
5
5
 
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * style of OIPage v1.5.0-alpha.0
2
+ * style of OIPage v1.5.0-alpha.1
3
3
  * git+https://github.com/oi-contrib/OIPage.git
4
4
  */
5
5
 
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * throttle of OIPage v1.5.0-alpha.0
2
+ * throttle of OIPage v1.5.0-alpha.1
3
3
  * git+https://github.com/oi-contrib/OIPage.git
4
4
  */
5
5