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 @@ @@ -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){
var l = Math.cos(a)*p[c1]+Math.sin(a)*p[c2]
var k = -Math.sin(a)*p[c1]+Math.cos(a)*p[c2]
@ -91,6 +59,40 @@ function project(point, size){ @@ -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 () {
fixdim()
@ -99,16 +101,39 @@ function init () { @@ -99,16 +101,39 @@ function init () {
}
function fixdim() {
if(dimensions.update()){
var displaywidth = Math.sqrt(dimensions.width)*18//dimensions.width > 900 ? 900 : 450
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
}
dimensions.update()
var displaywidth = Math.sqrt(dimensions.width)*18//dimensions.width > 900 ? 900 : 450
var doc = document.documentElement;
var top = (window.pageYOffset || doc.scrollTop) - (doc.clientTop || 0);
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){
var edges = tesseractedges()
for (var i = 0; i < tesseract.length; i++) {

2
codemirror/codemirror.css

@ -115,7 +115,7 @@ div.CodeMirror-overwrite div.CodeMirror-cursor {} @@ -115,7 +115,7 @@ div.CodeMirror-overwrite div.CodeMirror-cursor {}
.cm-s-default .cm-operator {}
.cm-s-default .cm-variable-2 {color: #05a;}
.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-2 {color: #f50;}
.cm-s-default .cm-meta {color: #555;}

93
css/color.css

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

184
css/wau.css

@ -3,24 +3,93 @@ @@ -3,24 +3,93 @@
width: 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 {
position: fixed;
width: 100%;
z-index: 3;
height: 50px;
vertical-align: middle;
text-align: right;
line-height: 50px;
background-color: #00DB9D;
}
.headernav {
padding-right: 35px;
vertical-align: middle;
padding-right: 3%;
color: #fff;
}
.run,
.running {
width: 100%;
height: 42px;
height: 47px;
text-align: center;
}
.running {
@ -63,10 +132,9 @@ a { @@ -63,10 +132,9 @@ a {
svg {
height: 100%
}
#marterial {
position: absolute;
.marterial {
/*position: absolute;*/
width: 100%;
height: 330px;
z-index: -1;
overflow: hidden;
background-color: #00DB9D;
@ -91,13 +159,15 @@ svg { @@ -91,13 +159,15 @@ svg {
flex-grow: 1;
height: 40px;
line-height: 40px;
cursor: pointer;
color: #fff;
background-color: #6A6A6A;
}
.selected {
background-color: #00DB9D;
font-weight: bold;
/*font-weight: bold;*/
}
.bookend {
@ -115,6 +185,7 @@ svg { @@ -115,6 +185,7 @@ svg {
text-align: center;
/*display: flex*/
}
#wow .demofooter {
display: flex;
padding: 0px;
@ -123,26 +194,40 @@ svg { @@ -123,26 +194,40 @@ svg {
}
#logo {
text-align: center;
padding-top: 70px;
margin-top: 8%;
margin-bottom: 8%;
height: 182px;
position: relative;
/*z-index: 4;*/
}
.to_ocr {
width: 100%;
}
#wow {
margin-top: 25px;
}
.demo {
border-radius: 5px;
width: 500px;
max-width: 100%;
text-align: left;
top:-50px;
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;
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 {
overflow: hidden;
border-radius: 5px 5px 0px 0px;
@ -156,10 +241,7 @@ svg { @@ -156,10 +241,7 @@ svg {
background-image: url(../img/logowhite.png);
background-size: cover;
}
#splash {
text-align: center;
position: relative;
}
.desc {
text-align: left;
font-size: 18px;
@ -168,7 +250,7 @@ svg { @@ -168,7 +250,7 @@ svg {
.vr {
display: inline-block;
height: 40px;
border-left: 1px solid #ddd;
border-left: 1px solid #5C5C5C;
}
.getStarted {
display: inline-block;
@ -182,13 +264,9 @@ svg { @@ -182,13 +264,9 @@ svg {
padding-right: 50px;
cursor: pointer;
}
#notconvinced {
max-width: 960;
margin-left: auto;
margin-right: auto;
margin-top: 8%;
}
.randombold {
.randombold
{
font-size: 18px;
/*font-family: Georgia;*/
@ -202,11 +280,12 @@ svg { @@ -202,11 +280,12 @@ svg {
.npm {
margin-top: 20px;
padding-left: 15px;
background-color: rgb(255, 238, 174);
background-color: #F3F3F3;
border-radius: 5px;
margin-bottom: 0px;
padding-top: 10px;
padding-bottom: 10px;
border-left: 10px solid #303061;
border-left: 6px solid #303061;
color: rgb(48, 48, 97);
font-size: 19px;
font-family: monospace;
@ -220,9 +299,9 @@ svg { @@ -220,9 +299,9 @@ svg {
text-align: center;
width: 335px;
border-radius: 5px;
margin-right: 40px;
margin-left: 40px;
margin-top: 120px;
margin-top: 80px;
margin-bottom: 80px;
max-width: 100%;
}
.woloasdf {
padding-top: 8%;
@ -241,14 +320,11 @@ svg { @@ -241,14 +320,11 @@ svg {
width: 100%;
display: flex;
flex-wrap: wrap;
justify-content: space-around;
justify-content: space-between;
max-width: 1100px;
margin-left: auto;
margin-right: auto;
}
#two {
margin-bottom: 8%;
}
.demoheader .CodeMirror {
padding-bottom: 9px;
padding-top: 9px;
@ -260,13 +336,13 @@ hr { @@ -260,13 +336,13 @@ hr {
border-top: 1px solid #ddd;
margin: 0px;
}
#ocroutput {
.ocroutput {
position: relative;
z-index: 2;
}
.manyLanguages {
font-size: 7px;
padding-top: 10px;
opacity: .3;
.manylangs{
display: flex;
flex-wrap: wrap;
}
body {
padding: 0px;
@ -296,31 +372,35 @@ button:hover { @@ -296,31 +372,35 @@ button:hover {
background: rgba(255, 255, 255, 1);
border: solid 1px #ddd;
}
@media (max-width: 914px) {
@media (max-width: 1015px) {
button {
color: #fff;
background-color: rgba(0, 0, 0, 0)
}
.desc {
/* .desc {
color: #FFFFFF;
text-shadow: 0px 0px 3px rgba(58, 58, 58, 1);
}
.desc a {
color: #B8EEFF;
color: #FFEEAE;
}
.npm {
box-shadow: 0px 0px 20px 4px rgb(180, 146, 150);
*/
.getStarted {
font-size: 33px;
}
#logo {
padding-top: 8%;
.noheight {
height: auto;
}
#marterial {
height: 100%;
}
.demo {
margin-right: 8%;
margin-left: 8%;
top:0;
margin-bottom: 20px;
box-shadow: 0px 1px 4px 0px rgba(0, 0, 0, .2);
}
#logo {
height: auto;
}
.two {
justify-content: space-around;
}
#code {
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 @@ @@ -1,193 +1,229 @@
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"}), 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="#00DB9D"
// 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 scale = document.getElementById('to_ocr').offsetHeight / document.getElementById('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.getElementById('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="https://cdn.rawgit.com/naptha/tesseract.js/master/lib/Tesseract.2015.07.25.v0.js"></script>', {name: 'xml', htmlMode: true}, scdiv)
// var scripttag = CodeMirror(,{
// mode: {name: 'xml', htmlMode: true},
// readOnly: 'nocursor',
// value:
// });
return {
run: function(){
var img = demo.querySelector('.to_ocr')
if (img.complete) {
run(editor)
} else{
img.onload = function(){
run(editor)
}
}
}
}
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="https://cdn.rawgit.com/naptha/tesseract.js/master/lib/Tesseract.2015.07.26.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
}
builddemo('wow',
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, {progress: show_progress} )\n\
.then( display )")
.run()
addEventListener('scroll', function(e){
//frum jcurry
var doc = document.documentElement;
var top = (window.pageYOffset || doc.scrollTop) - (doc.clientTop || 0);
if(top >= 227) {
document.querySelector('.stickyheader').style['background-color'] = '#00DB9D'
}
else {
document.querySelector('.stickyheader').style['background-color'] = 'rgba(0,0,0,0)'
}
.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'
// location.href = '#'
// location.href = '#get_started'
// }
// builddemo('demo2',

233
main_dev.js

@ -0,0 +1,233 @@ @@ -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 @@ @@ -1,193 +1,229 @@
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"}), 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="#00DB9D"
// 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 scale = document.getElementById('to_ocr').offsetHeight / document.getElementById('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.getElementById('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="__tesseractjs__"></script>', {name: 'xml', htmlMode: true}, scdiv)
// var scripttag = CodeMirror(,{
// mode: {name: 'xml', htmlMode: true},
// readOnly: 'nocursor',
// value:
// });
return {
run: function(){
var img = demo.querySelector('.to_ocr')
if (img.complete) {
run(editor)
} else{
img.onload = function(){
run(editor)
}
}
}
}
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="__tesseractjs__"></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
}
builddemo('wow',
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, {progress: show_progress} )\n\
.then( display )")
.run()
addEventListener('scroll', function(e){
//frum jcurry
var doc = document.documentElement;
var top = (window.pageYOffset || doc.scrollTop) - (doc.clientTop || 0);
if(top >= 227) {
document.querySelector('.stickyheader').style['background-color'] = '#00DB9D'
}
else {
document.querySelector('.stickyheader').style['background-color'] = 'rgba(0,0,0,0)'
}
.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'
// location.href = '#'
// location.href = '#get_started'
// }
// builddemo('demo2',

Loading…
Cancel
Save