Brunobkr/llama.cpp_AlgMor24_github
ΩFFFΣLLIa • llama.cpp • AlgMor24 ██████╗ ███████╗███████╗███████╗██╗ ██╗ ██╗ █████╗ ██╔═══██╗██╔════╝██╔════╝██╔════╝██║ ██║ ██║██╔══██╗ ██║ ██║█████╗ █████╗ █████╗ ██║ ██║ ██║███████║ ██║ ██║██╔══╝ ██╔══╝ ██╔══╝ ██║ ██║ ██║██╔══██║ ╚██████╔╝██║ ██║ ███████╗███████╗███████╗██║██║ ██║ ╚═════╝ ╚═╝ ╚═╝ ╚══════╝╚══════╝╚══════╝╚═╝╚═╝ ╚═╝ High-Performance LLM / VLM Inference & Autonomous Agentic Ecosystem… See the full description on the dataset page: https://huggingface.co/datasets/Brunobkr/llama.cpp_AlgMor24_github.
03.1k
1/**2 * Map of elements that have certain elements that are not allowed inside them, in the sense that they will auto-close the parent/ancestor element.3 * Theoretically one could take advantage of it but most of the time it will just result in confusing behavior and break when SSR'd.4 * There are more elements that are invalid inside other elements, but they're not auto-closed and so don't break SSR and are therefore not listed here.5 * @type {Record<string, { direct: string[]} | { descendant: string[]; reset_by?: string[] }>}6 */7const autoclosing_children = {8 // based on http://developers.whatwg.org/syntax.html#syntax-tag-omission9 li: { direct: ['li'] },10 // https://developer.mozilla.org/en-US/docs/Web/HTML/Element/dt#technical_summary11 dt: { descendant: ['dt', 'dd'], reset_by: ['dl'] },12 dd: { descendant: ['dt', 'dd'], reset_by: ['dl'] },13 p: {14 descendant: [15 'address',16 'article',17 'aside',18 'blockquote',19 'div',20 'dl',21 'fieldset',22 'footer',23 'form',24 'h1',25 'h2',26 'h3',27 'h4',28 'h5',29 'h6',30 'header',31 'hgroup',32 'hr',33 'main',34 'menu',35 'nav',36 'ol',37 'p',38 'pre',39 'section',40 'table',41 'ul'42 ]43 },44 rt: { descendant: ['rt', 'rp'] },45 rp: { descendant: ['rt', 'rp'] },46 optgroup: { descendant: ['optgroup'] },47 option: { descendant: ['option', 'optgroup'] },48 thead: { direct: ['tbody', 'tfoot'] },49 tbody: { direct: ['tbody', 'tfoot'] },50 tfoot: { direct: ['tbody'] },51 tr: { direct: ['tr', 'tbody'] },52 td: { direct: ['td', 'th', 'tr'] },53 th: { direct: ['td', 'th', 'tr'] }54};55 56/**57 * Returns true if the tag is either the last in the list of siblings and will be autoclosed,58 * or not allowed inside the parent tag such that it will auto-close it. The latter results59 * in the browser repairing the HTML, which will likely result in an error during hydration.60 * @param {string} current61 * @param {string} [next]62 */63export function closing_tag_omitted(current, next) {64 const disallowed = autoclosing_children[current];65 if (disallowed) {66 if (67 !next ||68 ('direct' in disallowed ? disallowed.direct : disallowed.descendant).includes(next)69 ) {70 return true;71 }72 }73 return false;74}75 76/**77 * Map of elements that have certain elements that are not allowed inside them, in the sense that the browser will somehow repair the HTML.78 * There are more elements that are invalid inside other elements, but they're not repaired and so don't break SSR and are therefore not listed here.79 * @type {Record<string, { direct: string[]} | { descendant: string[]; reset_by?: string[]; only?: string[] } | { only: string[] }>}80 */81const disallowed_children = {82 ...autoclosing_children,83 // Strictly speaking, seeing an <option> doesn't mean we're in a <select>, but we assume it here84 // option or optgroup does not have an `only` restriction because newer browsers support rich HTML content85 // inside option elements. For older browsers, hydration will handle the mismatch.86 form: { descendant: ['form'] },87 a: { descendant: ['a'] },88 button: { descendant: ['button'] },89 h1: { descendant: ['h1', 'h2', 'h3', 'h4', 'h5', 'h6'] },90 h2: { descendant: ['h1', 'h2', 'h3', 'h4', 'h5', 'h6'] },91 h3: { descendant: ['h1', 'h2', 'h3', 'h4', 'h5', 'h6'] },92 h4: { descendant: ['h1', 'h2', 'h3', 'h4', 'h5', 'h6'] },93 h5: { descendant: ['h1', 'h2', 'h3', 'h4', 'h5', 'h6'] },94 h6: { descendant: ['h1', 'h2', 'h3', 'h4', 'h5', 'h6'] },95 96 // https://html.spec.whatwg.org/multipage/syntax.html#parsing-main-intd97 // https://html.spec.whatwg.org/multipage/syntax.html#parsing-main-incaption98 // No special behavior since these rules fall back to "in body" mode for99 // all except special table nodes which cause bad parsing behavior anyway.100 101 // https://html.spec.whatwg.org/multipage/syntax.html#parsing-main-intd102 tr: { only: ['th', 'td', 'style', 'script', 'template'] },103 // https://html.spec.whatwg.org/multipage/syntax.html#parsing-main-intbody104 tbody: { only: ['tr', 'style', 'script', 'template'] },105 thead: { only: ['tr', 'style', 'script', 'template'] },106 tfoot: { only: ['tr', 'style', 'script', 'template'] },107 // https://html.spec.whatwg.org/multipage/syntax.html#parsing-main-incolgroup108 colgroup: { only: ['col', 'template'] },109 // https://html.spec.whatwg.org/multipage/syntax.html#parsing-main-intable110 table: {111 only: ['caption', 'colgroup', 'tbody', 'thead', 'tfoot', 'style', 'script', 'template']112 },113 // https://html.spec.whatwg.org/multipage/syntax.html#parsing-main-inhead114 head: {115 only: [116 'base',117 'basefont',118 'bgsound',119 'link',120 'meta',121 'title',122 'noscript',123 'noframes',124 'style',125 'script',126 'template'127 ]128 },129 // https://html.spec.whatwg.org/multipage/semantics.html#the-html-element130 html: { only: ['head', 'body', 'frameset'] },131 frameset: { only: ['frame'] },132 '#document': { only: ['html'] }133};134 135/**136 * Returns an error message if the tag is not allowed inside the ancestor tag (which is grandparent and above) such that it will result137 * in the browser repairing the HTML, which will likely result in an error during hydration.138 * @param {string} child_tag139 * @param {string[]} ancestors All nodes starting with the parent, up until the ancestor, which means two entries minimum140 * @param {string} [child_loc]141 * @param {string} [ancestor_loc]142 * @returns {string | null}143 */144export function is_tag_valid_with_ancestor(child_tag, ancestors, child_loc, ancestor_loc) {145 if (child_tag.includes('-')) return null; // custom elements can be anything146 147 const ancestor_tag = ancestors[ancestors.length - 1];148 const disallowed = disallowed_children[ancestor_tag];149 if (!disallowed) return null;150 151 if ('reset_by' in disallowed && disallowed.reset_by) {152 for (let i = ancestors.length - 2; i >= 0; i--) {153 const ancestor = ancestors[i];154 if (ancestor.includes('-')) return null; // custom elements can be anything155 156 // A reset means that forbidden descendants are allowed again157 if (disallowed.reset_by.includes(ancestors[i])) {158 return null;159 }160 }161 }162 163 if ('descendant' in disallowed && disallowed.descendant.includes(child_tag)) {164 const child = child_loc ? `\`<${child_tag}>\` (${child_loc})` : `\`<${child_tag}>\``;165 const ancestor = ancestor_loc166 ? `\`<${ancestor_tag}>\` (${ancestor_loc})`167 : `\`<${ancestor_tag}>\``;168 169 return `${child} cannot be a descendant of ${ancestor}`;170 }171 172 return null;173}174 175/**176 * Returns an error message if the tag is not allowed inside the parent tag such that it will result177 * in the browser repairing the HTML, which will likely result in an error during hydration.178 * @param {string} child_tag179 * @param {string} parent_tag180 * @param {string} [child_loc]181 * @param {string} [parent_loc]182 * @returns {string | null}183 */184export function is_tag_valid_with_parent(child_tag, parent_tag, child_loc, parent_loc) {185 if (child_tag.includes('-') || parent_tag?.includes('-')) return null; // custom elements can be anything186 187 if (parent_tag === 'template') return null; // no errors or warning should be thrown in immediate children of template tags188 189 const disallowed = disallowed_children[parent_tag];190 191 const child = child_loc ? `\`<${child_tag}>\` (${child_loc})` : `\`<${child_tag}>\``;192 const parent = parent_loc ? `\`<${parent_tag}>\` (${parent_loc})` : `\`<${parent_tag}>\``;193 194 if (disallowed) {195 if ('direct' in disallowed && disallowed.direct.includes(child_tag)) {196 return `${child} cannot be a direct child of ${parent}`;197 }198 199 if ('descendant' in disallowed && disallowed.descendant.includes(child_tag)) {200 return `${child} cannot be a child of ${parent}`;201 }202 203 if ('only' in disallowed && disallowed.only) {204 if (disallowed.only.includes(child_tag)) {205 return null;206 } else {207 return `${child} cannot be a child of ${parent}. \`<${parent_tag}>\` only allows these children: ${disallowed.only.map((d) => `\`<${d}>\``).join(', ')}`;208 }209 }210 }211 212 // These tags are only valid with a few parents that have special child213 // parsing rules - if we're down here, then none of those matched and214 // so we allow it only if we don't know what the parent is, as all other215 // cases are invalid (and we only get into this function if we know the parent).216 switch (child_tag) {217 case 'body':218 case 'caption':219 case 'col':220 case 'colgroup':221 case 'frameset':222 case 'frame':223 case 'head':224 case 'html':225 return `${child} cannot be a child of ${parent}`;226 case 'thead':227 case 'tbody':228 case 'tfoot':229 return `${child} must be the child of a \`<table>\`, not a ${parent}`;230 case 'td':231 case 'th':232 return `${child} must be the child of a \`<tr>\`, not a ${parent}`;233 case 'tr':234 return `\`<tr>\` must be the child of a \`<thead>\`, \`<tbody>\`, or \`<tfoot>\`, not a ${parent}`;235 }236 237 return null;238}239 