Generate list of specific style rules, applicable to margin/padding/border.
777095
function expandedRules( style ) {
		var sides = [ 'top', 'left', 'right', 'bottom' ], components;

		if ( style == 'border' )
				components = [ 'color', 'style', 'width' ];

		var styles = [];
		for ( var i = 0 ; i < sides.length ; i++ ) {

			if ( components ) {
				for ( var j = 0 ; j < components.length ; j++ )
					styles.push( [ style, sides[ i ], components[ j ] ].join( '-' ) );
			} else {
				styles.push( [ style, sides[ i ] ].join( '-' ) );
			}
		}

		return styles;
	}
275911
function buildStyleAttribute(styleMap) {
  var styleAttribute = [];
  for (var property in styleMap) {
    styleAttribute.push(property + ': ' + styleMap[property] + ';');
  }
  return styleAttribute.join(' ');
}
785695
def _numbered_style():
    """"""

    style = ListStyle(name='_numbered_list')

    lls = ListLevelStyleNumber(level=1)

    lls.setAttribute('displaylevels', 1)
    lls.setAttribute('numsuffix', '. ')
    lls.setAttribute('numformat', '1')

    llp = ListLevelProperties()
    llp.setAttribute('listlevelpositionandspacemode', 'label-alignment')

    llla = ListLevelLabelAlignment(labelfollowedby='listtab')
    llla.setAttribute('listtabstopposition', '1.27cm')
    llla.setAttribute('textindent', '-0.635cm')
    llla.setAttribute('marginleft', '1.27cm')

    llp.addElement(llla)

    # llp.setAttribute('spacebefore', '')
    # llp.setAttribute('minlabelwidth', '')
    lls.addElement(llp)

    style.addElement(lls)

    return style
155172
function interpolateStyle(styles, attr, subattr = '') {
  // Title-case the sub-attribute.
  if (subattr) {
    /* eslint-disable-next-line no-param-reassign */
    subattr = subattr.replace(subattr[0], subattr[0].toUpperCase());
  }

  return ['Top', 'Right', 'Bottom', 'Left']
    .map((dir) => styles[attr + dir + subattr])
    .join(' ');
}
445141
@Override
    public RuleList visitStylesheet(CSSParser.StylesheetContext ctx) {
        logEnter("stylesheet: ", ctx);
        this.rules = new RuleArrayList();
        //statement*
        for (CSSParser.StatementContext stmt : ctx.statement()) {
            RuleBlock<?> s = visitStatement(stmt);
            if (s != null) {
                //add statement to rules
                this.rules.add(s);
            }
        }
        log.debug("\n***\n{}\n***\n", this.rules);
        logLeave("stylesheet");
        return this.rules;
    }
438634
def css(self, *props, **kwprops):
        """"""
        self._stable = False
        styles = {}
        if props:
            if len(props) == 1 and isinstance(props[0], Mapping):
                styles = props[0]
            else:
                raise WrongContentError(self, props, "Arguments not valid")
        elif kwprops:
            styles = kwprops
        else:
            raise WrongContentError(self, None, "args OR wkargs are needed")
        return self.attr(style=styles)
182027
function get_border_properties() {
    return array("top" => array("width" => $this->__get("border_top_width"),
                                "style" => $this->__get("border_top_style"),
                                "color" => $this->__get("border_top_color")),
                 "bottom" => array("width" => $this->__get("border_bottom_width"),
                                   "style" => $this->__get("border_bottom_style"),
                                   "color" => $this->__get("border_bottom_color")),
                 "right" => array("width" => $this->__get("border_right_width"),
                                  "style" => $this->__get("border_right_style"),
                                  "color" => $this->__get("border_right_color")),
                 "left" => array("width" => $this->__get("border_left_width"),
                                 "style" => $this->__get("border_left_style"),
                                 "color" => $this->__get("border_left_color")));
  }
