@travel-match/ui 0.2.0 → 0.4.0
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/dist/components/CtaSentence/CtaSentence.cjs +1 -1
- package/dist/components/CtaSentence/CtaSentence.cjs.map +1 -1
- package/dist/components/CtaSentence/CtaSentence.js +142 -69
- package/dist/components/CtaSentence/CtaSentence.js.map +1 -1
- package/dist/components/HeroColumns/heroMotion.cjs +1 -1
- package/dist/components/HeroColumns/heroMotion.cjs.map +1 -1
- package/dist/components/HeroColumns/heroMotion.js +7 -44
- package/dist/components/HeroColumns/heroMotion.js.map +1 -1
- package/dist/components/HeroMap/HeroMap.cjs +1 -1
- package/dist/components/HeroMap/HeroMap.cjs.map +1 -1
- package/dist/components/HeroMap/HeroMap.js +58 -67
- package/dist/components/HeroMap/HeroMap.js.map +1 -1
- package/dist/components/HeroSwitcher/HeroSwitcher.cjs +1 -1
- package/dist/components/HeroSwitcher/HeroSwitcher.cjs.map +1 -1
- package/dist/components/HeroSwitcher/HeroSwitcher.js +85 -92
- package/dist/components/HeroSwitcher/HeroSwitcher.js.map +1 -1
- package/dist/components/HowItWorksSteps/HowItWorksSteps.cjs +1 -1
- package/dist/components/HowItWorksSteps/HowItWorksSteps.cjs.map +1 -1
- package/dist/components/HowItWorksSteps/HowItWorksSteps.js +84 -102
- package/dist/components/HowItWorksSteps/HowItWorksSteps.js.map +1 -1
- package/dist/components/LogoAnimation/LogoAnimation.cjs +2 -0
- package/dist/components/LogoAnimation/LogoAnimation.cjs.map +1 -0
- package/dist/components/LogoAnimation/LogoAnimation.js +202 -0
- package/dist/components/LogoAnimation/LogoAnimation.js.map +1 -0
- package/dist/components/LogoAnimation/LogoAnimationArtwork.cjs +2 -0
- package/dist/components/LogoAnimation/LogoAnimationArtwork.cjs.map +1 -0
- package/dist/components/LogoAnimation/LogoAnimationArtwork.js +57 -0
- package/dist/components/LogoAnimation/LogoAnimationArtwork.js.map +1 -0
- package/dist/components/LogoAnimation/motion.cjs +2 -0
- package/dist/components/LogoAnimation/motion.cjs.map +1 -0
- package/dist/components/LogoAnimation/motion.js +180 -0
- package/dist/components/LogoAnimation/motion.js.map +1 -0
- package/dist/components/PackageAnimation/PackageAnimation.cjs +1 -1
- package/dist/components/PackageAnimation/PackageAnimation.cjs.map +1 -1
- package/dist/components/PackageAnimation/PackageAnimation.js +31 -40
- package/dist/components/PackageAnimation/PackageAnimation.js.map +1 -1
- package/dist/components/PartnerCarousel/PartnerCarousel.cjs +1 -1
- package/dist/components/PartnerCarousel/PartnerCarousel.cjs.map +1 -1
- package/dist/components/PartnerCarousel/PartnerCarousel.js +94 -101
- package/dist/components/PartnerCarousel/PartnerCarousel.js.map +1 -1
- package/dist/components/PartnerCarousel/autoplay.cjs +1 -1
- package/dist/components/PartnerCarousel/autoplay.cjs.map +1 -1
- package/dist/components/PartnerCarousel/autoplay.js +13 -9
- package/dist/components/PartnerCarousel/autoplay.js.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +62 -55
- package/dist/index.d.ts +62 -55
- package/dist/index.js +100 -99
- package/dist/styles.css +1 -1
- package/package.json +1 -1
- package/dist/components/PartnerCarousel/AutoplayToggle.cjs +0 -2
- package/dist/components/PartnerCarousel/AutoplayToggle.cjs.map +0 -1
- package/dist/components/PartnerCarousel/AutoplayToggle.js +0 -36
- package/dist/components/PartnerCarousel/AutoplayToggle.js.map +0 -1
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use client";const e=require("../../icons/generated/DownArrowIcon.cjs"),t=require("../../utils/cn.cjs"),n=require("../
|
|
1
|
+
"use client";const e=require("../../icons/generated/DownArrowIcon.cjs"),t=require("../../utils/cn.cjs"),n=require("../PartnerCarousel/autoplay.cjs");;/* empty css */let r=require("react"),i=require("react/jsx-runtime");var a=500,o=90,s=e=>(0,r.isValidElement)(e)?e.type:e,c=(e,t)=>e.value===t.value&&s(e.icon)===s(t.icon);function l(e){let t=e[0];if(!t)return null;let n=[],r=0;for(let i=0;i<t.parts.length;i++){let a=[];for(let n of e){let e=n.parts[i];if(n.parts.length!==t.parts.length||e===void 0||typeof e!=typeof t.parts[i])return null;a.push(e)}if(typeof a[0]==`string`){let e=a,t=[...new Set(e)];n.push(t.length===1?{kind:`word`,text:t[0]}:{kind:`words`,options:t,byExample:e.map(e=>t.indexOf(e))})}else{let e=a,t=[],i=e.map(e=>{let n=t.findIndex(t=>c(t,e));return n>=0?n:(t.push(e),t.length-1)}),o=e.every(t=>s(t.icon)===s(e[0].icon));n.push({kind:`pill`,key:e[0].key,options:t,byExample:i,sharedIcon:o,order:r++})}}return n}function u({className:e,active:n,leaving:r,order:a,children:o}){return(0,i.jsx)(`span`,{className:t.cn(`tm-cta-sentence__roller`,e),style:{"--_order":a},children:o.map((e,t)=>(0,i.jsx)(`span`,{className:`tm-cta-sentence__option`,"data-state":t===n?`active`:t===r?`leaving`:`idle`,"aria-hidden":t!==n||void 0,children:e},t))})}var d=(0,r.forwardRef)(function({examples:s,value:c,defaultValue:d=0,onValueChange:f,autoPlay:p=!0,interval:m=2600,paused:h=!1,onPillClick:g,className:_,...v},y){let b=s.length,x=(0,r.useRef)(null),[S,C]=n.useIndexState(c,d,f,b),[w,T]=(0,r.useState)({current:S,previous:null});w.current!==S&&T({current:S,previous:w.current});let E=w.current===S?w.previous:w.current,D=l(s),O=D?D.filter(e=>e.kind===`pill`).length:0,{running:k,interactionProps:A}=n.useAutoplay({enabled:p&&b>1,paused:h,delay:m+a+Math.max(0,O-1)*o,onTick:()=>C((S+1)%b),rootRef:x,resetKey:S}),{onPointerEnter:j,onPointerLeave:M,onFocus:N,onBlur:P}=A,F=(e,t,n,r,a)=>g?(0,i.jsx)(`button`,{type:`button`,className:`tm-cta-sentence__pill`,"data-tm-icon-size":`lg`,tabIndex:r?-1:void 0,onClick:()=>g(t,n),children:a},e):(0,i.jsx)(`span`,{className:`tm-cta-sentence__pill`,"data-tm-icon-size":`lg`,children:a},e);return(0,i.jsx)(`div`,{ref:e=>{x.current=e,typeof y==`function`?y(e):y&&(y.current=e)},className:t.cn(`tm-cta-sentence`,_),"data-autoplay":k?`running`:p?`paused`:void 0,...v,onPointerEnter:e=>{v.onPointerEnter?.(e),j(e)},onPointerLeave:e=>{v.onPointerLeave?.(e),M()},onFocus:e=>{v.onFocus?.(e),N(e)},onBlur:e=>{v.onBlur?.(e),P(e)},children:(0,i.jsx)(`div`,{className:`tm-cta-sentence__stage`,"aria-live":k?`off`:`polite`,children:D?(0,i.jsx)(`p`,{className:`tm-cta-sentence__example`,"data-active":``,"data-padded":s[0]?.padded?``:void 0,children:D.map((t,n)=>{if(t.kind===`word`)return(0,i.jsx)(`span`,{className:`tm-cta-sentence__word`,children:t.text},n);let r=t.byExample[S]??0,a=E===null?null:t.byExample[E]??null,o=a===r?null:a;return t.kind===`words`?(0,i.jsx)(u,{className:`tm-cta-sentence__word`,active:r,leaving:o,order:0,children:t.options},n):F(t.key??n,S,n,!1,(0,i.jsxs)(i.Fragment,{children:[t.sharedIcon?t.options[0].icon:null,(0,i.jsx)(u,{className:`tm-cta-sentence__value`,active:r,leaving:o,order:t.order,children:t.options.map((e,n)=>(0,i.jsxs)(`span`,{className:`tm-cta-sentence__choice`,children:[t.sharedIcon?null:e.icon,(0,i.jsx)(`span`,{className:`tm-cta-sentence__text`,children:e.value})]},n))}),(0,i.jsx)(e.DownArrowIcon,{"aria-hidden":`true`})]}))})}):s.map((t,n)=>{let r=n===S;return(0,i.jsx)(`p`,{className:`tm-cta-sentence__example`,"data-swap":``,"data-active":r?``:void 0,"data-padded":t.padded?``:void 0,"aria-hidden":!r||void 0,children:t.parts.map((t,a)=>typeof t==`string`?(0,i.jsx)(`span`,{className:`tm-cta-sentence__word`,children:t},a):F(t.key??a,n,a,!r,(0,i.jsxs)(i.Fragment,{children:[t.icon,(0,i.jsx)(`span`,{className:`tm-cta-sentence__value`,children:t.value}),(0,i.jsx)(e.DownArrowIcon,{"aria-hidden":`true`})]})))},t.key??n)})})})});exports.CtaSentence=d;
|
|
2
2
|
//# sourceMappingURL=CtaSentence.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CtaSentence.cjs","names":["useRef","useIndexState","useAutoplay","cn","_Fragment","DownArrowIcon","Pagination","AutoplayToggle","require_DownArrowIcon","require_cn","require_Pagination","require_AutoplayToggle","require_autoplay","react","react_jsx_runtime","SWAP_DURATION","defaultPageLabel","page","pageCount","CtaSentence","props","count","examples","rootRef","index","setIndex","value","defaultValue","onValueChange","autoPlay","interval","interactionProps","node","ref","className","running","event","onPointerEnter","onPointerLeave","onFocus","onBlur","active","exampleIndex","example","part","partIndex","content","onPillClick","controls","paginationLabel","userPaused","toggle"],"sources":["../../../src/components/CtaSentence/CtaSentence.tsx"],"sourcesContent":["import { forwardRef, useRef, type HTMLAttributes, type ReactNode } from 'react';\nimport { DownArrowIcon } from '../../icons';\nimport { cn } from '../../utils/cn';\nimport { Pagination } from '../Pagination';\nimport { AutoplayToggle } from '../PartnerCarousel/AutoplayToggle';\nimport { useAutoplay, useIndexState } from '../PartnerCarousel/autoplay';\nimport './CtaSentence.css';\n\n/** Figma prototype: Smart animate, ease in and out, 500ms. Keep in sync with `--_duration` in the stylesheet. */\nconst SWAP_DURATION = 500;\n\n/** A value of the sentence, drawn as a pill (Figma \"Pill / Type\", \"Pill / Destination\", …). */\nexport interface CtaSentencePill {\n /** React key; defaults to the position in the sentence. */\n key?: string;\n /** One icon from `@travel-match/ui` (e.g. `<MapPinIcon />`). */\n icon?: ReactNode;\n /** The value, e.g. \"Rome\". */\n value: ReactNode;\n}\n\n/** One part of a sentence: plain words (a string) or a pill. */\nexport type CtaSentencePart = string | CtaSentencePill;\n\n/** One example sentence — Figma \"Example\". */\nexport interface CtaSentenceExample {\n /** React key; defaults to the position in the list. */\n key?: string;\n /** Words and pills in reading order, e.g. `[\"I’d like\", { value: \"a Flight\" }, \"to\", { value: \"Paris\" }]`. */\n parts: CtaSentencePart[];\n /** Insets the sentence by `spacing/3xl` on both sides so its lines break evenly (Figma does this on Example 2). */\n padded?: boolean;\n}\n\nexport interface CtaSentenceProps extends Omit<HTMLAttributes<HTMLDivElement>, 'onChange' | 'defaultValue'> {\n /** The example sentences the component cycles through. Any number. */\n examples: CtaSentenceExample[];\n /** Index (0-based) of the example shown — Figma \"Example\". Makes the component controlled. */\n value?: number;\n /** Example shown first when uncontrolled. */\n defaultValue?: number;\n /** Called with the new index when the example changes (autoplay or dots). */\n onValueChange?: (value: number) => void;\n /** Cycles through the examples by itself. Stops for hover, focus, a hidden tab, an off-screen sentence and reduced motion. */\n autoPlay?: boolean;\n /** Time an example rests before the next one, in ms (Figma: 2600). */\n interval?: number;\n /** Holds the autoplay (the pause control stays available). */\n paused?: boolean;\n /** Shows the dots that pick an example and, with `autoPlay`, the pause / play button. */\n controls?: boolean;\n /** Makes the pills buttons and is called with the example and part index of the pressed one, e.g. to open the request form. */\n onPillClick?: (exampleIndex: number, partIndex: number) => void;\n /** Accessible name of a dot — translate it. */\n getPageLabel?: (page: number, pageCount: number) => string;\n /** Name of the dots navigation — translate it. */\n paginationLabel?: string;\n /** Name of the pause button — translate it. */\n pauseLabel?: string;\n /** Name of the play button — translate it. */\n playLabel?: string;\n}\n\nconst defaultPageLabel = (page: number, pageCount: number) => `Example ${page} of ${pageCount}`;\n\n/**\n * A request written as a sentence whose values are pills, cycling through examples\n * (Figma component set \"How it works / CTA sentence\"). Every example is real text; the one on show is the only one\n * exposed to assistive technology, and the dots reach the others.\n */\nexport const CtaSentence = /* @__PURE__ */ forwardRef<HTMLDivElement, CtaSentenceProps>(function CtaSentence(\n {\n examples,\n value,\n defaultValue = 0,\n onValueChange,\n autoPlay = true,\n interval = 2600,\n paused = false,\n controls = true,\n onPillClick,\n getPageLabel = defaultPageLabel,\n paginationLabel = 'Examples',\n pauseLabel = 'Pause the examples',\n playLabel = 'Play the examples',\n className,\n ...props\n },\n ref,\n) {\n const count = examples.length;\n const rootRef = useRef<HTMLDivElement | null>(null);\n const [index, setIndex] = useIndexState(value, defaultValue, onValueChange, count);\n\n const { running, userPaused, toggle, interactionProps } = useAutoplay({\n enabled: autoPlay && count > 1,\n paused,\n delay: interval + SWAP_DURATION,\n onTick: () => setIndex((index + 1) % count),\n rootRef,\n resetKey: index,\n });\n const { onPointerEnter, onPointerLeave, onFocus, onBlur } = interactionProps;\n\n return (\n <div\n ref={(node) => {\n rootRef.current = node;\n if (typeof ref === 'function') ref(node);\n else if (ref) ref.current = node;\n }}\n className={cn('tm-cta-sentence', className)}\n data-autoplay={running ? 'running' : autoPlay ? 'paused' : undefined}\n {...props}\n onPointerEnter={(event) => {\n props.onPointerEnter?.(event);\n onPointerEnter(event);\n }}\n onPointerLeave={(event) => {\n props.onPointerLeave?.(event);\n onPointerLeave();\n }}\n onFocus={(event) => {\n props.onFocus?.(event);\n onFocus();\n }}\n onBlur={(event) => {\n props.onBlur?.(event);\n onBlur(event);\n }}\n >\n {/* All examples share one grid cell, so the block is as tall as the tallest and never shifts the page. */}\n <div className=\"tm-cta-sentence__stage\" aria-live={running ? 'off' : 'polite'}>\n {examples.map((example, exampleIndex) => {\n const active = exampleIndex === index;\n return (\n <p\n key={example.key ?? exampleIndex}\n className=\"tm-cta-sentence__example\"\n data-active={active ? '' : undefined}\n data-padded={example.padded ? '' : undefined}\n aria-hidden={active ? undefined : true}\n >\n {example.parts.map((part, partIndex) => {\n if (typeof part === 'string') {\n return (\n <span key={partIndex} className=\"tm-cta-sentence__word\">\n {part}\n </span>\n );\n }\n const content = (\n <>\n {part.icon}\n <span className=\"tm-cta-sentence__value\">{part.value}</span>\n <DownArrowIcon aria-hidden=\"true\" />\n </>\n );\n return onPillClick ? (\n <button\n key={part.key ?? partIndex}\n type=\"button\"\n className=\"tm-cta-sentence__pill\"\n data-tm-icon-size=\"lg\"\n // The examples that are not on show are hidden (visibility), which also takes them out of the tab order.\n tabIndex={active ? undefined : -1}\n onClick={() => onPillClick(exampleIndex, partIndex)}\n >\n {content}\n </button>\n ) : (\n <span key={part.key ?? partIndex} className=\"tm-cta-sentence__pill\" data-tm-icon-size=\"lg\">\n {content}\n </span>\n );\n })}\n </p>\n );\n })}\n </div>\n\n {controls && count > 1 ? (\n <div className=\"tm-cta-sentence__controls\">\n <Pagination page={index + 1} pageCount={count} onPageChange={(page) => setIndex(page - 1)} getPageLabel={getPageLabel} aria-label={paginationLabel} />\n {autoPlay ? <AutoplayToggle className=\"tm-cta-sentence__toggle\" paused={userPaused} pauseLabel={pauseLabel} playLabel={playLabel} onClick={toggle} /> : null}\n </div>\n ) : null}\n </div>\n );\n});\n"],"mappings":"A,yUASA,IAAMe,EAAgB,IAsDhBC,GAAoB,EAAc,IAAsB,WAAWC,EAAK,MAAMC,IAOvEC,GAA8B,EAAAN,EAAA,WAAA,CAA6C,SACtF,CACE,WACA,QACA,eAAe,EACf,gBACA,WAAW,GACX,WAAW,KACX,SAAS,GACT,WAAW,GACX,cACA,eAAeG,EACf,kBAAkB,WAClB,aAAa,qBACb,YAAY,oBACZ,YACA,GAAGI,GAEL,EACA,CACA,IAAMC,EAAQC,EAAS,OACjBC,GAAA,EAAUvB,EAAAA,OAAAA,CAA8B,IAAI,EAC5C,CAACwB,EAAOC,GAAYxB,EAAAA,cAAcyB,EAAOC,EAAcC,EAAeP,CAAK,EAE3E,CAAE,UAAS,aAAY,SAAQ,oBAAqBnB,EAAAA,YAAY,CACpE,QAAS2B,GAAYR,EAAQ,EAC7B,SACA,MAAOS,EAAWf,EAClB,WAAcU,GAAUD,EAAQ,GAAKH,CAAK,EAC1C,UACA,SAAUG,CACZ,CAAC,EACK,CAAE,iBAAgB,iBAAgB,UAAS,UAAWO,EAE5D,OACE,EAAAjB,EAAA,KAAA,CAAC,MAAD,CACE,IAAM,GAAS,CACb,EAAQ,QAAUkB,EACd,OAAOC,GAAQ,WAAYA,EAAID,CAAI,EAC9BC,IAAK,EAAI,QAAUD,EAC9B,EACA,UAAW7B,EAAAA,GAAG,kBAAmB+B,CAAS,EAC1C,gBAAeC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AAC,CACK,EATDF,EAAK,KAAOC,CASX,GAER,EAAA/B,EAAA,IAAA,CAAC,OAAD,CAAkC,UAAU,wBAAwB,oBAAkB,KACnF,SAAAgC,CACG,EAFKF,EAAK,KAAOC,CAEjB,CAEV,CAAC,CACA,EAvCIF,EAAQ,KAAOD,CAuCnB,CAEP,CAAC,CACE,CAAA,EAEJM,GAAY3B,EAAQ,GACnB,EAAAP,EAAA,KAAA,CAAC,MAAD,CAAK,UAAU,4BAAf,SAAA,EACE,EAAAA,EAAA,IAAA,CAACR,EAAAA,WAAD,CAAY,KAAMkB,EAAQ,EAAG,UAAWH,EAAO,aAAe,GAASI,EAASR,EAAO,CAAC,EAAiB,eAAc,aAAYgC,CAAkB,CAAA,EACpJpB,GAAW,EAAAf,EAAA,IAAA,CAACP,EAAAA,eAAD,CAAgB,UAAU,0BAA0B,OAAQ2C,EAAwB,aAAuB,YAAW,QAASC,CAAS,CAAA,EAAI,IACrJ,CACH,CAAA,EAAA,IACD,C,EAET,CAAC,E"}
|
|
1
|
+
{"version":3,"file":"CtaSentence.cjs","names":["isValidElement","cn","useRef","useIndexState","useState","useAutoplay","_Fragment","DownArrowIcon","require_DownArrowIcon","require_cn","require_autoplay","react","react_jsx_runtime","SWAP_DURATION","STAGGER","iconType","icon","samePill","a","b","alignExamples","first","examples","slots","pills","position","variants","example","part","words","options","word","all","byExample","known","option","pill","sharedIcon","Roller","className","order","children","active","leaving","child","CtaSentence","props","count","rootRef","index","setIndex","value","defaultValue","onValueChange","trail","setTrail","previous","pillCount","slot","autoPlay","interval","interactionProps","onPillClick","hidden","exampleIndex","partIndex","content","key","node","ref","running","event","onPointerEnter","onPointerLeave","onFocus","onBlur","before","optionIndex"],"sources":["../../../src/components/CtaSentence/CtaSentence.tsx"],"sourcesContent":["import { forwardRef, isValidElement, useRef, useState, type CSSProperties, type HTMLAttributes, type ReactNode } from 'react';\nimport { DownArrowIcon } from '../../icons';\nimport { cn } from '../../utils/cn';\nimport { useAutoplay, useIndexState } from '../PartnerCarousel/autoplay';\nimport './CtaSentence.css';\n\n/** Figma prototype: Smart animate, ease in and out, 500ms. Keep in sync with `--_duration` in the stylesheet. */\nconst SWAP_DURATION = 500;\n/** The pills change one after another, this many ms apart. Keep in sync with `--_stagger` in the stylesheet. */\nconst STAGGER = 90;\n\n/** A value of the sentence, drawn as a pill (Figma \"Pill / Type\", \"Pill / Destination\", …). */\nexport interface CtaSentencePill {\n /** React key; defaults to the position in the sentence. */\n key?: string;\n /** One icon from `@travel-match/ui` (e.g. `<MapPinIcon />`). */\n icon?: ReactNode;\n /** The value, e.g. \"Rome\". */\n value: ReactNode;\n}\n\n/** One part of a sentence: plain words (a string) or a pill. */\nexport type CtaSentencePart = string | CtaSentencePill;\n\n/** One example sentence — Figma \"Example\". */\nexport interface CtaSentenceExample {\n /** React key; defaults to the position in the list. */\n key?: string;\n /** Words and pills in reading order, e.g. `[\"I’d like\", { value: \"a Flight\" }, \"to\", { value: \"Paris\" }]`. */\n parts: CtaSentencePart[];\n /**\n * Insets the sentence by `spacing/3xl` on both sides so its lines break evenly. When the examples share one sentence\n * (see `CtaSentence`), the first example decides for all of them.\n */\n padded?: boolean;\n}\n\nexport interface CtaSentenceProps extends Omit<HTMLAttributes<HTMLDivElement>, 'onChange' | 'defaultValue'> {\n /** The example requests the sentence cycles through. Any number. */\n examples: CtaSentenceExample[];\n /** Index (0-based) of the example shown — Figma \"Example\". Makes the component controlled. */\n value?: number;\n /** Example shown first when uncontrolled. */\n defaultValue?: number;\n /** Called with the new index each time the sentence moves on to the next example. */\n onValueChange?: (value: number) => void;\n /** Cycles through the examples by itself, endlessly. Holds for hover, focus, a hidden tab, an off-screen sentence and reduced motion. */\n autoPlay?: boolean;\n /** Time an example rests before the next one, in ms (Figma: 2600). */\n interval?: number;\n /** Holds the autoplay. */\n paused?: boolean;\n /** Makes the pills buttons and is called with the example and part index of the pressed one, e.g. to open the request form. */\n onPillClick?: (exampleIndex: number, partIndex: number) => void;\n}\n\n/** What one position of the shared sentence shows across the examples. */\ntype Slot =\n | { kind: 'word'; text: string }\n /** `options`: the different contents, in order of first appearance; `byExample[i]` is the option example `i` shows. */\n | { kind: 'words'; options: string[]; byExample: number[] }\n | { kind: 'pill'; key?: string; options: CtaSentencePill[]; byExample: number[]; sharedIcon: boolean; order: number };\n\nconst iconType = (icon: ReactNode) => (isValidElement(icon) ? icon.type : icon);\nconst samePill = (a: CtaSentencePill, b: CtaSentencePill) => a.value === b.value && iconType(a.icon) === iconType(b.icon);\n\n/**\n * The examples as one sentence: for every position, what stays and what changes. Returns null when the examples are\n * not built the same way (a different number of parts, or a word where another has a pill).\n */\nfunction alignExamples(examples: CtaSentenceExample[]): Slot[] | null {\n const first = examples[0];\n if (!first) return null;\n const slots: Slot[] = [];\n let pills = 0;\n for (let position = 0; position < first.parts.length; position++) {\n const variants: CtaSentencePart[] = [];\n for (const example of examples) {\n const part = example.parts[position];\n if (example.parts.length !== first.parts.length || part === undefined || typeof part !== typeof first.parts[position]) return null;\n variants.push(part);\n }\n if (typeof variants[0] === 'string') {\n const words = variants as string[];\n const options = [...new Set(words)];\n slots.push(options.length === 1 ? { kind: 'word', text: options[0]! } : { kind: 'words', options, byExample: words.map((word) => options.indexOf(word)) });\n } else {\n const all = variants as CtaSentencePill[];\n const options: CtaSentencePill[] = [];\n const byExample = all.map((pill) => {\n const known = options.findIndex((option) => samePill(option, pill));\n if (known >= 0) return known;\n options.push(pill);\n return options.length - 1;\n });\n const sharedIcon = all.every((pill) => iconType(pill.icon) === iconType(all[0]!.icon));\n slots.push({ kind: 'pill', key: all[0]!.key, options, byExample, sharedIcon, order: pills++ });\n }\n }\n return slots;\n}\n\n/** The contents of one changing position, stacked in one cell: the one on show, the one rolling out, the rest waiting. */\nfunction Roller({ className, active, leaving, order, children }: { className: string; active: number; leaving: number | null; order: number; children: ReactNode[] }) {\n return (\n <span className={cn('tm-cta-sentence__roller', className)} style={{ '--_order': order } as CSSProperties}>\n {children.map((child, option) => (\n <span\n key={option}\n className=\"tm-cta-sentence__option\"\n data-state={option === active ? 'active' : option === leaving ? 'leaving' : 'idle'}\n aria-hidden={option === active ? undefined : true}\n >\n {child}\n </span>\n ))}\n </span>\n );\n}\n\n/**\n * A request written as one sentence whose values are pills that look like selects (Figma component set\n * \"How it works / CTA sentence\"). The sentence stays where it is; every few seconds the values in the pills roll over\n * to the next example, one pill after another, endlessly. Each pill is as wide as its longest value, so nothing around\n * it moves. Only the values on show are exposed to assistive technology.\n *\n * The examples are expected to be the same sentence with different values (the same words and pills in the same\n * order). Examples built differently are shown one whole sentence at a time, fading from one to the next.\n */\nexport const CtaSentence = /* @__PURE__ */ forwardRef<HTMLDivElement, CtaSentenceProps>(function CtaSentence(\n { examples, value, defaultValue = 0, onValueChange, autoPlay = true, interval = 2600, paused = false, onPillClick, className, ...props },\n ref,\n) {\n const count = examples.length;\n const rootRef = useRef<HTMLDivElement | null>(null);\n const [index, setIndex] = useIndexState(value, defaultValue, onValueChange, count);\n\n // The example that was on show just before: its values are the ones rolling out.\n const [trail, setTrail] = useState<{ current: number; previous: number | null }>({ current: index, previous: null });\n if (trail.current !== index) setTrail({ current: index, previous: trail.current });\n const previous = trail.current === index ? trail.previous : trail.current;\n\n const slots = alignExamples(examples);\n const pillCount = slots ? slots.filter((slot) => slot.kind === 'pill').length : 0;\n\n const { running, interactionProps } = useAutoplay({\n enabled: autoPlay && count > 1,\n paused,\n // An example rests for `interval` after its last pill has rolled in.\n delay: interval + SWAP_DURATION + Math.max(0, pillCount - 1) * STAGGER,\n onTick: () => setIndex((index + 1) % count),\n rootRef,\n resetKey: index,\n });\n const { onPointerEnter, onPointerLeave, onFocus, onBlur } = interactionProps;\n\n const pill = (key: string | number, exampleIndex: number, partIndex: number, hidden: boolean, content: ReactNode) =>\n onPillClick ? (\n <button\n key={key}\n type=\"button\"\n className=\"tm-cta-sentence__pill\"\n data-tm-icon-size=\"lg\"\n // A sentence that is not on show is hidden (visibility), which also takes it out of the tab order.\n tabIndex={hidden ? -1 : undefined}\n onClick={() => onPillClick(exampleIndex, partIndex)}\n >\n {content}\n </button>\n ) : (\n <span key={key} className=\"tm-cta-sentence__pill\" data-tm-icon-size=\"lg\">\n {content}\n </span>\n );\n\n return (\n <div\n ref={(node) => {\n rootRef.current = node;\n if (typeof ref === 'function') ref(node);\n else if (ref) ref.current = node;\n }}\n className={cn('tm-cta-sentence', className)}\n data-autoplay={running ? 'running' : autoPlay ? 'paused' : undefined}\n {...props}\n onPointerEnter={(event) => {\n props.onPointerEnter?.(event);\n onPointerEnter(event);\n }}\n onPointerLeave={(event) => {\n props.onPointerLeave?.(event);\n onPointerLeave();\n }}\n onFocus={(event) => {\n props.onFocus?.(event);\n // (With the event the hook holds only for keyboard focus, so the focus a click on a pill leaves does not freeze it.)\n onFocus(event);\n }}\n onBlur={(event) => {\n props.onBlur?.(event);\n onBlur(event);\n }}\n >\n <div className=\"tm-cta-sentence__stage\" aria-live={running ? 'off' : 'polite'}>\n {slots ? (\n // One sentence; only what differs between the examples rolls over.\n <p className=\"tm-cta-sentence__example\" data-active=\"\" data-padded={examples[0]?.padded ? '' : undefined}>\n {slots.map((slot, partIndex) => {\n if (slot.kind === 'word') {\n return (\n <span key={partIndex} className=\"tm-cta-sentence__word\">\n {slot.text}\n </span>\n );\n }\n const active = slot.byExample[index] ?? 0;\n const before = previous === null ? null : (slot.byExample[previous] ?? null);\n const leaving = before === active ? null : before;\n if (slot.kind === 'words') {\n return (\n <Roller key={partIndex} className=\"tm-cta-sentence__word\" active={active} leaving={leaving} order={0}>\n {slot.options}\n </Roller>\n );\n }\n return pill(\n slot.key ?? partIndex,\n index,\n partIndex,\n false,\n <>\n {slot.sharedIcon ? slot.options[0]!.icon : null}\n <Roller className=\"tm-cta-sentence__value\" active={active} leaving={leaving} order={slot.order}>\n {slot.options.map((option, optionIndex) => (\n <span key={optionIndex} className=\"tm-cta-sentence__choice\">\n {slot.sharedIcon ? null : option.icon}\n <span className=\"tm-cta-sentence__text\">{option.value}</span>\n </span>\n ))}\n </Roller>\n <DownArrowIcon aria-hidden=\"true\" />\n </>,\n );\n })}\n </p>\n ) : (\n // Examples that are not the same sentence: one whole sentence at a time, sharing one grid cell, so the block\n // is as tall as the tallest and never shifts the page.\n examples.map((example, exampleIndex) => {\n const active = exampleIndex === index;\n return (\n <p\n key={example.key ?? exampleIndex}\n className=\"tm-cta-sentence__example\"\n data-swap=\"\"\n data-active={active ? '' : undefined}\n data-padded={example.padded ? '' : undefined}\n aria-hidden={active ? undefined : true}\n >\n {example.parts.map((part, partIndex) =>\n typeof part === 'string' ? (\n <span key={partIndex} className=\"tm-cta-sentence__word\">\n {part}\n </span>\n ) : (\n pill(\n part.key ?? partIndex,\n exampleIndex,\n partIndex,\n !active,\n <>\n {part.icon}\n <span className=\"tm-cta-sentence__value\">{part.value}</span>\n <DownArrowIcon aria-hidden=\"true\" />\n </>,\n )\n ),\n )}\n </p>\n );\n })\n )}\n </div>\n </div>\n );\n});\n"],"mappings":"A,4OAOA,IAAMa,EAAgB,IAEhBC,EAAU,GAsDVC,EAAY,IAAA,EAAqBf,EAAAA,eAAAA,CAAegB,CAAI,EAAIA,EAAK,KAAOA,EACpEC,GAAY,EAAoB,IAAuBC,EAAE,QAAUC,EAAE,OAASJ,EAASG,EAAE,IAAI,IAAMH,EAASI,EAAE,IAAI,EAMxH,SAASC,EAAc,EAA+C,CACpE,IAAMC,EAAQC,EAAS,GACvB,GAAI,CAACD,EAAO,OAAO,KACnB,IAAME,EAAgB,CAAC,EACnBC,EAAQ,EACZ,IAAK,IAAIC,EAAW,EAAGA,EAAWJ,EAAM,MAAM,OAAQ,IAAY,CAChE,IAAMK,EAA8B,CAAC,EACrC,IAAK,IAAMC,KAAWL,EAAU,CAC9B,IAAMM,EAAOD,EAAQ,MAAMF,GAC3B,GAAIE,EAAQ,MAAM,SAAWN,EAAM,MAAM,QAAUO,IAAS,IAAA,IAAa,OAAOA,GAAS,OAAOP,EAAM,MAAMI,GAAW,OAAO,KAC9HC,EAAS,KA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,CACC,EA1BIoB,EAAQ,KAAOqC,CA0BnB,CAEP,CAAC,CAEA,CAAA,CACF,CAAA,CAET,CAAC,E"}
|
|
@@ -1,97 +1,170 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { DownArrowIcon as e } from "../../icons/generated/DownArrowIcon.js";
|
|
3
3
|
import { cn as t } from "../../utils/cn.js";
|
|
4
|
-
import {
|
|
5
|
-
import { AutoplayToggle as r } from "../PartnerCarousel/AutoplayToggle.js";
|
|
6
|
-
import { useAutoplay as i, useIndexState as a } from "../PartnerCarousel/autoplay.js";
|
|
4
|
+
import { useAutoplay as n, useIndexState as r } from "../PartnerCarousel/autoplay.js";
|
|
7
5
|
/* empty css */
|
|
8
|
-
import { forwardRef as
|
|
6
|
+
import { forwardRef as i, isValidElement as a, useRef as o, useState as s } from "react";
|
|
9
7
|
import { Fragment as c, jsx as l, jsxs as u } from "react/jsx-runtime";
|
|
10
8
|
// src/components/CtaSentence/CtaSentence.tsx
|
|
11
|
-
var d = 500, f =
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
9
|
+
var d = 500, f = 90, p = (e) => a(e) ? e.type : e, m = (e, t) => e.value === t.value && p(e.icon) === p(t.icon);
|
|
10
|
+
function h(e) {
|
|
11
|
+
let t = e[0];
|
|
12
|
+
if (!t) return null;
|
|
13
|
+
let n = [], r = 0;
|
|
14
|
+
for (let i = 0; i < t.parts.length; i++) {
|
|
15
|
+
let a = [];
|
|
16
|
+
for (let n of e) {
|
|
17
|
+
let e = n.parts[i];
|
|
18
|
+
if (n.parts.length !== t.parts.length || e === void 0 || typeof e != typeof t.parts[i]) return null;
|
|
19
|
+
a.push(e);
|
|
20
|
+
}
|
|
21
|
+
if (typeof a[0] == "string") {
|
|
22
|
+
let e = a, t = [...new Set(e)];
|
|
23
|
+
n.push(t.length === 1 ? {
|
|
24
|
+
kind: "word",
|
|
25
|
+
text: t[0]
|
|
26
|
+
} : {
|
|
27
|
+
kind: "words",
|
|
28
|
+
options: t,
|
|
29
|
+
byExample: e.map((e) => t.indexOf(e))
|
|
30
|
+
});
|
|
31
|
+
} else {
|
|
32
|
+
let e = a, t = [], i = e.map((e) => {
|
|
33
|
+
let n = t.findIndex((t) => m(t, e));
|
|
34
|
+
return n >= 0 ? n : (t.push(e), t.length - 1);
|
|
35
|
+
}), o = e.every((t) => p(t.icon) === p(e[0].icon));
|
|
36
|
+
n.push({
|
|
37
|
+
kind: "pill",
|
|
38
|
+
key: e[0].key,
|
|
39
|
+
options: t,
|
|
40
|
+
byExample: i,
|
|
41
|
+
sharedIcon: o,
|
|
42
|
+
order: r++
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return n;
|
|
47
|
+
}
|
|
48
|
+
function g({ className: e, active: n, leaving: r, order: i, children: a }) {
|
|
49
|
+
return /* @__PURE__ */ l("span", {
|
|
50
|
+
className: t("tm-cta-sentence__roller", e),
|
|
51
|
+
style: { "--_order": i },
|
|
52
|
+
children: a.map((e, t) => /* @__PURE__ */ l("span", {
|
|
53
|
+
className: "tm-cta-sentence__option",
|
|
54
|
+
"data-state": t === n ? "active" : t === r ? "leaving" : "idle",
|
|
55
|
+
"aria-hidden": t !== n || void 0,
|
|
56
|
+
children: e
|
|
57
|
+
}, t))
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
var _ = /* @__PURE__ */ i(function({ examples: i, value: a, defaultValue: p = 0, onValueChange: m, autoPlay: _ = !0, interval: v = 2600, paused: y = !1, onPillClick: b, className: x, ...S }, C) {
|
|
61
|
+
let w = i.length, T = o(null), [E, D] = r(a, p, m, w), [O, k] = s({
|
|
62
|
+
current: E,
|
|
63
|
+
previous: null
|
|
64
|
+
});
|
|
65
|
+
O.current !== E && k({
|
|
66
|
+
current: E,
|
|
67
|
+
previous: O.current
|
|
68
|
+
});
|
|
69
|
+
let A = O.current === E ? O.previous : O.current, j = h(i), M = j ? j.filter((e) => e.kind === "pill").length : 0, { running: N, interactionProps: P } = n({
|
|
70
|
+
enabled: _ && w > 1,
|
|
71
|
+
paused: y,
|
|
72
|
+
delay: v + d + Math.max(0, M - 1) * f,
|
|
73
|
+
onTick: () => D((E + 1) % w),
|
|
74
|
+
rootRef: T,
|
|
75
|
+
resetKey: E
|
|
76
|
+
}), { onPointerEnter: F, onPointerLeave: I, onFocus: L, onBlur: R } = P, z = (e, t, n, r, i) => b ? /* @__PURE__ */ l("button", {
|
|
77
|
+
type: "button",
|
|
78
|
+
className: "tm-cta-sentence__pill",
|
|
79
|
+
"data-tm-icon-size": "lg",
|
|
80
|
+
tabIndex: r ? -1 : void 0,
|
|
81
|
+
onClick: () => b(t, n),
|
|
82
|
+
children: i
|
|
83
|
+
}, e) : /* @__PURE__ */ l("span", {
|
|
84
|
+
className: "tm-cta-sentence__pill",
|
|
85
|
+
"data-tm-icon-size": "lg",
|
|
86
|
+
children: i
|
|
87
|
+
}, e);
|
|
88
|
+
return /* @__PURE__ */ l("div", {
|
|
21
89
|
ref: (e) => {
|
|
22
|
-
|
|
90
|
+
T.current = e, typeof C == "function" ? C(e) : C && (C.current = e);
|
|
23
91
|
},
|
|
24
|
-
className: t("tm-cta-sentence",
|
|
25
|
-
"data-autoplay":
|
|
26
|
-
...
|
|
92
|
+
className: t("tm-cta-sentence", x),
|
|
93
|
+
"data-autoplay": N ? "running" : _ ? "paused" : void 0,
|
|
94
|
+
...S,
|
|
27
95
|
onPointerEnter: (e) => {
|
|
28
|
-
|
|
96
|
+
S.onPointerEnter?.(e), F(e);
|
|
29
97
|
},
|
|
30
98
|
onPointerLeave: (e) => {
|
|
31
|
-
|
|
99
|
+
S.onPointerLeave?.(e), I();
|
|
32
100
|
},
|
|
33
101
|
onFocus: (e) => {
|
|
34
|
-
|
|
102
|
+
S.onFocus?.(e), L(e);
|
|
35
103
|
},
|
|
36
104
|
onBlur: (e) => {
|
|
37
|
-
|
|
105
|
+
S.onBlur?.(e), R(e);
|
|
38
106
|
},
|
|
39
|
-
children:
|
|
107
|
+
children: /* @__PURE__ */ l("div", {
|
|
40
108
|
className: "tm-cta-sentence__stage",
|
|
41
|
-
"aria-live":
|
|
42
|
-
children:
|
|
43
|
-
|
|
109
|
+
"aria-live": N ? "off" : "polite",
|
|
110
|
+
children: j ? /* @__PURE__ */ l("p", {
|
|
111
|
+
className: "tm-cta-sentence__example",
|
|
112
|
+
"data-active": "",
|
|
113
|
+
"data-padded": i[0]?.padded ? "" : void 0,
|
|
114
|
+
children: j.map((t, n) => {
|
|
115
|
+
if (t.kind === "word") return /* @__PURE__ */ l("span", {
|
|
116
|
+
className: "tm-cta-sentence__word",
|
|
117
|
+
children: t.text
|
|
118
|
+
}, n);
|
|
119
|
+
let r = t.byExample[E] ?? 0, i = A === null ? null : t.byExample[A] ?? null, a = i === r ? null : i;
|
|
120
|
+
return t.kind === "words" ? /* @__PURE__ */ l(g, {
|
|
121
|
+
className: "tm-cta-sentence__word",
|
|
122
|
+
active: r,
|
|
123
|
+
leaving: a,
|
|
124
|
+
order: 0,
|
|
125
|
+
children: t.options
|
|
126
|
+
}, n) : z(t.key ?? n, E, n, !1, /* @__PURE__ */ u(c, { children: [
|
|
127
|
+
t.sharedIcon ? t.options[0].icon : null,
|
|
128
|
+
/* @__PURE__ */ l(g, {
|
|
129
|
+
className: "tm-cta-sentence__value",
|
|
130
|
+
active: r,
|
|
131
|
+
leaving: a,
|
|
132
|
+
order: t.order,
|
|
133
|
+
children: t.options.map((e, n) => /* @__PURE__ */ u("span", {
|
|
134
|
+
className: "tm-cta-sentence__choice",
|
|
135
|
+
children: [t.sharedIcon ? null : e.icon, /* @__PURE__ */ l("span", {
|
|
136
|
+
className: "tm-cta-sentence__text",
|
|
137
|
+
children: e.value
|
|
138
|
+
})]
|
|
139
|
+
}, n))
|
|
140
|
+
}),
|
|
141
|
+
/* @__PURE__ */ l(e, { "aria-hidden": "true" })
|
|
142
|
+
] }));
|
|
143
|
+
})
|
|
144
|
+
}) : i.map((t, n) => {
|
|
145
|
+
let r = n === E;
|
|
44
146
|
return /* @__PURE__ */ l("p", {
|
|
45
147
|
className: "tm-cta-sentence__example",
|
|
148
|
+
"data-swap": "",
|
|
46
149
|
"data-active": r ? "" : void 0,
|
|
47
150
|
"data-padded": t.padded ? "" : void 0,
|
|
48
151
|
"aria-hidden": !r || void 0,
|
|
49
|
-
children: t.parts.map((t, i) => {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
/* @__PURE__ */ l(e, { "aria-hidden": "true" })
|
|
61
|
-
] });
|
|
62
|
-
return b ? /* @__PURE__ */ l("button", {
|
|
63
|
-
type: "button",
|
|
64
|
-
className: "tm-cta-sentence__pill",
|
|
65
|
-
"data-tm-icon-size": "lg",
|
|
66
|
-
tabIndex: r ? void 0 : -1,
|
|
67
|
-
onClick: () => b(n, i),
|
|
68
|
-
children: a
|
|
69
|
-
}, t.key ?? i) : /* @__PURE__ */ l("span", {
|
|
70
|
-
className: "tm-cta-sentence__pill",
|
|
71
|
-
"data-tm-icon-size": "lg",
|
|
72
|
-
children: a
|
|
73
|
-
}, t.key ?? i);
|
|
74
|
-
})
|
|
152
|
+
children: t.parts.map((t, i) => typeof t == "string" ? /* @__PURE__ */ l("span", {
|
|
153
|
+
className: "tm-cta-sentence__word",
|
|
154
|
+
children: t
|
|
155
|
+
}, i) : z(t.key ?? i, n, i, !r, /* @__PURE__ */ u(c, { children: [
|
|
156
|
+
t.icon,
|
|
157
|
+
/* @__PURE__ */ l("span", {
|
|
158
|
+
className: "tm-cta-sentence__value",
|
|
159
|
+
children: t.value
|
|
160
|
+
}),
|
|
161
|
+
/* @__PURE__ */ l(e, { "aria-hidden": "true" })
|
|
162
|
+
] })))
|
|
75
163
|
}, t.key ?? n);
|
|
76
164
|
})
|
|
77
|
-
})
|
|
78
|
-
className: "tm-cta-sentence__controls",
|
|
79
|
-
children: [/* @__PURE__ */ l(n, {
|
|
80
|
-
page: A + 1,
|
|
81
|
-
pageCount: O,
|
|
82
|
-
onPageChange: (e) => j(e - 1),
|
|
83
|
-
getPageLabel: x,
|
|
84
|
-
"aria-label": S
|
|
85
|
-
}), g ? /* @__PURE__ */ l(r, {
|
|
86
|
-
className: "tm-cta-sentence__toggle",
|
|
87
|
-
paused: N,
|
|
88
|
-
pauseLabel: C,
|
|
89
|
-
playLabel: w,
|
|
90
|
-
onClick: P
|
|
91
|
-
}) : null]
|
|
92
|
-
}) : null]
|
|
165
|
+
})
|
|
93
166
|
});
|
|
94
167
|
});
|
|
95
|
-
export {
|
|
168
|
+
export { _ as CtaSentence };
|
|
96
169
|
|
|
97
170
|
//# sourceMappingURL=CtaSentence.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CtaSentence.js","names":["_Fragment","Fragment$1","SWAP_DURATION","defaultPageLabel","page","pageCount","CtaSentence","props","count","examples","rootRef","useRef","index","setIndex","useIndexState","value","defaultValue","onValueChange","useAutoplay","autoPlay","interval","interactionProps","node","ref","cn","className","running","event","onPointerEnter","onPointerLeave","onFocus","onBlur","active","exampleIndex","example","part","partIndex","content","DownArrowIcon","onPillClick","controls","Pagination","paginationLabel","AutoplayToggle","userPaused","toggle"],"sources":["../../../src/components/CtaSentence/CtaSentence.tsx"],"sourcesContent":["import { forwardRef, useRef, type HTMLAttributes, type ReactNode } from 'react';\nimport { DownArrowIcon } from '../../icons';\nimport { cn } from '../../utils/cn';\nimport { Pagination } from '../Pagination';\nimport { AutoplayToggle } from '../PartnerCarousel/AutoplayToggle';\nimport { useAutoplay, useIndexState } from '../PartnerCarousel/autoplay';\nimport './CtaSentence.css';\n\n/** Figma prototype: Smart animate, ease in and out, 500ms. Keep in sync with `--_duration` in the stylesheet. */\nconst SWAP_DURATION = 500;\n\n/** A value of the sentence, drawn as a pill (Figma \"Pill / Type\", \"Pill / Destination\", …). */\nexport interface CtaSentencePill {\n /** React key; defaults to the position in the sentence. */\n key?: string;\n /** One icon from `@travel-match/ui` (e.g. `<MapPinIcon />`). */\n icon?: ReactNode;\n /** The value, e.g. \"Rome\". */\n value: ReactNode;\n}\n\n/** One part of a sentence: plain words (a string) or a pill. */\nexport type CtaSentencePart = string | CtaSentencePill;\n\n/** One example sentence — Figma \"Example\". */\nexport interface CtaSentenceExample {\n /** React key; defaults to the position in the list. */\n key?: string;\n /** Words and pills in reading order, e.g. `[\"I’d like\", { value: \"a Flight\" }, \"to\", { value: \"Paris\" }]`. */\n parts: CtaSentencePart[];\n /** Insets the sentence by `spacing/3xl` on both sides so its lines break evenly (Figma does this on Example 2). */\n padded?: boolean;\n}\n\nexport interface CtaSentenceProps extends Omit<HTMLAttributes<HTMLDivElement>, 'onChange' | 'defaultValue'> {\n /** The example sentences the component cycles through. Any number. */\n examples: CtaSentenceExample[];\n /** Index (0-based) of the example shown — Figma \"Example\". Makes the component controlled. */\n value?: number;\n /** Example shown first when uncontrolled. */\n defaultValue?: number;\n /** Called with the new index when the example changes (autoplay or dots). */\n onValueChange?: (value: number) => void;\n /** Cycles through the examples by itself. Stops for hover, focus, a hidden tab, an off-screen sentence and reduced motion. */\n autoPlay?: boolean;\n /** Time an example rests before the next one, in ms (Figma: 2600). */\n interval?: number;\n /** Holds the autoplay (the pause control stays available). */\n paused?: boolean;\n /** Shows the dots that pick an example and, with `autoPlay`, the pause / play button. */\n controls?: boolean;\n /** Makes the pills buttons and is called with the example and part index of the pressed one, e.g. to open the request form. */\n onPillClick?: (exampleIndex: number, partIndex: number) => void;\n /** Accessible name of a dot — translate it. */\n getPageLabel?: (page: number, pageCount: number) => string;\n /** Name of the dots navigation — translate it. */\n paginationLabel?: string;\n /** Name of the pause button — translate it. */\n pauseLabel?: string;\n /** Name of the play button — translate it. */\n playLabel?: string;\n}\n\nconst defaultPageLabel = (page: number, pageCount: number) => `Example ${page} of ${pageCount}`;\n\n/**\n * A request written as a sentence whose values are pills, cycling through examples\n * (Figma component set \"How it works / CTA sentence\"). Every example is real text; the one on show is the only one\n * exposed to assistive technology, and the dots reach the others.\n */\nexport const CtaSentence = /* @__PURE__ */ forwardRef<HTMLDivElement, CtaSentenceProps>(function CtaSentence(\n {\n examples,\n value,\n defaultValue = 0,\n onValueChange,\n autoPlay = true,\n interval = 2600,\n paused = false,\n controls = true,\n onPillClick,\n getPageLabel = defaultPageLabel,\n paginationLabel = 'Examples',\n pauseLabel = 'Pause the examples',\n playLabel = 'Play the examples',\n className,\n ...props\n },\n ref,\n) {\n const count = examples.length;\n const rootRef = useRef<HTMLDivElement | null>(null);\n const [index, setIndex] = useIndexState(value, defaultValue, onValueChange, count);\n\n const { running, userPaused, toggle, interactionProps } = useAutoplay({\n enabled: autoPlay && count > 1,\n paused,\n delay: interval + SWAP_DURATION,\n onTick: () => setIndex((index + 1) % count),\n rootRef,\n resetKey: index,\n });\n const { onPointerEnter, onPointerLeave, onFocus, onBlur } = interactionProps;\n\n return (\n <div\n ref={(node) => {\n rootRef.current = node;\n if (typeof ref === 'function') ref(node);\n else if (ref) ref.current = node;\n }}\n className={cn('tm-cta-sentence', className)}\n data-autoplay={running ? 'running' : autoPlay ? 'paused' : undefined}\n {...props}\n onPointerEnter={(event) => {\n props.onPointerEnter?.(event);\n onPointerEnter(event);\n }}\n onPointerLeave={(event) => {\n props.onPointerLeave?.(event);\n onPointerLeave();\n }}\n onFocus={(event) => {\n props.onFocus?.(event);\n onFocus();\n }}\n onBlur={(event) => {\n props.onBlur?.(event);\n onBlur(event);\n }}\n >\n {/* All examples share one grid cell, so the block is as tall as the tallest and never shifts the page. */}\n <div className=\"tm-cta-sentence__stage\" aria-live={running ? 'off' : 'polite'}>\n {examples.map((example, exampleIndex) => {\n const active = exampleIndex === index;\n return (\n <p\n key={example.key ?? exampleIndex}\n className=\"tm-cta-sentence__example\"\n data-active={active ? '' : undefined}\n data-padded={example.padded ? '' : undefined}\n aria-hidden={active ? undefined : true}\n >\n {example.parts.map((part, partIndex) => {\n if (typeof part === 'string') {\n return (\n <span key={partIndex} className=\"tm-cta-sentence__word\">\n {part}\n </span>\n );\n }\n const content = (\n <>\n {part.icon}\n <span className=\"tm-cta-sentence__value\">{part.value}</span>\n <DownArrowIcon aria-hidden=\"true\" />\n </>\n );\n return onPillClick ? (\n <button\n key={part.key ?? partIndex}\n type=\"button\"\n className=\"tm-cta-sentence__pill\"\n data-tm-icon-size=\"lg\"\n // The examples that are not on show are hidden (visibility), which also takes them out of the tab order.\n tabIndex={active ? undefined : -1}\n onClick={() => onPillClick(exampleIndex, partIndex)}\n >\n {content}\n </button>\n ) : (\n <span key={part.key ?? partIndex} className=\"tm-cta-sentence__pill\" data-tm-icon-size=\"lg\">\n {content}\n </span>\n );\n })}\n </p>\n );\n })}\n </div>\n\n {controls && count > 1 ? (\n <div className=\"tm-cta-sentence__controls\">\n <Pagination page={index + 1} pageCount={count} onPageChange={(page) => setIndex(page - 1)} getPageLabel={getPageLabel} aria-label={paginationLabel} />\n {autoPlay ? <AutoplayToggle className=\"tm-cta-sentence__toggle\" paused={userPaused} pauseLabel={pauseLabel} playLabel={playLabel} onClick={toggle} /> : null}\n </div>\n ) : null}\n </div>\n );\n});\n"],"mappings":";;;;;;;;;;AASA,IAAME,IAAgB,KAsDhBC,KAAoB,GAAc,MAAsB,WAAWC,EAAK,MAAMC,KAOvEC,IAA8B,kBAA6C,SACtF,EACE,aACA,UACA,kBAAe,GACf,kBACA,cAAW,IACX,cAAW,MACX,YAAS,IACT,cAAW,IACX,gBACA,kBAAeH,GACf,qBAAkB,YAClB,gBAAa,sBACb,eAAY,qBACZ,cACA,GAAGI,KAEL,GACA;CACA,IAAMC,IAAQC,EAAS,QACjBC,IAAUC,EAA8B,IAAI,GAC5C,CAACC,GAAOC,KAAYC,EAAcC,GAAOC,GAAcC,GAAeT,CAAK,GAE3E,EAAE,YAAS,eAAY,WAAQ,wBAAqBU,EAAY;EACpE,SAASC,KAAYX,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3D,kBAACG,GAAD,EAAe,eAAY,OAAQ,CAAA;MACnC,EAAA,CAAA;MAEJ,OAAOC,IACL,kBAAC,UAAD;OAEE,MAAK;OACL,WAAU;OACV,qBAAkB;OAElB,UAAUP,IAAS,KAAA,IAAY;OAC/B,eAAeO,EAAYN,GAAcG,CAAS;OAEjD,UAAAC;MACK,GATDF,EAAK,OAAOC,CASX,IAER,kBAAC,QAAD;OAAkC,WAAU;OAAwB,qBAAkB;OACnF,UAAAC;MACG,GAFKF,EAAK,OAAOC,CAEjB;KAEV,CAAC;IACA,GAvCIF,EAAQ,OAAOD,CAuCnB;GAEP,CAAC;EACE,CAAA,GAEJO,KAAYhC,IAAQ,IACnB,kBAAC,OAAD;GAAK,WAAU;GAAf,UAAA,CACE,kBAACiC,GAAD;IAAY,MAAM7B,IAAQ;IAAG,WAAWJ;IAAO,eAAe,MAASK,EAAST,IAAO,CAAC;IAAiB;IAAc,cAAYsC;GAAkB,CAAA,GACpJvB,IAAW,kBAACwB,GAAD;IAAgB,WAAU;IAA0B,QAAQC;IAAwB;IAAuB;IAAW,SAASC;GAAS,CAAA,IAAI,IACrJ;EACH,CAAA,IAAA,IACD;;AAET,CAAC"}
|
|
1
|
+
{"version":3,"file":"CtaSentence.js","names":["_Fragment","Fragment$1","SWAP_DURATION","STAGGER","iconType","isValidElement","icon","samePill","a","b","alignExamples","first","examples","slots","pills","position","variants","example","part","words","options","word","all","byExample","known","option","pill","sharedIcon","Roller","cn","className","order","children","active","leaving","child","CtaSentence","props","count","rootRef","useRef","index","setIndex","useIndexState","value","defaultValue","onValueChange","trail","setTrail","useState","previous","pillCount","slot","useAutoplay","autoPlay","interval","interactionProps","onPillClick","hidden","exampleIndex","partIndex","content","key","node","ref","running","event","onPointerEnter","onPointerLeave","onFocus","onBlur","before","optionIndex","DownArrowIcon"],"sources":["../../../src/components/CtaSentence/CtaSentence.tsx"],"sourcesContent":["import { forwardRef, isValidElement, useRef, useState, type CSSProperties, type HTMLAttributes, type ReactNode } from 'react';\nimport { DownArrowIcon } from '../../icons';\nimport { cn } from '../../utils/cn';\nimport { useAutoplay, useIndexState } from '../PartnerCarousel/autoplay';\nimport './CtaSentence.css';\n\n/** Figma prototype: Smart animate, ease in and out, 500ms. Keep in sync with `--_duration` in the stylesheet. */\nconst SWAP_DURATION = 500;\n/** The pills change one after another, this many ms apart. Keep in sync with `--_stagger` in the stylesheet. */\nconst STAGGER = 90;\n\n/** A value of the sentence, drawn as a pill (Figma \"Pill / Type\", \"Pill / Destination\", …). */\nexport interface CtaSentencePill {\n /** React key; defaults to the position in the sentence. */\n key?: string;\n /** One icon from `@travel-match/ui` (e.g. `<MapPinIcon />`). */\n icon?: ReactNode;\n /** The value, e.g. \"Rome\". */\n value: ReactNode;\n}\n\n/** One part of a sentence: plain words (a string) or a pill. */\nexport type CtaSentencePart = string | CtaSentencePill;\n\n/** One example sentence — Figma \"Example\". */\nexport interface CtaSentenceExample {\n /** React key; defaults to the position in the list. */\n key?: string;\n /** Words and pills in reading order, e.g. `[\"I’d like\", { value: \"a Flight\" }, \"to\", { value: \"Paris\" }]`. */\n parts: CtaSentencePart[];\n /**\n * Insets the sentence by `spacing/3xl` on both sides so its lines break evenly. When the examples share one sentence\n * (see `CtaSentence`), the first example decides for all of them.\n */\n padded?: boolean;\n}\n\nexport interface CtaSentenceProps extends Omit<HTMLAttributes<HTMLDivElement>, 'onChange' | 'defaultValue'> {\n /** The example requests the sentence cycles through. Any number. */\n examples: CtaSentenceExample[];\n /** Index (0-based) of the example shown — Figma \"Example\". Makes the component controlled. */\n value?: number;\n /** Example shown first when uncontrolled. */\n defaultValue?: number;\n /** Called with the new index each time the sentence moves on to the next example. */\n onValueChange?: (value: number) => void;\n /** Cycles through the examples by itself, endlessly. Holds for hover, focus, a hidden tab, an off-screen sentence and reduced motion. */\n autoPlay?: boolean;\n /** Time an example rests before the next one, in ms (Figma: 2600). */\n interval?: number;\n /** Holds the autoplay. */\n paused?: boolean;\n /** Makes the pills buttons and is called with the example and part index of the pressed one, e.g. to open the request form. */\n onPillClick?: (exampleIndex: number, partIndex: number) => void;\n}\n\n/** What one position of the shared sentence shows across the examples. */\ntype Slot =\n | { kind: 'word'; text: string }\n /** `options`: the different contents, in order of first appearance; `byExample[i]` is the option example `i` shows. */\n | { kind: 'words'; options: string[]; byExample: number[] }\n | { kind: 'pill'; key?: string; options: CtaSentencePill[]; byExample: number[]; sharedIcon: boolean; order: number };\n\nconst iconType = (icon: ReactNode) => (isValidElement(icon) ? icon.type : icon);\nconst samePill = (a: CtaSentencePill, b: CtaSentencePill) => a.value === b.value && iconType(a.icon) === iconType(b.icon);\n\n/**\n * The examples as one sentence: for every position, what stays and what changes. Returns null when the examples are\n * not built the same way (a different number of parts, or a word where another has a pill).\n */\nfunction alignExamples(examples: CtaSentenceExample[]): Slot[] | null {\n const first = examples[0];\n if (!first) return null;\n const slots: Slot[] = [];\n let pills = 0;\n for (let position = 0; position < first.parts.length; position++) {\n const variants: CtaSentencePart[] = [];\n for (const example of examples) {\n const part = example.parts[position];\n if (example.parts.length !== first.parts.length || part === undefined || typeof part !== typeof first.parts[position]) return null;\n variants.push(part);\n }\n if (typeof variants[0] === 'string') {\n const words = variants as string[];\n const options = [...new Set(words)];\n slots.push(options.length === 1 ? { kind: 'word', text: options[0]! } : { kind: 'words', options, byExample: words.map((word) => options.indexOf(word)) });\n } else {\n const all = variants as CtaSentencePill[];\n const options: CtaSentencePill[] = [];\n const byExample = all.map((pill) => {\n const known = options.findIndex((option) => samePill(option, pill));\n if (known >= 0) return known;\n options.push(pill);\n return options.length - 1;\n });\n const sharedIcon = all.every((pill) => iconType(pill.icon) === iconType(all[0]!.icon));\n slots.push({ kind: 'pill', key: all[0]!.key, options, byExample, sharedIcon, order: pills++ });\n }\n }\n return slots;\n}\n\n/** The contents of one changing position, stacked in one cell: the one on show, the one rolling out, the rest waiting. */\nfunction Roller({ className, active, leaving, order, children }: { className: string; active: number; leaving: number | null; order: number; children: ReactNode[] }) {\n return (\n <span className={cn('tm-cta-sentence__roller', className)} style={{ '--_order': order } as CSSProperties}>\n {children.map((child, option) => (\n <span\n key={option}\n className=\"tm-cta-sentence__option\"\n data-state={option === active ? 'active' : option === leaving ? 'leaving' : 'idle'}\n aria-hidden={option === active ? undefined : true}\n >\n {child}\n </span>\n ))}\n </span>\n );\n}\n\n/**\n * A request written as one sentence whose values are pills that look like selects (Figma component set\n * \"How it works / CTA sentence\"). The sentence stays where it is; every few seconds the values in the pills roll over\n * to the next example, one pill after another, endlessly. Each pill is as wide as its longest value, so nothing around\n * it moves. Only the values on show are exposed to assistive technology.\n *\n * The examples are expected to be the same sentence with different values (the same words and pills in the same\n * order). Examples built differently are shown one whole sentence at a time, fading from one to the next.\n */\nexport const CtaSentence = /* @__PURE__ */ forwardRef<HTMLDivElement, CtaSentenceProps>(function CtaSentence(\n { examples, value, defaultValue = 0, onValueChange, autoPlay = true, interval = 2600, paused = false, onPillClick, className, ...props },\n ref,\n) {\n const count = examples.length;\n const rootRef = useRef<HTMLDivElement | null>(null);\n const [index, setIndex] = useIndexState(value, defaultValue, onValueChange, count);\n\n // The example that was on show just before: its values are the ones rolling out.\n const [trail, setTrail] = useState<{ current: number; previous: number | null }>({ current: index, previous: null });\n if (trail.current !== index) setTrail({ current: index, previous: trail.current });\n const previous = trail.current === index ? trail.previous : trail.current;\n\n const slots = alignExamples(examples);\n const pillCount = slots ? slots.filter((slot) => slot.kind === 'pill').length : 0;\n\n const { running, interactionProps } = useAutoplay({\n enabled: autoPlay && count > 1,\n paused,\n // An example rests for `interval` after its last pill has rolled in.\n delay: interval + SWAP_DURATION + Math.max(0, pillCount - 1) * STAGGER,\n onTick: () => setIndex((index + 1) % count),\n rootRef,\n resetKey: index,\n });\n const { onPointerEnter, onPointerLeave, onFocus, onBlur } = interactionProps;\n\n const pill = (key: string | number, exampleIndex: number, partIndex: number, hidden: boolean, content: ReactNode) =>\n onPillClick ? (\n <button\n key={key}\n type=\"button\"\n className=\"tm-cta-sentence__pill\"\n data-tm-icon-size=\"lg\"\n // A sentence that is not on show is hidden (visibility), which also takes it out of the tab order.\n tabIndex={hidden ? -1 : undefined}\n onClick={() => onPillClick(exampleIndex, partIndex)}\n >\n {content}\n </button>\n ) : (\n <span key={key} className=\"tm-cta-sentence__pill\" data-tm-icon-size=\"lg\">\n {content}\n </span>\n );\n\n return (\n <div\n ref={(node) => {\n rootRef.current = node;\n if (typeof ref === 'function') ref(node);\n else if (ref) ref.current = node;\n }}\n className={cn('tm-cta-sentence', className)}\n data-autoplay={running ? 'running' : autoPlay ? 'paused' : undefined}\n {...props}\n onPointerEnter={(event) => {\n props.onPointerEnter?.(event);\n onPointerEnter(event);\n }}\n onPointerLeave={(event) => {\n props.onPointerLeave?.(event);\n onPointerLeave();\n }}\n onFocus={(event) => {\n props.onFocus?.(event);\n // (With the event the hook holds only for keyboard focus, so the focus a click on a pill leaves does not freeze it.)\n onFocus(event);\n }}\n onBlur={(event) => {\n props.onBlur?.(event);\n onBlur(event);\n }}\n >\n <div className=\"tm-cta-sentence__stage\" aria-live={running ? 'off' : 'polite'}>\n {slots ? (\n // One sentence; only what differs between the examples rolls over.\n <p className=\"tm-cta-sentence__example\" data-active=\"\" data-padded={examples[0]?.padded ? '' : undefined}>\n {slots.map((slot, partIndex) => {\n if (slot.kind === 'word') {\n return (\n <span key={partIndex} className=\"tm-cta-sentence__word\">\n {slot.text}\n </span>\n );\n }\n const active = slot.byExample[index] ?? 0;\n const before = previous === null ? null : (slot.byExample[previous] ?? null);\n const leaving = before === active ? null : before;\n if (slot.kind === 'words') {\n return (\n <Roller key={partIndex} className=\"tm-cta-sentence__word\" active={active} leaving={leaving} order={0}>\n {slot.options}\n </Roller>\n );\n }\n return pill(\n slot.key ?? partIndex,\n index,\n partIndex,\n false,\n <>\n {slot.sharedIcon ? slot.options[0]!.icon : null}\n <Roller className=\"tm-cta-sentence__value\" active={active} leaving={leaving} order={slot.order}>\n {slot.options.map((option, optionIndex) => (\n <span key={optionIndex} className=\"tm-cta-sentence__choice\">\n {slot.sharedIcon ? null : option.icon}\n <span className=\"tm-cta-sentence__text\">{option.value}</span>\n </span>\n ))}\n </Roller>\n <DownArrowIcon aria-hidden=\"true\" />\n </>,\n );\n })}\n </p>\n ) : (\n // Examples that are not the same sentence: one whole sentence at a time, sharing one grid cell, so the block\n // is as tall as the tallest and never shifts the page.\n examples.map((example, exampleIndex) => {\n const active = exampleIndex === index;\n return (\n <p\n key={example.key ?? exampleIndex}\n className=\"tm-cta-sentence__example\"\n data-swap=\"\"\n data-active={active ? '' : undefined}\n data-padded={example.padded ? '' : undefined}\n aria-hidden={active ? undefined : true}\n >\n {example.parts.map((part, partIndex) =>\n typeof part === 'string' ? (\n <span key={partIndex} className=\"tm-cta-sentence__word\">\n {part}\n </span>\n ) : (\n pill(\n part.key ?? partIndex,\n exampleIndex,\n partIndex,\n !active,\n <>\n {part.icon}\n <span className=\"tm-cta-sentence__value\">{part.value}</span>\n <DownArrowIcon aria-hidden=\"true\" />\n </>,\n )\n ),\n )}\n </p>\n );\n })\n )}\n </div>\n </div>\n );\n});\n"],"mappings":";;;;;;;;AAOA,IAAME,IAAgB,KAEhBC,IAAU,IAsDVC,KAAY,MAAqBC,EAAeC,CAAI,IAAIA,EAAK,OAAOA,GACpEC,KAAY,GAAoB,MAAuBC,EAAE,UAAUC,EAAE,SAASL,EAASI,EAAE,IAAI,MAAMJ,EAASK,EAAE,IAAI;AAMxH,SAASC,EAAc,GAA+C;CACpE,IAAMC,IAAQC,EAAS;CACvB,IAAI,CAACD,GAAO,OAAO;CACnB,IAAME,IAAgB,CAAC,GACnBC,IAAQ;CACZ,KAAK,IAAIC,IAAW,GAAGA,IAAWJ,EAAM,MAAM,QAAQ,KAAY;EAChE,IAAMK,IAA8B,CAAC;EACrC,KAAK,IAAMC,KAAWL,GAAU;GAC9B,IAAMM,IAAOD,EAAQ,MAAMF;GAC3B,IAAIE,EAAQ,MAAM,WAAWN,EAAM,MAAM,UAAUO,MAAS,KAAA,KAAa,OAAOA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AAwB,WAAU;QAAlC,UAAA,CACGA,EAAK,aAAa,OAAO3B,EAAO,MACjC,kBAAC,QAAD;SAAM,WAAU;SAAyB,UAAAA,EAAO;QAAY,CAAA,CACxD;OAHK,GAAA+C,CAGL,CACP;MACK,CAAA;MACR,kBAACC,GAAD,EAAe,eAAY,OAAQ,CAAA;KACnC,EAAA,CAAA,CACJ;IACF,CAAC;GACA,CAAA,IAIH7D,EAAS,KAAK,GAAS,MAAiB;IACtC,IAAMqB,IAAS0B,MAAiBlB;IAChC,OACE,kBAAC,KAAD;KAEE,WAAU;KACV,aAAU;KACV,eAAaR,IAAS,KAAK,KAAA;KAC3B,eAAahB,EAAQ,SAAS,KAAK,KAAA;KACnC,eAAa,MAAS,KAAA;KAErB,UAAAA,EAAQ,MAAM,KAAK,GAAM,MACxB,OAAOC,KAAS,WACd,kBAAC,QAAD;MAAsB,WAAU;MAC7B,UAAAA;KACG,GAFK0C,CAEL,IAENlC,EACER,EAAK,OAAO0C,GACZD,GACAC,GACA,CAAC3B,GACD,kBAAAjC,GAAA,EAAA,UAAA;MACGkB,EAAK;MACN,kBAAC,QAAD;OAAM,WAAU;OAA0B,UAAAA,EAAK;MAAY,CAAA;MAC3D,kBAACuD,GAAD,EAAe,eAAY,OAAQ,CAAA;KACnC,EAAA,CAAA,CACJ,CAEJ;IACC,GA1BIxD,EAAQ,OAAO0C,CA0BnB;GAEP,CAAC;EAEA,CAAA;CACF,CAAA;AAET,CAAC"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use client";let e=require("react")
|
|
1
|
+
"use client";let e=require("react");var t=`(prefers-reduced-motion: reduce)`;function n(){let[n,r]=(0,e.useState)(!1);return(0,e.useEffect)(()=>{if(typeof window>`u`||typeof window.matchMedia!=`function`)return;let e=window.matchMedia(t),n=()=>r(e.matches);return n(),e.addEventListener?.(`change`,n),()=>e.removeEventListener?.(`change`,n)},[]),n}function r(t){let[n,r]=(0,e.useState)(!0),[i,a]=(0,e.useState)(!0);return(0,e.useEffect)(()=>{let e=t.current;if(!e||typeof IntersectionObserver>`u`)return;let n=new IntersectionObserver(e=>{let t=e[e.length-1];t&&r(t.isIntersecting)});return n.observe(e),()=>n.disconnect()},[t]),(0,e.useEffect)(()=>{if(typeof document>`u`)return;let e=()=>a(document.visibilityState!==`hidden`);return e(),document.addEventListener(`visibilitychange`,e),()=>document.removeEventListener(`visibilitychange`,e)},[]),n&&i}exports.useOnScreen=r,exports.usePrefersReducedMotion=n;
|
|
2
2
|
//# sourceMappingURL=heroMotion.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"heroMotion.cjs","names":["useState","react","
|
|
1
|
+
{"version":3,"file":"heroMotion.cjs","names":["useState","react","REDUCED_MOTION","usePrefersReducedMotion","reduced","setReduced","query","update","useOnScreen","inView","setInView","pageVisible","setPageVisible","element","ref","observer","entry","entries"],"sources":["../../../src/components/HeroColumns/heroMotion.tsx"],"sourcesContent":["import { useEffect, useState, type RefObject } from 'react';\n\n/**\n * Shared plumbing of the hero animations (HeroColumns, HeroSwitcher, HeroOrbit, HeroMap). Internal — not exported\n * from the package.\n */\n\nconst REDUCED_MOTION = '(prefers-reduced-motion: reduce)';\n\n/** `true` while the user asks for reduced motion. Starts `false` so server and first client render agree. */\nexport function usePrefersReducedMotion(): boolean {\n const [reduced, setReduced] = useState(false);\n\n useEffect(() => {\n if (typeof window === 'undefined' || typeof window.matchMedia !== 'function') return;\n const query = window.matchMedia(REDUCED_MOTION);\n const update = () => setReduced(query.matches);\n update();\n query.addEventListener?.('change', update);\n return () => query.removeEventListener?.('change', update);\n }, []);\n\n return reduced;\n}\n\n/**\n * `false` while the element is scrolled out of the viewport or the tab is hidden, so animations can stop working\n * for nobody. Environments without IntersectionObserver count as visible.\n */\nexport function useOnScreen(ref: RefObject<Element | null>): boolean {\n const [inView, setInView] = useState(true);\n const [pageVisible, setPageVisible] = useState(true);\n\n useEffect(() => {\n const element = ref.current;\n if (!element || typeof IntersectionObserver === 'undefined') return;\n const observer = new IntersectionObserver((entries) => {\n const entry = entries[entries.length - 1];\n if (entry) setInView(entry.isIntersecting);\n });\n observer.observe(element);\n return () => observer.disconnect();\n }, [ref]);\n\n useEffect(() => {\n if (typeof document === 'undefined') return;\n const update = () => setPageVisible(document.visibilityState !== 'hidden');\n update();\n document.addEventListener('visibilitychange', update);\n return () => document.removeEventListener('visibilitychange', update);\n }, []);\n\n return inView && pageVisible;\n}\n"],"mappings":"A,oCAOA,IAAME,EAAiB,mCAGvB,SAAgBC,GAAmC,CACjD,GAAM,CAACC,EAASC,IAAA,EAAcL,EAAAA,SAAAA,CAAS,EAAK,EAW5C,OATA,EAAAC,EAAA,UAAA,KAAgB,CACd,GAAI,OAAO,OAAW,KAAe,OAAO,OAAO,YAAe,WAAY,OAC9E,IAAMK,EAAQ,OAAO,WAAWJ,CAAc,EACxCK,MAAeF,EAAWC,EAAM,OAAO,EAG7C,OAFAC,EAAO,EACPD,EAAM,mBAAmB,SAAUC,CAAM,MAC5BD,EAAM,sBAAsB,SAAUC,CAAM,CAC3D,EAAG,CAAC,CAAC,EAEEH,CACT,CAMA,SAAgBI,EAAY,EAAyC,CACnE,GAAM,CAACC,EAAQC,IAAA,EAAaV,EAAAA,SAAAA,CAAS,EAAI,EACnC,CAACW,EAAaC,IAAA,EAAkBZ,EAAAA,SAAAA,CAAS,EAAI,EAqBnD,OAnBA,EAAAC,EAAA,UAAA,KAAgB,CACd,IAAMY,EAAUC,EAAI,QACpB,GAAI,CAACD,GAAW,OAAO,qBAAyB,IAAa,OAC7D,IAAME,EAAW,IAAI,qBAAsB,GAAY,CACrD,IAAMC,EAAQC,EAAQA,EAAQ,OAAS,GACnCD,GAAON,EAAUM,EAAM,cAAc,CAC3C,CAAC,EAED,OADAD,EAAS,QAAQF,CAAO,MACXE,EAAS,WAAW,CACnC,EAAG,CAACD,CAAG,CAAC,GAER,EAAAb,EAAA,UAAA,KAAgB,CACd,GAAI,OAAO,SAAa,IAAa,OACrC,IAAMM,MAAeK,EAAe,SAAS,kBAAoB,QAAQ,EAGzE,OAFAL,EAAO,EACP,SAAS,iBAAiB,mBAAoBA,CAAM,MACvC,SAAS,oBAAoB,mBAAoBA,CAAM,CACtE,EAAG,CAAC,CAAC,EAEEE,GAAUE,CACnB,C"}
|
|
@@ -1,17 +1,16 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { useEffect as e, useState as t } from "react";
|
|
3
|
-
import { jsx as n, jsxs as r } from "react/jsx-runtime";
|
|
4
3
|
// src/components/HeroColumns/heroMotion.tsx
|
|
5
|
-
var
|
|
6
|
-
function
|
|
7
|
-
let [
|
|
4
|
+
var n = "(prefers-reduced-motion: reduce)";
|
|
5
|
+
function r() {
|
|
6
|
+
let [r, i] = t(!1);
|
|
8
7
|
return e(() => {
|
|
9
8
|
if (typeof window > "u" || typeof window.matchMedia != "function") return;
|
|
10
|
-
let e = window.matchMedia(
|
|
9
|
+
let e = window.matchMedia(n), t = () => i(e.matches);
|
|
11
10
|
return t(), e.addEventListener?.("change", t), () => e.removeEventListener?.("change", t);
|
|
12
|
-
}, []),
|
|
11
|
+
}, []), r;
|
|
13
12
|
}
|
|
14
|
-
function
|
|
13
|
+
function i(n) {
|
|
15
14
|
let [r, i] = t(!0), [a, o] = t(!0);
|
|
16
15
|
return e(() => {
|
|
17
16
|
let e = n.current;
|
|
@@ -27,42 +26,6 @@ function o(n) {
|
|
|
27
26
|
return e(), document.addEventListener("visibilitychange", e), () => document.removeEventListener("visibilitychange", e);
|
|
28
27
|
}, []), r && a;
|
|
29
28
|
}
|
|
30
|
-
|
|
31
|
-
return /* @__PURE__ */ r("svg", {
|
|
32
|
-
viewBox: "0 0 24 24",
|
|
33
|
-
width: "16",
|
|
34
|
-
height: "16",
|
|
35
|
-
fill: "currentColor",
|
|
36
|
-
"aria-hidden": "true",
|
|
37
|
-
focusable: "false",
|
|
38
|
-
...e,
|
|
39
|
-
children: [/* @__PURE__ */ n("rect", {
|
|
40
|
-
x: "6",
|
|
41
|
-
y: "5",
|
|
42
|
-
width: "4",
|
|
43
|
-
height: "14",
|
|
44
|
-
rx: "1.5"
|
|
45
|
-
}), /* @__PURE__ */ n("rect", {
|
|
46
|
-
x: "14",
|
|
47
|
-
y: "5",
|
|
48
|
-
width: "4",
|
|
49
|
-
height: "14",
|
|
50
|
-
rx: "1.5"
|
|
51
|
-
})]
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
function c(e) {
|
|
55
|
-
return /* @__PURE__ */ n("svg", {
|
|
56
|
-
viewBox: "0 0 24 24",
|
|
57
|
-
width: "16",
|
|
58
|
-
height: "16",
|
|
59
|
-
fill: "currentColor",
|
|
60
|
-
"aria-hidden": "true",
|
|
61
|
-
focusable: "false",
|
|
62
|
-
...e,
|
|
63
|
-
children: /* @__PURE__ */ n("path", { d: "M8 5.6v12.8a1 1 0 0 0 1.5.86l10.6-6.4a1 1 0 0 0 0-1.72L9.5 4.74A1 1 0 0 0 8 5.6Z" })
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
export { s as PauseGlyph, c as PlayGlyph, o as useOnScreen, a as usePrefersReducedMotion };
|
|
29
|
+
export { i as useOnScreen, r as usePrefersReducedMotion };
|
|
67
30
|
|
|
68
31
|
//# sourceMappingURL=heroMotion.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"heroMotion.js","names":["REDUCED_MOTION","usePrefersReducedMotion","reduced","setReduced","useState","useEffect","query","update","useOnScreen","inView","setInView","pageVisible","setPageVisible","element","ref","observer","entry","entries"
|
|
1
|
+
{"version":3,"file":"heroMotion.js","names":["REDUCED_MOTION","usePrefersReducedMotion","reduced","setReduced","useState","useEffect","query","update","useOnScreen","inView","setInView","pageVisible","setPageVisible","element","ref","observer","entry","entries"],"sources":["../../../src/components/HeroColumns/heroMotion.tsx"],"sourcesContent":["import { useEffect, useState, type RefObject } from 'react';\n\n/**\n * Shared plumbing of the hero animations (HeroColumns, HeroSwitcher, HeroOrbit, HeroMap). Internal — not exported\n * from the package.\n */\n\nconst REDUCED_MOTION = '(prefers-reduced-motion: reduce)';\n\n/** `true` while the user asks for reduced motion. Starts `false` so server and first client render agree. */\nexport function usePrefersReducedMotion(): boolean {\n const [reduced, setReduced] = useState(false);\n\n useEffect(() => {\n if (typeof window === 'undefined' || typeof window.matchMedia !== 'function') return;\n const query = window.matchMedia(REDUCED_MOTION);\n const update = () => setReduced(query.matches);\n update();\n query.addEventListener?.('change', update);\n return () => query.removeEventListener?.('change', update);\n }, []);\n\n return reduced;\n}\n\n/**\n * `false` while the element is scrolled out of the viewport or the tab is hidden, so animations can stop working\n * for nobody. Environments without IntersectionObserver count as visible.\n */\nexport function useOnScreen(ref: RefObject<Element | null>): boolean {\n const [inView, setInView] = useState(true);\n const [pageVisible, setPageVisible] = useState(true);\n\n useEffect(() => {\n const element = ref.current;\n if (!element || typeof IntersectionObserver === 'undefined') return;\n const observer = new IntersectionObserver((entries) => {\n const entry = entries[entries.length - 1];\n if (entry) setInView(entry.isIntersecting);\n });\n observer.observe(element);\n return () => observer.disconnect();\n }, [ref]);\n\n useEffect(() => {\n if (typeof document === 'undefined') return;\n const update = () => setPageVisible(document.visibilityState !== 'hidden');\n update();\n document.addEventListener('visibilitychange', update);\n return () => document.removeEventListener('visibilitychange', update);\n }, []);\n\n return inView && pageVisible;\n}\n"],"mappings":";;;AAOA,IAAMA,IAAiB;AAGvB,SAAgBC,IAAmC;CACjD,IAAM,CAACC,GAASC,KAAcC,EAAS,EAAK;CAW5C,OATAC,QAAgB;EACd,IAAI,OAAO,SAAW,OAAe,OAAO,OAAO,cAAe,YAAY;EAC9E,IAAMC,IAAQ,OAAO,WAAWN,CAAc,GACxCO,UAAeJ,EAAWG,EAAM,OAAO;EAG7C,OAFAC,EAAO,GACPD,EAAM,mBAAmB,UAAUC,CAAM,SAC5BD,EAAM,sBAAsB,UAAUC,CAAM;CAC3D,GAAG,CAAC,CAAC,GAEEL;AACT;AAMA,SAAgBM,EAAY,GAAyC;CACnE,IAAM,CAACC,GAAQC,KAAaN,EAAS,EAAI,GACnC,CAACO,GAAaC,KAAkBR,EAAS,EAAI;CAqBnD,OAnBAC,QAAgB;EACd,IAAMQ,IAAUC,EAAI;EACpB,IAAI,CAACD,KAAW,OAAO,uBAAyB,KAAa;EAC7D,IAAME,IAAW,IAAI,sBAAsB,MAAY;GACrD,IAAMC,IAAQC,EAAQA,EAAQ,SAAS;GACvC,AAAID,KAAON,EAAUM,EAAM,cAAc;EAC3C,CAAC;EAED,OADAD,EAAS,QAAQF,CAAO,SACXE,EAAS,WAAW;CACnC,GAAG,CAACD,CAAG,CAAC,GAERT,QAAgB;EACd,IAAI,OAAO,WAAa,KAAa;EACrC,IAAME,UAAeK,EAAe,SAAS,oBAAoB,QAAQ;EAGzE,OAFAL,EAAO,GACP,SAAS,iBAAiB,oBAAoBA,CAAM,SACvC,SAAS,oBAAoB,oBAAoBA,CAAM;CACtE,GAAG,CAAC,CAAC,GAEEE,KAAUE;AACnB"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use client";const e=require("../../utils/cn.cjs"),t=require("../HeroColumns/heroMotion.cjs"),n=require("./mapDots.cjs");;/* empty css */let r=require("react"),i=require("react/jsx-runtime");var a=640,o=480;function s(e,t){let n=e.x/100*a,r=e.y/100*o,i=t.x/100*a,s=t.y/100*o,c=.28*Math.hypot(i-n,s-r),l=e=>Math.round(e*100)/100;return`M${l(n)} ${l(r)}Q${l((n+i)/2)} ${l((r+s)/2-c)} ${l(i)} ${l(s)}`}var c=(0,r.forwardRef)(function({origin:c,destinations:l,activeIndex:u,defaultActiveIndex:d=0,onActiveIndexChange:f,autoPlay:p=!0,interval:m=2700,paused:h=!1,
|
|
1
|
+
"use client";const e=require("../../utils/cn.cjs"),t=require("../HeroColumns/heroMotion.cjs"),n=require("./mapDots.cjs");;/* empty css */let r=require("react"),i=require("react/jsx-runtime");var a=640,o=480;function s(e,t){let n=e.x/100*a,r=e.y/100*o,i=t.x/100*a,s=t.y/100*o,c=.28*Math.hypot(i-n,s-r),l=e=>Math.round(e*100)/100;return`M${l(n)} ${l(r)}Q${l((n+i)/2)} ${l((r+s)/2-c)} ${l(i)} ${l(s)}`}var c=(0,r.forwardRef)(function({origin:c,destinations:l,activeIndex:u,defaultActiveIndex:d=0,onActiveIndexChange:f,autoPlay:p=!0,interval:m=2700,paused:h=!1,className:g,onPointerEnter:_,onPointerLeave:v,...y},b){let x=(0,r.useRef)(null),[S,C]=(0,r.useState)(d),w=l.length,T=w?Math.min(Math.max(Math.trunc(u===void 0?S:u)||0,0),w-1):-1,[E,D]=(0,r.useState)(!1),O=t.useOnScreen(x),k=t.usePrefersReducedMotion(),A=p&&!k&&w>1&&!h&&!E&&O,j=(0,r.useCallback)(()=>{let e=(T+1)%w;u===void 0&&C(e),f?.(e)},[T,w,u,f]);return(0,r.useEffect)(()=>{if(!A)return;let e=window.setTimeout(j,Math.max(m,0));return()=>window.clearTimeout(e)},[A,j,m]),(0,i.jsxs)(`div`,{ref:e=>{x.current=e,typeof b==`function`?b(e):b&&(b.current=e)},className:e.cn(`tm-hero-map`,g),"data-playing":A?``:void 0,onPointerEnter:e=>{_?.(e),e.pointerType===`mouse`&&D(!0)},onPointerLeave:e=>{v?.(e),D(!1)},...y,children:[(0,i.jsx)(`svg`,{className:`tm-hero-map__dots`,viewBox:`0 0 620 420`,"aria-hidden":`true`,focusable:`false`,children:(0,i.jsx)(`path`,{d:n.getMapDotsPath(),fill:`none`,stroke:`currentColor`,strokeWidth:`3.2`,strokeLinecap:`round`})}),(0,i.jsx)(`svg`,{className:`tm-hero-map__routes`,viewBox:`0 0 ${a} ${o}`,"aria-hidden":`true`,focusable:`false`,children:l.map((e,t)=>(0,i.jsx)(`path`,{className:`tm-hero-map__route`,"data-active":t===T?``:void 0,d:s(c,e),fill:`none`,stroke:`currentColor`,strokeWidth:`1.5`,strokeLinecap:`round`,strokeDasharray:`4 4`},e.key??t))}),(0,i.jsxs)(`div`,{className:`tm-hero-map__origin`,style:{left:`${c.x}%`,top:`${c.y}%`},children:[(0,i.jsx)(`span`,{className:`tm-hero-map__origin-halo`,"aria-hidden":`true`}),(0,i.jsx)(`span`,{className:`tm-hero-map__origin-dot`,"aria-hidden":`true`}),c.label==null?null:(0,i.jsx)(`span`,{className:`tm-hero-map__origin-label`,children:c.label})]}),(0,i.jsx)(`ul`,{className:`tm-hero-map__destinations`,children:l.map((e,t)=>(0,i.jsxs)(`li`,{className:`tm-hero-map__destination`,"data-active":t===T?``:void 0,"data-side":e.x>50?`end`:`start`,style:{left:`${e.x}%`,top:`${e.y}%`,"--_x":e.x},children:[(0,i.jsxs)(`span`,{className:`tm-hero-map__pin`,"aria-hidden":`true`,children:[(0,i.jsx)(`span`,{className:`tm-hero-map__halo`}),(0,i.jsx)(`span`,{className:`tm-hero-map__dot`}),(0,i.jsx)(`span`,{className:`tm-hero-map__dot tm-hero-map__dot--active`})]}),(0,i.jsx)(`div`,{className:`tm-hero-map__tag-box`,children:(0,i.jsxs)(`div`,{className:`tm-hero-map__tag`,children:[e.icon==null?null:(0,i.jsx)(`span`,{className:`tm-hero-map__tag-icon`,"data-tm-icon-size":`sm`,"aria-hidden":`true`,children:e.icon}),(0,i.jsxs)(`span`,{className:`tm-hero-map__tag-text`,children:[(0,i.jsx)(`span`,{className:`tm-hero-map__tag-title`,children:e.title}),e.description==null?null:(0,i.jsx)(`span`,{className:`tm-hero-map__tag-description`,children:e.description})]})]})})]},e.key??t))})]})});exports.HeroMap=c;
|
|
2
2
|
//# sourceMappingURL=HeroMap.cjs.map
|