-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
1 lines (1 loc) · 7.14 KB
/
index.js
1
(function(){let t={hanzi:"林",font:"",upm:1e3,baseline:150,facew:96,faceh:96,medw:40,medh:40,overshoot:true,weightmix:.5,hweight:.2,vweight:.2};function e(){t.hanzi=$("#hanzi-input").val();t.upm=parseFloat($("#upm-input").val());t.baseline=parseFloat($("#baseline-input").val());t.facew=parseFloat($("#facew-input").val());t.faceh=parseFloat($("#faceh-input").val());t.medw=parseFloat($("#medw-input").val());t.medh=parseFloat($("#medh-input").val());t.overshoot=$("#overshoot-input").is(":checked");t.weightmix=parseFloat($("#weightmix-input").val());t.hweight=parseFloat($("#hweight-input").val());t.vweight=parseFloat($("#vweight-input").val());const a=$("#font-input").val();try{if(a===""||a===undefined){t.font="";$("#glyph-box").css({fontFamily:""})}else if(!document.fonts.check("12px "+a)){M.toast({html:`不支持的字体:${a}`});t.font="";$("#glyph-box").css({fontFamily:""})}else{t.font=a;$("#glyph-box").css({fontFamily:a})}}catch{M.toast({html:`不支持的字体:${a}`});$("#glyph-box").css({fontFamily:""})}$("#glyph-box").text(t.hanzi);if($("#showref-input").is(":checked")){$("#glyph-box").css({display:""})}else{$("#glyph-box").css({display:"none"})}o(t);localStorage.setItem("secondMedialData",JSON.stringify(t))}function s(a){$("#hanzi-input").val(a.hanzi);$("#font-input").val(a.font);$("#upm-input").val(a.upm);$("#baseline-input").val(a.baseline);$("#facew-input").val(a.facew);$("#faceh-input").val(a.faceh);$("#medw-input").val(a.medw);$("#medh-input").val(a.medh);$("#overshoot-input").prop("checked",a.overshoot);$("#weightmix-input").val(a.weightmix);$("#hweight-input").val(a.hweight);$("#vweight-input").val(a.vweight)}function o(a){const t=$("#em-box").width(),e=$("#em-box").height();const s=t*a.facew/100,o=e*a.faceh/100;$("#face-box").css({width:s+"px",height:o+"px",left:(t-s)/2+"px",top:(e-o)/2+"px"});const{axes:[h,i,l,n],bounds:[r,v,u,g],status:d}=p(a);switch(d){case"unknownIDS":{M.toast({html:"第二中心线理论不支持的构字,或拆字后部件过于生僻"});$("#h-axes").addClass("gray-out");$("#v-axes").addClass("gray-out");$("#h1-val").addClass("gray-out");$("#h2-val").addClass("gray-out");$("#v1-val").addClass("gray-out");$("#v2-val").addClass("gray-out");$("#bounds").addClass("gray-out");$("#hb-val").addClass("gray-out");$("#vb-val").addClass("gray-out")}break;case"unknownComplexity":{M.toast({html:"部分部件视觉重量未知,无法计算"});$("#h-axes").addClass("gray-out");$("#v-axes").addClass("gray-out");$("#h1-val").addClass("gray-out");$("#h2-val").addClass("gray-out");$("#v1-val").addClass("gray-out");$("#v2-val").addClass("gray-out");$("#bounds").addClass("gray-out");$("#hb-val").addClass("gray-out");$("#vb-val").addClass("gray-out")}break;case"horizontal":{$("#h-axes").removeClass("gray-out");$("#v-axes").addClass("gray-out");$("#h1-val").removeClass("gray-out");$("#h2-val").removeClass("gray-out");$("#v1-val").addClass("gray-out");$("#v2-val").addClass("gray-out");$("#bounds").removeClass("gray-out");$("#hb-val").removeClass("gray-out");$("#vb-val").addClass("gray-out")}break;case"vertical":{$("#h-axes").addClass("gray-out");$("#v-axes").removeClass("gray-out");$("#h1-val").addClass("gray-out");$("#h2-val").addClass("gray-out");$("#v1-val").removeClass("gray-out");$("#v2-val").removeClass("gray-out");$("#bounds").removeClass("gray-out");$("#hb-val").addClass("gray-out");$("#vb-val").removeClass("gray-out")}break;case"done":{$("#h-axes").removeClass("gray-out");$("#v-axes").removeClass("gray-out");$("#h1-val").removeClass("gray-out");$("#h2-val").removeClass("gray-out");$("#v1-val").removeClass("gray-out");$("#v2-val").removeClass("gray-out");$("#bounds").removeClass("gray-out");$("#hb-val").removeClass("gray-out");$("#vb-val").removeClass("gray-out")}break}$("#h-axes").css({width:`${s}px`,height:`${(i-h)*e}px`,left:`${(t-s)/2}px`,top:`${h*e}px`});$("#v-axes").css({width:`${(n-l)*t}px`,height:`${o}px`,left:`${l*t}px`,top:`${(e-o)/2}px`});$("#bounds").css({width:`${(v-r)*t}px`,height:`${(g-u)*e}px`,left:`${r*t}px`,top:`${u*t}px`});const m=.5-u<g-.5?u:g;const x=.5-r<v-.5?r:v;$("#h1-val").text(Math.round(a.upm*(1-h))-a.baseline);$("#h1-val").css({top:`${h*e}px`,transform:"translateY(-50%)"});$("#h2-val").text(Math.round(a.upm*(1-i))-a.baseline);$("#h2-val").css({top:`${i*e}px`,transform:"translateY(-50%)"});$("#hb-val").text(Math.round(a.upm*(1-m))-a.baseline);$("#hb-val").css({top:`${m*e}px`,transform:"translateY(-50%)"});$("#v1-val").text(Math.round(l*a.upm));$("#v1-val").css({left:`${l*t}px`,transform:"translateX(-50%)"});$("#v2-val").text(Math.round(n*a.upm));$("#v2-val").css({left:`${n*t}px`,transform:"translateX(-50%)"});$("#vb-val").text(Math.round(x*a.upm));$("#vb-val").css({left:`${x*e}px`,transform:"translateX(-50%)"})}function p(a){let t=a.medw/100,e=a.medh/100;let s=a.facew/100,o=a.faceh/100;let h=[.5-s/2,.5+s/2,.5-o/2,.5+o/2];let i=q[a.hanzi];const l=new Set("⿰⿱⿸⿹⿺");if(l.has(a.hanzi[0]))i=a.hanzi;if(typeof i!=="string")return{axes:[.5-e/2,.5+e/2,.5-t/2,.5+t/2],bounds:h,status:"unknownIDS"};let n=1,r=1,v=1,u=1;const g=k[[...i][1]];const $=k[[...i][2]];if(g===undefined||$===undefined)return{axes:[.5-e/2,.5+e/2,.5-t/2,.5+t/2],bounds:h,status:"unknownComplexity"};if(a.overshoot){const d=3236,m=933;const x=3529,p=1170;const c=g[1]+$[1];const w=g[2]+$[2];const y=(c-d)/m;const f=2/(1+Math.exp(-y*25/12))-1;const b=(w-x)/p;const C=2/(1+Math.exp(-b*25/11))-1;t*=1+f/20;e*=1+C/20}switch(i[0]){case"⿰":v=(a.weightmix*g[1]+(1-a.weightmix)*g[0])*(1-a.hweight);u=a.weightmix*$[1]+(1-a.weightmix)*$[0];h[1]=.5-t*(u/(v+u)-Math.sqrt(v)/(Math.sqrt(v)+Math.sqrt(u)));break;case"⿱":n=(a.weightmix*g[2]+(1-a.weightmix)*g[0])*(1-a.vweight);r=a.weightmix*$[2]+(1-a.weightmix)*$[0];h[3]=.5-e*(r/(n+r)-Math.sqrt(n)/(Math.sqrt(n)+Math.sqrt(r)));break;case"⿸":v=(a.weightmix*g[1]+(1-a.weightmix)*g[0])*(1-a.hweight);u=a.weightmix*$[1]+(1-a.weightmix)*$[0];n=(a.weightmix*g[2]+(1-a.weightmix)*g[0])*(1-a.vweight);r=a.weightmix*$[2]+(1-a.weightmix)*$[0];h[0]=.5-t*(u/(v+u)-Math.sqrt(v)/(Math.sqrt(v)+Math.sqrt(u)));h[2]=.5-e*(r/(n+r)-Math.sqrt(n)/(Math.sqrt(n)+Math.sqrt(r)));break;case"⿹":v=(a.weightmix*$[1]+(1-a.weightmix)*$[0])*(1-a.hweight);u=a.weightmix*g[1]+(1-a.weightmix)*g[0];n=(a.weightmix*g[2]+(1-a.weightmix)*g[0])*(1-a.vweight);r=a.weightmix*$[2]+(1-a.weightmix)*$[0];h[1]=.5-t*(u/(v+u)-Math.sqrt(v)/(Math.sqrt(v)+Math.sqrt(u)));h[2]=.5-e*(r/(n+r)-Math.sqrt(n)/(Math.sqrt(n)+Math.sqrt(r)));break;case"⿺":v=(a.weightmix*g[1]+(1-a.weightmix)*g[0])*(1-a.hweight);u=a.weightmix*$[1]+(1-a.weightmix)*$[0];n=(a.weightmix*$[2]+(1-a.weightmix)*$[0])*(1-a.vweight);r=a.weightmix*g[2]+(1-a.weightmix)*g[0];h[0]=.5-t*(u/(v+u)-Math.sqrt(v)/(Math.sqrt(v)+Math.sqrt(u)));h[3]=.5-e*(r/(n+r)-Math.sqrt(n)/(Math.sqrt(n)+Math.sqrt(r)));break;default:return{axes:[.5-e/2,.5+e/2,.5-t/2,.5+t/2],bounds:h,status:"unknownIDS"}}return{axes:[.5-e*r/(n+r),.5+e*n/(n+r),.5-t*u/(v+u),.5+t*v/(v+u)],bounds:h,status:i[0]==="⿱"?"horizontal":i[0]==="⿰"?"vertical":"done"}}let q={},k={};const a=$.getJSON("./data/ids_simple.json").then(a=>q=a);const h=$.getJSON("./data/glyph_complexities.json").then(a=>k=a);$.when(a,h).then(()=>{const a=localStorage.getItem("secondMedialData");if(a!==null){t=JSON.parse(a);s(t)}e();$("#loading").css({display:"none"})});window.syncUI2Data=e})();