@public-ui/components
Version:
Contains all web components that belong to KoliBri - The accessible HTML-Standard.
4 lines • 1.57 kB
JavaScript
/*!
* KoliBri - The accessible HTML-Standard
*/
;var common=require("./common-1pTy2kta.js");const headingLevelOptions=[0,1,2,3,4,5,6],READABLE_CHARS=/[a-zA-Z0-9äöüÄÖÜß]/g,ONLY_NUMBERS=/^\d+$/;function countReadableChars(e){var a;return"string"==typeof e&&(null===(a=e.match(READABLE_CHARS))||void 0===a?void 0:a.length)||0}function hasEnoughReadableChars(e,a=1){return countReadableChars(e)>=a}function containsOnlyNumbers(e){return ONLY_NUMBERS.test(e)}function getValidationOptions(e){var a;return Object.assign(Object.assign({},e),{hooks:{afterPatch:(a,t,o,n)=>{var i,l;"function"==typeof(null===(i=e.hooks)||void 0===i?void 0:i.afterPatch)&&(null===(l=e.hooks)||void 0===l||l.afterPatch(a,t,o,n)),"string"==typeof a&&!1===hasEnoughReadableChars(a,3)&&!1===containsOnlyNumbers(a)&&common.a11yHint(`The heading or label ("${a}") is inaccessible. A label should consist of at least three readable characters.`),"string"==typeof a&&a.length>80&&common.uiUxHint("A heading or label should not be longer than 80 characters.")},beforePatch:null===(a=e.hooks)||void 0===a?void 0:a.beforePatch}})}const LABEL_VALUES=new Set(["string"]),validateLabel=(e,a,t={})=>{common.watchValidator(e,"_label",e=>"string"==typeof e,LABEL_VALUES,a,getValidationOptions(t))},validateLabelWithExpertSlot=validateLabel;exports.containsOnlyNumbers=containsOnlyNumbers,exports.hasEnoughReadableChars=hasEnoughReadableChars,exports.headingLevelOptions=headingLevelOptions,exports.validateLabel=validateLabel,exports.validateLabelWithExpertSlot=validateLabelWithExpertSlot;