Ohm-Management - Projektarbeit B-ME
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.

helpers.js 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360
  1. 'use strict';
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.camelize = exports.keyCodes = exports.passiveSupported = undefined;
  6. var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
  7. 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; };
  8. exports.createSimpleFunctional = createSimpleFunctional;
  9. exports.createSimpleTransition = createSimpleTransition;
  10. exports.createJavaScriptTransition = createJavaScriptTransition;
  11. exports.directiveConfig = directiveConfig;
  12. exports.addOnceEventListener = addOnceEventListener;
  13. exports.addPassiveEventListener = addPassiveEventListener;
  14. exports.getNestedValue = getNestedValue;
  15. exports.deepEqual = deepEqual;
  16. exports.getObjectValueByPath = getObjectValueByPath;
  17. exports.getPropertyFromItem = getPropertyFromItem;
  18. exports.createRange = createRange;
  19. exports.getZIndex = getZIndex;
  20. exports.escapeHTML = escapeHTML;
  21. exports.filterObjectOnKeys = filterObjectOnKeys;
  22. exports.filterChildren = filterChildren;
  23. exports.convertToUnit = convertToUnit;
  24. exports.kebabCase = kebabCase;
  25. exports.isObject = isObject;
  26. exports.remapInternalIcon = remapInternalIcon;
  27. exports.keys = keys;
  28. exports.arrayDiff = arrayDiff;
  29. exports.upperFirst = upperFirst;
  30. exports.getSlotType = getSlotType;
  31. var _vue = require('vue');
  32. var _vue2 = _interopRequireDefault(_vue);
  33. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  34. function createSimpleFunctional(c) {
  35. var el = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'div';
  36. var name = arguments[2];
  37. return _vue2.default.extend({
  38. name: name || c.replace(/__/g, '-'),
  39. functional: true,
  40. render: function render(h, _ref) {
  41. var data = _ref.data,
  42. children = _ref.children;
  43. data.staticClass = (c + ' ' + (data.staticClass || '')).trim();
  44. return h(el, data, children);
  45. }
  46. });
  47. }
  48. function mergeTransitions(transitions, array) {
  49. if (Array.isArray(transitions)) return transitions.concat(array);
  50. if (transitions) array.push(transitions);
  51. return array;
  52. }
  53. function createSimpleTransition(name) {
  54. var origin = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'top center 0';
  55. var mode = arguments[2];
  56. return {
  57. name: name,
  58. functional: true,
  59. props: {
  60. group: {
  61. type: Boolean,
  62. default: false
  63. },
  64. hideOnLeave: {
  65. type: Boolean,
  66. default: false
  67. },
  68. leaveAbsolute: {
  69. type: Boolean,
  70. default: false
  71. },
  72. mode: {
  73. type: String,
  74. default: mode
  75. },
  76. origin: {
  77. type: String,
  78. default: origin
  79. }
  80. },
  81. render: function render(h, context) {
  82. var tag = 'transition' + (context.props.group ? '-group' : '');
  83. context.data = context.data || {};
  84. context.data.props = {
  85. name: name,
  86. mode: context.props.mode
  87. };
  88. context.data.on = context.data.on || {};
  89. if (!Object.isExtensible(context.data.on)) {
  90. context.data.on = _extends({}, context.data.on);
  91. }
  92. var ourBeforeEnter = [];
  93. var ourLeave = [];
  94. var absolute = function absolute(el) {
  95. return el.style.position = 'absolute';
  96. };
  97. ourBeforeEnter.push(function (el) {
  98. el.style.transformOrigin = context.props.origin;
  99. el.style.webkitTransformOrigin = context.props.origin;
  100. });
  101. if (context.props.leaveAbsolute) ourLeave.push(absolute);
  102. if (context.props.hideOnLeave) {
  103. ourLeave.push(function (el) {
  104. return el.style.display = 'none';
  105. });
  106. }
  107. var _context$data$on = context.data.on,
  108. beforeEnter = _context$data$on.beforeEnter,
  109. leave = _context$data$on.leave;
  110. // Type says Function | Function[] but
  111. // will only work if provided a function
  112. context.data.on.beforeEnter = function () {
  113. return mergeTransitions(beforeEnter, ourBeforeEnter);
  114. };
  115. context.data.on.leave = mergeTransitions(leave, ourLeave);
  116. return h(tag, context.data, context.children);
  117. }
  118. };
  119. }
  120. function createJavaScriptTransition(name, functions) {
  121. var mode = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'in-out';
  122. return {
  123. name: name,
  124. functional: true,
  125. props: {
  126. mode: {
  127. type: String,
  128. default: mode
  129. }
  130. },
  131. render: function render(h, context) {
  132. var data = {
  133. props: _extends({}, context.props, {
  134. name: name
  135. }),
  136. on: functions
  137. };
  138. return h('transition', data, context.children);
  139. }
  140. };
  141. }
  142. function directiveConfig(binding) {
  143. var defaults = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  144. return _extends({}, defaults, binding.modifiers, {
  145. value: binding.arg
  146. }, binding.value || {});
  147. }
  148. function addOnceEventListener(el, event, cb) {
  149. var once = function once() {
  150. cb();
  151. el.removeEventListener(event, once, false);
  152. };
  153. el.addEventListener(event, once, false);
  154. }
  155. var passiveSupported = false;
  156. try {
  157. if (typeof window !== 'undefined') {
  158. var testListenerOpts = Object.defineProperty({}, 'passive', {
  159. get: function get() {
  160. exports.passiveSupported = passiveSupported = true;
  161. }
  162. });
  163. window.addEventListener('testListener', testListenerOpts, testListenerOpts);
  164. window.removeEventListener('testListener', testListenerOpts, testListenerOpts);
  165. }
  166. } catch (e) {
  167. console.warn(e);
  168. }
  169. exports.passiveSupported = passiveSupported;
  170. function addPassiveEventListener(el, event, cb, options) {
  171. el.addEventListener(event, cb, passiveSupported ? options : false);
  172. }
  173. function getNestedValue(obj, path, fallback) {
  174. var last = path.length - 1;
  175. if (last < 0) return obj === undefined ? fallback : obj;
  176. for (var i = 0; i < last; i++) {
  177. if (obj == null) {
  178. return fallback;
  179. }
  180. obj = obj[path[i]];
  181. }
  182. if (obj == null) return fallback;
  183. return obj[path[last]] === undefined ? fallback : obj[path[last]];
  184. }
  185. function deepEqual(a, b) {
  186. if (a === b) return true;
  187. if (a instanceof Date && b instanceof Date) {
  188. // If the values are Date, they were convert to timestamp with getTime and compare it
  189. if (a.getTime() !== b.getTime()) return false;
  190. }
  191. if (a !== Object(a) || b !== Object(b)) {
  192. // If the values aren't objects, they were already checked for equality
  193. return false;
  194. }
  195. var props = Object.keys(a);
  196. if (props.length !== Object.keys(b).length) {
  197. // Different number of props, don't bother to check
  198. return false;
  199. }
  200. return props.every(function (p) {
  201. return deepEqual(a[p], b[p]);
  202. });
  203. }
  204. function getObjectValueByPath(obj, path, fallback) {
  205. // credit: http://stackoverflow.com/questions/6491463/accessing-nested-javascript-objects-with-string-key#comment55278413_6491621
  206. if (!path || path.constructor !== String) return fallback;
  207. path = path.replace(/\[(\w+)\]/g, '.$1'); // convert indexes to properties
  208. path = path.replace(/^\./, ''); // strip a leading dot
  209. return getNestedValue(obj, path.split('.'), fallback);
  210. }
  211. function getPropertyFromItem(item, property, fallback) {
  212. if (property == null) return item === undefined ? fallback : item;
  213. if (item !== Object(item)) return fallback === undefined ? item : fallback;
  214. if (typeof property === 'string') return getObjectValueByPath(item, property, fallback);
  215. if (Array.isArray(property)) return getNestedValue(item, property, fallback);
  216. if (typeof property !== 'function') return fallback;
  217. var value = property(item, fallback);
  218. return typeof value === 'undefined' ? fallback : value;
  219. }
  220. function createRange(length) {
  221. return Array.from({ length: length }, function (v, k) {
  222. return k;
  223. });
  224. }
  225. function getZIndex(el) {
  226. if (!el || el.nodeType !== Node.ELEMENT_NODE) return 0;
  227. var index = +window.getComputedStyle(el).getPropertyValue('z-index');
  228. if (isNaN(index)) return getZIndex(el.parentNode);
  229. return index;
  230. }
  231. var tagsToReplace = {
  232. '&': '&amp;',
  233. '<': '&lt;',
  234. '>': '&gt;'
  235. };
  236. function escapeHTML(str) {
  237. return str.replace(/[&<>]/g, function (tag) {
  238. return tagsToReplace[tag] || tag;
  239. });
  240. }
  241. function filterObjectOnKeys(obj, keys) {
  242. var filtered = {};
  243. for (var i = 0; i < keys.length; i++) {
  244. var key = keys[i];
  245. if (typeof obj[key] !== 'undefined') {
  246. filtered[key] = obj[key];
  247. }
  248. }
  249. return filtered;
  250. }
  251. function filterChildren() {
  252. var array = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
  253. var tag = arguments[1];
  254. return array.filter(function (child) {
  255. return child.componentOptions && child.componentOptions.Ctor.options.name === tag;
  256. });
  257. }
  258. function convertToUnit(str) {
  259. var unit = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'px';
  260. if (str == null || str === '') {
  261. return undefined;
  262. } else if (isNaN(+str)) {
  263. return String(str);
  264. } else {
  265. return '' + Number(str) + unit;
  266. }
  267. }
  268. function kebabCase(str) {
  269. return (str || '').replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase();
  270. }
  271. function isObject(obj) {
  272. return obj !== null && (typeof obj === 'undefined' ? 'undefined' : _typeof(obj)) === 'object';
  273. }
  274. // KeyboardEvent.keyCode aliases
  275. var keyCodes = exports.keyCodes = Object.freeze({
  276. enter: 13,
  277. tab: 9,
  278. delete: 46,
  279. esc: 27,
  280. space: 32,
  281. up: 38,
  282. down: 40,
  283. left: 37,
  284. right: 39,
  285. end: 35,
  286. home: 36,
  287. del: 46,
  288. backspace: 8,
  289. insert: 45,
  290. pageup: 33,
  291. pagedown: 34
  292. });
  293. var ICONS_PREFIX = '$vuetify.icons.';
  294. // This remaps internal names like '$vuetify.icons.cancel'
  295. // to the current name or component for that icon.
  296. function remapInternalIcon(vm, iconName) {
  297. if (!iconName.startsWith(ICONS_PREFIX)) {
  298. return iconName;
  299. }
  300. // Now look up icon indirection name, e.g. '$vuetify.icons.cancel'
  301. return getObjectValueByPath(vm, iconName, iconName);
  302. }
  303. function keys(o) {
  304. return Object.keys(o);
  305. }
  306. /**
  307. * Camelize a hyphen-delimited string.
  308. */
  309. var camelizeRE = /-(\w)/g;
  310. var camelize = exports.camelize = function camelize(str) {
  311. return str.replace(camelizeRE, function (_, c) {
  312. return c ? c.toUpperCase() : '';
  313. });
  314. };
  315. /**
  316. * Returns the set difference of B and A, i.e. the set of elements in B but not in A
  317. */
  318. function arrayDiff(a, b) {
  319. var diff = [];
  320. for (var i = 0; i < b.length; i++) {
  321. if (a.indexOf(b[i]) < 0) diff.push(b[i]);
  322. }
  323. return diff;
  324. }
  325. /**
  326. * Makes the first character of a string uppercase
  327. */
  328. function upperFirst(str) {
  329. return str.charAt(0).toUpperCase() + str.slice(1);
  330. }
  331. /**
  332. * Returns:
  333. * - 'normal' for old style slots - `<template slot="default">`
  334. * - 'scoped' for old style scoped slots (`<template slot="default" slot-scope="data">`) or bound v-slot (`#default="data"`)
  335. * - 'v-slot' for unbound v-slot (`#default`) - only if the third param is true, otherwise counts as scoped
  336. */
  337. function getSlotType(vm, name, split) {
  338. if (vm.$slots[name] && vm.$scopedSlots[name] && vm.$scopedSlots[name].name) {
  339. return split ? 'v-slot' : 'scoped';
  340. }
  341. if (vm.$slots[name]) return 'normal';
  342. if (vm.$scopedSlots[name]) return 'scoped';
  343. }
  344. //# sourceMappingURL=helpers.js.map