716304
def style_layout(style_less,
                 theme='grade3',
                 cursorwidth=2,
                 cursorcolor='default',
                 cellwidth='980',
                 lineheight=170,
                 margins='auto',
                 vimext=False,
                 toolbar=False,
                 nbname=False,
                 kernellogo=False,
                 altprompt=False,
                 altmd=False,
                 altout=False,
                 hideprompt=False):
    """"""

    # write theme name to ~/.jupyter/custom/ (referenced by jtplot.py)
    with fileOpen(theme_name_file, 'w') as f:
        f.write(theme)

    if (os.path.isdir(styles_dir_user) and
            '{}.less'.format(theme) in os.listdir(styles_dir_user)):
        theme_relpath = os.path.relpath(
            os.path.join(styles_dir_user, theme), package_dir)
    else:
        theme_relpath = os.path.relpath(
            os.path.join(styles_dir, theme), package_dir)

    style_less += '@import "{}";\n'.format(theme_relpath)

    textcell_bg = '@cc-input-bg'
    promptText = '@input-prompt'
    promptBG = '@cc-input-bg'
    promptPadding = '.25em'
    promptBorder = '2px solid @prompt-line'
    tcPromptBorder = '2px solid @tc-prompt-std'
    promptMinWidth = 11.5
    outpromptMinWidth = promptMinWidth # remove + 3 since it will overlay output print() text
    tcPromptWidth = promptMinWidth + 3
    tcPromptFontsize = "@prompt-fontsize"
    ccOutputBG = '@cc-output-bg-default'

    if theme == 'grade3':
        textcell_bg = '@notebook-bg'
    if altprompt:
        promptPadding = '.1em'
        promptMinWidth = 8
        outpromptMinWidth = promptMinWidth + 3
        tcPromptWidth = promptMinWidth + 3
        promptText = 'transparent'
        tcPromptBorder = '2px solid transparent'
    if altmd:
        textcell_bg = '@notebook-bg'
        tcPromptBorder = '2px dotted @tc-border-selected'
    if altout:
        ccOutputBG = '@notebook-bg'
    if margins != 'auto':
        margins = '{}px'.format(margins)
    if '%' not in cellwidth:
        cellwidth = str(cellwidth) + 'px'

    style_less += '@container-margins: {};\n'.format(margins)
    style_less += '@cell-width: {}; \n'.format(cellwidth)
    style_less += '@cc-line-height: {}%; \n'.format(lineheight)
    style_less += '@text-cell-bg: {}; \n'.format(textcell_bg)
    style_less += '@cc-prompt-width: {}ex; \n'.format(promptMinWidth)
    style_less += '@cc-prompt-bg: {}; \n'.format(promptBG)
    style_less += '@cc-output-bg: {}; \n'.format(ccOutputBG)
    style_less += '@prompt-text: {}; \n'.format(promptText)
    style_less += '@prompt-padding: {}; \n'.format(promptPadding)
    style_less += '@prompt-border: {}; \n'.format(promptBorder)
    style_less += '@prompt-min-width: {}ex; \n'.format(promptMinWidth)
    style_less += '@out-prompt-min-width: {}ex; \n'.format(outpromptMinWidth)
    style_less += '@tc-prompt-width: {}ex; \n'.format(tcPromptWidth)
    style_less += '@tc-prompt-border: {}; \n'.format(tcPromptBorder)
    style_less += '@cursor-width: {}px; \n'.format(cursorwidth)
    style_less += '@cursor-info: @cursor-width solid {}; \n'.format(
        cursorcolor)
    style_less += '@tc-prompt-fontsize: {}; \n'.format(tcPromptFontsize)
    style_less += '\n\n'

    # read-in notebook.less (general nb style)
    with fileOpen(nb_style, 'r') as notebook:
        style_less += notebook.read() + '\n'

    # read-in cells.less (cell layout)
    with fileOpen(cl_style, 'r') as cells:
        style_less += cells.read() + '\n'

    # read-in extras.less (misc layout)
    with fileOpen(ex_style, 'r') as extras:
        style_less += extras.read() + '\n'

    # read-in codemirror.less (syntax-highlighting)
    with fileOpen(cm_style, 'r') as codemirror:
        style_less += codemirror.read() + '\n'
    with fileOpen(comp_style, 'r') as codemirror:
        style_less += codemirror.read() + '\n'

    style_less += toggle_settings(
        toolbar, nbname, hideprompt, kernellogo) + '\n'
    if vimext:
        set_vim_style(theme)

    return style_less
569965
function styleBoxes(selection, self) {
    selection
      .style('width', `${self.boxWidth}px`)
      .style('height', `${self.boxHeight}px`);
    // .style('margin', `${self.boxMargin / 2}px`)
  }
632835
function getCSSText(className) {
			if (typeof document.styleSheets != "object") return "";
			if (document.styleSheets.length <= 0) return "";
			var classes = document.styleSheets[0].rules || document.styleSheets[0].cssRules;
			for (var x = 0; x < classes.length; x++) {
				if (classes[x].selectorText == "." + className || classes[x].selectorText == "#" + className) {
					return ((classes[x].cssText) ? (classes[x].cssText) : (classes[x].style.cssText));
				}
			}
			return "";
		}
