defStyle.ts 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. import { defaultStyle as iconDefStyle } from "@/core/components/icon";
  2. import { defaultStyle as rectDefStyle } from "@/core/components/rectangle";
  3. import { defaultStyle as circleDefStyle } from "@/core/components/circle";
  4. import { defaultStyle as triangleDefStyle } from "@/core/components/triangle";
  5. import { defaultStyle as arrowDefStyle } from "@/core/components/arrow";
  6. import { defaultStyle as serialDefStyle, defaultTableStyle as serialTableDefStyle } from "@/core/components/serial";
  7. import { defaultStyle as tableDefStyle } from "@/core/components/table";
  8. import { PaperKey } from "@/example/components/slide/actions";
  9. import { mergeFuns } from "@/utils/shared";
  10. import { getRealPixel } from "./tabulation/gen-tab";
  11. import { Draw } from "@/example/components/container/use-draw";
  12. import { ShapeType } from "@/index";
  13. const setDefStyle = <T extends {}>(
  14. sys: T,
  15. custom: Partial<T>,
  16. itemKey?: string
  17. ) => {
  18. const backs: (() => void)[] = [];
  19. for (const key in custom) {
  20. const oldVal = sys[key];
  21. sys[key] = custom[key]!;
  22. backs.push(() => {
  23. sys[key] = oldVal;
  24. });
  25. }
  26. return mergeFuns(backs);
  27. };
  28. export const tabCustomStyle = (p: PaperKey, draw: Draw) => {
  29. const types = ["icon", "table", "serial", 'arrow', 'circle', 'rectangle', 'triangle', 'polygon'] as ShapeType[];
  30. types.forEach((type) => {
  31. draw.mountFilter.setMenusFilter(type, (data) => {
  32. data.strokeWidth.props = {
  33. ...data.strokeWidth.props,
  34. proportion: true,
  35. step: 0.1,
  36. min: 0.1,
  37. max: 10
  38. };
  39. return data;
  40. });
  41. });
  42. const backs = [
  43. () => {
  44. types.forEach((type) => {
  45. draw.mountFilter.setMenusFilter(type);
  46. });
  47. },
  48. setDefStyle(
  49. iconDefStyle,
  50. {
  51. width: getRealPixel(10, p),
  52. height: getRealPixel(10, p),
  53. strokeWidth: getRealPixel(0.5, p),
  54. } as any,
  55. "icon"
  56. ),
  57. setDefStyle(serialDefStyle, {
  58. strokeWidth: getRealPixel(0.5, p),
  59. fill: null,
  60. } as any),
  61. setDefStyle(serialTableDefStyle, {
  62. nameColWidth: getRealPixel(20, p),
  63. valueColWidth: getRealPixel(20, p),
  64. fontSize: getRealPixel(4, p),
  65. padding: getRealPixel(2, p),
  66. colHeight: getRealPixel(8, p),
  67. tableStrokeWidth: getRealPixel(0.5, p),
  68. repColCount: 2,
  69. } as any),
  70. setDefStyle(tableDefStyle, { strokeWidth: getRealPixel(0.5, p) }),
  71. setDefStyle(rectDefStyle, { strokeWidth: getRealPixel(0.5, p) }),
  72. setDefStyle(circleDefStyle, { strokeWidth: getRealPixel(0.5, p) }),
  73. setDefStyle(triangleDefStyle, { strokeWidth: getRealPixel(0.5, p) }),
  74. setDefStyle(arrowDefStyle, { strokeWidth: getRealPixel(0.5, p) }),
  75. ];
  76. return mergeFuns(backs);
  77. };
  78. export const overviewCustomStyle = (draw: Draw) => {
  79. draw.mountFilter.setMenusFilter("icon", (data) => {
  80. data.strokeWidth.props = {
  81. ...data.strokeWidth.props,
  82. proportion: true,
  83. };
  84. return data;
  85. });
  86. const backs = [
  87. () => {
  88. draw.mountFilter.setMenusFilter("icon");
  89. },
  90. setDefStyle(
  91. iconDefStyle,
  92. {
  93. strokeWidth: 1,
  94. } as any,
  95. "icon"
  96. ),
  97. ];
  98. return mergeFuns(backs);
  99. };