eli-video-interview 1.2.42-alpha.67 → 1.2.42-alpha.69

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.
@@ -18,5 +18,6 @@ export declare function getLevel(score: any): {
18
18
  interface GraphProps {
19
19
  items: Array<Dimension>;
20
20
  }
21
+ export declare function hookCanvasContext(ctx: any): void;
21
22
  declare const _default: import("react").NamedExoticComponent<GraphProps>;
22
23
  export default _default;
@@ -1,3 +1,14 @@
1
+ var __values = (this && this.__values) || function(o) {
2
+ var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
3
+ if (m) return m.call(o);
4
+ if (o && typeof o.length === "number") return {
5
+ next: function () {
6
+ if (o && i >= o.length) o = void 0;
7
+ return { value: o && o[i++], done: !o };
8
+ }
9
+ };
10
+ throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
11
+ };
1
12
  var __read = (this && this.__read) || function (o, n) {
2
13
  var m = typeof Symbol === "function" && o[Symbol.iterator];
3
14
  if (!m) return o;
@@ -87,8 +98,10 @@ function isInPath(x, y, rect, ctx) {
87
98
  }
88
99
  var drawTop = function (layout, ctx) {
89
100
  // 设置全局样式
90
- var leftLableWidth = layout.leftLableWidth, height = layout.height, topLableHeight = layout.topLableHeight;
101
+ var leftLableWidth = layout.leftLableWidth, height = layout.height;
91
102
  var offset = leftLableWidth;
103
+ var lineEndY = height - 40; // 虚线结束位置,距离底部40px
104
+ var scoreTextY = height - 25; // 分数文字的Y位置,距离底部25px
92
105
  levelOrder.forEach(function (level, i) {
93
106
  var _a = levelConf[level], width = _a.width, gradient = _a.gradient, label = _a.label, fontColor = _a.fontColor;
94
107
  // 绘制渐变背景
@@ -102,15 +115,15 @@ var drawTop = function (layout, ctx) {
102
115
  ctx.fillStyle = fontColor;
103
116
  ctx.fillText(label, offset + width / 2 - labelWidth / 2, 18);
104
117
  // 绘制垂直虚线
105
- drawVerticalDashedLine(ctx, offset - 1, 0, height + topLableHeight - 54, 2, 2);
118
+ drawVerticalDashedLine(ctx, offset - 1, 0, lineEndY, 2, 2);
106
119
  // 绘制分数文本
107
120
  ctx.fillStyle = '#4CAF50';
108
- ctx.fillText("".concat(levelOrderScore[i]), offset - (i === 0 ? 5 : 9), height + topLableHeight - 40);
121
+ ctx.fillText("".concat(levelOrderScore[i]), offset - (i === 0 ? 5 : 9), scoreTextY);
109
122
  offset += width + 1;
110
123
  // 绘制结束的虚线和文本 '100'
111
124
  if (i === levelOrder.length - 1) {
112
- drawVerticalDashedLine(ctx, offset - 2, 0, height + topLableHeight - 54, 2, 2);
113
- ctx.fillText('100', offset - 2 - 24, height + topLableHeight - 40);
125
+ drawVerticalDashedLine(ctx, offset - 2, 0, lineEndY, 2, 2);
126
+ ctx.fillText('100', offset - 2 - 24, scoreTextY);
114
127
  }
115
128
  });
116
129
  };
@@ -183,11 +196,11 @@ var draw = function (layout, dimensions, pathRef, ctx) {
183
196
  // 绘制圆角矩形
184
197
  var borderRadius = 12;
185
198
  var x = layout.leftLableWidth;
186
- var y = 50 + 40 * i;
199
+ var y = 50 + layout.itemSpacing * i;
187
200
  // 设置背景颜色
188
201
  ctx.fillStyle = config.backgroundColor;
189
202
  drawRoundedRect(x, y, MAX_WIDTH, MAX_HEIGHT, borderRadius, true, false, ctx);
190
- var endPointY = 65 + layout.itemSpacing * i;
203
+ var endPointY = 50 + 15 + layout.itemSpacing * i; // 50是顶部偏移,15是文字相对矩形的偏移
191
204
  drawLable(v.name, 0, endPointY, ctx);
192
205
  pathRef.push({ x: 0, y: y, width: layout.leftLableWidth, height: 22, tips: "".concat(v.name, ": ").concat(v.score) });
193
206
  var score = v.score === 0 ? 0 : Math.max(v.score, 4);
@@ -200,16 +213,54 @@ var draw = function (layout, dimensions, pathRef, ctx) {
200
213
  });
201
214
  drawTop(layout, ctx);
202
215
  };
216
+ export function hookCanvasContext(ctx) {
217
+ var e_1, _a;
218
+ var methods = Object.getOwnPropertyNames(Object.getPrototypeOf(ctx)).filter(function (k) { return typeof ctx[k] === 'function'; });
219
+ var _loop_1 = function (method) {
220
+ var original = ctx[method];
221
+ ctx[method] = function () {
222
+ var args = [];
223
+ for (var _i = 0; _i < arguments.length; _i++) {
224
+ args[_i] = arguments[_i];
225
+ }
226
+ console.log("[Canvas2D] ".concat(method, "(").concat(args.map(function (a) { return JSON.stringify(a); }).join(', '), ")"));
227
+ return original.apply(this, args);
228
+ };
229
+ };
230
+ try {
231
+ for (var methods_1 = __values(methods), methods_1_1 = methods_1.next(); !methods_1_1.done; methods_1_1 = methods_1.next()) {
232
+ var method = methods_1_1.value;
233
+ _loop_1(method);
234
+ }
235
+ }
236
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
237
+ finally {
238
+ try {
239
+ if (methods_1_1 && !methods_1_1.done && (_a = methods_1.return)) _a.call(methods_1);
240
+ }
241
+ finally { if (e_1) throw e_1.error; }
242
+ }
243
+ }
203
244
  var Graph = function (_a) {
204
245
  var _b = _a.items, items = _b === void 0 ? [] : _b;
205
246
  var ref = useRef(null);
206
247
  var pathRef = useRef([]);
207
248
  var _c = __read(useState(), 2), ctx = _c[0], setCtx = _c[1];
208
- var height = useMemo(function () { return 36 * items.length + 50 + 35; }, [items]);
249
+ // 统一间距配置
250
+ var ITEM_SPACING = 40;
251
+ var TOP_OFFSET = 50;
252
+ var BOTTOM_SPACING = 20; // 最后一个item与虚线之间的间距
253
+ var SCORE_AREA_HEIGHT = 40; // 分数区域的高度
254
+ var height = useMemo(function () {
255
+ if (items.length === 0)
256
+ return 0;
257
+ return TOP_OFFSET + (items.length - 1) * ITEM_SPACING + MAX_HEIGHT + BOTTOM_SPACING + SCORE_AREA_HEIGHT;
258
+ }, [items]);
209
259
  useEffect(function () {
210
260
  if (items.length === 0)
211
261
  return;
212
262
  var currentCtx = setupCanvas(ref.current);
263
+ // hookCanvasContext(currentCtx);
213
264
  setCtx(currentCtx);
214
265
  tipEl.style.background = 'rgba(0,0,0,.7)';
215
266
  tipEl.style.color = '#fff';
@@ -232,13 +283,13 @@ var Graph = function (_a) {
232
283
  var layout = {
233
284
  leftLableWidth: 140,
234
285
  topLableHeight: 40,
235
- itemSpacing: 40,
286
+ itemSpacing: ITEM_SPACING,
236
287
  height: height,
237
288
  };
238
289
  pathRef.current = [];
239
290
  draw(layout, items, pathRef.current, ctx);
240
291
  }
241
- }, [ctx, items, height]);
292
+ }, [ctx, items, height, ITEM_SPACING]);
242
293
  // useEffect(() => {
243
294
  // console.log(pathRef);
244
295
  // }, [pathRef]);
@@ -18,5 +18,6 @@ export declare function getLevel(score: any): {
18
18
  interface GraphProps {
19
19
  items: Array<Dimension>;
20
20
  }
21
+ export declare function hookCanvasContext(ctx: any): void;
21
22
  declare const _default: import("react").NamedExoticComponent<GraphProps>;
22
23
  export default _default;
@@ -1,4 +1,15 @@
1
1
  "use strict";
2
+ var __values = (this && this.__values) || function(o) {
3
+ var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
4
+ if (m) return m.call(o);
5
+ if (o && typeof o.length === "number") return {
6
+ next: function () {
7
+ if (o && i >= o.length) o = void 0;
8
+ return { value: o && o[i++], done: !o };
9
+ }
10
+ };
11
+ throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
12
+ };
2
13
  var __read = (this && this.__read) || function (o, n) {
3
14
  var m = typeof Symbol === "function" && o[Symbol.iterator];
4
15
  if (!m) return o;
@@ -16,7 +27,7 @@ var __read = (this && this.__read) || function (o, n) {
16
27
  return ar;
17
28
  };
18
29
  Object.defineProperty(exports, "__esModule", { value: true });
19
- exports.getLevel = void 0;
30
+ exports.hookCanvasContext = exports.getLevel = void 0;
20
31
  var jsx_runtime_1 = require("react/jsx-runtime");
21
32
  var react_1 = require("react");
22
33
  function setupCanvas(canvas) {
@@ -90,8 +101,10 @@ function isInPath(x, y, rect, ctx) {
90
101
  }
91
102
  var drawTop = function (layout, ctx) {
92
103
  // 设置全局样式
93
- var leftLableWidth = layout.leftLableWidth, height = layout.height, topLableHeight = layout.topLableHeight;
104
+ var leftLableWidth = layout.leftLableWidth, height = layout.height;
94
105
  var offset = leftLableWidth;
106
+ var lineEndY = height - 40; // 虚线结束位置,距离底部40px
107
+ var scoreTextY = height - 25; // 分数文字的Y位置,距离底部25px
95
108
  levelOrder.forEach(function (level, i) {
96
109
  var _a = levelConf[level], width = _a.width, gradient = _a.gradient, label = _a.label, fontColor = _a.fontColor;
97
110
  // 绘制渐变背景
@@ -105,15 +118,15 @@ var drawTop = function (layout, ctx) {
105
118
  ctx.fillStyle = fontColor;
106
119
  ctx.fillText(label, offset + width / 2 - labelWidth / 2, 18);
107
120
  // 绘制垂直虚线
108
- drawVerticalDashedLine(ctx, offset - 1, 0, height + topLableHeight - 54, 2, 2);
121
+ drawVerticalDashedLine(ctx, offset - 1, 0, lineEndY, 2, 2);
109
122
  // 绘制分数文本
110
123
  ctx.fillStyle = '#4CAF50';
111
- ctx.fillText("".concat(levelOrderScore[i]), offset - (i === 0 ? 5 : 9), height + topLableHeight - 40);
124
+ ctx.fillText("".concat(levelOrderScore[i]), offset - (i === 0 ? 5 : 9), scoreTextY);
112
125
  offset += width + 1;
113
126
  // 绘制结束的虚线和文本 '100'
114
127
  if (i === levelOrder.length - 1) {
115
- drawVerticalDashedLine(ctx, offset - 2, 0, height + topLableHeight - 54, 2, 2);
116
- ctx.fillText('100', offset - 2 - 24, height + topLableHeight - 40);
128
+ drawVerticalDashedLine(ctx, offset - 2, 0, lineEndY, 2, 2);
129
+ ctx.fillText('100', offset - 2 - 24, scoreTextY);
117
130
  }
118
131
  });
119
132
  };
@@ -187,11 +200,11 @@ var draw = function (layout, dimensions, pathRef, ctx) {
187
200
  // 绘制圆角矩形
188
201
  var borderRadius = 12;
189
202
  var x = layout.leftLableWidth;
190
- var y = 50 + 40 * i;
203
+ var y = 50 + layout.itemSpacing * i;
191
204
  // 设置背景颜色
192
205
  ctx.fillStyle = config.backgroundColor;
193
206
  drawRoundedRect(x, y, MAX_WIDTH, MAX_HEIGHT, borderRadius, true, false, ctx);
194
- var endPointY = 65 + layout.itemSpacing * i;
207
+ var endPointY = 50 + 15 + layout.itemSpacing * i; // 50是顶部偏移,15是文字相对矩形的偏移
195
208
  drawLable(v.name, 0, endPointY, ctx);
196
209
  pathRef.push({ x: 0, y: y, width: layout.leftLableWidth, height: 22, tips: "".concat(v.name, ": ").concat(v.score) });
197
210
  var score = v.score === 0 ? 0 : Math.max(v.score, 4);
@@ -204,16 +217,55 @@ var draw = function (layout, dimensions, pathRef, ctx) {
204
217
  });
205
218
  drawTop(layout, ctx);
206
219
  };
220
+ function hookCanvasContext(ctx) {
221
+ var e_1, _a;
222
+ var methods = Object.getOwnPropertyNames(Object.getPrototypeOf(ctx)).filter(function (k) { return typeof ctx[k] === 'function'; });
223
+ var _loop_1 = function (method) {
224
+ var original = ctx[method];
225
+ ctx[method] = function () {
226
+ var args = [];
227
+ for (var _i = 0; _i < arguments.length; _i++) {
228
+ args[_i] = arguments[_i];
229
+ }
230
+ console.log("[Canvas2D] ".concat(method, "(").concat(args.map(function (a) { return JSON.stringify(a); }).join(', '), ")"));
231
+ return original.apply(this, args);
232
+ };
233
+ };
234
+ try {
235
+ for (var methods_1 = __values(methods), methods_1_1 = methods_1.next(); !methods_1_1.done; methods_1_1 = methods_1.next()) {
236
+ var method = methods_1_1.value;
237
+ _loop_1(method);
238
+ }
239
+ }
240
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
241
+ finally {
242
+ try {
243
+ if (methods_1_1 && !methods_1_1.done && (_a = methods_1.return)) _a.call(methods_1);
244
+ }
245
+ finally { if (e_1) throw e_1.error; }
246
+ }
247
+ }
248
+ exports.hookCanvasContext = hookCanvasContext;
207
249
  var Graph = function (_a) {
208
250
  var _b = _a.items, items = _b === void 0 ? [] : _b;
209
251
  var ref = (0, react_1.useRef)(null);
210
252
  var pathRef = (0, react_1.useRef)([]);
211
253
  var _c = __read((0, react_1.useState)(), 2), ctx = _c[0], setCtx = _c[1];
212
- var height = (0, react_1.useMemo)(function () { return 36 * items.length + 50 + 35; }, [items]);
254
+ // 统一间距配置
255
+ var ITEM_SPACING = 40;
256
+ var TOP_OFFSET = 50;
257
+ var BOTTOM_SPACING = 20; // 最后一个item与虚线之间的间距
258
+ var SCORE_AREA_HEIGHT = 40; // 分数区域的高度
259
+ var height = (0, react_1.useMemo)(function () {
260
+ if (items.length === 0)
261
+ return 0;
262
+ return TOP_OFFSET + (items.length - 1) * ITEM_SPACING + MAX_HEIGHT + BOTTOM_SPACING + SCORE_AREA_HEIGHT;
263
+ }, [items]);
213
264
  (0, react_1.useEffect)(function () {
214
265
  if (items.length === 0)
215
266
  return;
216
267
  var currentCtx = setupCanvas(ref.current);
268
+ // hookCanvasContext(currentCtx);
217
269
  setCtx(currentCtx);
218
270
  tipEl.style.background = 'rgba(0,0,0,.7)';
219
271
  tipEl.style.color = '#fff';
@@ -236,13 +288,13 @@ var Graph = function (_a) {
236
288
  var layout = {
237
289
  leftLableWidth: 140,
238
290
  topLableHeight: 40,
239
- itemSpacing: 40,
291
+ itemSpacing: ITEM_SPACING,
240
292
  height: height,
241
293
  };
242
294
  pathRef.current = [];
243
295
  draw(layout, items, pathRef.current, ctx);
244
296
  }
245
- }, [ctx, items, height]);
297
+ }, [ctx, items, height, ITEM_SPACING]);
246
298
  // useEffect(() => {
247
299
  // console.log(pathRef);
248
300
  // }, [pathRef]);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eli-video-interview",
3
- "version": "1.2.42-alpha.67",
3
+ "version": "1.2.42-alpha.69",
4
4
  "description": "鳄梨科技 AI视频面试 React SDK",
5
5
  "author": "鳄梨科技",
6
6
  "license": "MIT",