353473
function styleRuleValueFrom(selector, documentStyleRules) {
  for (var j = 0; j < documentStyleRules.length; j++) {
    if (documentStyleRules[j].selectorText && documentStyleRules[j].selectorText.toLowerCase() === selector) {
      return documentStyleRules[j].style;
    }
  }
}
860870
function CSSStyleDeclaration(element) {
			var
			style = this,
			currentStyle = element.currentStyle,
			fontSize = getComputedStylePixel(element, 'fontSize'),
			unCamelCase = function (match) {
				return '-' + match.toLowerCase();
			},
			property;

			for (property in currentStyle) {
				Array.prototype.push.call(style, property === 'styleFloat' ? 'float' : property.replace(/[A-Z]/, unCamelCase));

				if (property === 'width') {
					style[property] = element.offsetWidth + 'px';
				} else if (property === 'height') {
					style[property] = element.offsetHeight + 'px';
				} else if (property === 'styleFloat') {
					style.float = currentStyle[property];
				} else if (/margin.|padding.|border.+W/.test(property) && style[property] !== 'auto') {
					style[property] = Math.round(getComputedStylePixel(element, property, fontSize)) + 'px';
				} else if (/^outline/.test(property)) {
					// errors on checking outline
					try {
						style[property] = currentStyle[property];
					} catch (error) {
						style.outlineColor = currentStyle.color;
						style.outlineStyle = style.outlineStyle || 'none';
						style.outlineWidth = style.outlineWidth || '0px';
						style.outline = [style.outlineColor, style.outlineWidth, style.outlineStyle].join(' ');
					}
				} else {
					style[property] = currentStyle[property];
				}
			}

			setShortStyleProperty(style, 'margin');
			setShortStyleProperty(style, 'padding');
			setShortStyleProperty(style, 'border');

			style.fontSize = Math.round(fontSize) + 'px';
		}
1148373
function checkStylesheet(i) {
  const start = i;
  let l;

  while (i < tokensLength) {
    if (l = checkSC(i)) tokens[i].stylesheet_child = 1;
    else if (l = checkRuleset(i)) tokens[i].stylesheet_child = 2;
    else if (l = checkInclude(i)) tokens[i].stylesheet_child = 3;
    else if (l = checkExtend(i)) tokens[i].stylesheet_child = 4;
    else if (l = checkMixin(i)) tokens[i].stylesheet_child = 5;
    else if (l = checkLoop(i)) tokens[i].stylesheet_child = 6;
    else if (l = checkConditionalStatement(i)) tokens[i].stylesheet_child = 7;
    else if (l = checkAtrule(i)) tokens[i].stylesheet_child = 8;
    else if (l = checkDeclaration(i)) tokens[i].stylesheet_child = 9;
    else if (l = checkDeclDelim(i)) tokens[i].stylesheet_child = 10;
    else throwError(i);

    i += l;
  }

  return i - start;
}
549439
def _clean_css(self):
        
        # Init the cleaned CSS rules and contents string
        css_rules = []

        # For every rule in the CSS
        for rule in self.stylesheet.rules:

            try:
                # Clean the CSS rule
                cleaned_rule = self._clean_rule(rule)

                # Append the rule to matched CSS rules
                if cleaned_rule is not None:
                    css_rules.append(cleaned_rule)

            except:
                # On error, assume the rule matched the tree
                css_rules.append(rule)

        return self._build_css(css_rules)
645226
def default_styles():
    """"""

    styles = {}

    def _add_style(name, **kwargs):
        styles[name] = _create_style(name, **kwargs)

    _add_style('heading-1',
               family='paragraph',
               fontsize='24pt',
               fontweight='bold',
               )
    _add_style('heading-2',
               family='paragraph',
               fontsize='22pt',
               fontweight='bold',
               )
    _add_style('heading-3',
               family='paragraph',
               fontsize='20pt',
               fontweight='bold',
               )
    _add_style('heading-4',
               family='paragraph',
               fontsize='18pt',
               fontweight='bold',
               )
    _add_style('heading-5',
               family='paragraph',
               fontsize='16pt',
               fontweight='bold',
               )
    _add_style('heading-6',
               family='paragraph',
               fontsize='14pt',
               fontweight='bold',
               )
    _add_style('normal-paragraph',
               family='paragraph',
               fontsize='12pt',
               marginbottom='0.25cm',
               )
    _add_style('code',
               family='paragraph',
               fontsize='10pt',
               fontweight='bold',
               fontfamily='Courier New',
               color='#555555',
               )
    _add_style('quote',
               family='paragraph',
               fontsize='12pt',
               fontstyle='italic',
               )
    _add_style('list-paragraph',
               family='paragraph',
               fontsize='12pt',
               marginbottom='.1cm',
               )
    _add_style('sublist-paragraph',
               family='paragraph',
               fontsize='12pt',
               marginbottom='.1cm',
               )
    _add_style('numbered-list-paragraph',
               family='paragraph',
               fontsize='12pt',
               marginbottom='.1cm',
               )

    _add_style('normal-text',
               family='text',
               fontsize='12pt',
               )
    _add_style('italic',
               family='text',
               fontstyle='italic',
               fontsize='12pt',
               )
    _add_style('bold',
               family='text',
               fontweight='bold',
               fontsize='12pt',
               )
    _add_style('url',
               family='text',
               fontsize='12pt',
               fontweight='bold',
               fontfamily='Courier',
               )
    _add_style('inline-code',
               family='text',
               fontsize='10pt',
               fontweight='bold',
               fontfamily='Courier New',
               color='#555555',
               )

    styles['_numbered_list'] = _numbered_style()

    return styles
