2adb07518c
CI / test (push) Has been cancelled
PATCH /api/user/password — verifies the current password, enforces 8-char minimum on the new one, and rehashes via the configured password hasher. Returns 204 on success, 422 with an `error` body on every validation failure (wrong current, too-short new, missing fields). Settings adds a "Change password" link under the Account section that opens a modal with current/new/confirm fields and posts to the new endpoint. Confirm-mismatch and submit-disabled wiring is client-side; backend errors surface inline. Tests: 4 new controller tests cover success, wrong-current, short-new, and missing-fields; success path also re-fetches the user and checks the hash actually changed.
1 line
21 KiB
JavaScript
1 line
21 KiB
JavaScript
import{A as e,B as t,C as n,F as r,J as i,K as a,L as o,N as s,O as c,S as l,U as u,Y as d,_ as f,b as p,f as m,g as h,h as g,k as _,p as v,q as y,t as b,v as x,x as S,y as C,z as w}from"./_plugin-vue_export-helper-BNDVmFr7.js";import{a as T,i as E,s as D}from"./index-BA_yAOa7.js";import{i as O,n as ee,r as k,t as A}from"./BaseBottomSheet-Bsol3Sat.js";import{t as j}from"./DevicePicker-1UBxnMbg.js";var M={class:`crop-editor__top`},N={key:0,class:`crop-editor__label`},P={class:`crop-editor__orient`,role:`radiogroup`,"aria-label":`Crop orientation`},F=[`aria-checked`,`aria-label`,`onClick`],I={width:`20`,height:`20`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,"stroke-width":`2`,"aria-hidden":`true`},L={key:0,x:`2`,y:`6`,width:`20`,height:`12`,rx:`1.5`},te={key:1,x:`6`,y:`2`,width:`12`,height:`20`,rx:`1.5`},R={key:1,class:`crop-editor__mismatch`,role:`status`},ne={class:`crop-editor__actions`},z=b(n({__name:`CropEditor`,props:{src:{},orientation:{},deviceName:{},initialParams:{},initialOrientation:{}},emits:[`crop`],setup(n,{emit:i}){let a=n,o=i,c=[{value:`landscape`,label:`Landscape crop`},{value:`portrait`,label:`Portrait crop`}],f=u(a.initialOrientation??a.orientation),p=g(()=>f.value===`landscape`?{w:1600,h:960}:{w:960,h:1600}),m=g(()=>p.value.w/p.value.h),b=g(()=>f.value!==a.orientation),T=u(),E=u(),D=null,O=null,k=0,A=u(0),j=u(0),z=u(1),B={x:0,y:0,w:0,h:0},V=1;function re(e){f.value!==e&&(f.value=e,A.value=0,j.value=0,z.value=1,H())}function H(){let e=E.value,t=T.value;if(!e||!t)return;let n=t.getBoundingClientRect(),r=n.height-80,i=n.width;e.width=i,e.height=r,D=e.getContext(`2d`);let a=i-48,o=r-48,s,c;a/o>m.value?(c=o,s=c*m.value):(s=a,c=s/m.value),B={x:(i-s)/2,y:(r-c)/2,w:s,h:c},O&&U()}function U(){O&&(V=Math.max(B.w/O.naturalWidth,B.h/O.naturalHeight),a.initialParams?W(a.initialParams):(z.value=1,A.value=0,j.value=0,K()))}function W(e){if(!O)return;let t=B.w/e.natW;z.value=t/V,A.value=t*(O.naturalWidth/2-e.natX-e.natW/2),j.value=t*(O.naturalHeight/2-e.natY-e.natH/2);let[n,r]=G(A.value,j.value);A.value=n,j.value=r,K()}function G(e,t){if(!O)return[e,t];let n=V*z.value,r=O.naturalWidth*n,i=O.naturalHeight*n,a=(r-B.w)/2,o=(i-B.h)/2;return[Math.max(-a,Math.min(a,e)),Math.max(-o,Math.min(o,t))]}function K(){if(!D||!O||!E.value)return;let{width:e,height:t}=E.value,n=V*z.value,r=O.naturalWidth*n,i=O.naturalHeight*n,a=B.x+B.w/2+A.value,o=B.y+B.h/2+j.value,s=a-r/2,c=o-i/2;D.clearRect(0,0,e,t),D.drawImage(O,s,c,r,i);let l=B.x+B.w,u=B.y+B.h;D.fillStyle=`rgba(0,0,0,0.6)`,D.fillRect(0,0,e,B.y),D.fillRect(0,u,e,t-u),D.fillRect(0,B.y,B.x,B.h),D.fillRect(l,B.y,e-l,B.h),D.strokeStyle=`#fff`,D.lineWidth=2,D.strokeRect(B.x,B.y,B.w,B.h),D.lineWidth=3,[[B.x,B.y,20,0,0,20],[B.x+B.w,B.y,-20,0,0,20],[B.x,B.y+B.h,20,0,0,-20],[B.x+B.w,B.y+B.h,-20,0,0,-20]].forEach(([e,t,n,r,i,a])=>{D.beginPath(),D.moveTo(e+n,t+r),D.lineTo(e,t),D.lineTo(e+i,t+a),D.stroke()})}let q=new Map,J=0;function Y(e){if(E.value?.setPointerCapture(e.pointerId),q.set(e.pointerId,{x:e.clientX,y:e.clientY}),q.size===2){let e=[...q.values()];J=Math.hypot(e[1].x-e[0].x,e[1].y-e[0].y)}}function X(e){if(!q.has(e.pointerId))return;let t=q.get(e.pointerId);if(q.set(e.pointerId,{x:e.clientX,y:e.clientY}),q.size===1){let n=e.clientX-t.x,r=e.clientY-t.y,[i,a]=G(A.value+n,j.value+r);A.value=i,j.value=a,Q();return}if(q.size===2){let e=[...q.values()],t=Math.hypot(e[1].x-e[0].x,e[1].y-e[0].y);if(J>0){let e=t/J;z.value=Math.max(1,z.value*e);let[n,r]=G(A.value,j.value);A.value=n,j.value=r,Q()}J=t}}function Z(e){q.delete(e.pointerId),J=0}function Q(){cancelAnimationFrame(k),k=requestAnimationFrame(K)}async function ie(){if(!O)return;let e=V*z.value,t=B.x+B.w/2+A.value,n=B.y+B.h/2+j.value,r=t-O.naturalWidth*e/2,i=n-O.naturalHeight*e/2,a=(B.x-r)/e,s=(B.y-i)/e,c=B.w/e,l=B.h/e,{w:u,h:d}=p.value,m=new OffscreenCanvas(u,d);m.getContext(`2d`).drawImage(O,a,s,c,l,0,0,u,d),o(`crop`,{blob:await m.convertToBlob({type:`image/jpeg`,quality:.92}),params:{natX:a,natY:s,natW:c,natH:l},orientation:f.value})}let ae=new ResizeObserver(H);return e(()=>{T.value&&ae.observe(T.value),H(),O=new Image,O.onload=()=>{H(),U()},O.src=a.src}),w(()=>a.src,e=>{O&&(O.onload=()=>U(),O.src=e)}),_(()=>{ae.disconnect(),cancelAnimationFrame(k)}),(e,i)=>(s(),C(`div`,{class:`crop-editor`,ref_key:`containerRef`,ref:T},[h(`canvas`,{ref_key:`canvasRef`,ref:E,class:`crop-editor__canvas`,onPointerdown:Y,onPointermove:X,onPointerup:Z,onPointercancel:Z},null,544),h(`div`,M,[n.deviceName?(s(),C(`div`,N,d(n.deviceName),1)):x(``,!0),h(`div`,P,[(s(),C(v,null,r(c,e=>h(`button`,{key:e.value,type:`button`,role:`radio`,"aria-checked":f.value===e.value,"aria-label":e.label,class:y([`crop-editor__orient-btn`,{"crop-editor__orient-btn--active":f.value===e.value}]),onClick:t=>re(e.value)},[(s(),C(`svg`,I,[e.value===`landscape`?(s(),C(`rect`,L)):(s(),C(`rect`,te))]))],10,F)),64))]),b.value?(s(),C(`div`,R,[i[0]||=h(`svg`,{width:`14`,height:`14`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,"stroke-width":`2.5`,"aria-hidden":`true`},[h(`path`,{d:`M10.29 3.86 1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0z`}),h(`line`,{x1:`12`,y1:`9`,x2:`12`,y2:`13`}),h(`line`,{x1:`12`,y1:`17`,x2:`12.01`,y2:`17`})],-1),h(`span`,null,`Frame is set to `+d(n.orientation)+`. Switch the frame in Settings to display this crop.`,1)])):x(``,!0)]),h(`div`,ne,[l(ee,{variant:`primary`,class:`crop-editor__use-btn`,onClick:ie},{default:t(()=>[...i[1]||=[S(` Use this crop `,-1)]]),_:1})])],512))}}),[[`__scopeId`,`data-v-9ad25e6f`]]),B=[{id:`santa-hat`,label:`Santa hat`,url:`data:image/svg+xml,%3csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2064%2064'%3e%3cpath%20d='M%208%2052%20L%2056%2052%20Q%2050%2030%2042%2012%20Q%2032%2022%2024%2032%20Q%2014%2042%208%2052%20Z'%20fill='%23cf2030'/%3e%3cpath%20d='M%2024%2032%20Q%2014%2042%208%2052%20Q%2018%2050%2028%2044%20Q%2026%2038%2024%2032%20Z'%20fill='%23a8141d'%20opacity='0.55'/%3e%3crect%20x='6'%20y='48'%20width='52'%20height='10'%20rx='5'%20fill='%23ffffff'/%3e%3cellipse%20cx='14'%20cy='53'%20rx='2.2'%20ry='1.6'%20fill='%23ececec'/%3e%3cellipse%20cx='28'%20cy='53'%20rx='2.2'%20ry='1.6'%20fill='%23ececec'/%3e%3cellipse%20cx='42'%20cy='53'%20rx='2.2'%20ry='1.6'%20fill='%23ececec'/%3e%3cellipse%20cx='52'%20cy='53'%20rx='2'%20ry='1.4'%20fill='%23ececec'/%3e%3ccircle%20cx='42'%20cy='12'%20r='7.5'%20fill='%23ffffff'/%3e%3ccircle%20cx='40'%20cy='10'%20r='2'%20fill='%23f4f4f4'%20opacity='0.6'/%3e%3c/svg%3e`}],V={class:`sticker-tray`},re={key:0,class:`sticker-tray__section`},H={class:`sticker-tray__row`},U=[`aria-label`,`onClick`],W={key:0,class:`sticker-tray__emoji`,"aria-hidden":`true`},G=[`src`],K={class:`sticker-tray__section`},q={class:`sticker-tray__row`},J=[`aria-label`,`onClick`],Y=[`src`,`alt`],X={class:`sticker-tray__section`},Z=`pf.stickerTray.recents`,Q=12,ie=b(n({__name:`StickerTray`,props:{modelValue:{type:Boolean}},emits:[`update:modelValue`,`pick`],setup(n,{emit:i}){let o=i,c=u([]);e(()=>{c.value=l()});function l(){try{let e=localStorage.getItem(Z);return e?JSON.parse(e).map(e=>{if(e.kind===`image`&&e.imageAsset){let t=B.find(t=>t.id===e.imageAsset);return{...e,url:t?.url,label:t?.label??e.label}}return e}).filter(e=>e.kind===`emoji`?!!e.emoji:!!e.url):[]}catch{return[]}}function p(){try{localStorage.setItem(Z,JSON.stringify(c.value))}catch{}}function m(e){c.value=[e,...c.value.filter(t=>t.key!==e.key)].slice(0,Q),p()}function g(e){if(!e)return null;if(typeof Intl<`u`&&Intl.Segmenter){let t=[...new Intl.Segmenter(void 0,{granularity:`grapheme`}).segment(e)];return t[t.length-1]?.segment??null}return[...e].pop()??null}function _(e){let t=e.target,n=g(t.value);t.value=``,n&&(m({key:`emoji:${n}`,kind:`emoji`,label:n,emoji:n}),o(`pick`,{emoji:n}))}function y(e){m({key:`image:${e.id}`,kind:`image`,label:e.label,imageAsset:e.id,url:e.url}),o(`pick`,{imageAsset:e.id})}function b(e){m(e),e.kind===`emoji`&&e.emoji?o(`pick`,{emoji:e.emoji}):e.kind===`image`&&e.imageAsset&&o(`pick`,{imageAsset:e.imageAsset})}return(e,i)=>(s(),f(A,{"model-value":n.modelValue,label:`Add sticker`,"onUpdate:modelValue":i[0]||=t=>e.$emit(`update:modelValue`,t)},{default:t(()=>[h(`div`,V,[c.value.length?(s(),C(`section`,re,[i[1]||=h(`h3`,{class:`sticker-tray__heading`},`Recent`,-1),h(`div`,H,[(s(!0),C(v,null,r(c.value,e=>(s(),C(`button`,{key:e.key,type:`button`,class:`sticker-tray__chip`,"aria-label":e.label,onClick:t=>b(e)},[e.kind===`emoji`?(s(),C(`span`,W,d(e.emoji),1)):(s(),C(`img`,{key:1,src:e.url,alt:``,class:`sticker-tray__img`},null,8,G))],8,U))),128))])])):x(``,!0),h(`section`,K,[i[2]||=h(`h3`,{class:`sticker-tray__heading`},`Stickers`,-1),h(`div`,q,[(s(!0),C(v,null,r(a(B),e=>(s(),C(`button`,{key:e.id,type:`button`,class:`sticker-tray__chip`,"aria-label":e.label,onClick:t=>y(e)},[h(`img`,{src:e.url,alt:e.label,class:`sticker-tray__img`},null,8,Y)],8,J))),128))])]),h(`section`,X,[i[3]||=h(`h3`,{class:`sticker-tray__heading`},`Any emoji`,-1),i[4]||=h(`p`,{class:`sticker-tray__hint`},`Tap the box, then pick from your keyboard's emoji button.`,-1),h(`input`,{type:`text`,class:`sticker-tray__emoji-input`,inputmode:`text`,autocomplete:`off`,autocorrect:`off`,autocapitalize:`off`,spellcheck:`false`,placeholder:`😀 🎉 🐶 …`,"aria-label":`Emoji input — use your keyboard's emoji button`,onInput:_},null,32)])])]),_:1},8,[`model-value`]))}}),[[`__scopeId`,`data-v-9a64b78a`]]),ae=[{id:`sea-snow`,category:`seasonal`,label:`Snowflake`,emoji:`❄️`},{id:`sea-sun`,category:`seasonal`,label:`Sun`,emoji:`☀️`},{id:`sea-leaves`,category:`seasonal`,label:`Autumn`,emoji:`🍂`},{id:`sea-blossom`,category:`seasonal`,label:`Blossom`,emoji:`🌸`},{id:`sea-snowman`,category:`seasonal`,label:`Snowman`,emoji:`⛄`},{id:`hol-tree`,category:`holidays`,label:`Tree`,emoji:`🎄`},{id:`hol-gift`,category:`holidays`,label:`Gift`,emoji:`🎁`},{id:`hol-heart`,category:`holidays`,label:`Heart`,emoji:`❤️`},{id:`hol-party`,category:`holidays`,label:`Party`,emoji:`🎉`},{id:`hol-cake`,category:`holidays`,label:`Cake`,emoji:`🎂`},{id:`fun-star`,category:`fun`,label:`Star`,emoji:`⭐`},{id:`fun-rainbow`,category:`fun`,label:`Rainbow`,emoji:`🌈`},{id:`fun-balloon`,category:`fun`,label:`Balloon`,emoji:`🎈`},{id:`fun-sparkle`,category:`fun`,label:`Sparkles`,emoji:`✨`},{id:`fun-fire`,category:`fun`,label:`Fire`,emoji:`🔥`},{id:`fam-house`,category:`family`,label:`Home`,emoji:`🏠`},{id:`fam-paw`,category:`family`,label:`Paw`,emoji:`🐾`},{id:`fam-camera`,category:`family`,label:`Camera`,emoji:`📷`},{id:`fam-plane`,category:`family`,label:`Airplane`,emoji:`✈️`},{id:`fam-music`,category:`family`,label:`Music`,emoji:`🎵`},{id:`nat-tree`,category:`nature`,label:`Tree`,emoji:`🌲`},{id:`nat-flower`,category:`nature`,label:`Flower`,emoji:`🌺`},{id:`nat-bee`,category:`nature`,label:`Bee`,emoji:`🐝`},{id:`nat-fly`,category:`nature`,label:`Butterfly`,emoji:`🦋`},{id:`nat-moon`,category:`nature`,label:`Moon`,emoji:`🌙`}],oe={class:`sticker-canvas__bar`},se=52,$=96,ce=b(n({__name:`StickerCanvas`,props:{croppedUrl:{},orientation:{},stickers:{}},emits:[`add-sticker`,`update-sticker`,`remove-sticker`,`done`],setup(n,{emit:a}){let d=n,y=a,b=u(),T=u(),E=u(),D=u(),O=u(!1),k=u(null),A=u(375),j=u(225),M=d.orientation===`landscape`?1600/960:960/1600;function N(){if(!b.value)return;let{width:e,height:t}=b.value.getBoundingClientRect(),n=t-72;e/n>M?(j.value=n,A.value=n*M):(A.value=e,j.value=e/M),I()}let P=new ResizeObserver(N);e(()=>{b.value&&P.observe(b.value),N(),pe()}),_(()=>{P.disconnect(),me(),U?.()}),w(()=>d.stickers,()=>{if(!k.value)return;let e=(D.value?.getNode())?.findOne(`#${k.value}`);e&&W(e)},{deep:!0});let F=u(null);function I(){let e=new Image;e.onload=()=>{F.value=e},e.src=d.croppedUrl}w(()=>d.croppedUrl,()=>I(),{immediate:!0});let L=u({});e(()=>{for(let e of B){let t=new Image;t.onload=()=>{L.value={...L.value,[e.id]:t}},t.src=e.url}});let te=g(()=>({width:A.value,height:j.value})),R=g(()=>({image:F.value,x:0,y:0,width:A.value,height:j.value})),ne={enabledAnchors:[`top-left`,`top-right`,`bottom-left`,`bottom-right`],rotateEnabled:!0,borderStroke:`rgba(255,255,255,0.8)`,anchorFill:`#fff`,anchorSize:18,keepRatio:!0,boundBoxFunc:(e,t)=>t};function z(e){return{id:e.id,text:re(e),fontSize:se,fontFamily:`"Apple Color Emoji","Segoe UI Emoji","Noto Color Emoji",sans-serif`,x:e.x,y:e.y,scaleX:e.scale,scaleY:e.scale,rotation:e.rotation,draggable:!0,offsetX:se/2,offsetY:se/2}}function V(e){return{id:e.id,image:e.imageAsset?L.value[e.imageAsset]:null,x:e.x,y:e.y,width:$,height:$,scaleX:e.scale,scaleY:e.scale,rotation:e.rotation,draggable:!0,offsetX:$/2,offsetY:$/2}}function re(e){return e.emoji?e.emoji:ae.find(t=>t.id===e.type)?.emoji??`⭐`}let H=u(null),U=null;function W(e){let t=e.getClientRect(),n=t.x+t.width+4-14,r=t.y-4-14;n=Math.max(14,Math.min(A.value-14,n)),r=Math.max(14,Math.min(j.value-14,r)),H.value={x:n,y:r}}function G(e){U?.(),U=null;let t=(D.value?.getNode())?.findOne(`#${e}`);if(!t){H.value=null;return}W(t),t.on(`dragmove.handle transform.handle transformend.handle dragend.handle`,()=>W(t)),U=()=>t.off(`.handle`)}function K(e,t){t.cancelBubble=!0,k.value=e,c(()=>{let t=(D.value?.getNode())?.findOne(`#${e}`),n=E.value?.getNode();t&&n&&n.nodes([t]),G(e)})}function q(e){e.target===e.target.getStage()&&(k.value=null,E.value?.getNode()?.nodes([]),U?.(),U=null,H.value=null)}function J(){k.value&&(y(`remove-sticker`,k.value),k.value=null,E.value?.getNode()?.nodes([]),U?.(),U=null,H.value=null)}function Y(e,t){y(`update-sticker`,e,{x:t.target.x(),y:t.target.y()})}function X(e,t){y(`update-sticker`,e,{x:t.target.x(),y:t.target.y(),scale:t.target.scaleX(),rotation:t.target.rotation()})}function Z(e){let t={id:`${e.imageAsset??e.emoji??`sticker`}-${Date.now()}`,type:e.imageAsset?`image`:`emoji`,emoji:e.emoji,imageAsset:e.imageAsset,x:A.value/2,y:j.value/2,scale:1,rotation:0};y(`add-sticker`,t),O.value=!1,c(()=>K(t.id,{cancelBubble:!1}))}let Q=0,ce=1;function le(e){let t=e[0].clientX-e[1].clientX,n=e[0].clientY-e[1].clientY;return Math.hypot(t,n)}function ue(e){e.touches.length!==2||!k.value||(Q=le(e.touches),ce=d.stickers.find(e=>e.id===k.value)?.scale??1)}function de(e){if(e.touches.length!==2||!k.value||Q===0)return;e.preventDefault();let t=Math.max(.2,Math.min(6,ce*(le(e.touches)/Q)));y(`update-sticker`,k.value,{scale:t})}function fe(){Q=0,ce=1}function pe(){let e=b.value;e&&(e.addEventListener(`touchstart`,ue,{passive:!0}),e.addEventListener(`touchmove`,de,{passive:!1}),e.addEventListener(`touchend`,fe,{passive:!0}))}function me(){let e=b.value;e&&(e.removeEventListener(`touchstart`,ue),e.removeEventListener(`touchmove`,de),e.removeEventListener(`touchend`,fe))}async function he(){k.value=null,E.value?.getNode()?.nodes([]),await c();let e=T.value?.getNode();if(!e)return;let t=(d.orientation===`landscape`?1600:960)/A.value,n=await e.toBlob({pixelRatio:t,mimeType:`image/jpeg`,quality:.92});n&&y(`done`,n)}return(e,a)=>{let c=o(`v-image`),u=o(`v-layer`),d=o(`v-text`),g=o(`v-transformer`),_=o(`v-stage`);return s(),C(`div`,{class:`sticker-canvas`,ref_key:`containerRef`,ref:b},[l(_,{ref_key:`stageRef`,ref:T,config:te.value,onClick:q,onTap:q},{default:t(()=>[l(u,null,{default:t(()=>[l(c,{config:R.value},null,8,[`config`])]),_:1}),l(u,{ref_key:`stickerLayerRef`,ref:D},{default:t(()=>[(s(!0),C(v,null,r(n.stickers,e=>(s(),C(v,{key:e.id},[e.imageAsset?(s(),f(c,{key:0,config:V(e),onClick:t=>K(e.id,t),onTap:t=>K(e.id,t),onDragend:t=>Y(e.id,t),onTransformend:t=>X(e.id,t)},null,8,[`config`,`onClick`,`onTap`,`onDragend`,`onTransformend`])):(s(),f(d,{key:1,config:z(e),onClick:t=>K(e.id,t),onTap:t=>K(e.id,t),onDragend:t=>Y(e.id,t),onTransformend:t=>X(e.id,t)},null,8,[`config`,`onClick`,`onTap`,`onDragend`,`onTransformend`]))],64))),128)),l(g,{ref_key:`transformerRef`,ref:E,config:ne},null,512)]),_:1},512)]),_:1},8,[`config`]),H.value?(s(),C(`button`,{key:0,class:`sticker-canvas__delete-handle`,type:`button`,"aria-label":`Remove sticker`,style:i({left:H.value.x+`px`,top:H.value.y+`px`}),onPointerdown:a[0]||=m(()=>{},[`stop`]),onClick:m(J,[`stop`])},[...a[3]||=[p(`<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.4" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" data-v-0487769c><polyline points="3 6 5 6 21 6" data-v-0487769c></polyline><path d="M19 6l-1 14a2 2 0 0 1-2 2H8a2 2 0 0 1-2-2L5 6" data-v-0487769c></path><path d="M10 11v6" data-v-0487769c></path><path d="M14 11v6" data-v-0487769c></path><path d="M9 6V4a1 1 0 0 1 1-1h4a1 1 0 0 1 1 1v2" data-v-0487769c></path></svg>`,1)]],36)):x(``,!0),h(`div`,oe,[h(`button`,{class:`sticker-canvas__add-btn`,type:`button`,onClick:a[1]||=e=>O.value=!0},[...a[4]||=[h(`svg`,{width:`20`,height:`20`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,"stroke-width":`2`,"aria-hidden":`true`},[h(`circle`,{cx:`12`,cy:`12`,r:`10`}),h(`line`,{x1:`12`,y1:`8`,x2:`12`,y2:`16`}),h(`line`,{x1:`8`,y1:`12`,x2:`16`,y2:`12`})],-1),S(` Add sticker `,-1)]]),l(ee,{variant:`primary`,class:`sticker-canvas__next-btn`,onClick:he},{default:t(()=>[...a[5]||=[S(`Next`,-1)]]),_:1})]),l(ie,{modelValue:O.value,"onUpdate:modelValue":a[2]||=e=>O.value=e,onPick:Z},null,8,[`modelValue`])],512)}}}),[[`__scopeId`,`data-v-0487769c`]]),le={class:`upload-view`},ue={class:`upload-view__header`},de=[`aria-label`],fe={key:0,width:`20`,height:`20`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,"stroke-width":`2.5`,"aria-hidden":`true`},pe={key:1,width:`20`,height:`20`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,"stroke-width":`2.5`,"aria-hidden":`true`},me={class:`upload-view__step-label`},he={key:2,class:`upload-view__done`},ge={class:`upload-view__done-title`},_e=b(n({__name:`UploadView`,setup(n){let r=D(),i=k(),o=O(),c=T(),p=E(),m=u(`crop`),_=u(!1),v=u(!1),y=null,b=g(()=>i.editingImageId!==null);e(async()=>{if(await o.fetchDevices(),!i.originalFile){r.replace(`/`);return}m.value=`crop`});let w=g(()=>i.contextDeviceId?o.devices.find(e=>e.id===i.contextDeviceId):o.devices[0]),A=g(()=>w.value?.orientation??`landscape`),M=g(()=>i.cropOrientation??A.value),N=g(()=>w.value?.name),P=g(()=>m.value===`crop`?b.value?`Edit crop`:`Crop photo`:m.value===`stickers`?`Add stickers`:b.value?`Updated`:`Added`);function F({blob:e,params:t,orientation:n}){i.setCrop(e,t,n),m.value=`stickers`}function I(){i.croppedBlob&&(y=i.croppedBlob,b.value?R():v.value=!0)}function L(e){y=e,b.value?R():v.value=!0}function te(){if(m.value===`crop`){i.cleanup(),r.replace(`/library`);return}m.value===`stickers`&&(m.value=`crop`)}async function R(){if(y){_.value=!0;try{let e=new File([y],`photo.jpg`,{type:`image/jpeg`});if(b.value){await c.reprocessImage(i.editingImageId,e,{cropParams:i.cropParams??void 0,stickerState:i.stickers,cropOrientation:i.cropOrientation??void 0}),v.value=!1,m.value=`done`;return}let t=await c.uploadImage(e,{original:i.originalFile??void 0,cropParams:i.cropParams??void 0,stickerState:i.stickers,cropOrientation:i.cropOrientation??void 0});await Promise.all(i.selectedDeviceIds.map(e=>c.setApproval(t.id,e,!0))),v.value=!1,m.value=`done`}catch(e){p.show(e instanceof Error?e.message:`Upload failed`,`error`)}finally{_.value=!1}}}function ne(){i.cleanup(),r.replace(`/library`)}return(e,n)=>(s(),C(`div`,le,[h(`header`,ue,[m.value===`done`?x(``,!0):(s(),C(`button`,{key:0,class:`upload-view__back`,type:`button`,"aria-label":m.value===`crop`?`Cancel`:`Back`,onClick:te},[m.value===`crop`?(s(),C(`svg`,fe,[...n[2]||=[h(`line`,{x1:`18`,y1:`6`,x2:`6`,y2:`18`},null,-1),h(`line`,{x1:`6`,y1:`6`,x2:`18`,y2:`18`},null,-1)]])):(s(),C(`svg`,pe,[...n[3]||=[h(`polyline`,{points:`15 18 9 12 15 6`},null,-1)]]))],8,de)),h(`span`,me,d(P.value),1),m.value===`stickers`?(s(),C(`button`,{key:1,class:`upload-view__skip`,type:`button`,onClick:I},`Skip`)):x(``,!0)]),m.value===`crop`&&a(i).originalUrl?(s(),f(z,{key:0,src:a(i).originalUrl,orientation:A.value,"device-name":N.value,"initial-params":a(i).cropParams,"initial-orientation":a(i).cropOrientation,class:`upload-view__stage`,onCrop:F},null,8,[`src`,`orientation`,`device-name`,`initial-params`,`initial-orientation`])):m.value===`stickers`&&a(i).croppedUrl?(s(),f(ce,{key:1,"cropped-url":a(i).croppedUrl,orientation:M.value,stickers:a(i).stickers,class:`upload-view__stage`,onAddSticker:a(i).addSticker,onUpdateSticker:a(i).updateSticker,onRemoveSticker:a(i).removeSticker,onDone:L},null,8,[`cropped-url`,`orientation`,`stickers`,`onAddSticker`,`onUpdateSticker`,`onRemoveSticker`])):m.value===`done`?(s(),C(`div`,he,[n[5]||=h(`div`,{class:`upload-view__done-icon`,"aria-hidden":`true`},`🎉`,-1),h(`p`,ge,d(b.value?`Photo updated!`:`Photo added!`),1),n[6]||=h(`p`,{class:`upload-view__done-sub`},`It'll appear on your frame at the next update.`,-1),l(ee,{variant:`primary`,class:`upload-view__done-btn`,onClick:ne},{default:t(()=>[...n[4]||=[S(`Done`,-1)]]),_:1})])):x(``,!0),b.value?x(``,!0):(s(),f(j,{key:3,modelValue:v.value,"onUpdate:modelValue":n[0]||=e=>v.value=e,devices:a(o).devices,selected:a(i).selectedDeviceIds,uploading:_.value,"onUpdate:selected":n[1]||=e=>a(i).selectedDeviceIds=e,onConfirm:R},null,8,[`modelValue`,`devices`,`selected`,`uploading`]))]))}}),[[`__scopeId`,`data-v-af5b9c38`]]);export{_e as default}; |