UNPKG

4.09 kBJavaScriptView Raw
1/**
2 * ag-grid - Advanced Data Grid / Data Table supporting Javascript / React / AngularJS / Web Components
3 * @version v18.1.2
4 * @link http://www.ag-grid.com/
5 * @license MIT
6 */
7"use strict";
8var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
9 var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
10 if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
11 else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
12 return c > 3 && r && Object.defineProperty(target, key, r), r;
13};
14var __metadata = (this && this.__metadata) || function (k, v) {
15 if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
16};
17Object.defineProperty(exports, "__esModule", { value: true });
18var context_1 = require("./context/context");
19var themeNames = ['fresh', 'dark', 'blue', 'bootstrap', 'material', 'balham-dark', 'balham'];
20var themes = themeNames.concat(themeNames.map(function (name) { return "theme-" + name; }));
21var themeClass = new RegExp("ag-(" + themes.join('|') + ")");
22var matGridSize = 8;
23var freshGridSize = 4;
24var balhamGridSize = 4;
25var HARD_CODED_SIZES = {
26 'ag-theme-material': {
27 headerHeight: matGridSize * 7,
28 virtualItemHeight: matGridSize * 5,
29 rowHeight: matGridSize * 6
30 },
31 'ag-theme-classic': {
32 headerHeight: 25,
33 virtualItemHeight: freshGridSize * 5,
34 rowHeight: 25
35 },
36 'ag-theme-balham': {
37 headerHeight: balhamGridSize * 8,
38 virtualItemHeight: balhamGridSize * 7,
39 rowHeight: balhamGridSize * 7
40 }
41};
42var Environment = (function () {
43 function Environment() {
44 this.sassVariables = {};
45 }
46 // Approach described here:
47 // https://www.ofcodeandcolor.com/2017/04/02/encoding-data-in-css/
48 Environment.prototype.loadSassVariables = function () {
49 /*
50 var element = document.createElement('div');
51 element.className = 'sass-variables';
52 this.eGridDiv.appendChild(element);
53
54 var content = window.getComputedStyle(element, '::after').content;
55
56 try {
57 this.sassVariables = JSON.parse(JSON.parse(content));
58 } catch (e) {
59 throw new Error("Failed loading the theme sizing - check that you have the theme set up correctly.");
60 }
61
62 this.eGridDiv.removeChild(element);
63 */
64 };
65 Environment.prototype.getSassVariable = function (theme, key) {
66 if (theme == 'ag-theme-material') {
67 return HARD_CODED_SIZES['ag-theme-material'][key];
68 }
69 else if (theme == 'ag-theme-balham' || theme == 'ag-theme-balham-dark') {
70 return HARD_CODED_SIZES['ag-theme-balham'][key];
71 }
72 return HARD_CODED_SIZES['ag-theme-classic'][key];
73 /*
74 const result = parseInt(this.sassVariables[key]);
75 if (!result || isNaN(result)) {
76 throw new Error(`Failed loading ${key} Sass variable from ${this.sassVariables}`);
77 }
78 return result;
79 */
80 };
81 Environment.prototype.getTheme = function () {
82 var themeMatch;
83 var element = this.eGridDiv;
84 while (element != document.documentElement && themeMatch == null) {
85 themeMatch = element.className.match(themeClass);
86 element = element.parentElement;
87 if (element == null) {
88 break;
89 }
90 }
91 if (themeMatch) {
92 return themeMatch[0];
93 }
94 else {
95 return 'ag-fresh';
96 }
97 };
98 __decorate([
99 context_1.Autowired('eGridDiv'),
100 __metadata("design:type", HTMLElement)
101 ], Environment.prototype, "eGridDiv", void 0);
102 Environment = __decorate([
103 context_1.Bean('environment')
104 ], Environment);
105 return Environment;
106}());
107exports.Environment = Environment;