@visactor/vstory 0.0.7 → 0.0.8-alpha.1

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.
Files changed (131) hide show
  1. package/cjs/constants/character.d.ts +2 -1
  2. package/cjs/constants/character.js +2 -1
  3. package/cjs/constants/character.js.map +1 -1
  4. package/cjs/dsl/story-chart/pie.js +1 -1
  5. package/cjs/dsl/story-executor/index.js +0 -2
  6. package/cjs/dsl/story-processor/index.js +1 -1
  7. package/cjs/dsl/story-processor/processor.js +1 -1
  8. package/cjs/dsl/types/Datum.js +1 -2
  9. package/cjs/dsl/types/index.js +1 -1
  10. package/cjs/dsl/utils/datum.js +1 -1
  11. package/cjs/dsl/utils/flicker.js +1 -1
  12. package/cjs/edit/edit-component/image-selection.js +1 -1
  13. package/cjs/edit/edit-component/index.js +1 -1
  14. package/cjs/edit/edit-component/layer-edit.js +2 -0
  15. package/cjs/edit/edit-component/rect-selection.js +1 -1
  16. package/cjs/edit/edit-component/richtext-selection-common.js +1 -1
  17. package/cjs/edit/edit-component/richtext-selection.js +1 -1
  18. package/cjs/edit/edit-component/shape-selection.js +2 -1
  19. package/cjs/edit/edit-component/text-selection.js +1 -1
  20. package/cjs/index.d.ts +1 -0
  21. package/cjs/index.js +1 -1
  22. package/cjs/index.js.map +1 -1
  23. package/cjs/interface/type.js +1 -2
  24. package/cjs/player/processor/component/unit/unit-action.d.ts +11 -0
  25. package/cjs/player/processor/component/unit/unit-action.js +36 -0
  26. package/cjs/player/processor/component/unit/unit-action.js.map +1 -0
  27. package/cjs/player/processor/interface/appear-action.js.map +1 -1
  28. package/cjs/player/processor/interface/unit-action.d.ts +23 -0
  29. package/cjs/player/processor/interface/unit-action.js +6 -0
  30. package/cjs/player/processor/interface/unit-action.js.map +1 -0
  31. package/cjs/player/processor/processorMap.d.ts +7 -0
  32. package/cjs/player/processor/processorMap.js +9 -1
  33. package/cjs/player/processor/processorMap.js.map +1 -1
  34. package/cjs/scene/action.js +0 -2
  35. package/cjs/story/canvas/canvas.d.ts +10 -3
  36. package/cjs/story/canvas/canvas.js +29 -8
  37. package/cjs/story/canvas/canvas.js.map +1 -1
  38. package/cjs/story/character/component/characters/character-unit.d.ts +6 -0
  39. package/cjs/story/character/component/characters/character-unit.js +19 -0
  40. package/cjs/story/character/component/characters/character-unit.js.map +1 -0
  41. package/cjs/story/character/component/graphic/unit.d.ts +28 -0
  42. package/cjs/story/character/component/graphic/unit.js +106 -0
  43. package/cjs/story/character/component/graphic/unit.js.map +1 -0
  44. package/cjs/story/index.js +2 -1
  45. package/cjs/story/index.js.map +1 -1
  46. package/cjs/story/interface/dsl-interface.d.ts +2 -1
  47. package/cjs/story/interface/dsl-interface.js.map +1 -1
  48. package/cjs/story/interface/runtime-interface.d.ts +5 -1
  49. package/cjs/story/interface/runtime-interface.js.map +1 -1
  50. package/cjs/story/story.d.ts +1 -1
  51. package/cjs/story/story.js +6 -3
  52. package/cjs/story/story.js.map +1 -1
  53. package/cjs/template/unit/default.d.ts +4 -0
  54. package/cjs/template/unit/default.js +50 -0
  55. package/cjs/template/unit/default.js.map +1 -0
  56. package/cjs/template/unit/index.d.ts +2 -0
  57. package/cjs/template/unit/index.js +21 -0
  58. package/cjs/template/unit/index.js.map +1 -0
  59. package/cjs/template/unit/type.d.ts +51 -0
  60. package/cjs/template/unit/type.js +6 -0
  61. package/cjs/template/unit/type.js.map +1 -0
  62. package/cjs/template/unit/unit.d.ts +3 -0
  63. package/cjs/template/unit/unit.js +240 -0
  64. package/cjs/template/unit/unit.js.map +1 -0
  65. package/dist/index.js +1721 -1040
  66. package/dist/index.min.js +3 -3
  67. package/es/constants/character.d.ts +2 -1
  68. package/es/constants/character.js +2 -1
  69. package/es/constants/character.js.map +1 -1
  70. package/es/dsl/story-chart/pie.js +1 -1
  71. package/es/dsl/story-executor/index.js +0 -2
  72. package/es/dsl/story-processor/index.js +1 -1
  73. package/es/dsl/story-processor/processor.js +1 -1
  74. package/es/dsl/types/Datum.js +1 -2
  75. package/es/dsl/types/index.js +1 -1
  76. package/es/dsl/utils/datum.js +1 -1
  77. package/es/dsl/utils/flicker.js +1 -1
  78. package/es/edit/edit-component/image-selection.js +1 -1
  79. package/es/edit/edit-component/index.js +1 -1
  80. package/es/edit/edit-component/layer-edit.js +2 -0
  81. package/es/edit/edit-component/rect-selection.js +1 -1
  82. package/es/edit/edit-component/richtext-selection-common.js +1 -1
  83. package/es/edit/edit-component/richtext-selection.js +1 -1
  84. package/es/edit/edit-component/shape-selection.js +2 -1
  85. package/es/edit/edit-component/text-selection.js +1 -1
  86. package/es/index.d.ts +1 -0
  87. package/es/index.js +3 -1
  88. package/es/index.js.map +1 -1
  89. package/es/interface/type.js +1 -2
  90. package/es/player/processor/component/unit/unit-action.d.ts +11 -0
  91. package/es/player/processor/component/unit/unit-action.js +28 -0
  92. package/es/player/processor/component/unit/unit-action.js.map +1 -0
  93. package/es/player/processor/interface/appear-action.js.map +1 -1
  94. package/es/player/processor/interface/unit-action.d.ts +23 -0
  95. package/es/player/processor/interface/unit-action.js +2 -0
  96. package/es/player/processor/interface/unit-action.js.map +1 -0
  97. package/es/player/processor/processorMap.d.ts +7 -0
  98. package/es/player/processor/processorMap.js +10 -0
  99. package/es/player/processor/processorMap.js.map +1 -1
  100. package/es/scene/action.js +0 -2
  101. package/es/story/canvas/canvas.d.ts +10 -3
  102. package/es/story/canvas/canvas.js +29 -8
  103. package/es/story/canvas/canvas.js.map +1 -1
  104. package/es/story/character/component/characters/character-unit.d.ts +6 -0
  105. package/es/story/character/component/characters/character-unit.js +15 -0
  106. package/es/story/character/component/characters/character-unit.js.map +1 -0
  107. package/es/story/character/component/graphic/unit.d.ts +28 -0
  108. package/es/story/character/component/graphic/unit.js +103 -0
  109. package/es/story/character/component/graphic/unit.js.map +1 -0
  110. package/es/story/index.js +3 -0
  111. package/es/story/index.js.map +1 -1
  112. package/es/story/interface/dsl-interface.d.ts +2 -1
  113. package/es/story/interface/dsl-interface.js.map +1 -1
  114. package/es/story/interface/runtime-interface.d.ts +5 -1
  115. package/es/story/interface/runtime-interface.js.map +1 -1
  116. package/es/story/story.d.ts +1 -1
  117. package/es/story/story.js +6 -2
  118. package/es/story/story.js.map +1 -1
  119. package/es/template/unit/default.d.ts +4 -0
  120. package/es/template/unit/default.js +48 -0
  121. package/es/template/unit/default.js.map +1 -0
  122. package/es/template/unit/index.d.ts +2 -0
  123. package/es/template/unit/index.js +4 -0
  124. package/es/template/unit/index.js.map +1 -0
  125. package/es/template/unit/type.d.ts +51 -0
  126. package/es/template/unit/type.js +2 -0
  127. package/es/template/unit/type.js.map +1 -0
  128. package/es/template/unit/unit.d.ts +3 -0
  129. package/es/template/unit/unit.js +234 -0
  130. package/es/template/unit/unit.js.map +1 -0
  131. package/package.json +25 -24
