8
0

margin.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. /**
  2. * @license Copyright (c) 2003-2020, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
  4. */
  5. /**
  6. * @module engine/view/styles/margin
  7. */
  8. import { getPositionShorthandNormalizer, getBoxSidesValueReducer } from './utils';
  9. /**
  10. * Adds a margin CSS styles processing rules.
  11. *
  12. * editor.data.addStyleProcessorRules( addMarginRules );
  13. *
  14. * The normalized value is stored as:
  15. *
  16. * const styles = {
  17. * margin: {
  18. * top,
  19. * right,
  20. * bottom,
  21. * left
  22. * }
  23. * };
  24. *
  25. * @param {module:engine/view/stylesmap~StylesProcessor} stylesProcessor
  26. */
  27. export function addMarginRules( stylesProcessor ) {
  28. stylesProcessor.setNormalizer( 'margin', getPositionShorthandNormalizer( 'margin' ) );
  29. stylesProcessor.setNormalizer( 'margin-top', value => ( { path: 'margin.top', value } ) );
  30. stylesProcessor.setNormalizer( 'margin-right', value => ( { path: 'margin.right', value } ) );
  31. stylesProcessor.setNormalizer( 'margin-bottom', value => ( { path: 'margin.bottom', value } ) );
  32. stylesProcessor.setNormalizer( 'margin-left', value => ( { path: 'margin.left', value } ) );
  33. stylesProcessor.setReducer( 'margin', getBoxSidesValueReducer( 'margin' ) );
  34. stylesProcessor.setStyleRelation( 'margin', [ 'margin-top', 'margin-right', 'margin-bottom', 'margin-left' ] );
  35. }