storybook-vrhythm 0.0.4 → 0.2.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/README.md CHANGED
@@ -1,81 +1,151 @@
1
- [![Last Commit][last-commit-badge]][last-commit]
2
- [![Travis][build-badge]][build]
1
+ # 📐 storybook-vrhythm
2
+
3
3
  [![npm package][npm-badge]][npm]
4
+ [![License: MIT][license-badge]][license]
5
+ [![Bundle Size](https://img.shields.io/bundlephobia/minzip/storybook-vrhythm)](https://bundlephobia.com/package/storybook-vrhythm)
4
6
 
5
- [last-commit-badge]: https://img.shields.io/github/last-commit/jmlweb/storybook-vrhythm.svg
6
- [last-commit]: https://github.com/jmlweb/storybook-vrhythm
7
- [build-badge]: https://img.shields.io/travis/jmlweb/storybook-vrhythm/master.png?style=flat-square
8
- [build]: https://travis-ci.org/jmlweb/storybook-vrhythm
9
- [npm-badge]: https://img.shields.io/npm/v/storybook-vrhythm.png?style=flat-square
10
- [npm]: https://www.npmjs.org/package/storybook-vrhythm
7
+ **A Storybook decorator that overlays vertical rhythm guide lines on your stories.**
8
+ Verify that your components align to a baseline grid — with zero effort.
9
+
10
+ ![Vertical rhythm overlay example](storybook-vrhythm.jpg)
11
+
12
+ ## âœĻ Features
13
+
14
+ - ðŸŽŊ **Framework agnostic** — Works with React, Vue, Angular, Svelte, and any Storybook-supported framework
15
+ - ðŸŽĻ **Fully customizable** — Color, line height, offset, and visibility per story
16
+ - ðŸŠķ **Lightweight** — Pure CSS overlay using `linear-gradient` (no images, no canvas)
17
+ - ðŸ–ąïļ **Non-intrusive** — Overlay doesn't interfere with pointer events
18
+ - ⚡ **Zero config** — Works out of the box with sensible defaults
19
+
20
+ ## ðŸ“Ķ Installation
21
+
22
+ <details open>
23
+ <summary><strong>pnpm</strong></summary>
24
+
25
+ ```bash
26
+ pnpm add -D storybook-vrhythm
27
+ ```
28
+
29
+ </details>
30
+
31
+ <details>
32
+ <summary><strong>npm</strong></summary>
33
+
34
+ ```bash
35
+ npm install --save-dev storybook-vrhythm
36
+ ```
37
+
38
+ </details>
11
39
 
12
- # Storybook Vertical Rhythm Decorator
40
+ <details>
41
+ <summary><strong>yarn</strong></summary>
13
42
 
14
- Take an eye over the vertical rhythm of your stories with this decorator.
43
+ ```bash
44
+ yarn add -D storybook-vrhythm
45
+ ```
46
+
47
+ </details>
15
48
 
16
- It should work with any framework/library, however it's only tested in a React environment for the moment.
49
+ ## 🚀 Usage
17
50
 
18
- ![](storybook-vrhythm.jpg)
51
+ This package is a **Storybook preset addon**: you can register it in `main` (recommended) or add the decorator manually in `preview`.
19
52
 
20
- ## Installation
53
+ **Requirements:** Node.js 18+ and Storybook 8 or newer (see `peerDependencies` in `package.json`).
21
54
 
22
- `npm install storybook-vrhythm --development`
55
+ ### Register as an addon (recommended)
23
56
 
24
- or
57
+ Add the package to `addons` in `.storybook/main.ts` (or `main.js`). Storybook loads the preset and applies the vertical rhythm decorator in the preview iframe.
25
58
 
26
- `yarn add -D storybook-rhythm`
59
+ ```typescript
60
+ import type { StorybookConfig } from '@storybook/react-vite'; // or your framework package
27
61
 
28
- ## Using the decorator globally
62
+ const config = {
63
+ addons: ['storybook-vrhythm'],
64
+ } satisfies StorybookConfig;
29
65
 
30
- ```js
31
- import { addDecorator, addParameters } from '@storybook/react'; // or Vue, Angular...
32
- import StorybookVRhythm from 'storybook-vrhythm';
66
+ export default config;
67
+ ```
33
68
 
34
- addDecorator(StorybookVRhythm);
69
+ Optional defaults and overrides still use `parameters.vrhythm` in `.storybook/preview.ts`:
35
70
 
36
- addParameters({
71
+ ```typescript
72
+ export const parameters = {
37
73
  vrhythm: {
38
- color: 'rgba(178,86,18,0.5)',
74
+ color: 'rgba(178, 86, 18, 0.5)',
39
75
  lineHeight: '16px',
40
76
  offset: 0,
41
77
  },
42
- });
78
+ };
43
79
  ```
44
80
 
45
- ## Using the decorator in your stories
81
+ ### Manual decorator
82
+
83
+ If you prefer not to use the preset, import the decorator in `.storybook/preview.ts`:
46
84
 
47
- ```jsx
48
- const stories = storiesOf('components|MyComponent', module);
85
+ ```typescript
86
+ import { withVRhythm } from 'storybook-vrhythm';
49
87
 
50
- stories.addParameters({ vrhythm: { hide: true } });
88
+ export const decorators = [withVRhythm];
89
+
90
+ export const parameters = {
91
+ vrhythm: {
92
+ color: 'rgba(178, 86, 18, 0.5)',
93
+ lineHeight: '16px',
94
+ offset: 0,
95
+ },
96
+ };
51
97
  ```
52
98
 
53
- ## Available options
99
+ ### Per-story configuration
54
100
 
55
- ### color
101
+ Override or hide the overlay on individual stories:
56
102
 
