import { Player, $ } from '@oplayer/core' import Danmaku from 'danmaku' import { getMode } from './danmaku-parse' import { Options, Comment } from './types' function registerInputStyle() { const modeSelectionWrap = $.css(` display: none; box-sizing: border-box; width: 216px; height: auto; padding: 2px 0 0; position: absolute; bottom: 100%; left: 50%; margin-left: -108px; background: rgba(21,21,21,.9); border-radius: 2px; user-select: none;`) const modeSelectionRowSelection = $.css(` display: flex; flex-wrap: wrap; margin: 8px -8px 0 0;`) const danmakuTypeWrap = $.css({ width: '30px', height: '30px', padding: '3px 0', 'line-height': '30px', 'text-align': 'center', color: 'hsla(0,0%,100%,.8)', fill: '#757575', position: 'relative', 'box-sizing': 'border-box', cursor: 'pointer', '&:hover': { fill: 'var(--primary-color)' }, [`&:hover .${modeSelectionWrap}`]: { display: 'block' }, [`& .${modeSelectionRowSelection} label`]: { flex: 1, 'margin-bottom': '8px' }, '& input[type="radio"]': { display: 'none' }, '& input[type="radio"]:checked + label > div': { background: 'var(--primary-color)' } }) const danmakuType = $.css(` display: inline-flex; height: 100%; align-items: center; `) const danmakuTypeIcon = $.css(` display: block; width: 36px; height: 24px; `) const danmakuTypeSvg = $.css(`width: 100%;height: 100%;transition: fill .15s ease-in-out;`) const modeSelectionRow = $.css(` min-height: 22px; margin: 10px 20px; width: 176px; line-height: 22px; font-size: 12px;`) const modeSelectionRowTitle = $.css(`text-align: left;color: #fff; line-height: 16px;`) const modeSelectionSpan = $.css(` position: relative; cursor: pointer; border-radius: 2px; color: #fff; text-align: center; margin-right: 8px; background: hsla(0,0%,100%,.2); font-size: 12px; `) const colorPickerInput = $.css(` outline: none; background-color: transparent; color: #fff; border: 1px solid hsla(0,0%,100%,.2); border-radius: 2px; padding: 4px 7px; margin: 0 auto 8px auto; transition: background .2s; color:#000;background:#fff;text-shadow: 0px 0px 6px #FFF;text-align: center; `) const colorPickerWrap = $.css( `display: grid;grid-template-columns: repeat(7,auto);width: 100%;justify-items: center;` ) const activeColor = $.css('box-shadow: 0 0 1px 1px #fff;border-color: #000;') const colorPicker = $.css(` width: 16px; height: 16px; border: 1px solid rgba(0,0,0,.3); box-sizing: border-box; border-radius: 2px; margin-bottom: 4px; cursor: pointer; display: inline-block; `) const inputBar = $.css(` min-width: 25em; border-radius: 6px; background: #f4f4f4; color: #999; height:85%; `) const inputBarWrap = $.css(` flex: 1; display: flex; align-items: center; `) const input = $.css(` flex-grow: 1; padding: 0 8px; height: 28px; border: 0; -webkit-box-sizing: border-box; box-sizing: border-box; background: none; line-height: 28px; color: #212121; font-size: 12px; text-decoration: none; outline: none; touch-action: manipulation; `) const send = $.css(` height: 100%; width: 62px; min-width: 62px; border-radius: 0 6px 6px 0; cursor: pointer; width: 60px; min-width: 60px; box-sizing: border-box; overflow: hidden; `) const sendBottom = $.css(` height: 100%; background-color: var(--primary-color,#6668ab); color: #fff; min-width: 60px; outline: none; font-size: 14px; display: flex; align-items: center; justify-content: center; `) return { inputBar, inputBarWrap, input, send, sendBottom, danmakuTypeWrap, danmakuType, danmakuTypeIcon, danmakuTypeSvg, modeSelectionWrap, modeSelectionRow, modeSelectionRowTitle, modeSelectionRowSelection, modeSelectionSpan, colorPicker, colorPickerInput, colorPickerWrap, activeColor } } export function registerInput(player: Player, danmaku: Danmaku, options: Options) { if (!player.context.ui) return const { inputBar, inputBarWrap, input, send, sendBottom, danmakuTypeWrap, danmakuType, danmakuTypeIcon, danmakuTypeSvg, modeSelectionWrap, modeSelectionRow, modeSelectionRowTitle, modeSelectionRowSelection, modeSelectionSpan, colorPickerWrap, colorPicker, colorPickerInput, activeColor } = registerInputStyle() const $tpl = $.create( `div.${inputBar}`, {}, `