HTML2Canvas png colored offsets of divs

I’m coding a sort of UI-displayer for a game, and I want the UI to be downloaded when clicked on a button, i’m using html2canvas for that. The problem is, it shows some big offsets on the image when it gets downloaded: here is how it looks like, and here is how it should look like (without the background, it doesn’t matter).

Here is my code;

function DOWNLOAD() {
    var container = document.getElementById("DrawBox");; /* full page */
    window.scrollTo(0, 0);

    html2canvas(container, {
        allowTaint: true,
    }).then(function(canvas) {

        var link = document.createElement("a");
        document.body.appendChild(link);
        link.download = "html_image.jpg";
        link.href = canvas.toDataURL();
        console.log(container)
        link.target = '_blank';
        link.click();
    });
}

CSS drawbox code (it’s a div in my code);

.drawBox {
    position: absolute;
    box - sizing: content - box;
    width: 100 % ;
    height: 500 px;
    margin - top: 20 px;
    width: 800 px;
    box - shadow: 0 0 6 px hsl(200 deg 100 % 80 % );
    margin - left: 200 px;
    text - shadow: 0 0 7 px hsl(200 deg 100 % 80 % );
    background - color: rgb(25, 63, 83, 0.1);
    opacity: 1;
    transition: 1 s;
}

All the created divs are placed in drawBox.
Thanks in advance!

display:’block’ is not working as it supposed to be

I want the table to be visible only after the submit button clicks. But It’s not staying on the screen as it is supposed to be. Once I click the submit button, the table comes up for a second and then again becomes invisible. Please let me know what I am doing wrong in my code. Also please let me know if there is any other way to do it.

index.html

<div style="margin-left: 2rem;"> 
  <input class="btn btn-primary" type="submit" value="Submit" id="btn" onclick="hide()">        
</div>


<div style="margin-top: 4rem; display: flex; justify-content: center; align-content: center;" >  
  <table style="display: none;" id="table">
    <tbody>

      <tr>

        <th scope="row">Profile No. : </th>

        <td>{{ProfileUID}}</td>

      </tr>

      <tr>

        <th scope="row">Name : </th>

        <td>{{Name}}</td>

      </tr>
  </tbody>
</table>

</div>
 


<script>

