@versa_ai/vmml-editor 1.0.31 → 1.0.33

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@versa_ai/vmml-editor",
3
- "version": "1.0.31",
3
+ "version": "1.0.33",
4
4
  "module": "dist/index.mjs",
5
5
  "main": "dist/index.mjs",
6
6
  "types": "dist/index.d.mts",
@@ -465,6 +465,26 @@ const EditorCanvas = forwardRef(
465
465
  }
466
466
  }
467
467
 
468
+ const setTextAlign = (p: any, stroke: any, direction: 'left' | 'center' | 'right') => {
469
+ if (direction === 'center') {
470
+ p.style.justifyContent = 'center'
471
+ stroke.style.left = "50%";
472
+ stroke.style.top = "50%";
473
+ stroke.style.transform = 'translate(-50%, -50%)';
474
+ }
475
+ if (direction === 'left') {
476
+ stroke.style.left = "0";
477
+ stroke.style.top = "0";
478
+ stroke.style.transform = 'none';
479
+ }
480
+ if (direction === 'right') {
481
+ p.style.justifyContent = 'flex-end'
482
+ stroke.style.right = "0";
483
+ stroke.style.top = "50%";
484
+ stroke.style.transform = 'translateY(-50%)';
485
+ }
486
+ }
487
+
468
488
  //文字转图片
469
489
  const createTextImg = async ({ textContent, bgColor, textColor, stColor, strokeW, fontAssetUrl = null, textBasicInfo, letterSpacing }: any) => {
470
490
  const fontBase64 = await loadFont(fontAssetUrl)
@@ -477,6 +497,7 @@ const EditorCanvas = forwardRef(
477
497
  container.style.textAlign = textBasicInfo.textAlign || 'left';
478
498
  const lines = textContent.split('\n');
479
499
  const fontFamily = fontAssetUrl ? getFontFamilyName(fontAssetUrl) : 'sansMedium';
500
+ // const textCenter = textWarapCenter && textBasicInfo.textAlign === 'center'
480
501
  lines.forEach((line: string) => {
481
502
  const p = document.createElement('p');
482
503
  p.style.position = 'relative';
@@ -489,7 +510,7 @@ const EditorCanvas = forwardRef(
489
510
  p.style.padding = '0';
490
511
  if (letterSpacing) p.style.letterSpacing = `${letterSpacing}px`;
491
512
  p.style.zIndex = '2'
492
- if (textWarapCenter) p.style.justifyContent = 'center'
513
+ // if (textCenter) p.style.justifyContent = 'center'
493
514
 
494
515
  const fill = document.createElement('span');
495
516
  fill.textContent = line || ' ';
@@ -504,15 +525,19 @@ const EditorCanvas = forwardRef(
504
525
  stroke.style.color = 'transparent';
505
526
  stroke.style.webkitTextStrokeWidth = `${strokeW}px`;
506
527
  stroke.style.webkitTextStrokeColor = stColor;
507
- if (textWarapCenter) {
508
- stroke.style.left = "50%";
509
- stroke.style.top = "50%";
510
- stroke.style.transform = 'translate(-50%, -50%)';
511
- } else {
512
- stroke.style.left = '0';
513
- stroke.style.top = '0';
514
- }
515
- stroke.style.zIndex = '-1'
528
+
529
+ let dr = textBasicInfo.textAlign || 'left'
530
+ if (textWarapCenter) dr = 'center'
531
+ setTextAlign(p, stroke, dr)
532
+ // if (textCenter) {
533
+ // stroke.style.left = "50%";
534
+ // stroke.style.top = "50%";
535
+ // stroke.style.transform = 'translate(-50%, -50%)';
536
+ // } else {
537
+ // stroke.style.left = '0';
538
+ // stroke.style.top = '0';
539
+ // }
540
+ // stroke.style.zIndex = '-1'
516
541
 
517
542
  p.appendChild(fill);
518
543
  p.appendChild(stroke);
package/src/index.tsx CHANGED
@@ -386,10 +386,8 @@ const EditorFn = <Schema extends AnyZodObject, Props>(
386
386
  if (player) {
387
387
  const parent = player.getContainerNode();
388
388
  if (!canvasSize.width) {
389
- console.log(parent, 'parent>>>>')
390
389
  const playerElement = parent?.children[0];
391
390
  const { width, height } = playerElement?.getBoundingClientRect() || {};
392
- console.log(height)
393
391
  setCanvasSize({ width, height, top: playerElement.offsetTop });
394
392
  }
395
393
  player.addEventListener("play", onPlay);
@@ -438,6 +436,7 @@ const EditorFn = <Schema extends AnyZodObject, Props>(
438
436
  console.log(v, vmmlState, isSame, '判断vmml是否相同')
439
437
 
440
438
  needPlay.current = false
439
+ once.current = false
441
440
 
442
441
  const convertedVmml = convertVmmlTextScaleByForbidden(v);
443
442
  if (!isSame) { // vmml改变再重新刷新canvas