react-ink-scripter 0.0.21 → 0.0.22

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/dist/cjs/index.js CHANGED
@@ -19,7 +19,8 @@ var pix2mm = function pix2mm(pix) {
19
19
  };
20
20
  var usePagePrint = function usePagePrint(_ref) {
21
21
  var open = _ref.open,
22
- pageConfig = _ref.pageConfig;
22
+ pageConfig = _ref.pageConfig,
23
+ style = _ref.style;
23
24
  var _useState = react.useState({
24
25
  width: pageConfig.width || 0,
25
26
  height: pageConfig.height || 0,
@@ -62,11 +63,21 @@ var usePagePrint = function usePagePrint(_ref) {
62
63
  var getPageContent = react.useCallback(function () {
63
64
  return (pageNode === null || pageNode === void 0 ? void 0 : pageNode.innerHTML) || '';
64
65
  }, [pageNode]);
66
+ var pageStyle = react.useMemo(function () {
67
+ var width = page.width,
68
+ height = page.height,
69
+ marginLeft = page.marginLeft,
70
+ marginRight = page.marginRight,
71
+ marginTop = page.marginTop;
72
+ var extraStyle = "\nhtml {\nmargin: 0;\npadding: 0;\nwidth: ".concat(width, "mm;\nheight: ").concat(height, "mm\n}\n\nbody {\nwidth: ").concat(width, "mm;\nmargin: 0;\npadding: 0;\nbox-sizing: border-box;\npadding-left: ").concat(marginLeft, "mm;\npadding-right: ").concat(marginRight, "mm;\npadding-top: ").concat(marginTop, "mm;\n}\n");
73
+ return style + '\n' + extraStyle;
74
+ }, [page, style, page]);
65
75
  return {
66
76
  setPageNodeRef: setPageNodeRef,
67
77
  page: page,
68
78
  getPageContent: getPageContent,
69
- pageNode: pageNode
79
+ pageNode: pageNode,
80
+ pageStyle: pageStyle
70
81
  };
71
82
  };
72
83
 
package/dist/esm/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { useState, useCallback, useLayoutEffect, forwardRef, useRef, useMemo, useImperativeHandle } from 'react';
1
+ import { useState, useCallback, useLayoutEffect, useMemo, forwardRef, useRef, useImperativeHandle } from 'react';
2
2
  import { jsxs, jsx } from 'react/jsx-runtime';
3
3
  import { createPortal } from 'react-dom';
4
4
  import clsx from 'clsx';
@@ -8,7 +8,7 @@ const getPageHeight = (height, page) => {
8
8
  return height + marginTop + marginBottom;
9
9
  };
10
10
  const pix2mm = (pix) => Math.round(pix * 0.2645833333);
11
- const usePagePrint = ({ open, pageConfig, }) => {
11
+ const usePagePrint = ({ open, pageConfig, style, }) => {
12
12
  const [page, setPage] = useState({
13
13
  width: pageConfig.width || 0,
14
14
  height: pageConfig.height || 0,
@@ -43,7 +43,29 @@ const usePagePrint = ({ open, pageConfig, }) => {
43
43
  const getPageContent = useCallback(() => {
44
44
  return pageNode?.innerHTML || '';
45
45
  }, [pageNode]);
46
- return { setPageNodeRef, page, getPageContent, pageNode };
46
+ const pageStyle = useMemo(() => {
47
+ const { width, height, marginLeft, marginRight, marginTop } = page;
48
+ const extraStyle = `
49
+ html {
50
+ margin: 0;
51
+ padding: 0;
52
+ width: ${width}mm;
53
+ height: ${height}mm
54
+ }
55
+
56
+ body {
57
+ width: ${width}mm;
58
+ margin: 0;
59
+ padding: 0;
60
+ box-sizing: border-box;
61
+ padding-left: ${marginLeft}mm;
62
+ padding-right: ${marginRight}mm;
63
+ padding-top: ${marginTop}mm;
64
+ }
65
+ `;
66
+ return style + '\n' + extraStyle;
67
+ }, [page, style, page]);
68
+ return { setPageNodeRef, page, getPageContent, pageNode, pageStyle };
47
69
  };
48
70
 
49
71
  const IFrame = forwardRef((props, ref) => {
@@ -11,11 +11,13 @@ export declare const pix2mm: (pix: number) => number;
11
11
  export type usePagePrintProps = {
12
12
  open?: boolean;
13
13
  pageConfig: Partial<PageConfig>;
14
+ style?: string;
14
15
  };
15
- export declare const usePagePrint: <T extends Element>({ open, pageConfig, }: usePagePrintProps) => {
16
+ export declare const usePagePrint: <T extends Element>({ open, pageConfig, style, }: usePagePrintProps) => {
16
17
  setPageNodeRef: (node: T) => void;
17
18
  page: PageConfig;
18
19
  getPageContent: () => string;
19
20
  pageNode: T | undefined;
21
+ pageStyle: string;
20
22
  };
21
23
  export default usePagePrint;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-ink-scripter",
3
- "version": "0.0.21",
3
+ "version": "0.0.22",
4
4
  "description": "a react component for generate page to print",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",