{"version":3,"file":"ngwr-blur-text.mjs","sources":["../../../projects/lib/blur-text/blur-text.ts","../../../projects/lib/blur-text/blur-text.html","../../../projects/lib/blur-text/ngwr-blur-text.ts"],"sourcesContent":["/**\n * @license\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://github.com/thekhegay/ngwr/blob/main/LICENSE\n *\n * Angular adaptation of the BlurText effect by David Haz / reactbits.dev.\n * Original: https://www.reactbits.dev/text-animations/blur-text\n *\n * The reactbits version uses `motion/react` (framer-motion successor).\n * This port is dependency-free — uses the Web Animations API for the\n * three-keyframe blur-and-fade-in, triggered by `IntersectionObserver`.\n */\n\nimport { isPlatformBrowser } from '@angular/common';\nimport {\n  Component,\n  DestroyRef,\n  ElementRef,\n  PLATFORM_ID,\n  ViewEncapsulation,\n  afterNextRender,\n  computed,\n  effect,\n  inject,\n  input,\n  output,\n} from '@angular/core';\n\nimport { WrPlatform } from 'ngwr/platform';\nimport { numAttr } from 'ngwr/utils';\n\ntype Unit = 'chars' | 'words';\ntype Direction = 'top' | 'bottom';\ntype Piece = { readonly kind: 'piece'; readonly text: string } | { readonly kind: 'space'; readonly text: string };\n\nfunction splitPieces(text: string, unit: Unit): readonly Piece[] {\n  if (!text) return [];\n  if (unit === 'words') {\n    return text.split(/(\\s+)/).flatMap<Piece>(seg => {\n      if (seg.length === 0) return [];\n      if (/^\\s+$/.test(seg)) return [{ kind: 'space', text: seg }];\n      return [{ kind: 'piece', text: seg }];\n    });\n  }\n  return [...text].map<Piece>(ch => (/\\s/.test(ch) ? { kind: 'space', text: ch } : { kind: 'piece', text: ch }));\n}\n\n/**\n * Reveals text by splitting it into chars or words and animating each\n * piece in from a blurred / offset state through a brief mid-step into\n * the steady state. Triggers when the host enters the viewport.\n *\n * @example\n * ```html\n * <wr-blur-text\n *   text=\"Welcome to ngwr\"\n *   animateBy=\"words\"\n *   direction=\"top\"\n *   [delay]=\"120\"\n *   [stepDuration]=\"0.4\"\n * />\n * ```\n *\n * @see https://www.reactbits.dev/text-animations/blur-text\n */\n@Component({\n  selector: 'wr-blur-text',\n  templateUrl: './blur-text.html',\n  styleUrl: './blur-text.scss',\n  encapsulation: ViewEncapsulation.None,\n  host: { class: 'wr-blur-text' },\n})\nexport class WrBlurText {\n  /** Text to animate. Required. */\n  readonly text = input.required<string>();\n\n  /** Split granularity. @default 'words' */\n  readonly animateBy = input<Unit>('words');\n\n  /** Entry direction. `'top'` slides down into place; `'bottom'` slides up. @default 'top' */\n  readonly direction = input<Direction>('top');\n\n  /** Per-piece stagger in ms. @default 200 */\n  readonly delay = input(200, { transform: numAttr(200) });\n\n  /** Duration of each keyframe step in seconds (total = 2 × stepDuration). @default 0.35 */\n  readonly stepDuration = input(0.35, { transform: numAttr(0.35) });\n\n  /** CSS easing function. @default 'linear' (matches reactbits' identity easing) */\n  readonly easing = input('linear');\n\n  /** `IntersectionObserver.threshold` (0..1). @default 0.1 */\n  readonly threshold = input(0.1, { transform: numAttr(0.1) });\n\n  /** `IntersectionObserver.rootMargin`. @default '0px' */\n  readonly rootMargin = input('0px');\n\n  /** Emitted once all pieces finish animating. */\n  readonly animationComplete = output<void>();\n\n  protected readonly pieces = computed(() => splitPieces(this.text(), this.animateBy()));\n\n  private readonly host = inject<ElementRef<HTMLElement>>(ElementRef);\n  private readonly destroyRef = inject(DestroyRef);\n  private readonly isBrowser = isPlatformBrowser(inject(PLATFORM_ID));\n  private readonly platform = inject(WrPlatform);\n\n  private hasAnimated = false;\n\n  constructor() {\n    if (!this.isBrowser) return;\n    afterNextRender(() => this.startObserver());\n    effect(() => {\n      this.text();\n      this.animateBy();\n      this.hasAnimated = false;\n      queueMicrotask(() => this.startObserver());\n    });\n  }\n\n  private startObserver(): void {\n    if (this.hasAnimated) return;\n    const host = this.host.nativeElement;\n    const io = new IntersectionObserver(\n      (entries, obs) => {\n        for (const e of entries) {\n          if (e.isIntersecting) {\n            obs.disconnect();\n            this.animate();\n            break;\n          }\n        }\n      },\n      { threshold: this.threshold(), rootMargin: this.rootMargin() }\n    );\n    io.observe(host);\n    this.destroyRef.onDestroy(() => io.disconnect());\n  }\n\n  private animate(): void {\n    if (this.hasAnimated) return;\n    this.hasAnimated = true;\n\n    // Reduced motion: pieces already render clear and in place — skip\n    // the blur tween and report completion right away.\n    if (this.platform.prefersReducedMotion()) {\n      this.animationComplete.emit();\n      return;\n    }\n\n    const targets = this.host.nativeElement.querySelectorAll<HTMLElement>('.wr-blur-text__piece');\n    if (targets.length === 0) {\n      this.animationComplete.emit();\n      return;\n    }\n\n    const dir = this.direction();\n    const stepMs = this.stepDuration() * 1000;\n    const totalMs = stepMs * 2;\n    const stagger = this.delay();\n    const easing = this.easing();\n\n    // Three-keyframe shape per reactbits:\n    //   0    → fully blurred, offset, transparent\n    //   50%  → half-blur, half-opacity, small reverse offset\n    //   100% → clear, opaque, at rest\n    const startY = dir === 'top' ? -50 : 50;\n    const midY = dir === 'top' ? 5 : -5;\n    const keyframes: Keyframe[] = [\n      { opacity: 0, filter: 'blur(10px)', transform: `translate3d(0, ${startY}px, 0)` },\n      { opacity: 0.5, filter: 'blur(5px)', transform: `translate3d(0, ${midY}px, 0)`, offset: 0.5 },\n      { opacity: 1, filter: 'blur(0px)', transform: 'translate3d(0, 0, 0)' },\n    ];\n\n    let remaining = targets.length;\n    targets.forEach((el, i) => {\n      el.style.opacity = '0';\n      el.style.filter = 'blur(10px)';\n      el.style.transform = `translate3d(0, ${startY}px, 0)`;\n      const animation = el.animate(keyframes, {\n        duration: totalMs,\n        delay: i * stagger,\n        easing,\n        fill: 'forwards',\n      });\n      animation.onfinish = (): void => {\n        el.style.opacity = '1';\n        el.style.filter = 'blur(0px)';\n        el.style.transform = 'translate3d(0, 0, 0)';\n        try {\n          animation.cancel();\n        } catch {\n          /* noop */\n        }\n        remaining -= 1;\n        if (remaining === 0) this.animationComplete.emit();\n      };\n    });\n  }\n}\n","@for (p of pieces(); track $index) {\n  @if (p.kind === 'piece') {\n    <span class=\"wr-blur-text__piece\">{{ p.text }}</span>\n  } @else {\n    <span class=\"wr-blur-text__space\">{{ p.text }}</span>\n  }\n}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;;;;;AAAA;;;;;;;;;;;;AAYG;AAwBH,SAAS,WAAW,CAAC,IAAY,EAAE,IAAU,EAAA;AAC3C,IAAA,IAAI,CAAC,IAAI;AAAE,QAAA,OAAO,EAAE;AACpB,IAAA,IAAI,IAAI,KAAK,OAAO,EAAE;QACpB,OAAO,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,OAAO,CAAQ,GAAG,IAAG;AAC9C,YAAA,IAAI,GAAG,CAAC,MAAM,KAAK,CAAC;AAAE,gBAAA,OAAO,EAAE;AAC/B,YAAA,IAAI,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC;gBAAE,OAAO,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC;YAC5D,OAAO,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC;AACvC,QAAA,CAAC,CAAC;IACJ;IACA,OAAO,CAAC,GAAG,IAAI,CAAC,CAAC,GAAG,CAAQ,EAAE,KAAK,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,GAAG,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,EAAE,EAAE,GAAG,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC,CAAC;AAChH;AAEA;;;;;;;;;;;;;;;;;AAiBG;MAQU,UAAU,CAAA;;IAEZ,IAAI,GAAG,KAAK,CAAC,QAAQ;6EAAU;;IAG/B,SAAS,GAAG,KAAK,CAAO,OAAO;kFAAC;;IAGhC,SAAS,GAAG,KAAK,CAAY,KAAK;kFAAC;;AAGnC,IAAA,KAAK,GAAG,KAAK,CAAC,GAAG,EAAA,EAAA,IAAA,SAAA,GAAA,EAAA,SAAA,EAAA,OAAA,EAA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