@@ -5,12 +5,15 @@ const defaultOptions = {
55 vertical : "10px" ,
66 horizontal : "16px" ,
77 } ,
8+ innerPadding : "4px" ,
9+ outerPadding : "4px" ,
810 halfway : "50%" ,
911 fontFamily : {
1012 inner : "Rashi" ,
1113 outer : "Rashi" ,
1214 main : "Vilna"
1315 } ,
16+ direction : "rtl" ,
1417 fontSize : {
1518 main : "15px" ,
1619 side : "10.5px"
@@ -77,27 +80,23 @@ function calculateSpacers(mainText, innerText, outerText, options, dummy) {
7780 const topWidth = Number ( parsedOptions . width * parsedOptions . halfway ) - parsedOptions . padding . horizontal ; //each commentary top
7881 const sideWidth = Number ( parsedOptions . width * ( 1 - parsedOptions . mainWidth ) / 2 ) ; //each commentary widths, dont include padding, sokeep it constant
7982
80- // These values are unique to the font you are using:
81- // If you change fonts, you may have to modify these numbers, but the value should always be close to 1.
82- const innerModifier = 1 ; // Rashi font sometimes causes a percentage difference error 113% when it comes to browser rendering
83- const outerModifier = 1 ;
84- const mainModifier = 1 ; // Vilna font sometimes causes a percentage difference error of 95% when it comes to browser rendering
85-
8683 // We could probably put this somewhere else, it was meant to be a place for all the padding corrections,
8784 // but there turned out to only be one
8885 const paddingAreas = {
8986 name : "paddingAreas" ,
9087 horizontalSide : sideWidth * parsedOptions . padding . vertical ,
9188 } ;
9289
93- const adjustCommentaryArea = ( area , lineHeight ) => area - ( 4 * lineHeight * topWidth ) ; //remove area of the top 4 lines
90+
91+ const topArea = ( lineHeight ) => ( ( 4 * lineHeight * topWidth ) - paddingAreas . horizontalSide ) ; //remove area of the top 4 lines
92+
93+
9494 const main = {
9595 name : "main" ,
9696 width : midWidth ,
9797 text : mainText ,
9898 lineHeight : parsedOptions . lineHeight . main ,
99- area : getAreaOfText ( mainText , parsedOptions . fontFamily . main , parsedOptions . fontSize . main , midWidth , parsedOptions . lineHeight . main , dummy )
100- * mainModifier ,
99+ area : getAreaOfText ( mainText , parsedOptions . fontFamily . main , parsedOptions . fontSize . main , midWidth , parsedOptions . lineHeight . main , dummy ) ,
101100 length : null ,
102101 height : null ,
103102 } ;
@@ -106,11 +105,8 @@ function calculateSpacers(mainText, innerText, outerText, options, dummy) {
106105 width : sideWidth ,
107106 text : outerText ,
108107 lineHeight : parsedOptions . lineHeight . side ,
109- area : adjustCommentaryArea (
110- getAreaOfText ( outerText , parsedOptions . fontFamily . outer , parsedOptions . fontSize . side , sideWidth , parsedOptions . lineHeight . side , dummy )
111- * outerModifier ,
112- parsedOptions . lineHeight . side
113- ) - paddingAreas . horizontalSide ,
108+ area : getAreaOfText ( outerText , parsedOptions . fontFamily . outer , parsedOptions . fontSize . side , sideWidth , parsedOptions . lineHeight . side , dummy )
109+ - topArea ( parsedOptions . lineHeight . side ) ,
114110 length : null ,
115111 height : null ,
116112 } ;
@@ -119,17 +115,17 @@ function calculateSpacers(mainText, innerText, outerText, options, dummy) {
119115 width : sideWidth ,
120116 text : innerText ,
121117 lineHeight : parsedOptions . lineHeight . side ,
122- area : adjustCommentaryArea (
118+ area :
123119 getAreaOfText ( innerText , parsedOptions . fontFamily . inner , parsedOptions . fontSize . side , sideWidth , parsedOptions . lineHeight . side , dummy )
124- * innerModifier ,
125- parsedOptions . lineHeight . side
126- ) - paddingAreas . horizontalSide ,
120+ - topArea ( parsedOptions . lineHeight . side ) ,
127121 length : null ,
128122 height : null ,
129123 } ;
130124
131125 const texts = [ main , outer , inner ] ;
132- texts . forEach ( text => text . height = text . area / text . width ) ;
126+ texts . forEach ( text => text . height = text . area / text . width ) ;
127+ texts . forEach ( text => text . unadjustedArea = text . area + topArea ( parsedOptions . lineHeight . side ) ) ;
128+ texts . forEach ( text => text . unadjustedHeight = text . unadjustedArea / text . width ) ;
133129
134130 const perHeight = Array . from ( texts ) . sort ( ( a , b ) => a . height - b . height ) ;
135131
@@ -144,16 +140,41 @@ function calculateSpacers(mainText, innerText, outerText, options, dummy) {
144140
145141 //First we need to check we have enough commentary to fill the first four lines
146142 if ( inner . height <= 0 && outer . height <= 0 ) {
147- console . error ( "Not Enough Commentary" ) ;
148- return Error ( "Not enough commentary " ) ;
143+ console . error ( "No Commentary" ) ;
144+ return Error ( "No Commentary " ) ;
149145 }
150146 const spacerHeights = {
151- start : 4 * parsedOptions . lineHeight . side , // For Tzurat Hadaf this will always be the same
147+ start : 4 * parsedOptions . lineHeight . side ,
152148 inner : null ,
153149 outer : null ,
154150 end : 0 ,
155151 } ;
156152
153+ console . log ( inner . height , inner . unadjustedHeight , outer . height , outer . unadjustedHeight , spacerHeights . start ) ;
154+ // This is a case that we have to decice what to do with, when there is not enough commentary on both sides to fill the lines.
155+ if ( inner . height <= spacerHeights . start && outer . height <= spacerHeights . start ) {
156+ console . error ( "Not Enough Commentary to Fill Four Lines" ) ;
157+ return Error ( "Not Enough Commentary" ) ;
158+ }
159+ // We are going to deal with our first edge case when there is either only one commentary
160+ // Or where there is enough of one commentary, but not four lines of the other.
161+ if ( inner . unadjustedHeight <= spacerHeights . start || outer . unadjustedHeight <= spacerHeights . start ) {
162+ if ( inner . unadjustedHeight <= spacerHeights . start ) {
163+ spacerHeights . inner = inner . unadjustedHeight ;
164+
165+ spacerHeights . outer = ( outer . unadjustedArea - parsedOptions . width * 4 * parsedOptions . lineHeight . side ) / sideWidth ;
166+ return spacerHeights ;
167+ }
168+ if ( outer . unadjustedHeight <= spacerHeights . start ) {
169+ spacerHeights . outer = outer . unadjustedHeight ;
170+
171+ spacerHeights . inner = ( inner . unadjustedArea - parsedOptions . width * 4 * parsedOptions . lineHeight . side ) / sideWidth ;
172+ return spacerHeights ;
173+ }
174+ else {
175+ return Error ( "Inner Spacer Error" ) ;
176+ }
177+ }
157178 //If Double=Wrap
158179 if ( perHeight [ 0 ] . name === "main" ) {
159180 console . log ( "Double-Wrap" ) ;
@@ -219,7 +240,7 @@ function styleInject(css, ref) {
219240 }
220241}
221242
222- var css_248z = "/*Keep this as the first rule in the file*/\n.styles_dafRoot__1QUlM {\n --contentWidth: 0px;\n --padding-horizontal: 0px;\n --padding-vertical: 0px;\n --halfway: 50%;\n\n --fontFamily-inner: \"Rashi\";\n --fontFamily-outer: \"Tosafot\";\n --fontFamily-main: \"Vilna\";\n\n --fontSize-main: 0px;\n --fontSize-side: 0px;\n\n --lineHeight-main: 0px;\n --lineHeight-side: 0px;\n\n --mainMargin-start: 50%;\n --sidePercent: calc(calc(100% - var(--mainMargin-start))/2);\n --remainderPercent: calc(100% - var(--sidePercent));\n\n --innerFloat: left;\n --outerFloat: right;\n\n --spacerHeights-start: 0px;\n --spacerHeights-outer: 0px;\n --spacerHeights-inner: 0px;\n --spacerHeights-end: 0px;\n\n}\n\n/*Containers*/\n.styles_dafRoot__1QUlM, .styles_outer__abXQX, .styles_inner__x-amJ, .styles_main__BHTRd {\n position: absolute;\n width: var(--contentWidth);\n pointer-events: none;\n box-sizing: content-box;\n}\n\n/*Float changes with amud*/\n.styles_inner__x-amJ .styles_spacer__2T7TS, .styles_main__BHTRd .styles_spacer__2T7TS.styles_outerMid__2WtcY{\n float: var(--innerFloat);\n}\n\n.styles_outer__abXQX .styles_spacer__2T7TS, .styles_main__BHTRd .styles_spacer__2T7TS.styles_innerMid__27MCi{\n float: var(--outerFloat);\n}\n\n\n/*Spacer widths determined by options*/\n.styles_inner__x-amJ .styles_spacer__2T7TS, .styles_outer__abXQX .styles_spacer__2T7TS {\n width: var(--halfway);\n}\n.styles_spacer__2T7TS.styles_mid__dcgUr {\n width: var(--remainderPercent);\n}\n\n.styles_main__BHTRd .styles_spacer__2T7TS.styles_start__AwkfY {\n width: var(--contentWidth);\n}\n.styles_main__BHTRd .styles_spacer__2T7TS.styles_innerMid__27MCi, .styles_main__BHTRd .styles_spacer__2T7TS.styles_outerMid__2WtcY {\n width: var(--sidePercent);\n}\n\n/*Spacer heights determined by algorithm*/\n.styles_spacer__2T7TS.styles_start__AwkfY {\n height: var(--spacerHeights-start);\n}\n\n.styles_spacer__2T7TS.styles_end__2wr6A {\n height: var(--spacerHeights-end);\n}\n\n.styles_inner__x-amJ .styles_spacer__2T7TS.styles_mid__dcgUr, .styles_main__BHTRd .styles_spacer__2T7TS.styles_innerMid__27MCi {\n height: var(--spacerHeights-inner);\n}\n.styles_outer__abXQX .styles_spacer__2T7TS.styles_mid__dcgUr, .styles_main__BHTRd .styles_spacer__2T7TS.styles_outerMid__2WtcY {\n height: var(--spacerHeights-outer);\n}\n\n/*Margins!*/\n.styles_spacer__2T7TS.styles_start__AwkfY, .styles_spacer__2T7TS.styles_end__2wr6A, .styles_main__BHTRd .styles_spacer__2T7TS.styles_innerMid__27MCi, .styles_main__BHTRd .styles_spacer__2T7TS.styles_outerMid__2WtcY {\n margin-left: calc(0.5 * var(--padding-horizontal));\n margin-right: calc(0.5 * var(--padding-horizontal));\n}\n\n.styles_spacer__2T7TS.styles_mid__dcgUr, .styles_main__BHTRd .styles_text__1_7-z {\n margin-top: var(--padding-vertical);\n}\n\n.styles_spacer__2T7TS.styles_mid__dcgUr, .styles_main__BHTRd .styles_spacer__2T7TS.styles_innerMid__27MCi, .styles_main__BHTRd .styles_spacer__2T7TS.styles_outerMid__2WtcY {\n margin-bottom: calc(2 * var(--padding-vertical));\n}\n\n\n/*Text*/\n.styles_text__1_7-z {\n direction: rtl;\n text-align: justify;\n}\n\n.styles_text__1_7-z span {\n pointer-events: auto;\n}\n\n.styles_main__BHTRd .styles_text__1_7-z {\n font-family: var(--fontFamily-main);\n font-size: var(--fontSize-main);\n line-height: var(--lineHeight-main);\n}\n\n.styles_inner__x-amJ .styles_text__1_7-z, .styles_outer__abXQX .styles_text__1_7-z {\n font-size: var(--fontSize-side);\n line-height: var(--lineHeight-side);\n}\n\n.styles_inner__x-amJ .styles_text__1_7-z {\n font-family: var(--fontFamily-inner);\n}\n\n.styles_outer__abXQX .styles_text__1_7-z {\n font-family: var(--fontFamily-outer);\n}\n" ;
243+ var css_248z = "/*Keep this as the first rule in the file*/\n.styles_dafRoot__1QUlM {\n --contentWidth: 0px;\n --padding-horizontal: 0px;\n --padding-vertical: 0px;\n --halfway: 50%;\n\n --fontFamily-inner: \"Rashi\";\n --fontFamily-outer: \"Tosafot\";\n --fontFamily-main: \"Vilna\";\n --direction: \"rtl\"\n\n --fontSize-main: 0px;\n --fontSize-side: 0px;\n\n --lineHeight-main: 0px;\n --lineHeight-side: 0px;\n\n --mainMargin-start: 50%;\n --sidePercent: calc(calc(100% - var(--mainMargin-start)) / 2);\n --remainderPercent: calc(100% - var(--sidePercent));\n\n --innerFloat: left;\n --outerFloat: right;\n\n --exception1: 0;\n --exception2: 0;\n --innerStart: 50%;\n --innerPadding: 0px;\n --outerStart: 50%;\n --outerPadding: 0px;\n\n --spacerHeights-start: 0px;\n --spacerHeights-outer: 0px;\n --spacerHeights-inner: 0px;\n --spacerHeights-end: 0px;\n}\n\n/*Containers*/\n.styles_dafRoot__1QUlM,\n.styles_outer__abXQX,\n.styles_inner__x-amJ,\n.styles_main__BHTRd {\n position: absolute;\n width: var(--contentWidth);\n pointer-events: none;\n box-sizing: content-box;\n}\n\n/*Float changes with amud*/\n.styles_inner__x-amJ .styles_spacer__2T7TS,\n.styles_main__BHTRd .styles_spacer__2T7TS.styles_outerMid__2WtcY {\n float: var(--innerFloat);\n}\n\n.styles_outer__abXQX .styles_spacer__2T7TS,\n.styles_main__BHTRd .styles_spacer__2T7TS.styles_innerMid__27MCi {\n float: var(--outerFloat);\n}\n\n/*Spacer widths determined by options*/\n.styles_inner__x-amJ .styles_spacer__2T7TS,\n.styles_outer__abXQX .styles_spacer__2T7TS {\n width: var(--halfway);\n}\n.styles_spacer__2T7TS.styles_mid__dcgUr {\n width: var(--remainderPercent);\n}\n\n.styles_main__BHTRd .styles_spacer__2T7TS.styles_start__AwkfY {\n width: var(--contentWidth);\n}\n.styles_main__BHTRd .styles_spacer__2T7TS.styles_innerMid__27MCi,\n.styles_main__BHTRd .styles_spacer__2T7TS.styles_outerMid__2WtcY {\n width: var(--sidePercent);\n}\n\n/*Spacer heights determined by algorithm*/\n.styles_spacer__2T7TS.styles_start__AwkfY {\n height: var(--spacerHeights-start);\n}\n\n.styles_inner__x-amJ .styles_spacer__2T7TS.styles_start__AwkfY {\n width: var(--innerStart);\n margin-left: var(--innerPadding);\n margin-right: var(--innerPadding);\n}\n\n.styles_outer__abXQX .styles_spacer__2T7TS.styles_start__AwkfY {\n width: var(--outerStart);\n margin-left: var(--outerPadding);\n margin-right: var(--outerPadding);\n}\n\n.styles_spacer__2T7TS.styles_mid__dcgUr {\n clear: both;\n}\n\n.styles_spacer__2T7TS.styles_end__2wr6A {\n height: var(--spacerHeights-end);\n}\n\n.styles_inner__x-amJ .styles_spacer__2T7TS.styles_mid__dcgUr,\n.styles_main__BHTRd .styles_spacer__2T7TS.styles_innerMid__27MCi {\n height: var(--spacerHeights-inner);\n}\n.styles_outer__abXQX .styles_spacer__2T7TS.styles_mid__dcgUr,\n.styles_main__BHTRd .styles_spacer__2T7TS.styles_outerMid__2WtcY {\n height: var(--spacerHeights-outer);\n}\n\n/*Margins!*/\n.styles_spacer__2T7TS.styles_start__AwkfY,\n.styles_spacer__2T7TS.styles_end__2wr6A,\n.styles_main__BHTRd .styles_spacer__2T7TS.styles_innerMid__27MCi,\n.styles_main__BHTRd .styles_spacer__2T7TS.styles_outerMid__2WtcY {\n margin-left: calc(0.5 * var(--padding-horizontal));\n margin-right: calc(0.5 * var(--padding-horizontal));\n}\n\n.styles_spacer__2T7TS.styles_mid__dcgUr,\n.styles_main__BHTRd .styles_text__1_7-z {\n margin-top: var(--padding-vertical);\n}\n\n.styles_inner__x-amJ .styles_spacer__2T7TS.styles_start__AwkfY{\n margin-bottom: calc(var(--padding-vertical) * var(--exception1));\n}\n.styles_outer__abXQX .styles_spacer__2T7TS.styles_start__AwkfY {\n margin-bottom: calc(var(--padding-vertical) * var(--exception2));\n}\n\n.styles_spacer__2T7TS.styles_mid__dcgUr,\n.styles_main__BHTRd .styles_spacer__2T7TS.styles_innerMid__27MCi,\n.styles_main__BHTRd .styles_spacer__2T7TS.styles_outerMid__2WtcY {\n margin-bottom: var(--padding-vertical);\n}\n\n/*Text*/\n.styles_text__1_7-z {\n direction: var(--direction);\n text-align: justify;\n}\n\n.styles_text__1_7-z span {\n pointer-events: auto;\n}\n\n.styles_main__BHTRd .styles_text__1_7-z {\n font-family: var(--fontFamily-main);\n font-size: var(--fontSize-main);\n line-height: var(--lineHeight-main);\n}\n\n.styles_inner__x-amJ .styles_text__1_7-z,\n.styles_outer__abXQX .styles_text__1_7-z {\n font-size: var(--fontSize-side);\n line-height: var(--lineHeight-side);\n}\n\n.styles_inner__x-amJ .styles_text__1_7-z {\n font-family: var(--fontFamily-inner);\n}\n\n.styles_outer__abXQX .styles_text__1_7-z {\n font-family: var(--fontFamily-outer);\n}\n" ;
223244var classes = { "dafRoot" :"styles_dafRoot__1QUlM" , "outer" :"styles_outer__abXQX" , "inner" :"styles_inner__x-amJ" , "main" :"styles_main__BHTRd" , "spacer" :"styles_spacer__2T7TS" , "outerMid" :"styles_outerMid__2WtcY" , "innerMid" :"styles_innerMid__27MCi" , "mid" :"styles_mid__dcgUr" , "start" :"styles_start__AwkfY" , "end" :"styles_end__2wr6A" , "text" :"styles_text__1_7-z" } ;
224245styleInject ( css_248z ) ;
225246
@@ -305,6 +326,27 @@ var styleManager = {
305326 innerFloat : amudB ? "right" : "left" ,
306327 outerFloat : amudB ? "left" : "right"
307328 } ) ;
329+ } ,
330+ manageExceptions ( spacerHeights ) {
331+ if ( spacerHeights . inner < spacerHeights . start ) {
332+ setVars ( {
333+ exception1 : "1" ,
334+ innerStart : "100%" ,
335+ outerStart : "0%" ,
336+ innerPadding : "0px" ,
337+ outerPadding : "0px" ,
338+ } ) ;
339+ }
340+ if ( spacerHeights . outer < spacerHeights . start ) {
341+ setVars ( {
342+ exception2 : "1" ,
343+ outerStart : "0%" ,
344+ innerStart : "100%" ,
345+ innerPadding : "0px" ,
346+ outerPadding : "0px"
347+
348+ } ) ;
349+ }
308350 }
309351} ;
310352
@@ -391,8 +433,9 @@ function renderer (el, options = defaultOptions) {
391433 styleManager . updateIsAmudB ( amud == "b" ) ;
392434 }
393435 this . spacerHeights = calculateSpacers ( main , inner , outer , clonedOptions , containers . dummy ) ;
394- console . dir ( this . spacerHeights ) ;
395436 styleManager . updateSpacersVars ( this . spacerHeights ) ;
437+ styleManager . manageExceptions ( this . spacerHeights ) ;
438+ console . log ( this . spacerHeights ) ;
396439 textSpans . main . innerHTML = main ;
397440 textSpans . inner . innerHTML = inner ;
398441 textSpans . outer . innerHTML = outer ;
0 commit comments