{"version":3,"sources":["webpack:///./node_modules/@ckeditor/ckeditor5-code-block/theme/icons/codeblock.svg","webpack:///./node_modules/@ckeditor/ckeditor5-code-block/src/utils.js"],"names":["module","exports","getNormalizedAndLocalizedLanguageDefinitions","editor","_step","t","languageDefs","config","get","_iterator","_createForOfIteratorHelper","s","n","done","def","value","label","undefined","class","concat","language","err","e","f","getPropertyAssociation","key","_step2","association","_iterator2","split","shift","getLeadingWhiteSpaces","textNode","data","match","rawSnippetTextToViewDocumentFragment","writer","text","fragment","createDocumentFragment","textLines","nodes","reduce","line","lineIndex","push","length","createElement","appendChild","getIndentOutdentPositions","model","selection","document","positions","isCollapsed","anchor","_step3","walker","getFirstRange","getWalker","ignoreElementEnd","direction","_iterator3","item","is","parent","leadingWhiteSpaces","_item$textNode","startOffset","position","createPositionAt","isModelSelectionInCodeBlock","firstBlock","first","getSelectedBlocks"],"mappings":"mGAAAA,EAAAC,QAAA;;;;GCuBO,SAASC,EAA8CC,GAC7D,IADsEC,EAChEC,EAAIF,EAAOE,EACXC,EAAeH,EAAOI,OAAOC,IAAK,uBAF8BC,EAAAC,EAInDJ,GAJmD,IAItE,IAAAG,EAAAE,MAAAP,EAAAK,EAAAG,KAAAC,MAAkC,KAAtBC,EAAsBV,EAAAW,MACd,eAAdD,EAAIE,QACRF,EAAIE,MAAQX,EAAG,oBAGGY,IAAdH,EAAII,QACRJ,EAAII,MAAJ,YAAAC,OAAyBL,EAAIM,YAVuC,MAAAC,GAAAZ,EAAAa,EAAAD,GAAA,QAAAZ,EAAAc,IActE,OAAOjB,EAsCD,SAASkB,EAAwBlB,EAAcmB,EAAKV,GAC1D,IADkEW,EAC5DC,KAD4DC,EAAAlB,EAG/CJ,GAH+C,IAGlE,IAAAsB,EAAAjB,MAAAe,EAAAE,EAAAhB,KAAAC,MAAkC,KAAtBC,EAAsBY,EAAAX,MACpB,UAARU,EAEJE,EAAab,EAAKW,GAAMI,MAAO,KAAMC,SAAYhB,EAAKC,GAEtDY,EAAab,E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.exports = \"\"","/**\n * @license Copyright (c) 2003-2021, CKSource - Frederico Knabben. All rights reserved.\n * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license\n */\n\n/**\n * @module code-block/utils\n */\n\nimport { first } from 'ckeditor5/src/utils';\n\n/**\n * Returns code block languages as defined in `config.codeBlock.languages` but processed:\n *\n * * To consider the editor localization, i.e. to display {@link module:code-block/codeblock~CodeBlockLanguageDefinition}\n * in the correct language. There is no way to use {@link module:utils/locale~Locale#t} when the user\n * configuration is defined because the editor does not exist yet.\n * * To make sure each definition has a CSS class associated with it even if not specified\n * in the original configuration.\n *\n * @param {module:core/editor/editor~Editor} editor\n * @returns {Array.}.\n */\nexport function getNormalizedAndLocalizedLanguageDefinitions( editor ) {\n\tconst t = editor.t;\n\tconst languageDefs = editor.config.get( 'codeBlock.languages' );\n\n\tfor ( const def of languageDefs ) {\n\t\tif ( def.label === 'Plain text' ) {\n\t\t\tdef.label = t( 'Plain text' );\n\t\t}\n\n\t\tif ( def.class === undefined ) {\n\t\t\tdef.class = `language-${ def.language }`;\n\t\t}\n\t}\n\n\treturn languageDefs;\n}\n\n/**\n * Returns an object associating certain language definition properties with others. For instance:\n *\n * For:\n *\n *\t\tconst definitions = {\n *\t\t\t{ language: 'php', class: 'language-php', label: 'PHP' },\n *\t\t\t{ language: 'javascript', class: 'js', label: 'JavaScript' },\n *\t\t};\n *\n *\t\tgetPropertyAssociation( definitions, 'class', 'language' );\n *\n * returns:\n *\n *\t\t{\n *\t\t\t'language-php': 'php'\n *\t\t\t'js': 'javascript'\n *\t\t}\n *\n * and\n *\n *\t\tgetPropertyAssociation( definitions, 'language', 'label' );\n *\n * returns:\n *\n *\t\t{\n *\t\t\t'php': 'PHP'\n *\t\t\t'javascript': 'JavaScript'\n *\t\t}\n *\n * @param {Array.}\n * @param {String} key\n * @param {String} value\n * @param {Object.}\n */\nexport function getPropertyAssociation( languageDefs, key, value ) {\n\tconst association = {};\n\n\tfor ( const def of languageDefs ) {\n\t\tif ( key === 'class' ) {\n\t\t\t// Only the first class is considered.\n\t\t\tassociation[ def[ key ].split( ' ' ).shift() ] = def[ value ];\n\t\t} else {\n\t\t\tassociation[ def[ key ] ] = def[ value ];\n\t\t}\n\t}\n\n\treturn association;\n}\n\n/**\n * For a given model text node, it returns white spaces that precede other characters in that node.\n * This corresponds to the indentation part of the code block line.\n *\n * @param {module:engine/model/text~Text} codeLineNodes\n * @returns {String}\n */\nexport function getLeadingWhiteSpaces( textNode ) {\n\treturn textNode.data.match( /^(\\s*)/ )[ 0 ];\n}\n\n/**\n * For plain text containing the code (a snippet), it returns a document fragment containing\n * view text nodes separated by ` ` elements (in place of new line characters \"\\n\"), for instance:\n *\n * Input:\n *\n *\t\t\"foo()\\n\n *\t\tbar()\"\n *\n * Output:\n *\n *\t\t\n *\t\t\t\"foo()\"\n *\t\t\t \n *\t\t\t\"bar()\"\n *\t\t\n *\n * @param {module:engine/view/upcastwriter~UpcastWriter} writer\n * @param {String} text The raw code text to be converted.\n * @returns {module:engine/view/documentfragment~DocumentFragment}\n */\nexport function rawSnippetTextToViewDocumentFragment( writer, text ) {\n\tconst fragment = writer.createDocumentFragment();\n\tconst textLines = text.split( '\\n' );\n\n\tconst nodes = textLines.reduce( ( nodes, line, lineIndex ) => {\n\t\tnodes.push( line );\n\n\t\tif ( lineIndex < textLines.length - 1 ) {\n\t\t\tnodes.push( writer.createElement( 'br' ) );\n\t\t}\n\n\t\treturn nodes;\n\t}, [] );\n\n\twriter.appendChild( nodes, fragment );\n\n\treturn fragment;\n}\n\n/**\n * Returns an array of all model positions within the selection that represent code block lines.\n *\n * If the selection is collapsed, it returns the exact selection anchor position:\n *\n *\t\t[]foo -> ^foo\n *\t\tfoo[]bar -> foo^bar\n *\n * Otherwise, it returns positions **before** each text node belonging to all code blocks contained by the selection:\n *\n *\t\t\n *\t\t foo[bar ^foobar\n *\t\t -> \n *\t\t baz]qux ^bazqux\n *\t\t\n *\n * It also works across other non–code blocks:\n *\n *\t\t\n *\t\t foo[bar ^foobar\n *\t\t\n *\t\ttext -> text\n *\t\t\n *\t\t baz]qux ^bazqux\n *\t\t\n *\n * **Note:** The positions are in reverse order so they do not get outdated when iterating over them and\n * the writer inserts or removes elements at the same time.\n *\n * **Note:** The position is located after the leading white spaces in the text node.\n *\n * @param {module:engine/model/model~Model} model\n * @returns {Array.}\n */\nexport function getIndentOutdentPositions( model ) {\n\tconst selection = model.document.selection;\n\tconst positions = [];\n\n\t// When the selection is collapsed, there's only one position we can indent or outdent.\n\tif ( selection.isCollapsed ) {\n\t\tpositions.push( selection.anchor );\n\t}\n\n\t// When the selection is NOT collapsed, collect all positions starting before text nodes\n\t// (code lines) in any within the selection.\n\telse {\n\t\t// Walk backward so positions we are about to collect here do not get outdated when\n\t\t// inserting or deleting using the writer.\n\t\tconst walker = selection.getFirstRange().getWalker( {\n\t\t\tignoreElementEnd: true,\n\t\t\tdirection: 'backward'\n\t\t} );\n\n\t\tfor ( const { item } of walker ) {\n\t\t\tif ( item.is( '$textProxy' ) && item.parent.is( 'element', 'codeBlock' ) ) {\n\t\t\t\tconst leadingWhiteSpaces = getLeadingWhiteSpaces( item.textNode );\n\t\t\t\tconst { parent, startOffset } = item.textNode;\n\n\t\t\t\t// Make sure the position is after all leading whitespaces in the text node.\n\t\t\t\tconst position = model.createPositionAt( parent, startOffset + leadingWhiteSpaces.length );\n\n\t\t\t\tpositions.push( position );\n\t\t\t}\n\t\t}\n\t}\n\n\treturn positions;\n}\n\n/**\n * Checks if any of the blocks within the model selection is a code block.\n *\n * @param {module:engine/model/selection~Selection} selection\n * @returns {Boolean}\n */\nexport function isModelSelectionInCodeBlock( selection ) {\n\tconst firstBlock = first( selection.getSelectedBlocks() );\n\n\treturn firstBlock && firstBlock.is( 'element', 'codeBlock' );\n}\n"],"sourceRoot":""}