{"version":3,"file":"util.find-group-order-for-property.mjs","sources":["../../../../../src/rules/css/grouped-declarations/util.find-group-order-for-property.ts"],"sourcesContent":["import type { GroupOrder } from \"./config.order\";\n\n/**\n * Extracts the relevant group ordering for the current provided property.\n *\n * Do note that the first group order containing the provided property is\n * returned.\n *\n * Furthermore, an exact match isn't required, however, the provided prop need\n * not exactly match a given property in a groupOrder, it only needs to start\n * with the groupProp. e.g. \"font-family\" will match a group order which\n * contains the property \"font\"\n */\nexport function findGroupOrderForProperty(\n  property: string | undefined,\n): (groupOrder: GroupOrder) => boolean {\n  return (groupOrder) =>\n    findPropertyIndexInGroupOrder(groupOrder, property) !== undefined;\n}\n\nexport function findPropertyIndexInGroupOrder(\n  order: GroupOrder,\n  property: string | undefined,\n): number | undefined {\n  let index = order.findIndex(\n    (groupProp) =>\n      groupProp === property ||\n      [`-webkit-${groupProp}`, `-moz-${groupProp}`].includes(property ?? \"\"),\n  );\n\n  // If the index could not be resolved, then the current value may be an\n  // expanded form of the properties already included in the order. Thus we must\n  // search if this is the case.\n  if (index === -1) {\n    index = order.findIndex(\n      (groupProp) =>\n        property?.startsWith(groupProp) ||\n        property?.startsWith(`-webkit-${groupProp}`) ||\n        property?.startsWith(`-moz-${groupProp}`),\n    );\n\n    // In case we still haven't resolved the correct index after loosly matching\n    // then bail out immediately\n    if (index === -1) {\n      return undefined;\n    }\n\n    // expanded properties should always be ordered above their shorthand\n    // counterparts to avoid overriding due to CSS specificity. Thus we ensure\n    // a slightly higher index for expanded properties.\n    index *= 100;\n    index += 1;\n  } else {\n    // and for direct matches (which may or may not be shorthand) we simply\n    // multiply the index by a factor of two to avoid clashes with the shorthand\n    // /expanded property fixing.\n    index *= 100;\n  }\n\n  if (index === -1) {\n    return undefined;\n  } else {\n    return index;\n  }\n}\n"],"names":[],"mappings":"AAaO,SAAS,0BACd,QAAA,EACqC;AACrC,EAAA,OAAO,CAAC,UAAA,KACN,6BAAA,CAA8B,UAAA,EAAY,QAAQ,CAAA,KAAM,MAAA;AAC5D;AAEO,SAAS,6BAAA,CACd,OACA,QAAA,EACoB;AACpB,EAAA,IAAI,QAAQ,KAAA,CAAM,SAAA;AAAA,IAChB,CAAC,SAAA,KACC,SAAA,KAAc,QAAA,IACd,CAAC,CAAA,QAAA,EAAW,SAAS,CAAA,CAAA,EAAI,CAAA,KAAA,EAAQ,SAAS,CAAA,CAAE,CAAA,CAAE,QAAA,CAAS,YAAY,EAAE;AAAA,GACzE;AAKA,EAAA,IAAI,UAAU,EAAA,EAAI;AAChB,IAAA,KAAA,GAAQ,KAAA,CAAM,SAAA;AAAA,MACZ,CAAC,SAAA,KACC,QAAA,EAAU,UAAA,CAAW,SAAS,KAC9B,QAAA,EAAU,UAAA,CAAW,CAAA,QAAA,EAAW,SAAS,EAAE,CAAA,IAC3C,QAAA,EAAU,UAAA,CAAW,CAAA,KAAA,EAAQ,SAAS,CAAA,CAAE;AAAA,KAC5C;AAIA,IAAA,IAAI,UAAU,EAAA,EAAI;AAChB,MAAA,OAAO,MAAA;AAAA,IACT;AAKA,IAAA,KAAA,IAAS,GAAA;AACT,IAAA,KAAA,IAAS,CAAA;AAAA,EACX,CAAA,MAAO;AAIL,IAAA,KAAA,IAAS,GAAA;AAAA,EACX;AAEA,EAAA,IAAI,UAAU,EAAA,EAAI;AAChB,IAAA,OAAO,MAAA;AAAA,EACT,CAAA,MAAO;AACL,IAAA,OAAO,KAAA;AAAA,EACT;AACF;;;;"}