Skip to content
This repository has been archived by the owner on Aug 10, 2023. It is now read-only.

Commit

Permalink
Merge pull request #13 from Violin9906/dev
Browse files Browse the repository at this point in the history
v0.0.1-pre
  • Loading branch information
Violin9906 authored Jun 28, 2020
2 parents 3a55e14 + cce226e commit 0823257
Show file tree
Hide file tree
Showing 30 changed files with 9,746 additions and 1 deletion.
9 changes: 9 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"presets": [
["@babel/preset-env",{
"targets": {
"browsers": ["> 1%", "last 2 versions"]
}
}]
]
}
30 changes: 30 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// https://eslint.org/docs/user-guide/configuring
// File taken from https://github.com/vuejs-templates/webpack/blob/1.3.1/template/.eslintrc.js, thanks.

module.exports = {
root: true,
parserOptions: {
parser: 'babel-eslint'
},
env: {
browser: true,
webextensions: true,
},
extends: [
// https://github.com/vuejs/eslint-plugin-vue#priority-a-essential-error-prevention
// consider switching to `plugin:vue/strongly-recommended` or `plugin:vue/recommended` for stricter rules.
'plugin:vue/essential',
// https://github.com/standard/standard/blob/master/docs/RULES-en.md
'standard' ],
// required to lint *.vue files
plugins: [
'vue'
],
// add your custom rules here
rules: {
// allow async-await
'generator-star-spacing': 'off',
// allow debugger during development
'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'off'
}
}
24 changes: 24 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
*.log
/dist
/dist-zip
.DS_Store
node_modules
.nyc_output

# local env files
.env.local
.env.*.local

# Log files
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# Editor directories and files
.idea
.vscode
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
80 changes: 80 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
language: node_js
node_js:
- "12.13.1"

jobs:
include:
- stage: test
install:
- "yarn install"
script:
- "yarn run test"
- stage: deploy-dev
if: branch = dev
install:
- "yarn install"
script:
- "yarn run build:dev"
after_success:
- "export PKG_VERSION=$(cat package.json | grep version | head -1 | awk -F: '{ print $2 }' | sed 's/[\",]//g' | tr -d '[[:space:]]')"
- cd dist
- "zip -r ../$PKG_VERSION-dev.zip ./"
- cd ..
- git tag v$PKG_VERSION-$TRAVIS_COMMIT
- "echo VERSION: $PKG_VERSION"
deploy:
- provider: releases
token: $GITHUB_TOKEN
file: $PKG_VERSION-dev.zip
prerelease: true
name: v$PKG_VERSION Develop version $TRAVIS_COMMIT
release_notes: "这是一个开发版本,可能存在大量严重bug。请将您使用过程中发现的问题在issue中报告。"
cleanup: false
on:
branch: dev
- stage: deploy-prerelease
if: branch = prerelease
install:
- "yarn install"
script:
- "yarn run build"
after_success:
- "export PKG_VERSION=$(cat package.json | grep version | head -1 | awk -F: '{ print $2 }' | sed 's/[\",]//g' | tr -d '[[:space:]]')"
- cd dist
- "zip -r ../$PKG_VERSION-pre.zip ./"
- cd ..
- git tag v$PKG_VERSION-$TRAVIS_COMMIT
- "echo VERSION: $PKG_VERSION"
deploy:
- provider: releases
token: $GITHUB_TOKEN
file: $PKG_VERSION-pre.zip
prerelease: true
name: v$PKG_VERSION Pre-release version
release_notes: "这是一个预发布版本,请将您使用过程中发现的问题在issue中报告。"
cleanup: false
on:
branch: prerelease
- stage: deploy
if: branch = master
install:
- "yarn install"
script:
- "yarn run build"
after_success:
- "export PKG_VERSION=$(cat package.json | grep version | head -1 | awk -F: '{ print $2 }' | sed 's/[\",]//g' | tr -d '[[:space:]]')"
- cd dist
- "zip -r ../$PKG_VERSION.zip ./"
- cd ..
- git tag v$PKG_VERSION-$TRAVIS_COMMIT
- "echo VERSION: $PKG_VERSION"
deploy:
- provider: releases
token: $GITHUB_TOKEN
file: $PKG_VERSION.zip
name: v$PKG_VERSION
prerelease: false
release_notes: "![GitHub Releases](https://img.shields.io/github/downloads/Violin9906/my-ime2/$PKG_VERSION/total)"
cleanup: false
on:
branch: master
9 changes: 9 additions & 0 deletions IDEA.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# IDEA

## 词库
* 性能问题。或许可以采用WEB SQL数据库来存储词库,使用json文件导入。
* 亟待解决:用户输入自学习算法。

## 智能组句
* 采用统计语言模型。
* 需要语料库进行训练。
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2019 Violin9906 王若麟

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
17 changes: 16 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,17 @@
# my-ime2
A Shuangpin IME for Chrome OS
> A Shuangpin IME for Chrome OS.
> 用于Chrome OS的双拼输入法
## 项目说明
采用新技术构建的my-ime 2.0版本。相较于1.0版,新的my-ime2放弃了完全依赖在线输入api的做法,采用本地词库+用户输入自学习的方式构建一个完全离线可用的可扩展双拼输入法。

目前还处于开发阶段。

