Files
Paradise/tgui/packages/common/string.babel-plugin.cjs
AffectedArc07 58aa86cb9f TGUI-V3 (#13310)
* I need that gitignore file

* Temp Commit - DOES NOT COMPILE

* THE SHIT WORKS

* Readme change

* Disposal Unit --> TGUI

* mmmm yes CI which may not actually work

* New GitIgnore

* ITS TGUI-NEXT BABY

* Doc update

* CI tweak

* Chmod

* And again

* *sigh*

* Lets appreciate the irony of me failing CI stages

* 0/1 --> True/False

* Fixes some update nonsense

* CI Update

* Lets try this

* What about this maybe

* NVM is hurting me

* I swear to god

* A little bit of validation in my life

* V3 BABYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY

* Fixes

* Fixes NaN appearing for a few frames when UIs open

* Fixes + Crew Monitor

* Corn + Steel + Mochi Fixes

* Forgot this

* Fixes from stylemistake

* Code Change

* Adds logout proc

* Offline implications + Resizeable crew monitor

* Change locate() to locateUID()

* Change div --> box
2020-06-30 03:51:36 -04:00

71 lines
1.8 KiB
JavaScript

/**
* @file
* We are using a .cjs extension because:
*
* 1. Webpack CLI only supports CommonJS modules;
* 2. tgui-dev-server supports both, but we still need to signal NodeJS
* to import it as a CommonJS module, hence .cjs extension.
*
* We need to copy-paste the whole "multiline" function because we can't
* synchronously import an ES module from a CommonJS module.
*
* This plugin saves overall about 10KB on the final bundle size, so it's
* sort of worth it.
*/
/**
* Removes excess whitespace and indentation from the string.
*/
const multiline = str => {
const lines = str.split('\n');
// Determine base indentation
let minIndent;
for (let line of lines) {
for (let indent = 0; indent < line.length; indent++) {
const char = line[indent];
if (char !== ' ') {
if (minIndent === undefined || indent < minIndent) {
minIndent = indent;
}
break;
}
}
}
if (!minIndent) {
minIndent = 0;
}
// Remove this base indentation and trim the resulting string
// from both ends.
return lines
.map(line => line.substr(minIndent).trimRight())
.join('\n')
.trim();
};
const StringPlugin = ref => {
return {
visitor: {
TaggedTemplateExpression: path => {
if (path.node.tag.name === 'multiline') {
const { quasi } = path.node;
if (quasi.expressions.length > 0) {
throw new Error('Multiline tag does not support expressions!');
}
if (quasi.quasis.length > 1) {
throw new Error('Quasis is longer than 1');
}
const { value } = quasi.quasis[0];
value.raw = multiline(value.raw);
value.cooked = multiline(value.cooked);
path.replaceWith(quasi);
}
},
},
};
};
module.exports = {
__esModule: true,
default: StringPlugin,
};