<commit_before>import React from 'react'
import { connect } from 'react-redux'
import { ImportStyle } from 'sp-css-import'
import htmlHead from 'Utils/html-head.js'

import modeBackgroundOnAnimationEnd from '../logic/app-mode/mode-background.js'
import { swipedFromLeftEdge } from '../logic/side-menu/api.js'

import style from './app.less'

import Main from './layout/main.jsx'
import MainMask from './layout/main-mask.jsx'
import Nav from './layout/nav.jsx'
import Bgimg from './layout/bgimg.jsx'

let startSwipeAtLeftBorder = false

@connect(state => ({
    isMainBgimgLoaded: state.bgimg.isMainLoaded,
    appMode: state.appMode
}))
@ImportStyle(style)
export default class extends React.Component {
    /*
     * this.isAppReady      是否已初始化
     */

    // 仅针对 __SERVER__
    // static preprocess(state, dispatch) {
    //     const preprocessTasks = []
    //     preprocessTasks.push(
    //     )
    //     return preprocessTasks
    // }

    // 仅针对 __SERVER__
    static htmlExtends(ext, store) {
        if (__SERVER__) require('../logic/database/index.js').init()

        const head = htmlHead({
            state: store.getState()
        })

        ext.meta = ext.meta.concat(head.meta)
        ext.title = head.title
    }

    appReady(timeout = 0) {
        if (__CLIENT__ && !this.isAppReady) {
            this.isAppReady = true

            if ('serviceWorker' in navigator) {
                // console.log('Service Worker SUPPORTED')
                navigator.serviceWorker.register(self.__SERVICE_WORKER_FILENAME__, {
                    scope: '/'
                }).then((reg) => {
                    // console.log('Service Worker register', reg)
                }).catch((err) => {
                    console.log('Service Worker SUPPORTED. ERROR', err)
                })
            } else {
                console.log('Service Worker NOT-SUPPORTED')
            }

            setTimeout(() => {
                console.log('appReady')
                document.body.classList.add('is-ready')
            }, timeout)
        }
    }

    get className() {
        return this.props.className
            + (this.isAppReady && this.props.appMode.mode
                ? (' is-mode-' + this.props.appMode.mode
                    + (!this.props.appMode.leaving && this.props.appMode.animation ? (' is-mode-' + this.props.appMode.mode + '-entering') : '')
                    + (this.props.appMode.leaving ? (' is-mode-' + this.props.appMode.mode + '-leaving') : '')
                )
                : ''
            )
    }

    onAnimationEnd(evt) {
        const action = modeBackgroundOnAnimationEnd(evt.nativeEvent)
        if (action) this.props.dispatch(action)
    }

    onTouchStart(evt) {
        if (this.isAppReady && evt.nativeEvent.touches[0].pageX < 15)
            startSwipeAtLeftBorder = {
                x: evt.nativeEvent.touches[0].screenX,
                y: evt.nativeEvent.touches[0].screenY,
                timestamp: (new Date()).valueOf()
            }
        else
            startSwipeAtLeftBorder = false
    }

