From 39c938c372beddf74063ef1c3c7bb4d21079bcc9 Mon Sep 17 00:00:00 2001
From: Koichi Yasuoka <yasuoka@kanji.zinbun.kyoto-u.ac.jp>
Date: Sun, 11 Jul 2021 15:10:11 +0900
Subject: [PATCH] initial release

---
 conllusvg/Sutra.html | 282 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 282 insertions(+)
 create mode 100644 conllusvg/Sutra.html

diff --git a/conllusvg/Sutra.html b/conllusvg/Sutra.html
new file mode 100644
index 00000000000..9e038e0efac
--- /dev/null
+++ b/conllusvg/Sutra.html
@@ -0,0 +1,282 @@
+<!DOCTYPE html><head><meta charset="UTF-8" />
+<meta http-equiv="X-UA-Compatible" content="IE=edge" />
+<title>Universal Dependencies on 貍「隴ッ菴帛�</title>
+<script src="conllusvgview.js"></script>
+<script src="conllusvgload.js"></script>
+<script>
+var Sutra=new Object();
+Sutra.url="/gitlab/api/v4/projects/Kanbun%2Fud-kanbun/repository/";
+Sutra.init=function(){
+  var t=document.getElementById("top").cloneNode(true);
+  t.style.position="static";
+  t.style.visibility="hidden";
+  document.body.appendChild(t);
+  Sutra.svg=new Array();
+  Sutra.pre=new Array();
+  Sutra.timer=setTimeout("clearTimeout(Sutra.timer);Sutra.checkview()",200);
+  Sutra.volchange();
+}
+Sutra.checkview=function(){
+  var t,r,b,i,x;
+  Sutra.timer=setTimeout("clearTimeout(Sutra.timer);Sutra.checkview()",200);
+  if(Sutra.curr==null)
+    return;
+  if(Sutra.svg[Sutra.curr]==null||Sutra.pre[Sutra.curr]==null){
+    Sutra.buildup(Sutra.curr);
+    Sutra.lastTop=null;
+    return;
+  }
+  if(Sutra.svg[Sutra.curr].style.position=="absolute"){
+    Sutra.svg[Sutra.curr].style.position="static";
+    Sutra.svg[Sutra.curr].style.visibility="visible";
+  }
+  conllusvg.rewrite("pre"+Sutra.curr);
+  r=Sutra.svg[Sutra.curr].getBoundingClientRect();
+  t=r.top;
+  b=r.bottom;
+  r=document.getElementById("top").getBoundingClientRect().bottom;
+  x=Sutra.curr;
+  if(t-r>20){
+    while(t-r>0){
+      i=Sutra.svg[Sutra.curr-1];
+      if(i==null)
+	break;
+      if(i.style.position=="absolute")
+	break;
+      Sutra.curr--;
+      if(Sutra.curr==0)
+	break;
+      t=i.getBoundingClientRect().top;
+    }
+  }
+  else if(b<r){
+    while(b<r){
+      i=Sutra.svg[Sutra.curr+1];
+      if(i==null)
+	break;
+      if(i.style.position=="absolute")
+        break;
+      Sutra.curr++;
+      if(Sutra.curr==Sutra.currmax)
+	break;
+      b=i.getBoundingClientRect().bottom;
+    }
+  }
+  if(Sutra.curr!=x){
+    if(Sutra.retrytimes>0){
+      Sutra.retrytimes--;
+      Sutra.curr=parseInt(document.getElementById("count").value,10);
+      t=Sutra.svg[Sutra.curr].getBoundingClientRect().top;
+      if(Math.abs(t-r)>5){
+        if(document.scrollingElement==null)
+          document.documentElement.scrollTop+=t-r;
+        else
+          document.scrollingElement.scrollTop+=t-r;
+      }
+    }
+    else
+      document.getElementById("count").value=Sutra.curr;
+  }
+  else if(Sutra.retrytimes>0)
+    Sutra.retrytimes--;
+  Sutra.lastTop=Sutra.svg[Sutra.curr].getBoundingClientRect().top;
+  for(i=Sutra.curr+1;i<=Sutra.currmax;i++){
+    if(Sutra.svg[i]==null||Sutra.pre[i]==null){
+      Sutra.buildup(i);
+      break;
+    }
+    if(Sutra.svg[i].style.position=="absolute"){
+      Sutra.svg[i].style.position="static";
+      Sutra.svg[i].style.visibility="visible";
+    }
+    conllusvg.rewrite("pre"+i);
+    r=Sutra.svg[i].getBoundingClientRect();
+    if(r.top-window.innerHeight-1000>0)
+      break;
+  }
+  for(i=Sutra.curr-1;i>=0;i--){
+    if(Sutra.svg[i]==null||Sutra.pre[i]==null){
+      Sutra.buildup(i);
+      break;
+    }
+    if(Sutra.svg[i].style.position=="absolute"){
+      if(Sutra.pre[i].textContent>""){
+	Sutra.svg[i].style.position="static";
+	Sutra.svg[i].style.visibility="visible";
+      }
+      else
+	break;
+    }
+    conllusvg.rewrite("pre"+i);
+    r=Sutra.svg[Sutra.curr].getBoundingClientRect().top;
+    if(Math.abs(r-Sutra.lastTop)>5){
+      if(document.scrollingElement==null)
+        document.documentElement.scrollTop+=r-Sutra.lastTop;
+      else
+        document.scrollingElement.scrollTop+=r-Sutra.lastTop;
+      Sutra.lastTop=r;
+    }
+    r=Sutra.svg[i].getBoundingClientRect();
+    if(parseInt(r.bottom,10)<-300)
+      break;
+  }
+}
+Sutra.buildup=function(x){
+  var t,i;
+  if(Sutra.svg[x]==null){
+    t=document.createElementNS("http://www.w3.org/2000/svg","svg");
+    for(i=parseInt(x,10)+1;i<=Sutra.currmax;i++){
+      if(Sutra.svg[i]!=null)
+	break;
+    }
+    t.style.position="absolute";
+    t.style.visibility="hidden";
+    if(i>Sutra.currmax)
+      document.body.appendChild(t);
+    else
+      document.body.insertBefore(t,Sutra.svg[i]);
+    Sutra.svg[x]=t;
+    t.addEventListener("mousedown",Sutra.onmousedown);
+    t.addEventListener("touchstart",Sutra.onmousedown);
+  }
+  if(Sutra.pre[x]==null){
+    t=document.createElement("pre");
+    t.style.display="none";
+    t.setAttribute("id","pre"+x);
+    document.body.appendChild(t);
+    Sutra.pre[x]=t;
+    if(conllusvg.main["pre"+x]==null)
+      conllusvg.view(Sutra.svg[x],"pre"+x);
+    i=Sutra.volpath+"/"+("000"+x).slice(-3)+".txt";
+    conllusvg.loadRemote("pre"+x,Sutra.url+"files/"+encodeURIComponent(i)+"/raw?ref=master");
+  }
+}
+Sutra.volchange=function(){
+  var s,x;
+  Sutra.clearSVG();
+  for(s in Sutra.pre){
+    if(Sutra.pre[s]!=null){
+      document.body.removeChild(Sutra.pre[s]);
+    }
+    Sutra.pre[s]=null;
+  }
+  s=document.getElementById("vol");
+  Sutra.volpath=s.options[s.selectedIndex].value;
+  if(Sutra.tail==null)
+    Sutra.tail=new Array();
+  if(Sutra.tail[Sutra.volpath]==null)
+    Sutra.gettree();
+  else
+    Sutra.writeSVG();
+}
+Sutra.gettree=function(){
+  var p;
+  if(Sutra.request==null){
+    Sutra.request=new XMLHttpRequest();
+    Sutra.request.onload=Sutra.ongettree;
+  }
+  if(Sutra.tail[Sutra.volpath]==null)
+    p=1;
+  else
+    p=Math.floor(parseInt(Sutra.tail[Sutra.volpath],10)/100)+2;
+  Sutra.request.open("GET",Sutra.url+"tree?per_page=100&path="+Sutra.volpath+"&page="+p);
+  Sutra.request.send();
+}
+Sutra.ongettree=function(e){
+  var i,s;
+  if(Sutra.request.status==200){
+    s=Sutra.request.responseText;
+    i=s.lastIndexOf('.txt"');
+    if(i<0)
+      Sutra.writeSVG();
+    else{
+      Sutra.tail[Sutra.volpath]=s.substring(i-3,i);
+      Sutra.gettree();
+    }
+  }
+}
+Sutra.goto=function(){
+  Sutra.retrytimes=3;
+  Sutra.writeSVG();
+}
+Sutra.writeSVG=function(){
+  var c=document.getElementById("count");
+  Sutra.clearSVG();
+  Sutra.currmax=parseInt(Sutra.tail[Sutra.volpath],10);
+  Sutra.curr=parseInt(c.value,10);
+  if(Sutra.curr<0)
+    Sutra.curr=0;
+  if(Sutra.curr>Sutra.currmax)
+    Sutra.curr=Sutra.currmax;
+  c.value=Sutra.curr;
+  Sutra.lastTop=null;
+}
+Sutra.clearSVG=function(){
+  var x;
+  Sutra.curr=Sutra.lastTop=null;
+  if(Sutra.svg!=null){
+    for(x in Sutra.svg){
+      if(Sutra.svg[x]!=null){
+	Sutra.svg[x].style.position="absolute";
+	Sutra.svg[x].style.visibility="hidden";
+      }
+    }
+  }
+  if(document.scrollingElement==null)
+    document.documentElement.scrollTop=0;
+  else
+    document.scrollingElement.scrollTop=0;
+}
+Sutra.onmousedown=function(e){
+  var x,y;
+  if(Sutra.lastX==null){
+    Sutra.lastX=e.clientX;
+    Sutra.lastY=e.clientY;
+    return;
+  }
+  x=e.clientX-Sutra.lastX;
+  y=e.clientY-Sutra.lastY;
+  if(x*x+y*y>9){
+    Sutra.lastX=e.clientX;
+    Sutra.lastY=e.clientY;
+    return;
+  }
+  Sutra.lastX=null;
+  x=e.currentTarget;
+  for(y in Sutra.svg){
+    if(Sutra.svg[y]==x){
+      x=Sutra.volpath+"/"+("000"+y).slice(-3)+".txt";
+      window.open("editor-kanbun.html#"+Sutra.url+"files/"+encodeURIComponent(x)+"/raw?ref=master");
+      break;
+    }
+  }
+}
+Sutra.reload=function(){
+  var i,r;
+  for(i=Sutra.curr;i<=Sutra.currmax;i++){
+    if(Sutra.svg[i]==null||Sutra.pre[i]==null)
+      return;
+    r=Sutra.svg[i].getBoundingClientRect();
+    if(r.top>window.innerHeight||r.bottom<0)
+      return;
+    r=Sutra.volpath+"/"+("000"+i).slice(-3)+".txt";
+    conllusvg.loadRemote("pre"+i,Sutra.url+"files/"+encodeURIComponent(r)+"/raw?ref=master");
+  }
+}
+Sutra.gitlab=function(){
+  var r=Sutra.volpath+"/"+("000"+Sutra.curr).slice(-3)+".txt";
+  window.open("/gitlab/Kanbun/ud-kanbun/blob/master/"+r);
+}
+</script>
+<body onload="Sutra.init()">
+<div id="top" style="position:fixed; top:0px; left:0px; padding:10px; width:100%; background:white">
+<font size="+3"><b>讌夊セュ</b></font>
+<font size="+3"><b>Universal Dependencies on 貍「隴ッ菴帛�</b></font>
+<select id="vol" onchange="Sutra.volchange()">
+<option value="kanripo/kR6f0082/001" selected>菴幄ェェ髦ソ蠖碁凰邯�</option>
+</select>
+<input type="text" id="count" size=3 value=0 style="text-align:right" onchange="Sutra.goto()" />
+<input type="button" value="GitLab" onclick="Sutra.gitlab()" />
+<input type="button" value="Reload" onclick="Sutra.reload()" />
+</div>
+</body>
-- 
GitLab