Jump to content

User:PerfektesChaos/js/WikiSyntaxTextMod/dI.js

From Wikipedia, the free encyclopedia
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
/// PerfektesChaos/js/WikiSyntaxTextMod/dI.js
/// 2023-04-03 PerfektesChaos@de.wikipedia
/// Fingerprint: #0#0#
/// License: CC-by-sa/4.0
/// <nowiki>
// WikiSyntaxTextMod:  Wiki syntax media parameter handling
/* global mw:true, mediaWiki:false                                     */
/* jshint forin:false,
          bitwise:true, curly:true, eqeqeq:true, latedef:true,
          laxbreak:true,
          nocomma:true, strict:true, undef:true, unused:true           */


if ( typeof mediaWiki  !==  "object" ) {   // disconnected
   mw  =  { config: false,
            libs:   { WikiSyntaxTextMod:  { }
                    },
            log:    function () {"use strict";}
          };
}
( function ( mw ) {
   "use strict";
   var version  =  -7.61,
       sign     =  "WikiSyntaxTextMod",
       sub      =  "I",
       rls, self, WSTM;
   if ( typeof mw.loader  ===  "object" ) {
      rls   =  { };
      self  =  "user:PerfektesChaos/" + sign + "/" + sub;
      rls[ self ] = "loading";
      mw.loader.state( rls );
   }
   if ( typeof mw.libs[ sign ]  !==  "object" ) {   // isolated
      mw.libs[ sign ]  =  { };
   }
   WSTM  =  mw.libs[ sign ];
   if ( typeof WSTM.w  !==  "object" ) {
      WSTM.w  =  { img: { }  };
   }
   if ( typeof WSTM.w.img  !==  "object" ) {
      WSTM.w.img  =  { };
   }
   WSTM.w.img.vsn   =  version;
   WSTM.w.img.self  =  self;
   if ( typeof WSTM.bb  !==  "object" ) {
      WSTM.bb  =  { };
   }
   if ( typeof WSTM.debugging  !==  "object" ) {
      WSTM.debugging  =  { };
   }
} ( mw ) );



/*
Requires: JavaScript 1.3  String.charCodeAt
          JavaScript 1.5  RegExp non-capturing parenthese
 */



//-----------------------------------------------------------------------



mw.libs.WikiSyntaxTextMod.bb.bbI  =  function (WSTM) {
   // Building block and run environment support
   // 2012-05-18 PerfektesChaos@de.wikipedia
   "use strict";
   if ( typeof WSTM.util  !==  "object" ) {
      WSTM.util  =  { };
   }


   if ( typeof WSTM.util.fiatObjects  !==  "function" ) {
      WSTM.util.fiatObjects  =  function ( adult, activate, assign ) {
         // Ensure existence of at least empty object
         // Precondition:
         //    adult     -- parent object
         //    activate  -- String with name of child object
         //    assign    -- optional object with initial definition
         //                 if containing object components,
         //                 they will be asserted as well
         // Postcondition:
         //    adult has been extended
         // Uses:
         //    .util.fiatObjects()  -- recursive
         // 2012-05-18 PerfektesChaos@de.wikipedia
         var elt,
             obj,
             s;
         if ( typeof adult[ activate ]  !==  "object" ) {
            adult[ activate ]  =  ( assign  ?  assign  :  { } );
         }
         if ( assign ) {
            obj  =  adult[ activate ];
            for ( s in assign ) {
               elt  =  assign[ s ];
               if ( typeof elt  ===  "object" ) {
                  WSTM.util.fiatObjects( obj, s, elt );
               }
            }  // for s in obj
         }
      };   // .util.fiatObjects()
   }


   WSTM.util.fiatObjects(WSTM,  "debugging",  { loud: false });


};   // .bb.bbI()
mw.libs.WikiSyntaxTextMod.bb.bbI(mw.libs.WikiSyntaxTextMod);
delete mw.libs.WikiSyntaxTextMod.bb.bbI;



//-----------------------------------------------------------------------



