From 5ea37cb89f248f96402a66dd765eac2a7166d6e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AE=87=E5=A4=A9?= Date: Mon, 22 Jul 2019 10:11:52 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90=E7=BC=96=E8=AF=91=E5=B7=A5?= =?UTF-8?q?=E5=85=B7;icon=E7=BB=84=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.dev.js | 127 +++++++++++++++++---- build.prod.js | 141 +++++++++++++++++++----- package.json | 15 +-- src/css/reset-basic.css | 60 ++++++++++ src/css/reset-basic.scss | 157 -------------------------- src/form/button.wc | 170 ++++++++++++++++++++++++++++ src/icon/index.wc | 99 +++++++++++++++++ src/icon/svg.js | 48 ++++++++ src/pager/index.wc | 232 +++++++++++++++++++++++++++++++++++++++ 9 files changed, 835 insertions(+), 214 deletions(-) create mode 100644 src/css/reset-basic.css delete mode 100644 src/css/reset-basic.scss create mode 100644 src/form/button.wc create mode 100644 src/icon/index.wc create mode 100644 src/icon/svg.js create mode 100644 src/pager/index.wc diff --git a/build.dev.js b/build.dev.js index c48c0aa..675de0a 100644 --- a/build.dev.js +++ b/build.dev.js @@ -1,50 +1,137 @@ #! /usr/bin/env node +require('es.shim') const log = console.log const fs = require('iofs') const path = require('path') const babel = require('babel-core') const scss = require('node-sass') const chokidar = require('chokidar') -const postcss = require('postcss') -const autoprefixer = require('autoprefixer') const chalk = require('chalk') const sourceDir = path.resolve(__dirname, 'src') const buildDir = path.resolve(__dirname, 'dist') -const prefixer = postcss().use( - autoprefixer({ - browsers: ['ff > 61', 'Chrome > 63'] - }) -) -const compileJs = (entry, output) => { +const VERSION = require('./package.json').version +const BUILD_DATE = new Date().format() + +const BASE_SCSS = ` +$ct: #3fc2a7 #19b491 #16967a; +$cg: #58d68d #2ecc71 #27ae60; +$cpp: #ac61ce #9b59b6 #8e44ad; +$cb: #52a3de #2d8dd6 #2776b1; +$cr: #ff5061 #eb3b48 #ce3742; +$co: #ffb618 #f39c12 #e67e22; +$cp: #f3f5fb #e8ebf4 #dae1e9; +$cgr: #aabac3 #90a3ae #7e909a; +$cd: #62778d #526273 #425064; + +@mixin ts($c: all, $t: .2s, $m: ease-in-out){ + transition:$c $t $m; +} + +* { + box-sizing: border-box; + margin: 0;padding: 0; +} +::before, +::after{box-sizing:border-box;} +` + +function compileJs(entry, output) { log('编译JS: %s', chalk.green(entry)) let buf = fs.cat(entry).toString() let code = buf - .replace(/\.scss/g, '.css') - .replace(/import '([a-z0-9\/\.\-_]*)(? { - log('编译scss: %s', chalk.green(entry)) +// 编译样式 +function compileScss(code = '') { try { - const { css } = scss.renderSync({ file: entry }) - prefixer.process(css, { from: '', to: '' }).then(result => { - fs.echo(result.css, output) - }) + return scss.renderSync({ data: BASE_SCSS + code }).css } catch (err) { log(err) } } +function mkWCFile({ style, html, js }) { + style = compileScss(style) + + let name, props + + js = js.replace(/props = (\{[\w\W]*?\})/, function(s, m) { + props = m + var attr = new Function( + `var props = ${m}, attr = []; for(var i in props){attr.push(i)}; return attr` + )() + return `static get observedAttributes() { + return ${JSON.stringify(attr)} + } + ` + }) + + js = js + .replace(/class ([\w]+)/, function(s, m) { + name = m + return `${s} extends HTMLElement ` + }) + .replace(/import '([a-z0-9\/\.\-_]*)'/g, 'import "$1.js"') + .replace( + /import ([\w]*) from '([a-z0-9\/\.\-_]*)'/g, + 'import $1 from "$2.js"' + ) + .replace( + '/* render */', + ` + super() + this.root = this.attachShadow({ mode: 'open' }) + this.props = ${props} + + this.root.innerHTML = \`${html}\` + ` + ) + .replace('mounted', 'connectedCallback') + .replace('unmount', 'disconnectedCallback') + .replace('watch', 'attributeChangedCallback') + .replace('adopted', 'adoptedCallback') + + return `/** + * + * @authors yutent (yutent@doui.cc) + * @date ${BUILD_DATE} + * @version v${VERSION} + * + */ + +'use strict' + +${js} + +customElements.define('wc-${name.toLowerCase()}', ${name}) +` +} + +const compileWC = (entry, output) => { + log('编译wc: %s', chalk.green(entry)) + let code = fs.cat(entry).toString() + let style = code.match(/]*?>([\w\W]*?)<\/style>/) + let html = code.match(/