@leemeyer/nth-letter 1.0.2 → 1.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/nth-letter.es.js +5 -2
- package/dist/nth-letter.umd.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -39,7 +39,7 @@ import nthLetter from '@leemeyer/nth-letter';
|
|
|
39
39
|
|
|
40
40
|
## How it Works
|
|
41
41
|
|
|
42
|
-
The library parses your CSS for `::nth-letter()` selectors, rewrites them to use shadow DOM and CSS parts, and applies the styles to individual characters using
|
|
42
|
+
The library parses your CSS for `::nth-letter()` selectors, rewrites them to use shadow DOM and CSS parts, and applies the styles to individual characters using the split-text library.
|
|
43
43
|
|
|
44
44
|
## Browser Support
|
|
45
45
|
|
package/dist/nth-letter.es.js
CHANGED
|
@@ -184,8 +184,11 @@ var p = /* @__PURE__ */ c((/* @__PURE__ */ o(((e, t) => {
|
|
|
184
184
|
})))(), 1);
|
|
185
185
|
u({ onComplete(e, t, n) {
|
|
186
186
|
n.forEach((e) => e.remove());
|
|
187
|
-
let r = /* @__PURE__ */ new Set(), i = /* @__PURE__ */ new Set(), a =
|
|
188
|
-
|
|
187
|
+
let r = /* @__PURE__ */ new Set(), i = /* @__PURE__ */ new Set(), a = "";
|
|
188
|
+
t.forEach((e) => {
|
|
189
|
+
let t = e.selector, n = e.style;
|
|
190
|
+
t.includes("::nth-letter") && (t = t.replace(/([^,{]+?)::?nth-letter\s*\(([^)]*)\)/gi, (e, t, n) => (t = t.trim(), r.add(t), i.add(n), `${t}::part(nth-child(${CSS.escape(n)}))`))), a += `${t} { ${n} }\n`;
|
|
191
|
+
}), document.head.insertAdjacentHTML("beforeend", `<style>${a}</style>`), r.forEach((e) => {
|
|
189
192
|
document.querySelectorAll(e).forEach((e) => {
|
|
190
193
|
if (e.shadowRoot) return;
|
|
191
194
|
let t = e.attachShadow({ mode: "closed" }), n = document.createElement("span");
|
package/dist/nth-letter.umd.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(e){typeof define==`function`&&define.amd?define([],e):e()})(function(){var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),s=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},c=(n,r,a)=>(a=n==null?{}:e(i(n)),s(r||!n||!n.__esModule?t(a,`default`,{value:n,enumerable:!0}):a,n));function l(e){var t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},n={mimeType:t.mimeType||null,onBeforeSend:t.onBeforeSend||Function.prototype,onSuccess:t.onSuccess||Function.prototype,onError:t.onError||Function.prototype,onComplete:t.onComplete||Function.prototype},r=Array.isArray(e)?e:[e],i=Array.apply(null,Array(r.length)).map((function(e){return null}));function a(e){var t=typeof e==`string`,n=t&&e.trim().charAt(0)===`<`;return t&&!n}function o(e,t){n.onError(e,r[t],t)}function s(e,t){var a=n.onSuccess(e,r[t],t);e=a===!1?``:a||e,i[t]=e,i.indexOf(null)===-1&&n.onComplete(i)}var c=document.createElement(`a`);r.forEach((function(e,t){if(c.setAttribute(`href`,e),c.href=String(c.href),document.all&&!window.atob&&c.host.split(`:`)[0]!==location.host.split(`:`)[0])if(c.protocol===location.protocol){var r=new XDomainRequest;r.open(`GET`,e),r.timeout=0,r.onprogress=Function.prototype,r.ontimeout=Function.prototype,r.onload=function(){var e=r.responseText;a(e)?s(e,t):o(r,t)},r.onerror=function(e){o(r,t)},setTimeout((function(){r.send()}),0)}else console.warn(`Internet Explorer 9 Cross-Origin (CORS) requests must use the same protocol (${e})`),o(null,t);else{var i=new XMLHttpRequest;i.open(`GET`,e),n.mimeType&&i.overrideMimeType&&i.overrideMimeType(n.mimeType),n.onBeforeSend(i,e,t),i.onreadystatechange=function(){if(i.readyState===4){var e=i.responseText;i.status<400&&a(e)||i.status===0&&a(e)?s(e,t):o(i,t)}},i.send()}}))}function u(e){var t={cssComments:/\/\*[\s\S]+?\*\//g,cssImports:/(?:@import\s*)(?:url\(\s*)?(?:['"])([^'"]*)(?:['"])(?:\s*\))?(?:[^;]*;)/g},n={rootElement:e.rootElement||document,include:e.include||`style,link[rel="stylesheet"]`,exclude:e.exclude||null,filter:e.filter||null,skipDisabled:e.skipDisabled!==!1,useCSSOM:e.useCSSOM||!1,onBeforeSend:e.onBeforeSend||Function.prototype,onSuccess:e.onSuccess||Function.prototype,onError:e.onError||Function.prototype,onComplete:e.onComplete||Function.prototype},r=Array.apply(null,n.rootElement.querySelectorAll(n.include)).filter((function(e){return!f(e,n.exclude)})),i=Array.apply(null,Array(r.length)).map((function(e){return null}));function a(){if(i.indexOf(null)===-1){i.reduce((function(e,t,n){return t===``&&e.push(n),e}),[]).reverse().forEach((function(e){return[r,i].forEach((function(t){return t.splice(e,1)}))}));var e=i.join(``);n.onComplete(e,i,r)}}function o(e,t,r,o){var s=n.onSuccess(e,r,o);e=s!==void 0&&!s?``:s||e,c(e,r,o,(function(e,o){i[t]===null&&(o.forEach((function(e){return n.onError(e.xhr,r,e.url)})),!n.filter||n.filter.test(e)?i[t]=e:i[t]=``,a())}))}function s(e,n){var r=arguments.length>2&&arguments[2]!==void 0?arguments[2]:[],i={};return i.rules=(e.replace(t.cssComments,``).match(t.cssImports)||[]).filter((function(e){return r.indexOf(e)===-1})),i.urls=i.rules.map((function(e){return e.replace(t.cssImports,`$1`)})),i.absoluteUrls=i.urls.map((function(e){return d(e,n)})),i.absoluteRules=i.rules.map((function(e,t){var r=i.urls[t],a=d(i.absoluteUrls[t],n);return e.replace(r,a)})),i}function c(e,t,r,i){var a=arguments.length>4&&arguments[4]!==void 0?arguments[4]:[],o=arguments.length>5&&arguments[5]!==void 0?arguments[5]:[],u=s(e,r,o);u.rules.length?l(u.absoluteUrls,{onBeforeSend:function(e,r,i){n.onBeforeSend(e,t,r)},onSuccess:function(e,r,i){var a=n.onSuccess(e,t,r);e=a===!1?``:a||e;var c=s(e,r,o);return c.rules.forEach((function(t,n){e=e.replace(t,c.absoluteRules[n])})),e},onError:function(n,s,l){a.push({xhr:n,url:s}),o.push(u.rules[l]),c(e,t,r,i,a,o)},onComplete:function(n){n.forEach((function(t,n){e=e.replace(u.rules[n],t)})),c(e,t,r,i,a,o)}}):i(e,a)}r.length?r.forEach((function(e,t){var r=e.getAttribute(`href`),s=e.getAttribute(`rel`),c=e.nodeName.toLowerCase()===`link`&&r&&s&&s.toLowerCase().indexOf(`stylesheet`)!==-1,u=n.skipDisabled===!1?!1:e.disabled,f=e.nodeName.toLowerCase()===`style`;if(c&&!u)if(r.indexOf(`data:text/css`)!==-1){var p=decodeURIComponent(r.substring(r.indexOf(`,`)+1));n.useCSSOM&&(p=Array.apply(null,e.sheet.cssRules).map((function(e){return e.cssText})).join(``)),o(p,t,e,location.href)}else l(r,{mimeType:`text/css`,onBeforeSend:function(t,r,i){n.onBeforeSend(t,e,r)},onSuccess:function(n,i,a){o(n,t,e,d(r))},onError:function(r,o,s){i[t]=``,n.onError(r,e,o),a()}});else if(f&&!u){var m=e.textContent;n.useCSSOM&&(m=Array.apply(null,e.sheet.cssRules).map((function(e){return e.cssText})).join(``)),o(m,t,e,location.href)}else i[t]=``,a()})):n.onComplete(``,[])}function d(e,t){var n=document.implementation.createHTMLDocument(``),r=n.createElement(`base`),i=n.createElement(`a`);return n.head.appendChild(r),n.body.appendChild(i),r.href=t||document.baseURI||(document.querySelector(`base`)||{}).href||location.href,i.href=e,i.href}function f(e,t){return(e.matches||e.matchesSelector||e.webkitMatchesSelector||e.mozMatchesSelector||e.msMatchesSelector||e.oMatchesSelector).call(e,t)}var p=c(o(((e,t)=>{t.exports=function(e,t){for(var n=[];e.length>t;){var r=e.substring(0,t),i=r.lastIndexOf(` `);i!==-1&&(t=i),n.push(r.substring(0,t)),e=e.substring(t+1)}return n.push(e),n}}))(),1);u({onComplete(e,t,n){n.forEach(e=>e.remove());let r=new Set,i=new Set,a=e.replace(/([^,{]+?)::?nth-letter\s*\(([^)]*)\)/gi,(e,t,n)=>(t=t.trim(),r.add(t),i.add(n),`${t}::part(nth-child
|
|
1
|
+
(function(e){typeof define==`function`&&define.amd?define([],e):e()})(function(){var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),s=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},c=(n,r,a)=>(a=n==null?{}:e(i(n)),s(r||!n||!n.__esModule?t(a,`default`,{value:n,enumerable:!0}):a,n));function l(e){var t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},n={mimeType:t.mimeType||null,onBeforeSend:t.onBeforeSend||Function.prototype,onSuccess:t.onSuccess||Function.prototype,onError:t.onError||Function.prototype,onComplete:t.onComplete||Function.prototype},r=Array.isArray(e)?e:[e],i=Array.apply(null,Array(r.length)).map((function(e){return null}));function a(e){var t=typeof e==`string`,n=t&&e.trim().charAt(0)===`<`;return t&&!n}function o(e,t){n.onError(e,r[t],t)}function s(e,t){var a=n.onSuccess(e,r[t],t);e=a===!1?``:a||e,i[t]=e,i.indexOf(null)===-1&&n.onComplete(i)}var c=document.createElement(`a`);r.forEach((function(e,t){if(c.setAttribute(`href`,e),c.href=String(c.href),document.all&&!window.atob&&c.host.split(`:`)[0]!==location.host.split(`:`)[0])if(c.protocol===location.protocol){var r=new XDomainRequest;r.open(`GET`,e),r.timeout=0,r.onprogress=Function.prototype,r.ontimeout=Function.prototype,r.onload=function(){var e=r.responseText;a(e)?s(e,t):o(r,t)},r.onerror=function(e){o(r,t)},setTimeout((function(){r.send()}),0)}else console.warn(`Internet Explorer 9 Cross-Origin (CORS) requests must use the same protocol (${e})`),o(null,t);else{var i=new XMLHttpRequest;i.open(`GET`,e),n.mimeType&&i.overrideMimeType&&i.overrideMimeType(n.mimeType),n.onBeforeSend(i,e,t),i.onreadystatechange=function(){if(i.readyState===4){var e=i.responseText;i.status<400&&a(e)||i.status===0&&a(e)?s(e,t):o(i,t)}},i.send()}}))}function u(e){var t={cssComments:/\/\*[\s\S]+?\*\//g,cssImports:/(?:@import\s*)(?:url\(\s*)?(?:['"])([^'"]*)(?:['"])(?:\s*\))?(?:[^;]*;)/g},n={rootElement:e.rootElement||document,include:e.include||`style,link[rel="stylesheet"]`,exclude:e.exclude||null,filter:e.filter||null,skipDisabled:e.skipDisabled!==!1,useCSSOM:e.useCSSOM||!1,onBeforeSend:e.onBeforeSend||Function.prototype,onSuccess:e.onSuccess||Function.prototype,onError:e.onError||Function.prototype,onComplete:e.onComplete||Function.prototype},r=Array.apply(null,n.rootElement.querySelectorAll(n.include)).filter((function(e){return!f(e,n.exclude)})),i=Array.apply(null,Array(r.length)).map((function(e){return null}));function a(){if(i.indexOf(null)===-1){i.reduce((function(e,t,n){return t===``&&e.push(n),e}),[]).reverse().forEach((function(e){return[r,i].forEach((function(t){return t.splice(e,1)}))}));var e=i.join(``);n.onComplete(e,i,r)}}function o(e,t,r,o){var s=n.onSuccess(e,r,o);e=s!==void 0&&!s?``:s||e,c(e,r,o,(function(e,o){i[t]===null&&(o.forEach((function(e){return n.onError(e.xhr,r,e.url)})),!n.filter||n.filter.test(e)?i[t]=e:i[t]=``,a())}))}function s(e,n){var r=arguments.length>2&&arguments[2]!==void 0?arguments[2]:[],i={};return i.rules=(e.replace(t.cssComments,``).match(t.cssImports)||[]).filter((function(e){return r.indexOf(e)===-1})),i.urls=i.rules.map((function(e){return e.replace(t.cssImports,`$1`)})),i.absoluteUrls=i.urls.map((function(e){return d(e,n)})),i.absoluteRules=i.rules.map((function(e,t){var r=i.urls[t],a=d(i.absoluteUrls[t],n);return e.replace(r,a)})),i}function c(e,t,r,i){var a=arguments.length>4&&arguments[4]!==void 0?arguments[4]:[],o=arguments.length>5&&arguments[5]!==void 0?arguments[5]:[],u=s(e,r,o);u.rules.length?l(u.absoluteUrls,{onBeforeSend:function(e,r,i){n.onBeforeSend(e,t,r)},onSuccess:function(e,r,i){var a=n.onSuccess(e,t,r);e=a===!1?``:a||e;var c=s(e,r,o);return c.rules.forEach((function(t,n){e=e.replace(t,c.absoluteRules[n])})),e},onError:function(n,s,l){a.push({xhr:n,url:s}),o.push(u.rules[l]),c(e,t,r,i,a,o)},onComplete:function(n){n.forEach((function(t,n){e=e.replace(u.rules[n],t)})),c(e,t,r,i,a,o)}}):i(e,a)}r.length?r.forEach((function(e,t){var r=e.getAttribute(`href`),s=e.getAttribute(`rel`),c=e.nodeName.toLowerCase()===`link`&&r&&s&&s.toLowerCase().indexOf(`stylesheet`)!==-1,u=n.skipDisabled===!1?!1:e.disabled,f=e.nodeName.toLowerCase()===`style`;if(c&&!u)if(r.indexOf(`data:text/css`)!==-1){var p=decodeURIComponent(r.substring(r.indexOf(`,`)+1));n.useCSSOM&&(p=Array.apply(null,e.sheet.cssRules).map((function(e){return e.cssText})).join(``)),o(p,t,e,location.href)}else l(r,{mimeType:`text/css`,onBeforeSend:function(t,r,i){n.onBeforeSend(t,e,r)},onSuccess:function(n,i,a){o(n,t,e,d(r))},onError:function(r,o,s){i[t]=``,n.onError(r,e,o),a()}});else if(f&&!u){var m=e.textContent;n.useCSSOM&&(m=Array.apply(null,e.sheet.cssRules).map((function(e){return e.cssText})).join(``)),o(m,t,e,location.href)}else i[t]=``,a()})):n.onComplete(``,[])}function d(e,t){var n=document.implementation.createHTMLDocument(``),r=n.createElement(`base`),i=n.createElement(`a`);return n.head.appendChild(r),n.body.appendChild(i),r.href=t||document.baseURI||(document.querySelector(`base`)||{}).href||location.href,i.href=e,i.href}function f(e,t){return(e.matches||e.matchesSelector||e.webkitMatchesSelector||e.mozMatchesSelector||e.msMatchesSelector||e.oMatchesSelector).call(e,t)}var p=c(o(((e,t)=>{t.exports=function(e,t){for(var n=[];e.length>t;){var r=e.substring(0,t),i=r.lastIndexOf(` `);i!==-1&&(t=i),n.push(r.substring(0,t)),e=e.substring(t+1)}return n.push(e),n}}))(),1);u({onComplete(e,t,n){n.forEach(e=>e.remove());let r=new Set,i=new Set,a=``;t.forEach(e=>{let t=e.selector,n=e.style;t.includes(`::nth-letter`)&&(t=t.replace(/([^,{]+?)::?nth-letter\s*\(([^)]*)\)/gi,(e,t,n)=>(t=t.trim(),r.add(t),i.add(n),`${t}::part(nth-child(${CSS.escape(n)}))`))),a+=`${t} { ${n} }\n`}),document.head.insertAdjacentHTML(`beforeend`,`<style>${a}</style>`),r.forEach(e=>{document.querySelectorAll(e).forEach(e=>{if(e.shadowRoot)return;let t=e.attachShadow({mode:`closed`}),n=document.createElement(`span`);n.innerHTML=e.innerHTML,t.appendChild(n),(0,p.default)(n,{charClass:`char`}),i.forEach((e,t)=>{n.querySelectorAll(`.char:nth-child(${e})`).forEach(t=>t.part=`nth-child(${e})`)})})})}})});
|