From 490ba583675fb48d49f3d2a899b3117da8e1a03a Mon Sep 17 00:00:00 2001
From: Koichi Yasuoka <yasuoka@kanji.zinbun.kyoto-u.ac.jp>
Date: Fri, 24 Feb 2023 14:48:19 +0900
Subject: [PATCH] initial release

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

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