string-extract-class-names
Version:
Extracts CSS class/id names from a string
27 lines (25 loc) • 6.48 kB
JavaScript
/**
* @name string-extract-class-names
* @fileoverview Extracts CSS class/id names from a string
* @version 8.1.3
* @author Roy Revelt
* @license MIT
* {@link https://codsen.com/os/string-extract-class-names/}
*/
;var stringExtractClassNames=(()=>{var E=Object.create;var y=Object.defineProperty;var O=Object.getOwnPropertyDescriptor;var N=Object.getOwnPropertyNames;var R=Object.getPrototypeOf,k=Object.prototype.hasOwnProperty;var B=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),L=(e,t)=>{for(var u in t)y(e,u,{get:t[u],enumerable:!0})},v=(e,t,u,c)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of N(t))!k.call(e,i)&&i!==u&&y(e,i,{get:()=>t[i],enumerable:!(c=O(t,i))||c.enumerable});return e};var $=(e,t,u)=>(u=e!=null?E(R(e)):{},v(t||!e||!e.__esModule?y(u,"default",{value:e,enumerable:!0}):u,e)),T=e=>v(y({},"__esModule",{value:!0}),e);var w=B((J,x)=>{"use strict";x.exports=V;function h(e){return e instanceof Buffer?Buffer.from(e):new e.constructor(e.buffer.slice(),e.byteOffset,e.length)}function V(e){if(e=e||{},e.circles)return I(e);let t=new Map;if(t.set(Date,o=>new Date(o)),t.set(Map,(o,s)=>new Map(c(Array.from(o),s))),t.set(Set,(o,s)=>new Set(c(Array.from(o),s))),e.constructorHandlers)for(let o of e.constructorHandlers)t.set(o[0],o[1]);let u=null;return e.proto?p:i;function c(o,s){let n=Object.keys(o),r=new Array(n.length);for(let a=0;a<n.length;a++){let l=n[a],f=o[l];typeof f!="object"||f===null?r[l]=f:f.constructor!==Object&&(u=t.get(f.constructor))?r[l]=u(f,s):ArrayBuffer.isView(f)?r[l]=h(f):r[l]=s(f)}return r}function i(o){if(typeof o!="object"||o===null)return o;if(Array.isArray(o))return c(o,i);if(o.constructor!==Object&&(u=t.get(o.constructor)))return u(o,i);let s={};for(let n in o){if(Object.hasOwnProperty.call(o,n)===!1)continue;let r=o[n];typeof r!="object"||r===null?s[n]=r:r.constructor!==Object&&(u=t.get(r.constructor))?s[n]=u(r,i):ArrayBuffer.isView(r)?s[n]=h(r):s[n]=i(r)}return s}function p(o){if(typeof o!="object"||o===null)return o;if(Array.isArray(o))return c(o,p);if(o.constructor!==Object&&(u=t.get(o.constructor)))return u(o,p);let s={};for(let n in o){let r=o[n];typeof r!="object"||r===null?s[n]=r:r.constructor!==Object&&(u=t.get(r.constructor))?s[n]=u(r,p):ArrayBuffer.isView(r)?s[n]=h(r):s[n]=p(r)}return s}}function I(e){let t=[],u=[],c=new Map;if(c.set(Date,n=>new Date(n)),c.set(Map,(n,r)=>new Map(p(Array.from(n),r))),c.set(Set,(n,r)=>new Set(p(Array.from(n),r))),e.constructorHandlers)for(let n of e.constructorHandlers)c.set(n[0],n[1]);let i=null;return e.proto?s:o;function p(n,r){let a=Object.keys(n),l=new Array(a.length);for(let f=0;f<a.length;f++){let g=a[f],d=n[g];if(typeof d!="object"||d===null)l[g]=d;else if(d.constructor!==Object&&(i=c.get(d.constructor)))l[g]=i(d,r);else if(ArrayBuffer.isView(d))l[g]=h(d);else{let S=t.indexOf(d);S!==-1?l[g]=u[S]:l[g]=r(d)}}return l}function o(n){if(typeof n!="object"||n===null)return n;if(Array.isArray(n))return p(n,o);if(n.constructor!==Object&&(i=c.get(n.constructor)))return i(n,o);let r={};t.push(n),u.push(r);for(let a in n){if(Object.hasOwnProperty.call(n,a)===!1)continue;let l=n[a];if(typeof l!="object"||l===null)r[a]=l;else if(l.constructor!==Object&&(i=c.get(l.constructor)))r[a]=i(l,o);else if(ArrayBuffer.isView(l))r[a]=h(l);else{let f=t.indexOf(l);f!==-1?r[a]=u[f]:r[a]=o(l)}}return t.pop(),u.pop(),r}function s(n){if(typeof n!="object"||n===null)return n;if(Array.isArray(n))return p(n,s);if(n.constructor!==Object&&(i=c.get(n.constructor)))return i(n,s);let r={};t.push(n),u.push(r);for(let a in n){let l=n[a];if(typeof l!="object"||l===null)r[a]=l;else if(l.constructor!==Object&&(i=c.get(l.constructor)))r[a]=i(l,s);else if(ArrayBuffer.isView(l))r[a]=h(l);else{let f=t.indexOf(l);f!==-1?r[a]=u[f]:r[a]=s(l)}}return t.pop(),u.pop(),r}}});var _={};L(_,{extract:()=>F,version:()=>H});var j=$(w(),1);var Q=(0,j.default)();var C=$(w(),1);var Y=(0,C.default)();var b="\xA0";function M({str:e,idx:t=0,stopAtNewlines:u=!1,stopAtRawNbsp:c=!1}){if(typeof e!="string"||!e.length||((!t||typeof t!="number")&&(t=0),!e[t+1]))return null;if(e[t+1]&&(e[t+1].trim()||u&&"\n\r".includes(e[t+1])||c&&e[t+1]===b))return t+1;if(e[t+2]&&(e[t+2].trim()||u&&"\n\r".includes(e[t+2])||c&&e[t+2]===b))return t+2;for(let i=t+1,p=e.length;i<p;i++)if(e[i].trim()||u&&"\n\r".includes(e[i])||c&&e[i]===b)return i;return null}function m(e,t=0){return M({str:e,idx:t,stopAtNewlines:!1,stopAtRawNbsp:!1})}function P({str:e,idx:t,stopAtNewlines:u,stopAtRawNbsp:c}){if(typeof e!="string"||!e.length||((!t||typeof t!="number")&&(t=0),t<1))return null;if(e[~-t]&&(e[~-t].trim()||u&&"\n\r".includes(e[~-t])||c&&e[~-t]===b))return~-t;if(e[t-2]&&(e[t-2].trim()||u&&"\n\r".includes(e[t-2])||c&&e[t-2]===b))return t-2;for(let i=t;i--;)if(e[i]&&(e[i].trim()||u&&"\n\r".includes(e[i])||c&&e[i]===b))return i;return null}function A(e,t=0){return P({str:e,idx:t,stopAtNewlines:!1,stopAtRawNbsp:!1})}var D="8.1.3";var H=D;function F(e){var o;if(typeof e!="string")throw new TypeError("string-extract-class-names: [THROW_ID_01] first str should be string, not ".concat(typeof e,", currently equal to ").concat(JSON.stringify(e,null,4)));let t=".# ~\\!@$%^&*()+=,/';:\"?><[]{}|`",u;function c(s){return typeof s=="string"&&!!s.length&&(s.charCodeAt(0)>64&&s.charCodeAt(0)<91||s.charCodeAt(0)>96&&s.charCodeAt(0)<123)}let i=null,p={res:[],ranges:[]};for(let s=0,n=e.length;s<=n;s++){i!==null&&s>=i&&(!((o=e[s])!=null&&o.trim())||t.includes(e[s]))&&(s>i+1&&(p.ranges.push([i,s]),p.res.push("".concat(u||"").concat(e.slice(i,s))),u&&(u=void 0)),i=null),e[s]&&i===null&&(e[s]==="."||e[s]==="#")&&(i=s);let r=m(e,s+4);e.startsWith("class",s)&&typeof A(e,s)=="number"&&e[A(e,s)]==="["&&typeof r=="number"&&e[r]==="="&&(m(e,r)&&c(e[m(e,r)])?i=m(e,r):"'\"".includes(e[m(e,r)])&&c(e[m(e,m(e,r))])&&(i=m(e,m(e,r))),u=".");let a=m(e,s+1);e.startsWith("id",s)&&e[A(e,s)]==="["&&a!==null&&e[a]==="="&&(c(e[m(e,a)])?i=m(e,a):"'\"".includes(e[m(e,a)])&&c(e[m(e,m(e,a))])&&(i=m(e,m(e,a))),u="#")}return p.ranges.length||(p.ranges=null),p}return T(_);})();
/**
* @name codsen-utils
* @fileoverview Various utility functions
* @version 1.7.3
* @author Roy Revelt
* @license MIT
* {@link https://codsen.com/os/codsen-utils/}
*/
/**
* @name string-left-right
* @fileoverview Looks up the first non-whitespace character to the left/right of a given index
* @version 6.1.3
* @author Roy Revelt
* @license MIT
* {@link https://codsen.com/os/string-left-right/}
*/