@@ -0,0 +1,103 @@
1
+ import { createGroup, createSymbol } from "@visactor/vrender";
2
+
3
+ import { Graphic } from "./graphic";
4
+
5
+ import { getLayoutFromWidget } from "../../../utils/layout";
6
+
7
+ import { logger } from "../../../../util/output";
8
+
9
+ export class GraphicUnit extends Graphic {
10
+ getInitialAttributes() {
11
+ return {
12
+ padding: {
13
+ top: 50,
14
+ bottom: 50,
15
+ right: 50,
16
+ left: 50
17
+ },
18
+ count: 250,
19
+ styleFunc: index => ({
20
+ symbolType: "circle",
21
+ fill: "#4e8ae0"
22
+ }),
23
+ gap: [ .5, .5 ],
24
+ aspect: 1,
25
+ direction: "horizontal"
26
+ };
27
+ }
28
+ init() {
29
+ var _a, _b;
30
+ if (!this._graphic) {
31
+ const {width: width, height: height} = this._getContainerSize(this._character.spec.position, null === (_a = this._character.spec.options) || void 0 === _a ? void 0 : _a.graphic), attributes = Object.assign(Object.assign(Object.assign({}, this.getInitialAttributes()), null === (_b = this._character.spec.options) || void 0 === _b ? void 0 : _b.graphic), {
32
+ width: width,
33
+ height: height
34
+ }), gridConfig = this._calculateGrid(attributes);
35
+ this._graphic = createGroup(Object.assign(Object.assign({}, getLayoutFromWidget(this._character.spec.position)), {
36
+ angle: this._character.spec.options.angle,
37
+ zIndex: this._character.spec.zIndex
38
+ })), this._addUnitsToGraphic(gridConfig, attributes), this._character.getGraphicParent().add(this._graphic);
39
+ }
40
+ }
41
+ _getContainerSize(position, graphic) {
42
+ return graphic.width && graphic.height ? {
43
+ width: graphic.width,
44
+ height: graphic.height
45
+ } : "width" in position && "height" in position ? {
46
+ width: position.width,
47
+ height: position.height
48
+ } : "bottom" in position && "right" in position ? {
49
+ width: position.right - position.left,
50
+ height: position.bottom - position.top
51
+ } : void logger("error", "Invalid IWidgetData type");
52
+ }
53
+ _calculateGrid(attributes) {
54
+ const {width: width, height: height, padding: padding, count: count, gap: gap, aspect: aspect, direction: direction} = attributes, innerWidth = width - padding.left - padding.right, innerHeight = height - padding.top - padding.bottom, isHorizontal = "horizontal" === direction, primaryLength = isHorizontal ? innerHeight : innerWidth, secondaryLength = isHorizontal ? innerWidth : innerHeight, adjustedAspect = isHorizontal ? aspect : 1 / aspect, adjustedGap = isHorizontal ? gap : [ gap[1], gap[0] ], minPrimaryCount = this._calculateMinPrimaryCount(primaryLength, secondaryLength, adjustedAspect, adjustedGap, count), {primaryCount: primaryCount, secondaryCount: secondaryCount, unitPrimarySize: unitPrimarySize, unitSecondarySize: unitSecondarySize} = this._convergeGrid(minPrimaryCount, count, primaryLength, secondaryLength, adjustedAspect, adjustedGap), offset = (secondaryLength - secondaryCount * unitSecondarySize - (secondaryCount - 1) * adjustedGap[0] * unitSecondarySize) / (secondaryCount - 1);
55
+ let primaryOffset;
56
+ primaryOffset = secondaryCount <= 1 ? count <= 1 ? (primaryLength - unitPrimarySize) / 2 : (primaryLength - count * unitPrimarySize - (count - 1) * unitPrimarySize * adjustedGap[1]) / (count - 1) : 0;
57
+ const secondaryOffset = secondaryCount <= 1 ? (secondaryLength - unitSecondarySize) / 2 : offset;
58
+ return isHorizontal ? {
59
+ rows: primaryCount,
60
+ cols: secondaryCount,
61
+ unitWidth: unitSecondarySize,
62
+ unitHeight: unitPrimarySize,
63
+ offsetX: secondaryOffset,
64
+ offsetY: primaryOffset
65
+ } : {
66
+ rows: secondaryCount,
67
+ cols: primaryCount,
68
+ unitWidth: unitPrimarySize,
69
+ unitHeight: unitSecondarySize,
70
+ offsetX: primaryOffset,
71
+ offsetY: secondaryOffset
72
+ };
73
+ }
74
+ _calculateMinPrimaryCount(primaryLength, secondaryLength, aspect, gap, count) {
75
+ const a = Math.pow(secondaryLength * (1 + gap[1]), 2), b = gap[0] * aspect * primaryLength - secondaryLength * gap[1], c = -count * primaryLength * aspect * (1 + gap[0]) * (1 + gap[1]), delta = Math.sqrt(b * b - 4 * a * c);
76
+ return Math.ceil((-b + delta) / (2 * a));
77
+ }
78
+ _convergeGrid(minPrimaryCount, count, primaryLength, secondaryLength, aspect, gap) {
79
+ let unitPrimarySize, unitSecondarySize, secondaryCount, totalWidth, primaryCount = minPrimaryCount;
80
+ do {
81
+ unitPrimarySize = primaryLength / (primaryCount * (1 + gap[1]) - gap[1]), unitSecondarySize = aspect * unitPrimarySize,
82
+ secondaryCount = Math.ceil(count / primaryCount), totalWidth = secondaryCount * unitSecondarySize + (secondaryCount - 1) * gap[0] * unitSecondarySize;
83
+ } while (totalWidth > secondaryLength && primaryCount++);
84
+ return {
85
+ primaryCount: primaryCount,
86
+ secondaryCount: secondaryCount,
87
+ unitPrimarySize: unitPrimarySize,
88
+ unitSecondarySize: unitSecondarySize
89
+ };
90
+ }
91
+ _addUnitsToGraphic(gridConfig, attributes) {
92
+ const {rows: rows, cols: cols, unitWidth: unitWidth, unitHeight: unitHeight, offsetX: offsetX, offsetY: offsetY} = gridConfig, {count: count, styleFunc: unitStyle, padding: padding, gap: gap, direction: direction} = attributes, startX = padding.left + unitWidth / 2, startY = padding.top + unitHeight / 2, isHorizontal = "horizontal" === direction;
93
+ for (let i = 0; i < count; i++) {
94
+ const col = isHorizontal ? Math.floor(i / rows) : i % cols, row = isHorizontal ? i % rows : Math.floor(i / cols), dx = startX + col * (unitWidth + gap[0] * unitWidth + offsetX) + (isHorizontal && cols <= 1 ? offsetX : 0) + (!isHorizontal && rows <= 1 ? offsetX : 0), dy = startY + row * (unitHeight + gap[1] * unitHeight + offsetY) + (!isHorizontal && rows <= 1 ? offsetY : 0) + (isHorizontal && cols <= 1 ? offsetY : 0), graphic = createSymbol(Object.assign(Object.assign({}, unitStyle(i)), {
95
+ dx: dx,
96
+ dy: dy,
97
+ size: Math.max(unitWidth, unitHeight)
98
+ }));
99
+ graphic.name = `unit-${i}`, this._graphic.add(graphic);
100
+ }
101
+ }
102
+ }
103
+ //# sourceMappingURL=unit.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/story/character/component/graphic/unit.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,YAAY,EAA6C,MAAM,mBAAmB,CAAC;AACzG,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAE5D,OAAO,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AAmEjD,MAAM,OAAO,WAAY,SAAQ,OAAO;IAGtC,oBAAoB;QAClB,OAAO;YACL,OAAO,EAAE;gBACP,GAAG,EAAE,EAAE;gBACP,MAAM,EAAE,EAAE;gBACV,KAAK,EAAE,EAAE;gBACT,IAAI,EAAE,EAAE;aACT;YACD,KAAK,EAAE,GAAG;YACV,SAAS,EAAE,CAAC,KAAa,EAAE,EAAE,CAAC,CAAC;gBAC7B,UAAU,EAAE,QAAQ;gBACpB,IAAI,EAAE,SAAS;aAChB,CAAC;YACF,GAAG,EAAE,CAAC,GAAG,EAAE,GAAG,CAAC;YACf,MAAM,EAAE,CAAC;YACT,SAAS,EAAE,YAAY;SACxB,CAAC;IACJ,CAAC;IAED,IAAI;;QACF,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE;YAClB,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC,iBAAiB,CAC9C,I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AC;gBACzC,CAAC,CAAC,YAAY,IAAI,IAAI,IAAI,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;YAC7C,MAAM,EAAE,GACN,MAAM;gBACN,GAAG,GAAG,CAAC,UAAU,GAAG,GAAG,CAAC,CAAC,CAAC,GAAG,UAAU,GAAG,OAAO,CAAC;gBAClD,CAAC,CAAC,YAAY,IAAI,IAAI,IAAI,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC;gBAC1C,CAAC,YAAY,IAAI,IAAI,IAAI,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;YAE5C,MAAM,OAAO,GAAG,YAAY,iCAAM,SAAU,CAAC,CAAC,CAAC,KAAE,EAAE,EAAE,EAAE,EAAE,IAAI,EAAE,IAAI,CAAC,GAAG,CAAC,SAAS,EAAE,UAAU,CAAC,IAAG,CAAC;YAClG,OAAO,CAAC,IAAI,GAAG,QAAQ,CAAC,EAAE,CAAC;YAC3B,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;SAC5B;IACH,CAAC;CACF","file":"unit.js","sourcesContent":["import { createGroup, createSymbol, type IGroup, type ISymbolGraphicAttribute } from '@visactor/vrender';\nimport { Graphic } from './graphic';\nimport { getLayoutFromWidget } from '../../../utils/layout';\nimport type { IWidgetData } from '../../dsl-interface';\nimport { logger } from '../../../../util/output';\n\ninterface IGraphicUnitAttributes {\n /**\n * The width of the container.\n * Defaults to the width defined by the position of the character.\n */\n width?: number;\n\n /**\n * The height of the container.\n * Defaults to the height defined by the position of the character.\n */\n height?: number;\n\n /**\n * The padding inside the container, specifying space between the container border and its content.\n * @default { top: 50, bottom: 50, right: 50, left: 50 }\n */\n padding?: {\n top?: number;\n bottom?: number;\n right?: number;\n left?: number;\n };\n\n /**\n * The total number of units to be rendered within the container.\n * @default 250\n */\n count?: number;\n\n /**\n * A function defining the style of each unit based on its index.\n * @default { symbolType: 'circle', fill: '#4e8ae0' }\n */\n styleFunc?: (index: number) => ISymbolGraphicAttribute;\n\n /**\n * The gap between units, represented as a percentage of the unit's width and height.\n * The first value specifies the horizontal gap, and the second value specifies the vertical gap.\n * @default [0.5, 0.5]\n */\n gap?: [number, number];\n\n /**\n * The aspect ratio of the units, defined as width divided by height.\n * @default 1\n */\n aspect?: number;\n\n /**\n * The direction in which units are laid out within the container.\n * @default 'horizontal'\n */\n direction?: 'horizontal' | 'vertical';\n}\n\ninterface IGridConfig {\n rows: number;\n cols: number;\n unitWidth: number;\n unitHeight: number;\n offsetX: number;\n offsetY: number;\n}\n\nexport class GraphicUnit extends Graphic {\n protected _graphic: IGroup;\n\n getInitialAttributes(): IGraphicUnitAttributes {\n return {\n padding: {\n top: 50,\n bottom: 50,\n right: 50,\n left: 50\n },\n count: 250,\n styleFunc: (index: number) => ({\n symbolType: 'circle',\n fill: '#4e8ae0'\n }),\n gap: [0.5, 0.5],\n aspect: 1,\n direction: 'horizontal'\n };\n }\n\n init() {\n if (!this._graphic) {\n const { width, height } = this._getContainerSize(\n this._character.spec.position,\n this._character.spec.options?.graphic\n );\n const attributes = { ...this.getInitialAttributes(), ...this._character.spec.options?.graphic, width, height };\n const gridConfig = this._calculateGrid(attributes);\n this._graphic = createGroup({\n ...getLayoutFromWidget(this._character.spec.position),\n angle: this._character.spec.options.angle,\n zIndex: this._character.spec.zIndex\n });\n this._addUnitsToGraphic(gridConfig, attributes);\n this._character.getGraphicParent().add(this._graphic);\n }\n }\n\n private _getContainerSize(position: IWidgetData, graphic: IGraphicUnitAttributes) {\n if (graphic.width && graphic.height) {\n return { width: graphic.width, height: graphic.height };\n }\n if ('width' in position && 'height' in position) {\n return { width: position.width, height: position.height };\n }\n if ('bottom' in position && 'right' in position) {\n return { width: position.right - position.left, height: position.bottom - position.top };\n }\n logger('error', 'Invalid IWidgetData type');\n }\n\n private _calculateGrid(attributes: IGraphicUnitAttributes): IGridConfig {\n const { width, height, padding, count, gap, aspect, direction } = attributes;\n const innerWidth = width - padding.left - padding.right;\n const innerHeight = height - padding.top - padding.bottom;\n\n const isHorizontal = direction === 'horizontal';\n const primaryLength = isHorizontal ? innerHeight : innerWidth;\n const secondaryLength = isHorizontal ? innerWidth : innerHeight;\n const adjustedAspect = isHorizontal ? aspect : 1 / aspect;\n const adjustedGap: [number, number] = isHorizontal ? gap : [gap[1], gap[0]];\n\n const minPrimaryCount = this._calculateMinPrimaryCount(\n primaryLength,\n secondaryLength,\n adjustedAspect,\n adjustedGap,\n count\n );\n const { primaryCount, secondaryCount, unitPrimarySize, unitSecondarySize } = this._convergeGrid(\n minPrimaryCount,\n count,\n primaryLength,\n secondaryLength,\n adjustedAspect,\n adjustedGap\n );\n\n const offset =\n (secondaryLength -\n secondaryCount * unitSecondarySize -\n (secondaryCount - 1) * adjustedGap[0] * unitSecondarySize) /\n (secondaryCount - 1);\n\n let primaryOffset;\n if (secondaryCount <= 1) {\n if (count <= 1) {\n primaryOffset = (primaryLength - unitPrimarySize) / 2;\n } else {\n primaryOffset =\n (primaryLength - count * unitPrimarySize - (count - 1) * unitPrimarySize * adjustedGap[1]) / (count - 1);\n }\n } else {\n primaryOffset = 0;\n }\n const secondaryOffset = secondaryCount <= 1 ? (secondaryLength - unitSecondarySize) / 2 : offset;\n\n return isHorizontal\n ? {\n rows: primaryCount,\n cols: secondaryCount,\n unitWidth: unitSecondarySize,\n unitHeight: unitPrimarySize,\n offsetX: secondaryOffset,\n offsetY: primaryOffset\n }\n : {\n rows: secondaryCount,\n cols: primaryCount,\n unitWidth: unitPrimarySize,\n unitHeight: unitSecondarySize,\n offsetX: primaryOffset,\n offsetY: secondaryOffset\n };\n }\n\n private _calculateMinPrimaryCount(\n primaryLength: number,\n secondaryLength: number,\n aspect: number,\n gap: [number, number],\n count: number\n ): number {\n const a = Math.pow(secondaryLength * (1 + gap[1]), 2);\n const b = gap[0] * aspect * primaryLength - secondaryLength * gap[1];\n const c = -count * primaryLength * aspect * (1 + gap[0]) * (1 + gap[1]);\n const delta = Math.sqrt(b * b - 4 * a * c);\n return Math.ceil((-b + delta) / (2 * a));\n }\n\n private _convergeGrid(\n minPrimaryCount: number,\n count: number,\n primaryLength: number,\n secondaryLength: number,\n aspect: number,\n gap: [number, number]\n ) {\n let primaryCount = minPrimaryCount;\n let unitPrimarySize;\n let unitSecondarySize;\n let secondaryCount;\n let totalWidth;\n\n do {\n unitPrimarySize = primaryLength / (primaryCount * (1 + gap[1]) - gap[1]);\n unitSecondarySize = aspect * unitPrimarySize;\n secondaryCount = Math.ceil(count / primaryCount);\n totalWidth = secondaryCount * unitSecondarySize + (secondaryCount - 1) * gap[0] * unitSecondarySize;\n } while (totalWidth > secondaryLength && primaryCount++);\n\n return { primaryCount, secondaryCount, unitPrimarySize, unitSecondarySize };\n }\n\n private _addUnitsToGraphic(gridConfig: IGridConfig, attributes: IGraphicUnitAttributes) {\n const { rows, cols, unitWidth, unitHeight, offsetX, offsetY } = gridConfig;\n const { count, styleFunc: unitStyle, padding, gap, direction } = attributes;\n const startX = padding.left + unitWidth / 2;\n const startY = padding.top + unitHeight / 2;\n const isHorizontal = direction === 'horizontal';\n\n for (let i = 0; i < count; i++) {\n const col = isHorizontal ? Math.floor(i / rows) : i % cols;\n const row = isHorizontal ? i % rows : Math.floor(i / cols);\n const dx =\n startX +\n col * (unitWidth + gap[0] * unitWidth + offsetX) +\n (isHorizontal && cols <= 1 ? offsetX : 0) +\n (!isHorizontal && rows <= 1 ? offsetX : 0);\n const dy =\n startY +\n row * (unitHeight + gap[1] * unitHeight + offsetY) +\n (!isHorizontal && rows <= 1 ? offsetY : 0) +\n (isHorizontal && cols <= 1 ? offsetY : 0);\n\n const graphic = createSymbol({ ...unitStyle!(i), dx, dy, size: Math.max(unitWidth, unitHeight) });\n graphic.name = `unit-${i}`;\n this._graphic.add(graphic);\n }\n }\n}\n"]}
package/es/story/index.js CHANGED
@@ -30,6 +30,8 @@ import { CharacterComponentTimeline } from "./character/component/characters/cha
30
30
 
