<commit_before>package jsqrcode

class JsqrcodeTagLib {
    //static defaultEncodeAs = 'html'
    //static encodeAsForTags = [tagName: 'raw']
    
    static namespace = 'jsqr'
    
    def scanCanvas = {attrs ->
        out << createScanCanvas()
    }
    
    def scanButton = {attrs ->
        def fieldId = attrs['fieldId']
        out << createScanButton(fieldId)
    }
    
    def createScanCanvas() {
        StringBuilder sb = new StringBuilder()
        sb << """
<video id="jsqr_source" hidden autoplay/>

<script>
var localMediaStream = null;

function captureToCanvas() {
    document.getElementById("jsqr_source").hidden = false;
}

function startScan(fieldId) {
    navigator.getUserMedia  = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.msGetUserMedia;
    if (navigator.getUserMedia) {
        navigator.getUserMedia({video: true}, function(stream) {
            document.getElementById("jsqr_source").src = window.URL.createObjectURL(stream);
            captureToCanvas();
            localMediaStream = stream;
        }, function(e) {console.log('Reeeejected!', e);});
    }

    document.getElementById(fieldId).value='Hello World!';
}
</script>
"""
        sb.toString()
    }<commit_msg>Takes snapshot images every 500ms<commit_after>package jsqrcode

class JsqrcodeTagLib {
    //static defaultEncodeAs = 'html'
    //static encodeAsForTags = [tagName: 'raw']
    
    static namespace = 'jsqr'
    
    def scanCanvas = {attrs ->
        out << createScanCanvas()
    }
    
    def scanButton = {attrs ->
        def fieldId = attrs['fieldId']
        out << createScanButton(fieldId)
    }
    
    def createScanCanvas() {
        StringBuilder sb = new StringBuilder()
        sb << """
<video id="jsqr_source" hidden autoplay></video>
<canvas id="qr-canvas" width="640" height="480" hidden></canvas>
<img id="jsqr_display" src="" width="320" height="240" hidden>

<script>
var localMediaStream = null;
var video = document.getElementById("jsqr_source");
var canvas = document.getElementById("qr-canvas");
var display = document.getElementById("jsqr_display");
var canvasContext = canvas.getContext('2d');

function showDisplay() {
    display.hidden = false;
}

function hideDisplay() {
    display.hidden = true;
}

function captureToCanvas() {
    if(localMediaStream) {
        canvasContext.drawImage(video, 0, 0);
        display.src = canvas.toDataURL('image/webp');
        setTimeout(captureToCanvas, 500);
    }
}

function startScan(fieldId) {
    navigator.getUserMedia  = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.msGetUserMedia;
    if (navigator.getUserMedia) {
        navigator.getUserMedia({video: true}, function(stream) {
            document.getElementById("jsqr_source").src = window.URL.createObjectURL(stream);
            localMediaStream = stream;
            showDisplay();
            captureToCanvas();
        }, function(e) {console.log('Reeeejected!', e);});
    }

    document.getElementById(fieldId).value='Hello World!';
}
</script>
"""
        sb.toString()
    }
{'fraction_non_alphanumeric': 0.13073979591836735, 'fraction_numerical': 0.006696428571428571, 'mean_word_length': 3.2506775067750677, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4662349', 'n_tokens_mistral': 951, 'n_tokens_neox': 921, 'n_words': 182}