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AEA,SAAS,6BAAO,KAA6B;IAC3C,OAAO;QACL,WAAW;YACT,SAAS,+BAAS,CAAC,MAAM;YACzB,gBAAgB;QAClB;QACA,cAAc;YACZ,SAAS,kCAAY,CAAC,MAAM;YAC5B,eAAe;QACjB;IACF;AACF","sources":["packages/@react-spectrum/ai/src/style/prose.ts"],"sourcesContent":["/*\n * Copyright 2024 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {colorToken, getToken} from '../../../s2/style/tokens' with {type: 'macro'};\nimport {\n  colorTokenToString,\n  fontFamily,\n  fontSize,\n  fontSizeCalc,\n  fontWeight,\n  lineHeight,\n  resolveColorToken,\n  space\n} from '../../../s2/style/spectrum-theme' with {type: 'macro'};\n\ninterface MacroContext {\n  addAsset(asset: {type: string; content: string}): void;\n}\n\nconst marginTop = {\n  body: getToken('body-margin-multiplier') + 'em',\n  heading: 1 + 'em',\n  title: 1 + 'em',\n  detail: 1 + 'em'\n} as const;\n\nconst marginBottom = {\n  body: getToken('body-margin-multiplier') + 'em',\n  heading: getToken('heading-margin-bottom-multiplier') + 'em',\n  title: getToken('title-margin-bottom-multiplier') + 'em',\n  detail: 1 + 'em'\n} as const;\n\nexport function prose(this: MacroContext | void) {\n  let rules = {\n    '.prose': font('body'), // note: `prose` is a placeholder class name that is replaced with a hashed class name below\n    h1: {\n      ...font('heading-xl'),\n      ...margin('heading')\n    },\n    h2: {\n      ...font('heading-lg'),\n      ...margin('heading')\n    },\n    h3: {\n      ...font('heading'),\n      ...margin('heading')\n    },\n    h4: {\n      ...font('heading-sm'),\n      ...margin('heading')\n    },\n    h5: {\n      ...font('heading-xs'),\n      ...margin('heading')\n    },\n    h6: {\n      ...font('heading-2xs'),\n      ...margin('heading')\n    },\n    pre: {\n      ...font('code-sm'),\n      borderRadius: getToken('corner-radius-large-default'),\n      backgroundColor: colorTokenToString(\n        resolveColorToken(colorToken('background-layer-1-color'))\n      ),\n      margin: 0,\n      padding: '16px',\n      width: '100%',\n      overflow: 'auto',\n      boxSizing: 'border-box'\n    },\n    p: {\n      ...margin('body')\n    },\n    'ul, ol': {\n      paddingInlineStart: `${24 / 16}rem`,\n      marginTop: {\n        default: marginTop.body,\n        ':is(li > *)': 0\n      },\n      marginBottom: {\n        default: marginBottom.body,\n        ':is(li > *)': 0\n      }\n    },\n    ul: {\n      listStyleType: 'disc'\n    },\n    ol: {\n      listStyleType: 'decimal'\n    },\n    li: {\n      marginTop: '.25em',\n      marginBottom: '.25em'\n    },\n    'li > p:last-child:not(:first-child)': {\n      marginBottom: marginBottom.body\n    },\n    blockquote: {\n      ...margin('body'),\n      borderStyle: 'solid',\n      borderWidth: 0,\n      borderColor: colorTokenToString(resolveColorToken(colorToken('gray-200'))),\n      borderInlineStartWidth: getToken('border-width-200'),\n      // Padding uses px, spacing (margin) uses rem — matching the style macro's maps.\n      paddingInlineStart: '14px',\n      marginInlineStart: space(8)\n    },\n    hr: {\n      marginBlock: '32px',\n      height: '2px',\n      borderRadius: '2px',\n      borderStyle: 'none',\n      backgroundColor: colorTokenToString(resolveColorToken(colorToken('gray-200')))\n    },\n    'code:not(pre code)': {\n      ...font('code'),\n      fontSize: 'inherit',\n      backgroundColor: colorTokenToString(\n        resolveColorToken(colorToken('background-layer-1-color'))\n      ),\n      paddingInline: '4px',\n      borderWidth: getToken('border-width-100'),\n      borderColor: colorTokenToString(resolveColorToken(colorToken('gray-100'))),\n      borderStyle: 'solid',\n      borderRadius: getToken('corner-radius-small-default'),\n      whiteSpace: 'pre-wrap'\n    },\n    kbd: {\n      ...font('ui'),\n      fontSize: 'inherit',\n      paddingInline: '8px',\n      paddingBlock: '2px',\n      whiteSpace: 'nowrap',\n      backgroundColor: colorTokenToString(resolveColorToken(colorToken('gray-100'))),\n      borderRadius: getToken('corner-radius-small-default'),\n      unicodeBidi: 'plaintext'\n    },\n    a: {\n      color: {\n        default: colorTokenToString(resolveColorToken(colorToken('accent-content-color-default'))),\n        ':hover': colorTokenToString(resolveColorToken(colorToken('accent-content-color-hover'))),\n        ':active': colorTokenToString(resolveColorToken(colorToken('accent-content-color-down')))\n      },\n      textDecoration: 'underline',\n      transition: 'color 200ms'\n    },\n    ':is(h1, h2, h3, h4, h5, h6, hr) + *': {\n      marginTop: 0\n    },\n    table: {\n      ...font('ui'),\n      ...margin('body'),\n      backgroundColor: colorTokenToString(resolveColorToken(colorToken('gray-25'))),\n      borderRadius: getToken('corner-radius-medium-default'),\n      borderColor: colorTokenToString(resolveColorToken(colorToken('gray-300'))),\n      borderWidth: '1px',\n      borderStyle: 'solid',\n      overflow: 'hidden',\n      borderSpacing: 0,\n      width: '100%'\n    },\n    thead: {\n      backgroundColor: colorTokenToString(resolveColorToken(colorToken('gray-75'))),\n      // `borderTopRadius` isn't a real CSS property; the style macro expands it into\n      // the two top logical-corner properties, so do the same here.\n      borderStartStartRadius: getToken('corner-radius-medium-default'),\n      borderStartEndRadius: getToken('corner-radius-medium-default')\n    },\n    th: {\n      // height behaves like minHeight in a table\n      height: 32,\n      paddingInline: '16px',\n      paddingBlock: '4px',\n      textAlign: 'start',\n      fontWeight: 'bold',\n      borderColor: colorTokenToString(resolveColorToken(colorToken('gray-300'))),\n      borderWidth: 0,\n      borderBottomWidth: getToken('border-width-100'),\n      borderStyle: 'solid',\n      boxSizing: 'border-box'\n    },\n    td: {\n      height: 32,\n      paddingInline: '16px',\n      paddingBlock: '4px',\n      borderWidth: 0,\n      borderBottomWidth: {\n        default: getToken('border-width-100'),\n        ':is(tbody:last-child > tr:last-child > *)': 0\n      },\n      borderStyle: 'solid',\n      borderColor: colorTokenToString(resolveColorToken(colorToken('gray-300'))),\n      boxSizing: 'border-box'\n    },\n    'img, video': {\n      maxWidth: '100%'\n    },\n    figure: {\n      ...margin('body'),\n      marginInline: 0\n    },\n    figcaption: {\n      ...font('body-sm'),\n      textAlign: 'center'\n    }\n  };\n\n  // Emit the declarations (and any conditional sub-rules) for a single element,\n  // indented by `indent`. Nested `&`-conditions are relative to the enclosing rule.\n  let emitProperties = (properties: Record<string, any>, indent: string) => {\n    let css = '';\n    for (let property in properties) {\n      let value = properties[property];\n      let prop = property.replace(/([a-z])([A-Z])/g, (_, a, b) => `${a}-${b.toLowerCase()}`);\n      if (typeof value === 'object') {\n        if (value.default) {\n          css += `${indent}${prop}: ${value.default};\\n`;\n        }\n        for (let condition in value) {\n          // eslint-disable-next-line max-depth\n          if (condition === 'default') {\n            continue;\n          }\n          css += `${indent}${condition.startsWith(':') ? '&' : ''}${condition} { ${prop}: ${value[condition]}; }\\n`;\n        }\n      } else {\n        css += `${indent}${prop}: ${value};\\n`;\n      }\n    }\n    return css;\n  };\n\n  let css = '.prose {\\n';\n  for (let key in rules) {\n    let properties = rules[key];\n    if (key === '.prose') {\n      css += emitProperties(properties, '  ');\n    } else {\n      css += `  ${key} {\\n`;\n      css += emitProperties(properties, '    ');\n      css += '  }\\n';\n    }\n  }\n  css += '}\\n';\n\n  let hashedRoot = toBase62(hash(css));\n  css = css.replaceAll('prose', `${hashedRoot}`);\n\n  // The prose layer is always lower priority than the style macro layers.\n  css = `\n@layer _.prose {\n  ${css}\n}`;\n\n  this?.addAsset({\n    type: 'css',\n    content: css\n  });\n\n  return hashedRoot;\n}\n\n// Generate a class name from a number, e.g. index within the theme.\n// This maps to an alphabet containing lower case letters, upper case letters, and numbers.\n// For numbers larger than 62, an underscore is prepended.\n// This encoding allows easy parsing to enable runtime merging by property.\nfunction generateName(index: number, atStart = false): string {\n  if (index < 26) {\n    // lower case letters\n    return String.fromCharCode(index + 97);\n  }\n\n  if (index < 52) {\n    // upper case letters\n    return String.fromCharCode(index - 26 + 65);\n  }\n\n  if (index < 62 && !atStart) {\n    // numbers\n    return String.fromCharCode(index - 52 + 48);\n  }\n\n  return '_' + generateName(index - (atStart ? 52 : 62));\n}\n\nfunction toBase62(value: number) {\n  if (value === 0) {\n    return generateName(value, true);\n  }\n\n  let res = '';\n  let atStart = true;\n  while (value) {\n    let remainder = value % 62;\n    res += generateName(remainder, atStart);\n    atStart = false;\n    value = Math.floor((value - remainder) / 62);\n  }\n\n  return res;\n}\n\n// djb2 hash function.\n// http://www.cse.yorku.ca/~oz/hash.html\nfunction hash(v: string) {\n  let hash = 5381;\n  for (let i = 0; i < v.length; i++) {\n    hash = ((hash << 5) + hash + v.charCodeAt(i)) >>> 0;\n  }\n  return hash;\n}\n\n// Text color per font category. Resolved from static token names so the values\n// can be inlined at build time when `./tokens` is imported as a macro (matching\n// how spectrum-theme consumes tokens); a dynamically computed token name cannot.\nconst fontColor = {\n  body: colorTokenToString(resolveColorToken(colorToken('body-color'))),\n  heading: colorTokenToString(resolveColorToken(colorToken('heading-color'))),\n  title: colorTokenToString(resolveColorToken(colorToken('title-color'))),\n  detail: colorTokenToString(resolveColorToken(colorToken('detail-color'))),\n  code: colorTokenToString(resolveColorToken(colorToken('code-color'))),\n  ui: colorTokenToString(resolveColorToken(colorToken('body-color')))\n} as const;\n\nfunction font(value: keyof typeof fontSize) {\n  let type = value.split('-')[0];\n  let size = fontSize[value];\n  return {\n    fontFamily: fontFamily[type === 'code' ? 'code' : 'sans'],\n    '--fs': `pow(1.125, ${size})`,\n    fontSize: `round(${fontSizeCalc} / 16 * 1rem, 1px)`,\n    fontWeight:\n      fontWeight[type === 'heading' || type === 'title' || type === 'detail' ? type : 'normal'],\n    lineHeight: lineHeight[type],\n    color: fontColor[type as keyof typeof fontColor]\n  };\n}\n\nfunction margin(value: keyof typeof marginTop) {\n  return {\n    marginTop: {\n      default: marginTop[value],\n      ':first-child': 0\n    },\n    marginBottom: {\n      default: marginBottom[value],\n      ':last-child': 0\n    }\n  };\n}\n"],"names":[],"version":3,"file":"prose.mjs.map"}