MyScript / iinkTS

Other
52 stars 5 forks source link

editor.penStyle, ink color not work #7

Open sparrow84001 opened 1 week ago

sparrow84001 commented 1 week ago

Custom ink color not work.

function initializeEditor(q_no) { //console.log(q_no); for (let i = 1; i <= q_no; i++) { //console.log(i); const editorElement = document.getElementById(editor${i}); const resultElement = document.getElementById(user_answer${i}); const clearElement = document.getElementById(clear${i}`); //console.log(resultElement);

        // Initialize the iink editor
        const editor = new iink.Editor(editorElement, {
            configuration: {
                server: {
                    applicationKey: '388f9453-c3f1-441d-b20f-c8c9e6d1ee6a', // Ensure this is correct
                    hmacKey: 'a1f6b920-238b-40fe-9ae4-1bd9d069014c',
                    protocol: "WEBSOCKET"
                },
                recognition: {
                    type: "MATH",
                    math: {
                        mimeTypes: ["application/x-latex"]
                    }
                }

            }

        });

        // editor.penStyle = {
        //     "color": "black"
        // };
        editor.initialize();
        //editor.penStyle = {"color":"red"};

        editorElement.addEventListener("mousemove", () => {
            //console.log(Math.random());
            //console.log(editor);
            editor.penStyle = {"color":"#ff7314","-myscript-pen-width":"2"};
        });

        editor.events.addEventListener("exported", (evt) => {
            const exports = evt.detail;
            if (exports && exports["application/x-latex"]) {
                // convertElement.disabled = false;
                try {
                    katex.render(cleanLatex(exports["application/x-latex"]), resultElement
                        .value);
                    //resultElement.value = cleanLatex(exports['application/x-latex']);
                } catch (error) {
                    resultElement.innerHTML = '<span>' + cleanLatex(exports[
                            'application/x-latex']) +
                        '</span>';
                }
                //console.log(resultElement.value);
            }
        });

        function cleanLatex(latexExport) {
            //console.log('latexExport: ', latexExport);
            if (typeof latexExport === "number") {
                latexExport = latexExport.toString();
            }
            if (latexExport.includes("\\\\")) {
                const steps = "\\begin{align*}" + latexExport + "\\end{align*}";
                return steps.replace("\\begin{aligned}", "").replace("\\end{aligned}", "").replace(
                    new RegExp(
                        "(align.{1})",
                        "g"), "aligned");
            }
            return latexExport.replace(new RegExp("(align.{1})", "g"), "aligned");
        }

        clearElement.addEventListener('click', () => {
            editorElement.editor.clear();
            $("#user_answer" + i).val("");
        });

    }
}`
leJsboureau commented 4 days ago

Hi, Can you explain your problem in more detail? and possibly share your code with us in a file (removing your keys) Thank you we will follow this ticket