@wordpress/block-serialization-default-parser
Advanced tools
+42
-58
@@ -1,6 +0,5 @@ | ||
| import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray"; | ||
| var document; | ||
| var offset; | ||
| var output; | ||
| var stack; | ||
| let document; | ||
| let offset; | ||
| let output; | ||
| let stack; | ||
| /** | ||
@@ -48,11 +47,11 @@ * Matches block comment delimiters | ||
| var tokenizer = /<!--\s+(\/)?wp:([a-z][a-z0-9_-]*\/)?([a-z][a-z0-9_-]*)\s+({(?:(?=([^}]+|}+(?=})|(?!}\s+\/?-->)[^])*)\5|[^]*?)}\s+)?(\/)?-->/g; | ||
| const tokenizer = /<!--\s+(\/)?wp:([a-z][a-z0-9_-]*\/)?([a-z][a-z0-9_-]*)\s+({(?:(?=([^}]+|}+(?=})|(?!}\s+\/?-->)[^])*)\5|[^]*?)}\s+)?(\/)?-->/g; | ||
| function Block(blockName, attrs, innerBlocks, innerHTML, innerContent) { | ||
| return { | ||
| blockName: blockName, | ||
| attrs: attrs, | ||
| innerBlocks: innerBlocks, | ||
| innerHTML: innerHTML, | ||
| innerContent: innerContent | ||
| blockName, | ||
| attrs, | ||
| innerBlocks, | ||
| innerHTML, | ||
| innerContent | ||
| }; | ||
@@ -67,7 +66,7 @@ } | ||
| return { | ||
| block: block, | ||
| tokenStart: tokenStart, | ||
| tokenLength: tokenLength, | ||
| block, | ||
| tokenStart, | ||
| tokenLength, | ||
| prevOffset: prevOffset || tokenStart + tokenLength, | ||
| leadingHtmlStart: leadingHtmlStart | ||
| leadingHtmlStart | ||
| }; | ||
@@ -154,3 +153,3 @@ } | ||
| export var parse = function parse(doc) { | ||
| export const parse = doc => { | ||
| document = doc; | ||
@@ -169,15 +168,8 @@ offset = 0; | ||
| function proceed() { | ||
| var next = nextToken(); | ||
| const next = nextToken(); | ||
| const [tokenType, blockName, attrs, startOffset, tokenLength] = next; | ||
| const stackDepth = stack.length; // we may have some HTML soup before the next block | ||
| var _next = _slicedToArray(next, 5), | ||
| tokenType = _next[0], | ||
| blockName = _next[1], | ||
| attrs = _next[2], | ||
| startOffset = _next[3], | ||
| tokenLength = _next[4]; | ||
| const leadingHtmlStart = startOffset > offset ? offset : null; | ||
| var stackDepth = stack.length; // we may have some HTML soup before the next block | ||
| var leadingHtmlStart = startOffset > offset ? offset : null; | ||
| switch (tokenType) { | ||
@@ -256,4 +248,4 @@ case 'no-more-tokens': | ||
| var stackTop = stack.pop(); | ||
| var html = document.substr(stackTop.prevOffset, startOffset - stackTop.prevOffset); | ||
| const stackTop = stack.pop(); | ||
| const html = document.substr(stackTop.prevOffset, startOffset - stackTop.prevOffset); | ||
| stackTop.block.innerHTML += html; | ||
@@ -299,3 +291,3 @@ stackTop.block.innerContent.push(html); | ||
| // match back in JavaScript to see which one it was. | ||
| var matches = tokenizer.exec(document); // we have no more tokens | ||
| const matches = tokenizer.exec(document); // we have no more tokens | ||
@@ -306,21 +298,13 @@ if (null === matches) { | ||
| var startedAt = matches.index; | ||
| var _matches = _slicedToArray(matches, 7), | ||
| match = _matches[0], | ||
| closerMatch = _matches[1], | ||
| namespaceMatch = _matches[2], | ||
| nameMatch = _matches[3], | ||
| attrsMatch | ||
| const startedAt = matches.index; | ||
| const [match, closerMatch, namespaceMatch, nameMatch, attrsMatch | ||
| /* internal/unused */ | ||
| = _matches[4], | ||
| voidMatch = _matches[6]; | ||
| var length = match.length; | ||
| var isCloser = !!closerMatch; | ||
| var isVoid = !!voidMatch; | ||
| var namespace = namespaceMatch || 'core/'; | ||
| var name = namespace + nameMatch; | ||
| var hasAttrs = !!attrsMatch; | ||
| var attrs = hasAttrs ? parseJSON(attrsMatch) : {}; // This state isn't allowed | ||
| ,, voidMatch] = matches; | ||
| const length = match.length; | ||
| const isCloser = !!closerMatch; | ||
| const isVoid = !!voidMatch; | ||
| const namespace = namespaceMatch || 'core/'; | ||
| const name = namespace + nameMatch; | ||
| const hasAttrs = !!attrsMatch; | ||
| const attrs = hasAttrs ? parseJSON(attrsMatch) : {}; // This state isn't allowed | ||
| // This is an error | ||
@@ -344,3 +328,3 @@ | ||
| function addFreeform(rawLength) { | ||
| var length = rawLength ? rawLength : document.length - offset; | ||
| const length = rawLength ? rawLength : document.length - offset; | ||
@@ -355,5 +339,5 @@ if (0 === length) { | ||
| function addInnerBlock(block, tokenStart, tokenLength, lastOffset) { | ||
| var parent = stack[stack.length - 1]; | ||
| const parent = stack[stack.length - 1]; | ||
| parent.block.innerBlocks.push(block); | ||
| var html = document.substr(parent.prevOffset, tokenStart - parent.prevOffset); | ||
| const html = document.substr(parent.prevOffset, tokenStart - parent.prevOffset); | ||
@@ -370,10 +354,10 @@ if (html) { | ||
| function addBlockFromStack(endOffset) { | ||
| var _stack$pop = stack.pop(), | ||
| block = _stack$pop.block, | ||
| leadingHtmlStart = _stack$pop.leadingHtmlStart, | ||
| prevOffset = _stack$pop.prevOffset, | ||
| tokenStart = _stack$pop.tokenStart; | ||
| const { | ||
| block, | ||
| leadingHtmlStart, | ||
| prevOffset, | ||
| tokenStart | ||
| } = stack.pop(); | ||
| const html = endOffset ? document.substr(prevOffset, endOffset - prevOffset) : document.substr(prevOffset); | ||
| var html = endOffset ? document.substr(prevOffset, endOffset - prevOffset) : document.substr(prevOffset); | ||
| if (html) { | ||
@@ -380,0 +364,0 @@ block.innerHTML += html; |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"sources":["@wordpress/block-serialization-default-parser/src/index.js"],"names":["document","offset","output","stack","tokenizer","Block","blockName","attrs","innerBlocks","innerHTML","innerContent","Freeform","Frame","block","tokenStart","tokenLength","prevOffset","leadingHtmlStart","parse","doc","lastIndex","proceed","next","nextToken","tokenType","startOffset","stackDepth","length","addFreeform","addBlockFromStack","push","substr","addInnerBlock","stackTop","pop","html","parseJSON","input","JSON","e","matches","exec","startedAt","index","match","closerMatch","namespaceMatch","nameMatch","attrsMatch","voidMatch","isCloser","isVoid","namespace","name","hasAttrs","rawLength","lastOffset","parent","endOffset"],"mappings":";AAAA,IAAIA,QAAJ;AACA,IAAIC,MA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AiC;AAChCf,IAAAA,MAAM,CAAC4B,IAAP,CACCnB,QAAQ,CACPX,QAAQ,CAAC+B,MAAT,CACCd,gBADD,EAECH,UAAU,GAAGG,gBAFd,CADO,CADT;AAQA;;AAEDf,EAAAA,MAAM,CAAC4B,IAAP,CAAajB,KAAb;AACA","sourcesContent":["let document;\nlet offset;\nlet output;\nlet stack;\n\n/**\n * Matches block comment delimiters\n *\n * While most of this pattern is straightforward the attribute parsing\n * incorporates a tricks to make sure we don't choke on specific input\n *\n * - since JavaScript has no possessive quantifier or atomic grouping\n * we are emulating it with a trick\n *\n * we want a possessive quantifier or atomic group to prevent backtracking\n * on the `}`s should we fail to match the remainder of the pattern\n *\n * we can emulate this with a positive lookahead and back reference\n * (a++)*c === ((?=(a+))\\1)*c\n *\n * let's examine an example:\n * - /(a+)*c/.test('aaaaaaaaaaaaad') fails after over 49,000 steps\n * - /(a++)*c/.test('aaaaaaaaaaaaad') fails after 85 steps\n * - /(?>a+)*c/.test('aaaaaaaaaaaaad') fails after 126 steps\n *\n * this is because the possessive `++` and the atomic group `(?>)`\n * tell the engine that all those `a`s belong together as a single group\n * and so it won't split it up when stepping backwards to try and match\n *\n * if we use /((?=(a+))\\1)*c/ then we get the same behavior as the atomic group\n * or possessive and prevent the backtracking because the `a+` is matched but\n * not captured. thus, we find the long string of `a`s and remember it, then\n * reference it as a whole unit inside our pattern\n *\n * @see http://instanceof.me/post/52245507631/regex-emulate-atomic-grouping-with-lookahead\n * @see http://blog.stevenlevithan.com/archives/mimic-atomic-groups\n * @see https://javascript.info/regexp-infinite-backtracking-problem\n *\n * once browsers reliably support atomic grouping or possessive\n * quantifiers natively we should remove this trick and simplify\n *\n * @type {RegExp}\n *\n * @since 3.8.0\n * @since 4.6.1 added optimization to prevent backtracking on attribute parsing\n */\nconst tokenizer = /<!--\\s+(\\/)?wp:([a-z][a-z0-9_-]*\\/)?([a-z][a-z0-9_-]*)\\s+({(?:(?=([^}]+|}+(?=})|(?!}\\s+\\/?-->)[^])*)\\5|[^]*?)}\\s+)?(\\/)?-->/g;\n\nfunction Block( blockName, attrs, innerBlocks, innerHTML, innerContent ) {\n\treturn {\n\t\tblockName,\n\t\tattrs,\n\t\tinnerBlocks,\n\t\tinnerHTML,\n\t\tinnerContent,\n\t};\n}\n\nfunction Freeform( innerHTML ) {\n\treturn Block( null, {}, [], innerHTML, [ innerHTML ] );\n}\n\nfunction Frame( block, tokenStart, tokenLength, prevOffset, leadingHtmlStart ) {\n\treturn {\n\t\tblock,\n\t\ttokenStart,\n\t\ttokenLength,\n\t\tprevOffset: prevOffset || tokenStart + tokenLength,\n\t\tleadingHtmlStart,\n\t};\n}\n\n/**\n * Parser function, that converts input HTML into a block based structure.\n *\n * @param {string} doc The HTML document to parse.\n *\n * @example\n * Input post:\n * ```html\n * <!-- wp:columns {\"columns\":3} -->\n * <div class=\"wp-block-columns has-3-columns\"><!-- wp:column -->\n * <div class=\"wp-block-column\"><!-- wp:paragraph -->\n * <p>Left</p>\n * <!-- /wp:paragraph --></div>\n * <!-- /wp:column -->\n *\n * <!-- wp:column -->\n * <div class=\"wp-block-column\"><!-- wp:paragraph -->\n * <p><strong>Middle</strong></p>\n * <!-- /wp:paragraph --></div>\n * <!-- /wp:column -->\n *\n * <!-- wp:column -->\n * <div class=\"wp-block-column\"></div>\n * <!-- /wp:column --></div>\n * <!-- /wp:columns -->\n * ```\n *\n * Parsing code:\n * ```js\n * import { parse } from '@wordpress/block-serialization-default-parser';\n *\n * parse( post ) === [\n * {\n * blockName: \"core/columns\",\n * attrs: {\n * columns: 3\n * },\n * innerBlocks: [\n * {\n * blockName: \"core/column\",\n * attrs: null,\n * innerBlocks: [\n * {\n * blockName: \"core/paragraph\",\n * attrs: null,\n * innerBlocks: [],\n * innerHTML: \"\\n<p>Left</p>\\n\"\n * }\n * ],\n * innerHTML: '\\n<div class=\"wp-block-column\"></div>\\n'\n * },\n * {\n * blockName: \"core/column\",\n * attrs: null,\n * innerBlocks: [\n * {\n * blockName: \"core/paragraph\",\n * attrs: null,\n * innerBlocks: [],\n * innerHTML: \"\\n<p><strong>Middle</strong></p>\\n\"\n * }\n * ],\n * innerHTML: '\\n<div class=\"wp-block-column\"></div>\\n'\n * },\n * {\n * blockName: \"core/column\",\n * attrs: null,\n * innerBlocks: [],\n * innerHTML: '\\n<div class=\"wp-block-column\"></div>\\n'\n * }\n * ],\n * innerHTML: '\\n<div class=\"wp-block-columns has-3-columns\">\\n\\n\\n\\n</div>\\n'\n * }\n * ];\n * ```\n * @return {Array} A block-based representation of the input HTML.\n */\nexport const parse = ( doc ) => {\n\tdocument = doc;\n\toffset = 0;\n\toutput = [];\n\tstack = [];\n\ttokenizer.lastIndex = 0;\n\n\tdo {\n\t\t// twiddle our thumbs\n\t} while ( proceed() );\n\n\treturn output;\n};\n\nfunction proceed() {\n\tconst next = nextToken();\n\tconst [ tokenType, blockName, attrs, startOffset, tokenLength ] = next;\n\tconst stackDepth = stack.length;\n\n\t// we may have some HTML soup before the next block\n\tconst leadingHtmlStart = startOffset > offset ? offset : null;\n\n\tswitch ( tokenType ) {\n\t\tcase 'no-more-tokens':\n\t\t\t// if not in a block then flush output\n\t\t\tif ( 0 === stackDepth ) {\n\t\t\t\taddFreeform();\n\t\t\t\treturn false;\n\t\t\t}\n\n\t\t\t// Otherwise we have a problem\n\t\t\t// This is an error\n\t\t\t// we have options\n\t\t\t// - treat it all as freeform text\n\t\t\t// - assume an implicit closer (easiest when not nesting)\n\n\t\t\t// for the easy case we'll assume an implicit closer\n\t\t\tif ( 1 === stackDepth ) {\n\t\t\t\taddBlockFromStack();\n\t\t\t\treturn false;\n\t\t\t}\n\n\t\t\t// for the nested case where it's more difficult we'll\n\t\t\t// have to assume that multiple closers are missing\n\t\t\t// and so we'll collapse the whole stack piecewise\n\t\t\twhile ( 0 < stack.length ) {\n\t\t\t\taddBlockFromStack();\n\t\t\t}\n\t\t\treturn false;\n\n\t\tcase 'void-block':\n\t\t\t// easy case is if we stumbled upon a void block\n\t\t\t// in the top-level of the document\n\t\t\tif ( 0 === stackDepth ) {\n\t\t\t\tif ( null !== leadingHtmlStart ) {\n\t\t\t\t\toutput.push(\n\t\t\t\t\t\tFreeform(\n\t\t\t\t\t\t\tdocument.substr(\n\t\t\t\t\t\t\t\tleadingHtmlStart,\n\t\t\t\t\t\t\t\tstartOffset - leadingHtmlStart\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t)\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\toutput.push( Block( blockName, attrs, [], '', [] ) );\n\t\t\t\toffset = startOffset + tokenLength;\n\t\t\t\treturn true;\n\t\t\t}\n\n\t\t\t// otherwise we found an inner block\n\t\t\taddInnerBlock(\n\t\t\t\tBlock( blockName, attrs, [], '', [] ),\n\t\t\t\tstartOffset,\n\t\t\t\ttokenLength\n\t\t\t);\n\t\t\toffset = startOffset + tokenLength;\n\t\t\treturn true;\n\n\t\tcase 'block-opener':\n\t\t\t// track all newly-opened blocks on the stack\n\t\t\tstack.push(\n\t\t\t\tFrame(\n\t\t\t\t\tBlock( blockName, attrs, [], '', [] ),\n\t\t\t\t\tstartOffset,\n\t\t\t\t\ttokenLength,\n\t\t\t\t\tstartOffset + tokenLength,\n\t\t\t\t\tleadingHtmlStart\n\t\t\t\t)\n\t\t\t);\n\t\t\toffset = startOffset + tokenLength;\n\t\t\treturn true;\n\n\t\tcase 'block-closer':\n\t\t\t// if we're missing an opener we're in trouble\n\t\t\t// This is an error\n\t\t\tif ( 0 === stackDepth ) {\n\t\t\t\t// we have options\n\t\t\t\t// - assume an implicit opener\n\t\t\t\t// - assume _this_ is the opener\n\t\t\t\t// - give up and close out the document\n\t\t\t\taddFreeform();\n\t\t\t\treturn false;\n\t\t\t}\n\n\t\t\t// if we're not nesting then this is easy - close the block\n\t\t\tif ( 1 === stackDepth ) {\n\t\t\t\taddBlockFromStack( startOffset );\n\t\t\t\toffset = startOffset + tokenLength;\n\t\t\t\treturn true;\n\t\t\t}\n\n\t\t\t// otherwise we're nested and we have to close out the current\n\t\t\t// block and add it as a innerBlock to the parent\n\t\t\tconst stackTop = stack.pop();\n\t\t\tconst html = document.substr(\n\t\t\t\tstackTop.prevOffset,\n\t\t\t\tstartOffset - stackTop.prevOffset\n\t\t\t);\n\t\t\tstackTop.block.innerHTML += html;\n\t\t\tstackTop.block.innerContent.push( html );\n\t\t\tstackTop.prevOffset = startOffset + tokenLength;\n\n\t\t\taddInnerBlock(\n\t\t\t\tstackTop.block,\n\t\t\t\tstackTop.tokenStart,\n\t\t\t\tstackTop.tokenLength,\n\t\t\t\tstartOffset + tokenLength\n\t\t\t);\n\t\t\toffset = startOffset + tokenLength;\n\t\t\treturn true;\n\n\t\tdefault:\n\t\t\t// This is an error\n\t\t\taddFreeform();\n\t\t\treturn false;\n\t}\n}\n\n/**\n * Parse JSON if valid, otherwise return null\n *\n * Note that JSON coming from the block comment\n * delimiters is constrained to be an object\n * and cannot be things like `true` or `null`\n *\n * @param {string} input JSON input string to parse\n * @return {Object|null} parsed JSON if valid\n */\nfunction parseJSON( input ) {\n\ttry {\n\t\treturn JSON.parse( input );\n\t} catch ( e ) {\n\t\treturn null;\n\t}\n}\n\nfunction nextToken() {\n\t// aye the magic\n\t// we're using a single RegExp to tokenize the block comment delimiters\n\t// we're also using a trick here because the only difference between a\n\t// block opener and a block closer is the leading `/` before `wp:` (and\n\t// a closer has no attributes). we can trap them both and process the\n\t// match back in JavaScript to see which one it was.\n\tconst matches = tokenizer.exec( document );\n\n\t// we have no more tokens\n\tif ( null === matches ) {\n\t\treturn [ 'no-more-tokens' ];\n\t}\n\n\tconst startedAt = matches.index;\n\tconst [\n\t\tmatch,\n\t\tcloserMatch,\n\t\tnamespaceMatch,\n\t\tnameMatch,\n\t\tattrsMatch /* internal/unused */,\n\t\t,\n\t\tvoidMatch,\n\t] = matches;\n\n\tconst length = match.length;\n\tconst isCloser = !! closerMatch;\n\tconst isVoid = !! voidMatch;\n\tconst namespace = namespaceMatch || 'core/';\n\tconst name = namespace + nameMatch;\n\tconst hasAttrs = !! attrsMatch;\n\tconst attrs = hasAttrs ? parseJSON( attrsMatch ) : {};\n\n\t// This state isn't allowed\n\t// This is an error\n\tif ( isCloser && ( isVoid || hasAttrs ) ) {\n\t\t// we can ignore them since they don't hurt anything\n\t\t// we may warn against this at some point or reject it\n\t}\n\n\tif ( isVoid ) {\n\t\treturn [ 'void-block', name, attrs, startedAt, length ];\n\t}\n\n\tif ( isCloser ) {\n\t\treturn [ 'block-closer', name, null, startedAt, length ];\n\t}\n\n\treturn [ 'block-opener', name, attrs, startedAt, length ];\n}\n\nfunction addFreeform( rawLength ) {\n\tconst length = rawLength ? rawLength : document.length - offset;\n\n\tif ( 0 === length ) {\n\t\treturn;\n\t}\n\n\toutput.push( Freeform( document.substr( offset, length ) ) );\n}\n\nfunction addInnerBlock( block, tokenStart, tokenLength, lastOffset ) {\n\tconst parent = stack[ stack.length - 1 ];\n\tparent.block.innerBlocks.push( block );\n\tconst html = document.substr(\n\t\tparent.prevOffset,\n\t\ttokenStart - parent.prevOffset\n\t);\n\n\tif ( html ) {\n\t\tparent.block.innerHTML += html;\n\t\tparent.block.innerContent.push( html );\n\t}\n\n\tparent.block.innerContent.push( null );\n\tparent.prevOffset = lastOffset ? lastOffset : tokenStart + tokenLength;\n}\n\nfunction addBlockFromStack( endOffset ) {\n\tconst { block, leadingHtmlStart, prevOffset, tokenStart } = stack.pop();\n\n\tconst html = endOffset\n\t\t? document.substr( prevOffset, endOffset - prevOffset )\n\t\t: document.substr( prevOffset );\n\n\tif ( html ) {\n\t\tblock.innerHTML += html;\n\t\tblock.innerContent.push( html );\n\t}\n\n\tif ( null !== leadingHtmlStart ) {\n\t\toutput.push(\n\t\t\tFreeform(\n\t\t\t\tdocument.substr(\n\t\t\t\t\tleadingHtmlStart,\n\t\t\t\t\ttokenStart - leadingHtmlStart\n\t\t\t\t)\n\t\t\t)\n\t\t);\n\t}\n\n\toutput.push( block );\n}\n"]} | ||
| {"version":3,"sources":["@wordpress/block-serialization-default-parser/src/index.js"],"names":["document","offset","output","stack","tokenizer","Block","blockName","attrs","innerBlocks","innerHTML","innerContent","Freeform","Frame","block","tokenStart","tokenLength","prevOffset","leadingHtmlStart","parse","doc","lastIndex","proceed","next","nextToken","tokenType","startOffset","stackDepth","length","addFreeform","addBlockFromStack","push","substr","addInnerBlock","stackTop","pop","html","parseJSON","input","JSON","e","matches","exec","startedAt","index","match","closerMatch","namespaceMatch","nameMatch","attrsMatch","voidMatch","isCloser","isVoid","namespace","name","hasAttrs","rawLength","lastOffset","parent","endOffset"],"mappings":"AAAA,IAAIA,QAAJ;AACA,IAAIC,MAAJ;AACA,IAAIC,MAAJ;AACA,IAAIC,KAAJ;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,MAAMC,SAAS,GAAG,8HAAlB;;AAEA,SAASC,KAAT,CAAgBC,SAAhB,EAA2BC,KAA3B,EAAkCC,WAAlC,EAA+CC,SAA/C,EAA0DC,YAA1D,EAAyE;AACxE,SAAO;AACNJ,IAAAA,SADM;AAENC,IAAAA,KAFM;AAGNC,IAAAA,WAHM;AAINC,IAAAA,SAJM;AAKNC,IAAAA;AALM,GAAP;AAOA;;AAED,SAASC,QAAT,CAAmBF,SAAnB,EAA+B;AAC9B,SAAOJ,KAAK,CAAE,IAAF,EAAQ,EAAR,EAAY,EAAZ,EAAgBI,SAAhB,EAA2B,CAAEA,SAAF,CAA3B,CAAZ;AACA;;AAED,SAASG,KAAT,CAAgBC,KAAhB,EAAuBC,UAAvB,EAAmCC,WAAnC,EAAgDC,UAAhD,EAA4DC,gBAA5D,EAA+E;AAC9E,SAAO;AACNJ,IAAAA,KADM;AAENC,IAAAA,UAFM;AAGNC,IAAAA,WAHM;AAINC,IAAAA,UAAU,EAAEA,UAAU,IAAIF,UAAU,GAAGC,WAJjC;AAKNE,IAAAA;AALM,GAAP;AAOA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACA,OAAO,MAAMC,KAAK,GAAKC,GAAF,IAAW;AAC/BnB,EAAAA,QAAQ,GAAGmB,GAAX;AACAlB,EAAAA,MAAM,GAAG,CAAT;AACAC,EAAAA,MAAM,GAAG,EAAT;AACAC,EAAAA,KAAK,GAAG,EAAR;AACAC,EAAAA,SAAS,CAACgB,SAAV,GAAsB,CAAtB;;AAEA,KAAG,CACF;AACA,GAFD,QAEUC,OAAO,EAFjB;;AAIA,SAAOnB,MAAP;AACA,CAZM;;AAcP,SAASmB,OAAT,GAAmB;AAClB,QAAMC,IAAI,GAAGC,SAAS,EAAtB;AACA,QAAM,CAAEC,SAAF,EAAalB,SAAb,EAAwBC,KAAxB,EAA+BkB,WAA/B,EAA4CV,WAA5C,IAA4DO,IAAlE;AACA,QAAMI,UAAU,GAAGvB,KAAK,CAACwB,MAAzB,CAHkB,CAKlB;;AACA,QAAMV,gBAAgB,GAAGQ,WAAW,GAAGxB,MAAd,GAAuBA,MAAvB,GAAgC,IAAzD;;AAEA,UAASuB,SAAT;AACC,SAAK,gBAAL;AACC;AACA,UAAK,MAAME,UAAX,EAAwB;AACvBE,QAAAA,WAAW;AACX,eAAO,KAAP;AACA,OALF,CAOC;AACA;AACA;AACA;AACA;AAEA;;;AACA,UAAK,M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;AACAtB,IAAAA,KAAK,CAACH,YAAN,CAAmBoB,IAAnB,CAAyBK,IAAzB;AACA;;AAED,MAAK,SAASlB,gBAAd,EAAiC;AAChCf,IAAAA,MAAM,CAAC4B,IAAP,CACCnB,QAAQ,CACPX,QAAQ,CAAC+B,MAAT,CACCd,gBADD,EAECH,UAAU,GAAGG,gBAFd,CADO,CADT;AAQA;;AAEDf,EAAAA,MAAM,CAAC4B,IAAP,CAAajB,KAAb;AACA","sourcesContent":["let document;\nlet offset;\nlet output;\nlet stack;\n\n/**\n * Matches block comment delimiters\n *\n * While most of this pattern is straightforward the attribute parsing\n * incorporates a tricks to make sure we don't choke on specific input\n *\n * - since JavaScript has no possessive quantifier or atomic grouping\n * we are emulating it with a trick\n *\n * we want a possessive quantifier or atomic group to prevent backtracking\n * on the `}`s should we fail to match the remainder of the pattern\n *\n * we can emulate this with a positive lookahead and back reference\n * (a++)*c === ((?=(a+))\\1)*c\n *\n * let's examine an example:\n * - /(a+)*c/.test('aaaaaaaaaaaaad') fails after over 49,000 steps\n * - /(a++)*c/.test('aaaaaaaaaaaaad') fails after 85 steps\n * - /(?>a+)*c/.test('aaaaaaaaaaaaad') fails after 126 steps\n *\n * this is because the possessive `++` and the atomic group `(?>)`\n * tell the engine that all those `a`s belong together as a single group\n * and so it won't split it up when stepping backwards to try and match\n *\n * if we use /((?=(a+))\\1)*c/ then we get the same behavior as the atomic group\n * or possessive and prevent the backtracking because the `a+` is matched but\n * not captured. thus, we find the long string of `a`s and remember it, then\n * reference it as a whole unit inside our pattern\n *\n * @see http://instanceof.me/post/52245507631/regex-emulate-atomic-grouping-with-lookahead\n * @see http://blog.stevenlevithan.com/archives/mimic-atomic-groups\n * @see https://javascript.info/regexp-infinite-backtracking-problem\n *\n * once browsers reliably support atomic grouping or possessive\n * quantifiers natively we should remove this trick and simplify\n *\n * @type {RegExp}\n *\n * @since 3.8.0\n * @since 4.6.1 added optimization to prevent backtracking on attribute parsing\n */\nconst tokenizer = /<!--\\s+(\\/)?wp:([a-z][a-z0-9_-]*\\/)?([a-z][a-z0-9_-]*)\\s+({(?:(?=([^}]+|}+(?=})|(?!}\\s+\\/?-->)[^])*)\\5|[^]*?)}\\s+)?(\\/)?-->/g;\n\nfunction Block( blockName, attrs, innerBlocks, innerHTML, innerContent ) {\n\treturn {\n\t\tblockName,\n\t\tattrs,\n\t\tinnerBlocks,\n\t\tinnerHTML,\n\t\tinnerContent,\n\t};\n}\n\nfunction Freeform( innerHTML ) {\n\treturn Block( null, {}, [], innerHTML, [ innerHTML ] );\n}\n\nfunction Frame( block, tokenStart, tokenLength, prevOffset, leadingHtmlStart ) {\n\treturn {\n\t\tblock,\n\t\ttokenStart,\n\t\ttokenLength,\n\t\tprevOffset: prevOffset || tokenStart + tokenLength,\n\t\tleadingHtmlStart,\n\t};\n}\n\n/**\n * Parser function, that converts input HTML into a block based structure.\n *\n * @param {string} doc The HTML document to parse.\n *\n * @example\n * Input post:\n * ```html\n * <!-- wp:columns {\"columns\":3} -->\n * <div class=\"wp-block-columns has-3-columns\"><!-- wp:column -->\n * <div class=\"wp-block-column\"><!-- wp:paragraph -->\n * <p>Left</p>\n * <!-- /wp:paragraph --></div>\n * <!-- /wp:column -->\n *\n * <!-- wp:column -->\n * <div class=\"wp-block-column\"><!-- wp:paragraph -->\n * <p><strong>Middle</strong></p>\n * <!-- /wp:paragraph --></div>\n * <!-- /wp:column -->\n *\n * <!-- wp:column -->\n * <div class=\"wp-block-column\"></div>\n * <!-- /wp:column --></div>\n * <!-- /wp:columns -->\n * ```\n *\n * Parsing code:\n * ```js\n * import { parse } from '@wordpress/block-serialization-default-parser';\n *\n * parse( post ) === [\n * {\n * blockName: \"core/columns\",\n * attrs: {\n * columns: 3\n * },\n * innerBlocks: [\n * {\n * blockName: \"core/column\",\n * attrs: null,\n * innerBlocks: [\n * {\n * blockName: \"core/paragraph\",\n * attrs: null,\n * innerBlocks: [],\n * innerHTML: \"\\n<p>Left</p>\\n\"\n * }\n * ],\n * innerHTML: '\\n<div class=\"wp-block-column\"></div>\\n'\n * },\n * {\n * blockName: \"core/column\",\n * attrs: null,\n * innerBlocks: [\n * {\n * blockName: \"core/paragraph\",\n * attrs: null,\n * innerBlocks: [],\n * innerHTML: \"\\n<p><strong>Middle</strong></p>\\n\"\n * }\n * ],\n * innerHTML: '\\n<div class=\"wp-block-column\"></div>\\n'\n * },\n * {\n * blockName: \"core/column\",\n * attrs: null,\n * innerBlocks: [],\n * innerHTML: '\\n<div class=\"wp-block-column\"></div>\\n'\n * }\n * ],\n * innerHTML: '\\n<div class=\"wp-block-columns has-3-columns\">\\n\\n\\n\\n</div>\\n'\n * }\n * ];\n * ```\n * @return {Array} A block-based representation of the input HTML.\n */\nexport const parse = ( doc ) => {\n\tdocument = doc;\n\toffset = 0;\n\toutput = [];\n\tstack = [];\n\ttokenizer.lastIndex = 0;\n\n\tdo {\n\t\t// twiddle our thumbs\n\t} while ( proceed() );\n\n\treturn output;\n};\n\nfunction proceed() {\n\tconst next = nextToken();\n\tconst [ tokenType, blockName, attrs, startOffset, tokenLength ] = next;\n\tconst stackDepth = stack.length;\n\n\t// we may have some HTML soup before the next block\n\tconst leadingHtmlStart = startOffset > offset ? offset : null;\n\n\tswitch ( tokenType ) {\n\t\tcase 'no-more-tokens':\n\t\t\t// if not in a block then flush output\n\t\t\tif ( 0 === stackDepth ) {\n\t\t\t\taddFreeform();\n\t\t\t\treturn false;\n\t\t\t}\n\n\t\t\t// Otherwise we have a problem\n\t\t\t// This is an error\n\t\t\t// we have options\n\t\t\t// - treat it all as freeform text\n\t\t\t// - assume an implicit closer (easiest when not nesting)\n\n\t\t\t// for the easy case we'll assume an implicit closer\n\t\t\tif ( 1 === stackDepth ) {\n\t\t\t\taddBlockFromStack();\n\t\t\t\treturn false;\n\t\t\t}\n\n\t\t\t// for the nested case where it's more difficult we'll\n\t\t\t// have to assume that multiple closers are missing\n\t\t\t// and so we'll collapse the whole stack piecewise\n\t\t\twhile ( 0 < stack.length ) {\n\t\t\t\taddBlockFromStack();\n\t\t\t}\n\t\t\treturn false;\n\n\t\tcase 'void-block':\n\t\t\t// easy case is if we stumbled upon a void block\n\t\t\t// in the top-level of the document\n\t\t\tif ( 0 === stackDepth ) {\n\t\t\t\tif ( null !== leadingHtmlStart ) {\n\t\t\t\t\toutput.push(\n\t\t\t\t\t\tFreeform(\n\t\t\t\t\t\t\tdocument.substr(\n\t\t\t\t\t\t\t\tleadingHtmlStart,\n\t\t\t\t\t\t\t\tstartOffset - leadingHtmlStart\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t)\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\toutput.push( Block( blockName, attrs, [], '', [] ) );\n\t\t\t\toffset = startOffset + tokenLength;\n\t\t\t\treturn true;\n\t\t\t}\n\n\t\t\t// otherwise we found an inner block\n\t\t\taddInnerBlock(\n\t\t\t\tBlock( blockName, attrs, [], '', [] ),\n\t\t\t\tstartOffset,\n\t\t\t\ttokenLength\n\t\t\t);\n\t\t\toffset = startOffset + tokenLength;\n\t\t\treturn true;\n\n\t\tcase 'block-opener':\n\t\t\t// track all newly-opened blocks on the stack\n\t\t\tstack.push(\n\t\t\t\tFrame(\n\t\t\t\t\tBlock( blockName, attrs, [], '', [] ),\n\t\t\t\t\tstartOffset,\n\t\t\t\t\ttokenLength,\n\t\t\t\t\tstartOffset + tokenLength,\n\t\t\t\t\tleadingHtmlStart\n\t\t\t\t)\n\t\t\t);\n\t\t\toffset = startOffset + tokenLength;\n\t\t\treturn true;\n\n\t\tcase 'block-closer':\n\t\t\t// if we're missing an opener we're in trouble\n\t\t\t// This is an error\n\t\t\tif ( 0 === stackDepth ) {\n\t\t\t\t// we have options\n\t\t\t\t// - assume an implicit opener\n\t\t\t\t// - assume _this_ is the opener\n\t\t\t\t// - give up and close out the document\n\t\t\t\taddFreeform();\n\t\t\t\treturn false;\n\t\t\t}\n\n\t\t\t// if we're not nesting then this is easy - close the block\n\t\t\tif ( 1 === stackDepth ) {\n\t\t\t\taddBlockFromStack( startOffset );\n\t\t\t\toffset = startOffset + tokenLength;\n\t\t\t\treturn true;\n\t\t\t}\n\n\t\t\t// otherwise we're nested and we have to close out the current\n\t\t\t// block and add it as a innerBlock to the parent\n\t\t\tconst stackTop = stack.pop();\n\t\t\tconst html = document.substr(\n\t\t\t\tstackTop.prevOffset,\n\t\t\t\tstartOffset - stackTop.prevOffset\n\t\t\t);\n\t\t\tstackTop.block.innerHTML += html;\n\t\t\tstackTop.block.innerContent.push( html );\n\t\t\tstackTop.prevOffset = startOffset + tokenLength;\n\n\t\t\taddInnerBlock(\n\t\t\t\tstackTop.block,\n\t\t\t\tstackTop.tokenStart,\n\t\t\t\tstackTop.tokenLength,\n\t\t\t\tstartOffset + tokenLength\n\t\t\t);\n\t\t\toffset = startOffset + tokenLength;\n\t\t\treturn true;\n\n\t\tdefault:\n\t\t\t// This is an error\n\t\t\taddFreeform();\n\t\t\treturn false;\n\t}\n}\n\n/**\n * Parse JSON if valid, otherwise return null\n *\n * Note that JSON coming from the block comment\n * delimiters is constrained to be an object\n * and cannot be things like `true` or `null`\n *\n * @param {string} input JSON input string to parse\n * @return {Object|null} parsed JSON if valid\n */\nfunction parseJSON( input ) {\n\ttry {\n\t\treturn JSON.parse( input );\n\t} catch ( e ) {\n\t\treturn null;\n\t}\n}\n\nfunction nextToken() {\n\t// aye the magic\n\t// we're using a single RegExp to tokenize the block comment delimiters\n\t// we're also using a trick here because the only difference between a\n\t// block opener and a block closer is the leading `/` before `wp:` (and\n\t// a closer has no attributes). we can trap them both and process the\n\t// match back in JavaScript to see which one it was.\n\tconst matches = tokenizer.exec( document );\n\n\t// we have no more tokens\n\tif ( null === matches ) {\n\t\treturn [ 'no-more-tokens' ];\n\t}\n\n\tconst startedAt = matches.index;\n\tconst [\n\t\tmatch,\n\t\tcloserMatch,\n\t\tnamespaceMatch,\n\t\tnameMatch,\n\t\tattrsMatch /* internal/unused */,\n\t\t,\n\t\tvoidMatch,\n\t] = matches;\n\n\tconst length = match.length;\n\tconst isCloser = !! closerMatch;\n\tconst isVoid = !! voidMatch;\n\tconst namespace = namespaceMatch || 'core/';\n\tconst name = namespace + nameMatch;\n\tconst hasAttrs = !! attrsMatch;\n\tconst attrs = hasAttrs ? parseJSON( attrsMatch ) : {};\n\n\t// This state isn't allowed\n\t// This is an error\n\tif ( isCloser && ( isVoid || hasAttrs ) ) {\n\t\t// we can ignore them since they don't hurt anything\n\t\t// we may warn against this at some point or reject it\n\t}\n\n\tif ( isVoid ) {\n\t\treturn [ 'void-block', name, attrs, startedAt, length ];\n\t}\n\n\tif ( isCloser ) {\n\t\treturn [ 'block-closer', name, null, startedAt, length ];\n\t}\n\n\treturn [ 'block-opener', name, attrs, startedAt, length ];\n}\n\nfunction addFreeform( rawLength ) {\n\tconst length = rawLength ? rawLength : document.length - offset;\n\n\tif ( 0 === length ) {\n\t\treturn;\n\t}\n\n\toutput.push( Freeform( document.substr( offset, length ) ) );\n}\n\nfunction addInnerBlock( block, tokenStart, tokenLength, lastOffset ) {\n\tconst parent = stack[ stack.length - 1 ];\n\tparent.block.innerBlocks.push( block );\n\tconst html = document.substr(\n\t\tparent.prevOffset,\n\t\ttokenStart - parent.prevOffset\n\t);\n\n\tif ( html ) {\n\t\tparent.block.innerHTML += html;\n\t\tparent.block.innerContent.push( html );\n\t}\n\n\tparent.block.innerContent.push( null );\n\tparent.prevOffset = lastOffset ? lastOffset : tokenStart + tokenLength;\n}\n\nfunction addBlockFromStack( endOffset ) {\n\tconst { block, leadingHtmlStart, prevOffset, tokenStart } = stack.pop();\n\n\tconst html = endOffset\n\t\t? document.substr( prevOffset, endOffset - prevOffset )\n\t\t: document.substr( prevOffset );\n\n\tif ( html ) {\n\t\tblock.innerHTML += html;\n\t\tblock.innerContent.push( html );\n\t}\n\n\tif ( null !== leadingHtmlStart ) {\n\t\toutput.push(\n\t\t\tFreeform(\n\t\t\t\tdocument.substr(\n\t\t\t\t\tleadingHtmlStart,\n\t\t\t\t\ttokenStart - leadingHtmlStart\n\t\t\t\t)\n\t\t\t)\n\t\t);\n\t}\n\n\toutput.push( block );\n}\n"]} |
+42
-62
| "use strict"; | ||
| var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
| Object.defineProperty(exports, "__esModule", { | ||
@@ -9,9 +7,6 @@ value: true | ||
| exports.parse = void 0; | ||
| var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray")); | ||
| var document; | ||
| var offset; | ||
| var output; | ||
| var stack; | ||
| let document; | ||
| let offset; | ||
| let output; | ||
| let stack; | ||
| /** | ||
@@ -59,11 +54,11 @@ * Matches block comment delimiters | ||
| var tokenizer = /<!--\s+(\/)?wp:([a-z][a-z0-9_-]*\/)?([a-z][a-z0-9_-]*)\s+({(?:(?=([^}]+|}+(?=})|(?!}\s+\/?-->)[^])*)\5|[^]*?)}\s+)?(\/)?-->/g; | ||
| const tokenizer = /<!--\s+(\/)?wp:([a-z][a-z0-9_-]*\/)?([a-z][a-z0-9_-]*)\s+({(?:(?=([^}]+|}+(?=})|(?!}\s+\/?-->)[^])*)\5|[^]*?)}\s+)?(\/)?-->/g; | ||
| function Block(blockName, attrs, innerBlocks, innerHTML, innerContent) { | ||
| return { | ||
| blockName: blockName, | ||
| attrs: attrs, | ||
| innerBlocks: innerBlocks, | ||
| innerHTML: innerHTML, | ||
| innerContent: innerContent | ||
| blockName, | ||
| attrs, | ||
| innerBlocks, | ||
| innerHTML, | ||
| innerContent | ||
| }; | ||
@@ -78,7 +73,7 @@ } | ||
| return { | ||
| block: block, | ||
| tokenStart: tokenStart, | ||
| tokenLength: tokenLength, | ||
| block, | ||
| tokenStart, | ||
| tokenLength, | ||
| prevOffset: prevOffset || tokenStart + tokenLength, | ||
| leadingHtmlStart: leadingHtmlStart | ||
| leadingHtmlStart | ||
| }; | ||
@@ -165,3 +160,3 @@ } | ||
| var parse = function parse(doc) { | ||
| const parse = doc => { | ||
| document = doc; | ||
@@ -182,15 +177,8 @@ offset = 0; | ||
| function proceed() { | ||
| var next = nextToken(); | ||
| const next = nextToken(); | ||
| const [tokenType, blockName, attrs, startOffset, tokenLength] = next; | ||
| const stackDepth = stack.length; // we may have some HTML soup before the next block | ||
| var _next = (0, _slicedToArray2.default)(next, 5), | ||
| tokenType = _next[0], | ||
| blockName = _next[1], | ||
| attrs = _next[2], | ||
| startOffset = _next[3], | ||
| tokenLength = _next[4]; | ||
| const leadingHtmlStart = startOffset > offset ? offset : null; | ||
| var stackDepth = stack.length; // we may have some HTML soup before the next block | ||
| var leadingHtmlStart = startOffset > offset ? offset : null; | ||
| switch (tokenType) { | ||
@@ -269,4 +257,4 @@ case 'no-more-tokens': | ||
| var stackTop = stack.pop(); | ||
| var html = document.substr(stackTop.prevOffset, startOffset - stackTop.prevOffset); | ||
| const stackTop = stack.pop(); | ||
| const html = document.substr(stackTop.prevOffset, startOffset - stackTop.prevOffset); | ||
| stackTop.block.innerHTML += html; | ||
@@ -312,3 +300,3 @@ stackTop.block.innerContent.push(html); | ||
| // match back in JavaScript to see which one it was. | ||
| var matches = tokenizer.exec(document); // we have no more tokens | ||
| const matches = tokenizer.exec(document); // we have no more tokens | ||
@@ -319,21 +307,13 @@ if (null === matches) { | ||
| var startedAt = matches.index; | ||
| var _matches = (0, _slicedToArray2.default)(matches, 7), | ||
| match = _matches[0], | ||
| closerMatch = _matches[1], | ||
| namespaceMatch = _matches[2], | ||
| nameMatch = _matches[3], | ||
| attrsMatch | ||
| const startedAt = matches.index; | ||
| const [match, closerMatch, namespaceMatch, nameMatch, attrsMatch | ||
| /* internal/unused */ | ||
| = _matches[4], | ||
| voidMatch = _matches[6]; | ||
| var length = match.length; | ||
| var isCloser = !!closerMatch; | ||
| var isVoid = !!voidMatch; | ||
| var namespace = namespaceMatch || 'core/'; | ||
| var name = namespace + nameMatch; | ||
| var hasAttrs = !!attrsMatch; | ||
| var attrs = hasAttrs ? parseJSON(attrsMatch) : {}; // This state isn't allowed | ||
| ,, voidMatch] = matches; | ||
| const length = match.length; | ||
| const isCloser = !!closerMatch; | ||
| const isVoid = !!voidMatch; | ||
| const namespace = namespaceMatch || 'core/'; | ||
| const name = namespace + nameMatch; | ||
| const hasAttrs = !!attrsMatch; | ||
| const attrs = hasAttrs ? parseJSON(attrsMatch) : {}; // This state isn't allowed | ||
| // This is an error | ||
@@ -357,3 +337,3 @@ | ||
| function addFreeform(rawLength) { | ||
| var length = rawLength ? rawLength : document.length - offset; | ||
| const length = rawLength ? rawLength : document.length - offset; | ||
@@ -368,5 +348,5 @@ if (0 === length) { | ||
| function addInnerBlock(block, tokenStart, tokenLength, lastOffset) { | ||
| var parent = stack[stack.length - 1]; | ||
| const parent = stack[stack.length - 1]; | ||
| parent.block.innerBlocks.push(block); | ||
| var html = document.substr(parent.prevOffset, tokenStart - parent.prevOffset); | ||
| const html = document.substr(parent.prevOffset, tokenStart - parent.prevOffset); | ||
@@ -383,10 +363,10 @@ if (html) { | ||
| function addBlockFromStack(endOffset) { | ||
| var _stack$pop = stack.pop(), | ||
| block = _stack$pop.block, | ||
| leadingHtmlStart = _stack$pop.leadingHtmlStart, | ||
| prevOffset = _stack$pop.prevOffset, | ||
| tokenStart = _stack$pop.tokenStart; | ||
| const { | ||
| block, | ||
| leadingHtmlStart, | ||
| prevOffset, | ||
| tokenStart | ||
| } = stack.pop(); | ||
| const html = endOffset ? document.substr(prevOffset, endOffset - prevOffset) : document.substr(prevOffset); | ||
| var html = endOffset ? document.substr(prevOffset, endOffset - prevOffset) : document.substr(prevOffset); | ||
| if (html) { | ||
@@ -393,0 +373,0 @@ block.innerHTML += html; |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"sources":["@wordpress/block-serialization-default-parser/src/index.js"],"names":["document","offset","output","stack","tokenizer","Block","blockName","attrs","innerBlocks","innerHTML","innerContent","Freeform","Frame","block","tokenStart","tokenLength","prevOffset","leadingHtmlStart","parse","doc","lastIndex","proceed","next","nextToken","tokenType","startOffset","stackDepth","length","addFreeform","addBlockFromStack","push","substr","addInnerBlock","stackTop","pop","html","parseJSON","input","JSON","e","matches","exec","startedAt","index","match","closerMatch","namespaceMatch","nameMatch","attrsMatch","voidMatch","isCloser","isVoid","namespace","name","hasAttrs","rawLength","lastOffset","parent","endOffset"],"mappings":";;;;;;;;;;;AAAA,IAAIA,QAAJ;AACA,IAAIC,MAAJ;AACA,IAAIC,MAAJ;AACA,IAAIC,KAAJ;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,IAAMC,SAAS,GAAG,8HAAlB;;AAEA,SAASC,KAAT,CAAgBC,SAAhB,EAA2BC,KAA3B,EAAkCC,WAAlC,EAA+CC,SAA/C,EAA0DC,YAA1D,EAAyE;AACxE,SAAO;AACNJ,IAAAA,SAAS,EAATA,SADM;AAENC,IAAAA,KAAK,EAALA,KAFM;AAGNC,IAAAA,WAAW,EAAXA,WAHM;AAINC,IAAAA,SAAS,EAATA,SAJM;AAKNC,IAAAA,YAAY,EAAZA;AALM,GAAP;AAOA;;AAED,SAASC,QAAT,CAAmBF,SAAnB,EAA+B;AAC9B,SAAOJ,KAAK,CAAE,IAAF,EAAQ,EAAR,EAAY,EAAZ,EAAgBI,SAAhB,EAA2B,CAAEA,SAAF,CAA3B,CAAZ;AACA;;AAED,SAASG,KAAT,CAAgBC,KAAhB,EAAuBC,UAAvB,EAAmCC,WAAnC,EAAgDC,UAAhD,EAA4DC,gBAA5D,EAA+E;AAC9E,SAAO;AACNJ,IAAAA,KAAK,EAALA,KADM;AAENC,IAAAA,UAAU,EAAVA,UAFM;AAGNC,IAAAA,WAAW,EAAXA,WAHM;AAINC,IAAAA,UAAU,EAAEA,UAAU,IAAIF,UAAU,GAAGC,WAJjC;AAKNE,IAAAA,gBAAgB,EAAhBA;AALM,GAAP;AAOA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,IAAMC,KAAK,GAAG,SAARA,KAAQ,CAAEC,GAAF,EAAW;AAC/BnB,EAAAA,QAAQ,GAAGmB,GAAX;AACAlB,EAAAA,MAAM,GAAG,CAAT;AACAC,EAAAA,MAAM,GAAG,EAAT;AACAC,EAAAA,KAAK,GAAG,EAAR;AACAC,EAAAA,SAAS,CAACgB,SAAV,GAAsB,CAAtB;;AAEA,KAAG,CACF;AACA,GAFD,QAEUC,OAAO,EAFjB;;AAIA,SAAOnB,MAAP;AACA,CAZM;;;;AAcP,SAASmB,OAAT,GAAmB;AAClB,MAAMC,IAAI,GAAGC,SAAS,EAAtB;;AADkB,2CAEgDD,IAFhD;AAAA,MAEVE,SAFU;AAAA,MAEClB,SAFD;AAAA,MAEYC,KAFZ;AAAA,MAEmBkB,WAFnB;AAAA,MAEgCV,WAFhC;;AAGlB,MAAMW,UAAU,GAAGvB,KAAK,CAACwB,MAAzB,CAHkB,CAKlB;;AACA,MAAMV,gBAAgB,GAAGQ,WAAW,GAAGxB,MAAd,GAAuBA,MAAvB,GAAgC,IAAzD;;AAEA,UAASuB,SAAT;AACC,SAAK,gBAAL;AACC;AACA,UAAK,MAAME,UAAX,EAAwB;AACvBE,QAAAA,WAAW;AACX,eAAO,KAAP;AACA,OALF,CAOC;AACA;AACA;AACA;AACA;AAEA;;;AACA,UAAK,MAAMF,UAAX,EAAwB;AACvBG,QAA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B,CAFH;;AAIA,MAAKmB,IAAL,EAAY;AACXtB,IAAAA,KAAK,CAACJ,SAAN,IAAmB0B,IAAnB;AACAtB,IAAAA,KAAK,CAACH,YAAN,CAAmBoB,IAAnB,CAAyBK,IAAzB;AACA;;AAED,MAAK,SAASlB,gBAAd,EAAiC;AAChCf,IAAAA,MAAM,CAAC4B,IAAP,CACCnB,QAAQ,CACPX,QAAQ,CAAC+B,MAAT,CACCd,gBADD,EAECH,UAAU,GAAGG,gBAFd,CADO,CADT;AAQA;;AAEDf,EAAAA,MAAM,CAAC4B,IAAP,CAAajB,KAAb;AACA","sourcesContent":["let document;\nlet offset;\nlet output;\nlet stack;\n\n/**\n * Matches block comment delimiters\n *\n * While most of this pattern is straightforward the attribute parsing\n * incorporates a tricks to make sure we don't choke on specific input\n *\n * - since JavaScript has no possessive quantifier or atomic grouping\n * we are emulating it with a trick\n *\n * we want a possessive quantifier or atomic group to prevent backtracking\n * on the `}`s should we fail to match the remainder of the pattern\n *\n * we can emulate this with a positive lookahead and back reference\n * (a++)*c === ((?=(a+))\\1)*c\n *\n * let's examine an example:\n * - /(a+)*c/.test('aaaaaaaaaaaaad') fails after over 49,000 steps\n * - /(a++)*c/.test('aaaaaaaaaaaaad') fails after 85 steps\n * - /(?>a+)*c/.test('aaaaaaaaaaaaad') fails after 126 steps\n *\n * this is because the possessive `++` and the atomic group `(?>)`\n * tell the engine that all those `a`s belong together as a single group\n * and so it won't split it up when stepping backwards to try and match\n *\n * if we use /((?=(a+))\\1)*c/ then we get the same behavior as the atomic group\n * or possessive and prevent the backtracking because the `a+` is matched but\n * not captured. thus, we find the long string of `a`s and remember it, then\n * reference it as a whole unit inside our pattern\n *\n * @see http://instanceof.me/post/52245507631/regex-emulate-atomic-grouping-with-lookahead\n * @see http://blog.stevenlevithan.com/archives/mimic-atomic-groups\n * @see https://javascript.info/regexp-infinite-backtracking-problem\n *\n * once browsers reliably support atomic grouping or possessive\n * quantifiers natively we should remove this trick and simplify\n *\n * @type {RegExp}\n *\n * @since 3.8.0\n * @since 4.6.1 added optimization to prevent backtracking on attribute parsing\n */\nconst tokenizer = /<!--\\s+(\\/)?wp:([a-z][a-z0-9_-]*\\/)?([a-z][a-z0-9_-]*)\\s+({(?:(?=([^}]+|}+(?=})|(?!}\\s+\\/?-->)[^])*)\\5|[^]*?)}\\s+)?(\\/)?-->/g;\n\nfunction Block( blockName, attrs, innerBlocks, innerHTML, innerContent ) {\n\treturn {\n\t\tblockName,\n\t\tattrs,\n\t\tinnerBlocks,\n\t\tinnerHTML,\n\t\tinnerContent,\n\t};\n}\n\nfunction Freeform( innerHTML ) {\n\treturn Block( null, {}, [], innerHTML, [ innerHTML ] );\n}\n\nfunction Frame( block, tokenStart, tokenLength, prevOffset, leadingHtmlStart ) {\n\treturn {\n\t\tblock,\n\t\ttokenStart,\n\t\ttokenLength,\n\t\tprevOffset: prevOffset || tokenStart + tokenLength,\n\t\tleadingHtmlStart,\n\t};\n}\n\n/**\n * Parser function, that converts input HTML into a block based structure.\n *\n * @param {string} doc The HTML document to parse.\n *\n * @example\n * Input post:\n * ```html\n * <!-- wp:columns {\"columns\":3} -->\n * <div class=\"wp-block-columns has-3-columns\"><!-- wp:column -->\n * <div class=\"wp-block-column\"><!-- wp:paragraph -->\n * <p>Left</p>\n * <!-- /wp:paragraph --></div>\n * <!-- /wp:column -->\n *\n * <!-- wp:column -->\n * <div class=\"wp-block-column\"><!-- wp:paragraph -->\n * <p><strong>Middle</strong></p>\n * <!-- /wp:paragraph --></div>\n * <!-- /wp:column -->\n *\n * <!-- wp:column -->\n * <div class=\"wp-block-column\"></div>\n * <!-- /wp:column --></div>\n * <!-- /wp:columns -->\n * ```\n *\n * Parsing code:\n * ```js\n * import { parse } from '@wordpress/block-serialization-default-parser';\n *\n * parse( post ) === [\n * {\n * blockName: \"core/columns\",\n * attrs: {\n * columns: 3\n * },\n * innerBlocks: [\n * {\n * blockName: \"core/column\",\n * attrs: null,\n * innerBlocks: [\n * {\n * blockName: \"core/paragraph\",\n * attrs: null,\n * innerBlocks: [],\n * innerHTML: \"\\n<p>Left</p>\\n\"\n * }\n * ],\n * innerHTML: '\\n<div class=\"wp-block-column\"></div>\\n'\n * },\n * {\n * blockName: \"core/column\",\n * attrs: null,\n * innerBlocks: [\n * {\n * blockName: \"core/paragraph\",\n * attrs: null,\n * innerBlocks: [],\n * innerHTML: \"\\n<p><strong>Middle</strong></p>\\n\"\n * }\n * ],\n * innerHTML: '\\n<div class=\"wp-block-column\"></div>\\n'\n * },\n * {\n * blockName: \"core/column\",\n * attrs: null,\n * innerBlocks: [],\n * innerHTML: '\\n<div class=\"wp-block-column\"></div>\\n'\n * }\n * ],\n * innerHTML: '\\n<div class=\"wp-block-columns has-3-columns\">\\n\\n\\n\\n</div>\\n'\n * }\n * ];\n * ```\n * @return {Array} A block-based representation of the input HTML.\n */\nexport const parse = ( doc ) => {\n\tdocument = doc;\n\toffset = 0;\n\toutput = [];\n\tstack = [];\n\ttokenizer.lastIndex = 0;\n\n\tdo {\n\t\t// twiddle our thumbs\n\t} while ( proceed() );\n\n\treturn output;\n};\n\nfunction proceed() {\n\tconst next = nextToken();\n\tconst [ tokenType, blockName, attrs, startOffset, tokenLength ] = next;\n\tconst stackDepth = stack.length;\n\n\t// we may have some HTML soup before the next block\n\tconst leadingHtmlStart = startOffset > offset ? offset : null;\n\n\tswitch ( tokenType ) {\n\t\tcase 'no-more-tokens':\n\t\t\t// if not in a block then flush output\n\t\t\tif ( 0 === stackDepth ) {\n\t\t\t\taddFreeform();\n\t\t\t\treturn false;\n\t\t\t}\n\n\t\t\t// Otherwise we have a problem\n\t\t\t// This is an error\n\t\t\t// we have options\n\t\t\t// - treat it all as freeform text\n\t\t\t// - assume an implicit closer (easiest when not nesting)\n\n\t\t\t// for the easy case we'll assume an implicit closer\n\t\t\tif ( 1 === stackDepth ) {\n\t\t\t\taddBlockFromStack();\n\t\t\t\treturn false;\n\t\t\t}\n\n\t\t\t// for the nested case where it's more difficult we'll\n\t\t\t// have to assume that multiple closers are missing\n\t\t\t// and so we'll collapse the whole stack piecewise\n\t\t\twhile ( 0 < stack.length ) {\n\t\t\t\taddBlockFromStack();\n\t\t\t}\n\t\t\treturn false;\n\n\t\tcase 'void-block':\n\t\t\t// easy case is if we stumbled upon a void block\n\t\t\t// in the top-level of the document\n\t\t\tif ( 0 === stackDepth ) {\n\t\t\t\tif ( null !== leadingHtmlStart ) {\n\t\t\t\t\toutput.push(\n\t\t\t\t\t\tFreeform(\n\t\t\t\t\t\t\tdocument.substr(\n\t\t\t\t\t\t\t\tleadingHtmlStart,\n\t\t\t\t\t\t\t\tstartOffset - leadingHtmlStart\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t)\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\toutput.push( Block( blockName, attrs, [], '', [] ) );\n\t\t\t\toffset = startOffset + tokenLength;\n\t\t\t\treturn true;\n\t\t\t}\n\n\t\t\t// otherwise we found an inner block\n\t\t\taddInnerBlock(\n\t\t\t\tBlock( blockName, attrs, [], '', [] ),\n\t\t\t\tstartOffset,\n\t\t\t\ttokenLength\n\t\t\t);\n\t\t\toffset = startOffset + tokenLength;\n\t\t\treturn true;\n\n\t\tcase 'block-opener':\n\t\t\t// track all newly-opened blocks on the stack\n\t\t\tstack.push(\n\t\t\t\tFrame(\n\t\t\t\t\tBlock( blockName, attrs, [], '', [] ),\n\t\t\t\t\tstartOffset,\n\t\t\t\t\ttokenLength,\n\t\t\t\t\tstartOffset + tokenLength,\n\t\t\t\t\tleadingHtmlStart\n\t\t\t\t)\n\t\t\t);\n\t\t\toffset = startOffset + tokenLength;\n\t\t\treturn true;\n\n\t\tcase 'block-closer':\n\t\t\t// if we're missing an opener we're in trouble\n\t\t\t// This is an error\n\t\t\tif ( 0 === stackDepth ) {\n\t\t\t\t// we have options\n\t\t\t\t// - assume an implicit opener\n\t\t\t\t// - assume _this_ is the opener\n\t\t\t\t// - give up and close out the document\n\t\t\t\taddFreeform();\n\t\t\t\treturn false;\n\t\t\t}\n\n\t\t\t// if we're not nesting then this is easy - close the block\n\t\t\tif ( 1 === stackDepth ) {\n\t\t\t\taddBlockFromStack( startOffset );\n\t\t\t\toffset = startOffset + tokenLength;\n\t\t\t\treturn true;\n\t\t\t}\n\n\t\t\t// otherwise we're nested and we have to close out the current\n\t\t\t// block and add it as a innerBlock to the parent\n\t\t\tconst stackTop = stack.pop();\n\t\t\tconst html = document.substr(\n\t\t\t\tstackTop.prevOffset,\n\t\t\t\tstartOffset - stackTop.prevOffset\n\t\t\t);\n\t\t\tstackTop.block.innerHTML += html;\n\t\t\tstackTop.block.innerContent.push( html );\n\t\t\tstackTop.prevOffset = startOffset + tokenLength;\n\n\t\t\taddInnerBlock(\n\t\t\t\tstackTop.block,\n\t\t\t\tstackTop.tokenStart,\n\t\t\t\tstackTop.tokenLength,\n\t\t\t\tstartOffset + tokenLength\n\t\t\t);\n\t\t\toffset = startOffset + tokenLength;\n\t\t\treturn true;\n\n\t\tdefault:\n\t\t\t// This is an error\n\t\t\taddFreeform();\n\t\t\treturn false;\n\t}\n}\n\n/**\n * Parse JSON if valid, otherwise return null\n *\n * Note that JSON coming from the block comment\n * delimiters is constrained to be an object\n * and cannot be things like `true` or `null`\n *\n * @param {string} input JSON input string to parse\n * @return {Object|null} parsed JSON if valid\n */\nfunction parseJSON( input ) {\n\ttry {\n\t\treturn JSON.parse( input );\n\t} catch ( e ) {\n\t\treturn null;\n\t}\n}\n\nfunction nextToken() {\n\t// aye the magic\n\t// we're using a single RegExp to tokenize the block comment delimiters\n\t// we're also using a trick here because the only difference between a\n\t// block opener and a block closer is the leading `/` before `wp:` (and\n\t// a closer has no attributes). we can trap them both and process the\n\t// match back in JavaScript to see which one it was.\n\tconst matches = tokenizer.exec( document );\n\n\t// we have no more tokens\n\tif ( null === matches ) {\n\t\treturn [ 'no-more-tokens' ];\n\t}\n\n\tconst startedAt = matches.index;\n\tconst [\n\t\tmatch,\n\t\tcloserMatch,\n\t\tnamespaceMatch,\n\t\tnameMatch,\n\t\tattrsMatch /* internal/unused */,\n\t\t,\n\t\tvoidMatch,\n\t] = matches;\n\n\tconst length = match.length;\n\tconst isCloser = !! closerMatch;\n\tconst isVoid = !! voidMatch;\n\tconst namespace = namespaceMatch || 'core/';\n\tconst name = namespace + nameMatch;\n\tconst hasAttrs = !! attrsMatch;\n\tconst attrs = hasAttrs ? parseJSON( attrsMatch ) : {};\n\n\t// This state isn't allowed\n\t// This is an error\n\tif ( isCloser && ( isVoid || hasAttrs ) ) {\n\t\t// we can ignore them since they don't hurt anything\n\t\t// we may warn against this at some point or reject it\n\t}\n\n\tif ( isVoid ) {\n\t\treturn [ 'void-block', name, attrs, startedAt, length ];\n\t}\n\n\tif ( isCloser ) {\n\t\treturn [ 'block-closer', name, null, startedAt, length ];\n\t}\n\n\treturn [ 'block-opener', name, attrs, startedAt, length ];\n}\n\nfunction addFreeform( rawLength ) {\n\tconst length = rawLength ? rawLength : document.length - offset;\n\n\tif ( 0 === length ) {\n\t\treturn;\n\t}\n\n\toutput.push( Freeform( document.substr( offset, length ) ) );\n}\n\nfunction addInnerBlock( block, tokenStart, tokenLength, lastOffset ) {\n\tconst parent = stack[ stack.length - 1 ];\n\tparent.block.innerBlocks.push( block );\n\tconst html = document.substr(\n\t\tparent.prevOffset,\n\t\ttokenStart - parent.prevOffset\n\t);\n\n\tif ( html ) {\n\t\tparent.block.innerHTML += html;\n\t\tparent.block.innerContent.push( html );\n\t}\n\n\tparent.block.innerContent.push( null );\n\tparent.prevOffset = lastOffset ? lastOffset : tokenStart + tokenLength;\n}\n\nfunction addBlockFromStack( endOffset ) {\n\tconst { block, leadingHtmlStart, prevOffset, tokenStart } = stack.pop();\n\n\tconst html = endOffset\n\t\t? document.substr( prevOffset, endOffset - prevOffset )\n\t\t: document.substr( prevOffset );\n\n\tif ( html ) {\n\t\tblock.innerHTML += html;\n\t\tblock.innerContent.push( html );\n\t}\n\n\tif ( null !== leadingHtmlStart ) {\n\t\toutput.push(\n\t\t\tFreeform(\n\t\t\t\tdocument.substr(\n\t\t\t\t\tleadingHtmlStart,\n\t\t\t\t\ttokenStart - leadingHtmlStart\n\t\t\t\t)\n\t\t\t)\n\t\t);\n\t}\n\n\toutput.push( block );\n}\n"]} | ||
| {"version":3,"sources":["@wordpress/block-serialization-default-parser/src/index.js"],"names":["document","offset","output","stack","tokenizer","Block","blockName","attrs","innerBlocks","innerHTML","innerContent","Freeform","Frame","block","tokenStart","tokenLength","prevOffset","leadingHtmlStart","parse","doc","lastIndex","proceed","next","nextToken","tokenType","startOffset","stackDepth","length","addFreeform","addBlockFromStack","push","substr","addInnerBlock","stackTop","pop","html","parseJSON","input","JSON","e","matches","exec","startedAt","index","match","closerMatch","namespaceMatch","nameMatch","attrsMatch","voidMatch","isCloser","isVoid","namespace","name","hasAttrs","rawLength","lastOffset","parent","endOffset"],"mappings":";;;;;;AAAA,IAAIA,QAAJ;AACA,IAAIC,MAAJ;AACA,IAAIC,MAAJ;AACA,IAAIC,KAAJ;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,MAAMC,SAAS,GAAG,8HAAlB;;AAEA,SAASC,KAAT,CAAgBC,SAAhB,EAA2BC,KAA3B,EAAkCC,WAAlC,EAA+CC,SAA/C,EAA0DC,YAA1D,EAAyE;AACxE,SAAO;AACNJ,IAAAA,SADM;AAENC,IAAAA,KAFM;AAGNC,IAAAA,WAHM;AAINC,IAAAA,SAJM;AAKNC,IAAAA;AALM,GAAP;AAOA;;AAED,SAASC,QAAT,CAAmBF,SAAnB,EAA+B;AAC9B,SAAOJ,KAAK,CAAE,IAAF,EAAQ,EAAR,EAAY,EAAZ,EAAgBI,SAAhB,EAA2B,CAAEA,SAAF,CAA3B,CAAZ;AACA;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AAT,CAAiBf,UAAjB,EAA6B0C,SAAS,GAAG1C,UAAzC,CADmB,GAEnBhB,QAAQ,CAAC+B,MAAT,CAAiBf,UAAjB,CAFH;;AAIA,MAAKmB,IAAL,EAAY;AACXtB,IAAAA,KAAK,CAACJ,SAAN,IAAmB0B,IAAnB;AACAtB,IAAAA,KAAK,CAACH,YAAN,CAAmBoB,IAAnB,CAAyBK,IAAzB;AACA;;AAED,MAAK,SAASlB,gBAAd,EAAiC;AAChCf,IAAAA,MAAM,CAAC4B,IAAP,CACCnB,QAAQ,CACPX,QAAQ,CAAC+B,MAAT,CACCd,gBADD,EAECH,UAAU,GAAGG,gBAFd,CADO,CADT;AAQA;;AAEDf,EAAAA,MAAM,CAAC4B,IAAP,CAAajB,KAAb;AACA","sourcesContent":["let document;\nlet offset;\nlet output;\nlet stack;\n\n/**\n * Matches block comment delimiters\n *\n * While most of this pattern is straightforward the attribute parsing\n * incorporates a tricks to make sure we don't choke on specific input\n *\n * - since JavaScript has no possessive quantifier or atomic grouping\n * we are emulating it with a trick\n *\n * we want a possessive quantifier or atomic group to prevent backtracking\n * on the `}`s should we fail to match the remainder of the pattern\n *\n * we can emulate this with a positive lookahead and back reference\n * (a++)*c === ((?=(a+))\\1)*c\n *\n * let's examine an example:\n * - /(a+)*c/.test('aaaaaaaaaaaaad') fails after over 49,000 steps\n * - /(a++)*c/.test('aaaaaaaaaaaaad') fails after 85 steps\n * - /(?>a+)*c/.test('aaaaaaaaaaaaad') fails after 126 steps\n *\n * this is because the possessive `++` and the atomic group `(?>)`\n * tell the engine that all those `a`s belong together as a single group\n * and so it won't split it up when stepping backwards to try and match\n *\n * if we use /((?=(a+))\\1)*c/ then we get the same behavior as the atomic group\n * or possessive and prevent the backtracking because the `a+` is matched but\n * not captured. thus, we find the long string of `a`s and remember it, then\n * reference it as a whole unit inside our pattern\n *\n * @see http://instanceof.me/post/52245507631/regex-emulate-atomic-grouping-with-lookahead\n * @see http://blog.stevenlevithan.com/archives/mimic-atomic-groups\n * @see https://javascript.info/regexp-infinite-backtracking-problem\n *\n * once browsers reliably support atomic grouping or possessive\n * quantifiers natively we should remove this trick and simplify\n *\n * @type {RegExp}\n *\n * @since 3.8.0\n * @since 4.6.1 added optimization to prevent backtracking on attribute parsing\n */\nconst tokenizer = /<!--\\s+(\\/)?wp:([a-z][a-z0-9_-]*\\/)?([a-z][a-z0-9_-]*)\\s+({(?:(?=([^}]+|}+(?=})|(?!}\\s+\\/?-->)[^])*)\\5|[^]*?)}\\s+)?(\\/)?-->/g;\n\nfunction Block( blockName, attrs, innerBlocks, innerHTML, innerContent ) {\n\treturn {\n\t\tblockName,\n\t\tattrs,\n\t\tinnerBlocks,\n\t\tinnerHTML,\n\t\tinnerContent,\n\t};\n}\n\nfunction Freeform( innerHTML ) {\n\treturn Block( null, {}, [], innerHTML, [ innerHTML ] );\n}\n\nfunction Frame( block, tokenStart, tokenLength, prevOffset, leadingHtmlStart ) {\n\treturn {\n\t\tblock,\n\t\ttokenStart,\n\t\ttokenLength,\n\t\tprevOffset: prevOffset || tokenStart + tokenLength,\n\t\tleadingHtmlStart,\n\t};\n}\n\n/**\n * Parser function, that converts input HTML into a block based structure.\n *\n * @param {string} doc The HTML document to parse.\n *\n * @example\n * Input post:\n * ```html\n * <!-- wp:columns {\"columns\":3} -->\n * <div class=\"wp-block-columns has-3-columns\"><!-- wp:column -->\n * <div class=\"wp-block-column\"><!-- wp:paragraph -->\n * <p>Left</p>\n * <!-- /wp:paragraph --></div>\n * <!-- /wp:column -->\n *\n * <!-- wp:column -->\n * <div class=\"wp-block-column\"><!-- wp:paragraph -->\n * <p><strong>Middle</strong></p>\n * <!-- /wp:paragraph --></div>\n * <!-- /wp:column -->\n *\n * <!-- wp:column -->\n * <div class=\"wp-block-column\"></div>\n * <!-- /wp:column --></div>\n * <!-- /wp:columns -->\n * ```\n *\n * Parsing code:\n * ```js\n * import { parse } from '@wordpress/block-serialization-default-parser';\n *\n * parse( post ) === [\n * {\n * blockName: \"core/columns\",\n * attrs: {\n * columns: 3\n * },\n * innerBlocks: [\n * {\n * blockName: \"core/column\",\n * attrs: null,\n * innerBlocks: [\n * {\n * blockName: \"core/paragraph\",\n * attrs: null,\n * innerBlocks: [],\n * innerHTML: \"\\n<p>Left</p>\\n\"\n * }\n * ],\n * innerHTML: '\\n<div class=\"wp-block-column\"></div>\\n'\n * },\n * {\n * blockName: \"core/column\",\n * attrs: null,\n * innerBlocks: [\n * {\n * blockName: \"core/paragraph\",\n * attrs: null,\n * innerBlocks: [],\n * innerHTML: \"\\n<p><strong>Middle</strong></p>\\n\"\n * }\n * ],\n * innerHTML: '\\n<div class=\"wp-block-column\"></div>\\n'\n * },\n * {\n * blockName: \"core/column\",\n * attrs: null,\n * innerBlocks: [],\n * innerHTML: '\\n<div class=\"wp-block-column\"></div>\\n'\n * }\n * ],\n * innerHTML: '\\n<div class=\"wp-block-columns has-3-columns\">\\n\\n\\n\\n</div>\\n'\n * }\n * ];\n * ```\n * @return {Array} A block-based representation of the input HTML.\n */\nexport const parse = ( doc ) => {\n\tdocument = doc;\n\toffset = 0;\n\toutput = [];\n\tstack = [];\n\ttokenizer.lastIndex = 0;\n\n\tdo {\n\t\t// twiddle our thumbs\n\t} while ( proceed() );\n\n\treturn output;\n};\n\nfunction proceed() {\n\tconst next = nextToken();\n\tconst [ tokenType, blockName, attrs, startOffset, tokenLength ] = next;\n\tconst stackDepth = stack.length;\n\n\t// we may have some HTML soup before the next block\n\tconst leadingHtmlStart = startOffset > offset ? offset : null;\n\n\tswitch ( tokenType ) {\n\t\tcase 'no-more-tokens':\n\t\t\t// if not in a block then flush output\n\t\t\tif ( 0 === stackDepth ) {\n\t\t\t\taddFreeform();\n\t\t\t\treturn false;\n\t\t\t}\n\n\t\t\t// Otherwise we have a problem\n\t\t\t// This is an error\n\t\t\t// we have options\n\t\t\t// - treat it all as freeform text\n\t\t\t// - assume an implicit closer (easiest when not nesting)\n\n\t\t\t// for the easy case we'll assume an implicit closer\n\t\t\tif ( 1 === stackDepth ) {\n\t\t\t\taddBlockFromStack();\n\t\t\t\treturn false;\n\t\t\t}\n\n\t\t\t// for the nested case where it's more difficult we'll\n\t\t\t// have to assume that multiple closers are missing\n\t\t\t// and so we'll collapse the whole stack piecewise\n\t\t\twhile ( 0 < stack.length ) {\n\t\t\t\taddBlockFromStack();\n\t\t\t}\n\t\t\treturn false;\n\n\t\tcase 'void-block':\n\t\t\t// easy case is if we stumbled upon a void block\n\t\t\t// in the top-level of the document\n\t\t\tif ( 0 === stackDepth ) {\n\t\t\t\tif ( null !== leadingHtmlStart ) {\n\t\t\t\t\toutput.push(\n\t\t\t\t\t\tFreeform(\n\t\t\t\t\t\t\tdocument.substr(\n\t\t\t\t\t\t\t\tleadingHtmlStart,\n\t\t\t\t\t\t\t\tstartOffset - leadingHtmlStart\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t)\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\toutput.push( Block( blockName, attrs, [], '', [] ) );\n\t\t\t\toffset = startOffset + tokenLength;\n\t\t\t\treturn true;\n\t\t\t}\n\n\t\t\t// otherwise we found an inner block\n\t\t\taddInnerBlock(\n\t\t\t\tBlock( blockName, attrs, [], '', [] ),\n\t\t\t\tstartOffset,\n\t\t\t\ttokenLength\n\t\t\t);\n\t\t\toffset = startOffset + tokenLength;\n\t\t\treturn true;\n\n\t\tcase 'block-opener':\n\t\t\t// track all newly-opened blocks on the stack\n\t\t\tstack.push(\n\t\t\t\tFrame(\n\t\t\t\t\tBlock( blockName, attrs, [], '', [] ),\n\t\t\t\t\tstartOffset,\n\t\t\t\t\ttokenLength,\n\t\t\t\t\tstartOffset + tokenLength,\n\t\t\t\t\tleadingHtmlStart\n\t\t\t\t)\n\t\t\t);\n\t\t\toffset = startOffset + tokenLength;\n\t\t\treturn true;\n\n\t\tcase 'block-closer':\n\t\t\t// if we're missing an opener we're in trouble\n\t\t\t// This is an error\n\t\t\tif ( 0 === stackDepth ) {\n\t\t\t\t// we have options\n\t\t\t\t// - assume an implicit opener\n\t\t\t\t// - assume _this_ is the opener\n\t\t\t\t// - give up and close out the document\n\t\t\t\taddFreeform();\n\t\t\t\treturn false;\n\t\t\t}\n\n\t\t\t// if we're not nesting then this is easy - close the block\n\t\t\tif ( 1 === stackDepth ) {\n\t\t\t\taddBlockFromStack( startOffset );\n\t\t\t\toffset = startOffset + tokenLength;\n\t\t\t\treturn true;\n\t\t\t}\n\n\t\t\t// otherwise we're nested and we have to close out the current\n\t\t\t// block and add it as a innerBlock to the parent\n\t\t\tconst stackTop = stack.pop();\n\t\t\tconst html = document.substr(\n\t\t\t\tstackTop.prevOffset,\n\t\t\t\tstartOffset - stackTop.prevOffset\n\t\t\t);\n\t\t\tstackTop.block.innerHTML += html;\n\t\t\tstackTop.block.innerContent.push( html );\n\t\t\tstackTop.prevOffset = startOffset + tokenLength;\n\n\t\t\taddInnerBlock(\n\t\t\t\tstackTop.block,\n\t\t\t\tstackTop.tokenStart,\n\t\t\t\tstackTop.tokenLength,\n\t\t\t\tstartOffset + tokenLength\n\t\t\t);\n\t\t\toffset = startOffset + tokenLength;\n\t\t\treturn true;\n\n\t\tdefault:\n\t\t\t// This is an error\n\t\t\taddFreeform();\n\t\t\treturn false;\n\t}\n}\n\n/**\n * Parse JSON if valid, otherwise return null\n *\n * Note that JSON coming from the block comment\n * delimiters is constrained to be an object\n * and cannot be things like `true` or `null`\n *\n * @param {string} input JSON input string to parse\n * @return {Object|null} parsed JSON if valid\n */\nfunction parseJSON( input ) {\n\ttry {\n\t\treturn JSON.parse( input );\n\t} catch ( e ) {\n\t\treturn null;\n\t}\n}\n\nfunction nextToken() {\n\t// aye the magic\n\t// we're using a single RegExp to tokenize the block comment delimiters\n\t// we're also using a trick here because the only difference between a\n\t// block opener and a block closer is the leading `/` before `wp:` (and\n\t// a closer has no attributes). we can trap them both and process the\n\t// match back in JavaScript to see which one it was.\n\tconst matches = tokenizer.exec( document );\n\n\t// we have no more tokens\n\tif ( null === matches ) {\n\t\treturn [ 'no-more-tokens' ];\n\t}\n\n\tconst startedAt = matches.index;\n\tconst [\n\t\tmatch,\n\t\tcloserMatch,\n\t\tnamespaceMatch,\n\t\tnameMatch,\n\t\tattrsMatch /* internal/unused */,\n\t\t,\n\t\tvoidMatch,\n\t] = matches;\n\n\tconst length = match.length;\n\tconst isCloser = !! closerMatch;\n\tconst isVoid = !! voidMatch;\n\tconst namespace = namespaceMatch || 'core/';\n\tconst name = namespace + nameMatch;\n\tconst hasAttrs = !! attrsMatch;\n\tconst attrs = hasAttrs ? parseJSON( attrsMatch ) : {};\n\n\t// This state isn't allowed\n\t// This is an error\n\tif ( isCloser && ( isVoid || hasAttrs ) ) {\n\t\t// we can ignore them since they don't hurt anything\n\t\t// we may warn against this at some point or reject it\n\t}\n\n\tif ( isVoid ) {\n\t\treturn [ 'void-block', name, attrs, startedAt, length ];\n\t}\n\n\tif ( isCloser ) {\n\t\treturn [ 'block-closer', name, null, startedAt, length ];\n\t}\n\n\treturn [ 'block-opener', name, attrs, startedAt, length ];\n}\n\nfunction addFreeform( rawLength ) {\n\tconst length = rawLength ? rawLength : document.length - offset;\n\n\tif ( 0 === length ) {\n\t\treturn;\n\t}\n\n\toutput.push( Freeform( document.substr( offset, length ) ) );\n}\n\nfunction addInnerBlock( block, tokenStart, tokenLength, lastOffset ) {\n\tconst parent = stack[ stack.length - 1 ];\n\tparent.block.innerBlocks.push( block );\n\tconst html = document.substr(\n\t\tparent.prevOffset,\n\t\ttokenStart - parent.prevOffset\n\t);\n\n\tif ( html ) {\n\t\tparent.block.innerHTML += html;\n\t\tparent.block.innerContent.push( html );\n\t}\n\n\tparent.block.innerContent.push( null );\n\tparent.prevOffset = lastOffset ? lastOffset : tokenStart + tokenLength;\n}\n\nfunction addBlockFromStack( endOffset ) {\n\tconst { block, leadingHtmlStart, prevOffset, tokenStart } = stack.pop();\n\n\tconst html = endOffset\n\t\t? document.substr( prevOffset, endOffset - prevOffset )\n\t\t: document.substr( prevOffset );\n\n\tif ( html ) {\n\t\tblock.innerHTML += html;\n\t\tblock.innerContent.push( html );\n\t}\n\n\tif ( null !== leadingHtmlStart ) {\n\t\toutput.push(\n\t\t\tFreeform(\n\t\t\t\tdocument.substr(\n\t\t\t\t\tleadingHtmlStart,\n\t\t\t\t\ttokenStart - leadingHtmlStart\n\t\t\t\t)\n\t\t\t)\n\t\t);\n\t}\n\n\toutput.push( block );\n}\n"]} |
+11
-4
@@ -5,2 +5,9 @@ <!-- Learn how to maintain this file at https://github.com/WordPress/gutenberg/tree/HEAD/packages#maintaining-changelogs. --> | ||
| ## 4.0.0 (2021-05-14) | ||
| ### Breaking Changes | ||
| - Drop support for Internet Explorer 11 ([#31110](https://github.com/WordPress/gutenberg/pull/31110)). Learn more at https://make.wordpress.org/core/2021/04/22/ie-11-support-phase-out-plan/. | ||
| - Increase the minimum Node.js version to v12 matching Long Term Support releases ([#31270](https://github.com/WordPress/gutenberg/pull/31270)). Learn more at https://nodejs.org/en/about/releases/. | ||
| ## 3.10.0 (2021-03-17) | ||
@@ -18,4 +25,4 @@ | ||
| - Inner blocks are now cast as arrays instead of objects. | ||
| - JS and PHP parsers now behave consistently when parsing empty attributes. | ||
| - Inner blocks are now cast as arrays instead of objects. | ||
| - JS and PHP parsers now behave consistently when parsing empty attributes. | ||
@@ -26,4 +33,4 @@ ## 1.1.1 (2018-11-09) | ||
| - Add new list of HTML fragments to parse output. | ||
| - Optimize JSON-attribute parsing. | ||
| - Add new list of HTML fragments to parse output. | ||
| - Optimize JSON-attribute parsing. | ||
@@ -30,0 +37,0 @@ ## 1.0.2 (2018-11-03) |
+407
-19
@@ -1,19 +0,23 @@ | ||
| ### WordPress - Web publishing software | ||
| ## Gutenberg | ||
| Copyright 2011-2021 by the contributors | ||
| Copyright 2016-2021 by the contributors | ||
| This program is free software; you can redistribute it and/or modify | ||
| it under the terms of the GNU General Public License as published by | ||
| the Free Software Foundation; either version 2 of the License, or | ||
| (at your option) any later version. | ||
| **License for Contributions (on and after April 15, 2021)** | ||
| This program is distributed in the hope that it will be useful, | ||
| but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| GNU General Public License for more details. | ||
| All code contributed to the Gutenberg project is dual-licensed, | ||
| and released under both of the following licenses: | ||
| You should have received a copy of the GNU General Public License | ||
| along with this program; if not, write to the Free Software | ||
| Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
| the GNU General Public License as published by the Free Software Foundation; | ||
| either version 2 of the License or (at your option) any later version (the “GPL”) | ||
| and the Mozilla Public License, Version 2.0 (the “MPL”). | ||
| **Project License** | ||
| The Gutenberg project license is not affected by the License for Contributions (as | ||
| discussed in the [Dual License section](#dual-license) below). The Gutenberg project | ||
| continues to be free software; you can redistribute it and/or modify it | ||
| under the terms of the GNU General Public License as published by the Free | ||
| Software Foundation; either version 2 of the License or (at your option) any | ||
| later version (the “GPL”). | ||
| This program incorporates work covered by the following copyright and | ||
@@ -38,4 +42,45 @@ permission notices: | ||
| ### Dual License | ||
| **We are currently in the process of changing Gutenberg’s software license from | ||
| GPL to a dual license: GPL and MPL.** | ||
| **This process involves two independent steps (1) obtaining permission for dual | ||
| licensing from contributors of already contributed Gutenberg code and (2) | ||
| dual licensing of all contributions to Gutenberg that are made on or after | ||
| April 15, 2021.** | ||
| **For part (1): We’re reaching out to everyone who has contributed code, prior | ||
| to April 15, 2021, and asking that they agree to dual license their | ||
| contribution to the project. We expect this process to be completed by | ||
| mid-year, 2021.** | ||
| **For part (2): We have changed the license for contributed code to this | ||
| repository to make clear that all contributions on or after April 15, 2021 | ||
| will be made under the dual-license.** | ||
| **When we have received all necessary rights and permissions to dual license | ||
| the pre-April 15, 2021 code of the Gutenberg project (Part 1 above), you will | ||
| have the option to use and distribute all of the Gutenberg project under | ||
| either the GPL or MPL license. At this time we will change the “Project | ||
| License” to the following:** | ||
| The Gutenberg project is free software; you can redistribute it and/or modify | ||
| it under the terms of either of the following licenses: | ||
| 1. the GNU General Public License as published by the Free Software Foundation; | ||
| either version 2 of the License or (at your option) any later version (the | ||
| “GPL”) OR | ||
| 2. the Mozilla Public License Version 2.0 (the “MPL”). | ||
| --- | ||
| ## Full Text of Referenced Licenses | ||
| 1. [GNU General Public License, Version 2](#gnu-general-public-license-version-2) | ||
| 2. [Mozilla Public License, Version 2.0](#mozilla-public-license-version-20) | ||
| ## GNU General Public License, Version 2 | ||
| ### GNU GENERAL PUBLIC LICENSE | ||
@@ -139,7 +184,5 @@ | ||
| **a)** You must cause the modified files to carry prominent notices | ||
| stating that you changed the files and the date of any change. | ||
| **b)** You must cause any work that you distribute or publish, that in | ||
@@ -150,3 +193,2 @@ whole or in part contains or is derived from the Program or any part | ||
| **c)** If the modified program normally reads commands interactively | ||
@@ -188,3 +230,2 @@ when run, you must cause it, when started running for such interactive | ||
| **a)** Accompany it with the complete corresponding machine-readable | ||
@@ -194,3 +235,2 @@ source code, which must be distributed under the terms of Sections 1 | ||
| **b)** Accompany it with a written offer, valid for at least three | ||
@@ -203,3 +243,2 @@ years, to give any third party, for a charge no more than your cost of | ||
| **c)** Accompany it with the information you received as to the offer | ||
@@ -407,1 +446,350 @@ to distribute corresponding source code. (This alternative is allowed | ||
| License. | ||
| --- | ||
| ## Mozilla Public License, Version 2.0 | ||
| ### 1. Definitions | ||
| **1.1. “Contributor”** | ||
| means each individual or legal entity that creates, contributes to | ||
| the creation of, or owns Covered Software. | ||
| **1.2. “Contributor Version”** | ||
| means the combination of the Contributions of others (if any) used | ||
| by a Contributor and that particular Contributor's Contribution. | ||
| **1.3. “Contribution”** | ||
| means Covered Software of a particular Contributor. | ||
| **1.4. “Covered Software”** | ||
| means Source Code Form to which the initial Contributor has attached | ||
| the notice in Exhibit A, the Executable Form of such Source Code | ||
| Form, and Modifications of such Source Code Form, in each case | ||
| including portions thereof. | ||
| **1.5. “Incompatible With Secondary Licenses”** | ||
| means | ||
| - **(a)** that the initial Contributor has attached the notice described | ||
| in Exhibit B to the Covered Software; or | ||
| - **(b)** that the Covered Software was made available under the terms of | ||
| version 1.1 or earlier of the License, but not also under the | ||
| terms of a Secondary License. | ||
| **1.6. “Executable Form”** | ||
| means any form of the work other than Source Code Form. | ||
| **1.7. “Larger Work”** | ||
| means a work that combines Covered Software with other material, in | ||
| a separate file or files, that is not Covered Software. | ||
| **1.8. “License”** | ||
| means this document. | ||
| **1.9. “Licensable”** | ||
| means having the right to grant, to the maximum extent possible, | ||
| whether at the time of the initial grant or subsequently, any and | ||
| all of the rights conveyed by this License. | ||
| **1.10. “Modifications”** | ||
| means any of the following: | ||
| - **(a)** any file in Source Code Form that results from an addition to, | ||
| deletion from, or modification of the contents of Covered | ||
| Software; or | ||
| - **(b)** any new file in Source Code Form that contains any Covered | ||
| Software. | ||
| **1.11. “Patent Claims” of a Contributor** | ||
| means any patent claim(s), including without limitation, method, | ||
| process, and apparatus claims, in any patent Licensable by such | ||
| Contributor that would be infringed, but for the grant of the | ||
| License, by the making, using, selling, offering for sale, having | ||
| made, import, or transfer of either its Contributions or its | ||
| Contributor Version. | ||
| **1.12. “Secondary License”** | ||
| means either the GNU General Public License, Version 2.0, the GNU | ||
| Lesser General Public License, Version 2.1, the GNU Affero General | ||
| Public License, Version 3.0, or any later versions of those | ||
| licenses. | ||
| **1.13. “Source Code Form”** | ||
| means the form of the work preferred for making modifications. | ||
| **1.14. “You” (or “Your”)** | ||
| means an individual or a legal entity exercising rights under this | ||
| License. For legal entities, “You” includes any entity that | ||
| controls, is controlled by, or is under common control with You. For | ||
| purposes of this definition, “control” means **(a)** the power, direct | ||
| or indirect, to cause the direction or management of such entity, | ||
| whether by contract or otherwise, or **(b)** ownership of more than | ||
| fifty percent (50%) of the outstanding shares or beneficial | ||
| ownership of such entity. | ||
| ### 2. License Grants and Conditions | ||
| #### 2.1. Grants | ||
| Each Contributor hereby grants You a world-wide, royalty-free, | ||
| non-exclusive license: | ||
| - **(a)** under intellectual property rights (other than patent or trademark) | ||
| Licensable by such Contributor to use, reproduce, make available, | ||
| modify, display, perform, distribute, and otherwise exploit its | ||
| Contributions, either on an unmodified basis, with Modifications, or | ||
| as part of a Larger Work; and | ||
| - **(b)** under Patent Claims of such Contributor to make, use, sell, offer | ||
| for sale, have made, import, and otherwise transfer either its | ||
| Contributions or its Contributor Version. | ||
| #### 2.2. Effective Date | ||
| The licenses granted in Section 2.1 with respect to any Contribution | ||
| become effective for each Contribution on the date the Contributor first | ||
| distributes such Contribution. | ||
| #### 2.3. Limitations on Grant Scope | ||
| The licenses granted in this Section 2 are the only rights granted under | ||
| this License. No additional rights or licenses will be implied from the | ||
| distribution or licensing of Covered Software under this License. | ||
| Notwithstanding Section 2.1(b) above, no patent license is granted by a | ||
| Contributor: | ||
| - **(a)** for any code that a Contributor has removed from Covered Software; | ||
| or | ||
| - **(b)** for infringements caused by: **(i)** Your and any other third party's | ||
| modifications of Covered Software, or **(ii)** the combination of its | ||
| Contributions with other software (except as part of its Contributor | ||
| Version); or | ||
| - **(c)** under Patent Claims infringed by Covered Software in the absence of | ||
| its Contributions. | ||
| This License does not grant any rights in the trademarks, service marks, | ||
| or logos of any Contributor (except as may be necessary to comply with | ||
| the notice requirements in Section 3.4). | ||
| #### 2.4. Subsequent Licenses | ||
| No Contributor makes additional grants as a result of Your choice to | ||
| distribute the Covered Software under a subsequent version of this | ||
| License (see Section 10.2) or under the terms of a Secondary License (if | ||
| permitted under the terms of Section 3.3). | ||
| #### 2.5. Representation | ||
| Each Contributor represents that the Contributor believes its | ||
| Contributions are its original creation(s) or it has sufficient rights | ||
| to grant the rights to its Contributions conveyed by this License. | ||
| #### 2.6. Fair Use | ||
| This License is not intended to limit any rights You have under | ||
| applicable copyright doctrines of fair use, fair dealing, or other | ||
| equivalents. | ||
| #### 2.7. Conditions | ||
| Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted | ||
| in Section 2.1. | ||
| ### 3. Responsibilities | ||
| #### 3.1. Distribution of Source Form | ||
| All distribution of Covered Software in Source Code Form, including any | ||
| Modifications that You create or to which You contribute, must be under | ||
| the terms of this License. You must inform recipients that the Source | ||
| Code Form of the Covered Software is governed by the terms of this | ||
| License, and how they can obtain a copy of this License. You may not | ||
| attempt to alter or restrict the recipients' rights in the Source Code | ||
| Form. | ||
| #### 3.2. Distribution of Executable Form | ||
| If You distribute Covered Software in Executable Form then: | ||
| - **(a)** such Covered Software must also be made available in Source Code | ||
| Form, as described in Section 3.1, and You must inform recipients of | ||
| the Executable Form how they can obtain a copy of such Source Code | ||
| Form by reasonable means in a timely manner, at a charge no more | ||
| than the cost of distribution to the recipient; and | ||
| - **(b)** You may distribute such Executable Form under the terms of this | ||
| License, or sublicense it under different terms, provided that the | ||
| license for the Executable Form does not attempt to limit or alter | ||
| the recipients' rights in the Source Code Form under this License. | ||
| #### 3.3. Distribution of a Larger Work | ||
| You may create and distribute a Larger Work under terms of Your choice, | ||
| provided that You also comply with the requirements of this License for | ||
| the Covered Software. If the Larger Work is a combination of Covered | ||
| Software with a work governed by one or more Secondary Licenses, and the | ||
| Covered Software is not Incompatible With Secondary Licenses, this | ||
| License permits You to additionally distribute such Covered Software | ||
| under the terms of such Secondary License(s), so that the recipient of | ||
| the Larger Work may, at their option, further distribute the Covered | ||
| Software under the terms of either this License or such Secondary | ||
| License(s). | ||
| #### 3.4. Notices | ||
| You may not remove or alter the substance of any license notices | ||
| (including copyright notices, patent notices, disclaimers of warranty, | ||
| or limitations of liability) contained within the Source Code Form of | ||
| the Covered Software, except that You may alter any license notices to | ||
| the extent required to remedy known factual inaccuracies. | ||
| #### 3.5. Application of Additional Terms | ||
| You may choose to offer, and to charge a fee for, warranty, support, | ||
| indemnity or liability obligations to one or more recipients of Covered | ||
| Software. However, You may do so only on Your own behalf, and not on | ||
| behalf of any Contributor. You must make it absolutely clear that any | ||
| such warranty, support, indemnity, or liability obligation is offered by | ||
| You alone, and You hereby agree to indemnify every Contributor for any | ||
| liability incurred by such Contributor as a result of warranty, support, | ||
| indemnity or liability terms You offer. You may include additional | ||
| disclaimers of warranty and limitations of liability specific to any | ||
| jurisdiction. | ||
| ### 4. Inability to Comply Due to Statute or Regulation | ||
| If it is impossible for You to comply with any of the terms of this | ||
| License with respect to some or all of the Covered Software due to | ||
| statute, judicial order, or regulation then You must: **(a)** comply with | ||
| the terms of this License to the maximum extent possible; and **(b)** | ||
| describe the limitations and the code they affect. Such description must | ||
| be placed in a text file included with all distributions of the Covered | ||
| Software under this License. Except to the extent prohibited by statute | ||
| or regulation, such description must be sufficiently detailed for a | ||
| recipient of ordinary skill to be able to understand it. | ||
| ### 5. Termination | ||
| **5.1.** The rights granted under this License will terminate automatically | ||
| if You fail to comply with any of its terms. However, if You become | ||
| compliant, then the rights granted under this License from a particular | ||
| Contributor are reinstated **(a)** provisionally, unless and until such | ||
| Contributor explicitly and finally terminates Your grants, and **(b)** on an | ||
| ongoing basis, if such Contributor fails to notify You of the | ||
| non-compliance by some reasonable means prior to 60 days after You have | ||
| come back into compliance. Moreover, Your grants from a particular | ||
| Contributor are reinstated on an ongoing basis if such Contributor | ||
| notifies You of the non-compliance by some reasonable means, this is the | ||
| first time You have received notice of non-compliance with this License | ||
| from such Contributor, and You become compliant prior to 30 days after | ||
| Your receipt of the notice. | ||
| **5.2.** If You initiate litigation against any entity by asserting a patent | ||
| infringement claim (excluding declaratory judgment actions, | ||
| counter-claims, and cross-claims) alleging that a Contributor Version | ||
| directly or indirectly infringes any patent, then the rights granted to | ||
| You by any and all Contributors for the Covered Software under Section | ||
| 2.1 of this License shall terminate. | ||
| **5.3.** In the event of termination under Sections 5.1 or 5.2 above, all | ||
| end user license agreements (excluding distributors and resellers) which | ||
| have been validly granted by You or Your distributors under this License | ||
| prior to termination shall survive termination. | ||
| ### 6. Disclaimer of Warranty | ||
| > Covered Software is provided under this License on an “as is” | ||
| > basis, without warranty of any kind, either expressed, implied, or | ||
| > statutory, including, without limitation, warranties that the | ||
| > Covered Software is free of defects, merchantable, fit for a | ||
| > particular purpose or non-infringing. The entire risk as to the | ||
| > quality and performance of the Covered Software is with You. | ||
| > Should any Covered Software prove defective in any respect, You | ||
| > (not any Contributor) assume the cost of any necessary servicing, | ||
| > repair, or correction. This disclaimer of warranty constitutes an | ||
| > essential part of this License. No use of any Covered Software is | ||
| > authorized under this License except under this disclaimer. | ||
| ### 7. Limitation of Liability | ||
| > Under no circumstances and under no legal theory, whether tort | ||
| > (including negligence), contract, or otherwise, shall any | ||
| > Contributor, or anyone who distributes Covered Software as | ||
| > permitted above, be liable to You for any direct, indirect, | ||
| > special, incidental, or consequential damages of any character | ||
| > including, without limitation, damages for lost profits, loss of | ||
| > goodwill, work stoppage, computer failure or malfunction, or any | ||
| > and all other commercial damages or losses, even if such party | ||
| > shall have been informed of the possibility of such damages. This | ||
| > limitation of liability shall not apply to liability for death or | ||
| > personal injury resulting from such party's negligence to the | ||
| > extent applicable law prohibits such limitation. Some | ||
| > jurisdictions do not allow the exclusion or limitation of | ||
| > incidental or consequential damages, so this exclusion and | ||
| > limitation may not apply to You. | ||
| ### 8. Litigation | ||
| Any litigation relating to this License may be brought only in the | ||
| courts of a jurisdiction where the defendant maintains its principal | ||
| place of business and such litigation shall be governed by laws of that | ||
| jurisdiction, without reference to its conflict-of-law provisions. | ||
| Nothing in this Section shall prevent a party's ability to bring | ||
| cross-claims or counter-claims. | ||
| ### 9. Miscellaneous | ||
| This License represents the complete agreement concerning the subject | ||
| matter hereof. If any provision of this License is held to be | ||
| unenforceable, such provision shall be reformed only to the extent | ||
| necessary to make it enforceable. Any law or regulation which provides | ||
| that the language of a contract shall be construed against the drafter | ||
| shall not be used to construe this License against a Contributor. | ||
| ### 10. Versions of the License | ||
| #### 10.1. New Versions | ||
| Mozilla Foundation is the license steward. Except as provided in Section | ||
| 10.3, no one other than the license steward has the right to modify or | ||
| publish new versions of this License. Each version will be given a | ||
| distinguishing version number. | ||
| #### 10.2. Effect of New Versions | ||
| You may distribute the Covered Software under the terms of the version | ||
| of the License under which You originally received the Covered Software, | ||
| or under the terms of any subsequent version published by the license | ||
| steward. | ||
| #### 10.3. Modified Versions | ||
| If you create software not governed by this License, and you want to | ||
| create a new license for such software, you may create and use a | ||
| modified version of this License if you rename the license and remove | ||
| any references to the name of the license steward (except to note that | ||
| such modified license differs from this License). | ||
| #### 10.4. Distributing Source Code Form that is Incompatible With Secondary Licenses | ||
| If You choose to distribute Source Code Form that is Incompatible With | ||
| Secondary Licenses under the terms of this version of the License, the | ||
| notice described in Exhibit B of this License must be attached. | ||
| ## Exhibit A - Source Code Form License Notice | ||
| This Source Code Form is subject to the terms of the Mozilla Public | ||
| License, v. 2.0. If a copy of the MPL was not distributed with this | ||
| file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
| If it is not possible or desirable to put the notice in a particular | ||
| file, then You may include the notice in a location (such as a LICENSE | ||
| file in a relevant directory) where a recipient would be likely to look | ||
| for such a notice. | ||
| You may add additional accurate notices of copyright ownership. | ||
| ## Exhibit B - “Incompatible With Secondary Licenses” Notice | ||
| This Source Code Form is "Incompatible With Secondary Licenses", as | ||
| defined by the Mozilla Public License, v. 2.0. |
+5
-2
| { | ||
| "name": "@wordpress/block-serialization-default-parser", | ||
| "version": "3.10.2", | ||
| "version": "4.0.0", | ||
| "description": "Block serialization specification parser for WordPress posts.", | ||
@@ -22,2 +22,5 @@ "author": "The WordPress Contributors", | ||
| }, | ||
| "engines": { | ||
| "node": ">=12" | ||
| }, | ||
| "main": "build/index.js", | ||
@@ -33,3 +36,3 @@ "module": "build-module/index.js", | ||
| }, | ||
| "gitHead": "a71b0769184b8b1cf0c86f3c99d452ef7491b096" | ||
| "gitHead": "0c80fbada8b86cd8e4b4892460caa3a5d0e5f583" | ||
| } |
+1
-1
@@ -13,3 +13,3 @@ # Block Serialization Default Parser | ||
| _This package assumes that your code will run in an **ES2015+** environment. If you're using an environment that has limited or no support for ES2015+ such as lower versions of IE then using [core-js](https://github.com/zloirock/core-js) or [@babel/polyfill](https://babeljs.io/docs/en/next/babel-polyfill) will add support for these methods. Learn more about it in [Babel docs](https://babeljs.io/docs/en/next/caveats)._ | ||
| _This package assumes that your code will run in an **ES2015+** environment. If you're using an environment that has limited or no support for ES2015+ such as IE browsers then using [core-js](https://github.com/zloirock/core-js) will add polyfills for these methods._ | ||
@@ -16,0 +16,0 @@ ## API |
Copyleft License
LicenseCopyleft license information was found.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
Mixed license
LicensePackage contains multiple licenses.
Found 1 instance in 1 package
Non-permissive License
LicenseA license not known to be considered permissive was found.
Found 1 instance in 1 package
Copyleft License
LicenseCopyleft license information was found.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
Non-permissive License
LicenseA license not known to be considered permissive was found.
Found 1 instance in 1 package
134008
13.55%3
50%1028
-2.19%