469733
function stylesheet() {
    var rulesList = rules();

    return {
      type: 'stylesheet',
      stylesheet: {
        source: options.source,
        rules: rulesList,
        parsingErrors: errorsList
      }
    };
  }
489251
public function setupRules()
    {
        $identifier = '-?[_a-zA-Z]+[_a-zA-Z0-9-]*';
        $at = [
            'charset', 'import', 'namespace',
            'media', 'supports', 'document', 'page', 'font-face', 'keyframes', 'viewport', 'counter-style',
            'font-feature-values', 'swash', 'ornaments', 'annotation', 'stylistic', 'styleset', 'character-variant'
        ];
        
        $this->rules->addMany([
            'string' => CommonFeatures::strings(['single' => '\'', 'double' => '"'], [
                'context' => $this->everywhere()
            ]),

            'meta.declaration' => [
                new OpenRule(new SubStringMatcher('{'), [
                    'context' => ['!meta.declaration.media', '!comment'],
                    'factory' => new TokenFactory(MetaToken::class)
                ]),
                new CloseRule(new SubStringMatcher('}')),
            ],

            'meta.declaration.media' => [
                new Rule(new RegexMatcher('/@media(.*?\{)/'), [
                    'context' => Validator::everywhere(),
                    'factory' => new TokenFactory(MetaToken::class)
                ]),
            ],

            'meta.declaration.rule' => [
                new OpenRule(new RegexMatcher('/@media.*(\()/'), [
                    'context' => ['meta.declaration.media'],
                    'factory' => new TokenFactory(MetaToken::class)
                ]),
                new CloseRule(new SubStringMatcher(')')),
            ],

            'keyword.at-rule' => new Rule(new RegexMatcher('/(@(?:-[a-z]+-)?(?:'.implode('|', $at).'))/'), [
                'priority' => 2
            ]),

            'symbol.selector.id'    => new Rule(new RegexMatcher("/(#$identifier)/i")),
            'symbol.selector.tag'   => new Rule(new RegexMatcher('/(?>[\s}]|^)(?=(\w+)[^;]*\{)/ms')),
            'symbol.selector.class' => new Rule(new RegexMatcher("/(\\.$identifier)/i")),

            'symbol.selector.class.pseudo' => new Rule(new RegexMatcher("/(:{1,2}$identifier)/")),

            'number' => new Rule(new RegexMatcher("/([-+]?[0-9]*\\.?[0-9]+([\\w%]+)?)/"), [
                'context'  => ['meta.declaration', '!constant.color', '!comment', '!symbol', '!comment', '!string'],
                'priority' => 0
            ]),
            
            'symbol.property' => new Rule(new RegexMatcher("/($identifier:)/"), [
                'context' => ['meta.declaration', '!symbol', '!comment'],
                'priority' => 2
            ]),

            'call' => new Rule(new RegexMatcher("/($identifier)\\s*\\((?:(?P<string>[a-z].*?)|.*?)\\)/", [
                1 => Token::NAME,
                'string' => 'string.argument'
            ]), [
                'context' => ['meta.declaration', '!comment', '!string', '!keyword']
            ]),

            'constant.color' => [
                new Rule(new RegexMatcher("/(#[0-9a-f]{3,6})/i"), [
                    'priority' => 2,
                    'context'  => ['meta.declaration', '!comment']
                ]),
                new Rule(new WordMatcher([
                    'white', 'silver', 'gray', 'black', 'red', 'maroon', 'yellow', 'olive',
                    'lime', 'green', 'aqua', 'teal', 'blue', 'navy', 'fuchsia', 'purple'
                ]), [
                    'context'  => ['meta.declaration', '!comment', '!symbol', '!variable']
                ]),
            ],

            'operator' => new Rule(new WordMatcher(['>', '+', '*', '!important'], ['separated' => false]), [
                'context' => $this->everywhere()
            ]),

            'operator.punctuation' => new Rule(new SubStringMatcher(';'), [
                'context' => $this->everywhere()
            ]),

            'comment' => new Rule(new CommentMatcher([], [['/*', '*/']]), ['context' => $this->everywhere()])
        ]);
    }