my-ime 1.0版:[Violin9906/my-ime](https://github.com/Violin9906/my-ime)

## 开放源代码许可
本项目采用MIT许可证。

## 致谢

感谢Yzzi提供的LOGO设计。
62 changes: 62 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{
"name": "my-ime2",
"version": "0.0.1",
"description": "A Shuangpin IME for Chrome OS.",
"author": "Violin <violincorn@gmail.com>",
"license": "MIT",
"engines": {
"node": ">=10"
},
"scripts": {
"lint": "eslint --ext .js,.vue --fix src",
"build": "cross-env NODE_ENV=production webpack --hide-modules",
"build:dev": "cross-env NODE_ENV=development webpack --hide-modules",
"build-zip": "node scripts/build-zip.js",
"watch": "npm run build -- --watch",
"watch:dev": "cross-env HMR=true npm run build:dev -- --watch",
"test": "nyc mocha ./tests"
},
"dependencies": {
"axios": "^0.19.0",
"vue": "^2.6.10"
},
"devDependencies": {
"@babel/core": "^7.1.2",
"@babel/plugin-proposal-optional-chaining": "^7.0.0",
"@babel/preset-env": "^7.1.0",
"@babel/runtime-corejs3": "^7.4.0",
"@types/chrome": "^0.0.74",
"archiver": "^3.0.0",
"babel-eslint": "^10.0.3",
"babel-loader": "^8.0.2",
"babel-preset-env": "^1.7.0",
"chai": "^4.2.0",
"copy-webpack-plugin": "^5.1.1",
"core-js": "^3.0.1",
"cross-env": "^5.2.0",
"css-loader": "^3.4.0",
"ejs": "^2.6.1",
"eslint": "^6.6.0",
"eslint-config-standard": "^14.1.0",
"eslint-friendly-formatter": "^4.0.1",
"eslint-loader": "^3.0.2",
"eslint-plugin-import": "^2.18.2",
"eslint-plugin-node": "^10.0.0",
"eslint-plugin-promise": "^4.2.1",
"eslint-plugin-standard": "^4.0.1",
"eslint-plugin-vue": "^6.0.1",
"file-loader": "^5.0.2",
"json-loader": "^0.5.7",
"mini-css-extract-plugin": "^0.9.0",
"mocha": "^7.0.1",
"node-sass": "^4.9.3",
"nyc": "^15.0.0",
"sass-loader": "^7.1.0",
"sinon": "^8.1.1",
"vue-loader": "^15.4.2",
"vue-template-compiler": "^2.6.10",
"webpack": "^4.20.2",
"webpack-cli": "^3.3.10",
"webpack-extension-reloader": "^1.1.0"
}
}
53 changes: 53 additions & 0 deletions scripts/build-zip.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/usr/bin/env node

const fs = require('fs')
const path = require('path')
const archiver = require('archiver')

const DEST_DIR = path.join(__dirname, '../dist')
const DEST_ZIP_DIR = path.join(__dirname, '../dist-zip')

const extractExtensionData = () => {
const extPackageJson = require('../package.json')

return {
name: extPackageJson.name,
version: extPackageJson.version
}
}

const makeDestZipDirIfNotExists = () => {
if (!fs.existsSync(DEST_ZIP_DIR)) {
fs.mkdirSync(DEST_ZIP_DIR)
}
}

const buildZip = (src, dist, zipFilename) => {
console.info(`Building ${zipFilename}...`)

const archive = archiver('zip', { zlib: { level: 9 } })
const stream = fs.createWriteStream(path.join(dist, zipFilename))

return new Promise((resolve, reject) => {
archive
.directory(src, false)
.on('error', err => reject(err))
.pipe(stream)

stream.on('close', () => resolve())
archive.finalize()
})
}

const main = () => {
const { name, version } = extractExtensionData()
const zipFilename = `${name}-v${version}.zip`

makeDestZipDirIfNotExists()

buildZip(DEST_DIR, DEST_ZIP_DIR, zipFilename)
.then(() => console.info('OK'))
.catch(console.err)
}

main()
36 changes: 36 additions & 0 deletions src/background.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
var MyIME = require('./ime/my-ime.js')

var ime = null

chrome.input.ime.onFocus.addListener(function (context) {
console.log('onFocus:' + context.contextID)
console.log(context)
ime.onFocus(context.contextID)
})

chrome.input.ime.onBlur.addListener(function (contextID) {
console.log('onBlur:' + contextID)
ime.onBlur()
})

chrome.input.ime.onReset.addListener(function (engineID) {
ime.onReset()
})

chrome.input.ime.onActivate.addListener(function (engineID) {
console.log('onActivate:' + engineID)
ime = MyIME
MyIME.Init(engineID)
console.log('IME:')
console.log(ime)
})

chrome.input.ime.onDeactivated.addListener(function (engineID) {
console.log('onDeactivated:' + engineID)
ime.clearInput()
ime = null
})

chrome.input.ime.onKeyEvent.addListener(function (engineID, keyData) {
return ime.handleKeyEvent(keyData)
})
29 changes: 29 additions & 0 deletions src/dict/basic.js

Large diffs are not rendered by default.

32 changes: 32 additions & 0 deletions src/dict/match.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
const BasicDict = require('./basic.js')

const Dicts = [BasicDict]

var Match = {
result: [],
trans: function (text) {
this.result = []
for (var i in Dicts) {
if (Dicts[i][text]) {
// all match
for (var char in Dicts[i][text]) {
this.result.push({ char: Dicts[i][text][char], pinyin: text })
}
} else {
// partical match
var index = text.length
while (index !== -1) {
if (Dicts[i][text.slice(0, index)]) {
for (char in Dicts[i][text.slice(0, index)]) {
this.result.push({ char: Dicts[i][text.slice(0, index)][char], pinyin: text.slice(0, index) })
}
}
index = text.slice(0, index).lastIndexOf(' ')
}
}
}
return this.result
}
}

module.exports = Match
Binary file added src/icons/icon_128.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/icons/icon_48.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 0823257

Please sign in to comment.