From f1998c321a4eec6d75b58d84aa8610971bf21979 Mon Sep 17 00:00:00 2001 From: Brian Picciano Date: Sat, 31 Jul 2021 11:35:39 -0600 Subject: move static files into static sub-dir, refactor nix a bit --- static/src/assets/viz/2/goog/fs/url.js | 106 +++++++++++++++++++++++++++++++++ 1 file changed, 106 insertions(+) create mode 100644 static/src/assets/viz/2/goog/fs/url.js (limited to 'static/src/assets/viz/2/goog/fs/url.js') diff --git a/static/src/assets/viz/2/goog/fs/url.js b/static/src/assets/viz/2/goog/fs/url.js new file mode 100644 index 0000000..364615e --- /dev/null +++ b/static/src/assets/viz/2/goog/fs/url.js @@ -0,0 +1,106 @@ +// Copyright 2015 The Closure Library Authors. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS-IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +/** + * @fileoverview Wrapper for URL and its createObjectUrl and revokeObjectUrl + * methods that are part of the HTML5 File API. + */ + +goog.provide('goog.fs.url'); + + +/** + * Creates a blob URL for a blob object. + * Throws an error if the browser does not support Object Urls. + * + * @param {!Blob} blob The object for which to create the URL. + * @return {string} The URL for the object. + */ +goog.fs.url.createObjectUrl = function(blob) { + return goog.fs.url.getUrlObject_().createObjectURL(blob); +}; + + +/** + * Revokes a URL created by {@link goog.fs.url.createObjectUrl}. + * Throws an error if the browser does not support Object Urls. + * + * @param {string} url The URL to revoke. + */ +goog.fs.url.revokeObjectUrl = function(url) { + goog.fs.url.getUrlObject_().revokeObjectURL(url); +}; + + +/** + * @typedef {{createObjectURL: (function(!Blob): string), + * revokeObjectURL: function(string): void}} + */ +goog.fs.url.UrlObject_; + + +/** + * Get the object that has the createObjectURL and revokeObjectURL functions for + * this browser. + * + * @return {goog.fs.url.UrlObject_} The object for this browser. + * @private + */ +goog.fs.url.getUrlObject_ = function() { + var urlObject = goog.fs.url.findUrlObject_(); + if (urlObject != null) { + return urlObject; + } else { + throw Error('This browser doesn\'t seem to support blob URLs'); + } +}; + + +/** + * Finds the object that has the createObjectURL and revokeObjectURL functions + * for this browser. + * + * @return {?goog.fs.url.UrlObject_} The object for this browser or null if the + * browser does not support Object Urls. + * @private + */ +goog.fs.url.findUrlObject_ = function() { + // This is what the spec says to do + // http://dev.w3.org/2006/webapi/FileAPI/#dfn-createObjectURL + if (goog.isDef(goog.global.URL) && + goog.isDef(goog.global.URL.createObjectURL)) { + return /** @type {goog.fs.url.UrlObject_} */ (goog.global.URL); + // This is what Chrome does (as of 10.0.648.6 dev) + } else if ( + goog.isDef(goog.global.webkitURL) && + goog.isDef(goog.global.webkitURL.createObjectURL)) { + return /** @type {goog.fs.url.UrlObject_} */ (goog.global.webkitURL); + // This is what the spec used to say to do + } else if (goog.isDef(goog.global.createObjectURL)) { + return /** @type {goog.fs.url.UrlObject_} */ (goog.global); + } else { + return null; + } +}; + + +/** + * Checks whether this browser supports Object Urls. If not, calls to + * createObjectUrl and revokeObjectUrl will result in an error. + * + * @return {boolean} True if this browser supports Object Urls. + */ +goog.fs.url.browserSupportsObjectUrls = function() { + return goog.fs.url.findUrlObject_() != null; +}; -- cgit v1.2.3