From 121b4da0df6da2633970e5f414f86610edf9e419 Mon Sep 17 00:00:00 2001 From: mohuishou <1@lailin.xyz> Date: Fri, 29 Jun 2018 15:24:51 +0800 Subject: [PATCH] init --- .babelrc | 3 + .gitignore | 2 + dist/schedule.js | 366 ++++++++++++++++++++++++ example/app.js | 5 + example/app.json | 11 + example/app.wxss | 0 example/index.js | 251 ++++++++++++++++ example/index/index.js | 29 ++ example/index/index.wxml | 4 + example/index/index.wxss | 30 ++ example/project.config.json | 35 +++ example/schedule.js | 350 +++++++++++++++++++++++ img/example.png | Bin 0 -> 18595 bytes index.js | 318 +++++++++++++++++++++ package.json | 20 ++ readme.md | 107 +++++++ yarn.lock | 550 ++++++++++++++++++++++++++++++++++++ 17 files changed, 2081 insertions(+) create mode 100644 .babelrc create mode 100644 .gitignore create mode 100644 dist/schedule.js create mode 100644 example/app.js create mode 100644 example/app.json create mode 100644 example/app.wxss create mode 100644 example/index.js create mode 100644 example/index/index.js create mode 100644 example/index/index.wxml create mode 100644 example/index/index.wxss create mode 100644 example/project.config.json create mode 100644 example/schedule.js create mode 100644 img/example.png create mode 100644 index.js create mode 100644 package.json create mode 100644 readme.md create mode 100644 yarn.lock diff --git a/.babelrc b/.babelrc new file mode 100644 index 0000000..379bbd6 --- /dev/null +++ b/.babelrc @@ -0,0 +1,3 @@ +{ + "presets": ["env"] +} \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..74ff24f --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +node_modules +*.log \ No newline at end of file diff --git a/dist/schedule.js b/dist/schedule.js new file mode 100644 index 0000000..9769a1c --- /dev/null +++ b/dist/schedule.js @@ -0,0 +1,366 @@ +"use strict"; + +Object.defineProperty(exports, "__esModule", { + value: true +}); + +var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); + +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + +var days = ["一", "二", "三", "四", "五", "六", "日"]; +var dayMap = { + 1: "一", + 2: "二", + 3: "三", + 4: "四", + 5: "五", + 6: "六", + 7: "日" +}; +var firstColWidth = 25; +var header = { + size: 10, + height: 50, + bg: "#f5f5f5", + color: "#555", + lineColor: "#d0d0d0" +}; +var colHeader = { + size: 10, + width: 25, + bg: "#f5f5f5", + color: "#555", + lineColor: "#d0d0d0" +}; +var courseStyle = { + color: "#fff", + size: 10, + top: 5 + // title set +};var titleStyle = { + size: 20, + height: 50, + color: "#000", + bg: "#f5f5f5" +}; +/** + * 微信小程序Canvas课程表,用于展示或者是分享图 + * @class Schdule + */ + +var Schedule = function () { + /** + * 对象初始化 + * @param {Object} options 参数 + */ + function Schedule(options) { + var _this = this; + + _classCallCheck(this, Schedule); + + // 必要参数,canvas id,长宽 + ["id", "width", "height"].forEach(function (e) { + _this.optionCheck(e, options); + }, this); + + this.title = options.title || ''; + + // 不必要参数 + // 日期 + this.days = options.days || days; + + // 标题,第一列,第一行样式设置 + this.titleStyle = options.titleStyle || titleStyle; + this.colHeader = options.colHeader || colHeader; + this.header = options.header || header; + + // 一天多少节课 + this.sessions = options.sessions || 13; + + // 课程宽度 + this.courseWidth = options.courseWidth || (this.width - this.colHeader.width) / this.days.length; + if (options.courseHeight) { + this.courseHeight = options.courseHeight; + } else if (this.title != '') { + this.courseHeight = (this.height - this.titleStyle.height - this.header.height) / this.sessions; + } else { + this.courseHeight = (this.height - this.header.height) / this.sessions; + } + + // 设置首行文字大小 + if (!('header' in options) || !options.header) { + this.header = header; + this.header.size = this.courseWidth / 2 - 10; + } + // 课程样式 + this.courseStyle = options.courseStyle || courseStyle; + + // 获取canvas对象 + this.ctx = wx.createCanvasContext(this.id); + + // + this.startY = 0; + + // + this.options = options; + } + + /** + * 参数校验 + * @param {String} props 属性 + * @param {Object} option 参数 + */ + + + _createClass(Schedule, [{ + key: "optionCheck", + value: function optionCheck(props, option) { + if (!(props in option)) { + console.error("缺少" + props); + throw "缺少" + props; + } + this[props] = option[props]; + } + + /** + * 绘制课程表 + * courses = [ + * { + * name: '', // 课程名, + * address: '', // 课程地址, + * bg: '#000', //课程背景色, + * sessionArr: [1,2,3], // 上课节次 + * day: 1, // 周几上课 + * } + * ] + * @param {Array} courses 课程表 + */ + + }, { + key: "drawSchedule", + value: function drawSchedule(courses) { + var _this2 = this; + + var ctx = this.ctx; + if (this.title) { + this.drawTitle(); + } + + // 绘制第一行 + this.drawHeader(); + this.startY += this.header.height; + + // 第一列 + this.drawFirstCol(); + + // 获得课程,绘制课程 + courses.forEach(function (course) { + _this2.drawCourse(course); + }); + + ctx.draw(); + } + + /** + * 保存临时图片到相册 + * @param {String} path + */ + + }, { + key: "saveImage", + value: function saveImage(path) { + return new Promise(function (resolve, reject) { + wx.saveImageToPhotosAlbum({ + filePath: path, + success: function success(res) { + return resolve(res); + }, + fail: function fail(res) { + return reject(res); + } + }); + }); + } + + /** + * canvas 转临时图片 + * @return path + */ + + }, { + key: "canvasToImg", + value: function canvasToImg() { + var id = this.id; + return new Promise(function (resolve, reject) { + wx.canvasToTempFilePath({ + canvasId: id, + success: function success(res) { + return resolve(res.tempFilePath); + }, + fail: function fail(res) { + return reject(res); + } + }); + }); + } + }, { + key: "drawTitle", + value: function drawTitle() { + var ctx = this.ctx; + // 绘制标题 + ctx.setFillStyle(this.header.bg); + ctx.fillRect(0, 0, this.width, this.titleStyle.height); + ctx.beginPath(); + ctx.moveTo(0, this.titleStyle.height); + ctx.lineTo(this.width, this.titleStyle.height); + ctx.setStrokeStyle(this.header.lineColor); + ctx.stroke(); + ctx.closePath(); + this.drawText(ctx, this.title, (this.width - this.courseWidth) / 2, this.startY, 20, titleStyle); + this.startY += this.titleStyle.height; + } + + /** + * 绘制背景色 + * @param {String} bg 背景色 + */ + + }, { + key: "drawBg", + value: function drawBg() { + var bg = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "#f8f8f5"; + + this.ctx.rect(0, 0, this.width, this.height); + this.ctx.setFillStyle(bg); + this.ctx.fill(); + } + + /** + * 绘制首行 + */ + + }, { + key: "drawHeader", + value: function drawHeader() { + var ctx = this.ctx; + ctx.setFillStyle(this.header.bg); + ctx.fillRect(0, this.startY, this.width, this.header.height); + ctx.setStrokeStyle(this.header.lineColor); + ctx.setLineWidth(1); + ctx.setTextAlign("center"); + ctx.setFillStyle(this.header.color); + ctx.setFontSize(this.header.size); + for (var i = 0; i < this.days.length; i++) { + ctx.beginPath(); + ctx.moveTo(this.colHeader.width + i * this.courseWidth, this.startY); + ctx.lineTo(this.colHeader.width + i * this.courseWidth, this.startY + this.header.height); + ctx.stroke(); + ctx.closePath(); + ctx.fillText("周" + days[i], this.colHeader.width + this.courseWidth / 2 + i * this.courseWidth, this.startY + (this.header.height + this.header.size) / 2); + } + } + + /** + * 绘制第一列 + */ + + }, { + key: "drawFirstCol", + value: function drawFirstCol() { + var ctx = this.ctx; + ctx.setFillStyle(this.header.bg); + ctx.fillRect(0, this.startY, this.colHeader.width, this.height); + ctx.setStrokeStyle(this.header.lineColor); + ctx.setLineWidth(1); + ctx.setTextAlign("center"); + ctx.setFillStyle(this.header.color); + ctx.setFontSize(this.header.size); + for (var i = 0; i <= this.sessions; i++) { + ctx.beginPath(); + ctx.moveTo(0, this.courseHeight * i + this.startY); + ctx.lineTo(this.colHeader.width, this.courseHeight * i + this.startY); + ctx.stroke(); + ctx.closePath(); + if (i == this.sessions) continue; + ctx.fillText(i + 1, this.colHeader.width / 2, this.courseHeight * (i + 0.5) + this.startY + this.header.size / 2); + } + } + /** + * 绘制课程 + * @param {Object} course 课程 + */ + + }, { + key: "drawCourse", + value: function drawCourse(course) { + var ctx = this.ctx; + // 定位 + var x = this.colHeader.width + this.getCourseDayX(course.day) * this.courseWidth; + var y = (course.sessionArr[0] - 1) * this.courseHeight + this.startY; + ctx.setFillStyle(course.bg); + // 绘制背景 + ctx.fillRect(x, y, this.courseWidth, this.courseHeight * course.sessionArr.length); + // 绘制文字 + y = y + this.courseStyle.top; + y = this.drawText(ctx, course.name, x, y, 4, this.courseStyle); + this.drawText(ctx, "@" + course.address, x, y, 4, this.courseStyle); + } + /** + * 获取课程的偏移位置 + * @param {Number} day 周几,1 = 周一 + */ + + }, { + key: "getCourseDayX", + value: function getCourseDayX(day) { + for (var i = 0; i < this.days.length; i++) { + if (this.days[i] === dayMap[day]) { + return i; + } + } + throw "课程时间和设置不匹配!"; + } + }, { + key: "drawText", + value: function drawText(ctx, str, x, y, len, style) { + str = str.trim(); + ctx.setFillStyle(style.color); + ctx.setTextAlign("center"); + ctx.setFontSize(style.size); + for (var i = 0; i < str.length / len; i++) { + y = y + style.size * 1.5; + ctx.fillText(str.substr(i * len, len), x + this.courseWidth / 2, y); + } + return y; + } + }, { + key: "download", + value: function download(url) { + return new Promise(function (resolve, reject) { + wx.downloadFile({ + url: url, + success: function success(res) { + if (res.statusCode === 200) { + resolve(res.tempFilePath); + } else { + reject(res); + } + }, + fail: function fail(res) { + return reject(res); + } + }); + }); + } + }, { + key: "log", + value: function log() { + console.log(this.options); + } + }]); + + return Schedule; +}(); + +exports.default = Schedule; diff --git a/example/app.js b/example/app.js new file mode 100644 index 0000000..a0f82cf --- /dev/null +++ b/example/app.js @@ -0,0 +1,5 @@ +App({ + onLaunch: function () { + + } +}) diff --git a/example/app.json b/example/app.json new file mode 100644 index 0000000..7502597 --- /dev/null +++ b/example/app.json @@ -0,0 +1,11 @@ +{ + "pages":[ + "index/index" + ], + "window":{ + "backgroundTextStyle":"light", + "navigationBarBackgroundColor": "#fff", + "navigationBarTitleText": "WeChat", + "navigationBarTextStyle":"black" + } +} diff --git a/example/app.wxss b/example/app.wxss new file mode 100644 index 0000000..e69de29 diff --git a/example/index.js b/example/index.js new file mode 100644 index 0000000..6d654bb --- /dev/null +++ b/example/index.js @@ -0,0 +1,251 @@ +const days = ["一", "二", "三", "四", "五", "六", "日"]; +const dayMap = { + 1: "一", + 2: "二", + 3: "三", + 4: "四", + 5: "五", + 6: "六", + 7: "日" +}; +const firstColWidth = 25 +const header = { + size: 10, + height: 50, + bg: "#f5f5f5", + color: "#555", + lineColor: "#d0d0d0" +}; +const colHeader = { + size: 10, + width: 25, + bg: "#f5f5f5", + color: "#555", + lineColor: "#d0d0d0" +} +const courseStyle = { + color: "#fff", + size: 10, + top: 5 +} +// title set +const titleStyle = { + size: 20, + height: 50, + color: "#000", + bg: "#f5f5f5" +}; +/** + * 微信小程序Canvas课程表,用于展示或者是分享图 + * @class Schdule + */ +export default class Schedule { + /** + * 对象初始化 + * @param {Object} options 参数 + */ + constructor(options) { + // 必要参数,canvas id,长宽 + ["id", "width", "height"].forEach(e => { + this.optionCheck(e, options) + }, this) + + // 不必要参数 + // 日期 + this.days = options.days || days + + // 标题,第一列,第一行样式设置 + this.titleStyle = options.titleStyle || titleStyle + this.colHeader = options.colHeader || colHeader + this.header = options.header + + // 课程宽度 + this.courseWidth = options.courseWidth || ((this.width - this.colHeader.width) / this.days.length) + this.courseHeight = options.courseHeight || ((this.height - this.header.height) / this.days.length) + // 设置首行文字大小 + if (!('header' in options) || !options.header) { + this.header = header + this.header.size = this.courseWidth / 2 - 10 + } + // 课程样式 + this.courseStyle = options.courseStyle || courseStyle + + // 一天多少节课 + this.sessions = options.sessions || 13 + + // 获取canvas对象 + this.ctx = wx.createCanvasContext(this.id); + + // + this.startY = 0 + + // + this.options = options + } + + /** + * 参数校验 + * @param {String} props 属性 + * @param {Object} option 参数 + */ + optionCheck(props, option) { + if (!(props in option)) { + throw "缺少" + props + } + this[props] = option[props] + } + + /** + * 保存临时图片到相册 + * @param {String} path + */ + saveImage(path) { + return new Promise((resolve, reject) => { + wx.saveImageToPhotosAlbum({ + filePath: path, + success: res => resolve(res), + fail: res => reject(res) + }); + }); + } + + /** + * canvas 转临时图片 + */ + canvasToImg() { + let id = this.id + return new Promise((resolve, reject) => { + wx.canvasToTempFilePath({ + canvasId: id, + success: res => resolve(res.tempFilePath), + fail: res => reject(res) + }); + }); + } + + /** + * 绘制背景色 + * @param {String} bg 背景色 + */ + drawBg(bg = "#f8f8f5") { + this.ctx.rect(0, 0, this.width, height); + this.ctx.setFillStyle(bg); + this.ctx.fill(); + } + + /** + * 绘制首行 + */ + drawHeader() { + const ctx = this.ctx + ctx.setFillStyle(this.header.bg); + ctx.fillRect(0, this.startY, this.width, this.header.height); + ctx.setStrokeStyle(this.header.lineColor); + ctx.setLineWidth(1); + ctx.setTextAlign("center"); + ctx.setFillStyle(this.header.color); + ctx.setFontSize(this.header.size); + for (let i = 0; i < this.days.length; i++) { + ctx.beginPath(); + ctx.moveTo(this.colHeader.width + i * this.courseWidth, this.startY); + ctx.lineTo(this.colHeader.width + i * this.courseWidth, this.startY + this.header.height); + ctx.stroke(); + ctx.closePath(); + ctx.fillText( + "周" + days[i], + (this.header.width + this.colHeader.width) / 2 + i * this.courseWidth, + this.startY + (this.header.height + this.header.size) / 2 + ); + } + } + + /** + * 绘制第一列 + */ + drawFirstCol() { + const ctx = this.ctx + ctx.setFillStyle(this.header.bg); + ctx.fillRect(0, this.startY, this.colHeader.width, this.height); + ctx.setStrokeStyle(this.header.lineColor); + ctx.setLineWidth(1); + ctx.setTextAlign("center"); + ctx.setFillStyle(this.header.color); + ctx.setFontSize(this.header.size); + for (let i = 0; i <= this.sessions; i++) { + ctx.beginPath(); + ctx.moveTo(0, this.courseHeight * i + this.startY); + ctx.lineTo(this.colHeader.width, this.courseHeight * i + this.startY); + ctx.stroke(); + ctx.closePath(); + if (i == this.sessions) continue; + ctx.fillText( + i + 1, + this.colHeader.width / 2, + this.courseHeight * (i + 0.5) + this.startY + this.header.size / 2 + ); + } + } + /** + * 绘制课程 + * @param {Object} course 课程 + */ + drawCourse(course) { + const ctx = this.ctx + // 定位 + let x = this.colHeader.width + this.getCourseDayX(course.day) * this.courseWidth; + let y = (course.sessionArr[0] - 1) * this.courseHeight + this.startY; + ctx.setFillStyle(course.bg_color); + // 绘制背景 + ctx.fillRect(x, y, this.courseWidth, this.courseHeight * course.sessionArr.length); + // 绘制文字 + y = y + this.courseStyle.top; + y = this.drawText(ctx, course.course_name, x, y, 4, this.courseStyle); + this.drawText(ctx, "@" + course.address, x, y, 4, this.courseStyle); + } + /** + * 获取课程的偏移位置 + * @param {Number} day 周几,1 = 周一 + */ + getCourseDayX(day) { + for (let i = 0; i < this.days.length; i++) { + if (this.days[i] === dayMap[day]) { + return i + } + } + throw "课程时间和设置不匹配!" + } + drawText(ctx, str, x, y, len, style) { + str = str.trim(); + ctx.setFillStyle(style.color); + ctx.setTextAlign("center"); + ctx.setFontSize(style.size); + for (let i = 0; i < str.length / len; i++) { + y = y + style.size * 1.5; + ctx.fillText( + str.substr(i * len, len), + x + this.courseWidth / 2, + y + ); + } + return y; + } + download(url) { + return new Promise((resolve, reject) => { + wx.downloadFile({ + url: url, + success: res => { + if (res.statusCode === 200) { + resolve(res.tempFilePath); + } else { + reject(res); + } + }, + fail: res => reject(res) + }); + }); + } + + log() { + console.log(this.options) + } +} \ No newline at end of file diff --git a/example/index/index.js b/example/index/index.js new file mode 100644 index 0000000..bdaafec --- /dev/null +++ b/example/index/index.js @@ -0,0 +1,29 @@ +const app = getApp() +import Schedule from "../schedule.js" +let s +Page({ + data: {}, + save() { + s.canvasToImg().then(path => { + s.saveImage(path) + }) + }, + onLoad: function () { + s = new Schedule({ + id: "schedule", + width: 375, + height: 1000, + title: "测试课程表" + }) + s.drawBg() + s.drawSchedule([{ + day: 1, + sessionArr: [1, 2, 3], + address: "lalalal", + name: "测试课程", + bg: "#f07c82" + }]) + console.log('代码片段是一种迷你、可分享的小程序或小游戏项目,可用于分享小程序和小游戏的开发经验、展示组件和 API 的使用、复现开发问题和 Bug 等。可点击以下链接查看代码片段的详细文档:') + console.log('https://mp.weixin.qq.com/debug/wxadoc/dev/devtools/devtools.html') + }, +}) \ No newline at end of file diff --git a/example/index/index.wxml b/example/index/index.wxml new file mode 100644 index 0000000..adeac34 --- /dev/null +++ b/example/index/index.wxml @@ -0,0 +1,4 @@ + + + 保存图片 + \ No newline at end of file diff --git a/example/index/index.wxss b/example/index/index.wxss new file mode 100644 index 0000000..83e26fe --- /dev/null +++ b/example/index/index.wxss @@ -0,0 +1,30 @@ +page { + padding-bottom: 80rpx; +} +canvas { + width: 100%; + height: 1000px; +} +.mo-btn { + border-radius: 0; + width: 100%; + height: 80rpx; + display: inline-flex; + align-items: center; + justify-content: center; + background: linear-gradient(90deg, #f06292, #ed5a65); + color: #fff; + font-size: 28rpx; +} +.op { + position: fixed; + bottom: 0; + width: 100%; + display: flex; + background: #f06292; + +} +.op .item { + text-align: center; + flex: 1; +} \ No newline at end of file diff --git a/example/project.config.json b/example/project.config.json new file mode 100644 index 0000000..a6f7888 --- /dev/null +++ b/example/project.config.json @@ -0,0 +1,35 @@ +{ + "description": "项目配置文件。", + "packOptions": { + "ignore": [] + }, + "setting": { + "urlCheck": true, + "es6": true, + "postcss": true, + "minified": true, + "newFeature": true + }, + "compileType": "miniprogram", + "libVersion": "2.1.1", + "appid": "touristappid", + "projectname": "wxapp-schedule-example", + "condition": { + "search": { + "current": -1, + "list": [] + }, + "conversation": { + "current": -1, + "list": [] + }, + "game": { + "currentL": -1, + "list": [] + }, + "miniprogram": { + "current": -1, + "list": [] + } + } +} \ No newline at end of file diff --git a/example/schedule.js b/example/schedule.js new file mode 100644 index 0000000..fd6b717 --- /dev/null +++ b/example/schedule.js @@ -0,0 +1,350 @@ +"use strict"; + +Object.defineProperty(exports, "__esModule", { + value: true +}); + +var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); + +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + +var days = ["一", "二", "三", "四", "五", "六", "日"]; +var dayMap = { + 1: "一", + 2: "二", + 3: "三", + 4: "四", + 5: "五", + 6: "六", + 7: "日" +}; +var firstColWidth = 25; +var header = { + size: 10, + height: 50, + bg: "#f5f5f5", + color: "#555", + lineColor: "#d0d0d0" +}; +var colHeader = { + size: 10, + width: 25, + bg: "#f5f5f5", + color: "#555", + lineColor: "#d0d0d0" +}; +var courseStyle = { + color: "#fff", + size: 10, + top: 5 + // title set +};var titleStyle = { + size: 20, + height: 50, + color: "#000", + bg: "#f5f5f5" +}; +/** + * 微信小程序Canvas课程表,用于展示或者是分享图 + * @class Schdule + */ + +var Schedule = function () { + /** + * 对象初始化 + * @param {Object} options 参数 + */ + function Schedule(options) { + var _this = this; + + _classCallCheck(this, Schedule); + + // 必要参数,canvas id,长宽 + ["id", "width", "height"].forEach(function (e) { + _this.optionCheck(e, options); + }, this); + + this.title = options.title || ''; + + // 不必要参数 + // 日期 + this.days = options.days || days; + + // 标题,第一列,第一行样式设置 + this.titleStyle = options.titleStyle || titleStyle; + this.colHeader = options.colHeader || colHeader; + this.header = options.header || header; + + // 一天多少节课 + this.sessions = options.sessions || 13; + + // 课程宽度 + this.courseWidth = options.courseWidth || (this.width - this.colHeader.width) / this.days.length; + if (options.courseHeight) { + this.courseHeight = options.courseHeight; + } else if (this.title != '') { + this.courseHeight = (this.height - this.titleStyle.height - this.header.height) / this.sessions; + } else { + this.courseHeight = (this.height - this.header.height) / this.sessions; + } + + // 设置首行文字大小 + if (!('header' in options) || !options.header) { + this.header = header; + this.header.size = this.courseWidth / 2 - 10; + } + // 课程样式 + this.courseStyle = options.courseStyle || courseStyle; + + // 获取canvas对象 + this.ctx = wx.createCanvasContext(this.id); + + // + this.startY = 0; + + // + this.options = options; + } + + /** + * 参数校验 + * @param {String} props 属性 + * @param {Object} option 参数 + */ + + + _createClass(Schedule, [{ + key: "optionCheck", + value: function optionCheck(props, option) { + if (!(props in option)) { + console.error("缺少" + props); + throw "缺少" + props; + } + this[props] = option[props]; + } + }, { + key: "drawSchedule", + value: function drawSchedule(courses) { + var _this2 = this; + + var ctx = this.ctx; + if (this.title) { + this.drawTitle(); + } + + // 绘制第一行 + this.drawHeader(); + this.startY += this.header.height; + + // 第一列 + this.drawFirstCol(); + + // 获得课程,绘制课程 + courses.forEach(function (course) { + _this2.drawCourse(course); + }); + + ctx.draw(); + } + + /** + * 保存临时图片到相册 + * @param {String} path + */ + + }, { + key: "saveImage", + value: function saveImage(path) { + return new Promise(function (resolve, reject) { + wx.saveImageToPhotosAlbum({ + filePath: path, + success: function success(res) { + return resolve(res); + }, + fail: function fail(res) { + return reject(res); + } + }); + }); + } + + /** + * canvas 转临时图片 + */ + + }, { + key: "canvasToImg", + value: function canvasToImg() { + var id = this.id; + return new Promise(function (resolve, reject) { + wx.canvasToTempFilePath({ + canvasId: id, + success: function success(res) { + return resolve(res.tempFilePath); + }, + fail: function fail(res) { + return reject(res); + } + }); + }); + } + }, { + key: "drawTitle", + value: function drawTitle() { + var ctx = this.ctx; + // 绘制标题 + ctx.setFillStyle(this.header.bg); + ctx.fillRect(0, 0, this.width, this.titleStyle.height); + ctx.beginPath(); + ctx.moveTo(0, this.titleStyle.height); + ctx.lineTo(this.width, this.titleStyle.height); + ctx.setStrokeStyle(this.header.lineColor); + ctx.stroke(); + ctx.closePath(); + this.drawText(ctx, this.title, (this.width - this.courseWidth) / 2, this.startY, 20, titleStyle); + this.startY += this.titleStyle.height; + } + + /** + * 绘制背景色 + * @param {String} bg 背景色 + */ + + }, { + key: "drawBg", + value: function drawBg() { + var bg = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "#f8f8f5"; + + this.ctx.rect(0, 0, this.width, this.height); + this.ctx.setFillStyle(bg); + this.ctx.fill(); + } + + /** + * 绘制首行 + */ + + }, { + key: "drawHeader", + value: function drawHeader() { + var ctx = this.ctx; + ctx.setFillStyle(this.header.bg); + ctx.fillRect(0, this.startY, this.width, this.header.height); + ctx.setStrokeStyle(this.header.lineColor); + ctx.setLineWidth(1); + ctx.setTextAlign("center"); + ctx.setFillStyle(this.header.color); + ctx.setFontSize(this.header.size); + for (var i = 0; i < this.days.length; i++) { + ctx.beginPath(); + ctx.moveTo(this.colHeader.width + i * this.courseWidth, this.startY); + ctx.lineTo(this.colHeader.width + i * this.courseWidth, this.startY + this.header.height); + ctx.stroke(); + ctx.closePath(); + ctx.fillText("周" + days[i], this.colHeader.width + this.courseWidth / 2 + i * this.courseWidth, this.startY + (this.header.height + this.header.size) / 2); + } + } + + /** + * 绘制第一列 + */ + + }, { + key: "drawFirstCol", + value: function drawFirstCol() { + var ctx = this.ctx; + ctx.setFillStyle(this.header.bg); + ctx.fillRect(0, this.startY, this.colHeader.width, this.height); + ctx.setStrokeStyle(this.header.lineColor); + ctx.setLineWidth(1); + ctx.setTextAlign("center"); + ctx.setFillStyle(this.header.color); + ctx.setFontSize(this.header.size); + for (var i = 0; i <= this.sessions; i++) { + ctx.beginPath(); + ctx.moveTo(0, this.courseHeight * i + this.startY); + ctx.lineTo(this.colHeader.width, this.courseHeight * i + this.startY); + ctx.stroke(); + ctx.closePath(); + if (i == this.sessions) continue; + ctx.fillText(i + 1, this.colHeader.width / 2, this.courseHeight * (i + 0.5) + this.startY + this.header.size / 2); + } + } + /** + * 绘制课程 + * @param {Object} course 课程 + */ + + }, { + key: "drawCourse", + value: function drawCourse(course) { + var ctx = this.ctx; + // 定位 + var x = this.colHeader.width + this.getCourseDayX(course.day) * this.courseWidth; + var y = (course.sessionArr[0] - 1) * this.courseHeight + this.startY; + ctx.setFillStyle(course.bg); + // 绘制背景 + ctx.fillRect(x, y, this.courseWidth, this.courseHeight * course.sessionArr.length); + // 绘制文字 + y = y + this.courseStyle.top; + y = this.drawText(ctx, course.name, x, y, 4, this.courseStyle); + this.drawText(ctx, "@" + course.address, x, y, 4, this.courseStyle); + } + /** + * 获取课程的偏移位置 + * @param {Number} day 周几,1 = 周一 + */ + + }, { + key: "getCourseDayX", + value: function getCourseDayX(day) { + for (var i = 0; i < this.days.length; i++) { + if (this.days[i] === dayMap[day]) { + return i; + } + } + throw "课程时间和设置不匹配!"; + } + }, { + key: "drawText", + value: function drawText(ctx, str, x, y, len, style) { + str = str.trim(); + ctx.setFillStyle(style.color); + ctx.setTextAlign("center"); + ctx.setFontSize(style.size); + for (var i = 0; i < str.length / len; i++) { + y = y + style.size * 1.5; + ctx.fillText(str.substr(i * len, len), x + this.courseWidth / 2, y); + } + return y; + } + }, { + key: "download", + value: function download(url) { + return new Promise(function (resolve, reject) { + wx.downloadFile({ + url: url, + success: function success(res) { + if (res.statusCode === 200) { + resolve(res.tempFilePath); + } else { + reject(res); + } + }, + fail: function fail(res) { + return reject(res); + } + }); + }); + } + }, { + key: "log", + value: function log() { + console.log(this.options); + } + }]); + + return Schedule; +}(); + +exports.default = Schedule; diff --git a/img/example.png b/img/example.png new file mode 100644 index 0000000000000000000000000000000000000000..bc1de63e681887a9dd402556eeee8e01e2e90b2e GIT binary patch literal 18595 zcmeHv2~<;Awl*LXlM0H069kJAR6tZzl-a3JnN%hPNl+9-z(fWaLI@~GDGDkIA_7uO zGDbikfFTGfDwBd?%0xhg1V}^@0trd}bE&HC>VNfHZ@uo<@4fD>TFX_gn|sea_nf`= z_w8@*SKfV24~_BId)<^EzA9wYP3R z5fdkSzNuMb>_UH{;=Ne^V8-zeYuydI->-TZuT(=0v|#Sa3sKCpKecAvo89&gbjxv_ zi6fkKRva^2p`~Q53*peHpsH={<)LV&$Pe7< zsIfmrDmE(y6{Z7SU8|(P58UmXb|6Mdn!(o6wvK7qwL+CmMm^bbT}oP}nQCDTZV%k3 zO{rxZ^;|A3BOBL%2KUO4k6PoAEjjf+$jB-vgz>=@*_xaf6#d%%(8IC{s;X=@xS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P#a) zrwG7&wz8=y8MZ3nUSRsAji&MdW&YI&@!y>lc(LB;s7q@B%W literal 0 HcmV?d00001 diff --git a/index.js b/index.js new file mode 100644 index 0000000..a7311ba --- /dev/null +++ b/index.js @@ -0,0 +1,318 @@ +const days = ["一", "二", "三", "四", "五", "六", "日"]; +const dayMap = { + 1: "一", + 2: "二", + 3: "三", + 4: "四", + 5: "五", + 6: "六", + 7: "日" +}; +const firstColWidth = 25 +const header = { + size: 10, + height: 50, + bg: "#f5f5f5", + color: "#555", + lineColor: "#d0d0d0" +}; +const colHeader = { + size: 10, + width: 25, + bg: "#f5f5f5", + color: "#555", + lineColor: "#d0d0d0" +} +const courseStyle = { + color: "#fff", + size: 10, + top: 5 +} +// title set +const titleStyle = { + size: 20, + height: 50, + color: "#000", + bg: "#f5f5f5" +}; +/** + * 微信小程序Canvas课程表,用于展示或者是分享图 + * @class Schdule + */ +export default class Schedule { + /** + * 对象初始化 + * @param {Object} options 参数 + */ + constructor(options) { + // 必要参数,canvas id,长宽 + ["id", "width", "height"].forEach(e => { + this.optionCheck(e, options) + }, this) + + this.title = options.title || '' + + // 不必要参数 + // 日期 + this.days = options.days || days + + // 标题,第一列,第一行样式设置 + this.titleStyle = options.titleStyle || titleStyle + this.colHeader = options.colHeader || colHeader + this.header = options.header || header + + // 一天多少节课 + this.sessions = options.sessions || 13 + + // 课程宽度 + this.courseWidth = options.courseWidth || ((this.width - this.colHeader.width) / this.days.length) + if (options.courseHeight) { + this.courseHeight = options.courseHeight + } else if (this.title != '') { + this.courseHeight = ((this.height - this.titleStyle.height - this.header.height) / this.sessions) + } else { + this.courseHeight = ((this.height - this.header.height) / this.sessions) + } + + // 设置首行文字大小 + if (!('header' in options) || !options.header) { + this.header = header + this.header.size = this.courseWidth / 2 - 10 + } + // 课程样式 + this.courseStyle = options.courseStyle || courseStyle + + // 获取canvas对象 + this.ctx = wx.createCanvasContext(this.id); + + // + this.startY = 0 + + // + this.options = options + } + + /** + * 参数校验 + * @param {String} props 属性 + * @param {Object} option 参数 + */ + optionCheck(props, option) { + if (!(props in option)) { + console.error("缺少" + props); + throw "缺少" + props + } + this[props] = option[props] + } + + /** + * 绘制课程表 + * courses = [ + * { + * name: '', // 课程名, + * address: '', // 课程地址, + * bg: '#000', //课程背景色, + * sessionArr: [1,2,3], // 上课节次 + * day: 1, // 周几上课 + * } + * ] + * @param {Array} courses 课程表 + */ + drawSchedule(courses) { + const ctx = this.ctx + if (this.title) { + this.drawTitle() + } + + // 绘制第一行 + this.drawHeader(); + this.startY += this.header.height; + + // 第一列 + this.drawFirstCol(); + + // 获得课程,绘制课程 + courses.forEach(course => { + this.drawCourse(course); + }); + + ctx.draw(); + } + + /** + * 保存临时图片到相册 + * @param {String} path + */ + saveImage(path) { + return new Promise((resolve, reject) => { + wx.saveImageToPhotosAlbum({ + filePath: path, + success: res => resolve(res), + fail: res => reject(res) + }); + }); + } + + /** + * canvas 转临时图片 + * @return path + */ + canvasToImg() { + let id = this.id + return new Promise((resolve, reject) => { + wx.canvasToTempFilePath({ + canvasId: id, + success: res => resolve(res.tempFilePath), + fail: res => reject(res) + }); + }); + } + + drawTitle() { + const ctx = this.ctx + // 绘制标题 + ctx.setFillStyle(this.header.bg); + ctx.fillRect(0, 0, this.width, this.titleStyle.height); + ctx.beginPath(); + ctx.moveTo(0, this.titleStyle.height); + ctx.lineTo(this.width, this.titleStyle.height); + ctx.setStrokeStyle(this.header.lineColor); + ctx.stroke(); + ctx.closePath(); + this.drawText( + ctx, + this.title, + (this.width - this.courseWidth) / 2, + this.startY, + 20, + titleStyle + ); + this.startY += this.titleStyle.height; + } + + /** + * 绘制背景色 + * @param {String} bg 背景色 + */ + drawBg(bg = "#f8f8f5") { + this.ctx.rect(0, 0, this.width, this.height); + this.ctx.setFillStyle(bg); + this.ctx.fill(); + } + + /** + * 绘制首行 + */ + drawHeader() { + const ctx = this.ctx + ctx.setFillStyle(this.header.bg); + ctx.fillRect(0, this.startY, this.width, this.header.height); + ctx.setStrokeStyle(this.header.lineColor); + ctx.setLineWidth(1); + ctx.setTextAlign("center"); + ctx.setFillStyle(this.header.color); + ctx.setFontSize(this.header.size); + for (let i = 0; i < this.days.length; i++) { + ctx.beginPath(); + ctx.moveTo(this.colHeader.width + i * this.courseWidth, this.startY); + ctx.lineTo(this.colHeader.width + i * this.courseWidth, this.startY + this.header.height); + ctx.stroke(); + ctx.closePath(); + ctx.fillText( + "周" + days[i], + this.colHeader.width + this.courseWidth / 2 + i * this.courseWidth, + this.startY + (this.header.height + this.header.size) / 2 + ); + } + } + + /** + * 绘制第一列 + */ + drawFirstCol() { + const ctx = this.ctx + ctx.setFillStyle(this.header.bg); + ctx.fillRect(0, this.startY, this.colHeader.width, this.height); + ctx.setStrokeStyle(this.header.lineColor); + ctx.setLineWidth(1); + ctx.setTextAlign("center"); + ctx.setFillStyle(this.header.color); + ctx.setFontSize(this.header.size); + for (let i = 0; i <= this.sessions; i++) { + ctx.beginPath(); + ctx.moveTo(0, this.courseHeight * i + this.startY); + ctx.lineTo(this.colHeader.width, this.courseHeight * i + this.startY); + ctx.stroke(); + ctx.closePath(); + if (i == this.sessions) continue; + ctx.fillText( + i + 1, + this.colHeader.width / 2, + this.courseHeight * (i + 0.5) + this.startY + this.header.size / 2 + ); + } + } + /** + * 绘制课程 + * @param {Object} course 课程 + */ + drawCourse(course) { + const ctx = this.ctx + // 定位 + let x = this.colHeader.width + this.getCourseDayX(course.day) * this.courseWidth; + let y = (course.sessionArr[0] - 1) * this.courseHeight + this.startY; + ctx.setFillStyle(course.bg); + // 绘制背景 + ctx.fillRect(x, y, this.courseWidth, this.courseHeight * course.sessionArr.length); + // 绘制文字 + y = y + this.courseStyle.top; + y = this.drawText(ctx, course.name, x, y, 4, this.courseStyle); + this.drawText(ctx, "@" + course.address, x, y, 4, this.courseStyle); + } + /** + * 获取课程的偏移位置 + * @param {Number} day 周几,1 = 周一 + */ + getCourseDayX(day) { + for (let i = 0; i < this.days.length; i++) { + if (this.days[i] === dayMap[day]) { + return i + } + } + throw "课程时间和设置不匹配!" + } + drawText(ctx, str, x, y, len, style) { + str = str.trim(); + ctx.setFillStyle(style.color); + ctx.setTextAlign("center"); + ctx.setFontSize(style.size); + for (let i = 0; i < str.length / len; i++) { + y = y + style.size * 1.5; + ctx.fillText( + str.substr(i * len, len), + x + this.courseWidth / 2, + y + ); + } + return y; + } + download(url) { + return new Promise((resolve, reject) => { + wx.downloadFile({ + url: url, + success: res => { + if (res.statusCode === 200) { + resolve(res.tempFilePath); + } else { + reject(res); + } + }, + fail: res => reject(res) + }); + }); + } + + log() { + console.log(this.options) + } +} \ No newline at end of file diff --git a/package.json b/package.json new file mode 100644 index 0000000..b644cf7 --- /dev/null +++ b/package.json @@ -0,0 +1,20 @@ +{ + "name": "wxapp-schedule", + "version": "1.0.0", + "description": "\"微信小程序课程表canvas组件\"", + "main": "index.js", + "scripts": { + "build": "babel index.js --out-file ./dist/schedule.js", + "dev": "babel index.js -w --out-file ./example/schedule.js", + "test": "echo \"Error: no test specified\" && exit 1" + }, + "keywords": [ + "\"微信小程序", + "课程表\"" + ], + "author": "mohuishou", + "license": "MIT", + "devDependencies": { + "babel-preset-env": "^1.7.0" + } +} diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..0ebf355 --- /dev/null +++ b/readme.md @@ -0,0 +1,107 @@ +# wxapp-schedule 小程序课程表组件 + +这是一个使用canvas绘制的小程序课程表,可以用于展示小程序课程表,也可以用于保存分享图] + +## Example +- example文件夹 [example](example) +直接点击打开代码片段 +- [wechatide://minicode/3FFtexmB7qFW](wechatide://minicode/3FFtexmB7qFW) + +# install +直接复制dist文件夹的`schedule.js`到相应使用位置 + +# use +```javascript +let s = new Schedule({ + id: "schedule", + width: 375, + height: 1000, + title: "测试课程表" +}) +s.drawBg() +s.drawSchedule([{ + day: 1, + sessionArr: [1, 2, 3], + address: "lalalal", + name: "测试课程", + bg: "#f07c82" +}]) +``` + +## option +```javascript +{ + id: "", //必选 canvas id + width: 0, //必选 canvas width + height: 0, //必选 canvas height + title: "", // 可选,课程表标题 + titleStyle: { // 可选,标题样式 + size: 20, // 字体大小 + height: 50, // 高度 + color: "#000", // 字体颜色 + bg: "#f5f5f5" // 背景颜色 + }, + days: ["一", "二", "三", "四", "五", "六", "日"], // 可选,一周时间安排,适应不同学校 + colHeader: { // 可选,第一列样式 + size: 10, // 字体大小 + width: 25, // 宽度 + bg: "#f5f5f5", // 背景色 + color: "#555", // 字体颜色 + lineColor: "#d0d0d0" // 间隔线颜色 + }, + header: { // 可选,第一行样式 + size: 10, // 字体大小 + height: 50, // 高度 + bg: "#f5f5f5", // 背景色 + color: "#555", // 字体颜色 + lineColor: "#d0d0d0" // 间隔线颜色 + }, + sessions: 13, // 可选,一天多少节课, + courseWidth: , // 可选,每节课宽度,默认自适应 + courseHeight: , // 可选,每节课高度,默认自适应 + courseStyle: { // 可选,课程样式 + color: "#fff", // 字体颜色 + size: 10, // 自已大小 + top: 5 // padding top + }, +} +``` + +## api +```javascript +/** + * 绘制背景色 + * @param {String} bg 背景色 + */ +drawBg(bg = "#f8f8f5") + +/** + * 绘制课程表 + * courses = [ + * { + * name: '', // 课程名, + * address: '', // 课程地址, + * bg: '#000', //课程背景色, + * sessionArr: [1,2,3], // 上课节次 + * day: 1, // 周几上课 + * } + * ] + * @param {Array} courses 课程表 + */ +drawSchedule(courses) + +/** + * 保存临时图片到相册 + * @param {String} path 图片地址 + */ +saveImage(path) + +/** + * canvas 转临时图片 + * @return path + */ +canvasToImg() +``` + +# preview +![](./img/example.png) \ No newline at end of file diff --git a/yarn.lock b/yarn.lock new file mode 100644 index 0000000..04d0a3d --- /dev/null +++ b/yarn.lock @@ -0,0 +1,550 @@ +# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. +# yarn lockfile v1 + + +ansi-regex@^2.0.0: + version "2.1.1" + resolved "http://registry.npm.taobao.org/ansi-regex/download/ansi-regex-2.1.1.tgz#c3b33ab5ee360d86e0e628f0468ae7ef27d654df" + +ansi-styles@^2.2.1: + version "2.2.1" + resolved "http://registry.npm.taobao.org/ansi-styles/download/ansi-styles-2.2.1.tgz#b432dd3358b634cf75e1e4664368240533c1ddbe" + +babel-code-frame@^6.26.0: + version "6.26.0" + resolved "http://registry.npm.taobao.org/babel-code-frame/download/babel-code-frame-6.26.0.tgz#63fd43f7dc1e3bb7ce35947db8fe369a3f58c74b" + dependencies: + chalk "^1.1.3" + esutils "^2.0.2" + js-tokens "^3.0.2" + +babel-helper-builder-binary-assignment-operator-visitor@^6.24.1: + version "6.24.1" + resolved "http://registry.npm.taobao.org/babel-helper-builder-binary-assignment-operator-visitor/download/babel-helper-builder-binary-assignment-operator-visitor-6.24.1.tgz#cce4517ada356f4220bcae8a02c2b346f9a56664" + dependencies: + babel-helper-explode-assignable-expression "^6.24.1" + babel-runtime "^6.22.0" + babel-types "^6.24.1" + +babel-helper-call-delegate@^6.24.1: + version "6.24.1" + resolved "http://registry.npm.taobao.org/babel-helper-call-delegate/download/babel-helper-call-delegate-6.24.1.tgz#ece6aacddc76e41c3461f88bfc575bd0daa2df8d" + dependencies: + babel-helper-hoist-variables "^6.24.1" + babel-runtime "^6.22.0" + babel-traverse "^6.24.1" + babel-types "^6.24.1" + +babel-helper-define-map@^6.24.1: + version "6.26.0" + resolved "http://registry.npm.taobao.org/babel-helper-define-map/download/babel-helper-define-map-6.26.0.tgz#a5f56dab41a25f97ecb498c7ebaca9819f95be5f" + dependencies: + babel-helper-function-name "^6.24.1" + babel-runtime "^6.26.0" + babel-types "^6.26.0" + lodash "^4.17.4" + +babel-helper-explode-assignable-expression@^6.24.1: + version "6.24.1" + resolved "http://registry.npm.taobao.org/babel-helper-explode-assignable-expression/download/babel-helper-explode-assignable-expression-6.24.1.tgz#f25b82cf7dc10433c55f70592d5746400ac22caa" + dependencies: + babel-runtime "^6.22.0" + babel-traverse "^6.24.1" + babel-types "^6.24.1" + +babel-helper-function-name@^6.24.1: + version "6.24.1" + resolved "http://registry.npm.taobao.org/babel-helper-function-name/download/babel-helper-function-name-6.24.1.tgz#d3475b8c03ed98242a25b48351ab18399d3580a9" + dependencies: + babel-helper-get-function-arity "^6.24.1" + babel-runtime "^6.22.0" + babel-template "^6.24.1" + babel-traverse "^6.24.1" + babel-types "^6.24.1" + +babel-helper-get-function-arity@^6.24.1: + version "6.24.1" + resolved "http://registry.npm.taobao.org/babel-helper-get-function-arity/download/babel-helper-get-function-arity-6.24.1.tgz#8f7782aa93407c41d3aa50908f89b031b1b6853d" + dependencies: + babel-runtime "^6.22.0" + babel-types "^6.24.1" + +babel-helper-hoist-variables@^6.24.1: + version "6.24.1" + resolved "http://registry.npm.taobao.org/babel-helper-hoist-variables/download/babel-helper-hoist-variables-6.24.1.tgz#1ecb27689c9d25513eadbc9914a73f5408be7a76" + dependencies: + babel-runtime "^6.22.0" + babel-types "^6.24.1" + +babel-helper-optimise-call-expression@^6.24.1: + version "6.24.1" + resolved "http://registry.npm.taobao.org/babel-helper-optimise-call-expression/download/babel-helper-optimise-call-expression-6.24.1.tgz#f7a13427ba9f73f8f4fa993c54a97882d1244257" + dependencies: + babel-runtime "^6.22.0" + babel-types "^6.24.1" + +babel-helper-regex@^6.24.1: + version "6.26.0" + resolved "http://registry.npm.taobao.org/babel-helper-regex/download/babel-helper-regex-6.26.0.tgz#325c59f902f82f24b74faceed0363954f6495e72" + dependencies: + babel-runtime "^6.26.0" + babel-types "^6.26.0" + lodash "^4.17.4" + +babel-helper-remap-async-to-generator@^6.24.1: + version "6.24.1" + resolved "http://registry.npm.taobao.org/babel-helper-remap-async-to-generator/download/babel-helper-remap-async-to-generator-6.24.1.tgz#5ec581827ad723fecdd381f1c928390676e4551b" + dependencies: + babel-helper-function-name "^6.24.1" + babel-runtime "^6.22.0" + babel-template "^6.24.1" + babel-traverse "^6.24.1" + babel-types "^6.24.1" + +babel-helper-replace-supers@^6.24.1: + version "6.24.1" + resolved "http://registry.npm.taobao.org/babel-helper-replace-supers/download/babel-helper-replace-supers-6.24.1.tgz#bf6dbfe43938d17369a213ca8a8bf74b6a90ab1a" + dependencies: + babel-helper-optimise-call-expression "^6.24.1" + babel-messages "^6.23.0" + babel-runtime "^6.22.0" + babel-template "^6.24.1" + babel-traverse "^6.24.1" + babel-types "^6.24.1" + +babel-messages@^6.23.0: + version "6.23.0" + resolved "http://registry.npm.taobao.org/babel-messages/download/babel-messages-6.23.0.tgz#f3cdf4703858035b2a2951c6ec5edf6c62f2630e" + dependencies: + babel-runtime "^6.22.0" + +babel-plugin-check-es2015-constants@^6.22.0: + version "6.22.0" + resolved "http://registry.npm.taobao.org/babel-plugin-check-es2015-constants/download/babel-plugin-check-es2015-constants-6.22.0.tgz#35157b101426fd2ffd3da3f75c7d1e91835bbf8a" + dependencies: + babel-runtime "^6.22.0" + +babel-plugin-syntax-async-functions@^6.8.0: + version "6.13.0" + resolved "http://registry.npm.taobao.org/babel-plugin-syntax-async-functions/download/babel-plugin-syntax-async-functions-6.13.0.tgz#cad9cad1191b5ad634bf30ae0872391e0647be95" + +babel-plugin-syntax-exponentiation-operator@^6.8.0: + version "6.13.0" + resolved "http://registry.npm.taobao.org/babel-plugin-syntax-exponentiation-operator/download/babel-plugin-syntax-exponentiation-operator-6.13.0.tgz#9ee7e8337290da95288201a6a57f4170317830de" + +babel-plugin-syntax-trailing-function-commas@^6.22.0: + version "6.22.0" + resolved "http://registry.npm.taobao.org/babel-plugin-syntax-trailing-function-commas/download/babel-plugin-syntax-trailing-function-commas-6.22.0.tgz#ba0360937f8d06e40180a43fe0d5616fff532cf3" + +babel-plugin-transform-async-to-generator@^6.22.0: + version "6.24.1" + resolved "http://registry.npm.taobao.org/babel-plugin-transform-async-to-generator/download/babel-plugin-transform-async-to-generator-6.24.1.tgz#6536e378aff6cb1d5517ac0e40eb3e9fc8d08761" + dependencies: + babel-helper-remap-async-to-generator "^6.24.1" + babel-plugin-syntax-async-functions "^6.8.0" + babel-runtime "^6.22.0" + +babel-plugin-transform-es2015-arrow-functions@^6.22.0: + version "6.22.0" + resolved "http://registry.npm.taobao.org/babel-plugin-transform-es2015-arrow-functions/download/babel-plugin-transform-es2015-arrow-functions-6.22.0.tgz#452692cb711d5f79dc7f85e440ce41b9f244d221" + dependencies: + babel-runtime "^6.22.0" + +babel-plugin-transform-es2015-block-scoped-functions@^6.22.0: + version "6.22.0" + resolved "http://registry.npm.taobao.org/babel-plugin-transform-es2015-block-scoped-functions/download/babel-plugin-transform-es2015-block-scoped-functions-6.22.0.tgz#bbc51b49f964d70cb8d8e0b94e820246ce3a6141" + dependencies: + babel-runtime "^6.22.0" + +babel-plugin-transform-es2015-block-scoping@^6.23.0: + version "6.26.0" + resolved "http://registry.npm.taobao.org/babel-plugin-transform-es2015-block-scoping/download/babel-plugin-transform-es2015-block-scoping-6.26.0.tgz#d70f5299c1308d05c12f463813b0a09e73b1895f" + dependencies: + babel-runtime "^6.26.0" + babel-template "^6.26.0" + babel-traverse "^6.26.0" + babel-types "^6.26.0" + lodash "^4.17.4" + +babel-plugin-transform-es2015-classes@^6.23.0: + version "6.24.1" + resolved "http://registry.npm.taobao.org/babel-plugin-transform-es2015-classes/download/babel-plugin-transform-es2015-classes-6.24.1.tgz#5a4c58a50c9c9461e564b4b2a3bfabc97a2584db" + dependencies: + babel-helper-define-map "^6.24.1" + babel-helper-function-name "^6.24.1" + babel-helper-optimise-call-expression "^6.24.1" + babel-helper-replace-supers "^6.24.1" + babel-messages "^6.23.0" + babel-runtime "^6.22.0" + babel-template "^6.24.1" + babel-traverse "^6.24.1" + babel-types "^6.24.1" + +babel-plugin-transform-es2015-computed-properties@^6.22.0: + version "6.24.1" + resolved "http://registry.npm.taobao.org/babel-plugin-transform-es2015-computed-properties/download/babel-plugin-transform-es2015-computed-properties-6.24.1.tgz#6fe2a8d16895d5634f4cd999b6d3480a308159b3" + dependencies: + babel-runtime "^6.22.0" + babel-template "^6.24.1" + +babel-plugin-transform-es2015-destructuring@^6.23.0: + version "6.23.0" + resolved "http://registry.npm.taobao.org/babel-plugin-transform-es2015-destructuring/download/babel-plugin-transform-es2015-destructuring-6.23.0.tgz#997bb1f1ab967f682d2b0876fe358d60e765c56d" + dependencies: + babel-runtime "^6.22.0" + +babel-plugin-transform-es2015-duplicate-keys@^6.22.0: + version "6.24.1" + resolved "http://registry.npm.taobao.org/babel-plugin-transform-es2015-duplicate-keys/download/babel-plugin-transform-es2015-duplicate-keys-6.24.1.tgz#73eb3d310ca969e3ef9ec91c53741a6f1576423e" + dependencies: + babel-runtime "^6.22.0" + babel-types "^6.24.1" + +babel-plugin-transform-es2015-for-of@^6.23.0: + version "6.23.0" + resolved "http://registry.npm.taobao.org/babel-plugin-transform-es2015-for-of/download/babel-plugin-transform-es2015-for-of-6.23.0.tgz#f47c95b2b613df1d3ecc2fdb7573623c75248691" + dependencies: + babel-runtime "^6.22.0" + +babel-plugin-transform-es2015-function-name@^6.22.0: + version "6.24.1" + resolved "http://registry.npm.taobao.org/babel-plugin-transform-es2015-function-name/download/babel-plugin-transform-es2015-function-name-6.24.1.tgz#834c89853bc36b1af0f3a4c5dbaa94fd8eacaa8b" + dependencies: + babel-helper-function-name "^6.24.1" + babel-runtime "^6.22.0" + babel-types "^6.24.1" + +babel-plugin-transform-es2015-literals@^6.22.0: + version "6.22.0" + resolved "http://registry.npm.taobao.org/babel-plugin-transform-es2015-literals/download/babel-plugin-transform-es2015-literals-6.22.0.tgz#4f54a02d6cd66cf915280019a31d31925377ca2e" + dependencies: + babel-runtime "^6.22.0" + +babel-plugin-transform-es2015-modules-amd@^6.22.0, babel-plugin-transform-es2015-modules-amd@^6.24.1: + version "6.24.1" + resolved "http://registry.npm.taobao.org/babel-plugin-transform-es2015-modules-amd/download/babel-plugin-transform-es2015-modules-amd-6.24.1.tgz#3b3e54017239842d6d19c3011c4bd2f00a00d154" + dependencies: + babel-plugin-transform-es2015-modules-commonjs "^6.24.1" + babel-runtime "^6.22.0" + babel-template "^6.24.1" + +babel-plugin-transform-es2015-modules-commonjs@^6.23.0, babel-plugin-transform-es2015-modules-commonjs@^6.24.1: + version "6.26.2" + resolved "http://registry.npm.taobao.org/babel-plugin-transform-es2015-modules-commonjs/download/babel-plugin-transform-es2015-modules-commonjs-6.26.2.tgz#58a793863a9e7ca870bdc5a881117ffac27db6f3" + dependencies: + babel-plugin-transform-strict-mode "^6.24.1" + babel-runtime "^6.26.0" + babel-template "^6.26.0" + babel-types "^6.26.0" + +babel-plugin-transform-es2015-modules-systemjs@^6.23.0: + version "6.24.1" + resolved "http://registry.npm.taobao.org/babel-plugin-transform-es2015-modules-systemjs/download/babel-plugin-transform-es2015-modules-systemjs-6.24.1.tgz#ff89a142b9119a906195f5f106ecf305d9407d23" + dependencies: + babel-helper-hoist-variables "^6.24.1" + babel-runtime "^6.22.0" + babel-template "^6.24.1" + +babel-plugin-transform-es2015-modules-umd@^6.23.0: + version "6.24.1" + resolved "http://registry.npm.taobao.org/babel-plugin-transform-es2015-modules-umd/download/babel-plugin-transform-es2015-modules-umd-6.24.1.tgz#ac997e6285cd18ed6176adb607d602344ad38468" + dependencies: + babel-plugin-transform-es2015-modules-amd "^6.24.1" + babel-runtime "^6.22.0" + babel-template "^6.24.1" + +babel-plugin-transform-es2015-object-super@^6.22.0: + version "6.24.1" + resolved "http://registry.npm.taobao.org/babel-plugin-transform-es2015-object-super/download/babel-plugin-transform-es2015-object-super-6.24.1.tgz#24cef69ae21cb83a7f8603dad021f572eb278f8d" + dependencies: + babel-helper-replace-supers "^6.24.1" + babel-runtime "^6.22.0" + +babel-plugin-transform-es2015-parameters@^6.23.0: + version "6.24.1" + resolved "http://registry.npm.taobao.org/babel-plugin-transform-es2015-parameters/download/babel-plugin-transform-es2015-parameters-6.24.1.tgz#57ac351ab49caf14a97cd13b09f66fdf0a625f2b" + dependencies: + babel-helper-call-delegate "^6.24.1" + babel-helper-get-function-arity "^6.24.1" + babel-runtime "^6.22.0" + babel-template "^6.24.1" + babel-traverse "^6.24.1" + babel-types "^6.24.1" + +babel-plugin-transform-es2015-shorthand-properties@^6.22.0: + version "6.24.1" + resolved "http://registry.npm.taobao.org/babel-plugin-transform-es2015-shorthand-properties/download/babel-plugin-transform-es2015-shorthand-properties-6.24.1.tgz#24f875d6721c87661bbd99a4622e51f14de38aa0" + dependencies: + babel-runtime "^6.22.0" + babel-types "^6.24.1" + +babel-plugin-transform-es2015-spread@^6.22.0: + version "6.22.0" + resolved "http://registry.npm.taobao.org/babel-plugin-transform-es2015-spread/download/babel-plugin-transform-es2015-spread-6.22.0.tgz#d6d68a99f89aedc4536c81a542e8dd9f1746f8d1" + dependencies: + babel-runtime "^6.22.0" + +babel-plugin-transform-es2015-sticky-regex@^6.22.0: + version "6.24.1" + resolved "http://registry.npm.taobao.org/babel-plugin-transform-es2015-sticky-regex/download/babel-plugin-transform-es2015-sticky-regex-6.24.1.tgz#00c1cdb1aca71112cdf0cf6126c2ed6b457ccdbc" + dependencies: + babel-helper-regex "^6.24.1" + babel-runtime "^6.22.0" + babel-types "^6.24.1" + +babel-plugin-transform-es2015-template-literals@^6.22.0: + version "6.22.0" + resolved "http://registry.npm.taobao.org/babel-plugin-transform-es2015-template-literals/download/babel-plugin-transform-es2015-template-literals-6.22.0.tgz#a84b3450f7e9f8f1f6839d6d687da84bb1236d8d" + dependencies: + babel-runtime "^6.22.0" + +babel-plugin-transform-es2015-typeof-symbol@^6.23.0: + version "6.23.0" + resolved "http://registry.npm.taobao.org/babel-plugin-transform-es2015-typeof-symbol/download/babel-plugin-transform-es2015-typeof-symbol-6.23.0.tgz#dec09f1cddff94b52ac73d505c84df59dcceb372" + dependencies: + babel-runtime "^6.22.0" + +babel-plugin-transform-es2015-unicode-regex@^6.22.0: + version "6.24.1" + resolved "http://registry.npm.taobao.org/babel-plugin-transform-es2015-unicode-regex/download/babel-plugin-transform-es2015-unicode-regex-6.24.1.tgz#d38b12f42ea7323f729387f18a7c5ae1faeb35e9" + dependencies: + babel-helper-regex "^6.24.1" + babel-runtime "^6.22.0" + regexpu-core "^2.0.0" + +babel-plugin-transform-exponentiation-operator@^6.22.0: + version "6.24.1" + resolved "http://registry.npm.taobao.org/babel-plugin-transform-exponentiation-operator/download/babel-plugin-transform-exponentiation-operator-6.24.1.tgz#2ab0c9c7f3098fa48907772bb813fe41e8de3a0e" + dependencies: + babel-helper-builder-binary-assignment-operator-visitor "^6.24.1" + babel-plugin-syntax-exponentiation-operator "^6.8.0" + babel-runtime "^6.22.0" + +babel-plugin-transform-regenerator@^6.22.0: + version "6.26.0" + resolved "http://registry.npm.taobao.org/babel-plugin-transform-regenerator/download/babel-plugin-transform-regenerator-6.26.0.tgz#e0703696fbde27f0a3efcacf8b4dca2f7b3a8f2f" + dependencies: + regenerator-transform "^0.10.0" + +babel-plugin-transform-strict-mode@^6.24.1: + version "6.24.1" + resolved "http://registry.npm.taobao.org/babel-plugin-transform-strict-mode/download/babel-plugin-transform-strict-mode-6.24.1.tgz#d5faf7aa578a65bbe591cf5edae04a0c67020758" + dependencies: + babel-runtime "^6.22.0" + babel-types "^6.24.1" + +babel-preset-env@^1.7.0: + version "1.7.0" + resolved "http://registry.npm.taobao.org/babel-preset-env/download/babel-preset-env-1.7.0.tgz#dea79fa4ebeb883cd35dab07e260c1c9c04df77a" + dependencies: + babel-plugin-check-es2015-constants "^6.22.0" + babel-plugin-syntax-trailing-function-commas "^6.22.0" + babel-plugin-transform-async-to-generator "^6.22.0" + babel-plugin-transform-es2015-arrow-functions "^6.22.0" + babel-plugin-transform-es2015-block-scoped-functions "^6.22.0" + babel-plugin-transform-es2015-block-scoping "^6.23.0" + babel-plugin-transform-es2015-classes "^6.23.0" + babel-plugin-transform-es2015-computed-properties "^6.22.0" + babel-plugin-transform-es2015-destructuring "^6.23.0" + babel-plugin-transform-es2015-duplicate-keys "^6.22.0" + babel-plugin-transform-es2015-for-of "^6.23.0" + babel-plugin-transform-es2015-function-name "^6.22.0" + babel-plugin-transform-es2015-literals "^6.22.0" + babel-plugin-transform-es2015-modules-amd "^6.22.0" + babel-plugin-transform-es2015-modules-commonjs "^6.23.0" + babel-plugin-transform-es2015-modules-systemjs "^6.23.0" + babel-plugin-transform-es2015-modules-umd "^6.23.0" + babel-plugin-transform-es2015-object-super "^6.22.0" + babel-plugin-transform-es2015-parameters "^6.23.0" + babel-plugin-transform-es2015-shorthand-properties "^6.22.0" + babel-plugin-transform-es2015-spread "^6.22.0" + babel-plugin-transform-es2015-sticky-regex "^6.22.0" + babel-plugin-transform-es2015-template-literals "^6.22.0" + babel-plugin-transform-es2015-typeof-symbol "^6.23.0" + babel-plugin-transform-es2015-unicode-regex "^6.22.0" + babel-plugin-transform-exponentiation-operator "^6.22.0" + babel-plugin-transform-regenerator "^6.22.0" + browserslist "^3.2.6" + invariant "^2.2.2" + semver "^5.3.0" + +babel-runtime@^6.18.0, babel-runtime@^6.22.0, babel-runtime@^6.26.0: + version "6.26.0" + resolved "http://registry.npm.taobao.org/babel-runtime/download/babel-runtime-6.26.0.tgz#965c7058668e82b55d7bfe04ff2337bc8b5647fe" + dependencies: + core-js "^2.4.0" + regenerator-runtime "^0.11.0" + +babel-template@^6.24.1, babel-template@^6.26.0: + version "6.26.0" + resolved "http://registry.npm.taobao.org/babel-template/download/babel-template-6.26.0.tgz#de03e2d16396b069f46dd9fff8521fb1a0e35e02" + dependencies: + babel-runtime "^6.26.0" + babel-traverse "^6.26.0" + babel-types "^6.26.0" + babylon "^6.18.0" + lodash "^4.17.4" + +babel-traverse@^6.24.1, babel-traverse@^6.26.0: + version "6.26.0" + resolved "http://registry.npm.taobao.org/babel-traverse/download/babel-traverse-6.26.0.tgz#46a9cbd7edcc62c8e5c064e2d2d8d0f4035766ee" + dependencies: + babel-code-frame "^6.26.0" + babel-messages "^6.23.0" + babel-runtime "^6.26.0" + babel-types "^6.26.0" + babylon "^6.18.0" + debug "^2.6.8" + globals "^9.18.0" + invariant "^2.2.2" + lodash "^4.17.4" + +babel-types@^6.19.0, babel-types@^6.24.1, babel-types@^6.26.0: + version "6.26.0" + resolved "http://registry.npm.taobao.org/babel-types/download/babel-types-6.26.0.tgz#a3b073f94ab49eb6fa55cd65227a334380632497" + dependencies: + babel-runtime "^6.26.0" + esutils "^2.0.2" + lodash "^4.17.4" + to-fast-properties "^1.0.3" + +babylon@^6.18.0: + version "6.18.0" + resolved "http://registry.npm.taobao.org/babylon/download/babylon-6.18.0.tgz#af2f3b88fa6f5c1e4c634d1a0f8eac4f55b395e3" + +browserslist@^3.2.6: + version "3.2.8" + resolved "http://registry.npm.taobao.org/browserslist/download/browserslist-3.2.8.tgz#b0005361d6471f0f5952797a76fc985f1f978fc6" + dependencies: + caniuse-lite "^1.0.30000844" + electron-to-chromium "^1.3.47" + +caniuse-lite@^1.0.30000844: + version "1.0.30000860" + resolved "http://registry.npm.taobao.org/caniuse-lite/download/caniuse-lite-1.0.30000860.tgz#c902e3df3cc4303f631abc7a1579a3ce0a6153a3" + +chalk@^1.1.3: + version "1.1.3" + resolved "http://registry.npm.taobao.org/chalk/download/chalk-1.1.3.tgz#a8115c55e4a702fe4d150abd3872822a7e09fc98" + dependencies: + ansi-styles "^2.2.1" + escape-string-regexp "^1.0.2" + has-ansi "^2.0.0" + strip-ansi "^3.0.0" + supports-color "^2.0.0" + +core-js@^2.4.0: + version "2.5.7" + resolved "http://registry.npm.taobao.org/core-js/download/core-js-2.5.7.tgz#f972608ff0cead68b841a16a932d0b183791814e" + +debug@^2.6.8: + version "2.6.9" + resolved "http://registry.npm.taobao.org/debug/download/debug-2.6.9.tgz#5d128515df134ff327e90a4c93f4e077a536341f" + dependencies: + ms "2.0.0" + +electron-to-chromium@^1.3.47: + version "1.3.50" + resolved "http://registry.npm.taobao.org/electron-to-chromium/download/electron-to-chromium-1.3.50.tgz#7438b76f92b41b919f3fbdd350fbd0757dacddf7" + +escape-string-regexp@^1.0.2: + version "1.0.5" + resolved "http://registry.npm.taobao.org/escape-string-regexp/download/escape-string-regexp-1.0.5.tgz#1b61c0562190a8dff6ae3bb2cf0200ca130b86d4" + +esutils@^2.0.2: + version "2.0.2" + resolved "http://registry.npm.taobao.org/esutils/download/esutils-2.0.2.tgz#0abf4f1caa5bcb1f7a9d8acc6dea4faaa04bac9b" + +globals@^9.18.0: + version "9.18.0" + resolved "http://registry.npm.taobao.org/globals/download/globals-9.18.0.tgz#aa3896b3e69b487f17e31ed2143d69a8e30c2d8a" + +has-ansi@^2.0.0: + version "2.0.0" + resolved "http://registry.npm.taobao.org/has-ansi/download/has-ansi-2.0.0.tgz#34f5049ce1ecdf2b0649af3ef24e45ed35416d91" + dependencies: + ansi-regex "^2.0.0" + +invariant@^2.2.2: + version "2.2.4" + resolved "http://registry.npm.taobao.org/invariant/download/invariant-2.2.4.tgz#610f3c92c9359ce1db616e538008d23ff35158e6" + dependencies: + loose-envify "^1.0.0" + +js-tokens@^3.0.0, js-tokens@^3.0.2: + version "3.0.2" + resolved "http://registry.npm.taobao.org/js-tokens/download/js-tokens-3.0.2.tgz#9866df395102130e38f7f996bceb65443209c25b" + +jsesc@~0.5.0: + version "0.5.0" + resolved "http://registry.npm.taobao.org/jsesc/download/jsesc-0.5.0.tgz#e7dee66e35d6fc16f710fe91d5cf69f70f08911d" + +lodash@^4.17.4: + version "4.17.10" + resolved "http://registry.npm.taobao.org/lodash/download/lodash-4.17.10.tgz#1b7793cf7259ea38fb3661d4d38b3260af8ae4e7" + +loose-envify@^1.0.0: + version "1.3.1" + resolved "http://registry.npm.taobao.org/loose-envify/download/loose-envify-1.3.1.tgz#d1a8ad33fa9ce0e713d65fdd0ac8b748d478c848" + dependencies: + js-tokens "^3.0.0" + +ms@2.0.0: + version "2.0.0" + resolved "http://registry.npm.taobao.org/ms/download/ms-2.0.0.tgz#5608aeadfc00be6c2901df5f9861788de0d597c8" + +private@^0.1.6: + version "0.1.8" + resolved "http://registry.npm.taobao.org/private/download/private-0.1.8.tgz#2381edb3689f7a53d653190060fcf822d2f368ff" + +regenerate@^1.2.1: + version "1.4.0" + resolved "http://registry.npm.taobao.org/regenerate/download/regenerate-1.4.0.tgz#4a856ec4b56e4077c557589cae85e7a4c8869a11" + +regenerator-runtime@^0.11.0: + version "0.11.1" + resolved "http://registry.npm.taobao.org/regenerator-runtime/download/regenerator-runtime-0.11.1.tgz#be05ad7f9bf7d22e056f9726cee5017fbf19e2e9" + +regenerator-transform@^0.10.0: + version "0.10.1" + resolved "http://registry.npm.taobao.org/regenerator-transform/download/regenerator-transform-0.10.1.tgz#1e4996837231da8b7f3cf4114d71b5691a0680dd" + dependencies: + babel-runtime "^6.18.0" + babel-types "^6.19.0" + private "^0.1.6" + +regexpu-core@^2.0.0: + version "2.0.0" + resolved "http://registry.npm.taobao.org/regexpu-core/download/regexpu-core-2.0.0.tgz#49d038837b8dcf8bfa5b9a42139938e6ea2ae240" + dependencies: + regenerate "^1.2.1" + regjsgen "^0.2.0" + regjsparser "^0.1.4" + +regjsgen@^0.2.0: + version "0.2.0" + resolved "http://registry.npm.taobao.org/regjsgen/download/regjsgen-0.2.0.tgz#6c016adeac554f75823fe37ac05b92d5a4edb1f7" + +regjsparser@^0.1.4: + version "0.1.5" + resolved "http://registry.npm.taobao.org/regjsparser/download/regjsparser-0.1.5.tgz#7ee8f84dc6fa792d3fd0ae228d24bd949ead205c" + dependencies: + jsesc "~0.5.0" + +semver@^5.3.0: + version "5.5.0" + resolved "http://registry.npm.taobao.org/semver/download/semver-5.5.0.tgz#dc4bbc7a6ca9d916dee5d43516f0092b58f7b8ab" + +strip-ansi@^3.0.0: + version "3.0.1" + resolved "http://registry.npm.taobao.org/strip-ansi/download/strip-ansi-3.0.1.tgz#6a385fb8853d952d5ff05d0e8aaf94278dc63dcf" + dependencies: + ansi-regex "^2.0.0" + +supports-color@^2.0.0: + version "2.0.0" + resolved "http://registry.npm.taobao.org/supports-color/download/supports-color-2.0.0.tgz#535d045ce6b6363fa40117084629995e9df324c7" + +to-fast-properties@^1.0.3: + version "1.0.3" + resolved "http://registry.npm.taobao.org/to-fast-properties/download/to-fast-properties-1.0.3.tgz#b83571fa4d8c25b82e231b06e3a3055de4ca1a47"