Browse Source

wow it all works kinda

pull/24/head
Guillermo 10 years ago
parent
commit
5b02e236c1
  1. 105
      animation/animate.js
  2. 2
      codemirror/codemirror.css
  3. 93
      css/color.css
  4. 12
      css/explorer.css
  5. 184
      css/wau.css
  6. BIN
      img/chi_sim.png
  7. BIN
      img/chinese.png
  8. 0
      img/eng.png
  9. BIN
      img/redstars.png
  10. BIN
      img/rus.png
  11. BIN
      img/tha.png
  12. 238
      index.html
  13. 160
      index_dev.html
  14. 400
      main.js
  15. 233
      main_dev.js
  16. 0
      src/explorer.js
  17. 236
      src/index.html
  18. 400
      src/main.js

105
animation/main.js → animation/animate.js

@ -1,35 +1,3 @@
// (function(){
// var color = "rgb(255,133,0)"
// var color = "rgb(55,110,79)"
var color="white"
// var color = "rgb(255,221,21)"
// var color = '#'+(16777216+Math.floor(Math.random()*16777215)).toString(16).slice(1)
// document.styleSheets[0].insertRule("a {color: "+color+"}",0)
var lasttime,
canvas = document.getElementById('canvas'),
ctx = canvas.getContext('2d');
// canvas.style['background-color'] = color;
var logo = new Image(), logo_small = new Image()
logo.src = 'img/logo.png'
logo_small.src = 'img/logo.png'
// var pixelRatio = (function(context) {
// var backingStore = context.backingStorePixelRatio ||
// context.webkitBackingStorePixelRatio ||
// context.mozBackingStorePixelRatio ||
// context.msBackingStorePixelRatio ||
// context.oBackingStorePixelRatio ||
// context.backingStorePixelRatio || 1;
// return (window.devicePixelRatio || 1) / backingStore;
// })(ctx);
function app1(p,a,c1,c2){ function app1(p,a,c1,c2){
var l = Math.cos(a)*p[c1]+Math.sin(a)*p[c2] var l = Math.cos(a)*p[c1]+Math.sin(a)*p[c2]
var k = -Math.sin(a)*p[c1]+Math.cos(a)*p[c2] var k = -Math.sin(a)*p[c1]+Math.cos(a)*p[c2]
@ -91,6 +59,40 @@ function project(point, size){
} }
} }
// (function(){
// var color = "rgb(255,133,0)"
// var color = "rgb(55,110,79)"
var color="white"
// var color = "rgb(255,221,21)"
// var color = '#'+(16777216+Math.floor(Math.random()*16777215)).toString(16).slice(1)
// document.styleSheets[0].insertRule("a {color: "+color+"}",0)
var lasttime,
canvas = document.getElementById('canvas'),
ctx = canvas.getContext('2d');
// canvas.style['background-color'] = color;
var logo = new Image(), logo_small = new Image()
logo.src = 'img/logo.png'
logo_small.src = 'img/logo.png'
// var pixelRatio = (function(context) {
// var backingStore = context.backingStorePixelRatio ||
// context.webkitBackingStorePixelRatio ||
// context.mozBackingStorePixelRatio ||
// context.msBackingStorePixelRatio ||
// context.oBackingStorePixelRatio ||
// context.backingStorePixelRatio || 1;
// return (window.devicePixelRatio || 1) / backingStore;
// })(ctx);
function init () { function init () {
fixdim() fixdim()
@ -99,16 +101,39 @@ function init () {
} }
function fixdim() { function fixdim() {
if(dimensions.update()){ dimensions.update()
var displaywidth = Math.sqrt(dimensions.width)*18//dimensions.width > 900 ? 900 : 450
var displayheight = displaywidth * 4/15//dimensions.width > 900 ? 250 : 125 var displaywidth = Math.sqrt(dimensions.width)*18//dimensions.width > 900 ? 900 : 450
canvas.width = displaywidth*window.devicePixelRatio
canvas.style.width = displaywidth var doc = document.documentElement;
canvas.height = displayheight*window.devicePixelRatio var top = (window.pageYOffset || doc.scrollTop) - (doc.clientTop || 0);
canvas.style.height = displayheight var header = document.querySelector('.stickyheader')
}
document.getElementById('logo').style.top = top /2
var rect = document.querySelector('.marterial').getBoundingClientRect()
var bottom = rect.top + rect.height
// console.log(bottom)
// if(bottom < 100){
// document.getElementById('logo').style.left = bottom - 100
// }
var fadestart = Math.min(rect.height/2, 100)
header.style['background-color'] = 'rgba(0, 219, 157,'+Math.max(Math.min((-bottom+fadestart),1),0)+')'
header.querySelector('.smalllogo').style.opacity = Math.max(Math.min((-bottom+fadestart)*2/fadestart,1),0)
document.getElementById('logo').style.opacity = Math.max(Math.min((bottom-fadestart)/fadestart,1),0)
var displayheight = displaywidth * 4/15//dimensions.width > 900 ? 250 : 125
canvas.width = displaywidth*window.devicePixelRatio
canvas.style.width = displaywidth
canvas.height = displayheight*window.devicePixelRatio
canvas.style.height = displayheight
} }
addEventListener('scroll', fixdim)
function drawtesseract(tesseract, opts){ function drawtesseract(tesseract, opts){
var edges = tesseractedges() var edges = tesseractedges()
for (var i = 0; i < tesseract.length; i++) { for (var i = 0; i < tesseract.length; i++) {

2
codemirror/codemirror.css

@ -115,7 +115,7 @@ div.CodeMirror-overwrite div.CodeMirror-cursor {}
.cm-s-default .cm-operator {} .cm-s-default .cm-operator {}
.cm-s-default .cm-variable-2 {color: #05a;} .cm-s-default .cm-variable-2 {color: #05a;}
.cm-s-default .cm-variable-3 {color: #085;} .cm-s-default .cm-variable-3 {color: #085;}
.cm-s-default .cm-comment {color: #a50;} .cm-s-default .cm-comment {color: #DB0000;}
.cm-s-default .cm-string {color: #5426C9;} .cm-s-default .cm-string {color: #5426C9;}
.cm-s-default .cm-string-2 {color: #f50;} .cm-s-default .cm-string-2 {color: #f50;}
.cm-s-default .cm-meta {color: #555;} .cm-s-default .cm-meta {color: #555;}

93
css/color.css

@ -1,93 +0,0 @@
#wow {
}
#splash {
/*border-bottom: solid 1px #ddd;*/
/*background-color: #222*/
}
.desc {
/* text-shadow: 0px 0px 2px rgba(0, 131, 255, 0.53); */
}
.headernav {
}
.vr {
}
/*.ellipsis {
background-color: rgb(58, 51, 60);
color: white;
padding: 3px;
border-radius: 2px;
}*/
.getStarted {
}
.npm {
}
#marterial {
/*background: linear-gradient(#27C6F9 80%, #0CB5EB 100%);*/
/*background-attachment: fixed;*/
}
.demoheader .CodeMirror {
}
.runbutton {
}
.demo {
}
.hint {
}
body {
}
hr {
}
a {
}
.manyLanguages {
/*color: #C8D1F3;*/
}
button {
}
button:hover {
}
@media (max-width: 914px) {
button:hover {
background: rgba(255,255,255,.3);
border: solid 1px #fff;
}
.desc {
color: #FFFFFF;
text-shadow: 0px 0px 3px rgba(58, 58, 58, 1);
}
/*#splash {
background-color: #27C6F9;
}*/
}

12
css/explorer.css

@ -1,22 +1,14 @@
#explorer { #explorer {
max-width: 500px;
max-height: 500px; max-height: 500px;
white-space: nowrap; white-space: nowrap;
overflow: scroll; overflow: scroll;
padding: 10px; padding: 10px;
/*border: 1px solid #eee;*/
border: 1px solid #eee;
border-radius: 5px; border-radius: 5px;
font-family: monospace; font-family: monospace;
background-color: #fff;
} }
@media (max-width: 914px) {
#explorer {
margin: 8%;
}
}
.textNode { .textNode {
display: inline-block; display: inline-block;

184
css/wau.css

@ -3,24 +3,93 @@
width: 100%; width: 100%;
min-height: 100%; min-height: 100%;
} }
.stretch {
max-width: 100%
}
.langpair {
display: inline-block;
padding: -1px;
font-family: monospace;
text-align: center;
/*border: 1px solid #F3F3F3;*/
margin-bottom: 10px;
margin-right: 5px;
font-size: initial;
line-height: 1.5em;
flex-grow:1;
}
.footer {
width: 100%;
color: #fff;
margin-top: 8%;
background-color: #6A6A6A;
text-align: right;
}
.lengle {
margin-top: 8%;
margin-bottom: 8%;
line-height: normal;
display: inline-block;
vertical-align: middle;
}
.shortlang {
/*background-color: #FFEEAE;*/
}
.longlang {
background-color: #59C6FF;
color:#fff;
padding-left: 5px;
padding-right: 5px;
border-radius: 3px;
}
.explorersection{
background-color: rgb(255, 238, 174);
width: 100%;
padding-top: 8%;
padding-bottom: 8%;
}
.noheight{
height: 0;
}
.columnwrap {
max-width: 1100;
margin-left: auto;
margin-right: auto;
}
.column {
padding-left: 8%;
padding-right: 8%;
}
.smalllogo {
height: 50px;
vertical-align: middle;
position: absolute;
left: 3%;
opacity: 0;
}
.stickyheader { .stickyheader {
position: fixed; position: fixed;
width: 100%; width: 100%;
z-index: 3; z-index: 3;
height: 50px;
vertical-align: middle;
text-align: right; text-align: right;
line-height: 50px; line-height: 50px;
background-color: #00DB9D;
} }
.headernav { .headernav {
padding-right: 35px; padding-right: 3%;
vertical-align: middle;
color: #fff; color: #fff;
} }
.run, .run,
.running { .running {
width: 100%; width: 100%;
height: 42px; height: 47px;
text-align: center; text-align: center;
} }
.running { .running {
@ -63,10 +132,9 @@ a {
svg { svg {
height: 100% height: 100%
} }
#marterial { .marterial {
position: absolute; /*position: absolute;*/
width: 100%; width: 100%;
height: 330px;
z-index: -1; z-index: -1;
overflow: hidden; overflow: hidden;
background-color: #00DB9D; background-color: #00DB9D;
@ -91,13 +159,15 @@ svg {
flex-grow: 1; flex-grow: 1;
height: 40px; height: 40px;
line-height: 40px; line-height: 40px;
cursor: pointer;
color: #fff; color: #fff;
background-color: #6A6A6A; background-color: #6A6A6A;
} }
.selected { .selected {
background-color: #00DB9D; background-color: #00DB9D;
font-weight: bold; /*font-weight: bold;*/
} }
.bookend { .bookend {
@ -115,6 +185,7 @@ svg {
text-align: center; text-align: center;
/*display: flex*/ /*display: flex*/
} }
#wow .demofooter { #wow .demofooter {
display: flex; display: flex;
padding: 0px; padding: 0px;
@ -123,26 +194,40 @@ svg {
} }
#logo { #logo {
text-align: center; text-align: center;
padding-top: 70px; margin-top: 8%;
margin-bottom: 8%;
height: 182px; height: 182px;
position: relative;
/*z-index: 4;*/
} }
.to_ocr { .to_ocr {
width: 100%; width: 100%;
} }
#wow {
margin-top: 25px;
}
.demo { .demo {
border-radius: 5px; border-radius: 5px;
width: 500px; width: 500px;
max-width: 100%; max-width: 100%;
text-align: left; text-align: left;
top:-50px;
overflow: hidden; overflow: hidden;
box-shadow: 0px 1px 4px 0px rgba(0, 0, 0, .2); box-shadow: 0px 40px 60px 10px rgba(0, 0, 0, .2);
position: relative; position: relative;
background-color: #f3f3f3; background-color: #f3f3f3;
opacity: 1;
-webkit-transition: .7s ease-out;
-moz-transition: .7s ease-out;
-ms-transition: .7s ease-out;
-o-transition: .7s ease-out;
transition: .7s ease-out;
} }
/*.opaque {
top:-30;
box-shadow: 0px 1px 4px 0px rgba(0, 0, 0, .2);
}*/
.demoheader { .demoheader {
overflow: hidden; overflow: hidden;
border-radius: 5px 5px 0px 0px; border-radius: 5px 5px 0px 0px;
@ -156,10 +241,7 @@ svg {
background-image: url(../img/logowhite.png); background-image: url(../img/logowhite.png);
background-size: cover; background-size: cover;
} }
#splash {
text-align: center;
position: relative;
}
.desc { .desc {
text-align: left; text-align: left;
font-size: 18px; font-size: 18px;
@ -168,7 +250,7 @@ svg {
.vr { .vr {
display: inline-block; display: inline-block;
height: 40px; height: 40px;
border-left: 1px solid #ddd; border-left: 1px solid #5C5C5C;
} }
.getStarted { .getStarted {
display: inline-block; display: inline-block;
@ -182,13 +264,9 @@ svg {
padding-right: 50px; padding-right: 50px;
cursor: pointer; cursor: pointer;
} }
#notconvinced {
max-width: 960; .randombold
margin-left: auto; {
margin-right: auto;
margin-top: 8%;
}
.randombold {
font-size: 18px; font-size: 18px;
/*font-family: Georgia;*/ /*font-family: Georgia;*/
@ -202,11 +280,12 @@ svg {
.npm { .npm {
margin-top: 20px; margin-top: 20px;
padding-left: 15px; padding-left: 15px;
background-color: rgb(255, 238, 174); background-color: #F3F3F3;
border-radius: 5px;
margin-bottom: 0px; margin-bottom: 0px;
padding-top: 10px; padding-top: 10px;
padding-bottom: 10px; padding-bottom: 10px;
border-left: 10px solid #303061; border-left: 6px solid #303061;
color: rgb(48, 48, 97); color: rgb(48, 48, 97);
font-size: 19px; font-size: 19px;
font-family: monospace; font-family: monospace;
@ -220,9 +299,9 @@ svg {
text-align: center; text-align: center;
width: 335px; width: 335px;
border-radius: 5px; border-radius: 5px;
margin-right: 40px; margin-top: 80px;
margin-left: 40px; margin-bottom: 80px;
margin-top: 120px; max-width: 100%;
} }
.woloasdf { .woloasdf {
padding-top: 8%; padding-top: 8%;
@ -241,14 +320,11 @@ svg {
width: 100%; width: 100%;
display: flex; display: flex;
flex-wrap: wrap; flex-wrap: wrap;
justify-content: space-around; justify-content: space-between;
max-width: 1100px; max-width: 1100px;
margin-left: auto; margin-left: auto;
margin-right: auto; margin-right: auto;
} }
#two {
margin-bottom: 8%;
}
.demoheader .CodeMirror { .demoheader .CodeMirror {
padding-bottom: 9px; padding-bottom: 9px;
padding-top: 9px; padding-top: 9px;
@ -260,13 +336,13 @@ hr {
border-top: 1px solid #ddd; border-top: 1px solid #ddd;
margin: 0px; margin: 0px;
} }
#ocroutput { .ocroutput {
position: relative; position: relative;
z-index: 2;
} }
.manyLanguages { .manylangs{
font-size: 7px; display: flex;
padding-top: 10px; flex-wrap: wrap;
opacity: .3;
} }
body { body {
padding: 0px; padding: 0px;
@ -296,31 +372,35 @@ button:hover {
background: rgba(255, 255, 255, 1); background: rgba(255, 255, 255, 1);
border: solid 1px #ddd; border: solid 1px #ddd;
} }
@media (max-width: 914px) { @media (max-width: 1015px) {
button { button {
color: #fff; color: #fff;
background-color: rgba(0, 0, 0, 0) background-color: rgba(0, 0, 0, 0)
} }
.desc { /* .desc {
color: #FFFFFF; color: #FFFFFF;
text-shadow: 0px 0px 3px rgba(58, 58, 58, 1); text-shadow: 0px 0px 3px rgba(58, 58, 58, 1);
} }
.desc a { .desc a {
color: #B8EEFF; color: #FFEEAE;
} }
.npm { */
box-shadow: 0px 0px 20px 4px rgb(180, 146, 150); .getStarted {
font-size: 33px;
} }
#logo { .noheight {
padding-top: 8%;
height: auto; height: auto;
} }
#marterial {
height: 100%;
}
.demo { .demo {
margin-right: 8%; top:0;
margin-left: 8%; margin-bottom: 20px;
box-shadow: 0px 1px 4px 0px rgba(0, 0, 0, .2);
}
#logo {
height: auto;
}
.two {
justify-content: space-around;
} }
#code { #code {
margin-top: 20px; margin-top: 20px;

BIN
img/chi_sim.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 276 KiB

BIN
img/chinese.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 78 KiB

0
img/poem.png → img/eng.png

Before

Width:  |  Height:  |  Size: 1.6 MiB

After

Width:  |  Height:  |  Size: 1.6 MiB

BIN
img/redstars.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.6 MiB

BIN
img/rus.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 183 KiB

BIN
img/tha.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 628 KiB

238
index.html

File diff suppressed because one or more lines are too long

160
index_dev.html

File diff suppressed because one or more lines are too long

400
main.js

@ -1,193 +1,229 @@
function builddemo(id, val){ function builddemo(id, val){
var demo = document.getElementById(id) var demo = document.getElementById(id)
var prog = demo.querySelector('.prog') var prog = demo.querySelector('.prog')
var out = demo.querySelector('.out') var out = demo.querySelector('.out')
var disp = demo.querySelector('.display') var disp = demo.querySelector('.display')
var dctx = disp.getContext('2d') var dctx = disp.getContext('2d')
disp.width = 0 disp.width = 0
disp.height = 0 disp.height = 0
demo.querySelector('.runbutton').onclick = function(){ demo.querySelector('.runbutton').onclick = function(){
setrunning(0) setrunning(0)
run(editor) run(editor)
} }
function show_progress(p){ function show_progress(p){
setrunning(0) setrunning(0)
console.log(p) console.log(p)
if(p.loaded_lang_model) prog.value = p.loaded_lang_model if(p.loaded_lang_model) prog.value = p.loaded_lang_model
if(p.recognized) prog.value = p.recognized if(p.recognized) prog.value = p.recognized
out.innerText = JSON.stringify(p) out.innerText = JSON.stringify(p)
out.innerText = JSON.stringify(p) out.innerText = JSON.stringify(p)
} }
function setrunning(v){ function setrunning(v){
if (v == 1) { if (v == 1) {
demo.querySelector('.running').style.display = 'none' demo.querySelector('.running').style.display = 'none'
demo.querySelector('.notrunning').style.display = 'block' demo.querySelector('.notrunning').style.display = 'block'
// out.style.visibility = 'hidden' // out.style.visibility = 'hidden'
} }
else { else {
demo.querySelector('.running').style.display = 'block' demo.querySelector('.running').style.display = 'block'
demo.querySelector('.notrunning').style.display = 'none' demo.querySelector('.notrunning').style.display = 'none'
} }
} }
function display(result) { function display(result) {
React.render(React.createElement(Node, { node: result, expanded: true, label: "output_of_above_demo"}), document.getElementById("explorer")); React.render(React.createElement(Node, { node: result, expanded: true, label: "output_of_above_demo_plz_click_stuff"}), document.getElementById("explorer"));
setrunning(1) setrunning(1)
out.innerText = "Lightning Speeeeeeed" out.innerText = "Lightning Speeeeeeed"
prog.value = 0 prog.value = 0
console.log(result) console.log(result)
disp.width = demo.querySelector('.to_ocr').naturalWidth disp.width = demo.querySelector('.to_ocr').naturalWidth
disp.height = demo.querySelector('.to_ocr').naturalHeight disp.height = demo.querySelector('.to_ocr').naturalHeight
disp.style.width = demo.querySelector('.to_ocr').offsetWidth disp.style.width = demo.querySelector('.to_ocr').offsetWidth
disp.style.height = demo.querySelector('.to_ocr').offsetHeight disp.style.height = demo.querySelector('.to_ocr').offsetHeight
dctx.shadowColor = "rgba(255,255,255,.1)" dctx.shadowColor = "rgba(255,255,255,.1)"
dctx.shadowOffsetX = 0; dctx.shadowOffsetX = 0;
dctx.shadowOffsetY = 0; dctx.shadowOffsetY = 0;
dctx.shadowBlur = 10; dctx.shadowBlur = 10;
dctx.fillRect(0,0,disp.width, disp.height) dctx.fillRect(0,0,disp.width, disp.height)
var m = result.words.map(function(w){ var m = result.words.map(function(w){
var b = w.bbox var b = w.bbox
dctx.font = '20px Times' dctx.font = '20px Times'
var font = 20*(b.x1-b.x0)/dctx.measureText(w.text).width+"px Times" var font = 20*(b.x1-b.x0)/dctx.measureText(w.text).width+"px Times"
var k = function(){ var k = function(){
dctx.font = font dctx.font = font
dctx.fillText(w.text, b.x0, w.baseline.y0); dctx.fillText(w.text, b.x0, w.baseline.y0);
return font return font
} }
return k return k
}) })
var times = 0 var times = 0
var maxtimes = m.length + 100 var maxtimes = m.length + 100
function draw(i){ function draw(i){
times++ times++
dctx.fillStyle="rgba(30, 29, 49, .8)" // dctx.fillStyle="rgba(30, 29, 49, .8)"
dctx.fillStyle="#00DB9D" dctx.fillStyle="rgba(0, 219, 157, "+Math.min(i/100,1)+")"
// dctx.globalAlpha = .1; // dctx.globalAlpha = .1;
dctx.clearRect(0,0,disp.width, disp.height) dctx.clearRect(0,0,disp.width, disp.height)
dctx.fillRect(0,0,disp.width, disp.height) dctx.fillRect(0,0,disp.width, disp.height)
for (var j = 0; j < Math.min(i,m.length); j++) { for (var j = 0; j < Math.min(i,m.length); j++) {
var asdf = Math.min(Math.max(i - j,0), 100) var asdf = Math.min(Math.max(i - j,0), 100)
dctx.fillStyle = "rgba(255,255,255,"+asdf*.01+")" dctx.fillStyle = "rgba(255,255,255,"+asdf*.01+")"
m[j]() m[j]()
}; };
if(i<maxtimes){ if(i<maxtimes){
setTimeout(function(){ setTimeout(function(){
draw(i+1) draw(i+1)
},10) },10)
} }
else{ else{
console.log('done') console.log('done')
} }
} }
draw(0) draw(0)
// result.words.forEach(function(word, index){ result.words.forEach(function(word, index){
// var wdiv = document.createElement('div') var wdiv = document.createElement('div')
// wdiv.innerText = word.text+' ' wdiv.innerText = word.text+' '
// wdiv.style['font-family'] = "Times" wdiv.style['font-family'] = "Times"
// wdiv.style.position = 'absolute' wdiv.style.position = 'absolute'
// var scale = document.getElementById('to_ocr').offsetHeight / document.getElementById('to_ocr').naturalHeight var to_ocr = document.querySelector('.to_ocr')
// wdiv.style['font-size'] = parseFloat(m[index]().split('px')[0]) * scale var scale = to_ocr.offsetHeight / to_ocr.naturalHeight
// wdiv.style.color = "rgba(0,0,0,0)" wdiv.style['font-size'] = parseFloat(m[index]().split('px')[0]) * scale
// wdiv.style.top = word.bbox.y0 * scale wdiv.style.color = "rgba(0,0,0,0)"
// wdiv.style.left = word.bbox.x0 * scale wdiv.style.top = word.bbox.y0 * scale
// wdiv.style.height = (word.bbox.y1 - word.bbox.y0)*scale wdiv.style.left = word.bbox.x0 * scale
// wdiv.style.width = (word.bbox.x1 - word.bbox.x0)*scale wdiv.style.height = (word.bbox.y1 - word.bbox.y0)*scale
// document.getElementById('ocroutput').appendChild(wdiv) wdiv.style.width = (word.bbox.x1 - word.bbox.x0)*scale
// }) document.querySelector('.ocroutput').appendChild(wdiv)
} })
}
window.addEventListener('resize', function() {
disp.style.width = demo.querySelector('.to_ocr').offsetWidth window.addEventListener('resize', function() {
disp.style.height = demo.querySelector('.to_ocr').offsetHeight disp.style.width = demo.querySelector('.to_ocr').offsetWidth
}) disp.style.height = demo.querySelector('.to_ocr').offsetHeight
})
function run(c){
eval(c.getValue()) function run(c){
} eval(c.getValue())
}
var editor = CodeMirror(demo.querySelector('.editor'),{
// lineNumbers: true, var editor = CodeMirror(demo.querySelector('.editor'),{
viewportMargin: Infinity, // lineNumbers: true,
value: val viewportMargin: Infinity,
}); value: val
});
var sc = demo.querySelector('.demoheader')
var scdiv = document.createElement('div') var sc = demo.querySelector('.demoheader')
sc.appendChild(scdiv) var scdiv = document.createElement('div')
scdiv.className = 'CodeMirror cm-s-default' sc.appendChild(scdiv)
// scdiv.className = 'cm-s-default' scdiv.className = 'CodeMirror cm-s-default'
CodeMirror.runMode('<script src="https://cdn.rawgit.com/naptha/tesseract.js/master/lib/Tesseract.2015.07.25.v0.js"></script>', {name: 'xml', htmlMode: true}, scdiv) // scdiv.className = 'cm-s-default'
CodeMirror.runMode('<script src="https://cdn.rawgit.com/naptha/tesseract.js/master/lib/Tesseract.2015.07.26.js"></script>', {
// var scripttag = CodeMirror(,{ name: 'xml',
// mode: {name: 'xml', htmlMode: true}, htmlMode: true
// readOnly: 'nocursor', }, scdiv)
// value:
// }); // var scripttag = CodeMirror(,{
// mode: {name: 'xml', htmlMode: true},
// readOnly: 'nocursor',
return { // value:
// });
run: function(){ editor.clear = function(){
var img = demo.querySelector('.to_ocr') dctx.clearRect(0,0,disp.width, disp.height)
document.querySelector('.ocroutput').innerHTML = ''
if (img.complete) {
run(editor) }
} else{
img.onload = function(){ editor.img = demo.querySelector('.to_ocr')
run(editor)
} editor.run = function(){
}
if (editor.img.complete) {
} run(editor)
} } else{
editor.img.onload = function(){
run(editor)
}
}
}
return editor
} }
builddemo('wow', setTimeout(function(){
document.getElementById('wow').className += ' opaque'
}, 100)
var wow = builddemo('wow',
"var img = demo.querySelector('img.to_ocr')\n\n\ "var img = demo.querySelector('img.to_ocr')\n\n\
Tesseract\n\ Tesseract\n\
.recognize( img, {progress: show_progress} )\n\ .recognize( img, {\n\
.then( display )") progress: show_progress} )\n\
.run() .then( display ) // scroll down for full output ")
addEventListener('scroll', function(e){ wow.run()
//frum jcurry
var doc = document.documentElement;
var top = (window.pageYOffset || doc.scrollTop) - (doc.clientTop || 0); var tabs = Array.prototype.slice.call(document.querySelectorAll('.langlabel'))
if(top >= 227) { var ltabs = Array.prototype.slice.call(document.querySelectorAll('.ltab'))
document.querySelector('.stickyheader').style['background-color'] = '#00DB9D' var langs = ['eng', 'chi_sim', 'rus', 'tha']
}
else { function setlang(i){
document.querySelector('.stickyheader').style['background-color'] = 'rgba(0,0,0,0)' tabs.forEach(function(t){
} t.className = 'langlabel'
})
tabs[i].className = 'langlabel selected'
console.log(tabs[i])
wow.setValue(
"var img = demo.querySelector('img.to_ocr')\n\n"
+"Tesseract\n"
+" .recognize( img, {\n"
+" progress: show_progress, lang: '"+langs[i]+"'} )\n"
+" .then( display ) // scroll down for full output ")
wow.img.src = 'img/'+langs[i]+'.png'
wow.clear()
}
ltabs.forEach(function(ltab,i){
ltab.onclick = function(){
setlang(i)
}
}) })
tabs.forEach(function(tab,i){
tab.onclick = function(){
setlang(i)
}
})
// document.querySelector('.getStarted')[0].onclick = function(){ // document.querySelector('.getStarted')[0].onclick = function(){
// location.href = '#' // location.href = '#'
// location.href = '#get_started' // location.href = '#get_started'
// } // }
// builddemo('demo2', // builddemo('demo2',

233
main_dev.js

@ -0,0 +1,233 @@
function builddemo(id, val){
var demo = document.getElementById(id)
var prog = demo.querySelector('.prog')
var out = demo.querySelector('.out')
var disp = demo.querySelector('.display')
var dctx = disp.getContext('2d')
disp.width = 0
disp.height = 0
demo.querySelector('.runbutton').onclick = function(){
setrunning(0)
run(editor)
}
function show_progress(p){
setrunning(0)
console.log(p)
if(p.loaded_lang_model) prog.value = p.loaded_lang_model
if(p.recognized) prog.value = p.recognized
out.innerText = JSON.stringify(p)
out.innerText = JSON.stringify(p)
}
function setrunning(v){
if (v == 1) {
demo.querySelector('.running').style.display = 'none'
demo.querySelector('.notrunning').style.display = 'block'
// out.style.visibility = 'hidden'
}
else {
demo.querySelector('.running').style.display = 'block'
demo.querySelector('.notrunning').style.display = 'none'
}
}
function display(result) {
React.render(React.createElement(Node, { node: result, expanded: true, label: "output_of_above_demo_plz_click_stuff"}), document.getElementById("explorer"));
setrunning(1)
out.innerText = "Lightning Speeeeeeed"
prog.value = 0
console.log(result)
disp.width = demo.querySelector('.to_ocr').naturalWidth
disp.height = demo.querySelector('.to_ocr').naturalHeight
disp.style.width = demo.querySelector('.to_ocr').offsetWidth
disp.style.height = demo.querySelector('.to_ocr').offsetHeight
dctx.shadowColor = "rgba(255,255,255,.1)"
dctx.shadowOffsetX = 0;
dctx.shadowOffsetY = 0;
dctx.shadowBlur = 10;
dctx.fillRect(0,0,disp.width, disp.height)
var m = result.words.map(function(w){
var b = w.bbox
dctx.font = '20px Times'
var font = 20*(b.x1-b.x0)/dctx.measureText(w.text).width+"px Times"
var k = function(){
dctx.font = font
dctx.fillText(w.text, b.x0, w.baseline.y0);
return font
}
return k
})
var times = 0
var maxtimes = m.length + 100
function draw(i){
times++
// dctx.fillStyle="rgba(30, 29, 49, .8)"
dctx.fillStyle="rgba(0, 219, 157, "+Math.min(i/100,1)+")"
// dctx.globalAlpha = .1;
dctx.clearRect(0,0,disp.width, disp.height)
dctx.fillRect(0,0,disp.width, disp.height)
for (var j = 0; j < Math.min(i,m.length); j++) {
var asdf = Math.min(Math.max(i - j,0), 100)
dctx.fillStyle = "rgba(255,255,255,"+asdf*.01+")"
m[j]()
};
if(i<maxtimes){
setTimeout(function(){
draw(i+1)
},10)
}
else{
console.log('done')
}
}
draw(0)
result.words.forEach(function(word, index){
var wdiv = document.createElement('div')
wdiv.innerText = word.text+' '
wdiv.style['font-family'] = "Times"
wdiv.style.position = 'absolute'
var to_ocr = document.querySelector('.to_ocr')
var scale = to_ocr.offsetHeight / to_ocr.naturalHeight
wdiv.style['font-size'] = parseFloat(m[index]().split('px')[0]) * scale
wdiv.style.color = "rgba(0,0,0,0)"
wdiv.style.top = word.bbox.y0 * scale
wdiv.style.left = word.bbox.x0 * scale
wdiv.style.height = (word.bbox.y1 - word.bbox.y0)*scale
wdiv.style.width = (word.bbox.x1 - word.bbox.x0)*scale
document.querySelector('.ocroutput').appendChild(wdiv)
})
}
window.addEventListener('resize', function() {
disp.style.width = demo.querySelector('.to_ocr').offsetWidth
disp.style.height = demo.querySelector('.to_ocr').offsetHeight
})
function run(c){
eval(c.getValue())
}
var editor = CodeMirror(demo.querySelector('.editor'),{
// lineNumbers: true,
viewportMargin: Infinity,
value: val
});
var sc = demo.querySelector('.demoheader')
var scdiv = document.createElement('div')
sc.appendChild(scdiv)
scdiv.className = 'CodeMirror cm-s-default'
// scdiv.className = 'cm-s-default'
CodeMirror.runMode('<script src="http://localhost:1234/master/lib/Tesseract_dev.js"></script>', {
name: 'xml',
htmlMode: true
}, scdiv)
// var scripttag = CodeMirror(,{
// mode: {name: 'xml', htmlMode: true},
// readOnly: 'nocursor',
// value:
// });
editor.clear = function(){
dctx.clearRect(0,0,disp.width, disp.height)
document.querySelector('.ocroutput').innerHTML = ''
}
editor.img = demo.querySelector('.to_ocr')
editor.run = function(){
if (editor.img.complete) {
run(editor)
} else{
editor.img.onload = function(){
run(editor)
}
}
}
return editor
}
setTimeout(function(){
document.getElementById('wow').className += ' opaque'
}, 100)
var wow = builddemo('wow',
"var img = demo.querySelector('img.to_ocr')\n\n\
Tesseract\n\
.recognize( img, {\n\
progress: show_progress} )\n\
.then( display ) // scroll down for full output ")
wow.run()
var tabs = Array.prototype.slice.call(document.querySelectorAll('.langlabel'))
var ltabs = Array.prototype.slice.call(document.querySelectorAll('.ltab'))
var langs = ['eng', 'chi_sim', 'rus', 'tha']
function setlang(i){
tabs.forEach(function(t){
t.className = 'langlabel'
})
tabs[i].className = 'langlabel selected'
console.log(tabs[i])
wow.setValue(
"var img = demo.querySelector('img.to_ocr')\n\n"
+"Tesseract\n"
+" .recognize( img, {\n"
+" progress: show_progress, lang: '"+langs[i]+"'} )\n"
+" .then( display ) // scroll down for full output ")
wow.img.src = 'img/'+langs[i]+'.png'
wow.clear()
}
ltabs.forEach(function(ltab,i){
ltab.onclick = function(){
setlang(i)
}
})
tabs.forEach(function(tab,i){
tab.onclick = function(){
setlang(i)
}
})
// document.querySelector('.getStarted')[0].onclick = function(){
// location.href = '#'
// location.href = '#get_started'
// }
// builddemo('demo2',
// "var img = demo.querySelector('img.to_ocr')\n\n\
// Tesseract\n\
// .recognize( img, {progress: show_progress, lang:'chi_sim'} )\n\
// .then( display )")

0
explorer_src/explorer.js → src/explorer.js

236
src/index.html

File diff suppressed because one or more lines are too long

400
src/main.js

@ -1,193 +1,229 @@
function builddemo(id, val){ function builddemo(id, val){
var demo = document.getElementById(id) var demo = document.getElementById(id)
var prog = demo.querySelector('.prog') var prog = demo.querySelector('.prog')
var out = demo.querySelector('.out') var out = demo.querySelector('.out')
var disp = demo.querySelector('.display') var disp = demo.querySelector('.display')
var dctx = disp.getContext('2d') var dctx = disp.getContext('2d')
disp.width = 0 disp.width = 0
disp.height = 0 disp.height = 0
demo.querySelector('.runbutton').onclick = function(){ demo.querySelector('.runbutton').onclick = function(){
setrunning(0) setrunning(0)
run(editor) run(editor)
} }
function show_progress(p){ function show_progress(p){
setrunning(0) setrunning(0)
console.log(p) console.log(p)
if(p.loaded_lang_model) prog.value = p.loaded_lang_model if(p.loaded_lang_model) prog.value = p.loaded_lang_model
if(p.recognized) prog.value = p.recognized if(p.recognized) prog.value = p.recognized
out.innerText = JSON.stringify(p) out.innerText = JSON.stringify(p)
out.innerText = JSON.stringify(p) out.innerText = JSON.stringify(p)
} }
function setrunning(v){ function setrunning(v){
if (v == 1) { if (v == 1) {
demo.querySelector('.running').style.display = 'none' demo.querySelector('.running').style.display = 'none'
demo.querySelector('.notrunning').style.display = 'block' demo.querySelector('.notrunning').style.display = 'block'
// out.style.visibility = 'hidden' // out.style.visibility = 'hidden'
} }
else { else {
demo.querySelector('.running').style.display = 'block' demo.querySelector('.running').style.display = 'block'
demo.querySelector('.notrunning').style.display = 'none' demo.querySelector('.notrunning').style.display = 'none'
} }
} }
function display(result) { function display(result) {
React.render(React.createElement(Node, { node: result, expanded: true, label: "output_of_above_demo"}), document.getElementById("explorer")); React.render(React.createElement(Node, { node: result, expanded: true, label: "output_of_above_demo_plz_click_stuff"}), document.getElementById("explorer"));
setrunning(1) setrunning(1)
out.innerText = "Lightning Speeeeeeed" out.innerText = "Lightning Speeeeeeed"
prog.value = 0 prog.value = 0
console.log(result) console.log(result)
disp.width = demo.querySelector('.to_ocr').naturalWidth disp.width = demo.querySelector('.to_ocr').naturalWidth
disp.height = demo.querySelector('.to_ocr').naturalHeight disp.height = demo.querySelector('.to_ocr').naturalHeight
disp.style.width = demo.querySelector('.to_ocr').offsetWidth disp.style.width = demo.querySelector('.to_ocr').offsetWidth
disp.style.height = demo.querySelector('.to_ocr').offsetHeight disp.style.height = demo.querySelector('.to_ocr').offsetHeight
dctx.shadowColor = "rgba(255,255,255,.1)" dctx.shadowColor = "rgba(255,255,255,.1)"
dctx.shadowOffsetX = 0; dctx.shadowOffsetX = 0;
dctx.shadowOffsetY = 0; dctx.shadowOffsetY = 0;
dctx.shadowBlur = 10; dctx.shadowBlur = 10;
dctx.fillRect(0,0,disp.width, disp.height) dctx.fillRect(0,0,disp.width, disp.height)
var m = result.words.map(function(w){ var m = result.words.map(function(w){
var b = w.bbox var b = w.bbox
dctx.font = '20px Times' dctx.font = '20px Times'
var font = 20*(b.x1-b.x0)/dctx.measureText(w.text).width+"px Times" var font = 20*(b.x1-b.x0)/dctx.measureText(w.text).width+"px Times"
var k = function(){ var k = function(){
dctx.font = font dctx.font = font
dctx.fillText(w.text, b.x0, w.baseline.y0); dctx.fillText(w.text, b.x0, w.baseline.y0);
return font return font
} }
return k return k
}) })
var times = 0 var times = 0
var maxtimes = m.length + 100 var maxtimes = m.length + 100
function draw(i){ function draw(i){
times++ times++
dctx.fillStyle="rgba(30, 29, 49, .8)" // dctx.fillStyle="rgba(30, 29, 49, .8)"
dctx.fillStyle="#00DB9D" dctx.fillStyle="rgba(0, 219, 157, "+Math.min(i/100,1)+")"
// dctx.globalAlpha = .1; // dctx.globalAlpha = .1;
dctx.clearRect(0,0,disp.width, disp.height) dctx.clearRect(0,0,disp.width, disp.height)
dctx.fillRect(0,0,disp.width, disp.height) dctx.fillRect(0,0,disp.width, disp.height)
for (var j = 0; j < Math.min(i,m.length); j++) { for (var j = 0; j < Math.min(i,m.length); j++) {
var asdf = Math.min(Math.max(i - j,0), 100) var asdf = Math.min(Math.max(i - j,0), 100)
dctx.fillStyle = "rgba(255,255,255,"+asdf*.01+")" dctx.fillStyle = "rgba(255,255,255,"+asdf*.01+")"
m[j]() m[j]()
}; };
if(i<maxtimes){ if(i<maxtimes){
setTimeout(function(){ setTimeout(function(){
draw(i+1) draw(i+1)
},10) },10)
} }
else{ else{
console.log('done') console.log('done')
} }
} }
draw(0) draw(0)
// result.words.forEach(function(word, index){ result.words.forEach(function(word, index){
// var wdiv = document.createElement('div') var wdiv = document.createElement('div')
// wdiv.innerText = word.text+' ' wdiv.innerText = word.text+' '
// wdiv.style['font-family'] = "Times" wdiv.style['font-family'] = "Times"
// wdiv.style.position = 'absolute' wdiv.style.position = 'absolute'
// var scale = document.getElementById('to_ocr').offsetHeight / document.getElementById('to_ocr').naturalHeight var to_ocr = document.querySelector('.to_ocr')
// wdiv.style['font-size'] = parseFloat(m[index]().split('px')[0]) * scale var scale = to_ocr.offsetHeight / to_ocr.naturalHeight
// wdiv.style.color = "rgba(0,0,0,0)" wdiv.style['font-size'] = parseFloat(m[index]().split('px')[0]) * scale
// wdiv.style.top = word.bbox.y0 * scale wdiv.style.color = "rgba(0,0,0,0)"
// wdiv.style.left = word.bbox.x0 * scale wdiv.style.top = word.bbox.y0 * scale
// wdiv.style.height = (word.bbox.y1 - word.bbox.y0)*scale wdiv.style.left = word.bbox.x0 * scale
// wdiv.style.width = (word.bbox.x1 - word.bbox.x0)*scale wdiv.style.height = (word.bbox.y1 - word.bbox.y0)*scale
// document.getElementById('ocroutput').appendChild(wdiv) wdiv.style.width = (word.bbox.x1 - word.bbox.x0)*scale
// }) document.querySelector('.ocroutput').appendChild(wdiv)
} })
}
window.addEventListener('resize', function() {
disp.style.width = demo.querySelector('.to_ocr').offsetWidth window.addEventListener('resize', function() {
disp.style.height = demo.querySelector('.to_ocr').offsetHeight disp.style.width = demo.querySelector('.to_ocr').offsetWidth
}) disp.style.height = demo.querySelector('.to_ocr').offsetHeight
})
function run(c){
eval(c.getValue()) function run(c){
} eval(c.getValue())
}
var editor = CodeMirror(demo.querySelector('.editor'),{
// lineNumbers: true, var editor = CodeMirror(demo.querySelector('.editor'),{
viewportMargin: Infinity, // lineNumbers: true,
value: val viewportMargin: Infinity,
}); value: val
});
var sc = demo.querySelector('.demoheader')
var scdiv = document.createElement('div') var sc = demo.querySelector('.demoheader')
sc.appendChild(scdiv) var scdiv = document.createElement('div')
scdiv.className = 'CodeMirror cm-s-default' sc.appendChild(scdiv)
// scdiv.className = 'cm-s-default' scdiv.className = 'CodeMirror cm-s-default'
CodeMirror.runMode('<script src="__tesseractjs__"></script>', {name: 'xml', htmlMode: true}, scdiv) // scdiv.className = 'cm-s-default'
CodeMirror.runMode('<script src="__tesseractjs__"></script>', {
// var scripttag = CodeMirror(,{ name: 'xml',
// mode: {name: 'xml', htmlMode: true}, htmlMode: true
// readOnly: 'nocursor', }, scdiv)
// value:
// }); // var scripttag = CodeMirror(,{
// mode: {name: 'xml', htmlMode: true},
// readOnly: 'nocursor',
return { // value:
// });
run: function(){ editor.clear = function(){
var img = demo.querySelector('.to_ocr') dctx.clearRect(0,0,disp.width, disp.height)
document.querySelector('.ocroutput').innerHTML = ''
if (img.complete) {
run(editor) }
} else{
img.onload = function(){ editor.img = demo.querySelector('.to_ocr')
run(editor)
} editor.run = function(){
}
if (editor.img.complete) {
} run(editor)
} } else{
editor.img.onload = function(){
run(editor)
}
}
}
return editor
} }
builddemo('wow', setTimeout(function(){
document.getElementById('wow').className += ' opaque'
}, 100)
var wow = builddemo('wow',
"var img = demo.querySelector('img.to_ocr')\n\n\ "var img = demo.querySelector('img.to_ocr')\n\n\
Tesseract\n\ Tesseract\n\
.recognize( img, {progress: show_progress} )\n\ .recognize( img, {\n\
.then( display )") progress: show_progress} )\n\
.run() .then( display ) // scroll down for full output ")
addEventListener('scroll', function(e){ wow.run()
//frum jcurry
var doc = document.documentElement;
var top = (window.pageYOffset || doc.scrollTop) - (doc.clientTop || 0); var tabs = Array.prototype.slice.call(document.querySelectorAll('.langlabel'))
if(top >= 227) { var ltabs = Array.prototype.slice.call(document.querySelectorAll('.ltab'))
document.querySelector('.stickyheader').style['background-color'] = '#00DB9D' var langs = ['eng', 'chi_sim', 'rus', 'tha']
}
else { function setlang(i){
document.querySelector('.stickyheader').style['background-color'] = 'rgba(0,0,0,0)' tabs.forEach(function(t){
} t.className = 'langlabel'
})
tabs[i].className = 'langlabel selected'
console.log(tabs[i])
wow.setValue(
"var img = demo.querySelector('img.to_ocr')\n\n"
+"Tesseract\n"
+" .recognize( img, {\n"
+" progress: show_progress, lang: '"+langs[i]+"'} )\n"
+" .then( display ) // scroll down for full output ")
wow.img.src = 'img/'+langs[i]+'.png'
wow.clear()
}
ltabs.forEach(function(ltab,i){
ltab.onclick = function(){
setlang(i)
}
}) })
tabs.forEach(function(tab,i){
tab.onclick = function(){
setlang(i)
}
})
// document.querySelector('.getStarted')[0].onclick = function(){ // document.querySelector('.getStarted')[0].onclick = function(){
// location.href = '#' // location.href = '#'
// location.href = '#get_started' // location.href = '#get_started'
// } // }
// builddemo('demo2', // builddemo('demo2',

Loading…
Cancel
Save