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AAIS,OAChC,MAAM,IAAIE,WAAW,mBAAmBf,KAAUA,EAAS,8BAE/D,IAAK,IAAIN,EAAI,EAAGA,EAAI,KAAMA,EACtBU,EAAIJ,EAASN,GAAKe,EAAKf,GAE3B,OAAOU,CACX,CACA,OAAON,EAAgBW,EAC3B,CArBWO,CAAIb,EAASC,EAAKJ,GAFdK,OAAOC,YAGtB,ECgPA,MAAMW,EAAQ,IAAIC,YAAiD,yBAA0B,CAC3FC,OAAQ,CACNC,UAAWC,YAAYD,UACvBE,cAAe,SACfC,iBAAkBF,YAAYG,iBAAiBD,iBAC/CE,OAAQJ,YAAYK,cACpBC,SAA0B,OAAlBC,EAAEC,QAAQF,eAAQ,EAAhBC,EAAkBE,OAC5BC,SAAU7B,IACV8B,OAAQX,YAAYW,OACpBC,UAAWZ,YAAYG,iBAAiBU,MAAMC,KAAOd,YAAYe,mBACjEC,WAAYhB,YAAYiB,GACxBC,MAAOlB,YAAYkB,MACnBC,IAAKnB,YAAYG,iBAAiBgB,IAClCC,cAAepB,YAAYqB,MAC3BC,KAAMtB,YAAYsB,KAClBC,IAAKvB,YAAYG,iBAAiBoB,IAClCC,WAAYxB,YAAYG,iBAAiBc,GACzCQ,cAAezB,YAAYG,iBAAiBe,MAC5CQ,cAAe1B,YAAYG,iBAAiBkB,SAGhDM,cAAc/B","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/./snippets/product-view-observer/index.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';\n\ndeclare global {\n  /**\n   * This global is defined by the product view observer snippet. It is initialized via liquid.\n   *\n   * This variable should only be accessed by the javascript loaded by the product view observer\n   * snippet.\n   *\n   * @see https://shopify.dev/docs/api/liquid/objects/product\n   */\n  var pvo_product: {\n    /**\n     * Returns true if at least one of the variants of the product is available. Returns false if\n     * not.\n     */\n    available: boolean;\n\n    /**\n     * Whether there is a promotional discount code associated with the display of the product.\n     */\n    discount_code: string;\n\n    /**\n     * The first (featured) image attached to the product.\n     *\n     * @see https://shopify.dev/docs/api/liquid/objects/product#product-featured_image\n     */\n    featured_image_url: string;\n\n    /**\n     * The handle of the product.\n     *\n     * @see https://shopify.dev/docs/api/liquid/basics#handles\n     */\n    handle: string;\n\n    /**\n     * The ID of the product.\n     */\n    id: number;\n\n    /**\n     * In cents\n     */\n    price: number;\n\n    /**\n     * Returns true if all of the variants of the product require a selling plan. Returns false if\n     * not.\n     *\n     * A variant requires a selling plan if variant.requires_selling_plan is true.\n     */\n    requires_selling_plan: boolean;\n\n    /**\n     * The currently selected or first available variant of the product.\n     *\n     * The selected variant is determined by the variant URL parameter. The selected_variant\n     * parameter is available on product pages only.\n     *\n     * For a variant to be available, it needs to meet one of the following criteria:\n     *\n     * - The `variant.inventory_quantity` is greater than 1.\n     * - The `variant.inventory_policy` is set to continue.\n     * - The variant.inventory_management is nil.\n     *\n     * We are not capturing all of the variant's information here in globals. We want to limit\n     * exposure of certain properties like inventory to help prevent abuse and we do not want to\n     * bloat the HTML.\n     *\n     * @see https://shopify.dev/docs/api/liquid/objects/product\n     * @see https://shopify.dev/docs/api/liquid/objects/variant\n     */\n    selected_variant: {\n      /**\n       * The compare at price of the variant in the currency's subunit.\n       *\n       * The value is output in the customer's local (presentment) currency.\n       */\n      compare_at_price: number | null;\n\n      /**\n       * The ID of the variant.\n       */\n      id: number;\n\n      /**\n       * featured_image is the same as this property, so we only init this property in liquid\n       *\n       * we do not capture all properties because they are many.\n       */\n      image: {\n        src: string;\n      };\n\n      /**\n       * The price of the variant in the currency's subunit.\n       *\n       * The value is output in the customer's local (presentment) currency.\n       */\n      price: number;\n\n      /**\n       * The SKU of the variant.\n       */\n      sku: string;\n\n      /**\n       * A concatenation of each variant option, separated by a /.\n       */\n      title: string;\n\n      /**\n       * The URL of the variant.\n       *\n       * Variant URLs use the following structure:\n       *\n       * `/products/[product-handle]?variant=[variant-id]`\n       */\n      url: string;\n    };\n\n    /**\n     * The tags of the product.\n     *\n     * The tags are returned in alphabetical order.\n     */\n    tags: string[];\n\n    /**\n     * The title of the product.\n     */\n    title: string;\n\n    /**\n     * The type of the product.\n     */\n    type: string;\n\n    /**\n     * The relative URL of the product.\n     */\n    url: string;\n  };\n\n  interface WindowEventMap {\n    'product-bundle-viewed': ProductVariantViewedEvent;\n    'product-variant-viewed': ProductVariantViewedEvent;\n  }\n}\n\n/**\n * Fired when a specific product variant is viewed.\n */\ntype ProductVariantViewedEvent = CustomEvent<{\n  /** Whether the product is available for sale. This is based on available inventory. */\n  available: boolean;\n\n  bundling_type: 'single';\n\n  /**\n   * The original non-discounted price of the product variant being viewed.\n   */\n  compare_at_price?: number;\n\n  /** The coupon code that was applied to the product. */\n  coupon?: string;\n\n  /**\n   * @example \"USD\"\n   */\n  currency?: string;\n\n  event_id?: string;\n\n  handle?: string;\n\n  /** Collection id */\n  id?: number | string;\n\n  /**\n   * Image url. This is generally the relative image url of the variant, otherwise the product. The\n   * url will contain url parameters including the variant id, typically, when it is the url of the\n   * variant.\n   */\n  image_url?: string;\n\n  /** The price of the product in cents. */\n  price?: number;\n\n  /** Right now this is coming from the product metafield subtitle property */\n  product_description_override?: string;\n\n  /** The Shopify product id. */\n  product_id?: number;\n\n  /** The Shopify product title. */\n  product_title?: string;\n\n  /**\n   * An override of the Shopify product title\n   *\n   * For lange, this is probably the product metafield title property, which is configured for some\n   * products, and what is displayed visually on the product, even though it is not the product's\n   * configured title in the admin.\n   */\n  product_title_override?: string;\n\n  /** Collection products */\n  products?: any[];\n\n  /** The product variant's sku. */\n  sku?: string;\n\n  /**\n   * Comes from Shopify product type\n   *\n   * @example \"hair-care\"\n   */\n  type?: string;\n\n  /** Product page url. This might be a relative url. */\n  url?: string;\n\n  /** Shopify variant id. */\n  variant_id?: number;\n\n  /**\n   * The price of the selected variant, in cents.\n   *\n   * This is not the same as price, which is the product's price, meaning the lowest price across\n   * all of the variants. The two only agree when the selected variant happens to be the cheapest\n   * one.\n   */\n  variant_price?: number;\n\n  /** Shopify variant title. */\n  variant_title?: string;\n\n  /** An override of the variant title */\n  variant_title_override?: string;\n\n  /** The name of the vendor that manufactured the product. */\n  vendor?: string;\n}>;\n\nconst event = new CustomEvent<ProductVariantViewedEvent['detail']>('product-variant-viewed', {\n  detail: {\n    available: pvo_product.available,\n    bundling_type: 'single',\n    compare_at_price: pvo_product.selected_variant.compare_at_price,\n    coupon: pvo_product.discount_code,\n    currency: Shopify.currency?.active,\n    event_id: uuidv4(),\n    handle: pvo_product.handle,\n    image_url: pvo_product.selected_variant.image.src || pvo_product.featured_image_url,\n    product_id: pvo_product.id,\n    price: pvo_product.price,\n    sku: pvo_product.selected_variant.sku,\n    product_title: pvo_product.title,\n    type: pvo_product.type,\n    url: pvo_product.selected_variant.url,\n    variant_id: pvo_product.selected_variant.id,\n    variant_price: pvo_product.selected_variant.price,\n    variant_title: pvo_product.selected_variant.title\n  }\n});\ndispatchEvent(event);\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","product_view_observer_event","CustomEvent","detail","available","pvo_product","bundling_type","compare_at_price","selected_variant","coupon","discount_code","currency","_Shopify$currency","Shopify","active","event_id","handle","image_url","image","src","featured_image_url","product_id","id","price","sku","product_title","title","type","url","variant_id","variant_price","variant_title","dispatchEvent"],"sourceRoot":""}