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,EAAG,GAAK,KAC3B,EAAS,UAAU,EAAG,GAAK,KAE3B,IACA,IACA,MACA,QAEE,EAAW,EAAU,MAAQ,EAAW,EAAU,OACpD,EAAkB,KAAK,SAGzB,IAAK,IAAI,EAAI,EAAG,EAAI,EAAkB,OAAQ,IAAK,CACjD,IAAI,EA7CS,aA6CW,EAAkB,GACtC,EAAY,EAAI,yBAAyB,EAAK,GAClD,GAAI,EACF,MAAkB,SAAd,EACK,EAAI,gBAAgB,EAAK,GAEzB,EAAI,iBAAiB,EAAK,EAGvC,CAEA,OAAO,IACT,CAyDmB,CAAkB,EAAI,OAAO,cAAc,IAAK,EAAI,OAAO,IAAI,QAM5E,OALI,IACF,EAAgB,GAChB,EAAI,OAAO,YAAa,EACxB,EAAI,OAAO,OAAS,IAEf,CACT,CACF,GAEH,CAhID","file":"/npm/htmx-ext-response-targets@2.0.3/dist/response-targets.esm.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.37.0.\n * Original file: /npm/htmx-ext-response-targets@2.0.3/dist/response-targets.esm.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","import htmx from 'htmx.org';\n(function() {\n  /** @type {import(\"../htmx\").HtmxInternalApi} */\n  var api\n\n  var attrPrefix = 'hx-target-'\n\n  // IE11 doesn't support string.startsWith\n  function startsWith(str, prefix) {\n    return str.substring(0, prefix.length) === prefix\n  }\n\n  /**\n     * @param {HTMLElement} elt\n     * @param {number} respCode\n     * @returns {HTMLElement | null}\n     */\n  function getRespCodeTarget(elt, respCodeNumber) {\n    if (!elt || !respCodeNumber) return null\n\n    var respCode = respCodeNumber.toString()\n\n    // '*' is the original syntax, as the obvious character for a wildcard.\n    // The 'x' alternative was added for maximum compatibility with HTML\n    // templating engines, due to ambiguity around which characters are\n    // supported in HTML attributes.\n    //\n    // Start with the most specific possible attribute and generalize from\n    // there.\n    var attrPossibilities = [\n      respCode,\n\n      respCode.substring(0, 2) + '*',\n      respCode.substring(0, 2) + 'x',\n\n      respCode.substring(0, 1) + '*',\n      respCode.substring(0, 1) + 'x',\n      respCode.substring(0, 1) + '**',\n      respCode.substring(0, 1) + 'xx',\n\n      '*',\n      'x',\n      '***',\n      'xxx'\n    ]\n    if (startsWith(respCode, '4') || startsWith(respCode, '5')) {\n      attrPossibilities.push('error')\n    }\n\n    for (var i = 0; i < attrPossibilities.length; i++) {\n      var attr = attrPrefix + attrPossibilities[i]\n      var attrValue = api.getClosestAttributeValue(elt, attr)\n      if (attrValue) {\n        if (attrValue === 'this') {\n          return api.findThisElement(elt, attr)\n        } else {\n          return api.querySelectorExt(elt, attrValue)\n        }\n      }\n    }\n\n    return null\n  }\n\n  /** @param {Event} evt */\n  function handleErrorFlag(evt) {\n    if (evt.detail.isError) {\n      if (htmx.config.responseTargetUnsetsError) {\n        evt.detail.isError = false\n      }\n    } else if (htmx.config.responseTargetSetsError) {\n      evt.detail.isError = true\n    }\n  }\n\n  htmx.defineExtension('response-targets', {\n\n    /** @param {import(\"../htmx\").HtmxInternalApi} apiRef */\n    init: function(apiRef) {\n      api = apiRef\n\n      if (htmx.config.responseTargetUnsetsError === undefined) {\n        htmx.config.responseTargetUnsetsError = true\n      }\n      if (htmx.config.responseTargetSetsError === undefined) {\n        htmx.config.responseTargetSetsError = false\n      }\n      if (htmx.config.responseTargetPrefersExisting === undefined) {\n        htmx.config.responseTargetPrefersExisting = false\n      }\n      if (htmx.config.responseTargetPrefersRetargetHeader === undefined) {\n        htmx.config.responseTargetPrefersRetargetHeader = true\n      }\n    },\n\n    /**\n         * @param {string} name\n         * @param {Event} evt\n         */\n    onEvent: function(name, evt) {\n      if (name === 'htmx:beforeSwap' &&\n                evt.detail.xhr &&\n                evt.detail.xhr.status !== 200) {\n        if (evt.detail.target) {\n          if (htmx.config.responseTargetPrefersExisting) {\n            evt.detail.shouldSwap = true\n            handleErrorFlag(evt)\n            return true\n          }\n          if (htmx.config.responseTargetPrefersRetargetHeader &&\n                        evt.detail.xhr.getAllResponseHeaders().match(/HX-Retarget:/i)) {\n            evt.detail.shouldSwap = true\n            handleErrorFlag(evt)\n            return true\n          }\n        }\n        if (!evt.detail.requestConfig) {\n          return true\n        }\n        var target = getRespCodeTarget(evt.detail.requestConfig.elt, evt.detail.xhr.status)\n        if (target) {\n          handleErrorFlag(evt)\n          evt.detail.shouldSwap = true\n          evt.detail.target = target\n        }\n        return true\n      }\n    }\n  })\n})()\n"]}