diff --git a/.github/workflows/node.js.yml b/.github/workflows/node.js.yml deleted file mode 100644 index cac5823..0000000 --- a/.github/workflows/node.js.yml +++ /dev/null @@ -1,32 +0,0 @@ -# This workflow will do a clean install of node dependencies, cache/restore them, build the source code and run tests across different versions of node -# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions - -name: Node.js CI - -on: - push: - branches: [ main ] - pull_request: - branches: [ main ] - -jobs: - build: - - runs-on: ubuntu-latest - - strategy: - matrix: - node-version: [12.x, 14.x, 16.x] - # See supported Node.js release schedule at https://nodejs.org/en/about/releases/ - - steps: - - uses: actions/checkout@v2 - - name: Use Node.js ${{ matrix.node-version }} - uses: actions/setup-node@v2 - with: - node-version: ${{ matrix.node-version }} - cache: 'npm' - - run: npm install -g grunt-cli - - run: npm ci - - run: npm test - - run: npm run build diff --git a/.gitignore b/.gitignore index 6629c8c..ecba101 100644 --- a/.gitignore +++ b/.gitignore @@ -24,3 +24,5 @@ build # Deployed apps should consider commenting this line out: # see https://npmjs.org/doc/faq.html#Should-I-check-my-node_modules-folder-into-git node_modules +.vscode +.github \ No newline at end of file diff --git a/dist/textgrid.js b/dist/textgrid.js index 0d3aed1..3415e43 100644 --- a/dist/textgrid.js +++ b/dist/textgrid.js @@ -1,6 +1,6 @@ -/*! textgrid - v2.2.0 - 2021-12-14 +/*! textgrid - v2.2.0 - 2025-10-17 * https://github.com/OpenSourceFieldlinguistics/PraatTextGridJS -* Copyright (c) 2021 OpenSourceFieldLinguistics Contribs; Licensed Apache 2.0 */ +* Copyright (c) 2025 OpenSourceFieldLinguistics Contribs; Licensed Apache 2.0 */ (function(exports) { 'use strict'; @@ -270,6 +270,63 @@ } }; + TextGrid.jsonToTextgrid = function(json) { + var textgrid = ''; + + // 写入文件头 + textgrid += 'File type = "ooTextFile"\n'; + textgrid += 'Object class = "TextGrid"\n\n'; + + // 写入基本属性 + textgrid += 'xmin = ' + (json.xmin || 0) + '\n'; + textgrid += 'xmax = ' + (json.xmax || 0) + '\n'; + textgrid += 'tiers? \n'; + textgrid += 'size = ' + (json.items ? json.items.length : 0) + '\n'; + textgrid += 'item []:\n'; + + // 处理每个层级 + if (json.items) { + for (var i = 0; i < json.items.length; i++) { + var item = json.items[i]; + + // 写入层级头 + textgrid += ' item [' + (i + 1) + ']:\n'; + + // 写入层级属性 + textgrid += ' class = "' + (item.class || 'IntervalTier') + '"\n'; + textgrid += ' name = "' + (item.name || '') + '"\n'; + textgrid += ' xmin = ' + (item.xmin || 0) + '\n'; + textgrid += ' xmax = ' + (item.xmax || 0) + '\n'; + + // 处理区间层级 + if (item.class === 'IntervalTier' && item.intervals) { + textgrid += ' intervals: size = ' + item.intervals.length + '\n'; + + for (var j = 0; j < item.intervals.length; j++) { + var interval = item.intervals[j]; + textgrid += ' intervals [' + (j + 1) + ']:\n'; + textgrid += ' xmin = ' + (interval.xmin || 0) + '\n'; + textgrid += ' xmax = ' + (interval.xmax || 0) + '\n'; + textgrid += ' text = "' + (interval.text || '') + '"\n'; + } + } + // 处理点层级 + else if (item.class === 'TextTier' && item.points) { + textgrid += ' points: size = ' + item.points.length + '\n'; + + for (var k = 0; k < item.points.length; k++) { + var point = item.points[k]; + textgrid += ' points [' + (k + 1) + ']:\n'; + textgrid += ' number = ' + (point.number || 0) + '\n'; + textgrid += ' text = "' + (point.text || '') + '"\n'; + } + } + } + } + + return textgrid; + }; + exports.TextGrid = TextGrid; }(typeof exports === "object" && exports || this)); diff --git a/dist/textgrid.min.js b/dist/textgrid.min.js index a924451..57457f2 100644 --- a/dist/textgrid.min.js +++ b/dist/textgrid.min.js @@ -1,5 +1,5 @@ -/*! textgrid - v2.2.0 - 2021-12-14 +/*! textgrid - v2.2.0 - 2025-10-17 * https://github.com/OpenSourceFieldlinguistics/PraatTextGridJS -* Copyright (c) 2021 OpenSourceFieldLinguistics Contribs; Licensed Apache 2.0 */ +* Copyright (c) 2025 OpenSourceFieldLinguistics Contribs; Licensed Apache 2.0 */ -!function(e){"use strict";function h(e){for(var t,i,n={},r=0;r