UNPKG

13.6 kBJavaScriptView Raw
1// Copyright (c) Jupyter Development Team.
2// Distributed under the terms of the Modified BSD License.
3var __rest = (this && this.__rest) || function (s, e) {
4 var t = {};
5 for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
6 t[p] = s[p];
7 if (s != null && typeof Object.getOwnPropertySymbols === "function")
8 for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
9 if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
10 t[p[i]] = s[p[i]];
11 }
12 return t;
13};
14import { style as typestyleClass } from 'typestyle/lib';
15export var LabIconStyle;
16(function (LabIconStyle) {
17 /**
18 * The builtin stylesheets
19 */
20 const builtinSheets = {
21 breadCrumb: {
22 container: {
23 $nest: {
24 // `&` will be substituted for the generated classname (interpolation)
25 '&:first-child svg': {
26 bottom: '1px',
27 marginLeft: '0px',
28 position: 'relative'
29 },
30 '&:hover': {
31 backgroundColor: 'var(--jp-layout-color2)'
32 },
33 ['.jp-mod-dropTarget&']: {
34 backgroundColor: 'var(--jp-brand-color2)',
35 opacity: 0.7
36 }
37 }
38 },
39 element: {
40 borderRadius: 'var(--jp-border-radius)',
41 cursor: 'pointer',
42 margin: '0px 2px',
43 padding: '0px 2px',
44 height: '16px',
45 width: '16px',
46 verticalAlign: 'middle'
47 }
48 },
49 commandPaletteHeader: {
50 container: {
51 height: '14px',
52 margin: '0 14px 0 auto'
53 },
54 element: {
55 height: '14px',
56 width: '14px'
57 },
58 options: {
59 elementPosition: 'center'
60 }
61 },
62 commandPaletteItem: {
63 element: {
64 height: '16px',
65 width: '16px'
66 },
67 options: {
68 elementPosition: 'center'
69 }
70 },
71 launcherCard: {
72 container: {
73 height: '52px',
74 width: '52px'
75 },
76 element: {
77 height: '52px',
78 width: '52px'
79 },
80 options: {
81 elementPosition: 'center'
82 }
83 },
84 launcherSection: {
85 container: {
86 boxSizing: 'border-box',
87 marginRight: '12px',
88 height: '32px',
89 width: '32px'
90 },
91 element: {
92 height: '32px',
93 width: '32px'
94 },
95 options: {
96 elementPosition: 'center'
97 }
98 },
99 listing: {
100 container: {
101 flex: '0 0 20px',
102 marginRight: '4px',
103 position: 'relative'
104 },
105 element: {
106 height: '16px',
107 width: '16px'
108 },
109 options: {
110 elementPosition: 'center'
111 }
112 },
113 listingHeaderItem: {
114 container: {
115 display: 'inline',
116 height: '16px',
117 width: '16px'
118 },
119 element: {
120 height: 'auto',
121 margin: '-2px 0 0 0',
122 width: '20px'
123 },
124 options: {
125 elementPosition: 'center'
126 }
127 },
128 mainAreaTab: {
129 container: {
130 $nest: {
131 '.lm-DockPanel-tabBar &': {
132 marginRight: '4px'
133 },
134 '#tab-manager &': {
135 marginRight: '2px',
136 position: 'relative'
137 }
138 }
139 },
140 element: {
141 $nest: {
142 '.lm-DockPanel-tabBar &': {
143 height: '14px',
144 width: '14px'
145 },
146 '#tab-manager &': {
147 height: '16px',
148 width: '16px'
149 }
150 }
151 },
152 options: {
153 elementPosition: 'center'
154 }
155 },
156 menuItem: {
157 container: {
158 display: 'inline-block',
159 verticalAlign: 'middle'
160 },
161 element: {
162 height: '16px',
163 width: '16px'
164 },
165 options: {
166 elementPosition: 'center'
167 }
168 },
169 runningItem: {
170 container: {
171 margin: '0px 4px 0px 4px'
172 },
173 element: {
174 height: '16px',
175 width: '16px'
176 },
177 options: {
178 elementPosition: 'center'
179 }
180 },
181 select: {
182 container: {
183 pointerEvents: 'none'
184 },
185 element: {
186 position: 'absolute',
187 height: 'auto',
188 width: '16px'
189 }
190 },
191 settingsEditor: {
192 container: {
193 display: 'flex',
194 flex: '0 0 20px',
195 margin: '0 3px 0 0',
196 position: 'relative',
197 height: '20px',
198 width: '20px'
199 },
200 element: {
201 height: '16px',
202 width: '16px'
203 },
204 options: {
205 elementPosition: 'center'
206 }
207 },
208 sideBar: {
209 container: {
210 // `&` will be substituted for the generated classname (interpolation)
211 $nest: {
212 // left sidebar tab divs
213 '.jp-SideBar.jp-mod-left .lm-TabBar-tab &': {
214 transform: 'rotate(90deg)'
215 },
216 // left sidebar currently selected tab div
217 '.jp-SideBar.jp-mod-left .lm-TabBar-tab.lm-mod-current &': {
218 transform: 'rotate(90deg)\n' +
219 ' translate(\n' +
220 ' calc(-0.5 * var(--jp-border-width)),\n' +
221 ' calc(-0.5 * var(--jp-border-width))\n' +
222 ' )'
223 },
224 // right sidebar tab divs
225 '.jp-SideBar.jp-mod-right .lm-TabBar-tab &': {
226 transform: 'rotate(-90deg)'
227 },
228 // right sidebar currently selected tab div
229 '.jp-SideBar.jp-mod-right .lm-TabBar-tab.lm-mod-current &': {
230 transform: 'rotate(-90deg)\n' +
231 ' translate(\n' +
232 ' calc(0.5 * var(--jp-border-width)),\n' +
233 ' calc(-0.5 * var(--jp-border-width))\n' +
234 ' )'
235 }
236 }
237 },
238 element: {
239 height: 'auto',
240 width: '20px'
241 },
242 options: {
243 elementPosition: 'center'
244 }
245 },
246 splash: {
247 container: {
248 animation: '0.3s fade-in linear forwards',
249 height: '100%',
250 width: '100%',
251 zIndex: 1
252 },
253 element: {
254 // width no height
255 width: '100px'
256 },
257 options: {
258 elementPosition: 'center'
259 }
260 },
261 statusBar: {
262 element: {
263 left: '0px',
264 top: '0px',
265 height: '18px',
266 width: '20px',
267 position: 'relative'
268 }
269 },
270 toolbarButton: {
271 container: {
272 display: 'inline-block',
273 verticalAlign: 'middle'
274 },
275 element: {
276 height: '16px',
277 width: '16px'
278 },
279 options: {
280 elementPosition: 'center'
281 }
282 }
283 };
284 function _elementPositionFactory(extra) {
285 return {
286 container: {
287 alignItems: 'center',
288 display: 'flex'
289 },
290 element: Object.assign({ display: 'block' }, extra)
291 };
292 }
293 /**
294 * Styles to help with positioning
295 */
296 const positionSheets = {
297 center: _elementPositionFactory({ margin: '0 auto', width: '100%' }),
298 top: _elementPositionFactory({ margin: '0 0 auto 0' }),
299 right: _elementPositionFactory({ margin: '0 0 0 auto' }),
300 bottom: _elementPositionFactory({ margin: 'auto 0 0 0' }),
301 left: _elementPositionFactory({ margin: '0 auto 0 0' }),
302 'top right': _elementPositionFactory({ margin: '0 0 auto auto' }),
303 'bottom right': _elementPositionFactory({ margin: 'auto 0 0 auto' }),
304 'bottom left': _elementPositionFactory({ margin: 'auto auto 0 0' }),
305 'top left': _elementPositionFactory({ margin: '0 auto 0 auto' })
306 };
307 function _elementSizeFactory(size) {
308 return {
309 element: {
310 height: size,
311 width: size
312 }
313 };
314 }
315 /**
316 * sheets that establish some default sizes
317 */
318 const sizeSheets = {
319 small: _elementSizeFactory('14px'),
320 normal: _elementSizeFactory('16px'),
321 large: _elementSizeFactory('20px'),
322 xlarge: _elementSizeFactory('24px')
323 };
324 /**
325 * Merge two or more icon sheets into a single "pure"
326 * icon style (ie collections of CSS props only)
327 */
328 function mergeSheets(sheets) {
329 return {
330 container: Object.assign({}, ...sheets.map(s => s.container)),
331 element: Object.assign({}, ...sheets.map(s => s.element))
332 };
333 }
334 /**
335 * Resolve one or more stylesheets that may just be a string naming
336 * one of the builtin stylesheets to an array of proper ISheet objects
337 */
338 function resolveSheet(stylesheet) {
339 if (!stylesheet) {
340 return [];
341 }
342 if (!Array.isArray(stylesheet)) {
343 // wrap in array
344 stylesheet = [stylesheet];
345 }
346 return stylesheet.map(k => (typeof k === 'string' ? builtinSheets[k] : k));
347 }
348 /**
349 * Resolve and merge multiple icon stylesheets
350 */
351 function applySheetOptions(sheets) {
352 const options = Object.assign({}, ...sheets.map(s => s.options));
353 if (options.elementPosition) {
354 sheets.unshift(positionSheets[options.elementPosition]);
355 }
356 if (options.elementSize) {
357 sheets.unshift(sizeSheets[options.elementSize]);
358 }
359 return mergeSheets(sheets);
360 }
361 /**
362 * Resolve a pure icon stylesheet into a typestyle class
363 */
364 function resolveStyleClass(stylesheet) {
365 var _a;
366 return typestyleClass(Object.assign(Object.assign({}, stylesheet.container), { $nest: Object.assign(Object.assign({}, (_a = stylesheet.container) === null || _a === void 0 ? void 0 : _a.$nest), { ['svg']: stylesheet.element }) }));
367 }
368 // cache style classes for builtin stylesheets
369 const _styleClassCache = new Map();
370 /**
371 * Get a typestyle class, given a set of icon styling props
372 */
373 function styleClass(props) {
374 if (!props || Object.keys(props).length === 0) {
375 // props is empty
376 return '';
377 }
378 let { elementPosition, elementSize, stylesheet, kind, justify } = props, elementCSS = __rest(props, ["elementPosition", "elementSize", "stylesheet", "kind", "justify"]);
379 // DEPRECATED: alias kind => stylesheet
380 if (!stylesheet) {
381 stylesheet = kind;
382 }
383 // DEPRECATED: alias justify => elementPosition
384 if (!elementPosition) {
385 elementPosition = justify;
386 }
387 // add option args with defined values to overrides
388 const options = Object.assign(Object.assign({}, (elementPosition && { elementPosition })), (elementSize && { elementSize }));
389 // try to look up the style class in the cache
390 const cacheable = typeof stylesheet === 'string' && Object.keys(elementCSS).length === 0;
391 const cacheKey = cacheable
392 ? [stylesheet, elementPosition, elementSize].join(',')
393 : '';
394 if (cacheable && _styleClassCache.has(cacheKey)) {
395 return _styleClassCache.get(cacheKey);
396 }
397 // resolve kind to an array of sheets, then stick overrides on the end
398 const sheets = resolveSheet(stylesheet);
399 sheets.push({ element: elementCSS, options });
400 // apply style options/merge sheets, then convert to typestyle class
401 const cls = resolveStyleClass(applySheetOptions(sheets));
402 if (cacheable) {
403 // store in cache for later reuse
404 _styleClassCache.set(cacheKey, cls);
405 }
406 return cls;
407 }
408 LabIconStyle.styleClass = styleClass;
409})(LabIconStyle || (LabIconStyle = {}));
410//# sourceMappingURL=icon.js.map
\No newline at end of file