<commit_before>/**
* Copyright 2012-2020, Plotly, Inc.
* All rights reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/


'use strict';

var isNumeric = require('fast-isnumeric');

var glPlot3d = require('gl-plot3d');
var createCamera = glPlot3d.createCamera;
var createPlot = glPlot3d.createScene;

var getContext = require('webgl-context');
var passiveSupported = require('has-passive-events');

var Registry = require('../../registry');
var Lib = require('../../lib');

var Axes = require('../../plots/cartesian/axes');
var Fx = require('../../components/fx');

var str2RGBAarray = require('../../lib/str2rgbarray');
var showNoWebGlMsg = require('../../lib/show_no_webgl_msg');

var project = require('./project');
var createAxesOptions = require('./layout/convert');
var createSpikeOptions = require('./layout/spikes');
var computeTickMarks = require('./layout/tick_marks');

var isMobileOrTablet = require('is-mobile')({ tablet: true, featureDetect: true });
var preserveDrawingBuffer = handleSafari14(isMobileOrTablet);

function handleSafari14(hasDrawingBuffer) {
    if(!hasDrawingBuffer) {
        var ua = getUserAgent();
        if(typeof ua !== 'string') return false;

        var allParts = ua.split('/');
        for(var i = 0; i < allParts.length; i++) {
            var part = allParts[i];
            if(part.indexOf('Safari') !== -1) {
                // find Safari version
                var v = part.split('.')[0];
                if(isNumeric(v)) v = +v;

                // to fix https://github.com/plotly/plotly.js/issues/5158
                if(v >= 14) return true;
            }
        }
    }

    return hasDrawingBuffer;
}

function getUserAgent() {
    // similar to https://github.com/juliangruber/is-mobile/blob/91ca39ccdd4cfc5edfb5391e2515b923a730fbea/index.js#L14-L17
    var ua;
    if(typeof navigator !== 'undefined') {
        ua = navigator.userAgent;
    }

    if(
        ua &&
        ua.headers &&
        typeof ua.headers['user-agent'] === 'string'<commit_msg>pass userAgent to the is-mobile<commit_after>/**
* Copyright 2012-2020, Plotly, Inc.
* All rights reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/


'use strict';

var isNumeric = require('fast-isnumeric');

var glPlot3d = require('gl-plot3d');
var createCamera = glPlot3d.createCamera;
var createPlot = glPlot3d.createScene;

var getContext = require('webgl-context');
var passiveSupported = require('has-passive-events');

var Registry = require('../../registry');
var Lib = require('../../lib');

var Axes = require('../../plots/cartesian/axes');
var Fx = require('../../components/fx');

var str2RGBAarray = require('../../lib/str2rgbarray');
var showNoWebGlMsg = require('../../lib/show_no_webgl_msg');

var project = require('./project');
var createAxesOptions = require('./layout/convert');
var createSpikeOptions = require('./layout/spikes');
var computeTickMarks = require('./layout/tick_marks');

var isMobileOrTablet = require('is-mobile');
var preserveDrawingBuffer = getPreserveDrawingBuffer();

function getPreserveDrawingBuffer() {
    var ua = getUserAgent();
    if(typeof ua !== 'string') return false;

    var hasDrawingBuffer = isMobileOrTablet({
        ua: ua,
        tablet: true,
        featureDetect: true
    });

    if(!hasDrawingBuffer) {
        var allParts = ua.split('/');
        for(var i = 0; i < allParts.length; i++) {
            var part = allParts[i];
            if(part.indexOf('Safari') !== -1) {
                // find Safari version
                var v = part.split('.')[0];
                if(isNumeric(v)) v = +v;

                // to fix https://github.com/plotly/plotly.js/issues/5158
                if(v >= 14) return true;
            }
        }
    }

    return hasDrawingBuffer;
}

function getUserAgent() {
    // similar to https://github.com/juliangruber/is-mobile/blob/91ca39ccdd4cfc5edfb5391e2515b923a730fbea/index.js#L14-L17
    var ua;
    if(typeof navigator !== 'undefined') {
        ua = navigator.userAgent;
    }

    if(
        ua &&
        ua.headers &&
        typeof ua.headers['user-agent'] === 'string'
{'fraction_non_alphanumeric': 0.15458372310570626, 'fraction_numerical': 0.022918615528531337, 'mean_word_length': 2.815343443354148, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 4, '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': '6852383', 'n_tokens_mistral': 1415, 'n_tokens_neox': 1318, 'n_words': 310}