@willwade/aac-processors 0.2.16 → 0.2.17

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.
@@ -909,6 +909,61 @@ export function getAllPluginIds() {
909
909
  const plugins = new Set(Object.values(GRID3_COMMANDS).map((cmd) => cmd.pluginId));
910
910
  return Array.from(plugins).sort();
911
911
  }
912
+ function textOfStructured(val) {
913
+ if (!val || typeof val !== 'object')
914
+ return undefined;
915
+ const parts = [];
916
+ const processS = (s) => {
917
+ if (!s)
918
+ return;
919
+ if (s.r !== undefined) {
920
+ const rElements = Array.isArray(s.r) ? s.r : [s.r];
921
+ for (const r of rElements) {
922
+ if (typeof r === 'number') {
923
+ if (r !== 0)
924
+ parts.push(String(r));
925
+ continue;
926
+ }
927
+ if (typeof r === 'object' && r !== null) {
928
+ if ('#text' in r)
929
+ parts.push(String(r['#text']));
930
+ else if ('#cdata' in r)
931
+ parts.push(String(r['#cdata']));
932
+ else
933
+ parts.push(String(r));
934
+ }
935
+ else {
936
+ parts.push(String(r));
937
+ }
938
+ }
939
+ }
940
+ };
941
+ if (val.p) {
942
+ const sElements = Array.isArray(val.p.s) ? val.p.s : val.p.s ? [val.p.s] : [];
943
+ sElements.forEach(processS);
944
+ }
945
+ else if (val.s) {
946
+ const sElements = Array.isArray(val.s) ? val.s : [val.s];
947
+ sElements.forEach(processS);
948
+ }
949
+ else if (val.r !== undefined) {
950
+ processS(val);
951
+ }
952
+ return parts.length > 0 ? parts.join('').trim() : undefined;
953
+ }
954
+ function extractParamValue(param) {
955
+ if (typeof param === 'string')
956
+ return param;
957
+ if (param.p || param.s || (param.r !== undefined && typeof param.r !== 'string')) {
958
+ const structured = textOfStructured(param);
959
+ if (structured !== undefined)
960
+ return structured;
961
+ }
962
+ const simple = param['#text'] ?? param.text ?? param.value;
963
+ if (simple !== undefined)
964
+ return simple;
965
+ return textOfStructured(param);
966
+ }
912
967
  export function extractCommandParameters(command) {
913
968
  const parameters = {};
914
969
  const params = command.Parameter || command.parameter;
@@ -917,7 +972,7 @@ export function extractCommandParameters(command) {
917
972
  const paramArray = Array.isArray(params) ? params : [params];
918
973
  for (const param of paramArray) {
919
974
  const key = param['@_Key'] || param.Key || param.key;
920
- let value = param['#text'] ?? param.text ?? param.value;
975
+ let value = extractParamValue(param);
921
976
  if (key && value !== undefined) {
922
977
  // Try to convert to number if it looks numeric
923
978
  if (typeof value === 'string' && /^\d+$/.test(value)) {
@@ -700,6 +700,13 @@ class GridsetProcessor extends BaseProcessor {
700
700
  }
701
701
  }
702
702
  }
703
+ if (pageWordListItems.length > 0) {
704
+ page.wordListItems = pageWordListItems.map((item) => ({
705
+ text: item.text,
706
+ image: item.image,
707
+ partOfSpeech: item.partOfSpeech,
708
+ }));
709
+ }
703
710
  // Track WordList AutoContent cells and their positions for "more" button placement
704
711
  const wordListAutoContentCells = [];
705
712
  let wordListCellIndex = 0;
@@ -1032,6 +1039,15 @@ class GridsetProcessor extends BaseProcessor {
1032
1039
  const param = getRawParam(key);
1033
1040
  if (param === undefined)
1034
1041
  return undefined;
1042
+ if (typeof param === 'string')
1043
+ return param;
1044
+ if (param.p ||
1045
+ param.s ||
1046
+ (param.r !== undefined && typeof param.r !== 'string')) {
1047
+ const structuredValue = this.textOf(param);
1048
+ if (structuredValue !== undefined)
1049
+ return structuredValue;
1050
+ }
1035
1051
  const simpleValue = param['#text'] ?? param.text ?? param.value;
1036
1052
  if (typeof simpleValue === 'string')
1037
1053
  return simpleValue;
@@ -1040,8 +1056,6 @@ class GridsetProcessor extends BaseProcessor {
1040
1056
  const structuredValue = this.textOf(param);
1041
1057
  if (structuredValue !== undefined)
1042
1058
  return structuredValue;
1043
- if (typeof param === 'string')
1044
- return param;
1045
1059
  return undefined;
1046
1060
  };
1047
1061
  // Skip PredictThis in primary action loop as it was handled in pre-pass
@@ -222,6 +222,7 @@ export declare class AACPage {
222
222
  descriptionHtml?: string;
223
223
  images?: any[];
224
224
  sounds?: any[];
225
+ wordListItems?: import('../types/aac').AACWordListItem[];
225
226
  semantic_ids?: string[];
226
227
  clone_ids?: string[];
227
228
  scanningConfig?: import('../types/aac').ScanningConfig;
@@ -920,6 +920,61 @@ function getAllPluginIds() {
920
920
  const plugins = new Set(Object.values(exports.GRID3_COMMANDS).map((cmd) => cmd.pluginId));
921
921
  return Array.from(plugins).sort();
922
922
  }
923
+ function textOfStructured(val) {
924
+ if (!val || typeof val !== 'object')
925
+ return undefined;
926
+ const parts = [];
927
+ const processS = (s) => {
928
+ if (!s)
929
+ return;
930
+ if (s.r !== undefined) {
931
+ const rElements = Array.isArray(s.r) ? s.r : [s.r];
932
+ for (const r of rElements) {
933
+ if (typeof r === 'number') {
934
+ if (r !== 0)
935
+ parts.push(String(r));
936
+ continue;
937
+ }
938
+ if (typeof r === 'object' && r !== null) {
939
+ if ('#text' in r)
940
+ parts.push(String(r['#text']));
941
+ else if ('#cdata' in r)
942
+ parts.push(String(r['#cdata']));
943
+ else
944
+ parts.push(String(r));
945
+ }
946
+ else {
947
+ parts.push(String(r));
948
+ }
949
+ }
950
+ }
951
+ };
952
+ if (val.p) {
953
+ const sElements = Array.isArray(val.p.s) ? val.p.s : val.p.s ? [val.p.s] : [];
954
+ sElements.forEach(processS);
955
+ }
956
+ else if (val.s) {
957
+ const sElements = Array.isArray(val.s) ? val.s : [val.s];
958
+ sElements.forEach(processS);
959
+ }
960
+ else if (val.r !== undefined) {
961
+ processS(val);
962
+ }
963
+ return parts.length > 0 ? parts.join('').trim() : undefined;
964
+ }
965
+ function extractParamValue(param) {
966
+ if (typeof param === 'string')
967
+ return param;
968
+ if (param.p || param.s || (param.r !== undefined && typeof param.r !== 'string')) {
969
+ const structured = textOfStructured(param);
970
+ if (structured !== undefined)
971
+ return structured;
972
+ }
973
+ const simple = param['#text'] ?? param.text ?? param.value;
974
+ if (simple !== undefined)
975
+ return simple;
976
+ return textOfStructured(param);
977
+ }
923
978
  function extractCommandParameters(command) {
924
979
  const parameters = {};
925
980
  const params = command.Parameter || command.parameter;
@@ -928,7 +983,7 @@ function extractCommandParameters(command) {
928
983
  const paramArray = Array.isArray(params) ? params : [params];
929
984
  for (const param of paramArray) {
930
985
  const key = param['@_Key'] || param.Key || param.key;
931
- let value = param['#text'] ?? param.text ?? param.value;
986
+ let value = extractParamValue(param);
932
987
  if (key && value !== undefined) {
933
988
  // Try to convert to number if it looks numeric
934
989
  if (typeof value === 'string' && /^\d+$/.test(value)) {
@@ -703,6 +703,13 @@ class GridsetProcessor extends baseProcessor_1.BaseProcessor {
703
703
  }
704
704
  }
705
705
  }
706
+ if (pageWordListItems.length > 0) {
707
+ page.wordListItems = pageWordListItems.map((item) => ({
708
+ text: item.text,
709
+ image: item.image,
710
+ partOfSpeech: item.partOfSpeech,
711
+ }));
712
+ }
706
713
  // Track WordList AutoContent cells and their positions for "more" button placement
707
714
  const wordListAutoContentCells = [];
708
715
  let wordListCellIndex = 0;
@@ -1035,6 +1042,15 @@ class GridsetProcessor extends baseProcessor_1.BaseProcessor {
1035
1042
  const param = getRawParam(key);
1036
1043
  if (param === undefined)
1037
1044
  return undefined;
1045
+ if (typeof param === 'string')
1046
+ return param;
1047
+ if (param.p ||
1048
+ param.s ||
1049
+ (param.r !== undefined && typeof param.r !== 'string')) {
1050
+ const structuredValue = this.textOf(param);
1051
+ if (structuredValue !== undefined)
1052
+ return structuredValue;
1053
+ }
1038
1054
  const simpleValue = param['#text'] ?? param.text ?? param.value;
1039
1055
  if (typeof simpleValue === 'string')
1040
1056
  return simpleValue;
@@ -1043,8 +1059,6 @@ class GridsetProcessor extends baseProcessor_1.BaseProcessor {
1043
1059
  const structuredValue = this.textOf(param);
1044
1060
  if (structuredValue !== undefined)
1045
1061
  return structuredValue;
1046
- if (typeof param === 'string')
1047
- return param;
1048
1062
  return undefined;
1049
1063
  };
1050
1064
  // Skip PredictThis in primary action loop as it was handled in pre-pass
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@willwade/aac-processors",
3
- "version": "0.2.16",
3
+ "version": "0.2.17",
4
4
  "description": "A comprehensive TypeScript library for processing AAC (Augmentative and Alternative Communication) file formats with translation support",
5
5
  "main": "dist/index.js",
6
6
  "browser": "dist/browser/index.browser.js",
@@ -131,7 +131,7 @@
131
131
  ],
132
132
  "author": {
133
133
  "name": "Will Wade",
134
- "email": "wwade@acecentre.org.uk",
134
+ "email": "will@aactools.co.uk",
135
135
  "url": "https://github.com/willwade"
136
136
  },
137
137
  "license": "MIT",
@@ -140,12 +140,12 @@
140
140
  },
141
141
  "repository": {
142
142
  "type": "git",
143
- "url": "https://github.com/willwade/AACProcessors-nodejs.git"
143
+ "url": "https://github.com/AACTools/AACProcessors-nodejs.git"
144
144
  },
145
145
  "bugs": {
146
- "url": "https://github.com/willwade/AACProcessors-nodejs/issues"
146
+ "url": "https://github.com/AACTools/AACProcessors-nodejs/issues"
147
147
  },
148
- "homepage": "https://github.com/willwade/AACProcessors-nodejs#readme",
148
+ "homepage": "https://github.com/AACTools/AACProcessors-nodejs#readme",
149
149
  "engines": {
150
150
  "node": ">=20.0.0",
151
151
  "npm": ">=9.0.0"