You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

пре 3 година
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. (function webpackUniversalModuleDefinition(root, factory) {
  2. if(typeof exports === 'object' && typeof module === 'object')
  3. module.exports = factory();
  4. else if(typeof define === 'function' && define.amd)
  5. define([], factory);
  6. else if(typeof exports === 'object')
  7. exports["jssNested"] = factory();
  8. else
  9. root["jssNested"] = factory();
  10. })(this, function() {
  11. return /******/ (function(modules) { // webpackBootstrap
  12. /******/ // The module cache
  13. /******/ var installedModules = {};
  14. /******/
  15. /******/ // The require function
  16. /******/ function __webpack_require__(moduleId) {
  17. /******/
  18. /******/ // Check if module is in cache
  19. /******/ if(installedModules[moduleId])
  20. /******/ return installedModules[moduleId].exports;
  21. /******/
  22. /******/ // Create a new module (and put it into the cache)
  23. /******/ var module = installedModules[moduleId] = {
  24. /******/ exports: {},
  25. /******/ id: moduleId,
  26. /******/ loaded: false
  27. /******/ };
  28. /******/
  29. /******/ // Execute the module function
  30. /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
  31. /******/
  32. /******/ // Flag the module as loaded
  33. /******/ module.loaded = true;
  34. /******/
  35. /******/ // Return the exports of the module
  36. /******/ return module.exports;
  37. /******/ }
  38. /******/
  39. /******/
  40. /******/ // expose the modules object (__webpack_modules__)
  41. /******/ __webpack_require__.m = modules;
  42. /******/
  43. /******/ // expose the module cache
  44. /******/ __webpack_require__.c = installedModules;
  45. /******/
  46. /******/ // __webpack_public_path__
  47. /******/ __webpack_require__.p = "";
  48. /******/
  49. /******/ // Load entry module and return exports
  50. /******/ return __webpack_require__(0);
  51. /******/ })
  52. /************************************************************************/
  53. /******/ ([
  54. /* 0 */
  55. /***/ (function(module, exports, __webpack_require__) {
  56. 'use strict';
  57. Object.defineProperty(exports, "__esModule", {
  58. value: true
  59. });
  60. var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
  61. exports.default = jssNested;
  62. var _warning = __webpack_require__(1);
  63. var _warning2 = _interopRequireDefault(_warning);
  64. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  65. var separatorRegExp = /\s*,\s*/g;
  66. var parentRegExp = /&/g;
  67. var refRegExp = /\$([\w-]+)/g;
  68. /**
  69. * Convert nested rules to separate, remove them from original styles.
  70. *
  71. * @param {Rule} rule
  72. * @api public
  73. */
  74. function jssNested() {
  75. // Get a function to be used for $ref replacement.
  76. function getReplaceRef(container) {
  77. return function (match, key) {
  78. var rule = container.getRule(key);
  79. if (rule) return rule.selector;
  80. (0, _warning2.default)(false, '[JSS] Could not find the referenced rule %s in %s.', key, container.options.meta || container);
  81. return key;
  82. };
  83. }
  84. var hasAnd = function hasAnd(str) {
  85. return str.indexOf('&') !== -1;
  86. };
  87. function replaceParentRefs(nestedProp, parentProp) {
  88. var parentSelectors = parentProp.split(separatorRegExp);
  89. var nestedSelectors = nestedProp.split(separatorRegExp);
  90. var result = '';
  91. for (var i = 0; i < parentSelectors.length; i++) {
  92. var parent = parentSelectors[i];
  93. for (var j = 0; j < nestedSelectors.length; j++) {
  94. var nested = nestedSelectors[j];
  95. if (result) result += ', ';
  96. // Replace all & by the parent or prefix & with the parent.
  97. result += hasAnd(nested) ? nested.replace(parentRegExp, parent) : parent + ' ' + nested;
  98. }
  99. }
  100. return result;
  101. }
  102. function getOptions(rule, container, options) {
  103. // Options has been already created, now we only increase index.
  104. if (options) return _extends({}, options, { index: options.index + 1 });
  105. var nestingLevel = rule.options.nestingLevel;
  106. nestingLevel = nestingLevel === undefined ? 1 : nestingLevel + 1;
  107. return _extends({}, rule.options, {
  108. nestingLevel: nestingLevel,
  109. index: container.indexOf(rule) + 1
  110. });
  111. }
  112. function onProcessStyle(style, rule) {
  113. if (rule.type !== 'style') return style;
  114. var container = rule.options.parent;
  115. var options = void 0;
  116. var replaceRef = void 0;
  117. for (var prop in style) {
  118. var isNested = hasAnd(prop);
  119. var isNestedConditional = prop[0] === '@';
  120. if (!isNested && !isNestedConditional) continue;
  121. options = getOptions(rule, container, options);
  122. if (isNested) {
  123. var selector = replaceParentRefs(prop, rule.selector
  124. // Lazily create the ref replacer function just once for
  125. // all nested rules within the sheet.
  126. );if (!replaceRef) replaceRef = getReplaceRef(container
  127. // Replace all $refs.
  128. );selector = selector.replace(refRegExp, replaceRef);
  129. container.addRule(selector, style[prop], _extends({}, options, { selector: selector }));
  130. } else if (isNestedConditional) {
  131. container
  132. // Place conditional right after the parent rule to ensure right ordering.
  133. .addRule(prop, null, options).addRule(rule.key, style[prop], { selector: rule.selector });
  134. }
  135. delete style[prop];
  136. }
  137. return style;
  138. }
  139. return { onProcessStyle: onProcessStyle };
  140. }
  141. /***/ }),
  142. /* 1 */
  143. /***/ (function(module, exports, __webpack_require__) {
  144. /**
  145. * Copyright 2014-2015, Facebook, Inc.
  146. * All rights reserved.
  147. *
  148. * This source code is licensed under the BSD-style license found in the
  149. * LICENSE file in the root directory of this source tree. An additional grant
  150. * of patent rights can be found in the PATENTS file in the same directory.
  151. */
  152. 'use strict';
  153. /**
  154. * Similar to invariant but only logs a warning if the condition is not met.
  155. * This can be used to log issues in development environments in critical
  156. * paths. Removing the logging code for production environments will keep the
  157. * same logic and follow the same code paths.
  158. */
  159. var warning = function() {};
  160. if (true) {
  161. warning = function(condition, format, args) {
  162. var len = arguments.length;
  163. args = new Array(len > 2 ? len - 2 : 0);
  164. for (var key = 2; key < len; key++) {
  165. args[key - 2] = arguments[key];
  166. }
  167. if (format === undefined) {
  168. throw new Error(
  169. '`warning(condition, format, ...args)` requires a warning ' +
  170. 'message argument'
  171. );
  172. }
  173. if (format.length < 10 || (/^[s\W]*$/).test(format)) {
  174. throw new Error(
  175. 'The warning format should be able to uniquely identify this ' +
  176. 'warning. Please, use a more descriptive format than: ' + format
  177. );
  178. }
  179. if (!condition) {
  180. var argIndex = 0;
  181. var message = 'Warning: ' +
  182. format.replace(/%s/g, function() {
  183. return args[argIndex++];
  184. });
  185. if (typeof console !== 'undefined') {
  186. console.error(message);
  187. }
  188. try {
  189. // This error was thrown as a convenience so that you can use this stack
  190. // to find the callsite that caused this warning to fire.
  191. throw new Error(message);
  192. } catch(x) {}
  193. }
  194. };
  195. }
  196. module.exports = warning;
  197. /***/ })
  198. /******/ ])
  199. });
  200. ;
  201. //# sourceMappingURL=jss-nested.js.map