@cos-design/photo-postcard 3.7.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +22 -0
- package/dist/index.cjs +1 -0
- package/dist/index.css +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +274 -0
- package/dist/packages/photoPostcard/src/index.d.ts +3 -0
- package/dist/src/components/photoPostcard/index.d.ts +8 -0
- package/dist/src/components/photoPostcard/types.d.ts +45 -0
- package/dist/src/vite-env.d.ts +39 -0
- package/package.json +54 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
MIT LICENSE
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2021-present jiaxiantao
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
6
|
+
a copy of this software and associated documentation files (the
|
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
11
|
+
the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be
|
|
14
|
+
included in all copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});require('./index.css');var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},s=(n,r,a)=>(a=n==null?{}:e(i(n)),o(r||!n||!n.__esModule?t(a,`default`,{value:n,enumerable:!0}):a,n));let c=require("react");c=s(c,1);let l=require("react/jsx-runtime");var u={postcard:`cos-postcard-g2207`,stage:`cos-stage-jZQ8g`,stack:`cos-stack-fblvy`,stackCard:`cos-stackCard-vGX-D`,cardSlot:`cos-cardSlot-r9iP9`,cardActive:`cos-cardActive-oxk4p`,cardExiting:`cos-cardExiting-PLlYP`,flipInner:`cos-flipInner--e4Ib`,flipped:`cos-flipped-IIL2I`,face:`cos-face-5lB6h`,front:`cos-front-C--cv`,back:`cos-back-3zraM`,photoFrame:`cos-photoFrame-HWolG`,photoFrameWithCaption:`cos-photoFrameWithCaption-4crS0`,photoWrap:`cos-photoWrap-WK92L`,photo:`cos-photo-bdRgi`,cornerStamp:`cos-cornerStamp-Xq-fF`,frontCaption:`cos-frontCaption-w8czv`,frontCaptionTitle:`cos-frontCaptionTitle-rVeaq`,frontCaptionDesc:`cos-frontCaptionDesc-i7PGX`,linedPaper:`cos-linedPaper-iYgmF`,greeting:`cos-greeting-MkrH1`,bodyText:`cos-bodyText-2YX8O`,bodyPlaceholder:`cos-bodyPlaceholder-qovIN`,backFooter:`cos-backFooter-3Dn0w`,stampSquare:`cos-stampSquare-fGd3a`,postmark:`cos-postmark-1FaXp`,postmarkText:`cos-postmarkText-1Ewtv`,divider:`cos-divider-Wgj-N`,empty:`cos-empty-Ys5A1`,hint:`cos-hint-JGozg`},d=6,f=280,p=320,m=e=>typeof e==`number`?`${e}px`:e,h=(e,t)=>t<=0?0:(e%t+t)%t,g=(e,t)=>t<=0?0:Math.max(0,Math.min(t-1,Math.floor(e))),_=e=>{let t=Math.sin(e*127.1+31.7)*43758.5453;return t-Math.floor(t)},v=({photo:e,showCaption:t})=>{let n=t&&(e.title||e.description),r=e.title?e.title:`Greetings from the road`;return(0,l.jsxs)(l.Fragment,{children:[(0,l.jsxs)(`div`,{className:`${u.face} ${u.front}`,children:[(0,l.jsx)(`div`,{className:`${u.photoFrame} ${n?u.photoFrameWithCaption:``}`,children:(0,l.jsx)(`div`,{className:u.photoWrap,children:(0,l.jsx)(`img`,{className:u.photo,src:e.src,alt:e.alt??e.title??``,draggable:!1})})}),(0,l.jsx)(`div`,{className:u.cornerStamp,"aria-hidden":`true`}),n?(0,l.jsxs)(`div`,{className:u.frontCaption,children:[e.title?(0,l.jsx)(`p`,{className:u.frontCaptionTitle,children:e.title}):null,e.description?(0,l.jsx)(`p`,{className:u.frontCaptionDesc,children:e.description}):null]}):null]}),(0,l.jsxs)(`div`,{className:`${u.face} ${u.back}`,children:[(0,l.jsx)(`div`,{className:u.divider,"aria-hidden":`true`}),(0,l.jsxs)(`div`,{className:u.linedPaper,children:[(0,l.jsx)(`p`,{className:u.greeting,children:r}),e.description?(0,l.jsx)(`p`,{className:u.bodyText,children:e.description}):(0,l.jsx)(`p`,{className:u.bodyPlaceholder,children:`Wish you were here…`})]}),(0,l.jsxs)(`div`,{className:u.backFooter,children:[(0,l.jsx)(`div`,{className:u.postmark,"aria-hidden":`true`,children:(0,l.jsxs)(`span`,{className:u.postmarkText,children:[`TRAVEL`,(0,l.jsx)(`br`,{}),`POST`]})}),(0,l.jsx)(`div`,{className:u.stampSquare,"aria-hidden":`true`})]})]})]})},y=({photos:e,width:t=360,height:n=420,cardWidth:r=260,cardHeight:i=170,pullThreshold:a=80,showCaption:o=!0,initialIndex:s=0,initialFlipped:y=!1,onPhotoClick:b,onIndexChange:x,onFlipChange:S,ariaLabel:C=`明信片`,className:w,style:T})=>{let E=(0,c.useRef)(null),D=(0,c.useRef)(null),O=(0,c.useRef)(g(s,e.length)),k=(0,c.useRef)(b),A=(0,c.useRef)(x),j=(0,c.useRef)(S),M=(0,c.useRef)(e),N=(0,c.useRef)(null),[P,F]=(0,c.useState)(()=>g(s,e.length)),[I,L]=(0,c.useState)(y),[R,z]=(0,c.useState)(0),[B,V]=(0,c.useState)(`idle`),H=e.length,U=e[P];(0,c.useEffect)(()=>{k.current=b,A.current=x,j.current=S,M.current=e},[b,x,S,e]),(0,c.useEffect)(()=>{O.current=P},[P]),(0,c.useEffect)(()=>()=>{N.current!=null&&window.clearTimeout(N.current)},[]);let W=(0,c.useMemo)(()=>H<=1?[]:[1,2].slice(0,Math.min(2,H-1)).map(e=>{let t=P*13.7+e*5.3;return{depth:e,rot:(_(t)*2-1)*5.5,dx:e*5+_(t+1.1)*4,dy:e*3+_(t+2.4)*3}}),[H,P]),G=(0,c.useCallback)(e=>{let t=M.current,n=g(e,t.length);F(n),O.current=n,L(!1),j.current?.(!1);let r=t[n];r&&A.current?.(n,r)},[]),K=(0,c.useCallback)(e=>{G(e),z(0),V(`idle`)},[G]),q=(0,c.useCallback)(e=>{let t=e*(r*.55+48);V(`exiting`),z(t),N.current!=null&&window.clearTimeout(N.current),N.current=window.setTimeout(()=>{let t=M.current;K(h(O.current+e,t.length))},f)},[r,K]),J=(0,c.useCallback)(()=>{V(`snapping`),z(0),window.setTimeout(()=>V(`idle`),p)},[]),Y=(0,c.useCallback)(e=>{M.current.length<=1||q(e>0?1:-1)},[q]),X=(0,c.useCallback)(()=>{L(e=>{let t=!e;return j.current?.(t),t})},[]),Z=(0,c.useCallback)(e=>{B===`exiting`||H===0||(D.current={pointerId:e.pointerId,startX:e.clientX,moved:!1},V(`dragging`),e.currentTarget.setPointerCapture(e.pointerId))},[H,B]),Q=(0,c.useCallback)(e=>{let t=D.current;if(!t||t.pointerId!==e.pointerId||B===`exiting`)return;let n=e.clientX-t.startX;Math.abs(n)>d&&(t.moved=!0),z(H<=1?n*.22:n)},[H,B]),$=(0,c.useCallback)(e=>{let t=D.current;if(!t||t.pointerId!==e.pointerId||(D.current=null,e.currentTarget.hasPointerCapture(e.pointerId)&&e.currentTarget.releasePointerCapture(e.pointerId),B===`exiting`))return;let n=e.clientX-t.startX;if(!t.moved){V(`idle`),z(0),X();let e=M.current[O.current];e&&k.current?.(O.current,e);return}if(Math.abs(n)>=a&&H>1){q(n>0?1:-1);return}J()},[q,H,B,a,J,X]),ee=(0,c.useCallback)(e=>{let t=D.current;!t||t.pointerId!==e.pointerId||(D.current=null,e.currentTarget.hasPointerCapture(e.pointerId)&&e.currentTarget.releasePointerCapture(e.pointerId),B!==`exiting`&&J())},[B,J]);(0,c.useEffect)(()=>{let e=E.current;if(!e)return;let t=e=>{e.key===`ArrowRight`?(e.preventDefault(),Y(1)):e.key===`ArrowLeft`?(e.preventDefault(),Y(-1)):(e.key===` `||e.key===`Enter`)&&(e.preventDefault(),X())};return e.addEventListener(`keydown`,t),()=>e.removeEventListener(`keydown`,t)},[Y,X]);let te=`translateX(${R}px)`,ne=B===`snapping`||B===`exiting`?`transform ${B===`exiting`?f:p}ms cubic-bezier(0.22, 1, 0.36, 1), opacity ${f}ms ease`:`none`,re=[u.postcard,w].filter(Boolean).join(` `),ie=[u.cardActive,I?u.flipped:``,B===`exiting`?u.cardExiting:``].filter(Boolean).join(` `);return(0,l.jsx)(`div`,{ref:E,className:re,style:{width:m(t),height:m(n),...T},role:`region`,"aria-label":C,tabIndex:0,children:(0,l.jsx)(`div`,{className:u.stage,children:H===0?(0,l.jsx)(`div`,{className:u.empty,children:`暂无明信片`}):(0,l.jsxs)(l.Fragment,{children:[(0,l.jsxs)(`div`,{className:u.stack,style:{width:r,height:i},children:[W.map(({depth:e,rot:t,dx:n,dy:a})=>(0,l.jsx)(`div`,{className:u.stackCard,style:{width:r,height:i,transform:`translate(calc(-50% + ${n}px), calc(-50% + ${a}px)) rotate(${t}deg)`,opacity:e===1?.92:.78},"aria-hidden":`true`},e)),(0,l.jsx)(`div`,{className:u.cardSlot,style:{width:r,height:i},children:(0,l.jsx)(`div`,{className:ie,style:{width:r,height:i,transform:te,transition:ne,opacity:B===`exiting`?.55:1},onPointerDown:Z,onPointerMove:Q,onPointerUp:$,onPointerCancel:ee,role:`button`,"aria-label":U?`${I?`背面`:`正面`}:${U.alt??U.title??`明信片 ${P+1}`}`:void 0,"aria-pressed":I,children:U?(0,l.jsx)(`div`,{className:u.flipInner,children:(0,l.jsx)(v,{photo:U,showCaption:o})}):null})})]}),H>1?(0,l.jsx)(`div`,{className:u.hint,children:`拖拽切换 · 点击查看背面`}):null]})})})};exports.PhotoPostcard=y,exports.default=y;
|
package/dist/index.css
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
.cos-postcard-g2207{--card-stock:#f4f0e8;--card-edge:#e8e2d6;--ink:#3d4a4f;--ink-muted:#6b787d;--stamp-teal:#2a5f6f;--stamp-coral:#c97b6a;--line-color:#2a5f6f24;--shadow-soft:#23373e24;--shadow-deep:#1928301a;-webkit-user-select:none;user-select:none;-webkit-tap-highlight-color:transparent;background:radial-gradient(120% 90% at 50% 108%,#2a5f6f1a 0%,#0000 58%),radial-gradient(70% 55% at 14% 8%,#ffffff6b 0%,#0000 62%),linear-gradient(168deg,#ece7de 0%,#e4dfd4 48%,#d9d3c8 100%);border-radius:14px;position:relative;overflow:hidden}.cos-postcard-g2207:before{content:"";pointer-events:none;background:repeating-linear-gradient(92deg,#ffffff0d 0 1px,#0000 1px 9px),repeating-linear-gradient(8deg,#3c464b0a 0 2px,#0000 2px 16px);position:absolute;inset:0}.cos-stage-jZQ8g{justify-content:center;align-items:center;width:100%;height:100%;display:flex;position:relative}.cos-stack-fblvy{touch-action:none;position:relative}.cos-stackCard-vGX-D{background:var(--card-stock);box-shadow:0 1px 0 #ffffff8c inset, 0 2px 4px var(--shadow-soft), 0 10px 24px var(--shadow-deep);pointer-events:none;will-change:transform;border-radius:3px;position:absolute;top:50%;left:50%}.cos-stackCard-vGX-D:first-child{z-index:1}.cos-stackCard-vGX-D:nth-child(2){z-index:2}.cos-cardSlot-r9iP9{z-index:3;perspective:900px;position:absolute;top:50%;left:50%;transform:translate(-50%,-50%)}.cos-cardActive-oxk4p{cursor:grab;will-change:transform;filter:drop-shadow(0 8px 18px var(--shadow-soft)) drop-shadow(0 2px 6px var(--shadow-deep));position:relative}.cos-cardActive-oxk4p:active{cursor:grabbing}.cos-cardExiting-PLlYP{pointer-events:none}.cos-flipInner--e4Ib{width:100%;height:100%;transform-style:preserve-3d;transition:transform .58s cubic-bezier(.4,.12,.18,1);position:relative}.cos-flipped-IIL2I .cos-flipInner--e4Ib{transform:rotateY(180deg)}.cos-face-5lB6h{backface-visibility:hidden;transform-style:preserve-3d;background:var(--card-stock);border:1px solid var(--card-edge);border-radius:3px;position:absolute;inset:0;overflow:hidden}.cos-front-C--cv{transform:rotateY(0)}.cos-back-3zraM{flex-direction:column;display:flex;transform:rotateY(180deg)}.cos-photoFrame-HWolG{background:#fff;border:2px solid #fff;flex-direction:column;display:flex;position:absolute;inset:10px;box-shadow:0 0 0 1px #0000000d}.cos-photoFrameWithCaption-4crS0{bottom:52px}.cos-photoWrap-WK92L{background:#dfe5e8;flex:1;min-height:0;position:relative;overflow:hidden}.cos-photo-bdRgi{object-fit:cover;pointer-events:none;width:100%;height:100%;display:block}.cos-cornerStamp-Xq-fF{z-index:2;border:1.5px solid var(--stamp-teal);background:repeating-linear-gradient(0deg, var(--stamp-teal) 0 2px, transparent 2px 4px), linear-gradient(145deg, #2a5f6f2e 0%, #2a5f6f14 100%);opacity:.88;width:28px;height:34px;position:absolute;top:8px;right:8px;box-shadow:0 1px 2px #00000014;-webkit-mask-image:radial-gradient(circle at 0 0,#0000 2px,#000 2.5px),linear-gradient(#000 0 0);mask-image:radial-gradient(circle at 0 0,#0000 2px,#000 2.5px),linear-gradient(#000 0 0);-webkit-mask-position:0 0,0 0;mask-position:0 0,0 0;-webkit-mask-size:4px 4px,auto;mask-size:4px 4px,auto;-webkit-mask-repeat:repeat,repeat;mask-repeat:repeat,repeat;-webkit-mask-clip:border-box,border-box;mask-clip:border-box,border-box;-webkit-mask-origin:border-box,border-box;mask-origin:border-box,border-box;-webkit-mask-composite:xor;mask-composite:exclude;-webkit-mask-source-type:auto,auto;mask-mode:match-source,match-source}.cos-cornerStamp-Xq-fF:after{content:"";border:1px dashed #ffffff8c;position:absolute;inset:5px 4px}.cos-frontCaption-w8czv{color:var(--ink);letter-spacing:.02em;border-top:1px solid #2a5f6f1f;padding:6px 8px;font-size:10px;line-height:1.35;position:absolute;bottom:8px;left:10px;right:10px}.cos-frontCaptionTitle-rVeaq{margin:0;font-size:11px;font-weight:600}.cos-frontCaptionDesc-i7PGX{color:var(--ink-muted);margin:2px 0 0;font-size:9px}.cos-linedPaper-iYgmF{background:repeating-linear-gradient(180deg, transparent 0, transparent 17px, var(--line-color) 17px, var(--line-color) 18px), linear-gradient(180deg, #ffffff59 0%, transparent 24%);border-radius:1px;flex:1;margin:14px 16px 10px;padding:12px 14px 8px;position:relative}.cos-greeting-MkrH1{color:var(--stamp-teal);letter-spacing:.03em;margin:0 0 10px;font-family:Georgia,Times New Roman,serif;font-size:13px;font-style:italic;font-weight:600}.cos-bodyText-2YX8O{color:var(--ink);letter-spacing:.01em;white-space:pre-wrap;margin:0;font-family:Georgia,Times New Roman,serif;font-size:11px;line-height:18px}.cos-bodyPlaceholder-qovIN{color:var(--ink-muted);opacity:.72;margin:0;font-family:Georgia,Times New Roman,serif;font-size:11px;font-style:italic;line-height:18px}.cos-backFooter-3Dn0w{flex-shrink:0;height:58px;margin:0 14px 12px;position:relative}.cos-stampSquare-fGd3a{border:2px solid var(--stamp-teal);background:repeating-linear-gradient(-38deg,#2a5f6f38 0 3px,#c97b6a29 3px 6px),linear-gradient(160deg,#2a5f6f1f 0%,#c97b6a1a 100%);width:44px;height:52px;position:absolute;bottom:0;right:0;box-shadow:inset 0 0 0 3px #f4f0e8d9,0 1px 3px #0000001a}.cos-stampSquare-fGd3a:before{content:"";border:1px dashed #2a5f6f73;position:absolute;inset:6px}.cos-postmark-1FaXp{border:2px solid var(--stamp-coral);width:52px;height:52px;color:var(--stamp-coral);letter-spacing:.08em;text-transform:uppercase;opacity:.82;border-radius:50%;justify-content:center;align-items:center;font-size:7px;font-weight:700;display:flex;position:absolute;bottom:6px;left:4px;transform:rotate(-12deg)}.cos-postmark-1FaXp:before{content:"";border:1px solid #c97b6a73;border-radius:50%;position:absolute;inset:5px}.cos-postmarkText-1Ewtv{z-index:1;text-align:center;line-height:1.2;position:relative}.cos-divider-Wgj-N{pointer-events:none;background:linear-gradient(#0000,#2a5f6f2e 18% 82%,#0000);width:1px;position:absolute;top:14px;bottom:14px;left:58%}.cos-empty-Ys5A1{color:#3d4a4f94;letter-spacing:.06em;justify-content:center;align-items:center;width:100%;height:100%;font-size:13px;display:flex}.cos-hint-JGozg{color:#3d4a4f6b;letter-spacing:.12em;text-transform:uppercase;pointer-events:none;white-space:nowrap;font-size:10px;position:absolute;bottom:12px;left:50%;transform:translate(-50%)}
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,274 @@
|
|
|
1
|
+
import { useCallback as e, useEffect as t, useMemo as n, useRef as r, useState as i } from "react";
|
|
2
|
+
import { Fragment as a, jsx as o, jsxs as s } from "react/jsx-runtime";
|
|
3
|
+
import './index.css';var c = {
|
|
4
|
+
postcard: "cos-postcard-g2207",
|
|
5
|
+
stage: "cos-stage-jZQ8g",
|
|
6
|
+
stack: "cos-stack-fblvy",
|
|
7
|
+
stackCard: "cos-stackCard-vGX-D",
|
|
8
|
+
cardSlot: "cos-cardSlot-r9iP9",
|
|
9
|
+
cardActive: "cos-cardActive-oxk4p",
|
|
10
|
+
cardExiting: "cos-cardExiting-PLlYP",
|
|
11
|
+
flipInner: "cos-flipInner--e4Ib",
|
|
12
|
+
flipped: "cos-flipped-IIL2I",
|
|
13
|
+
face: "cos-face-5lB6h",
|
|
14
|
+
front: "cos-front-C--cv",
|
|
15
|
+
back: "cos-back-3zraM",
|
|
16
|
+
photoFrame: "cos-photoFrame-HWolG",
|
|
17
|
+
photoFrameWithCaption: "cos-photoFrameWithCaption-4crS0",
|
|
18
|
+
photoWrap: "cos-photoWrap-WK92L",
|
|
19
|
+
photo: "cos-photo-bdRgi",
|
|
20
|
+
cornerStamp: "cos-cornerStamp-Xq-fF",
|
|
21
|
+
frontCaption: "cos-frontCaption-w8czv",
|
|
22
|
+
frontCaptionTitle: "cos-frontCaptionTitle-rVeaq",
|
|
23
|
+
frontCaptionDesc: "cos-frontCaptionDesc-i7PGX",
|
|
24
|
+
linedPaper: "cos-linedPaper-iYgmF",
|
|
25
|
+
greeting: "cos-greeting-MkrH1",
|
|
26
|
+
bodyText: "cos-bodyText-2YX8O",
|
|
27
|
+
bodyPlaceholder: "cos-bodyPlaceholder-qovIN",
|
|
28
|
+
backFooter: "cos-backFooter-3Dn0w",
|
|
29
|
+
stampSquare: "cos-stampSquare-fGd3a",
|
|
30
|
+
postmark: "cos-postmark-1FaXp",
|
|
31
|
+
postmarkText: "cos-postmarkText-1Ewtv",
|
|
32
|
+
divider: "cos-divider-Wgj-N",
|
|
33
|
+
empty: "cos-empty-Ys5A1",
|
|
34
|
+
hint: "cos-hint-JGozg"
|
|
35
|
+
}, l = 6, u = 280, d = 320, f = (e) => typeof e == "number" ? `${e}px` : e, p = (e, t) => t <= 0 ? 0 : (e % t + t) % t, m = (e, t) => t <= 0 ? 0 : Math.max(0, Math.min(t - 1, Math.floor(e))), h = (e) => {
|
|
36
|
+
let t = Math.sin(e * 127.1 + 31.7) * 43758.5453;
|
|
37
|
+
return t - Math.floor(t);
|
|
38
|
+
}, g = ({ photo: e, showCaption: t }) => {
|
|
39
|
+
let n = t && (e.title || e.description), r = e.title ? e.title : "Greetings from the road";
|
|
40
|
+
return /* @__PURE__ */ s(a, { children: [/* @__PURE__ */ s("div", {
|
|
41
|
+
className: `${c.face} ${c.front}`,
|
|
42
|
+
children: [
|
|
43
|
+
/* @__PURE__ */ o("div", {
|
|
44
|
+
className: `${c.photoFrame} ${n ? c.photoFrameWithCaption : ""}`,
|
|
45
|
+
children: /* @__PURE__ */ o("div", {
|
|
46
|
+
className: c.photoWrap,
|
|
47
|
+
children: /* @__PURE__ */ o("img", {
|
|
48
|
+
className: c.photo,
|
|
49
|
+
src: e.src,
|
|
50
|
+
alt: e.alt ?? e.title ?? "",
|
|
51
|
+
draggable: !1
|
|
52
|
+
})
|
|
53
|
+
})
|
|
54
|
+
}),
|
|
55
|
+
/* @__PURE__ */ o("div", {
|
|
56
|
+
className: c.cornerStamp,
|
|
57
|
+
"aria-hidden": "true"
|
|
58
|
+
}),
|
|
59
|
+
n ? /* @__PURE__ */ s("div", {
|
|
60
|
+
className: c.frontCaption,
|
|
61
|
+
children: [e.title ? /* @__PURE__ */ o("p", {
|
|
62
|
+
className: c.frontCaptionTitle,
|
|
63
|
+
children: e.title
|
|
64
|
+
}) : null, e.description ? /* @__PURE__ */ o("p", {
|
|
65
|
+
className: c.frontCaptionDesc,
|
|
66
|
+
children: e.description
|
|
67
|
+
}) : null]
|
|
68
|
+
}) : null
|
|
69
|
+
]
|
|
70
|
+
}), /* @__PURE__ */ s("div", {
|
|
71
|
+
className: `${c.face} ${c.back}`,
|
|
72
|
+
children: [
|
|
73
|
+
/* @__PURE__ */ o("div", {
|
|
74
|
+
className: c.divider,
|
|
75
|
+
"aria-hidden": "true"
|
|
76
|
+
}),
|
|
77
|
+
/* @__PURE__ */ s("div", {
|
|
78
|
+
className: c.linedPaper,
|
|
79
|
+
children: [/* @__PURE__ */ o("p", {
|
|
80
|
+
className: c.greeting,
|
|
81
|
+
children: r
|
|
82
|
+
}), e.description ? /* @__PURE__ */ o("p", {
|
|
83
|
+
className: c.bodyText,
|
|
84
|
+
children: e.description
|
|
85
|
+
}) : /* @__PURE__ */ o("p", {
|
|
86
|
+
className: c.bodyPlaceholder,
|
|
87
|
+
children: "Wish you were here…"
|
|
88
|
+
})]
|
|
89
|
+
}),
|
|
90
|
+
/* @__PURE__ */ s("div", {
|
|
91
|
+
className: c.backFooter,
|
|
92
|
+
children: [/* @__PURE__ */ o("div", {
|
|
93
|
+
className: c.postmark,
|
|
94
|
+
"aria-hidden": "true",
|
|
95
|
+
children: /* @__PURE__ */ s("span", {
|
|
96
|
+
className: c.postmarkText,
|
|
97
|
+
children: [
|
|
98
|
+
"TRAVEL",
|
|
99
|
+
/* @__PURE__ */ o("br", {}),
|
|
100
|
+
"POST"
|
|
101
|
+
]
|
|
102
|
+
})
|
|
103
|
+
}), /* @__PURE__ */ o("div", {
|
|
104
|
+
className: c.stampSquare,
|
|
105
|
+
"aria-hidden": "true"
|
|
106
|
+
})]
|
|
107
|
+
})
|
|
108
|
+
]
|
|
109
|
+
})] });
|
|
110
|
+
}, _ = ({ photos: _, width: v = 360, height: y = 420, cardWidth: b = 260, cardHeight: x = 170, pullThreshold: S = 80, showCaption: C = !0, initialIndex: w = 0, initialFlipped: T = !1, onPhotoClick: E, onIndexChange: D, onFlipChange: O, ariaLabel: k = "明信片", className: ee, style: te }) => {
|
|
111
|
+
let A = r(null), j = r(null), M = r(m(w, _.length)), N = r(E), P = r(D), F = r(O), I = r(_), L = r(null), [R, z] = i(() => m(w, _.length)), [B, V] = i(T), [H, U] = i(0), [W, G] = i("idle"), K = _.length, q = _[R];
|
|
112
|
+
t(() => {
|
|
113
|
+
N.current = E, P.current = D, F.current = O, I.current = _;
|
|
114
|
+
}, [
|
|
115
|
+
E,
|
|
116
|
+
D,
|
|
117
|
+
O,
|
|
118
|
+
_
|
|
119
|
+
]), t(() => {
|
|
120
|
+
M.current = R;
|
|
121
|
+
}, [R]), t(() => () => {
|
|
122
|
+
L.current != null && window.clearTimeout(L.current);
|
|
123
|
+
}, []);
|
|
124
|
+
let ne = n(() => K <= 1 ? [] : [1, 2].slice(0, Math.min(2, K - 1)).map((e) => {
|
|
125
|
+
let t = R * 13.7 + e * 5.3;
|
|
126
|
+
return {
|
|
127
|
+
depth: e,
|
|
128
|
+
rot: (h(t) * 2 - 1) * 5.5,
|
|
129
|
+
dx: e * 5 + h(t + 1.1) * 4,
|
|
130
|
+
dy: e * 3 + h(t + 2.4) * 3
|
|
131
|
+
};
|
|
132
|
+
}), [K, R]), J = e((e) => {
|
|
133
|
+
let t = I.current, n = m(e, t.length);
|
|
134
|
+
z(n), M.current = n, V(!1), F.current?.(!1);
|
|
135
|
+
let r = t[n];
|
|
136
|
+
r && P.current?.(n, r);
|
|
137
|
+
}, []), Y = e((e) => {
|
|
138
|
+
J(e), U(0), G("idle");
|
|
139
|
+
}, [J]), X = e((e) => {
|
|
140
|
+
let t = e * (b * .55 + 48);
|
|
141
|
+
G("exiting"), U(t), L.current != null && window.clearTimeout(L.current), L.current = window.setTimeout(() => {
|
|
142
|
+
let t = I.current;
|
|
143
|
+
Y(p(M.current + e, t.length));
|
|
144
|
+
}, u);
|
|
145
|
+
}, [b, Y]), Z = e(() => {
|
|
146
|
+
G("snapping"), U(0), window.setTimeout(() => G("idle"), d);
|
|
147
|
+
}, []), Q = e((e) => {
|
|
148
|
+
I.current.length <= 1 || X(e > 0 ? 1 : -1);
|
|
149
|
+
}, [X]), $ = e(() => {
|
|
150
|
+
V((e) => {
|
|
151
|
+
let t = !e;
|
|
152
|
+
return F.current?.(t), t;
|
|
153
|
+
});
|
|
154
|
+
}, []), re = e((e) => {
|
|
155
|
+
W === "exiting" || K === 0 || (j.current = {
|
|
156
|
+
pointerId: e.pointerId,
|
|
157
|
+
startX: e.clientX,
|
|
158
|
+
moved: !1
|
|
159
|
+
}, G("dragging"), e.currentTarget.setPointerCapture(e.pointerId));
|
|
160
|
+
}, [K, W]), ie = e((e) => {
|
|
161
|
+
let t = j.current;
|
|
162
|
+
if (!t || t.pointerId !== e.pointerId || W === "exiting") return;
|
|
163
|
+
let n = e.clientX - t.startX;
|
|
164
|
+
Math.abs(n) > l && (t.moved = !0), U(K <= 1 ? n * .22 : n);
|
|
165
|
+
}, [K, W]), ae = e((e) => {
|
|
166
|
+
let t = j.current;
|
|
167
|
+
if (!t || t.pointerId !== e.pointerId || (j.current = null, e.currentTarget.hasPointerCapture(e.pointerId) && e.currentTarget.releasePointerCapture(e.pointerId), W === "exiting")) return;
|
|
168
|
+
let n = e.clientX - t.startX;
|
|
169
|
+
if (!t.moved) {
|
|
170
|
+
G("idle"), U(0), $();
|
|
171
|
+
let e = I.current[M.current];
|
|
172
|
+
e && N.current?.(M.current, e);
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
175
|
+
if (Math.abs(n) >= S && K > 1) {
|
|
176
|
+
X(n > 0 ? 1 : -1);
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
Z();
|
|
180
|
+
}, [
|
|
181
|
+
X,
|
|
182
|
+
K,
|
|
183
|
+
W,
|
|
184
|
+
S,
|
|
185
|
+
Z,
|
|
186
|
+
$
|
|
187
|
+
]), oe = e((e) => {
|
|
188
|
+
let t = j.current;
|
|
189
|
+
!t || t.pointerId !== e.pointerId || (j.current = null, e.currentTarget.hasPointerCapture(e.pointerId) && e.currentTarget.releasePointerCapture(e.pointerId), W !== "exiting" && Z());
|
|
190
|
+
}, [W, Z]);
|
|
191
|
+
t(() => {
|
|
192
|
+
let e = A.current;
|
|
193
|
+
if (!e) return;
|
|
194
|
+
let t = (e) => {
|
|
195
|
+
e.key === "ArrowRight" ? (e.preventDefault(), Q(1)) : e.key === "ArrowLeft" ? (e.preventDefault(), Q(-1)) : (e.key === " " || e.key === "Enter") && (e.preventDefault(), $());
|
|
196
|
+
};
|
|
197
|
+
return e.addEventListener("keydown", t), () => e.removeEventListener("keydown", t);
|
|
198
|
+
}, [Q, $]);
|
|
199
|
+
let se = `translateX(${H}px)`, ce = W === "snapping" || W === "exiting" ? `transform ${W === "exiting" ? u : d}ms cubic-bezier(0.22, 1, 0.36, 1), opacity ${u}ms ease` : "none", le = [c.postcard, ee].filter(Boolean).join(" "), ue = [
|
|
200
|
+
c.cardActive,
|
|
201
|
+
B ? c.flipped : "",
|
|
202
|
+
W === "exiting" ? c.cardExiting : ""
|
|
203
|
+
].filter(Boolean).join(" ");
|
|
204
|
+
return /* @__PURE__ */ o("div", {
|
|
205
|
+
ref: A,
|
|
206
|
+
className: le,
|
|
207
|
+
style: {
|
|
208
|
+
width: f(v),
|
|
209
|
+
height: f(y),
|
|
210
|
+
...te
|
|
211
|
+
},
|
|
212
|
+
role: "region",
|
|
213
|
+
"aria-label": k,
|
|
214
|
+
tabIndex: 0,
|
|
215
|
+
children: /* @__PURE__ */ o("div", {
|
|
216
|
+
className: c.stage,
|
|
217
|
+
children: K === 0 ? /* @__PURE__ */ o("div", {
|
|
218
|
+
className: c.empty,
|
|
219
|
+
children: "暂无明信片"
|
|
220
|
+
}) : /* @__PURE__ */ s(a, { children: [/* @__PURE__ */ s("div", {
|
|
221
|
+
className: c.stack,
|
|
222
|
+
style: {
|
|
223
|
+
width: b,
|
|
224
|
+
height: x
|
|
225
|
+
},
|
|
226
|
+
children: [ne.map(({ depth: e, rot: t, dx: n, dy: r }) => /* @__PURE__ */ o("div", {
|
|
227
|
+
className: c.stackCard,
|
|
228
|
+
style: {
|
|
229
|
+
width: b,
|
|
230
|
+
height: x,
|
|
231
|
+
transform: `translate(calc(-50% + ${n}px), calc(-50% + ${r}px)) rotate(${t}deg)`,
|
|
232
|
+
opacity: e === 1 ? .92 : .78
|
|
233
|
+
},
|
|
234
|
+
"aria-hidden": "true"
|
|
235
|
+
}, e)), /* @__PURE__ */ o("div", {
|
|
236
|
+
className: c.cardSlot,
|
|
237
|
+
style: {
|
|
238
|
+
width: b,
|
|
239
|
+
height: x
|
|
240
|
+
},
|
|
241
|
+
children: /* @__PURE__ */ o("div", {
|
|
242
|
+
className: ue,
|
|
243
|
+
style: {
|
|
244
|
+
width: b,
|
|
245
|
+
height: x,
|
|
246
|
+
transform: se,
|
|
247
|
+
transition: ce,
|
|
248
|
+
opacity: W === "exiting" ? .55 : 1
|
|
249
|
+
},
|
|
250
|
+
onPointerDown: re,
|
|
251
|
+
onPointerMove: ie,
|
|
252
|
+
onPointerUp: ae,
|
|
253
|
+
onPointerCancel: oe,
|
|
254
|
+
role: "button",
|
|
255
|
+
"aria-label": q ? `${B ? "背面" : "正面"}:${q.alt ?? q.title ?? `明信片 ${R + 1}`}` : void 0,
|
|
256
|
+
"aria-pressed": B,
|
|
257
|
+
children: q ? /* @__PURE__ */ o("div", {
|
|
258
|
+
className: c.flipInner,
|
|
259
|
+
children: /* @__PURE__ */ o(g, {
|
|
260
|
+
photo: q,
|
|
261
|
+
showCaption: C
|
|
262
|
+
})
|
|
263
|
+
}) : null
|
|
264
|
+
})
|
|
265
|
+
})]
|
|
266
|
+
}), K > 1 ? /* @__PURE__ */ o("div", {
|
|
267
|
+
className: c.hint,
|
|
268
|
+
children: "拖拽切换 · 点击查看背面"
|
|
269
|
+
}) : null] })
|
|
270
|
+
})
|
|
271
|
+
});
|
|
272
|
+
};
|
|
273
|
+
//#endregion
|
|
274
|
+
export { _ as PhotoPostcard, _ as default };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { default as React } from 'react';
|
|
2
|
+
import { PhotoPostcardProps } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* 旅行明信片堆叠:单张特色明信片可 3D 翻转,水平拖拽切换上一张/下一张。
|
|
5
|
+
*/
|
|
6
|
+
declare const PhotoPostcard: React.FC<PhotoPostcardProps>;
|
|
7
|
+
export default PhotoPostcard;
|
|
8
|
+
export type { PhotoPostcardItem, PhotoPostcardProps } from './types';
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { CSSProperties } from 'react';
|
|
2
|
+
/** 单张旅行明信片数据 */
|
|
3
|
+
export interface PhotoPostcardItem {
|
|
4
|
+
/** 图片地址 */
|
|
5
|
+
src: string;
|
|
6
|
+
/** 图片替代文本 */
|
|
7
|
+
alt?: string;
|
|
8
|
+
/** 明信片标题(背面问候语 / 正面说明标题) */
|
|
9
|
+
title?: string;
|
|
10
|
+
/** 明信片正文(背面书写区 / 正面说明) */
|
|
11
|
+
description?: string;
|
|
12
|
+
}
|
|
13
|
+
/** PhotoPostcard 组件属性 */
|
|
14
|
+
export interface PhotoPostcardProps {
|
|
15
|
+
/** 明信片照片列表 */
|
|
16
|
+
photos: PhotoPostcardItem[];
|
|
17
|
+
/** 组件宽度 */
|
|
18
|
+
width?: number | string;
|
|
19
|
+
/** 组件高度 */
|
|
20
|
+
height?: number | string;
|
|
21
|
+
/** 单张明信片宽度(px) */
|
|
22
|
+
cardWidth?: number;
|
|
23
|
+
/** 单张明信片高度(px) */
|
|
24
|
+
cardHeight?: number;
|
|
25
|
+
/** 水平拖拽切换阈值(px) */
|
|
26
|
+
pullThreshold?: number;
|
|
27
|
+
/** 是否在正面底部显示标题与说明 */
|
|
28
|
+
showCaption?: boolean;
|
|
29
|
+
/** 初始展示索引 */
|
|
30
|
+
initialIndex?: number;
|
|
31
|
+
/** 初始是否背面朝上 */
|
|
32
|
+
initialFlipped?: boolean;
|
|
33
|
+
/** 点击当前明信片(几乎无位移时触发) */
|
|
34
|
+
onPhotoClick?: (index: number, photo: PhotoPostcardItem) => void;
|
|
35
|
+
/** 当前索引变化回调 */
|
|
36
|
+
onIndexChange?: (index: number, photo: PhotoPostcardItem) => void;
|
|
37
|
+
/** 正反面翻转状态变化回调 */
|
|
38
|
+
onFlipChange?: (flipped: boolean) => void;
|
|
39
|
+
/** 无障碍名称 */
|
|
40
|
+
ariaLabel?: string;
|
|
41
|
+
/** 自定义类名 */
|
|
42
|
+
className?: string;
|
|
43
|
+
/** 自定义样式 */
|
|
44
|
+
style?: CSSProperties;
|
|
45
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/// <reference types="vite/client" />
|
|
2
|
+
|
|
3
|
+
declare module '*.module.less' {
|
|
4
|
+
const classes: { readonly [key: string]: string };
|
|
5
|
+
export default classes;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
declare module '*.less' {
|
|
9
|
+
const classes: { readonly [key: string]: string };
|
|
10
|
+
export default classes;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
declare module '*.png' {
|
|
14
|
+
const src: string;
|
|
15
|
+
export default src;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
declare module '*.jpg' {
|
|
19
|
+
const src: string;
|
|
20
|
+
export default src;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
declare module '*.mp4' {
|
|
24
|
+
const src: string;
|
|
25
|
+
export default src;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
declare module '*.mp3' {
|
|
29
|
+
const src: string;
|
|
30
|
+
export default src;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
declare module '*.svg' {
|
|
34
|
+
import type { FC, SVGProps } from 'react';
|
|
35
|
+
|
|
36
|
+
export const ReactComponent: FC<SVGProps<SVGSVGElement>>;
|
|
37
|
+
const src: string;
|
|
38
|
+
export default src;
|
|
39
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@cos-design/photo-postcard",
|
|
3
|
+
"version": "3.7.3",
|
|
4
|
+
"description": "PhotoPostcard component from cos-design",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.cjs",
|
|
7
|
+
"module": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"import": {
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"default": "./dist/index.js"
|
|
14
|
+
},
|
|
15
|
+
"require": {
|
|
16
|
+
"types": "./dist/index.d.ts",
|
|
17
|
+
"default": "./dist/index.cjs"
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"files": [
|
|
22
|
+
"dist",
|
|
23
|
+
"LICENSE"
|
|
24
|
+
],
|
|
25
|
+
"sideEffects": [
|
|
26
|
+
"**/*.css",
|
|
27
|
+
"**/*.less"
|
|
28
|
+
],
|
|
29
|
+
"keywords": [
|
|
30
|
+
"cos-design",
|
|
31
|
+
"react",
|
|
32
|
+
"photoPostcard",
|
|
33
|
+
"PhotoPostcard"
|
|
34
|
+
],
|
|
35
|
+
"homepage": "https://jiaxiantao.github.io/cos-design/",
|
|
36
|
+
"bugs": {
|
|
37
|
+
"url": "https://github.com/jiaxiantao/cos-design/issues"
|
|
38
|
+
},
|
|
39
|
+
"repository": {
|
|
40
|
+
"type": "git",
|
|
41
|
+
"url": "git+https://github.com/jiaxiantao/cos-design.git",
|
|
42
|
+
"directory": "packages/photoPostcard"
|
|
43
|
+
},
|
|
44
|
+
"author": "jiaxiantao <jiaxiantao@souche.com>",
|
|
45
|
+
"license": "MIT",
|
|
46
|
+
"peerDependencies": {
|
|
47
|
+
"react": ">=18.0.0",
|
|
48
|
+
"react-dom": ">=18.0.0"
|
|
49
|
+
},
|
|
50
|
+
"publishConfig": {
|
|
51
|
+
"access": "public",
|
|
52
|
+
"registry": "https://registry.npmjs.org"
|
|
53
|
+
}
|
|
54
|
+
}
|