Expose the Web API Screen properties to space script functions and to templates

It would be nice if we can access some Web API Screen properties (and perhaps other things too) from our space script custom functions and from our templates.

Use case: I have the following function to truncate strings…

silverbullet.registerFunction({name: 'truncate'}, (str, maxLength, elipsis, location) => {
  if(str.length <= maxLength) {
    return str;
  }

  let startStr;
  let endStr;
  let elipsisStr = elipsis || '…';
  let elipsisLen = elipsisStr.length;
  let partLength = Math.ceil((maxLength - elipsisLen)/2);

  switch(location) {
    case 'start':
      endStr = str.substring(str.length - maxLength + elipsisLen);
      return elipsisStr + endStr;

    case 'end':
      startStr = str.substring(0, maxLength - elipsisLen);
      return startStr + elipsisStr;

    case 'middle':
    default:
      startStr = str.substring(0, partLength);
      endStr = str.substring(str.length - partLength);
      return startStr + elipsisStr + endStr;
  }
})

(I know it’s probably a pile of bad TS code but it does what I need.)

I use the function in miscellaneous templated listings. It would be great if I could modify how the function is be called based on the screen width, for example. I would specifically like to
get the Web API Screen values exposed so that I can use them either in the function body directly or at least in the templates in the {{#if}} clauses to enforce different function calls for different environments. Would that be possible?

Once some of us use the CSS @media queries to distinquish media size to provide mobile stylesheets, we have AFAIK no way to reflect that from within the space script functions or templates yet. The requested feature would allow for that.

I would like the following Web API Screen properties to be exposed (as a starting point):

  • Screen.awailHeight, Screen.availWidth,
  • Screen.height, Screen.width and
  • Screen.orientation.

If that would be possible I will create feature request on GitHub. Thank you.