mw.libs.WikiSyntaxTextMod.bb.img  =  function ( WSTM ) {
   // Image parameter handling
   // Uses:
   //    .util.fiatObjects()
   // 2012-10-10 PerfektesChaos@de.wikipedia
   "use strict";
   var IMG;
   WSTM.util.fiatObjects( WSTM,  "w",
                          { img:  { }  }
                        );
   IMG  =  WSTM.w.img;


   IMG.d  =  {
      "alt":             {lone:false,  type:"string",  group:"alt"},
      "baseline":        {lone:true,   type:false,     group:"v"},
      "border":          {lone:true,   type:false,     group:"border"},
      "bottom":          {lone:true,   type:false,     group:"v"},
      "center":          {lone:true,   type:false,     group:"h"},
      "class":           {lone:false,  type:"string",  group:"class"},
      "disablecontrols": {lone:false,  type:"string",  group:"mc"},
      "endtime":         {lone:false,  type:"time",    group:"me"},
      "framed":          {lone:true,   type:false,     group:"f"},
      "frameless":       {lone:true,   type:false,     group:"f"},
      "lang":            {lone:false,  type:"string",  group:"lang"},
      "left":            {lone:true,   type:false,     group:"h"},
      "link":            {lone:false,  type:"string",  group:"link"},
      "lossy":           {lone:false,  type:"string",  group:"lossy"},
      "middle":          {lone:true,   type:false,     group:"v"},
      "noicon":          {lone:true,   type:false,     group:"mi"},
      "none":            {lone:true,   type:false,     group:"h"},
      "noplayer":        {lone:true,   type:false,     group:"mp"},
      "page":            {lone:false,  type:"number",  group:"page"},
      "px":              {lone:false,  type:true,      group:"px"},
      "right":           {lone:true,   type:false,     group:"h"},
      "starttime":       {lone:false,  type:"time",    group:"ms"},
      "sub":             {lone:true,   type:false,     group:"v"},
      "super":           {lone:true,   type:false,     group:"v"},
      "text-bottom":     {lone:true,   type:false,     group:"v"},
      "text-top":        {lone:true,   type:false,     group:"v"},
      "thumbnail":       {lone:true,   type:"string",  group:"f"},
      "thumbtime":       {lone:false,  type:"time",    group:"mt"},
      "top":             {lone:true,   type:false,     group:"v"},
      "upright":         {lone:true,   type:"number",  group:"upright"}
   };   // 2019-12-14
   IMG.pattern  =  [ "page",
                     "px",
                     "upright",
                     "f",
                     "h",
                     "v",
                     "class",
                     "link",
                     "alt",
                     "mi",
                     "mp",
                     "ms",
                     "me",
                     "mt",
                     "mc",
                     "unknown",
                     "title" ];   // 2019-12-14



   IMG.factory  =  function ( apply ) {
      // Initialize media keyword translation
      // Precondition:
      //    apply  -- 0: read/write,  -1: read,  1: write
      // Uses:
      //    >  .lang.translate.read
      //    >  .str.spaces
      //    >  .lang.translate.write
      //    >  .lang.translate.d
      //    >< .w.img.d
      //     < .w.img.language
      //     < .w.img.re.*
      //     < .w.img.translate
      //    .lang.translate.feed()
      //    .lang.translate.fiat()
      // 2016-07-20 PerfektesChaos@de.wikipedia
      var e,   // element in .w.img.d
          i, k, m, n,
          q,   // element in .lang.translate.d
          s,
          t,
          v;
      if ( ! this.language ) {
         this.language  =  { };
         for ( s in this.d ) {
            this.language[ s ]  =  s;
         }  // for s in this.d
      }
      if ( apply <= 0 ) {
         t  =  "";
         for ( s in this.d ) {
            t  =  WSTM.lang.translate.feed( t,
                                            "$" + s,
                                            s,
                                            WSTM.lang.translate.read,
                                            false );
         }  // for s in this.d
         t             =  t.substr(0,  t.length - 1);
         if ( typeof this.re  !==  "object" ) {
            this.re  =  { };
         }
         this.re.beg   =  new RegExp( "^(" + t + ")\\b",  "i" );
         s             =  "[ " + WSTM.str.spaces + "]";
         t             =  WSTM.lang.translate.feed( "|",
                                                    "$px",
                                                    "px",
                                                WSTM.lang.translate.read,
                                                   true );
         t             =  "^"
                           + "([0-9]*)"                       // 1
                           + "(" + s + "*[x*×]" + s + "*"     // 2 x
                            + "([0-9]+)"                      // 3
                           + ")?"
                           + s + "*"
                           + "(" + t + ")"                    // 4
                           + "$";
         this.re.px    =  new RegExp( t, "i" );
         t             =  "^("
                           + s + "*[:_=]?" + s + "*)"  // 1 :_=
                           + "([0-9]+)?"               // 2 numeric value
                           + "([.,]"                   // 3 decimal sep
                            + "([0-9]*)"               // 4 decimals
                           + ")?$";
         this.re.vnum  =  new RegExp( t, "" );
         t             =  "^"
                           + "(" + s + "*[:_=]?" + s + "*)"   // 1 sep
                           + "(.+)$";                         // 2 value
         this.re.vstr  =  new RegExp( t, "" );
         t             =  "^"
                           + "(" + s + "*[_=]?" + s + "*)"    // 1 sep
                           + "([0-9]?[0-9]+)?"                // 2 min
                           + "(:([0-5]?[0-9]))?"              // 4 sec
                           + "(\\.([0-9]*))?$";               // 6 msec
         this.re.vtim  =  new RegExp( t, "" );
         n             =  WSTM.lang.translate.read.length;
         for ( s in this.d ) {
            e  =  this.d[ s ];
            q  =  WSTM.lang.translate.d[ "$" + s ];
            if ( q ) {
               for ( i = 0;  i < n;  i++ ) {
                  v  =  q[ WSTM.lang.translate.read[ i ] ];
                  switch ( typeof v ) {
                     case "string" :
                        if ( ! this.language[ v ] ) {
                           this.language[ v ]  =  s;
                        }
                        break;
                     case "object" :
                        m  =  v.length;
                        for ( k = 0;  k < m;  k++ ) {
                           t  =  v[k];
                           if ( t ) {
                              if ( typeof t  ===  "object" ) {
                                 t  =  WSTM.lang.translate.fiat( t );
                              }
                              if ( ! this.language[ t ] ) {
                                 this.language[ t ]  =  s;
                              }
                           }
                        }   //  for k
                        break;
                  }   // switch typeof v
               }   //  for i
            }
         }  // for s in this.d
      }
      if ( apply >= 0 ) {
         n  =  WSTM.lang.translate.write.length;
         for ( s in this.d ) {
            e        =  this.d[ s ];
            e.write  =  s;
            q        =  WSTM.lang.translate.d[ "$" + s ];
            if ( q ) {
               for ( i = 0;  i < n;  i++ ) {
                  t  =  WSTM.lang.translate.write[ i ];
                  v  =  q[ t ];
                  switch ( typeof v ) {
                     case "string" :
                        e.write  =  v;
                        i        =  n;
                        break;
                     case "object" :
                        v  =  v[ 0 ];
                        if ( v ) {
                           e.write  =  WSTM.lang.translate.fiat( v );
                        }
                        i  =  n;
                        break;
                  }   // switch typeof v
               }   // for i
            }
         }  // for s in this.d
      }
   };   // .w.img.factory()



   IMG.fault  =  function ( action, about, accumulate ) {
      // Submit error message
      // Precondition:
      //    action      -- message key string
      //                           "Contradiction",
      //                           "InvalidValue",
      //                           "MissingValue",
      //                           "Unrecognized",
      //                           "ValueConflict"
      //    about       -- string with objectionable element
      //    accumulate  -- object with transclusion parameters
      //                   >  .file$   file name
      //                   >< .error$
      // Uses:
      //    .errors.found()
      // 2012-09-20 PerfektesChaos@de.wikipedia
      if ( ! accumulate.error$ ) {
         WSTM.errors.found( "imgPar" + action,
                            false,
                            about + "\n(" + accumulate.file$ + ")" );
         accumulate.error$  =  true;
      }
   };   // .w.img.fault()



   IMG.feature  =  function ( attr, adapt, alter, apply, accumulate ) {
      // Format valid assignment
      // Precondition:
      //    attr        -- attribute name, generic
      //    adapt       -- entry for attr in definition
      //    alter       -- attribute name, local
      //    apply       -- string with value assignment;  else false
      //                   leading '=' or px
      //    accumulate  -- object with transclusion parameters
      // Postcondition:
      //    Returns string with assignment in local format
      // Uses:
      //    .w.img.disablecontrols()()
      //    .w.img.lang()
      //    .hooks.fire()
      // 2013-06-14 PerfektesChaos@de.wikipedia
      var r;
      switch ( attr ) {
         case "disablecontrols" :
         case "lang" :
            r  =  this[ attr ]( apply, accumulate );
            if ( r ) {
               r  =  adapt.write + r;
            }
            break;
         case "px" :
            r  =  apply + adapt.write;
            break;
         case "thumbnail" :
            r  =  WSTM.hooks.fire( "thumbnail", alter );
            if (! r) {
               r  =  adapt.write;
            }
            r  =  r  +  (apply ? apply : "");
            break;
         default:
            r  =  adapt.write  +  ( apply ? apply : "" );
      }  // switch attr
      return  r;
   };   // .w.img.feature()



   IMG.feed  =  function ( attr, apply, alter, attempt, accumulate ) {
      // Store transclusion parameter assignment
      // Precondition:
      //    attr        -- known attribute name, generic
      //                   false: unknown, may be title
      //    apply       -- string with value assignment;  else false
      //                   leading '=' or px
      //    alter       -- attribute name, local;  else false
      //    attempt     -- full string, if not attr
      //    accumulate  -- object with transclusion parameters
      //                   >  .title
      //                   >< .unknown
      //                    < .all$   dump entire
      // Postcondition:
      //    Returns string with formatted parameter assignment, or false
      //    Extends accumulate
      // Uses:
      //    >  .w.img.d
      //    .w.img.fault()
      //    .w.img.feature()
      // 2020-01-10 PerfektesChaos@de.wikipedia
      var r       =  attempt,
          stored,
          what;
      if ( attr ) {
         what  =  this.d[ attr ];
         if ( what.lone || apply ) {
            if ( accumulate.title || accumulate.unknown ) {
               accumulate.all$  =  true;
            }
            stored  =  accumulate[ attr ];
            if ( stored ) {
               if ( stored === apply  ||  ! apply ) {
                  r  =  false;   // remove double parameters
               } else if ( attr === "px"  &&  apply ) {
                  accumulate[ attr ]  =  apply;
               } else if ( stored === true  &&  apply ) {
                  accumulate.all$     =  true;   // already without value
                  accumulate[ attr ]  =  apply;
               } else {
                  stored  =  false;
                  this.fault( "ValueConflict", attempt, accumulate );
               }
            } else {
               accumulate[attr]  =  ( apply ? apply : true );
               stored            =  true;
            }
            if ( stored  &&  r ) {
               r  =  this.feature( attr,
                                   what,
                                   alter,
                                   apply,
                                   accumulate );
            }
         } else {
            this.fault( "MissingValue", alter, accumulate );
         }
      } else {
         if ( accumulate.unknown ) {
            this.fault( "Unrecognized", accumulate.unknown, accumulate );
         } else {   // may be title
            accumulate.unknown  =  attempt;
         }
      }
      return  r;
   };   // .w.img.feed()



   IMG.file  =  function (assert) {
      // Ensure media file format
      // Precondition:
      //    assert  -- string with presumable media file title, or null
      // Postcondition:
      //    Returns string with downcased extension, or false
      //    Error message issued, if assert invalid
      // Uses:
      //    >  .w.link.mediatypes
      //    >< .w.img.re.tit
      //     < .w.img.re.ext
      //    .errors.found()
      // 2016-07-20 PerfektesChaos@de.wikipedia
      var r  =  false,
          g, s;
      if ( typeof this.re  !==  "object" ) {
         this.re  =  { };
      }
      if ( typeof this.re.tit  !==  "object" ) {
         this.re.ext  =  new RegExp("\\.(" + WSTM.w.link.mediatypes
                                      + ")$",
                                    "i");
         this.re.tit  =  new RegExp("^[^/#|{}\n]+\\.[a-zA-Z]+[0-9]?$");
      }
      if (assert) {
         s  =  WSTM.str.trim(assert);
         g  =  this.re.tit.exec(s);
         if (g) {
            g  =  this.re.ext.exec(s);
            if (g) {
               r  =  g[1].toLowerCase();
            } else {
               WSTM.errors.found("fileTypeUnkown", false, s);
            }
         } else {
            WSTM.errors.found("fileInvalid", false, s);
         }
      }
   };   // .w.img.file()



   IMG.fix  =  function (assign, accumulate) {
      // Format single media transclusion parameter
      // Precondition:
      //    assign      -- string with trimmed attribute or assignment
      //    accumulate  -- object with transclusion parameters
      // Postcondition:
      //    Returns string with formatted parameter assignment, or false
      //    Extends accumulate
      // Uses:
      //    >  .w.img.re.beg
      //    >  .w.img.re.px
      //    .w.img.front()
      //    .w.img.px()
      //    .w.img.feed()
      // 2016-07-20 PerfektesChaos@de.wikipedia
      var g  =  this.re.beg.exec( assign ),
          r  =  assign;
      if ( g ) {
         r  =  this.front( g[ 1 ], assign, accumulate );
      } else {
         g  =  this.re.px.exec( assign );
         if ( g ) {
            r  =  this.px( g[ 4 ],  g[ 1 ],  g[ 3 ],  accumulate );
         } else {
            r  =  this.feed( false, false, false, assign, accumulate );
         }
      }
      return  r;
   };   // .w.img.fix()



   IMG.flip  =  function (assignment, accumulate) {
      // Reorder media transclusion parameters
      // Precondition:
      //    assignment  -- string with all parameters
      //    accumulate  -- object with transclusion parameters
      //                   >  .unknown
      //                   >  .all$    dump entire
      // Uses:
      //    >  .w.img.pattern
      //    >  .w.img.d
      //    >  .g.projLang
      //    >  .lang.chr.rtl
      //    >< .w.img.cross
      //    >< .w.img.horizontal
      //    .w.img.fault()
      //    .w.img.feature()
      // 2020-01-02 PerfektesChaos@de.wikipedia
      var lapsus  =  false,
          n       =  WSTM.w.img.pattern.length,
          r       =  assignment,
          show    =  "",
          i, k,
          q,
          s,
          select,
          single,
          type,
          what;
      if ( accumulate.noicon ||
           accumulate.noplayer ) {
         delete accumulate.noicon;
         delete accumulate.noplayer;
         accumulate.all$  =  true;
      }
      if ( accumulate.end ) {
         accumulate.endtime  =  accumulate.end;
         delete accumulate.end;
         accumulate.all$  =  true;
      }
      if ( accumulate.start ) {
         accumulate.starttime  =  accumulate.start;
         delete accumulate.start;
         accumulate.all$  =  true;
      }
      if ( typeof accumulate.framed  !==  "undefined"   &&
           typeof accumulate.px      !==  "undefined" ) {
         this.fault( "Contradiction", "framed ./. px", accumulate );
      }
      if ( ! this.cross ) {
         this.cross  =  new Array( n );
         for ( i = 0;  i < n;  i++ ) {
            select           =  this.pattern[ i ];
            this.cross[ i ]  =  [ ];
            for ( s in this.d ) {
               what  =  this.d[ s ];
               if ( what.group === select ) {
                  this.cross[ i ].push( s );
               }
            }  // for s in this.d
            if ( select === "h" ) {
               this.horizontal  =  this.cross[ i ];
            }
         }  // for i
      }
      if ( accumulate.thumbnail ) {
         for ( k = 0;  k < this.horizontal.length;  k++ ) {
            s  =  this.horizontal[ k ];
            if ( typeof accumulate[ s ]  !==  "undefined" ) {
               if ( single ) {
                  single  =  false;
                  break;
               } else {
                  single  =  s;
               }
            }
         }  // for k
         if ( single ) {
            s  =  ":" + WSTM.g.projLang + ":";
            if ( WSTM.lang.chr.rtl.indexOf( s )  <  0 ) {
               //   TODO   WSTM.lang.forward()    2016  _M 6.13
               if ( single === "right" ) {
                  accumulate.all$   =  true;
                  accumulate.right  =  undefined;
               }
            } else {
               if ( single === "left" ) {
                  accumulate.all$  =  true;
                  accumulate.left  =  undefined;
               }
            }
         }
      }
      for ( i = 0;  i < n;  i++ ) {
         type    =  this.cross[ i ];
         single  =  false;
         for ( k = 0;  k < type.length;  k++ ) {
            s  =  type[ k ];
            if ( typeof accumulate[ s ]  !==  "undefined" ) {
               if ( single ) {
                  lapsus  =  true;
                  this.fault( "Contradiction",
                              single + " ./. " + s,
                              accumulate );
               } else if ( ! lapsus ) {
                  if ( accumulate[ s ] === true ) {
                     q  =  false;
                  } else {
                     q  =  accumulate[ s ];
                  }
                  s  =  this.feature( s,
                                      this.d[ s ],
                                      false,
                                      q,
                                      accumulate );
                  if ( s ) {
                     if ( show ) {
                        show  =  show + "|";
                     }
                     show    =  show + s;
                     single  =  s;
                  }
               }
            }
         }  // for k
      }  // for i
      if ( ! lapsus ) {
         if ( accumulate.unknown ) {
            show  =  show + "|" + accumulate.unknown;
         }
         if ( accumulate.all$ ) {
            r  =  show;
         }
      }
      return  r;
   };   // .w.img.flip()



   IMG.format  =  function ( arglist ) {
      // Format media transclusion parameters
      // Precondition:
      //    arglist  -- Wikilink object
      //       >  .score     -- file name
      //       >  .sequence  -- string with transclusion parameters
      //       >  .last      -- pipe at end of parameter list
      // Postcondition:
      //    Returns string with transclusion parameters, or false
      // Uses:
      //    .str.trim()
      //    .w.img.file()
      //    .w.img.fix()
      //    .w.img.flip()
      // Requires: JavaScript 1.3   charCodeAt()
      // 2016-07-20 PerfektesChaos@de.wikipedia
      var current  =  { "all$":   false,
                        "error$": false,
                        "file$":  arglist.score,
                        title:    false,
                        unknown:  false },
          i        =  -99,
          r        =  "",
          show     =  arglist.sequence,
          sparse   =  WSTM.str.trim( show ),
          story    =  sparse,
          s,
          single;
      this.file( arglist.score );
      while ( story ) {
         i  =  story.indexOf( "|" );
         if (i > 0) {
            single  =  story.substr( 0, i );
            story   =  story.substr( i + 1 );
         } else if ( i ) {
            single  =  story;
            story   =  false;
         } else if ( ! i ) {
            single  =  false;
            story   =  story.substr(1);
         }
         if ( single ) {
            single  =  WSTM.str.trim( single, true, true );
         }
         if (single) {
            s  =  this.fix( single, current );
            if ( s ) {
               if ( r ) {
                  r  =  r + "|";
               }
               r  =  r + s;
            }
         }
      }  // while story
      if ( ! current.error$ ) {
         r  =  this.flip( r, current );
      }
      if ( sparse.charCodeAt( sparse.length - 1 )  ===  124
          &&    ! arglist.last ) {   // '|'
         r  =  r + "|";
      }
      if ( current.title ) {
         if ( show.charCodeAt( show.length - 1 )  ===  32 ) {   // ' '
            r  =  r + " ";
         }
      }
//    if (r === show) {
//       r  =  false;
//    }
      return  r;
   };   // .w.img.format()



   IMG.front  =  function ( attribute, assign, accumulate ) {
      // Analysis of leading parameter name
      // Precondition:
      //    attribute   -- known attribute name, local with case
      //    assign      -- string with attribute or assignment
      //    accumulate  -- object with transclusion parameters
      // Postcondition:
      //    Returns string with formatted parameter assignment
      //    Extends accumulate
      // Uses:
      //    >  .w.img.language
      //    >  .w.img.d
      //    >  .w.img.re.vnum
      //    >  .w.img.re.vstr
      //    >  .w.img.re.vtim
      //    .str.trimL()
      //    .str.parseIntNumber()
      //    .str.trim()
      //    .w.img.disablecontrols()
      //    .w.img.fault()
      //    .w.img.feed()
      // Requires: JavaScript 1.3   charCodeAt()
      // 2023-04-03 PerfektesChaos@de.wikipedia
      var r        =  assign,
          setting  =  false,
          slip     =  attribute.toLowerCase(),
          seed     =  this.language[ slip ],
          suffix   =  assign.substr( attribute.length ),
          what     =  this.d[ seed ],
          i, j, k, s,
          got;
      if ( what ) {
         switch ( what.type ) {
            case "link" :
               //TODO format protect
               break;
            case "number" :
               if ( suffix ) {
                  s    =  WSTM.str.trimL( suffix );
                  got  =  this.re.vnum.exec( s );
                  if ( got ) {
                     i  =  WSTM.str.parseIntNumber( got[ 2 ],  10 );
                     j  =  got[4];
                     if ( i || j ) {   // no sign possible in regexp
                        if (j) {
                           switch ( seed ) {
                              case "upright" :
                                 j  =  j.substr(0, 1);
                                 if ( j === "0" ) {
                                    if ( i === 0 ) {
                                       j  =  "1";
                                    } else {
                                       j  =  false;
                                    }
                                 }
                                 break;
                              default:
                                 j  =  false;
                           }   // switch
                        } else {
                           j  =  false;
                        }
                        if ( i || j ) {
                           setting  =  "=" + i;
                           if ( j ) {
                              setting  =  setting + "." + j;
                           }
                        }
                     } else if ( WSTM.str.trim( got[ 1 ] ) ) {
                        seed  =  false;
                        this.fault( "InvalidValue", assign, accumulate );
                     }
                  } else {
                     seed  =  false;
                  }
               }
               break;
            case "string" :
               suffix  =  WSTM.str.trimL( suffix );
               got     =  this.re.vstr.exec( suffix );
               if ( got ) {
                  if ( got[ 1 ] ) {
                     if ( slip === "disablecontrols" ) {
                        setting  =  this.disablecontrols( got[ 2 ] );
                        if ( ! setting ) {
                           seed  =  false;
                        }
                     } else {
                        setting  =  "=" + got[ 2 ];
                     }
                  } else if ( seed === "alt"  ||
                              seed === "link" ) {
// TODO
//Unrecognized
                     if ( got[ 0 ] === "=" ) {
                        setting  =  "=";
                     } else {
                        seed  =  false;
                     }
                  } else {
                     seed  =  false;
                  }
               } else if ( ! what.lone ) {
                  seed  =  false;
               }
               break;
            case "time" :
               suffix  =  WSTM.str.trim( suffix );
               got     =  this.re.vtim.exec( suffix );
               if ( got ) {
                  if ( ! got[3 ]) {
                     got[4]  =  got[ 2 ];
                     got[3]  =  true;
                     got[2]  =  false;
                  }
                  if ( got[ 2 ] ) {
                     i  =  got[ 2 ];
                  } else {
                     i  =  0;
                  }
                  if ( got[ 3 ] ) {
                     if ( got[ 4 ] ) {
                        j  =  parseInt( got[ 4 ], 10 );
                     } else {
                        j  =  0;
                     }
                  } else if ( i ) {
                     j  =  0;
                  }
                  if (got[6]) {
                     k  =  parseInt( got[ 6 ], 10 );
                  } else {
                     k  =  0;
                  }
                  setting  =  "=";
                  if (i) {
                     setting  =  setting + i + ":";
                  }
                  if (j || k) {
                     setting  =  setting   +   ( j < 10  ?  "0"  :  "" )
                                           +   j;
                     if (k) {
                        setting  =  setting + "." + got[ 6 ];
                     }
                  } else if (i) {
                     setting  =  setting  +  "00";
                  } else {
                     setting  =  setting  +  "0";
/*
                  } else if (WSTM.str.trim(got[1])) {
                     seed     =  false;
                     this.fault("InvalidValue", assign, accumulate);
*/
                  }
               } else {
                  seed  =  false;
               }
               break;
            default:
               if ( suffix ) {
                  seed  =  false;
               }
         }   // switch what.type
         r  =  this.feed( seed, setting, slip, assign, accumulate );
      } else {
         mw.log( WSTM.debugging,".w.img.front() what?\n" + assign,  2 );
      }
      return  r;
   };   // .w.img.front()



   IMG.disablecontrols  =  function ( assign ) {
      // Analysis of width parameter
      // Precondition:
      //    assign  -- comma-separated list of keywords
      // Postcondition:
      //    Returns string with '=' and formatted parameter assignment
      // 2013-06-10 PerfektesChaos@de.wikipedia
      var r     =  false,
          pars  =  { fullscreen: [ false, "fullscreen" ],
                     options:    [ false, "options" ],
                     timedtext:  [ false, "timedText" ]
                   },
          e;
      for ( e in pars ) {
         if ( assign.search( new RegExp( "\\b" + e + "\\b",  "i" ) )
              >= 0 ) {
            pars[e][0]  =  true;
         }
      }   // for e in pars
      for ( e in pars ) {
         if ( pars[ e ][ 0 ] ) {
            if ( r ) {
               r  =  r + ",";
            } else {
               r  =  "=";
            }
            r  =  r + pars[e][1];
         }
      }   // for e in pars
      return  r;
   };   // .w.img.disablecontrols()



   IMG.lang  =  function (assign, accumulate) {
      // Analysis of lang parameter
      // Precondition:
      //    assign      -- expecting language code (ISO 639, or wiki)
      //                   "= de-CH"
      //    accumulate  -- object with transclusion parameters
      //                   >  .file$  -- expecting SVG file name
      // Postcondition:
      //    Returns string with '=' and formatted parameter assignment
      // Uses:
      //    >< .w.img.re.svg
      //     < .w.img.re.
      //    .str.trim()
      //    .w.img.fault()
      // 2019-12-29 PerfektesChaos@de.wikipedia
      var r = false,
          got;
      if ( typeof this.re.svg  !==  "object" ) {
         this.re.svg   =  new RegExp( "\\.svg$", "i" );
         this.re.lang  =  new RegExp( "^([a-z][a-z][a-z]?)(-[a-z]+)?$",
                                      "i" );
      }
      if ( accumulate.file$.match( this.re.svg ) ) {
         if ( assign.substr(0,1) === "=" ) {
            r    =  WSTM.str.trim(assign.substr(1));
            got  =  this.re.lang.exec( r );
            if ( got ) {
               r  =  "=" + got[1].toLowerCase();
               if ( got[ 2 ] ) {
                  r  =  r + "-" + got[ 2 ];
               }
            } else {
               r  =  false;
            }
         }
      } else {
         this.fault( "LangNoSVG", accumulate.file$, accumulate );
      }
      return  r;
   };   // .w.img.lang()



   IMG.px  =  function ( attribute, ahead, after, accumulate ) {
      // Analysis of width parameter
      // Precondition:
      //    attribute   -- known attribute name, local with case
      //    ahead       -- number before x
      //    after       -- number after x; x is present
      //    accumulate  -- object with transclusion parameters
      // Postcondition:
      //    Returns string with formatted parameter assignment
      //    Extends accumulate
      // Uses:
      //    .w.img.fault()
      //    .w.img.feed()
      // Requires: JavaScript 1.3   charCodeAt()
      // 2012-09-21 PerfektesChaos@de.wikipedia
      var setting  =  "";
      if ( ahead === 0  ||  after === 0 ) {
         this.fault( "InvalidValue", "0px", accumulate );
      }
      if ( ahead ) {
         setting  =  ahead.toString();
      }
      if ( after ) {
         setting  =  setting + "x" + after;
      }
      if ( typeof accumulate.px  !==  "undefined" ) {
         if ( setting === accumulate.px ) {
            setting  =  false;
         } else {
            this.fault( "ValueConflict",
                        setting + "px ./. " + accumulate.px + "px",
                        accumulate );
            setting  =  accumulate.px + "px|" + setting;
         }
      }
      if ( setting ) {
         return  this.feed( "px", setting, attribute, true, accumulate );
      }
   };   // .w.img.px()



};   // .bb.img()
mw.libs.WikiSyntaxTextMod.bb.img(mw.libs.WikiSyntaxTextMod);
delete mw.libs.WikiSyntaxTextMod.bb.img;



//-----------------------------------------------------------------------



( function ( WSTM ) {
   "use strict";
   var sub      =  "I",
       self     =  WSTM.w.img.self,
       version  =  WSTM.w.img.vsn,
       rls;
   if ( typeof WSTM.main  !==  "object" ) {
      WSTM.main  =  { };
   }
   if ( ! WSTM.main.bb ) {
      WSTM.main.bb  =  { };
   }
   WSTM.main.bb[ sub ]  =  { load: true,
                             vsn:  version };
   if ( typeof WSTM.main.wait  ===  "function" ) {
      // Start on import: callback to waiting ...
      WSTM.main.wait( sub, version );
   }
   if ( typeof mw.loader  ===  "object"   &&
        typeof mw.hook  !==  "undefined" ) {
      rls = { };
      rls[ self ] = "ready";
      mw.loader.state( rls );
      mw.hook( "WikiSyntaxTextMod/" + sub + ".ready" )
        .fire( [ sub, version ] );
   }
} ( mw.libs.WikiSyntaxTextMod ) );



// Emacs
// Local Variables:
// coding: utf-8-dos
// fill-column: 80
// End:

/// EOF </nowiki>   WikiSyntaxTextMod/dI.js