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ASpC,YAAc,YACvBoC,EAASC,QAAU5C,EACnB2C,EAASnC,OAASV,EAClBrG,SAASgH,KAAKC,YAAYiC,EAC5B,CAyBEE,GACF","sources":["webpack://lange/../node_modules/uuid/dist/rng.js","webpack://lange/../node_modules/uuid/dist/stringify.js","webpack://lange/../node_modules/uuid/dist/v4.js","webpack://lange/./sections/tangent-hair-quiz/index.ts","webpack://lange/./lib/dom-ready.ts"],"sourcesContent":["const rnds8 = new Uint8Array(16);\nexport default function rng() {\n    return crypto.getRandomValues(rnds8);\n}\n","import validate from './validate.js';\nconst byteToHex = [];\nfor (let i = 0; i < 256; ++i) {\n    byteToHex.push((i + 0x100).toString(16).slice(1));\n}\nexport function unsafeStringify(arr, offset = 0) {\n    return (byteToHex[arr[offset + 0]] +\n        byteToHex[arr[offset + 1]] +\n        byteToHex[arr[offset + 2]] +\n        byteToHex[arr[offset + 3]] +\n        '-' +\n        byteToHex[arr[offset + 4]] +\n        byteToHex[arr[offset + 5]] +\n        '-' +\n        byteToHex[arr[offset + 6]] +\n        byteToHex[arr[offset + 7]] +\n        '-' +\n        byteToHex[arr[offset + 8]] +\n        byteToHex[arr[offset + 9]] +\n        '-' +\n        byteToHex[arr[offset + 10]] +\n        byteToHex[arr[offset + 11]] +\n        byteToHex[arr[offset + 12]] +\n        byteToHex[arr[offset + 13]] +\n        byteToHex[arr[offset + 14]] +\n        byteToHex[arr[offset + 15]]).toLowerCase();\n}\nfunction stringify(arr, offset = 0) {\n    const uuid = unsafeStringify(arr, offset);\n    if (!validate(uuid)) {\n        throw TypeError('Stringified UUID is invalid');\n    }\n    return uuid;\n}\nexport default stringify;\n","import rng from './rng.js';\nimport { unsafeStringify } from './stringify.js';\nfunction v4(options, buf, offset) {\n    if (!buf && !options && crypto.randomUUID) {\n        return crypto.randomUUID();\n    }\n    return _v4(options, buf, offset);\n}\nfunction _v4(options, buf, offset) {\n    options = options || {};\n    const rnds = options.random ?? options.rng?.() ?? rng();\n    if (rnds.length < 16) {\n        throw new Error('Random bytes length must be >= 16');\n    }\n    rnds[6] = (rnds[6] & 0x0f) | 0x40;\n    rnds[8] = (rnds[8] & 0x3f) | 0x80;\n    if (buf) {\n        offset = offset || 0;\n        if (offset < 0 || offset + 16 > buf.length) {\n            throw new RangeError(`UUID byte range ${offset}:${offset + 15} is out of buffer bounds`);\n        }\n        for (let i = 0; i < 16; ++i) {\n            buf[offset + i] = rnds[i];\n        }\n        return buf;\n    }\n    return unsafeStringify(rnds);\n}\nexport default v4;\n","import { v4 as uuidv4 } from 'uuid';\nimport { ready } from '../../lib/dom-ready.js';\n\n// Integration with Tangent.ai quiz platform for hair analysis.\n//\n// This module handles the complete lifecycle of the Tangent hair quiz including:\n// - Loading appropriate quiz versions based on geolocation (selfie vs no-selfie)\n// - Tracking quiz progress and user responses for analytics\n// - Prefilling customer information when available\n// - Rendering hair damage analysis overlays on selfie images\n//\n// Note: CSS selectors ending in `_custom` are Tangent's convention for customized components that\n//  override their default quiz styling and behavior.\n\n/**\n * Module level variables to track the active quiz's lead slide index and question ID to auto\n * populate the name and email fields if known. Since there could be up to 4 variations of the quiz\n * (selfie and no selfie versions with potential experiments for each), we need to track these\n * values dynamically based on which quiz version/experiment the user is bucketed into. Since the\n * lead slide position can vary between versions and experiments, we rely on bootstrapping logic\n * during quiz initialization to set these values based on the active quiz variation to identify\n * when the user has reached the lead form.\n */\nlet activeQuizEmailIndex: number;\nlet activeQuizEmailQuestionId: string;\nlet quizProgressIndex = 0;\n\n/**\n * Utility method for emitting the \"hair-quiz-started\" custom event which is used for tracking quiz\n * starts in analytics. This event is emitted when the user starts the Tangent quiz and includes the\n * quiz vendor in the event detail.\n */\nfunction emitHairQuizStartedEvent(vendor: string) {\n  type HairQuizStartedEventDetail = WindowEventMap['hair-quiz-started']['detail'];\n  const hairEvent = new CustomEvent<HairQuizStartedEventDetail>('hair-quiz-started', {\n    detail: {\n      quiz_vendor: vendor\n    }\n  });\n  dispatchEvent(hairEvent);\n\n  const quizId = tangent_quiz.no_selfie ?\n    tangent_quiz.no_selfie_form_id : tangent_quiz.with_selfie_form_id;\n  type QuizStartedEventDetail = WindowEventMap['quiz-started']['detail'];\n  const quizEvent = new CustomEvent<QuizStartedEventDetail>('quiz-started', {\n    detail: {\n      event_id: uuidv4(),\n      quiz_id: quizId,\n      vendor: 'tangent',\n      name: 'hair-quiz'\n    }\n  });\n  dispatchEvent(quizEvent);\n}\n\n/**\n * Utility method for emitting the \"hair-quiz-question-viewed\" custom event which is used for\n * tracking quiz question views in analytics. This event is emitted when the user views a quiz\n * question and includes the question ID, question text, and quiz name in the event detail.\n */\nfunction emitHairQuizQuestionViewedEvent(questionId: string, questionText: string) {\n  type HairQuizQuestionViewedEventDetail = WindowEventMap['hair-quiz-question-viewed']['detail'];\n  const hairEvent = new CustomEvent<HairQuizQuestionViewedEventDetail>(\n    'hair-quiz-question-viewed',\n    {\n      detail: {\n        question_id: questionId,\n        quiz_name: 'hair-quiz',\n        question_text: questionText\n      }\n    });\n  dispatchEvent(hairEvent);\n\n  const quizId = tangent_quiz.no_selfie ?\n    tangent_quiz.no_selfie_form_id : tangent_quiz.with_selfie_form_id;\n  type QuizViewedEventDetail = WindowEventMap['quiz-viewed']['detail'];\n  const quizEvent = new CustomEvent<QuizViewedEventDetail>(\n    'quiz-viewed',\n    {\n      detail: {\n        event_id: uuidv4(),\n        question_id: questionId,\n        quiz_id: quizId,\n        vendor: 'tangent',\n        name: 'hair-quiz',\n        question_text: questionText\n      }\n    });\n  dispatchEvent(quizEvent);\n}\n\n/**\n * Utility method for emitting the \"hair-quiz-question-response\" custom event which is used for\n * tracking quiz question responses in analytics. This event is emitted when the user answers a quiz\n * question and includes the question ID and answer value in the event detail.\n */\nfunction emitHairQuizQuestionResponseEvent(questionId: string, answerValue: string) {\n  type HairQuizQuestionResponseEventDetail =\n    WindowEventMap['hair-quiz-question-response']['detail'];\n  const event = new CustomEvent<HairQuizQuestionResponseEventDetail>(\n    'hair-quiz-question-response',\n    {\n      detail: {\n        question_id: questionId,\n        answer_value: answerValue\n      }\n    });\n  dispatchEvent(event);\n\n  const quizId = tangent_quiz.no_selfie ?\n    tangent_quiz.no_selfie_form_id : tangent_quiz.with_selfie_form_id;\n  type QuizResponseEventDetail = WindowEventMap['quiz-response']['detail'];\n  const responseEvent = new CustomEvent<QuizResponseEventDetail>(\n    'quiz-response',\n    {\n      detail: {\n        event_id: uuidv4(),\n        quiz_id: quizId,\n        name: 'hair-quiz',\n        vendor: 'tangent',\n        question_id: questionId,\n        answer_text: answerValue\n      }\n    });\n  dispatchEvent(responseEvent);\n}\n\n/**\n * Utility method for applying progress update to the Tangent quiz progress bar. The Tangent quiz\n * emits a \"quiz_progress\" event with the current question index and total number of questions which\n * we use to calculate the progress percentage and apply it to the progress bar.\n */\nfunction applyProgress(current: number, total: number) {\n  const progress = Math.min((current / total) * 100, 100);\n  const progressBar = document.getElementById('tangent-progress-bar');\n  if (progressBar) {\n    progressBar.style.width = `${progress}%`;\n  }\n}\n\n/**\n * Called when either the selfie or no-selfie version of the Tangent quiz loads the lead page and\n * attempts to prefill the name and email fields if the Shopify customer information is available.\n */\nfunction preFillNameAndEmail() {\n  const nameInput = document.querySelector<HTMLInputElement>(\n    `.tangent_${activeQuizEmailQuestionId}_inputs_container_custom > div:nth-child(1) > input`);\n  if (nameInput && tangent_quiz.customer_name) {\n    forceReactInput(nameInput, tangent_quiz.customer_name);\n  }\n\n  const emailInput = document.querySelector<HTMLInputElement>(\n    `.tangent_${activeQuizEmailQuestionId}_inputs_container_custom > div:nth-child(2) > input`);\n  if (emailInput && tangent_quiz.customer_email) {\n    forceReactInput(emailInput, tangent_quiz.customer_email);\n  }\n}\n\n/**\n * Forces React to recognize programmatic input value changes by directly manipulating React's\n * internal properties and triggering its onChange handler. This workaround is necessary because\n * we're integrating with Tangent's React-based quiz from vanilla JavaScript, and React doesn't\n * detect programmatic value changes without synthetic events.\n */\nfunction forceReactInput(input: HTMLInputElement, value: string) {\n  // Use the native HTMLInputElement setter to update the value\n  const setter = Object.getOwnPropertyDescriptor(HTMLInputElement.prototype, 'value')?.set;\n  if (!setter) {\n    return;\n  }\n\n  setter.call(input, value);\n\n  // Find React's internal props object (key starts with __reactProps$)\n  const key = Object.keys(input).find(k => k.startsWith('__reactProps$'));\n  if (!key) {\n    return;\n  }\n\n  // React hands its onChange a synthetic event, and we only know the few properties Tangent's\n  // handler reads off it, so this describes that much and nothing more.\n  type ReactChangeEvent = {\n    currentTarget: HTMLInputElement;\n    target: HTMLInputElement;\n    type: string;\n  };\n\n  type ReactInputProps = {\n    onChange?: (event: ReactChangeEvent) => void;\n  };\n\n  const props = (<Record<string, ReactInputProps>><unknown>input)[key];\n\n  if (props?.onChange) {\n    props.onChange({\n      currentTarget: input,\n      target: input,\n      type: 'change'\n    });\n  }\n}\n\nfunction handleLoadingAnimation() {\n  const progressFill = document.getElementById('progressFill');\n  const percent = document.getElementById('percent');\n  const heading = document.querySelector('.loading-message');\n\n  const loadingText = [\n    'Analyzing your hair profile...',\n    'Evaluating texture & condition...',\n    'Cross-referencing 50+ product formulas...',\n    'Matching products to your goals...',\n    'Building your personalized routine...',\n    'Finalizing recommendations...',\n    'Your routine is ready!'\n  ];\n\n  const duration = 7000;\n\n  // change text every 1 second\n  loadingText.forEach((text, index) => {\n    setTimeout(() => {\n      if (heading) {\n        heading.textContent = text;\n      }\n    }, index * 1000);\n  });\n\n  const start = Date.now();\n  const percentInterval = setInterval(() => {\n    const elapsed = Date.now() - start;\n    const progress = Math.min((elapsed / duration) * 100, 100);\n\n    percent.textContent = Math.floor(progress) + '%';\n    progressFill.style.width = `${Math.floor(progress)}%`;\n\n    if (progress >= 100) {\n      clearInterval(percentInterval);\n    }\n  }, 50);\n}\n\n// Track the last viewed slide ID so we can associate user responses with the correct question when\n// they click an option. The quiz_progress event updates this before the user clicks.\nlet lastSlideId = '';\n\n/**\n * This handles the quiz_progress event emitted by the Tangent quiz library which provides\n * information on the current question index, total number of questions, and the previous and\n * current question GUID. We use this information to emit a hair-quiz-question-viewed event with the\n * question text and to update the quiz progress bar. Additionally, when the user reaches the email\n * question, we pre-fill the email and name fields with known customer information to streamline the\n * quiz completion process.\n */\nfunction onQuizProgress(event: WindowEventMap['quiz_progress']) {\n  const parts = event.detail.split('_');\n  const current = parseInt(parts[0], 10);\n  const total = parseInt(parts[1], 10);\n  const currentSlideId = parts[3];\n  lastSlideId = parts[2];\n  applyProgress(current, total - 1);\n  handleProgressLabel(current);\n\n  // Tangent tells us the slide changed before it has drawn the new slide. The quiz_progress event\n  // fires part way through the same task that renders it, so when we get the event the elements for\n  // the incoming slide are not in the page yet and querying for them finds nothing. Tangent\n  // finishes rendering later in that same task. We measured the gap at 7 to 11 milliseconds over a\n  // dozen transitions, so 50 is a cushion over that rather than a meaningful number. Waiting is\n  // what lets our animation classes land on elements that exist. The other timers in this handler\n  // are waiting on the same render.\n  setTimeout(() => {\n    if (current !== 0 && current > quizProgressIndex) {\n      const questionTextBlock = document.querySelector<HTMLElement>(\n        `.tangent_${currentSlideId}_question_text_custom`);\n      const optionBlockClass = current === activeQuizEmailIndex ?\n        `.tangent_${currentSlideId}_inputs_container_custom` :\n        `.tangent_${currentSlideId}_options_container_custom`;\n      const optionsBlock = document.querySelector<HTMLElement>(optionBlockClass);\n      if (questionTextBlock && optionsBlock) {\n        questionTextBlock.style.opacity = '0';\n        questionTextBlock.classList.add('slideIn_animation');\n        optionsBlock.style.opacity = '0';\n        optionsBlock.classList.add('slideIn_animation');\n      }\n    }\n\n    if (current !== 0 && current < quizProgressIndex) {\n      const questionTextBlock = document.querySelector(\n        `.tangent_${currentSlideId}_question_text_custom`);\n      const optionBlockClass = current === activeQuizEmailIndex ?\n        `.tangent_${currentSlideId}_inputs_container_custom` :\n        `.tangent_${currentSlideId}_options_container_custom`;\n      const optionsBlock = document.querySelector(optionBlockClass);\n      if (questionTextBlock && optionsBlock) {\n        questionTextBlock.classList.add('slide-from-left');\n        optionsBlock.classList.add('slide-from-left');\n      }\n    }\n\n    quizProgressIndex = current;\n    if (current === total) {\n      handleLoadingAnimation();\n    }\n  }, 50);\n\n  if (current !== total) {\n    // Wait for DOM to update with new question text before extracting it for analytics\n    setTimeout(() => {\n      const questionText = getQuestionText(current);\n      emitHairQuizQuestionViewedEvent(currentSlideId, questionText);\n    }, 100);\n  }\n\n  if (tangent_quiz.no_selfie && current === tangent_quiz.no_selfie_email_index ||\n    !tangent_quiz.no_selfie && current === tangent_quiz.with_selfie_email_index) {\n    setTimeout(preFillNameAndEmail, 100);\n  }\n\n  const progress = document.getElementById('progress-wrapper');\n  if (current === 0) {\n    progress.style.display = 'none';\n  } else {\n    progress.style.display = 'flex';\n  }\n}\n\nfunction handleProgressLabel(current: number) {\n  const blocks = document.querySelectorAll('.progress-category-block');\n\n  // The slide number at which each block lights up. A block with no threshold never lights up,\n  // because comparing against undefined is false.\n  const thresholds = [1, 5, 9];\n\n  for (let index = 0; index < blocks.length; index++) {\n    blocks[index].classList.toggle('fadeinAnimation', current >= thresholds[index]);\n  }\n}\n\n/**\n * Handles the click on the email question's submit button. Reads the email the user typed and\n * dispatches an identity-captured event so marketing automation can pick it up.\n */\nfunction onEmailSubmitClick(event: MouseEvent) {\n  if (!(event.target instanceof Element)) {\n    return;\n  }\n\n  const selector = `.tangent_${activeQuizEmailQuestionId}_survey_next_button_mob_custom`;\n  const submitEl = event.target.closest(selector);\n  if (!submitEl) {\n    return;\n  }\n\n  const emailEl = document.querySelector<HTMLInputElement>(\n    `.tangent_${activeQuizEmailQuestionId}_inputs_container_mob_custom > div > input`);\n\n  type IdentityCapturedEvent = WindowEventMap['identity-captured'];\n\n  const identityCaptured = new CustomEvent<IdentityCapturedEvent['detail']>('identity-captured', {\n    bubbles: true,\n    composed: true,\n    detail: {\n      email: emailEl?.value\n    }\n  });\n\n  submitEl.dispatchEvent(identityCaptured);\n}\n\n/**\n * Handles the click on one of a question's answer options. Reports which option the user picked for\n * the slide they were on, for analytics.\n */\nfunction onAnswerOptionClick(event: MouseEvent) {\n  if (!(event.target instanceof Element)) {\n    return;\n  }\n\n  const option = event.target.closest<HTMLElement>('.tangent_options_custom');\n  if (!option) {\n    return;\n  }\n\n  const questionEl = document.querySelector('.tangent_question_text_custom');\n  if (!questionEl) {\n    return;\n  }\n\n  const optionText = option.innerText;\n\n  emitHairQuizQuestionResponseEvent(lastSlideId, optionText);\n}\n\n/**\n * Handles the selfie retry button click. Clears the current selfie image and hides the image\n * container so the user can upload a new photo.\n *\n * The retry button is not in our markup. Tangent renders the whole quiz from a script they host,\n * and that happens some time after our script runs, so there is no button for us to bind to when we\n * set this up. We listen on document instead and check on each click whether it came from the\n * button.\n */\nfunction onRetryClick(event: MouseEvent) {\n  if (!(event.target instanceof Element)) {\n    return;\n  }\n\n  const option = event.target.closest('.tangent_selfie_retry_button_custom');\n  if (!option) {\n    return;\n  }\n\n  // Clear out existing attribute overlays applied to old selfie image\n  const attributesContainer = document.getElementById('attributes-overlay-container');\n  if (attributesContainer) {\n    attributesContainer.innerHTML = '';\n  }\n\n  const selfieContainer = document.getElementById('selfie-img-container');\n  if (selfieContainer) {\n    selfieContainer.style.display = 'none';\n  }\n\n  const selfieImage = document.getElementById('selfie_img');\n  if (selfieImage) {\n    selfieImage.removeAttribute('src');\n  }\n}\n\n/**\n * Helper method to extract the currently viewed question text from the DOM. This method takes into\n * account the different quiz structures for the selfie and no-selfie versions as well as variations\n * in the DOM when querying for the question text based on the question index. Since there is\n * currently not a reliable way to extract the question text at the time the quiz_progress event is\n * emitted, we will use this method in conjunction with a delayed event emission to ensure that we\n * can extract the correct question text from the DOM when emitting our custom quiz question viewed\n * event for analytics tracking.\n */\nfunction getQuestionText(index: number) {\n  let questionEl;\n  if (index === 0) {\n    questionEl = document.querySelector('.tangent-title-heading');\n  } else if (index === 1 && !tangent_quiz.no_selfie) {\n    questionEl = document.querySelector('#selfie-info-text');\n  } else {\n    questionEl = document.querySelector('.question-text');\n  }\n\n  let questionText = '';\n  if (questionEl) {\n    questionText = questionEl.textContent.trim();\n  }\n\n  return questionText;\n}\n\n/**\n * Handler for the quiz_initialized event which is emitted by Tangent.\n */\nfunction onQuizInitialized(_event: WindowEventMap['quiz_initialized']) {\n  const hasSelfie = tangent_quiz.no_selfie ? 'no-selfie' : 'with-selfie';\n  const vendor = `tangent-${hasSelfie}`;\n\n  emitHairQuizStartedEvent(vendor);\n}\n\n/**\n * To mitigate against a race condition between the loading of the Tangent quiz script and attaching\n * of event listeners to handle emitted quiz events, we attach an onload listener which is attached\n * to both script loads to properly add required event listeners.\n */\nfunction onJsLoadSuccess() {\n  addEventListener('quiz_progress', onQuizProgress);\n  addEventListener('quiz_initialized', onQuizInitialized);\n}\n\n/**\n * The vendor Tangent is responsible for geolocation of customers and blocking the selfie feature of\n * the quiz in the states of California and Illinois. If the loading of the default Tangent quiz\n * JavaScript throws an error, this is their signal to load alternate assets that load a version of\n * the quiz excluding the selfie feature.\n */\nfunction onSelfieJsLoadError() {\n  tangent_quiz.no_selfie = true;\n\n  activeQuizEmailIndex = tangent_quiz.no_selfie_email_index;\n  activeQuizEmailQuestionId = tangent_quiz.no_selfie_email_qid;\n\n  const tangentMainContainer = document.getElementById('tangent-main-container');\n  tangentMainContainer.dataset.formid = tangent_quiz.no_selfie_form_id;\n\n  // Attempt to load with no-selfie quiz version by injecting alternate Tangent assets that power\n  // the no-selfie version of the quiz.\n  const noSelfieJs = document.createElement('script');\n  noSelfieJs.src = 'https://a.tangent.ai/quiz-inline/2.0.91/assets/index-v2.0.91.js';\n  noSelfieJs.type = 'module';\n  noSelfieJs.crossOrigin = 'anonymous';\n  noSelfieJs.onload = onJsLoadSuccess;\n  document.head.appendChild(noSelfieJs);\n\n  const noSelfieCss = document.createElement('link');\n  noSelfieCss.href = 'https://a.tangent.ai/quiz-inline/2.0.91/assets/index-v2.0.91.css';\n  noSelfieCss.rel = 'stylesheet';\n  noSelfieCss.type = 'text/css';\n  document.head.appendChild(noSelfieCss);\n}\n\nfunction loadTangentHairQuizScript() {\n  // Load the primary selfie-enabled quiz version. If it fails (due to geolocation restrictions),\n  // the error handler will load the no-selfie version instead.\n  const selfieJs = document.createElement('script');\n  selfieJs.src = 'https://a.tangent.ai/quiz-inline/2.0.91/assets/index-v2.0.91.js';\n  selfieJs.type = 'module';\n  selfieJs.crossOrigin = 'anonymous';\n  selfieJs.onerror = onSelfieJsLoadError;\n  selfieJs.onload = onJsLoadSuccess;\n  document.head.appendChild(selfieJs);\n}\n\n/**\n * Attaches event listeners for Tangent quiz events after the DOM is ready. These listeners handle\n * quiz progress tracking, initialization, and selfie upload responses.\n */\nfunction onReady() {\n  // If the quiz is configured to only show the no-selfie version, skip loading the default quiz\n  // script and directly load the no-selfie version of the quiz assets. This is used as a temporary\n  // solution to allow for testing of the no-selfie quiz variation while we work on a long-term\n  // solution to address the selfie step abandonment issue.\n  if (tangent_quiz.show_no_selfie_quiz_only) {\n    onSelfieJsLoadError();\n    return;\n  }\n\n  // We bootstrap the active quiz variation's email question index and ID on page load based on the\n  // presence of an active experiment and whether the quiz is in selfie or no-selfie mode. This\n  // allows us to properly track when the user reaches the lead form question to prefill known\n  // information and emit analytics events tied to the correct question.\n  activeQuizEmailIndex = tangent_quiz.with_selfie_email_index;\n  activeQuizEmailQuestionId = tangent_quiz.with_selfie_email_qid;\n\n  // Attempt to load with selfie quiz version by default. If the user is in a restricted location,\n  // the onerror handler will load the no-selfie version of the quiz instead.\n  loadTangentHairQuizScript();\n}\n\n// These listen in the capture phase on purpose. Tangent's quiz is a React app, and it swaps in the\n// next question while the click is still in flight, so by the time the event bubbles back up to\n// document the slide the user clicked is already gone. We measured a gap of 14ms between the two\n// phases, and in that gap the question text had changed and the clicked option had been detached.\n// Capture gets us in ahead of that, so we read the question the user was actually answering.\ndocument.addEventListener('click', onEmailSubmitClick, true);\ndocument.addEventListener('click', onAnswerOptionClick, true);\ndocument.addEventListener('click', onRetryClick, true);\n\nready(onReady);\n","/**\n * Releases the handle returned from the ready() function.\n *\n * This is idempotent. Additional calls are pointless but harmless.\n */\nexport type ReleaseHandle = () => void;\n\n/**\n * A subset of events that pertain to document ready state.\n */\ntype LoadingEventMap = Pick<DocumentEventMap, 'DOMContentLoaded' | 'load'>;\n\n/**\n * Calls the provided callback when the document is ready. This works both when the document is\n * already ready and when it is not, so callers do not have to care. This exists because it ensures\n * that each caller consistently expresses its dependency on document readiness, and to save a bit\n * of boilerplate.\n *\n * A document is considered ready when it has been parsed. This corresponds to the ready state of\n * 'interactive'. When the document has been fully loaded, the ready state is 'complete'. The\n * callback runs either way, so callers do not have to check which one they are in.\n *\n * Ready means the html is parsed and the DOM is there to query. It does not mean the page's other\n * scripts have run. Deferred scripts and module scripts run after the ready state turns\n * 'interactive' and before DOMContentLoaded fires, so a callback here can run before them. When a\n * caller needs some other script to have run already, this is the wrong tool, and it should wait on\n * whatever that script produces instead.\n *\n * That remedy has a catch of its own when the calling bundle is loaded with async. An async bundle\n * can execute after DOMContentLoaded has already fired, so a plain listener for that event never\n * runs and the work silently never happens. Nothing here can detect that, because by the time this\n * file executes the event is long gone. Catching it needs something registered at parse time,\n * before any bundle loads.\n *\n * There is a second trap right next to that one, and it applies only when waiting for\n * DOMContentLoaded. The ready state stays 'interactive' after DOMContentLoaded has fired, all the\n * way until 'complete', so the ready state cannot tell you whether DOMContentLoaded is still coming\n * or has already gone. Waiting for load is not exposed to this, because the ready state turns\n * 'complete' and load fires in the same task, so seeing 'complete' means load has fired too.\n *\n * When the document is already ready, the callback is invoked via setTimeout. This way, if the\n * callback throws, the error surfaces to the global error handler in a way that is similar to what\n * happens when an event listener throws.\n *\n * We might one day want to move this to an NPM library.\n *\n * Beware of a quirk here. setTimeout yields, and the busier the frontend, the longer it takes to\n * fire. Page load is exactly when the frontend is busiest. The timeout is a floor and not a\n * guarantee, so there is no real bound on how long that yield lasts. What this means is that using\n * this library can introduce more delay than you might expect. Compare code that runs on async load\n * and checks ready state and invokes immediately to code that runs after setTimeout. The former\n * runs in the same tick, the latter runs in \"some later tick\". That later tick can be surprisingly\n * much later. That can cause initial paint issues.\n *\n * @see https://developer.mozilla.org/en-US/docs/Web/API/Document/readyState\n * @see https://developer.mozilla.org/en-US/docs/Web/API/Document/DOMContentLoaded_event\n * @see https://html.spec.whatwg.org/multipage/parsing.html#the-end\n */\nexport function ready(callback: (event?: Event) => void,\n  type: keyof LoadingEventMap = 'DOMContentLoaded') {\n  if (document.readyState === 'complete' || (type === 'DOMContentLoaded' &&\n    document.readyState === 'interactive')) {\n    const timer = setTimeout(callback, 0);\n    const handle: ReleaseHandle = () => clearTimeout(timer);\n    return handle;\n  } else {\n    addEventListener(type, callback);\n    const handle: ReleaseHandle = () => removeEventListener(type, callback);\n    return handle;\n  }\n}\n"],"names":["rnds8","Uint8Array","byteToHex","i","push","toString","slice","unsafeStringify","arr","offset","toLowerCase","dist_v4","options","buf","crypto","randomUUID","_ref","_options$random","rnds","random","rng","getRandomValues","length","Error","RangeError","_v4","activeQuizEmailIndex","activeQuizEmailQuestionId","quizProgressIndex","preFillNameAndEmail","nameInput","document","querySelector","tangent_quiz","customer_name","forceReactInput","emailInput","customer_email","input","value","_Object$getOwnPropert","setter","Object","getOwnPropertyDescriptor","HTMLInputElement","prototype","set","call","key","keys","find","k","startsWith","props","onChange","currentTarget","target","type","lastSlideId","onQuizProgress","event","parts","detail","split","current","parseInt","total","currentSlideId","progress","Math","min","progressBar","getElementById","style","width","applyProgress","blocks","querySelectorAll","thresholds","index","classList","toggle","handleProgressLabel","setTimeout","questionTextBlock","optionBlockClass","optionsBlock","opacity","add","progressFill","percent","heading","forEach","text","textContent","start","Date","now","percentInterval","setInterval","elapsed","floor","clearInterval","handleLoadingAnimation","questionText","questionEl","no_selfie","trim","getQuestionText","questionId","hairEvent","CustomEvent","question_id","quiz_name","question_text","dispatchEvent","quizId","no_selfie_form_id","with_selfie_form_id","quizEvent","event_id","quiz_id","vendor","name","emitHairQuizQuestionViewedEvent","no_selfie_email_index","with_selfie_email_index","display","onQuizInitialized","_event","quiz_vendor","emitHairQuizStartedEvent","onJsLoadSuccess","addEventListener","onSelfieJsLoadError","no_selfie_email_qid","dataset","formid","noSelfieJs","createElement","src","crossOrigin","onload","head","appendChild","noSelfieCss","href","rel","Element","selector","submitEl","closest","emailEl","identityCaptured","bubbles","composed","email","option","optionText","innerText","answerValue","answer_value","responseEvent","answer_text","emitHairQuizQuestionResponseEvent","attributesContainer","innerHTML","selfieContainer","selfieImage","removeAttribute","callback","readyState","timer","clearTimeout","ready","show_no_selfie_quiz_only","with_selfie_email_qid","selfieJs","onerror","loadTangentHairQuizScript"],"sourceRoot":""}