From 5db0050584abd9e3b5fb2f4415c60b1ac93bca74 Mon Sep 17 00:00:00 2001 From: Harvey Zack Date: Thu, 11 Oct 2018 11:25:51 +0800 Subject: [PATCH] add files --- package.json | 4 +++ rollup.config.js | 4 ++- src/{menus.js => contextmenu.js} | 0 src/events.js | 0 src/hotkey.js | 0 src/i18n/en.js | 3 ++ src/i18n/index.js | 22 +++++++++++++ src/i18n/jp.js | 3 ++ src/i18n/zh-CN.js | 3 ++ src/i18n/zh-TW.js | 3 ++ src/icons/index.js | 0 src/index.js | 53 +++++++++++++++++++++++++++++--- src/screenshot.js | 0 src/utils/error.js | 0 src/utils/verification.js | 0 15 files changed, 90 insertions(+), 5 deletions(-) rename src/{menus.js => contextmenu.js} (100%) create mode 100644 src/events.js create mode 100644 src/hotkey.js create mode 100644 src/icons/index.js create mode 100644 src/screenshot.js create mode 100644 src/utils/error.js create mode 100644 src/utils/verification.js diff --git a/package.json b/package.json index 528bc4a16..fa53ca45e 100644 --- a/package.json +++ b/package.json @@ -35,9 +35,13 @@ "rollup": "^0.66.5", "rollup-plugin-babel": "^4.0.3", "rollup-plugin-commonjs": "^9.2.0", + "rollup-plugin-eslint": "^5.0.0", "rollup-plugin-node-resolve": "^3.4.0", "rollup-plugin-postcss": "^1.6.2", "rollup-plugin-replace": "^2.1.0", "rollup-plugin-uglify": "^6.0.0" + }, + "dependencies": { + "tiny-emitter": "^2.0.2" } } diff --git a/rollup.config.js b/rollup.config.js index 36e1a98b2..de0f305a9 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -2,6 +2,7 @@ const babel = require("rollup-plugin-babel"); const commonjs = require("rollup-plugin-commonjs"); const nodeResolve = require("rollup-plugin-node-resolve"); const postcss = require("rollup-plugin-postcss"); +const { eslint } = require("rollup-plugin-eslint"); const autoprefixer = require("autoprefixer"); const cssnano = require("cssnano"); const replace = require("rollup-plugin-replace"); @@ -33,6 +34,7 @@ export default { __ENV__: JSON.stringify(process.env.NODE_ENV || "development"), __VERSION__: version }), - isProd && uglify() + isProd && uglify(), + !isProd && eslint() ] }; diff --git a/src/menus.js b/src/contextmenu.js similarity index 100% rename from src/menus.js rename to src/contextmenu.js diff --git a/src/events.js b/src/events.js new file mode 100644 index 000000000..e69de29bb diff --git a/src/hotkey.js b/src/hotkey.js new file mode 100644 index 000000000..e69de29bb diff --git a/src/i18n/en.js b/src/i18n/en.js index e69de29bb..ff2dbcee8 100644 --- a/src/i18n/en.js +++ b/src/i18n/en.js @@ -0,0 +1,3 @@ +export default { + +} \ No newline at end of file diff --git a/src/i18n/index.js b/src/i18n/index.js index e69de29bb..432c9351a 100644 --- a/src/i18n/index.js +++ b/src/i18n/index.js @@ -0,0 +1,22 @@ +import ZHCN from "./zh-CN"; +import ZHTW from "./zh-TW"; +import EN from "./en"; +import JP from "./jp"; + +const i18nMap = { + "zh": ZHCN, + "zh-CN": ZHCN, + "zh-TW": ZHTW, + "en": EN, + "jp": JP +}; + +export default class I18n { + constructor({ option }) { + this.language = i18nMap[option.language || "en"]; + } + + get(key) { + return this.language[key] || key; + } +} diff --git a/src/i18n/jp.js b/src/i18n/jp.js index e69de29bb..ff2dbcee8 100644 --- a/src/i18n/jp.js +++ b/src/i18n/jp.js @@ -0,0 +1,3 @@ +export default { + +} \ No newline at end of file diff --git a/src/i18n/zh-CN.js b/src/i18n/zh-CN.js index e69de29bb..ff2dbcee8 100644 --- a/src/i18n/zh-CN.js +++ b/src/i18n/zh-CN.js @@ -0,0 +1,3 @@ +export default { + +} \ No newline at end of file diff --git a/src/i18n/zh-TW.js b/src/i18n/zh-TW.js index e69de29bb..ff2dbcee8 100644 --- a/src/i18n/zh-TW.js +++ b/src/i18n/zh-TW.js @@ -0,0 +1,3 @@ +export default { + +} \ No newline at end of file diff --git a/src/icons/index.js b/src/icons/index.js new file mode 100644 index 000000000..e69de29bb diff --git a/src/index.js b/src/index.js index e01631c84..91a9e982f 100644 --- a/src/index.js +++ b/src/index.js @@ -1,17 +1,62 @@ import "./style/index.scss"; +import Emitter from 'tiny-emitter'; +import { verification } from "./utils"; +import I18n from "./i18n"; +import Player from "./player"; +import Controls from "./controls"; +import Screenshot from "./screenshot"; +import Contextmenu from "./contextmenu"; +import Danmu from "./danmu"; +import Info from "./info"; +import Captions from "./captions"; +import Events from "./events"; +import Hotkey from "./hotkey"; -class Artplayer { +let id = 0; +export const instances = []; + +class Artplayer extends Emitter { constructor(option) { - // + super(); + this.option = Object.assign({}, Artplayer.DEFAULTS, option); + verification(this.option); + this.init(); } static get version() { - return __VERSION__; + return "__VERSION__"; } static get DEFAULTS() { return { - // + // }; } + + init() { + this.refs = {}; + this.destroyEvents = []; + + this.i18n = new I18n(this); + this.player = new Player(this); + this.controls = new Controls(this); + this.screenshot = new Screenshot(this); + this.contextmenu = new Contextmenu(this); + this.danmu = new Danmu(this); + this.captions = new Captions(this); + this.info = new Info(this); + this.events = new Events(this); + this.hotkey = new Hotkey(this); + + this.id = id++; + instances.push(this); + } + + destroy() { + this.destroyEvents.forEach(event => event.destroy()); + this.refs.container.innerHTML = ""; + } } + +window.Artplayer = Artplayer; +export default Artplayer; diff --git a/src/screenshot.js b/src/screenshot.js new file mode 100644 index 000000000..e69de29bb diff --git a/src/utils/error.js b/src/utils/error.js new file mode 100644 index 000000000..e69de29bb diff --git a/src/utils/verification.js b/src/utils/verification.js new file mode 100644 index 000000000..e69de29bb