phylotree 2.2.0 → 2.3.0

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/dist/phylotree.js CHANGED
@@ -6931,244 +6931,370 @@
6931
6931
  }
6932
6932
  }
6933
6933
 
6934
- //TODO: handle comments
6935
- function readDocType(xmlData, i){
6934
+ class DocTypeReader{
6935
+ constructor(processEntities){
6936
+ this.suppressValidationErr = !processEntities;
6937
+ }
6936
6938
 
6937
- const entities = {};
6938
- if( xmlData[i + 3] === 'O' &&
6939
- xmlData[i + 4] === 'C' &&
6940
- xmlData[i + 5] === 'T' &&
6941
- xmlData[i + 6] === 'Y' &&
6942
- xmlData[i + 7] === 'P' &&
6943
- xmlData[i + 8] === 'E')
6944
- {
6945
- i = i+9;
6946
- let angleBracketsCount = 1;
6947
- let hasBody = false, comment = false;
6948
- let exp = "";
6949
- for(;i<xmlData.length;i++){
6950
- if (xmlData[i] === '<' && !comment) { //Determine the tag type
6951
- if( hasBody && hasSeq(xmlData, "!ENTITY",i)){
6952
- i += 7;
6953
- let entityName, val;
6954
- [entityName, val,i] = readEntityExp(xmlData,i+1);
6955
- if(val.indexOf("&") === -1) //Parameter entities are not supported
6956
- entities[ entityName ] = {
6957
- regx : RegExp( `&${entityName};`,"g"),
6958
- val: val
6959
- };
6960
- }
6961
- else if( hasBody && hasSeq(xmlData, "!ELEMENT",i)) {
6962
- i += 8;//Not supported
6963
- const {index} = readElementExp(xmlData,i+1);
6964
- i = index;
6965
- }else if( hasBody && hasSeq(xmlData, "!ATTLIST",i)){
6966
- i += 8;//Not supported
6967
- // const {index} = readAttlistExp(xmlData,i+1);
6968
- // i = index;
6969
- }else if( hasBody && hasSeq(xmlData, "!NOTATION",i)) {
6970
- i += 9;//Not supported
6971
- const {index} = readNotationExp(xmlData,i+1);
6972
- i = index;
6973
- }else if( hasSeq(xmlData, "!--",i) ) comment = true;
6974
- else throw new Error(`Invalid DOCTYPE`);
6975
-
6976
- angleBracketsCount++;
6977
- exp = "";
6978
- } else if (xmlData[i] === '>') { //Read tag content
6979
- if(comment){
6980
- if( xmlData[i - 1] === "-" && xmlData[i - 2] === "-"){
6981
- comment = false;
6939
+ readDocType(xmlData, i){
6940
+
6941
+ const entities = {};
6942
+ if( xmlData[i + 3] === 'O' &&
6943
+ xmlData[i + 4] === 'C' &&
6944
+ xmlData[i + 5] === 'T' &&
6945
+ xmlData[i + 6] === 'Y' &&
6946
+ xmlData[i + 7] === 'P' &&
6947
+ xmlData[i + 8] === 'E')
6948
+ {
6949
+ i = i+9;
6950
+ let angleBracketsCount = 1;
6951
+ let hasBody = false, comment = false;
6952
+ let exp = "";
6953
+ for(;i<xmlData.length;i++){
6954
+ if (xmlData[i] === '<' && !comment) { //Determine the tag type
6955
+ if( hasBody && hasSeq(xmlData, "!ENTITY",i)){
6956
+ i += 7;
6957
+ let entityName, val;
6958
+ [entityName, val,i] = this.readEntityExp(xmlData,i+1,this.suppressValidationErr);
6959
+ if(val.indexOf("&") === -1) //Parameter entities are not supported
6960
+ entities[ entityName ] = {
6961
+ regx : RegExp( `&${entityName};`,"g"),
6962
+ val: val
6963
+ };
6964
+ }
6965
+ else if( hasBody && hasSeq(xmlData, "!ELEMENT",i)) {
6966
+ i += 8;//Not supported
6967
+ const {index} = this.readElementExp(xmlData,i+1);
6968
+ i = index;
6969
+ }else if( hasBody && hasSeq(xmlData, "!ATTLIST",i)){
6970
+ i += 8;//Not supported
6971
+ // const {index} = this.readAttlistExp(xmlData,i+1);
6972
+ // i = index;
6973
+ }else if( hasBody && hasSeq(xmlData, "!NOTATION",i)) {
6974
+ i += 9;//Not supported
6975
+ const {index} = this.readNotationExp(xmlData,i+1,this.suppressValidationErr);
6976
+ i = index;
6977
+ }else if( hasSeq(xmlData, "!--",i) ) comment = true;
6978
+ else throw new Error(`Invalid DOCTYPE`);
6979
+
6980
+ angleBracketsCount++;
6981
+ exp = "";
6982
+ } else if (xmlData[i] === '>') { //Read tag content
6983
+ if(comment){
6984
+ if( xmlData[i - 1] === "-" && xmlData[i - 2] === "-"){
6985
+ comment = false;
6986
+ angleBracketsCount--;
6987
+ }
6988
+ }else {
6982
6989
  angleBracketsCount--;
6983
6990
  }
6991
+ if (angleBracketsCount === 0) {
6992
+ break;
6993
+ }
6994
+ }else if( xmlData[i] === '['){
6995
+ hasBody = true;
6984
6996
  }else {
6985
- angleBracketsCount--;
6986
- }
6987
- if (angleBracketsCount === 0) {
6988
- break;
6997
+ exp += xmlData[i];
6989
6998
  }
6990
- }else if( xmlData[i] === '['){
6991
- hasBody = true;
6992
- }else {
6993
- exp += xmlData[i];
6994
6999
  }
7000
+ if(angleBracketsCount !== 0){
7001
+ throw new Error(`Unclosed DOCTYPE`);
7002
+ }
7003
+ }else {
7004
+ throw new Error(`Invalid Tag instead of DOCTYPE`);
6995
7005
  }
6996
- if(angleBracketsCount !== 0){
6997
- throw new Error(`Unclosed DOCTYPE`);
6998
- }
6999
- }else {
7000
- throw new Error(`Invalid Tag instead of DOCTYPE`);
7006
+ return {entities, i};
7001
7007
  }
7002
- return {entities, i};
7003
- }
7008
+ readEntityExp(xmlData, i) {
7009
+ //External entities are not supported
7010
+ // <!ENTITY ext SYSTEM "http://normal-website.com" >
7004
7011
 
7005
- const skipWhitespace = (data, index) => {
7006
- while (index < data.length && /\s/.test(data[index])) {
7007
- index++;
7008
- }
7009
- return index;
7010
- };
7012
+ //Parameter entities are not supported
7013
+ // <!ENTITY entityname "&anotherElement;">
7011
7014
 
7012
- function readEntityExp(xmlData, i) {
7013
- //External entities are not supported
7014
- // <!ENTITY ext SYSTEM "http://normal-website.com" >
7015
+ //Internal entities are supported
7016
+ // <!ENTITY entityname "replacement text">
7015
7017
 
7016
- //Parameter entities are not supported
7017
- // <!ENTITY entityname "&anotherElement;">
7018
+ // Skip leading whitespace after <!ENTITY
7019
+ i = skipWhitespace(xmlData, i);
7018
7020
 
7019
- //Internal entities are supported
7020
- // <!ENTITY entityname "replacement text">
7021
+ // Read entity name
7022
+ let entityName = "";
7023
+ while (i < xmlData.length && !/\s/.test(xmlData[i]) && xmlData[i] !== '"' && xmlData[i] !== "'") {
7024
+ entityName += xmlData[i];
7025
+ i++;
7026
+ }
7027
+ validateEntityName(entityName);
7021
7028
 
7022
- // Skip leading whitespace after <!ENTITY
7023
- i = skipWhitespace(xmlData, i);
7029
+ // Skip whitespace after entity name
7030
+ i = skipWhitespace(xmlData, i);
7024
7031
 
7025
- // Read entity name
7026
- let entityName = "";
7027
- while (i < xmlData.length && !/\s/.test(xmlData[i]) && xmlData[i] !== '"' && xmlData[i] !== "'") {
7028
- entityName += xmlData[i];
7029
- i++;
7032
+ // Check for unsupported constructs (external entities or parameter entities)
7033
+ if(!this.suppressValidationErr){
7034
+ if (xmlData.substring(i, i + 6).toUpperCase() === "SYSTEM") {
7035
+ throw new Error("External entities are not supported");
7036
+ }else if (xmlData[i] === "%") {
7037
+ throw new Error("Parameter entities are not supported");
7038
+ }
7039
+ }
7040
+
7041
+ // Read entity value (internal entity)
7042
+ let entityValue = "";
7043
+ [i, entityValue] = this.readIdentifierVal(xmlData, i, "entity");
7044
+ i--;
7045
+ return [entityName, entityValue, i ];
7030
7046
  }
7031
- validateEntityName(entityName);
7032
7047
 
7033
- // Skip whitespace after entity name
7034
- i = skipWhitespace(xmlData, i);
7048
+ readNotationExp(xmlData, i) {
7049
+ // Skip leading whitespace after <!NOTATION
7050
+ i = skipWhitespace(xmlData, i);
7051
+
7052
+ // Read notation name
7053
+ let notationName = "";
7054
+ while (i < xmlData.length && !/\s/.test(xmlData[i])) {
7055
+ notationName += xmlData[i];
7056
+ i++;
7057
+ }
7058
+ !this.suppressValidationErr && validateEntityName(notationName);
7059
+
7060
+ // Skip whitespace after notation name
7061
+ i = skipWhitespace(xmlData, i);
7062
+
7063
+ // Check identifier type (SYSTEM or PUBLIC)
7064
+ const identifierType = xmlData.substring(i, i + 6).toUpperCase();
7065
+ if (!this.suppressValidationErr && identifierType !== "SYSTEM" && identifierType !== "PUBLIC") {
7066
+ throw new Error(`Expected SYSTEM or PUBLIC, found "${identifierType}"`);
7067
+ }
7068
+ i += identifierType.length;
7069
+
7070
+ // Skip whitespace after identifier type
7071
+ i = skipWhitespace(xmlData, i);
7072
+
7073
+ // Read public identifier (if PUBLIC)
7074
+ let publicIdentifier = null;
7075
+ let systemIdentifier = null;
7035
7076
 
7036
- // Check for unsupported constructs (external entities or parameter entities)
7037
- if (xmlData.substring(i, i + 6).toUpperCase() === "SYSTEM") {
7038
- throw new Error("External entities are not supported");
7039
- }else if (xmlData[i] === "%") {
7040
- throw new Error("Parameter entities are not supported");
7077
+ if (identifierType === "PUBLIC") {
7078
+ [i, publicIdentifier ] = this.readIdentifierVal(xmlData, i, "publicIdentifier");
7079
+
7080
+ // Skip whitespace after public identifier
7081
+ i = skipWhitespace(xmlData, i);
7082
+
7083
+ // Optionally read system identifier
7084
+ if (xmlData[i] === '"' || xmlData[i] === "'") {
7085
+ [i, systemIdentifier ] = this.readIdentifierVal(xmlData, i,"systemIdentifier");
7086
+ }
7087
+ } else if (identifierType === "SYSTEM") {
7088
+ // Read system identifier (mandatory for SYSTEM)
7089
+ [i, systemIdentifier ] = this.readIdentifierVal(xmlData, i, "systemIdentifier");
7090
+
7091
+ if (!this.suppressValidationErr && !systemIdentifier) {
7092
+ throw new Error("Missing mandatory system identifier for SYSTEM notation");
7093
+ }
7094
+ }
7095
+
7096
+ return {notationName, publicIdentifier, systemIdentifier, index: --i};
7041
7097
  }
7042
7098
 
7043
- // Read entity value (internal entity)
7044
- let entityValue = "";
7045
- [i, entityValue] = readIdentifierVal(xmlData, i, "entity");
7046
- i--;
7047
- return [entityName, entityValue, i ];
7048
- }
7099
+ readIdentifierVal(xmlData, i, type) {
7100
+ let identifierVal = "";
7101
+ const startChar = xmlData[i];
7102
+ if (startChar !== '"' && startChar !== "'") {
7103
+ throw new Error(`Expected quoted string, found "${startChar}"`);
7104
+ }
7105
+ i++;
7049
7106
 
7050
- function readNotationExp(xmlData, i) {
7051
- // Skip leading whitespace after <!NOTATION
7052
- i = skipWhitespace(xmlData, i);
7107
+ while (i < xmlData.length && xmlData[i] !== startChar) {
7108
+ identifierVal += xmlData[i];
7109
+ i++;
7110
+ }
7053
7111
 
7054
- // Read notation name
7055
- let notationName = "";
7056
- while (i < xmlData.length && !/\s/.test(xmlData[i])) {
7057
- notationName += xmlData[i];
7112
+ if (xmlData[i] !== startChar) {
7113
+ throw new Error(`Unterminated ${type} value`);
7114
+ }
7058
7115
  i++;
7116
+ return [i, identifierVal];
7059
7117
  }
7060
- validateEntityName(notationName);
7061
7118
 
7062
- // Skip whitespace after notation name
7063
- i = skipWhitespace(xmlData, i);
7119
+ readElementExp(xmlData, i) {
7120
+ // <!ELEMENT br EMPTY>
7121
+ // <!ELEMENT div ANY>
7122
+ // <!ELEMENT title (#PCDATA)>
7123
+ // <!ELEMENT book (title, author+)>
7124
+ // <!ELEMENT name (content-model)>
7125
+
7126
+ // Skip leading whitespace after <!ELEMENT
7127
+ i = skipWhitespace(xmlData, i);
7064
7128
 
7065
- // Check identifier type (SYSTEM or PUBLIC)
7066
- const identifierType = xmlData.substring(i, i + 6).toUpperCase();
7067
- if (identifierType !== "SYSTEM" && identifierType !== "PUBLIC") {
7068
- throw new Error(`Expected SYSTEM or PUBLIC, found "${identifierType}"`);
7129
+ // Read element name
7130
+ let elementName = "";
7131
+ while (i < xmlData.length && !/\s/.test(xmlData[i])) {
7132
+ elementName += xmlData[i];
7133
+ i++;
7134
+ }
7135
+
7136
+ // Validate element name
7137
+ if (!this.suppressValidationErr && !isName(elementName)) {
7138
+ throw new Error(`Invalid element name: "${elementName}"`);
7139
+ }
7140
+
7141
+ // Skip whitespace after element name
7142
+ i = skipWhitespace(xmlData, i);
7143
+ let contentModel = "";
7144
+ // Expect '(' to start content model
7145
+ if(xmlData[i] === "E" && hasSeq(xmlData, "MPTY",i)) i+=4;
7146
+ else if(xmlData[i] === "A" && hasSeq(xmlData, "NY",i)) i+=2;
7147
+ else if (xmlData[i] === "(") {
7148
+ i++; // Move past '('
7149
+
7150
+ // Read content model
7151
+ while (i < xmlData.length && xmlData[i] !== ")") {
7152
+ contentModel += xmlData[i];
7153
+ i++;
7154
+ }
7155
+ if (xmlData[i] !== ")") {
7156
+ throw new Error("Unterminated content model");
7157
+ }
7158
+
7159
+ }else if(!this.suppressValidationErr){
7160
+ throw new Error(`Invalid Element Expression, found "${xmlData[i]}"`);
7161
+ }
7162
+
7163
+ return {
7164
+ elementName,
7165
+ contentModel: contentModel.trim(),
7166
+ index: i
7167
+ };
7069
7168
  }
7070
- i += identifierType.length;
7071
7169
 
7072
- // Skip whitespace after identifier type
7073
- i = skipWhitespace(xmlData, i);
7170
+ readAttlistExp(xmlData, i) {
7171
+ // Skip leading whitespace after <!ATTLIST
7172
+ i = skipWhitespace(xmlData, i);
7074
7173
 
7075
- // Read public identifier (if PUBLIC)
7076
- let publicIdentifier = null;
7077
- let systemIdentifier = null;
7174
+ // Read element name
7175
+ let elementName = "";
7176
+ while (i < xmlData.length && !/\s/.test(xmlData[i])) {
7177
+ elementName += xmlData[i];
7178
+ i++;
7179
+ }
7078
7180
 
7079
- if (identifierType === "PUBLIC") {
7080
- [i, publicIdentifier ] = readIdentifierVal(xmlData, i, "publicIdentifier");
7181
+ // Validate element name
7182
+ validateEntityName(elementName);
7081
7183
 
7082
- // Skip whitespace after public identifier
7184
+ // Skip whitespace after element name
7083
7185
  i = skipWhitespace(xmlData, i);
7084
7186
 
7085
- // Optionally read system identifier
7086
- if (xmlData[i] === '"' || xmlData[i] === "'") {
7087
- [i, systemIdentifier ] = readIdentifierVal(xmlData, i,"systemIdentifier");
7187
+ // Read attribute name
7188
+ let attributeName = "";
7189
+ while (i < xmlData.length && !/\s/.test(xmlData[i])) {
7190
+ attributeName += xmlData[i];
7191
+ i++;
7088
7192
  }
7089
- } else if (identifierType === "SYSTEM") {
7090
- // Read system identifier (mandatory for SYSTEM)
7091
- [i, systemIdentifier ] = readIdentifierVal(xmlData, i, "systemIdentifier");
7092
7193
 
7093
- if (!systemIdentifier) {
7094
- throw new Error("Missing mandatory system identifier for SYSTEM notation");
7194
+ // Validate attribute name
7195
+ if (!validateEntityName(attributeName)) {
7196
+ throw new Error(`Invalid attribute name: "${attributeName}"`);
7095
7197
  }
7096
- }
7097
-
7098
- return {notationName, publicIdentifier, systemIdentifier, index: --i};
7099
- }
7100
7198
 
7101
- function readIdentifierVal(xmlData, i, type) {
7102
- let identifierVal = "";
7103
- const startChar = xmlData[i];
7104
- if (startChar !== '"' && startChar !== "'") {
7105
- throw new Error(`Expected quoted string, found "${startChar}"`);
7106
- }
7107
- i++;
7199
+ // Skip whitespace after attribute name
7200
+ i = skipWhitespace(xmlData, i);
7108
7201
 
7109
- while (i < xmlData.length && xmlData[i] !== startChar) {
7110
- identifierVal += xmlData[i];
7111
- i++;
7112
- }
7202
+ // Read attribute type
7203
+ let attributeType = "";
7204
+ if (xmlData.substring(i, i + 8).toUpperCase() === "NOTATION") {
7205
+ attributeType = "NOTATION";
7206
+ i += 8; // Move past "NOTATION"
7113
7207
 
7114
- if (xmlData[i] !== startChar) {
7115
- throw new Error(`Unterminated ${type} value`);
7116
- }
7117
- i++;
7118
- return [i, identifierVal];
7119
- }
7208
+ // Skip whitespace after "NOTATION"
7209
+ i = skipWhitespace(xmlData, i);
7120
7210
 
7121
- function readElementExp(xmlData, i) {
7122
- // <!ELEMENT br EMPTY>
7123
- // <!ELEMENT div ANY>
7124
- // <!ELEMENT title (#PCDATA)>
7125
- // <!ELEMENT book (title, author+)>
7126
- // <!ELEMENT name (content-model)>
7127
-
7128
- // Skip leading whitespace after <!ELEMENT
7129
- i = skipWhitespace(xmlData, i);
7211
+ // Expect '(' to start the list of notations
7212
+ if (xmlData[i] !== "(") {
7213
+ throw new Error(`Expected '(', found "${xmlData[i]}"`);
7214
+ }
7215
+ i++; // Move past '('
7216
+
7217
+ // Read the list of allowed notations
7218
+ let allowedNotations = [];
7219
+ while (i < xmlData.length && xmlData[i] !== ")") {
7220
+ let notation = "";
7221
+ while (i < xmlData.length && xmlData[i] !== "|" && xmlData[i] !== ")") {
7222
+ notation += xmlData[i];
7223
+ i++;
7224
+ }
7130
7225
 
7131
- // Read element name
7132
- let elementName = "";
7133
- while (i < xmlData.length && !/\s/.test(xmlData[i])) {
7134
- elementName += xmlData[i];
7135
- i++;
7136
- }
7226
+ // Validate notation name
7227
+ notation = notation.trim();
7228
+ if (!validateEntityName(notation)) {
7229
+ throw new Error(`Invalid notation name: "${notation}"`);
7230
+ }
7137
7231
 
7138
- // Validate element name
7139
- if (!validateEntityName(elementName)) {
7140
- throw new Error(`Invalid element name: "${elementName}"`);
7141
- }
7232
+ allowedNotations.push(notation);
7142
7233
 
7143
- // Skip whitespace after element name
7144
- i = skipWhitespace(xmlData, i);
7145
- let contentModel = "";
7146
- // Expect '(' to start content model
7147
- if(xmlData[i] === "E" && hasSeq(xmlData, "MPTY",i)) i+=4;
7148
- else if(xmlData[i] === "A" && hasSeq(xmlData, "NY",i)) i+=2;
7149
- else if (xmlData[i] === "(") {
7150
- i++; // Move past '('
7234
+ // Skip '|' separator or exit loop
7235
+ if (xmlData[i] === "|") {
7236
+ i++; // Move past '|'
7237
+ i = skipWhitespace(xmlData, i); // Skip optional whitespace after '|'
7238
+ }
7239
+ }
7151
7240
 
7152
- // Read content model
7153
- while (i < xmlData.length && xmlData[i] !== ")") {
7154
- contentModel += xmlData[i];
7155
- i++;
7241
+ if (xmlData[i] !== ")") {
7242
+ throw new Error("Unterminated list of notations");
7243
+ }
7244
+ i++; // Move past ')'
7245
+
7246
+ // Store the allowed notations as part of the attribute type
7247
+ attributeType += " (" + allowedNotations.join("|") + ")";
7248
+ } else {
7249
+ // Handle simple types (e.g., CDATA, ID, IDREF, etc.)
7250
+ while (i < xmlData.length && !/\s/.test(xmlData[i])) {
7251
+ attributeType += xmlData[i];
7252
+ i++;
7253
+ }
7254
+
7255
+ // Validate simple attribute type
7256
+ const validTypes = ["CDATA", "ID", "IDREF", "IDREFS", "ENTITY", "ENTITIES", "NMTOKEN", "NMTOKENS"];
7257
+ if (!this.suppressValidationErr && !validTypes.includes(attributeType.toUpperCase())) {
7258
+ throw new Error(`Invalid attribute type: "${attributeType}"`);
7259
+ }
7156
7260
  }
7157
- if (xmlData[i] !== ")") {
7158
- throw new Error("Unterminated content model");
7261
+
7262
+ // Skip whitespace after attribute type
7263
+ i = skipWhitespace(xmlData, i);
7264
+
7265
+ // Read default value
7266
+ let defaultValue = "";
7267
+ if (xmlData.substring(i, i + 8).toUpperCase() === "#REQUIRED") {
7268
+ defaultValue = "#REQUIRED";
7269
+ i += 8;
7270
+ } else if (xmlData.substring(i, i + 7).toUpperCase() === "#IMPLIED") {
7271
+ defaultValue = "#IMPLIED";
7272
+ i += 7;
7273
+ } else {
7274
+ [i, defaultValue] = this.readIdentifierVal(xmlData, i, "ATTLIST");
7159
7275
  }
7160
7276
 
7161
- }else {
7162
- throw new Error(`Invalid Element Expression, found "${xmlData[i]}"`);
7277
+ return {
7278
+ elementName,
7279
+ attributeName,
7280
+ attributeType,
7281
+ defaultValue,
7282
+ index: i
7283
+ }
7163
7284
  }
7164
-
7165
- return {
7166
- elementName,
7167
- contentModel: contentModel.trim(),
7168
- index: i
7169
- };
7170
7285
  }
7171
7286
 
7287
+
7288
+
7289
+ const skipWhitespace = (data, index) => {
7290
+ while (index < data.length && /\s/.test(data[index])) {
7291
+ index++;
7292
+ }
7293
+ return index;
7294
+ };
7295
+
7296
+
7297
+
7172
7298
  function hasSeq(data, seq,i){
7173
7299
  for(let j=0;j<seq.length;j++){
7174
7300
  if(seq[j]!==data[i+j+1]) return false;
@@ -7178,7 +7304,7 @@
7178
7304
 
7179
7305
  function validateEntityName(name){
7180
7306
  if (isName(name))
7181
- return name;
7307
+ return name;
7182
7308
  else
7183
7309
  throw new Error(`Invalid entity name ${name}`);
7184
7310
  }
@@ -7380,6 +7506,20 @@
7380
7506
  this.saveTextToParentTag = saveTextToParentTag;
7381
7507
  this.addChild = addChild$1;
7382
7508
  this.ignoreAttributesFn = getIgnoreAttributesFn(this.options.ignoreAttributes);
7509
+
7510
+ if(this.options.stopNodes && this.options.stopNodes.length > 0){
7511
+ this.stopNodesExact = new Set();
7512
+ this.stopNodesWildcard = new Set();
7513
+ for(let i = 0; i < this.options.stopNodes.length; i++){
7514
+ const stopNodeExp = this.options.stopNodes[i];
7515
+ if(typeof stopNodeExp !== 'string') continue;
7516
+ if(stopNodeExp.startsWith("*.")){
7517
+ this.stopNodesWildcard.add(stopNodeExp.substring(2));
7518
+ }else {
7519
+ this.stopNodesExact.add(stopNodeExp);
7520
+ }
7521
+ }
7522
+ }
7383
7523
  }
7384
7524
 
7385
7525
  }
@@ -7451,7 +7591,7 @@
7451
7591
  //const attrsRegx = new RegExp("([\\w\\-\\.\\:]+)\\s*=\\s*(['\"])((.|\n)*?)\\2","gm");
7452
7592
  const attrsRegx = new RegExp('([^\\s=]+)\\s*(=\\s*([\'"])([\\s\\S]*?)\\3)?', 'gm');
7453
7593
 
7454
- function buildAttributesMap(attrStr, jPath, tagName) {
7594
+ function buildAttributesMap(attrStr, jPath) {
7455
7595
  if (this.options.ignoreAttributes !== true && typeof attrStr === 'string') {
7456
7596
  // attrStr = attrStr.replace(/\r?\n/g, ' ');
7457
7597
  //attrStr = attrStr || attrStr.trim();
@@ -7514,6 +7654,7 @@
7514
7654
  let currentNode = xmlObj;
7515
7655
  let textData = "";
7516
7656
  let jPath = "";
7657
+ const docTypeReader = new DocTypeReader(this.options.processEntities);
7517
7658
  for(let i=0; i< xmlData.length; i++){//for each char in XML data
7518
7659
  const ch = xmlData[i];
7519
7660
  if(ch === '<'){
@@ -7567,7 +7708,7 @@
7567
7708
  childNode.add(this.options.textNodeName, "");
7568
7709
 
7569
7710
  if(tagData.tagName !== tagData.tagExp && tagData.attrExpPresent){
7570
- childNode[":@"] = this.buildAttributesMap(tagData.tagExp, jPath, tagData.tagName);
7711
+ childNode[":@"] = this.buildAttributesMap(tagData.tagExp, jPath);
7571
7712
  }
7572
7713
  this.addChild(currentNode, childNode, jPath, i);
7573
7714
  }
@@ -7585,7 +7726,7 @@
7585
7726
  }
7586
7727
  i = endIndex;
7587
7728
  } else if( xmlData.substr(i + 1, 2) === '!D') {
7588
- const result = readDocType(xmlData, i);
7729
+ const result = docTypeReader.readDocType(xmlData, i);
7589
7730
  this.docTypeEntities = result.entities;
7590
7731
  i = result.i;
7591
7732
  }else if(xmlData.substr(i + 1, 2) === '![') {
@@ -7614,7 +7755,12 @@
7614
7755
  let closeIndex = result.closeIndex;
7615
7756
 
7616
7757
  if (this.options.transformTagName) {
7617
- tagName = this.options.transformTagName(tagName);
7758
+ //console.log(tagExp, tagName)
7759
+ const newTagName = this.options.transformTagName(tagName);
7760
+ if(tagExp === tagName) {
7761
+ tagExp = newTagName;
7762
+ }
7763
+ tagName = newTagName;
7618
7764
  }
7619
7765
 
7620
7766
  //save text as child node
@@ -7635,7 +7781,7 @@
7635
7781
  jPath += jPath ? "." + tagName : tagName;
7636
7782
  }
7637
7783
  const startIndex = i;
7638
- if (this.isItStopNode(this.options.stopNodes, jPath, tagName)) {
7784
+ if (this.isItStopNode(this.stopNodesExact, this.stopNodesWildcard, jPath, tagName)) {
7639
7785
  let tagContent = "";
7640
7786
  //self-closing tag
7641
7787
  if(tagExp.length > 0 && tagExp.lastIndexOf("/") === tagExp.length - 1){
@@ -7665,7 +7811,8 @@
7665
7811
  const childNode = new XmlNode(tagName);
7666
7812
 
7667
7813
  if(tagName !== tagExp && attrExpPresent){
7668
- childNode[":@"] = this.buildAttributesMap(tagExp, jPath, tagName);
7814
+ childNode[":@"] = this.buildAttributesMap(tagExp, jPath
7815
+ );
7669
7816
  }
7670
7817
  if(tagContent) {
7671
7818
  tagContent = this.parseTextData(tagContent, tagName, jPath, true, attrExpPresent, true, true);
@@ -7687,12 +7834,16 @@
7687
7834
  }
7688
7835
 
7689
7836
  if(this.options.transformTagName) {
7690
- tagName = this.options.transformTagName(tagName);
7837
+ const newTagName = this.options.transformTagName(tagName);
7838
+ if(tagExp === tagName) {
7839
+ tagExp = newTagName;
7840
+ }
7841
+ tagName = newTagName;
7691
7842
  }
7692
7843
 
7693
7844
  const childNode = new XmlNode(tagName);
7694
7845
  if(tagName !== tagExp && attrExpPresent){
7695
- childNode[":@"] = this.buildAttributesMap(tagExp, jPath, tagName);
7846
+ childNode[":@"] = this.buildAttributesMap(tagExp, jPath);
7696
7847
  }
7697
7848
  this.addChild(currentNode, childNode, jPath, startIndex);
7698
7849
  jPath = jPath.substr(0, jPath.lastIndexOf("."));
@@ -7703,7 +7854,7 @@
7703
7854
  this.tagsNodeStack.push(currentNode);
7704
7855
 
7705
7856
  if(tagName !== tagExp && attrExpPresent){
7706
- childNode[":@"] = this.buildAttributesMap(tagExp, jPath, tagName);
7857
+ childNode[":@"] = this.buildAttributesMap(tagExp, jPath);
7707
7858
  }
7708
7859
  this.addChild(currentNode, childNode, jPath, startIndex);
7709
7860
  currentNode = childNode;
@@ -7772,17 +7923,14 @@
7772
7923
 
7773
7924
  //TODO: use jPath to simplify the logic
7774
7925
  /**
7775
- *
7776
- * @param {string[]} stopNodes
7926
+ * @param {Set} stopNodesExact
7927
+ * @param {Set} stopNodesWildcard
7777
7928
  * @param {string} jPath
7778
- * @param {string} currentTagName
7929
+ * @param {string} currentTagName
7779
7930
  */
7780
- function isItStopNode(stopNodes, jPath, currentTagName){
7781
- const allNodesExp = "*." + currentTagName;
7782
- for (const stopNodePath in stopNodes) {
7783
- const stopNodeExp = stopNodes[stopNodePath];
7784
- if( allNodesExp === stopNodeExp || jPath === stopNodeExp ) return true;
7785
- }
7931
+ function isItStopNode(stopNodesExact, stopNodesWildcard, jPath, currentTagName){
7932
+ if(stopNodesWildcard && stopNodesWildcard.has(currentTagName)) return true;
7933
+ if(stopNodesExact && stopNodesExact.has(jPath)) return true;
7786
7934
  return false;
7787
7935
  }
7788
7936
 
@@ -8052,15 +8200,16 @@
8052
8200
  }
8053
8201
  /**
8054
8202
  * Parse XML dats to JS object
8055
- * @param {string|Buffer} xmlData
8203
+ * @param {string|Uint8Array} xmlData
8056
8204
  * @param {boolean|Object} validationOption
8057
8205
  */
8058
8206
  parse(xmlData,validationOption){
8059
- if(typeof xmlData === "string");else if( xmlData.toString){
8207
+ if(typeof xmlData !== "string" && xmlData.toString){
8060
8208
  xmlData = xmlData.toString();
8061
- }else {
8209
+ }else if(typeof xmlData !== "string"){
8062
8210
  throw new Error("XML data is accepted in String or Bytes[] form.")
8063
8211
  }
8212
+
8064
8213
  if( validationOption){
8065
8214
  if(validationOption === true) validationOption = {}; //validate with default options
8066
8215
 
@@ -9873,19 +10022,7 @@
9873
10022
  }
9874
10023
  }
9875
10024
 
9876
- function shiftTip$1(d) {
9877
- if (this.options["is-radial"]) {
9878
- return [
9879
- (d.text_align == "end" ? -1 : 1) *
9880
- (this.radius_pad_for_bubbles - d.radius),
9881
- 0
9882
- ];
9883
- }
9884
- if (this.options["right-to-left"]) {
9885
- return [this.right_most_leaf - d.screen_x, 0];
9886
- }
9887
- return [this.right_most_leaf - d.screen_x, 0];
9888
- }
10025
+ // shiftTip function is defined in nodes.js - removed duplicate here
9889
10026
 
9890
10027
  function layoutHandler(attr) {
9891
10028
  if (!arguments.length) return this.layout_listener_handler;
@@ -9966,7 +10103,6 @@
9966
10103
  radial: radial,
9967
10104
  alignTips: alignTips,
9968
10105
  nodeBubbleSize: nodeBubbleSize,
9969
- shiftTip: shiftTip$1,
9970
10106
  layoutHandler: layoutHandler,
9971
10107
  selectionLabel: selectionLabel,
9972
10108
  get nodeSpan () { return nodeSpan$1; },
@@ -9984,8 +10120,10 @@
9984
10120
  ];
9985
10121
  }
9986
10122
 
9987
- if (this.options["right-to-left"]) {
9988
- return [this.right_most_leaf - d.screen_x, 0];
10123
+ if (this.options["layout"] == "right-to-left") {
10124
+ // For RTL, shift labels to align at the left edge (x=0)
10125
+ // screen_x is the node's horizontal position; shifting by -screen_x moves label to x=0
10126
+ return [-d.screen_x, 0];
9989
10127
  }
9990
10128
 
9991
10129
  return [this.right_most_leaf - d.screen_x, 0];
@@ -10042,18 +10180,27 @@
10042
10180
  return d.text_align;
10043
10181
  });
10044
10182
  } else {
10045
- labels = labels.attr("text-anchor", "start").attr("transform", d => {
10046
- if (this.options["layout"] == "right-to-left") {
10047
- return this.d3PhylotreeSvgTranslate([-20, 0]);
10048
- }
10049
- return this.d3PhylotreeSvgTranslate(
10050
- this.alignTips() ? this.shiftTip(d) : null
10051
- );
10052
- });
10183
+ const isRTL = this.options["layout"] == "right-to-left";
10184
+ labels = labels
10185
+ .attr("text-anchor", isRTL ? "end" : "start")
10186
+ .attr("transform", d => {
10187
+ return this.d3PhylotreeSvgTranslate(
10188
+ this.alignTips() ? this.shiftTip(d) : null
10189
+ );
10190
+ });
10053
10191
  }
10054
10192
 
10055
10193
  if (this.alignTips()) {
10056
10194
  tracers = tracers.data([node]);
10195
+ const isRTL = this.options["layout"] == "right-to-left";
10196
+
10197
+ // Determine direction multiplier for tracer start position
10198
+ const getX1Direction = (d) => {
10199
+ if (this.radial()) {
10200
+ return d.text_align == "end" ? -1 : 1;
10201
+ }
10202
+ return isRTL ? -1 : 1;
10203
+ };
10057
10204
 
10058
10205
  if (transitions) {
10059
10206
  tracers = tracers
@@ -10062,27 +10209,12 @@
10062
10209
  .classed(this.css_classes["branch-tracer"], true)
10063
10210
  .merge(tracers)
10064
10211
  .attr("x1", d => {
10065
- return (
10066
- (d.text_align == "end" ? -1 : 1) * this.nodeBubbleSize(node)
10067
- );
10212
+ return getX1Direction(d) * this.nodeBubbleSize(node);
10068
10213
  })
10069
10214
  .attr("x2", 0)
10070
10215
  .attr("y1", 0)
10071
10216
  .attr("y2", 0)
10072
10217
  .attr("x2", d => {
10073
- if (this.options["layout"] == "right-to-left") {
10074
- return d.screen_x;
10075
- }
10076
-
10077
- return this.shiftTip(d)[0];
10078
- })
10079
- .attr("transform", d => {
10080
- return this.d3PhylotreeSvgRotate(d.text_angle);
10081
- })
10082
- .attr("x2", d => {
10083
- if (this.options["layout"] == "right-to-left") {
10084
- return d.screen_x;
10085
- }
10086
10218
  return this.shiftTip(d)[0];
10087
10219
  })
10088
10220
  .attr("transform", d => {
@@ -10095,9 +10227,7 @@
10095
10227
  .classed(this.css_classes["branch-tracer"], true)
10096
10228
  .merge(tracers)
10097
10229
  .attr("x1", d => {
10098
- return (
10099
- (d.text_align == "end" ? -1 : 1) * this.nodeBubbleSize(node)
10100
- );
10230
+ return getX1Direction(d) * this.nodeBubbleSize(node);
10101
10231
  })
10102
10232
  .attr("y2", 0)
10103
10233
  .attr("y1", 0)
@@ -10127,17 +10257,24 @@
10127
10257
  });
10128
10258
 
10129
10259
  if (this.shown_font_size >= 5) {
10260
+ const isRTL = this.options["layout"] == "right-to-left";
10130
10261
  labels = labels.attr("dx", d => {
10131
- return (
10132
- (d.text_align == "end" ? -1 : 1) *
10133
- ((this.alignTips() ? 0 : shift) + this.shown_font_size * 0.33)
10134
- );
10262
+ // For radial, use text_align; for linear RTL, use negative offset; otherwise positive
10263
+ const direction = this.radial()
10264
+ ? (d.text_align == "end" ? -1 : 1)
10265
+ : (isRTL ? -1 : 1);
10266
+ return direction * ((this.alignTips() ? 0 : shift) + this.shown_font_size * 0.33);
10135
10267
  });
10136
10268
  }
10137
10269
  } else {
10138
10270
  if (this.shown_font_size >= 5) {
10271
+ const isRTL = this.options["layout"] == "right-to-left";
10139
10272
  labels = labels.attr("dx", d => { // eslint-disable-line
10140
- return (d.text_align == "end" ? -1 : 1) * this.shown_font_size * 0.33;
10273
+ // For radial, use text_align; for linear RTL, use negative offset; otherwise positive
10274
+ const direction = this.radial()
10275
+ ? (d.text_align == "end" ? -1 : 1)
10276
+ : (isRTL ? -1 : 1);
10277
+ return direction * this.shown_font_size * 0.33;
10141
10278
  });
10142
10279
  }
10143
10280
  }
@@ -10671,17 +10808,25 @@
10671
10808
  sizes[0] + 2 * pad_radius + vertical_offset
10672
10809
  ];
10673
10810
 
10811
+ // Update base transform for radial layout
10812
+ this.baseTransform = {
10813
+ x: pad_radius,
10814
+ y: pad_radius + vertical_offset
10815
+ };
10816
+
10674
10817
  if (svg) {
10818
+ // Compose with zoom transform if present
10819
+ let transform;
10820
+ if (this.currentZoomTransform && this.options["zoom"]) {
10821
+ const zt = this.currentZoomTransform;
10822
+ transform = `translate(${zt.x + this.baseTransform.x * zt.k}, ${zt.y + this.baseTransform.y * zt.k}) scale(${zt.k})`;
10823
+ } else {
10824
+ transform = "translate(" + pad_radius + "," + (pad_radius + vertical_offset) + ")";
10825
+ }
10826
+
10675
10827
  svg
10676
10828
  .selectAll("." + css_classes["tree-container"])
10677
- .attr(
10678
- "transform",
10679
- "translate (" +
10680
- pad_radius +
10681
- "," +
10682
- (pad_radius + vertical_offset) +
10683
- ")"
10684
- );
10829
+ .attr("transform", transform);
10685
10830
  }
10686
10831
  } else {
10687
10832
 
@@ -10862,11 +11007,15 @@
10862
11007
  .attr("class", "phylotree-menu-item dropdown-item")
10863
11008
  .attr("tabindex", "-1")
10864
11009
  .text("All descendant branches")
10865
- .on("click", function(d) {
11010
+ .on("click", (d) => {
10866
11011
  menu_object.style("display", "none");
10867
- phylotree.modifySelection(
10868
- phylotree.selectAllDescendants(node, true, true)
10869
- );
11012
+ const nodes = phylotree.selectAllDescendants(node, true, true);
11013
+ if (this.options["selection-mode"] === "multi-set" && this._activeSetName) {
11014
+ nodes.forEach(n => this.addToSet(n, this._activeSetName));
11015
+ this.update();
11016
+ } else {
11017
+ this.modifySelection(nodes);
11018
+ }
10870
11019
  });
10871
11020
 
10872
11021
  menu_object
@@ -10874,11 +11023,15 @@
10874
11023
  .attr("class", "phylotree-menu-item dropdown-item")
10875
11024
  .attr("tabindex", "-1")
10876
11025
  .text("All terminal branches")
10877
- .on("click", function(d) {
11026
+ .on("click", (d) => {
10878
11027
  menu_object.style("display", "none");
10879
- phylotree.modifySelection(
10880
- phylotree.selectAllDescendants(node, true, false)
10881
- );
11028
+ const nodes = phylotree.selectAllDescendants(node, true, false);
11029
+ if (this.options["selection-mode"] === "multi-set" && this._activeSetName) {
11030
+ nodes.forEach(n => this.addToSet(n, this._activeSetName));
11031
+ this.update();
11032
+ } else {
11033
+ this.modifySelection(nodes);
11034
+ }
10882
11035
  });
10883
11036
 
10884
11037
  menu_object
@@ -10886,11 +11039,15 @@
10886
11039
  .attr("class", "phylotree-menu-item dropdown-item")
10887
11040
  .attr("tabindex", "-1")
10888
11041
  .text("All internal branches")
10889
- .on("click", function(d) {
11042
+ .on("click", (d) => {
10890
11043
  menu_object.style("display", "none");
10891
- phylotree.modifySelection(
10892
- phylotree.selectAllDescendants(node, false, true)
10893
- );
11044
+ const nodes = phylotree.selectAllDescendants(node, false, true);
11045
+ if (this.options["selection-mode"] === "multi-set" && this._activeSetName) {
11046
+ nodes.forEach(n => this.addToSet(n, this._activeSetName));
11047
+ this.update();
11048
+ } else {
11049
+ this.modifySelection(nodes);
11050
+ }
10894
11051
  });
10895
11052
  }
10896
11053
  }
@@ -10902,9 +11059,14 @@
10902
11059
  .attr("class", "phylotree-menu-item dropdown-item")
10903
11060
  .attr("tabindex", "-1")
10904
11061
  .text("Incident branch")
10905
- .on("click", function(d) {
11062
+ .on("click", (d) => {
10906
11063
  menu_object.style("display", "none");
10907
- phylotree.modifySelection([node]);
11064
+ if (this.options["selection-mode"] === "multi-set" && this._activeSetName) {
11065
+ this.addToSet(node, this._activeSetName);
11066
+ this.update();
11067
+ } else {
11068
+ this.modifySelection([node]);
11069
+ }
10908
11070
  });
10909
11071
 
10910
11072
  menu_object
@@ -10912,9 +11074,15 @@
10912
11074
  .attr("class", "phylotree-menu-item dropdown-item")
10913
11075
  .attr("tabindex", "-1")
10914
11076
  .text("Path to root")
10915
- .on("click", d => {
11077
+ .on("click", (d) => {
10916
11078
  menu_object.style("display", "none");
10917
- this.modifySelection(this.phylotree.pathToRoot(node));
11079
+ const nodes = this.phylotree.pathToRoot(node);
11080
+ if (this.options["selection-mode"] === "multi-set" && this._activeSetName) {
11081
+ nodes.forEach(n => this.addToSet(n, this._activeSetName));
11082
+ this.update();
11083
+ } else {
11084
+ this.modifySelection(nodes);
11085
+ }
10918
11086
  });
10919
11087
 
10920
11088
  if (options["reroot"] || options["hide"]) {
@@ -11791,6 +11959,10 @@
11791
11959
  this.node_styler = this.options['node-styler'];
11792
11960
  this.edge_styler = this.options['edge-styler'];
11793
11961
 
11962
+ // Store zoom state to preserve across updates
11963
+ this.currentZoomTransform = null;
11964
+ this.baseTransform = { x: 0, y: 0 };
11965
+
11794
11966
  this.nodeSpan = this.options['node-span'];
11795
11967
 
11796
11968
  if(!this.nodeSpan) {
@@ -11975,6 +12147,10 @@
11975
12147
 
11976
12148
  this.placenodes();
11977
12149
 
12150
+ // Sync edge labels BEFORE drawing edges so that edge.selected reflects node.selected
12151
+ // This is critical for custom edge stylers that rely on selection state
12152
+ this.syncEdgeLabels();
12153
+
11978
12154
  transitions = this.transitions(transitions);
11979
12155
 
11980
12156
  let node_id = 0;
@@ -11983,15 +12159,26 @@
11983
12159
  .selectAll("." + css_classes["tree-container"])
11984
12160
  .data([0]);
11985
12161
 
12162
+ // Store base transform for composition with zoom
12163
+ this.baseTransform = {
12164
+ x: this.offsets[1] + this.options["left-offset"],
12165
+ y: this.pad_height()
12166
+ };
12167
+
11986
12168
  enclosure = enclosure
11987
12169
  .enter()
11988
12170
  .append("g")
11989
12171
  .attr("class", css_classes["tree-container"])
11990
12172
  .merge(enclosure)
11991
12173
  .attr("transform", d => {
12174
+ // Compose base transform with current zoom transform if present
12175
+ if (this.currentZoomTransform && this.options["zoom"]) {
12176
+ const zt = this.currentZoomTransform;
12177
+ return `translate(${zt.x + this.baseTransform.x * zt.k}, ${zt.y + this.baseTransform.y * zt.k}) scale(${zt.k})`;
12178
+ }
11992
12179
  return this.d3PhylotreeSvgTranslate([
11993
- this.offsets[1] + this.options["left-offset"],
11994
- this.pad_height()
12180
+ this.baseTransform.x,
12181
+ this.baseTransform.y
11995
12182
  ]);
11996
12183
  });
11997
12184
 
@@ -12140,28 +12327,38 @@
12140
12327
  brush$1.call(brush_object);
12141
12328
  }
12142
12329
 
12143
- this.syncEdgeLabels();
12330
+ // Note: syncEdgeLabels() is called at the start of update() before edges are drawn
12331
+ // to ensure selection state is synced before reclassEdge and edge_styler run
12144
12332
 
12145
12333
  if (this.options["zoom"]) {
12146
- let zoom$1 = zoom()
12147
- .scaleExtent([0.1, 10])
12148
- .on("zoom", (event) => {
12149
-
12150
- select("." + css_classes["tree-container"]).attr("transform", d => {
12151
- let toTransform = event.transform;
12152
- return toTransform;
12334
+ // Create zoom behavior if not already created
12335
+ if (!this.zoomBehavior) {
12336
+ this.zoomBehavior = zoom()
12337
+ .scaleExtent([0.1, 10])
12338
+ .on("zoom", (event) => {
12339
+ // Store the current zoom transform
12340
+ this.currentZoomTransform = event.transform;
12341
+
12342
+ // Compose zoom transform with base transform
12343
+ const zt = event.transform;
12344
+ const composedTransform = `translate(${zt.x + this.baseTransform.x * zt.k}, ${zt.y + this.baseTransform.y * zt.k}) scale(${zt.k})`;
12345
+
12346
+ // Use this.svg.select() to target only this tree instance (not global d3.select)
12347
+ this.svg.select("." + css_classes["tree-container"]).attr("transform", composedTransform);
12348
+
12349
+ // Apply same transform to scale bar
12350
+ this.svg.select("." + css_classes["tree-scale-bar"]).attr("transform", d => {
12351
+ return `translate(${zt.x + this.baseTransform.x * zt.k}, ${zt.y + (this.baseTransform.y - 10) * zt.k}) scale(${zt.k})`;
12352
+ });
12153
12353
  });
12354
+ }
12154
12355
 
12155
- // Give some extra room
12156
- select("." + css_classes["tree-scale-bar"]).attr("transform", d => {
12157
- let toTransform = event.transform;
12158
- toTransform.y -= 10;
12159
- return toTransform;
12160
- });
12161
-
12162
- });
12356
+ this.svg.call(this.zoomBehavior);
12163
12357
 
12164
- this.svg.call(zoom$1);
12358
+ // Restore zoom transform if we have one stored (preserves zoom across updates)
12359
+ if (this.currentZoomTransform) {
12360
+ this.svg.call(this.zoomBehavior.transform, this.currentZoomTransform);
12361
+ }
12165
12362
  }
12166
12363
 
12167
12364
  // Emit rendered event
@@ -12690,7 +12887,7 @@
12690
12887
  this.size[0] = this.radial_center + this.radius / scaler;
12691
12888
  this.size[1] = this.radial_center + this.radius / scaler;
12692
12889
  } else {
12693
- this.do_lr();
12890
+ this.do_lr();
12694
12891
 
12695
12892
  this.draw_branch = draw_line;
12696
12893
  this.edge_placer = lineSegmentPlacer;
@@ -12701,8 +12898,10 @@
12701
12898
  d.x *= this.scales[0];
12702
12899
  d.y *= this.scales[1]*.8;
12703
12900
 
12704
- if (this.options["layout"] == "right-to-left") {
12705
- d.y = this._extents[1][1] * this.scales[1] - d.y;
12901
+ if (this.options["layout"] == "right-to-left") {
12902
+ // For RTL, always add label_width offset to shift tree right,
12903
+ // creating space on the left for labels (prevents labels overlapping branches)
12904
+ d.y = this._extents[1][1] * this.scales[1] - d.y + this.label_width;
12706
12905
  }
12707
12906
 
12708
12907