// Given a document, return a <style> tag that contains all the styles // required to render the page. Not currently used but could be as an // option to clip pages as HTML. function getStyleSheets(doc) { const output = []; for (let i = 0; i < doc.styleSheets.length; i++) { const sheet = doc.styleSheets[i]; try { for (const cssRule of sheet.cssRules) { output.push({ type: 'text', value: cssRule.cssText }); } } catch (error) { // Calling sheet.cssRules will throw a CORS error on Chrome if the stylesheet is on a different domain. // In that case, we skip it and add it to the list of stylesheet URLs. These URls will be downloaded // by the desktop application, since it doesn't have CORS restrictions. console.info('Could not retrieve stylesheet now:', sheet.href); console.info('It will downloaded by the main application.'); console.info(error); output.push({ type: 'url', value: sheet.href }); } } return output; }
ast.cssRules.forEach(function (rule) { var type = rule.constructor.name; var cssInfo; if (typeof that[type] === 'function') { cssInfo = that[type](rule); if (cssInfo) { tasks.push(cssInfo); } } });
injectElementWithStyles('@font-face {font-family:"font";src:url("https://")}', function( node, rule ) { var style = document.getElementById('smodernizr'), sheet = style.sheet || style.styleSheet, cssText = sheet ? (sheet.cssRules && sheet.cssRules[0] ? sheet.cssRules[0].cssText : sheet.cssText || '') : ''; bool = /src/i.test(cssText) && cssText.indexOf(rule.split(' ')[0]) === 0; });
const clearStyles = stylesheet => { const rulesObj = stylesheet.cssRules || stylesheet.rules; range(rulesObj.length).forEach(() => { stylesheet.deleteRule(0); }); }
/** * StyleSheetLoader.js * * Released under LGPL License. * Copyright (c) 1999-2017 Ephox Corp. All rights reserved * * License: http://www.tinymce.com/license * Contributing: http://www.tinymce.com/contributing */ c("tinymce.core.dom.StyleSheetLoader",["ephox.katamari.api.Arr","ephox.katamari.api.Fun","ephox.katamari.api.Future","ephox.katamari.api.Futures","ephox.katamari.api.Result","tinymce.core.util.Delay","tinymce.core.util.Tools"],function(e,t,n,r,i,o,a){return function(c,s){function u(e){c.getElementsByTagName("head")[0].appendChild(e)}function l(e,t,n){function r(){for(var e=b.passed,t=e.length;t--;)e[t]();b.status=2,b.passed=[],b.failed=[]}function i(){for(var e=b.failed,t=e.length;t--;)e[t]();b.status=3,b.passed=[],b.failed=[]}function s(){var e=navigator.userAgent.match(/WebKit\/(\d*)/);return!!(e&&e[1]<536)}function l(e,t){e()||((new Date).getTime()-y<d?o.setTimeout(t):i())}function p(){l(function(){for(var e,t,n=c.styleSheets,i=n.length;i--;)if(e=n[i],t=e.ownerNode?e.ownerNode:e.owningElement,t&&t.id===g.id)return r(),!0},p)}function h(){l(function(){try{var e=v.sheet.cssRules;return r(),!!e}catch(t){}},h)}var g,v,y,b;if(e=a._addCacheSuffix(e),m[e]?b=m[e]:(b={passed:[],failed:[]},m[e]=b),t&&b.passed.push(t),n&&b.failed.push(n),1!=b.status){if(2==b.status)return void r();if(3==b.status)return void i();if(b.status=1,g=c.createElement("link"),g.rel="stylesheet",g.type="text/css",g.id="u"+f++,g.async=!1,g.defer=!1,y=(new Date).getTime(),"onload"in g&&!s())g.onload=p,g.onerror=i;else{if(navigator.userAgent.indexOf("Firefox")>0)return v=c.createElement("style"),v.textContent='@import "'+e+'"',h(),void u(v);p()}u(g),g.href=e}}var d,f=0,m={};s=s||{},d=s.maxLoadTime||5e3;var p=function(e){return n.nu(function(n){l(e,t.compose(n,t.constant(i.value(e))),t.compose(n,t.constant(i.error(e))))})},h=function(e){return e.fold(t.identity,t.identity)},g=function(t,n,i){r.par(e.map(t,p)).get(function(t){var r=e.partition(t,function(e){return e.isValue()});r.fail.length>0?i(r.fail.map(h)):n(r.pass.map(h))})};return{load:l,loadAll:g}}})
function cssToRules(cssText) { var style = cssTextToStyle(cssText); document.head.appendChild(style); var rules = []; if (style.sheet) { try { rules = style.sheet.cssRules; } catch (e) {} } else { console.warn("sheet not found", style); } style.parentNode.removeChild(style); return rules; }
describe('index.html', function() { var url = __dirname + '/html/index.html'; var html = fs.readFileSync(url, 'utf8'); var window = browser.sync(html, { url: url, loadCssFile: false }); it('#test::after', function() { assert.equal('"hello world\\\"" attr(id) "\\\""', window.document.styleSheets[0].cssRules[0].style.content); }); });
Array.each(document.styleSheets, function(sheet){ var href = sheet.href; if (href && href.indexOf('://') > -1 && href.indexOf(document.domain) == -1) return; var rules = sheet.rules || sheet.cssRules; searchStyles(rules); });
injectElementWithStyles('@font-face {font-family:"font";src:url("https://")}', function( node, rule ) { var style = document.getElementById('smodernizr'), sheet = style.sheet || style.styleSheet, cssText = sheet ? (sheet.cssRules && sheet.cssRules[0] ? sheet.cssRules[0].cssText : sheet.cssText || '') : ''; bool = /src/i.test(cssText) && cssText.indexOf(rule.split(' ')[0]) === 0; });
injectElementWithStyles('@font-face {font-family:"font";src:url("https://")}', function( node, rule ) { var style = document.getElementById('smodernizr'), sheet = style.sheet || style.styleSheet, cssText = sheet ? (sheet.cssRules && sheet.cssRules[0] ? sheet.cssRules[0].cssText : sheet.cssText || '') : ''; bool = /src/i.test(cssText) && cssText.indexOf(rule.split(' ')[0]) === 0; });
injectElementWithStyles('@font-face {font-family:"font";src:url("https://")}', function( node, rule ) { var style = document.getElementById('smodernizr'), sheet = style.sheet || style.styleSheet, cssText = sheet ? (sheet.cssRules && sheet.cssRules[0] ? sheet.cssRules[0].cssText : sheet.cssText || '') : ''; bool = /src/i.test(cssText) && cssText.indexOf(rule.split(' ')[0]) === 0; });
injectElementWithStyles('@font-face {font-family:"font";src:url("https://")}', function( node, rule ) { var style = document.getElementById('smodernizr'), sheet = style.sheet || style.styleSheet, cssText = sheet ? (sheet.cssRules && sheet.cssRules[0] ? sheet.cssRules[0].cssText : sheet.cssText || '') : ''; bool = /src/i.test(cssText) && cssText.indexOf(rule.split(' ')[0]) === 0; });