57
- Any valid color for the lines (examples: #ff0000, rgba(0,0,0,0.3))
103
+ ```typescript
104
+ export const MyStory = {
105
+ parameters: {
106
+ vrhythm: {
107
+ hide: true,
108
+ },
109
+ },
110
+ };
111
+ ```
58
112
 
59
- default: `'rgb(204, 204, 204)'`
113
+ ## ⚙ïļ Options
60
114
 
61
- ### lineHeight
115
+ | Option | Type | Default | Description |
116
+ | ------------ | ------------------ | ---------------------- | ------------------------------------------ |
117
+ | `color` | `string` | `'rgb(204, 204, 204)'` | Any valid CSS color for the guide lines |
118
+ | `lineHeight` | `string \| number` | `'16px'` | Baseline grid height (e.g. `16px`, `1rem`) |
119
+ | `offset` | `string \| number` | `0` | Vertical offset from the top |
120
+ | `hide` | `boolean` | `false` | Hide the overlay for specific stories |
62
121
 
63
- Any valid value for the lineHeight of your system (examples: 16px, 1rem...)
122
+ ## ðŸ’Ą Why vertical rhythm?
64
123
 
65
- default: `16px`
124
+ Vertical rhythm is the practice of spacing elements on a page based on a consistent baseline grid. It improves readability and creates a sense of visual harmony. This decorator lets you **see** the grid while developing, so you can catch alignment issues before they reach production.
66
125
 
67
- ### offset
126
+ ## 🛠ïļ Development
68
127
 
69
- The offset from the top, in case your component is wrapped or whatever.
128
+ ```bash
129
+ pnpm install # Install dependencies
130
+ pnpm build # Build the package
131
+ pnpm test # Run tests
132
+ pnpm lint # Lint source code
133
+ pnpm format # Format with Prettier
134
+ ```
135
+
136
+ ## ðŸĪ Contributing
70
137
 
71
- default: `0`
138
+ Contributions are welcome! Feel free to open an [issue](https://github.com/jmlweb/storybook-vrhythm/issues) or submit a pull request.
72
139
 
73
- ### hide
140
+ ## 🙏 Inspiration
74
141
 
75
- Useful to hide the decorator in some stories
142
+ [Baseliner](https://jpedroribeiro.com/2015/08/baseliner-my-first-chrome-extension/) — a Chrome extension by JP Ribeiro for overlaying baseline grids.
76
143
 
77
- default: `false`
144
+ ## 📄 License
78
145
 
79
- ## Inspiration
146
+ [MIT](LICENSE)
80
147
 
81
- [Baseliner extension](https://jpedroribeiro.com/2015/08/baseliner-my-first-chrome-extension/)
148
+ [npm-badge]: https://img.shields.io/npm/v/storybook-vrhythm.svg
149
+ [npm]: https://www.npmjs.org/package/storybook-vrhythm
150
+ [license-badge]: https://img.shields.io/badge/license-MIT-blue.svg
151
+ [license]: https://github.com/jmlweb/storybook-vrhythm/blob/master/LICENSE
package/dist/index.d.ts CHANGED
@@ -1,2 +1,15 @@
1
- declare const _default: (...args: any) => any;
2
- export default _default;
1
+ import { DecoratorFunction } from '@storybook/types';
2
+
3
+ interface StyleProps {
4
+ color?: string;
5
+ lineHeight?: string | number;
6
+ offset?: string | number;
7
+ }
8
+ interface ConfigProps {
9
+ hide?: boolean;
10
+ }
11
+
12
+ type VRhythmParams = StyleProps & ConfigProps;
13
+ declare const withVRhythm: DecoratorFunction;
14
+
15
+ export { type ConfigProps, type StyleProps, type VRhythmParams, withVRhythm };
package/dist/index.js CHANGED
@@ -1,8 +1,76 @@
1
+ // src/constants.ts
2
+ var DEFAULT_COLOR = "rgb(204, 204, 204)";
3
+ var DEFAULT_LINE_HEIGHT = "16px";
4
+ var DEFAULT_OFFSET = 0;
5
+ var PARENT_SELECTOR = "body";
6
+ var DIV_ID = "storybook-rhythm";
1
7
 
2
- 'use strict'
8
+ // src/getStyle.ts
9
+ var getStyle = ({
10
+ color = DEFAULT_COLOR,
11
+ lineHeight = DEFAULT_LINE_HEIGHT,
12
+ offset = DEFAULT_OFFSET
13
+ }) => ({
14
+ position: "absolute",
15
+ top: offset,
16
+ left: 0,
17
+ right: 0,
18
+ bottom: 0,
19
+ background: `linear-gradient(${color} 1px, transparent 1px) left top / 1px ${lineHeight}`,
20
+ pointerEvents: "none"
21
+ });
3
22
 
4
- if (process.env.NODE_ENV === 'production') {
5
- module.exports = require('./storybook-vrhythm.cjs.production.min.js')
6
- } else {
7
- module.exports = require('./storybook-vrhythm.cjs.development.js')
23
+ // src/utils.ts
24
+ function createElement() {
25
+ const element = document.createElement("div");
26
+ element.setAttribute("id", DIV_ID);
27
+ return element;
8
28
  }
29
+ function getOrCreateElement() {
30
+ const existing = document.getElementById(DIV_ID);
31
+ if (existing) {
32
+ return existing;
33
+ }
34
+ return createElement();
35
+ }
36
+ function removeElement() {
37
+ const element = document.getElementById(DIV_ID);
38
+ if (element) {
39
+ element.remove();
40
+ }
41
+ }
42
+ function injectStyle(style) {
43
+ const element = getOrCreateElement();
44
+ Object.assign(element.style, style);
45
+ if (!element.parentNode) {
46
+ const parent = document.querySelector(PARENT_SELECTOR);
47
+ if (parent) {
48
+ parent.append(element);
49
+ }
50
+ }
51
+ }
52
+
53
+ // src/index.ts
54
+ var DEFAULT_PARAMS = {
55
+ hide: false,
56
+ color: DEFAULT_COLOR,
57
+ lineHeight: DEFAULT_LINE_HEIGHT,
58
+ offset: DEFAULT_OFFSET
59
+ };
60
+ var withVRhythm = (storyFn, context) => {
61
+ const params = {
62
+ ...DEFAULT_PARAMS,
63
+ ...context.parameters?.vrhythm
64
+ };
65
+ if (params.hide) {
66
+ removeElement();
67
+ } else {
68
+ const style = getStyle(params);
69
+ injectStyle(style);
70
+ }
71
+ return storyFn(context);
72
+ };
73
+
74
+ export { withVRhythm };
75
+ //# sourceMappingURL=index.js.map
76
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/constants.ts","../src/getStyle.ts","../src/utils.ts","../src/index.ts"],"names":[],"mappings":";AAAO,IAAM,aAAA,GAAgB,oBAAA;AACtB,IAAM,mBAAA,GAAsB,MAAA;AAC5B,IAAM,cAAA,GAAiB,CAAA;AACvB,IAAM,eAAA,GAAkB,MAAA;AACxB,IAAM,MAAA,GAAS,kBAAA;;;ACGf,IAAM,WAAW,CAAC;AAAA,EACvB,KAAA,GAAQ,aAAA;AAAA,EACR,UAAA,GAAa,mBAAA;AAAA,EACb,MAAA,GAAS;AACX,CAAA,MAA6B;AAAA,EAC3B,QAAA,EAAU,UAAA;AAAA,EACV,GAAA,EAAK,MAAA;AAAA,EACL,IAAA,EAAM,CAAA;AAAA,EACN,KAAA,EAAO,CAAA;AAAA,EACP,MAAA,EAAQ,CAAA;AAAA,EACR,UAAA,EAAY,CAAA,gBAAA,EAAmB,KAAK,CAAA,sCAAA,EAAyC,UAAU,CAAA,CAAA;AAAA,EACvF,aAAA,EAAe;AACjB,CAAA,CAAA;;;AChBA,SAAS,aAAA,GAAgC;AACvC,EAAA,MAAM,OAAA,GAAU,QAAA,CAAS,aAAA,CAAc,KAAK,CAAA;AAC5C,EAAA,OAAA,CAAQ,YAAA,CAAa,MAAM,MAAM,CAAA;AACjC,EAAA,OAAO,OAAA;AACT;AAEA,SAAS,kBAAA,GAAqC;AAC5C,EAAA,MAAM,QAAA,GAAW,QAAA,CAAS,cAAA,CAAe,MAAM,CAAA;AAC/C,EAAA,IAAI,QAAA,EAAU;AACZ,IAAA,OAAO,QAAA;AAAA,EACT;AACA,EAAA,OAAO,aAAA,EAAc;AACvB;AAEO,SAAS,aAAA,GAAsB;AACpC,EAAA,MAAM,OAAA,GAAU,QAAA,CAAS,cAAA,CAAe,MAAM,CAAA;AAC9C,EAAA,IAAI,OAAA,EAAS;AACX,IAAA,OAAA,CAAQ,MAAA,EAAO;AAAA,EACjB;AACF;AAEO,SAAS,YAAY,KAAA,EAAuB;AACjD,EAAA,MAAM,UAAU,kBAAA,EAAmB;AACnC,EAAA,MAAA,CAAO,MAAA,CAAO,OAAA,CAAQ,KAAA,EAAO,KAAK,CAAA;AAElC,EAAA,IAAI,CAAC,QAAQ,UAAA,EAAY;AACvB,IAAA,MAAM,MAAA,GAAS,QAAA,CAAS,aAAA,CAAc,eAAe,CAAA;AACrD,IAAA,IAAI,MAAA,EAAQ;AACV,MAAA,MAAA,CAAO,OAAO,OAAO,CAAA;AAAA,IACvB;AAAA,EACF;AACF;;;ACrBA,IAAM,cAAA,GAA0C;AAAA,EAC9C,IAAA,EAAM,KAAA;AAAA,EACN,KAAA,EAAO,aAAA;AAAA,EACP,UAAA,EAAY,mBAAA;AAAA,EACZ,MAAA,EAAQ;AACV,CAAA;AAEO,IAAM,WAAA,GAAiC,CAAC,OAAA,EAAS,OAAA,KAAY;AAClE,EAAA,MAAM,MAAA,GAAkC;AAAA,IACtC,GAAG,cAAA;AAAA,IACH,GAAI,QAAQ,UAAA,EAAwD;AAAA,GACtE;AAEA,EAAA,IAAI,OAAO,IAAA,EAAM;AACf,IAAA,aAAA,EAAc;AAAA,EAChB,CAAA,MAAO;AACL,IAAA,MAAM,KAAA,GAAQ,SAAS,MAAM,CAAA;AAC7B,IAAA,WAAA,CAAY,KAAK,CAAA;AAAA,EACnB;AAEA,EAAA,OAAO,QAAQ,OAAO,CAAA;AACxB","file":"index.js","sourcesContent":["export const DEFAULT_COLOR = 'rgb(204, 204, 204)';\nexport const DEFAULT_LINE_HEIGHT = '16px';\nexport const DEFAULT_OFFSET = 0;\nexport const PARENT_SELECTOR = 'body';\nexport const DIV_ID = 'storybook-rhythm';\n","import { StyleObj, StyleProps } from './types';\nimport {\n DEFAULT_COLOR,\n DEFAULT_LINE_HEIGHT,\n DEFAULT_OFFSET,\n} from './constants';\n\nexport const getStyle = ({\n color = DEFAULT_COLOR,\n lineHeight = DEFAULT_LINE_HEIGHT,\n offset = DEFAULT_OFFSET,\n}: StyleProps): StyleObj => ({\n position: 'absolute',\n top: offset,\n left: 0,\n right: 0,\n bottom: 0,\n background: `linear-gradient(${color} 1px, transparent 1px) left top / 1px ${lineHeight}`,\n pointerEvents: 'none',\n});\n","import { PARENT_SELECTOR, DIV_ID } from './constants';\nimport { StyleObj } from './types';\n\nfunction createElement(): HTMLDivElement {\n const element = document.createElement('div');\n element.setAttribute('id', DIV_ID);\n return element;\n}\n\nfunction getOrCreateElement(): HTMLDivElement {\n const existing = document.getElementById(DIV_ID) as HTMLDivElement | null;\n if (existing) {\n return existing;\n }\n return createElement();\n}\n\nexport function removeElement(): void {\n const element = document.getElementById(DIV_ID);\n if (element) {\n element.remove();\n }\n}\n\nexport function injectStyle(style: StyleObj): void {\n const element = getOrCreateElement();\n Object.assign(element.style, style);\n\n if (!element.parentNode) {\n const parent = document.querySelector(PARENT_SELECTOR);\n if (parent) {\n parent.append(element);\n }\n }\n}\n","import type { DecoratorFunction } from '@storybook/types';\n\nimport { getStyle } from './getStyle';\nimport { StyleProps, ConfigProps } from './types';\nimport { injectStyle, removeElement } from './utils';\nimport {\n DEFAULT_COLOR,\n DEFAULT_LINE_HEIGHT,\n DEFAULT_OFFSET,\n} from './constants';\n\nexport type VRhythmParams = StyleProps & ConfigProps;\n\nconst DEFAULT_PARAMS: Required<VRhythmParams> = {\n hide: false,\n color: DEFAULT_COLOR,\n lineHeight: DEFAULT_LINE_HEIGHT,\n offset: DEFAULT_OFFSET,\n};\n\nexport const withVRhythm: DecoratorFunction = (storyFn, context) => {\n const params: Required<VRhythmParams> = {\n ...DEFAULT_PARAMS,\n ...(context.parameters as { vrhythm?: VRhythmParams } | undefined)?.vrhythm,\n };\n\n if (params.hide) {\n removeElement();\n } else {\n const style = getStyle(params);\n injectStyle(style);\n }\n\n return storyFn(context);\n};\n\nexport type { StyleProps, ConfigProps } from './types';\n"]}
package/dist/preset.js ADDED
@@ -0,0 +1,11 @@
1
+ // src/preset.ts
2
+ import { dirname, join } from "path";
3
+ import { fileURLToPath } from "url";
4
+ var dir = dirname(fileURLToPath(import.meta.url));
5
+ function previewAnnotations(entry = []) {
6
+ return [...entry, join(dir, "preview.js")];
7
+ }
8
+ export {
9
+ previewAnnotations
10
+ };
11
+ //# sourceMappingURL=preset.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/preset.ts"],"sourcesContent":["import { dirname, join } from 'node:path';\nimport { fileURLToPath } from 'node:url';\n\nconst dir = dirname(fileURLToPath(import.meta.url));\n\nexport function previewAnnotations(entry: string[] = []) {\n return [...entry, join(dir, 'preview.js')];\n}\n"],"mappings":";AAAA,SAAS,SAAS,YAAY;AAC9B,SAAS,qBAAqB;AAE9B,IAAM,MAAM,QAAQ,cAAc,YAAY,GAAG,CAAC;AAE3C,SAAS,mBAAmB,QAAkB,CAAC,GAAG;AACvD,SAAO,CAAC,GAAG,OAAO,KAAK,KAAK,YAAY,CAAC;AAC3C;","names":[]}
@@ -0,0 +1,5 @@
1
+ import { ProjectAnnotations, Renderer } from '@storybook/types';
2
+
3
+ declare const preview: ProjectAnnotations<Renderer>;
4
+
5
+ export { preview as default };
@@ -0,0 +1,82 @@
1
+ // src/constants.ts
2
+ var DEFAULT_COLOR = "rgb(204, 204, 204)";
3
+ var DEFAULT_LINE_HEIGHT = "16px";
4
+ var DEFAULT_OFFSET = 0;
5
+ var PARENT_SELECTOR = "body";
6
+ var DIV_ID = "storybook-rhythm";
7
+
8
+ // src/getStyle.ts
9
+ var getStyle = ({
10
+ color = DEFAULT_COLOR,
11
+ lineHeight = DEFAULT_LINE_HEIGHT,
12
+ offset = DEFAULT_OFFSET
13
+ }) => ({
14
+ position: "absolute",
15
+ top: offset,
16
+ left: 0,
17
+ right: 0,
18
+ bottom: 0,
19
+ background: `linear-gradient(${color} 1px, transparent 1px) left top / 1px ${lineHeight}`,
20
+ pointerEvents: "none"
21
+ });
22
+
23
+ // src/utils.ts
24
+ function createElement() {
25
+ const element = document.createElement("div");
26
+ element.setAttribute("id", DIV_ID);
27
+ return element;
28
+ }
29
+ function getOrCreateElement() {
30
+ const existing = document.getElementById(DIV_ID);
31
+ if (existing) {
32
+ return existing;
33
+ }
34
+ return createElement();
35
+ }
36
+ function removeElement() {
37
+ const element = document.getElementById(DIV_ID);
38
+ if (element) {
39
+ element.remove();
40
+ }
41
+ }
42
+ function injectStyle(style) {
43
+ const element = getOrCreateElement();
44
+ Object.assign(element.style, style);
45
+ if (!element.parentNode) {
46
+ const parent = document.querySelector(PARENT_SELECTOR);
47
+ if (parent) {
48
+ parent.append(element);
49
+ }
50
+ }
51
+ }
52
+
53
+ // src/index.ts
54
+ var DEFAULT_PARAMS = {
55
+ hide: false,
56
+ color: DEFAULT_COLOR,
57
+ lineHeight: DEFAULT_LINE_HEIGHT,
58
+ offset: DEFAULT_OFFSET
59
+ };
60
+ var withVRhythm = (storyFn, context) => {
61
+ const params = {
62
+ ...DEFAULT_PARAMS,
63
+ ...context.parameters?.vrhythm
64
+ };
65
+ if (params.hide) {
66
+ removeElement();
67
+ } else {
68
+ const style = getStyle(params);
69
+ injectStyle(style);
70
+ }
71
+ return storyFn(context);
72
+ };
73
+
74
+ // src/preview.ts
75
+ var preview = {
76
+ decorators: [withVRhythm]
77
+ };
78
+ var preview_default = preview;
79
+
80
+ export { preview_default as default };
81
+ //# sourceMappingURL=preview.js.map
82
+ //# sourceMappingURL=preview.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/constants.ts","../src/getStyle.ts","../src/utils.ts","../src/index.ts","../src/preview.ts"],"names":[],"mappings":";AAAO,IAAM,aAAA,GAAgB,oBAAA;AACtB,IAAM,mBAAA,GAAsB,MAAA;AAC5B,IAAM,cAAA,GAAiB,CAAA;AACvB,IAAM,eAAA,GAAkB,MAAA;AACxB,IAAM,MAAA,GAAS,kBAAA;;;ACGf,IAAM,WAAW,CAAC;AAAA,EACvB,KAAA,GAAQ,aAAA;AAAA,EACR,UAAA,GAAa,mBAAA;AAAA,EACb,MAAA,GAAS;AACX,CAAA,MAA6B;AAAA,EAC3B,QAAA,EAAU,UAAA;AAAA,EACV,GAAA,EAAK,MAAA;AAAA,EACL,IAAA,EAAM,CAAA;AAAA,EACN,KAAA,EAAO,CAAA;AAAA,EACP,MAAA,EAAQ,CAAA;AAAA,EACR,UAAA,EAAY,CAAA,gBAAA,EAAmB,KAAK,CAAA,sCAAA,EAAyC,UAAU,CAAA,CAAA;AAAA,EACvF,aAAA,EAAe;AACjB,CAAA,CAAA;;;AChBA,SAAS,aAAA,GAAgC;AACvC,EAAA,MAAM,OAAA,GAAU,QAAA,CAAS,aAAA,CAAc,KAAK,CAAA;AAC5C,EAAA,OAAA,CAAQ,YAAA,CAAa,MAAM,MAAM,CAAA;AACjC,EAAA,OAAO,OAAA;AACT;AAEA,SAAS,kBAAA,GAAqC;AAC5C,EAAA,MAAM,QAAA,GAAW,QAAA,CAAS,cAAA,CAAe,MAAM,CAAA;AAC/C,EAAA,IAAI,QAAA,EAAU;AACZ,IAAA,OAAO,QAAA;AAAA,EACT;AACA,EAAA,OAAO,aAAA,EAAc;AACvB;AAEO,SAAS,aAAA,GAAsB;AACpC,EAAA,MAAM,OAAA,GAAU,QAAA,CAAS,cAAA,CAAe,MAAM,CAAA;AAC9C,EAAA,IAAI,OAAA,EAAS;AACX,IAAA,OAAA,CAAQ,MAAA,EAAO;AAAA,EACjB;AACF;AAEO,SAAS,YAAY,KAAA,EAAuB;AACjD,EAAA,MAAM,UAAU,kBAAA,EAAmB;AACnC,EAAA,MAAA,CAAO,MAAA,CAAO,OAAA,CAAQ,KAAA,EAAO,KAAK,CAAA;AAElC,EAAA,IAAI,CAAC,QAAQ,UAAA,EAAY;AACvB,IAAA,MAAM,MAAA,GAAS,QAAA,CAAS,aAAA,CAAc,eAAe,CAAA;AACrD,IAAA,IAAI,MAAA,EAAQ;AACV,MAAA,MAAA,CAAO,OAAO,OAAO,CAAA;AAAA,IACvB;AAAA,EACF;AACF;;;ACrBA,IAAM,cAAA,GAA0C;AAAA,EAC9C,IAAA,EAAM,KAAA;AAAA,EACN,KAAA,EAAO,aAAA;AAAA,EACP,UAAA,EAAY,mBAAA;AAAA,EACZ,MAAA,EAAQ;AACV,CAAA;AAEO,IAAM,WAAA,GAAiC,CAAC,OAAA,EAAS,OAAA,KAAY;AAClE,EAAA,MAAM,MAAA,GAAkC;AAAA,IACtC,GAAG,cAAA;AAAA,IACH,GAAI,QAAQ,UAAA,EAAwD;AAAA,GACtE;AAEA,EAAA,IAAI,OAAO,IAAA,EAAM;AACf,IAAA,aAAA,EAAc;AAAA,EAChB,CAAA,MAAO;AACL,IAAA,MAAM,KAAA,GAAQ,SAAS,MAAM,CAAA;AAC7B,IAAA,WAAA,CAAY,KAAK,CAAA;AAAA,EACnB;AAEA,EAAA,OAAO,QAAQ,OAAO,CAAA;AACxB,CAAA;;;AC9BA,IAAM,OAAA,GAAwC;AAAA,EAC5C,UAAA,EAAY,CAAC,WAAW;AAC1B,CAAA;AAEA,IAAO,eAAA,GAAQ","file":"preview.js","sourcesContent":["export const DEFAULT_COLOR = 'rgb(204, 204, 204)';\nexport const DEFAULT_LINE_HEIGHT = '16px';\nexport const DEFAULT_OFFSET = 0;\nexport const PARENT_SELECTOR = 'body';\nexport const DIV_ID = 'storybook-rhythm';\n","import { StyleObj, StyleProps } from './types';\nimport {\n DEFAULT_COLOR,\n DEFAULT_LINE_HEIGHT,\n DEFAULT_OFFSET,\n} from './constants';\n\nexport const getStyle = ({\n color = DEFAULT_COLOR,\n lineHeight = DEFAULT_LINE_HEIGHT,\n offset = DEFAULT_OFFSET,\n}: StyleProps): StyleObj => ({\n position: 'absolute',\n top: offset,\n left: 0,\n right: 0,\n bottom: 0,\n background: `linear-gradient(${color} 1px, transparent 1px) left top / 1px ${lineHeight}`,\n pointerEvents: 'none',\n});\n","import { PARENT_SELECTOR, DIV_ID } from './constants';\nimport { StyleObj } from './types';\n\nfunction createElement(): HTMLDivElement {\n const element = document.createElement('div');\n element.setAttribute('id', DIV_ID);\n return element;\n}\n\nfunction getOrCreateElement(): HTMLDivElement {\n const existing = document.getElementById(DIV_ID) as HTMLDivElement | null;\n if (existing) {\n return existing;\n }\n return createElement();\n}\n\nexport function removeElement(): void {\n const element = document.getElementById(DIV_ID);\n if (element) {\n element.remove();\n }\n}\n\nexport function injectStyle(style: StyleObj): void {\n const element = getOrCreateElement();\n Object.assign(element.style, style);\n\n if (!element.parentNode) {\n const parent = document.querySelector(PARENT_SELECTOR);\n if (parent) {\n parent.append(element);\n }\n }\n}\n","import type { DecoratorFunction } from '@storybook/types';\n\nimport { getStyle } from './getStyle';\nimport { StyleProps, ConfigProps } from './types';\nimport { injectStyle, removeElement } from './utils';\nimport {\n DEFAULT_COLOR,\n DEFAULT_LINE_HEIGHT,\n DEFAULT_OFFSET,\n} from './constants';\n\nexport type VRhythmParams = StyleProps & ConfigProps;\n\nconst DEFAULT_PARAMS: Required<VRhythmParams> = {\n hide: false,\n color: DEFAULT_COLOR,\n lineHeight: DEFAULT_LINE_HEIGHT,\n offset: DEFAULT_OFFSET,\n};\n\nexport const withVRhythm: DecoratorFunction = (storyFn, context) => {\n const params: Required<VRhythmParams> = {\n ...DEFAULT_PARAMS,\n ...(context.parameters as { vrhythm?: VRhythmParams } | undefined)?.vrhythm,\n };\n\n if (params.hide) {\n removeElement();\n } else {\n const style = getStyle(params);\n injectStyle(style);\n }\n\n return storyFn(context);\n};\n\nexport type { StyleProps, ConfigProps } from './types';\n","import type { ProjectAnnotations, Renderer } from '@storybook/types';\n\nimport { withVRhythm } from './index';\n\nconst preview: ProjectAnnotations<Renderer> = {\n decorators: [withVRhythm],\n};\n\nexport default preview;\n"]}
package/package.json CHANGED
@@ -1,24 +1,65 @@
1
1
  {
2
2
  "name": "storybook-vrhythm",
3
- "version": "0.0.4",
4
- "description": "Storybook Vertical Rhythm Decorator",
3
+ "version": "0.2.0",
4
+ "description": "Storybook decorator and preset addon for vertical rhythm baseline guides",
5
+ "license": "MIT",
6
+ "author": "jmlweb",
5
7
  "homepage": "https://github.com/jmlweb/storybook-vrhythm",
6
- "main": "dist/index.js",
7
- "umd:main": "dist/storybook-vrhythm.umd.production.js",
8
- "module": "dist/storybook-vrhythm.es.production.js",
9
- "typings": "dist/index.d.ts",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "https://github.com/jmlweb/storybook-vrhythm.git"
11
+ },
12
+ "keywords": [
13
+ "storybook-addon",
14
+ "style",
15
+ "debug",
16
+ "layout",
17
+ "baseline",
18
+ "vertical-rhythm",
19
+ "storybook",
20
+ "decorator"
21
+ ],
22
+ "type": "module",
23
+ "main": "./dist/index.js",
24
+ "module": "./dist/index.js",
25
+ "types": "./dist/index.d.ts",
26
+ "exports": {
27
+ ".": {
28
+ "types": "./dist/index.d.ts",
29
+ "import": "./dist/index.js",
30
+ "default": "./dist/index.js"
31
+ },
32
+ "./preview": {
33
+ "types": "./dist/preview.d.ts",
34
+ "import": "./dist/preview.js",
35
+ "default": "./dist/preview.js"
36
+ },
37
+ "./preset": "./dist/preset.js",
38
+ "./package.json": "./package.json"
39
+ },
10
40
  "files": [
11
- "dist"
41
+ "dist",
42
+ "preset.js"
12
43
  ],
13
- "scripts": {
14
- "start": "tsdx watch",
15
- "build": "tsdx build",
16
- "test": "tsdx test --env=jsdom"
44
+ "engines": {
45
+ "node": ">=20"
46
+ },
47
+ "peerDependencies": {
48
+ "storybook": "^8.0.0 || ^9.0.0 || ^10.0.0"
17
49
  },
18
- "husky": {
19
- "hooks": {
20
- "pre-commit": "pretty-quick --staged"
21
- }
50
+ "storybook": {
51
+ "displayName": "Vertical rhythm",
52
+ "supportedFrameworks": [
53
+ "react",
54
+ "vue",
55
+ "angular",
56
+ "web-components",
57
+ "ember",
58
+ "html",
59
+ "svelte",
60
+ "preact",
61
+ "react-native"
62
+ ]
22
63
  },
23
64
  "prettier": {
24
65
  "printWidth": 80,
@@ -27,16 +68,24 @@
27
68
  "trailingComma": "es5"
28
69
  },
29
70
  "devDependencies": {
30
- "@types/jest": "^25.1.2",
31
- "husky": "^4.2.3",
32
- "prettier": "^1.19.1",
33
- "pretty-quick": "^2.0.1",
34
- "react": "^16.12.0",
35
- "tsdx": "^0.12.3",
36
- "tslib": "^1.10.0",
37
- "typescript": "^3.7.5"
71
+ "@storybook/types": "^8.6.14",
72
+ "@types/node": "^25.5.0",
73
+ "@vitest/coverage-v8": "^4.1.2",
74
+ "jsdom": "^29.0.1",
75
+ "prettier": "^3.5.3",
76
+ "storybook": "^8.6.18",
77
+ "tsup": "^8.5.1",
78
+ "typescript": "^5.9.3",
79
+ "vitest": "^4.1.2"
38
80
  },
39
- "dependencies": {
40
- "@storybook/addons": "5.3.13"
81
+ "scripts": {
82
+ "build": "tsup",
83
+ "dev": "tsup --watch",
84
+ "test": "vitest run",
85
+ "test:watch": "vitest",
86
+ "test:coverage": "vitest run --coverage",
87
+ "lint": "tsc --noEmit",
88
+ "format": "prettier --write 'src/**/*.ts' 'test/**/*.ts'",
89
+ "format:check": "prettier --check 'src/**/*.ts' 'test/**/*.ts'"
41
90
  }
42
- }
91
+ }
package/preset.js ADDED
@@ -0,0 +1 @@
1
+ export * from './dist/preset.js';
@@ -1,5 +0,0 @@
1
- export declare const DEFAULT_COLOR = "rgb(204, 204, 204)";
2
- export declare const DEFAULT_LINE_HEIGHT = "16px";
3
- export declare const DEFAULT_OFFSET = 0;
4
- export declare const PARENT_SELECTOR = "body";
5
- export declare const DIV_ID = "storybook-rhythm";
@@ -1,3 +0,0 @@
1
- import { StyleObj, StyleProps } from './types';
2
- declare const getStyle: ({ color, lineHeight, offset, }: StyleProps) => StyleObj;
3
- export default getStyle;
@@ -1,77 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var addons = require('@storybook/addons');
6
-
7
- var DEFAULT_COLOR = 'rgb(204, 204, 204)';
8
- var DEFAULT_LINE_HEIGHT = '16px';
9
- var DEFAULT_OFFSET = 0;
10
- var PARENT_SELECTOR = 'body';
11
- var DIV_ID = 'storybook-rhythm';
12
-
13
- var getStyle = function getStyle(_ref) {
14
- var _ref$color = _ref.color,
15
- color = _ref$color === void 0 ? DEFAULT_COLOR : _ref$color,
16
- _ref$lineHeight = _ref.lineHeight,
17
- lineHeight = _ref$lineHeight === void 0 ? DEFAULT_LINE_HEIGHT : _ref$lineHeight,
18
- _ref$offset = _ref.offset,
19
- offset = _ref$offset === void 0 ? DEFAULT_OFFSET : _ref$offset;
20
- return {
21
- position: 'absolute',
22
- top: offset,
23
- left: 0,
24
- right: 0,
25
- bottom: 0,
26
- background: "linear-gradient(" + color + " 1px, transparent 1px) left top / 1px " + lineHeight,
27
- pointerEvents: 'none'
28
- };
29
- };
30
-
31
- function createElement() {
32
- var element = document.createElement('div');
33
- element.setAttribute('id', DIV_ID);
34
- return element;
35
- }
36
-
37
- function getOrCreateElement() {
38
- var elementOnDom = document.getElementById(DIV_ID);
39
-
40
- if (elementOnDom) {
41
- return elementOnDom;
42
- }
43
-
44
- return createElement();
45
- }
46
-
47
- function removeElement() {
48
- var elementOnDom = document.getElementById(DIV_ID);
49
- elementOnDom && elementOnDom.parentNode && elementOnDom.parentNode.removeChild(elementOnDom);
50
- }
51
- function injectStyle(style) {
52
- var element = getOrCreateElement();
53
- Object.assign(element.style, style);
54
- var parent = document.querySelector(PARENT_SELECTOR);
55
- parent && parent.append(element);
56
- }
57
-
58
- var index = /*#__PURE__*/
59
- addons.makeDecorator({
60
- name: 'withVRhythm',
61
- parameterName: 'vrhythm',
62
- wrapper: function wrapper(getStory, context, _ref) {
63
- var parameters = _ref.parameters;
64
-
65
- if (parameters.hide) {
66
- removeElement();
67
- } else {
68
- var style = getStyle(parameters);
69
- injectStyle(style);
70
- }
71
-
72
- return getStory(context);
73
- }
74
- });
75
-
76
- exports.default = index;
77
- //# sourceMappingURL=storybook-vrhythm.cjs.development.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"storybook-vrhythm.cjs.development.js","sources":["../src/constants.ts","../src/getStyle.ts","../src/utils.ts","../src/index.tsx"],"sourcesContent":["export const DEFAULT_COLOR = 'rgb(204, 204, 204)';\nexport const DEFAULT_LINE_HEIGHT = '16px';\nexport const DEFAULT_OFFSET = 0;\nexport const PARENT_SELECTOR = 'body';\nexport const DIV_ID = 'storybook-rhythm';\n","import { StyleObj, StyleProps } from './types';\nimport {\n DEFAULT_COLOR,\n DEFAULT_LINE_HEIGHT,\n DEFAULT_OFFSET,\n} from './constants';\n\nconst getStyle = ({\n color = DEFAULT_COLOR,\n lineHeight = DEFAULT_LINE_HEIGHT,\n offset = DEFAULT_OFFSET,\n}: StyleProps): StyleObj => ({\n position: 'absolute',\n top: offset,\n left: 0,\n right: 0,\n bottom: 0,\n background: `linear-gradient(${color} 1px, transparent 1px) left top / 1px ${lineHeight}`,\n pointerEvents: 'none',\n});\n\nexport default getStyle;\n","import { PARENT_SELECTOR, DIV_ID } from './constants';\nimport { StyleObj } from './types';\n\nfunction createElement() {\n const element = document.createElement('div') as HTMLDivElement;\n element.setAttribute('id', DIV_ID);\n return element;\n}\n\nfunction getOrCreateElement() {\n const elementOnDom = document.getElementById(DIV_ID);\n if (elementOnDom) {\n return elementOnDom;\n }\n return createElement();\n}\n\nexport function removeElement() {\n const elementOnDom = document.getElementById(DIV_ID);\n elementOnDom &&\n elementOnDom.parentNode &&\n elementOnDom.parentNode.removeChild(elementOnDom);\n}\n\nexport function injectStyle(style: StyleObj) {\n const element = getOrCreateElement();\n Object.assign(element.style, style);\n const parent = document.querySelector(PARENT_SELECTOR);\n parent && parent.append(element);\n}\n","import { makeDecorator } from '@storybook/addons';\n\nimport getStyle from './getStyle';\nimport { StyleProps, ConfigProps } from './types';\nimport { injectStyle, removeElement } from './utils';\n\ntype Params = StyleProps & ConfigProps;\n\nexport default makeDecorator({\n name: 'withVRhythm',\n parameterName: 'vrhythm',\n wrapper: (getStory, context, { parameters }: { parameters: Params }) => {\n if (parameters.hide) {\n removeElement();\n } else {\n const style = getStyle(parameters);\n injectStyle(style);\n }\n return getStory(context);\n },\n});\n"],"names":["DEFAULT_COLOR","DEFAULT_LINE_HEIGHT","DEFAULT_OFFSET","PARENT_SELECTOR","DIV_ID","getStyle","color","lineHeight","offset","position","top","left","right","bottom","background","pointerEvents","createElement","element","document","setAttribute","getOrCreateElement","elementOnDom","getElementById","removeElement","parentNode","removeChild","injectStyle","style","Object","assign","parent","querySelector","append","makeDecorator","name","parameterName","wrapper","getStory","context","parameters","hide"],"mappings":";;;;;;AAAO,IAAMA,aAAa,GAAG,oBAAtB;AACA,IAAMC,mBAAmB,GAAG,MAA5B;AACA,IAAMC,cAAc,GAAG,CAAvB;AACA,IAAMC,eAAe,GAAG,MAAxB;AACA,IAAMC,MAAM,GAAG,kBAAf;;ACGP,IAAMC,QAAQ,GAAG,SAAXA,QAAW;AAAA,wBACfC,KADe;AAAA,MACfA,KADe,2BACPN,aADO;AAAA,6BAEfO,UAFe;AAAA,MAEfA,UAFe,gCAEFN,mBAFE;AAAA,yBAGfO,MAHe;AAAA,MAGfA,MAHe,4BAGNN,cAHM;AAAA,SAIY;AAC3BO,IAAAA,QAAQ,EAAE,UADiB;AAE3BC,IAAAA,GAAG,EAAEF,MAFsB;AAG3BG,IAAAA,IAAI,EAAE,CAHqB;AAI3BC,IAAAA,KAAK,EAAE,CAJoB;AAK3BC,IAAAA,MAAM,EAAE,CALmB;AAM3BC,IAAAA,UAAU,uBAAqBR,KAArB,8CAAmEC,UANlD;AAO3BQ,IAAAA,aAAa,EAAE;AAPY,GAJZ;AAAA,CAAjB;;ACJA,SAASC,aAAT;AACE,MAAMC,OAAO,GAAGC,QAAQ,CAACF,aAAT,CAAuB,KAAvB,CAAhB;AACAC,EAAAA,OAAO,CAACE,YAAR,CAAqB,IAArB,EAA2Bf,MAA3B;AACA,SAAOa,OAAP;AACD;;AAED,SAASG,kBAAT;AACE,MAAMC,YAAY,GAAGH,QAAQ,CAACI,cAAT,CAAwBlB,MAAxB,CAArB;;AACA,MAAIiB,YAAJ,EAAkB;AAChB,WAAOA,YAAP;AACD;;AACD,SAAOL,aAAa,EAApB;AACD;;AAED,SAAgBO;AACd,MAAMF,YAAY,GAAGH,QAAQ,CAACI,cAAT,CAAwBlB,MAAxB,CAArB;AACAiB,EAAAA,YAAY,IACVA,YAAY,CAACG,UADf,IAEEH,YAAY,CAACG,UAAb,CAAwBC,WAAxB,CAAoCJ,YAApC,CAFF;AAGD;AAED,SAAgBK,YAAYC;AAC1B,MAAMV,OAAO,GAAGG,kBAAkB,EAAlC;AACAQ,EAAAA,MAAM,CAACC,MAAP,CAAcZ,OAAO,CAACU,KAAtB,EAA6BA,KAA7B;AACA,MAAMG,MAAM,GAAGZ,QAAQ,CAACa,aAAT,CAAuB5B,eAAvB,CAAf;AACA2B,EAAAA,MAAM,IAAIA,MAAM,CAACE,MAAP,CAAcf,OAAd,CAAV;AACD;;ACrBD,YAAA;AAAegB,oBAAa,CAAC;AAC3BC,EAAAA,IAAI,EAAE,aADqB;AAE3BC,EAAAA,aAAa,EAAE,SAFY;AAG3BC,EAAAA,OAAO,EAAE,iBAACC,QAAD,EAAWC,OAAX;QAAsBC,kBAAAA;;AAC7B,QAAIA,UAAU,CAACC,IAAf,EAAqB;AACnBjB,MAAAA,aAAa;AACd,KAFD,MAEO;AACL,UAAMI,KAAK,GAAGtB,QAAQ,CAACkC,UAAD,CAAtB;AACAb,MAAAA,WAAW,CAACC,KAAD,CAAX;AACD;;AACD,WAAOU,QAAQ,CAACC,OAAD,CAAf;AACD;AAX0B,CAAD,CAA5B;;;;"}
@@ -1,2 +0,0 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@storybook/addons"),t="storybook-rhythm";exports.default=e.makeDecorator({name:"withVRhythm",parameterName:"vrhythm",wrapper:function(e,r,o){var n,a=o.parameters;return a.hide?(n=document.getElementById(t))&&n.parentNode&&n.parentNode.removeChild(n):function(e){var r=function(){var e;return document.getElementById(t)||((e=document.createElement("div")).setAttribute("id",t),e)}();Object.assign(r.style,e);var o=document.querySelector("body");o&&o.append(r)}(function(e){var t=e.color,r=e.lineHeight,o=e.offset;return{position:"absolute",top:void 0===o?0:o,left:0,right:0,bottom:0,background:"linear-gradient("+(void 0===t?"rgb(204, 204, 204)":t)+" 1px, transparent 1px) left top / 1px "+(void 0===r?"16px":r),pointerEvents:"none"}}(a)),e(r)}});
2
- //# sourceMappingURL=storybook-vrhythm.cjs.production.min.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"storybook-vrhythm.cjs.production.min.js","sources":["../src/constants.ts","../src/index.tsx","../src/utils.ts","../src/getStyle.ts"],"sourcesContent":["export const DEFAULT_COLOR = 'rgb(204, 204, 204)';\nexport const DEFAULT_LINE_HEIGHT = '16px';\nexport const DEFAULT_OFFSET = 0;\nexport const PARENT_SELECTOR = 'body';\nexport const DIV_ID = 'storybook-rhythm';\n","import { makeDecorator } from '@storybook/addons';\n\nimport getStyle from './getStyle';\nimport { StyleProps, ConfigProps } from './types';\nimport { injectStyle, removeElement } from './utils';\n\ntype Params = StyleProps & ConfigProps;\n\nexport default makeDecorator({\n name: 'withVRhythm',\n parameterName: 'vrhythm',\n wrapper: (getStory, context, { parameters }: { parameters: Params }) => {\n if (parameters.hide) {\n removeElement();\n } else {\n const style = getStyle(parameters);\n injectStyle(style);\n }\n return getStory(context);\n },\n});\n","import { PARENT_SELECTOR, DIV_ID } from './constants';\nimport { StyleObj } from './types';\n\nfunction createElement() {\n const element = document.createElement('div') as HTMLDivElement;\n element.setAttribute('id', DIV_ID);\n return element;\n}\n\nfunction getOrCreateElement() {\n const elementOnDom = document.getElementById(DIV_ID);\n if (elementOnDom) {\n return elementOnDom;\n }\n return createElement();\n}\n\nexport function removeElement() {\n const elementOnDom = document.getElementById(DIV_ID);\n elementOnDom &&\n elementOnDom.parentNode &&\n elementOnDom.parentNode.removeChild(elementOnDom);\n}\n\nexport function injectStyle(style: StyleObj) {\n const element = getOrCreateElement();\n Object.assign(element.style, style);\n const parent = document.querySelector(PARENT_SELECTOR);\n parent && parent.append(element);\n}\n","import { StyleObj, StyleProps } from './types';\nimport {\n DEFAULT_COLOR,\n DEFAULT_LINE_HEIGHT,\n DEFAULT_OFFSET,\n} from './constants';\n\nconst getStyle = ({\n color = DEFAULT_COLOR,\n lineHeight = DEFAULT_LINE_HEIGHT,\n offset = DEFAULT_OFFSET,\n}: StyleProps): StyleObj => ({\n position: 'absolute',\n top: offset,\n left: 0,\n right: 0,\n bottom: 0,\n background: `linear-gradient(${color} 1px, transparent 1px) left top / 1px ${lineHeight}`,\n pointerEvents: 'none',\n});\n\nexport default getStyle;\n"],"names":["DIV_ID","makeDecorator","name","parameterName","wrapper","getStory","context","elementOnDom","parameters","hide","document","getElementById","parentNode","removeChild","style","element","createElement","setAttribute","getOrCreateElement","Object","assign","parent","querySelector","append","injectStyle","color","lineHeight","offset","position","top","left","right","bottom","background","pointerEvents","getStyle"],"mappings":"uGAIaA,EAAS,mCCIPC,gBAAc,CAC3BC,KAAM,cACNC,cAAe,UACfC,QAAS,SAACC,EAAUC,SCOdC,EDPyBC,IAAAA,kBACzBA,EAAWC,MCMXF,EAAeG,SAASC,eAAeX,KAE3CO,EAAaK,YACbL,EAAaK,WAAWC,YAAYN,YAGZO,OACpBC,EAhBR,eALQA,SAMeL,SAASC,eAAeX,MANvCe,EAAUL,SAASM,cAAc,QAC/BC,aAAa,KAAMjB,GACpBe,GAmBSG,GAChBC,OAAOC,OAAOL,EAAQD,MAAOA,OACvBO,EAASX,SAASY,cFxBK,QEyB7BD,GAAUA,EAAOE,OAAOR,GDZpBS,CETW,oBACfC,UACAC,eACAC,aAC2B,CAC3BC,SAAU,WACVC,eHX4B,IGY5BC,KAAM,EACNC,MAAO,EACPC,OAAQ,EACRC,0CHjB2B,6EACM,UGiBjCC,cAAe,QFHGC,CAAS3B,IAGlBH,EAASC"}
@@ -1,73 +0,0 @@
1
- import { makeDecorator } from '@storybook/addons';
2
-
3
- var DEFAULT_COLOR = 'rgb(204, 204, 204)';
4
- var DEFAULT_LINE_HEIGHT = '16px';
5
- var DEFAULT_OFFSET = 0;
6
- var PARENT_SELECTOR = 'body';
7
- var DIV_ID = 'storybook-rhythm';
8
-
9
- var getStyle = function getStyle(_ref) {
10
- var _ref$color = _ref.color,
11
- color = _ref$color === void 0 ? DEFAULT_COLOR : _ref$color,
12
- _ref$lineHeight = _ref.lineHeight,
13
- lineHeight = _ref$lineHeight === void 0 ? DEFAULT_LINE_HEIGHT : _ref$lineHeight,
14
- _ref$offset = _ref.offset,
15
- offset = _ref$offset === void 0 ? DEFAULT_OFFSET : _ref$offset;
16
- return {
17
- position: 'absolute',
18
- top: offset,
19
- left: 0,
20
- right: 0,
21
- bottom: 0,
22
- background: "linear-gradient(" + color + " 1px, transparent 1px) left top / 1px " + lineHeight,
23
- pointerEvents: 'none'
24
- };
25
- };
26
-
27
- function createElement() {
28
- var element = document.createElement('div');
29
- element.setAttribute('id', DIV_ID);
30
- return element;
31
- }
32
-
33
- function getOrCreateElement() {
34
- var elementOnDom = document.getElementById(DIV_ID);
35
-
36
- if (elementOnDom) {
37
- return elementOnDom;
38
- }
39
-
40
- return createElement();
41
- }
42
-
43
- function removeElement() {
44
- var elementOnDom = document.getElementById(DIV_ID);
45
- elementOnDom && elementOnDom.parentNode && elementOnDom.parentNode.removeChild(elementOnDom);
46
- }
47
- function injectStyle(style) {
48
- var element = getOrCreateElement();
49
- Object.assign(element.style, style);
50
- var parent = document.querySelector(PARENT_SELECTOR);
51
- parent && parent.append(element);
52
- }
53
-
54
- var index = /*#__PURE__*/
55
- makeDecorator({
56
- name: 'withVRhythm',
57
- parameterName: 'vrhythm',
58
- wrapper: function wrapper(getStory, context, _ref) {
59
- var parameters = _ref.parameters;
60
-
61
- if (parameters.hide) {
62
- removeElement();
63
- } else {
64
- var style = getStyle(parameters);
65
- injectStyle(style);
66
- }
67
-
68
- return getStory(context);
69
- }
70
- });
71
-
72
- export default index;
73
- //# sourceMappingURL=storybook-vrhythm.esm.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"storybook-vrhythm.esm.js","sources":["../src/constants.ts","../src/getStyle.ts","../src/utils.ts","../src/index.tsx"],"sourcesContent":["export const DEFAULT_COLOR = 'rgb(204, 204, 204)';\nexport const DEFAULT_LINE_HEIGHT = '16px';\nexport const DEFAULT_OFFSET = 0;\nexport const PARENT_SELECTOR = 'body';\nexport const DIV_ID = 'storybook-rhythm';\n","import { StyleObj, StyleProps } from './types';\nimport {\n DEFAULT_COLOR,\n DEFAULT_LINE_HEIGHT,\n DEFAULT_OFFSET,\n} from './constants';\n\nconst getStyle = ({\n color = DEFAULT_COLOR,\n lineHeight = DEFAULT_LINE_HEIGHT,\n offset = DEFAULT_OFFSET,\n}: StyleProps): StyleObj => ({\n position: 'absolute',\n top: offset,\n left: 0,\n right: 0,\n bottom: 0,\n background: `linear-gradient(${color} 1px, transparent 1px) left top / 1px ${lineHeight}`,\n pointerEvents: 'none',\n});\n\nexport default getStyle;\n","import { PARENT_SELECTOR, DIV_ID } from './constants';\nimport { StyleObj } from './types';\n\nfunction createElement() {\n const element = document.createElement('div') as HTMLDivElement;\n element.setAttribute('id', DIV_ID);\n return element;\n}\n\nfunction getOrCreateElement() {\n const elementOnDom = document.getElementById(DIV_ID);\n if (elementOnDom) {\n return elementOnDom;\n }\n return createElement();\n}\n\nexport function removeElement() {\n const elementOnDom = document.getElementById(DIV_ID);\n elementOnDom &&\n elementOnDom.parentNode &&\n elementOnDom.parentNode.removeChild(elementOnDom);\n}\n\nexport function injectStyle(style: StyleObj) {\n const element = getOrCreateElement();\n Object.assign(element.style, style);\n const parent = document.querySelector(PARENT_SELECTOR);\n parent && parent.append(element);\n}\n","import { makeDecorator } from '@storybook/addons';\n\nimport getStyle from './getStyle';\nimport { StyleProps, ConfigProps } from './types';\nimport { injectStyle, removeElement } from './utils';\n\ntype Params = StyleProps & ConfigProps;\n\nexport default makeDecorator({\n name: 'withVRhythm',\n parameterName: 'vrhythm',\n wrapper: (getStory, context, { parameters }: { parameters: Params }) => {\n if (parameters.hide) {\n removeElement();\n } else {\n const style = getStyle(parameters);\n injectStyle(style);\n }\n return getStory(context);\n },\n});\n"],"names":["DEFAULT_COLOR","DEFAULT_LINE_HEIGHT","DEFAULT_OFFSET","PARENT_SELECTOR","DIV_ID","getStyle","color","lineHeight","offset","position","top","left","right","bottom","background","pointerEvents","createElement","element","document","setAttribute","getOrCreateElement","elementOnDom","getElementById","removeElement","parentNode","removeChild","injectStyle","style","Object","assign","parent","querySelector","append","makeDecorator","name","parameterName","wrapper","getStory","context","parameters","hide"],"mappings":";;AAAO,IAAMA,aAAa,GAAG,oBAAtB;AACA,IAAMC,mBAAmB,GAAG,MAA5B;AACA,IAAMC,cAAc,GAAG,CAAvB;AACA,IAAMC,eAAe,GAAG,MAAxB;AACA,IAAMC,MAAM,GAAG,kBAAf;;ACGP,IAAMC,QAAQ,GAAG,SAAXA,QAAW;AAAA,wBACfC,KADe;AAAA,MACfA,KADe,2BACPN,aADO;AAAA,6BAEfO,UAFe;AAAA,MAEfA,UAFe,gCAEFN,mBAFE;AAAA,yBAGfO,MAHe;AAAA,MAGfA,MAHe,4BAGNN,cAHM;AAAA,SAIY;AAC3BO,IAAAA,QAAQ,EAAE,UADiB;AAE3BC,IAAAA,GAAG,EAAEF,MAFsB;AAG3BG,IAAAA,IAAI,EAAE,CAHqB;AAI3BC,IAAAA,KAAK,EAAE,CAJoB;AAK3BC,IAAAA,MAAM,EAAE,CALmB;AAM3BC,IAAAA,UAAU,uBAAqBR,KAArB,8CAAmEC,UANlD;AAO3BQ,IAAAA,aAAa,EAAE;AAPY,GAJZ;AAAA,CAAjB;;ACJA,SAASC,aAAT;AACE,MAAMC,OAAO,GAAGC,QAAQ,CAACF,aAAT,CAAuB,KAAvB,CAAhB;AACAC,EAAAA,OAAO,CAACE,YAAR,CAAqB,IAArB,EAA2Bf,MAA3B;AACA,SAAOa,OAAP;AACD;;AAED,SAASG,kBAAT;AACE,MAAMC,YAAY,GAAGH,QAAQ,CAACI,cAAT,CAAwBlB,MAAxB,CAArB;;AACA,MAAIiB,YAAJ,EAAkB;AAChB,WAAOA,YAAP;AACD;;AACD,SAAOL,aAAa,EAApB;AACD;;AAED,SAAgBO;AACd,MAAMF,YAAY,GAAGH,QAAQ,CAACI,cAAT,CAAwBlB,MAAxB,CAArB;AACAiB,EAAAA,YAAY,IACVA,YAAY,CAACG,UADf,IAEEH,YAAY,CAACG,UAAb,CAAwBC,WAAxB,CAAoCJ,YAApC,CAFF;AAGD;AAED,SAAgBK,YAAYC;AAC1B,MAAMV,OAAO,GAAGG,kBAAkB,EAAlC;AACAQ,EAAAA,MAAM,CAACC,MAAP,CAAcZ,OAAO,CAACU,KAAtB,EAA6BA,KAA7B;AACA,MAAMG,MAAM,GAAGZ,QAAQ,CAACa,aAAT,CAAuB5B,eAAvB,CAAf;AACA2B,EAAAA,MAAM,IAAIA,MAAM,CAACE,MAAP,CAAcf,OAAd,CAAV;AACD;;ACrBD,YAAA;AAAegB,aAAa,CAAC;AAC3BC,EAAAA,IAAI,EAAE,aADqB;AAE3BC,EAAAA,aAAa,EAAE,SAFY;AAG3BC,EAAAA,OAAO,EAAE,iBAACC,QAAD,EAAWC,OAAX;QAAsBC,kBAAAA;;AAC7B,QAAIA,UAAU,CAACC,IAAf,EAAqB;AACnBjB,MAAAA,aAAa;AACd,KAFD,MAEO;AACL,UAAMI,KAAK,GAAGtB,QAAQ,CAACkC,UAAD,CAAtB;AACAb,MAAAA,WAAW,CAACC,KAAD,CAAX;AACD;;AACD,WAAOU,QAAQ,CAACC,OAAD,CAAf;AACD;AAX0B,CAAD,CAA5B;;;;"}
package/dist/types.d.ts DELETED
@@ -1,11 +0,0 @@
1
- export interface StyleProps {
2
- color?: string;
3
- lineHeight?: string | number;
4
- offset?: string | number;
5
- }
6
- export interface ConfigProps {
7
- hide?: boolean;
8
- }
9
- export interface StyleObj {
10
- [key: string]: string | number;
11
- }
package/dist/utils.d.ts DELETED
@@ -1,3 +0,0 @@
1
- import { StyleObj } from './types';
2
- export declare function removeElement(): void;
3
- export declare function injectStyle(style: StyleObj): void;