31
31
  import { RankingBarCharacter } from "./character/chart/characters/rankingBar";
32
32
 
33
+ import { CharacterComponentUnit } from "./character/component/characters/character-unit";
34
+
33
35
  const splitModule = new ContainerModule((bind => {
34
36
  bind(VChartRender).toSelf().inSingletonScope(), bind(ChartRender).toService(VChartRender),
35
37
  bind(GraphicRender).toService(ChartRender), bind(VChartPicker).to(VChartPicker).inSingletonScope(),
@@ -50,6 +52,7 @@ export function registerCharacter() {
50
52
  StoryFactory.registerCharacter(StoryComponentType.IMAGE, CharacterComponentImage),
51
53
  StoryFactory.registerCharacter(StoryComponentType.SHAPE, CharacterComponentShape),
52
54
  StoryFactory.registerCharacter(StoryComponentType.TIMELINE, CharacterComponentTimeline),
55
+ StoryFactory.registerCharacter(StoryComponentType.UNIT, CharacterComponentUnit),
53
56
  container.load(splitModule), container.load(editPlugin));
54
57
  }
55
58
 
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/story/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,MAAM,kDAAkD,CAAC;AAC3F,OAAO,EAAE,sBAAsB,EAAE,MAAM,iDAAiD,CAAC;AACzF,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,iBAAiB,EAAE,eAAe,EAAE,aAAa,EAAE,kBAAkB,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AACrH,OAAO,EAAE,wBAAwB,EAAE,MAAM,mBAAmB,CAAC;AAC7D,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,iDAAiD,CAAC;AAC5F,OAAO,EAAE,sBAAsB,EAAE,MAAM,iDAAiD,CAAC;AAEzF,OAAO,EAAE,YAAY,EAAE,MAAM,iDAAiD,CAAC;AAC/E,OAAO,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAC5D,OAAO,EAAE,sBAAsB,EAAE,MAAM,iDAAiD,CAAC;AACzF,OAAO,EAAE,uB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AAI,CAAC;IACjB,YAAY,CAAC,iBAAiB,CAAC,eAAe,CAAC,IAAI,EAAE,eAAe,CAAC,CAAC;IACtE,YAAY,CAAC,iBAAiB,CAAC,mBAAmB,CAAC,IAAI,EAAE,mBAAmB,CAAC,CAAC;IAK9E,YAAY,CAAC,iBAAiB,CAAC,kBAAkB,CAAC,IAAI,EAAE,sBAAsB,CAAC,CAAC;IAChF,YAAY,CAAC,iBAAiB,CAAC,kBAAkB,CAAC,IAAI,EAAE,sBAAsB,CAAC,CAAC;IAEhF,YAAY,CAAC,iBAAiB,CAAC,kBAAkB,CAAC,KAAK,EAAE,uBAAuB,CAAC,CAAC;IAClF,YAAY,CAAC,iBAAiB,CAAC,kBAAkB,CAAC,IAAI,EAAE,sBAAsB,CAAC,CAAC;IAChF,YAAY,CAAC,iBAAiB,CAAC,kBAAkB,CAAC,KAAK,EAAE,uBAAuB,CAAC,CAAC;IAClF,YAAY,CAAC,iBAAiB,CAAC,kBAAkB,CAAC,KAAK,EAAE,uBAAuB,CAAC,CAAC;IAClF,YAAY,CAAC,iBAAiB,CAAC,kBAAkB,CAAC,QAAQ,EAAE,0BAA0B,CAAC,CAAC;IAExF,SAAS,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;IAC5B,SAAS,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;AAC7B,CAAC;AAED,iBAAiB,EAAE,CAAC;AAEpB,cAAc,SAAS,CAAC","file":"index.js","sourcesContent":["import { CharacterComponentQipao } from './character/component/characters/character-qipao';\nimport { CharacterComponentRect } from './character/component/characters/character-rect';\nimport { StoryFactory } from './factory/factory';\nimport { AutoEnablePlugins, ContainerModule, GraphicRender, RichTextEditPlugin, container } from '@visactor/vrender';\nimport { CanvasPickerContribution } from '@visactor/vrender';\nimport { ChartRender, VChartRender } from './character/chart/graphic/vchart-graphic-render';\nimport { CharacterComponentText } from './character/component/characters/character-text';\n// import { CharacterComponentRichText } from './character/component/characters/character-richtext';\nimport { VChartPicker } from './character/chart/graphic/vchart-graphic-picker';\nimport { StoryComponentType } from '../constants/character';\nimport { CharacterComponentLine } from './character/component/characters/character-line';\nimport { CharacterComponentImage } from './character/component/characters/character-image';\nimport { CharacterComponentShape } from './character/component/characters/character-shape';\nimport { VChartCharacter } from './character/chart/characters/vchart';\nimport { ComponentGroupRender } from './character/component/character-group/component-group-graphic-render';\nimport { CharacterComponentTimeline } from './character/component/characters/character-timeline';\nimport { RankingBarCharacter } from './character/chart/characters/rankingBar';\n\nconst splitModule = new ContainerModule(bind => {\n // chart渲染器注入\n bind(VChartRender).toSelf().inSingletonScope();\n bind(ChartRender).toService(VChartRender);\n bind(GraphicRender).toService(ChartRender);\n bind(VChartPicker).to(VChartPicker).inSingletonScope();\n bind(CanvasPickerContribution).toService(VChartPicker);\n\n // component渲染器注入\n bind(ComponentGroupRender).toSelf().inSingletonScope();\n bind(GraphicRender).toService(ComponentGroupRender);\n});\n\nconst editPlugin = new ContainerModule(bind => {\n bind(RichTextEditPlugin).toSelf();\n bind(AutoEnablePlugins).toService(RichTextEditPlugin);\n});\n\nlet _register = false;\nexport function registerCharacter() {\n if (_register) {\n return;\n }\n _register = true;\n StoryFactory.registerCharacter(VChartCharacter.type, VChartCharacter);\n StoryFactory.registerCharacter(RankingBarCharacter.type, RankingBarCharacter);\n\n // StoryFactory.registerCharacter('BarChart', CharacterChart);\n // StoryFactory.registerCharacter('CharacterChart', CharacterChart);\n // StoryFactory.registerCharacter('LineChart', CharacterChart);\n StoryFactory.registerCharacter(StoryComponentType.RECT, CharacterComponentRect);\n StoryFactory.registerCharacter(StoryComponentType.TEXT, CharacterComponentText);\n // StoryFactory.registerCharacter(StoryComponentType.RICH_TEXT, CharacterComponentRichText);\n StoryFactory.registerCharacter(StoryComponentType.QIPAO, CharacterComponentQipao);\n StoryFactory.registerCharacter(StoryComponentType.LINE, CharacterComponentLine);\n StoryFactory.registerCharacter(StoryComponentType.IMAGE, CharacterComponentImage);\n StoryFactory.registerCharacter(StoryComponentType.SHAPE, CharacterComponentShape);\n StoryFactory.registerCharacter(StoryComponentType.TIMELINE, CharacterComponentTimeline);\n\n container.load(splitModule);\n container.load(editPlugin);\n}\n\nregisterCharacter();\n\nexport * from './story';\n"]}
1
+ {"version":3,"sources":["../src/story/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,MAAM,kDAAkD,CAAC;AAC3F,OAAO,EAAE,sBAAsB,EAAE,MAAM,iDAAiD,CAAC;AACzF,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,iBAAiB,EAAE,eAAe,EAAE,aAAa,EAAE,kBAAkB,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AACrH,OAAO,EAAE,wBAAwB,EAAE,MAAM,mBAAmB,CAAC;AAC7D,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,iDAAiD,CAAC;AAC5F,OAAO,EAAE,sBAAsB,EAAE,MAAM,iDAAiD,CAAC;AAEzF,OAAO,EAAE,YAAY,EAAE,MAAM,iDAAiD,CAAC;AAC/E,OAAO,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAC5D,OAAO,EAAE,sBAAsB,EAAE,MAAM,iDAAiD,CAAC;AACzF,OAAO,EAAE,uBAAuB,EAAE,MAAM,kDAAkD,CAAC;AAC3F,OAAO,EAAE,uBAAuB,EAAE,MAAM,kDAAkD,CAAC;AAC3F,OAAO,EAAE,eAAe,EAAE,MAAM,qCAAqC,CAAC;AACtE,OAAO,EAAE,oBAAoB,EAAE,MAAM,sEAAsE,CAAC;AAC5G,OAAO,EAAE,0BAA0B,EAAE,MAAM,qDAAqD,CAAC;AACjG,OAAO,EAAE,mBAAmB,EAAE,MAAM,yCAAyC,CAAC;AAC9E,OAAO,EAAE,sBAAsB,EAAE,MAAM,iDAAiD,CAAC;AAEzF,MAAM,WAAW,GAAG,IAAI,eAAe,CAAC,IAAI,CAAC,EAAE;IAE7C,IAAI,CAAC,YAAY,CA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AAuB,CAAC,CAAC;IAClF,YAAY,CAAC,iBAAiB,CAAC,kBAAkB,CAAC,IAAI,EAAE,sBAAsB,CAAC,CAAC;IAChF,YAAY,CAAC,iBAAiB,CAAC,kBAAkB,CAAC,KAAK,EAAE,uBAAuB,CAAC,CAAC;IAClF,YAAY,CAAC,iBAAiB,CAAC,kBAAkB,CAAC,KAAK,EAAE,uBAAuB,CAAC,CAAC;IAClF,YAAY,CAAC,iBAAiB,CAAC,kBAAkB,CAAC,QAAQ,EAAE,0BAA0B,CAAC,CAAC;IACxF,YAAY,CAAC,iBAAiB,CAAC,kBAAkB,CAAC,IAAI,EAAE,sBAAsB,CAAC,CAAC;IAEhF,SAAS,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;IAC5B,SAAS,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;AAC7B,CAAC;AAED,iBAAiB,EAAE,CAAC;AAEpB,cAAc,SAAS,CAAC","file":"index.js","sourcesContent":["import { CharacterComponentQipao } from './character/component/characters/character-qipao';\nimport { CharacterComponentRect } from './character/component/characters/character-rect';\nimport { StoryFactory } from './factory/factory';\nimport { AutoEnablePlugins, ContainerModule, GraphicRender, RichTextEditPlugin, container } from '@visactor/vrender';\nimport { CanvasPickerContribution } from '@visactor/vrender';\nimport { ChartRender, VChartRender } from './character/chart/graphic/vchart-graphic-render';\nimport { CharacterComponentText } from './character/component/characters/character-text';\n// import { CharacterComponentRichText } from './character/component/characters/character-richtext';\nimport { VChartPicker } from './character/chart/graphic/vchart-graphic-picker';\nimport { StoryComponentType } from '../constants/character';\nimport { CharacterComponentLine } from './character/component/characters/character-line';\nimport { CharacterComponentImage } from './character/component/characters/character-image';\nimport { CharacterComponentShape } from './character/component/characters/character-shape';\nimport { VChartCharacter } from './character/chart/characters/vchart';\nimport { ComponentGroupRender } from './character/component/character-group/component-group-graphic-render';\nimport { CharacterComponentTimeline } from './character/component/characters/character-timeline';\nimport { RankingBarCharacter } from './character/chart/characters/rankingBar';\nimport { CharacterComponentUnit } from './character/component/characters/character-unit';\n\nconst splitModule = new ContainerModule(bind => {\n // chart渲染器注入\n bind(VChartRender).toSelf().inSingletonScope();\n bind(ChartRender).toService(VChartRender);\n bind(GraphicRender).toService(ChartRender);\n bind(VChartPicker).to(VChartPicker).inSingletonScope();\n bind(CanvasPickerContribution).toService(VChartPicker);\n\n // component渲染器注入\n bind(ComponentGroupRender).toSelf().inSingletonScope();\n bind(GraphicRender).toService(ComponentGroupRender);\n});\n\nconst editPlugin = new ContainerModule(bind => {\n bind(RichTextEditPlugin).toSelf();\n bind(AutoEnablePlugins).toService(RichTextEditPlugin);\n});\n\nlet _register = false;\nexport function registerCharacter() {\n if (_register) {\n return;\n }\n _register = true;\n StoryFactory.registerCharacter(VChartCharacter.type, VChartCharacter);\n StoryFactory.registerCharacter(RankingBarCharacter.type, RankingBarCharacter);\n\n // StoryFactory.registerCharacter('BarChart', CharacterChart);\n // StoryFactory.registerCharacter('CharacterChart', CharacterChart);\n // StoryFactory.registerCharacter('LineChart', CharacterChart);\n StoryFactory.registerCharacter(StoryComponentType.RECT, CharacterComponentRect);\n StoryFactory.registerCharacter(StoryComponentType.TEXT, CharacterComponentText);\n // StoryFactory.registerCharacter(StoryComponentType.RICH_TEXT, CharacterComponentRichText);\n StoryFactory.registerCharacter(StoryComponentType.QIPAO, CharacterComponentQipao);\n StoryFactory.registerCharacter(StoryComponentType.LINE, CharacterComponentLine);\n StoryFactory.registerCharacter(StoryComponentType.IMAGE, CharacterComponentImage);\n StoryFactory.registerCharacter(StoryComponentType.SHAPE, CharacterComponentShape);\n StoryFactory.registerCharacter(StoryComponentType.TIMELINE, CharacterComponentTimeline);\n StoryFactory.registerCharacter(StoryComponentType.UNIT, CharacterComponentUnit);\n\n container.load(splitModule);\n container.load(editPlugin);\n}\n\nregisterCharacter();\n\nexport * from './story';\n"]}
@@ -3,7 +3,8 @@ import type { IChartAddAction, IChartUpdateAction } from '../../player/processor
3
3
  import type { IChartVisibilityAction, IComponentVisibilityAction } from '../../player/processor/interface/appear-action';
4
4
  import type { IComponentBounceAction, IComponentMoveToAction, IComponentScaleToAction, IComponentStyleAction } from '../../player/processor/interface/style-action';
5
5
  import type { ICharacterSpec } from '../character';
6
- export type IActionSpec = IComponentStyleAction | IComponentVisibilityAction | IComponentMoveToAction | IComponentScaleToAction | IComponentBounceAction | IChartVisibilityAction | IChartUpdateAction | IChartAddAction | IRankingBarPlayAction;
6
+ import type { IUnitStyleAction, IUnitVisibilityAction } from '../../player/processor/interface/unit-action';
7
+ export type IActionSpec = IComponentStyleAction | IComponentVisibilityAction | IComponentMoveToAction | IComponentScaleToAction | IComponentBounceAction | IChartVisibilityAction | IChartUpdateAction | IChartAddAction | IRankingBarPlayAction | IUnitStyleAction | IUnitVisibilityAction;
7
8
  export interface IStorySpec {
8
9
  acts: IActSpec[];
9
10
  characters: ICharacterSpec[];
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/story/interface/dsl-interface.ts"],"names":[],"mappings":"","file":"dsl-interface.js","sourcesContent":["import type { IRankingBarPlayAction } from './../../player/processor/chart/rankingBar/rankingBar';\nimport type { IChartAddAction, IChartUpdateAction } from '../../player/processor/chart/vchart';\nimport type {\n IChartVisibilityAction,\n IComponentVisibilityAction\n} from '../../player/processor/interface/appear-action';\nimport type {\n IComponentBounceAction,\n IComponentMoveToAction,\n IComponentScaleToAction,\n IComponentStyleAction\n} from '../../player/processor/interface/style-action';\nimport type { ICharacterSpec } from '../character';\n\nexport type IActionSpec =\n | IComponentStyleAction\n | IComponentVisibilityAction\n | IComponentMoveToAction\n | IComponentScaleToAction\n | IComponentBounceAction\n | IChartVisibilityAction\n | IChartUpdateAction\n | IChartAddAction\n | IRankingBarPlayAction;\n\nexport interface IStorySpec {\n acts: IActSpec[]; // 作品的章节\n characters: ICharacterSpec[]; // 作品中的元素\n}\n\nexport interface IActionsLink {\n characterId: string | string[];\n characterActions: IActionSpec[];\n}\n\nexport type ISceneSpec = {\n id: string;\n delay?: number; // 入场延迟,可以是正数或者负数\n actions: IActionsLink[];\n};\n\nexport interface IActSpec {\n id: string;\n scenes: ISceneSpec[];\n}\n"]}
1
+ {"version":3,"sources":["../src/story/interface/dsl-interface.ts"],"names":[],"mappings":"","file":"dsl-interface.js","sourcesContent":["import type { IRankingBarPlayAction } from './../../player/processor/chart/rankingBar/rankingBar';\nimport type { IChartAddAction, IChartUpdateAction } from '../../player/processor/chart/vchart';\nimport type {\n IChartVisibilityAction,\n IComponentVisibilityAction\n} from '../../player/processor/interface/appear-action';\nimport type {\n IComponentBounceAction,\n IComponentMoveToAction,\n IComponentScaleToAction,\n IComponentStyleAction\n} from '../../player/processor/interface/style-action';\nimport type { ICharacterSpec } from '../character';\nimport type { IUnitStyleAction, IUnitVisibilityAction } from '../../player/processor/interface/unit-action';\n\nexport type IActionSpec =\n | IComponentStyleAction\n | IComponentVisibilityAction\n | IComponentMoveToAction\n | IComponentScaleToAction\n | IComponentBounceAction\n | IChartVisibilityAction\n | IChartUpdateAction\n | IChartAddAction\n | IRankingBarPlayAction\n | IUnitStyleAction\n | IUnitVisibilityAction;\n\nexport interface IStorySpec {\n acts: IActSpec[]; // 作品的章节\n characters: ICharacterSpec[]; // 作品中的元素\n}\n\nexport interface IActionsLink {\n characterId: string | string[];\n characterActions: IActionSpec[];\n}\n\nexport type ISceneSpec = {\n id: string;\n delay?: number; // 入场延迟,可以是正数或者负数\n actions: IActionsLink[];\n};\n\nexport interface IActSpec {\n id: string;\n scenes: ISceneSpec[];\n}\n"]}
@@ -2,7 +2,10 @@ import type { IGraphic, IStage } from '@visactor/vrender';
2
2
  import type { ICharacter, ICharacterSpec } from '../character';
3
3
  import type { IPlayer } from '../../player/interface/player';
4
4
  export interface IStoryInitOption {
5
- dom: string | HTMLDivElement;
5
+ dom?: string | HTMLDivElement;
6
+ canvas?: string | HTMLCanvasElement;
7
+ width?: number;
8
+ height?: number;
6
9
  playerOption?: {
7
10
  scaleX?: number;
8
11
  scaleY?: number;
@@ -11,6 +14,7 @@ export interface IStoryInitOption {
11
14
  export interface IStoryCanvas {
12
15
  getStage: () => IStage;
13
16
  getCanvas: () => HTMLCanvasElement;
17
+ resize: (w: number, height: number) => void;
14
18
  getEventDetail: (event: StoryEvent) => {
15
19
  character: ICharacter;
16
20
  characterInfo: undefined;
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/story/interface/runtime-interface.ts"],"names":[],"mappings":"","file":"runtime-interface.js","sourcesContent":["import type { IGraphic, IStage } from '@visactor/vrender';\nimport type { ICharacter, ICharacterSpec } from '../character';\nimport type { IPlayer } from '../../player/interface/player';\n\nexport interface IStoryInitOption {\n dom: string | HTMLDivElement; // dom id\n playerOption?: {\n scaleX?: number;\n scaleY?: number;\n };\n}\n\nexport interface IStoryCanvas {\n getStage: () => IStage;\n getCanvas: () => HTMLCanvasElement;\n getEventDetail: (event: StoryEvent) => {\n character: ICharacter;\n characterInfo: undefined;\n };\n release: () => void;\n}\n\nexport interface IStory {\n readonly id: string;\n readonly player: IPlayer;\n canvas: IStoryCanvas;\n getCharacters: () => { [key: string]: ICharacter };\n getCharactersById: (key: string) => ICharacter | null;\n}\nexport interface ICharacterTree {\n getCharacters: () => { [key: string]: ICharacter };\n getCharactersById: (key: string) => ICharacter | null;\n addCharacter: (spec: ICharacterSpec) => ICharacter;\n initCharacters: (spec: ICharacterSpec[]) => void;\n}\n\nexport type StoryEvent = Event & {\n detailPath: IGraphic[];\n path: IGraphic[];\n canvasX?: number;\n canvasY?: number;\n};\n"]}
1
+ {"version":3,"sources":["../src/story/interface/runtime-interface.ts"],"names":[],"mappings":"","file":"runtime-interface.js","sourcesContent":["import type { IGraphic, IStage } from '@visactor/vrender';\nimport type { ICharacter, ICharacterSpec } from '../character';\nimport type { IPlayer } from '../../player/interface/player';\n\nexport interface IStoryInitOption {\n dom?: string | HTMLDivElement; // dom id\n canvas?: string | HTMLCanvasElement; // canvas id\n width?: number;\n height?: number;\n playerOption?: {\n scaleX?: number;\n scaleY?: number;\n };\n}\n\nexport interface IStoryCanvas {\n getStage: () => IStage;\n getCanvas: () => HTMLCanvasElement;\n resize: (w: number, height: number) => void;\n getEventDetail: (event: StoryEvent) => {\n character: ICharacter;\n characterInfo: undefined;\n };\n release: () => void;\n}\n\nexport interface IStory {\n readonly id: string;\n readonly player: IPlayer;\n canvas: IStoryCanvas;\n getCharacters: () => { [key: string]: ICharacter };\n getCharactersById: (key: string) => ICharacter | null;\n}\nexport interface ICharacterTree {\n getCharacters: () => { [key: string]: ICharacter };\n getCharactersById: (key: string) => ICharacter | null;\n addCharacter: (spec: ICharacterSpec) => ICharacter;\n initCharacters: (spec: ICharacterSpec[]) => void;\n}\n\nexport type StoryEvent = Event & {\n detailPath: IGraphic[];\n path: IGraphic[];\n canvasX?: number;\n canvasY?: number;\n};\n"]}
@@ -11,7 +11,7 @@ export declare class Story implements IStory {
11
11
  protected _spec: IStorySpec;
12
12
  get canvas(): IStoryCanvas;
13
13
  get player(): IPlayer;
14
- constructor(spec: IStorySpec, option: IStoryInitOption);
14
+ constructor(spec: IStorySpec | null, option: IStoryInitOption);
15
15
  load(spec: IStorySpec): void;
16
16
  getCharacters(): {
17
17
  [key: string]: ICharacter;
package/es/story/story.js CHANGED
@@ -44,8 +44,12 @@ export class Story {
44
44
  return this._player;
45
45
  }
46
46
  constructor(spec, option) {
47
- this.id = "test-mvp_" + Story._id_++, this._canvas = new StoryCanvas(this, isString(option.dom) ? document.getElementById(option.dom) : option.dom),
48
- this._player = new Player(this, option.playerOption), this._characterTree = new CharacterTree(this),
47
+ this.id = "test-mvp_" + Story._id_++, this._canvas = new StoryCanvas(this, {
48
+ container: isString(option.dom) ? document.getElementById(option.dom) : option.dom,
49
+ canvas: isString(option.canvas) ? document.getElementById(option.canvas) : option.canvas,
50
+ width: option.width,
51
+ height: option.height
52
+ }), this._player = new Player(this, option.playerOption), this._characterTree = new CharacterTree(this),
49
53
  spec && this.load(spec);
50
54
  }
51
55
  load(spec) {
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/story/story.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ACpD,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACnC,CAAC;IAED,aAAa;QACX,OAAO,IAAI,CAAC,cAAc,CAAC,aAAa,EAAE,CAAC;IAC7C,CAAC;IAED,iBAAiB,CAAC,GAAW;QAC3B,OAAO,IAAI,CAAC,cAAc,CAAC,iBAAiB,CAAC,GAAG,CAAC,CAAC;IACpD,CAAC;IAMD,IAAI,CAAC,OAAgB,IAAI;QAEvB,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACpC,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC;QACpB,IAAI,IAAI,EAAE;YACR,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,QAAQ,EAAE,GAAG,EAAE;gBAC/B,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YAClB,CAAC,CAAC,CAAC;SACJ;IACH,CAAC;IAED,KAAK;QACH,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC;QACrB,OAAO;IACT,CAAC;IAEK,aAAa,CAAC,YAAoB,EAAE,UAAkB,EAAE,GAAW;;YACvE,OAAO,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,UAAU,EAAE,GAAG,CAAC,CAAC;QACrD,CAAC;KAAA;IAED,SAAS;QACP,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,CAAC;IAED,OAAO;QACL,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC;QACvB,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC;IACzB,CAAC;;AAhFM,UAAI,GAAG,CAAC,CAAC","file":"story.js","sourcesContent":["import type { ICharacterSpec } from './character/dsl-interface';\nimport { isString } from '@visactor/vutils';\nimport type { ICharacterTree, IStory, IStoryCanvas, IStoryInitOption } from './interface/runtime-interface';\nimport type { ICharacter } from './character/runtime-interface';\nimport { StoryCanvas } from './canvas/canvas';\nimport type { IStorySpec, IActSpec } from './interface';\nimport { StoryFactory } from './factory/factory';\nimport { defaultTicker, defaultTimeline } from '@visactor/vrender';\nimport { CharacterTree } from './character-tree/character-tree';\nimport type { IPlayer } from '../player/interface/player';\nimport { Player } from '../player/player';\nimport { logger } from '../util/output';\n\ndefaultTicker.remTimeline(defaultTimeline);\n\nexport class Story implements IStory {\n static _id_ = 0;\n\n protected _player: IPlayer;\n\n readonly id: string;\n\n protected _canvas: IStoryCanvas;\n\n protected _characterTree: ICharacterTree;\n\n protected _spec: IStorySpec;\n\n get canvas() {\n return this._canvas;\n }\n\n get player(): IPlayer {\n return this._player;\n }\n\n constructor(spec: IStorySpec, option: IStoryInitOption) {\n this.id = 'test-mvp_' + Story._id_++;\n this._canvas = new StoryCanvas(\n this,\n isString(option.dom) ? (document.getElementById(option.dom) as HTMLDivElement) : option.dom\n );\n this._player = new Player(this, option.playerOption);\n\n this._characterTree = new CharacterTree(this);\n spec && this.load(spec);\n }\n\n load(spec: IStorySpec) {\n this._spec = spec;\n if (!spec) {\n return;\n }\n this._characterTree.initCharacters(spec.characters);\n this._player.initActs(spec.acts);\n }\n\n getCharacters(): { [key: string]: ICharacter } {\n return this._characterTree.getCharacters();\n }\n\n getCharactersById(key: string) {\n return this._characterTree.getCharactersById(key);\n }\n\n // private _createAct(spec: IActSpec) {\n // this._player.addAct(spec, this._characters);\n // }\n\n play(loop: boolean = true) {\n // player 开始播放\n this._spec && this.load(this._spec);\n this._player.play();\n if (loop) {\n this._player.once('onstop', () => {\n this.play(loop);\n });\n }\n }\n\n pause() {\n this._player.pause();\n return;\n }\n\n async encodeToVideo(actIndexOrId: number, millsecond: number, fps: number) {\n return this._player.encodeToVideo(millsecond, fps);\n }\n\n getPlayer() {\n return this._player;\n }\n\n release() {\n this._player.release();\n this._canvas.release();\n }\n}\n"]}
1
+ {"version":3,"sources":["../src/story/story.ts"],"names":[],"mappings":";;;;;;;;;AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,k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CAAC,CAAC","file":"story.js","sourcesContent":["import type { ICharacterSpec } from './character/dsl-interface';\nimport { isString } from '@visactor/vutils';\nimport type { ICharacterTree, IStory, IStoryCanvas, IStoryInitOption } from './interface/runtime-interface';\nimport type { ICharacter } from './character/runtime-interface';\nimport { StoryCanvas } from './canvas/canvas';\nimport type { IStorySpec, IActSpec } from './interface';\nimport { StoryFactory } from './factory/factory';\nimport { defaultTicker, defaultTimeline } from '@visactor/vrender';\nimport { CharacterTree } from './character-tree/character-tree';\nimport type { IPlayer } from '../player/interface/player';\nimport { Player } from '../player/player';\nimport { logger } from '../util/output';\n\ndefaultTicker.remTimeline(defaultTimeline);\n\nexport class Story implements IStory {\n static _id_ = 0;\n\n protected _player: IPlayer;\n\n readonly id: string;\n\n protected _canvas: IStoryCanvas;\n\n protected _characterTree: ICharacterTree;\n\n protected _spec: IStorySpec;\n\n get canvas() {\n return this._canvas;\n }\n\n get player(): IPlayer {\n return this._player;\n }\n\n constructor(spec: IStorySpec | null, option: IStoryInitOption) {\n this.id = 'test-mvp_' + Story._id_++;\n this._canvas = new StoryCanvas(this, {\n container: isString(option.dom) ? (document.getElementById(option.dom) as HTMLDivElement) : option.dom,\n canvas: isString(option.canvas) ? (document.getElementById(option.canvas) as HTMLCanvasElement) : option.canvas,\n width: option.width,\n height: option.height\n });\n this._player = new Player(this, option.playerOption);\n\n this._characterTree = new CharacterTree(this);\n spec && this.load(spec);\n }\n\n load(spec: IStorySpec) {\n this._spec = spec;\n if (!spec) {\n return;\n }\n this._characterTree.initCharacters(spec.characters);\n this._player.initActs(spec.acts);\n }\n\n getCharacters(): { [key: string]: ICharacter } {\n return this._characterTree.getCharacters();\n }\n\n getCharactersById(key: string) {\n return this._characterTree.getCharactersById(key);\n }\n\n // private _createAct(spec: IActSpec) {\n // this._player.addAct(spec, this._characters);\n // }\n\n play(loop: boolean = true) {\n // player 开始播放\n this._spec && this.load(this._spec);\n this._player.play();\n if (loop) {\n this._player.once('onstop', () => {\n this.play(loop);\n });\n }\n }\n\n pause() {\n this._player.pause();\n return;\n }\n\n async encodeToVideo(actIndexOrId: number, millsecond: number, fps: number) {\n return this._player.encodeToVideo(millsecond, fps);\n }\n\n getPlayer() {\n return this._player;\n }\n\n release() {\n this._player.release();\n this._canvas.release();\n }\n}\n"]}
@@ -0,0 +1,4 @@
1
+ import type { IUnitTemplateSpec } from './type';
2
+ export declare const DEFAULT_SCENE_DURATION = 5000;
3
+ export declare const DEFAULT_ANIMATION_DURATION = 1000;
4
+ export declare const defaultConfig: Partial<IUnitTemplateSpec>;
@@ -0,0 +1,48 @@
1
+ export const DEFAULT_SCENE_DURATION = 5e3;
2
+
3
+ export const DEFAULT_ANIMATION_DURATION = 1e3;
4
+
5
+ export const defaultConfig = {
6
+ layout: {
7
+ width: 1920,
8
+ height: 1080,
9
+ title: {
10
+ height: 250,
11
+ backgroundColor: "#ffffff",
12
+ style: {
13
+ fontSize: 40,
14
+ fontWeight: 200,
15
+ textAlign: "center",
16
+ fill: "black",
17
+ wordBreak: "break-word"
18
+ },
19
+ padding: {
20
+ left: 50,
21
+ right: 50,
22
+ top: 50,
23
+ bottom: 0
24
+ }
25
+ },
26
+ viz: {
27
+ backgroundColor: "#ffffff",
28
+ direction: "horizontal",
29
+ padding: {
30
+ left: 50,
31
+ right: 50,
32
+ top: 50,
33
+ bottom: 50
34
+ }
35
+ }
36
+ },
37
+ unit: {
38
+ gap: [ .5, .5 ],
39
+ aspect: 1,
40
+ defaultStyle: {
41
+ symbolType: "circle",
42
+ fill: "#ffffff"
43
+ }
44
+ },
45
+ data: [],
46
+ scenes: []
47
+ };
48
+ //# sourceMappingURL=default.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/template/unit/default.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,sBAAsB,GAAG,IAAI,CAAC;AAC3C,MAAM,CAAC,MAAM,0BAA0B,GAAG,IAAI,CAAC;AAE/C,MAAM,CAAC,MAAM,aAAa,GAA+B;IACvD,MAAM,EAAE;QACN,KAAK,EAAE,IAAI;QACX,MAAM,EAAE,IAAI;QACZ,KAAK,EAAE;YACL,MAAM,EAAE,GAAG;YACX,eAAe,EAAE,SAAS;YAC1B,KAAK,EAAE;gBACL,QAAQ,EAAE,EAAE;gBACZ,UAAU,EAAE,GAAG;gBACf,SAAS,EAAE,QAAQ;gBACnB,IAAI,EAAE,OAAO;gBACb,SAAS,EAAE,YAAY;aACxB;YACD,OAAO,EAAE;gBACP,IAAI,EAAE,EAAE;gBACR,KAAK,EAAE,EAAE;gBACT,GAAG,EAAE,EAAE;gBACP,MAAM,EAAE,CAAC;aACV;SACF;QACD,GAAG,EAAE;YACH,eAAe,EAAE,SAAS;YAC1B,SAAS,EAAE,YAAY;YACvB,OAAO,EAAE;gBACP,IAAI,EAAE,EAAE;gBACR,KAAK,EAAE,EAAE;gBACT,GAAG,EAAE,EAAE;gBACP,MAAM,EAAE,EAAE;aACX;SACF;KACF;IACD,IAAI,EAAE;QACJ,GAAG,EAAE,CAAC,GAAG,EAAE,GAAG,CAAC;QACf,MAAM,EAAE,CAAC;QACT,YAAY,EAAE;YACZ,UAAU,EAAE,QAAQ;YACpB,IAAI,EAAE,SAAS;SAChB;KACF;IACD,IAAI,EAAE,EAAE;IACR,MAAM,EAAE,EAAE;CACX,CAAC","file":"default.js","sourcesContent":["import type { IUnitTemplateSpec } from './type';\n\nexport const DEFAULT_SCENE_DURATION = 5000;\nexport const DEFAULT_ANIMATION_DURATION = 1000;\n\nexport const defaultConfig: Partial<IUnitTemplateSpec> = {\n layout: {\n width: 1920,\n height: 1080,\n title: {\n height: 250,\n backgroundColor: '#ffffff',\n style: {\n fontSize: 40,\n fontWeight: 200,\n textAlign: 'center',\n fill: 'black',\n wordBreak: 'break-word'\n },\n padding: {\n left: 50,\n right: 50,\n top: 50,\n bottom: 0\n }\n },\n viz: {\n backgroundColor: '#ffffff',\n direction: 'horizontal',\n padding: {\n left: 50,\n right: 50,\n top: 50,\n bottom: 50\n }\n }\n },\n unit: {\n gap: [0.5, 0.5],\n aspect: 1,\n defaultStyle: {\n symbolType: 'circle',\n fill: '#ffffff'\n }\n },\n data: [],\n scenes: []\n};\n"]}
@@ -0,0 +1,2 @@
1
+ export * from './type';
2
+ export * from './unit';
@@ -0,0 +1,4 @@
1
+ export * from "./type";
2
+
3
+ export * from "./unit";
4
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/template/unit/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAC;AACvB,cAAc,QAAQ,CAAC","file":"index.js","sourcesContent":["export * from './type';\nexport * from './unit';\n"]}
@@ -0,0 +1,51 @@
1
+ import type { ISymbolGraphicAttribute, ITextGraphicAttribute } from '@visactor/vrender-core';
2
+ import type { IEditorTextGraphicAttribute } from '../../story/character';
3
+ export interface IUnitTemplateSpec {
4
+ layout?: {
5
+ width?: number;
6
+ height?: number;
7
+ title?: {
8
+ height?: number;
9
+ backgroundColor?: string;
10
+ style?: IEditorTextGraphicAttribute;
11
+ padding?: {
12
+ left?: number;
13
+ right?: number;
14
+ top?: number;
15
+ bottom?: number;
16
+ };
17
+ };
18
+ viz?: {
19
+ backgroundColor?: string;
20
+ direction?: 'horizontal' | 'vertical';
21
+ padding?: {
22
+ left?: number;
23
+ right?: number;
24
+ top?: number;
25
+ bottom?: number;
26
+ };
27
+ };
28
+ };
29
+ unit?: {
30
+ gap?: [number, number];
31
+ aspect?: number;
32
+ defaultStyle?: ISymbolGraphicAttribute | ((index: number) => ISymbolGraphicAttribute);
33
+ };
34
+ data: Record<string, any>[];
35
+ scenes: {
36
+ title: ITextGraphicAttribute[];
37
+ sceneDuration?: number;
38
+ animationDuration?: number;
39
+ nodes: QueryNode[];
40
+ }[];
41
+ }
42
+ export interface QueryNode {
43
+ query?: (datum: any) => boolean;
44
+ style?: ISymbolGraphicAttribute;
45
+ children?: QueryNode[];
46
+ }
47
+ export interface UnitNode {
48
+ style?: ISymbolGraphicAttribute;
49
+ count: number;
50
+ children?: UnitNode[];
51
+ }
@@ -0,0 +1,2 @@
1
+ export { };
2
+ //# sourceMappingURL=type.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/template/unit/type.ts"],"names":[],"mappings":"","file":"type.js","sourcesContent":["import type { ISymbolGraphicAttribute, ITextGraphicAttribute } from '@visactor/vrender-core';\nimport type { IEditorTextGraphicAttribute } from '../../story/character';\n\nexport interface IUnitTemplateSpec {\n layout?: {\n width?: number;\n height?: number;\n title?: {\n height?: number;\n backgroundColor?: string;\n style?: IEditorTextGraphicAttribute;\n padding?: {\n left?: number;\n right?: number;\n top?: number;\n bottom?: number;\n };\n };\n viz?: {\n backgroundColor?: string;\n direction?: 'horizontal' | 'vertical';\n padding?: {\n left?: number;\n right?: number;\n top?: number;\n bottom?: number;\n };\n };\n };\n unit?: {\n gap?: [number, number];\n aspect?: number;\n defaultStyle?: ISymbolGraphicAttribute | ((index: number) => ISymbolGraphicAttribute);\n };\n data: Record<string, any>[];\n scenes: {\n title: ITextGraphicAttribute[];\n sceneDuration?: number;\n animationDuration?: number;\n nodes: QueryNode[];\n }[];\n}\n\nexport interface QueryNode {\n query?: (datum: any) => boolean;\n style?: ISymbolGraphicAttribute;\n children?: QueryNode[];\n}\n\nexport interface UnitNode {\n style?: ISymbolGraphicAttribute;\n count: number;\n children?: UnitNode[];\n}\n"]}
@@ -0,0 +1,3 @@
1
+ import type { IUnitTemplateSpec } from './type';
2
+ import type { IStorySpec } from '../../story/interface';
3
+ export declare function generateSpec(input: IUnitTemplateSpec): IStorySpec;