2 lines
4.7 KiB
JavaScript
2 lines
4.7 KiB
JavaScript
const F={standard:"\u6807\u51C6",brown_area:"\u68D5\u533A",intersection:"\u4EA4\u53C9\u504F\u632F",parallel:"\u5E73\u884C\u504F\u632F",red_zone:"\u7EA2\u533A\u56FE",red_zone_heat:"\u7EA2\u533A\u70ED\u529B",redness:"\u7EA2\u8840\u4E1D",sunlight:"\u65E5\u5149\u56FE",ultraviolet:"\u7D2B\u5916\u7EBF",uv_spot:"UV\u6591"},M=["standard","brown_area","intersection","parallel","red_zone","red_zone_heat","redness","sunlight","ultraviolet","uv_spot"];function y(t){return t&&String(t).trim()?String(t).trim():""}function E(t){if(!t||typeof t!="object"||Array.isArray(t))return!1;const n=Object.values(t);return n.length?n.every(o=>typeof o=="string"||o==null||o===""):!1}function _(t,n){return{left:t.left||n.left,front:t.front||n.front,right:t.right||n.right}}function B(t,n){var f,e;const o=new Set([...t.keys(),...n.keys()]),s=new Map;for(const r of o){const i=_((f=t.get(r))!=null?f:{left:"",front:"",right:""},(e=n.get(r))!=null?e:{left:"",front:"",right:""});(i.left||i.front||i.right)&&s.set(r,i)}return s}function S(t){const n=new Map(t.map(e=>[e.key,e])),o=[],s=new Set;for(const e of M){const r=n.get(e);r&&(s.add(e),o.push(r))}const f=t.filter(e=>!s.has(e.key)).sort((e,r)=>e.key.localeCompare(r.key));return[...o,...f]}function U(t){const n=t==null?void 0:t.images,o=t==null?void 0:t.imagex,s=n==null?void 0:n.front,f=o==null?void 0:o.front,e=n==null?void 0:n.images,r=o==null?void 0:o.images,i=s&&typeof s=="object"&&!Array.isArray(s)&&E(s),g=f&&typeof f=="object"&&!Array.isArray(f)&&E(f),l=e&&typeof e=="object"&&!Array.isArray(e),m=r&&typeof r=="object"&&!Array.isArray(r);if(!i&&!g&&!l&&!m)return[];const h=new Set;i&&Object.keys(s).forEach(c=>h.add(c)),g&&Object.keys(f).forEach(c=>h.add(c)),l&&Object.keys(e).forEach(c=>h.add(c)),m&&Object.keys(r).forEach(c=>h.add(c));const j=c=>y(i?s[c]:"")||y(g?f[c]:""),k=c=>{const a=u=>{if(!u||typeof u!="object"||Array.isArray(u))return{left:"",front:"",right:""};const p=u[c];if(!p||typeof p!="object"||Array.isArray(p))return{left:"",front:"",right:""};const b=p;return{left:y(b.left),front:y(b.front),right:y(b.right)}};return _(a(e),a(r))},A=[];for(const c of h){const a=j(c),u=k(c),p={left:u.left,front:u.front||a,right:u.right};!a&&!p.left&&!p.front&&!p.right||A.push({key:c,label:F[c]||c,angles:p,thumbUrl:a||u.front||u.left||u.right})}return A.length?S(A):[]}function v(t){var i,g,l,m,h,j,k,A,c;const n=(a,u)=>{var p,b,w,O;return y((b=(p=t==null?void 0:t.images)==null?void 0:p[a])==null?void 0:b[u])||y((O=(w=t==null?void 0:t.imagex)==null?void 0:w[a])==null?void 0:O[u])},o=(l=(i=t==null?void 0:t.images)==null?void 0:i.front)!=null?l:(g=t==null?void 0:t.imagex)==null?void 0:g.front,s=(j=(m=t==null?void 0:t.images)==null?void 0:m.left)!=null?j:(h=t==null?void 0:t.imagex)==null?void 0:h.left,f=(c=(k=t==null?void 0:t.images)==null?void 0:k.right)!=null?c:(A=t==null?void 0:t.imagex)==null?void 0:A.right,e=new Set;[s,f].forEach(a=>{a&&typeof a=="object"&&!Array.isArray(a)&&Object.keys(a).forEach(u=>e.add(u))}),o&&typeof o=="object"&&!Array.isArray(o)&&!E(o)&&Object.keys(o).forEach(a=>e.add(a));const r=new Map;for(const a of e){const u={left:n("left",a),front:n("front",a),right:n("right",a)};(u.left||u.front||u.right)&&r.set(a,u)}return r}function I(t){const n=[t==null?void 0:t.images,t==null?void 0:t.imagex].filter(f=>f&&typeof f=="object"&&!Array.isArray(f)),o=new Map;function s(f,e,r,i){var l;if(!e&&!r&&!i)return;const g=(l=o.get(f))!=null?l:{left:"",front:"",right:""};o.set(f,{left:g.left||e,front:g.front||r,right:g.right||i})}for(const f of n)for(const[e,r]of Object.entries(f)){if(["left","front","right"].includes(e))continue;if(e==="images"&&r&&typeof r=="object"&&!Array.isArray(r)){for(const[g,l]of Object.entries(r)){if(!l||typeof l!="object"||Array.isArray(l))continue;const m=l;s(g,y(m.left),y(m.front),y(m.right))}continue}if(!r||typeof r!="object"||Array.isArray(r))continue;const i=r;s(e,y(i.left),y(i.front),y(i.right))}return o}function z(t){const n=[];for(const[o,s]of t)!s.left&&!s.front&&!s.right||n.push({key:o,label:F[o]||o,angles:s,thumbUrl:s.front||s.left||s.right});return S(n)}function C(t){var r,i,g;if(!t||typeof t!="object")return[];const n=U(t);if(n.length)return n;const o=v(t),s=I(t),f=B(o,s);if(f.size)return z(f);const e=(g=(r=t==null?void 0:t.images)==null?void 0:r.front)!=null?g:(i=t==null?void 0:t.imagex)==null?void 0:i.front;return!e||typeof e!="object"||!E(e)?[]:Object.entries(e).map(([l,m])=>{const h=y(m);return h?{key:l,label:F[l]||l,angles:{left:"",front:h,right:""},thumbUrl:h}:null}).filter(l=>l!=null)}function D(...t){const n=new Set;for(const e of t)for(const r of e)n.add(r.key);const o=[],s=new Set;for(const e of M)n.has(e)&&(o.push(e),s.add(e));const f=[...n].filter(e=>!s.has(e)).sort((e,r)=>e.localeCompare(r));return[...o,...f]}export{C as b,D as o};
|