@shortfuse/materialdesignweb 0.7.0 → 0.7.1-0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/components/Badge.css +8 -0
- package/components/Button.css +1 -0
- package/components/Checkbox.css +17 -5
- package/components/CheckboxIcon.css +1 -0
- package/components/IconButton.css +0 -1
- package/components/NavRail.css +1 -1
- package/components/Progress.css +1 -0
- package/components/Radio.css +13 -1
- package/components/SegmentedButtonGroup.css +1 -1
- package/components/Slider.css +2 -1
- package/components/Switch.css +1 -0
- package/components/SwitchIcon.css +3 -2
- package/components/TextArea.css +1 -1
- package/index.js +77 -0
- package/mixins/TextFieldMixin.css +1 -1
- package/package.json +2 -1
- package/theming/index.js +0 -121
- package/utils/svg.js +0 -117
package/components/Badge.css
CHANGED
|
@@ -6,6 +6,9 @@
|
|
|
6
6
|
--mdw-type__letter-spacing: var(--mdw-typescale__label-small__letter-spacing);
|
|
7
7
|
position: relative;
|
|
8
8
|
|
|
9
|
+
display: inline-block;
|
|
10
|
+
vertical-align: middle;
|
|
11
|
+
|
|
9
12
|
box-sizing: border-box;
|
|
10
13
|
min-block-size: var(--mdw-typescale__label-small__line-height);
|
|
11
14
|
min-inline-size: var(--mdw-typescale__label-small__line-height);
|
|
@@ -20,11 +23,16 @@
|
|
|
20
23
|
|
|
21
24
|
@supports (width: 1lh) {
|
|
22
25
|
:host {
|
|
26
|
+
min-block-size: 1lh; /* Clamps to 1:1 */
|
|
23
27
|
min-inline-size: 1lh; /* Clamps to 1:1 */
|
|
24
28
|
padding-inline: max(0.25lh, calc(0.25lh + (var(--mdw-density) * 2px)));
|
|
25
29
|
}
|
|
26
30
|
}
|
|
27
31
|
|
|
32
|
+
:host(:empty) {
|
|
33
|
+
vertical-align: middle;
|
|
34
|
+
}
|
|
35
|
+
|
|
28
36
|
:host(:empty) #shape {
|
|
29
37
|
inset: 5px;
|
|
30
38
|
}
|
package/components/Button.css
CHANGED
package/components/Checkbox.css
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
--mdw-bg: var(--mdw-color__primary);
|
|
6
6
|
|
|
7
7
|
display: inline-grid;
|
|
8
|
-
align-items:
|
|
8
|
+
align-items: baseline;
|
|
9
9
|
gap: 12px;
|
|
10
10
|
grid-auto-flow: column;
|
|
11
11
|
justify-content: flex-start;
|
|
@@ -15,6 +15,20 @@
|
|
|
15
15
|
transition: none 100ms cubic-bezier(0.4, 0.0, 1, 1);
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
+
:host([disabled]) {
|
|
19
|
+
opacity: 0.38;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
:host(:empty) {
|
|
23
|
+
vertical-align: -11.5%;
|
|
24
|
+
|
|
25
|
+
line-height: 18px;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
:host(:empty) #checkbox {
|
|
29
|
+
transform: none;
|
|
30
|
+
}
|
|
31
|
+
|
|
18
32
|
#control {
|
|
19
33
|
grid-column: 1/1;
|
|
20
34
|
|
|
@@ -42,10 +56,6 @@
|
|
|
42
56
|
border-radius: 50%;
|
|
43
57
|
}
|
|
44
58
|
|
|
45
|
-
:host([disabled]) {
|
|
46
|
-
opacity: 0.38;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
59
|
#checkbox {
|
|
50
60
|
position: relative;
|
|
51
61
|
|
|
@@ -55,6 +65,8 @@
|
|
|
55
65
|
|
|
56
66
|
pointer-events: none;
|
|
57
67
|
|
|
68
|
+
transform: translateY(11.5%);
|
|
69
|
+
|
|
58
70
|
color: rgb(var(--mdw-color__on-surface));
|
|
59
71
|
}
|
|
60
72
|
|
package/components/NavRail.css
CHANGED
package/components/Progress.css
CHANGED
package/components/Radio.css
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
--mdw-ink: var(--mdw-color__primary);
|
|
5
5
|
--mdw-shape__size: var(--mdw-shape__full);
|
|
6
6
|
display: inline-grid;
|
|
7
|
-
align-items:
|
|
7
|
+
align-items: baseline;
|
|
8
8
|
gap: 12px;
|
|
9
9
|
grid-auto-flow: column;
|
|
10
10
|
grid-template-rows: minmax(20px, auto);
|
|
@@ -16,6 +16,16 @@
|
|
|
16
16
|
transition: none 100ms cubic-bezier(0.4, 0.0, 1, 1);
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
+
:host(:empty) {
|
|
20
|
+
vertical-align: -11.5%;
|
|
21
|
+
|
|
22
|
+
line-height: 20px;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
:host(:empty) #radio {
|
|
26
|
+
transform: none;
|
|
27
|
+
}
|
|
28
|
+
|
|
19
29
|
#control {
|
|
20
30
|
grid-column: 1/1;
|
|
21
31
|
|
|
@@ -62,6 +72,8 @@
|
|
|
62
72
|
|
|
63
73
|
pointer-events: none;
|
|
64
74
|
|
|
75
|
+
transform: translateY(11.5%);
|
|
76
|
+
|
|
65
77
|
color: rgb(var(--mdw-color__on-surface));
|
|
66
78
|
}
|
|
67
79
|
|
package/components/Slider.css
CHANGED
package/components/Switch.css
CHANGED
|
@@ -5,16 +5,17 @@
|
|
|
5
5
|
--mdw-bg: var(--mdw-color__primary);
|
|
6
6
|
--mdw-shape__size: var(--mdw-shape__full);
|
|
7
7
|
--mdw-switch__value: 0;
|
|
8
|
-
container-type: inline-size;
|
|
9
|
-
container-name: switch-icon;
|
|
10
8
|
|
|
11
9
|
position: relative;
|
|
12
10
|
|
|
13
11
|
display: inline-block;
|
|
12
|
+
vertical-align: middle;
|
|
14
13
|
|
|
15
14
|
box-sizing: border-box;
|
|
16
15
|
block-size: 32px;
|
|
17
16
|
inline-size: 52px;
|
|
17
|
+
container-type: inline-size;
|
|
18
|
+
container-name: switch-icon;
|
|
18
19
|
}
|
|
19
20
|
|
|
20
21
|
:host([selected]) {
|
package/components/TextArea.css
CHANGED
package/index.js
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
export { default as Badge } from './components/Badge.js';
|
|
2
|
+
export { default as Body } from './components/Body.js';
|
|
3
|
+
export { default as BottomAppBar } from './components/BottomAppBar.js';
|
|
4
|
+
export { default as Box } from './components/Box.js';
|
|
5
|
+
export { default as Button } from './components/Button.js';
|
|
6
|
+
export { default as Card } from './components/Card.js';
|
|
7
|
+
export { default as Checkbox } from './components/Checkbox.js';
|
|
8
|
+
export { default as Chip } from './components/Chip.js';
|
|
9
|
+
export { default as Dialog } from './components/Dialog.js';
|
|
10
|
+
export { default as Divider } from './components/Divider.js';
|
|
11
|
+
export { default as ExtendedFab } from './components/ExtendedFab.js';
|
|
12
|
+
export { default as Fab } from './components/Fab.js';
|
|
13
|
+
export { default as FilterChip } from './components/FilterChip.js';
|
|
14
|
+
export { default as Headline } from './components/Headline.js';
|
|
15
|
+
export { default as Icon } from './components/Icon.js';
|
|
16
|
+
export { default as IconButton } from './components/IconButton.js';
|
|
17
|
+
export { default as Input } from './components/Input.js';
|
|
18
|
+
export { default as Label } from './components/Label.js';
|
|
19
|
+
export { default as Layout } from './components/Layout.js';
|
|
20
|
+
export { default as List } from './components/List.js';
|
|
21
|
+
export { default as ListItem } from './components/ListItem.js';
|
|
22
|
+
export { default as ListOption } from './components/ListOption.js';
|
|
23
|
+
export { default as ListSelect } from './components/ListSelect.js';
|
|
24
|
+
export { default as Menu } from './components/Menu.js';
|
|
25
|
+
export { default as MenuItem } from './components/MenuItem.js';
|
|
26
|
+
export { default as NavBar } from './components/NavBar.js';
|
|
27
|
+
export { default as NavBarItem } from './components/NavBarItem.js';
|
|
28
|
+
export { default as NavDrawer } from './components/NavDrawer.js';
|
|
29
|
+
export { default as NavDrawerItem } from './components/NavDrawerItem.js';
|
|
30
|
+
export { default as NavItem } from './components/NavItem.js';
|
|
31
|
+
export { default as NavRail } from './components/NavRail.js';
|
|
32
|
+
export { default as NavRailItem } from './components/NavRailItem.js';
|
|
33
|
+
export { default as Pane } from './components/Pane.js';
|
|
34
|
+
export { default as Progress } from './components/Progress.js';
|
|
35
|
+
export { default as Radio } from './components/Radio.js';
|
|
36
|
+
export { default as SegmentedButton } from './components/SegmentedButton.js';
|
|
37
|
+
export { default as SegmentedButtonGroup } from './components/SegmentedButtonGroup.js';
|
|
38
|
+
export { default as Select } from './components/Select.js';
|
|
39
|
+
export { default as Slider } from './components/Slider.js';
|
|
40
|
+
export { default as Snackbar } from './components/Snackbar.js';
|
|
41
|
+
export { default as Surface } from './components/Surface.js';
|
|
42
|
+
export { default as Switch } from './components/Switch.js';
|
|
43
|
+
export { default as Tab } from './components/Tab.js';
|
|
44
|
+
export { default as TabContent } from './components/TabContent.js';
|
|
45
|
+
export { default as TabList } from './components/TabList.js';
|
|
46
|
+
export { default as TabPanel } from './components/TabPanel.js';
|
|
47
|
+
export { default as TextArea } from './components/TextArea.js';
|
|
48
|
+
export { default as Title } from './components/Title.js';
|
|
49
|
+
export { default as Tooltip } from './components/Tooltip.js';
|
|
50
|
+
export { default as TopAppBar } from './components/TopAppBar.js';
|
|
51
|
+
|
|
52
|
+
export { default as CustomElement } from './core/CustomElement.js';
|
|
53
|
+
export { default as Composition } from './core/Composition.js';
|
|
54
|
+
|
|
55
|
+
export { default as InputMixin } from './mixins/InputMixin.js';
|
|
56
|
+
export { default as AriaReflectorMixin } from './mixins/AriaReflectorMixin.js';
|
|
57
|
+
export { default as ControlMixin } from './mixins/ControlMixin.js';
|
|
58
|
+
export { default as RTLObserverMixin } from './mixins/RTLObserverMixin.js';
|
|
59
|
+
export { default as TouchTargetMixin } from './mixins/TouchTargetMixin.js';
|
|
60
|
+
export { default as ShapeMixin } from './mixins/ShapeMixin.js';
|
|
61
|
+
export { default as RippleMixin } from './mixins/RippleMixin.js';
|
|
62
|
+
export { default as FormAssociatedMixin } from './mixins/FormAssociatedMixin.js';
|
|
63
|
+
export { default as KeyboardNavMixin } from './mixins/KeyboardNavMixin.js';
|
|
64
|
+
export { default as ResizeObserverMixin } from './mixins/ResizeObserverMixin.js';
|
|
65
|
+
export { default as DensityMixin } from './mixins/DensityMixin.js';
|
|
66
|
+
export { default as TooltipTriggerMixin } from './mixins/TooltipTriggerMixin.js';
|
|
67
|
+
export { default as ScrollListenerMixin } from './mixins/ScrollListenerMixin.js';
|
|
68
|
+
export { default as FlexableMixin } from './mixins/FlexableMixin.js';
|
|
69
|
+
export { default as ThemableMixin } from './mixins/ThemableMixin.js';
|
|
70
|
+
export { default as AriaToolbarMixin } from './mixins/AriaToolbarMixin.js';
|
|
71
|
+
export { default as TextFieldMixin } from './mixins/TextFieldMixin.js';
|
|
72
|
+
export { default as SurfaceMixin } from './mixins/SurfaceMixin.js';
|
|
73
|
+
export { default as StateMixin } from './mixins/StateMixin.js';
|
|
74
|
+
|
|
75
|
+
export * as themeLoader from './theming/loader.js';
|
|
76
|
+
|
|
77
|
+
export * as theming from './theming/index.js';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shortfuse/materialdesignweb",
|
|
3
|
-
"version": "0.7.0",
|
|
3
|
+
"version": "0.7.1-0",
|
|
4
4
|
"description": "Material Design for Web",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"scripts": {
|
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
"pretest": "eslint --ignore-path .gitignore",
|
|
13
13
|
"test": "c8 tap --no-coverage"
|
|
14
14
|
},
|
|
15
|
+
"main": "index.js",
|
|
15
16
|
"repository": {
|
|
16
17
|
"type": "git",
|
|
17
18
|
"url": "git+https://github.com/clshortfuse/materialdesignweb.git"
|
package/theming/index.js
CHANGED
|
@@ -10,53 +10,6 @@ import { svgToCSSURL } from '../utils/svg.js';
|
|
|
10
10
|
* @return {string}
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
|
-
/** @return {string} */
|
|
14
|
-
function cornerCutClipPath() {
|
|
15
|
-
const TOP = 0;
|
|
16
|
-
const END = '100%';
|
|
17
|
-
const BOTTOM = '100%';
|
|
18
|
-
const START = 0;
|
|
19
|
-
|
|
20
|
-
const TOP_START_SIZE = 'var(--mdw-shape__size__top-start-size)';
|
|
21
|
-
const TOP_END_SIZE = 'var(--mdw-shape__size__top-end-size)';
|
|
22
|
-
const BOTTOM_START_SIZE = 'var(--mdw-shape__size__bottom-start-size)';
|
|
23
|
-
const BOTTOM_END_SIZE = 'var(--mdw-shape__size__bottom-end-size)';
|
|
24
|
-
|
|
25
|
-
const TOP_INSET = (size) => `min(${size},50%)`;
|
|
26
|
-
const START_INSET = (size) => `min(${size},50%)`;
|
|
27
|
-
const END_INSET = (size) => `calc(100% - min(${size},50%))`;
|
|
28
|
-
const BOTTOM_INSET = (size) => `calc(100% - min(${size},50%))`;
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* 2 3
|
|
32
|
-
* ┌──────────────┐
|
|
33
|
-
* 1 │ │ 4
|
|
34
|
-
* │ │
|
|
35
|
-
* │ │
|
|
36
|
-
* │ │
|
|
37
|
-
* 8 │ │ 5
|
|
38
|
-
* └──────────────┘
|
|
39
|
-
* 7 6
|
|
40
|
-
*/
|
|
41
|
-
|
|
42
|
-
return `polygon(${
|
|
43
|
-
[
|
|
44
|
-
[START, TOP_INSET(TOP_START_SIZE)],
|
|
45
|
-
[START_INSET(TOP_START_SIZE), TOP],
|
|
46
|
-
|
|
47
|
-
[END_INSET(TOP_END_SIZE), TOP],
|
|
48
|
-
[END, TOP_INSET(TOP_END_SIZE)],
|
|
49
|
-
|
|
50
|
-
[END, BOTTOM_INSET(BOTTOM_END_SIZE)],
|
|
51
|
-
[END_INSET(BOTTOM_END_SIZE), BOTTOM],
|
|
52
|
-
|
|
53
|
-
[START_INSET(BOTTOM_START_SIZE), BOTTOM],
|
|
54
|
-
[START, BOTTOM_INSET(BOTTOM_START_SIZE)],
|
|
55
|
-
|
|
56
|
-
].map((coordinates) => coordinates.join(' ')).join(', ')
|
|
57
|
-
})`;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
13
|
/**
|
|
61
14
|
* @param {string} shape
|
|
62
15
|
* @return {string}
|
|
@@ -156,31 +109,6 @@ const SHAPE_SQUIRCLE_DEFAULT = {
|
|
|
156
109
|
mask: SQUIRCLE_PATH,
|
|
157
110
|
};
|
|
158
111
|
|
|
159
|
-
const LAYOUT_DEFAULT = {
|
|
160
|
-
density: 0,
|
|
161
|
-
body: {
|
|
162
|
-
0: 'calc(100% - 32px)',
|
|
163
|
-
'600px': 'calc(100% - 64px)',
|
|
164
|
-
'904px': '840px',
|
|
165
|
-
'1240px': 'calc(100% - 200px)',
|
|
166
|
-
'1440px': '1040px',
|
|
167
|
-
},
|
|
168
|
-
columns: {
|
|
169
|
-
'0px': 4,
|
|
170
|
-
'600px': 8,
|
|
171
|
-
'904px': 12,
|
|
172
|
-
},
|
|
173
|
-
alias: {
|
|
174
|
-
'extra-small': '0px',
|
|
175
|
-
phone: '0px',
|
|
176
|
-
small: '600px',
|
|
177
|
-
medium: '904px',
|
|
178
|
-
tablet: '600px',
|
|
179
|
-
laptop: '1240px',
|
|
180
|
-
large: '1440px',
|
|
181
|
-
},
|
|
182
|
-
};
|
|
183
|
-
|
|
184
112
|
const SP = 1 / 16;
|
|
185
113
|
|
|
186
114
|
const TYPOGRAPHY_DEFAULT = {
|
|
@@ -430,55 +358,6 @@ export function generateTypographyGlobalCSS() {
|
|
|
430
358
|
.join('\n')}}`;
|
|
431
359
|
}
|
|
432
360
|
|
|
433
|
-
/**
|
|
434
|
-
* @param {LAYOUT_DEFAULT} [config]
|
|
435
|
-
* @return {string}
|
|
436
|
-
*/
|
|
437
|
-
export function generateLayoutGlobalCSS(config = LAYOUT_DEFAULT) {
|
|
438
|
-
/** @type {Map<string, Set<string>>} */
|
|
439
|
-
const breakpoints = new Map();
|
|
440
|
-
/**
|
|
441
|
-
*
|
|
442
|
-
* @param {string} breakpoint
|
|
443
|
-
* @return {Set<string>}
|
|
444
|
-
*/
|
|
445
|
-
function getSet(breakpoint) {
|
|
446
|
-
let set = breakpoints.get(breakpoint);
|
|
447
|
-
if (!set) {
|
|
448
|
-
set = new Set();
|
|
449
|
-
breakpoints.set(breakpoint, set);
|
|
450
|
-
}
|
|
451
|
-
return set;
|
|
452
|
-
}
|
|
453
|
-
|
|
454
|
-
for (const [breakpoint, value] of Object.entries(config.body)) {
|
|
455
|
-
getSet((breakpoint === '0' || breakpoint === '0px') ? '' : `min-width ${breakpoint}`)
|
|
456
|
-
.add(`--mdw-breakpoint__body: ${value};`);
|
|
457
|
-
}
|
|
458
|
-
|
|
459
|
-
for (const [breakpoint, value] of Object.entries(config.columns)) {
|
|
460
|
-
getSet((breakpoint === '0' || breakpoint === '0px') ? '' : `min-width ${breakpoint}`)
|
|
461
|
-
.add(`--mdw-breakpoint__columns: ${value};`);
|
|
462
|
-
}
|
|
463
|
-
|
|
464
|
-
for (const [alias, value] of Object.entries(config.alias)) {
|
|
465
|
-
getSet('').add(`--mdw-breakpoint__${alias}: ${value};`);
|
|
466
|
-
}
|
|
467
|
-
|
|
468
|
-
getSet('').add(`--mdw-density__default: ${config.density};`);
|
|
469
|
-
|
|
470
|
-
let css = '';
|
|
471
|
-
for (const [breakpoint, set] of breakpoints) {
|
|
472
|
-
let rules = `:root { ${[...set].join('')}}`;
|
|
473
|
-
if (breakpoint) {
|
|
474
|
-
rules = `@media (min-width: ${breakpoint}) { ${rules} }`;
|
|
475
|
-
}
|
|
476
|
-
css += rules;
|
|
477
|
-
}
|
|
478
|
-
|
|
479
|
-
return css;
|
|
480
|
-
}
|
|
481
|
-
|
|
482
361
|
/**
|
|
483
362
|
* @param {typeof SHAPE_ROUNDED_DEFAULT} config
|
|
484
363
|
* @return {string}
|
package/utils/svg.js
CHANGED
|
@@ -1,120 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @param {string} path
|
|
3
|
-
* @param {Object} [options]
|
|
4
|
-
* @param {number} [options.size=24]
|
|
5
|
-
* @param {boolean} [options.outline] Outline path
|
|
6
|
-
* @return {string}
|
|
7
|
-
*/
|
|
8
|
-
export function pathToSVG(path, options = {}) {
|
|
9
|
-
const svgSize = 24;
|
|
10
|
-
const outline = options.outline;
|
|
11
|
-
/* eslint-disable indent */
|
|
12
|
-
return [
|
|
13
|
-
`<svg xmlns="http://www.w3.org/2000/svg" width="${svgSize}" height="${svgSize}" preserveAspectRatio="none">`,
|
|
14
|
-
outline
|
|
15
|
-
? `
|
|
16
|
-
<mask id="m">
|
|
17
|
-
<rect width="24" height="24" fill="white"/>
|
|
18
|
-
<path fill="black" d="${path}"/>
|
|
19
|
-
</mask>
|
|
20
|
-
<rect width="24" height="24" fill="black" mask="url(#m)"/>
|
|
21
|
-
`
|
|
22
|
-
: `<path fill="black" d="${path}"/>`,
|
|
23
|
-
'</svg>',
|
|
24
|
-
].join('');
|
|
25
|
-
/* eslint-enable indent */
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* @param {string} path
|
|
30
|
-
* @param {Object} [options]
|
|
31
|
-
* @param {number} [options.size=24]
|
|
32
|
-
* @param {boolean} [options.outline] Outline path
|
|
33
|
-
* @return {string}
|
|
34
|
-
*/
|
|
35
|
-
export function maskedPathToSVG(path, options = {}) {
|
|
36
|
-
const svgSize = 24;
|
|
37
|
-
const outline = options.outline;
|
|
38
|
-
/* eslint-disable indent */
|
|
39
|
-
return [
|
|
40
|
-
`<svg xmlns="http://www.w3.org/2000/svg" width="${svgSize}" height="${svgSize}" preserveAspectRatio="none">`,
|
|
41
|
-
outline
|
|
42
|
-
? `
|
|
43
|
-
<defs>
|
|
44
|
-
<path id="p" d="${path}"/>
|
|
45
|
-
</defs>
|
|
46
|
-
<mask id="m">
|
|
47
|
-
<use href="#p" fill="white"/>
|
|
48
|
-
<use href="#p" fill="black" transform="scale(0.9166666666666667) translate(1 1)"/>
|
|
49
|
-
</mask>
|
|
50
|
-
<use href="#p" fill="black" mask="url(#m)"/>
|
|
51
|
-
`
|
|
52
|
-
: `<path fill="black" d="${path}"/>`,
|
|
53
|
-
'</svg>',
|
|
54
|
-
].join('');
|
|
55
|
-
/* eslint-enable indent */
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* @param {string} path
|
|
60
|
-
* @param {Object} [options]
|
|
61
|
-
* @param {number} [options.size=24]
|
|
62
|
-
* @param {string} [options.outline] Outline path
|
|
63
|
-
* @return {string}
|
|
64
|
-
*/
|
|
65
|
-
export function auto9SliceSVG(path, options = {}) {
|
|
66
|
-
const pathSize = options.size ?? 24;
|
|
67
|
-
const svgSize = 24;
|
|
68
|
-
const outline = options.outline;
|
|
69
|
-
/* eslint-disable indent */
|
|
70
|
-
return [
|
|
71
|
-
`<svg xmlns="http://www.w3.org/2000/svg" width="${svgSize}" height="${svgSize}">`,
|
|
72
|
-
'<defs>',
|
|
73
|
-
`<path id="p" d="${path}"/>`,
|
|
74
|
-
'<g id="g">',
|
|
75
|
-
'<use href="#p" transform="translate(0 0)"/>',
|
|
76
|
-
`<use href="#p" transform="translate(${svgSize - pathSize} 0)"/>`,
|
|
77
|
-
`<use href="#p" transform="translate(${svgSize - pathSize} ${svgSize - pathSize})"/>`,
|
|
78
|
-
`<use href="#p" transform="translate(0 ${svgSize - pathSize})"/>`,
|
|
79
|
-
'<path d="',
|
|
80
|
-
`M${pathSize / 2} 0`,
|
|
81
|
-
`H${svgSize - (pathSize / 2)}`,
|
|
82
|
-
`V${pathSize / 2}`,
|
|
83
|
-
`H${svgSize}`,
|
|
84
|
-
`V${svgSize - (pathSize / 2)}`,
|
|
85
|
-
`H${svgSize - (pathSize / 2)}`,
|
|
86
|
-
`V${svgSize}`,
|
|
87
|
-
`H${pathSize / 2}`,
|
|
88
|
-
`V${svgSize - (pathSize / 2)}`,
|
|
89
|
-
'H0',
|
|
90
|
-
`V${pathSize / 2}`,
|
|
91
|
-
`H${pathSize / 2}`,
|
|
92
|
-
'Z',
|
|
93
|
-
'"/>',
|
|
94
|
-
'</g>',
|
|
95
|
-
'</defs>',
|
|
96
|
-
outline
|
|
97
|
-
? [
|
|
98
|
-
'<mask id="m">',
|
|
99
|
-
'<use href="#g" fill="white"/>',
|
|
100
|
-
`<use href="#g" fill="black" transform="scale(0.5) translate(${pathSize / 2} ${pathSize / 2})" />`,
|
|
101
|
-
`<use href="#g" fill="black" transform="scale(0.5) translate(${svgSize - (pathSize / 2)} ${pathSize / 2})" />`,
|
|
102
|
-
`<use href="#g" fill="black" transform="scale(0.5) translate(${svgSize - (pathSize / 2)} ${svgSize - (pathSize / 2)})" />`,
|
|
103
|
-
`<use href="#g" fill="black" transform="scale(0.5) translate(${pathSize / 2} ${svgSize - (pathSize / 2)})" />`,
|
|
104
|
-
'</mask>',
|
|
105
|
-
'<path d="',
|
|
106
|
-
'M0 0',
|
|
107
|
-
`H${svgSize}`,
|
|
108
|
-
`V${svgSize}`,
|
|
109
|
-
'H0',
|
|
110
|
-
'Z',
|
|
111
|
-
'" fill="black" mask="url(#m)"/>',
|
|
112
|
-
].join('') : '<use href="#g" fill="black"/>',
|
|
113
|
-
'</svg>',
|
|
114
|
-
].join('');
|
|
115
|
-
/* eslint-enable indent */
|
|
116
|
-
}
|
|
117
|
-
|
|
118
1
|
/**
|
|
119
2
|
* Uses UTF-8 charset instead of base64 for better compression
|
|
120
3
|
* @param {string} svg
|