    onTouchMove(evt) {
        if (startSwipeAtLeftBorder) {
            const deltaX = evt.nativeEvent.touches[0].screenX - startSwipeAtLeftBorder.x
            const deltaY = evt.nativeEvent.touches[0].screenY - startSwipeAtLeftBorder.y
            const elapseTime = (new Date()).valueOf() - startSwipeAtLeftBorder.timestamp

            if (elapseTime > 200) {
                startSwipeAtLeftBorder = false
                return
            }

            if (Math.max(Math.abs(deltaX), Math.abs(deltaY)) > 10) {
                if (deltaX > 10 && deltaX >= Math.abs(deltaY) && deltaX / elapseTime > (10 / 200)) {<commit_msg>side menu gesture<commit_after>import React from 'react'
import { connect } from 'react-redux'
import { ImportStyle } from 'sp-css-import'
import htmlHead from 'Utils/html-head.js'

import modeBackgroundOnAnimationEnd from '../logic/app-mode/mode-background.js'
import { swipedFromLeftEdge } from '../logic/side-menu/api.js'

import style from './app.less'

import Main from './layout/main.jsx'
import MainMask from './layout/main-mask.jsx'
import Nav from './layout/nav.jsx'
import Bgimg from './layout/bgimg.jsx'

let startSwipeAtLeftBorder = false

@connect(state => ({
    isMainBgimgLoaded: state.bgimg.isMainLoaded,
    appMode: state.appMode
}))
@ImportStyle(style)
export default class extends React.Component {
    /*
     * this.isAppReady      是否已初始化
     */

    // 仅针对 __SERVER__
    // static preprocess(state, dispatch) {
    //     const preprocessTasks = []
    //     preprocessTasks.push(
    //     )
    //     return preprocessTasks
    // }

    // 仅针对 __SERVER__
    static htmlExtends(ext, store) {
        if (__SERVER__) require('../logic/database/index.js').init()

        const head = htmlHead({
            state: store.getState()
        })

        ext.meta = ext.meta.concat(head.meta)
        ext.title = head.title
    }

    appReady(timeout = 0) {
        if (__CLIENT__ && !this.isAppReady) {
            this.isAppReady = true

            if ('serviceWorker' in navigator) {
                // console.log('Service Worker SUPPORTED')
                navigator.serviceWorker.register(self.__SERVICE_WORKER_FILENAME__, {
                    scope: '/'
                }).then((reg) => {
                    // console.log('Service Worker register', reg)
                }).catch((err) => {
                    console.log('Service Worker SUPPORTED. ERROR', err)
                })
            } else {
                console.log('Service Worker NOT-SUPPORTED')
            }

            setTimeout(() => {
                console.log('appReady')
                document.body.classList.add('is-ready')
                setTimeout(() => {
                    this.isAppReadyFull = true
                }, 1000)
            }, timeout)
        }
    }

    get className() {
        return this.props.className
            + (this.isAppReady && this.props.appMode.mode
                ? (' is-mode-' + this.props.appMode.mode
                    + (!this.props.appMode.leaving && this.props.appMode.animation ? (' is-mode-' + this.props.appMode.mode + '-entering') : '')
                    + (this.props.appMode.leaving ? (' is-mode-' + this.props.appMode.mode + '-leaving') : '')
                )
                : ''
            )
    }

    onAnimationEnd(evt) {
        const action = modeBackgroundOnAnimationEnd(evt.nativeEvent)
        if (action) this.props.dispatch(action)
    }

    onTouchStart(evt) {
        if (this.isAppReadyFull && evt.nativeEvent.touches[0].pageX < 15)
            startSwipeAtLeftBorder = {
                x: evt.nativeEvent.touches[0].screenX,
                y: evt.nativeEvent.touches[0].screenY,
                timestamp: (new Date()).valueOf()
            }
        else
            startSwipeAtLeftBorder = false
    }

    onTouchMove(evt) {
        if (startSwipeAtLeftBorder) {
            const deltaX = evt.nativeEvent.touches[0].screenX - startSwipeAtLeftBorder.x
            const deltaY = evt.nativeEvent.touches[0].screenY - startSwipeAtLeftBorder.y
            const elapseTime = (new Date()).valueOf() - startSwipeAtLeftBorder.timestamp

            if (elapseTime > 200) {
                startSwipeAtLeftBorder = false
                return
            }

            if (Math.max(Math.abs(deltaX), Math.abs(deltaY)) > 10) {
                if (deltaX > 10 && deltaX >= Math.abs(deltaY) && deltaX / elapseTime > (10 / 200)) {
{'fraction_non_alphanumeric': 0.12787146461293322, 'fraction_numerical': 0.005842517593945027, 'mean_word_length': 1.8125466766243465, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 22, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5134967', 'n_tokens_mistral': 2298, 'n_tokens_neox': 2213, 'n_words': 400}