function hide(){          

let btn=document.getElementById("btn");         

let table=document.getElementById("table");          

if (table.style.display === 'none'){            

   table.style.display='block';          

}                  

</script>

Different way of showing and hiding certain elements

I made a javascript aim train app that contains a menu. When I click play, I hide the elements of the menu and show the elements of the game… I was wondering if there was a more correct way of doing this without doing visibility hidden.

https://codepen.io/miguelserdeira/pen/oNEZRMj

This is an example of the part of the code that I want to change. Perhaps when I click play it should direct me to another page with the game? Thanks.

 //Shows the elements that should be visible or hidden
    imgTarget.style.visibility = "visible";
    startBtn.style.visibility = "hidden";
    timeText.style.visibility = "hidden";
    timeSlider.style.visibility = "hidden";
    targets.style.visibility = "hidden";
    sizeImg.style.visibility = "hidden";
    aviso.style.visibility = "visible";
    valor.style.visibility = "hidden";
    valor2.style.visibility = "hidden";
    valor3.style.visibility = "hidden";
    hits.style.visibility = "visible";

Globally change the value of any string in Angular/Typescript

I’m looking for a solution to change the value of all strings in my application similar to an internationalization/localization.

My strings follow a specific pattern like this:

let sample = "[someID]"

Then i use the string like this:

<h5>Sample:</h5>
<h5>{{sample}}</h5>

And the result should look like this:

Sample:
Result for the ID

Possible solutions might be to tag the string with some special character similar to the localization in Angular with “$localize”, but followed by a custom function to find the correct value for the given ID.

I tried to manipulate primitive string type but as far as I know there is no way to change the default getter for the string type. The only way is to extend the String Prototype by a custom function but then the usage would look like this:

<h5>Sample:</h5>
<h5>{{sample.customMethod()}}</h5>

This would result in a lot of work because I need to change all currently used string properties in this way.

Maybe there is some sort of way to change the value of the string while it’s being compiled or something. Like getting/setting a display value or applying some sort of filter globally.

Cannot read properties of undefined (reading ‘auth’) nextjs in react

I am working on a nextjs app where I am working with google authentication and after successfull authentication I am reloading the page.

but I get a blank page saying client side exception(black page).
and this error in console.

framework-5f4595e5518b5600.js:1 TypeError: Cannot read properties of undefined (reading 'auth')
    at a (main-81f4fb35f4507347.js:1:74266)
    at Object.t.formatWithValidation (main-81f4fb35f4507347.js:1:73873)
    at Object.q [as resolveHref] (main-81f4fb35f4507347.js:1:54715)
    at 664-41844e7ff48658f9.js:1:2256
    at Object.To [as useMemo] (framework-5f4595e5518b5600.js:1:64145)
    at Object.t.useMemo (framework-5f4595e5518b5600.js:1:125283)
    at 664-41844e7ff48658f9.js:1:2226
    at oo (framework-5f4595e5518b5600.js:1:59412)
    at Ao (framework-5f4595e5518b5600.js:1:67599)
    at Ku (framework-5f4595e5518b5600.js:1:113771)

The login is succesfull as i can see data in session storage.

This is my login button and successfulLogin function:

                        <GoogleLogin
                            clientId={clientId}
                            buttonText="Log in With Google"
                            // redirectUri="https://www.devdad.org/"
                            onSuccess={this.successGoogleLogin}
                            onFailure={this.failureGoogleLogin}
                            cookiePolicy={"single_host_origin"}
                            scope="profile"
                        />

This is my successGoogleLogin:

successGoogleLogin(response) {
        
        const user = {
            username: response.profileObj.name,
            socialId: response.googleId,
        };

        // Make an API call to either findOrCreate the user
        axios
            .post(`${baseURL}/auth/login`, user)
            .then((res) => {
                // Reload the page once count is 1 to reload the navbar component and display "Logout" as an option instead of "Login"
                let count = 0;

                // If the response has a valid social Id
                if (res.data.socialId === response.googleId) {
                    // Set the username and isLoggedIn in the session storage
                    sessionStorage.setItem("isLoggedIn", "true");
                    sessionStorage.setItem("username", res.data.username);
                    count++;

                    window.setTimeout(() => {
                        sessionStorage.removeItem("isLoggedIn");
                        sessionStorage.removeItem("username");
                    }, 24 * 60 * 60 * 60);

                 
                    if (count === 1) {
                        Router.reload();
                    }
                }
                // If user data returned is invalid, then redirect to the login page once again
                else {
                    window.location = "/Login";
                }
            })
            .catch((err) => console.error(err));
    }

As you can see router.reload but after reloading nextjs throws a client exception page.

Can someone help?

Add a Css Style to a Live script file in WordPress

I’m new to making custom changes in wordpress. I have a script file, which needs to change its position and design, once the user clicks on the button.

<script>

(function (w,d,s,o,f,js,fjs) {
w['ReachifyLiveChat']=o;w[o] = w[o] || function () { (w[o].q = w[o].q || []).push(arguments) };
js = d.createElement(s), fjs = d.getElementsByTagName(s)[0];
js.id = o; js.src = f; js.async = 1; fjs.parentNode.insertBefore(js, fjs);
}(window, document, 'script', 'rlc', 'https://s3-us-west-2.amazonaws.com/reachify-live-chat/main.js'));

rlc({
"id": "dcms",
"name": "The One Beauty Bar",
"primaryColor": "#6cc7ff",
"secondaryColor": "#9e86ff",
"popupDelay": 1000,
"requestDetailsDelay": 120000,
"requestDetailsOnStart": true,
"helloMessage": "Hello! How can I help you?"
});

    
</script>

Added this script file for a live chatbot from Reachify.io.
The code was added to the header of the wordpress, using ‘Insert Header and Footer’ plugin.

Once I added it, the layout is breaking of the pop-up when is opened. I’d have to add the following style lines to the script code. Is this possible?

.dnwUpt {
position: inherit; 
margin-top: 100px;
};

This is how it looks now, without the style.

https://postimg.cc/zbdDWS3T

This is how I want it to appear like –

https://postimg.cc/q6JTmt64

Please help me with the script code edit.

SyntaxError: Unexpected number – Javascript

Receving error

.1 = 999999999999;

^^

SyntaxError: Unexpected number

let content019 = JSON.parse(require("fs").readFileSync("./settings.json"));
// edit or add property
content019.api.client.locations.1 = 999999999999;
//write file
fs.writeFileSync('settings.json', JSON.stringify(content019,null ,2));

I tried inserting the number in a box [] and {}

Received error:
SyntaxError: Unexpected token ‘[‘

make the error send in channel instead of the console so the program wont stop running

I am currently having a problem about my signup command and when searched about the error I am having which is:
MongoServerError: E11000 duplicate key error collection: ShinDB.users index: username_1 dup key: { username: "Shin" }

they always say to drop the collection which I don’t want.

what i want is for example i wrote '>signup Shin thisisatest@1234' and if the 'Shin' username is already in the username database it will NOT send the 'MongoServerError' in the console but instead it will send an error 'That username already exist' in the channel which the user send it to.

Signup Command:

var strongRegex = new RegExp("^(?=.{14,})(?=.*[A-Z])(?=.*[a-z])(?=.*[0-9])(?=.*\W).*$", "g");
var mediumRegex = new RegExp("^(?=.{10,})(((?=.*[A-Z])(?=.*[a-z]))|((?=.*[A-Z])(?=.*[0-9]))|((?=.*[a-z])(?=.*[0-9]))).*$", "g");
var enoughRegex = new RegExp("(?=.{8,}).*", "g");
var specialChar = /[`!@#$%^&*()_+-=[]{};':"\|,.<>/?~]/;
const User = require('../../Database/models/user')

module.exports = {
    name: "signup",
    description: "Signup for an Economy Account",
    usage: ">signup",
    aliases: [],
    run: async (client, message, args) => {
        //message is inguild
        if (message.inGuild()) {
            return message.reply({ content: `This command can only be used in <@${client.user.id}> DM.n``Usage: >signup <username> <password>``n``Note: Your Economy Account is Safe``` })
        }

        //message is in DM
        if (message.channel.type === 'DM') {
            
            // USERNAME
            const userargs = args[0]
            const pass = args[1]

            if (!userargs) {
                return message.reply({ content: '**Please provide a username for your Economy Account!n``Correct Usage: >signup <username> <password>``**' })
            }

            const userToLow = userargs.toLowerCase()
            const user = userToLow.charAt(0).toUpperCase() + userToLow.substring(1, userToLow.length)
            
            if (user.length < 3) return message.reply({ content: '**[__Too Short__]** **Your Username must have atleast 3 Characters**' })
            if (user.length > 7) return message.reply({ content: '**[__Too Long__]** **You Username must only have 7 Characters**' })
            if (specialChar.test(user)) {
                return message.reply({ content: '**Username's must not have any Special Characters**' })
            }

            // PASSWORD
            let str
            let med
            let weak
            if (strongRegex.test(pass)) {
                str = 'Strong'
            }
            if (mediumRegex.test(pass)) {
                med = 'Medium'
            }
            if (!strongRegex.test(pass) && !mediumRegex.test(pass)) {
                weak = 'Weak'
            }

            if (!pass) return message.reply({ content: '**Please provide a password for your Economy Account!**' })
            if (pass.length < 8) return message.reply({ content: '**[__Too Short__]** **Your Password must have atleast 8 Characters**' })

            // CREATING THE ACCOUNT
            User.findOne({ createdBy: message.author.id }, async (err, data) => {
                if (data) {
                    return message.reply({ content: `**You already have made an Account and the Username of the Account that you made is: ``${data.username}``n``Note: if you forget your password you can just run the command >recoveraccount``**` })
                } else if (err) {
                    return message.reply({ content: 'That username already exist' })
                } else {
                    new User({
                        loggedInOn: "0",
                        createdBy: message.author.id,
                        isLoggedIn: false,
                        username: user,
                        password: pass,
                    }).save()
                    return message.reply({ content: 'You have successfuly made an Economy Account!'})
                }

            })

        }
    }
}

User Schema/Model:

const mongoose = require('mongoose')

const userSchema = new mongoose.Schema({
    loggedInOn: String,
    createdBy: String,
    isLoggedIn: Boolean,
    username: {
        type: String,
        unique: true
    },
    password: String
})

module.exports = mongoose.model('Users', userSchema)

Full Error:

                return callback(new error_1.MongoServerError(res.writeErrors[0]));
                                ^

MongoServerError: E11000 duplicate key error collection: ShinDB.users index: username_1 dup key: { username: "Shin" }
    at C:UsersLenovoDesktopShinomynode_modulesmongoosenode_modulesmongodbliboperationsinsert.js:53:33
    at C:UsersLenovoDesktopShinomynode_modulesmongoosenode_modulesmongodblibcmapconnection_pool.js:273:25
    at handleOperationResult (C:UsersLenovoDesktopShinomynode_modulesmongoosenode_modulesmongodblibsdamserver.js:327:20)
    at Connection.onMessage (C:UsersLenovoDesktopShinomynode_modulesmongoosenode_modulesmongodblibcmapconnection.js:215:9)
    at MessageStream.<anonymous> (C:UsersLenovoDesktopShinomynode_modulesmongoosenode_modulesmongodblibcmapconnection.js:63:60)
    at MessageStream.emit (node:events:527:28)
    at processIncomingData (C:UsersLenovoDesktopShinomynode_modulesmongoosenode_modulesmongodblibcmapmessage_stream.js:108:16)
    at MessageStream._write (C:UsersLenovoDesktopShinomynode_modulesmongoosenode_modulesmongodblibcmapmessage_stream.js:28:9)
    at writeOrBuffer (node:internal/streams/writable:389:12)
    at _write (node:internal/streams/writable:330:10) {
  index: 0,
  code: 11000,
  keyPattern: { username: 1 },
  keyValue: { username: 'Shin' },
  [Symbol(errorLabels)]: Set(0) {}
}

My Database Current Collections:

Collections Picture

i hope i have explained it very well, any help would be really appreciated. thanks.

issue with using svgr/webpack in next.js app

Trying to add SVGR into the next.js project.

The issue with a building project, getting error:

 Module not found: Can't resolve '@svgr/webpack'

Setps:

  1. Installed svgr as devDependecies

  2. Add svgr into next.config.js

webpack: (config) => {
    config.module.rules.push({
    test: /.svg$/i,
    issuer: /.[jt]sx?$/,
    use: ['@svgr/webpack'],
});
  1. Import svg file as Component

  2. Build the project and error happens

Has anyone had a similar problem?

enter image description here

jest-dom toBeExpected throws: TypeError: element.getRootNode is not a function

We recently updated some of our project dependencies and one of them was jest-dom, we went from v5.11.0 to v5.16.4, now as of version v5.11.10 they introduced a new condition to the toBeVisible method so that the element had to be in the document, as part of this check its implementation calls element.getRootNode.

Since this change our tests which use toBeVisible now fail with the following message: TypeError: element.getRootNode is not a function.

I suspect the using node as the jest testEnvironment is the issue and that for whatever reason the node implementation doesn’t have getRootNode and it probably should.

Is there a way round this without changing the testEnvironment to jsdom since that causes loads of tests to break?

How to display ant design flow chart? Can you help me?

I’m working with ant design chart, specifically is flow chart of it. I use the basic code on this: “https://charts.ant.design/en/examples/flowchart/basic#basic”. But I have a problem is I can not render the flow chart as the example. Do you know how to display it? Can you help me with this. Thank you very much!

I am trying to persist Page onMouseEnter in Menu in react,

I am working on a Menu Project, and I want the sub-menu component to display when i hover on a menu item, and it should persist when the mouse enters the submenu component page.

const [subVisibility, setSubVisibility] = useState(false)
return (
    <Grid
      container
      spacing={1}
      sx={{ position: 'absolute', top: 0, zIndex: 10 }}
    >
        <Grid item xs={2} sm={2} md={3} lg={3}>
          <>
            <Paper>
              <MenuList sx={{ overflow: 'auto', maxHeight: '70vh' }}>
                <Box
                  sx={{
                    background: '#E9F2E4',
                    display: 'flex',
                    padding: 2,
                    alignItems: 'center',
                    cursor: 'pointer',
                  }}
                  onClick={() => window.open('/all-categories', '_blank')}
                >
                  <MenuIcon sx={{ color: '#7AB259' }} />
                  <Typography
                    variant='h6'
                    sx={{
                      display: 'flex',
                      alignItems: 'center',
                      justifyContent: 'space-between',
                      color: '#7AB259',
                      pl: 2,
                    }}
                  >
                    ALL CATEGORIES
                  </Typography>
                </Box>
                <Divider />
                {categories &&
                  categories.map((category) => (
                    <>
                      <MenuItem
                        key={category._id}
                        sx={{ pl: 5 }}
                        onMouseEnter={() => setSubVisibility(true)}
                        onMouseLeave={() => setSubVisibility(false)}
                      >
                        <Typography variant='subtitle2'>
                          {category.name}
                        </Typography>
                      </MenuItem>
                      <Divider />
                    </>
                  ))}
              </MenuList>
            </Paper>
          </>
        </Grid>
    </Grid>
  )
}  

I am using onMouseEnter and onMouseLeave. The problem is that i am unable to move my cursor into the submenu because the submenu disappears.

This is the submenu that should display when I hover on a menu item

{subVisibility && (
            <Grid item xs={12} md={9} lg={9}>
              <div style={{ background: '#fff', height: '50vh', padding: 20 }}>
                <Typography
                  variant='h6'
                  sx={{ borderBottom: '1px solid #fff', py: 2 }}
                >
                  Fruits
                </Typography>
                <Grid container rowSpacing={2}>
                  <Grid item xs={3}>
                    <Typography variant='body2'>Mangoes</Typography>
                  </Grid>
                  <Grid item xs={3}>
                    <Typography variant='body2'>Oranges</Typography>
                  </Grid>
                  <Grid item xs={3}>
                    <Typography variant='body2'>Water Melon</Typography>
                  </Grid>
                  <Grid item xs={3}>
                    <Typography variant='body2'>Paw Paw</Typography>
                  </Grid>
                  <Grid item xs={3}>
                    <Typography variant='body2'>Guava</Typography>
                  </Grid>
                  <Grid item xs={3}>
                    <Typography variant='body2'>Bananas</Typography>
                  </Grid>
                  <Grid item xs={3}>
                    <Typography variant='body2'>Cherry</Typography>
                  </Grid>
                </Grid>
              </div>
            </Grid>
          )}

Why is there an error on importing cross dependencies in an angular library?

I am looking for some help for my angular 13 library cross dependency import.

I have library api and library shared. I want to import some models from api-library into the shared library.

Now i am having the following problem. If i want to import these models into the shared library i am getting the following error: Cannot find module '@api-library' or its corresponding type declarations.. But if am building the shared library with the model imports i am getting no error and the build succeed.

public-api.ts from the api library (i am exporting everything in the whole library):

export * from './lib/api/api';
export * from './lib/api.module';
export * from './lib/model/models';

shared library tsconfig.lib.ts:

{
  "extends": "../../tsconfig.json",
  "compilerOptions": {
    "outDir": "../../out-tsc/lib",
    "declaration": true,
    "declarationMap": true,
    "inlineSources": true,
    "types": [],

    "experimentalDecorators": true,
    "emitDecoratorMetadata": true,
    "forceConsistentCasingInFileNames": true,

    "baseUrl": "./",
    "paths": {
      "@api-library": [
        "../../projects/api/src/public-api.ts",
      ],
      "@api-library/*": [
        "../../projects/api/src/lib/*",
      ]
    }
  },
  "exclude": [
    "src/test.ts",
    "**/*.spec.ts"
  ],
}

shared library tsconfig.build.ts:

{
  "extends": "./tsconfig.lib.json",
  "compilerOptions": {
    "declarationMap": false,
    "paths": {
      "@api-library": ["../../dist/api"],
      "@shared": ["../../dist/shared"],
      "@store": ["../../dist/store"]
    }
  },
  "angularCompilerOptions": {
    "compilationMode": "partial"
  }
}