|
| 1 | +<script lang="ts"> |
| 2 | + import TabsLayout from '$lib/components/docs/preview/TabsLayout.svelte'; |
| 3 | + import Customize from '$lib/components/docs/preview/Customize.svelte'; |
| 4 | + import PreviewSlider from '$lib/components/docs/preview/PreviewSlider.svelte'; |
| 5 | + import PreviewSwitch from '$lib/components/docs/preview/PreviewSwitch.svelte'; |
| 6 | + import PreviewSelect from '$lib/components/docs/preview/PreviewSelect.svelte'; |
| 7 | + import PropTable, { type PropRow } from '$lib/components/docs/preview/PropTable.svelte'; |
| 8 | + import DemoCodeTab from '$lib/components/docs/preview/DemoCodeTab.svelte'; |
| 9 | + import ReplayButton from '$lib/components/docs/preview/ReplayButton.svelte'; |
| 10 | + import DecryptedText from '$lib/components/library/TextAnimations/DecryptedText/DecryptedText.svelte'; |
| 11 | + import source from '$lib/components/library/TextAnimations/DecryptedText/DecryptedText.svelte?raw'; |
| 12 | +
|
| 13 | + const DEFAULTS = { |
| 14 | + speed: 60, |
| 15 | + maxIterations: 10, |
| 16 | + sequential: true, |
| 17 | + useOriginalCharsOnly: false, |
| 18 | + revealDirection: 'start' as 'start' | 'end' | 'center', |
| 19 | + animateOn: 'view' as 'view' | 'hover' | 'inViewHover' | 'click', |
| 20 | + clickMode: 'once' as 'once' | 'toggle' |
| 21 | + }; |
| 22 | +
|
| 23 | + let speed = $state(DEFAULTS.speed); |
| 24 | + let maxIterations = $state(DEFAULTS.maxIterations); |
| 25 | + let sequential = $state(DEFAULTS.sequential); |
| 26 | + let useOriginalCharsOnly = $state(DEFAULTS.useOriginalCharsOnly); |
| 27 | + let revealDirection = $state<'start' | 'end' | 'center'>(DEFAULTS.revealDirection); |
| 28 | + let animateOn = $state<'view' | 'hover' | 'inViewHover' | 'click'>(DEFAULTS.animateOn); |
| 29 | + let clickMode = $state<'once' | 'toggle'>(DEFAULTS.clickMode); |
| 30 | + let replay = $state(0); |
| 31 | +
|
| 32 | + const hasChanges = $derived( |
| 33 | + speed !== DEFAULTS.speed || |
| 34 | + maxIterations !== DEFAULTS.maxIterations || |
| 35 | + sequential !== DEFAULTS.sequential || |
| 36 | + useOriginalCharsOnly !== DEFAULTS.useOriginalCharsOnly || |
| 37 | + revealDirection !== DEFAULTS.revealDirection || |
| 38 | + animateOn !== DEFAULTS.animateOn || |
| 39 | + clickMode !== DEFAULTS.clickMode |
| 40 | + ); |
| 41 | +
|
| 42 | + function reset() { |
| 43 | + speed = DEFAULTS.speed; |
| 44 | + maxIterations = DEFAULTS.maxIterations; |
| 45 | + sequential = DEFAULTS.sequential; |
| 46 | + useOriginalCharsOnly = DEFAULTS.useOriginalCharsOnly; |
| 47 | + revealDirection = DEFAULTS.revealDirection; |
| 48 | + animateOn = DEFAULTS.animateOn; |
| 49 | + clickMode = DEFAULTS.clickMode; |
| 50 | + replay++; |
| 51 | + } |
| 52 | +
|
| 53 | + const usage = $derived(`<DecryptedText |
| 54 | + text="Hacking into the mainframe..." |
| 55 | + speed={${speed}} |
| 56 | + maxIterations={${maxIterations}} |
| 57 | + sequential={${sequential}} |
| 58 | + revealDirection="${revealDirection}" |
| 59 | + useOriginalCharsOnly={${useOriginalCharsOnly}} |
| 60 | + animateOn="${animateOn}" |
| 61 | + clickMode="${clickMode}" |
| 62 | +/>`); |
| 63 | +
|
| 64 | + const props: PropRow[] = [ |
| 65 | + { name: 'text', type: 'string', default: '""', description: 'The text content to decrypt.' }, |
| 66 | + { name: 'speed', type: 'number', default: '50', description: 'Time in ms between each iteration.' }, |
| 67 | + { name: 'maxIterations', type: 'number', default: '10', description: 'Max number of random iterations (non-sequential mode).' }, |
| 68 | + { name: 'sequential', type: 'boolean', default: 'false', description: 'Whether to reveal one character at a time in sequence.' }, |
| 69 | + { name: 'revealDirection', type: '"start" | "end" | "center"', default: '"start"', description: 'From which position characters begin to reveal in sequential mode.' }, |
| 70 | + { name: 'useOriginalCharsOnly', type: 'boolean', default: 'false', description: 'Restrict scrambling to only the characters already in the text.' }, |
| 71 | + { name: 'class', type: 'string', default: '""', description: 'CSS class for revealed characters.' }, |
| 72 | + { name: 'parentClassName', type: 'string', default: '""', description: 'CSS class for the main characters container.' }, |
| 73 | + { name: 'encryptedClassName', type: 'string', default: '""', description: 'CSS class for encrypted characters.' }, |
| 74 | + { name: 'animateOn', type: '"view" | "hover" | "inViewHover" | "click"', default: '"hover"', description: 'Trigger scrambling on hover, scroll-into-view, or click.' }, |
| 75 | + { name: 'clickMode', type: '"once" | "toggle"', default: '"once"', description: 'Click behavior; only applies when animateOn is "click".' } |
| 76 | + ]; |
| 77 | +
|
| 78 | + const animateOptions = [ |
| 79 | + { value: 'view', label: 'View' }, |
| 80 | + { value: 'hover', label: 'Hover' }, |
| 81 | + { value: 'inViewHover', label: 'View & Hover' }, |
| 82 | + { value: 'click', label: 'Click' } |
| 83 | + ]; |
| 84 | + const clickOptions = [ |
| 85 | + { value: 'once', label: 'Once' }, |
| 86 | + { value: 'toggle', label: 'Toggle' } |
| 87 | + ]; |
| 88 | + const directionOptions = [ |
| 89 | + { value: 'start', label: 'Start' }, |
| 90 | + { value: 'end', label: 'End' }, |
| 91 | + { value: 'center', label: 'Center' } |
| 92 | + ]; |
| 93 | +</script> |
| 94 | + |
| 95 | +<svelte:head><title>Decrypted Text - svelte-bits</title></svelte:head> |
| 96 | + |
| 97 | +<h1 class="sub-category">Decrypted Text</h1> |
| 98 | + |
| 99 | +<TabsLayout onreset={reset} {hasChanges} componentName="DecryptedText" {usage} {source} {props}> |
| 100 | + {#snippet preview()} |
| 101 | + <div |
| 102 | + class="demo-container relative w-full overflow-hidden" |
| 103 | + style="height:400px;display:flex;align-items:center;justify-content:center;font-size:clamp(1.25rem, 3vw, 2.5rem);font-weight:600;" |
| 104 | + > |
| 105 | + <ReplayButton onClick={() => replay++} /> |
| 106 | + {#key replay} |
| 107 | + <DecryptedText |
| 108 | + text="Hacking into the mainframe..." |
| 109 | + {speed} |
| 110 | + {maxIterations} |
| 111 | + {sequential} |
| 112 | + {revealDirection} |
| 113 | + {useOriginalCharsOnly} |
| 114 | + {animateOn} |
| 115 | + {clickMode} |
| 116 | + /> |
| 117 | + {/key} |
| 118 | + </div> |
| 119 | + {/snippet} |
| 120 | + {#snippet code()} |
| 121 | + <DemoCodeTab slug="decrypted-text" {usage} {source} /> |
| 122 | + {/snippet} |
| 123 | + {#snippet customize()} |
| 124 | + <Customize> |
| 125 | + <PreviewSelect |
| 126 | + title="Animate On" |
| 127 | + options={animateOptions} |
| 128 | + value={animateOn} |
| 129 | + onChange={(v) => { |
| 130 | + animateOn = v as typeof animateOn; |
| 131 | + replay++; |
| 132 | + }} |
| 133 | + /> |
| 134 | + <PreviewSelect |
| 135 | + title="Click Mode" |
| 136 | + options={clickOptions} |
| 137 | + value={clickMode} |
| 138 | + isDisabled={animateOn !== 'click'} |
| 139 | + onChange={(v) => { |
| 140 | + clickMode = v as typeof clickMode; |
| 141 | + replay++; |
| 142 | + }} |
| 143 | + /> |
| 144 | + <PreviewSelect |
| 145 | + title="Direction" |
| 146 | + options={directionOptions} |
| 147 | + value={revealDirection} |
| 148 | + onChange={(v) => { |
| 149 | + revealDirection = v as typeof revealDirection; |
| 150 | + replay++; |
| 151 | + }} |
| 152 | + /> |
| 153 | + <PreviewSlider |
| 154 | + title="Speed" |
| 155 | + min={10} |
| 156 | + max={200} |
| 157 | + step={10} |
| 158 | + value={speed} |
| 159 | + valueUnit="ms" |
| 160 | + onChange={(v) => { |
| 161 | + speed = v; |
| 162 | + replay++; |
| 163 | + }} |
| 164 | + /> |
| 165 | + <PreviewSlider |
| 166 | + title="Iterations" |
| 167 | + min={1} |
| 168 | + max={50} |
| 169 | + step={1} |
| 170 | + value={maxIterations} |
| 171 | + onChange={(v) => { |
| 172 | + maxIterations = v; |
| 173 | + replay++; |
| 174 | + }} |
| 175 | + /> |
| 176 | + <PreviewSwitch |
| 177 | + title="Sequential" |
| 178 | + checked={sequential} |
| 179 | + onChange={(v) => { |
| 180 | + sequential = v; |
| 181 | + replay++; |
| 182 | + }} |
| 183 | + /> |
| 184 | + <PreviewSwitch |
| 185 | + title="Original Chars" |
| 186 | + checked={useOriginalCharsOnly} |
| 187 | + onChange={(v) => { |
| 188 | + useOriginalCharsOnly = v; |
| 189 | + replay++; |
| 190 | + }} |
| 191 | + /> |
| 192 | + </Customize> |
| 193 | + {/snippet} |
| 194 | + {#snippet propTable()} |
| 195 | + <PropTable rows={props} /> |
| 196 | + {/snippet} |
| 197 | +</TabsLayout> |
0 commit comments