defStyle.ts 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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 {
  7. defaultStyle as serialDefStyle,
  8. defaultTableStyle as serialTableDefStyle,
  9. joinKey,
  10. } from "@/core/components/serial";
  11. import { defaultStyle as tableDefStyle } from "@/core/components/table";
  12. import { PaperKey } from "@/example/components/slide/actions";
  13. import { mergeFuns } from "@/utils/shared";
  14. import { getRealPixel } from "./tabulation/gen-tab";
  15. import { Draw } from "@/example/components/container/use-draw";
  16. import { ShapeType } from "@/index";
  17. import { watch } from "vue";
  18. const setDefStyle = <T extends {}>(
  19. sys: T,
  20. custom: Partial<T>,
  21. itemKey?: string
  22. ) => {
  23. const backs: (() => void)[] = [];
  24. for (const key in custom) {
  25. const oldVal = sys[key];
  26. sys[key] = custom[key]!;
  27. backs.push(() => {
  28. sys[key] = oldVal;
  29. });
  30. }
  31. return mergeFuns(backs);
  32. };
  33. export const tabCustomStyle = (p: PaperKey, draw: Draw) => {
  34. const types = [
  35. "icon",
  36. "table",
  37. "serial",
  38. "arrow",
  39. "circle",
  40. "rectangle",
  41. "triangle",
  42. "polygon",
  43. ] as ShapeType[];
  44. types.forEach((type) => {
  45. draw.mountFilter.setMenusFilter(type, (data) => {
  46. data.strokeWidth.props = {
  47. ...data.strokeWidth.props,
  48. proportion: true,
  49. step: 0.1,
  50. min: 0.1,
  51. max: 10,
  52. };
  53. return data;
  54. });
  55. });
  56. draw.mountFilter.setMenusFilter('serial', data => {
  57. data = {...data}
  58. delete data.fontStyle
  59. return data
  60. })
  61. const backs = [
  62. () => {
  63. types.forEach((type) => {
  64. draw.mountFilter.setMenusFilter(type);
  65. });
  66. draw.mountFilter.setMenusFilter('serial')
  67. },
  68. setDefStyle(
  69. iconDefStyle,
  70. {
  71. width: getRealPixel(10, p),
  72. height: getRealPixel(10, p),
  73. strokeWidth: getRealPixel(0.5, p),
  74. } as any,
  75. "icon"
  76. ),
  77. setDefStyle(serialDefStyle, {
  78. strokeWidth: getRealPixel(0.5, p),
  79. fill: null,
  80. } as any),
  81. setDefStyle(serialTableDefStyle, {
  82. nameColWidth: getRealPixel(20, p),
  83. valueColWidth: getRealPixel(20, p),
  84. fontSize: getRealPixel(4, p),
  85. padding: getRealPixel(2, p),
  86. colHeight: getRealPixel(8, p),
  87. tableStrokeWidth: getRealPixel(0.5, p),
  88. repColCount: 2,
  89. } as any),
  90. setDefStyle(tableDefStyle, { strokeWidth: getRealPixel(0.5, p) }),
  91. setDefStyle(rectDefStyle, { strokeWidth: getRealPixel(0.5, p) }),
  92. setDefStyle(circleDefStyle, { strokeWidth: getRealPixel(0.5, p) }),
  93. setDefStyle(triangleDefStyle, { strokeWidth: getRealPixel(0.5, p) }),
  94. setDefStyle(arrowDefStyle, { strokeWidth: getRealPixel(0.5, p) }),
  95. watch(
  96. () =>
  97. draw.store.getTypeItems("table").filter((item) => item.key === joinKey),
  98. (serialTables, _, onCleanup) => {
  99. const fns = serialTables.map((item) => {
  100. draw.mountFilter.setShapeMenusFilter(item.id, item => {
  101. const c = {...item}
  102. delete c.align
  103. return c
  104. })
  105. return () => draw.menusFilter.setShapeMenusFilter(item.id)
  106. });
  107. onCleanup(mergeFuns(fns))
  108. },
  109. { immediate: true }
  110. ),
  111. ];
  112. return mergeFuns(backs);
  113. };
  114. export const overviewCustomStyle = (draw: Draw) => {
  115. draw.mountFilter.setMenusFilter("icon", (data) => {
  116. data.strokeWidth.props = {
  117. ...data.strokeWidth.props,
  118. proportion: true,
  119. };
  120. return data;
  121. });
  122. const backs = [
  123. () => draw.mountFilter.setMenusFilter("icon"),
  124. setDefStyle(
  125. iconDefStyle,
  126. {
  127. strokeWidth: 1,
  128. } as any,
  129. "icon"
  130. ),
  131. ];
  132. return mergeFuns(backs);
  133. };