{
  "version": 3,
  "sources": ["../../../src/api/raw-handling/html-to-blocks.ts"],
  "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { Platform } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport { createBlock, findTransform } from '../factory';\nimport parse from '../parser';\nimport { getBlockAttributes } from '../parser/get-block-attributes';\nimport { getRawTransforms } from './get-raw-transforms';\nimport type { Block } from '../../types';\n\n/**\n * Converts HTML directly to blocks. Looks for a matching transform for each\n * top-level tag. The HTML should be filtered to not have any text between\n * top-level tags and formatted in a way that blocks can handle the HTML.\n *\n * @param html    HTML to convert.\n * @param handler The handler calling htmlToBlocks: either rawHandler\n *                or pasteHandler.\n *\n * @return An array of blocks.\n */\nexport function htmlToBlocks(\n\thtml: string,\n\thandler: ( options: { HTML: string } ) => Block[] | string\n): Block[] {\n\tconst doc = document.implementation.createHTMLDocument( '' );\n\n\tdoc.body.innerHTML = html;\n\n\treturn Array.from( doc.body.children ).flatMap( ( node ) => {\n\t\tconst transforms = getRawTransforms();\n\t\tconst rawTransform = findTransform(\n\t\t\ttransforms as unknown as Parameters< typeof findTransform >[ 0 ],\n\t\t\t( ( t: unknown ) => {\n\t\t\t\tconst transform = t as ( typeof transforms )[ number ];\n\t\t\t\treturn transform.isMatch( node );\n\t\t\t} ) as Parameters< typeof findTransform >[ 1 ]\n\t\t) as unknown as ( typeof transforms )[ number ] | null;\n\n\t\tif ( ! rawTransform ) {\n\t\t\t// Until the HTML block is supported in the native version, we'll parse it\n\t\t\t// instead of creating the block to generate it as an unsupported block.\n\t\t\tif ( ( Platform as Record< string, unknown > ).isNative ) {\n\t\t\t\treturn parse(\n\t\t\t\t\t`<!-- wp:html -->${ node.outerHTML }<!-- /wp:html -->`\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn createBlock(\n\t\t\t\t// Should not be hardcoded.\n\t\t\t\t'core/html',\n\t\t\t\tgetBlockAttributes( 'core/html', node.outerHTML )\n\t\t\t);\n\t\t}\n\n\t\tconst { transform, blockName } = rawTransform;\n\n\t\tif ( transform ) {\n\t\t\tconst block = transform( node, handler ) as Block;\n\t\t\tif ( node.hasAttribute( 'class' ) ) {\n\t\t\t\tblock.attributes.className = node.getAttribute( 'class' );\n\t\t\t}\n\t\t\treturn block;\n\t\t}\n\n\t\treturn createBlock(\n\t\t\tblockName!,\n\t\t\tgetBlockAttributes( blockName!, node.outerHTML )\n\t\t);\n\t} );\n}\n"],
  "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,qBAAyB;AAKzB,qBAA2C;AAC3C,oBAAkB;AAClB,kCAAmC;AACnC,gCAAiC;AAc1B,SAAS,aACf,MACA,SACU;AACV,QAAM,MAAM,SAAS,eAAe,mBAAoB,EAAG;AAE3D,MAAI,KAAK,YAAY;AAErB,SAAO,MAAM,KAAM,IAAI,KAAK,QAAS,EAAE,QAAS,CAAE,SAAU;AAC3D,UAAM,iBAAa,4CAAiB;AACpC,UAAM,mBAAe;AAAA,MACpB;AAAA,OACE,CAAE,MAAgB;AACnB,cAAMA,aAAY;AAClB,eAAOA,WAAU,QAAS,IAAK;AAAA,MAChC;AAAA,IACD;AAEA,QAAK,CAAE,cAAe;AAGrB,UAAO,wBAAwC,UAAW;AACzD,mBAAO,cAAAC;AAAA,UACN,mBAAoB,KAAK,SAAU;AAAA,QACpC;AAAA,MACD;AACA,iBAAO;AAAA;AAAA,QAEN;AAAA,YACA,gDAAoB,aAAa,KAAK,SAAU;AAAA,MACjD;AAAA,IACD;AAEA,UAAM,EAAE,WAAW,UAAU,IAAI;AAEjC,QAAK,WAAY;AAChB,YAAM,QAAQ,UAAW,MAAM,OAAQ;AACvC,UAAK,KAAK,aAAc,OAAQ,GAAI;AACnC,cAAM,WAAW,YAAY,KAAK,aAAc,OAAQ;AAAA,MACzD;AACA,aAAO;AAAA,IACR;AAEA,eAAO;AAAA,MACN;AAAA,UACA,gDAAoB,WAAY,KAAK,SAAU;AAAA,IAChD;AAAA,EACD,CAAE;AACH;",
  "names": ["transform", "parse"]
}
