{"version":3,"file":"frappe-web.min.js","sources":["../../../apps/frappe/frappe/public/js/frappe/class.js","../../../apps/frappe/frappe/public/js/frappe/format.js","../../../apps/frappe/frappe/public/js/frappe/utils/number_format.js","../../../apps/frappe/frappe/public/js/frappe/polyfill.js","../../../apps/frappe/frappe/public/js/lib/md5.min.js","../../../apps/frappe/frappe/public/js/frappe/provide.js","../../../apps/frappe/frappe/public/js/frappe/utils/datatype.js","../../../apps/frappe/node_modules/fast-deep-equal/index.js","../../../apps/frappe/frappe/public/js/frappe/utils/pretty_date.js","../../../apps/frappe/frappe/public/js/frappe/query_string.js","../../../apps/frappe/frappe/public/js/frappe/utils/utils.js","../../../apps/frappe/frappe/public/js/frappe/utils/common.js","../../../apps/frappe/frappe/public/js/frappe/form/layout.js","../../../apps/frappe/frappe/public/js/frappe/ui/field_group.js","../../../apps/frappe/frappe/public/js/frappe/dom.js","../../../apps/frappe/frappe/public/js/frappe/ui/dialog.js","../../../apps/frappe/frappe/public/js/frappe/ui/messages.js","../../../apps/frappe/frappe/public/js/frappe/translate.js","../../../apps/frappe/frappe/public/js/frappe/microtemplate.js","../../../apps/frappe/frappe/public/js/frappe/ui/dropzone.js","../../../apps/frappe/frappe/public/js/frappe/file_uploader/FilePreview.vue?rollup-plugin-vue=script.js","../../../apps/frappe/frappe/public/js/frappe/file_uploader/TreeNode.vue?rollup-plugin-vue=script.js","../../../apps/frappe/frappe/public/js/frappe/file_uploader/FileBrowser.vue?rollup-plugin-vue=script.js","../../../apps/frappe/frappe/public/js/frappe/file_uploader/WebLink.vue?rollup-plugin-vue=script.js","../../../apps/frappe/frappe/public/js/frappe/file_uploader/FileUploader.vue?rollup-plugin-vue=script.js","../../../apps/frappe/frappe/public/js/frappe/file_uploader/index.js","../../../apps/frappe/node_modules/highlight.js/lib/core.js","../../../apps/frappe/frappe/public/js/frappe/upload.js","../../../apps/frappe/frappe/public/js/frappe/model/meta.js","../../../apps/frappe/frappe/public/js/frappe/model/model.js","../../../apps/frappe/frappe/public/js/frappe/model/perm.js","../../../apps/frappe/node_modules/highlight.js/lib/languages/javascript.js","../../../apps/frappe/node_modules/highlight.js/lib/languages/python.js","../../../apps/frappe/node_modules/highlight.js/lib/languages/xml.js","../../../apps/frappe/node_modules/highlight.js/lib/languages/django.js","../../../apps/frappe/node_modules/highlight.js/lib/languages/bash.js","../../../apps/frappe/node_modules/highlight.js/lib/languages/css.js","../../../apps/frappe/node_modules/highlight.js/lib/languages/markdown.js","../../../apps/frappe/node_modules/highlight.js/lib/languages/diff.js","../../../apps/frappe/node_modules/highlight.js/lib/languages/json.js","../../../apps/frappe/node_modules/highlight.js/lib/languages/less.js","../../../apps/frappe/node_modules/highlight.js/lib/languages/nginx.js","../../../apps/frappe/node_modules/highlight.js/lib/languages/scss.js","../../../apps/frappe/node_modules/highlight.js/lib/languages/shell.js","../../../apps/frappe/node_modules/highlight.js/lib/languages/sql.js","../../../apps/frappe/frappe/website/js/syntax_highlight.js","../../../apps/frappe/frappe/website/js/website.js","../../../apps/frappe/frappe/public/js/frappe/socketio_client.js"],"sourcesContent":["// Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors\n// MIT License. See license.txt\n\n/*\n\nInheritence \"Class\"\n-------------------\nsee: http://ejohn.org/blog/simple-javascript-inheritance/\nTo subclass, use:\n\n\tvar MyClass = Class.extend({\n\t\tinit: function\n\t})\n\n*/\n// https://stackoverflow.com/a/15052240/5353542\n\n/* Simple JavaScript Inheritance for ES 5.1\n * based on http://ejohn.org/blog/simple-javascript-inheritance/\n * (inspired by base2 and Prototype)\n * MIT Licensed.\n */\n(function(global) {\n\t\"use strict\";\n\tvar fnTest = /xyz/.test(function(){xyz;}) ? /\\b_super\\b/ : /.*/;\n\n\t// The base Class implementation (does nothing)\n\tfunction Class(){}\n\n\t// Create a new Class that inherits from this class\n\tClass.extend = function(props) {\n\t var _super = this.prototype;\n\n\t // Set up the prototype to inherit from the base class\n\t // (but without running the init constructor)\n\t var proto = Object.create(_super);\n\n\t // Copy the properties over onto the new prototype\n\t for (var name in props) {\n\t\t// Check if we're overwriting an existing function\n\t\tproto[name] = typeof props[name] === \"function\" &&\n\t\t typeof _super[name] == \"function\" && fnTest.test(props[name])\n\t\t ? (function(name, fn){\n\t\t\t return function() {\n\t\t\t\tvar tmp = this._super;\n\n\t\t\t\t// Add a new ._super() method that is the same method\n\t\t\t\t// but on the super-class\n\t\t\t\tthis._super = _super[name];\n\n\t\t\t\t// The method only need to be bound temporarily, so we\n\t\t\t\t// remove it when we're done executing\n\t\t\t\tvar ret = fn.apply(this, arguments);\n\t\t\t\tthis._super = tmp;\n\n\t\t\t\treturn ret;\n\t\t\t };\n\t\t\t})(name, props[name])\n\t\t : props[name];\n\t }\n\n\t // The new constructor\n\t var newClass = typeof proto.init === \"function\"\n\t\t? proto.hasOwnProperty(\"init\")\n\t\t ? proto.init // All construction is actually done in the init method\n\t\t : function SubClass(){ _super.init.apply(this, arguments); }\n\t\t: function EmptyClass(){};\n\n\t // Populate our constructed prototype object\n\t newClass.prototype = proto;\n\n\t // Enforce the constructor to be what we expect\n\t proto.constructor = newClass;\n\n\t // And make this class extendable\n\t newClass.extend = Class.extend;\n\n\t return newClass;\n\t};\n\n\t// export\n\tglobal.Class = Class;\n })(this);","function format (str, args) {\n\tif(str==undefined) return str;\n\n\tthis.unkeyed_index = 0;\n\treturn str.replace(/\\{(\\w*)\\}/g, function(match, key) {\n\n\t\tif (key === '') {\n\t\t\tkey = this.unkeyed_index;\n\t\t\tthis.unkeyed_index++\n\t\t}\n\t\tif (key == +key) {\n\t\t\treturn args[key] !== undefined\n\t\t\t\t? args[key]\n\t\t\t\t: match;\n\t\t}\n\t}.bind(this));\n}\n\nif (jQuery) {\n\tjQuery.format = format\n}\n","// Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors\n// MIT License. See license.txt\n\nimport './datatype';\n\nif (!window.frappe) window.frappe = {};\n\nfunction flt(v, decimals, number_format) {\n\tif (v == null || v == '') return 0;\n\n\tif (typeof v !== \"number\") {\n\t\tv = v + \"\";\n\n\t\t// strip currency symbol if exists\n\t\tif (v.indexOf(\" \") != -1) {\n\t\t\t// using slice(1).join(\" \") because space could also be a group separator\n\t\t\tvar parts = v.split(\" \");\n\t\t\tv = isNaN(parseFloat(parts[0])) ? parts.slice(parts.length - 1).join(\" \") : v;\n\t\t}\n\n\t\tv = strip_number_groups(v, number_format);\n\n\t\tv = parseFloat(v);\n\t\tif (isNaN(v))\n\t\t\tv = 0;\n\t}\n\n\tif (decimals != null)\n\t\treturn _round(v, decimals);\n\treturn v;\n}\n\nfunction strip_number_groups(v, number_format) {\n\tif (!number_format) number_format = get_number_format();\n\tvar info = get_number_format_info(number_format);\n\n\t// strip groups (,)\n\tvar group_regex = new RegExp(info.group_sep === \".\" ? \"\\\\.\" : info.group_sep, \"g\");\n\tv = v.replace(group_regex, \"\");\n\n\t// replace decimal separator with (.)\n\tif (info.decimal_str !== \".\" && info.decimal_str !== \"\") {\n\t\tvar decimal_regex = new RegExp(info.decimal_str, \"g\");\n\t\tv = v.replace(decimal_regex, \".\");\n\t}\n\n\treturn v;\n}\n\n\nfrappe.number_format_info = {\n\t\"#,###.##\": { decimal_str: \".\", group_sep: \",\" },\n\t\"#.###,##\": { decimal_str: \",\", group_sep: \".\" },\n\t\"# ###.##\": { decimal_str: \".\", group_sep: \" \" },\n\t\"# ###,##\": { decimal_str: \",\", group_sep: \" \" },\n\t\"#'###.##\": { decimal_str: \".\", group_sep: \"'\" },\n\t\"#, ###.##\": { decimal_str: \".\", group_sep: \", \" },\n\t\"#,##,###.##\": { decimal_str: \".\", group_sep: \",\" },\n\t\"#,###.###\": { decimal_str: \".\", group_sep: \",\" },\n\t\"#.###\": { decimal_str: \"\", group_sep: \".\" },\n\t\"#,###\": { decimal_str: \"\", group_sep: \",\" },\n}\n\nwindow.format_number = function (v, format, decimals) {\n\tif (!format) {\n\t\tformat = get_number_format();\n\t\tif (decimals == null) decimals = cint(frappe.defaults.get_default(\"float_precision\")) || 3;\n\t}\n\n\tvar info = get_number_format_info(format);\n\n\t// Fix the decimal first, toFixed will auto fill trailing zero.\n\tif (decimals == null) decimals = info.precision;\n\n\tv = flt(v, decimals, format);\n\n\tlet is_negative = false;\n\tif (v < 0) is_negative = true;\n\tv = Math.abs(v);\n\n\tv = v.toFixed(decimals);\n\n\tvar part = v.split('.');\n\n\t// get group position and parts\n\tvar group_position = info.group_sep ? 3 : 0;\n\n\tif (group_position) {\n\t\tvar integer = part[0];\n\t\tvar str = '';\n\t\tvar offset = integer.length % group_position;\n\t\tfor (var i = integer.length; i >= 0; i--) {\n\t\t\tvar l = replace_all(str, info.group_sep, \"\").length;\n\t\t\tif (format == \"#,##,###.##\" && str.indexOf(\",\") != -1) { // INR\n\t\t\t\tgroup_position = 2;\n\t\t\t\tl += 1;\n\t\t\t}\n\n\t\t\tstr += integer.charAt(i);\n\n\t\t\tif (l && !((l + 1) % group_position) && i != 0) {\n\t\t\t\tstr += info.group_sep;\n\t\t\t}\n\t\t}\n\t\tpart[0] = str.split(\"\").reverse().join(\"\");\n\t}\n\tif (part[0] + \"\" == \"\") {\n\t\tpart[0] = \"0\";\n\t}\n\n\t// join decimal\n\tpart[1] = (part[1] && info.decimal_str) ? (info.decimal_str + part[1]) : \"\";\n\n\t// join\n\treturn (is_negative ? \"-\" : \"\") + part[0] + part[1];\n};\n\nfunction format_currency(v, currency, decimals) {\n\tvar format = get_number_format(currency);\n\tvar symbol = get_currency_symbol(currency);\n\tif(decimals === undefined) {\n\t\tdecimals = frappe.boot.sysdefaults.currency_precision || null;\n\t}\n\n\tif (symbol)\n\t\treturn symbol + \" \" + format_number(v, format, decimals);\n\telse\n\t\treturn format_number(v, format, decimals);\n}\n\nfunction get_currency_symbol(currency) {\n\tif (frappe.boot) {\n\t\tif (frappe.boot.sysdefaults.hide_currency_symbol == \"Yes\")\n\t\t\treturn null;\n\n\t\tif (!currency)\n\t\t\tcurrency = frappe.boot.sysdefaults.currency;\n\n\t\treturn frappe.model.get_value(\":Currency\", currency, \"symbol\") || currency;\n\t} else {\n\t\t// load in template\n\t\treturn frappe.currency_symbols[currency];\n\t}\n}\n\nfunction get_number_format(currency) {\n\treturn (frappe.boot && frappe.boot.sysdefaults && frappe.boot.sysdefaults.number_format) || \"#,###.##\";\n}\n\nfunction get_number_format_info(format) {\n\tvar info = frappe.number_format_info[format];\n\n\tif (!info) {\n\t\tinfo = { decimal_str: \".\", group_sep: \",\" };\n\t}\n\n\t// get the precision from the number format\n\tinfo.precision = format.split(info.decimal_str).slice(1)[0].length;\n\n\treturn info;\n}\n\nfunction _round(num, precision) {\n\tvar is_negative = num < 0 ? true : false;\n\tvar d = cint(precision);\n\tvar m = Math.pow(10, d);\n\tvar n = +(d ? Math.abs(num) * m : Math.abs(num)).toFixed(8); // Avoid rounding errors\n\tvar i = Math.floor(n), f = n - i;\n\tvar r = ((!precision && f == 0.5) ? ((i % 2 == 0) ? i : i + 1) : Math.round(n));\n\tr = d ? r / m : r;\n\treturn is_negative ? -r : r;\n\n}\n\nfunction roundNumber(num, precision) {\n\t// backward compatibility\n\treturn _round(num, precision);\n}\n\nfunction precision(fieldname, doc) {\n\tif (cur_frm) {\n\t\tif (!doc) doc = cur_frm.doc;\n\t\tvar df = frappe.meta.get_docfield(doc.doctype, fieldname, doc.parent || doc.name);\n\t\tif (!df) console.log(fieldname + \": could not find docfield in method precision()\");\n\t\treturn frappe.meta.get_field_precision(df, doc);\n\t} else {\n\t\treturn frappe.boot.sysdefaults.float_precision\n\t}\n}\n\nfunction in_list(list, item) {\n\treturn list.includes(item);\n}\n\nfunction remainder(numerator, denominator, precision) {\n\tprecision = cint(precision);\n\tvar multiplier = Math.pow(10, precision);\n\tif (precision) {\n\t\tvar _remainder = ((numerator * multiplier) % (denominator * multiplier)) / multiplier;\n\t} else {\n\t\tvar _remainder = numerator % denominator;\n\t}\n\n\treturn flt(_remainder, precision);\n}\n\nfunction round_based_on_smallest_currency_fraction(value, currency, precision) {\n\tvar smallest_currency_fraction_value = flt(frappe.model.get_value(\":Currency\",\n\t\tcurrency, \"smallest_currency_fraction_value\"))\n\n\tif (smallest_currency_fraction_value) {\n\t\tvar remainder_val = remainder(value, smallest_currency_fraction_value, precision);\n\t\tif (remainder_val > (smallest_currency_fraction_value / 2)) {\n\t\t\tvalue += (smallest_currency_fraction_value - remainder_val);\n\t\t} else {\n\t\t\tvalue -= remainder_val;\n\t\t}\n\t} else {\n\t\tvalue = _round(value);\n\t}\n\treturn value;\n}\n\nfunction fmt_money(v, format){\n\t// deprecated!\n\t// for backward compatibility\n\treturn format_currency(v, format);\n}\n\n\nObject.assign(window, {\n\tflt,\n\tcint,\n\tstrip_number_groups,\n\tformat_currency,\n\tfmt_money,\n\tget_currency_symbol,\n\tget_number_format,\n\tget_number_format_info,\n\t_round,\n\troundNumber,\n\tprecision,\n\tremainder,\n\tround_based_on_smallest_currency_fraction,\n\tin_list\n});","// String.prototype.includes polyfill\n// https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/String/includes\nif (!String.prototype.includes) {\n\tString.prototype.includes = function(search, start) {\n\t\t'use strict';\n\t\tif (typeof start !== 'number') {\n\t\t\tstart = 0;\n\t\t}\n\t\tif (start + search.length > this.length) {\n\t\t\treturn false;\n\t\t} else {\n\t\t\treturn this.indexOf(search, start) !== -1;\n\t\t}\n\t};\n}\n// Array.prototype.includes polyfill\n// https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Array/includes\nif (!Array.prototype.includes) {\n\tObject.defineProperty(Array.prototype, 'includes', {\n\t\tvalue: function(searchElement, fromIndex) {\n\t\t\tif (this == null) {\n\t\t\t\tthrow new TypeError('\"this\" is null or not defined');\n\t\t\t}\n\t\t\tvar o = Object(this);\n\t\t\tvar len = o.length >>> 0;\n\t\t\tif (len === 0) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\tvar n = fromIndex | 0;\n\t\t\tvar k = Math.max(n >= 0 ? n : len - Math.abs(n), 0);\n\t\t\twhile (k < len) {\n\t\t\t\tif (o[k] === searchElement) {\n\t\t\t\t\treturn true;\n\t\t\t\t}\n\t\t\t\tk++;\n\t\t\t}\n\t\t\treturn false;\n\t\t}\n\t});\n}\n\n\nif (typeof String.prototype.trimLeft !== \"function\") {\n\tString.prototype.trimLeft = function() {\n\t\treturn this.replace(/^\\s+/, \"\");\n\t};\n}\nif (typeof String.prototype.trimRight !== \"function\") {\n\tString.prototype.trimRight = function() {\n\t\treturn this.replace(/\\s+$/, \"\");\n\t};\n}\n\n// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign\nif (typeof Object.assign != 'function') {\n\t// Must be writable: true, enumerable: false, configurable: true\n\tObject.defineProperty(Object, \"assign\", {\n\t\tvalue: function assign(target) { // .length of function is 2\n\t\t\t'use strict';\n\t\t\tif (target == null) { // TypeError if undefined or null\n\t\t\t\tthrow new TypeError('Cannot convert undefined or null to object');\n\t\t\t}\n\n\t\t\tvar to = Object(target);\n\n\t\t\tfor (var index = 1; index < arguments.length; index++) {\n\t\t\t\tvar nextSource = arguments[index];\n\n\t\t\t\tif (nextSource != null) { // Skip over if undefined or null\n\t\t\t\t\tfor (var nextKey in nextSource) {\n\t\t\t\t\t\t// Avoid bugs when hasOwnProperty is shadowed\n\t\t\t\t\t\tif (Object.prototype.hasOwnProperty.call(nextSource, nextKey)) {\n\t\t\t\t\t\t\tto[nextKey] = nextSource[nextKey];\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn to;\n\t\t},\n\t\twritable: true,\n\t\tconfigurable: true\n\t});\n}\n","!function(a){\"use strict\";function b(a,b){var c=(65535&a)+(65535&b),d=(a>>16)+(b>>16)+(c>>16);return d<<16|65535&c}function c(a,b){return a<>>32-b}function d(a,d,e,f,g,h){return b(c(b(b(d,a),b(f,h)),g),e)}function e(a,b,c,e,f,g,h){return d(b&c|~b&e,a,b,f,g,h)}function f(a,b,c,e,f,g,h){return d(b&e|c&~e,a,b,f,g,h)}function g(a,b,c,e,f,g,h){return d(b^c^e,a,b,f,g,h)}function h(a,b,c,e,f,g,h){return d(c^(b|~e),a,b,f,g,h)}function i(a,c){a[c>>5]|=128<>>9<<4)+14]=c;var d,i,j,k,l,m=1732584193,n=-271733879,o=-1732584194,p=271733878;for(d=0;d>5]>>>b%32&255);return c}function k(a){var b,c=[];for(c[(a.length>>2)-1]=void 0,b=0;b>5]|=(255&a.charCodeAt(b/8))<16&&(e=i(e,8*a.length)),c=0;16>c;c+=1)f[c]=909522486^e[c],g[c]=1549556828^e[c];return d=i(f.concat(k(b)),512+8*b.length),j(i(g.concat(d),640))}function n(a){var b,c,d=\"0123456789abcdef\",e=\"\";for(c=0;c>>4&15)+d.charAt(15&b);return e}function o(a){return unescape(encodeURIComponent(a))}function p(a){return l(o(a))}function q(a){return n(p(a))}function r(a,b){return m(o(a),o(b))}function s(a,b){return n(r(a,b))}function t(a,b,c){return b?c?r(b,a):s(b,a):c?p(a):q(a)}\"function\"==typeof define&&define.amd?define(function(){return t}):a.md5=t}(this);","// Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors\n// MIT License. See license.txt\n\n// provide a namespace\nif(!window.frappe)\n\twindow.frappe = {};\n\nfrappe.provide = function(namespace) {\n\t// docs: create a namespace //\n\tvar nsl = namespace.split('.');\n\tvar parent = window;\n\tfor(var i=0; i'\n\t\t+ prettyDate(datetime, mini) + '';\n};\nfrappe.datetime.comment_when = comment_when;\n\nfrappe.datetime.refresh_when = function() {\n\tif (jQuery) {\n\t\t$(\".frappe-timestamp\").each(function() {\n\t\t\t$(this).html(prettyDate($(this).attr(\"data-timestamp\"), $(this).hasClass(\"mini\")));\n\t\t});\n\t}\n};\n\nsetInterval(function() {\n\tfrappe.datetime.refresh_when();\n}, 60000); // refresh every minute\n","frappe.provide('frappe.utils');\n\nfunction get_url_arg(name) {\n\treturn get_query_params()[name] || \"\";\n}\n\nfunction get_query_string(url) {\n\tif(url.includes(\"?\")) {\n\t\treturn url.slice(url.indexOf(\"?\")+1);\n\t}else {\n\t\treturn \"\";\n\t}\n}\n\nfunction get_query_params(query_string) {\n\tvar query_params = {};\n\tif (!query_string) {\n\t\tquery_string = location.search.substring(1);\n\t}\n\n\tvar query_list = query_string.split(\"&\");\n\tfor (var i=0, l=query_list.length; i < l; i++ ){\n\t\tvar pair = query_list[i].split(/=(.+)/);\n\t\tvar key = pair[0];\n\t\tif (!key) {\n\t\t\tcontinue;\n\t\t}\n\n\t\tvar value = pair[1];\n\t\tif (typeof value === \"string\") {\n\t\t\tvalue = value.replace(/\\+/g, \"%20\");\n\t\t\ttry {\n\t\t\t\tvalue = decodeURIComponent(value);\n\t\t\t} catch(e) {\n\t\t\t\t// if value contains %, it fails\n\t\t\t}\n\t\t}\n\n\t\tif (key in query_params) {\n\t\t\tif (typeof query_params[key] === \"undefined\") {\n\t\t\t\tquery_params[key] = [];\n\t\t\t} else if (typeof query_params[key] === \"string\") {\n\t\t\t\tquery_params[key] = [query_params[key]];\n\t\t\t}\n\t\t\tquery_params[key].push(value);\n\t\t} else {\n\t\t\tquery_params[key] = value;\n\t\t}\n\t}\n\treturn query_params;\n}\n\nfunction make_query_string(obj, encode=true) {\n\tlet query_params = [];\n\tfor (let key in obj) {\n\t\tlet value = obj[key];\n\t\tif (value === undefined || value === '' || value === null) {\n\t\t\tcontinue;\n\t\t}\n\t\tif (typeof value === 'object') {\n\t\t\tvalue = JSON.stringify(value);\n\t\t}\n\n\t\tif (encode) {\n\t\t\tkey = encodeURIComponent(key);\n\t\t\tvalue = encodeURIComponent(value);\n\t\t}\n\n\t\tquery_params.push(`${key}=${value}`);\n\t}\n\treturn '?' + query_params.join('&');\n}\n\nObject.assign(frappe.utils, {\n\tget_url_arg,\n\tget_query_string,\n\tget_query_params,\n\tmake_query_string\n});","// Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors\n// MIT License. See license.txt\n\nimport deep_equal from \"fast-deep-equal\";\nfrappe.provide('frappe.utils');\n\nObject.assign(frappe.utils, {\n\tget_random: function(len) {\n\t\tvar text = \"\";\n\t\tvar possible = \"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\";\n\n\t\tfor( var i=0; i < len; i++ )\n\t\t\ttext += possible.charAt(Math.floor(Math.random() * possible.length));\n\n\t\treturn text;\n\t},\n\tget_file_link: function(filename) {\n\t\tfilename = cstr(filename);\n\t\tif(frappe.utils.is_url(filename)) {\n\t\t\treturn filename;\n\t\t} else if(filename.indexOf(\"/\")===-1) {\n\t\t\treturn \"files/\" + filename;\n\t\t} else {\n\t\t\treturn filename;\n\t\t}\n\t},\n\treplace_newlines(t) {\n\t\treturn t?t.replace(/\\n/g, '
'):'';\n\t},\n\tis_html: function(txt) {\n\t\tif (!txt) return false;\n\n\t\tif(txt.indexOf(\"
\")==-1 && txt.indexOf(\"= 768;\n\t},\n\tis_md: function() {\n\t\treturn $(document).width() < 1199 && $(document).width() >= 991;\n\t},\n\tis_json: function(str) {\n\t\ttry {\n\t\t\tJSON.parse(str);\n\t\t} catch (e) {\n\t\t\treturn false;\n\t\t}\n\t\treturn true;\n\t},\n\tstrip_whitespace: function(html) {\n\t\treturn (html || \"\").replace(/

\\s*<\\/p>/g, \"\").replace(/
(\\s*
\\s*)+/g, \"

\");\n\t},\n\tencode_tags: function(html) {\n\t\tvar tagsToReplace = {\n\t\t\t'&': '&',\n\t\t\t'<': '<',\n\t\t\t'>': '>'\n\t\t};\n\n\t\tfunction replaceTag(tag) {\n\t\t\treturn tagsToReplace[tag] || tag;\n\t\t}\n\n\t\treturn html.replace(/[&<>]/g, replaceTag);\n\t},\n\tstrip_original_content: function(txt) {\n\t\tvar out = [],\n\t\t\tpart = [],\n\t\t\tnewline = txt.indexOf(\"
\")===-1 ? \"\\n\" : \"
\";\n\n\t\t$.each(txt.split(newline), function(i, t) {\n\t\t\tvar tt = strip(t);\n\t\t\tif(tt && (tt.substr(0,1)===\">\" || tt.substr(0,4)===\">\")) {\n\t\t\t\tpart.push(t);\n\t\t\t} else {\n\t\t\t\tout.concat(part);\n\t\t\t\tout.push(t);\n\t\t\t\tpart = [];\n\t\t\t}\n\t\t});\n\t\treturn out.join(newline);\n\t},\n\tescape_html: function(txt) {\n\t\treturn $(\"

\").text(txt || \"\").html();\n\t},\n\n\thtml2text: function(html) {\n\t\tlet d = document.createElement('div');\n\t\td.innerHTML = html;\n\t\treturn d.textContent;\n\t},\n\n\tis_url: function(txt) {\n\t\treturn txt.toLowerCase().substr(0,7)=='http://'\n\t\t\t|| txt.toLowerCase().substr(0,8)=='https://'\n\t},\n\tto_title_case: function(string, with_space=false) {\n\t\tlet titlecased_string = string.toLowerCase().replace(/(?:^|[\\s-/])\\w/g, function(match) {\n\t\t\treturn match.toUpperCase();\n\t\t});\n\n\t\tlet replace_with = with_space ? ' ' : '';\n\n\t\treturn titlecased_string.replace(/-|_/g, replace_with);\n\t},\n\ttoggle_blockquote: function(txt) {\n\t\tif (!txt) return txt;\n\n\t\tvar content = $(\"
\").html(txt)\n\t\tcontent.find(\"blockquote\").parent(\"blockquote\").addClass(\"hidden\")\n\t\t\t.before('

\\\n\t\t\t\t\t• • • \\\n\t\t\t\t

');\n\t\treturn content.html();\n\t},\n\tscroll_to: function(element, animate, additional_offset) {\n\t\tvar y = 0;\n\t\tif(element && typeof element==='number') {\n\t\t\ty = element;\n\t\t} else if(element) {\n\t\t\tvar header_offset = $(\".navbar\").height() + $(\".page-head\").height();\n\t\t\tvar y = $(element).offset().top - header_offset - cint(additional_offset);\n\t\t}\n\n\t\tif(y < 0) {\n\t\t\ty = 0;\n\t\t}\n\n\t\t// already there\n\t\tif(y==$('html, body').scrollTop()) {\n\t\t\treturn;\n\t\t}\n\n\t\tif (animate!==false) {\n\t\t\t$(\"html, body\").animate({ scrollTop: y });\n\t\t} else {\n\t\t\t$(window).scrollTop(y);\n\t\t}\n\n\t},\n\tfilter_dict: function(dict, filters) {\n\t\tvar ret = [];\n\t\tif(typeof filters=='string') {\n\t\t\treturn [dict[filters]]\n\t\t}\n\t\t$.each(dict, function(i, d) {\n\t\t\tfor(var key in filters) {\n\t\t\t\tif($.isArray(filters[key])) {\n\t\t\t\t\tif(filters[key][0]==\"in\") {\n\t\t\t\t\t\tif(filters[key][1].indexOf(d[key])==-1)\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t} else if(filters[key][0]==\"not in\") {\n\t\t\t\t\t\tif(filters[key][1].indexOf(d[key])!=-1)\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t} else if(filters[key][0]==\"<\") {\n\t\t\t\t\t\tif (!(d[key] < filters[key])) return;\n\t\t\t\t\t} else if(filters[key][0]==\"<=\") {\n\t\t\t\t\t\tif (!(d[key] <= filters[key])) return;\n\t\t\t\t\t} else if(filters[key][0]==\">\") {\n\t\t\t\t\t\tif (!(d[key] > filters[key])) return;\n\t\t\t\t\t} else if(filters[key][0]==\">=\") {\n\t\t\t\t\t\tif (!(d[key] >= filters[key])) return;\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tif(d[key]!=filters[key]) return;\n\t\t\t\t}\n\t\t\t}\n\t\t\tret.push(d);\n\t\t});\n\t\treturn ret;\n\t},\n\tcomma_or: function(list) {\n\t\treturn frappe.utils.comma_sep(list, \" \" + __(\"or\") + \" \");\n\t},\n\tcomma_and: function(list) {\n\t\treturn frappe.utils.comma_sep(list, \" \" + __(\"and\") + \" \");\n\t},\n\tcomma_sep: function(list, sep) {\n\t\tif(list instanceof Array) {\n\t\t\tif(list.length==0) {\n\t\t\t\treturn \"\";\n\t\t\t} else if (list.length==1) {\n\t\t\t\treturn list[0];\n\t\t\t} else {\n\t\t\t\treturn list.slice(0, list.length-1).join(\", \") + sep + list.slice(-1)[0];\n\t\t\t}\n\t\t} else {\n\t\t\treturn list;\n\t\t}\n\t},\n\tset_footnote: function(footnote_area, wrapper, txt) {\n\t\tif(!footnote_area) {\n\t\t\tfootnote_area = $('
')\n\t\t\t\t.appendTo(wrapper);\n\t\t}\n\n\t\tif(txt) {\n\t\t\tfootnote_area.html(txt);\n\t\t} else {\n\t\t\tfootnote_area.remove();\n\t\t\tfootnote_area = null;\n\t\t}\n\t\treturn footnote_area;\n\t},\n\tget_args_dict_from_url: function(txt) {\n\t\tvar args = {};\n\t\t$.each(decodeURIComponent(txt).split(\"&\"), function(i, arg) {\n\t\t\targ = arg.split(\"=\");\n\t\t\targs[arg[0]] = arg[1]\n\t\t});\n\t\treturn args;\n\t},\n\tget_url_from_dict: function(args) {\n\t\treturn $.map(args, function(val, key) {\n\t\t\tif(val!==null)\n\t\t\t\treturn encodeURIComponent(key)+\"=\"+encodeURIComponent(val);\n\t\t\telse\n\t\t\t\treturn null;\n\t\t}).join(\"&\") || \"\";\n\t},\n\tvalidate_type: function ( val, type ) {\n\t\t// from https://github.com/guillaumepotier/Parsley.js/blob/master/parsley.js#L81\n\t\tvar regExp;\n\n\t\tswitch ( type ) {\n\t\t\tcase \"phone\":\n\t\t\t\tregExp = /^([0-9 +_\\-,.*#()]){1,20}$/;\n\t\t\t\tbreak;\n\t\t\tcase \"number\":\n\t\t\t\tregExp = /^-?(?:\\d+|\\d{1,3}(?:,\\d{3})+)?(?:\\.\\d+)?$/;\n\t\t\t\tbreak;\n\t\t\tcase \"digits\":\n\t\t\t\tregExp = /^\\d+$/;\n\t\t\t\tbreak;\n\t\t\tcase \"alphanum\":\n\t\t\t\tregExp = /^\\w+$/;\n\t\t\t\tbreak;\n\t\t\tcase \"email\":\n\t\t\t\tregExp = /^((([a-z]|\\d|[!#\\$%&'\\*\\+\\-\\/=\\?\\^_`{\\|}~]|[\\u00A0-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF])+(\\.([a-z]|\\d|[!#\\$%&'\\*\\+\\-\\/=\\?\\^_`{\\|}~]|[\\u00A0-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF])+)*)|((\\x22)((((\\x20|\\x09)*(\\x0d\\x0a))?(\\x20|\\x09)+)?(([\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x7f]|\\x21|[\\x23-\\x5b]|[\\x5d-\\x7e]|[\\u00A0-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF])|(\\\\([\\x01-\\x09\\x0b\\x0c\\x0d-\\x7f]|[\\u00A0-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF]))))*(((\\x20|\\x09)*(\\x0d\\x0a))?(\\x20|\\x09)+)?(\\x22)))@((([a-z]|\\d|[\\u00A0-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF])|(([a-z]|\\d|[\\u00A0-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF])([a-z]|\\d|-|\\.|_|~|[\\u00A0-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF])*([a-z]|\\d|[\\u00A0-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF])))\\.)+(([a-z]|[\\u00A0-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF])|(([a-z]|[\\u00A0-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF])([a-z]|\\d|-|\\.|_|~|[\\u00A0-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF])*([a-z]|[\\u00A0-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF])))$/i;\n\t\t\t\tbreak;\n\t\t\tcase \"url\":\n\t\t\t\tregExp = /^(https?|s?ftp):\\/\\/(((([a-z]|\\d|-|\\.|_|~|[\\u00A0-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF])|(%[\\da-f]{2})|[!\\$&'\\(\\)\\*\\+,;=]|:)*@)?(((\\d|[1-9]\\d|1\\d\\d|2[0-4]\\d|25[0-5])\\.(\\d|[1-9]\\d|1\\d\\d|2[0-4]\\d|25[0-5])\\.(\\d|[1-9]\\d|1\\d\\d|2[0-4]\\d|25[0-5])\\.(\\d|[1-9]\\d|1\\d\\d|2[0-4]\\d|25[0-5]))|((([a-z]|\\d|[\\u00A0-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF])|(([a-z]|\\d|[\\u00A0-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF])([a-z]|\\d|-|\\.|_|~|[\\u00A0-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF])*([a-z]|\\d|[\\u00A0-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF])))\\.)+(([a-z]|[\\u00A0-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF])|(([a-z]|[\\u00A0-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF])([a-z]|\\d|-|\\.|_|~|[\\u00A0-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF])*([a-z]|[\\u00A0-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF])))\\.?)(:\\d*)?)(\\/((([a-z]|\\d|-|\\.|_|~|[\\u00A0-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF])|(%[\\da-f]{2})|[!\\$&'\\(\\)\\*\\+,;=]|:|@)+(\\/(([a-z]|\\d|-|\\.|_|~|[\\u00A0-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF])|(%[\\da-f]{2})|[!\\$&'\\(\\)\\*\\+,;=]|:|@)*)*)?)?(\\?((([a-z]|\\d|-|\\.|_|~|[\\u00A0-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF])|(%[\\da-f]{2})|[!\\$&'\\(\\)\\*\\+,;=]|:|@)|[\\uE000-\\uF8FF]|\\/|\\?)*)?(#((([a-z]|\\d|-|\\.|_|~|[\\u00A0-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF])|(%[\\da-f]{2})|[!\\$&'\\(\\)\\*\\+,;=]|:|@)|\\/|\\?)*)?$/i;\n\t\t\t\tbreak;\n\t\t\tcase \"dateIso\":\n\t\t\t\tregExp = /^(\\d{4})\\D?(0[1-9]|1[0-2])\\D?([12]\\d|0[1-9]|3[01])$/;\n\t\t\t\tbreak;\n\t\t\tdefault:\n\t\t\t\treturn false;\n\t\t}\n\n\t\t// test regExp if not null\n\t\treturn '' !== val ? regExp.test( val ) : false;\n\t},\n\tguess_style: function(text, default_style, _colour) {\n\t\tvar style = default_style || \"default\";\n\t\tvar colour = \"darkgrey\";\n\t\tif(text) {\n\t\t\tif(has_words([\"Pending\", \"Review\", \"Medium\", \"Not Approved\"], text)) {\n\t\t\t\tstyle = \"warning\";\n\t\t\t\tcolour = \"orange\";\n\t\t\t} else if(has_words([\"Open\", \"Urgent\", \"High\", \"Failed\", \"Rejected\", \"Error\"], text)) {\n\t\t\t\tstyle = \"danger\";\n\t\t\t\tcolour = \"red\";\n\t\t\t} else if(has_words([\"Closed\", \"Finished\", \"Converted\", \"Completed\", \"Confirmed\",\n\t\t\t\t\"Approved\", \"Yes\", \"Active\", \"Available\", \"Paid\"], text)) {\n\t\t\t\tstyle = \"success\";\n\t\t\t\tcolour = \"green\";\n\t\t\t} else if(has_words([\"Submitted\"], text)) {\n\t\t\t\tstyle = \"info\";\n\t\t\t\tcolour = \"blue\";\n\t\t\t}\n\t\t}\n\t\treturn _colour ? colour : style;\n\t},\n\n\tguess_colour: function(text) {\n\t\treturn frappe.utils.guess_style(text, null, true);\n\t},\n\n\tget_indicator_color: function(state) {\n\t\treturn frappe.db.get_list('Workflow State', {filters: {name: state}, fields: ['name', 'style']}).then(res => {\n\t\t\tconst state = res[0];\n\t\t\tif (!state.style) {\n\t\t\t\treturn frappe.utils.guess_colour(state.name);\n\t\t\t}\n\t\t\tconst style = state.style;\n\t\t\tconst colour_map = {\n\t\t\t\t\"Success\": \"green\",\n\t\t\t\t\"Warning\": \"orange\",\n\t\t\t\t\"Danger\": \"red\",\n\t\t\t\t\"Primary\": \"blue\",\n\t\t\t};\n\n\t\t\treturn colour_map[style];\n\t\t});\n\n\t},\n\n\tsort: function(list, key, compare_type, reverse) {\n\t\tif(!list || list.length < 2)\n\t\t\treturn list || [];\n\n\t\tvar sort_fn = {\n\t\t\t\"string\": function(a, b) {\n\t\t\t\treturn cstr(a[key]).localeCompare(cstr(b[key]));\n\t\t\t},\n\t\t\t\"number\": function(a, b) {\n\t\t\t\treturn flt(a[key]) - flt(b[key]);\n\t\t\t}\n\t\t};\n\n\t\tif(!compare_type)\n\t\t\tcompare_type = typeof list[0][key]===\"string\" ? \"string\" : \"number\";\n\n\t\tlist.sort(sort_fn[compare_type]);\n\n\t\tif(reverse) { list.reverse(); }\n\n\t\treturn list;\n\t},\n\n\tunique: function(list) {\n\t\tvar dict = {},\n\t\t\tarr = [];\n\t\tfor(var i=0, l=list.length; i < l; i++) {\n\t\t\tif(!dict.hasOwnProperty(list[i])) {\n\t\t\t\tdict[list[i]] = null;\n\t\t\t\tarr.push(list[i]);\n\t\t\t}\n\t\t}\n\t\treturn arr;\n\t},\n\n\tremove_nulls: function(list) {\n\t\tvar new_list = [];\n\t\tfor (var i=0, l=list.length; i < l; i++) {\n\t\t\tif (!is_null(list[i])) {\n\t\t\t\tnew_list.push(list[i]);\n\t\t\t}\n\t\t}\n\t\treturn new_list;\n\t},\n\n\tall: function(lst) {\n\t\tfor(var i=0, l=lst.length; i b[bi] ) { bi++; }\n\t\t\telse {\n\t\t\t\t/* they're equal */\n\t\t\t\tresult.push(a[ai]);\n\t\t\t\tai++;\n\t\t\t\tbi++;\n\t\t\t}\n\t\t}\n\n\t\treturn result;\n\t},\n\n\tresize_image: function(reader, callback, max_width, max_height) {\n\t\tvar tempImg = new Image();\n\t\tif(!max_width) max_width = 600;\n\t\tif(!max_height) max_height = 400;\n\t\ttempImg.src = reader.result;\n\n\t\ttempImg.onload = function() {\n\t\t\tvar tempW = tempImg.width;\n\t\t\tvar tempH = tempImg.height;\n\t\t\tif (tempW > tempH) {\n\t\t\t\tif (tempW > max_width) {\n\t\t\t\t\ttempH *= max_width / tempW;\n\t\t\t\t\ttempW = max_width;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tif (tempH > max_height) {\n\t\t\t\t\ttempW *= max_height / tempH;\n\t\t\t\t\ttempH = max_height;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tvar canvas = document.createElement('canvas');\n\t\t\tcanvas.width = tempW;\n\t\t\tcanvas.height = tempH;\n\t\t\tvar ctx = canvas.getContext(\"2d\");\n\t\t\tctx.drawImage(this, 0, 0, tempW, tempH);\n\t\t\tvar dataURL = canvas.toDataURL(\"image/jpeg\");\n\t\t\tsetTimeout(function() { callback(dataURL); }, 10 );\n\t\t}\n\t},\n\n\tcsv_to_array: function (strData, strDelimiter) {\n\t\t// Check to see if the delimiter is defined. If not,\n\t\t// then default to comma.\n\t\tstrDelimiter = (strDelimiter || \",\");\n\n\t\t// Create a regular expression to parse the CSV values.\n\t\tvar objPattern = new RegExp(\n\t\t\t(\n\t\t\t\t// Delimiters.\n\t\t\t\t\"(\\\\\" + strDelimiter + \"|\\\\r?\\\\n|\\\\r|^)\" +\n\n\t\t\t\t// Quoted fields.\n\t\t\t\t\"(?:\\\"([^\\\"]*(?:\\\"\\\"[^\\\"]*)*)\\\"|\" +\n\n\t\t\t\t// Standard fields.\n\t\t\t\t\"([^\\\"\\\\\" + strDelimiter + \"\\\\r\\\\n]*))\"\n\t\t\t),\n\t\t\t\"gi\"\n\t\t\t);\n\n\n\t\t// Create an array to hold our data. Give the array\n\t\t// a default empty first row.\n\t\tvar arrData = [[]];\n\n\t\t// Create an array to hold our individual pattern\n\t\t// matching groups.\n\t\tvar arrMatches = null;\n\n\n\t\t// Keep looping over the regular expression matches\n\t\t// until we can no longer find a match.\n\t\twhile ((arrMatches = objPattern.exec( strData ))){\n\n\t\t\t// Get the delimiter that was found.\n\t\t\tvar strMatchedDelimiter = arrMatches[ 1 ];\n\n\t\t\t// Check to see if the given delimiter has a length\n\t\t\t// (is not the start of string) and if it matches\n\t\t\t// field delimiter. If id does not, then we know\n\t\t\t// that this delimiter is a row delimiter.\n\t\t\tif (\n\t\t\t\tstrMatchedDelimiter.length &&\n\t\t\t\tstrMatchedDelimiter !== strDelimiter\n\t\t\t\t){\n\n\t\t\t\t// Since we have reached a new row of data,\n\t\t\t\t// add an empty row to our data array.\n\t\t\t\tarrData.push( [] );\n\n\t\t\t}\n\n\t\t\tvar strMatchedValue;\n\n\t\t\t// Now that we have our delimiter out of the way,\n\t\t\t// let's check to see which kind of value we\n\t\t\t// captured (quoted or unquoted).\n\t\t\tif (arrMatches[ 2 ]){\n\n\t\t\t\t// We found a quoted value. When we capture\n\t\t\t\t// this value, unescape any double quotes.\n\t\t\t\tstrMatchedValue = arrMatches[ 2 ].replace(\n\t\t\t\t\tnew RegExp( \"\\\"\\\"\", \"g\" ),\n\t\t\t\t\t\"\\\"\"\n\t\t\t\t\t);\n\n\t\t\t} else {\n\n\t\t\t\t// We found a non-quoted value.\n\t\t\t\tstrMatchedValue = arrMatches[ 3 ];\n\n\t\t\t}\n\n\n\t\t\t// Now that we have our value string, let's add\n\t\t\t// it to the data array.\n\t\t\tarrData[ arrData.length - 1 ].push( strMatchedValue );\n\t\t}\n\n\t\t// Return the parsed data.\n\t\treturn( arrData );\n\t},\n\n\twarn_page_name_change: function(frm) {\n\t\tfrappe.msgprint(__(\"Note: Changing the Page Name will break previous URL to this page.\"));\n\t},\n\n\tnotify: function(subject, body, route, onclick) {\n\t\tconsole.log('push notifications are evil and deprecated');\n\t},\n\n\tset_title: function(title) {\n\t\tfrappe._original_title = title;\n\t\tif(frappe._title_prefix) {\n\t\t\ttitle = frappe._title_prefix + \" \" + title.replace(/<[^>]*>/g, \"\");\n\t\t}\n\t\tdocument.title = title;\n\t},\n\n\tset_title_prefix: function(prefix) {\n\t\tfrappe._title_prefix = prefix;\n\n\t\t// reset the original title\n\t\tfrappe.utils.set_title(frappe._original_title);\n\t},\n\n\tis_image_file: function(filename) {\n\t\tif (!filename) return false;\n\t\t// url can have query params\n\t\tfilename = filename.split('?')[0];\n\t\treturn (/\\.(gif|jpg|jpeg|tiff|png|svg)$/i).test(filename);\n\t},\n\n\tplay_sound: function(name) {\n\t\ttry {\n\t\t\tif (frappe.boot.user.mute_sounds) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tvar audio = $(\"#sound-\" + name)[0];\n\t\t\taudio.volume = audio.getAttribute(\"volume\");\n\t\t\taudio.play();\n\n\t\t} catch(e) {\n\t\t\tconsole.log(\"Cannot play sound\", name, e);\n\t\t\t// pass\n\t\t}\n\n\t},\n\tsplit_emails: function(txt) {\n\t\tvar email_list = [];\n\n\t\tif (!txt) {\n\t\t\treturn email_list;\n\t\t}\n\n\t\t// emails can be separated by comma or newline\n\t\ttxt.split(/[,\\n](?=(?:[^\"]|\"[^\"]*\")*$)/g).forEach(function(email) {\n\t\t\temail = email.trim();\n\t\t\tif (email) {\n\t\t\t\temail_list.push(email);\n\t\t\t}\n\t\t});\n\n\t\treturn email_list;\n\t},\n\tsupportsES6: function() {\n\t\ttry {\n\t\t\tnew Function(\"(a = 0) => a\");\n\t\t\treturn true;\n\t\t}\n\t\tcatch (err) {\n\t\t\treturn false;\n\t\t}\n\t}(),\n\tthrottle: function (func, wait, options) {\n\t\tvar context, args, result;\n\t\tvar timeout = null;\n\t\tvar previous = 0;\n\t\tif (!options) options = {};\n\n\t\tlet later = function () {\n\t\t\tprevious = options.leading === false ? 0 : Date.now();\n\t\t\ttimeout = null;\n\t\t\tresult = func.apply(context, args);\n\t\t\tif (!timeout) context = args = null;\n\t\t};\n\n\t\treturn function () {\n\t\t\tvar now = Date.now();\n\t\t\tif (!previous && options.leading === false) previous = now;\n\t\t\tlet remaining = wait - (now - previous);\n\t\t\tcontext = this;\n\t\t\targs = arguments;\n\t\t\tif (remaining <= 0 || remaining > wait) {\n\t\t\t\tif (timeout) {\n\t\t\t\t\tclearTimeout(timeout);\n\t\t\t\t\ttimeout = null;\n\t\t\t\t}\n\t\t\t\tprevious = now;\n\t\t\t\tresult = func.apply(context, args);\n\t\t\t\tif (!timeout) context = args = null;\n\t\t\t} else if (!timeout && options.trailing !== false) {\n\t\t\t\ttimeout = setTimeout(later, remaining);\n\t\t\t}\n\t\t\treturn result;\n\t\t};\n\t},\n\tdebounce: function(func, wait, immediate) {\n\t\tvar timeout;\n\t\treturn function() {\n\t\t\tvar context = this, args = arguments;\n\t\t\tvar later = function() {\n\t\t\t\ttimeout = null;\n\t\t\t\tif (!immediate) func.apply(context, args);\n\t\t\t};\n\t\t\tvar callNow = immediate && !timeout;\n\t\t\tclearTimeout(timeout);\n\t\t\ttimeout = setTimeout(later, wait);\n\t\t\tif (callNow) func.apply(context, args);\n\t\t};\n\t},\n\tget_form_link: function(doctype, name, html = false, display_text = null) {\n\t\tdisplay_text = display_text || name;\n\t\tdoctype = encodeURIComponent(doctype);\n\t\tname = encodeURIComponent(name);\n\t\tconst route = ['#Form', doctype, name].join('/');\n\t\tif (html) {\n\t\t\treturn `${display_text}`;\n\t\t}\n\t\treturn route;\n\t},\n\tget_route_label(route_str) {\n\t\tlet route = route_str.split('/');\n\n\t\tif (route[2] === 'Report' || route[0] === 'query-report') {\n\t\t\treturn __('{0} Report', [route[3] || route[1]]);\n\t\t}\n\t\tif (route[0] === 'List') {\n\t\t\treturn __('{0} List', [route[1]]);\n\t\t}\n\t\tif (route[0] === 'modules') {\n\t\t\treturn __('{0} Modules', [route[1]]);\n\t\t}\n\t\tif (route[0] === 'dashboard') {\n\t\t\treturn __('{0} Dashboard', [route[1]]);\n\t\t}\n\t\treturn __(frappe.utils.to_title_case(route[0], true));\n\t},\n\treport_column_total: function(values, column, type) {\n\t\tif (column.column.disable_total) {\n\t\t\treturn '';\n\t\t} else if (values.length > 0) {\n\t\t\tif (column.column.fieldtype == \"Percent\" || type === \"mean\") {\n\t\t\t\treturn values.reduce((a, b) => a + flt(b)) / values.length;\n\t\t\t} else if (column.column.fieldtype == \"Int\") {\n\t\t\t\treturn values.reduce((a, b) => a + cint(b));\n\t\t\t} else if (frappe.model.is_numeric_field(column.column.fieldtype)) {\n\t\t\t\treturn values.reduce((a, b) => a + flt(b));\n\t\t\t} else {\n\t\t\t\treturn null;\n\t\t\t}\n\t\t}\n\t\telse {\n\t\t\treturn null;\n\t\t}\n\t},\n\tsetup_search($wrapper, el_class, text_class, data_attr) {\n\t\tconst $search_input = $wrapper.find('[data-element=\"search\"]').show();\n\t\t$search_input.focus().val('');\n\t\tconst $elements = $wrapper.find(el_class).show();\n\n\t\t$search_input.off('keyup').on('keyup', () => {\n\t\t\tlet text_filter = $search_input.val().toLowerCase();\n\t\t\t// Replace trailing and leading spaces\n\t\t\ttext_filter = text_filter.replace(/^\\s+|\\s+$/g, '');\n\t\t\tfor (let i = 0; i < $elements.length; i++) {\n\t\t\t\tconst text_element = $elements.eq(i).find(text_class);\n\t\t\t\tconst text = text_element.text().toLowerCase();\n\n\t\t\t\tlet name = '';\n\t\t\t\tif (data_attr && text_element.attr(data_attr)) {\n\t\t\t\t\tname = text_element.attr(data_attr).toLowerCase();\n\t\t\t\t}\n\n\t\t\t\tif (text.includes(text_filter) || name.includes(text_filter)) {\n\t\t\t\t\t$elements.eq(i).css('display', '');\n\t\t\t\t} else {\n\t\t\t\t\t$elements.eq(i).css('display', 'none');\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\t},\n\tdeep_equal(a, b) {\n\t\treturn deep_equal(a, b);\n\t},\n\n\tfile_name_ellipsis(filename, length) {\n\t\tlet first_part_length = length * 2 / 3;\n\t\tlet last_part_length = length - first_part_length;\n\t\tlet parts = filename.split('.');\n\t\tlet extn = parts.pop();\n\t\tlet name = parts.join('');\n\t\tlet first_part = name.slice(0, first_part_length);\n\t\tlet last_part = name.slice(-last_part_length);\n\t\tif (name.length > length) {\n\t\t\treturn `${first_part}...${last_part}.${extn}`;\n\t\t} else {\n\t\t\treturn filename;\n\t\t}\n\t},\n\tget_decoded_string(dataURI) {\n\t\t// decodes base64 to string\n\t\tlet parts = dataURI.split(',');\n\t\tconst encoded_data = parts[1];\n\t\treturn decodeURIComponent(escape(atob(encoded_data)));\n\t},\n\tcopy_to_clipboard(string) {\n\t\tlet input = $(\"\");\n\t\t$(\"body\").append(input);\n\t\tinput.val(string).select();\n\n\t\tdocument.execCommand(\"copy\");\n\t\tinput.remove();\n\n\t\tfrappe.show_alert({\n\t\t\tindicator: 'green',\n\t\t\tmessage: __('Copied to clipboard.')\n\t\t});\n\t},\n\tis_rtl() {\n\t\treturn [\"ar\", \"he\", \"fa\"].includes(frappe.boot.lang);\n\t},\n\tbind_actions_with_object($el, object) {\n\t\t// remove previously bound event\n\t\t$($el).off('click.class_actions');\n\t\t// attach new event\n\t\t$($el).on('click.class_actions', '[data-action]', e => {\n\t\t\tlet $target = $(e.currentTarget);\n\t\t\tlet action = $target.data('action');\n\t\t\tlet method = object[action];\n\t\t\tmethod ? object[action](e, $target) : null;\n\t\t});\n\n\t\treturn $el;\n\t}\n});\n\n// Array de duplicate\nif (!Array.prototype.uniqBy) {\n\tObject.defineProperty(Array.prototype, 'uniqBy', {\n\t\tvalue: function (key) {\n\t\t\tvar seen = {};\n\t\t\treturn this.filter(function (item) {\n\t\t\t\tvar k = key(item);\n\t\t\t\treturn seen.hasOwnProperty(k) ? false : (seen[k] = true);\n\t\t\t});\n\t\t}\n\t});\n\tObject.defineProperty(Array.prototype, 'move', {\n\t\tvalue: function(from, to) {\n\t\t\tthis.splice(to, 0, this.splice(from, 1)[0]);\n\t\t}\n\t});\n}\n","// common file between desk and website\n\nfrappe.avatar = function (user, css_class, title, image_url = null) {\n\tlet user_info;\n\tif (user) {\n\t\t// desk\n\t\tuser_info = frappe.user_info(user);\n\t} else {\n\t\t// website\n\t\tlet full_name = title || frappe.get_cookie(\"full_name\");\n\t\tuser_info = {\n\t\t\timage: image_url === null ? frappe.get_cookie(\"user_image\") : image_url,\n\t\t\tfullname: full_name,\n\t\t\tabbr: frappe.get_abbr(full_name),\n\t\t\tcolor: frappe.get_palette(full_name)\n\t\t};\n\t}\n\n\tif (!title) {\n\t\ttitle = user_info.fullname;\n\t}\n\n\tif (!css_class) {\n\t\tcss_class = \"avatar-small\";\n\t}\n\n\tif (user_info.image || image_url) {\n\t\timage_url = image_url || user_info.image;\n\n\t\tconst image = (window.cordova && image_url.indexOf('http') === -1) ? frappe.base_url + image_url : image_url;\n\n\t\treturn `\n\t\t\t\t\n\t\t\t`;\n\t} else {\n\t\tvar abbr = user_info.abbr;\n\t\tif (css_class === 'avatar-small' || css_class == 'avatar-xs') {\n\t\t\tabbr = abbr.substr(0, 1);\n\t\t}\n\t\treturn `\n\t\t\t
\n\t\t\t\t${abbr}
\n\t\t
`;\n\t}\n};\n\nfrappe.ui.scroll = function(element, animate, additional_offset) {\n\tvar header_offset = $(\".navbar\").height() + $(\".page-head\").height();\n\tvar top = $(element).offset().top - header_offset - cint(additional_offset);\n\tif (animate) {\n\t\t$(\"html, body\").animate({ scrollTop: top });\n\t} else {\n\t\t$(window).scrollTop(top);\n\t}\n};\n\nfrappe.get_palette = function(txt) {\n\treturn '#fafbfc';\n\t// //return '#8D99A6';\n\t// if(txt==='Administrator') return '#36414C';\n\t// // get color palette selection from md5 hash\n\t// var idx = cint((parseInt(md5(txt).substr(4,2), 16) + 1) / 5.33);\n\t// if(idx > 47) idx = 47;\n\t// return frappe.palette[idx][0]\n}\n\nfrappe.get_abbr = function(txt, max_length) {\n\tif (!txt) return \"\";\n\tvar abbr = \"\";\n\t$.each(txt.split(\" \"), function(i, w) {\n\t\tif (abbr.length >= (max_length || 2)) {\n\t\t\t// break\n\t\t\treturn false;\n\n\t\t} else if (!w.trim().length) {\n\t\t\t// continue\n\t\t\treturn true;\n\t\t}\n\t\tabbr += w.trim()[0];\n\t});\n\n\treturn abbr || \"?\";\n}\n\nfrappe.gravatars = {};\nfrappe.get_gravatar = function(email_id, size = 0) {\n\tvar param = size ? ('s=' + size) : 'd=retro';\n\tif(!frappe.gravatars[email_id]) {\n\t\t// TODO: check if gravatar exists\n\t\tfrappe.gravatars[email_id] = \"https://secure.gravatar.com/avatar/\" + md5(email_id) + \"?\" + param;\n\t}\n\treturn frappe.gravatars[email_id];\n}\n\n// string commons\n\nwindow.repl =function repl(s, dict) {\n\tif(s==null)return '';\n\tfor(var key in dict) {\n\t\ts = s.split(\"%(\"+key+\")s\").join(dict[key]);\n\t}\n\treturn s;\n}\n\nwindow.replace_all = function(s, t1, t2) {\n\treturn s.split(t1).join(t2);\n}\n\nwindow.strip_html = function(txt) {\n\treturn cstr(txt).replace(/<[^>]*>/g, \"\");\n}\n\nwindow.strip = function(s, chars) {\n\tif (s) {\n\t\tvar s= lstrip(s, chars)\n\t\ts = rstrip(s, chars);\n\t\treturn s;\n\t}\n}\n\nwindow.lstrip = function lstrip(s, chars) {\n\tif(!chars) chars = ['\\n', '\\t', ' '];\n\t// strip left\n\tvar first_char = s.substr(0,1);\n\twhile(in_list(chars, first_char)) {\n\t\tvar s = s.substr(1);\n\t\tfirst_char = s.substr(0,1);\n\t}\n\treturn s;\n}\n\nwindow.rstrip = function(s, chars) {\n\tif(!chars) chars = ['\\n', '\\t', ' '];\n\tvar last_char = s.substr(s.length-1);\n\twhile(in_list(chars, last_char)) {\n\t\tvar s = s.substr(0, s.length-1);\n\t\tlast_char = s.substr(s.length-1);\n\t}\n\treturn s;\n}\n\nfrappe.get_cookie = function getCookie(name) {\n\treturn frappe.get_cookies()[name];\n}\n\nfrappe.get_cookies = function getCookies() {\n\tvar c = document.cookie, v = 0, cookies = {};\n\tif (document.cookie.match(/^\\s*\\$Version=(?:\"1\"|1);\\s*(.*)/)) {\n\t\tc = RegExp.$1;\n\t\tv = 1;\n\t}\n\tif (v === 0) {\n\t\tc.split(/[,;]/).map(function(cookie) {\n\t\t\tvar parts = cookie.split(/=/, 2),\n\t\t\t\tname = decodeURIComponent(parts[0].trimLeft()),\n\t\t\t\tvalue = parts.length > 1 ? decodeURIComponent(parts[1].trimRight()) : null;\n\t\t\tif(value && value.charAt(0)==='\"') {\n\t\t\t\tvalue = value.substr(1, value.length-2);\n\t\t\t}\n\t\t\tcookies[name] = value;\n\t\t});\n\t} else {\n\t\tc.match(/(?:^|\\s+)([!#$%&'*+\\-.0-9A-Z^`a-z|~]+)=([!#$%&'*+\\-.0-9A-Z^`a-z|~]*|\"(?:[\\x20-\\x7E\\x80\\xFF]|\\\\[\\x00-\\x7F])*\")(?=\\s*[,;]|$)/g).map(function($0, $1) {\n\t\t\tvar name = $0,\n\t\t\t\tvalue = $1.charAt(0) === '\"'\n\t\t\t\t\t\t? $1.substr(1, -1).replace(/\\\\(.)/g, \"$1\")\n\t\t\t\t\t\t: $1;\n\t\t\tcookies[name] = value;\n\t\t});\n\t}\n\treturn cookies;\n}\n\nfrappe.palette = [\n\t['#FFC4C4', 0],\n\t['#FFE8CD', 0],\n\t['#FFD2C2', 0],\n\t['#FF8989', 0],\n\t['#FFD19C', 0],\n\t['#FFA685', 0],\n\t['#FF4D4D', 1],\n\t['#FFB868', 0],\n\t['#FF7846', 1],\n\t['#A83333', 1],\n\t['#A87945', 1],\n\t['#A84F2E', 1],\n\t['#D2D2FF', 0],\n\t['#F8D4F8', 0],\n\t['#DAC7FF', 0],\n\t['#A3A3FF', 0],\n\t['#F3AAF0', 0],\n\t['#B592FF', 0],\n\t['#7575FF', 0],\n\t['#EC7DEA', 0],\n\t['#8E58FF', 1],\n\t['#4D4DA8', 1],\n\t['#934F92', 1],\n\t['#5E3AA8', 1],\n\t['#EBF8CC', 0],\n\t['#FFD7D7', 0],\n\t['#D2F8ED', 0],\n\t['#D9F399', 0],\n\t['#FFB1B1', 0],\n\t['#A4F3DD', 0],\n\t['#C5EC63', 0],\n\t['#FF8989', 1],\n\t['#77ECCA', 0],\n\t['#7B933D', 1],\n\t['#A85B5B', 1],\n\t['#49937E', 1],\n\t['#FFFACD', 0],\n\t['#D2F1FF', 0],\n\t['#CEF6D1', 0],\n\t['#FFF69C', 0],\n\t['#A6E4FF', 0],\n\t['#9DECA2', 0],\n\t['#FFF168', 0],\n\t['#78D6FF', 0],\n\t['#6BE273', 0],\n\t['#A89F45', 1],\n\t['#4F8EA8', 1],\n\t['#428B46', 1]\n]\n\nfrappe.is_mobile = function() {\n\treturn $(document).width() < 768;\n}\n\nfrappe.utils.xss_sanitise = function (string, options) {\n\t// Reference - https://www.owasp.org/index.php/XSS_(Cross_Site_Scripting)_Prevention_Cheat_Sheet\n\tlet sanitised = string; // un-sanitised string.\n\tconst DEFAULT_OPTIONS = {\n\t\tstrategies: ['html', 'js'] // use all strategies.\n\t}\n\tconst HTML_ESCAPE_MAP = {\n\t\t'<': '<',\n\t\t'>': '>',\n\t\t'\"': '"',\n\t\t\"'\": ''',\n\t\t'/': '/'\n\t};\n\tconst REGEX_SCRIPT = /)<[^<]*)*<\\/script>/gi; // used in jQuery 1.7.2 src/ajax.js Line 14\n\toptions \t = Object.assign({ }, DEFAULT_OPTIONS, options); // don't deep copy, immutable beauty.\n\n\t// Rule 1\n\tif ( options.strategies.includes('html') ) {\n\t\tfor (let char in HTML_ESCAPE_MAP) {\n\t\t\tconst escape = HTML_ESCAPE_MAP[char];\n\t\t\tconst regex = new RegExp(char, \"g\");\n\t\t\tsanitised = sanitised.replace(regex, escape);\n\t\t}\n\t}\n\n\t// Rule 3 - TODO: Check event handlers?\n\tif ( options.strategies.includes('js') ) {\n\t\tsanitised = sanitised.replace(REGEX_SCRIPT, \"\");\n\t}\n\n\treturn sanitised;\n}\n\nfrappe.utils.new_auto_repeat_prompt = function(frm) {\n\tconst fields = [\n\t\t{\n\t\t\t'fieldname': 'frequency',\n\t\t\t'fieldtype': 'Select',\n\t\t\t'label': __('Frequency'),\n\t\t\t'reqd': 1,\n\t\t\t'options': [\n\t\t\t\t{'label': __('Daily'), 'value': 'Daily'},\n\t\t\t\t{'label': __('Weekly'), 'value': 'Weekly'},\n\t\t\t\t{'label': __('Monthly'), 'value': 'Monthly'},\n\t\t\t\t{'label': __('Quarterly'), 'value': 'Quarterly'},\n\t\t\t\t{'label': __('Half-yearly'), 'value': 'Half-yearly'},\n\t\t\t\t{'label': __('Yearly'), 'value': 'Yearly'}\n\t\t\t]\n\t\t},\n\t\t{\n\t\t\t'fieldname': 'start_date',\n\t\t\t'fieldtype': 'Date',\n\t\t\t'label': __('Start Date'),\n\t\t\t'reqd': 1,\n\t\t\t'default': frappe.datetime.nowdate()\n\t\t},\n\t\t{\n\t\t\t'fieldname': 'end_date',\n\t\t\t'fieldtype': 'Date',\n\t\t\t'label': __('End Date')\n\t\t}\n\t];\n\tfrappe.prompt(fields, function(values) {\n\t\tfrappe.call({\n\t\t\tmethod: \"frappe.automation.doctype.auto_repeat.auto_repeat.make_auto_repeat\",\n\t\t\targs: {\n\t\t\t\t'doctype': frm.doc.doctype,\n\t\t\t\t'docname': frm.doc.name,\n\t\t\t\t'frequency': values['frequency'],\n\t\t\t\t'start_date': values['start_date'],\n\t\t\t\t'end_date': values['end_date']\n\t\t\t},\n\t\t\tcallback: function (r) {\n\t\t\t\tif (r.message) {\n\t\t\t\t\tfrappe.show_alert({\n\t\t\t\t\t\t'message': __(\"Auto Repeat created for this document\"),\n\t\t\t\t\t\t'indicator': 'green'\n\t\t\t\t\t});\n\t\t\t\t\tfrm.reload_doc();\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\t},\n\t__('Auto Repeat'),\n\t__('Save')\n\t);\n}\n","import '../class';\n\nfrappe.ui.form.Layout = Class.extend({\n\tinit: function(opts) {\n\t\tthis.views = {};\n\t\tthis.pages = [];\n\t\tthis.sections = [];\n\t\tthis.fields_list = [];\n\t\tthis.fields_dict = {};\n\n\t\t$.extend(this, opts);\n\t},\n\tmake: function() {\n\t\tif(!this.parent && this.body) {\n\t\t\tthis.parent = this.body;\n\t\t}\n\t\tthis.wrapper = $('
').appendTo(this.parent);\n\t\tthis.message = $('
').appendTo(this.wrapper);\n\t\tif(!this.fields) {\n\t\t\tthis.fields = this.get_doctype_fields();\n\t\t}\n\t\tthis.setup_tabbing();\n\t\tthis.render();\n\t},\n\tshow_empty_form_message: function() {\n\t\tif(!(this.wrapper.find(\".frappe-control:visible\").length || this.wrapper.find(\".section-head.collapsed\").length)) {\n\t\t\tthis.show_message(__(\"This form does not have any input\"));\n\t\t}\n\t},\n\tget_doctype_fields: function() {\n\t\tlet fields = [\n\t\t\t{\n\t\t\t\tparent: this.frm.doctype,\n\t\t\t\tfieldtype: 'Data',\n\t\t\t\tfieldname: '__newname',\n\t\t\t\treqd: 1,\n\t\t\t\thidden: 1,\n\t\t\t\tlabel: __('Name'),\n\t\t\t\tget_status: function(field) {\n\t\t\t\t\tif (field.frm && field.frm.is_new()\n\t\t\t\t\t\t&& field.frm.meta.autoname\n\t\t\t\t\t\t&& ['prompt', 'name'].includes(field.frm.meta.autoname.toLowerCase())) {\n\t\t\t\t\t\treturn 'Write';\n\t\t\t\t\t}\n\t\t\t\t\treturn 'None';\n\t\t\t\t}\n\t\t\t}\n\t\t];\n\t\tfields = fields.concat(frappe.meta.sort_docfields(frappe.meta.docfield_map[this.doctype]));\n\t\treturn fields;\n\t},\n\tshow_message: function(html, color) {\n\t\tif (this.message_color) {\n\t\t\t// remove previous color\n\t\t\tthis.message.removeClass(this.message_color);\n\t\t}\n\t\tthis.message_color = (color && ['yellow', 'blue'].includes(color)) ? color : 'blue';\n\t\tif(html) {\n\t\t\tif(html.substr(0, 1)!=='<') {\n\t\t\t\t// wrap in a block\n\t\t\t\thtml = '
' + html + '
';\n\t\t\t}\n\t\t\tthis.message.removeClass('hidden').addClass(this.message_color);\n\t\t\t$(html).appendTo(this.message);\n\t\t} else {\n\t\t\tthis.message.empty().addClass('hidden');\n\t\t}\n\t},\n\trender: function(new_fields) {\n\t\tvar me = this;\n\t\tvar fields = new_fields || this.fields;\n\n\t\tthis.section = null;\n\t\tthis.column = null;\n\n\t\tif (this.with_dashboard) {\n\t\t\tthis.setup_dashboard_section();\n\t\t}\n\n\t\tif (this.no_opening_section()) {\n\t\t\tthis.make_section();\n\t\t}\n\t\t$.each(fields, function(i, df) {\n\t\t\tswitch(df.fieldtype) {\n\t\t\t\tcase \"Fold\":\n\t\t\t\t\tme.make_page(df);\n\t\t\t\t\tbreak;\n\t\t\t\tcase \"Section Break\":\n\t\t\t\t\tme.make_section(df);\n\t\t\t\t\tbreak;\n\t\t\t\tcase \"Column Break\":\n\t\t\t\t\tme.make_column(df);\n\t\t\t\t\tbreak;\n\t\t\t\tdefault:\n\t\t\t\t\tme.make_field(df);\n\t\t\t}\n\t\t});\n\n\t},\n\n\tno_opening_section: function() {\n\t\treturn (this.fields[0] && this.fields[0].fieldtype!=\"Section Break\") || !this.fields.length;\n\t},\n\n\tsetup_dashboard_section: function() {\n\t\tif (this.no_opening_section()) {\n\t\t\tthis.fields.unshift({fieldtype: 'Section Break'});\n\t\t}\n\n\t\tthis.fields.unshift({\n\t\t\tfieldtype: 'Section Break',\n\t\t\tfieldname: '_form_dashboard',\n\t\t\tlabel: __('Dashboard'),\n\t\t\tcssClass: 'form-dashboard',\n\t\t\tcollapsible: 1,\n\t\t\t// hidden: 1\n\t\t});\n\t},\n\n\treplace_field: function(fieldname, df, render) {\n\t\tdf.fieldname = fieldname; // change of fieldname is avoided\n\t\tif (this.fields_dict[fieldname] && this.fields_dict[fieldname].df) {\n\t\t\tconst fieldobj = this.init_field(df, render);\n\t\t\tthis.fields_dict[fieldname].$wrapper.remove();\n\t\t\tthis.fields_list.splice(this.fields_dict[fieldname], 1, fieldobj);\n\t\t\tthis.fields_dict[fieldname] = fieldobj;\n\t\t\tif (this.frm) {\n\t\t\t\tfieldobj.perm = this.frm.perm;\n\t\t\t}\n\t\t\tthis.section.fields_list.splice(this.section.fields_dict[fieldname], 1, fieldobj);\n\t\t\tthis.section.fields_dict[fieldname] = fieldobj;\n\t\t\tthis.refresh_fields([df]);\n\t\t}\n\t},\n\n\tmake_field: function(df, colspan, render) {\n\t\t!this.section && this.make_section();\n\t\t!this.column && this.make_column();\n\n\t\tconst fieldobj = this.init_field(df, render);\n\t\tthis.fields_list.push(fieldobj);\n\t\tthis.fields_dict[df.fieldname] = fieldobj;\n\t\tif(this.frm) {\n\t\t\tfieldobj.perm = this.frm.perm;\n\t\t}\n\n\t\tthis.section.fields_list.push(fieldobj);\n\t\tthis.section.fields_dict[df.fieldname] = fieldobj;\n\t\tfieldobj.section = this.section;\n\t},\n\n\tinit_field: function(df, render = false) {\n\t\tconst fieldobj = frappe.ui.form.make_control({\n\t\t\tdf: df,\n\t\t\tdoctype: this.doctype,\n\t\t\tparent: this.column.wrapper.get(0),\n\t\t\tfrm: this.frm,\n\t\t\trender_input: render,\n\t\t\tdoc: this.doc\n\t\t});\n\n\t\tfieldobj.layout = this;\n\t\treturn fieldobj;\n\t},\n\n\tmake_page: function(df) {\n\t\tvar me = this,\n\t\t\thead = $('
\\\n\t\t\t\t'+__(\"Show more details\")+'\\\n\t\t\t
').appendTo(this.wrapper);\n\n\t\tthis.page = $('
').appendTo(this.wrapper);\n\n\t\tthis.fold_btn = head.find(\".btn-fold\").on(\"click\", function() {\n\t\t\tvar page = $(this).parent().next();\n\t\t\tif(page.hasClass(\"hide\")) {\n\t\t\t\t$(this).removeClass(\"btn-fold\").html(__(\"Hide details\"));\n\t\t\t\tpage.removeClass(\"hide\");\n\t\t\t\tfrappe.utils.scroll_to($(this), true, 30);\n\t\t\t\tme.folded = false;\n\t\t\t} else {\n\t\t\t\t$(this).addClass(\"btn-fold\").html(__(\"Show more details\"));\n\t\t\t\tpage.addClass(\"hide\");\n\t\t\t\tme.folded = true;\n\t\t\t}\n\t\t});\n\n\t\tthis.section = null;\n\t\tthis.folded = true;\n\t},\n\n\tunfold: function() {\n\t\tthis.fold_btn.trigger('click');\n\t},\n\n\tmake_section: function(df) {\n\t\tthis.section = new frappe.ui.form.Section(this, df);\n\n\t\t// append to layout fields\n\t\tif(df) {\n\t\t\tthis.fields_dict[df.fieldname] = this.section;\n\t\t\tthis.fields_list.push(this.section);\n\t\t}\n\n\t\tthis.column = null;\n\t},\n\n\tmake_column: function(df) {\n\t\tthis.column = new frappe.ui.form.Column(this.section, df);\n\t\tif(df && df.fieldname) {\n\t\t\tthis.fields_list.push(this.column);\n\t\t}\n\t},\n\n\trefresh: function(doc) {\n\t\tvar me = this;\n\t\tif(doc) this.doc = doc;\n\n\t\tif (this.frm) {\n\t\t\tthis.wrapper.find(\".empty-form-alert\").remove();\n\t\t}\n\n\t\t// NOTE this might seem redundant at first, but it needs to be executed when frm.refresh_fields is called\n\t\tme.attach_doc_and_docfields(true);\n\n\t\tif(this.frm && this.frm.wrapper) {\n\t\t\t$(this.frm.wrapper).trigger(\"refresh-fields\");\n\t\t}\n\n\t\t// dependent fields\n\t\tthis.refresh_dependency();\n\n\t\t// refresh sections\n\t\tthis.refresh_sections();\n\n\t\t// collapse sections\n\t\tif(this.frm) {\n\t\t\tthis.refresh_section_collapse();\n\t\t}\n\t},\n\n\trefresh_sections: function() {\n\t\tvar cnt = 0;\n\n\t\t// hide invisible sections and set alternate background color\n\t\tthis.wrapper.find(\".form-section:not(.hide-control)\").each(function() {\n\t\t\tvar $this = $(this).removeClass(\"empty-section\")\n\t\t\t\t.removeClass(\"visible-section\")\n\t\t\t\t.removeClass(\"shaded-section\");\n\t\t\tif(!$this.find(\".frappe-control:not(.hide-control)\").length\n\t\t\t\t&& !$this.hasClass('form-dashboard')) {\n\t\t\t\t// nothing visible, hide the section\n\t\t\t\t$this.addClass(\"empty-section\");\n\t\t\t} else {\n\t\t\t\t$this.addClass(\"visible-section\");\n\t\t\t\tif(cnt % 2) {\n\t\t\t\t\t$this.addClass(\"shaded-section\");\n\t\t\t\t}\n\t\t\t\tcnt++;\n\t\t\t}\n\t\t});\n\t},\n\n\trefresh_fields: function(fields) {\n\t\tlet fieldnames = fields.map((field) => {\n\t\t\tif(field.fieldname) return field.fieldname;\n\t\t});\n\n\t\tthis.fields_list.map(fieldobj => {\n\t\t\tif(fieldnames.includes(fieldobj.df.fieldname)) {\n\t\t\t\tfieldobj.refresh();\n\t\t\t\tif(fieldobj.df[\"default\"]) {\n\t\t\t\t\tfieldobj.set_input(fieldobj.df[\"default\"]);\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\t},\n\n\tadd_fields: function(fields) {\n\t\tthis.render(fields);\n\t\tthis.refresh_fields(fields);\n\t},\n\n\trefresh_section_collapse: function() {\n\t\tif(!this.doc) return;\n\n\t\tfor(var i=0; i=0;i--) {\n\t\t\tvar f = me.fields_list[i];\n\t\t\tf.guardian_has_value = true;\n\t\t\tif(f.df.depends_on) {\n\t\t\t\t// evaluate guardian\n\n\t\t\t\tf.guardian_has_value = this.evaluate_depends_on_value(f.df.depends_on);\n\n\t\t\t\t// show / hide\n\t\t\t\tif(f.guardian_has_value) {\n\t\t\t\t\tif(f.df.hidden_due_to_dependency) {\n\t\t\t\t\t\tf.df.hidden_due_to_dependency = false;\n\t\t\t\t\t\tf.refresh();\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tif(!f.df.hidden_due_to_dependency) {\n\t\t\t\t\t\tf.df.hidden_due_to_dependency = true;\n\t\t\t\t\t\tf.refresh();\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tthis.refresh_section_count();\n\t},\n\tevaluate_depends_on_value: function(expression) {\n\t\tvar out = null;\n\t\tvar doc = this.doc;\n\n\t\tif (!doc && this.get_values) {\n\t\t\tvar doc = this.get_values(true);\n\t\t}\n\n\t\tif (!doc) {\n\t\t\treturn;\n\t\t}\n\n\t\tvar parent = this.frm ? this.frm.doc : this.doc || null;\n\n\t\tif(typeof(expression) === 'boolean') {\n\t\t\tout = expression;\n\n\t\t} else if(typeof(expression) === 'function') {\n\t\t\tout = expression(doc);\n\n\t\t} else if(expression.substr(0,5)=='eval:') {\n\t\t\ttry {\n\t\t\t\tout = eval(expression.substr(5));\n\t\t\t\tif(parent && parent.istable && expression.includes('is_submittable')) {\n\t\t\t\t\tout = true;\n\t\t\t\t}\n\t\t\t} catch(e) {\n\t\t\t\tfrappe.throw(__('Invalid \"depends_on\" expression'));\n\t\t\t}\n\n\t\t} else if(expression.substr(0,3)=='fn:' && this.frm) {\n\t\t\tout = this.frm.script_manager.trigger(expression.substr(3), this.doctype, this.docname);\n\t\t} else {\n\t\t\tvar value = doc[expression];\n\t\t\tif($.isArray(value)) {\n\t\t\t\tout = !!value.length;\n\t\t\t} else {\n\t\t\t\tout = !!value;\n\t\t\t}\n\t\t}\n\n\t\treturn out;\n\t}\n});\n\nfrappe.ui.form.Section = Class.extend({\n\tinit: function(layout, df) {\n\t\tvar me = this;\n\t\tthis.layout = layout;\n\t\tthis.df = df || {};\n\t\tthis.fields_list = [];\n\t\tthis.fields_dict = {};\n\n\t\tthis.make();\n\t\t// if(this.frm)\n\t\t// \tthis.section.body.css({\"padding\":\"0px 3%\"})\n\t\tthis.row = {\n\t\t\twrapper: this.wrapper\n\t\t};\n\n\t\tif (this.df.collapsible && this.df.fieldname !== '_form_dashboard') {\n\t\t\tthis.collapse(true);\n\t\t}\n\n\t\tthis.refresh();\n\t},\n\tmake: function() {\n\t\tif(!this.layout.page) {\n\t\t\tthis.layout.page = $('
').appendTo(this.layout.wrapper);\n\t\t}\n\n\t\tthis.wrapper = $('
')\n\t\t\t.appendTo(this.layout.page);\n\t\tthis.layout.sections.push(this);\n\n\t\tif(this.df) {\n\t\t\tif(this.df.label) {\n\t\t\t\tthis.make_head();\n\t\t\t}\n\t\t\tif(this.df.description) {\n\t\t\t\t$('
' + __(this.df.description) + '
')\n\t\t\t\t\t.appendTo(this.wrapper);\n\t\t\t}\n\t\t\tif(this.df.cssClass) {\n\t\t\t\tthis.wrapper.addClass(this.df.cssClass);\n\t\t\t}\n\t\t}\n\n\n\t\t// for bc\n\t\tthis.body = $('
').appendTo(this.wrapper);\n\t},\n\tmake_head: function() {\n\t\tvar me = this;\n\t\tif(!this.df.collapsible) {\n\t\t\t$('
'\n\t\t\t\t+ __(this.df.label) + '
')\n\t\t\t\t.appendTo(this.wrapper);\n\t\t} else {\n\t\t\tthis.head = $('').appendTo(this.wrapper);\n\n\t\t\t// show / hide based on status\n\t\t\tthis.collapse_link = this.head.on(\"click\", function() {\n\t\t\t\tme.collapse();\n\t\t\t});\n\n\t\t\tthis.indicator = this.head.find(\".collapse-indicator\");\n\t\t}\n\t},\n\trefresh: function() {\n\t\tif(!this.df)\n\t\t\treturn;\n\n\t\t// hide if explictly hidden\n\t\tvar hide = this.df.hidden || this.df.hidden_due_to_dependency;\n\n\t\t// hide if no perm\n\t\tif(!hide && this.layout && this.layout.frm && !this.layout.frm.get_perm(this.df.permlevel || 0, \"read\")) {\n\t\t\thide = true;\n\t\t}\n\n\t\tthis.wrapper.toggleClass(\"hide-control\", !!hide);\n\t},\n\tcollapse: function(hide) {\n\t\t// unknown edge case\n\t\tif (!(this.head && this.body)) {\n\t\t\treturn;\n\t\t}\n\n\t\tif(hide===undefined) {\n\t\t\thide = !this.body.hasClass(\"hide\");\n\t\t}\n\n\t\tif (this.df.fieldname==='_form_dashboard') {\n\t\t\tlocalStorage.setItem('collapseFormDashboard', hide ? 'yes' : 'no');\n\t\t}\n\n\t\tthis.body.toggleClass(\"hide\", hide);\n\t\tthis.head.toggleClass(\"collapsed\", hide);\n\t\tthis.indicator.toggleClass(\"octicon-chevron-down\", hide);\n\t\tthis.indicator.toggleClass(\"octicon-chevron-up\", !hide);\n\n\t\t// refresh signature fields\n\t\tthis.fields_list.forEach((f) => {\n\t\t\tif (f.df.fieldtype=='Signature') {\n\t\t\t\tf.refresh();\n\t\t\t}\n\t\t});\n\t},\n\tis_collapsed() {\n\t\treturn this.body.hasClass('hide');\n\t},\n\thas_missing_mandatory: function() {\n\t\tvar missing_mandatory = false;\n\t\tfor (var j=0, l=this.fields_list.length; j < l; j++) {\n\t\t\tvar section_df = this.fields_list[j].df;\n\t\t\tif (section_df.reqd && this.layout.doc[section_df.fieldname]==null) {\n\t\t\t\tmissing_mandatory = true;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\treturn missing_mandatory;\n\t}\n});\n\nfrappe.ui.form.Column = Class.extend({\n\tinit: function(section, df) {\n\t\tif(!df) df = {};\n\n\t\tthis.df = df;\n\t\tthis.section = section;\n\t\tthis.make();\n\t\tthis.resize_all_columns();\n\t},\n\tmake: function() {\n\t\tthis.wrapper = $('
\\\n\t\t\t
\\\n\t\t\t
\\\n\t\t
').appendTo(this.section.body)\n\t\t\t.find(\"form\")\n\t\t\t.on(\"submit\", function() {\n\t\t\t\treturn false;\n\t\t\t});\n\n\t\tif (this.df.label) {\n\t\t\t$('').appendTo(this.wrapper);\n\t\t}\n\t},\n\tresize_all_columns: function() {\n\t\t// distribute all columns equally\n\t\tvar colspan = cint(12 / this.section.wrapper.find(\".form-column\").length);\n\n\t\tthis.section.wrapper.find(\".form-column\").removeClass()\n\t\t\t.addClass(\"form-column\")\n\t\t\t.addClass(\"col-sm-\" + colspan);\n\n\t},\n\trefresh: function() {\n\t\tthis.section.refresh();\n\t}\n});\n","import '../form/layout';\n\nfrappe.provide('frappe.ui');\n\nfrappe.ui.FieldGroup = frappe.ui.form.Layout.extend({\n\tinit: function(opts) {\n\t\t$.extend(this, opts);\n\t\tthis.dirty = false;\n\t\tthis._super();\n\t\t$.each(this.fields || [], function(i, f) {\n\t\t\tif(!f.fieldname && f.label) {\n\t\t\t\tf.fieldname = f.label.replace(/ /g, \"_\").toLowerCase();\n\t\t\t}\n\t\t})\n\t\tif(this.values) {\n\t\t\tthis.set_values(this.values);\n\t\t}\n\t},\n\tmake: function() {\n\t\tvar me = this;\n\t\tif(this.fields) {\n\t\t\tthis._super();\n\t\t\tthis.refresh();\n\t\t\t// set default\n\t\t\t$.each(this.fields_list, function(i, field) {\n\t\t\t\tif (field.df[\"default\"]) {\n\t\t\t\t\tlet def_value = field.df[\"default\"];\n\n\t\t\t\t\tif (def_value == 'Today' && field.df[\"fieldtype\"] == 'Date') {\n\t\t\t\t\t\tdef_value = frappe.datetime.get_today();\n\t\t\t\t\t}\n\n\t\t\t\t\tfield.set_input(def_value);\n\t\t\t\t\t// if default and has depends_on, render its fields.\n\t\t\t\t\tme.refresh_dependency();\n\t\t\t\t}\n\t\t\t})\n\n\t\t\tif(!this.no_submit_on_enter) {\n\t\t\t\tthis.catch_enter_as_submit();\n\t\t\t}\n\n\t\t\t$(this.wrapper).find('input, select').on('change', () => {\n\t\t\t\tthis.dirty = true;\n\n\t\t\t\tfrappe.run_serially([\n\t\t\t\t\t() => frappe.timeout(0.1),\n\t\t\t\t\t() => me.refresh_dependency()\n\t\t\t\t]);\n\t\t\t});\n\n\t\t}\n\t},\n\tfirst_button: false,\n\tfocus_on_first_input: function() {\n\t\tif(this.no_focus) return;\n\t\t$.each(this.fields_list, function(i, f) {\n\t\t\tif(!in_list(['Date', 'Datetime', 'Time', 'Check'], f.df.fieldtype) && f.set_focus) {\n\t\t\t\tf.set_focus();\n\t\t\t\treturn false;\n\t\t\t}\n\t\t});\n\t},\n\tcatch_enter_as_submit: function() {\n\t\tvar me = this;\n\t\t$(this.body).find('input[type=\"text\"], input[type=\"password\"], select').keypress(function(e) {\n\t\t\tif(e.which==13) {\n\t\t\t\tif(me.has_primary_action) {\n\t\t\t\t\te.preventDefault();\n\t\t\t\t\tme.get_primary_btn().trigger(\"click\");\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\t},\n\tget_input: function(fieldname) {\n\t\tvar field = this.fields_dict[fieldname];\n\t\treturn $(field.txt ? field.txt : field.input);\n\t},\n\tget_field: function(fieldname) {\n\t\treturn this.fields_dict[fieldname];\n\t},\n\tget_values: function(ignore_errors) {\n\t\tvar ret = {};\n\t\tvar errors = [];\n\t\tfor(var key in this.fields_dict) {\n\t\t\tvar f = this.fields_dict[key];\n\t\t\tif(f.get_value) {\n\t\t\t\tvar v = f.get_value();\n\t\t\t\tif(f.df.reqd && is_null(v))\n\t\t\t\t\terrors.push(__(f.df.label));\n\n\t\t\t\tif(!is_null(v)) ret[f.df.fieldname] = v;\n\t\t\t}\n\t\t}\n\t\tif(errors.length && !ignore_errors) {\n\t\t\tfrappe.msgprint({\n\t\t\t\ttitle: __('Missing Values Required'),\n\t\t\t\tmessage: __('Following fields have missing values:') +\n\t\t\t\t\t'

  • ' + errors.join('
  • ') + '
',\n\t\t\t\tindicator: 'orange'\n\t\t\t});\n\t\t\treturn null;\n\t\t}\n\t\treturn ret;\n\t},\n\tget_value: function(key) {\n\t\tvar f = this.fields_dict[key];\n\t\treturn f && (f.get_value ? f.get_value() : null);\n\t},\n\tset_value: function(key, val){\n\t\treturn new Promise(resolve => {\n\t\t\tvar f = this.fields_dict[key];\n\t\t\tif(f) {\n\t\t\t\tf.set_value(val).then(() => {\n\t\t\t\t\tf.set_input(val);\n\t\t\t\t\tthis.refresh_dependency();\n\t\t\t\t\tresolve();\n\t\t\t\t});\n\t\t\t} else {\n\t\t\t\tresolve();\n\t\t\t}\n\t\t});\n\t},\n\tset_input: function(key, val) {\n\t\treturn this.set_value(key, val);\n\t},\n\tset_values: function(dict) {\n\t\tfor(var key in dict) {\n\t\t\tif(this.fields_dict[key]) {\n\t\t\t\tthis.set_value(key, dict[key]);\n\t\t\t}\n\t\t}\n\t},\n\tclear: function() {\n\t\tfor(var key in this.fields_dict) {\n\t\t\tvar f = this.fields_dict[key];\n\t\t\tif(f && f.set_input) {\n\t\t\t\tf.set_input(f.df['default'] || '');\n\t\t\t}\n\t\t}\n\t},\n\tset_df_property: function (fieldname, prop, value) {\n\t\tconst field = this.get_field(fieldname);\n\t\tfield.df[prop] = value;\n\t\tfield.refresh();\n\t}\n});\n","// Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors\n// MIT License. See license.txt\n\n// add a new dom element\nfrappe.provide('frappe.dom');\n\nfrappe.dom = {\n\tid_count: 0,\n\tfreeze_count: 0,\n\tby_id: function(id) {\n\t\treturn document.getElementById(id);\n\t},\n\tget_unique_id: function() {\n\t\tconst id = 'unique-' + frappe.dom.id_count;\n\t\tfrappe.dom.id_count++;\n\t\treturn id;\n\t},\n\tset_unique_id: function(ele) {\n\t\tvar $ele = $(ele);\n\t\tif($ele.attr('id')) {\n\t\t\treturn $ele.attr('id');\n\t\t}\n\t\tvar id = 'unique-' + frappe.dom.id_count;\n\t\t$ele.attr('id', id);\n\t\tfrappe.dom.id_count++;\n\t\treturn id;\n\t},\n\teval: function(txt) {\n\t\tif(!txt) return;\n\t\tvar el = document.createElement('script');\n\t\tel.appendChild(document.createTextNode(txt));\n\t\t// execute the script globally\n\t\tdocument.getElementsByTagName('head')[0].appendChild(el);\n\t},\n\tremove_script_and_style: function(txt) {\n\t\tconst evil_tags = [\"script\", \"style\", \"noscript\", \"title\", \"meta\", \"base\", \"head\"];\n\t\tconst regex = new RegExp(evil_tags.map(tag => `<${tag}>.*<\\\\/${tag}>`).join('|'));\n\t\tif (!regex.test(txt)) {\n\t\t\t// no evil tags found, skip the DOM method entirely!\n\t\t\treturn txt;\n\t\t}\n\n\t\tvar div = document.createElement('div');\n\t\tdiv.innerHTML = txt;\n\t\tvar found = false;\n\t\tevil_tags.forEach(function(e) {\n\t\t\tvar elements = div.getElementsByTagName(e);\n\t\t\ti = elements.length;\n\t\t\twhile (i--) {\n\t\t\t\tfound = true;\n\t\t\t\telements[i].parentNode.removeChild(elements[i]);\n\t\t\t}\n\t\t});\n\n\t\t// remove links with rel=\"stylesheet\"\n\t\tvar elements = div.getElementsByTagName('link');\n\t\tvar i = elements.length;\n\t\twhile (i--) {\n\t\t\tif (elements[i].getAttribute(\"rel\")==\"stylesheet\"){\n\t\t\t\tfound = true;\n\t\t\t\telements[i].parentNode.removeChild(elements[i]);\n\t\t\t}\n\t\t}\n\t\tif(found) {\n\t\t\treturn div.innerHTML;\n\t\t} else {\n\t\t\t// don't disturb\n\t\t\treturn txt;\n\t\t}\n\t},\n\tis_element_in_viewport: function (el, tolerance=0) {\n\n\t\t//special bonus for those using jQuery\n\t\tif (typeof jQuery === \"function\" && el instanceof jQuery) {\n\t\t\tel = el[0];\n\t\t}\n\n\t\tvar rect = el.getBoundingClientRect();\n\n\t\treturn (\n\t\t\trect.top + tolerance >= 0\n\t\t\t&& rect.left + tolerance >= 0\n\t\t\t&& rect.bottom - tolerance <= $(window).height()\n\t\t\t&& rect.right - tolerance <= $(window).width()\n\t\t);\n\t},\n\n\tset_style: function(txt, id) {\n\t\tif(!txt) return;\n\n\t\tvar se = document.createElement('style');\n\t\tse.type = \"text/css\";\n\n\t\tif (id) {\n\t\t\tvar element = document.getElementById(id);\n\t\t\tif (element) {\n\t\t\t\telement.parentNode.removeChild(element);\n\t\t\t}\n\t\t\tse.id = id;\n\t\t}\n\n\t\tif (se.styleSheet) {\n\t\t\tse.styleSheet.cssText = txt;\n\t\t} else {\n\t\t\tse.appendChild(document.createTextNode(txt));\n\t\t}\n\t\tdocument.getElementsByTagName('head')[0].appendChild(se);\n\t\treturn se;\n\t},\n\tadd: function(parent, newtag, className, cs, innerHTML, onclick) {\n\t\tif(parent && parent.substr)parent = frappe.dom.by_id(parent);\n\t\tvar c = document.createElement(newtag);\n\t\tif(parent)\n\t\t\tparent.appendChild(c);\n\n\t\t// if image, 3rd parameter is source\n\t\tif(className) {\n\t\t\tif(newtag.toLowerCase()=='img')\n\t\t\t\tc.src = className\n\t\t\telse\n\t\t\t\tc.className = className;\n\t\t}\n\t\tif(cs) frappe.dom.css(c,cs);\n\t\tif(innerHTML) c.innerHTML = innerHTML;\n\t\tif(onclick) c.onclick = onclick;\n\t\treturn c;\n\t},\n\tcss: function(ele, s) {\n\t\tif(ele && s) {\n\t\t\t$.extend(ele.style, s);\n\t\t}\n\t\treturn ele;\n\t},\n\tactivate: function($parent, $child, common_class, active_class='active') {\n\t\t$parent.find(`.${common_class}.${active_class}`)\n\t\t\t.removeClass(active_class);\n\t\t$child.addClass(active_class);\n\t},\n\tfreeze: function(msg, css_class) {\n\t\t// blur\n\t\tif(!$('#freeze').length) {\n\t\t\tvar freeze = $('
')\n\t\t\t\t.on(\"click\", function() {\n\t\t\t\t\tif (cur_frm && cur_frm.cur_grid) {\n\t\t\t\t\t\tcur_frm.cur_grid.toggle_view();\n\t\t\t\t\t\treturn false;\n\t\t\t\t\t}\n\t\t\t\t})\n\t\t\t\t.appendTo(\"#body_div\");\n\n\t\t\tfreeze.html(repl('

%(msg)s

',\n\t\t\t\t{msg: msg || \"\"}));\n\n\t\t\tsetTimeout(function() { freeze.addClass(\"in\") }, 1);\n\n\t\t} else {\n\t\t\t$(\"#freeze\").addClass(\"in\");\n\t\t}\n\n\t\tif (css_class) {\n\t\t\t$(\"#freeze\").addClass(css_class);\n\t\t}\n\n\t\tfrappe.dom.freeze_count++;\n\t},\n\tunfreeze: function() {\n\t\tif(!frappe.dom.freeze_count) return; // anything open?\n\t\tfrappe.dom.freeze_count--;\n\t\tif(!frappe.dom.freeze_count) {\n\t\t\tvar freeze = $('#freeze').removeClass(\"in\").remove();\n\t\t}\n\t},\n\tsave_selection: function() {\n\t\t// via http://stackoverflow.com/questions/5605401/insert-link-in-contenteditable-element\n\t\tif (window.getSelection) {\n\t\t\tvar sel = window.getSelection();\n\t\t\tif (sel.getRangeAt && sel.rangeCount) {\n\t\t\t\tvar ranges = [];\n\t\t\t\tfor (var i = 0, len = sel.rangeCount; i < len; ++i) {\n\t\t\t\t\tranges.push(sel.getRangeAt(i));\n\t\t\t\t}\n\t\t\t\treturn ranges;\n\t\t\t}\n\t\t} else if (document.selection && document.selection.createRange) {\n\t\t\treturn document.selection.createRange();\n\t\t}\n\t\treturn null;\n\t},\n\trestore_selection: function(savedSel) {\n\t\tif (savedSel) {\n\t\t\tif (window.getSelection) {\n\t\t\t\tvar sel = window.getSelection();\n\t\t\t\tsel.removeAllRanges();\n\t\t\t\tfor (var i = 0, len = savedSel.length; i < len; ++i) {\n\t\t\t\t\tsel.addRange(savedSel[i]);\n\t\t\t\t}\n\t\t\t} else if (document.selection && savedSel.select) {\n\t\t\t\tsavedSel.select();\n\t\t\t}\n\t\t}\n\t},\n\tis_touchscreen: function() {\n\t\treturn ('ontouchstart' in window)\n\t},\n\thandle_broken_images(container) {\n\t\t$(container).find('img').on('error', (e) => {\n\t\t\tconst $img = $(e.currentTarget);\n\t\t\t$img.addClass('no-image');\n\t\t});\n\t},\n\tscroll_to_bottom(container) {\n\t\tconst $container = $(container);\n\t\t$container.scrollTop($container[0].scrollHeight);\n\t},\n\tfile_to_base64(file_obj) {\n\t\treturn new Promise(resolve => {\n\t\t\tconst reader = new FileReader();\n\t\t\treader.onload = function() {\n\t\t\t\tresolve(reader.result);\n\t\t\t};\n\t\t\treader.readAsDataURL(file_obj);\n\t\t});\n\t},\n\tscroll_to_section(section_name) {\n\t\tsetTimeout(() => {\n\t\t\tconst section = $(`a:contains(\"${section_name}\")`);\n\t\t\tif (section.length) {\n\t\t\t\tif(section.parent().hasClass('collapsed')) {\n\t\t\t\t\t// opens the section\n\t\t\t\t\tsection.click();\n\t\t\t\t}\n\t\t\t\tfrappe.ui.scroll(section.parent().parent());\n\t\t\t}\n\t\t}, 200);\n\t},\n\tpixel_to_inches(pixels) {\n\t\tconst div = $('
');\n\t\tdiv.appendTo(document.body);\n\n\t\tconst dpi_x = document.getElementById('dpi').offsetWidth;\n\t\tconst inches = pixels / dpi_x;\n\t\tdiv.remove();\n\n\t\treturn inches;\n\t}\n};\n\nfrappe.ellipsis = function(text, max) {\n\tif(!max) max = 20;\n\ttext = cstr(text);\n\tif(text.length > max) {\n\t\ttext = text.substr(0, max) + '...';\n\t}\n\treturn text;\n};\n\nfrappe.run_serially = function(tasks) {\n\tvar result = Promise.resolve();\n\ttasks.forEach(task => {\n\t\tif(task) {\n\t\t\tresult = result.then ? result.then(task) : Promise.resolve();\n\t\t}\n\t});\n\treturn result;\n};\n\nfrappe.load_image = (src, onload, onerror, preprocess = () => {}) => {\n\tvar tester = new Image();\n\ttester.onload = function() {\n\t\tonload(this);\n\t};\n\ttester.onerror = onerror;\n\n\tpreprocess(tester);\n\ttester.src = src;\n}\n\nfrappe.timeout = seconds => {\n\treturn new Promise((resolve) => {\n\t\tsetTimeout(() => resolve(), seconds * 1000);\n\t});\n};\n\nfrappe.scrub = function(text, spacer='_') {\n\treturn text.replace(/ /g, spacer).toLowerCase();\n};\n\nfrappe.get_modal = function(title, content) {\n\treturn $(`
\n\t\t
\n\t\t\t
\n\t\t\t\t
\n\t\t\t\t\t
\n\t\t\t\t\t\t
\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t

${title}

\n\t\t\t\t\t\t
\n\t\t\t\t\t\t
\n\t\t\t\t\t\t\t
\n\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t
\n\t\t\t\t\t\t
\n\t\t\t\t\t
\n\t\t\t\t
\n\t\t\t\t
${content}
\n\t\t\t
\n\t\t
\n\t
`);\n};\n\nfrappe.is_online = function() {\n\tif (frappe.boot.developer_mode == 1) {\n\t\t// always online in developer_mode\n\t\treturn true;\n\t}\n\tif ('onLine' in navigator) {\n\t\treturn navigator.onLine;\n\t}\n\treturn true;\n};\n\n// bind online/offline events\n$(window).on('online', function() {\n\tfrappe.show_alert({\n\t\tindicator: 'green',\n\t\tmessage: __('You are connected to internet.')\n\t});\n});\n\n$(window).on('offline', function() {\n\tfrappe.show_alert({\n\t\tindicator: 'orange',\n\t\tmessage: __('Connection lost. Some features might not work.')\n\t});\n});\n","\nimport './field_group';\nimport '../dom';\n\nfrappe.provide('frappe.ui');\n\nwindow.cur_dialog = null;\n\nfrappe.ui.open_dialogs = [];\n\nfrappe.ui.Dialog = class Dialog extends frappe.ui.FieldGroup {\n\tconstructor(opts) {\n\t\tsuper();\n\t\tthis.display = false;\n\t\tthis.is_dialog = true;\n\n\t\t$.extend(this, { animate: true, size: null }, opts);\n\t\tthis.make();\n\t}\n\n\tmake() {\n\t\tthis.$wrapper = frappe.get_modal(\"\", \"\");\n\n\t\tif(this.static) {\n\t\t\tthis.$wrapper.modal({\n\t\t\t\tbackdrop: 'static',\n\t\t\t\tkeyboard: false\n\t\t\t});\n\t\t\tthis.get_close_btn().hide();\n\t\t}\n\n\t\tthis.wrapper = this.$wrapper.find('.modal-dialog')\n\t\t\t.get(0);\n\t\tif ( this.size == \"small\" )\n\t\t\t$(this.wrapper).addClass(\"modal-sm\");\n\t\telse if ( this.size == \"large\" )\n\t\t\t$(this.wrapper).addClass(\"modal-lg\");\n\n\t\tthis.make_head();\n\t\tthis.modal_body = this.$wrapper.find(\".modal-body\");\n\t\tthis.$body = $('
').appendTo(this.modal_body);\n\t\tthis.body = this.$body.get(0);\n\t\tthis.$message = $('
').appendTo(this.modal_body);\n\t\tthis.header = this.$wrapper.find(\".modal-header\");\n\t\tthis.buttons = this.header.find('.buttons');\n\t\tthis.set_indicator();\n\n\t\t// make fields (if any)\n\t\tsuper.make();\n\n\t\t// show footer\n\t\tthis.action = this.action || { primary: { }, secondary: { } };\n\t\tif(this.primary_action || (this.action.primary && this.action.primary.onsubmit)) {\n\t\t\tthis.set_primary_action(this.primary_action_label || this.action.primary.label || __(\"Submit\"),\n\t\t\t\tthis.primary_action || this.action.primary.onsubmit);\n\t\t}\n\n\t\tif(this.secondary_action) {\n\t\t\tthis.set_secondary_action(this.secondary_action);\n\t\t}\n\n\t\tif (this.secondary_action_label || (this.action.secondary && this.action.secondary.label)) {\n\t\t\tthis.get_close_btn().html(this.secondary_action_label || this.action.secondary.label);\n\t\t}\n\n\t\tif (this.minimizable) {\n\t\t\tthis.header.find('.modal-title').click(() => this.toggle_minimize());\n\t\t\tthis.get_minimize_btn().removeClass('hide').on('click', () => this.toggle_minimize());\n\t\t}\n\n\t\tvar me = this;\n\t\tthis.$wrapper\n\t\t\t.on(\"hide.bs.modal\", function() {\n\t\t\t\tme.display = false;\n\t\t\t\tme.secondary_action && me.secondary_action();\n\n\t\t\t\tif(frappe.ui.open_dialogs[frappe.ui.open_dialogs.length-1]===me) {\n\t\t\t\t\tfrappe.ui.open_dialogs.pop();\n\t\t\t\t\tif(frappe.ui.open_dialogs.length) {\n\t\t\t\t\t\twindow.cur_dialog = frappe.ui.open_dialogs[frappe.ui.open_dialogs.length-1];\n\t\t\t\t\t} else {\n\t\t\t\t\t\twindow.cur_dialog = null;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tme.onhide && me.onhide();\n\t\t\t\tme.on_hide && me.on_hide();\n\t\t\t})\n\t\t\t.on(\"shown.bs.modal\", function() {\n\t\t\t\t// focus on first input\n\t\t\t\tme.display = true;\n\t\t\t\twindow.cur_dialog = me;\n\t\t\t\tfrappe.ui.open_dialogs.push(me);\n\t\t\t\tme.focus_on_first_input();\n\t\t\t\tme.on_page_show && me.on_page_show();\n\t\t\t\t$(document).trigger('frappe.ui.Dialog:shown');\n\t\t\t})\n\t\t\t.on('scroll', function() {\n\t\t\t\tvar $input = $('input:focus');\n\t\t\t\tif($input.length && ['Date', 'Datetime', 'Time'].includes($input.attr('data-fieldtype'))) {\n\t\t\t\t\t$input.blur();\n\t\t\t\t}\n\t\t\t});\n\n\t}\n\n\tget_primary_btn() {\n\t\treturn this.$wrapper.find(\".modal-header .btn-primary\");\n\t}\n\n\tget_minimize_btn() {\n\t\treturn this.$wrapper.find(\".modal-header .btn-modal-minimize\");\n\t}\n\n\tset_message(text) {\n\t\tthis.$message.removeClass('hide');\n\t\tthis.$body.addClass('hide');\n\t\tthis.$message.text(text);\n\t}\n\n\tclear_message() {\n\t\tthis.$message.addClass('hide');\n\t\tthis.$body.removeClass('hide');\n\t}\n\n\tclear() {\n\t\tsuper.clear();\n\t\tthis.clear_message();\n\t}\n\n\tset_primary_action(label, click) {\n\t\tthis.has_primary_action = true;\n\t\tvar me = this;\n\t\treturn this.get_primary_btn()\n\t\t\t.removeClass(\"hide\")\n\t\t\t.html(label)\n\t\t\t.click(function() {\n\t\t\t\tme.primary_action_fulfilled = true;\n\t\t\t\t// get values and send it\n\t\t\t\t// as first parameter to click callback\n\t\t\t\t// if no values then return\n\t\t\t\tvar values = me.get_values();\n\t\t\t\tif(!values) return;\n\t\t\t\tclick && click.apply(me, [values]);\n\t\t\t});\n\t}\n\n\tset_secondary_action(click) {\n\t\tthis.get_close_btn().on('click', click);\n\t}\n\n\tdisable_primary_action() {\n\t\tthis.get_primary_btn().addClass('disabled');\n\t}\n\tenable_primary_action() {\n\t\tthis.get_primary_btn().removeClass('disabled');\n\t}\n\tmake_head() {\n\t\tthis.set_title(this.title);\n\t}\n\tset_title(t) {\n\t\tthis.$wrapper.find(\".modal-title\").html(t);\n\t}\n\tset_indicator() {\n\t\tif (this.indicator) {\n\t\t\tthis.header.find('.indicator').removeClass().addClass('indicator ' + this.indicator);\n\t\t}\n\t}\n\tshow() {\n\t\t// show it\n\t\tif ( this.animate ) {\n\t\t\tthis.$wrapper.addClass('fade');\n\t\t} else {\n\t\t\tthis.$wrapper.removeClass('fade');\n\t\t}\n\t\tthis.$wrapper.modal(\"show\");\n\n\t\t// clear any message\n\t\tthis.clear_message();\n\n\t\tthis.primary_action_fulfilled = false;\n\t\tthis.is_visible = true;\n\t\treturn this;\n\t}\n\thide() {\n\t\tthis.$wrapper.modal(\"hide\");\n\t\tthis.is_visible = false;\n\t}\n\tget_close_btn() {\n\t\treturn this.$wrapper.find(\".btn-modal-close\");\n\t}\n\tno_cancel() {\n\t\tthis.get_close_btn().toggle(false);\n\t}\n\tcancel() {\n\t\tthis.get_close_btn().trigger(\"click\");\n\t}\n\ttoggle_minimize() {\n\t\tlet modal = this.$wrapper.closest('.modal').toggleClass('modal-minimize');\n\t\tmodal.attr('tabindex') ? modal.removeAttr('tabindex') : modal.attr('tabindex', -1);\n\t\tthis.get_minimize_btn().find('i').toggleClass('octicon-chevron-down').toggleClass('octicon-chevron-up');\n\t\tthis.is_minimized = !this.is_minimized;\n\t\tthis.on_minimize_toggle && this.on_minimize_toggle(this.is_minimized);\n\t\tthis.header.find('.modal-title').toggleClass('cursor-pointer');\n\t}\n};\n","// Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors\n// MIT License. See license.txt\n\nfrappe.provide(\"frappe.messages\");\n\nimport './dialog';\n\nfrappe.messages.waiting = function(parent, msg) {\n\treturn $(frappe.messages.get_waiting_message(msg))\n\t\t.appendTo(parent);\n};\n\nfrappe.messages.get_waiting_message = function(msg) {\n\treturn repl('
\\\n\t\t

%(msg)s

', { msg: msg });\n}\n\nfrappe.throw = function(msg) {\n\tif(typeof msg==='string') {\n\t\tmsg = {message: msg, title: __('Error')};\n\t}\n\tif(!msg.indicator) msg.indicator = 'red';\n\tfrappe.msgprint(msg);\n\tthrow new Error(msg.message);\n}\n\nfrappe.confirm = function(message, ifyes, ifno) {\n\tvar d = new frappe.ui.Dialog({\n\t\ttitle: __(\"Confirm\"),\n\t\tfields: [\n\t\t\t{fieldtype:\"HTML\", options:`

${message}

`}\n\t\t],\n\t\tprimary_action_label: __(\"Yes\"),\n\t\tprimary_action: function() {\n\t\t\tif(ifyes) ifyes();\n\t\t\td.hide();\n\t\t},\n\t\tsecondary_action_label: __(\"No\")\n\t});\n\td.show();\n\n\t// flag, used to bind \"okay\" on enter\n\td.confirm_dialog = true;\n\n\t// no if closed without primary action\n\tif(ifno) {\n\t\td.onhide = function() {\n\t\t\tif(!d.primary_action_fulfilled) {\n\t\t\t\tifno();\n\t\t\t}\n\t\t};\n\t}\n\treturn d;\n}\n\nfrappe.warn = function(title, message_html, proceed_action, primary_label, is_minimizable) {\n\tconst d = new frappe.ui.Dialog({\n\t\ttitle: title,\n\t\tindicator: 'red',\n\t\tfields: [\n\t\t\t{\n\t\t\t\tfieldtype: 'HTML',\n\t\t\t\tfieldname: 'warning_message',\n\t\t\t\toptions: `
${message_html}
`\n\t\t\t}\n\t\t],\n\t\tprimary_action_label: primary_label,\n\t\tprimary_action: () => {\n\t\t\tif (proceed_action) proceed_action();\n\t\t\td.hide();\n\t\t},\n\t\tsecondary_action_label: __(\"Cancel\"),\n\t\tminimizable: is_minimizable\n\t});\n\n\td.footer = $(`
`).insertAfter($(d.modal_body));\n\n\td.get_close_btn().appendTo(d.footer);\n\td.get_primary_btn().appendTo(d.footer);\n\n\td.footer.find('.btn-primary').removeClass('btn-primary').addClass('btn-danger');\n\n\td.show();\n\treturn d;\n};\n\nfrappe.prompt = function(fields, callback, title, primary_label) {\n\tif (typeof fields === \"string\") {\n\t\tfields = [{\n\t\t\tlabel: fields,\n\t\t\tfieldname: \"value\",\n\t\t\tfieldtype: \"Data\",\n\t\t\treqd: 1\n\t\t}];\n\t}\n\tif(!$.isArray(fields)) fields = [fields];\n\tvar d = new frappe.ui.Dialog({\n\t\tfields: fields,\n\t\ttitle: title || __(\"Enter Value\"),\n\t});\n\td.set_primary_action(primary_label || __(\"Submit\"), function() {\n\t\tvar values = d.get_values();\n\t\tif(!values) {\n\t\t\treturn;\n\t\t}\n\t\td.hide();\n\t\tcallback(values);\n\t});\n\td.show();\n\treturn d;\n}\n\nfrappe.msgprint = function(msg, title, is_minimizable) {\n\tif(!msg) return;\n\n\tif($.isPlainObject(msg)) {\n\t\tvar data = msg;\n\t} else {\n\t\t// passed as JSON\n\t\tif(typeof msg==='string' && msg.substr(0,1)==='{') {\n\t\t\tvar data = JSON.parse(msg);\n\t\t} else {\n\t\t\tvar data = {'message': msg, 'title': title};\n\t\t}\n\t}\n\n\tif(!data.indicator) {\n\t\tdata.indicator = 'blue';\n\t}\n\n\tif(data.message instanceof Array) {\n\t\tdata.message.forEach(function(m) {\n\t\t\tfrappe.msgprint(m);\n\t\t});\n\t\treturn;\n\t}\n\n\tif(data.alert) {\n\t\tfrappe.show_alert(data);\n\t\treturn;\n\t}\n\n\tif(!frappe.msg_dialog) {\n\t\tfrappe.msg_dialog = new frappe.ui.Dialog({\n\t\t\ttitle: __(\"Message\"),\n\t\t\tonhide: function() {\n\t\t\t\tif(frappe.msg_dialog.custom_onhide) {\n\t\t\t\t\tfrappe.msg_dialog.custom_onhide();\n\t\t\t\t}\n\t\t\t\tfrappe.msg_dialog.msg_area.empty();\n\t\t\t},\n\t\t\tminimizable: data.is_minimizable || is_minimizable\n\t\t});\n\n\t\t// class \"msgprint\" is used in tests\n\t\tfrappe.msg_dialog.msg_area = $('
')\n\t\t\t.appendTo(frappe.msg_dialog.body);\n\n\t\tfrappe.msg_dialog.clear = function() {\n\t\t\tfrappe.msg_dialog.msg_area.empty();\n\t\t}\n\n\t\tfrappe.msg_dialog.indicator = frappe.msg_dialog.header.find('.indicator');\n\t}\n\n\t// setup and bind an action to the primary button\n\tif (data.primary_action) {\n\t\tif (data.primary_action.server_action && typeof data.primary_action.server_action === 'string') {\n\t\t\tdata.primary_action.action = () => {\n\t\t\t\tfrappe.call({\n\t\t\t\t\tmethod: data.primary_action.server_action,\n\t\t\t\t\targs: {\n\t\t\t\t\t\targs: data.primary_action.args\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\n\t\tif (data.primary_action.client_action && typeof data.primary_action.client_action === 'string') {\n\t\t\tlet parts = data.primary_action.client_action.split('.');\n\t\t\tlet obj = window;\n\t\t\tfor (let part of parts) {\n\t\t\t\tobj = obj[part];\n\t\t\t}\n\t\t\tdata.primary_action.action = () => {\n\t\t\t\tif (typeof obj === 'function') {\n\t\t\t\t\tobj(data.primary_action.args);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tfrappe.msg_dialog.set_primary_action(\n\t\t\t__(data.primary_action.label || \"Done\"),\n\t\t\tdata.primary_action.action\n\t\t);\n\t} else {\n\t\tif (frappe.msg_dialog.has_primary_action) {\n\t\t\tfrappe.msg_dialog.get_primary_btn().addClass('hide');\n\t\t\tfrappe.msg_dialog.has_primary_action = false;\n\t\t}\n\t}\n\n\tif(data.message==null) {\n\t\tdata.message = '';\n\t}\n\n\tif(data.message.search(/
|

|

  • /)==-1) {\n\t\tmsg = frappe.utils.replace_newlines(data.message);\n\t}\n\n\tvar msg_exists = false;\n\tif(data.clear) {\n\t\tfrappe.msg_dialog.msg_area.empty();\n\t} else {\n\t\tmsg_exists = frappe.msg_dialog.msg_area.html();\n\t}\n\n\tif(data.title || !msg_exists) {\n\t\t// set title only if it is explicitly given\n\t\t// and no existing title exists\n\t\tfrappe.msg_dialog.set_title(data.title || __('Message'));\n\t}\n\n\t// show / hide indicator\n\tif(data.indicator) {\n\t\tfrappe.msg_dialog.indicator.removeClass().addClass('indicator ' + data.indicator);\n\t} else {\n\t\tfrappe.msg_dialog.indicator.removeClass().addClass('hidden');\n\t}\n\n\t// width\n\tif (data.wide) {\n\t\t// msgprint should be narrower than the usual dialog\n\t\tif (frappe.msg_dialog.wrapper.classList.contains('msgprint-dialog')) {\n\t\t\tfrappe.msg_dialog.wrapper.classList.remove('msgprint-dialog');\n\t\t}\n\t} else {\n\t\t// msgprint should be narrower than the usual dialog\n\t\tfrappe.msg_dialog.wrapper.classList.add('msgprint-dialog');\n\t}\n\n\tif (data.scroll) {\n\t\t// limit modal height and allow scrolling instead\n\t\tfrappe.msg_dialog.body.classList.add('msgprint-scroll');\n\t} else {\n\t\tif (frappe.msg_dialog.body.classList.contains('msgprint-scroll')) {\n\t\t\tfrappe.msg_dialog.body.classList.remove('msgprint-scroll');\n\t\t}\n\t}\n\n\n\tif(msg_exists) {\n\t\tfrappe.msg_dialog.msg_area.append(\"
    \");\n\t// append a
    if another msg already exists\n\t}\n\n\tfrappe.msg_dialog.msg_area.append(data.message);\n\n\t// make msgprint always appear on top\n\tfrappe.msg_dialog.$wrapper.css(\"z-index\", 2000);\n\tfrappe.msg_dialog.show();\n\n\treturn frappe.msg_dialog;\n}\n\nwindow.msgprint = frappe.msgprint;\n\nfrappe.hide_msgprint = function(instant) {\n\t// clear msgprint\n\tif(frappe.msg_dialog && frappe.msg_dialog.msg_area) {\n\t\tfrappe.msg_dialog.msg_area.empty();\n\t}\n\tif(frappe.msg_dialog && frappe.msg_dialog.$wrapper.is(\":visible\")) {\n\t\tif(instant) {\n\t\t\tfrappe.msg_dialog.$wrapper.removeClass(\"fade\");\n\t\t}\n\t\tfrappe.msg_dialog.hide();\n\t\tif(instant) {\n\t\t\tfrappe.msg_dialog.$wrapper.addClass(\"fade\");\n\t\t}\n\t}\n}\n\n// update html in existing msgprint\nfrappe.update_msgprint = function(html) {\n\tif(!frappe.msg_dialog || (frappe.msg_dialog && !frappe.msg_dialog.$wrapper.is(\":visible\"))) {\n\t\tfrappe.msgprint(html);\n\t} else {\n\t\tfrappe.msg_dialog.msg_area.html(html);\n\t}\n}\n\nfrappe.verify_password = function(callback) {\n\tfrappe.prompt({\n\t\tfieldname: \"password\",\n\t\tlabel: __(\"Enter your password\"),\n\t\tfieldtype: \"Password\",\n\t\treqd: 1\n\t}, function(data) {\n\t\tfrappe.call({\n\t\t\tmethod: \"frappe.core.doctype.user.user.verify_password\",\n\t\t\targs: {\n\t\t\t\tpassword: data.password\n\t\t\t},\n\t\t\tcallback: function(r) {\n\t\t\t\tif(!r.exc) {\n\t\t\t\t\tcallback();\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\t}, __(\"Verify Password\"), __(\"Verify\"))\n}\n\nfrappe.show_progress = function(title, count, total=100, description) {\n\tif(frappe.cur_progress && frappe.cur_progress.title === title && frappe.cur_progress.is_visible) {\n\t\tvar dialog = frappe.cur_progress;\n\t} else {\n\t\tvar dialog = new frappe.ui.Dialog({\n\t\t\ttitle: title,\n\t\t});\n\t\tdialog.progress = $(`
    \n\t\t\t
    \n\t\t\t\t
    \n\t\t\t
    \n\t\t\t

    \n\t\t
    ').appendTo('body');\n\t}\n\n\tlet body_html;\n\n\tif (message.body) {\n\t\tbody_html = message.body;\n\t}\n\n\tconst div = $(`\n\t\t
    \n\t\t\t
    \n\t\t\t
    \n\t\t\t×\n\t\t
    `);\n\n\tif(message.indicator) {\n\t\tdiv.find('.alert-message').append(``);\n\t}\n\n\tdiv.find('.alert-message').append(message.message);\n\n\tif (body_html) {\n\t\tdiv.find('.alert-body').show().html(body_html);\n\t}\n\n\tdiv.hide().appendTo(\"#alert-container\").show()\n\t\t.css('transform', 'translateX(0)');\n\n\tdiv.find('.close, button').click(function() {\n\t\tdiv.remove();\n\t\treturn false;\n\t});\n\n\tObject.keys(actions).map(key => {\n\t\tdiv.find(`[data-action=${key}]`).on('click', actions[key]);\n\t});\n\n\tdiv.delay(seconds * 1000).fadeOut(300);\n\treturn div;\n}\n\n// Proxy for frappe.show_alert\nObject.defineProperty(window, 'show_alert', {\n\tget: function() {\n\t\tconsole.warn('Please use `frappe.show_alert` instead of `show_alert`. It will be deprecated soon.');\n\t\treturn frappe.show_alert;\n\t}\n});\n","// Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors\n// MIT License. See license.txt\n\n// for translation\nfrappe._messages = {};\nfrappe._ = function(txt, replace) {\n\tif(!txt)\n\t\treturn txt;\n\tif(typeof(txt) != \"string\")\n\t\treturn txt;\n\tvar ret = frappe._messages[txt.replace(/\\n/g, \"\")] || txt;\n\tif(replace && typeof(replace) === \"object\") {\n\t\tret = $.format(ret, replace);\n\t}\n\treturn ret;\n};\nwindow.__ = frappe._\n\nfrappe.get_languages = function() {\n\tif(!frappe.languages) {\n\t\tfrappe.languages = []\n\t\t$.each(frappe.boot.lang_dict, function(lang, value){\n\t\t\tfrappe.languages.push({'label': lang, 'value': value})\n\t\t});\n\t\tfrappe.languages = frappe.languages.sort(function(a, b) { return (a.value < b.value) ? -1 : 1 });\n\t}\n\treturn frappe.languages;\n};\n","// Simple JavaScript Templating\n// Adapted from John Resig - http://ejohn.org/ - MIT Licensed\n\nfrappe.template = {compiled: {}, debug:{}};\nfrappe.template.compile = function(str, name) {\n\tvar key = name || str;\n\n\tif(!frappe.template.compiled[key]) {\n\t\tif(str.indexOf(\"'\")!==-1) {\n\t\t\tstr.replace(/'/g, \"\\\\'\");\n\t\t\t//console.warn(\"Warning: Single quotes (') may not work in templates\");\n\t\t}\n\n\t\t// replace jinja style tags\n\t\tstr = str.replace(/{{/g, \"{%=\").replace(/}}/g, \"%}\");\n\n\t\t// {% if not test %} --> {% if (!test) { %}\n\t\tstr = str.replace(/{%\\s?if\\s?\\s?not\\s?([^\\(][^%{]+)\\s?%}/g, \"{% if (! $1) { %}\")\n\n\t\t// {% if test %} --> {% if (test) { %}\n\t\tstr = str.replace(/{%\\s?if\\s?([^\\(][^%{]+)\\s?%}/g, \"{% if ($1) { %}\");\n\n\t\t// {% for item in list %}\n\t\t// --> {% for (var i=0, len=list.length; i {% } %}\n\t\tstr = str.replace(/{%\\s?endif\\s?%}/g, \"{% }; %}\");\n\n\t\t// {% else %} --> {% } else { %}\n\t\tstr = str.replace(/{%\\s?else\\s?%}/g, \"{% } else { %}\");\n\n\t\t// {% endif %} --> {% } %}\n\t\tstr = str.replace(/{%\\s?endfor\\s?%}/g, \"{% }; %}\");\n\n\t\tvar fn_str = \"var _p=[],print=function(){_p.push.apply(_p,arguments)};\" +\n\n\t // Introduce the data as local variables using with(){}\n\t \"with(obj){\\n_p.push('\" +\n\n\t // Convert the template into pure JavaScript\n\t str\n\t .replace(/[\\r\\t\\n]/g, \" \")\n\t .split(\"{%\").join(\"\\t\")\n\t .replace(/((^|%})[^\\t]*)'/g, \"$1\\r\")\n\t .replace(/\\t=(.*?)%}/g, \"',$1,'\")\n\t .split(\"\\t\").join(\"');\\n\")\n\t .split(\"%}\").join(\"\\n_p.push('\")\n\t .split(\"\\r\").join(\"\\\\'\")\n\t + \"');}return _p.join('');\";\n\n\t\t frappe.template.debug[name] = fn_str;\n\t\ttry {\n\t\t\tfrappe.template.compiled[key] = new Function(\"obj\", fn_str);\n\t\t} catch (e) {\n\t\t\tconsole.log(\"Error in Template:\");\n\t\t\tconsole.log(fn_str);\n\t\t\tif(e.lineNumber) {\n\t\t\t\tconsole.log(\"Error in Line \"+e.lineNumber+\", Col \"+e.columnNumber+\":\");\n\t\t\t\tconsole.log(fn_str.split(\"\\n\")[e.lineNumber - 1]);\n\t\t\t}\n\t\t}\n }\n\n\treturn frappe.template.compiled[key];\n};\nfrappe.render = function(str, data, name) {\n\treturn frappe.template.compile(str, name)(data);\n};\nfrappe.render_template = function(name, data) {\n\tif(name.indexOf(' ')!==-1) {\n\t\tvar template = name;\n\t} else {\n\t\tvar template = frappe.templates[name];\n\t}\n\tif(data===undefined) {\n\t\tdata = {};\n\t}\n\tif (!template) {\n\t\tfrappe.throw(`Template ${name} not found.`);\n\t}\n\treturn frappe.render(template, data, name);\n}\nfrappe.render_grid = function(opts) {\n\t// build context\n\tif (opts.grid) {\n\t\topts.columns = opts.grid.getColumns();\n\t\topts.data = opts.grid.getData().getItems();\n\t}\n\n\tif (\n\t\topts.print_settings &&\n\t\topts.print_settings.orientation &&\n\t\topts.print_settings.orientation.toLowerCase() === \"landscape\"\n\t) {\n\t\topts.landscape = true;\n\t}\n\n\t// show landscape view if columns more than 10\n\tif (opts.landscape == null) {\n\t\tif(opts.columns && opts.columns.length > 10) {\n\t\t\topts.landscape = true;\n\t\t} else {\n\t\t\topts.landscape = false;\n\t\t}\n\t}\n\n\t// render content\n\tif(!opts.content) {\n\t\topts.content = frappe.render_template(opts.template || \"print_grid\", opts);\n\t}\n\n\t// render HTML wrapper page\n\topts.base_url = frappe.urllib.get_base_url();\n\topts.print_css = frappe.boot.print_css;\n\tvar html = frappe.render_template(\"print_template\", opts);\n\n\tvar w = window.open();\n\n\tif(!w) {\n\t\tfrappe.msgprint(__(\"Please enable pop-ups in your browser\"))\n\t}\n\n\tw.document.write(html);\n\tw.document.close();\n},\nfrappe.render_tree = function(opts) {\n\topts.base_url = frappe.urllib.get_base_url();\n\topts.landscape = false;\n\topts.print_css = frappe.boot.print_css;\n\tvar tree = frappe.render_template(\"print_tree\", opts);\n\tvar w = window.open();\n\n\tif(!w) {\n\t\tfrappe.msgprint(__(\"Please enable pop-ups in your browser\"))\n\t}\n\n\tw.document.write(tree);\n\tw.document.close();\n}\nfrappe.render_pdf = function(html, opts = {}) {\n\t//Create a form to place the HTML content\n\tvar formData = new FormData();\n\n\t//Push the HTML content into an element\n\tformData.append(\"html\", html);\n\tif (opts.orientation) {\n\t\tformData.append(\"orientation\", opts.orientation);\n\t}\n\tvar blob = new Blob([], { type: \"text/xml\"});\n\tformData.append(\"blob\", blob);\n\n\tvar xhr = new XMLHttpRequest();\n\txhr.open(\"POST\", '/api/method/frappe.utils.print_format.report_to_pdf');\n\txhr.setRequestHeader(\"X-Frappe-CSRF-Token\", frappe.csrf_token);\n\txhr.responseType = \"arraybuffer\";\n\n\txhr.onload = function(success) {\n\t\tif (this.status === 200) {\n\t\t\tvar blob = new Blob([success.currentTarget.response], {type: \"application/pdf\"});\n\t\t\tvar objectUrl = URL.createObjectURL(blob);\n\n\t\t\t//Open report in a new window\n\t\t\twindow.open(objectUrl);\n\t\t}\n\t};\n\txhr.send(formData);\n};\n","// DropZone\nfrappe.ui.DropZone = class \n{\n\tconstructor (selector, options) {\n\t\tthis.options = Object.assign({ }, frappe.ui.DropZone.OPTIONS, options);\n\t\tthis.$container = $(selector);\n\t\tthis.$wrapper = $(frappe.ui.DropZone.TEMPLATE);\n\n\t\tthis.make();\n\t}\n\n\tmake ( ) {\n\t\tconst me = this;\n\t\tconst $dropzone = this.$wrapper.find('.panel-body');\n\t\tconst $title = $dropzone.find('.dropzone-title');\n\t\t$title.html(this.options.title);\n\n\t\t$dropzone.on('dragover', function (e) {\n\t\t\te.preventDefault();\n\n\t\t\t$title.html(__('Drop'));\n\t\t});\n\t\t$dropzone.on('dragleave', function (e) {\n\t\t\te.preventDefault();\n\n\t\t\t$title.html(me.options.title);\n\t\t});\n\t\t$dropzone.on('drop', function (e) {\n\t\t\te.preventDefault();\n\n\t\t\tconst files = e.originalEvent.dataTransfer.files;\n\t\t\tme.options.drop(files);\n\n\t\t\t$title.html(me.options.title);\n\t\t});\n\n\t\tthis.$container.html(this.$wrapper);\n\t}\n};\nfrappe.ui.DropZone.TEMPLATE =\n`\n
    \n\t
    \n\t\t
    \n\t\t
    \n\t
    \n
    \n`;\nfrappe.ui.DropZone.OPTIONS = \n{\n\ttitle: __('Drop Here')\n};\n","//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n\nexport default {\n\tname: 'FilePreview',\n\tprops: ['file'],\n\tdata() {\n\t\treturn {\n\t\t\tsrc: null\n\t\t}\n\t},\n\tmounted() {\n\t\tif (this.is_image) {\n\t\t\tif (window.FileReader) {\n\t\t\t\tlet fr = new FileReader();\n\t\t\t\tfr.onload = () => this.src = fr.result;\n\t\t\t\tfr.readAsDataURL(this.file.file_obj);\n\t\t\t}\n\t\t}\n\t},\n\tfilters: {\n\t\tfile_size(value) {\n\t\t\treturn frappe.form.formatters.FileSize(value);\n\t\t},\n\t\tfile_name(value) {\n\t\t\treturn frappe.utils.file_name_ellipsis(value, 9);\n\t\t}\n\t},\n\tcomputed: {\n\t\tuploaded() {\n\t\t\treturn this.file.total && this.file.total === this.file.progress && !this.file.failed;\n\t\t},\n\t\tis_image() {\n\t\t\treturn this.file.file_obj.type.startsWith('image');\n\t\t}\n\t}\n}\n","//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n\nexport default {\n\tname: 'TreeNode',\n\tprops: ['node', 'selected_node'],\n\tcomponents: {\n\t\tTreeNode: () => frappe.ui.components.TreeNode\n\t}\n}\n","//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n\nimport TreeNode from \"./TreeNode.vue\";\n\nexport default {\n\tname: 'FileBrowser',\n\tcomponents: {\n\t\tTreeNode\n\t},\n\tdata() {\n\t\treturn {\n\t\t\tnode: {\n\t\t\t\tlabel: __('Home'),\n\t\t\t\tvalue: 'Home',\n\t\t\t\tchildren: [],\n\t\t\t\tis_leaf: false,\n\t\t\t\tfetching: false,\n\t\t\t\tfetched: false,\n\t\t\t\topen: false,\n\t\t\t\tfiltered: true\n\t\t\t},\n\t\t\tselected_node: {},\n\t\t\tfilter_text: ''\n\t\t}\n\t},\n\tmounted() {\n\t\tthis.toggle_node(this.node);\n\t},\n\tmethods: {\n\t\ttoggle_node(node) {\n\t\t\tif (!node.fetched && !node.is_leaf) {\n\t\t\t\tnode.fetching = true;\n\t\t\t\tthis.get_files_in_folder(node.value)\n\t\t\t\t\t.then(files => {\n\t\t\t\t\t\tnode.open = true;\n\t\t\t\t\t\tnode.children = files;\n\t\t\t\t\t\tnode.fetched = true;\n\t\t\t\t\t\tnode.fetching = false;\n\t\t\t\t\t});\n\t\t\t} else {\n\t\t\t\tnode.open = !node.open;\n\t\t\t\tthis.select_node(node);\n\t\t\t}\n\t\t},\n\t\tselect_node(node) {\n\t\t\tif (node.is_leaf) {\n\t\t\t\tthis.selected_node = node;\n\t\t\t}\n\t\t},\n\t\tget_files_in_folder(folder) {\n\t\t\treturn frappe.call('frappe.core.doctype.file.file.get_files_in_folder', { folder })\n\t\t\t\t.then(r => {\n\t\t\t\t\tlet files = r.message || [];\n\t\t\t\t\tfiles.sort((a, b) => {\n\t\t\t\t\t\tif (a.is_folder && b.is_folder) {\n\t\t\t\t\t\t\treturn a.modified < b.modified ? -1 : 1;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (a.is_folder) {\n\t\t\t\t\t\t\treturn -1;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (b.is_folder) {\n\t\t\t\t\t\t\treturn 1;\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn 0;\n\t\t\t\t\t});\n\t\t\t\t\treturn files.map(file => {\n\t\t\t\t\t\tlet filename = file.file_name || file.name;\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tlabel: frappe.utils.file_name_ellipsis(filename, 40),\n\t\t\t\t\t\t\tfilename: filename,\n\t\t\t\t\t\t\tfile_url: file.file_url,\n\t\t\t\t\t\t\tvalue: file.name,\n\t\t\t\t\t\t\tis_leaf: !file.is_folder,\n\t\t\t\t\t\t\tfetched: !file.is_folder, // fetched if node is leaf\n\t\t\t\t\t\t\tchildren: [],\n\t\t\t\t\t\t\topen: false,\n\t\t\t\t\t\t\tfetching: false,\n\t\t\t\t\t\t\tfiltered: true\n\t\t\t\t\t\t}\n\t\t\t\t\t});\n\t\t\t\t});\n\t\t},\n\t\tapply_filter: frappe.utils.debounce(function() {\n\t\t\tlet filter_text = this.filter_text.toLowerCase();\n\t\t\tlet apply_filter = (node) => {\n\t\t\t\tlet search_string = node.filename.toLowerCase();\n\t\t\t\tif (node.is_leaf) {\n\t\t\t\t\tnode.filtered = search_string.includes(filter_text);\n\t\t\t\t} else {\n\t\t\t\t\tnode.children.forEach(apply_filter);\n\t\t\t\t}\n\t\t\t}\n\t\t\tthis.node.children.forEach(apply_filter);\n\t\t}, 300)\n\t}\n}\n","//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n\nexport default {\n\tname: 'WebLink',\n\tdata() {\n\t\treturn {\n\t\t\turl: '',\n\t\t}\n\t}\n}\n","//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n\nimport FilePreview from './FilePreview.vue';\nimport FileBrowser from './FileBrowser.vue';\nimport WebLink from './WebLink.vue';\n\nexport default {\n\tname: 'FileUploader',\n\tprops: {\n\t\tshow_upload_button: {\n\t\t\tdefault: true\n\t\t},\n\t\tdisable_file_browser: {\n\t\t\tdefault: false\n\t\t},\n\t\tallow_multiple: {\n\t\t\tdefault: true\n\t\t},\n\t\tas_dataurl: {\n\t\t\tdefault: false\n\t\t},\n\t\tdoctype: {\n\t\t\tdefault: null\n\t\t},\n\t\tdocname: {\n\t\t\tdefault: null\n\t\t},\n\t\tfolder: {\n\t\t\tdefault: 'Home'\n\t\t},\n\t\tmethod: {\n\t\t\tdefault: null\n\t\t},\n\t\ton_success: {\n\t\t\tdefault: null\n\t\t},\n\t\trestrictions: {\n\t\t\tdefault: () => ({\n\t\t\t\tmax_file_size: null, // 2048 -> 2KB\n\t\t\t\tmax_number_of_files: null,\n\t\t\t\tallowed_file_types: [] // ['image/*', 'video/*', '.jpg', '.gif', '.pdf']\n\t\t\t})\n\t\t},\n\t\tupload_notes: {\n\t\t\tdefault: null // \"Images or video, upto 2MB\"\n\t\t}\n\t},\n\tcomponents: {\n\t\tFilePreview,\n\t\tFileBrowser,\n\t\tWebLink\n\t},\n\tdata() {\n\t\treturn {\n\t\t\tfiles: [],\n\t\t\tis_dragging: false,\n\t\t\tcurrently_uploading: -1,\n\t\t\tshow_file_browser: false,\n\t\t\tshow_web_link: false,\n\t\t}\n\t},\n\twatch: {\n\t\tfiles(newvalue, oldvalue) {\n\t\t\tif (!this.allow_multiple && newvalue.length > 1) {\n\t\t\t\tthis.files = [newvalue[newvalue.length - 1]];\n\t\t\t}\n\t\t}\n\t},\n\tcomputed: {\n\t\tupload_complete() {\n\t\t\treturn this.files.length > 0\n\t\t\t\t&& this.files.every(\n\t\t\t\t\tfile => file.total !== 0 && file.progress === file.total);\n\t\t}\n\t},\n\tmethods: {\n\t\tdragover() {\n\t\t\tthis.is_dragging = true;\n\t\t},\n\t\tdragleave() {\n\t\t\tthis.is_dragging = false;\n\t\t},\n\t\tdropfiles(e) {\n\t\t\tthis.is_dragging = false;\n\t\t\tthis.add_files(e.dataTransfer.files);\n\t\t},\n\t\tbrowse_files() {\n\t\t\tthis.$refs.file_input.click();\n\t\t},\n\t\ton_file_input(e) {\n\t\t\tthis.add_files(this.$refs.file_input.files);\n\t\t},\n\t\tremove_file(i) {\n\t\t\tthis.files = this.files.filter((file, j) => i !== j);\n\t\t},\n\t\ttoggle_private(i) {\n\t\t\tthis.files[i].private = !this.files[i].private;\n\t\t},\n\t\ttoggle_all_private(flag) {\n\t\t\tthis.files = this.files.map(file => {\n\t\t\t\tfile.private = flag;\n\t\t\t\treturn file;\n\t\t\t});\n\t\t},\n\t\tadd_files(file_array) {\n\t\t\tlet files = Array.from(file_array)\n\t\t\t\t.filter(this.check_restrictions)\n\t\t\t\t.map(file => {\n\t\t\t\t\tlet is_image = file.type.startsWith('image');\n\t\t\t\t\treturn {\n\t\t\t\t\t\tfile_obj: file,\n\t\t\t\t\t\tname: file.name,\n\t\t\t\t\t\tdoc: null,\n\t\t\t\t\t\tprogress: 0,\n\t\t\t\t\t\ttotal: 0,\n\t\t\t\t\t\tfailed: false,\n\t\t\t\t\t\tuploading: false,\n\t\t\t\t\t\tprivate: !is_image\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\tthis.files = this.files.concat(files);\n\t\t},\n\t\tcheck_restrictions(file) {\n\t\t\tlet { max_file_size, allowed_file_types } = this.restrictions;\n\n\t\t\tlet mime_type = file.type;\n\t\t\tlet extension = '.' + file.name.split('.').pop();\n\n\t\t\tlet is_correct_type = true;\n\t\t\tlet valid_file_size = true;\n\n\t\t\tif (allowed_file_types.length) {\n\t\t\t\tis_correct_type = allowed_file_types.some((type) => {\n\t\t\t\t\t// is this is a mime-type\n\t\t\t\t\tif (type.includes('/')) {\n\t\t\t\t\t\tif (!file.type) return false;\n\t\t\t\t\t\treturn file.type.match(type);\n\t\t\t\t\t}\n\n\t\t\t\t\t// otherwise this is likely an extension\n\t\t\t\t\tif (type[0] === '.') {\n\t\t\t\t\t\treturn file.name.endsWith(type);\n\t\t\t\t\t}\n\t\t\t\t\treturn false;\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tif (max_file_size && file.size != null) {\n\t\t\t\tvalid_file_size = file.size < max_file_size;\n\t\t\t}\n\n\t\t\tif (!is_correct_type) {\n\t\t\t\tconsole.warn('File skipped because of invalid file type', file);\n\t\t\t}\n\t\t\tif (!valid_file_size) {\n\t\t\t\tconsole.warn('File skipped because of invalid file size', file.size, file);\n\t\t\t}\n\n\t\t\treturn is_correct_type && valid_file_size;\n\t\t},\n\t\tupload_files() {\n\t\t\tif (this.show_file_browser) {\n\t\t\t\treturn this.upload_via_file_browser();\n\t\t\t}\n\t\t\tif (this.show_web_link) {\n\t\t\t\treturn this.upload_via_web_link();\n\t\t\t}\n\t\t\tif (this.as_dataurl) {\n\t\t\t\treturn this.return_as_dataurl();\n\t\t\t}\n\t\t\treturn frappe.run_serially(\n\t\t\t\tthis.files.map(\n\t\t\t\t\t(file, i) =>\n\t\t\t\t\t\t() => this.upload_file(file, i)\n\t\t\t\t)\n\t\t\t);\n\t\t},\n\t\tupload_via_file_browser() {\n\t\t\tlet selected_file = this.$refs.file_browser.selected_node;\n\t\t\tif (!selected_file.value) {\n\t\t\t\tfrappe.msgprint(__('Click on a file to select it.'));\n\t\t\t\treturn Promise.reject();\n\t\t\t}\n\n\t\t\treturn this.upload_file({\n\t\t\t\tfile_url: selected_file.file_url\n\t\t\t});\n\t\t},\n\t\tupload_via_web_link() {\n\t\t\tlet file_url = this.$refs.web_link.url;\n\t\t\tif (!file_url) {\n\t\t\t\tfrappe.msgprint(__('Invalid URL'));\n\t\t\t\treturn Promise.reject();\n\t\t\t}\n\n\t\t\treturn this.upload_file({\n\t\t\t\tfile_url\n\t\t\t});\n\t\t},\n\t\treturn_as_dataurl() {\n\t\t\tlet promises = this.files.map(file =>\n\t\t\t\tfrappe.dom.file_to_base64(file.file_obj)\n\t\t\t\t\t.then(dataurl => {\n\t\t\t\t\t\tfile.dataurl = dataurl;\n\t\t\t\t\t\tthis.on_success && this.on_success(file);\n\t\t\t\t\t})\n\t\t\t);\n\t\t\treturn Promise.all(promises);\n\t\t},\n\t\tupload_file(file, i) {\n\t\t\tthis.currently_uploading = i;\n\n\t\t\treturn new Promise((resolve, reject) => {\n\t\t\t\tlet xhr = new XMLHttpRequest();\n\t\t\t\txhr.upload.addEventListener('loadstart', (e) => {\n\t\t\t\t\tfile.uploading = true;\n\t\t\t\t})\n\t\t\t\txhr.upload.addEventListener('progress', (e) => {\n\t\t\t\t\tif (e.lengthComputable) {\n\t\t\t\t\t\tfile.progress = e.loaded;\n\t\t\t\t\t\tfile.total = e.total;\n\t\t\t\t\t}\n\t\t\t\t})\n\t\t\t\txhr.upload.addEventListener('load', (e) => {\n\t\t\t\t\tfile.uploading = false;\n\t\t\t\t\tresolve();\n\t\t\t\t})\n\t\t\t\txhr.addEventListener('error', (e) => {\n\t\t\t\t\tfile.failed = true;\n\t\t\t\t\treject();\n\t\t\t\t})\n\t\t\t\txhr.onreadystatechange = () => {\n\t\t\t\t\tif (xhr.readyState == XMLHttpRequest.DONE) {\n\t\t\t\t\t\tif (xhr.status === 200) {\n\t\t\t\t\t\t\tlet r = null;\n\t\t\t\t\t\t\tlet file_doc = null;\n\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\tr = JSON.parse(xhr.responseText);\n\t\t\t\t\t\t\t\tif (r.message.doctype === 'File') {\n\t\t\t\t\t\t\t\t\tfile_doc = r.message;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t} catch(e) {\n\t\t\t\t\t\t\t\tr = xhr.responseText;\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tfile.doc = file_doc;\n\n\t\t\t\t\t\t\tif (this.on_success) {\n\t\t\t\t\t\t\t\tthis.on_success(file_doc, r);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t} else if (xhr.status === 403) {\n\t\t\t\t\t\t\tlet response = JSON.parse(xhr.responseText);\n\t\t\t\t\t\t\tfrappe.msgprint({\n\t\t\t\t\t\t\t\ttitle: __('Not permitted'),\n\t\t\t\t\t\t\t\tindicator: 'red',\n\t\t\t\t\t\t\t\tmessage: response._error_message\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tfile.failed = true;\n\t\t\t\t\t\t\tlet error = null;\n\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\terror = JSON.parse(xhr.responseText);\n\t\t\t\t\t\t\t} catch(e) {\n\t\t\t\t\t\t\t\t// pass\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tfrappe.request.cleanup({}, error);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\txhr.open('POST', '/api/method/upload_file', true);\n\t\t\t\txhr.setRequestHeader('Accept', 'application/json');\n\t\t\t\txhr.setRequestHeader('X-Frappe-CSRF-Token', frappe.csrf_token);\n\n\t\t\t\tlet form_data = new FormData();\n\t\t\t\tif (file.file_obj) {\n\t\t\t\t\tform_data.append('file', file.file_obj, file.name);\n\t\t\t\t}\n\t\t\t\tform_data.append('is_private', +file.private);\n\t\t\t\tform_data.append('folder', this.folder);\n\n\t\t\t\tif (file.file_url) {\n\t\t\t\t\tform_data.append('file_url', file.file_url);\n\t\t\t\t}\n\n\t\t\t\tif (this.doctype && this.docname) {\n\t\t\t\t\tform_data.append('doctype', this.doctype);\n\t\t\t\t\tform_data.append('docname', this.docname);\n\t\t\t\t}\n\n\t\t\t\tif (this.method) {\n\t\t\t\t\tform_data.append('method', this.method);\n\t\t\t\t}\n\n\t\t\t\txhr.send(form_data);\n\t\t\t});\n\t\t}\n\t}\n}\n","import FileUploaderComponent from './FileUploader.vue';\n\nexport default class FileUploader {\n\tconstructor({\n\t\twrapper,\n\t\tmethod,\n\t\ton_success,\n\t\tdoctype,\n\t\tdocname,\n\t\tfiles,\n\t\tfolder,\n\t\trestrictions,\n\t\tupload_notes,\n\t\tallow_multiple,\n\t\tas_dataurl,\n\t\tdisable_file_browser,\n\t\tfrm\n\t} = {}) {\n\n\t\tfrm && frm.attachments.max_reached(true);\n\n\t\tif (!wrapper) {\n\t\t\tthis.make_dialog();\n\t\t} else {\n\t\t\tthis.wrapper = wrapper.get ? wrapper.get(0) : wrapper;\n\t\t}\n\n\t\tthis.$fileuploader = new Vue({\n\t\t\tel: this.wrapper,\n\t\t\trender: h => h(FileUploaderComponent, {\n\t\t\t\tprops: {\n\t\t\t\t\tshow_upload_button: !Boolean(this.dialog),\n\t\t\t\t\tdoctype,\n\t\t\t\t\tdocname,\n\t\t\t\t\tmethod,\n\t\t\t\t\tfolder,\n\t\t\t\t\ton_success,\n\t\t\t\t\trestrictions,\n\t\t\t\t\tupload_notes,\n\t\t\t\t\tallow_multiple,\n\t\t\t\t\tas_dataurl,\n\t\t\t\t\tdisable_file_browser,\n\t\t\t\t}\n\t\t\t})\n\t\t});\n\n\t\tthis.uploader = this.$fileuploader.$children[0];\n\n\t\tif (files && files.length) {\n\t\t\tthis.uploader.add_files(files);\n\t\t}\n\t}\n\n\tupload_files() {\n\t\tthis.dialog && this.dialog.get_primary_btn().prop('disabled', true);\n\t\treturn this.uploader.upload_files()\n\t\t\t.then(() => {\n\t\t\t\tthis.dialog && this.dialog.hide();\n\t\t\t});\n\t}\n\n\tmake_dialog() {\n\t\tthis.dialog = new frappe.ui.Dialog({\n\t\t\ttitle: 'Upload',\n\t\t\tfields: [\n\t\t\t\t{\n\t\t\t\t\tfieldtype: 'HTML',\n\t\t\t\t\tfieldname: 'upload_area'\n\t\t\t\t}\n\t\t\t],\n\t\t\tprimary_action_label: __('Upload'),\n\t\t\tprimary_action: () => this.upload_files()\n\t\t});\n\n\t\tthis.wrapper = this.dialog.fields_dict.upload_area.$wrapper[0];\n\t\tthis.dialog.show();\n\t\tthis.dialog.$wrapper.on('hidden.bs.modal', function() {\n\t\t\t$(this).data('bs.modal', null);\n\t\t\t$(this).remove();\n\t\t});\n\t}\n}\n","function deepFreeze(obj) {\n if (obj instanceof Map) {\n obj.clear = obj.delete = obj.set = function () {\n throw new Error('map is read-only');\n };\n } else if (obj instanceof Set) {\n obj.add = obj.clear = obj.delete = function () {\n throw new Error('set is read-only');\n };\n }\n\n // Freeze self\n Object.freeze(obj);\n\n Object.getOwnPropertyNames(obj).forEach(function (name) {\n var prop = obj[name];\n\n // Freeze prop if it is an object\n if (typeof prop == 'object' && !Object.isFrozen(prop)) {\n deepFreeze(prop);\n }\n });\n\n return obj;\n}\n\nvar deepFreezeEs6 = deepFreeze;\nvar _default = deepFreeze;\ndeepFreezeEs6.default = _default;\n\nclass Response {\n /**\n * @param {CompiledMode} mode\n */\n constructor(mode) {\n // eslint-disable-next-line no-undefined\n if (mode.data === undefined) mode.data = {};\n\n this.data = mode.data;\n }\n\n ignoreMatch() {\n this.ignore = true;\n }\n}\n\n/**\n * @param {string} value\n * @returns {string}\n */\nfunction escapeHTML(value) {\n return value\n .replace(/&/g, '&')\n .replace(//g, '>')\n .replace(/\"/g, '"')\n .replace(/'/g, ''');\n}\n\n/**\n * performs a shallow merge of multiple objects into one\n *\n * @template T\n * @param {T} original\n * @param {Record[]} objects\n * @returns {T} a single new object\n */\nfunction inherit(original, ...objects) {\n /** @type Record */\n const result = Object.create(null);\n\n for (const key in original) {\n result[key] = original[key];\n }\n objects.forEach(function(obj) {\n for (const key in obj) {\n result[key] = obj[key];\n }\n });\n return /** @type {T} */ (result);\n}\n\n/* Stream merging */\n\n/**\n * @typedef Event\n * @property {'start'|'stop'} event\n * @property {number} offset\n * @property {Node} node\n */\n\n/**\n * @param {Node} node\n */\nfunction tag(node) {\n return node.nodeName.toLowerCase();\n}\n\n/**\n * @param {Node} node\n */\nfunction nodeStream(node) {\n /** @type Event[] */\n const result = [];\n (function _nodeStream(node, offset) {\n for (let child = node.firstChild; child; child = child.nextSibling) {\n if (child.nodeType === 3) {\n offset += child.nodeValue.length;\n } else if (child.nodeType === 1) {\n result.push({\n event: 'start',\n offset: offset,\n node: child\n });\n offset = _nodeStream(child, offset);\n // Prevent void elements from having an end tag that would actually\n // double them in the output. There are more void elements in HTML\n // but we list only those realistically expected in code display.\n if (!tag(child).match(/br|hr|img|input/)) {\n result.push({\n event: 'stop',\n offset: offset,\n node: child\n });\n }\n }\n }\n return offset;\n })(node, 0);\n return result;\n}\n\n/**\n * @param {any} original - the original stream\n * @param {any} highlighted - stream of the highlighted source\n * @param {string} value - the original source itself\n */\nfunction mergeStreams(original, highlighted, value) {\n let processed = 0;\n let result = '';\n const nodeStack = [];\n\n function selectStream() {\n if (!original.length || !highlighted.length) {\n return original.length ? original : highlighted;\n }\n if (original[0].offset !== highlighted[0].offset) {\n return (original[0].offset < highlighted[0].offset) ? original : highlighted;\n }\n\n /*\n To avoid starting the stream just before it should stop the order is\n ensured that original always starts first and closes last:\n\n if (event1 == 'start' && event2 == 'start')\n return original;\n if (event1 == 'start' && event2 == 'stop')\n return highlighted;\n if (event1 == 'stop' && event2 == 'start')\n return original;\n if (event1 == 'stop' && event2 == 'stop')\n return highlighted;\n\n ... which is collapsed to:\n */\n return highlighted[0].event === 'start' ? original : highlighted;\n }\n\n /**\n * @param {Node} node\n */\n function open(node) {\n /** @param {Attr} attr */\n function attributeString(attr) {\n return ' ' + attr.nodeName + '=\"' + escapeHTML(attr.value) + '\"';\n }\n // @ts-ignore\n result += '<' + tag(node) + [].map.call(node.attributes, attributeString).join('') + '>';\n }\n\n /**\n * @param {Node} node\n */\n function close(node) {\n result += '';\n }\n\n /**\n * @param {Event} event\n */\n function render(event) {\n (event.event === 'start' ? open : close)(event.node);\n }\n\n while (original.length || highlighted.length) {\n let stream = selectStream();\n result += escapeHTML(value.substring(processed, stream[0].offset));\n processed = stream[0].offset;\n if (stream === original) {\n /*\n On any opening or closing tag of the original markup we first close\n the entire highlighted node stack, then render the original tag along\n with all the following original tags at the same offset and then\n reopen all the tags on the highlighted stack.\n */\n nodeStack.reverse().forEach(close);\n do {\n render(stream.splice(0, 1)[0]);\n stream = selectStream();\n } while (stream === original && stream.length && stream[0].offset === processed);\n nodeStack.reverse().forEach(open);\n } else {\n if (stream[0].event === 'start') {\n nodeStack.push(stream[0].node);\n } else {\n nodeStack.pop();\n }\n render(stream.splice(0, 1)[0]);\n }\n }\n return result + escapeHTML(value.substr(processed));\n}\n\nvar utils = /*#__PURE__*/Object.freeze({\n __proto__: null,\n escapeHTML: escapeHTML,\n inherit: inherit,\n nodeStream: nodeStream,\n mergeStreams: mergeStreams\n});\n\n/**\n * @typedef {object} Renderer\n * @property {(text: string) => void} addText\n * @property {(node: Node) => void} openNode\n * @property {(node: Node) => void} closeNode\n * @property {() => string} value\n */\n\n/** @typedef {{kind?: string, sublanguage?: boolean}} Node */\n/** @typedef {{walk: (r: Renderer) => void}} Tree */\n/** */\n\nconst SPAN_CLOSE = '';\n\n/**\n * Determines if a node needs to be wrapped in \n *\n * @param {Node} node */\nconst emitsWrappingTags = (node) => {\n return !!node.kind;\n};\n\n/** @type {Renderer} */\nclass HTMLRenderer {\n /**\n * Creates a new HTMLRenderer\n *\n * @param {Tree} parseTree - the parse tree (must support `walk` API)\n * @param {{classPrefix: string}} options\n */\n constructor(parseTree, options) {\n this.buffer = \"\";\n this.classPrefix = options.classPrefix;\n parseTree.walk(this);\n }\n\n /**\n * Adds texts to the output stream\n *\n * @param {string} text */\n addText(text) {\n this.buffer += escapeHTML(text);\n }\n\n /**\n * Adds a node open to the output stream (if needed)\n *\n * @param {Node} node */\n openNode(node) {\n if (!emitsWrappingTags(node)) return;\n\n let className = node.kind;\n if (!node.sublanguage) {\n className = `${this.classPrefix}${className}`;\n }\n this.span(className);\n }\n\n /**\n * Adds a node close to the output stream (if needed)\n *\n * @param {Node} node */\n closeNode(node) {\n if (!emitsWrappingTags(node)) return;\n\n this.buffer += SPAN_CLOSE;\n }\n\n /**\n * returns the accumulated buffer\n */\n value() {\n return this.buffer;\n }\n\n // helpers\n\n /**\n * Builds a span element\n *\n * @param {string} className */\n span(className) {\n this.buffer += ``;\n }\n}\n\n/** @typedef {{kind?: string, sublanguage?: boolean, children: Node[]} | string} Node */\n/** @typedef {{kind?: string, sublanguage?: boolean, children: Node[]} } DataNode */\n/** */\n\nclass TokenTree {\n constructor() {\n /** @type DataNode */\n this.rootNode = { children: [] };\n this.stack = [this.rootNode];\n }\n\n get top() {\n return this.stack[this.stack.length - 1];\n }\n\n get root() { return this.rootNode; }\n\n /** @param {Node} node */\n add(node) {\n this.top.children.push(node);\n }\n\n /** @param {string} kind */\n openNode(kind) {\n /** @type Node */\n const node = { kind, children: [] };\n this.add(node);\n this.stack.push(node);\n }\n\n closeNode() {\n if (this.stack.length > 1) {\n return this.stack.pop();\n }\n // eslint-disable-next-line no-undefined\n return undefined;\n }\n\n closeAllNodes() {\n while (this.closeNode());\n }\n\n toJSON() {\n return JSON.stringify(this.rootNode, null, 4);\n }\n\n /**\n * @typedef { import(\"./html_renderer\").Renderer } Renderer\n * @param {Renderer} builder\n */\n walk(builder) {\n // this does not\n return this.constructor._walk(builder, this.rootNode);\n // this works\n // return TokenTree._walk(builder, this.rootNode);\n }\n\n /**\n * @param {Renderer} builder\n * @param {Node} node\n */\n static _walk(builder, node) {\n if (typeof node === \"string\") {\n builder.addText(node);\n } else if (node.children) {\n builder.openNode(node);\n node.children.forEach((child) => this._walk(builder, child));\n builder.closeNode(node);\n }\n return builder;\n }\n\n /**\n * @param {Node} node\n */\n static _collapse(node) {\n if (typeof node === \"string\") return;\n if (!node.children) return;\n\n if (node.children.every(el => typeof el === \"string\")) {\n // node.text = node.children.join(\"\");\n // delete node.children;\n node.children = [node.children.join(\"\")];\n } else {\n node.children.forEach((child) => {\n TokenTree._collapse(child);\n });\n }\n }\n}\n\n/**\n Currently this is all private API, but this is the minimal API necessary\n that an Emitter must implement to fully support the parser.\n\n Minimal interface:\n\n - addKeyword(text, kind)\n - addText(text)\n - addSublanguage(emitter, subLanguageName)\n - finalize()\n - openNode(kind)\n - closeNode()\n - closeAllNodes()\n - toHTML()\n\n*/\n\n/**\n * @implements {Emitter}\n */\nclass TokenTreeEmitter extends TokenTree {\n /**\n * @param {*} options\n */\n constructor(options) {\n super();\n this.options = options;\n }\n\n /**\n * @param {string} text\n * @param {string} kind\n */\n addKeyword(text, kind) {\n if (text === \"\") { return; }\n\n this.openNode(kind);\n this.addText(text);\n this.closeNode();\n }\n\n /**\n * @param {string} text\n */\n addText(text) {\n if (text === \"\") { return; }\n\n this.add(text);\n }\n\n /**\n * @param {Emitter & {root: DataNode}} emitter\n * @param {string} name\n */\n addSublanguage(emitter, name) {\n /** @type DataNode */\n const node = emitter.root;\n node.kind = name;\n node.sublanguage = true;\n this.add(node);\n }\n\n toHTML() {\n const renderer = new HTMLRenderer(this, this.options);\n return renderer.value();\n }\n\n finalize() {\n return true;\n }\n}\n\n/**\n * @param {string} value\n * @returns {RegExp}\n * */\nfunction escape(value) {\n return new RegExp(value.replace(/[-/\\\\^$*+?.()|[\\]{}]/g, '\\\\$&'), 'm');\n}\n\n/**\n * @param {RegExp | string } re\n * @returns {string}\n */\nfunction source(re) {\n if (!re) return null;\n if (typeof re === \"string\") return re;\n\n return re.source;\n}\n\n/**\n * @param {...(RegExp | string) } args\n * @returns {string}\n */\nfunction concat(...args) {\n const joined = args.map((x) => source(x)).join(\"\");\n return joined;\n}\n\n/**\n * @param {RegExp} re\n * @returns {number}\n */\nfunction countMatchGroups(re) {\n return (new RegExp(re.toString() + '|')).exec('').length - 1;\n}\n\n/**\n * Does lexeme start with a regular expression match at the beginning\n * @param {RegExp} re\n * @param {string} lexeme\n */\nfunction startsWith(re, lexeme) {\n const match = re && re.exec(lexeme);\n return match && match.index === 0;\n}\n\n// join logically computes regexps.join(separator), but fixes the\n// backreferences so they continue to match.\n// it also places each individual regular expression into it's own\n// match group, keeping track of the sequencing of those match groups\n// is currently an exercise for the caller. :-)\n/**\n * @param {(string | RegExp)[]} regexps\n * @param {string} separator\n * @returns {string}\n */\nfunction join(regexps, separator = \"|\") {\n // backreferenceRe matches an open parenthesis or backreference. To avoid\n // an incorrect parse, it additionally matches the following:\n // - [...] elements, where the meaning of parentheses and escapes change\n // - other escape sequences, so we do not misparse escape sequences as\n // interesting elements\n // - non-matching or lookahead parentheses, which do not capture. These\n // follow the '(' with a '?'.\n const backreferenceRe = /\\[(?:[^\\\\\\]]|\\\\.)*\\]|\\(\\??|\\\\([1-9][0-9]*)|\\\\./;\n let numCaptures = 0;\n let ret = '';\n for (let i = 0; i < regexps.length; i++) {\n numCaptures += 1;\n const offset = numCaptures;\n let re = source(regexps[i]);\n if (i > 0) {\n ret += separator;\n }\n ret += \"(\";\n while (re.length > 0) {\n const match = backreferenceRe.exec(re);\n if (match == null) {\n ret += re;\n break;\n }\n ret += re.substring(0, match.index);\n re = re.substring(match.index + match[0].length);\n if (match[0][0] === '\\\\' && match[1]) {\n // Adjust the backreference.\n ret += '\\\\' + String(Number(match[1]) + offset);\n } else {\n ret += match[0];\n if (match[0] === '(') {\n numCaptures++;\n }\n }\n }\n ret += \")\";\n }\n return ret;\n}\n\n// Common regexps\nconst IDENT_RE = '[a-zA-Z]\\\\w*';\nconst UNDERSCORE_IDENT_RE = '[a-zA-Z_]\\\\w*';\nconst NUMBER_RE = '\\\\b\\\\d+(\\\\.\\\\d+)?';\nconst C_NUMBER_RE = '(-?)(\\\\b0[xX][a-fA-F0-9]+|(\\\\b\\\\d+(\\\\.\\\\d*)?|\\\\.\\\\d+)([eE][-+]?\\\\d+)?)'; // 0x..., 0..., decimal, float\nconst BINARY_NUMBER_RE = '\\\\b(0b[01]+)'; // 0b...\nconst RE_STARTERS_RE = '!|!=|!==|%|%=|&|&&|&=|\\\\*|\\\\*=|\\\\+|\\\\+=|,|-|-=|/=|/|:|;|<<|<<=|<=|<|===|==|=|>>>=|>>=|>=|>>>|>>|>|\\\\?|\\\\[|\\\\{|\\\\(|\\\\^|\\\\^=|\\\\||\\\\|=|\\\\|\\\\||~';\n\n/**\n* @param { Partial & {binary?: string | RegExp} } opts\n*/\nconst SHEBANG = (opts = {}) => {\n const beginShebang = /^#![ ]*\\//;\n if (opts.binary) {\n opts.begin = concat(\n beginShebang,\n /.*\\b/,\n opts.binary,\n /\\b.*/);\n }\n return inherit({\n className: 'meta',\n begin: beginShebang,\n end: /$/,\n relevance: 0,\n /** @type {ModeCallback} */\n \"on:begin\": (m, resp) => {\n if (m.index !== 0) resp.ignoreMatch();\n }\n }, opts);\n};\n\n// Common modes\nconst BACKSLASH_ESCAPE = {\n begin: '\\\\\\\\[\\\\s\\\\S]', relevance: 0\n};\nconst APOS_STRING_MODE = {\n className: 'string',\n begin: '\\'',\n end: '\\'',\n illegal: '\\\\n',\n contains: [BACKSLASH_ESCAPE]\n};\nconst QUOTE_STRING_MODE = {\n className: 'string',\n begin: '\"',\n end: '\"',\n illegal: '\\\\n',\n contains: [BACKSLASH_ESCAPE]\n};\nconst PHRASAL_WORDS_MODE = {\n begin: /\\b(a|an|the|are|I'm|isn't|don't|doesn't|won't|but|just|should|pretty|simply|enough|gonna|going|wtf|so|such|will|you|your|they|like|more)\\b/\n};\n/**\n * Creates a comment mode\n *\n * @param {string | RegExp} begin\n * @param {string | RegExp} end\n * @param {Mode | {}} [modeOptions]\n * @returns {Partial}\n */\nconst COMMENT = function(begin, end, modeOptions = {}) {\n const mode = inherit(\n {\n className: 'comment',\n begin,\n end,\n contains: []\n },\n modeOptions\n );\n mode.contains.push(PHRASAL_WORDS_MODE);\n mode.contains.push({\n className: 'doctag',\n begin: '(?:TODO|FIXME|NOTE|BUG|OPTIMIZE|HACK|XXX):',\n relevance: 0\n });\n return mode;\n};\nconst C_LINE_COMMENT_MODE = COMMENT('//', '$');\nconst C_BLOCK_COMMENT_MODE = COMMENT('/\\\\*', '\\\\*/');\nconst HASH_COMMENT_MODE = COMMENT('#', '$');\nconst NUMBER_MODE = {\n className: 'number',\n begin: NUMBER_RE,\n relevance: 0\n};\nconst C_NUMBER_MODE = {\n className: 'number',\n begin: C_NUMBER_RE,\n relevance: 0\n};\nconst BINARY_NUMBER_MODE = {\n className: 'number',\n begin: BINARY_NUMBER_RE,\n relevance: 0\n};\nconst CSS_NUMBER_MODE = {\n className: 'number',\n begin: NUMBER_RE + '(' +\n '%|em|ex|ch|rem' +\n '|vw|vh|vmin|vmax' +\n '|cm|mm|in|pt|pc|px' +\n '|deg|grad|rad|turn' +\n '|s|ms' +\n '|Hz|kHz' +\n '|dpi|dpcm|dppx' +\n ')?',\n relevance: 0\n};\nconst REGEXP_MODE = {\n // this outer rule makes sure we actually have a WHOLE regex and not simply\n // an expression such as:\n //\n // 3 / something\n //\n // (which will then blow up when regex's `illegal` sees the newline)\n begin: /(?=\\/[^/\\n]*\\/)/,\n contains: [{\n className: 'regexp',\n begin: /\\//,\n end: /\\/[gimuy]*/,\n illegal: /\\n/,\n contains: [\n BACKSLASH_ESCAPE,\n {\n begin: /\\[/,\n end: /\\]/,\n relevance: 0,\n contains: [BACKSLASH_ESCAPE]\n }\n ]\n }]\n};\nconst TITLE_MODE = {\n className: 'title',\n begin: IDENT_RE,\n relevance: 0\n};\nconst UNDERSCORE_TITLE_MODE = {\n className: 'title',\n begin: UNDERSCORE_IDENT_RE,\n relevance: 0\n};\nconst METHOD_GUARD = {\n // excludes method names from keyword processing\n begin: '\\\\.\\\\s*' + UNDERSCORE_IDENT_RE,\n relevance: 0\n};\n\n/**\n * Adds end same as begin mechanics to a mode\n *\n * Your mode must include at least a single () match group as that first match\n * group is what is used for comparison\n * @param {Partial} mode\n */\nconst END_SAME_AS_BEGIN = function(mode) {\n return Object.assign(mode,\n {\n /** @type {ModeCallback} */\n 'on:begin': (m, resp) => { resp.data._beginMatch = m[1]; },\n /** @type {ModeCallback} */\n 'on:end': (m, resp) => { if (resp.data._beginMatch !== m[1]) resp.ignoreMatch(); }\n });\n};\n\nvar MODES = /*#__PURE__*/Object.freeze({\n __proto__: null,\n IDENT_RE: IDENT_RE,\n UNDERSCORE_IDENT_RE: UNDERSCORE_IDENT_RE,\n NUMBER_RE: NUMBER_RE,\n C_NUMBER_RE: C_NUMBER_RE,\n BINARY_NUMBER_RE: BINARY_NUMBER_RE,\n RE_STARTERS_RE: RE_STARTERS_RE,\n SHEBANG: SHEBANG,\n BACKSLASH_ESCAPE: BACKSLASH_ESCAPE,\n APOS_STRING_MODE: APOS_STRING_MODE,\n QUOTE_STRING_MODE: QUOTE_STRING_MODE,\n PHRASAL_WORDS_MODE: PHRASAL_WORDS_MODE,\n COMMENT: COMMENT,\n C_LINE_COMMENT_MODE: C_LINE_COMMENT_MODE,\n C_BLOCK_COMMENT_MODE: C_BLOCK_COMMENT_MODE,\n HASH_COMMENT_MODE: HASH_COMMENT_MODE,\n NUMBER_MODE: NUMBER_MODE,\n C_NUMBER_MODE: C_NUMBER_MODE,\n BINARY_NUMBER_MODE: BINARY_NUMBER_MODE,\n CSS_NUMBER_MODE: CSS_NUMBER_MODE,\n REGEXP_MODE: REGEXP_MODE,\n TITLE_MODE: TITLE_MODE,\n UNDERSCORE_TITLE_MODE: UNDERSCORE_TITLE_MODE,\n METHOD_GUARD: METHOD_GUARD,\n END_SAME_AS_BEGIN: END_SAME_AS_BEGIN\n});\n\n// keywords that should have no default relevance value\nconst COMMON_KEYWORDS = [\n 'of',\n 'and',\n 'for',\n 'in',\n 'not',\n 'or',\n 'if',\n 'then',\n 'parent', // common variable name\n 'list', // common variable name\n 'value' // common variable name\n];\n\n// compilation\n\n/**\n * Compiles a language definition result\n *\n * Given the raw result of a language definition (Language), compiles this so\n * that it is ready for highlighting code.\n * @param {Language} language\n * @returns {CompiledLanguage}\n */\nfunction compileLanguage(language) {\n /**\n * Builds a regex with the case sensativility of the current language\n *\n * @param {RegExp | string} value\n * @param {boolean} [global]\n */\n function langRe(value, global) {\n return new RegExp(\n source(value),\n 'm' + (language.case_insensitive ? 'i' : '') + (global ? 'g' : '')\n );\n }\n\n /**\n Stores multiple regular expressions and allows you to quickly search for\n them all in a string simultaneously - returning the first match. It does\n this by creating a huge (a|b|c) regex - each individual item wrapped with ()\n and joined by `|` - using match groups to track position. When a match is\n found checking which position in the array has content allows us to figure\n out which of the original regexes / match groups triggered the match.\n\n The match object itself (the result of `Regex.exec`) is returned but also\n enhanced by merging in any meta-data that was registered with the regex.\n This is how we keep track of which mode matched, and what type of rule\n (`illegal`, `begin`, end, etc).\n */\n class MultiRegex {\n constructor() {\n this.matchIndexes = {};\n // @ts-ignore\n this.regexes = [];\n this.matchAt = 1;\n this.position = 0;\n }\n\n // @ts-ignore\n addRule(re, opts) {\n opts.position = this.position++;\n // @ts-ignore\n this.matchIndexes[this.matchAt] = opts;\n this.regexes.push([opts, re]);\n this.matchAt += countMatchGroups(re) + 1;\n }\n\n compile() {\n if (this.regexes.length === 0) {\n // avoids the need to check length every time exec is called\n // @ts-ignore\n this.exec = () => null;\n }\n const terminators = this.regexes.map(el => el[1]);\n this.matcherRe = langRe(join(terminators), true);\n this.lastIndex = 0;\n }\n\n /** @param {string} s */\n exec(s) {\n this.matcherRe.lastIndex = this.lastIndex;\n const match = this.matcherRe.exec(s);\n if (!match) { return null; }\n\n // eslint-disable-next-line no-undefined\n const i = match.findIndex((el, i) => i > 0 && el !== undefined);\n // @ts-ignore\n const matchData = this.matchIndexes[i];\n // trim off any earlier non-relevant match groups (ie, the other regex\n // match groups that make up the multi-matcher)\n match.splice(0, i);\n\n return Object.assign(match, matchData);\n }\n }\n\n /*\n Created to solve the key deficiently with MultiRegex - there is no way to\n test for multiple matches at a single location. Why would we need to do\n that? In the future a more dynamic engine will allow certain matches to be\n ignored. An example: if we matched say the 3rd regex in a large group but\n decided to ignore it - we'd need to started testing again at the 4th\n regex... but MultiRegex itself gives us no real way to do that.\n\n So what this class creates MultiRegexs on the fly for whatever search\n position they are needed.\n\n NOTE: These additional MultiRegex objects are created dynamically. For most\n grammars most of the time we will never actually need anything more than the\n first MultiRegex - so this shouldn't have too much overhead.\n\n Say this is our search group, and we match regex3, but wish to ignore it.\n\n regex1 | regex2 | regex3 | regex4 | regex5 ' ie, startAt = 0\n\n What we need is a new MultiRegex that only includes the remaining\n possibilities:\n\n regex4 | regex5 ' ie, startAt = 3\n\n This class wraps all that complexity up in a simple API... `startAt` decides\n where in the array of expressions to start doing the matching. It\n auto-increments, so if a match is found at position 2, then startAt will be\n set to 3. If the end is reached startAt will return to 0.\n\n MOST of the time the parser will be setting startAt manually to 0.\n */\n class ResumableMultiRegex {\n constructor() {\n // @ts-ignore\n this.rules = [];\n // @ts-ignore\n this.multiRegexes = [];\n this.count = 0;\n\n this.lastIndex = 0;\n this.regexIndex = 0;\n }\n\n // @ts-ignore\n getMatcher(index) {\n if (this.multiRegexes[index]) return this.multiRegexes[index];\n\n const matcher = new MultiRegex();\n this.rules.slice(index).forEach(([re, opts]) => matcher.addRule(re, opts));\n matcher.compile();\n this.multiRegexes[index] = matcher;\n return matcher;\n }\n\n resumingScanAtSamePosition() {\n return this.regexIndex !== 0;\n }\n\n considerAll() {\n this.regexIndex = 0;\n }\n\n // @ts-ignore\n addRule(re, opts) {\n this.rules.push([re, opts]);\n if (opts.type === \"begin\") this.count++;\n }\n\n /** @param {string} s */\n exec(s) {\n const m = this.getMatcher(this.regexIndex);\n m.lastIndex = this.lastIndex;\n let result = m.exec(s);\n\n // The following is because we have no easy way to say \"resume scanning at the\n // existing position but also skip the current rule ONLY\". What happens is\n // all prior rules are also skipped which can result in matching the wrong\n // thing. Example of matching \"booger\":\n\n // our matcher is [string, \"booger\", number]\n //\n // ....booger....\n\n // if \"booger\" is ignored then we'd really need a regex to scan from the\n // SAME position for only: [string, number] but ignoring \"booger\" (if it\n // was the first match), a simple resume would scan ahead who knows how\n // far looking only for \"number\", ignoring potential string matches (or\n // future \"booger\" matches that might be valid.)\n\n // So what we do: We execute two matchers, one resuming at the same\n // position, but the second full matcher starting at the position after:\n\n // /--- resume first regex match here (for [number])\n // |/---- full match here for [string, \"booger\", number]\n // vv\n // ....booger....\n\n // Which ever results in a match first is then used. So this 3-4 step\n // process essentially allows us to say \"match at this position, excluding\n // a prior rule that was ignored\".\n //\n // 1. Match \"booger\" first, ignore. Also proves that [string] does non match.\n // 2. Resume matching for [number]\n // 3. Match at index + 1 for [string, \"booger\", number]\n // 4. If #2 and #3 result in matches, which came first?\n if (this.resumingScanAtSamePosition()) {\n if (result && result.index === this.lastIndex) ; else { // use the second matcher result\n const m2 = this.getMatcher(0);\n m2.lastIndex = this.lastIndex + 1;\n result = m2.exec(s);\n }\n }\n\n if (result) {\n this.regexIndex += result.position + 1;\n if (this.regexIndex === this.count) {\n // wrap-around to considering all matches again\n this.considerAll();\n }\n }\n\n return result;\n }\n }\n\n /**\n * Given a mode, builds a huge ResumableMultiRegex that can be used to walk\n * the content and find matches.\n *\n * @param {CompiledMode} mode\n * @returns {ResumableMultiRegex}\n */\n function buildModeRegex(mode) {\n const mm = new ResumableMultiRegex();\n\n mode.contains.forEach(term => mm.addRule(term.begin, { rule: term, type: \"begin\" }));\n\n if (mode.terminator_end) {\n mm.addRule(mode.terminator_end, { type: \"end\" });\n }\n if (mode.illegal) {\n mm.addRule(mode.illegal, { type: \"illegal\" });\n }\n\n return mm;\n }\n\n // TODO: We need negative look-behind support to do this properly\n /**\n * Skip a match if it has a preceding dot\n *\n * This is used for `beginKeywords` to prevent matching expressions such as\n * `bob.keyword.do()`. The mode compiler automatically wires this up as a\n * special _internal_ 'on:begin' callback for modes with `beginKeywords`\n * @param {RegExpMatchArray} match\n * @param {CallbackResponse} response\n */\n function skipIfhasPrecedingDot(match, response) {\n const before = match.input[match.index - 1];\n if (before === \".\") {\n response.ignoreMatch();\n }\n }\n\n /** skip vs abort vs ignore\n *\n * @skip - The mode is still entered and exited normally (and contains rules apply),\n * but all content is held and added to the parent buffer rather than being\n * output when the mode ends. Mostly used with `sublanguage` to build up\n * a single large buffer than can be parsed by sublanguage.\n *\n * - The mode begin ands ends normally.\n * - Content matched is added to the parent mode buffer.\n * - The parser cursor is moved forward normally.\n *\n * @abort - A hack placeholder until we have ignore. Aborts the mode (as if it\n * never matched) but DOES NOT continue to match subsequent `contains`\n * modes. Abort is bad/suboptimal because it can result in modes\n * farther down not getting applied because an earlier rule eats the\n * content but then aborts.\n *\n * - The mode does not begin.\n * - Content matched by `begin` is added to the mode buffer.\n * - The parser cursor is moved forward accordingly.\n *\n * @ignore - Ignores the mode (as if it never matched) and continues to match any\n * subsequent `contains` modes. Ignore isn't technically possible with\n * the current parser implementation.\n *\n * - The mode does not begin.\n * - Content matched by `begin` is ignored.\n * - The parser cursor is not moved forward.\n */\n\n /**\n * Compiles an individual mode\n *\n * This can raise an error if the mode contains certain detectable known logic\n * issues.\n * @param {Mode} mode\n * @param {CompiledMode | null} [parent]\n * @returns {CompiledMode | never}\n */\n function compileMode(mode, parent) {\n const cmode = /** @type CompiledMode */ (mode);\n if (mode.compiled) return cmode;\n mode.compiled = true;\n\n // __beforeBegin is considered private API, internal use only\n mode.__beforeBegin = null;\n\n mode.keywords = mode.keywords || mode.beginKeywords;\n\n let keywordPattern = null;\n if (typeof mode.keywords === \"object\") {\n keywordPattern = mode.keywords.$pattern;\n delete mode.keywords.$pattern;\n }\n\n if (mode.keywords) {\n mode.keywords = compileKeywords(mode.keywords, language.case_insensitive);\n }\n\n // both are not allowed\n if (mode.lexemes && keywordPattern) {\n throw new Error(\"ERR: Prefer `keywords.$pattern` to `mode.lexemes`, BOTH are not allowed. (see mode reference) \");\n }\n\n // `mode.lexemes` was the old standard before we added and now recommend\n // using `keywords.$pattern` to pass the keyword pattern\n cmode.keywordPatternRe = langRe(mode.lexemes || keywordPattern || /\\w+/, true);\n\n if (parent) {\n if (mode.beginKeywords) {\n // for languages with keywords that include non-word characters checking for\n // a word boundary is not sufficient, so instead we check for a word boundary\n // or whitespace - this does no harm in any case since our keyword engine\n // doesn't allow spaces in keywords anyways and we still check for the boundary\n // first\n mode.begin = '\\\\b(' + mode.beginKeywords.split(' ').join('|') + ')(?!\\\\.)(?=\\\\b|\\\\s)';\n mode.__beforeBegin = skipIfhasPrecedingDot;\n }\n if (!mode.begin) mode.begin = /\\B|\\b/;\n cmode.beginRe = langRe(mode.begin);\n if (mode.endSameAsBegin) mode.end = mode.begin;\n if (!mode.end && !mode.endsWithParent) mode.end = /\\B|\\b/;\n if (mode.end) cmode.endRe = langRe(mode.end);\n cmode.terminator_end = source(mode.end) || '';\n if (mode.endsWithParent && parent.terminator_end) {\n cmode.terminator_end += (mode.end ? '|' : '') + parent.terminator_end;\n }\n }\n if (mode.illegal) cmode.illegalRe = langRe(mode.illegal);\n // eslint-disable-next-line no-undefined\n if (mode.relevance === undefined) mode.relevance = 1;\n if (!mode.contains) mode.contains = [];\n\n mode.contains = [].concat(...mode.contains.map(function(c) {\n return expandOrCloneMode(c === 'self' ? mode : c);\n }));\n mode.contains.forEach(function(c) { compileMode(/** @type Mode */ (c), cmode); });\n\n if (mode.starts) {\n compileMode(mode.starts, parent);\n }\n\n cmode.matcher = buildModeRegex(cmode);\n return cmode;\n }\n\n // self is not valid at the top-level\n if (language.contains && language.contains.includes('self')) {\n throw new Error(\"ERR: contains `self` is not supported at the top-level of a language. See documentation.\");\n }\n\n // we need a null object, which inherit will guarantee\n language.classNameAliases = inherit(language.classNameAliases || {});\n\n return compileMode(/** @type Mode */ (language));\n}\n\n/**\n * Determines if a mode has a dependency on it's parent or not\n *\n * If a mode does have a parent dependency then often we need to clone it if\n * it's used in multiple places so that each copy points to the correct parent,\n * where-as modes without a parent can often safely be re-used at the bottom of\n * a mode chain.\n *\n * @param {Mode | null} mode\n * @returns {boolean} - is there a dependency on the parent?\n * */\nfunction dependencyOnParent(mode) {\n if (!mode) return false;\n\n return mode.endsWithParent || dependencyOnParent(mode.starts);\n}\n\n/**\n * Expands a mode or clones it if necessary\n *\n * This is necessary for modes with parental dependenceis (see notes on\n * `dependencyOnParent`) and for nodes that have `variants` - which must then be\n * exploded into their own individual modes at compile time.\n *\n * @param {Mode} mode\n * @returns {Mode | Mode[]}\n * */\nfunction expandOrCloneMode(mode) {\n if (mode.variants && !mode.cached_variants) {\n mode.cached_variants = mode.variants.map(function(variant) {\n return inherit(mode, { variants: null }, variant);\n });\n }\n\n // EXPAND\n // if we have variants then essentially \"replace\" the mode with the variants\n // this happens in compileMode, where this function is called from\n if (mode.cached_variants) {\n return mode.cached_variants;\n }\n\n // CLONE\n // if we have dependencies on parents then we need a unique\n // instance of ourselves, so we can be reused with many\n // different parents without issue\n if (dependencyOnParent(mode)) {\n return inherit(mode, { starts: mode.starts ? inherit(mode.starts) : null });\n }\n\n if (Object.isFrozen(mode)) {\n return inherit(mode);\n }\n\n // no special dependency issues, just return ourselves\n return mode;\n}\n\n/***********************************************\n Keywords\n***********************************************/\n\n/**\n * Given raw keywords from a language definition, compile them.\n *\n * @param {string | Record} rawKeywords\n * @param {boolean} caseInsensitive\n */\nfunction compileKeywords(rawKeywords, caseInsensitive) {\n /** @type KeywordDict */\n const compiledKeywords = {};\n\n if (typeof rawKeywords === 'string') { // string\n splitAndCompile('keyword', rawKeywords);\n } else {\n Object.keys(rawKeywords).forEach(function(className) {\n splitAndCompile(className, rawKeywords[className]);\n });\n }\n return compiledKeywords;\n\n // ---\n\n /**\n * Compiles an individual list of keywords\n *\n * Ex: \"for if when while|5\"\n *\n * @param {string} className\n * @param {string} keywordList\n */\n function splitAndCompile(className, keywordList) {\n if (caseInsensitive) {\n keywordList = keywordList.toLowerCase();\n }\n keywordList.split(' ').forEach(function(keyword) {\n const pair = keyword.split('|');\n compiledKeywords[pair[0]] = [className, scoreForKeyword(pair[0], pair[1])];\n });\n }\n}\n\n/**\n * Returns the proper score for a given keyword\n *\n * Also takes into account comment keywords, which will be scored 0 UNLESS\n * another score has been manually assigned.\n * @param {string} keyword\n * @param {string} [providedScore]\n */\nfunction scoreForKeyword(keyword, providedScore) {\n // manual scores always win over common keywords\n // so you can force a score of 1 if you really insist\n if (providedScore) {\n return Number(providedScore);\n }\n\n return commonKeyword(keyword) ? 0 : 1;\n}\n\n/**\n * Determines if a given keyword is common or not\n *\n * @param {string} keyword */\nfunction commonKeyword(keyword) {\n return COMMON_KEYWORDS.includes(keyword.toLowerCase());\n}\n\nvar version = \"10.4.1\";\n\n// @ts-nocheck\n\nfunction hasValueOrEmptyAttribute(value) {\n return Boolean(value || value === \"\");\n}\n\nfunction BuildVuePlugin(hljs) {\n const Component = {\n props: [\"language\", \"code\", \"autodetect\"],\n data: function() {\n return {\n detectedLanguage: \"\",\n unknownLanguage: false\n };\n },\n computed: {\n className() {\n if (this.unknownLanguage) return \"\";\n \n return \"hljs \" + this.detectedLanguage;\n },\n highlighted() {\n // no idea what language to use, return raw code\n if (!this.autoDetect && !hljs.getLanguage(this.language)) {\n console.warn(`The language \"${this.language}\" you specified could not be found.`);\n this.unknownLanguage = true;\n return escapeHTML(this.code);\n }\n \n let result;\n if (this.autoDetect) {\n result = hljs.highlightAuto(this.code);\n this.detectedLanguage = result.language;\n } else {\n result = hljs.highlight(this.language, this.code, this.ignoreIllegals);\n this.detectedLanguage = this.language;\n }\n return result.value;\n },\n autoDetect() {\n return !this.language || hasValueOrEmptyAttribute(this.autodetect);\n },\n ignoreIllegals() {\n return true;\n }\n },\n // this avoids needing to use a whole Vue compilation pipeline just\n // to build Highlight.js\n render(createElement) {\n return createElement(\"pre\", {}, [\n createElement(\"code\", {\n class: this.className,\n domProps: { innerHTML: this.highlighted }})\n ]);\n }\n // template: `
    `\n };\n \n const VuePlugin = {\n install(Vue) {\n Vue.component('highlightjs', Component);\n }\n };\n\n return { Component, VuePlugin };\n}\n\n/*\nSyntax highlighting with language autodetection.\nhttps://highlightjs.org/\n*/\n\nconst escape$1 = escapeHTML;\nconst inherit$1 = inherit;\n\nconst { nodeStream: nodeStream$1, mergeStreams: mergeStreams$1 } = utils;\nconst NO_MATCH = Symbol(\"nomatch\");\n\n/**\n * @param {any} hljs - object that is extended (legacy)\n * @returns {HLJSApi}\n */\nconst HLJS = function(hljs) {\n // Convenience variables for build-in objects\n /** @type {unknown[]} */\n const ArrayProto = [];\n\n // Global internal variables used within the highlight.js library.\n /** @type {Record} */\n const languages = Object.create(null);\n /** @type {Record} */\n const aliases = Object.create(null);\n /** @type {HLJSPlugin[]} */\n const plugins = [];\n\n // safe/production mode - swallows more errors, tries to keep running\n // even if a single syntax or parse hits a fatal error\n let SAFE_MODE = true;\n const fixMarkupRe = /(^(<[^>]+>|\\t|)+|\\n)/gm;\n const LANGUAGE_NOT_FOUND = \"Could not find the language '{}', did you forget to load/include a language module?\";\n /** @type {Language} */\n const PLAINTEXT_LANGUAGE = { disableAutodetect: true, name: 'Plain text', contains: [] };\n\n // Global options used when within external APIs. This is modified when\n // calling the `hljs.configure` function.\n /** @type HLJSOptions */\n let options = {\n noHighlightRe: /^(no-?highlight)$/i,\n languageDetectRe: /\\blang(?:uage)?-([\\w-]+)\\b/i,\n classPrefix: 'hljs-',\n tabReplace: null,\n useBR: false,\n languages: null,\n // beta configuration options, subject to change, welcome to discuss\n // https://github.com/highlightjs/highlight.js/issues/1086\n __emitter: TokenTreeEmitter\n };\n\n /* Utility functions */\n\n /**\n * Tests a language name to see if highlighting should be skipped\n * @param {string} languageName\n */\n function shouldNotHighlight(languageName) {\n return options.noHighlightRe.test(languageName);\n }\n\n /**\n * @param {HighlightedHTMLElement} block - the HTML element to determine language for\n */\n function blockLanguage(block) {\n let classes = block.className + ' ';\n\n classes += block.parentNode ? block.parentNode.className : '';\n\n // language-* takes precedence over non-prefixed class names.\n const match = options.languageDetectRe.exec(classes);\n if (match) {\n const language = getLanguage(match[1]);\n if (!language) {\n console.warn(LANGUAGE_NOT_FOUND.replace(\"{}\", match[1]));\n console.warn(\"Falling back to no-highlight mode for this block.\", block);\n }\n return language ? match[1] : 'no-highlight';\n }\n\n return classes\n .split(/\\s+/)\n .find((_class) => shouldNotHighlight(_class) || getLanguage(_class));\n }\n\n /**\n * Core highlighting function.\n *\n * @param {string} languageName - the language to use for highlighting\n * @param {string} code - the code to highlight\n * @param {boolean} [ignoreIllegals] - whether to ignore illegal matches, default is to bail\n * @param {CompiledMode} [continuation] - current continuation mode, if any\n *\n * @returns {HighlightResult} Result - an object that represents the result\n * @property {string} language - the language name\n * @property {number} relevance - the relevance score\n * @property {string} value - the highlighted HTML code\n * @property {string} code - the original raw code\n * @property {CompiledMode} top - top of the current mode stack\n * @property {boolean} illegal - indicates whether any illegal matches were found\n */\n function highlight(languageName, code, ignoreIllegals, continuation) {\n /** @type {{ code: string, language: string, result?: any }} */\n const context = {\n code,\n language: languageName\n };\n // the plugin can change the desired language or the code to be highlighted\n // just be changing the object it was passed\n fire(\"before:highlight\", context);\n\n // a before plugin can usurp the result completely by providing it's own\n // in which case we don't even need to call highlight\n const result = context.result ?\n context.result :\n _highlight(context.language, context.code, ignoreIllegals, continuation);\n\n result.code = context.code;\n // the plugin can change anything in result to suite it\n fire(\"after:highlight\", result);\n\n return result;\n }\n\n /**\n * private highlight that's used internally and does not fire callbacks\n *\n * @param {string} languageName - the language to use for highlighting\n * @param {string} code - the code to highlight\n * @param {boolean} [ignoreIllegals] - whether to ignore illegal matches, default is to bail\n * @param {CompiledMode} [continuation] - current continuation mode, if any\n * @returns {HighlightResult} - result of the highlight operation\n */\n function _highlight(languageName, code, ignoreIllegals, continuation) {\n const codeToHighlight = code;\n\n /**\n * Return keyword data if a match is a keyword\n * @param {CompiledMode} mode - current mode\n * @param {RegExpMatchArray} match - regexp match data\n * @returns {KeywordData | false}\n */\n function keywordData(mode, match) {\n const matchText = language.case_insensitive ? match[0].toLowerCase() : match[0];\n return Object.prototype.hasOwnProperty.call(mode.keywords, matchText) && mode.keywords[matchText];\n }\n\n function processKeywords() {\n if (!top.keywords) {\n emitter.addText(modeBuffer);\n return;\n }\n\n let lastIndex = 0;\n top.keywordPatternRe.lastIndex = 0;\n let match = top.keywordPatternRe.exec(modeBuffer);\n let buf = \"\";\n\n while (match) {\n buf += modeBuffer.substring(lastIndex, match.index);\n const data = keywordData(top, match);\n if (data) {\n const [kind, keywordRelevance] = data;\n emitter.addText(buf);\n buf = \"\";\n\n relevance += keywordRelevance;\n const cssClass = language.classNameAliases[kind] || kind;\n emitter.addKeyword(match[0], cssClass);\n } else {\n buf += match[0];\n }\n lastIndex = top.keywordPatternRe.lastIndex;\n match = top.keywordPatternRe.exec(modeBuffer);\n }\n buf += modeBuffer.substr(lastIndex);\n emitter.addText(buf);\n }\n\n function processSubLanguage() {\n if (modeBuffer === \"\") return;\n /** @type HighlightResult */\n let result = null;\n\n if (typeof top.subLanguage === 'string') {\n if (!languages[top.subLanguage]) {\n emitter.addText(modeBuffer);\n return;\n }\n result = _highlight(top.subLanguage, modeBuffer, true, continuations[top.subLanguage]);\n continuations[top.subLanguage] = /** @type {CompiledMode} */ (result.top);\n } else {\n result = highlightAuto(modeBuffer, top.subLanguage.length ? top.subLanguage : null);\n }\n\n // Counting embedded language score towards the host language may be disabled\n // with zeroing the containing mode relevance. Use case in point is Markdown that\n // allows XML everywhere and makes every XML snippet to have a much larger Markdown\n // score.\n if (top.relevance > 0) {\n relevance += result.relevance;\n }\n emitter.addSublanguage(result.emitter, result.language);\n }\n\n function processBuffer() {\n if (top.subLanguage != null) {\n processSubLanguage();\n } else {\n processKeywords();\n }\n modeBuffer = '';\n }\n\n /**\n * @param {Mode} mode - new mode to start\n */\n function startNewMode(mode) {\n if (mode.className) {\n emitter.openNode(language.classNameAliases[mode.className] || mode.className);\n }\n top = Object.create(mode, { parent: { value: top } });\n return top;\n }\n\n /**\n * @param {CompiledMode } mode - the mode to potentially end\n * @param {RegExpMatchArray} match - the latest match\n * @param {string} matchPlusRemainder - match plus remainder of content\n * @returns {CompiledMode | void} - the next mode, or if void continue on in current mode\n */\n function endOfMode(mode, match, matchPlusRemainder) {\n let matched = startsWith(mode.endRe, matchPlusRemainder);\n\n if (matched) {\n if (mode[\"on:end\"]) {\n const resp = new Response(mode);\n mode[\"on:end\"](match, resp);\n if (resp.ignore) matched = false;\n }\n\n if (matched) {\n while (mode.endsParent && mode.parent) {\n mode = mode.parent;\n }\n return mode;\n }\n }\n // even if on:end fires an `ignore` it's still possible\n // that we might trigger the end node because of a parent mode\n if (mode.endsWithParent) {\n return endOfMode(mode.parent, match, matchPlusRemainder);\n }\n }\n\n /**\n * Handle matching but then ignoring a sequence of text\n *\n * @param {string} lexeme - string containing full match text\n */\n function doIgnore(lexeme) {\n if (top.matcher.regexIndex === 0) {\n // no more regexs to potentially match here, so we move the cursor forward one\n // space\n modeBuffer += lexeme[0];\n return 1;\n } else {\n // no need to move the cursor, we still have additional regexes to try and\n // match at this very spot\n resumeScanAtSamePosition = true;\n return 0;\n }\n }\n\n /**\n * Handle the start of a new potential mode match\n *\n * @param {EnhancedMatch} match - the current match\n * @returns {number} how far to advance the parse cursor\n */\n function doBeginMatch(match) {\n const lexeme = match[0];\n const newMode = match.rule;\n\n const resp = new Response(newMode);\n // first internal before callbacks, then the public ones\n const beforeCallbacks = [newMode.__beforeBegin, newMode[\"on:begin\"]];\n for (const cb of beforeCallbacks) {\n if (!cb) continue;\n cb(match, resp);\n if (resp.ignore) return doIgnore(lexeme);\n }\n\n if (newMode && newMode.endSameAsBegin) {\n newMode.endRe = escape(lexeme);\n }\n\n if (newMode.skip) {\n modeBuffer += lexeme;\n } else {\n if (newMode.excludeBegin) {\n modeBuffer += lexeme;\n }\n processBuffer();\n if (!newMode.returnBegin && !newMode.excludeBegin) {\n modeBuffer = lexeme;\n }\n }\n startNewMode(newMode);\n // if (mode[\"after:begin\"]) {\n // let resp = new Response(mode);\n // mode[\"after:begin\"](match, resp);\n // }\n return newMode.returnBegin ? 0 : lexeme.length;\n }\n\n /**\n * Handle the potential end of mode\n *\n * @param {RegExpMatchArray} match - the current match\n */\n function doEndMatch(match) {\n const lexeme = match[0];\n const matchPlusRemainder = codeToHighlight.substr(match.index);\n\n const endMode = endOfMode(top, match, matchPlusRemainder);\n if (!endMode) { return NO_MATCH; }\n\n const origin = top;\n if (origin.skip) {\n modeBuffer += lexeme;\n } else {\n if (!(origin.returnEnd || origin.excludeEnd)) {\n modeBuffer += lexeme;\n }\n processBuffer();\n if (origin.excludeEnd) {\n modeBuffer = lexeme;\n }\n }\n do {\n if (top.className) {\n emitter.closeNode();\n }\n if (!top.skip && !top.subLanguage) {\n relevance += top.relevance;\n }\n top = top.parent;\n } while (top !== endMode.parent);\n if (endMode.starts) {\n if (endMode.endSameAsBegin) {\n endMode.starts.endRe = endMode.endRe;\n }\n startNewMode(endMode.starts);\n }\n return origin.returnEnd ? 0 : lexeme.length;\n }\n\n function processContinuations() {\n const list = [];\n for (let current = top; current !== language; current = current.parent) {\n if (current.className) {\n list.unshift(current.className);\n }\n }\n list.forEach(item => emitter.openNode(item));\n }\n\n /** @type {{type?: MatchType, index?: number, rule?: Mode}}} */\n let lastMatch = {};\n\n /**\n * Process an individual match\n *\n * @param {string} textBeforeMatch - text preceeding the match (since the last match)\n * @param {EnhancedMatch} [match] - the match itself\n */\n function processLexeme(textBeforeMatch, match) {\n const lexeme = match && match[0];\n\n // add non-matched text to the current mode buffer\n modeBuffer += textBeforeMatch;\n\n if (lexeme == null) {\n processBuffer();\n return 0;\n }\n\n // we've found a 0 width match and we're stuck, so we need to advance\n // this happens when we have badly behaved rules that have optional matchers to the degree that\n // sometimes they can end up matching nothing at all\n // Ref: https://github.com/highlightjs/highlight.js/issues/2140\n if (lastMatch.type === \"begin\" && match.type === \"end\" && lastMatch.index === match.index && lexeme === \"\") {\n // spit the \"skipped\" character that our regex choked on back into the output sequence\n modeBuffer += codeToHighlight.slice(match.index, match.index + 1);\n if (!SAFE_MODE) {\n /** @type {AnnotatedError} */\n const err = new Error('0 width match regex');\n err.languageName = languageName;\n err.badRule = lastMatch.rule;\n throw err;\n }\n return 1;\n }\n lastMatch = match;\n\n if (match.type === \"begin\") {\n return doBeginMatch(match);\n } else if (match.type === \"illegal\" && !ignoreIllegals) {\n // illegal match, we do not continue processing\n /** @type {AnnotatedError} */\n const err = new Error('Illegal lexeme \"' + lexeme + '\" for mode \"' + (top.className || '') + '\"');\n err.mode = top;\n throw err;\n } else if (match.type === \"end\") {\n const processed = doEndMatch(match);\n if (processed !== NO_MATCH) {\n return processed;\n }\n }\n\n // edge case for when illegal matches $ (end of line) which is technically\n // a 0 width match but not a begin/end match so it's not caught by the\n // first handler (when ignoreIllegals is true)\n if (match.type === \"illegal\" && lexeme === \"\") {\n // advance so we aren't stuck in an infinite loop\n return 1;\n }\n\n // infinite loops are BAD, this is a last ditch catch all. if we have a\n // decent number of iterations yet our index (cursor position in our\n // parsing) still 3x behind our index then something is very wrong\n // so we bail\n if (iterations > 100000 && iterations > match.index * 3) {\n const err = new Error('potential infinite loop, way more iterations than matches');\n throw err;\n }\n\n /*\n Why might be find ourselves here? Only one occasion now. An end match that was\n triggered but could not be completed. When might this happen? When an `endSameasBegin`\n rule sets the end rule to a specific match. Since the overall mode termination rule that's\n being used to scan the text isn't recompiled that means that any match that LOOKS like\n the end (but is not, because it is not an exact match to the beginning) will\n end up here. A definite end match, but when `doEndMatch` tries to \"reapply\"\n the end rule and fails to match, we wind up here, and just silently ignore the end.\n\n This causes no real harm other than stopping a few times too many.\n */\n\n modeBuffer += lexeme;\n return lexeme.length;\n }\n\n const language = getLanguage(languageName);\n if (!language) {\n console.error(LANGUAGE_NOT_FOUND.replace(\"{}\", languageName));\n throw new Error('Unknown language: \"' + languageName + '\"');\n }\n\n const md = compileLanguage(language);\n let result = '';\n /** @type {CompiledMode} */\n let top = continuation || md;\n /** @type Record */\n const continuations = {}; // keep continuations for sub-languages\n const emitter = new options.__emitter(options);\n processContinuations();\n let modeBuffer = '';\n let relevance = 0;\n let index = 0;\n let iterations = 0;\n let resumeScanAtSamePosition = false;\n\n try {\n top.matcher.considerAll();\n\n for (;;) {\n iterations++;\n if (resumeScanAtSamePosition) {\n // only regexes not matched previously will now be\n // considered for a potential match\n resumeScanAtSamePosition = false;\n } else {\n top.matcher.considerAll();\n }\n top.matcher.lastIndex = index;\n\n const match = top.matcher.exec(codeToHighlight);\n // console.log(\"match\", match[0], match.rule && match.rule.begin)\n\n if (!match) break;\n\n const beforeMatch = codeToHighlight.substring(index, match.index);\n const processedCount = processLexeme(beforeMatch, match);\n index = match.index + processedCount;\n }\n processLexeme(codeToHighlight.substr(index));\n emitter.closeAllNodes();\n emitter.finalize();\n result = emitter.toHTML();\n\n return {\n relevance: relevance,\n value: result,\n language: languageName,\n illegal: false,\n emitter: emitter,\n top: top\n };\n } catch (err) {\n if (err.message && err.message.includes('Illegal')) {\n return {\n illegal: true,\n illegalBy: {\n msg: err.message,\n context: codeToHighlight.slice(index - 100, index + 100),\n mode: err.mode\n },\n sofar: result,\n relevance: 0,\n value: escape$1(codeToHighlight),\n emitter: emitter\n };\n } else if (SAFE_MODE) {\n return {\n illegal: false,\n relevance: 0,\n value: escape$1(codeToHighlight),\n emitter: emitter,\n language: languageName,\n top: top,\n errorRaised: err\n };\n } else {\n throw err;\n }\n }\n }\n\n /**\n * returns a valid highlight result, without actually doing any actual work,\n * auto highlight starts with this and it's possible for small snippets that\n * auto-detection may not find a better match\n * @param {string} code\n * @returns {HighlightResult}\n */\n function justTextHighlightResult(code) {\n const result = {\n relevance: 0,\n emitter: new options.__emitter(options),\n value: escape$1(code),\n illegal: false,\n top: PLAINTEXT_LANGUAGE\n };\n result.emitter.addText(code);\n return result;\n }\n\n /**\n Highlighting with language detection. Accepts a string with the code to\n highlight. Returns an object with the following properties:\n\n - language (detected language)\n - relevance (int)\n - value (an HTML string with highlighting markup)\n - second_best (object with the same structure for second-best heuristically\n detected language, may be absent)\n\n @param {string} code\n @param {Array} [languageSubset]\n @returns {AutoHighlightResult}\n */\n function highlightAuto(code, languageSubset) {\n languageSubset = languageSubset || options.languages || Object.keys(languages);\n const plaintext = justTextHighlightResult(code);\n\n const results = languageSubset.filter(getLanguage).filter(autoDetection).map(name =>\n _highlight(name, code, false)\n );\n results.unshift(plaintext); // plaintext is always an option\n\n const sorted = results.sort((a, b) => {\n // sort base on relevance\n if (a.relevance !== b.relevance) return b.relevance - a.relevance;\n\n // always award the tie to the base language\n // ie if C++ and Arduino are tied, it's more likely to be C++\n if (a.language && b.language) {\n if (getLanguage(a.language).supersetOf === b.language) {\n return 1;\n } else if (getLanguage(b.language).supersetOf === a.language) {\n return -1;\n }\n }\n\n // otherwise say they are equal, which has the effect of sorting on\n // relevance while preserving the original ordering - which is how ties\n // have historically been settled, ie the language that comes first always\n // wins in the case of a tie\n return 0;\n });\n\n const [best, secondBest] = sorted;\n\n /** @type {AutoHighlightResult} */\n const result = best;\n result.second_best = secondBest;\n\n return result;\n }\n\n /**\n Post-processing of the highlighted markup:\n\n - replace TABs with something more useful\n - replace real line-breaks with '
    ' for non-pre containers\n\n @param {string} html\n @returns {string}\n */\n function fixMarkup(html) {\n if (!(options.tabReplace || options.useBR)) {\n return html;\n }\n\n return html.replace(fixMarkupRe, match => {\n if (match === '\\n') {\n return options.useBR ? '
    ' : match;\n } else if (options.tabReplace) {\n return match.replace(/\\t/g, options.tabReplace);\n }\n return match;\n });\n }\n\n /**\n * Builds new class name for block given the language name\n *\n * @param {string} prevClassName\n * @param {string} [currentLang]\n * @param {string} [resultLang]\n */\n function buildClassName(prevClassName, currentLang, resultLang) {\n const language = currentLang ? aliases[currentLang] : resultLang;\n const result = [prevClassName.trim()];\n\n if (!prevClassName.match(/\\bhljs\\b/)) {\n result.push('hljs');\n }\n\n if (!prevClassName.includes(language)) {\n result.push(language);\n }\n\n return result.join(' ').trim();\n }\n\n /**\n * Applies highlighting to a DOM node containing code. Accepts a DOM node and\n * two optional parameters for fixMarkup.\n *\n * @param {HighlightedHTMLElement} element - the HTML element to highlight\n */\n function highlightBlock(element) {\n /** @type HTMLElement */\n let node = null;\n const language = blockLanguage(element);\n\n if (shouldNotHighlight(language)) return;\n\n fire(\"before:highlightBlock\",\n { block: element, language: language });\n\n if (options.useBR) {\n node = document.createElement('div');\n node.innerHTML = element.innerHTML.replace(/\\n/g, '').replace(//g, '\\n');\n } else {\n node = element;\n }\n const text = node.textContent;\n const result = language ? highlight(language, text, true) : highlightAuto(text);\n\n const originalStream = nodeStream$1(node);\n if (originalStream.length) {\n const resultNode = document.createElement('div');\n resultNode.innerHTML = result.value;\n result.value = mergeStreams$1(originalStream, nodeStream$1(resultNode), text);\n }\n result.value = fixMarkup(result.value);\n\n fire(\"after:highlightBlock\", { block: element, result: result });\n\n element.innerHTML = result.value;\n element.className = buildClassName(element.className, language, result.language);\n element.result = {\n language: result.language,\n // TODO: remove with version 11.0\n re: result.relevance,\n relavance: result.relevance\n };\n if (result.second_best) {\n element.second_best = {\n language: result.second_best.language,\n // TODO: remove with version 11.0\n re: result.second_best.relevance,\n relavance: result.second_best.relevance\n };\n }\n }\n\n /**\n * Updates highlight.js global options with the passed options\n *\n * @param {Partial} userOptions\n */\n function configure(userOptions) {\n if (userOptions.useBR) {\n console.warn(\"'useBR' option is deprecated and will be removed entirely in v11.0\");\n console.warn(\"Please see https://github.com/highlightjs/highlight.js/issues/2559\");\n }\n options = inherit$1(options, userOptions);\n }\n\n /**\n * Highlights to all
     blocks on a page\n   *\n   * @type {Function & {called?: boolean}}\n   */\n  const initHighlighting = () => {\n    if (initHighlighting.called) return;\n    initHighlighting.called = true;\n\n    const blocks = document.querySelectorAll('pre code');\n    ArrayProto.forEach.call(blocks, highlightBlock);\n  };\n\n  // Higlights all when DOMContentLoaded fires\n  function initHighlightingOnLoad() {\n    // @ts-ignore\n    window.addEventListener('DOMContentLoaded', initHighlighting, false);\n  }\n\n  /**\n   * Register a language grammar module\n   *\n   * @param {string} languageName\n   * @param {LanguageFn} languageDefinition\n   */\n  function registerLanguage(languageName, languageDefinition) {\n    let lang = null;\n    try {\n      lang = languageDefinition(hljs);\n    } catch (error) {\n      console.error(\"Language definition for '{}' could not be registered.\".replace(\"{}\", languageName));\n      // hard or soft error\n      if (!SAFE_MODE) { throw error; } else { console.error(error); }\n      // languages that have serious errors are replaced with essentially a\n      // \"plaintext\" stand-in so that the code blocks will still get normal\n      // css classes applied to them - and one bad language won't break the\n      // entire highlighter\n      lang = PLAINTEXT_LANGUAGE;\n    }\n    // give it a temporary name if it doesn't have one in the meta-data\n    if (!lang.name) lang.name = languageName;\n    languages[languageName] = lang;\n    lang.rawDefinition = languageDefinition.bind(null, hljs);\n\n    if (lang.aliases) {\n      registerAliases(lang.aliases, { languageName });\n    }\n  }\n\n  /**\n   * @returns {string[]} List of language internal names\n   */\n  function listLanguages() {\n    return Object.keys(languages);\n  }\n\n  /**\n    intended usage: When one language truly requires another\n\n    Unlike `getLanguage`, this will throw when the requested language\n    is not available.\n\n    @param {string} name - name of the language to fetch/require\n    @returns {Language | never}\n  */\n  function requireLanguage(name) {\n    console.warn(\"requireLanguage is deprecated and will be removed entirely in the future.\");\n    console.warn(\"Please see https://github.com/highlightjs/highlight.js/pull/2844\");\n\n    const lang = getLanguage(name);\n    if (lang) { return lang; }\n\n    const err = new Error('The \\'{}\\' language is required, but not loaded.'.replace('{}', name));\n    throw err;\n  }\n\n  /**\n   * @param {string} name - name of the language to retrieve\n   * @returns {Language | undefined}\n   */\n  function getLanguage(name) {\n    name = (name || '').toLowerCase();\n    return languages[name] || languages[aliases[name]];\n  }\n\n  /**\n   *\n   * @param {string|string[]} aliasList - single alias or list of aliases\n   * @param {{languageName: string}} opts\n   */\n  function registerAliases(aliasList, { languageName }) {\n    if (typeof aliasList === 'string') {\n      aliasList = [aliasList];\n    }\n    aliasList.forEach(alias => { aliases[alias] = languageName; });\n  }\n\n  /**\n   * Determines if a given language has auto-detection enabled\n   * @param {string} name - name of the language\n   */\n  function autoDetection(name) {\n    const lang = getLanguage(name);\n    return lang && !lang.disableAutodetect;\n  }\n\n  /**\n   * @param {HLJSPlugin} plugin\n   */\n  function addPlugin(plugin) {\n    plugins.push(plugin);\n  }\n\n  /**\n   *\n   * @param {PluginEvent} event\n   * @param {any} args\n   */\n  function fire(event, args) {\n    const cb = event;\n    plugins.forEach(function(plugin) {\n      if (plugin[cb]) {\n        plugin[cb](args);\n      }\n    });\n  }\n\n  /**\n  Note: fixMarkup is deprecated and will be removed entirely in v11\n\n  @param {string} arg\n  @returns {string}\n  */\n  function deprecateFixMarkup(arg) {\n    console.warn(\"fixMarkup is deprecated and will be removed entirely in v11.0\");\n    console.warn(\"Please see https://github.com/highlightjs/highlight.js/issues/2534\");\n\n    return fixMarkup(arg);\n  }\n\n  /* Interface definition */\n  Object.assign(hljs, {\n    highlight,\n    highlightAuto,\n    fixMarkup: deprecateFixMarkup,\n    highlightBlock,\n    configure,\n    initHighlighting,\n    initHighlightingOnLoad,\n    registerLanguage,\n    listLanguages,\n    getLanguage,\n    registerAliases,\n    requireLanguage,\n    autoDetection,\n    inherit: inherit$1,\n    addPlugin,\n    // plugins for frameworks\n    vuePlugin: BuildVuePlugin(hljs).VuePlugin\n  });\n\n  hljs.debugMode = function() { SAFE_MODE = false; };\n  hljs.safeMode = function() { SAFE_MODE = true; };\n  hljs.versionString = version;\n\n  for (const key in MODES) {\n    // @ts-ignore\n    if (typeof MODES[key] === \"object\") {\n      // @ts-ignore\n      deepFreezeEs6(MODES[key]);\n    }\n  }\n\n  // merge all the modes/regexs into our main object\n  Object.assign(hljs, MODES);\n\n  return hljs;\n};\n\n// export an \"instance\" of the highlighter\nvar highlight = HLJS({});\n\nmodule.exports = highlight;\n","// Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors\n// MIT License. See license.txt\n\nimport FileUploader from './file_uploader';\n\nfrappe.provide('frappe.ui');\nfrappe.ui.FileUploader = FileUploader;\n","// Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors\n// MIT License. See license.txt\n\nfrappe.provide('frappe.meta.docfield_map');\nfrappe.provide('frappe.meta.docfield_copy');\nfrappe.provide('frappe.meta.docfield_list');\nfrappe.provide('frappe.meta.doctypes');\nfrappe.provide(\"frappe.meta.precision_map\");\n\nfrappe.get_meta = function(doctype) {\n\treturn locals['DocType'] ? locals['DocType'][doctype] : null;\n}\n\n$.extend(frappe.meta, {\n\tsync: function(doc) {\n\t\t$.each(doc.fields, function(i, df) {\n\t\t\tfrappe.meta.add_field(df);\n\t\t})\n\t\tfrappe.meta.sync_messages(doc);\n\t\tif(doc.__print_formats) frappe.model.sync(doc.__print_formats);\n\t\tif(doc.__workflow_docs) frappe.model.sync(doc.__workflow_docs);\n\t},\n\n\t// build docfield_map and docfield_list\n\tadd_field: function(df) {\n\t\tfrappe.provide('frappe.meta.docfield_map.' + df.parent);\n\t\tfrappe.meta.docfield_map[df.parent][df.fieldname || df.label] = df;\n\n\t\tif(!frappe.meta.docfield_list[df.parent])\n\t\t\tfrappe.meta.docfield_list[df.parent] = [];\n\n\t\t// check for repeat\n\t\tfor(var i in frappe.meta.docfield_list[df.parent]) {\n\t\t\tvar d = frappe.meta.docfield_list[df.parent][i];\n\t\t\tif(df.fieldname==d.fieldname)\n\t\t\t\treturn; // no repeat\n\t\t}\n\t\tfrappe.meta.docfield_list[df.parent].push(df);\n\t},\n\n\tmake_docfield_copy_for: function(doctype, docname) {\n\t\tvar c = frappe.meta.docfield_copy;\n\t\tif(!c[doctype])\n\t\t\tc[doctype] = {};\n\t\tif(!c[doctype][docname])\n\t\t\tc[doctype][docname] = {};\n\n\t\tvar docfield_list = frappe.meta.docfield_list[doctype] || [];\n\t\tfor(var i=0, j=docfield_list.length; i%(name)s', {\n\t\t\t\t\tcolor: get_color(),\n\t\t\t\t\tname: get_text()\n\t\t\t\t});\n\t\t\t};\n\t},\n\n\tget_docfields: function(doctype, name, filters) {\n\t\tvar docfield_map = frappe.meta.get_docfield_copy(doctype, name);\n\n\t\tvar docfields = frappe.meta.sort_docfields(docfield_map);\n\n\t\tif(filters) {\n\t\t\tdocfields = frappe.utils.filter_dict(docfields, filters);\n\t\t}\n\n\t\treturn docfields;\n\t},\n\n\tget_linked_fields: function(doctype) {\n\t\treturn $.map(frappe.get_meta(doctype).fields,\n\t\t\tfunction(d) { return d.fieldtype==\"Link\" ? d.options : null; });\n\t},\n\n\tget_fields_to_check_permissions: function(doctype) {\n\t\tvar fields = $.map(frappe.meta.get_docfields(doctype, name), function(df) {\n\t\t\treturn (df.fieldtype===\"Link\" && df.ignore_user_permissions!==1) ? df : null;\n\t\t});\n\t\tfields = fields.concat({label: \"Name\", fieldname: name, options: doctype});\n\t\treturn fields;\n\t},\n\n\tsort_docfields: function(docs) {\n\t\treturn $.map(docs, function(d) { return d; }).sort(function(a, b) { return a.idx - b.idx });\n\t},\n\n\tget_docfield_copy: function(doctype, name) {\n\t\tif(!name) return frappe.meta.docfield_map[doctype];\n\n\t\tif(!(frappe.meta.docfield_copy[doctype] && frappe.meta.docfield_copy[doctype][name])) {\n\t\t\tfrappe.meta.make_docfield_copy_for(doctype, name);\n\t\t}\n\n\t\treturn frappe.meta.docfield_copy[doctype][name];\n\t},\n\n\tget_fieldnames: function(doctype, name, filters) {\n\t\treturn $.map(frappe.utils.filter_dict(frappe.meta.docfield_map[doctype], filters),\n\t\t\tfunction(df) { return df.fieldname; });\n\t},\n\n\thas_field: function(dt, fn) {\n\t\tlet docfield_map = frappe.meta.docfield_map[dt];\n\t\treturn docfield_map && docfield_map[fn];\n\t},\n\n\tget_table_fields: function(dt) {\n\t\treturn $.map(frappe.meta.docfield_list[dt], function(d) {\n\t\t\treturn frappe.model.table_fields.includes(d.fieldtype) ? d : null});\n\t},\n\n\tget_doctype_for_field: function(doctype, key) {\n\t\tvar out = null;\n\t\tif(in_list(frappe.model.std_fields_list, key)) {\n\t\t\t// standard\n\t\t\tout = doctype;\n\t\t} else if(frappe.meta.has_field(doctype, key)) {\n\t\t\t// found in parent\n\t\t\tout = doctype;\n\t\t} else {\n\t\t\tfrappe.meta.get_table_fields(doctype).every(function(d) {\n\t\t\t\tif(frappe.meta.has_field(d.options, key)) {\n\t\t\t\t\tout = d.options;\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t\treturn true;\n\t\t\t});\n\n\t\t\tif(!out) {\n\t\t\t\t// eslint-disable-next-line\n\t\t\t\tconsole.log(__('Warning: Unable to find {0} in any table related to {1}', [\n\t\t\t\t\tkey, __(doctype)]));\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t},\n\n\tget_parentfield: function(parent_dt, child_dt) {\n\t\tvar df = (frappe.get_doc(\"DocType\", parent_dt).fields || [])\n\t\t\t.filter(df => frappe.model.table_fields.includes(df.fieldtype) && df.options===child_dt)\n\t\tif(!df.length)\n\t\t\tthrow \"parentfield not found for \" + parent_dt + \", \" + child_dt;\n\t\treturn df[0].fieldname;\n\t},\n\n\tget_label: function(dt, fn, dn) {\n\t\tvar standard = {\n\t\t\t'owner': __('Owner'),\n\t\t\t'creation': __('Created On'),\n\t\t\t'modified': __('Last Modified On'),\n\t\t\t'idx': __('Idx'),\n\t\t\t'name': __('Name'),\n\t\t\t'modified_by': __('Last Modified By')\n\t\t}\n\t\tif(standard[fn]) {\n\t\t\treturn standard[fn];\n\t\t} else {\n\t\t\tvar df = this.get_docfield(dt, fn, dn);\n\t\t\treturn (df ? df.label : \"\") || fn;\n\t\t}\n\t},\n\n\tget_print_formats: function(doctype) {\n\t\tvar print_format_list = [\"Standard\"];\n\t\tvar default_print_format = locals.DocType[doctype].default_print_format;\n\t\tlet enable_raw_printing = frappe.model.get_doc(\":Print Settings\", \"Print Settings\").enable_raw_printing;\n\t\tvar print_formats = frappe.get_list(\"Print Format\", {doc_type: doctype})\n\t\t\t.sort(function(a, b) { return (a > b) ? 1 : -1; });\n\t\t$.each(print_formats, function(i, d) {\n\t\t\tif (\n\t\t\t\t!in_list(print_format_list, d.name)\n\t\t\t\t&& d.print_format_type !== 'JS'\n\t\t\t\t&& (cint(enable_raw_printing) || !d.raw_printing)\n\t\t\t) {\n\t\t\t\tprint_format_list.push(d.name);\n\t\t\t}\n\t\t});\n\n\t\tif(default_print_format && default_print_format != \"Standard\") {\n\t\t\tvar index = print_format_list.indexOf(default_print_format);\n\t\t\tprint_format_list.splice(index, 1).sort();\n\t\t\tprint_format_list.unshift(default_print_format);\n\t\t}\n\n\t\treturn print_format_list;\n\t},\n\n\tsync_messages: function(doc) {\n\t\tif(doc.__messages) {\n\t\t\t$.extend(frappe._messages, doc.__messages);\n\t\t}\n\t},\n\n\tget_field_currency: function(df, doc) {\n\t\tvar currency = frappe.boot.sysdefaults.currency;\n\t\tif(!doc && cur_frm)\n\t\t\tdoc = cur_frm.doc;\n\n\t\tif(df && df.options) {\n\t\t\tif(doc && df.options.indexOf(\":\")!=-1) {\n\t\t\t\tvar options = df.options.split(\":\");\n\t\t\t\tif(options.length==3) {\n\t\t\t\t\t// get reference record e.g. Company\n\t\t\t\t\tvar docname = doc[options[1]];\n\t\t\t\t\tif(!docname && cur_frm) {\n\t\t\t\t\t\tdocname = cur_frm.doc[options[1]];\n\t\t\t\t\t}\n\t\t\t\t\tcurrency = frappe.model.get_value(options[0], docname, options[2]) ||\n\t\t\t\t\t\tfrappe.model.get_value(\":\" + options[0], docname, options[2]) ||\n\t\t\t\t\t\tcurrency;\n\t\t\t\t}\n\t\t\t} else if(doc && doc[df.options]) {\n\t\t\t\tcurrency = doc[df.options];\n\t\t\t} else if(cur_frm && cur_frm.doc[df.options]) {\n\t\t\t\tcurrency = cur_frm.doc[df.options];\n\t\t\t}\n\t\t}\n\t\treturn currency;\n\t},\n\n\tget_field_precision: function(df, doc) {\n\t\tvar precision = null;\n\t\tif (df && df.precision) {\n\t\t\tprecision = cint(df.precision);\n\t\t} else if(df && df.fieldtype === \"Currency\") {\n\t\t\tprecision = cint(frappe.defaults.get_default(\"currency_precision\"));\n\t\t\tif(!precision) {\n\t\t\t\tvar number_format = get_number_format();\n\t\t\t\tvar number_format_info = get_number_format_info(number_format);\n\t\t\t\tprecision = number_format_info.precision;\n\t\t\t}\n\t\t} else {\n\t\t\tprecision = cint(frappe.defaults.get_default(\"float_precision\")) || 3;\n\t\t}\n\t\treturn precision;\n\t},\n});\n","// Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors\n// MIT License. See license.txt\n\nfrappe.provide('frappe.model');\n\n$.extend(frappe.model, {\n\tno_value_type: ['Section Break', 'Column Break', 'HTML', 'Table', 'Table MultiSelect',\n\t\t'Button', 'Image', 'Fold', 'Heading'],\n\n\tlayout_fields: ['Section Break', 'Column Break', 'Fold'],\n\n\tstd_fields_list: ['name', 'owner', 'creation', 'modified', 'modified_by',\n\t\t'_user_tags', '_comments', '_assign', '_liked_by', 'docstatus',\n\t\t'parent', 'parenttype', 'parentfield', 'idx'],\n\n\tcore_doctypes_list: ['DocType', 'DocField', 'DocPerm', 'User', 'Role', 'Has Role',\n\t\t'Page', 'Module Def', 'Print Format', 'Report', 'Customize Form',\n\t\t'Customize Form Field', 'Property Setter', 'Custom Field', 'Custom Script'],\n\n\tstd_fields: [\n\t\t{fieldname:'name', fieldtype:'Link', label:__('ID')},\n\t\t{fieldname:'owner', fieldtype:'Link', label:__('Created By'), options: 'User'},\n\t\t{fieldname:'idx', fieldtype:'Int', label:__('Index')},\n\t\t{fieldname:'creation', fieldtype:'Date', label:__('Created On')},\n\t\t{fieldname:'modified', fieldtype:'Date', label:__('Last Updated On')},\n\t\t{fieldname:'modified_by', fieldtype:'Data', label:__('Last Updated By')},\n\t\t{fieldname:'_user_tags', fieldtype:'Data', label:__('Tags')},\n\t\t{fieldname:'_liked_by', fieldtype:'Data', label:__('Liked By')},\n\t\t{fieldname:'_comments', fieldtype:'Text', label:__('Comments')},\n\t\t{fieldname:'_assign', fieldtype:'Text', label:__('Assigned To')},\n\t\t{fieldname:'docstatus', fieldtype:'Int', label:__('Document Status')},\n\t],\n\n\tnumeric_fieldtypes: [\"Int\", \"Float\", \"Currency\", \"Percent\"],\n\n\tstd_fields_table: [\n\t\t{fieldname:'parent', fieldtype:'Data', label:__('Parent')},\n\t],\n\n\ttable_fields: ['Table', 'Table MultiSelect'],\n\n\tnew_names: {},\n\tevents: {},\n\tuser_settings: {},\n\n\tinit: function() {\n\t\t// setup refresh if the document is updated somewhere else\n\t\tfrappe.realtime.on(\"doc_update\", function(data) {\n\t\t\t// set list dirty\n\t\t\tfrappe.views.ListView.trigger_list_update(data);\n\t\t\tvar doc = locals[data.doctype] && locals[data.doctype][data.name];\n\n\t\t\tif(doc) {\n\t\t\t\t// current document is dirty, show message if its not me\n\t\t\t\tif(frappe.get_route()[0]===\"Form\" && cur_frm.doc.doctype===doc.doctype && cur_frm.doc.name===doc.name) {\n\t\t\t\t\tif(!frappe.ui.form.is_saving && data.modified!=cur_frm.doc.modified) {\n\t\t\t\t\t\tdoc.__needs_refresh = true;\n\t\t\t\t\t\tcur_frm.show_conflict_message();\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tif(!doc.__unsaved) {\n\t\t\t\t\t\t// no local changes, remove from locals\n\t\t\t\t\t\tfrappe.model.remove_from_locals(doc.doctype, doc.name);\n\t\t\t\t\t} else {\n\t\t\t\t\t\t// show message when user navigates back\n\t\t\t\t\t\tdoc.__needs_refresh = true;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\n\t\tfrappe.realtime.on(\"list_update\", function(data) {\n\t\t\tfrappe.views.ListView.trigger_list_update(data);\n\t\t});\n\n\t},\n\n\tis_value_type: function(fieldtype) {\n\t\tif (typeof fieldtype == 'object') {\n\t\t\tfieldtype = fieldtype.fieldtype;\n\t\t}\n\t\t// not in no-value type\n\t\treturn frappe.model.no_value_type.indexOf(fieldtype)===-1;\n\t},\n\n\tis_non_std_field: function(fieldname) {\n\t\treturn !frappe.model.std_fields_list.includes(fieldname);\n\t},\n\n\tget_std_field: function(fieldname, ignore=false) {\n\t\tvar docfield = $.map([].concat(frappe.model.std_fields).concat(frappe.model.std_fields_table),\n\t\t\tfunction(d) {\n\t\t\t\tif(d.fieldname==fieldname) return d;\n\t\t\t});\n\t\tif (!docfield.length) {\n\t\t\t//Standard fields are ignored in case of adding columns as a result of groupby\n\t\t\tif (ignore) {\n\t\t\t\treturn {fieldname: fieldname};\n\t\t\t} else {\n\t\t\t\tfrappe.msgprint(__(\"Unknown Column: {0}\", [fieldname]));\n\t\t\t}\n\t\t}\n\t\treturn docfield[0];\n\t},\n\n\twith_doctype: function(doctype, callback, async) {\n\t\tif(locals.DocType[doctype]) {\n\t\t\tcallback && callback();\n\t\t} else {\n\t\t\tlet cached_timestamp = null;\n\t\t\tlet cached_doc = null;\n\n\t\t\tif(localStorage[\"_doctype:\" + doctype]) {\n\t\t\t\tlet cached_docs = JSON.parse(localStorage[\"_doctype:\" + doctype]);\n\t\t\t\tcached_doc = cached_docs.filter(doc => doc.name === doctype)[0];\n\t\t\t\tif(cached_doc) {\n\t\t\t\t\tcached_timestamp = cached_doc.modified;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn frappe.call({\n\t\t\t\tmethod:'frappe.desk.form.load.getdoctype',\n\t\t\t\ttype: \"GET\",\n\t\t\t\targs: {\n\t\t\t\t\tdoctype: doctype,\n\t\t\t\t\twith_parent: 1,\n\t\t\t\t\tcached_timestamp: cached_timestamp\n\t\t\t\t},\n\t\t\t\tasync: async,\n\t\t\t\tcallback: function(r) {\n\t\t\t\t\tif(r.exc) {\n\t\t\t\t\t\tfrappe.msgprint(__(\"Unable to load: {0}\", [__(doctype)]));\n\t\t\t\t\t\tthrow \"No doctype\";\n\t\t\t\t\t}\n\t\t\t\t\tif(r.message==\"use_cache\") {\n\t\t\t\t\t\tfrappe.model.sync(cached_doc);\n\t\t\t\t\t} else {\n\t\t\t\t\t\tlocalStorage[\"_doctype:\" + doctype] = JSON.stringify(r.docs);\n\t\t\t\t\t}\n\t\t\t\t\tfrappe.model.init_doctype(doctype);\n\n\t\t\t\t\tif(r.user_settings) {\n\t\t\t\t\t\t// remember filters and other settings from last view\n\t\t\t\t\t\tfrappe.model.user_settings[doctype] = JSON.parse(r.user_settings);\n\t\t\t\t\t\tfrappe.model.user_settings[doctype].updated_on = moment().toString();\n\t\t\t\t\t}\n\t\t\t\t\tcallback && callback(r);\n\t\t\t\t}\n\t\t\t});\n\t\t}\n\t},\n\n\tinit_doctype: function(doctype) {\n\t\tvar meta = locals.DocType[doctype];\n\t\tif(meta.__list_js) {\n\t\t\teval(meta.__list_js);\n\t\t}\n\t\tif(meta.__calendar_js) {\n\t\t\teval(meta.__calendar_js);\n\t\t}\n\t\tif(meta.__map_js) {\n\t\t\teval(meta.__map_js);\n\t\t}\n\t\tif(meta.__tree_js) {\n\t\t\teval(meta.__tree_js);\n\t\t}\n\t\tif(meta.__templates) {\n\t\t\t$.extend(frappe.templates, meta.__templates);\n\t\t}\n\t},\n\n\twith_doc: function(doctype, name, callback) {\n\t\treturn new Promise(resolve => {\n\t\t\tif(!name) name = doctype; // single type\n\t\t\tif(locals[doctype] && locals[doctype][name] && frappe.model.get_docinfo(doctype, name)) {\n\t\t\t\tcallback && callback(name);\n\t\t\t\tresolve(frappe.get_doc(doctype, name));\n\t\t\t} else {\n\t\t\t\treturn frappe.call({\n\t\t\t\t\tmethod: 'frappe.desk.form.load.getdoc',\n\t\t\t\t\ttype: \"GET\",\n\t\t\t\t\targs: {\n\t\t\t\t\t\tdoctype: doctype,\n\t\t\t\t\t\tname: name\n\t\t\t\t\t},\n\t\t\t\t\tcallback: function(r) {\n\t\t\t\t\t\tcallback && callback(name, r);\n\t\t\t\t\t\tresolve(frappe.get_doc(doctype, name));\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t}\n\t\t});\n\t},\n\n\tget_docinfo: function(doctype, name) {\n\t\treturn frappe.model.docinfo[doctype] && frappe.model.docinfo[doctype][name] || null;\n\t},\n\n\tset_docinfo: function(doctype, name, key, value) {\n\t\tif (frappe.model.docinfo[doctype] && frappe.model.docinfo[doctype][name]) {\n\t\t\tfrappe.model.docinfo[doctype][name][key] = value;\n\t\t}\n\t},\n\n\tget_shared: function(doctype, name) {\n\t\treturn frappe.model.get_docinfo(doctype, name).shared;\n\t},\n\n\tget_server_module_name: function(doctype) {\n\t\tvar dt = frappe.model.scrub(doctype);\n\t\tvar module = frappe.model.scrub(locals.DocType[doctype].module);\n\t\tvar app = frappe.boot.module_app[module];\n\t\treturn app + \".\" + module + '.doctype.' + dt + '.' + dt;\n\t},\n\n\tscrub: function(txt) {\n\t\treturn txt.replace(/ /g, \"_\").toLowerCase();  // use to slugify or create a slug, a \"code-friendly\" string\n\t},\n\n\tunscrub: function(txt) {\n\t\treturn __(txt || '').replace(/-|_/g, \" \").replace(/\\w*/g,\n            function(keywords){return keywords.charAt(0).toUpperCase() + keywords.substr(1).toLowerCase();});\n\t},\n\n\tcan_create: function(doctype) {\n\t\treturn frappe.boot.user.can_create.indexOf(doctype)!==-1;\n\t},\n\n\tcan_read: function(doctype) {\n\t\treturn frappe.boot.user.can_read.indexOf(doctype)!==-1;\n\t},\n\n\tcan_write: function(doctype) {\n\t\treturn frappe.boot.user.can_write.indexOf(doctype)!==-1;\n\t},\n\n\tcan_get_report: function(doctype) {\n\t\treturn frappe.boot.user.can_get_report.indexOf(doctype)!==-1;\n\t},\n\n\tcan_delete: function(doctype) {\n\t\tif(!doctype) return false;\n\t\treturn frappe.boot.user.can_delete.indexOf(doctype)!==-1;\n\t},\n\n\tcan_cancel: function(doctype) {\n\t\tif(!doctype) return false;\n\t\treturn frappe.boot.user.can_cancel.indexOf(doctype)!==-1;\n\t},\n\n\thas_workflow: function(doctype) {\n\t\treturn frappe.get_list('Workflow', {'document_type': doctype,\n\t\t\t'is_active': 1}).length;\n\t},\n\n\tis_submittable: function(doctype) {\n\t\tif(!doctype) return false;\n\t\treturn locals.DocType[doctype]\n\t\t\t&& locals.DocType[doctype].is_submittable;\n\t},\n\n\tis_table: function(doctype) {\n\t\tif(!doctype) return false;\n\t\treturn locals.DocType[doctype] && locals.DocType[doctype].istable;\n\t},\n\n\tis_single: function(doctype) {\n\t\tif(!doctype) return false;\n\t\treturn frappe.boot.single_types.indexOf(doctype) != -1;\n\t},\n\n\tcan_import: function(doctype, frm) {\n\t\t// system manager can always import\n\t\tif(frappe.user_roles.includes(\"System Manager\")) return true;\n\n\t\tif(frm) return frm.perm[0].import===1;\n\t\treturn frappe.boot.user.can_import.indexOf(doctype)!==-1;\n\t},\n\n\tcan_export: function(doctype, frm) {\n\t\t// system manager can always export\n\t\tif(frappe.user_roles.includes(\"System Manager\")) return true;\n\n\t\tif(frm) return frm.perm[0].export===1;\n\t\treturn frappe.boot.user.can_export.indexOf(doctype)!==-1;\n\t},\n\n\tcan_print: function(doctype, frm) {\n\t\tif(frm) return frm.perm[0].print===1;\n\t\treturn frappe.boot.user.can_print.indexOf(doctype)!==-1;\n\t},\n\n\tcan_email: function(doctype, frm) {\n\t\tif(frm) return frm.perm[0].email===1;\n\t\treturn frappe.boot.user.can_email.indexOf(doctype)!==-1;\n\t},\n\n\tcan_share: function(doctype, frm) {\n\t\tif(frm) {\n\t\t\treturn frm.perm[0].share===1;\n\t\t}\n\t\treturn frappe.boot.user.can_share.indexOf(doctype)!==-1;\n\t},\n\n\tcan_set_user_permissions: function(doctype, frm) {\n\t\t// system manager can always set user permissions\n\t\tif(frappe.user_roles.includes(\"System Manager\")) return true;\n\n\t\tif(frm) return frm.perm[0].set_user_permissions===1;\n\t\treturn frappe.boot.user.can_set_user_permissions.indexOf(doctype)!==-1;\n\t},\n\n\thas_value: function(dt, dn, fn) {\n\t\t// return true if property has value\n\t\tvar val = locals[dt] && locals[dt][dn] && locals[dt][dn][fn];\n\t\tvar df = frappe.meta.get_docfield(dt, fn, dn);\n\n\t\tif(frappe.model.table_fields.includes(df.fieldtype)) {\n\t\t\tvar ret = false;\n\t\t\t$.each(locals[df.options] || {}, function(k,d) {\n\t\t\t\tif(d.parent==dn && d.parenttype==dt && d.parentfield==df.fieldname) {\n\t\t\t\t\tret = true;\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t});\n\t\t} else {\n\t\t\tvar ret = !is_null(val);\n\t\t}\n\t\treturn ret ? true : false;\n\t},\n\n\tget_list: function(doctype, filters) {\n\t\tvar docsdict = locals[doctype] || locals[\":\" + doctype] || {};\n\t\tif($.isEmptyObject(docsdict))\n\t\t\treturn [];\n\t\treturn frappe.utils.filter_dict(docsdict, filters);\n\t},\n\n\tget_value: function(doctype, filters, fieldname, callback) {\n\t\tif(callback) {\n\t\t\tfrappe.call({\n\t\t\t\tmethod:\"frappe.client.get_value\",\n\t\t\t\targs: {\n\t\t\t\t\tdoctype: doctype,\n\t\t\t\t\tfieldname: fieldname,\n\t\t\t\t\tfilters: filters\n\t\t\t\t},\n\t\t\t\tcallback: function(r) {\n\t\t\t\t\tif(!r.exc) {\n\t\t\t\t\t\tcallback(r.message);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t});\n\t\t} else {\n\t\t\tif(typeof filters===\"string\" && locals[doctype] && locals[doctype][filters]) {\n\t\t\t\treturn locals[doctype][filters][fieldname];\n\t\t\t} else {\n\t\t\t\tvar l = frappe.get_list(doctype, filters);\n\t\t\t\treturn (l.length && l[0]) ? l[0][fieldname] : null;\n\t\t\t}\n\t\t}\n\t},\n\n\tset_value: function(doctype, docname, fieldname, value, fieldtype) {\n\t\t/* help: Set a value locally (if changed) and execute triggers */\n\n\t\tvar doc;\n\t\tif ($.isPlainObject(doctype)) {\n\t\t\t// first parameter is the doc, shift parameters to the left\n\t\t\tdoc = doctype; fieldname = docname; value = fieldname;\n\t\t} else {\n\t\t\tdoc = locals[doctype] && locals[doctype][docname];\n\t\t}\n\n\t\tlet to_update = fieldname;\n\t\tlet tasks = [];\n\t\tif(!$.isPlainObject(to_update)) {\n\t\t\tto_update = {};\n\t\t\tto_update[fieldname] = value;\n\t\t}\n\n\t\t$.each(to_update, (key, value) => {\n\t\t\tif (doc && doc[key] !== value) {\n\t\t\t\tif(doc.__unedited && !(!doc[key] && !value)) {\n\t\t\t\t\t// unset unedited flag for virgin rows\n\t\t\t\t\tdoc.__unedited = false;\n\t\t\t\t}\n\n\t\t\t\tdoc[key] = value;\n\t\t\t\ttasks.push(() => frappe.model.trigger(key, value, doc));\n\t\t\t} else {\n\t\t\t\t// execute link triggers (want to reselect to execute triggers)\n\t\t\t\tif(in_list([\"Link\", \"Dynamic Link\"], fieldtype) && doc) {\n\t\t\t\t\ttasks.push(() => frappe.model.trigger(key, value, doc));\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\n\t\treturn frappe.run_serially(tasks);\n\t},\n\n\ton: function(doctype, fieldname, fn) {\n\t\t/* help: Attach a trigger on change of a particular field.\n\t\tTo trigger on any change in a particular doctype, use fieldname as \"*\"\n\t\t*/\n\t\t/* example: frappe.model.on(\"Customer\", \"age\", function(fieldname, value, doc) {\n\t\t  if(doc.age < 16) {\n\t\t   \tfrappe.msgprint(\"Warning, Customer must atleast be 16 years old.\");\n\t\t    raise \"CustomerAgeError\";\n\t\t  }\n\t\t}) */\n\t\tfrappe.provide(\"frappe.model.events.\" + doctype);\n\t\tif(!frappe.model.events[doctype][fieldname]) {\n\t\t\tfrappe.model.events[doctype][fieldname] = [];\n\t\t}\n\t\tfrappe.model.events[doctype][fieldname].push(fn);\n\t},\n\n\ttrigger: function(fieldname, value, doc) {\n\t\tconst tasks = [];\n\n\t\tfunction enqueue_events(events) {\n\t\t\tif (!events) return;\n\n\t\t\tfor (const fn of events) {\n\t\t\t\tif (!fn) continue;\n\n\t\t\t\ttasks.push(() => {\n\t\t\t\t\tconst return_value = fn(fieldname, value, doc);\n\n\t\t\t\t\t// if the trigger returns a promise, return it,\n\t\t\t\t\t// or use the default promise frappe.after_ajax\n\t\t\t\t\tif (return_value && return_value.then) {\n\t\t\t\t\t\treturn return_value;\n\t\t\t\t\t} else {\n\t\t\t\t\t\treturn frappe.after_server_call();\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t}\n\t\t};\n\n\t\tif(frappe.model.events[doc.doctype]) {\n\t\t\tenqueue_events(frappe.model.events[doc.doctype][fieldname]);\n\t\t\tenqueue_events(frappe.model.events[doc.doctype]['*']);\n\t\t}\n\n\t\treturn frappe.run_serially(tasks);\n\t},\n\n\tget_doc: function(doctype, name) {\n\t\tif(!name) name = doctype;\n\t\tif($.isPlainObject(name)) {\n\t\t\tvar doc = frappe.get_list(doctype, name);\n\t\t\treturn doc && doc.length ? doc[0] : null;\n\t\t}\n\t\treturn locals[doctype] ? locals[doctype][name] : null;\n\t},\n\n\tget_children: function(doctype, parent, parentfield, filters) {\n\t\tif($.isPlainObject(doctype)) {\n\t\t\tvar doc = doctype;\n\t\t\tvar filters = parentfield\n\t\t\tvar parentfield = parent;\n\t\t} else {\n\t\t\tvar doc = frappe.get_doc(doctype, parent);\n\t\t}\n\n\t\tvar children = doc[parentfield] || [];\n\t\tif(filters) {\n\t\t\treturn frappe.utils.filter_dict(children, filters);\n\t\t} else {\n\t\t\treturn children;\n\t\t}\n\t},\n\n\tclear_table: function(doc, parentfield) {\n\t\tfor (var i=0, l=(doc[parentfield] || []).length; i {\n\t\tif (!permlevel) permlevel = 0;\n\t\tif (!frappe.perm.doctype_perm[doctype]) {\n\t\t\tfrappe.perm.doctype_perm[doctype] = frappe.perm.get_perm(doctype);\n\t\t}\n\n\t\tlet perms = frappe.perm.doctype_perm[doctype];\n\n\t\tif (!perms || !perms[permlevel]) return false;\n\n\t\tlet perm = !!perms[permlevel][ptype];\n\n\t\tif (permlevel === 0 && perm && doc) {\n\t\t\tlet docinfo = frappe.model.get_docinfo(doctype, doc.name);\n\t\t\tif (docinfo && !docinfo.permissions[ptype])\n\t\t\t\tperm = false;\n\t\t}\n\n\t\treturn perm;\n\t},\n\n\tget_perm: (doctype, doc) => {\n\t\tlet perm = [{ read: 0, permlevel: 0 }];\n\n\t\tlet meta = frappe.get_doc(\"DocType\", doctype);\n\t\tconst user  = frappe.session.user;\n\n\t\tif (user === \"Administrator\" || frappe.user_roles.includes(\"Administrator\")) {\n\t\t\tperm[0].read = 1;\n\t\t}\n\n\t\tif (!meta) return perm;\n\n\t\tperm = frappe.perm.get_role_permissions(meta);\n\n\t\tif (doc) {\n\t\t\t// apply user permissions via docinfo (which is processed server-side)\n\t\t\tlet docinfo = frappe.model.get_docinfo(doctype, doc.name);\n\t\t\tif (docinfo && docinfo.permissions) {\n\t\t\t\tObject.keys(docinfo.permissions).forEach((ptype) => {\n\t\t\t\t\tperm[0][ptype] = docinfo.permissions[ptype];\n\t\t\t\t});\n\t\t\t}\n\n\t\t\t// if owner\n\t\t\tif (!$.isEmptyObject(perm[0].if_owner)) {\n\t\t\t\tif (doc.owner === user) {\n\t\t\t\t\t$.extend(perm[0], perm[0].if_owner);\n\t\t\t\t} else {\n\t\t\t\t\t// not owner, remove permissions\n\t\t\t\t\t$.each(perm[0].if_owner, (ptype) => {\n\t\t\t\t\t\tif (perm[0].if_owner[ptype]) {\n\t\t\t\t\t\t\tperm[0][ptype] = 0;\n\t\t\t\t\t\t}\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// apply permissions from shared\n\t\t\tif (docinfo && docinfo.shared) {\n\t\t\t\tfor (let i = 0; i < docinfo.shared.length; i++) {\n\t\t\t\t\tlet s = docinfo.shared[i];\n\t\t\t\t\tif (s.user === user) {\n\t\t\t\t\t\tperm[0][\"read\"] = perm[0][\"read\"] || s.read;\n\t\t\t\t\t\tperm[0][\"write\"] = perm[0][\"write\"] || s.write;\n\t\t\t\t\t\tperm[0][\"share\"] = perm[0][\"share\"] || s.share;\n\n\t\t\t\t\t\tif (s.read) {\n\t\t\t\t\t\t\t// also give print, email permissions if read\n\t\t\t\t\t\t\t// and these permissions exist at level [0]\n\t\t\t\t\t\t\tperm[0].email = frappe.boot.user.can_email.indexOf(doctype) !== -1 ? 1 : 0;\n\t\t\t\t\t\t\tperm[0].print = frappe.boot.user.can_print.indexOf(doctype) !== -1 ? 1 : 0;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t}\n\n\t\tif (frappe.model.can_read(doctype) && !perm[0].read) {\n\t\t\t// read via sharing\n\t\t\tperm[0].read = 1;\n\t\t}\n\n\t\treturn perm;\n\t},\n\n\tget_role_permissions: (meta) => {\n\t\tlet perm = [{ read: 0, permlevel: 0 }];\n\t\t// Returns a `dict` of evaluated Role Permissions\n\t\t(meta.permissions || []).forEach(p => {\n\t\t\t// if user has this role\n\t\t\tlet permlevel = cint(p.permlevel);\n\t\t\tif (!perm[permlevel]) {\n\t\t\t\tperm[permlevel] = {};\n\t\t\t\tperm[permlevel][\"permlevel\"] = permlevel;\n\t\t\t}\n\n\t\t\tif (frappe.user_roles.includes(p.role)) {\n\t\t\t\tfrappe.perm.rights.forEach(right => {\n\t\t\t\t\tlet value = perm[permlevel][right] || (p[right] || 0);\n\t\t\t\t\tif (value) {\n\t\t\t\t\t\tperm[permlevel][right] = value;\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t}\n\t\t});\n\n\t\t// fill gaps with empty object\n\t\tperm = perm.map(p => p || {});\n\t\treturn perm;\n\t},\n\n\tget_match_rules: (doctype, ptype) => {\n\t\tlet match_rules = [];\n\n\t\tif (!ptype) ptype = \"read\";\n\n\t\tlet perm = frappe.perm.get_perm(doctype);\n\n\t\tlet user_permissions = frappe.defaults.get_user_permissions();\n\n\t\tif (user_permissions && !$.isEmptyObject(user_permissions)) {\n\t\t\tlet rules = {};\n\t\t\tlet fields_to_check = frappe.meta.get_fields_to_check_permissions(doctype);\n\t\t\t$.each(fields_to_check, (i, df) => {\n\t\t\t\tconst user_permissions_for_doctype = user_permissions[df.options] || [];\n\t\t\t\tconst allowed_records = frappe.perm.get_allowed_docs_for_doctype(user_permissions_for_doctype, doctype);\n\t\t\t\tif (allowed_records.length) {\n\t\t\t\t\trules[df.label] = allowed_records;\n\t\t\t\t}\n\t\t\t});\n\t\t\tif (!$.isEmptyObject(rules)) {\n\t\t\t\tmatch_rules.push(rules);\n\t\t\t}\n\t\t}\n\n\t\tif (perm[0].if_owner && perm[0].read) {\n\t\t\tmatch_rules.push({ \"Owner\": frappe.session.user });\n\t\t}\n\t\treturn match_rules;\n\t},\n\n\tget_field_display_status: (df, doc, perm, explain) => {\n\t\t// returns the display status of a particular field\n\t\t// returns one of \"Read\", \"Write\" or \"None\"\n\t\tif (!perm && doc) {\n\t\t\tperm = frappe.perm.get_perm(doc.doctype, doc);\n\t\t}\n\n\t\tif (!perm) {\n\t\t\treturn (df && (cint(df.hidden) || cint(df.hidden_due_to_dependency))) ? \"None\" : \"Write\";\n\t\t}\n\n\t\tif (!df.permlevel) df.permlevel = 0;\n\t\tlet p = perm[df.permlevel];\n\t\tlet status = \"None\";\n\n\t\t// permission\n\t\tif (p) {\n\t\t\tif (p.write && !df.disabled) {\n\t\t\t\tstatus = \"Write\";\n\t\t\t} else if (p.read) {\n\t\t\t\tstatus = \"Read\";\n\t\t\t}\n\t\t}\n\t\tif (explain) console.log(\"By Permission:\" + status);\n\n\t\t// hidden\n\t\tif (cint(df.hidden)) status = \"None\";\n\t\tif (explain) console.log(\"By Hidden:\" + status);\n\n\t\t// hidden due to dependency\n\t\tif (cint(df.hidden_due_to_dependency)) status = \"None\";\n\t\tif (explain) console.log(\"By Hidden Due To Dependency:\" + status);\n\n\t\tif (!doc) {\n\t\t\treturn status;\n\t\t}\n\n\t\t// submit\n\t\tif (status === \"Write\" && cint(doc.docstatus) > 0) status = \"Read\";\n\t\tif (explain) console.log(\"By Submit:\" + status);\n\n\t\t// allow on submit\n\t\t// let allow_on_submit = df.fieldtype===\"Table\" ? 0 : cint(df.allow_on_submit);\n\t\tlet allow_on_submit = cint(df.allow_on_submit);\n\t\tif (status === \"Read\" && allow_on_submit && cint(doc.docstatus) === 1 && p.write) {\n\t\t\tstatus = \"Write\";\n\t\t}\n\t\tif (explain) console.log(\"By Allow on Submit:\" + status);\n\n\t\t// workflow state\n\t\tif (status === \"Read\" && cur_frm && cur_frm.state_fieldname) {\n\t\t\t// fields updated by workflow must be read-only\n\t\t\tif (cint(cur_frm.read_only) ||\n\t\t\t\tin_list(cur_frm.states.update_fields, df.fieldname) ||\n\t\t\t\tdf.fieldname == cur_frm.state_fieldname) {\n\t\t\t\tstatus = \"Read\";\n\t\t\t}\n\t\t}\n\t\tif (explain) console.log(\"By Workflow:\" + status);\n\n\t\t// read only field is checked\n\t\tif (status === \"Write\" && cint(df.read_only)) {\n\t\t\tstatus = \"Read\";\n\t\t}\n\t\tif (explain) console.log(\"By Read Only:\" + status);\n\n\t\tif (status === \"Write\" && df.set_only_once && !doc.__islocal) {\n\t\t\tstatus = \"Read\";\n\t\t}\n\t\tif (explain) console.log(\"By Set Only Once:\" + status);\n\n\t\treturn status;\n\t},\n\n\tis_visible: (df, doc, perm) => {\n\t\tif (typeof df === 'string') {\n\t\t\t// df is fieldname\n\t\t\tdf = frappe.meta.get_docfield(doc.doctype, df, doc.parent || doc.name);\n\t\t}\n\n\t\tlet status = frappe.perm.get_field_display_status(df, doc, perm);\n\n\t\treturn status === \"None\" ? false : true;\n\t},\n\n\tget_allowed_docs_for_doctype: (user_permissions, doctype) => {\n\t\t// returns docs from the list of user permissions that are allowed under provided doctype\n\t\treturn frappe.perm.filter_allowed_docs_for_doctype(user_permissions, doctype, false);\n\t},\n\n\tfilter_allowed_docs_for_doctype: (user_permissions, doctype, with_default_doc=true) => {\n\t\t// returns docs from the list of user permissions that are allowed under provided doctype\n\t\t// also returns default doc when with_default_doc is set\n\t\tconst filtered_perms = (user_permissions || []).filter(perm => {\n\t\t\treturn (perm.applicable_for === doctype || !perm.applicable_for);\n\t\t});\n\n\t\tconst allowed_docs = (filtered_perms).map(perm => perm.doc);\n\n\t\tif (with_default_doc) {\n\t\t\tconst default_doc = allowed_docs.length === 1 ? allowed_docs : filtered_perms\n\t\t\t\t.filter(perm => perm.is_default)\n\t\t\t\t.map(record => record.doc);\n\n\t\t\treturn {\n\t\t\t\tallowed_records: allowed_docs,\n\t\t\t\tdefault_doc: default_doc[0]\n\t\t\t};\n\t\t} else {\n\t\t\treturn allowed_docs;\n\t\t}\n\t}\n});","const IDENT_RE = '[A-Za-z$_][0-9A-Za-z$_]*';\nconst KEYWORDS = [\n  \"as\", // for exports\n  \"in\",\n  \"of\",\n  \"if\",\n  \"for\",\n  \"while\",\n  \"finally\",\n  \"var\",\n  \"new\",\n  \"function\",\n  \"do\",\n  \"return\",\n  \"void\",\n  \"else\",\n  \"break\",\n  \"catch\",\n  \"instanceof\",\n  \"with\",\n  \"throw\",\n  \"case\",\n  \"default\",\n  \"try\",\n  \"switch\",\n  \"continue\",\n  \"typeof\",\n  \"delete\",\n  \"let\",\n  \"yield\",\n  \"const\",\n  \"class\",\n  // JS handles these with a special rule\n  // \"get\",\n  // \"set\",\n  \"debugger\",\n  \"async\",\n  \"await\",\n  \"static\",\n  \"import\",\n  \"from\",\n  \"export\",\n  \"extends\"\n];\nconst LITERALS = [\n  \"true\",\n  \"false\",\n  \"null\",\n  \"undefined\",\n  \"NaN\",\n  \"Infinity\"\n];\n\nconst TYPES = [\n  \"Intl\",\n  \"DataView\",\n  \"Number\",\n  \"Math\",\n  \"Date\",\n  \"String\",\n  \"RegExp\",\n  \"Object\",\n  \"Function\",\n  \"Boolean\",\n  \"Error\",\n  \"Symbol\",\n  \"Set\",\n  \"Map\",\n  \"WeakSet\",\n  \"WeakMap\",\n  \"Proxy\",\n  \"Reflect\",\n  \"JSON\",\n  \"Promise\",\n  \"Float64Array\",\n  \"Int16Array\",\n  \"Int32Array\",\n  \"Int8Array\",\n  \"Uint16Array\",\n  \"Uint32Array\",\n  \"Float32Array\",\n  \"Array\",\n  \"Uint8Array\",\n  \"Uint8ClampedArray\",\n  \"ArrayBuffer\"\n];\n\nconst ERROR_TYPES = [\n  \"EvalError\",\n  \"InternalError\",\n  \"RangeError\",\n  \"ReferenceError\",\n  \"SyntaxError\",\n  \"TypeError\",\n  \"URIError\"\n];\n\nconst BUILT_IN_GLOBALS = [\n  \"setInterval\",\n  \"setTimeout\",\n  \"clearInterval\",\n  \"clearTimeout\",\n\n  \"require\",\n  \"exports\",\n\n  \"eval\",\n  \"isFinite\",\n  \"isNaN\",\n  \"parseFloat\",\n  \"parseInt\",\n  \"decodeURI\",\n  \"decodeURIComponent\",\n  \"encodeURI\",\n  \"encodeURIComponent\",\n  \"escape\",\n  \"unescape\"\n];\n\nconst BUILT_IN_VARIABLES = [\n  \"arguments\",\n  \"this\",\n  \"super\",\n  \"console\",\n  \"window\",\n  \"document\",\n  \"localStorage\",\n  \"module\",\n  \"global\" // Node.js\n];\n\nconst BUILT_INS = [].concat(\n  BUILT_IN_GLOBALS,\n  BUILT_IN_VARIABLES,\n  TYPES,\n  ERROR_TYPES\n);\n\n/**\n * @param {string} value\n * @returns {RegExp}\n * */\n\n/**\n * @param {RegExp | string } re\n * @returns {string}\n */\nfunction source(re) {\n  if (!re) return null;\n  if (typeof re === \"string\") return re;\n\n  return re.source;\n}\n\n/**\n * @param {RegExp | string } re\n * @returns {string}\n */\nfunction lookahead(re) {\n  return concat('(?=', re, ')');\n}\n\n/**\n * @param {...(RegExp | string) } args\n * @returns {string}\n */\nfunction concat(...args) {\n  const joined = args.map((x) => source(x)).join(\"\");\n  return joined;\n}\n\n/*\nLanguage: JavaScript\nDescription: JavaScript (JS) is a lightweight, interpreted, or just-in-time compiled programming language with first-class functions.\nCategory: common, scripting\nWebsite: https://developer.mozilla.org/en-US/docs/Web/JavaScript\n*/\n\n/** @type LanguageFn */\nfunction javascript(hljs) {\n  /**\n   * Takes a string like \" {\n    const tag = \"',\n    end: ''\n  };\n  const XML_TAG = {\n    begin: /<[A-Za-z0-9\\\\._:-]+/,\n    end: /\\/[A-Za-z0-9\\\\._:-]+>|\\/>/,\n    /**\n     * @param {RegExpMatchArray} match\n     * @param {CallbackResponse} response\n     */\n    isTrulyOpeningTag: (match, response) => {\n      const afterMatchIndex = match[0].length + match.index;\n      const nextChar = match.input[afterMatchIndex];\n      // nested type?\n      // HTML should not include another raw `<` inside a tag\n      // But a type might: `>`, etc.\n      if (nextChar === \"<\") {\n        response.ignoreMatch();\n        return;\n      }\n      // \n      // This is now either a tag or a type.\n      if (nextChar === \">\") {\n        // if we cannot find a matching closing tag, then we\n        // will ignore it\n        if (!hasClosingTag(match, { after: afterMatchIndex })) {\n          response.ignoreMatch();\n        }\n      }\n    }\n  };\n  const KEYWORDS$1 = {\n    $pattern: IDENT_RE,\n    keyword: KEYWORDS.join(\" \"),\n    literal: LITERALS.join(\" \"),\n    built_in: BUILT_INS.join(\" \")\n  };\n\n  // https://tc39.es/ecma262/#sec-literals-numeric-literals\n  const decimalDigits = '[0-9](_?[0-9])*';\n  const frac = `\\\\.(${decimalDigits})`;\n  // DecimalIntegerLiteral, including Annex B NonOctalDecimalIntegerLiteral\n  // https://tc39.es/ecma262/#sec-additional-syntax-numeric-literals\n  const decimalInteger = `0|[1-9](_?[0-9])*|0[0-7]*[89][0-9]*`;\n  const NUMBER = {\n    className: 'number',\n    variants: [\n      // DecimalLiteral\n      { begin: `(\\\\b(${decimalInteger})((${frac})|\\\\.)?|(${frac}))` +\n        `[eE][+-]?(${decimalDigits})\\\\b` },\n      { begin: `\\\\b(${decimalInteger})\\\\b((${frac})\\\\b|\\\\.)?|(${frac})\\\\b` },\n\n      // DecimalBigIntegerLiteral\n      { begin: `\\\\b(0|[1-9](_?[0-9])*)n\\\\b` },\n\n      // NonDecimalIntegerLiteral\n      { begin: \"\\\\b0[xX][0-9a-fA-F](_?[0-9a-fA-F])*n?\\\\b\" },\n      { begin: \"\\\\b0[bB][0-1](_?[0-1])*n?\\\\b\" },\n      { begin: \"\\\\b0[oO][0-7](_?[0-7])*n?\\\\b\" },\n\n      // LegacyOctalIntegerLiteral (does not include underscore separators)\n      // https://tc39.es/ecma262/#sec-additional-syntax-numeric-literals\n      { begin: \"\\\\b0[0-7]+n?\\\\b\" },\n    ],\n    relevance: 0\n  };\n\n  const SUBST = {\n    className: 'subst',\n    begin: '\\\\$\\\\{',\n    end: '\\\\}',\n    keywords: KEYWORDS$1,\n    contains: [] // defined later\n  };\n  const HTML_TEMPLATE = {\n    begin: 'html`',\n    end: '',\n    starts: {\n      end: '`',\n      returnEnd: false,\n      contains: [\n        hljs.BACKSLASH_ESCAPE,\n        SUBST\n      ],\n      subLanguage: 'xml'\n    }\n  };\n  const CSS_TEMPLATE = {\n    begin: 'css`',\n    end: '',\n    starts: {\n      end: '`',\n      returnEnd: false,\n      contains: [\n        hljs.BACKSLASH_ESCAPE,\n        SUBST\n      ],\n      subLanguage: 'css'\n    }\n  };\n  const TEMPLATE_STRING = {\n    className: 'string',\n    begin: '`',\n    end: '`',\n    contains: [\n      hljs.BACKSLASH_ESCAPE,\n      SUBST\n    ]\n  };\n  const JSDOC_COMMENT = hljs.COMMENT(\n    '/\\\\*\\\\*',\n    '\\\\*/',\n    {\n      relevance: 0,\n      contains: [\n        {\n          className: 'doctag',\n          begin: '@[A-Za-z]+',\n          contains: [\n            {\n              className: 'type',\n              begin: '\\\\{',\n              end: '\\\\}',\n              relevance: 0\n            },\n            {\n              className: 'variable',\n              begin: IDENT_RE$1 + '(?=\\\\s*(-)|$)',\n              endsParent: true,\n              relevance: 0\n            },\n            // eat spaces (not newlines) so we can find\n            // types or variables\n            {\n              begin: /(?=[^\\n])\\s/,\n              relevance: 0\n            }\n          ]\n        }\n      ]\n    }\n  );\n  const COMMENT = {\n    className: \"comment\",\n    variants: [\n      JSDOC_COMMENT,\n      hljs.C_BLOCK_COMMENT_MODE,\n      hljs.C_LINE_COMMENT_MODE\n    ]\n  };\n  const SUBST_INTERNALS = [\n    hljs.APOS_STRING_MODE,\n    hljs.QUOTE_STRING_MODE,\n    HTML_TEMPLATE,\n    CSS_TEMPLATE,\n    TEMPLATE_STRING,\n    NUMBER,\n    hljs.REGEXP_MODE\n  ];\n  SUBST.contains = SUBST_INTERNALS\n    .concat({\n      // we need to pair up {} inside our subst to prevent\n      // it from ending too early by matching another }\n      begin: /\\{/,\n      end: /\\}/,\n      keywords: KEYWORDS$1,\n      contains: [\n        \"self\"\n      ].concat(SUBST_INTERNALS)\n    });\n  const SUBST_AND_COMMENTS = [].concat(COMMENT, SUBST.contains);\n  const PARAMS_CONTAINS = SUBST_AND_COMMENTS.concat([\n    // eat recursive parens in sub expressions\n    {\n      begin: /\\(/,\n      end: /\\)/,\n      keywords: KEYWORDS$1,\n      contains: [\"self\"].concat(SUBST_AND_COMMENTS)\n    }\n  ]);\n  const PARAMS = {\n    className: 'params',\n    begin: /\\(/,\n    end: /\\)/,\n    excludeBegin: true,\n    excludeEnd: true,\n    keywords: KEYWORDS$1,\n    contains: PARAMS_CONTAINS\n  };\n\n  return {\n    name: 'Javascript',\n    aliases: ['js', 'jsx', 'mjs', 'cjs'],\n    keywords: KEYWORDS$1,\n    // this will be extended by TypeScript\n    exports: { PARAMS_CONTAINS },\n    illegal: /#(?![$_A-z])/,\n    contains: [\n      hljs.SHEBANG({\n        label: \"shebang\",\n        binary: \"node\",\n        relevance: 5\n      }),\n      {\n        label: \"use_strict\",\n        className: 'meta',\n        relevance: 10,\n        begin: /^\\s*['\"]use (strict|asm)['\"]/\n      },\n      hljs.APOS_STRING_MODE,\n      hljs.QUOTE_STRING_MODE,\n      HTML_TEMPLATE,\n      CSS_TEMPLATE,\n      TEMPLATE_STRING,\n      COMMENT,\n      NUMBER,\n      { // object attr container\n        begin: concat(/[{,\\n]\\s*/,\n          // we need to look ahead to make sure that we actually have an\n          // attribute coming up so we don't steal a comma from a potential\n          // \"value\" container\n          //\n          // NOTE: this might not work how you think.  We don't actually always\n          // enter this mode and stay.  Instead it might merely match `,\n          // ` and then immediately end after the , because it\n          // fails to find any actual attrs. But this still does the job because\n          // it prevents the value contain rule from grabbing this instead and\n          // prevening this rule from firing when we actually DO have keys.\n          lookahead(concat(\n            // we also need to allow for multiple possible comments inbetween\n            // the first key:value pairing\n            /(((\\/\\/.*$)|(\\/\\*(\\*[^/]|[^*])*\\*\\/))\\s*)*/,\n            IDENT_RE$1 + '\\\\s*:'))),\n        relevance: 0,\n        contains: [\n          {\n            className: 'attr',\n            begin: IDENT_RE$1 + lookahead('\\\\s*:'),\n            relevance: 0\n          }\n        ]\n      },\n      { // \"value\" container\n        begin: '(' + hljs.RE_STARTERS_RE + '|\\\\b(case|return|throw)\\\\b)\\\\s*',\n        keywords: 'return throw case',\n        contains: [\n          COMMENT,\n          hljs.REGEXP_MODE,\n          {\n            className: 'function',\n            // we have to count the parens to make sure we actually have the\n            // correct bounding ( ) before the =>.  There could be any number of\n            // sub-expressions inside also surrounded by parens.\n            begin: '(\\\\(' +\n            '[^()]*(\\\\(' +\n            '[^()]*(\\\\(' +\n            '[^()]*' +\n            '\\\\)[^()]*)*' +\n            '\\\\)[^()]*)*' +\n            '\\\\)|' + hljs.UNDERSCORE_IDENT_RE + ')\\\\s*=>',\n            returnBegin: true,\n            end: '\\\\s*=>',\n            contains: [\n              {\n                className: 'params',\n                variants: [\n                  {\n                    begin: hljs.UNDERSCORE_IDENT_RE,\n                    relevance: 0\n                  },\n                  {\n                    className: null,\n                    begin: /\\(\\s*\\)/,\n                    skip: true\n                  },\n                  {\n                    begin: /\\(/,\n                    end: /\\)/,\n                    excludeBegin: true,\n                    excludeEnd: true,\n                    keywords: KEYWORDS$1,\n                    contains: PARAMS_CONTAINS\n                  }\n                ]\n              }\n            ]\n          },\n          { // could be a comma delimited list of params to a function call\n            begin: /,/, relevance: 0\n          },\n          {\n            className: '',\n            begin: /\\s/,\n            end: /\\s*/,\n            skip: true\n          },\n          { // JSX\n            variants: [\n              { begin: FRAGMENT.begin, end: FRAGMENT.end },\n              {\n                begin: XML_TAG.begin,\n                // we carefully check the opening tag to see if it truly\n                // is a tag and not a false positive\n                'on:begin': XML_TAG.isTrulyOpeningTag,\n                end: XML_TAG.end\n              }\n            ],\n            subLanguage: 'xml',\n            contains: [\n              {\n                begin: XML_TAG.begin,\n                end: XML_TAG.end,\n                skip: true,\n                contains: ['self']\n              }\n            ]\n          }\n        ],\n        relevance: 0\n      },\n      {\n        className: 'function',\n        beginKeywords: 'function',\n        end: /[{;]/,\n        excludeEnd: true,\n        keywords: KEYWORDS$1,\n        contains: [\n          'self',\n          hljs.inherit(hljs.TITLE_MODE, { begin: IDENT_RE$1 }),\n          PARAMS\n        ],\n        illegal: /%/\n      },\n      {\n        // prevent this from getting swallowed up by function\n        // since they appear \"function like\"\n        beginKeywords: \"while if switch catch for\"\n      },\n      {\n        className: 'function',\n        // we have to count the parens to make sure we actually have the correct\n        // bounding ( ).  There could be any number of sub-expressions inside\n        // also surrounded by parens.\n        begin: hljs.UNDERSCORE_IDENT_RE +\n          '\\\\(' + // first parens\n          '[^()]*(\\\\(' +\n            '[^()]*(\\\\(' +\n              '[^()]*' +\n            '\\\\)[^()]*)*' +\n          '\\\\)[^()]*)*' +\n          '\\\\)\\\\s*\\\\{', // end parens\n        returnBegin:true,\n        contains: [\n          PARAMS,\n          hljs.inherit(hljs.TITLE_MODE, { begin: IDENT_RE$1 }),\n        ]\n      },\n      // hack: prevents detection of keywords in some circumstances\n      // .keyword()\n      // $keyword = x\n      {\n        variants: [\n          { begin: '\\\\.' + IDENT_RE$1 },\n          { begin: '\\\\$' + IDENT_RE$1 }\n        ],\n        relevance: 0\n      },\n      { // ES6 class\n        className: 'class',\n        beginKeywords: 'class',\n        end: /[{;=]/,\n        excludeEnd: true,\n        illegal: /[:\"[\\]]/,\n        contains: [\n          { beginKeywords: 'extends' },\n          hljs.UNDERSCORE_TITLE_MODE\n        ]\n      },\n      {\n        begin: /\\b(?=constructor)/,\n        end: /[{;]/,\n        excludeEnd: true,\n        contains: [\n          hljs.inherit(hljs.TITLE_MODE, { begin: IDENT_RE$1 }),\n          'self',\n          PARAMS\n        ]\n      },\n      {\n        begin: '(get|set)\\\\s+(?=' + IDENT_RE$1 + '\\\\()',\n        end: /\\{/,\n        keywords: \"get set\",\n        contains: [\n          hljs.inherit(hljs.TITLE_MODE, { begin: IDENT_RE$1 }),\n          { begin: /\\(\\)/ }, // eat to avoid empty params\n          PARAMS\n        ]\n      },\n      {\n        begin: /\\$[(.]/ // relevance booster for a pattern common to JS libs: `$(something)` and `$.something`\n      }\n    ]\n  };\n}\n\nmodule.exports = javascript;\n","/*\nLanguage: Python\nDescription: Python is an interpreted, object-oriented, high-level programming language with dynamic semantics.\nWebsite: https://www.python.org\nCategory: common\n*/\n\nfunction python(hljs) {\n  const RESERVED_WORDS = [\n    'and',\n    'as',\n    'assert',\n    'async',\n    'await',\n    'break',\n    'class',\n    'continue',\n    'def',\n    'del',\n    'elif',\n    'else',\n    'except',\n    'finally',\n    'for',\n    '',\n    'from',\n    'global',\n    'if',\n    'import',\n    'in',\n    'is',\n    'lambda',\n    'nonlocal|10',\n    'not',\n    'or',\n    'pass',\n    'raise',\n    'return',\n    'try',\n    'while',\n    'with',\n    'yield',\n  ];\n\n  const BUILT_INS = [\n    '__import__',\n    'abs',\n    'all',\n    'any',\n    'ascii',\n    'bin',\n    'bool',\n    'breakpoint',\n    'bytearray',\n    'bytes',\n    'callable',\n    'chr',\n    'classmethod',\n    'compile',\n    'complex',\n    'delattr',\n    'dict',\n    'dir',\n    'divmod',\n    'enumerate',\n    'eval',\n    'exec',\n    'filter',\n    'float',\n    'format',\n    'frozenset',\n    'getattr',\n    'globals',\n    'hasattr',\n    'hash',\n    'help',\n    'hex',\n    'id',\n    'input',\n    'int',\n    'isinstance',\n    'issubclass',\n    'iter',\n    'len',\n    'list',\n    'locals',\n    'map',\n    'max',\n    'memoryview',\n    'min',\n    'next',\n    'object',\n    'oct',\n    'open',\n    'ord',\n    'pow',\n    'print',\n    'property',\n    'range',\n    'repr',\n    'reversed',\n    'round',\n    'set',\n    'setattr',\n    'slice',\n    'sorted',\n    'staticmethod',\n    'str',\n    'sum',\n    'super',\n    'tuple',\n    'type',\n    'vars',\n    'zip',\n  ];\n\n  const LITERALS = [\n    '__debug__',\n    'Ellipsis',\n    'False',\n    'None',\n    'NotImplemented',\n    'True',\n  ];\n\n  const KEYWORDS = {\n    keyword: RESERVED_WORDS.join(' '),\n    built_in: BUILT_INS.join(' '),\n    literal: LITERALS.join(' ')\n  };\n\n  const PROMPT = {\n    className: 'meta',  begin: /^(>>>|\\.\\.\\.) /\n  };\n\n  const SUBST = {\n    className: 'subst',\n    begin: /\\{/, end: /\\}/,\n    keywords: KEYWORDS,\n    illegal: /#/\n  };\n\n  const LITERAL_BRACKET = {\n    begin: /\\{\\{/,\n    relevance: 0\n  };\n\n  const STRING = {\n    className: 'string',\n    contains: [hljs.BACKSLASH_ESCAPE],\n    variants: [\n      {\n        begin: /([uU]|[bB]|[rR]|[bB][rR]|[rR][bB])?'''/, end: /'''/,\n        contains: [hljs.BACKSLASH_ESCAPE, PROMPT],\n        relevance: 10\n      },\n      {\n        begin: /([uU]|[bB]|[rR]|[bB][rR]|[rR][bB])?\"\"\"/, end: /\"\"\"/,\n        contains: [hljs.BACKSLASH_ESCAPE, PROMPT],\n        relevance: 10\n      },\n      {\n        begin: /([fF][rR]|[rR][fF]|[fF])'''/, end: /'''/,\n        contains: [hljs.BACKSLASH_ESCAPE, PROMPT, LITERAL_BRACKET, SUBST]\n      },\n      {\n        begin: /([fF][rR]|[rR][fF]|[fF])\"\"\"/, end: /\"\"\"/,\n        contains: [hljs.BACKSLASH_ESCAPE, PROMPT, LITERAL_BRACKET, SUBST]\n      },\n      {\n        begin: /([uU]|[rR])'/, end: /'/,\n        relevance: 10\n      },\n      {\n        begin: /([uU]|[rR])\"/, end: /\"/,\n        relevance: 10\n      },\n      {\n        begin: /([bB]|[bB][rR]|[rR][bB])'/, end: /'/\n      },\n      {\n        begin: /([bB]|[bB][rR]|[rR][bB])\"/, end: /\"/\n      },\n      {\n        begin: /([fF][rR]|[rR][fF]|[fF])'/, end: /'/,\n        contains: [hljs.BACKSLASH_ESCAPE, LITERAL_BRACKET, SUBST]\n      },\n      {\n        begin: /([fF][rR]|[rR][fF]|[fF])\"/, end: /\"/,\n        contains: [hljs.BACKSLASH_ESCAPE, LITERAL_BRACKET, SUBST]\n      },\n      hljs.APOS_STRING_MODE,\n      hljs.QUOTE_STRING_MODE\n    ]\n  };\n\n  // https://docs.python.org/3.9/reference/lexical_analysis.html#numeric-literals\n  const digitpart = '[0-9](_?[0-9])*';\n  const pointfloat = `(\\\\b(${digitpart}))?\\\\.(${digitpart})|\\\\b(${digitpart})\\\\.`;\n  const NUMBER = {\n    className: 'number', relevance: 0,\n    variants: [\n      // exponentfloat, pointfloat\n      // https://docs.python.org/3.9/reference/lexical_analysis.html#floating-point-literals\n      // optionally imaginary\n      // https://docs.python.org/3.9/reference/lexical_analysis.html#imaginary-literals\n      // Note: no leading \\b because floats can start with a decimal point\n      // and we don't want to mishandle e.g. `fn(.5)`,\n      // no trailing \\b for pointfloat because it can end with a decimal point\n      // and we don't want to mishandle e.g. `0..hex()`; this should be safe\n      // because both MUST contain a decimal point and so cannot be confused with\n      // the interior part of an identifier\n      { begin: `(\\\\b(${digitpart})|(${pointfloat}))[eE][+-]?(${digitpart})[jJ]?\\\\b` },\n      { begin: `(${pointfloat})[jJ]?` },\n\n      // decinteger, bininteger, octinteger, hexinteger\n      // https://docs.python.org/3.9/reference/lexical_analysis.html#integer-literals\n      // optionally \"long\" in Python 2\n      // https://docs.python.org/2.7/reference/lexical_analysis.html#integer-and-long-integer-literals\n      // decinteger is optionally imaginary\n      // https://docs.python.org/3.9/reference/lexical_analysis.html#imaginary-literals\n      { begin: '\\\\b([1-9](_?[0-9])*|0+(_?0)*)[lLjJ]?\\\\b' },\n      { begin: '\\\\b0[bB](_?[01])+[lL]?\\\\b' },\n      { begin: '\\\\b0[oO](_?[0-7])+[lL]?\\\\b' },\n      { begin: '\\\\b0[xX](_?[0-9a-fA-F])+[lL]?\\\\b' },\n\n      // imagnumber (digitpart-based)\n      // https://docs.python.org/3.9/reference/lexical_analysis.html#imaginary-literals\n      { begin: `\\\\b(${digitpart})[jJ]\\\\b` },\n    ]\n  };\n\n  const PARAMS = {\n    className: 'params',\n    variants: [\n      // Exclude params at functions without params\n      {begin: /\\(\\s*\\)/, skip: true, className: null },\n      {\n        begin: /\\(/, end: /\\)/, excludeBegin: true, excludeEnd: true,\n        keywords: KEYWORDS,\n        contains: ['self', PROMPT, NUMBER, STRING, hljs.HASH_COMMENT_MODE],\n      },\n    ],\n  };\n  SUBST.contains = [STRING, NUMBER, PROMPT];\n\n  return {\n    name: 'Python',\n    aliases: ['py', 'gyp', 'ipython'],\n    keywords: KEYWORDS,\n    illegal: /(<\\/|->|\\?)|=>/,\n    contains: [\n      PROMPT,\n      NUMBER,\n      // eat \"if\" prior to string so that it won't accidentally be\n      // labeled as an f-string as in:\n      { begin: /\\bself\\b/, }, // very common convention\n      { beginKeywords: \"if\", relevance: 0 },\n      STRING,\n      hljs.HASH_COMMENT_MODE,\n      {\n        variants: [\n          {className: 'function', beginKeywords: 'def'},\n          {className: 'class', beginKeywords: 'class'}\n        ],\n        end: /:/,\n        illegal: /[${=;\\n,]/,\n        contains: [\n          hljs.UNDERSCORE_TITLE_MODE,\n          PARAMS,\n          {\n            begin: /->/, endsWithParent: true,\n            keywords: 'None'\n          }\n        ]\n      },\n      {\n        className: 'meta',\n        begin: /^[\\t ]*@/, end: /(?=#)|$/,\n        contains: [NUMBER, PARAMS, STRING]\n      },\n      {\n        begin: /\\b(print|exec)\\(/ // don’t highlight keywords-turned-functions in Python 3\n      }\n    ]\n  };\n}\n\nmodule.exports = python;\n","/**\n * @param {string} value\n * @returns {RegExp}\n * */\n\n/**\n * @param {RegExp | string } re\n * @returns {string}\n */\nfunction source(re) {\n  if (!re) return null;\n  if (typeof re === \"string\") return re;\n\n  return re.source;\n}\n\n/**\n * @param {RegExp | string } re\n * @returns {string}\n */\nfunction lookahead(re) {\n  return concat('(?=', re, ')');\n}\n\n/**\n * @param {RegExp | string } re\n * @returns {string}\n */\nfunction optional(re) {\n  return concat('(', re, ')?');\n}\n\n/**\n * @param {...(RegExp | string) } args\n * @returns {string}\n */\nfunction concat(...args) {\n  const joined = args.map((x) => source(x)).join(\"\");\n  return joined;\n}\n\n/**\n * Any of the passed expresssions may match\n *\n * Creates a huge this | this | that | that match\n * @param {(RegExp | string)[] } args\n * @returns {string}\n */\nfunction either(...args) {\n  const joined = '(' + args.map((x) => source(x)).join(\"|\") + \")\";\n  return joined;\n}\n\n/*\nLanguage: HTML, XML\nWebsite: https://www.w3.org/XML/\nCategory: common\n*/\n\n/** @type LanguageFn */\nfunction xml(hljs) {\n  // Element names can contain letters, digits, hyphens, underscores, and periods\n  const TAG_NAME_RE = concat(/[A-Z_]/, optional(/[A-Z0-9_.-]+:/), /[A-Z0-9_.-]*/);\n  const XML_IDENT_RE = '[A-Za-z0-9\\\\._:-]+';\n  const XML_ENTITIES = {\n    className: 'symbol',\n    begin: '&[a-z]+;|&#[0-9]+;|&#x[a-f0-9]+;'\n  };\n  const XML_META_KEYWORDS = {\n    begin: '\\\\s',\n    contains: [\n      {\n        className: 'meta-keyword',\n        begin: '#?[a-z_][a-z1-9_-]+',\n        illegal: '\\\\n'\n      }\n    ]\n  };\n  const XML_META_PAR_KEYWORDS = hljs.inherit(XML_META_KEYWORDS, {\n    begin: '\\\\(',\n    end: '\\\\)'\n  });\n  const APOS_META_STRING_MODE = hljs.inherit(hljs.APOS_STRING_MODE, {\n    className: 'meta-string'\n  });\n  const QUOTE_META_STRING_MODE = hljs.inherit(hljs.QUOTE_STRING_MODE, {\n    className: 'meta-string'\n  });\n  const TAG_INTERNALS = {\n    endsWithParent: true,\n    illegal: /`]+/\n              }\n            ]\n          }\n        ]\n      }\n    ]\n  };\n  return {\n    name: 'HTML, XML',\n    aliases: [\n      'html',\n      'xhtml',\n      'rss',\n      'atom',\n      'xjb',\n      'xsd',\n      'xsl',\n      'plist',\n      'wsf',\n      'svg'\n    ],\n    case_insensitive: true,\n    contains: [\n      {\n        className: 'meta',\n        begin: '',\n        relevance: 10,\n        contains: [\n          XML_META_KEYWORDS,\n          QUOTE_META_STRING_MODE,\n          APOS_META_STRING_MODE,\n          XML_META_PAR_KEYWORDS,\n          {\n            begin: '\\\\[',\n            end: '\\\\]',\n            contains: [\n              {\n                className: 'meta',\n                begin: '',\n                contains: [\n                  XML_META_KEYWORDS,\n                  XML_META_PAR_KEYWORDS,\n                  QUOTE_META_STRING_MODE,\n                  APOS_META_STRING_MODE\n                ]\n              }\n            ]\n          }\n        ]\n      },\n      hljs.COMMENT(\n        '',\n        {\n          relevance: 10\n        }\n      ),\n      {\n        begin: '',\n        relevance: 10\n      },\n      XML_ENTITIES,\n      {\n        className: 'meta',\n        begin: /<\\?xml/,\n        end: /\\?>/,\n        relevance: 10\n      },\n      {\n        className: 'tag',\n        /*\n        The lookahead pattern (?=...) ensures that 'begin' only matches\n        ')',\n        end: '>',\n        keywords: {\n          name: 'style'\n        },\n        contains: [ TAG_INTERNALS ],\n        starts: {\n          end: '',\n          returnEnd: true,\n          subLanguage: [\n            'css',\n            'xml'\n          ]\n        }\n      },\n      {\n        className: 'tag',\n        // See the comment in the