<commit_before>import { render } from 'omi'
import ajax from '@fdaciuk/ajax'

let appOption = null
function App(option) {
  appOption = option
}

function getApp() {
  return appOption
}

function Page(option) {
  return option
}

function Component(option) {
  return option
}

function noop() {}

const wx = {}

wx.canIUse = function() {
  return false
}

wx.getStorageSync = noop

wx.getSystemInfoSync = function() {
  return {
    windowWidth: window.innerWidth,
    windowHeight: window.innerHeight,
    pixelRatio: window.devicePixelRadio
  }
}

wx.getSystemInfo = function(options){
  options.success({
    windowWidth: window.innerWidth,
    windowHeight: window.innerHeight,
    pixelRatio: window.devicePixelRadio
  })
}

wx.getUserInfo = function() {
  console.warn('wx.getUserInfo method cannot be invoked in browser.')
}

wx.navigateTo = function(option) {
  route.query = getUrlParams(option.url)
  route.to(option.url, option)
}

function getUrlParam(name, url){
  if(!name){
      return ''
  }
  url = url || location.search
  name = name.replace(/(?=[\\^$*+?.():|{}])/, '\\')
  var reg = new RegExp('(?:[?&]|^)' + name + '=([^?&#]*)', 'i')
  var match = url.match(reg)
  return !match ? '' : match[1]
}

wx.setNavigationBarTitle = function(option){
  document.title = option.title
}

function getUrlParams(url) {
  url = url.replace(/#.*$/, '')
  var queryArray = url.split(/[?&]/).slice(1)
  var i, args = {}
  for (i = 0; i < queryArray.length; i++) {
      var match = queryArray[i].match(/([^=]+)=([^=]+)/)
      if (match !== null) {
          args[match[1]] = decodeURIComponent(match[2])
      }
  }
  return args
}

export function routeUpdate(node, selector, byNative, root) {
  root.childNodes.forEach(child => {
    child.style.display = 'none'
  })
  if (byNative) {
    const ele = document.querySelector(selector)
    if (ele) {
      ele.style.display = 'block'
      document.documentElement.scrollTop = ele._preScrollTop
      document.body.scrollTop = ele._preScrollTop
      //set twice
      setTimeout(function(){
        document.documentElement.scrollTop = ele._preScrollTop
        document.body.scrollTop = ele._preScrollTop
      }, 0)
    } else {
      render(node, root)
      document.documentElement.scrollTop = 0
      document.body.scrollTop = 0
    }
  } else {
    const ele = document.querySelector(selector)
    ele && ele.parentNode.removeChild(ele)
    render(node, root)
    document.documentElement.scrollTop = 0
    document.body.scrollTop = 0
  }
}

wx.request = function(options){
  const request = ajax({
    method: options.method || 'GET',
    url: options.url,
    data: options.data,
    headers: options.header
  })

  request.then((data, xhr)=>{
    options.success({
      data: data,
      statusCode: xhr.status<commit_msg>omi-mp - onShow and onHide of page support<commit_after>import { render } from 'omi'
import ajax from '@fdaciuk/ajax'

let appOption = null
function App(option) {
  appOption = option
}

function getApp() {
  return appOption
}

function Page(option) {
  return option
}

function Component(option) {
  return option
}

function noop() {}

const wx = {}

wx.canIUse = function() {
  return false
}

wx.getStorageSync = noop

wx.getSystemInfoSync = function() {
  return {
    windowWidth: window.innerWidth,
    windowHeight: window.innerHeight,
    pixelRatio: window.devicePixelRadio
  }
}

wx.getSystemInfo = function(options){
  options.success({
    windowWidth: window.innerWidth,
    windowHeight: window.innerHeight,
    pixelRatio: window.devicePixelRadio
  })
}

wx.getUserInfo = function() {
  console.warn('wx.getUserInfo method cannot be invoked in browser.')
}

wx.navigateTo = function(option) {
  route.query = getUrlParams(option.url)
  route.to(option.url, option)
}

function getUrlParam(name, url){
  if(!name){
      return ''
  }
  url = url || location.search
  name = name.replace(/(?=[\\^$*+?.():|{}])/, '\\')
  var reg = new RegExp('(?:[?&]|^)' + name + '=([^?&#]*)', 'i')
  var match = url.match(reg)
  return !match ? '' : match[1]
}

wx.setNavigationBarTitle = function(option){
  document.title = option.title
}

function getUrlParams(url) {
  url = url.replace(/#.*$/, '')
  var queryArray = url.split(/[?&]/).slice(1)
  var i, args = {}
  for (i = 0; i < queryArray.length; i++) {
      var match = queryArray[i].match(/([^=]+)=([^=]+)/)
      if (match !== null) {
          args[match[1]] = decodeURIComponent(match[2])
      }
  }
  return args
}

export function routeUpdate(vnode, selector, byNative, root) {
  root.childNodes.forEach(child => {
    if(child.style.display !== 'none'){
      child.style.display = 'none'
      child.onHide && child.onHide()
    }
  })
  if (byNative) {
    const ele = document.querySelector(selector)
    if (ele) {
      ele.style.display = 'block'
      ele.onShow && ele.onShow()
      document.documentElement.scrollTop = ele._preScrollTop
      document.body.scrollTop = ele._preScrollTop
      //set twice
      setTimeout(function(){
        document.documentElement.scrollTop = ele._preScrollTop
        document.body.scrollTop = ele._preScrollTop
      }, 0)
    } else {
      const node = render(vnode, root)
      node.onShow && node.onShow()
      document.documentElement.scrollTop = 0
      document.body.scrollTop = 0
    }
  } else {
    const ele = document.querySelector(selector)
    ele && ele.parentNode.removeChild(ele)
    const node = render(vnode, root)
    node.onShow && node.onShow()
    document.documentElement.scrollTop = 0
    document.body.scrollTop = 0
  }
}

wx.request = function(options){
  const request = ajax({
    method: options.method || 'GET',
    url: options.url,
    data: options.data,
    headers: options.header
  })

  request.then((data, xhr)=>{
    options.success({
      data: data,
      statusCode: xhr.status
{'fraction_non_alphanumeric': 0.15238258484744602, 'fraction_numerical': 0.0034281796366129585, 'mean_word_length': 3.1738197424892705, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, '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': '1198606', 'n_tokens_mistral': 1938, 'n_tokens_neox': 1925, 'n_words': 405}