writing-mode.js 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. "use strict";
  2. function _defaults(obj, defaults) { var keys = Object.getOwnPropertyNames(defaults); for (var i = 0; i < keys.length; i++) { var key = keys[i]; var value = Object.getOwnPropertyDescriptor(defaults, key); if (value && value.configurable && obj[key] === undefined) { Object.defineProperty(obj, key, value); } } return obj; }
  3. function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _defaults(subClass, superClass); }
  4. function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
  5. var Declaration = require('../declaration');
  6. var WritingMode = /*#__PURE__*/function (_Declaration) {
  7. _inheritsLoose(WritingMode, _Declaration);
  8. function WritingMode() {
  9. return _Declaration.apply(this, arguments) || this;
  10. }
  11. var _proto = WritingMode.prototype;
  12. _proto.insert = function insert(decl, prefix, prefixes) {
  13. if (prefix === '-ms-') {
  14. var cloned = this.set(this.clone(decl), prefix);
  15. if (this.needCascade(decl)) {
  16. cloned.raws.before = this.calcBefore(prefixes, decl, prefix);
  17. }
  18. var direction = 'ltr';
  19. decl.parent.nodes.forEach(function (i) {
  20. if (i.prop === 'direction') {
  21. if (i.value === 'rtl' || i.value === 'ltr') direction = i.value;
  22. }
  23. });
  24. cloned.value = WritingMode.msValues[direction][decl.value] || decl.value;
  25. return decl.parent.insertBefore(decl, cloned);
  26. }
  27. return _Declaration.prototype.insert.call(this, decl, prefix, prefixes);
  28. };
  29. return WritingMode;
  30. }(Declaration);
  31. _defineProperty(WritingMode, "names", ['writing-mode']);
  32. _defineProperty(WritingMode, "msValues", {
  33. ltr: {
  34. 'horizontal-tb': 'lr-tb',
  35. 'vertical-rl': 'tb-rl',
  36. 'vertical-lr': 'tb-lr'
  37. },
  38. rtl: {
  39. 'horizontal-tb': 'rl-tb',
  40. 'vertical-rl': 'bt-rl',
  41. 'vertical-lr': 'bt-lr'
  42. }
  43. });
  44. module.exports = WritingMode;