[
  {
    "path": ".github/FUNDING.yml",
    "content": "github: yireo\ncustom: [\"https://www.paypal.me/yireo\"]\n\n"
  },
  {
    "path": ".github/workflows/compile.yml",
    "content": "name: Magento 2 DI compilation\non: ['push', 'pull_request']\n\njobs:\n  compile:\n    name: Magento 2 DI compilation\n    #runs-on: self-hosted\n    runs-on: ubuntu-latest\n    strategy:\n      matrix:\n        magento_version: ['2.4.5-p14', '2.4.7-p4', '2.4.7-p7', '2.4.8', '2.4.8-p1', '2.4.8-p2', '2.4.8-p3']\n    container:\n      image: yireo/magento2installed:${{ matrix.magento_version }}\n    steps:\n      - name: Checkout sources\n        uses: actions/checkout@v4\n\n      - name: Configure Yireo GitLab\n        run: |\n          test -n \"${{ secrets.GITLAB_TOKEN }}\" || exit 0\n          cd /tmp/magento\n          composer config gitlab-domains gitlab.yireo.com\n          composer config --global --auth http-basic.gitlab.yireo.com yireo \"${{ secrets.GITLAB_TOKEN }}\"\n          composer config repositories.loki-third-party composer https://gitlab.yireo.com/api/v4/group/loki-third-party/-/packages/composer/packages.json\n          composer config repositories.loki-checkout composer https://gitlab.yireo.com/api/v4/group/loki-checkout/-/packages/composer/packages.json\n\n      - name: Add module source\n        run: |\n          COMPOSER_NAME=$(grep '^COMPOSER_NAME=' .module.ini | cut -d= -f2- | tr -d '\"')\n          cp -R ${GITHUB_WORKSPACE} /tmp/magento/package-source\n          cd /tmp/magento\n          composer config repositories.local-source path package-source/\n          composer require --prefer-source ${COMPOSER_NAME}:@dev\n\n      - name: Run Magento 2 compilation\n        run: |\n          cd /tmp/magento\n          bin/magento module:enable --all\n          php -dmemory_limit=-1 bin/magento setup:di:compile\n\n"
  },
  {
    "path": ".github/workflows/integration-tests/etc/install-config-mysql.php",
    "content": "<?php // phpcs:ignoreFile\n\nuse Yireo\\IntegrationTestHelper\\Utilities\\DisableModules;\nuse Yireo\\IntegrationTestHelper\\Utilities\\InstallConfig;\n\n$disableModules = (new DisableModules(__DIR__.'/../../../../'))\n    ->disableAll()\n    ->enableMagento()\n    ->disableByPattern('SampleData')\n    ->disableByPattern('Magento_TestModule')\n    ->disableMagentoInventory()\n    ->disableGraphQl()\n    ->enableByMagentoModuleEnv();\n\nreturn (new InstallConfig())\n    ->setDisableModules($disableModules)\n    ->addDb('mysql', 'magento2', 'magento2', 'magento2')\n    ->addRedis('redis')\n    ->addElasticSearch('opensearch', 'opensearch', 9200)\n    ->get();\n"
  },
  {
    "path": ".github/workflows/integration-tests/etc/mysql-client-config.php",
    "content": "<?php // phpcs:ignoreFile\n\nreturn [\n    'client-mariadb' => [\n        'disable-ssl',\n    ],\n];\n\n"
  },
  {
    "path": ".github/workflows/integration-tests/phpunit10.xml",
    "content": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!--\n/**\n * Copyright © Magento, Inc. All rights reserved.\n * See COPYING.txt for license details.\n */\n-->\n<phpunit xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n         xsi:noNamespaceSchemaLocation=\"https://schema.phpunit.de/10.4/phpunit.xsd\"\n         colors=\"true\"\n         columns=\"max\"\n         beStrictAboutTestsThatDoNotTestAnything=\"false\"\n         bootstrap=\"./framework/bootstrap.php\"\n         stderr=\"true\">\n    <testsuites>\n        <testsuite name=\"LokiCheckout\">\n            <directory>../../../app/code/Yireo/LokiCheckout*/Test/Integration</directory>\n            <directory>../../../vendor/yireo/magento2-loki-checkout*/Test/Integration</directory>\n        </testsuite>\n    </testsuites>\n    <php>\n        <includePath>.</includePath>\n        <includePath>testsuite</includePath>\n        <ini name=\"date.timezone\" value=\"America/Los_Angeles\"/>\n        <ini name=\"xdebug.max_nesting_level\" value=\"200\"/>\n        <const name=\"TESTS_INSTALL_CONFIG_FILE\" value=\"etc/install-config-mysql.php\"/>\n        <const name=\"TESTS_GLOBAL_CONFIG_FILE\" value=\"etc/config-global.php\"/>\n        <const name=\"TESTS_GLOBAL_CONFIG_DIR\" value=\"../../../app/etc\"/>\n        <const name=\"TESTS_POST_INSTALL_SETUP_COMMAND_CONFIG_FILE\" value=\"etc/post-install-setup-command-config.php\"/>\n        <const name=\"TESTS_CLEANUP\" value=\"enabled\"/>\n        <const name=\"TESTS_MEM_USAGE_LIMIT\" value=\"8192M\"/>\n        <const name=\"TESTS_MEM_LEAK_LIMIT\" value=\"\"/>\n        <const name=\"TESTS_EXTRA_VERBOSE_LOG\" value=\"1\"/>\n        <const name=\"TESTS_MAGENTO_MODE\" value=\"developer\"/>\n        <const name=\"TESTS_ERROR_LOG_LISTENER_LEVEL\" value=\"-1\"/>\n        <const name=\"USE_OVERRIDE_CONFIG\" value=\"enabled\"/>\n    </php>\n    <extensions>\n        <bootstrap class=\"Magento\\TestFramework\\Event\\Subscribers\"/>\n    </extensions>\n</phpunit>\n"
  },
  {
    "path": ".github/workflows/integration-tests/phpunit9.xml",
    "content": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<phpunit xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n         xsi:noNamespaceSchemaLocation=\"http://schema.phpunit.de/9.6/phpunit.xsd\"\n         colors=\"true\"\n         beStrictAboutTestsThatDoNotTestAnything=\"false\"\n         bootstrap=\"./framework/bootstrap.php\"\n         stderr=\"true\"\n>\n    <testsuites>\n        <testsuite name=\"LokiCheckout\">\n            <directory>../../../app/code/Yireo/LokiCheckout*/Test/Integration</directory>\n            <directory>../../../vendor/yireo/magento2-loki-checkout*/Test/Integration</directory>\n        </testsuite>\n    </testsuites>\n    <php>\n        <includePath>.</includePath>\n        <includePath>testsuite</includePath>\n        <ini name=\"date.timezone\" value=\"America/Los_Angeles\"/>\n        <ini name=\"xdebug.max_nesting_level\" value=\"200\"/>\n        <const name=\"TESTS_INSTALL_CONFIG_FILE\" value=\"etc/install-config-mysql.php\"/>\n        <const name=\"TESTS_GLOBAL_CONFIG_FILE\" value=\"etc/config-global.php\"/>\n        <const name=\"TESTS_GLOBAL_CONFIG_DIR\" value=\"../../../app/etc\"/>\n        <const name=\"TESTS_POST_INSTALL_SETUP_COMMAND_CONFIG_FILE\" value=\"etc/post-install-setup-command-config.php\"/>\n        <const name=\"TESTS_CLEANUP\" value=\"enabled\"/>\n        <const name=\"TESTS_MEM_USAGE_LIMIT\" value=\"8192M\"/>\n        <const name=\"TESTS_MEM_LEAK_LIMIT\" value=\"\"/>\n        <const name=\"TESTS_EXTRA_VERBOSE_LOG\" value=\"1\"/>\n        <const name=\"TESTS_MAGENTO_MODE\" value=\"developer\"/>\n        <const name=\"TESTS_ERROR_LOG_LISTENER_LEVEL\" value=\"-1\"/>\n    </php>\n     <listeners>\n         <listener class=\"Magento\\TestFramework\\Event\\PhpUnit\"/>\n         <listener class=\"Magento\\TestFramework\\ErrorLog\\Listener\"/>\n     </listeners>\n</phpunit>\n"
  },
  {
    "path": ".github/workflows/integration-tests.yml",
    "content": "name: Magento 2 Integration Tests\non: ['push', 'pull_request']\n\njobs:\n  integration-tests:\n    name: Magento 2 Integration Tests\n    #runs-on: self-hosted\n    runs-on: ubuntu-latest\n    container:\n      image: yireo/magento2installed:2.4.8-p3\n    services:\n      mysql:\n        image: yireo/mariadb:10\n        env:\n          MYSQL_ROOT_PASSWORD: root\n          MYSQL_USER: magento2\n          MYSQL_PASSWORD: magento2\n          MYSQL_DATABASE: magento2\n        options: --tmpfs /tmp:rw --tmpfs /var/lib/mysql:rw --health-cmd=\"mysqladmin ping\" \n      opensearch:\n        image: yireo/opensearch:latest\n        env:\n          'discovery.type': single-node\n          ES_JAVA_OPTS: \"-Xms256m -Xmx256m\"\n        options: --health-cmd=\"curl localhost:9200/_cluster/health?wait_for_status=yellow&timeout=60s\" --health-interval=10s --health-timeout=5s --health-retries=3\n      redis:\n        image: redis\n        options: --health-cmd \"redis-cli ping\" --health-interval 10s --health-timeout 5s --health-retries 5\n    steps:\n      - name: Checkout sources\n        uses: actions/checkout@v4\n\n      - name: Apply patch for reporting memory under Alpine\n        run: cd /tmp/magento && curl -fsSL https://patch-diff.githubusercontent.com/raw/magento/magento2/pull/39216.diff | git apply\n\n      - name: Apply patch for changing MySQL client configuration\n        run: cd /tmp/magento && curl -fsSL https://patch-diff.githubusercontent.com/raw/magento/magento2/pull/40410.diff | git apply\n\n      - name: Configure GitLab\n        run: |\n          test -n \"${{ secrets.GITLAB_TOKEN }}\" || exit 0\n          cd /tmp/magento\n          composer config --auth gitlab-token.gitlab.yireo.com ${{ secrets.GITLAB_TOKEN }}\n          composer config repositories.loki-checkout composer https://gitlab.yireo.com/api/v4/group/loki-checkout/-/packages/composer/packages.json\n\n      - name: Add module source\n        run: |\n          export COMPOSER_NAME=`cat .module.ini | grep COMPOSER_NAME | cut -f2 -d= | tr -d '\"'`\n          cp -R ${GITHUB_WORKSPACE} /tmp/magento/package-source\n          cd /tmp/magento\n          composer config repositories.local-source path package-source/\n          composer require --prefer-source -- ${COMPOSER_NAME}:@dev yireo/magento2-integration-test-helper\n\n      - name: Run Magento 2 Integration Tests\n        run: |\n          test -d $GITHUB_WORKSPACE/Test/Integration || exit 0\n          export EXTENSION_VENDOR=`cat .module.ini | grep EXTENSION_VENDOR | cut -f2 -d= | tr -d '\"'`\n          export EXTENSION_NAME=`cat .module.ini | grep EXTENSION_NAME | cut -f2 -d= | tr -d '\"'`\n          export COMPOSER_NAME=`cat .module.ini | grep COMPOSER_NAME | cut -f2 -d= | tr -d '\"'`\n          export MAGENTO_MODULE=${EXTENSION_VENDOR}_${EXTENSION_NAME}\n          cd /tmp/magento/dev/tests/integration/\n          cp -R ${GITHUB_WORKSPACE}/.github/workflows/integration-tests/* .\n          php ../../../vendor/bin/phpunit --atleast-version 9 && cp phpunit9.xml phpunit.xml\n          php ../../../vendor/bin/phpunit --atleast-version 10 && cp phpunit10.xml phpunit.xml\n          php -d memory_limit=4G ../../../vendor/bin/phpunit -c phpunit.xml ../../../vendor/$COMPOSER_NAME/Test/Integration\n\n"
  },
  {
    "path": ".github/workflows/static-tests.yml",
    "content": "name: Magento 2 Static Tests\non: ['push', 'pull_request']\n\njobs:\n  phpcs:\n    name: Magento PHPCS\n    runs-on: ubuntu-latest\n    container:\n        image: yireo/magento2installed:2.4.8-p3\n    steps:\n      - name: Checkout sources\n        uses: actions/checkout@v4\n\n      - name: Run Magento 2 PHPCS Tests\n        run: |\n          PHPCS_LEVEL=${{ env.PHPCS_LEVEL }}\n          test -z \"$PHPCS_LEVEL\" && PHPCS_LEVEL=$(jq -r '.phpcs_severity // 10' MODULE.json)\n          test -z \"$PHPCS_LEVEL\" && PHPCS_LEVEL=10\n          echo \"Testing for PHPCS severity $PHPCS_LEVEL\"\n          cd /tmp/magento\n          php vendor/bin/phpcs --standard=Magento2 --ignore=Test/,node_modules/ --colors --extensions=php,phtml --severity=$PHPCS_LEVEL ${GITHUB_WORKSPACE}\n\n  phpstan:\n    name: Magento PHPStan\n    runs-on: ubuntu-latest\n    container:\n        image: yireo/magento2installed:2.4.8-p3\n    steps:\n      - name: Checkout sources\n        uses: actions/checkout@v4\n\n      - name: Configure GitLab\n        run: |\n          test -n \"${{ secrets.GITLAB_TOKEN }}\" || exit 0\n          cd /tmp/magento\n          composer config gitlab-domains gitlab.yireo.com\n          composer config --auth gitlab-token.gitlab.yireo.com ${{ secrets.GITLAB_TOKEN }}\n          composer config repositories.loki-checkout composer https://gitlab.yireo.com/api/v4/group/loki-checkout/-/packages/composer/packages.json\n\n      - name: Add module source\n        run: |\n          export COMPOSER_NAME=`cat .module.ini | grep COMPOSER_NAME | cut -f2 -d= | tr -d '\"'`\n          export COMPOSER_DEV_REQUIREMENTS=`jq -r '.[\"require-dev\"] // {} | to_entries | map(\"\\(.key):\\(.value)\") | join(\" \")' composer.json`\n          cp -R ${GITHUB_WORKSPACE} /tmp/magento/package-source\n          cd /tmp/magento\n          composer config repositories.local-source path package-source/\n          composer config --no-plugins allow-plugins true\n          composer remove --dev magento/magento-coding-standard\n          test -z \"$COMPOSER_DEV_REQUIREMENTS\" || composer require --dev $COMPOSER_DEV_REQUIREMENTS\n          composer require --dev --prefer-source -- phpstan/phpstan:^2.0 bitexpert/phpstan-magento:^0.42 phpstan/extension-installer\n          composer require --prefer-source -- ${COMPOSER_NAME}:@dev yireo/magento2-integration-test-helper\n\n      - name: Run Magento 2 PHPStan Tests\n        run: |\n          export COMPOSER_NAME=`cat .module.ini | grep COMPOSER_NAME | cut -f2 -d= | tr -d '\"'`\n          export PHPSTAN_LEVEL=$(jq -r '.phpstan_level // 1' MODULE.json)\n          test -z \"$PHPSTAN_LEVEL\" && PHPSTAN_LEVEL=1\n          test -f /tmp/magento/phpstan.neon || echo 'parameters:' > /tmp/magento/phpstan.neon\n          echo \"Testing for PHPStan level $PHPSTAN_LEVEL\"\n          cd /tmp/magento\n          export MODULE_PATH=$(realpath vendor/${COMPOSER_NAME})\n          php -d memory_limit=4G vendor/bin/phpstan analyse --level $PHPSTAN_LEVEL $MODULE_PATH\n\n"
  },
  {
    "path": ".github/workflows/unit-tests.yml",
    "content": "name: Magento 2 Unit Tests\non: ['push', 'pull_request']\n\njobs:\n  unit-tests:\n    name: Magento 2 Unit Tests\n    #runs-on: self-hosted\n    runs-on: ubuntu-latest\n    container:\n        image: yireo/magento2installed:2.4.8-p3\n    steps:\n      - name: Checkout sources\n        uses: actions/checkout@v4\n\n      - name: Configure GitLab\n        run: |\n          test -n \"${{ secrets.GITLAB_TOKEN }}\" || exit 0\n          cd /tmp/magento\n          composer config --auth gitlab-token.gitlab.yireo.com ${{ secrets.GITLAB_TOKEN }}\n          composer config repositories.loki-checkout composer https://gitlab.yireo.com/api/v4/group/loki-checkout/-/packages/composer/packages.json\n\n      - name: Add module source\n        run: |\n          export COMPOSER_NAME=`cat .module.ini | grep COMPOSER_NAME | cut -f2 -d= | tr -d '\"'`\n          test -z \"$COMPOSER_NAME}\" && (echo \"No composer name found\" && exit 1)\n          cp -R $GITHUB_WORKSPACE /tmp/magento/package-source\n          cd /tmp/magento\n          composer config repositories.local-source path package-source/\n          composer require --prefer-source -W -- $COMPOSER_NAME:@dev\n\n      - name: Run Magento 2 Unit Tests\n        run: |\n          test -d $GITHUB_WORKSPACE/Test/Unit || exit 0\n          export COMPOSER_NAME=`cat .module.ini | grep COMPOSER_NAME | cut -f2 -d= | tr -d '\"'`\n          cd /tmp/magento/dev/tests/unit/\n          php -d memory_limit=4G ../../../vendor/bin/phpunit -c phpunit.xml.dist ../../../vendor/$COMPOSER_NAME/Test/Unit\n \n"
  },
  {
    "path": ".gitignore",
    "content": ""
  },
  {
    "path": ".magento/dev/tests/integration/etc/install-config-mysql.phps",
    "content": "<?php\n/**\n * Copyright © Magento, Inc. All rights reserved.\n * See COPYING.txt for license details.\n */\n\nreturn [\n    'db-host' => '%MYSQL_HOST%',\n    'db-user' => 'root',\n    'db-password' => 'root',\n    'db-name' => 'magento-integration-test',\n    'db-prefix' => '',\n    'backend-frontname' => 'backend',\n    'admin-user' => \\Magento\\TestFramework\\Bootstrap::ADMIN_NAME,\n    'admin-password' => \\Magento\\TestFramework\\Bootstrap::ADMIN_PASSWORD,\n    'admin-email' => \\Magento\\TestFramework\\Bootstrap::ADMIN_EMAIL,\n    'admin-firstname' => \\Magento\\TestFramework\\Bootstrap::ADMIN_FIRSTNAME,\n    'admin-lastname' => \\Magento\\TestFramework\\Bootstrap::ADMIN_LASTNAME,\n];\n"
  },
  {
    "path": ".magento/dev/tests/integration/phpunit.xml",
    "content": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<phpunit xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n         xsi:noNamespaceSchemaLocation=\"https://schema.phpunit.de/9.1/phpunit.xsd\"\n         colors=\"true\"\n         beStrictAboutTestsThatDoNotTestAnything=\"false\"\n         bootstrap=\"./framework/bootstrap.php\"\n         stderr=\"true\"\n>\n    <testsuites>\n        <testsuite name=\"App\">\n            <directory suffix=\"Test.php\">../../../vendor/yireo/*/Test/Integration</directory>\n        </testsuite>\n    </testsuites>\n    <filter>\n        <whitelist>\n            <directory suffix=\".php\">../../../vendor/yireo</directory>\n            <exclude>\n                <directory>../../../vendor/yireo/*/Test</directory>\n            </exclude>\n        </whitelist>\n    </filter>\n    <php>\n        <includePath>.</includePath>\n        <includePath>testsuite</includePath>\n        <ini name=\"date.timezone\" value=\"America/Los_Angeles\"/>\n        <ini name=\"xdebug.max_nesting_level\" value=\"200\"/>\n        <const name=\"TESTS_INSTALL_CONFIG_FILE\" value=\"etc/install-config-mysql.php\"/>\n        <const name=\"TESTS_GLOBAL_CONFIG_FILE\" value=\"etc/config-global.php\"/>\n        <const name=\"TESTS_GLOBAL_CONFIG_DIR\" value=\"../../../app/etc\"/>\n        <const name=\"TESTS_CLEANUP\" value=\"enabled\"/>\n        <const name=\"TESTS_MEM_USAGE_LIMIT\" value=\"1024M\"/>\n        <const name=\"TESTS_MEM_LEAK_LIMIT\" value=\"\"/>\n        <const name=\"TESTS_EXTRA_VERBOSE_LOG\" value=\"0\"/>\n        <const name=\"TESTS_MAGENTO_MODE\" value=\"developer\"/>\n        <const name=\"TESTS_ERROR_LOG_LISTENER_LEVEL\" value=\"-1\"/>\n    </php>\n</phpunit>\n"
  },
  {
    "path": ".magento/dev/tests/unit/phpunit.xml",
    "content": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<phpunit xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n         xsi:noNamespaceSchemaLocation=\"http://schema.phpunit.de/6.2/phpunit.xsd\"\n         colors=\"true\"\n         beStrictAboutTestsThatDoNotTestAnything=\"false\"\n         bootstrap=\"../../../vendor/autoload.php\"\n         stderr=\"true\"\n>\n    <testsuites>\n        <testsuite name=\"App\">\n            <directory suffix=\"Test.php\">../../../app/code/*/*/Test/Unit</directory>\n        </testsuite>\n    </testsuites>\n    <filter>\n        <whitelist>\n            <directory suffix=\".php\">../../../app/code</directory>\n            <exclude>\n                <directory>../../../app/code/*/*/Test</directory>\n            </exclude>\n        </whitelist>\n    </filter>\n    <php>\n        <includePath>.</includePath>\n        <includePath>testsuite</includePath>\n        <ini name=\"date.timezone\" value=\"America/Los_Angeles\"/>\n        <ini name=\"xdebug.max_nesting_level\" value=\"200\"/>\n    </php>\n</phpunit>\n"
  },
  {
    "path": ".module.ini",
    "content": "EXTENSION_VENDOR=\"Yireo\"\nEXTENSION_NAME=\"Webp2\"\nMODULE_NAME=\"Yireo_Webp2\"\nCOMPOSER_NAME=\"yireo/magento2-webp2\"\nPHP_VERSIONS=(\"7.4\", \"8.1\", \"8.2\")\n"
  },
  {
    "path": "CHANGELOG.md",
    "content": "# Changelog\nAll notable changes to this project will be documented in this file.\n\nThe format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),\nand this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).\n\n## [Unreleased]\n\n## [0.14.3] - 24 October 2024\n### Fixed\n- Add funding\n\n## [0.14.2] - 23 August 2024\n### Fixed\n- Guarantee return type is string #170\n\n## [0.14.1] - 23 August 2024\n### Fixed\n- Add CSP nonces to inline scripts\n\n## [0.14.0] - 20 June 2024\n### Fixed\n- Move GraphQL support in seperate [module](https://github.com/yireo/Yireo_Webp2GraphQl)\n\n## [0.13.5] - 4 April 2024\n### Fixed\n- Compatibility with Magento >=2.4.7-beta3\n\n## [0.13.4] - 26 September 2023\n### Fixed\n- Catch the correct exception when using properties of a specific exception.\n\n## [0.13.3] - 22 September 2023\n### Fixed\n- Properly check for MIME-typed (fix of #149)\n- Add \"webp\" / \"nowebp\" to body class for Hyva\n\n## [0.13.2] - 6 September 2023\n### Fixed\n- Make sure convertor is called for unsupported types #149 (@kernstmediarox)\n\n## [0.13.1] - 6 September 2023\n### Fixed\n- Remove non-existing `description` in exception handling\n- Move Hyva dependency to separate package `yireo/magento2-webp2-for-hyva`\n\n## [0.13.0] - 30 August 2023\n### Added\n- Copied GraphQL `url_webp` from Hyva compatibility module to here\n\n### Fixed\n- Catch exceptions in converters by changing array to string with a foreach (@ghezelbash PR #140)\n\n## [0.12.5] - 19 March 2023\n### Fixed\n- Version bump because of new NextGenImages minor\n\n## [0.12.4] - 13 September 2022\n### Fixed\n- Implement the NextGenImages config setting `convert_images`\n\n## [0.12.3] - 20 August 2022\n### Fixed\n- Add missing semicolon #130\n\n## [0.12.2] - 21 July 2022\n### Fixed\n- Using JS native `_determineProductData` function #120 (@artbambou)\n- Fix uncaught exception #127 (@jakegore)\n\n## [0.12.1] - 2 June 2022\n### Fixed\n- Skip image replacement if target URL is still empty\n\n## [0.12.0] - 4 May 2022\n### Added\n- Added ACL for user permissions (@jeroenalewijns)\n- Always add `webp` CSS class to body via JS detection\n- Add various integration tests\n- Refactoring because of changed NextGenImages API\n\n### Removed\n- Moved AJAX plugin for swatches to NextGenImages\n\n## [0.11.4] - 23 August 2021\n### Fixed\n- Check for double InvalidInputImageTypeException\n\n## [0.11.3] - 23 August 2021\n### Fixed\n- Fix wrong exception being caught\n\n## [0.11.2] - 11 August 2021\n### Fixed\n- Remove async from function (IE11 Support) (@barryvdh)\n\n## [0.11.1] - 10 August 2021\n### Fixed\n- Fix error to config.xml introduced in last version (@chrisastley)\n\n## [0.11.0] - 9 August 2021\n### Added\n- New option `encoding` for better performance with only `lossy` (@basvanpoppel)\n\n## [0.10.11] - 15 July 2021\n### Fixed\n- Prevent exception when GIF is renamed to JPG\n\n## [0.10.10] - 7 July 2021\n### Fixed\n- Hide all other fields if setting \"Enabled\" is set to 0\n- Add current store to all methods\n\n## [0.10.9] - 24 June 2021\n### Fixed\n- Fix PHP Notice when gallery is missing\n\n## [0.10.8] - 24 June 2021\n### Fixed\n- Allow configuring convertors (#77)\n\n## [0.10.7] - 6 May 2021\n### Fixed\n- Prevents error if variable $imageData[$imageType] is empty (@maksymcherevko)\n\n## [0.10.6] - 2 April 2021\n### Fixed\n- Webp images not being generated if cached jpg does not exist yet #70 (@gtlt)\n\n## [0.10.5] - 9 March 2021\n### Fixed\n- Refactor conversion errors\n- Move helper function to NextGenImages\n- Throw exception when no conversion is needed\n- Update convertor class to comply to updated interface\n\n## [0.10.4] - 15 February 2021\n### Fixed\n- Log all exceptions to NextGenImages logger\n\n## [0.10.3] - 12 February 2021\n### Fixed\n- Make sure configurable images don't throw exception\n\n## [0.10.2] - 12 February 2021\n### Fixed\n- Make sure wrong gallery images don't throw exception\n\n## [0.10.1] - 11 February 2021\n### Fixed\n- Fix JS error\n- Rewrite into synchronous way of detecting WebP\n\n\n## [0.10.0] - 28 January 2021\n### Added\n- Improved support on product detail page (configurable swatches + fotorama)\n\n## [0.9.6] - 22 January 2021\n### Fixed\n- When no .webp file is available, the source tag will be removed to prevent old image being shown on the frontend (@ar-vie)\n\n\n## [0.9.5] - 3 December 2020\n### Fixed\n- Remove class UrlReplacer again after refactoring NextGenImages\n\n## [0.9.4] - 3 December 2020\n### Fixed\n- Fix missing class UrlReplacer\n\n## [0.9.3] - 2 December 2020\n### Fixed\n- Fix composer deps with magento2-next-gen-images\n\n## [0.9.2] - 30 November 2020\n### Fixed\n- Stick to new ConvertorInterface interface of NextGenImages\n\n## [0.9.1] - 30 November 2020\n### Fixed\n- Wrong composer dependency with NextGenImages\n\n## [0.9.0] - 30 November 2020\n### Removed\n- Remove JavaScript check and Browser class\n- Moved code from this module to generic NextGenImages module\n- Remove Travis CI script\n\n## [0.8.0] - 30 November 2020\n### Fixed\n- Lazy loading configuration option was not working\n\n### Added\n- Add new option for quality level\n\n## [0.7.6] - 19 August 2020\n### Fixed\n- Fixes wrong name in require-js config (@johannessmit)\n\n## [0.7.5] - 13 August 2020\n### Fixed\n- Add jQuery Cookie to prevent load order issues (@basvanpoppel)\n\n## [0.7.4] - 3 August 2020\n### Fixed\n- Image is correctly updated including the source (@johannessmit)\n\n### Removed\n- Undo of `parse_url` Laminas replacement because this breaks pre-Laminas Magento releases\n\n## [0.7.3] - 29 July 2020\n### Added\n- Magento 2.4 support \n\n### Fixed\n- Numerous PHPCS issues\n\n### Added\n- URL parsing via laminas/laminas-uri package\n\n## [0.7.2] - June 13th, 2020\n### Fixed\n- Remove alt attribute from picture element (@gjportegies)\n\n## [0.7.1] - April 6th, 2020\n### Added\n- Quick fix to allow for WebP images in catalog swatches\n\n## [0.7.0] - March 31st, 2020\n### Added\n- Code refactoring to allow for Amasty Shopby compatibility\n\n## [0.6.2] - March 18th, 2020\n### Fixed\n- Skip captcha images (PR from @jasperzeinstra)\n\n## [0.6.1] - March 18th, 2020\n### Fixed\n- Do not throw error in debugging with non-existing images\n- Rename \"Debug Log\" to \"Debugging\" because that's what's happening\n\n## [0.6.0] - March 7th, 2020\n### Added\n- Skipping WebP image creation by configuration option\n\n## [0.5.2] - March 5th, 2020\n### Fixed\n- Fix next tag not being closed properly\n\n## [0.5.1] - February 19th, 2020\n### Fixed\n- Prevent overwriting existing `picture` tags\n\n## [0.5.0] - February 11th, 2020\n### Added\n- Upgraded rosell-dk/webp-convert library\n\n## [0.4.7] - January 31st, 2020\n### Added\n- Add class attribute in picture (PR from itsazzad)\n- Better support info\n- Raise framework requirements for proper support of ViewModels\n- Added logic for fetching the css class from the original image (PR from duckchip)\n- Added missing  variable in the ReplaceTags plugin (PR from duckchip)\n\n## [0.4.6] - November 23rd, 2019\n### Fixed\n- Raise requirements for proper support of ViewModels\n\n## [0.4.5] - October 16th, 2019\n### Added\n- Add check for additional layout handle `webp_skip` \n\n## [0.4.4] - October 15th, 2019\n### Fixed\n- Dirty workaround for email layout \n \n## [0.4.3] - October 4th, 2019\n### Added\n- Add controller for email testing\n\n### Fixed\n- Do not apply WebP if no handles\n\n## [0.4.2] - July 14th, 2019\n### Fixed\n- Make sure modified gallery images are returned as Collection, not an array\n- Test with Aimes_Notorama\n\n## [0.4.1] - July 2019\n### Fixed\n- Original tag (with custom styling) was not used in `picture` element, but new one was created instead\n\n## [0.4.0] - July 2019\n### Added\n- Move configuration to separate **Yireo** section\n- Add a `config.xml` file\n- Changed configuration path from `system/yireo_webp2/*` to `yireo_webp2/settings/*`\n- Move `quality_level` to `config.xml`\n\n## [0.3.0] - 2019-05-02\n### Fixed\n- Fix issue with additional images not being converted if already converted (@jove4015)\n- Fix issue with static versioning not being reckognized\n- Make sure src, width and height still remain in picture-tag\n\n### Added\n- Integration test for multiple instances of same image\n- Add fields in backend for PHP version and module version\n- Integration Test to test conversion of test-files\n- Throw an exception of source file is not found\n- Add provider of dummy images\n- Add integration test of dummy images page\n- Add test page with dummy images\n- Only show original image in HTML source when debugging\n\n## [0.2.0] - 2019-04-28\n### Fixed\n- Fix issue with additional images not being converted if already converted\n- Make sure to enable cookie-check whenever FPC is enabled\n\n### Added\n- Actual meaningful integration test for browsing product page\n\n## [0.1.1] - 2019-04-12\n### Fixed\n- Disable gallery fix if FPC is enabled\n\n## [0.1.0] - 2019-04-12\n### Added\n- Add GD checker in backend settings\n\n## [0.0.3] - 2019-03-21\n### Fixed\n- Fix for Fotorama gallery\n- Check via timestamps for new and modified files\n\n### Added\n- Check for browser support via cookie and Chrome-check\n- Inspect ACCEPT header for image/webp support\n- Implement detect.js script to detect WebP support and set a cookie\n- Add configuration values\n\n## [0.0.2] - 2019-03-20\n### Added\n- Temporary release for CI purpose\n\n## [0.0.1] - 2019-03-20\n### Added\n- Initial commit\n- Support for regular img-tags to picture-tags conversion\n"
  },
  {
    "path": "Config/Config.php",
    "content": "<?php declare(strict_types=1);\n\nnamespace Yireo\\Webp2\\Config;\n\nuse Magento\\Framework\\App\\Config\\ScopeConfigInterface;\nuse Magento\\Framework\\Exception\\NoSuchEntityException;\nuse Magento\\Framework\\View\\Element\\Block\\ArgumentInterface;\nuse Magento\\Store\\Model\\ScopeInterface;\nuse Magento\\Store\\Model\\StoreManagerInterface;\nuse Yireo\\NextGenImages\\Config\\Config as NextGenImagesConfig;\nuse Yireo\\Webp2\\Exception\\InvalidConvertorException;\n\nclass Config implements ArgumentInterface\n{\n    /**\n     * @var ScopeConfigInterface\n     */\n    private $scopeConfig;\n\n    /**\n     * @var StoreManagerInterface\n     */\n    private $storeManager;\n\n    /**\n     * @var NextGenImagesConfig\n     */\n    private $nextGenImagesConfig;\n\n    /**\n     * Config constructor.\n     *\n     * @param ScopeConfigInterface $scopeConfig\n     * @param StoreManagerInterface $storeManager\n     * @param NextGenImagesConfig $nextGenImagesConfig\n     */\n    public function __construct(\n        ScopeConfigInterface $scopeConfig,\n        StoreManagerInterface $storeManager,\n        NextGenImagesConfig $nextGenImagesConfig\n    ) {\n        $this->scopeConfig = $scopeConfig;\n        $this->storeManager = $storeManager;\n        $this->nextGenImagesConfig = $nextGenImagesConfig;\n    }\n\n    /**\n     * @return bool\n     */\n    public function enabled(): bool\n    {\n        return (bool)$this->getValue('yireo_webp2/settings/enabled');\n    }\n\n    /**\n     * @return bool\n     */\n    public function allowImageCreation(): bool\n    {\n        return $this->nextGenImagesConfig->allowImageCreation();\n    }\n\n    /**\n     * @return int\n     */\n    public function getQualityLevel(): int\n    {\n        $qualityLevel = (int)$this->getValue('yireo_webp2/settings/quality_level');\n        if ($qualityLevel > 100) {\n            return 100;\n        }\n\n        if ($qualityLevel < 1) {\n            return 1;\n        }\n\n        return $qualityLevel;\n    }\n\n    /**\n     * @return string[]\n     * @throws InvalidConvertorException\n     */\n    public function getConvertors(): array\n    {\n        $allConvertors = ['cwebp', 'gd', 'imagick', 'wpc', 'ewww'];\n        $storedConvertors = $this->getValue('yireo_webp2/settings/convertors');\n        $storedConvertors = $this->stringToArray((string)$storedConvertors);\n        if (empty($storedConvertors)) {\n            return $allConvertors;\n        }\n\n        foreach ($storedConvertors as $storedConvertor) {\n            if (!in_array($storedConvertor, $allConvertors)) {\n                throw new InvalidConvertorException('Invalid convertor: \"' . $storedConvertor . '\"');\n            }\n        }\n\n        return $storedConvertors;\n    }\n\n    /**\n     * @return string\n     * @throws InvalidConvertorException\n     */\n    public function getEncoding(): string\n    {\n        $allEncoding = ['lossy', 'lossless', 'auto'];\n        $storedEncoding = (string)$this->getValue('yireo_webp2/settings/encoding');\n        if (empty($storedEncoding)) {\n            return 'lossy';\n        }\n\n        if (!in_array($storedEncoding, $allEncoding)) {\n            throw new InvalidConvertorException('Invalid encoding: \"' . $storedEncoding . '\"');\n        }\n\n        return $storedEncoding;\n    }\n\n    /**\n     * @param string $path\n     * @return mixed\n     */\n    private function getValue(string $path)\n    {\n        try {\n            return $this->scopeConfig->getValue(\n                $path,\n                ScopeInterface::SCOPE_STORE,\n                $this->storeManager->getStore()\n            );\n        } catch (NoSuchEntityException $e) {\n            return null;\n        }\n    }\n\n    /**\n     * @param string $string\n     * @return array\n     */\n    private function stringToArray(string $string): array\n    {\n        $array = [];\n        $strings = explode(',', $string);\n        foreach ($strings as $string) {\n            $string = trim($string);\n            if ($string) {\n                $array[] = $string;\n            }\n        }\n\n        return $array;\n    }\n}\n"
  },
  {
    "path": "Config/Frontend/Funding.php",
    "content": "<?php declare(strict_types=1);\n\nnamespace Yireo\\Webp2\\Config\\Frontend;\n\nuse Magento\\Config\\Block\\System\\Config\\Form\\Field;\nuse Magento\\Framework\\Data\\Form\\Element\\AbstractElement;\n\nclass Funding extends Field\n{\n    protected $_template = 'Yireo_Webp2::funding.phtml';\n\n    public function render(AbstractElement $element)\n    {\n        return $this->toHtml();\n    }\n}\n\n"
  },
  {
    "path": "Controller/Test/Images.php",
    "content": "<?php\ndeclare(strict_types=1);\n\nnamespace Yireo\\Webp2\\Controller\\Test;\n\nuse Magento\\Framework\\App\\Action\\Action;\nuse Magento\\Framework\\App\\Action\\Context;\nuse Magento\\Framework\\View\\Result\\Page;\nuse Magento\\Framework\\View\\Result\\PageFactory;\n\nclass Images extends Action\n{\n    /**\n     * @var PageFactory\n     */\n    protected $pageFactory;\n\n    /**\n     * Index constructor.\n     *\n     * @param Context     $context\n     * @param PageFactory $pageFactory\n     */\n    public function __construct(\n        Context $context,\n        PageFactory $pageFactory\n    ) {\n        parent::__construct($context);\n        $this->pageFactory = $pageFactory;\n    }\n\n    /**\n     * @return Page\n     */\n    public function execute()\n    {\n        $page = $this->pageFactory->create();\n\n        $case = strtolower((string)$this->_request->getParam('case'));\n        $case = preg_replace('/([^a-z\\_]+)/', '', $case);\n        $handle = 'webp_test_images_' . $case;\n        $page->addHandle($handle);\n\n        return $page;\n    }\n}\n"
  },
  {
    "path": "Controller/Test/Mail.php",
    "content": "<?php\ndeclare(strict_types=1);\n\nnamespace Yireo\\Webp2\\Controller\\Test;\n\nuse Magento\\Framework\\App\\Action\\Action;\nuse Magento\\Framework\\App\\Action\\Context;\nuse Magento\\Framework\\App\\Area;\nuse Magento\\Framework\\App\\Config\\ScopeConfigInterface;\nuse Magento\\Framework\\App\\DeploymentConfig;\nuse Magento\\Framework\\App\\RequestInterface;\nuse Magento\\Framework\\Controller\\Result\\Json;\nuse Magento\\Framework\\Controller\\Result\\JsonFactory;\nuse Magento\\Framework\\Controller\\ResultInterface;\nuse Magento\\Framework\\Exception\\LocalizedException;\nuse Magento\\Framework\\Exception\\MailException;\nuse Magento\\Framework\\Exception\\NoSuchEntityException;\nuse Magento\\Framework\\Mail\\Template\\TransportBuilder;\nuse Magento\\Framework\\View\\Result\\LayoutFactory;\nuse Magento\\Framework\\View\\Result\\Page;\nuse Magento\\Store\\Model\\StoreManagerInterface;\n\nclass Mail extends Action\n{\n    /**\n     * @var TransportBuilder\n     */\n    private $transportBuilder;\n\n    /**\n     * @var StoreManagerInterface\n     */\n    private $storeManager;\n\n    /**\n     * @var LayoutFactory\n     */\n    private $layoutFactory;\n\n    /**\n     * @var RequestInterface\n     */\n    private $request;\n\n    /**\n     * @var JsonFactory\n     */\n    private $jsonFactory;\n\n    /**\n     * @var ScopeConfigInterface\n     */\n    private $scopeConfig;\n\n    /**\n     * @var DeploymentConfig\n     */\n    private $config;\n\n    /**\n     * Mail constructor.\n     * @param TransportBuilder $transportBuilder\n     * @param StoreManagerInterface $storeManager\n     * @param LayoutFactory $layoutFactory\n     * @param RequestInterface $request\n     * @param JsonFactory $jsonFactory\n     * @param ScopeConfigInterface $scopeConfig\n     * @param DeploymentConfig $config\n     * @param Context $context\n     */\n    public function __construct(\n        TransportBuilder $transportBuilder,\n        StoreManagerInterface $storeManager,\n        LayoutFactory $layoutFactory,\n        RequestInterface $request,\n        JsonFactory $jsonFactory,\n        ScopeConfigInterface $scopeConfig,\n        DeploymentConfig $config,\n        Context $context\n    ) {\n        parent::__construct($context);\n        $this->transportBuilder = $transportBuilder;\n        $this->storeManager = $storeManager;\n        $this->layoutFactory = $layoutFactory;\n        $this->request = $request;\n        $this->jsonFactory = $jsonFactory;\n        $this->scopeConfig = $scopeConfig;\n        $this->config = $config;\n    }\n\n    /**\n     * @return ResultInterface\n     * @throws LocalizedException\n     * @throws MailException\n     * @throws NoSuchEntityException\n     */\n    public function execute(): ResultInterface\n    {\n        $token = (string)$this->request->getParam('token');\n        $cryptKey = (string)$this->config->get('crypt/key');\n        if ($token === $cryptKey) {\n            return $this->sendResult(['msg' => 'Invalid token']);\n        }\n\n        $emailTemplate = (string)$this->request->getParam('email');\n\n        if (empty($emailTemplate)) {\n            $emailTemplate = 'sales_email_invoice_template';\n        }\n\n        $receiverInfo = [\n            'name' => $this->scopeConfig->getValue('trans_email_ident/general/name'),\n            'email' => $this->scopeConfig->getValue('trans_email_ident/general/email'),\n        ];\n\n        $senderInfo = [\n            'name' => $this->scopeConfig->getValue('trans_email_ident/general/name'),\n            'email' => $this->scopeConfig->getValue('trans_email_ident/general/email'),\n        ];\n\n        $data = [\n            'template' => $emailTemplate,\n            'sender' => $senderInfo,\n            'receiver' => $receiverInfo\n        ];\n\n        $variables = [];\n        $this->transportBuilder->setTemplateIdentifier($emailTemplate)\n            ->setTemplateOptions(\n                [\n                    'area' => Area::AREA_FRONTEND,\n                    'store' => $this->storeManager->getStore()->getId(),\n                ]\n            )\n            ->setTemplateVars($variables)\n            ->setFrom($senderInfo)\n            ->addTo($receiverInfo['email'], $receiverInfo['name']);\n\n        $transport = $this->transportBuilder->getTransport();\n        $transport->sendMessage();\n        $data['msg'] = 'Email sent';\n\n        return $this->sendResult($data);\n    }\n\n    /**\n     * @param mixed[] $data\n     * @return ResultInterface\n     */\n    private function sendResult(array $data): ResultInterface\n    {\n        $jsonResult = $this->jsonFactory->create();\n        $jsonResult->setData($data);\n        return $jsonResult;\n    }\n}\n"
  },
  {
    "path": "Convertor/ConvertWrapper.php",
    "content": "<?php\ndeclare(strict_types=1);\n\nnamespace Yireo\\Webp2\\Convertor;\n\nuse Exception;\nuse Psr\\Log\\LoggerInterface;\nuse WebPConvert\\Convert\\Exceptions\\ConversionFailed\\InvalidInput\\InvalidImageTypeException;\nuse WebPConvert\\Convert\\Exceptions\\ConversionFailedException;\nuse WebPConvert\\WebPConvert;\nuse Yireo\\Webp2\\Config\\Config;\nuse Yireo\\Webp2\\Exception\\InvalidConvertorException;\n\n/**\n * Class ConvertWrapper to wrap third party wrapper for purpose of preference overrides and testing\n */\nclass ConvertWrapper\n{\n    /**\n     * @var Config\n     */\n    private $config;\n\n    /**\n     * @var LoggerInterface\n     */\n    private $logger;\n\n    /**\n     * ConvertWrapper constructor.\n     * @param Config $config\n     */\n    public function __construct(\n        Config $config,\n        LoggerInterface $logger\n    ) {\n        $this->config = $config;\n        $this->logger = $logger;\n    }\n\n    /**\n     * @param string $sourceImageFilename\n     * @param string $destinationImageFilename\n     * @throws ConversionFailedException\n     * @throws InvalidConvertorException\n     * @throws InvalidImageTypeException\n     */\n    public function convert(string $sourceImageFilename, string $destinationImageFilename): void\n    {\n        $options = $this->getOptions();\n        foreach ($this->config->getConvertors() as $convertor){\n            $options['converter'] = $convertor;\n            try {\n                WebPConvert::convert($sourceImageFilename, $destinationImageFilename, $options);\n            } catch (ConversionFailedException $e) {\n                $this->logger->debug($e->getMessage() . ' - ' . $e->description, $e->getTrace());\n                continue;\n            } catch (\\Exception $e) {\n                $this->logger->debug($e->getMessage(), $e->getTrace());\n                continue;\n            }\n            break;\n        }\n    }\n\n    /**\n     * @return array\n     * @throws InvalidConvertorException\n     */\n    public function getOptions(): array\n    {\n        return [\n            'quality' => 'auto',\n            'max-quality' => $this->config->getQualityLevel(),\n            'encoding' => $this->config->getEncoding(),\n        ];\n    }\n}\n"
  },
  {
    "path": "Convertor/Convertor.php",
    "content": "<?php declare(strict_types=1);\n\nnamespace Yireo\\Webp2\\Convertor;\n\nuse Magento\\Framework\\Exception\\FileSystemException;\nuse Magento\\Framework\\Exception\\NoSuchEntityException;\nuse WebPConvert\\Convert\\Exceptions\\ConversionFailed\\InvalidInput\\InvalidImageTypeException;\nuse WebPConvert\\Convert\\Exceptions\\ConversionFailedException;\nuse Yireo\\NextGenImages\\Convertor\\ConvertorInterface;\nuse Yireo\\NextGenImages\\Exception\\ConvertorException;\nuse Yireo\\NextGenImages\\Image\\Image;\nuse Yireo\\NextGenImages\\Image\\ImageFactory;\nuse Yireo\\NextGenImages\\Image\\TargetImageFactory;\nuse Yireo\\NextGenImages\\Util\\File;\nuse Yireo\\Webp2\\Config\\Config;\nuse Yireo\\Webp2\\Exception\\InvalidConvertorException;\nuse WebPConvert\\Exceptions\\InvalidInput\\InvalidImageTypeException as InvalidInputImageTypeException;\nuse WebPConvert\\Exceptions\\InvalidInputException;\n\nclass Convertor implements ConvertorInterface\n{\n    /**\n     * @var Config\n     */\n    private $config;\n\n    /**\n     * @var File\n     */\n    private $imageFile;\n\n    /**\n     * @var ConvertWrapper\n     */\n    private $convertWrapper;\n\n    /**\n     * @var TargetImageFactory\n     */\n    private $targetImageFactory;\n\n    /**\n     * @var ImageFactory\n     */\n    private $imageFactory;\n\n    /**\n     * Convertor constructor.\n     * @param Config $config\n     * @param File $imageFile\n     * @param ConvertWrapper $convertWrapper\n     * @param TargetImageFactory $targetImageFactory\n     * @param ImageFactory $imageFactory\n     */\n    public function __construct(\n        Config $config,\n        File $imageFile,\n        ConvertWrapper $convertWrapper,\n        TargetImageFactory $targetImageFactory,\n        ImageFactory $imageFactory\n    ) {\n        $this->config = $config;\n        $this->imageFile = $imageFile;\n        $this->convertWrapper = $convertWrapper;\n        $this->targetImageFactory = $targetImageFactory;\n        $this->imageFactory = $imageFactory;\n    }\n\n    /**\n     * @param Image $image\n     * @return Image\n     * @throws ConvertorException\n     * @throws FileSystemException\n     */\n    public function convertImage(Image $image): Image\n    {\n        if (!$this->config->enabled()) {\n            throw new ConvertorException('WebP conversion is not enabled');\n        }\n\n        if (!in_array($image->getMimetype(), ['image/jpeg', 'image/jpg', 'image/png'])) {\n            throw new ConvertorException('The mimetype \"'.$image->getMimetype().'\" is not supported');\n        }\n\n        // @todo: https://gitlab.hyva.io/hyva-themes/hyva-compat/magento2-yireo-next-gen-images/-/blob/main/src/Plugin/ConverterPlugin.php#L50\n\n        $webpImage = $this->targetImageFactory->create($image, 'webp');\n        $result = $this->convert($image->getPath(), $webpImage->getPath());\n\n        if (!$result && !$this->imageFile->fileExists($webpImage->getPath())) {\n            throw new ConvertorException('WebP path \"'.$webpImage->getPath().'\" does not exist after conversion');\n        }\n\n        $webpImage->setSrcSet($this->convertSrcSet($image));\n\n        return $webpImage;\n    }\n\n    /**\n     * @param string $sourceImagePath\n     * @param string $targetImagePath\n     * @return bool\n     * @throws ConvertorException\n     */\n    private function convert(string $sourceImagePath, string $targetImagePath): bool\n    {\n        if (!$this->imageFile->fileExists($sourceImagePath)) {\n            throw new ConvertorException('Source cached image does not exists: '.$sourceImagePath);\n        }\n\n        if (!$this->imageFile->needsConversion($sourceImagePath, $targetImagePath)) {\n            return true;\n        }\n\n        if (!$this->config->enabled() || !$this->config->allowImageCreation()) {\n            throw new ConvertorException('WebP conversion is not enabled');\n        }\n\n        try {\n            $this->convertWrapper->convert($sourceImagePath, $targetImagePath);\n        } catch (InvalidImageTypeException|InvalidInputException|InvalidInputImageTypeException $e) {\n            return false;\n        } catch (ConversionFailedException|InvalidConvertorException $e) {\n            throw new ConvertorException($targetImagePath.': '.$e->getMessage());\n        }\n\n        return true;\n    }\n\n    private function convertSrcSet(Image $image): string\n    {\n        $srcSetImages = explode(',', $image->getSrcSet());\n        $webpImageSrcSet = '';\n        foreach ($srcSetImages as $srcSetImage) {\n            $pieces = explode(' ', trim($srcSetImage));\n            $imageUrl = $pieces[0];\n            $descriptor = $pieces[1] ?? 0;\n\n            $srcSetImage = $this->imageFactory->createFromUrl($imageUrl);\n            $srcSetWebpImage = $this->targetImageFactory->create($srcSetImage, 'webp');\n            $result = $this->convert($srcSetImage->getPath(), $srcSetWebpImage->getPath());\n\n            if (!$result && !$this->imageFile->fileExists($srcSetWebpImage->getPath())) {\n                throw new ConvertorException('WebP path \"'.$srcSetWebpImage->getPath().'\" does not exist after conversion');\n            }\n\n            $webpImageSrcSet .= ($webpImageSrcSet ? ', ' : '') . $srcSetWebpImage->getUrl() . ' ' . ($descriptor ?: '');\n        }\n\n        return $webpImageSrcSet;\n    }\n}\n"
  },
  {
    "path": "Exception/InvalidConvertorException.php",
    "content": "<?php declare(strict_types=1);\n\nnamespace Yireo\\Webp2\\Exception;\n\nuse Exception;\n\nclass InvalidConvertorException extends Exception\n{\n}\n"
  },
  {
    "path": "LICENSE.txt",
    "content": "Open Software License (\"OSL\") v. 3.0\n\nThis Open Software License (the \"License\") applies to any original work of authorship (the \"Original Work\") whose owner (the \"Licensor\") has placed the following licensing notice adjacent to the copyright notice for the Original Work:\n\nLicensed under the Open Software License version 3.0\n\n1. Grant of Copyright License. Licensor grants You a worldwide, royalty-free, non-exclusive, sublicensable license, for the duration of the copyright, to do the following:\n\n1.1. to reproduce the Original Work in copies, either alone or as part of a collective work;\n\n1.2. to translate, adapt, alter, transform, modify, or arrange the Original Work, thereby creating derivative works (\"Derivative Works\") based upon the Original Work;\n\n1.3. to distribute or communicate copies of the Original Work and Derivative Works to the public, with the proviso that copies of Original Work or Derivative Works that You distribute or communicate shall be licensed under this Open Software License;\n\n1.4. to perform the Original Work publicly; and\n\n1.5. to display the Original Work publicly. \n\n2. Grant of Patent License. Licensor grants You a worldwide, royalty-free, non-exclusive, sublicensable license, under patent claims owned or controlled by the Licensor that are embodied in the Original Work as furnished by the Licensor, for the duration of the patents, to make, use, sell, offer for sale, have made, and import the Original Work and Derivative Works.\n\n3. Grant of Source Code License. The term \"Source Code\" means the preferred form of the Original Work for making modifications to it and all available documentation describing how to modify the Original Work. Licensor agrees to provide a machine-readable copy of the Source Code of the Original Work along with each copy of the Original Work that Licensor distributes. Licensor reserves the right to satisfy this obligation by placing a machine-readable copy of the Source Code in an information repository reasonably calculated to permit inexpensive and convenient access by You for as long as Licensor continues to distribute the Original Work.\n\n4. Exclusions From License Grant. Neither the names of Licensor, nor the names of any contributors to the Original Work, nor any of their trademarks or service marks, may be used to endorse or promote products derived from this Original Work without express prior permission of the Licensor. Except as expressly stated herein, nothing in this License grants any license to Licensor's trademarks, copyrights, patents, trade secrets or any other intellectual property. No patent license is granted to make, use, sell, offer for sale, have made, or import embodiments of any patent claims other than the licensed claims defined in Section 2. No license is granted to the trademarks of Licensor even if such marks are included in the Original Work. Nothing in this License shall be interpreted to prohibit Licensor from licensing under terms different from this License any Original Work that Licensor otherwise would have a right to license.\n\n5. External Deployment. The term \"External Deployment\" means the use, distribution, or communication of the Original Work or Derivative Works in any way such that the Original Work or Derivative Works may be used by anyone other than You, whether those works are distributed or communicated to those persons or made available as an application intended for use over a network. As an express condition for the grants of license hereunder, You must treat any External Deployment by You of the Original Work or a Derivative Work as a distribution under section 1(c).\n\n6. Attribution Rights. You must retain, in the Source Code of any Derivative Works that You create, all copyright, patent, or trademark notices from the Source Code of the Original Work, as well as any notices of licensing and any descriptive text identified therein as an \"Attribution Notice.\" You must cause the Source Code for any Derivative Works that You create to carry a prominent Attribution Notice reasonably calculated to inform recipients that You have modified the Original Work.\n\n7. Warranty of Provenance and Disclaimer of Warranty. Licensor warrants that the copyright in and to the Original Work and the patent rights granted herein by Licensor are owned by the Licensor or are sublicensed to You under the terms of this License with the permission of the contributor(s) of those copyrights and patent rights. Except as expressly stated in the immediately preceding sentence, the Original Work is provided under this License on an \"AS IS\" BASIS and WITHOUT WARRANTY, either express or implied, including, without limitation, the warranties of non-infringement, merchantability or fitness for a particular purpose. THE ENTIRE RISK AS TO THE QUALITY OF THE ORIGINAL WORK IS WITH YOU. This DISCLAIMER OF WARRANTY constitutes an essential part of this License. No license to the Original Work is granted by this License except under this disclaimer.\n\n8. Limitation of Liability. Under no circumstances and under no legal theory, whether in tort (including negligence), contract, or otherwise, shall the Licensor be liable to anyone for any indirect, special, incidental, or consequential damages of any character arising as a result of this License or the use of the Original Work including, without limitation, damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses. This limitation of liability shall not apply to the extent applicable law prohibits such limitation.\n\n9. Acceptance and Termination. If, at any time, You expressly assented to this License, that assent indicates your clear and irrevocable acceptance of this License and all of its terms and conditions. If You distribute or communicate copies of the Original Work or a Derivative Work, You must make a reasonable effort under the circumstances to obtain the express assent of recipients to the terms of this License. This License conditions your rights to undertake the activities listed in Section 1, including your right to create Derivative Works based upon the Original Work, and doing so without honoring these terms and conditions is prohibited by copyright law and international treaty. Nothing in this License is intended to affect copyright exceptions and limitations (including 'fair use' or 'fair dealing'). This License shall terminate immediately and You may no longer exercise any of the rights granted to You by this License upon your failure to honor the conditions in Section 1(c).\n\n10. Termination for Patent Action. This License shall terminate automatically and You may no longer exercise any of the rights granted to You by this License as of the date You commence an action, including a cross-claim or counterclaim, against Licensor or any licensee alleging that the Original Work infringes a patent. This termination provision shall not apply for an action alleging patent infringement by combinations of the Original Work with other software or hardware.\n\n11. Jurisdiction, Venue and Governing Law. Any action or suit relating to this License may be brought only in the courts of a jurisdiction wherein the Licensor resides or in which Licensor conducts its primary business, and under the laws of that jurisdiction excluding its conflict-of-law provisions. The application of the United Nations Convention on Contracts for the International Sale of Goods is expressly excluded. Any use of the Original Work outside the scope of this License or after its termination shall be subject to the requirements and penalties of copyright or patent law in the appropriate jurisdiction. This section shall survive the termination of this License.\n\n12. Attorneys' Fees. In any action to enforce the terms of this License or seeking damages relating thereto, the prevailing party shall be entitled to recover its costs and expenses, including, without limitation, reasonable attorneys' fees and costs incurred in connection with such action, including any appeal of such action. This section shall survive the termination of this License.\n\n13. Miscellaneous. If any provision of this License is held to be unenforceable, such provision shall be reformed only to the extent necessary to make it enforceable.\n\n14. Definition of \"You\" in This License. \"You\" throughout this License, whether in upper or lower case, means an individual or a legal entity exercising rights under, and complying with all of the terms of, this License. For legal entities, \"You\" includes any entity that controls, is controlled by, or is under common control with you. For purposes of this definition, \"control\" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity.\n\n15. Right to Use. You may use the Original Work in all ways not otherwise restricted or conditioned by this License or by law, and Licensor promises not to interfere with or be responsible for such uses by You.\n\n16. Modification of This License. This License is Copyright © 2005 Lawrence Rosen. Permission is granted to copy, distribute, or communicate this License without modification. Nothing in this License permits You to modify this License as applied to the Original Work or to Derivative Works. However, You may modify the text of this License and copy, distribute or communicate your modified version (the \"Modified License\") and apply it to other original works of authorship subject to the following conditions: (i) You may not indicate in any way that your Modified License is the \"Open Software License\" or \"OSL\" and you may not use those names in the name of your Modified License; (ii) You must replace the notice specified in the first paragraph above with the notice \"Licensed under <insert your license name here>\" or with a notice of your own that is not confusingly similar to the notice in this License; and (iii) You may not claim that your original works are open source software unless your Modified License has been approved by Open Source Initiative (OSI) and You comply with its license review and certification process. \n"
  },
  {
    "path": "Model/Config/Source/Encoding.php",
    "content": "<?php declare(strict_types=1);\n\nnamespace Yireo\\Webp2\\Model\\Config\\Source;\n\nuse Magento\\Framework\\Data\\OptionSourceInterface;\n\nclass Encoding implements OptionSourceInterface\n{\n    public function toOptionArray()\n    {\n        return [\n            ['value' => 'lossy', 'label' => 'Lossy'],\n            ['value' => 'lossless', 'label' => 'Lossless'],\n            ['value' => 'auto', 'label' => 'Auto (both lossy and lossless)'],\n        ];\n    }\n}\n"
  },
  {
    "path": "Plugin/AddCspInlineScripts.php",
    "content": "<?php declare(strict_types=1);\n\nnamespace Yireo\\Webp2\\Plugin;\n\nuse Magento\\Framework\\View\\Element\\Template;\nuse Yireo\\CspUtilities\\Util\\ReplaceInlineScripts;\n\nclass AddCspInlineScripts\n{\n    private ReplaceInlineScripts $replaceInlineScripts;\n\n    public function __construct(\n        ReplaceInlineScripts $replaceInlineScripts\n    ) {\n        $this->replaceInlineScripts = $replaceInlineScripts;\n    }\n\n    public function afterToHtml(Template $block, $html): string\n    {\n        if (false === strstr((string)$block->getNameInLayout(), 'yireo_webp2.')) {\n            return (string)$html;\n        }\n\n        return $this->replaceInlineScripts->replace((string)$html);\n    }\n}\n"
  },
  {
    "path": "README.md",
    "content": "# Magento 2 module for WebP\n<img src=\"https://img.shields.io/packagist/dt/yireo/magento2-webp2\"/> <img src=\"https://img.shields.io/packagist/v/yireo/magento2-webp2\"/> <img src=\"https://img.shields.io/github/languages/top/yireo/Yireo_Webp2\"/> <img src=\"https://img.shields.io/github/last-commit/yireo/Yireo_Webp2\" /> <img src=\"https://img.shields.io/github/sponsors/yireo\"/> <img src=\"https://img.shields.io/badge/Hyva_Themes-Supported-3df0af.svg?longCache=true\" /> <img src=\"https://img.shields.io/twitter/follow/yireo?style=social\" />\n\n**This module adds WebP support to Magento 2.**\n\n## About this module\n- When `<img>` tags are found on the page, the corresponding JPG or PNG is converted into WebP and a corresponding `<picture` tag is used to replace the original `<img>` tag.\n- The Fotorama gallery of the Magento core product pages is replaced with WebP images without issues as well. However, the Fotorama effect loads new JPG images again, replacing the original `<picture>` tag. This shows that the Fotorama library is not scalable and may be a bad decision to use. We recommend you replace it with the [Notorama](https://github.com/robaimes/module-notorama) module instead.\n\n> [!WARNING]\n> Hyvä support is built into the latest versions of this module. Please do not use the deprecated compatibility module anymore.\n\n## Instructions for using composer\nUse composer to install this extension. Not using composer is **not** supported. Next, install the new module plus its dependency `Yireo_NextGenImages` into Magento itself: \n\n```bash\ncomposer require yireo/magento2-webp2\nbin/magento module:enable Yireo_Webp2 Yireo_NextGenImages\nbin/magento setup:upgrade\n```\n\nEnable the module by toggling the setting in **Stores > Configuration > Yireo > Yireo WebP > Enabled**.\n\n## System requirements\nMake sure your PHP environment supports WebP: This means that the function `imagewebp` should exist in PHP. We hope to add\nmore checks for this in the extension itself soon. For now, just open up a PHP `phpinfo()` page and check for WebP\nsupport. Please note that installing `libwebp` on your system is not the same as having PHP support WebP. Check the\n`phpinfo()` file and add new PHP modules to PHP if needed. If in doubt, simple create a PHP script `test.php` and a line\n`<?php echo (int)function_exists('imagewebp');` to it: A `1` indicates that the function is available, a `0` indicates\nthat it is not. Alternatively you can check for WebP using the command `php -r 'var_dump(gd_info());'`. Make sure your CLI\nbinary is the same as the one being called by the webserver though.\n\nAn alternative is that the `cwebp` binary from the WebP project is uploaded to your server and placed in a generic folder like `/usr/local/bin`. Make sure to grab a copy from this binary from the [rosell-dk/webp-convert](https://github.com/rosell-dk/webp-convert/tree/master/src/Convert/Converters/Binaries) project. This method is preferred because it is the fastest. But it assumes also that the binary is placed in a folder by the server administrator.\n\nWe recommend you to work on making all options work, not just one.\n\nPlease note that both tasks should be simple for developers and system administrator, but might be magical for non-technical people. If this extension is not working out of the box for you, most likely a technical person needs to take a look at your hosting environment.\n\n## FAQ\n\n#### Does this module support GraphQL?\nYes, but only via the additional [Yireo Webp2GraphQl](https://github.com/yireo/Yireo_Webp2GraphQl) module\n\n#### How do I know WebP is used?\nMake sure to test things with the obvious caches disabled (Full Page Cache, Block HTML Cache). Once this extension is working, catalog images (like on a category page) should be replaced with: Their `<img>` tag should be replaced with a `<picture>` tag that lists both the old image and the new WebP image. If the conversion from the old image to WebP goes well.\n\nYou can expect the HTML to be changed, so inspecting the HTML source gives a good impression. You can also use the Error Console to inspect network traffic: If some `webp` images are flying be in a default Magento environment, this usually proofs that the extension is working to some extent.\n\n#### My CPU usage goes up. Is that normal?\nYes, it is normal. This extension does two things: It shows a WebP on the frontend of your shop. And it\ngenerates that WebP when it is missing. Obviously, generating an image takes up system resources. And if\nyou have a large catalog, it is going to do more time. How much time? Do make sure to calculate this\nyourself: Take an image, resize it using the `cwebp` binary and measure the time - multiply it by how many\nimages there are. This should give a fair estimation on how much time is needed.\n\nNote that this extension allows for using various mechanisms (aka *convertors*). Tune the **Convertors**\nsettings if you want to try to optimize things. Sometimes, GD is faster than `cwebp`. Sometimes, GD just\nbreaks things. It depends, so you need to pick upon the responsibility to try this in your specific\nenvironment.\n\nAlso note that this extension allows for setting an *encoding*. The default is `auto` which creates both a lossy and a lossless WebP and then picks the smallest one. Things could be twice as fast by setting this to `lossy`.\n\nIf you don't like the generation of images at all, you could also use other CLI tools instead.\n\n#### Class 'WebPConvert\\WebPConvert' not found\nWe only support the installation of our Magento 2 extensions, if they are installed via `composer`. Please note that - as we see it - `composer` is the only way for managing Magento depedencies. If you want to install the extension manually in `app/code`, please study the contents of `cmoposer.json` to install all dependencies of this module manually as well.\n\n#### After installation, I'm still seeing only PNG and JPEG images\nThis could mean that the conversion failed. New WebP images are stored in the same path as the original path (somewhere in `pub/`) which means that all folders need to be writable by the webserver. Specifically, if your deployment is based on artifacts, this could be an issue.\n\nAlso make sure that your PHP environment is capable of WebP: The function `imagewebp` should exist in PHP and we recommend a `cwebp` binary to be placed in `/usr/local/bin/`.\n\nLast but not least, WebP images only work in WebP-capable browsers. The extension detects the browser support. Make sure to test this in Chrome first, which natively supports WebP.\n\n#### Warning: filesize(): stat failed for xxx.webp\nIf you are seeing this issue in the `exception.log` and/or `system.log`,\ndo make sure to wipe out Magento caching and do make sure that the WebP\nfile in question is accessible: The webserver running Magento should have\nread access to the file. Likewise, if you want this extension to\nautomatically convert a JPEG into WebP, do make sure that the folder\ncontaining the JPEG is writable.\n\n#### Some of the images are converted, but others are not.\nNot all JPEG and PNG images are fit for conversion to WebP. In the past, WebP has had issues with alpha-transparency and partial transparency. If the WebP image can't be generated by our extension, it is not generated. Simple as that. If some images are converted but some are not, try to upload those to online conversion tools to see if they work.\n\nMake sure your `cwebp` binary and PHP environment are up-to-date.\n\n#### This sucks. It only works in some browsers.\nDon't complain to us. Instead, ask the other browser vendors to support this as well. And don't say this\nis not worth implementing, because I bet more than 25% of your sites visitors will benefit from WebP. Not\noffering this to them, is wasting additional bandwidth.\n\n#### Some emails are also displaying WebP\nIt could be that your transactional email templates are including XML layout handles that suddenly introduce this extensions functionality, while actually adding WebP to emails is a bad idea (because most email clients will not support anything of the like).\n\nIf you encounter such an email, find out which XML layout handle is the cause of this (`{handle layout=\"foobar\"}`). Next, create a new XML layout file with that name (`foobar.xml`) and call the `webp_skip` handle from it (`<update handle=\"webp_skip\" />`). So this instructs the WebP extension to skip loading itself.\n\n#### error while loading shared libraries: libjpeg.so.8: cannot open shared object file: No such file or directory\nAsk your system administrator to install this library. Or ask the system administrator to install WebP support in PHP by upgrading PHP itself to the right version and to include the right PHP modules (like imagemagick). Or skip converting WebP images by disabling the setting in our extension and then convert all WebP images by hand.\n\n#### Can I use this with Amasty Shopby?\nYes, you can. Make sure to install the addition https://github.com/yireo/Yireo_Webp2ForAmastyShopby as well.\n\n#### How can I convert WebP images manually from the CLI?\nEven though this extension (or actually its parent extension `Yireo_NextGenImages`) support a CLI (`bin/magento next-gen-images:convert`), using this extension for 1000s of images will definitely not be performant. If you want to convert all images at once from the CLI, it is better to look at other tools. For instance, the `cwebp` binary (part of the Google WebP project itself) could be installed. Or perhaps you could use `convert` of the Imagick project. \n\nNext, a simple shell script could be used to build all WebP files:\n```bash\nfind . -type f -name \\*.jpg | while read IMAGE do; convert $IMAGE ${IMAGE/.jpg/.webp}; done\n```\n\nOr another example (of @rostilos):\n```bash\n#!/bin/bash\nstart=`date +%s`\ndirectory=\"../pub/media\"\n\ncd \"$directory\" || exit\nfind . -type f \\( -iname \\*.jpg -o -iname \\*.jpeg -o -iname \\*.png \\) -print0 |\n\nwhile IFS= read -r -d $'\\0' file;\n  do\n    filename=$(basename -- \"$file\")\n    new_filename=\"${filename%.*}.webp\"\n    new_filepath=\"$(dirname \"$file\")/$new_filename\"\n    echo \"Converting: $file -> $new_filepath\"\n    cwebp -q 80 -quiet \"$file\" -o \"$new_filepath\"\n  done\nend=`date +%s`\nruntime=$((end-start))\n\necho \"Execution completed in $runtime seconds.\"\n```\n\n## Requesting support\n\n### First check to see if our extension is doing its job\nBefore requesting support, please make sure that you properly check whether this extension is working or not. Do not look at your browser and definitely do not use third party SEO tools to make any conclusions. Instead, inspect the HTML source in your browser. Our extension modifies the HTML so that regular `<img>` tags are replaced with something similar to the following:\n```html\n<picture>\n  <source type=\"image/webp\" srcset=\"example.webp\">\n  <source type=\"image/png\" srcset=\"example.png\">\n  <img src=\"example.png\" />\n</picture>\n```\n\nIf similar HTML is there, but your browser is not showing the WebP image, then realize that this is not due to our extension, but due to your browser. Unfortunately, we are not browser manufacturers and we can't change this. Refer to https://caniuse.com/#search=webp instead.\n\n### Opening an issue for this extension\nFeel free to open an **Issue** in the GitHub project of this extension. However, do make sure to be thorough and provide as many details as you can:\n\n- What browser did you test this with?\n- What is your Magento version?\n- What is your PHP version?\n- Did you make sure to use `composer` to install all dependencies?\n    - Not using `composer` is **not** supported.\n- Which specific composer version of the Yireo WebP2 extension did you install?\n- Which specific composer version of the Yireo NextGenImages extension did you install?\n- Have you tested this after flushing all caches, especially the Full Page Cache?\n- Have you tested this after disabling all caches, especially the Full Page Cache?\n    - The Full Page Cache will prevent you from seeing dynamic results. The Full Page Cache works with our extension, it just pointless to troubleshoot things with FPC enabled, unless you are troubleshooting FPC itself.\n- Are you testing this in the Developer Mode or in the Production Mode?\n    - We recommend you to use the Developer Mode. Do not use the Default Mode anywhere. Do not use the Production Mode to make modifications to Magento.\n- Under **Stores > Configuration > Yireo > Yireo WebP2** and **Stores > Configuration > Yireo > Yireo NextGenImages**, what settings do you see with which values?\n    - Preferably post a screenshot with the settings.\n- Could you supply a URL to a live demo?\n- Could you please supply a snapshot of the HTML source of a product page?\n\nPlease note that we do not support Windows to be used to run Magento. Magento itself is not supporting Windows either. If you are stuck with Windows, make sure to use the WSL (Windows Subsystem for Linux) and use the Linux layer instead.\n\nIf the WebP configuration section is showing in the backend, but the HTML source in the frontend is not modified, please send the output of the command `bin/magento dev:di:info \"\\Magento\\Framework\\View\\LayoutInterface\"`.\n\n### Issues with specific images\nIf some images are converted but others are not, please supply the following details:\n\n- The output of the command `bin/magento next-gen-images:test-uri $URL` where `$URL` is the URL to the original image (JPG or PNG)\n- The output of the command `bin/magento next-gen-images:convert $PATH` where `$PATH` is the absolute path to the original image (JPG or PNG)\n- Whether or not you are using a CDN for serving images.\n"
  },
  {
    "path": "Setup/UpgradeData.php",
    "content": "<?php declare(strict_types=1);\n// phpcs:ignoreFile\n\nnamespace Yireo\\Webp2\\Setup;\n\nuse Magento\\Config\\Model\\ResourceModel\\Config\\Data\\CollectionFactory;\nuse Magento\\Framework\\App\\Config\\Storage\\WriterInterface;\nuse Magento\\Framework\\Setup\\ModuleContextInterface;\nuse Magento\\Framework\\Setup\\ModuleDataSetupInterface;\nuse Magento\\Framework\\Setup\\UpgradeDataInterface;\n\nclass UpgradeData implements UpgradeDataInterface\n{\n    /**\n     * @var CollectionFactory\n     */\n    private $configCollectionFactory;\n\n    /**\n     * @var WriterInterface\n     */\n    private $storageWriter;\n\n    /**\n     * UpgradeData constructor.\n     * @param CollectionFactory $configCollectionFactory\n     * @param WriterInterface $storageWriter\n     */\n    public function __construct(\n        CollectionFactory $configCollectionFactory,\n        WriterInterface $storageWriter\n    ) {\n\n        $this->configCollectionFactory = $configCollectionFactory;\n        $this->storageWriter = $storageWriter;\n    }\n\n    /**\n     * @param ModuleDataSetupInterface $setup\n     * @param ModuleContextInterface $context\n     * @return void\n     */\n    public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface $context)\n    {\n        $setup->startSetup();\n\n        $oldPath = 'system/yireo_webp/';\n        $newPath = 'yireo_webp2/settings/';\n\n        $configCollection = $this->configCollectionFactory->create();\n        $configCollection->addFieldToFilter('path', ['like' => $oldPath . '%']);\n        $items = $configCollection->getItems();\n\n        foreach ($items as $item) {\n            $data = $item->getData();\n            $this->storageWriter->delete($data['path'], $data['scope'], $data['scope_id']);\n            $newPath = str_replace($oldPath, $newPath, $data['path']);\n            $this->storageWriter->save($newPath, $data['value'], $data['scope'], $data['scope_id']);\n        }\n\n        $setup->endSetup();\n    }\n}\n"
  },
  {
    "path": "Test/Integration/Common.php",
    "content": "<?php declare(strict_types=1);\n\nnamespace Yireo\\Webp2\\Test\\Integration;\n\nuse Magento\\Framework\\App\\Filesystem\\DirectoryList;\nuse Magento\\Framework\\Component\\ComponentRegistrar;\nuse Magento\\Framework\\View\\LayoutInterface;\nuse Magento\\TestFramework\\TestCase\\AbstractController;\nuse RuntimeException;\nuse Yireo\\Webp2\\Convertor\\ConvertWrapper;\nuse Yireo\\Webp2\\Test\\Utils\\ImageProvider;\nuse Yireo\\Webp2\\Test\\Utils\\ConvertWrapperStub;\n\nclass Common extends AbstractController\n{\n    protected function setUp(): void\n    {\n        parent::setUp();\n        $convertWrapperStub = $this->_objectManager->get(ConvertWrapperStub::class);\n        $this->_objectManager->addSharedInstance($convertWrapperStub, ConvertWrapper::class);\n    }\n\n    /**\n     * @return string[]\n     */\n    protected function fixtureImageFiles(): array\n    {\n        // @todo: It would be cleaner to use the sandbox directory for this\n        /** @var DirectoryList $directoryList */\n        $directoryList = $this->_objectManager->get(DirectoryList::class);\n\n        $root = $directoryList->getRoot();\n        $imagesInThemePath = $root . '/pub/static/frontend/Magento/luma/en_US/Yireo_Webp2/images/test';\n\n        if (!is_dir($imagesInThemePath)) {\n            mkdir($imagesInThemePath, 0777, true);\n        }\n\n        if (!is_dir($imagesInThemePath)) {\n            throw new RuntimeException('Failed to create folder: ' . $imagesInThemePath);\n        }\n\n        $currentFiles = scandir($imagesInThemePath);\n        foreach ($currentFiles as $currentFile) {\n            if (!in_array($currentFile, ['.', '..'])) {\n                unlink($imagesInThemePath . '/' . $currentFile);\n            }\n        }\n\n        /** @var ImageProvider $imageProvider */\n        $imageProvider = $this->_objectManager->get(ImageProvider::class);\n        $images = $imageProvider->getImages();\n\n        /** @var ComponentRegistrar $componentRegistrar */\n        $componentRegistrar = $this->_objectManager->get(ComponentRegistrar::class);\n        $modulePath = $componentRegistrar->getPath('module', 'Yireo_Webp2');\n        $moduleWebPath = $modulePath . '/view/frontend/web';\n\n        foreach ($images as $image) {\n            $sourceImage = $moduleWebPath . '/' . $image;\n            $destinationImage = $imagesInThemePath . '/' . basename($image);\n            copy($sourceImage, $destinationImage);\n        }\n\n        return glob($root . '/pub/static/frontend/Magento/luma/en_US/Yireo_Webp2/images/test/*');\n    }\n\n    /**\n     * @return ImageProvider\n     */\n    protected function getImageProvider(): ImageProvider\n    {\n        return $this->_objectManager->get(ImageProvider::class);\n    }\n\n    /**\n     * @param string $body\n     * @param array $images\n     */\n    protected function assertImageTagsExist(string $body, array $images)\n    {\n        $layout = $this->_objectManager->get(LayoutInterface::class);\n        $blocks = $layout->getChildBlocks('main');\n        $html = '';\n        foreach ($blocks as $block) {\n            $html .= $block->toHtml();\n        }\n\n        foreach ($images as $image) {\n            $webPImage = preg_replace('/\\.(png|jpg)$/', '.webp', $image);\n            $debugMsg = 'Asserting that body contains \"' . $webPImage . '\": ' . $html;\n            $this->assertTrue((bool)strpos($body, $webPImage), $debugMsg);\n        }\n    }\n}\n"
  },
  {
    "path": "Test/Integration/ImageConversionTest.php",
    "content": "<?php declare(strict_types=1);\n\nnamespace Yireo\\Webp2\\Test\\Integration;\n\nuse Yireo\\NextGenImages\\Image\\ImageFactory;\nuse Yireo\\Webp2\\Convertor\\Convertor;\n\nclass ImageConversionTest extends Common\n{\n    /**\n     * @@magentoConfigFixture current_store yireo_nextgenimages/settings/enabled 1\n     * @@magentoConfigFixture current_store yireo_nextgenimages/settings/convert_images 1\n     * @@magentoConfigFixture current_store yireo_webp2/settings/enabled 1\n     * @@magentoConfigFixture current_store yireo_webp2/settings/debug 1\n     */\n    public function testIfHtmlContainsImageWithCustomStyle()\n    {\n        $images = $this->fixtureImageFiles();\n        $imagePath = $images[0];\n        $image = $this->_objectManager->get(ImageFactory::class)->createFromPath($imagePath);\n        $convertor = $this->_objectManager->get(Convertor::class);\n        $convertedImage = $convertor->convertImage($image);\n        $this->assertNotEmpty($convertedImage->getPath());\n    }\n}\n"
  },
  {
    "path": "Test/Integration/ImageWithCustomStyleTest.php",
    "content": "<?php declare(strict_types=1);\n\nnamespace Yireo\\Webp2\\Test\\Integration;\n\nclass ImageWithCustomStyleTest extends Common\n{\n    /**\n     * @magentoAppArea frontend\n     * @magentoDbIsolation enabled\n     * @magentoAppIsolation enabled\n     * @magentoCache all disabled\n     * @@magentoConfigFixture current_store yireo_nextgenimages/settings/enabled 1\n     * @@magentoConfigFixture current_store yireo_nextgenimages/settings/convert_images 1\n     * @@magentoConfigFixture current_store yireo_webp2/settings/enabled 1\n     * @@magentoConfigFixture current_store dev/static/sign 0\n     */\n    public function testIfHtmlContainsImageWithCustomStyle()\n    {\n        $this->fixtureImageFiles();\n\n        $this->getRequest()->setParam('case', 'image_with_custom_style');\n        $this->dispatch('webp/test/images');\n        $this->assertSame('image_with_custom_style', $this->getRequest()->getParam('case'));\n        $this->assertSame(200, $this->getResponse()->getHttpResponseCode());\n\n        $body = $this->getResponse()->getContent();\n        $this->assertImageTagsExist($body, [$this->getImageProvider()->getImage()]);\n        $this->assertTrue((bool)strpos($body, 'type=\"image/webp\"'));\n\n        if (!getenv('TRAVIS')) {\n            $this->assertTrue((bool)strpos($body, 'style=\"display:insane; opacity:666;\"'));\n        }\n    }\n}\n"
  },
  {
    "path": "Test/Integration/ModuleTest.php",
    "content": "<?php declare(strict_types=1);\n\nnamespace Yireo\\Webp2\\Test\\Integration;\n\nuse Magento\\Framework\\Component\\ComponentRegistrar;\nuse Magento\\Framework\\Module\\ModuleList;\nuse Magento\\TestFramework\\Helper\\Bootstrap;\nuse PHPUnit\\Framework\\TestCase;\n\nclass ModuleTest extends TestCase\n{\n    /**\n     * Test if the module is registered\n     */\n    public function testIfModuleIsRegistered()\n    {\n        $registrar = new ComponentRegistrar();\n        $paths = $registrar->getPaths(ComponentRegistrar::MODULE);\n        $this->assertArrayHasKey('Yireo_Webp2', $paths);\n    }\n\n    /**\n     * Test if the module is known and enabled\n     */\n    public function testIfModuleIsKnownAndEnabled()\n    {\n        $objectManager = Bootstrap::getObjectManager();\n        $moduleList = $objectManager->create(ModuleList::class);\n        $this->assertTrue($moduleList->has('Yireo_NextGenImages'));\n        $this->assertTrue($moduleList->has('Yireo_Webp2'));\n    }\n}\n"
  },
  {
    "path": "Test/Integration/MultipleImagesSameTest.php",
    "content": "<?php declare(strict_types=1);\n\nnamespace Yireo\\Webp2\\Test\\Integration;\n\nuse Magento\\Framework\\View\\LayoutInterface;\n\nclass MultipleImagesSameTest extends Common\n{\n    /**\n     * @magentoAdminConfigFixture yireo_nextgenimages/settings/enabled 1\n     * @magentoAdminConfigFixture yireo_nextgenimages/settings/convert_images 1\n     * @magentoAdminConfigFixture yireo_webp2/settings/enabled 1\n     * @magentoAdminConfigFixture yireo_webp2/settings/debug 1\n     */\n    public function testIfHtmlContainsSingleWebpImage()\n    {\n        $this->fixtureImageFiles();\n\n        $this->getRequest()->setParam('case', 'multiple_images_same');\n        $this->dispatch('webp/test/images');\n        $this->assertSame('multiple_images_same', $this->getRequest()->getParam('case'));\n        $this->assertSame(200, $this->getResponse()->getHttpResponseCode());\n\n        $body = $this->getResponse()->getContent();\n\n        $this->assertImageTagsExist($body, [$this->getImageProvider()->getImage()]);\n        $this->assertTrue((bool)strpos($body, 'type=\"image/webp\"'));\n\n        if (!getenv('TRAVIS')) {\n            $this->assertImageTagsExist($body, [$this->getImageProvider()->getImage()]);\n        }\n    }\n}\n"
  },
  {
    "path": "Test/Integration/MultipleImagesTest.php",
    "content": "<?php declare(strict_types=1);\n\nnamespace Yireo\\Webp2\\Test\\Integration;\n\nclass MultipleImagesTest extends Common\n{\n    /**\n     * @magentoAdminConfigFixture yireo_nextgenimages/settings/enabled 1\n     * @magentoAdminConfigFixture yireo_nextgenimages/settings/convert_images 1\n     * @magentoAdminConfigFixture yireo_webp2/settings/enabled 1\n     * @magentoAdminConfigFixture yireo_webp2/settings/debug 1\n     */\n    public function testIfHtmlContainsWebpImages(): void\n    {\n        $this->fixtureImageFiles();\n\n        $this->getRequest()->setParam('case', 'multiple_images');\n        $this->dispatch('webp/test/images');\n        $this->assertSame('multiple_images', $this->getRequest()->getParam('case'));\n        $this->assertSame(200, $this->getResponse()->getHttpResponseCode());\n\n        $body = $this->getResponse()->getBody();\n        $this->assertImageTagsExist($body, [$this->getImageProvider()->getImage()]);\n        $this->assertTrue((bool)strpos($body, 'type=\"image/webp\"'));\n\n        if (!getenv('TRAVIS')) {\n            $this->assertImageTagsExist($body, $this->getImageProvider()->getImages());\n        }\n    }\n}\n"
  },
  {
    "path": "Test/Unit/Config/ConfigTest.php",
    "content": "<?php declare(strict_types=1);\n\nnamespace Yireo\\Webp2\\Test\\Unit\\Config;\n\nuse Magento\\Framework\\App\\Config\\ScopeConfigInterface;\nuse Magento\\Store\\Model\\StoreManagerInterface;\nuse PHPUnit\\Framework\\TestCase;\nuse Yireo\\NextGenImages\\Config\\Config as NextGenImagesConfig;\nuse Yireo\\Webp2\\Config\\Config;\n\nclass ConfigTest extends TestCase\n{\n    public function testEnabled()\n    {\n        $scopeConfig = $this->createMock(ScopeConfigInterface::class);\n        $storeManager = $this->createMock(StoreManagerInterface::class);\n        $nextGenImagesConfig = $this->createMock(NextGenImagesConfig::class);\n        $config = new Config($scopeConfig, $storeManager, $nextGenImagesConfig);\n        $this->assertFalse($config->enabled());\n\n        $scopeConfig->method('getValue')->willReturn(1);\n        $this->assertTrue($config->enabled());\n    }\n\n    public function testGetQualityLevel()\n    {\n        $scopeConfig = $this->createMock(ScopeConfigInterface::class);\n        $storeManager = $this->createMock(StoreManagerInterface::class);\n        $nextGenImagesConfig = $this->createMock(NextGenImagesConfig::class);\n        $config = new Config($scopeConfig, $storeManager, $nextGenImagesConfig);\n        $this->assertEquals(1, $config->getQualityLevel());\n\n        $scopeConfig = $this->createMock(ScopeConfigInterface::class);\n        $scopeConfig->method('getValue')->willReturn(42);\n        $config = new Config($scopeConfig, $storeManager, $nextGenImagesConfig);\n        $this->assertEquals(42, $config->getQualityLevel());\n\n        $scopeConfig = $this->createMock(ScopeConfigInterface::class);\n        $scopeConfig->method('getValue')->willReturn(142);\n        $config = new Config($scopeConfig, $storeManager, $nextGenImagesConfig);\n        $this->assertEquals(100, $config->getQualityLevel());\n\n        $scopeConfig = $this->createMock(ScopeConfigInterface::class);\n        $scopeConfig->method('getValue')->willReturn(0);\n        $config = new Config($scopeConfig, $storeManager, $nextGenImagesConfig);\n        $this->assertEquals(1, $config->getQualityLevel());\n    }\n\n    public function testGetConvertors()\n    {\n        $scopeConfig = $this->createMock(ScopeConfigInterface::class);\n        $storeManager = $this->createMock(StoreManagerInterface::class);\n        $nextGenImagesConfig = $this->createMock(NextGenImagesConfig::class);\n        $config = new Config($scopeConfig, $storeManager, $nextGenImagesConfig);\n        $this->assertNotEmpty($config->getConvertors());\n    }\n}\n"
  },
  {
    "path": "Test/Unit/Convertor/ConvertorTest.php",
    "content": "<?php declare(strict_types=1);\n\nnamespace Yireo\\Webp2\\Test\\Unit\\Convertor;\n\nuse PHPUnit\\Framework\\TestCase;\nuse Yireo\\NextGenImages\\Exception\\ConvertorException;\nuse Yireo\\NextGenImages\\Image\\TargetImageFactory;\nuse Yireo\\NextGenImages\\Util\\File;\nuse Yireo\\NextGenImages\\Image\\Image;\nuse Yireo\\NextGenImages\\Image\\ImageFactory;\nuse Yireo\\Webp2\\Config\\Config;\nuse Yireo\\Webp2\\Convertor\\Convertor;\nuse Yireo\\Webp2\\Convertor\\ConvertWrapper;\n\nclass ConvertorTest extends TestCase\n{\n    /**\n     * Test for Yireo\\Webp2\\Convertor\\Convertor::getImage\n     */\n    public function testGetImage()\n    {\n        $config = $this->createMock(Config::class);\n        $config->method('enabled')->willReturn(true);\n        $convertor = $this->getConvertor($config);\n        \n        $this->expectException(ConvertorException::class);\n        $image = new Image('/tmp/pub/test/foobar.jpg', '/test/foobar.jpg');\n        $this->assertEquals('/test/foobar.webp', $convertor->convertImage($image));\n    }\n    \n    /**\n     * Test for Yireo\\Webp2\\Convertor\\Convertor::convertImage\n     */\n    public function testConvert()\n    {\n        $convertor = $this->getConvertor();\n        $this->expectException(ConvertorException::class);\n        $image = new Image('/tmp/pub/test/foobar.jpg', '/test/foobar.jpg');\n        $convertor->convertImage($image);\n    }\n    \n    /**\n     * Test for Yireo\\Webp2\\Convertor\\Convertor::convertImage\n     */\n    public function testItWillConvertSrcSetIfFound()\n    {\n        $givenSrcSet = '/test/foobar-small.jpg 500w, /test/foobar-medium.jpg 800w, /test/foobar-default.jpg';\n        $expectedSrcSet  = '/test/foobar-small.webp 500w, /test/foobar-medium.webp 800w, /test/foobar-default.webp ';\n        \n        $config = $this->createMock(Config::class);\n        $config->method('enabled')->willReturn(true);\n        $config->method('allowImageCreation')->willReturn(true);\n        $imageFile = $this->createMock(File::class);\n        $imageFile->method('fileExists')->willReturn(true);\n        $imageFile->method('needsConversion')->willReturn(true);\n        \n        $webpImageFile = $this->createMock(Image::class);\n        $webpImageFile->method('getUrl')->willReturnOnConsecutiveCalls(\n            '/test/foobar-small.webp',\n            '/test/foobar-medium.webp',\n            '/test/foobar-default.webp',\n        );\n        $webpImageFile->expects($this->once())\n            ->method('setSrcSet')\n            ->with($expectedSrcSet)\n            ->willReturnSelf();\n        $convertWrapper = $this->createMock(ConvertWrapper::class);\n        $targetImageFactory = $this->createMock(TargetImageFactory::class);\n        $targetImageFactory->method('create')->willReturn($webpImageFile);\n        $imageFactory = $this->createMock(ImageFactory::class);\n        \n        $convertor = new Convertor(\n            $config,\n            $imageFile,\n            $convertWrapper,\n            $targetImageFactory,\n            $imageFactory\n        );\n        \n        $image = new Image('/tmp/pub/test/foobar.jpg', '/test/foobar.jpg', $givenSrcSet);\n        $convertedImage = $convertor->convertImage($image);\n    }\n    \n    /**\n     * @param Config|null $config\n     * @return Convertor\n     */\n    private function getConvertor(?Config $config = null): Convertor\n    {\n        if (!$config) {\n            $config = $this->createMock(Config::class);\n        }\n        \n        $file = $this->createMock(File::class);\n        $convertWrapper = $this->createMock(ConvertWrapper::class);\n        $targetImageFactory = $this->createMock(TargetImageFactory::class);\n        $imageFactory = $this->createMock(ImageFactory::class);\n        \n        return new Convertor(\n            $config,\n            $file,\n            $convertWrapper,\n            $targetImageFactory,\n            $imageFactory\n        );\n    }\n}\n"
  },
  {
    "path": "Test/Utils/ConvertWrapperStub.php",
    "content": "<?php declare(strict_types=1);\n\nnamespace Yireo\\Webp2\\Test\\Utils;\n\nuse Yireo\\Webp2\\Convertor\\ConvertWrapper;\n\n/**\n * Class ConvertWrapper to wrap third party wrapper for purpose of preference overrides and testing\n */\nclass ConvertWrapperStub extends ConvertWrapper\n{\n    /**\n     * @param string $sourceImageFilename\n     * @param string $destinationImageFilename\n     */\n    public function convert(string $sourceImageFilename, string $destinationImageFilename): void\n    {\n        copy($sourceImageFilename, $destinationImageFilename);\n    }\n}\n"
  },
  {
    "path": "Test/Utils/ImageProvider.php",
    "content": "<?php\ndeclare(strict_types=1);\n\nnamespace Yireo\\Webp2\\Test\\Utils;\n\nuse Magento\\Framework\\View\\Element\\Block\\ArgumentInterface;\n\nclass ImageProvider implements ArgumentInterface\n{\n    /**\n     * @return string[]\n     */\n    public function getImages(): array\n    {\n        return [\n            'images/test/flowers.jpg',\n            'images/test/goku.jpg',\n            'images/test/transparent-dragon.png',\n        ];\n    }\n\n    /**\n     * @return string\n     */\n    public function getImage(): string\n    {\n        $images = $this->getImages();\n        return $images[0];\n    }\n\n    /**\n     * @return string\n     */\n    public function getNonExistingImage(): string\n    {\n        return 'images/test/non-existing.jpg';\n    }\n}\n"
  },
  {
    "path": "composer.json",
    "content": "{\n    \"name\": \"yireo/magento2-webp2\",\n    \"license\": \"OSL-3.0\",\n    \"version\": \"0.14.3\",\n    \"type\": \"magento2-module\",\n    \"homepage\": \"https://www.yireo.com/software/magento-extensions/webp2\",\n    \"description\": \"Magento 2 module to add WebP support to the Magento frontend\",\n    \"keywords\": [\n        \"composer-installer\",\n        \"magento\",\n        \"Magento 2\",\n        \"Exception\",\n        \"Yireo\"\n    ],\n    \"authors\": [\n        {\n            \"name\": \"Jisse Reitsma (Yireo)\",\n            \"email\": \"jisse@yireo.com\"\n        }\n    ],\n    \"require\": {\n        \"yireo/magento2-next-gen-images\": \"~0.3\",\n        \"yireo/magento2-csp-utilities\": \"^1.0\",\n        \"magento/framework\": \"^101.0.1|^101.1|^102.0|^103.0\",\n        \"magento/module-backend\": \"^100.0|^101.0|^102.0\",\n        \"magento/module-config\": \"^101.0\",\n        \"magento/module-store\": \"^101.0\",\n        \"rosell-dk/webp-convert\": \"^2.0\",\n        \"psr/log\": \"^1 || ^2 || ^3\",\n        \"php\": \">=7.4.0\",\n        \"ext-json\": \"*\",\n        \"ext-pcre\": \"*\",\n        \"ext-gd\": \"*\"\n    },\n    \"require-dev\": {\n        \"phpunit/phpunit\": \"^9.0|^10.0|^11.0\",\n        \"phpstan/phpstan\": \"^0.12.32\",\n        \"bitexpert/phpstan-magento\": \"^0.3.0\",\n        \"yireo/magento2-integration-test-helper\": \"^0.0.8\"\n    },\n    \"suggest\": {\n        \"yireo/magento2-webp2-for-hyva\": \"Additional fixes with Yireo Webp2 for Hyva\",\n        \"yireo/magento2-webp2-graph-ql\": \"GraphQL endpoints for Yireo Webp2\"\n    },\n    \"autoload\": {\n        \"psr-4\": {\n            \"Yireo\\\\Webp2\\\\\": \"\"\n        },\n        \"files\": [\n            \"registration.php\"\n        ]\n    },\n    \"funding\": [\n        {\n            \"type\": \"github\",\n            \"url\": \"https://github.com/sponsors/jissereitsma\"\n        },\n        {\n            \"type\": \"github\",\n            \"url\": \"https://github.com/sponsors/yireo\"\n        },\n        {\n            \"type\": \"paypal\",\n            \"url\": \"https://www.paypal.me/yireo\"\n        },\n        {\n            \"type\": \"other\",\n            \"url\": \"https://www.buymeacoffee.com/jissereitsma\"\n        }\n    ]\n}\n"
  },
  {
    "path": "etc/acl.xml",
    "content": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<config xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"urn:magento:framework:Acl/etc/acl.xsd\">\n    <acl>\n        <resources>\n            <resource id=\"Magento_Backend::admin\">\n                <resource id=\"Yireo_Webp2::config\" title=\"Yireo_Webp2\" sortOrder=\"100\"/>\n            </resource>\n        </resources>\n    </acl>\n</config>\n"
  },
  {
    "path": "etc/adminhtml/system.xml",
    "content": "<?xml version=\"1.0\"?>\n<config xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"urn:magento:module:Magento_Config:etc/system_file.xsd\">\n    <system>\n        <tab id=\"yireo\" sortOrder=\"999\" translate=\"label\">\n            <label>Yireo</label>\n        </tab>\n        <section id=\"yireo_webp2\" translate=\"label\" sortOrder=\"342\" showInDefault=\"1\" showInWebsite=\"1\" showInStore=\"1\">\n            <label>Yireo WebP2</label>\n            <tab>yireo</tab>\n            <resource>Yireo_Webp2::config</resource>\n            <group id=\"settings\" translate=\"label\" type=\"text\" sortOrder=\"34\" showInDefault=\"1\" showInWebsite=\"1\" showInStore=\"1\">\n                <label>Settings</label>\n                <field id=\"funding\" type=\"note\" sortOrder=\"1\" showInDefault=\"1\" showInWebsite=\"1\" showInStore=\"1\">\n                    <label>Funding</label>\n                    <frontend_model>Yireo\\Webp2\\Config\\Frontend\\Funding</frontend_model>\n                </field>\n                <field id=\"enabled\" translate=\"label\" type=\"select\" sortOrder=\"1\" showInDefault=\"1\" showInWebsite=\"1\" showInStore=\"1\" canRestore=\"1\">\n                    <label>Enabled</label>\n                    <source_model>Magento\\Config\\Model\\Config\\Source\\Yesno</source_model>\n                </field>\n                <field id=\"quality_level\" translate=\"label\" type=\"text\" sortOrder=\"1\" showInDefault=\"1\" showInWebsite=\"1\" showInStore=\"1\" canRestore=\"1\">\n                    <label>Quality level</label>\n                    <comment><![CDATA[Between 0 and 100]]></comment>\n                    <depends>\n                        <field id=\"*/*/enabled\">1</field>\n                    </depends>\n                </field>\n                <field id=\"module_version\" translate=\"label\" type=\"select\" sortOrder=\"3\" showInDefault=\"1\" showInWebsite=\"1\" showInStore=\"1\" canRestore=\"1\">\n                    <label>Module version</label>\n                    <frontend_model>Yireo\\Webp2\\VirtualType\\Block\\Adminhtml\\System\\Config\\ModuleVersion</frontend_model>\n                    <depends>\n                        <field id=\"*/*/enabled\">1</field>\n                    </depends>\n                </field>\n                <field id=\"convertors\" translate=\"label\" type=\"text\" sortOrder=\"1\" showInDefault=\"1\" showInWebsite=\"1\" showInStore=\"0\" canRestore=\"1\">\n                    <label>Convertors</label>\n                    <comment><![CDATA[Allowed values: cwebp,gd,imagick,wpc,ewww]]></comment>\n                    <depends>\n                        <field id=\"*/*/enabled\">1</field>\n                    </depends>\n                </field>\n                <field id=\"encoding\" translate=\"label\" type=\"select\" sortOrder=\"1\" showInDefault=\"1\" showInWebsite=\"1\" showInStore=\"0\" canRestore=\"1\">\n                    <label>Encoding</label>\n                    <source_model>Yireo\\Webp2\\Model\\Config\\Source\\Encoding</source_model>\n                    <comment><![CDATA[Allowed values: lossy,lossless,auto]]></comment>\n                    <depends>\n                        <field id=\"*/*/enabled\">1</field>\n                    </depends>\n                </field>\n            </group>\n        </section>\n    </system>\n</config>\n"
  },
  {
    "path": "etc/config.xml",
    "content": "<?xml version=\"1.0\"?>\n<!--\n/**\n * Yireo Webp2 for Magento\n *\n * @author      Yireo (https://www.yireo.com/)\n * @copyright   Copyright 2019 Yireo (https://www.yireo.com/)\n * @license     Open Source License (OSL v3)\n */\n-->\n<config xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"urn:magento:module:Magento_Store:etc/config.xsd\">\n    <default>\n        <yireo_webp2>\n            <settings>\n                <enabled>1</enabled>\n                <quality_level>80</quality_level>\n                <convertors>cwebp,gd,imagick,wpc,ewww</convertors>\n                <encoding>lossy</encoding>\n            </settings>\n        </yireo_webp2>\n    </default>\n</config>\n"
  },
  {
    "path": "etc/di.xml",
    "content": "<?xml version=\"1.0\"?>\n<config xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n        xsi:noNamespaceSchemaLocation=\"urn:magento:framework:ObjectManager/etc/config.xsd\">\n    <type name=\"Yireo\\NextGenImages\\Convertor\\ConvertorListing\">\n        <arguments>\n            <argument name=\"convertors\" xsi:type=\"array\">\n                <item name=\"webp2\" xsi:type=\"object\">Yireo\\Webp2\\Convertor\\Convertor</item>\n            </argument>\n        </arguments>\n    </type>\n\n    <virtualType name=\"Yireo\\Webp2\\VirtualType\\Block\\Adminhtml\\System\\Config\\ModuleVersion\" type=\"Yireo\\NextGenImages\\Block\\Adminhtml\\System\\Config\\ModuleVersion\">\n        <arguments>\n            <argument name=\"moduleName\" xsi:type=\"string\">Yireo_Webp2</argument>\n        </arguments>\n    </virtualType>\n</config>\n"
  },
  {
    "path": "etc/frontend/di.xml",
    "content": "<?xml version=\"1.0\"?>\n<config xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n        xsi:noNamespaceSchemaLocation=\"urn:magento:framework:ObjectManager/etc/config.xsd\">\n    <type name=\"Magento\\Framework\\View\\Element\\Template\">\n        <plugin name=\"Yireo_Webp2::addCspInlineScripts\" type=\"Yireo\\Webp2\\Plugin\\AddCspInlineScripts\"/>\n    </type>\n</config>\n"
  },
  {
    "path": "etc/frontend/routes.xml",
    "content": "<?xml version=\"1.0\" ?>\n<config xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"urn:magento:framework:App/etc/routes.xsd\">\n    <router id=\"standard\">\n        <route frontName=\"webp\" id=\"webp\">\n            <module name=\"Yireo_Webp2\"/>\n        </route>\n    </router>\n</config>"
  },
  {
    "path": "etc/module.xml",
    "content": "<?xml version=\"1.0\"?>\n<config xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"urn:magento:framework:Module/etc/module.xsd\">\n    <module name=\"Yireo_Webp2\" setup_version=\"0.4.0\">\n        <sequence>\n            <module name=\"Yireo_NextGenImages\" />\n            <module name=\"Yireo_CspUtilities\" />\n            <module name=\"Magento_Backend\" />\n            <module name=\"Magento_Config\" />\n            <module name=\"Magento_Store\" />\n        </sequence>\n    </module>\n</config>\n"
  },
  {
    "path": "phpstan.neon",
    "content": "parameters:\n    excludePaths:\n        - */Test/*/*\n"
  },
  {
    "path": "registration.php",
    "content": "<?php\n/**\n * Webp2 module for Magento\n *\n * @author      Yireo (https://www.yireo.com/)\n * @copyright   Copyright 2019 Yireo (https://www.yireo.com/)\n * @license     Open Source License\n */\n\nuse Magento\\Framework\\Component\\ComponentRegistrar;\n\nComponentRegistrar::register(\n    ComponentRegistrar::MODULE,\n    'Yireo_Webp2',\n    __DIR__\n);\n"
  },
  {
    "path": "view/adminhtml/templates/funding.phtml",
    "content": "<?php\n?>\n<div class=\"yireo-funding\">\n    <div class=\"github-logo\">\n        <svg xmlns=\"http://www.w3.org/2000/svg\" height=\"800\" width=\"1200\" viewBox=\"-74.4 -120.90175 644.8 725.4105\">\n            <path\n                d=\"M165.9 389.4c0 2-2.3 3.6-5.2 3.6-3.3.3-5.6-1.3-5.6-3.6 0-2 2.3-3.6 5.2-3.6 3-.3 5.6 1.3 5.6 3.6zm-31.1-4.5c-.7 2 1.3 4.3 4.3 4.9 2.6 1 5.6 0 6.2-2 .6-2-1.3-4.3-4.3-5.2-2.6-.7-5.5.3-6.2 2.3zm44.2-1.7c-2.9.7-4.9 2.6-4.6 4.9.3 2 2.9 3.3 5.9 2.6 2.9-.7 4.9-2.6 4.6-4.6-.3-1.9-3-3.2-5.9-2.9zM244.8 0C106.1 0 0 105.3 0 244c0 110.9 69.8 205.8 169.5 239.2 12.8 2.3 17.3-5.6 17.3-12.1 0-6.2-.3-40.4-.3-61.4 0 0-70 15-84.7-29.8 0 0-11.4-29.1-27.8-36.6 0 0-22.9-15.7 1.6-15.4 0 0 24.9 2 38.6 25.8 21.9 38.6 58.6 27.5 72.9 20.9 2.3-16 8.8-27.1 16-33.7-55.9-6.2-112.3-14.3-112.3-110.5 0-27.5 7.6-41.3 23.6-58.9-2.6-6.5-11.1-33.3 2.6-67.9 20.9-6.5 69 27 69 27 20-5.6 41.5-8.5 62.8-8.5 21.3 0 42.8 2.9 62.8 8.5 0 0 48.1-33.6 69-27 13.7 34.7 5.2 61.4 2.6 67.9 16 17.7 25.8 31.5 25.8 58.9 0 96.5-58.9 104.2-114.8 110.5 9.2 7.9 17 22.9 17 46.4 0 33.7-.3 75.4-.3 83.6 0 6.5 4.6 14.4 17.3 12.1C428.2 449.8 496 354.9 496 244 496 105.3 383.5 0 244.8 0zM97.2 344.9c-1.3 1-1 3.3.7 5.2 1.6 1.6 3.9 2.3 5.2 1 1.3-1 1-3.3-.7-5.2-1.6-1.6-3.9-2.3-5.2-1zm-10.8-8.1c-.7 1.3.3 2.9 2.3 3.9 1.6 1 3.6.7 4.3-.7.7-1.3-.3-2.9-2.3-3.9-2-.6-3.6-.3-4.3.7zm32.4 35.6c-1.6 1.3-1 4.3 1.3 6.2 2.3 2.3 5.2 2.6 6.5 1 1.3-1.3.7-4.3-1.3-6.2-2.2-2.3-5.2-2.6-6.5-1zm-11.4-14.7c-1.6 1-1.6 3.6 0 5.9 1.6 2.3 4.3 3.3 5.6 2.3 1.6-1.3 1.6-3.9 0-6.2-1.4-2.3-4-3.3-5.6-2z\"/>\n        </svg>\n    </div>\n    <div class=\"details\">\n        <h3>Consider sponsoring this extension</h3>\n        <p>\n            This extension is totally free. It takes time to develop and maintain though, all on a voluntary basis.\n            If you are using this extension in a Magento shop that earns you money (either as an agency, as a developer\n            or as a merchant),\n            please consider sponsoring me and/or Yireo via GitHub. It would be appreciated and would help me to build\n            even more cool things.\n        </p>\n        <ul>\n            <li><a href=\"https://github.com/sponsors/jissereitsma\">https://github.com/sponsors/jissereitsma</a></li>\n            <li><a href=\"https://github.com/sponsors/yireo\">https://github.com/sponsors/yireo</a></li>\n        </ul>\n    </div>\n</div>\n\n<style>\n    .yireo-funding {\n        display: flex;\n        background: #f8f8f8;\n        border: 1px solid #e3e3e3;\n        padding: 30px;\n    }\n\n    .yireo-funding .github-logo {\n        width: 150px;\n        min-width: 150px;\n        margin-right: 10px;\n    }\n\n    .yireo-funding .github-logo svg {\n        width: 100%;\n        height: auto;\n    }\n\n    .yireo-funding .details ul {\n        margin-left: 20px;\n    }\n</style>\n"
  },
  {
    "path": "view/frontend/layout/hyva_catalog_category_view.xml",
    "content": "<?xml version=\"1.0\"?>\n<page xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n      xsi:noNamespaceSchemaLocation=\"urn:magento:module:View/Layout:etc/page_configuration.xsd\">\n    <body>\n        <referenceContainer name=\"content\">\n            <block name=\"yireo_webp2.gallery-additions\" template=\"Yireo_Webp2::hyva/gallery-additions.phtml\"/>\n        </referenceContainer>\n    </body>\n</page>\n"
  },
  {
    "path": "view/frontend/layout/hyva_catalog_product_view.xml",
    "content": "<?xml version=\"1.0\"?>\n<page xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n      xsi:noNamespaceSchemaLocation=\"urn:magento:module:View/Layout:etc/page_configuration.xsd\">\n    <body>\n        <referenceContainer name=\"content\">\n            <block name=\"yireo_webp2.gallery-additions\" template=\"Yireo_Webp2::hyva/gallery-additions.phtml\"/>\n        </referenceContainer>\n    </body>\n</page>\n"
  },
  {
    "path": "view/frontend/layout/hyva_default.xml",
    "content": "<?xml version=\"1.0\"?>\n<page xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n      xsi:noNamespaceSchemaLocation=\"urn:magento:module:View/Layout:etc/page_configuration.xsd\">\n    <body>\n        <referenceContainer name=\"content\">\n            <block name=\"yireo_webp2.add-webp-class-to-body\" template=\"Yireo_Webp2::hyva/add-webp-class-to-body.phtml\"/>\n        </referenceContainer>\n    </body>\n</page>\n"
  },
  {
    "path": "view/frontend/layout/webp_test_images_image_with_custom_style.xml",
    "content": "<?xml version=\"1.0\"?>\n<page xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"urn:magento:framework:View/Layout/etc/page_configuration.xsd\" layout=\"empty\">\n    <body>\n        <referenceContainer name=\"main\">\n            <block name=\"webp-multiple-image-with-custom-style\" template=\"Yireo_Webp2::test/image_with_custom_style.phtml\" before=\"-\">\n                <arguments>\n                    <argument name=\"image_provider\" xsi:type=\"object\">Yireo\\Webp2\\Test\\Utils\\ImageProvider</argument>\n                </arguments>\n            </block>\n        </referenceContainer>\n    </body>\n</page>\n"
  },
  {
    "path": "view/frontend/layout/webp_test_images_multiple_existing_picturesets.xml",
    "content": "<?xml version=\"1.0\"?>\n<page xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"urn:magento:framework:View/Layout/etc/page_configuration.xsd\" layout=\"empty\">\n    <body>\n        <referenceContainer name=\"main\">\n            <block name=\"webp-multiple-existing-imagesets\" template=\"Yireo_Webp2::test/multiple_existing_picturesets.phtml\" before=\"-\">\n                <arguments>\n                    <argument name=\"image_provider\" xsi:type=\"object\">Yireo\\Webp2\\Test\\Utils\\ImageProvider</argument>\n                </arguments>\n            </block>\n        </referenceContainer>\n    </body>\n</page>\n"
  },
  {
    "path": "view/frontend/layout/webp_test_images_multiple_images.xml",
    "content": "<?xml version=\"1.0\"?>\n<page xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"urn:magento:framework:View/Layout/etc/page_configuration.xsd\" layout=\"empty\">\n    <body>\n        <referenceContainer name=\"main\">\n            <block name=\"webp-multiple-images\" template=\"Yireo_Webp2::test/multiple_images.phtml\" before=\"-\">\n                <arguments>\n                    <argument name=\"image_provider\" xsi:type=\"object\">Yireo\\Webp2\\Test\\Utils\\ImageProvider</argument>\n                </arguments>\n            </block>\n        </referenceContainer>\n    </body>\n</page>\n"
  },
  {
    "path": "view/frontend/layout/webp_test_images_multiple_images_same.xml",
    "content": "<?xml version=\"1.0\"?>\n<page xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"urn:magento:framework:View/Layout/etc/page_configuration.xsd\" layout=\"empty\">\n    <body>\n        <referenceContainer name=\"main\">\n            <block name=\"webp-multiple-images-same\" template=\"Yireo_Webp2::test/multiple_images_same.phtml\" before=\"-\">\n                <arguments>\n                    <argument name=\"image_provider\" xsi:type=\"object\">Yireo\\Webp2\\Test\\Utils\\ImageProvider</argument>\n                </arguments>\n            </block>\n        </referenceContainer>\n    </body>\n</page>\n"
  },
  {
    "path": "view/frontend/layout/webp_test_images_unknown_image.xml",
    "content": "<?xml version=\"1.0\"?>\n<page xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"urn:magento:framework:View/Layout/etc/page_configuration.xsd\" layout=\"empty\">\n    <body>\n        <referenceContainer name=\"main\">\n            <block name=\"webp-multiple-images\" template=\"Yireo_Webp2::test/unknown_image.phtml\" before=\"-\">\n                <arguments>\n                    <argument name=\"image_provider\" xsi:type=\"object\">Yireo\\Webp2\\Test\\Utils\\ImageProvider</argument>\n                </arguments>\n            </block>\n        </referenceContainer>\n    </body>\n</page>\n"
  },
  {
    "path": "view/frontend/requirejs-config.js",
    "content": "var config = {\n    config: {\n        mixins: {\n            'Magento_Swatches/js/swatch-renderer': {\n                'Yireo_Webp2/js/swatch-renderer-mixin': true\n            },\n            'mage/gallery/gallery': {\n                'Yireo_Webp2/js/gallery-mixin': true\n            }\n        }\n    },\n    deps: [\n        'Yireo_Webp2/js/add-webp-class-to-body'\n    ]\n};\n"
  },
  {
    "path": "view/frontend/templates/hyva/add-webp-class-to-body.phtml",
    "content": "<?php declare(strict_types=1); ?> <script>\n    function hasWebP() {\n        var elem = document.createElement('canvas');\n\n        if (!!(elem.getContext && elem.getContext('2d'))) {\n            return elem.toDataURL('image/webp').indexOf('data:image/webp') === 0;\n        }\n        return false;\n    }\n\n    if (hasWebP()) {\n        document.body.classList.add(\"webp\");\n    } else {\n        document.body.classList.add(\"no-webp\");\n    }</script>"
  },
  {
    "path": "view/frontend/templates/hyva/gallery-additions.phtml",
    "content": "<script>\n    const yireoWebp2ReplaceImage = function (image) {\n        if (image.full && image.full_webp) {\n            image.full = image.full_webp;\n            delete image.full_webp;\n        }\n\n        if (image.img && image.img_webp) {\n            image.img = image.img_webp;\n            delete image.img_webp;\n        }\n\n        if (image.thumb && image.thumb_webp) {\n            image.thumb = image.thumb_webp;\n            delete image.thumb_webp;\n        }\n\n        return image;\n    }\n\n    document.addEventListener('after-product-item-image-update', ({detail: element}) => {\n        if (typeof hasWebP != 'function') {\n            console.error('[Yireo_WebP2] JavaScript function \"hasWebP\" does not exist');\n            return;\n        }\n\n        const imageUrl = element.src;\n        const webpUrl = imageUrl.replace(/.jpg$/, '.webp');\n        const picture = element.closest('picture');\n        const webpSource = picture.querySelector('source[type=\"image/webp\"]');\n        webpSource.srcset = webpUrl;\n    });\n\n    document.addEventListener('configurable-options-init', ({detail: optionConfig}) => {\n        if (typeof hasWebP != 'function') {\n            console.error('[Yireo_WebP2] JavaScript function \"hasWebP\" does not exist');\n            return;\n        }\n\n        if (optionConfig.images) {\n            Object.entries(optionConfig.images).forEach(([key, imageArray]) => {\n                Object.entries(imageArray).forEach(([index, image]) => {\n                    imageArray[index] = yireoWebp2ReplaceImage(image);\n                });\n                optionConfig.images[key] = imageArray;\n            });\n        }\n    });\n\n    document.addEventListener('gallery-init', ({detail: galleryData}) => {\n        if (typeof hasWebP != 'function') {\n            console.error('[Yireo_WebP2] JavaScript function \"hasWebP\" does not exist');\n            return;\n        }\n\n        if (galleryData.images) {\n            galleryData.images.forEach(function (image) {\n                yireoWebp2ReplaceImage(image);\n            });\n        }\n\n        if (galleryData.initialImages) {\n            galleryData.initialImages.forEach(function (image) {\n                yireoWebp2ReplaceImage(image);\n            });\n        }\n\n    });</script>\n"
  },
  {
    "path": "view/frontend/templates/test/image_with_custom_style.phtml",
    "content": "<?php declare(strict_types=1); /** @var $block \\Magento\\Framework\\View\\Element\\Template */ /** @var $imageProvider \\Yireo\\Webp2\\Test\\Utils\\ImageProvider */ $imageProvider = $block->getImageProvider(); $image = $imageProvider->getImage(); $imageUrl = $block->escapeUrl($block->getViewFileUrl('Yireo_Webp2/' . $image)); ?> <h1><?= /* @noEscape */ $block->getNameInLayout() ?></h1><img class=\"alt-img\" src=\"<?= /* @noEscape */ $imageUrl ?>\" alt=\"test sample\" style=\"display:insane; opacity:666;\"><h2>Layout handles</h2><pre><?= implode(', ', /* @noEscape */ $block->getLayout()->getUpdate()->getHandles()); ?></pre>"
  },
  {
    "path": "view/frontend/templates/test/multiple_existing_picturesets.phtml",
    "content": "<?php declare(strict_types=1); /** @var $block \\Magento\\Framework\\View\\Element\\Template */ /** @var $imageProvider \\Yireo\\Webp2\\Test\\Utils\\ImageProvider */ $imageProvider = $block->getImageProvider(); $images = $imageProvider->getImages(); $imageUrl = $block->escapeUrl($block->getViewFileUrl('Yireo_Webp2/' . $image)); ?> <h1><?= /* @noEscape */ $block->getNameInLayout() ?></h1><?php foreach ($images as $image): ?> <div><picture><img src=\"<?= /* @noEscape */ $imageUrl ?>\" width=\"100\" height=\"100\"/></picture></div><?php endforeach; ?> <h2>Layout handles</h2><pre><?= implode(', ', /* @noEscape */ $block->getLayout()->getUpdate()->getHandles()); ?></pre>"
  },
  {
    "path": "view/frontend/templates/test/multiple_images.phtml",
    "content": "<?php declare(strict_types=1); /** @var $block \\Magento\\Framework\\View\\Element\\Template */ /** @var $imageProvider \\Yireo\\Webp2\\Test\\Utils\\ImageProvider */ $imageProvider = $block->getImageProvider(); $images = $imageProvider->getImages(); ?> <h1><?= /* @noEscape */ $block->getNameInLayout() ?></h1><?php foreach ($images as $image): ?> <?php $imageUrl = $block->escapeUrl($block->getViewFileUrl('Yireo_Webp2/' . $image)); ?> <div><img src=\"<?= /* @noEscape */ $imageUrl ?>\" width=\"100\" height=\"100\"/></div><?php endforeach; ?> <h2>Layout handles</h2><pre><?= implode(', ', /* @noEscape */ $block->getLayout()->getUpdate()->getHandles()); ?></pre>"
  },
  {
    "path": "view/frontend/templates/test/multiple_images_same.phtml",
    "content": "<?php declare(strict_types=1); /** @var $block \\Magento\\Framework\\View\\Element\\Template */ /** @var $imageProvider \\Yireo\\Webp2\\Test\\Utils\\ImageProvider */ $imageProvider = $block->getImageProvider(); $image = $imageProvider->getImage(); ?> <h1><?= /* @noEscape */$block->getNameInLayout() ?></h1><?php for ($i = 0; $i < 3; $i++): ?> <div><img src=\"<?= $block->escapeUrl($block->getViewFileUrl('Yireo_Webp2/' . $image)) ?>\" width=\"100\" height=\"100\"/></div><?php endfor; ?> <h2>Layout handles</h2><pre><?= implode(', ', /* @noEscape */ $block->getLayout()->getUpdate()->getHandles()); ?></pre>"
  },
  {
    "path": "view/frontend/templates/test/unknown_image.phtml",
    "content": "<?php declare(strict_types=1); /** @var $block \\Magento\\Framework\\View\\Element\\Template */ ?> <img src=\"https://example.com/some/non/existing/image.png\" alt=\"\" width=\"10px\"><h2>Layout handles</h2><pre><?= implode(', ', /* @noEscape */ $block->getLayout()->getUpdate()->getHandles()); ?></pre>"
  },
  {
    "path": "view/frontend/web/js/add-webp-class-to-body.js",
    "content": "define([\n    'jquery',\n    './has-webp'\n], function($, hasWebP) {\n    if (hasWebP()) {\n        $('body').addClass('webp');\n    } else {\n        $('body').addClass('no-webp');\n    }\n});\n"
  },
  {
    "path": "view/frontend/web/js/gallery-mixin.js",
    "content": "define([\n    'jquery',\n    './has-webp',\n    \"domReady!\"\n], function ($, hasWebP) {\n    'use strict';\n\n    var mixin = {\n        initialize: function (config, element) {\n            if (hasWebP()) {\n                this._replaceImageDataWithWebp(config.data);\n            }\n            this._super(config, element);\n        },\n\n        _replaceImageDataWithWebp: function (imagesData) {\n            if (_.isEmpty(imagesData)) {\n                return;\n            }\n\n            $.each(imagesData, function (key, imageData) {\n                if (imageData['full_webp']) imageData['full'] = imageData['full_webp'];\n                if (imageData['img_webp'])imageData['img'] = imageData['img_webp'];\n                if (imageData['thumb_webp'])imageData['thumb'] = imageData['thumb_webp'];\n            });\n        }\n    };\n\n    return function (target) {\n        return target.extend(mixin);\n    }\n});"
  },
  {
    "path": "view/frontend/web/js/has-webp.js",
    "content": "define([], function () {\n    'use strict';\n\n    return function hasWebP() {\n        var elem = document.createElement('canvas');\n\n        if (!!(elem.getContext && elem.getContext('2d'))) {\n            return elem.toDataURL('image/webp').indexOf('data:image/webp') === 0;\n        }\n        return false;\n    }\n});\n"
  },
  {
    "path": "view/frontend/web/js/swatch-renderer-mixin.js",
    "content": "define([\n    'jquery',\n    './has-webp',\n    \"domReady!\"\n], function ($, hasWebP) {\n    'use strict';\n\n    return function (widget) {\n        $.widget('mage.SwatchRenderer', widget, {\n            _init: function () {\n                this._super();\n                if (hasWebP()) {\n                    $.each(this.options.jsonConfig.images, (function (key, imagesData) {\n                        $.each(imagesData, (function (key, imageData) {\n                            this._replaceImageData(imageData);\n                        }).bind(this));\n                    }).bind(this));\n                }\n            },\n\n            _ProductMediaCallback: function ($this, response, isInProductView) {\n                if (hasWebP()) {\n                    this._replaceImageData(response);\n                    if (response.gallery) {\n                        $.each(response.gallery, (function (key, galleryImage) {\n                            this._replaceImageData(galleryImage);\n                        }).bind(this));\n                    }\n                }\n\n                this._super($this, response, isInProductView);\n\n                var productData = this._determineProductData();\n                let $pictureTag = $('.product-image-container-' + productData.productId + ' picture');\n                $pictureTag.find('source').remove();\n            },\n\n            _replaceImageData: function (imageData) {\n                if (_.isEmpty(imageData)) {\n                    return imageData;\n                }\n\n                for (const [key, value] of Object.entries(imageData)) {\n                    if (imageData[key + '_webp']) {\n                        imageData[key] = imageData[key + '_webp'];\n                    }\n                }\n\n                return imageData;\n            }\n        });\n\n        return $.mage.SwatchRenderer;\n    }\n});\n"
  }
]