{"version":3,"file":"brand-button.cjs","names":["videojs","version","SvgComponent","getComponent","log","createLogger","_updateHref","WeakMap","BrandButton","constructor","player","options","obj","merge","target","rel","_classPrivateFieldInitSpec","updateHref","on","_classPrivateFieldGet","dispose","off","createEl","tag","props","attributes","error","Error","title","href","getHref","localize","el","buildCSSClass","handleLanguagechange","VERSION","prototype","options_","iconName","registerComponent"],"sources":["../package.json","../src/brand-button.js"],"sourcesContent":["{\n  \"name\": \"@srgssr/brand-button\",\n  \"version\": \"1.2.0\",\n  \"license\": \"MIT\",\n  \"author\": \"SRG SSR\",\n  \"repository\": {\n    \"type\": \"git\",\n    \"url\": \"git+https://github.com/SRGSSR/pillarbox-web-suite.git\"\n  },\n  \"publishConfig\": {\n    \"access\": \"public\"\n  },\n  \"homepage\": \"https://github.com/SRGSSR/pillarbox-web-suite/tree/main/packages/brand-button#readme\",\n  \"type\": \"module\",\n  \"main\": \"dist/brand-button.cjs\",\n  \"browser\": \"dist/brand-button.umd.min.js\",\n  \"module\": \"dist/brand-button.js\",\n  \"style\": \"./dist/brand-button.min.css\",\n  \"exports\": {\n    \".\": {\n      \"import\": \"./dist/brand-button.js\",\n      \"require\": \"./dist/brand-button.cjs\"\n    },\n    \"./*\": \"./*\"\n  },\n  \"files\": [\n    \"dist/*\",\n    \"scss/*\"\n  ],\n  \"keywords\": [\n    \"video.js\",\n    \"player\"\n  ],\n  \"scripts\": {\n    \"clean\": \"rimraf dist\",\n    \"build\": \"npm-run-all clean build:*\",\n    \"build:css\": \"sass ./scss/brand-button.scss:dist/brand-button.min.css --style compressed --source-map --load-path node_modules\",\n    \"build:lib\": \"vite build --config vite.config.lib.js\",\n    \"build:umd\": \"vite build --config vite.config.umd.js\",\n    \"github:page\": \"vite build\",\n    \"release:ci\": \"semantic-release\",\n    \"start\": \" vite --port 4200 --open\",\n    \"test\": \"vitest run --silent --coverage --coverage.reporter text\"\n  },\n  \"dependencies\": {\n    \"@srgssr/svg-button\": \"^1.0.0\"\n  },\n  \"peerDependencies\": {\n    \"video.js\": \"^8.0.0\"\n  },\n  \"devDependencies\": {\n    \"@srgssr/pillarbox-web\": \"^1.24.1\"\n  }\n}\n","import videojs from 'video.js';\nimport '@srgssr/svg-button';\nimport { version } from '../package.json';\n\n/**\n * @ignore\n * @type {typeof import('@srgssr/svg-button').SvgComponent}\n */\nconst SvgComponent = videojs.getComponent('SvgComponent');\n\n/**\n * @ignore\n * @type {typeof import('video.js/dist/types/utils/log.js').default}\n */\nconst log = videojs.log.createLogger('brand-button');\n\n/**\n * Represents a BrandButton component for the video.js player.\n * Displays a clickable brand icon that redirects to a specified URL.\n */\nclass BrandButton extends SvgComponent {\n  /**\n   * A bound method for updating the href attribute.\n   * @private\n   */\n  #updateHref = () => this.updateHref();\n\n  /**\n   * Creates an instance of BrandButton.\n   *\n   * @param {import('video.js/dist/types/player.js').default} player - The Video.js player instance.\n   * @param {Object} [options={}] - Configuration options for the BrandButton.\n   * @param {string} [options.title] - The title (tooltip) text for the link element.\n   * @param {SVGElement|string|URL} options.icon - The SVG icon to display inside the button. Can be an SVGElement, a raw SVG string, or a URL (string or URL object).   * @param {string | ((player: import('video.js/dist/types/player.js').default) => string)} [options.href] - A static URL string or a callback function that receives the player instance and returns a URL.\n   * @param {string} [options.target='_blank'] - The target attribute for the link (e.g., '_blank', '_self').\n   * @param {string} [options.rel='noopener noreferrer'] - The rel attribute for the link, defining the relationship between the current page and the linked page.\n   */\n  constructor(player, options = {}) {\n    super(player, videojs.obj.merge({\n      target: '_blank',\n      rel: 'noopener noreferrer'\n    }, options));\n\n    this.player().on('loadeddata', this.#updateHref);\n  }\n\n  dispose() {\n    this.player().off('loadeddata', this.#updateHref);\n    super.dispose();\n  }\n\n  /**\n   * Constructs the DOM element that will be used to render the button.\n   * Ensures the element is an '<a>' and sets up the necessary properties.\n   *\n   * @param {string} [tag='a'] - The HTML tag name for the element. Must be 'a'.\n   * @param {Object} [props={}] - Additional properties to set on the element.\n   * @param {Object} [attributes={}] - Additional attributes to set on the element.\n   * @returns {HTMLAnchorElement} The created anchor element.\n   */\n  createEl(tag = 'a', props = {}, attributes = {}) {\n    if (tag !== 'a') {\n      log.error(`Creating a BrandButton with an HTML element of ${tag} is not supported; the element must be an 'a'`);\n      throw new Error(`'${tag}' is not supported for BrandButton`);\n    }\n\n    const { title, target, rel } = this.options();\n\n    return super.createEl(\n      tag,\n      props,\n      videojs.obj.merge({\n        href: this.getHref(),\n        title: this.localize(title),\n        target,\n        rel\n      }, attributes)\n    );\n  }\n\n  /**\n   * Returns the href for the button, resolving callbacks if necessary.\n   *\n   * @returns {string} The resolved href URL.\n   */\n  getHref() {\n    if (typeof this.options().href === 'string') {\n      return this.options().href || '';\n    }\n\n    if (typeof this.options().href === 'function') {\n      try {\n        return this.options().href(this.player());\n      } catch (error) {\n        log.error('Error executing the href callback:', error);\n      }\n    }\n\n    return '';\n  }\n\n  /**\n   * Updates the href attribute of the button element dynamically.\n   */\n  updateHref() {\n    this.el().href = this.getHref();\n  }\n\n  /**\n   * Builds the CSS class string for the button.\n   *\n   * @returns {string} The CSS class string.\n   */\n  buildCSSClass() {\n    return `vjs-brand-button vjs-control ${super.buildCSSClass()}`;\n  }\n\n  /**\n   * Updated the link title when a language change is detected.\n   */\n  handleLanguagechange() {\n    this.el().title = this.localize(this.options().title);\n  }\n\n  /**\n   * Returns the current version of the BrandButton component.\n   *\n   * @static\n   * @returns {string} The version string.\n   */\n  static get VERSION() {\n    return version;\n  }\n}\n\nBrandButton.prototype.options_ = {\n  iconName: 'brand-button'\n};\n\nvideojs.registerComponent('BrandButton', BrandButton);\n\nexport default BrandButton;\n"],"mappings":"u2DCQME,EAAeF,EAAAA,QAAQG,aAAa,cAAc,EAMlDC,EAAMJ,EAAAA,QAAQI,IAAIC,aAAa,cAAc,EAEnDC,EAAA,IAAAC,QAIMC,EAAN,cAA0BN,CAAa,CAiBrCO,YAAYC,EAAQC,EAAU,CAAC,EAAG,CAChC,MAAMD,EAAQV,EAAAA,QAAQY,IAAIC,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