This commit is contained in:
Adam LaCombe 2020-06-11 23:13:41 +08:00
parent a4cf9d9c33
commit f4aa3a2f0d
No known key found for this signature in database
GPG Key ID: F3D176C096E9D0BD
6 changed files with 9 additions and 5 deletions

7
.gitignore vendored
View File

@ -4,4 +4,9 @@
# Dependency directories
node_modules/
.rpt2_cache
.rpt2_cache
dist/
.history/
.vscode/

View File

@ -1,3 +1,5 @@
.rpt2_cache
.vscode
.history
rollup.config.js
src

1
dist/index.d.ts vendored
View File

@ -1 +0,0 @@
export declare function injectStyles(shadowRootElement: HTMLElement, insertBeforeSelector: string, styles: string): void;

1
dist/index.js vendored
View File

@ -1 +0,0 @@
function injectStyles(e,t,n){const o=e.shadowRoot;let r=!1;const c=Array.from(o.querySelectorAll("style"));c.forEach((e,l)=>{if(e.innerHTML===n&&(r=!0),c.length-1===l&&!1===r){const e=document.createElement("style");e.innerHTML=n,o.insertBefore(e,o.querySelector(t))}})}export{injectStyles};

1
dist/index.js.map vendored
View File

@ -1 +0,0 @@
{"version":3,"file":"index.js","sources":["../src/index.ts"],"sourcesContent":["export function injectStyles(\n shadowRootElement: HTMLElement,\n insertBeforeSelector: string,\n styles: string\n) {\n const root = shadowRootElement.shadowRoot;\n let styleAlreadyAdded = false;\n const currentStyleTags = Array.from(root.querySelectorAll('style'));\n currentStyleTags.forEach((element: HTMLStyleElement, index) => {\n if (element.innerHTML === styles) {\n styleAlreadyAdded = true;\n }\n if (currentStyleTags.length - 1 === index && styleAlreadyAdded === false) {\n const newStyleTag = document.createElement('style');\n newStyleTag.innerHTML = styles;\n root.insertBefore(newStyleTag, root.querySelector(insertBeforeSelector));\n }\n });\n}\n"],"names":[],"mappings":"sBACE,iBAA8B,EAC9B,oBAA4B,EAC5B,MAAc;IAEd,MAAM,IAAI,GAAG,iBAAiB,CAAC,UAAU,CAAC;IAC1C,IAAI,iBAAiB,GAAG,KAAK,CAAC;IAC9B,MAAM,gBAAgB,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC,CAAC;IACpE,gBAAgB,CAAC,OAAO,CAAC,CAAC,OAAyB,EAAE,KAAK;QACxD,IAAI,OAAO,CAAC,SAAS,KAAK,MAAM,EAAE;YAChC,iBAAiB,GAAG,IAAI,CAAC;SAC1B;QACD,IAAI,gBAAgB,CAAC,MAAM,GAAG,CAAC,KAAK,KAAK,IAAI,iBAAiB,KAAK,KAAK,EAAE;YACxE,MAAM,WAAW,GAAG,QAAQ,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;YACpD,WAAW,CAAC,SAAS,GAAG,MAAM,CAAC;YAC/B,IAAI,CAAC,YAAY,CAAC,WAAW,EAAE,IAAI,CAAC,aAAa,CAAC,oBAAoB,CAAC,CAAC,CAAC;SAC1E;KACF,CAAC,CAAC;CACJ;;;;"}

View File

@ -1,6 +1,6 @@
{
"name": "shadow-dom-inject-styles",
"version": "1.0.2",
"version": "1.0.3",
"description": "A helper function to easily modify shadow dom css.",
"module": "./dist/index.js",
"main": "./dist/index.js",