UNPKG

code-exercises-js

Version:

Create exercises for your students!

1 lines 30.1 kB
var t={334:t=>{function e(t,e=100,n={}){if("function"!=typeof t)throw new TypeError(`Expected the first parameter to be a function, got \`${typeof t}\`.`);if(e<0)throw new RangeError("`wait` must not be negative.");const{immediate:r}="boolean"==typeof n?{immediate:n}:n;let i,s,a,o,u;function l(){const e=i,n=s;return i=void 0,s=void 0,u=t.apply(e,n),u}function h(){const t=Date.now()-o;t<e&&t>=0?a=setTimeout(h,e-t):(a=void 0,r||(u=l()))}const c=function(...t){if(i&&this!==i&&Object.getPrototypeOf(this)===Object.getPrototypeOf(i))throw new Error("Debounced method called with different contexts of the same prototype.");i=this,s=t,o=Date.now();const n=r&&!a;return a||(a=setTimeout(h,e)),n&&(u=l()),u};return Object.defineProperty(c,"isPending",{get:()=>void 0!==a}),c.clear=()=>{a&&(clearTimeout(a),a=void 0)},c.flush=()=>{a&&c.trigger()},c.trigger=()=>{u=l(),c.clear()},c}t.exports.debounce=e,t.exports=e},267:t=>{function e(t,e,n){var r=Math.sqrt,i=Math.pow;this.x1=t,this.x2=e,this.weights=n||{},this.ksubL=this.weights.lightness||1,this.ksubC=this.weights.chroma||1,this.ksubH=this.weights.hue||1,this.deltaLPrime=e.L-t.L,this.LBar=(t.L+e.L)/2,this.C1=r(i(t.A,2)+i(t.B,2)),this.C2=r(i(e.A,2)+i(e.B,2)),this.CBar=(this.C1+this.C2)/2,this.aPrime1=t.A+t.A/2*(1-r(i(this.CBar,7)/(i(this.CBar,7)+i(25,7)))),this.aPrime2=e.A+e.A/2*(1-r(i(this.CBar,7)/(i(this.CBar,7)+i(25,7)))),this.CPrime1=r(i(this.aPrime1,2)+i(t.B,2)),this.CPrime2=r(i(this.aPrime2,2)+i(e.B,2)),this.CBarPrime=(this.CPrime1+this.CPrime2)/2,this.deltaCPrime=this.CPrime2-this.CPrime1,this.SsubL=1+.015*i(this.LBar-50,2)/r(20+i(this.LBar-50,2)),this.SsubC=1+.045*this.CBarPrime,this.hPrime1=0,this.hPrime2=0,this.deltahPrime=0,this.deltaHPrime=0,this.HBarPrime=0,this.T=0,this.SsubH=0,this.RsubT=0}e.prototype.getDeltaE=function(){var t=Math.sqrt,e=Math.sin,n=Math.pow;this.hPrime1=this.gethPrime1(),this.hPrime2=this.gethPrime2(),this.deltahPrime=this.getDeltahPrime(),this.deltaHPrime=2*t(this.CPrime1*this.CPrime2)*e(this.degreesToRadians(this.deltahPrime)/2),this.HBarPrime=this.getHBarPrime(),this.T=this.getT(),this.SsubH=1+.015*this.CBarPrime*this.T,this.RsubT=this.getRsubT();var r=this.deltaLPrime/(this.ksubL*this.SsubL),i=this.deltaCPrime/(this.ksubC*this.SsubC),s=this.deltaHPrime/(this.ksubH*this.SsubH);return t(n(r,2)+n(i,2)+n(s,2)+this.RsubT*i*s)},e.prototype.getRsubT=function(){var t=Math.sin,e=Math.sqrt,n=Math.pow,r=Math.exp;return-2*e(n(this.CBarPrime,7)/(n(this.CBarPrime,7)+n(25,7)))*t(this.degreesToRadians(60*r(-n((this.HBarPrime-275)/25,2))))},e.prototype.getT=function(){var t=Math.cos;return 1-.17*t(this.degreesToRadians(this.HBarPrime-30))+.24*t(this.degreesToRadians(2*this.HBarPrime))+.32*t(this.degreesToRadians(3*this.HBarPrime+6))-.2*t(this.degreesToRadians(4*this.HBarPrime-63))},e.prototype.getHBarPrime=function(){return(0,Math.abs)(this.hPrime1-this.hPrime2)>180?(this.hPrime1+this.hPrime2+360)/2:(this.hPrime1+this.hPrime2)/2},e.prototype.getDeltahPrime=function(){var t=Math.abs;return 0===this.C1||0===this.C2?0:t(this.hPrime1-this.hPrime2)<=180?this.hPrime2-this.hPrime1:this.hPrime2<=this.hPrime1?this.hPrime2-this.hPrime1+360:this.hPrime2-this.hPrime1-360},e.prototype.gethPrime1=function(){return this._gethPrimeFn(this.x1.B,this.aPrime1)},e.prototype.gethPrime2=function(){return this._gethPrimeFn(this.x2.B,this.aPrime2)},e.prototype._gethPrimeFn=function(t,e){var n;return 0===t&&0===e?0:(n=this.radiansToDegrees(Math.atan2(t,e)))>=0?n:n+360},e.prototype.radiansToDegrees=function(t){return t*(180/Math.PI)},e.prototype.degreesToRadians=function(t){return t*(Math.PI/180)},t.exports=e},30:t=>{function e(t,e){this.x1=t,this.x2=e}e.prototype.getDeltaE=function(){var t=this.x1,e=this.x2;return Math.sqrt(Math.pow(e.L-t.L,2)+Math.pow(e.A-t.A,2)+Math.pow(e.B-t.B,2))},t.exports=e},794:t=>{function e(t,e,n){this.x1=t,this.x2=e,this.weights=n||{},this.weights.lightness=this.weights.lightness||1,this.weights.chroma=this.weights.chroma||1,this.weights.hue=this.weights.hue||1,1===this.weights.lightness?(this.weights.K1=.045,this.weights.K2=.015):(this.weights.K1=.048,this.weights.K2=.014)}e.prototype.getDeltaE=function(){var t=this.x1,e=this.x2,n=Math.sqrt,r=Math.pow;return n(r(this.calculateL(t,e),2)+r(this.calculateA(t,e),2)+r(this.calculateB(t,e),2))},e.prototype.calculateL=function(t,e){return(t.L-e.L)/this.weights.lightness},e.prototype.calculateA=function(t,e){var n=Math.sqrt,r=Math.pow,i=n(r(t.A,2)+r(t.B,2)),s=i-n(r(e.A,2)+r(e.B,2)),a=1+this.weights.K1*i;return s/(this.weights.chroma*a)},e.prototype.calculateB=function(t,e){var n=Math.sqrt,r=Math.pow,i=n(r(t.A,2)+r(t.B,2))-n(r(e.A,2)+r(e.B,2)),s=t.A-e.A,a=t.B-e.B,o=n(r(s,2)+r(a,2)-r(i,2))||0,u=n(r(t.A,2)+r(t.B,2));return o/(1+this.weights.K2*u)},t.exports=e},54:(t,e,n)=>{var r=n(30),i=n(794),s=n(267);function a(){}a.prototype.getDeltaE76=function(t,e){return new r(t,e).getDeltaE()},a.prototype.getDeltaE94=function(t,e){return new i(t,e).getDeltaE()},a.prototype.getDeltaE00=function(t,e){return new s(t,e).getDeltaE()},t.exports=new a},484:(t,e,n)=>{Object.defineProperty(e,"__esModule",{value:!0});var r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},i=function(t,e){if(Array.isArray(t))return t;if(Symbol.iterator in Object(t))return function(t,e){var n=[],r=!0,i=!1,s=void 0;try{for(var a,o=t[Symbol.iterator]();!(r=(a=o.next()).done)&&(n.push(a.value),!e||n.length!==e);r=!0);}catch(t){i=!0,s=t}finally{try{!r&&o.return&&o.return()}finally{if(i)throw s}}return n}(t,e);throw new TypeError("Invalid attempt to destructure non-iterable instance")};function s(t,e){t.forEach((function(t){var n=!0;e(t,(function(){return n=!1})),t.childTags&&n&&s(t.childTags,e)}))}function a(t,e,n){for(;t.parent;){if(n(t=t.parent))return t;if(t===e)break}return null}e.default=function(t,e){if(n.g.document)return!1;n.g.document=e.context||function(){for(var e=t;e.parent;)e=e.parent;return e}();var o=Object.getPrototypeOf(n.g.document);return Object.getOwnPropertyDescriptor(o,"childTags")||Object.defineProperty(o,"childTags",{enumerable:!0,get:function(){return this.children.filter((function(t){return"tag"===t.type||"script"===t.type||"style"===t.type}))}}),Object.getOwnPropertyDescriptor(o,"attributes")||Object.defineProperty(o,"attributes",{enumerable:!0,get:function(){var t=this.attribs,e=Object.keys(t),n=e.reduce((function(e,n,r){return e[r]={name:n,value:t[n]},e}),{});return Object.defineProperty(n,"length",{enumerable:!1,configurable:!1,value:e.length}),n}}),o.getAttribute||(o.getAttribute=function(t){return this.attribs[t]||null}),o.getElementsByTagName||(o.getElementsByTagName=function(t){var e=[];return s(this.childTags,(function(n){n.name!==t&&"*"!==t||e.push(n)})),e}),o.getElementsByClassName||(o.getElementsByClassName=function(t){var e=t.trim().replace(/\s+/g," ").split(" "),n=[];return s([this],(function(t){var r=t.attribs.class;r&&e.every((function(t){return r.indexOf(t)>-1}))&&n.push(t)})),n}),o.querySelectorAll||(o.querySelectorAll=function(t){var e=this,n=function(t){return t.split(" ").reverse().map((function(t,e){var n=0===e,o=t.split(":"),u=i(o,2),l=u[0],h=u[1],c=null,d=null;if(function(){switch(!0){case/>/.test(l):d=function(t){return function(e){return e(t.parent)&&t.parent}};break;case/^\./.test(l):var t=l.substr(1).split(".");c=function(e){var n=e.attribs.class;return n&&t.every((function(t){return n.indexOf(t)>-1}))},d=function(e,r){return n?e.getElementsByClassName(t.join(" ")):"function"==typeof e?e(c):a(e,r,c)};break;case/^\[/.test(l):var e=l.replace(/\[|\]|"/g,"").split("="),o=i(e,2),u=o[0],h=o[1];c=function(t){return!(!(Object.keys(t.attribs).indexOf(u)>-1)||h&&t.attribs[u]!==h)},d=function(t,e){if(n){var i=(o=[],s([t],(function(t){c(t)&&o.push(t)})),{v:o});if("object"===(void 0===i?"undefined":r(i)))return i.v}var o;return"function"==typeof t?t(c):a(t,e,c)};break;case/^#/.test(l):var f=l.substr(1);c=function(t){return t.attribs.id===f},d=function(t,e){if(n){var i=(o=[],s([t],(function(t,e){c(t)&&(o.push(t),e())})),{v:o});if("object"===(void 0===i?"undefined":r(i)))return i.v}var o;return"function"==typeof t?t(c):a(t,e,c)};break;case/\*/.test(l):c=function(t){return!0},d=function(t,e){if(n){var i=(o=[],s([t],(function(t){return o.push(t)})),{v:o});if("object"===(void 0===i?"undefined":r(i)))return i.v}var o;return"function"==typeof t?t(c):a(t,e,c)};break;default:c=function(t){return t.name===l},d=function(t,e){if(n){var i=(o=[],s([t],(function(t){c(t)&&o.push(t)})),{v:o});if("object"===(void 0===i?"undefined":r(i)))return i.v}var o;return"function"==typeof t?t(c):a(t,e,c)}}}(),!h)return d;var f=h.match(/-(child|type)\((\d+)\)$/),g=f[1],m=parseInt(f[2],10)-1,p=function(t){if(t){var e=t.parent.childTags;if("type"===g&&(e=e.filter(c)),e.findIndex((function(e){return e===t}))===m)return!0}return!1};return function(t){var e=d(t);return n?e.reduce((function(t,e){return p(e)&&t.push(e),t}),[]):p(e)&&e}}))}(t=t.replace(/(>)(\S)/g,"$1 $2").trim()),o=n.shift(),u=n.length;return o(this).filter((function(t){for(var r=0;r<u;){if(!(t=n[r](t,e)))return!1;r+=1}return!0}))}),o.contains||(o.contains=function(t){var e=!1;return s([this],(function(n,r){n===t&&(e=!0,r())})),e}),!0},t.exports=e.default},611:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.getCommonAncestor=function(t){var e=(arguments.length>1&&void 0!==arguments[1]?arguments[1]:{}).root,n=void 0===e?document:e,r=[];t.forEach((function(t,e){for(var i=[];t!==n;)t=t.parentNode,i.unshift(t);r[e]=i})),r.sort((function(t,e){return t.length-e.length}));for(var i=r.shift(),s=null,a=function(){var t=i[o];if(r.some((function(e){return!e.some((function(e){return e===t}))})))return"break";s=t},o=0,u=i.length;o<u&&"break"!==a();o++);return s},e.getCommonProperties=function(t){var e={classes:[],attributes:{},tag:null};return t.forEach((function(t){var n,r,i,s,a=e.classes,o=e.attributes,u=e.tag;if(void 0!==a){var l=t.getAttribute("class");l?(l=l.trim().split(" "),a.length?(a=a.filter((function(t){return l.some((function(e){return e===t}))}))).length?e.classes=a:delete e.classes:e.classes=l):delete e.classes}if(void 0!==o&&(n=t.attributes,r=Object.keys(n).reduce((function(t,e){var r=n[e],i=r.name;return r&&"class"!==i&&(t[i]=r.value),t}),{}),i=Object.keys(r),s=Object.keys(o),i.length?s.length?(o=s.reduce((function(t,e){var n=o[e];return n===r[e]&&(t[e]=n),t}),{}),Object.keys(o).length?e.attributes=o:delete e.attributes):e.attributes=r:delete e.attributes),void 0!==u){var h=t.tagName.toLowerCase();u?h!==u&&delete e.tag:e.tag=h}})),e}},296:(t,e,n)=>{e.Lt=void 0;var r=s(n(126)),i=s(n(433));!function(t){if(t&&t.__esModule)return t;var e={};if(null!=t)for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n]);e.default=t}(n(611));function s(t){return t&&t.__esModule?t:{default:t}}e.Lt=r.default,i.default,r.default},409:(t,e,n)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.default=function(t,e){var n,i=e.root,a=void 0===i?document:i,u=e.skip,c=void 0===u?null:u,d=e.priority,f=void 0===d?["id","class","href","src"]:d,g=e.ignore,m=void 0===g?{}:g,p=[],v=t,y=p.length,b=!1,w=c&&(Array.isArray(c)?c:[c]).map((function(t){return"function"!=typeof t?function(e){return e===t}:t})),_=function(t){return c&&w.some((function(e){return e(t)}))};for(Object.keys(m).forEach((function(t){"class"===t&&(b=!0);var e=m[t];"function"!=typeof e&&("number"==typeof e&&(e=e.toString()),"string"==typeof e&&(e=new RegExp((0,r.escapeValue)(e).replace(/\\/g,"\\\\"))),"boolean"==typeof e&&(e=e?/(?:)/:/.^/),m[t]=function(t,n){return e.test(n)})})),b&&(n=m.attribute,m.attribute=function(t,e,r){return m.class(e)||n&&n(t,e,r)});v!==a;){if(!0!==_(v)){if(s(f,v,m,p,a))break;if(o(v,m,p,a))break;s(f,v,m,p),p.length===y&&o(v,m,p),p.length===y&&l(f,v,m,p)}v=v.parentNode,y=p.length}if(v===a){var P=h(f,v,m);p.unshift(P)}return p.join(" ")};var r=n(692),i={attribute:function(t){return["style","data-reactid","data-react-checksum"].indexOf(t)>-1}};function s(t,e,n,r){var i=arguments.length>4&&void 0!==arguments[4]?arguments[4]:e.parentNode,s=a(t,e,n);return!(!s||1!==i.querySelectorAll(s).length)&&(r.unshift(s),!0)}function a(t,e,n){for(var s=e.attributes,a=Object.keys(s).sort((function(e,n){var r=t.indexOf(s[e].name),i=t.indexOf(s[n].name);return-1===i?-1===r?0:-1:r-i})),o=0,u=a.length;o<u;o++){var l=a[o],h=s[l],d=h.name,f=(0,r.escapeValue)(h.value);if(!c(n[d]||n.attribute,d,f,i[d]||i.attribute)){var g="["+d+'="'+f+'"]';return!1===/\b\d/.test(f)&&("id"===d&&(g="#"+f),"class"===d&&(g="."+f.trim().replace(/\s+/g,"."))),g}}return null}function o(t,e,n){var r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:t.parentNode,i=u(t,e);return!(!i||1!==r.getElementsByTagName(i).length)&&(n.unshift(i),!0)}function u(t,e){var n=t.tagName.toLowerCase();return c(e.tag,null,n)?null:n}function l(t,e,n,r){for(var i=e.parentNode,s=i.childTags||i.children,a=0,o=s.length;a<o;a++){var u=s[a];if(u===e){var l=h(t,u,n);if(!l)return console.warn("\n Element couldn't be matched through strict ignore pattern!\n ",u,n,l);var c="> "+l+":nth-child("+(a+1)+")";return r.unshift(c),!0}}return!1}function h(t,e,n){var r=a(t,e,n);return r||(r=u(e,n)),r}function c(t,e,n,r){if(!n)return!0;var i=t||r;return!!i&&i(e,n,r)}t.exports=e.default},433:(t,e,n)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.default=function(t,e){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};if(Array.isArray(e)||(e=e.length?(0,s.convertNodeList)(e):[e]),!e.length||e.some((function(t){return 1!==t.nodeType})))throw new Error('Invalid input - to compare HTMLElements its necessary to provide a reference of the selected node(s)! (missing "elements")');var o=(0,i.default)(e[0],r),u=t.replace(/> /g,">").split(/\s+(?=(?:(?:[^"]*"){2})*[^"]*$)/);if(u.length<2)return a("",t,"",e);for(var l=[u.pop()];u.length>1;){var h=u.pop(),c=u.join(" "),d=l.join(" "),f=c+" "+d;document.querySelectorAll(f).length!==e.length&&l.unshift(a(c,h,d,e))}return l.unshift(u[0]),(u=l)[0]=a("",u[0],u.slice(1).join(" "),e),u[u.length-1]=a(u.slice(0,-1).join(" "),u[u.length-1],"",e),o&&delete n.g.document,u.join(" ").replace(/>/g,"> ").trim()};var r,i=(r=n(484))&&r.__esModule?r:{default:r},s=n(692);function a(t,e,n,r){if(t.length&&(t+=" "),n.length&&(n=" "+n),/\[*\]/.test(e)){var i=e.replace(/=.*$/,"]"),s=""+t+i+n;if(o(document.querySelectorAll(s),r))e=i;else for(var a=document.querySelectorAll(""+t+i),u=function(){var i=a[l];if(r.some((function(t){return i.contains(t)}))){var u=i.tagName.toLowerCase();return s=""+t+u+n,o(document.querySelectorAll(s),r)&&(e=u),"break"}},l=0,h=a.length;l<h&&"break"!==u();l++);}if(/>/.test(e)){var c=e.replace(/>/,"");s=""+t+c+n,o(document.querySelectorAll(s),r)&&(e=c)}if(/:nth-child/.test(e)){var d=e.replace(/nth-child/g,"nth-of-type");s=""+t+d+n,o(document.querySelectorAll(s),r)&&(e=d)}if(/\.\S+\.\S+/.test(e)){for(var f=e.trim().split(".").slice(1).map((function(t){return"."+t})).sort((function(t,e){return t.length-e.length}));f.length;){var g=e.replace(f.shift(),"").trim();if(!(s=(""+t+g+n).trim()).length||">"===s.charAt(0)||">"===s.charAt(s.length-1))break;o(document.querySelectorAll(s),r)&&(e=g)}if((f=e&&e.match(/\./g))&&f.length>2){var m=document.querySelectorAll(""+t+e),p=function(){var i=m[l];if(r.some((function(t){return i.contains(t)}))){var a=i.tagName.toLowerCase();return s=""+t+a+n,o(document.querySelectorAll(s),r)&&(e=a),"break"}};for(l=0,h=m.length;l<h&&"break"!==p();l++);}}return e}function o(t,e){var n=t.length;return n===e.length&&e.every((function(e){for(var r=0;r<n;r++)if(t[r]===e)return!0;return!1}))}t.exports=e.default},126:(t,e,n)=>{Object.defineProperty(e,"__esModule",{value:!0});var r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t};e.getSingleSelector=h,e.getMultiSelector=c,e.default=function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return t.length&&!t.name?c(t,e):h(t,e)};var i=l(n(484)),s=l(n(409)),a=l(n(433)),o=n(692),u=n(611);function l(t){return t&&t.__esModule?t:{default:t}}function h(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(3===t.nodeType&&(t=t.parentNode),1!==t.nodeType)throw new Error('Invalid input - only HTMLElements or representations of them are supported! (not "'+(void 0===t?"undefined":r(t))+'")');var o=(0,i.default)(t,e),u=(0,s.default)(t,e),l=(0,a.default)(u,t,e);return o&&delete n.g.document,l}function c(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(Array.isArray(t)||(t=(0,o.convertNodeList)(t)),t.some((function(t){return 1!==t.nodeType})))throw new Error("Invalid input - only an Array of HTMLElements or representations of them is supported!");var r=(0,i.default)(t[0],e),s=h((0,u.getCommonAncestor)(t,e),e),l=function(t){var e=(0,u.getCommonProperties)(t),n=e.classes,r=e.attributes,i=e.tag,s=[];if(i&&s.push(i),n){var a=n.map((function(t){return"."+t})).join("");s.push(a)}if(r){var o=Object.keys(r).reduce((function(t,e){return t.push("["+e+'="'+r[e]+'"]'),t}),[]).join("");s.push(o)}return s.length,[s.join("")]}(t),c=l[0],d=(0,a.default)(s+" "+c,t,e),f=(0,o.convertNodeList)(document.querySelectorAll(d));return t.every((function(t){return f.some((function(e){return e===t}))}))?(r&&delete n.g.document,d):console.warn("\n The selected elements can't be efficiently mapped.\n Its probably best to use multiple single selectors instead!\n ",t)}},692:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.convertNodeList=function(t){for(var e=t.length,n=new Array(e),r=0;r<e;r++)n[r]=t[r];return n},e.escapeValue=function(t){return t&&t.replace(/['"`\\/:\?&!#$%^()[\]{|}*+;,.<=>@~]/g,"\\$&").replace(/\n/g,"A")}}},e={};function n(r){var i=e[r];if(void 0!==i)return i.exports;var s=e[r]={exports:{}};return t[r](s,s.exports,n),s.exports}n.d=(t,e)=>{for(var r in e)n.o(e,r)&&!n.o(t,r)&&Object.defineProperty(t,r,{enumerable:!0,get:e[r]})},n.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(t){if("object"==typeof window)return window}}(),n.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e);var r={};n.d(r,{BX:()=>l,Gj:()=>i,GX:()=>u,Jh:()=>h,FR:()=>p,PZ:()=>E,Ni:()=>b,dT:()=>P,TY:()=>f,OH:()=>s,nA:()=>a,XK:()=>d});class i{constructor(t,e){this.method=t,this.message=e}}class s{constructor(){this._stopOnFail=!1,this._negateNext=!1,this.id=crypto.randomUUID()}get shouldStopOnFail(){return this._stopOnFail}get not(){return this._negateNext=!0,this}stopOnFail(t){return this._stopOnFail=t,this}}class a{get isValid(){return 0==this.getInvalidResults().length}constructor(t,e){this.id=t,this._results=null!=e?e:[]}get results(){return this._results}getInvalidResults(){return this._results.filter((t=>!t.isValid))}getValidResults(){return this._results.filter((t=>t.isValid))}getInvalidMessages(){return this._results.filter((t=>!t.isValid)).map((t=>t.message))}getValidMessages(){return this._results.filter((t=>t.isValid)).map((t=>t.message))}getMessages(){return this._results.map((t=>t.message))}}class o{get isValid(){return"valid"===this.status}constructor(t,e="unknown"){this.message=t,this.status=e}}class u extends s{constructor(){super(...arguments),this._rules=[]}get rules(){return this._rules}validate(t){const e=[];let n=!0;for(let r=0;r<this._rules.length;++r){const i=this._rules[r];if(n){const r=i.method(t),s=new o(i.message,r?"valid":"invalid");e.push(s),!r&&this.shouldStopOnFail&&(n=!1)}else{const t=new o(i.message);e.push(t)}}return new a(this.id,e)}lambda(t,e){if(this._negateNext){this._negateNext=!1;const n=e=>!t(e);this._rules.push(new i(n,e))}else this._rules.push(new i(t,e));return this}required(t){return this.lambda((t=>t.length>0),null!=t?t:this._negateNext?"Field should be empty":"Field is required")}equals(t,e){return this.lambda((e=>e===t),null!=e?e:this._negateNext?`Field must not equal '${t}'.`:`Field must equal '${t}'.`)}startsWith(t,e){return this.lambda((e=>e.startsWith(t)),null!=e?e:this._negateNext?`Field must not start with '${t}'.`:`Field must start with '${t}'.`)}endsWith(t,e){return this.lambda((e=>e.endsWith(t)),null!=e?e:this._negateNext?`Field must not end with '${t}'.`:`Field must end with '${t}'.`)}equalsRegex(t,e){return this.lambda((e=>t.test(e)),null!=e?e:this._negateNext?`Field must not match the pattern '${t.toString()}'.`:`Field must match the pattern '${t.toString()}'.`)}}class l{addValidationRule(){const t=new u;return this._ruleSets.push(t),t}constructor(t,e=!1){this._ruleSets=[],this.range=t,this.allowMultiline=e,this.id=crypto.randomUUID()}validate(t){const e=[];for(const n of this._ruleSets){const r=n.validate(t);e.push(r)}return e}}class h{constructor(){this.handlers=[]}on(t){this.handlers.push(t)}off(t){this.handlers=this.handlers.filter((e=>e!==t))}trigger(t){this.handlers.slice(0).forEach((e=>e(t)))}expose(){return this}}var c=n(334);class d{constructor(t,e){this.content=t,this.rangeValues=e}}class f{get _model(){const t=this._editorInstance.getModel();if(null==t)throw"missing moddel";return t}get content(){return this._model.getValue()}get editorInstance(){return this._editorInstance}get rangeValues(){let t={};return this._rangeRestrictions.length>0&&(t=this._model.getValueInEditableRanges()),t}constructor(t,e,n){this._rangeRestrictions=[],this.restrictions=[],this._previousRestrictionLength=0,this.onChangeContext=new h;const r=Object.assign({value:e},n);this._editorInstance=monaco.editor.create(t,r),this._constrainedInstance=constrainedEditor(monaco),this._constrainedInstance.initializeIn(this._editorInstance);const i=c((()=>{this.onChangeContext.trigger(new d(this.content,this.rangeValues))}),200);this._model.onDidChangeContent(i)}changeRanges(){this._rangeRestrictions.length!==this._previousRestrictionLength&&(this._previousRestrictionLength>1&&this._constrainedInstance.removeRestrictionsIn(this._model),this._constrainedInstance.addRestrictionsTo(this._model,this._rangeRestrictions),this._previousRestrictionLength=this._rangeRestrictions.length)}setRanges(t){this._rangeRestrictions=t,this.changeRanges()}clearRanges(){this._rangeRestrictions.length=0,this.changeRanges()}}var g=n(296);class m{constructor(t){this._validationResultGroups=t}get valid(){return 0==this.getInvalidResults().length}get results(){return this._validationResultGroups.map((t=>t.results)).flat()}get resultGroups(){return this._validationResultGroups}getInvalidResults(){return this.results.filter((t=>!t.isValid))}getValidResults(){return this.results.filter((t=>t.isValid))}getInvalidMessages(){return this.results.filter((t=>!t.isValid)).map((t=>t.message))}getValidMessages(){return this.results.filter((t=>t.isValid)).map((t=>t.message))}getMessages(){return this.results.map((t=>t.message))}}class p{constructor(t,e,n){this.onValidate=new h,this.id=(0,g.Lt)(t),this._editableFields=[],this._monacoEditorInstance=new f(t,e,Object.assign({language:"html"},n)),this._monacoEditorInstance.onChangeContext.on((()=>{this.validate()}))}get content(){return this._monacoEditorInstance.content}get monacoEditorInstance(){return this._monacoEditorInstance.editorInstance}setEditableFields(t){this._editableFields=t,this.editableFieldsChanged()}clearEditableFields(){this._editableFields.length=0,this.editableFieldsChanged()}validate(){return t=this,e=void 0,r=function*(){const t=this._monacoEditorInstance.rangeValues,e=this._editableFields.map((e=>{const n=t[e.id];if(null==n)throw"Unexpected missing value in ranges!";return e.validate(n)})).concat(yield this.validateExtend()).flat(),n=new m(e);return this.onValidate.trigger(n),n},new((n=void 0)||(n=Promise))((function(i,s){function a(t){try{u(r.next(t))}catch(t){s(t)}}function o(t){try{u(r.throw(t))}catch(t){s(t)}}function u(t){var e;t.done?i(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(a,o)}u((r=r.apply(t,e||[])).next())}));var t,e,n,r}editableFieldsChanged(){const t=[];this._editableFields.forEach((e=>{t.push({range:e.range,allowMultiline:e.allowMultiline,label:e.id})})),this._monacoEditorInstance.setRanges(t)}}function v(t){let e;if(t.startsWith("#")){let n=t.slice(1);if(3===n.length&&(n=n.split("").map((t=>t+t)).join("")),6!==n.length)throw new Error("Invalid hex color format");e=[parseInt(n.slice(0,2),16),parseInt(n.slice(2,4),16),parseInt(n.slice(4,6),16)]}else{if(!t.startsWith("rgb"))throw new Error("Unsupported color format");{const n=t.match(/rgba?\((\d+),\s*(\d+),\s*(\d+)/);if(!n)throw new Error("Invalid rgb/rgba format");e=[parseInt(n[1],10),parseInt(n[2],10),parseInt(n[3],10)]}}e=[y(e[0],0,255),y(e[1],0,255),y(e[2],0,255)];const[n,r,i]=function(t,e,n){e/=255,n/=255;return[100*(.4124564*(t=(t/=255)>.04045?Math.pow((t+.055)/1.055,2.4):t/12.92)+.3575761*(e=e>.04045?Math.pow((e+.055)/1.055,2.4):e/12.92)+.1804375*(n=n>.04045?Math.pow((n+.055)/1.055,2.4):n/12.92)),100*(.2126729*t+.7151522*e+.072175*n),100*(.0193339*t+.119192*e+.9503041*n)]}(e[0],e[1],e[2]);return function(t,e,n){e/=100,n/=108.883;const r=t=>t>.008856?Math.cbrt(t):7.787*t+16/116,i=r(t/=95.047),s=r(e);return{L:116*s-16,A:500*(i-s),B:200*(s-r(n))}}(n,r,i)}function y(t,e,n){return Math.max(e,Math.min(n,t))}class b{constructor(t,e){this.method=t,this.message=e}}var w=n(54),_=function(t,e,n,r){return new(n||(n=Promise))((function(i,s){function a(t){try{u(r.next(t))}catch(t){s(t)}}function o(t){try{u(r.throw(t))}catch(t){s(t)}}function u(t){var e;t.done?i(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(a,o)}u((r=r.apply(t,e||[])).next())}))};class P extends s{constructor(){super(...arguments),this._rules=[]}get rules(){return this._rules}validate(t,e){return _(this,void 0,void 0,(function*(){const n=[];let r=!0;for(let i=0;i<this._rules.length;++i){const s=this._rules[i];if(r){const i=yield s.method(t,e),a=new o(s.message,i?"valid":"invalid");n.push(a),!i&&this.shouldStopOnFail&&(r=!1)}else{const t=new o(s.message);n.push(t)}}return new a(this.id,n)}))}lambda(t,e){if(this._negateNext){this._negateNext=!1;const n=(e,n)=>_(this,void 0,void 0,(function*(){return!(yield t(e,n))}));this._rules.push(new b(n,e))}else this._rules.push(new b(t,e));return this}required(t){return this.lambda((t=>t.length>0),null!=t?t:this._negateNext?"String should be empty":"String field is required")}isValidHTML(t){return this.lambda((t=>_(this,void 0,void 0,(function*(){let e={messages:Array};try{const n=yield fetch("https://validator.w3.org/nu/?out=json&level=error",{method:"POST",headers:{"Content-Type":"text/html; charset=UTF-8"},body:t});e=yield n.json()}catch(t){console.error("Error:",t)}return 0==e.messages.length}))),null!=t?t:this._negateNext?"Valid HTML":"Invalid HTML")}stringEquals(t,e){return this.lambda((e=>e===t),null!=e?e:this._negateNext?`String field must not equal '${t}'.`:`String field must equal '${t}'.`)}contentIncludes(t,e){return this.lambda((e=>e.includes(t)),null!=e?e:this._negateNext?`String field must not include '${t}'.`:`String field must include '${t}'.`)}iframeContains(t,e){return this.lambda(((e,n)=>null!==n.querySelector(t)),null!=e?e:this._negateNext?`IFrame must not contain an element matching '${t}'.`:`IFrame must contain an element matching '${t}'.`)}elementHasAttributeColor(t,e,n,r=50,i){return this.lambda(((i,s)=>{const a=v(n),o=s.querySelector(t);if(null==o)return!1;const u=window.getComputedStyle(o).getPropertyValue(e);if(""==u)return!1;const l=v(u);return(0,w.getDeltaE00)(a,l)<=r}),null!=i?i:this._negateNext?`Element '${t}' exists, and has property '${e}' and color '${n}'.`:`Element '${t}' is missig, has no property '${e}' or does not have color '${n}'.`)}elementIncludesText(t,e,n){return this.lambda(((n,r)=>{const i=r.querySelector(t);return null!=i&&i.innerText.toLowerCase().includes(e.toLowerCase())}),null!=n?n:this._negateNext?`Element '${t}' exists and text matches '${e}'.`:`Element '${t}' is missig or text does not match '${e}'.`)}elementTextMatchesRegex(t,e,n){return this.lambda(((n,r)=>{const i=r.querySelector(t);return null!=i&&e.test(i.innerText)}),null!=n?n:this._negateNext?`Element '${t}' exists and text matches '${e}'.`:`Element '${t}' is missig or text does not match '${e}'.`)}stringMatchesRegex(t,e){return this.lambda((e=>t.test(e)),null!=e?e:this._negateNext?`String matches the pattern '${t}'.`:`String does not match the pattern '${t}'.`)}}var x=function(t,e,n,r){return new(n||(n=Promise))((function(i,s){function a(t){try{u(r.next(t))}catch(t){s(t)}}function o(t){try{u(r.throw(t))}catch(t){s(t)}}function u(t){var e;t.done?i(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(a,o)}u((r=r.apply(t,e||[])).next())}))};class E extends p{constructor(t,e,n,r){if(super(t,e,r),this._ruleSets=[],null==n){const t=document.createElement("iframe");t.setAttribute("style","display: none"),document.body.appendChild(t),this.iframe=t}else this.iframe=n;this._monacoEditorInstance.onChangeContext.on((t=>{this.renderIframe()})),this.renderIframe()}addValidationRule(){const t=new P;return this._ruleSets.push(t),t}validateExtend(){return x(this,void 0,void 0,(function*(){this.renderIframe();const t=this.iframe.contentDocument;if(null==t)throw"contendDocument was null!";const e=[];for(const n of this._ruleSets){const r=yield n.validate(this.content,t);e.push(r)}return e}))}validateRule(t){return x(this,void 0,void 0,(function*(){this.renderIframe();const e=this.iframe.contentDocument;if(null==e)throw"contendDocument was null!";return yield t.method(this.content,e)}))}renderIframe(){if(null==this.iframe.srcdoc)throw"iframe was null!";const t=this.iframe.contentDocument;t.open(),t.write(this.content),t.close()}}var S=r.BX,C=r.Gj,M=r.GX,T=r.Jh,I=r.FR,R=r.PZ,A=r.Ni,O=r.dT,j=r.TY,B=r.OH,L=r.nA,N=r.XK;export{S as EditableField,C as EditableFieldValidationRule,M as EditableFieldValidationRuleSet,T as Event,I as Exercise,R as HtmlExcercise,A as HtmlValidationRule,O as HtmlValidationRuleSet,j as MonacoEditor,B as Validation,L as ValidationResult,N as onChangeContextData};