ソースを参照

Merge branch 'feature-tianyong-newVersion' into ktyq-test-new

TIANYONG 6 ヶ月 前
コミット
facb528d92
3 ファイル変更34 行追加4 行削除
  1. 3 2
      src/helpers/calcSpeed.ts
  2. 30 1
      src/helpers/customMusicScore.ts
  3. 1 1
      vite.config.ts

+ 3 - 2
src/helpers/calcSpeed.ts

@@ -1,4 +1,5 @@
 import { OpenSheetMusicDisplay, SourceMeasure } from "/osmd-extended/src";
+import { onlyVisible } from "/src/helpers/formateMusic";
 
 export const noteDuration = {
 	"1/2": 2,
@@ -113,8 +114,8 @@ export type GradualItem = {
  * @param xml 始终按照第一分谱进行减慢速度的计算
  */
 export const getGradualLengthByXml = (xml: string) => {
-	// const firstPartXml = onlyVisible(xml, 0)
-	const xmlParse = new DOMParser().parseFromString(xml, "text/xml");
+	const firstPartXml = onlyVisible(xml, 0)
+	const xmlParse = new DOMParser().parseFromString(firstPartXml, "text/xml");
 	const measures = Array.from(xmlParse.querySelectorAll("measure"));
 	const notes = Array.from(xmlParse.querySelectorAll("note"));
 	const words = Array.from(xmlParse.querySelectorAll("words"));

+ 30 - 1
src/helpers/customMusicScore.ts

@@ -268,6 +268,18 @@ export const limitSingleSvgPageHeight = () => {
 
 }
 
+const isElementInViewport = (el: any) => {
+    const rect = el.getBoundingClientRect();
+    return (
+        rect.top >= 0 &&
+        rect.left >= 0 &&
+        rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) &&
+        rect.right <= (window.innerWidth || document.documentElement.clientWidth)
+    );
+}
+const isNumeric = (str: any) => {
+	return /^\d+$/.test(str);
+  }
 // 谱面优化
 export const resetFormate = () => {
 	container.value = document.getElementById('scrollContainer')
@@ -296,14 +308,23 @@ export const resetFormate = () => {
 		const paths: SVGAElement[] = Array.from(staffline.querySelectorAll(".vf-measure > .vf-stave path"));
 		const dotModifiers: SVGAElement[] = Array.from(staffline.querySelectorAll(".vf-measure .vf-stopDot"));
 		const staves: SVGAElement[] = Array.from(staffline.querySelectorAll(".vf-measure > .vf-stave"));
+		const numberVfTexts = Array.from((container.value as HTMLElement).querySelectorAll(".vf-text > text")); 
 
 		// 获取第一个线谱的y轴坐标
 		const firstLinePathY = paths[0]?.getBBox().y || 0
+		// D.C循环标记没有显示完全修复
 		// 反复标记 和 小节碰撞
-		const repetWord = ["To Coda", "D.S. al Coda", "Coda"];
+		const repetWord = ["To Coda", "D.S. al Coda", "Coda", "D.C."];
 		texts
 			.filter((n) => repetWord.includes(n.textContent || ""))
 			.forEach((t) => {
+				// console.log('文本123',t.textContent,'是否在可视区域内',isElementInViewport(t))
+				// D.C循环标记不在可视区域内,需要修复移动其位置信息
+				if (t.textContent?.includes('D.C')) {
+					if (!isElementInViewport(t)) {
+						t.style.transform = `translateX(-40px)`;
+					}
+				}
 				vfbeams.forEach((curve) => {
 					const result = collisionDetection(t, curve);
 					const prePath: SVGAElement = t?.previousSibling as unknown as SVGAElement;
@@ -430,6 +451,14 @@ export const resetFormate = () => {
 				label.textContent = labelText.replace('#','♯')
 			}
 		});
+		// numberVfTexts.forEach((label: any) => {
+		// 	const labelText = label.textContent as string
+		// 	if (isNumeric(labelText)) {
+		// 		const _y = Number(label.getAttribute("y"))
+		// 		const endY = firstLinePathY ? firstLinePathY - musicalDistance : _y
+		// 		label.setAttribute("y", endY)
+		// 	}
+		// })
 		dotModifiers.forEach((group: any) => {
 			if (state.musicRenderType === 'fixedTone') {
 				group.setAttribute('transform', 'translate(3,-12)')

+ 1 - 1
vite.config.ts

@@ -78,7 +78,7 @@ export default defineConfig({
         // target: "https://kt.colexiu.com",
         target: "https://test.resource.colexiu.com", // 内容平台开发环境,内容平台开发,需在url链接上加上isCbs=true
         // target: "https://test.kt.colexiu.com",
-        //target: "https://mec.colexiu.com",
+        // target: "https://mec.colexiu.com",
         changeOrigin: true,
         rewrite: (path) => path.replace(/^\/instrument/, ""),
       },