elearning/Frontend-Learner/node_modules/refa/index.js

2 lines
989 KiB
JavaScript
Raw Normal View History

2026-01-13 10:46:40 +07:00
"use strict";function m(m){function n(i){let a=n.cache.get(i);return void 0===a&&n.cache.set(i,a=m(i)),a}return n.cache=new Map,n}Object.defineProperty(exports,"__esModule",{value:!0});const n=Array.isArray;function i(m,n){let i=0;for(let a=0;a<m.length;a++){const x=m[a];n(x,m[a-i-1])?m[a-i]=x:i++}m.splice(m.length-i,i)}function a(m,n){n===m.length-1?m.pop():m[n]=m.pop()}function x(m,n){let i,a=1/0;for(const x of m){const m=n(x);m<a&&(i=x,a=m)}return i}function e(m){return Array.isArray(m)?m:[...m]}function t(m){return m instanceof Set?m:new Set(m)}function r(m){for(const n of m)return n}function s(m,n){const i=new Set,a=[{element:m,nextIndex:-1}];for(;a.length>0;){const m=a[a.length-1];-1===m.nextIndex&&(i.add(m.element),m.nextElements=e(n(m.element)));const x=m.nextElements;if(!x)throw new Error("This should not happen.");if(m.nextIndex++,m.nextIndex>=x.length){a.pop();continue}const t=x[m.nextIndex];i.has(t)||a.push({element:t,nextIndex:-1})}}function*o(m,n){const i=new Set;let a=[...m],x=[];for(;a.length>0;){for(const m of a)i.has(m)||(i.add(m),yield m,x.push(...n(m)));[a,x]=[x,a],x.length=0}}function l(m,n){const i=new Set,a=[m];let x;for(;a.length;)x=a.pop(),i.has(x)||(i.add(x),n(x,a))}function c(m,n){const i=new Set,a=[...m];let x;for(;a.length;)x=a.pop(),i.has(x)||(i.add(x),n(x,a))}function h(m,n){const i=new Error(n);throw i.data=m,i}function*u(m){for(const n of m)yield*n}function*f(m){for(const n of _(m)){const m=[];for(const i of n)m.push(...i);yield m}}function*p(m){for(const n of _(m))yield[...n]}class d{constructor(m){this._cache=[],this._fullyCached=!1,this._iterator=m[Symbol.iterator]()}[Symbol.iterator](){return this._fullyCached?this._cache[Symbol.iterator]():function*(m){const{_cache:n,_iterator:i}=m;let a=0;for(;!m._fullyCached;)if(a<n.length)yield n[a],a++;else{const x=i.next();if(x.done)m._fullyCached=!0;else{const{value:m}=x;n.push(m),yield m,a++}}for(;a<n.length;a++)yield n[a]}(this)}}function g(m){return Array.isArray(m)||m instanceof Set||m instanceof d?m:new d(m)}function*_(m){const n=e(m).map(g),i=n.map((m=>m[Symbol.iterator]())),a=[];for(const m of i){const n=m.next();if(n.done)return;a.push(n.value)}if(yield a,0!==i.length)for(;;){for(let m=i.length-1;m>=0;m--){const x=i[m].next();if(!x.done){a[m]=x.value;break}if(0===m)return;{i[m]=n[m][Symbol.iterator]();const x=i[m].next();if(x.done)throw new Error;a[m]=x.value}}yield a}}function C(m,n){v(m,n)}function v(m,n){switch(m.type){case"Concatenation":if(null===n)throw new Error("The parent of a concatenation cannot be null.");switch(n.type){case"Alternation":case"Assertion":case"Expression":case"Quantifier":m.parent=n;break;case"Concatenation":throw new Error("A concatenation cannot be parent of a concatenation.");default:throw h(n)}m.elements.forEach((n=>v(n,m)));break;case"Alternation":case"Assertion":case"CharacterClass":case"Quantifier":case"Unknown":if(null===n)throw new Error(`The parent of a(n) ${m.type} cannot be null.`);if("Concatenation"!==n.type)throw new Error(`A(n) ${n.type} cannot be parent of a(n) ${m.type}.`);m.parent=n,"CharacterClass"!==m.type&&"Unknown"!==m.type&&m.alternatives.forEach((n=>v(n,m)));break;case"Expression":if(null!==n)throw new Error(`The parent of an expression has to be null and cannot be a(n) ${n.type}.`);m.parent=null,m.alternatives.forEach((n=>v(n,m)));break;default:throw h(m)}}function y(m,n,i){if("function"!=typeof n){const{start:m,end:i}=n;n=()=>({start:m,end:i})}S(m,n,i)}function S(m,n,i){if(i||!m.source)m.source=n();else{const{start:i,end:a}=m.source;n=()=>({start:i,end:a})}switch(m.type){case"Concatenation":m.elements.forEach((m=>S(m,n,i)));break;case"Alternation":case"Assertion":case"Expression":case"Quantifier":m.alternatives.forEach((m=>S(m,n,i)));break;case"CharacterClass":case"Unknown":break;default:throw h(m)}}function w(m,n){const i=n[`on${m.type}Enter`];switch(i&&i(m),m.type){case"Alternation":case"Assertion":case"Expression":case"Quantifier":for(const i of m.alternatives)w(i,n);break;case"Concatenation":for(const i of m.elements)w(i,n)}const a=n[`on${m.type}Leave`];a&&a(m)}class k{constructo