UNPKG

@public-ui/components

Version:

Contains all web components that belong to KoliBri - The accessible HTML-Standard.

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