summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--heat_dashboard/enabled/_1650_project_template_generator_panel.py54
-rw-r--r--heat_dashboard/static/dashboard/project/heat_dashboard/template_generator/css/angular-notify.scss2
-rw-r--r--heat_dashboard/static/dashboard/project/heat_dashboard/template_generator/css/hotgen-main.scss4
-rw-r--r--heat_dashboard/static/dashboard/project/heat_dashboard/template_generator/js/libs/FileSaver.js188
-rw-r--r--heat_dashboard/static/dashboard/project/heat_dashboard/template_generator/js/libs/angular-uuid.js251
-rw-r--r--heat_dashboard/static/dashboard/project/heat_dashboard/template_generator/js/libs/angular-vis.js227
-rw-r--r--heat_dashboard/static/dashboard/project/heat_dashboard/template_generator/js/libs/js-yaml.js3862
-rw-r--r--heat_dashboard/static/dashboard/project/heat_dashboard/template_generator/js/libs/json2yaml.js103
-rw-r--r--karma.conf.js9
-rw-r--r--lower-constraints.txt5
-rw-r--r--package.json26
-rw-r--r--requirements.txt6
-rw-r--r--tox.ini5
13 files changed, 77 insertions, 4665 deletions
diff --git a/heat_dashboard/enabled/_1650_project_template_generator_panel.py b/heat_dashboard/enabled/_1650_project_template_generator_panel.py
index f6dd1f7..cab7fb6 100644
--- a/heat_dashboard/enabled/_1650_project_template_generator_panel.py
+++ b/heat_dashboard/enabled/_1650_project_template_generator_panel.py
@@ -12,12 +12,10 @@
12 12
13import os 13import os
14 14
15from importlib import import_module 15from horizon.utils.file_discovery import discover_files
16 16
17import heat_dashboard 17import heat_dashboard
18 18
19from horizon.utils.file_discovery import discover_files
20
21# The slug of the panel to be added to HORIZON_CONFIG. Required. 19# The slug of the panel to be added to HORIZON_CONFIG. Required.
22PANEL = 'template_generator' 20PANEL = 'template_generator'
23# The slug of the dashboard the PANEL associated with. Required. 21# The slug of the dashboard the PANEL associated with. Required.
@@ -39,32 +37,34 @@ TEMPLATE_GENERATOR_BASE = 'dashboard/project/heat_dashboard/template_generator'
39CSS_BASE = '%s/css' % TEMPLATE_GENERATOR_BASE 37CSS_BASE = '%s/css' % TEMPLATE_GENERATOR_BASE
40JS_BASE = '%s/js' % TEMPLATE_GENERATOR_BASE 38JS_BASE = '%s/js' % TEMPLATE_GENERATOR_BASE
41 39
42ADD_SCSS_FILES = [ 40ADD_XSTATIC_MODULES = [
43 '%s/hotgen-main.scss' % CSS_BASE,
44 'horizon/lib/bootstrap_scss/scss/_bootstrap.scss',
45 'horizon/lib/font_awesome/scss/font-awesome.scss']
46
47XSTATIC_MODULES = [
48 ('xstatic.pkg.angular', [ 41 ('xstatic.pkg.angular', [
49 'angular-animate.js', 42 'angular-animate.js',
50 'angular-aria.js', 43 'angular-aria.js',
51 'angular-messages.js', 44 'angular-messages.js',
52 ]), 45 ]),
53 ('xstatic.pkg.angular_bootstrap', ['angular-bootstrap.js']), 46 ('xstatic.pkg.angular_bootstrap', ['angular-bootstrap.js']),
47 # ('xstatic.pkg.angular_material', ['angular-material.js']),
48 ('xstatic.pkg.angular_uuid', ['angular-uuid.js']),
49 ('xstatic.pkg.angular_vis', ['angular-vis.js']),
50 ('xstatic.pkg.filesaver', ['FileSaver.js']),
51 ('xstatic.pkg.js_yaml', ['js-yaml.js']),
52 ('xstatic.pkg.json2yaml', ['json2yaml.js']),
54] 53]
54
55ADD_SCSS_FILES = [
56 'horizon/lib/bootstrap_scss/scss/_bootstrap.scss',
57 'horizon/lib/font_awesome/scss/font-awesome.scss',
58 '%s/hotgen-main.scss' % CSS_BASE
59 ]
60
55HEAT_DASHBOARD_ROOT = heat_dashboard.__path__[0] 61HEAT_DASHBOARD_ROOT = heat_dashboard.__path__[0]
56 62
63
57ADD_JS_FILES = discover_files(os.path.join(HEAT_DASHBOARD_ROOT, 'static'), 64ADD_JS_FILES = discover_files(os.path.join(HEAT_DASHBOARD_ROOT, 'static'),
58 sub_path='%s/libs' % JS_BASE, 65 sub_path='%s/libs' % JS_BASE,
59 ext='.js', trim_base_path=True) 66 ext='.js', trim_base_path=True)
60 67
61for module_name, js_files in XSTATIC_MODULES:
62 module = import_module(module_name)
63 for js_file in js_files:
64 ADD_JS_FILES.append(
65 os.path.join('horizon/lib/', module.NAME, js_file)
66 )
67
68ADD_JS_FILES.extend([ 68ADD_JS_FILES.extend([
69 '%s/components/template-generator.module.js' % JS_BASE, 69 '%s/components/template-generator.module.js' % JS_BASE,
70 '%s/components/utils.module.js' % JS_BASE, 70 '%s/components/utils.module.js' % JS_BASE,
@@ -72,18 +72,32 @@ ADD_JS_FILES.extend([
72]) 72])
73 73
74ADD_JS_FILES.extend( 74ADD_JS_FILES.extend(
75 [file for file in discover_files( 75 [js_file for js_file in discover_files(
76 os.path.join(HEAT_DASHBOARD_ROOT, 76 os.path.join(HEAT_DASHBOARD_ROOT,
77 'static'), 77 'static'),
78 sub_path='%s/components' % JS_BASE, 78 sub_path='%s/components' % JS_BASE,
79 ext='.js', 79 ext='.js',
80 trim_base_path=True) 80 trim_base_path=True)
81 if file not in ADD_JS_FILES and 'spec.js' not in file 81 if js_file not in ADD_JS_FILES and not js_file.endswith('spec.js')
82 ]) 82 ])
83 83
84ADD_JS_FILES.extend( 84ADD_JS_FILES.extend(
85 [file for file in discover_files( 85 [js_file for js_file in discover_files(
86 os.path.join(HEAT_DASHBOARD_ROOT, 'static'),
87 sub_path='%s/resources' % JS_BASE,
88 ext='.js', trim_base_path=True) if not js_file.endswith('spec.js')
89 ])
90
91ADD_JS_SPEC_FILES = [
92 js_file for js_file in discover_files(
93 os.path.join(HEAT_DASHBOARD_ROOT, 'static'),
94 sub_path='%s/components' % JS_BASE,
95 ext='.js',
96 trim_base_path=True) if js_file.endswith('spec.js')]
97
98ADD_JS_SPEC_FILES.extend(
99 [js_file for js_file in discover_files(
86 os.path.join(HEAT_DASHBOARD_ROOT, 'static'), 100 os.path.join(HEAT_DASHBOARD_ROOT, 'static'),
87 sub_path='%s/resources' % JS_BASE, 101 sub_path='%s/resources' % JS_BASE,
88 ext='.js', trim_base_path=True) if 'spec.js' not in file 102 ext='.js', trim_base_path=True) if js_file.endswith('spec.js')
89 ]) 103 ])
diff --git a/heat_dashboard/static/dashboard/project/heat_dashboard/template_generator/css/angular-notify.scss b/heat_dashboard/static/dashboard/project/heat_dashboard/template_generator/css/angular-notify.scss
index b19addc..ec993f9 100644
--- a/heat_dashboard/static/dashboard/project/heat_dashboard/template_generator/css/angular-notify.scss
+++ b/heat_dashboard/static/dashboard/project/heat_dashboard/template_generator/css/angular-notify.scss
@@ -80,4 +80,4 @@
80 overflow: hidden; 80 overflow: hidden;
81 clip: rect(0,0,0,0); 81 clip: rect(0,0,0,0);
82 border: 0; 82 border: 0;
83} 83} \ No newline at end of file
diff --git a/heat_dashboard/static/dashboard/project/heat_dashboard/template_generator/css/hotgen-main.scss b/heat_dashboard/static/dashboard/project/heat_dashboard/template_generator/css/hotgen-main.scss
index ee411ac..ff86adb 100644
--- a/heat_dashboard/static/dashboard/project/heat_dashboard/template_generator/css/hotgen-main.scss
+++ b/heat_dashboard/static/dashboard/project/heat_dashboard/template_generator/css/hotgen-main.scss
@@ -2,6 +2,4 @@
2@import "/dashboard/project/heat_dashboard/template_generator/css/angular-material.scss"; 2@import "/dashboard/project/heat_dashboard/template_generator/css/angular-material.scss";
3@import "/dashboard/project/heat_dashboard/template_generator/css/angular-notify.scss"; 3@import "/dashboard/project/heat_dashboard/template_generator/css/angular-notify.scss";
4@import "/dashboard/project/heat_dashboard/template_generator/css/hotgen.scss"; 4@import "/dashboard/project/heat_dashboard/template_generator/css/hotgen.scss";
5@import "/dashboard/project/heat_dashboard/template_generator/css/vis.scss"; 5@import "/dashboard/project/heat_dashboard/template_generator/css/vis.scss"; \ No newline at end of file
6
7
diff --git a/heat_dashboard/static/dashboard/project/heat_dashboard/template_generator/js/libs/FileSaver.js b/heat_dashboard/static/dashboard/project/heat_dashboard/template_generator/js/libs/FileSaver.js
deleted file mode 100644
index 315dc02..0000000
--- a/heat_dashboard/static/dashboard/project/heat_dashboard/template_generator/js/libs/FileSaver.js
+++ /dev/null
@@ -1,188 +0,0 @@
1/* FileSaver.js
2 * A saveAs() FileSaver implementation.
3 * 1.3.2
4 * 2016-06-16 18:25:19
5 *
6 * By Eli Grey, http://eligrey.com
7 * License: MIT
8 * See https://github.com/eligrey/FileSaver.js/blob/master/LICENSE.md
9 */
10
11/*global self */
12/*jslint bitwise: true, indent: 4, laxbreak: true, laxcomma: true, smarttabs: true, plusplus: true */
13
14/*! @source http://purl.eligrey.com/github/FileSaver.js/blob/master/FileSaver.js */
15
16var saveAs = saveAs || (function(view) {
17 "use strict";
18 // IE <10 is explicitly unsupported
19 if (typeof view === "undefined" || typeof navigator !== "undefined" && /MSIE [1-9]\./.test(navigator.userAgent)) {
20 return;
21 }
22 var
23 doc = view.document
24 // only get URL when necessary in case Blob.js hasn't overridden it yet
25 , get_URL = function() {
26 return view.URL || view.webkitURL || view;
27 }
28 , save_link = doc.createElementNS("http://www.w3.org/1999/xhtml", "a")
29 , can_use_save_link = "download" in save_link
30 , click = function(node) {
31 var event = new MouseEvent("click");
32 node.dispatchEvent(event);
33 }
34 , is_safari = /constructor/i.test(view.HTMLElement) || view.safari
35 , is_chrome_ios =/CriOS\/[\d]+/.test(navigator.userAgent)
36 , throw_outside = function(ex) {
37 (view.setImmediate || view.setTimeout)(function() {
38 throw ex;
39 }, 0);
40 }
41 , force_saveable_type = "application/octet-stream"
42 // the Blob API is fundamentally broken as there is no "downloadfinished" event to subscribe to
43 , arbitrary_revoke_timeout = 1000 * 40 // in ms
44 , revoke = function(file) {
45 var revoker = function() {
46 if (typeof file === "string") { // file is an object URL
47 get_URL().revokeObjectURL(file);
48 } else { // file is a File
49 file.remove();
50 }
51 };
52 setTimeout(revoker, arbitrary_revoke_timeout);
53 }
54 , dispatch = function(filesaver, event_types, event) {
55 event_types = [].concat(event_types);
56 var i = event_types.length;
57 while (i--) {
58 var listener = filesaver["on" + event_types[i]];
59 if (typeof listener === "function") {
60 try {
61 listener.call(filesaver, event || filesaver);
62 } catch (ex) {
63 throw_outside(ex);
64 }
65 }
66 }
67 }
68 , auto_bom = function(blob) {
69 // prepend BOM for UTF-8 XML and text/* types (including HTML)
70 // note: your browser will automatically convert UTF-16 U+FEFF to EF BB BF
71 if (/^\s*(?:text\/\S*|application\/xml|\S*\/\S*\+xml)\s*;.*charset\s*=\s*utf-8/i.test(blob.type)) {
72 return new Blob([String.fromCharCode(0xFEFF), blob], {type: blob.type});
73 }
74 return blob;
75 }
76 , FileSaver = function(blob, name, no_auto_bom) {
77 if (!no_auto_bom) {
78 blob = auto_bom(blob);
79 }
80 // First try a.download, then web filesystem, then object URLs
81 var
82 filesaver = this
83 , type = blob.type
84 , force = type === force_saveable_type
85 , object_url
86 , dispatch_all = function() {
87 dispatch(filesaver, "writestart progress write writeend".split(" "));
88 }
89 // on any filesys errors revert to saving with object URLs
90 , fs_error = function() {
91 if ((is_chrome_ios || (force && is_safari)) && view.FileReader) {
92 // Safari doesn't allow downloading of blob urls
93 var reader = new FileReader();
94 reader.onloadend = function() {
95 var url = is_chrome_ios ? reader.result : reader.result.replace(/^data:[^;]*;/, 'data:attachment/file;');
96 var popup = view.open(url, '_blank');
97 if(!popup) view.location.href = url;
98 url=undefined; // release reference before dispatching
99 filesaver.readyState = filesaver.DONE;
100 dispatch_all();
101 };
102 reader.readAsDataURL(blob);
103 filesaver.readyState = filesaver.INIT;
104 return;
105 }
106 // don't create more object URLs than needed
107 if (!object_url) {
108 object_url = get_URL().createObjectURL(blob);
109 }
110 if (force) {
111 view.location.href = object_url;
112 } else {
113 var opened = view.open(object_url, "_blank");
114 if (!opened) {
115 // Apple does not allow window.open, see https://developer.apple.com/library/safari/documentation/Tools/Conceptual/SafariExtensionGuide/WorkingwithWindowsandTabs/WorkingwithWindowsandTabs.html
116 view.location.href = object_url;
117 }
118 }
119 filesaver.readyState = filesaver.DONE;
120 dispatch_all();
121 revoke(object_url);
122 }
123 ;
124 filesaver.readyState = filesaver.INIT;
125
126 if (can_use_save_link) {
127 object_url = get_URL().createObjectURL(blob);
128 setTimeout(function() {
129 save_link.href = object_url;
130 save_link.download = name;
131 click(save_link);
132 dispatch_all();
133 revoke(object_url);
134 filesaver.readyState = filesaver.DONE;
135 });
136 return;
137 }
138
139 fs_error();
140 }
141 , FS_proto = FileSaver.prototype
142 , saveAs = function(blob, name, no_auto_bom) {
143 return new FileSaver(blob, name || blob.name || "download", no_auto_bom);
144 }
145 ;
146 // IE 10+ (native saveAs)
147 if (typeof navigator !== "undefined" && navigator.msSaveOrOpenBlob) {
148 return function(blob, name, no_auto_bom) {
149 name = name || blob.name || "download";
150
151 if (!no_auto_bom) {
152 blob = auto_bom(blob);
153 }
154 return navigator.msSaveOrOpenBlob(blob, name);
155 };
156 }
157
158 FS_proto.abort = function(){};
159 FS_proto.readyState = FS_proto.INIT = 0;
160 FS_proto.WRITING = 1;
161 FS_proto.DONE = 2;
162
163 FS_proto.error =
164 FS_proto.onwritestart =
165 FS_proto.onprogress =
166 FS_proto.onwrite =
167 FS_proto.onabort =
168 FS_proto.onerror =
169 FS_proto.onwriteend =
170 null;
171
172 return saveAs;
173}(
174 typeof self !== "undefined" && self
175 || typeof window !== "undefined" && window
176 || this.content
177));
178// `self` is undefined in Firefox for Android content script context
179// while `this` is nsIContentFrameMessageManager
180// with an attribute `content` that corresponds to the window
181
182if (typeof module !== "undefined" && module.exports) {
183 module.exports.saveAs = saveAs;
184} else if ((typeof define !== "undefined" && define !== null) && (define.amd !== null)) {
185 define("FileSaver.js", function() {
186 return saveAs;
187 });
188} \ No newline at end of file
diff --git a/heat_dashboard/static/dashboard/project/heat_dashboard/template_generator/js/libs/angular-uuid.js b/heat_dashboard/static/dashboard/project/heat_dashboard/template_generator/js/libs/angular-uuid.js
deleted file mode 100644
index 5ff85c2..0000000
--- a/heat_dashboard/static/dashboard/project/heat_dashboard/template_generator/js/libs/angular-uuid.js
+++ /dev/null
@@ -1,251 +0,0 @@
1// angular-uuid created by Ivan Hayes @munkychop
2// MIT License - http://opensource.org/licenses/mit-license.php
3// --------------------------------------------------------------
4// This is an AngularJS wrapper for the original node-uuid library
5// written by Robert Kieffer – https://github.com/broofa/node-uuid
6// MIT License - http://opensource.org/licenses/mit-license.php
7// The wrapped node-uuid library is at version 1.4.7
8
9function AngularUUID () {
10 'use strict';
11
12 angular.module('angular-uuid',[]).factory('uuid', ['$window', nodeUUID]);
13
14 function nodeUUID ($window) {
15 // Unique ID creation requires a high quality random # generator. We feature
16 // detect to determine the best RNG source, normalizing to a function that
17 // returns 128-bits of randomness, since that's what's usually required
18 var _rng, _mathRNG, _whatwgRNG;
19
20 // Allow for MSIE11 msCrypto
21 var _crypto = $window.crypto || $window.msCrypto;
22
23 if (!_rng && _crypto && _crypto.getRandomValues) {
24 // WHATWG crypto-based RNG - http://wiki.whatwg.org/wiki/Crypto
25 //
26 // Moderately fast, high quality
27 try {
28 var _rnds8 = new Uint8Array(16);
29 _whatwgRNG = _rng = function whatwgRNG() {
30 _crypto.getRandomValues(_rnds8);
31 return _rnds8;
32 };
33 _rng();
34 } catch(e) {}
35 }
36
37 if (!_rng) {
38 // Math.random()-based (RNG)
39 //
40 // If all else fails, use Math.random(). It's fast, but is of unspecified
41 // quality.
42 var _rnds = new Array(16);
43 _mathRNG = _rng = function() {
44 for (var i = 0, r; i < 16; i++) {
45 if ((i & 0x03) === 0) { r = Math.random() * 0x100000000; }
46 _rnds[i] = r >>> ((i & 0x03) << 3) & 0xff;
47 }
48
49 return _rnds;
50 };
51 if ('undefined' !== typeof console && console.warn) {
52 console.warn('[SECURITY] node-uuid: crypto not usable, falling back to insecure Math.random()');
53 }
54 }
55
56 // Buffer class to use
57 var BufferClass = ('function' === typeof Buffer) ? Buffer : Array;
58
59 // Maps for number <-> hex string conversion
60 var _byteToHex = [];
61 var _hexToByte = {};
62 for (var i = 0; i < 256; i++) {
63 _byteToHex[i] = (i + 0x100).toString(16).substr(1);
64 _hexToByte[_byteToHex[i]] = i;
65 }
66
67 // **`parse()` - Parse a UUID into it's component bytes**
68 function parse(s, buf, offset) {
69 var i = (buf && offset) || 0, ii = 0;
70
71 buf = buf || [];
72 s.toLowerCase().replace(/[0-9a-f]{2}/g, function(oct) {
73 if (ii < 16) { // Don't overflow!
74 buf[i + ii++] = _hexToByte[oct];
75 }
76 });
77
78 // Zero out remaining bytes if string was short
79 while (ii < 16) {
80 buf[i + ii++] = 0;
81 }
82
83 return buf;
84 }
85
86 // **`unparse()` - Convert UUID byte array (ala parse()) into a string**
87 function unparse(buf, offset) {
88 var i = offset || 0, bth = _byteToHex;
89 return bth[buf[i++]] + bth[buf[i++]] +
90 bth[buf[i++]] + bth[buf[i++]] + '-' +
91 bth[buf[i++]] + bth[buf[i++]] + '-' +
92 bth[buf[i++]] + bth[buf[i++]] + '-' +
93 bth[buf[i++]] + bth[buf[i++]] + '-' +
94 bth[buf[i++]] + bth[buf[i++]] +
95 bth[buf[i++]] + bth[buf[i++]] +
96 bth[buf[i++]] + bth[buf[i++]];
97 }
98
99 // **`v1()` - Generate time-based UUID**
100 //
101 // Inspired by https://github.com/LiosK/UUID.js
102 // and http://docs.python.org/library/uuid.html
103
104 // random #'s we need to init node and clockseq
105 var _seedBytes = _rng();
106
107 // Per 4.5, create and 48-bit node id, (47 random bits + multicast bit = 1)
108 var _nodeId = [
109 _seedBytes[0] | 0x01,
110 _seedBytes[1], _seedBytes[2], _seedBytes[3], _seedBytes[4], _seedBytes[5]
111 ];
112
113 // Per 4.2.2, randomize (14 bit) clockseq
114 var _clockseq = (_seedBytes[6] << 8 | _seedBytes[7]) & 0x3fff;
115
116 // Previous uuid creation time
117 var _lastMSecs = 0, _lastNSecs = 0;
118
119 // See https://github.com/broofa/node-uuid for API details
120 function v1(options, buf, offset) {
121 var i = buf && offset || 0;
122 var b = buf || [];
123
124 options = options || {};
125
126 var clockseq = (options.clockseq != null) ? options.clockseq : _clockseq;
127
128 // UUID timestamps are 100 nano-second units since the Gregorian epoch,
129 // (1582-10-15 00:00). JSNumbers aren't precise enough for this, so
130 // time is handled internally as 'msecs' (integer milliseconds) and 'nsecs'
131 // (100-nanoseconds offset from msecs) since unix epoch, 1970-01-01 00:00.
132 var msecs = (options.msecs != null) ? options.msecs : new Date().getTime();
133
134 // Per 4.2.1.2, use count of uuid's generated during the current clock
135 // cycle to simulate higher resolution clock
136 var nsecs = (options.nsecs != null) ? options.nsecs : _lastNSecs + 1;
137
138 // Time since last uuid creation (in msecs)
139 var dt = (msecs - _lastMSecs) + (nsecs - _lastNSecs)/10000;
140
141 // Per 4.2.1.2, Bump clockseq on clock regression
142 if (dt < 0 && options.clockseq == null) {
143 clockseq = clockseq + 1 & 0x3fff;
144 }
145
146 // Reset nsecs if clock regresses (new clockseq) or we've moved onto a new
147 // time interval
148 if ((dt < 0 || msecs > _lastMSecs) && options.nsecs == null) {
149 nsecs = 0;
150 }
151
152 // Per 4.2.1.2 Throw error if too many uuids are requested
153 if (nsecs >= 10000) {
154 throw new Error('uuid.v1(): Can\'t create more than 10M uuids/sec');
155 }
156
157 _lastMSecs = msecs;
158 _lastNSecs = nsecs;
159 _clockseq = clockseq;
160
161 // Per 4.1.4 - Convert from unix epoch to Gregorian epoch
162 msecs += 12219292800000;
163
164 // `time_low`
165 var tl = ((msecs & 0xfffffff) * 10000 + nsecs) % 0x100000000;
166 b[i++] = tl >>> 24 & 0xff;
167 b[i++] = tl >>> 16 & 0xff;
168 b[i++] = tl >>> 8 & 0xff;
169 b[i++] = tl & 0xff;
170
171 // `time_mid`
172 var tmh = (msecs / 0x100000000 * 10000) & 0xfffffff;
173 b[i++] = tmh >>> 8 & 0xff;
174 b[i++] = tmh & 0xff;
175
176 // `time_high_and_version`
177 b[i++] = tmh >>> 24 & 0xf | 0x10; // include version
178 b[i++] = tmh >>> 16 & 0xff;
179
180 // `clock_seq_hi_and_reserved` (Per 4.2.2 - include variant)
181 b[i++] = clockseq >>> 8 | 0x80;
182
183 // `clock_seq_low`
184 b[i++] = clockseq & 0xff;
185
186 // `node`
187 var node = options.node || _nodeId;
188 for (var n = 0; n < 6; n++) {
189 b[i + n] = node[n];
190 }
191
192 return buf ? buf : unparse(b);
193 }
194
195 // **`v4()` - Generate random UUID**
196
197 // See https://github.com/broofa/node-uuid for API details
198 function v4(options, buf, offset) {
199 // Deprecated - 'format' argument, as supported in v1.2
200 var i = buf && offset || 0;
201
202 if (typeof(options) === 'string') {
203 buf = (options === 'binary') ? new BufferClass(16) : null;
204 options = null;
205 }
206 options = options || {};
207
208 var rnds = options.random || (options.rng || _rng)();
209
210 // Per 4.4, set bits for version and `clock_seq_hi_and_reserved`
211 rnds[6] = (rnds[6] & 0x0f) | 0x40;
212 rnds[8] = (rnds[8] & 0x3f) | 0x80;
213
214 // Copy bytes to buffer, if provided
215 if (buf) {
216 for (var ii = 0; ii < 16; ii++) {
217 buf[i + ii] = rnds[ii];
218 }
219 }
220
221 return buf || unparse(rnds);
222 }
223
224 // Export public API
225 var uuid = v4;
226 uuid.v1 = v1;
227 uuid.v4 = v4;
228 uuid.parse = parse;
229 uuid.unparse = unparse;
230 uuid.BufferClass = BufferClass;
231 uuid._rng = _rng;
232 uuid._mathRNG = _mathRNG;
233 uuid._whatwgRNG = _whatwgRNG;
234
235 return uuid;
236 }
237}
238
239// check for Module/AMD support, otherwise call the uuid function to setup the angular module.
240if (typeof module !== 'undefined' && module.exports) {
241 module.exports = new AngularUUID();
242
243} else if (typeof define !== 'undefined' && define.amd) {
244 // AMD. Register as an anonymous module.
245 define (function() {
246 return new AngularUUID();
247 });
248
249} else {
250 AngularUUID();
251} \ No newline at end of file
diff --git a/heat_dashboard/static/dashboard/project/heat_dashboard/template_generator/js/libs/angular-vis.js b/heat_dashboard/static/dashboard/project/heat_dashboard/template_generator/js/libs/angular-vis.js
deleted file mode 100644
index fca672d..0000000
--- a/heat_dashboard/static/dashboard/project/heat_dashboard/template_generator/js/libs/angular-vis.js
+++ /dev/null
@@ -1,227 +0,0 @@
1angular.module('ngVis', [])
2
3 .factory('VisDataSet', function () {
4 'use strict';
5 return function (data, options) {
6 // Create the new dataSets
7 return new vis.DataSet(data, options);
8 };
9 })
10
11/**
12 * TimeLine directive
13 */
14 .directive('visTimeline', function () {
15 'use strict';
16 return {
17 restrict: 'EA',
18 transclude: false,
19 scope: {
20 data: '=',
21 options: '=',
22 events: '='
23 },
24 link: function (scope, element, attr) {
25 var timelineEvents = [
26 'rangechange',
27 'rangechanged',
28 'timechange',
29 'timechanged',
30 'select',
31 'doubleClick',
32 'click',
33 'contextmenu'
34 ];
35
36 // Declare the timeline
37 var timeline = null;
38
39 scope.$watch('data', function () {
40 // Sanity check
41 if (scope.data == null) {
42 return;
43 }
44
45 // If we've actually changed the data set, then recreate the graph
46 // We can always update the data by adding more data to the existing data set
47 if (timeline != null) {
48 timeline.destroy();
49 }
50
51 // Create the timeline object
52 timeline = new vis.Timeline(element[0], scope.data.items, scope.data.groups, scope.options);
53
54 // Attach an event handler if defined
55 angular.forEach(scope.events, function (callback, event) {
56 if (timelineEvents.indexOf(String(event)) >= 0) {
57 timeline.on(event, callback);
58 }
59 });
60
61 // onLoad callback
62 if (scope.events != null && scope.events.onload != null &&
63 angular.isFunction(scope.events.onload)) {
64 scope.events.onload(timeline);
65 }
66 });
67
68 scope.$watchCollection('options', function (options) {
69 if (timeline == null) {
70 return;
71 }
72 timeline.setOptions(options);
73 });
74 }
75 };
76 })
77
78/**
79 * Directive for network chart.
80 */
81 .directive('visNetwork', function () {
82 return {
83 restrict: 'EA',
84 transclude: false,
85 scope: {
86 data: '=',
87 options: '=',
88 events: '='
89 },
90 link: function (scope, element, attr) {
91 var networkEvents = [
92 'click',
93 'doubleClick',
94 'oncontext',
95 'hold',
96 'release',
97 'selectNode',
98 'selectEdge',
99 'deselectNode',
100 'deselectEdge',
101 'dragStart',
102 'dragging',
103 'dragEnd',
104 'hoverNode',
105 'hoverEdge',
106 'blurNode',
107 'blurEdge',
108 'zoom',
109 'showPopup',
110 'hidePopup',
111 'startStabilizing',
112 'stabilizationProgress',
113 'stabilizationIterationsDone',
114 'stabilized',
115 'resize',
116 'initRedraw',
117 'beforeDrawing',
118 'afterDrawing',
119 'animationFinished'
120
121 ];
122
123 var network = null;
124
125 scope.$watch('data', function () {
126 // Sanity check
127 if (scope.data == null) {
128 return;
129 }
130
131 // If we've actually changed the data set, then recreate the graph
132 // We can always update the data by adding more data to the existing data set
133 if (network != null) {
134 network.destroy();
135 }
136
137 // Create the graph2d object
138 network = new vis.Network(element[0], scope.data, scope.options);
139
140 // Attach an event handler if defined
141 angular.forEach(scope.events, function (callback, event) {
142 if (networkEvents.indexOf(String(event)) >= 0) {
143 network.on(event, callback);
144 }
145 });
146
147 // onLoad callback
148 if (scope.events != null && scope.events.onload != null &&
149 angular.isFunction(scope.events.onload)) {
150 scope.events.onload(network);
151 }
152 });
153
154 scope.$watchCollection('options', function (options) {
155 if (network == null) {
156 return;
157 }
158 network.setOptions(options);
159 });
160 }
161 };
162 })
163
164/**
165 * Directive for graph2d.
166 */
167 .directive('visGraph2d', function () {
168 'use strict';
169 return {
170 restrict: 'EA',
171 transclude: false,
172 scope: {
173 data: '=',
174 options: '=',
175 events: '='
176 },
177 link: function (scope, element, attr) {
178 var graphEvents = [
179 'rangechange',
180 'rangechanged',
181 'timechange',
182 'timechanged',
183 'finishedRedraw'
184 ];
185
186 // Create the chart
187 var graph = null;
188
189 scope.$watch('data', function () {
190 // Sanity check
191 if (scope.data == null) {
192 return;
193 }
194
195 // If we've actually changed the data set, then recreate the graph
196 // We can always update the data by adding more data to the existing data set
197 if (graph != null) {
198 graph.destroy();
199 }
200
201 // Create the graph2d object
202 graph = new vis.Graph2d(element[0], scope.data.items, scope.data.groups, scope.options);
203
204 // Attach an event handler if defined
205 angular.forEach(scope.events, function (callback, event) {
206 if (graphEvents.indexOf(String(event)) >= 0) {
207 graph.on(event, callback);
208 }
209 });
210
211 // onLoad callback
212 if (scope.events != null && scope.events.onload != null &&
213 angular.isFunction(scope.events.onload)) {
214 scope.events.onload(graph);
215 }
216 });
217
218 scope.$watchCollection('options', function (options) {
219 if (graph == null) {
220 return;
221 }
222 graph.setOptions(options);
223 });
224 }
225 };
226 })
227;
diff --git a/heat_dashboard/static/dashboard/project/heat_dashboard/template_generator/js/libs/js-yaml.js b/heat_dashboard/static/dashboard/project/heat_dashboard/template_generator/js/libs/js-yaml.js
deleted file mode 100644
index 422dce1..0000000
--- a/heat_dashboard/static/dashboard/project/heat_dashboard/template_generator/js/libs/js-yaml.js
+++ /dev/null
@@ -1,3862 +0,0 @@
1/* js-yaml 3.8.1 https://github.com/nodeca/js-yaml */(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.jsyaml = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
2'use strict';
3
4
5var loader = require('./js-yaml/loader');
6var dumper = require('./js-yaml/dumper');
7
8
9function deprecated(name) {
10 return function () {
11 throw new Error('Function ' + name + ' is deprecated and cannot be used.');
12 };
13}
14
15
16module.exports.Type = require('./js-yaml/type');
17module.exports.Schema = require('./js-yaml/schema');
18module.exports.FAILSAFE_SCHEMA = require('./js-yaml/schema/failsafe');
19module.exports.JSON_SCHEMA = require('./js-yaml/schema/json');
20module.exports.CORE_SCHEMA = require('./js-yaml/schema/core');
21module.exports.DEFAULT_SAFE_SCHEMA = require('./js-yaml/schema/default_safe');
22module.exports.DEFAULT_FULL_SCHEMA = require('./js-yaml/schema/default_full');
23module.exports.load = loader.load;
24module.exports.loadAll = loader.loadAll;
25module.exports.safeLoad = loader.safeLoad;
26module.exports.safeLoadAll = loader.safeLoadAll;
27module.exports.dump = dumper.dump;
28module.exports.safeDump = dumper.safeDump;
29module.exports.YAMLException = require('./js-yaml/exception');
30
31// Deprecated schema names from JS-YAML 2.0.x
32module.exports.MINIMAL_SCHEMA = require('./js-yaml/schema/failsafe');
33module.exports.SAFE_SCHEMA = require('./js-yaml/schema/default_safe');
34module.exports.DEFAULT_SCHEMA = require('./js-yaml/schema/default_full');
35
36// Deprecated functions from JS-YAML 1.x.x
37module.exports.scan = deprecated('scan');
38module.exports.parse = deprecated('parse');
39module.exports.compose = deprecated('compose');
40module.exports.addConstructor = deprecated('addConstructor');
41
42},{"./js-yaml/dumper":3,"./js-yaml/exception":4,"./js-yaml/loader":5,"./js-yaml/schema":7,"./js-yaml/schema/core":8,"./js-yaml/schema/default_full":9,"./js-yaml/schema/default_safe":10,"./js-yaml/schema/failsafe":11,"./js-yaml/schema/json":12,"./js-yaml/type":13}],2:[function(require,module,exports){
43'use strict';
44
45
46function isNothing(subject) {
47 return (typeof subject === 'undefined') || (subject === null);
48}
49
50
51function isObject(subject) {
52 return (typeof subject === 'object') && (subject !== null);
53}
54
55
56function toArray(sequence) {
57 if (Array.isArray(sequence)) return sequence;
58 else if (isNothing(sequence)) return [];
59
60 return [ sequence ];
61}
62
63
64function extend(target, source) {
65 var index, length, key, sourceKeys;
66
67 if (source) {
68 sourceKeys = Object.keys(source);
69
70 for (index = 0, length = sourceKeys.length; index < length; index += 1) {
71 key = sourceKeys[index];
72 target[key] = source[key];
73 }
74 }
75
76 return target;
77}
78
79
80function repeat(string, count) {
81 var result = '', cycle;
82
83 for (cycle = 0; cycle < count; cycle += 1) {
84 result += string;
85 }
86
87 return result;
88}
89
90
91function isNegativeZero(number) {
92 return (number === 0) && (Number.NEGATIVE_INFINITY === 1 / number);
93}
94
95
96module.exports.isNothing = isNothing;
97module.exports.isObject = isObject;
98module.exports.toArray = toArray;
99module.exports.repeat = repeat;
100module.exports.isNegativeZero = isNegativeZero;
101module.exports.extend = extend;
102
103},{}],3:[function(require,module,exports){
104'use strict';
105
106/*eslint-disable no-use-before-define*/
107
108var common = require('./common');
109var YAMLException = require('./exception');
110var DEFAULT_FULL_SCHEMA = require('./schema/default_full');
111var DEFAULT_SAFE_SCHEMA = require('./schema/default_safe');
112
113var _toString = Object.prototype.toString;
114var _hasOwnProperty = Object.prototype.hasOwnProperty;
115
116var CHAR_TAB = 0x09; /* Tab */
117var CHAR_LINE_FEED = 0x0A; /* LF */
118var CHAR_SPACE = 0x20; /* Space */
119var CHAR_EXCLAMATION = 0x21; /* ! */
120var CHAR_DOUBLE_QUOTE = 0x22; /* " */
121var CHAR_SHARP = 0x23; /* # */
122var CHAR_PERCENT = 0x25; /* % */
123var CHAR_AMPERSAND = 0x26; /* & */
124var CHAR_SINGLE_QUOTE = 0x27; /* ' */
125var CHAR_ASTERISK = 0x2A; /* * */
126var CHAR_COMMA = 0x2C; /* , */
127var CHAR_MINUS = 0x2D; /* - */
128var CHAR_COLON = 0x3A; /* : */
129var CHAR_GREATER_THAN = 0x3E; /* > */
130var CHAR_QUESTION = 0x3F; /* ? */
131var CHAR_COMMERCIAL_AT = 0x40; /* @ */
132var CHAR_LEFT_SQUARE_BRACKET = 0x5B; /* [ */
133var CHAR_RIGHT_SQUARE_BRACKET = 0x5D; /* ] */
134var CHAR_GRAVE_ACCENT = 0x60; /* ` */
135var CHAR_LEFT_CURLY_BRACKET = 0x7B; /* { */
136var CHAR_VERTICAL_LINE = 0x7C; /* | */
137var CHAR_RIGHT_CURLY_BRACKET = 0x7D; /* } */
138
139var ESCAPE_SEQUENCES = {};
140
141ESCAPE_SEQUENCES[0x00] = '\\0';
142ESCAPE_SEQUENCES[0x07] = '\\a';
143ESCAPE_SEQUENCES[0x08] = '\\b';
144ESCAPE_SEQUENCES[0x09] = '\\t';
145ESCAPE_SEQUENCES[0x0A] = '\\n';
146ESCAPE_SEQUENCES[0x0B] = '\\v';
147ESCAPE_SEQUENCES[0x0C] = '\\f';
148ESCAPE_SEQUENCES[0x0D] = '\\r';
149ESCAPE_SEQUENCES[0x1B] = '\\e';
150ESCAPE_SEQUENCES[0x22] = '\\"';
151ESCAPE_SEQUENCES[0x5C] = '\\\\';
152ESCAPE_SEQUENCES[0x85] = '\\N';
153ESCAPE_SEQUENCES[0xA0] = '\\_';
154ESCAPE_SEQUENCES[0x2028] = '\\L';
155ESCAPE_SEQUENCES[0x2029] = '\\P';
156
157var DEPRECATED_BOOLEANS_SYNTAX = [
158 'y', 'Y', 'yes', 'Yes', 'YES', 'on', 'On', 'ON',
159 'n', 'N', 'no', 'No', 'NO', 'off', 'Off', 'OFF'
160];
161
162function compileStyleMap(schema, map) {
163 var result, keys, index, length, tag, style, type;
164
165 if (map === null) return {};
166
167 result = {};
168 keys = Object.keys(map);
169
170 for (index = 0, length = keys.length; index < length; index += 1) {
171 tag = keys[index];
172 style = String(map[tag]);
173
174 if (tag.slice(0, 2) === '!!') {
175 tag = 'tag:yaml.org,2002:' + tag.slice(2);
176 }
177 type = schema.compiledTypeMap['fallback'][tag];
178
179 if (type && _hasOwnProperty.call(type.styleAliases, style)) {
180 style = type.styleAliases[style];
181 }
182
183 result[tag] = style;
184 }
185
186 return result;
187}
188
189function encodeHex(character) {
190 var string, handle, length;
191
192 string = character.toString(16).toUpperCase();
193
194 if (character <= 0xFF) {
195 handle = 'x';
196 length = 2;
197 } else if (character <= 0xFFFF) {
198 handle = 'u';
199 length = 4;
200 } else if (character <= 0xFFFFFFFF) {
201 handle = 'U';
202 length = 8;
203 } else {
204 throw new YAMLException('code point within a string may not be greater than 0xFFFFFFFF');
205 }
206
207 return '\\' + handle + common.repeat('0', length - string.length) + string;
208}
209
210function State(options) {
211 this.schema = options['schema'] || DEFAULT_FULL_SCHEMA;
212 this.indent = Math.max(1, (options['indent'] || 2));
213 this.skipInvalid = options['skipInvalid'] || false;
214 this.flowLevel = (common.isNothing(options['flowLevel']) ? -1 : options['flowLevel']);
215 this.styleMap = compileStyleMap(this.schema, options['styles'] || null);
216 this.sortKeys = options['sortKeys'] || false;
217 this.lineWidth = options['lineWidth'] || 80;
218 this.noRefs = options['noRefs'] || false;
219 this.noCompatMode = options['noCompatMode'] || false;
220
221 this.implicitTypes = this.schema.compiledImplicit;
222 this.explicitTypes = this.schema.compiledExplicit;
223
224 this.tag = null;
225 this.result = '';
226
227 this.duplicates = [];
228 this.usedDuplicates = null;
229}
230
231// Indents every line in a string. Empty lines (\n only) are not indented.
232function indentString(string, spaces) {
233 var ind = common.repeat(' ', spaces),
234 position = 0,
235 next = -1,
236 result = '',
237 line,
238 length = string.length;
239
240 while (position < length) {
241 next = string.indexOf('\n', position);
242 if (next === -1) {
243 line = string.slice(position);
244 position = length;
245 } else {
246 line = string.slice(position, next + 1);
247 position = next + 1;
248 }
249
250 if (line.length && line !== '\n') result += ind;
251
252 result += line;
253 }
254
255 return result;
256}
257
258function generateNextLine(state, level) {
259 return '\n' + common.repeat(' ', state.indent * level);
260}
261
262function testImplicitResolving(state, str) {
263 var index, length, type;
264
265 for (index = 0, length = state.implicitTypes.length; index < length; index += 1) {
266 type = state.implicitTypes[index];
267
268 if (type.resolve(str)) {
269 return true;
270 }
271 }
272
273 return false;
274}
275
276// [33] s-white ::= s-space | s-tab
277function isWhitespace(c) {
278 return c === CHAR_SPACE || c === CHAR_TAB;
279}
280
281// Returns true if the character can be printed without escaping.
282// From YAML 1.2: "any allowed characters known to be non-printable
283// should also be escaped. [However,] This isn’t mandatory"
284// Derived from nb-char - \t - #x85 - #xA0 - #x2028 - #x2029.
285function isPrintable(c) {
286 return (0x00020 <= c && c <= 0x00007E)
287 || ((0x000A1 <= c && c <= 0x00D7FF) && c !== 0x2028 && c !== 0x2029)
288 || ((0x0E000 <= c && c <= 0x00FFFD) && c !== 0xFEFF /* BOM */)
289 || (0x10000 <= c && c <= 0x10FFFF);
290}
291
292// Simplified test for values allowed after the first character in plain style.
293function isPlainSafe(c) {
294 // Uses a subset of nb-char - c-flow-indicator - ":" - "#"
295 // where nb-char ::= c-printable - b-char - c-byte-order-mark.
296 return isPrintable(c) && c !== 0xFEFF
297 // - c-flow-indicator
298 && c !== CHAR_COMMA
299 && c !== CHAR_LEFT_SQUARE_BRACKET
300 && c !== CHAR_RIGHT_SQUARE_BRACKET
301 && c !== CHAR_LEFT_CURLY_BRACKET
302 && c !== CHAR_RIGHT_CURLY_BRACKET
303 // - ":" - "#"
304 && c !== CHAR_COLON
305 && c !== CHAR_SHARP;
306}
307
308// Simplified test for values allowed as the first character in plain style.
309function isPlainSafeFirst(c) {
310 // Uses a subset of ns-char - c-indicator
311 // where ns-char = nb-char - s-white.
312 return isPrintable(c) && c !== 0xFEFF
313 && !isWhitespace(c) // - s-white
314 // - (c-indicator ::=
315 // “-” | “?” | “:” | “,” | “[” | “]” | “{” | “}”
316 && c !== CHAR_MINUS
317 && c !== CHAR_QUESTION
318 && c !== CHAR_COLON
319 && c !== CHAR_COMMA
320 && c !== CHAR_LEFT_SQUARE_BRACKET
321 && c !== CHAR_RIGHT_SQUARE_BRACKET
322 && c !== CHAR_LEFT_CURLY_BRACKET
323 && c !== CHAR_RIGHT_CURLY_BRACKET
324 // | “#” | “&” | “*” | “!” | “|” | “>” | “'” | “"”
325 && c !== CHAR_SHARP
326 && c !== CHAR_AMPERSAND
327 && c !== CHAR_ASTERISK
328 && c !== CHAR_EXCLAMATION
329 && c !== CHAR_VERTICAL_LINE
330 && c !== CHAR_GREATER_THAN
331 && c !== CHAR_SINGLE_QUOTE
332 && c !== CHAR_DOUBLE_QUOTE
333 // | “%” | “@” | “`”)
334 && c !== CHAR_PERCENT
335 && c !== CHAR_COMMERCIAL_AT
336 && c !== CHAR_GRAVE_ACCENT;
337}
338
339var STYLE_PLAIN = 1,
340 STYLE_SINGLE = 2,
341 STYLE_LITERAL = 3,
342 STYLE_FOLDED = 4,
343 STYLE_DOUBLE = 5;
344
345// Determines which scalar styles are possible and returns the preferred style.
346// lineWidth = -1 => no limit.
347// Pre-conditions: str.length > 0.
348// Post-conditions:
349// STYLE_PLAIN or STYLE_SINGLE => no \n are in the string.
350// STYLE_LITERAL => no lines are suitable for folding (or lineWidth is -1).
351// STYLE_FOLDED => a line > lineWidth and can be folded (and lineWidth != -1).
352function chooseScalarStyle(string, singleLineOnly, indentPerLevel, lineWidth, testAmbiguousType) {
353 var i;
354 var char;
355 var hasLineBreak = false;
356 var hasFoldableLine = false; // only checked if shouldTrackWidth
357 var shouldTrackWidth = lineWidth !== -1;
358 var previousLineBreak = -1; // count the first line correctly
359 var plain = isPlainSafeFirst(string.charCodeAt(0))
360 && !isWhitespace(string.charCodeAt(string.length - 1));
361
362 if (singleLineOnly) {
363 // Case: no block styles.
364 // Check for disallowed characters to rule out plain and single.
365 for (i = 0; i < string.length; i++) {
366 char = string.charCodeAt(i);
367 if (!isPrintable(char)) {
368 return STYLE_DOUBLE;
369 }
370 plain = plain && isPlainSafe(char);
371 }
372 } else {
373 // Case: block styles permitted.
374 for (i = 0; i < string.length; i++) {
375 char = string.charCodeAt(i);
376 if (char === CHAR_LINE_FEED) {
377 hasLineBreak = true;
378 // Check if any line can be folded.
379 if (shouldTrackWidth) {
380 hasFoldableLine = hasFoldableLine ||
381 // Foldable line = too long, and not more-indented.
382 (i - previousLineBreak - 1 > lineWidth &&
383 string[previousLineBreak + 1] !== ' ');
384 previousLineBreak = i;
385 }
386 } else if (!isPrintable(char)) {
387 return STYLE_DOUBLE;
388 }
389 plain = plain && isPlainSafe(char);
390 }
391 // in case the end is missing a \n
392 hasFoldableLine = hasFoldableLine || (shouldTrackWidth &&
393 (i - previousLineBreak - 1 > lineWidth &&
394 string[previousLineBreak + 1] !== ' '));
395 }
396 // Although every style can represent \n without escaping, prefer block styles
397 // for multiline, since they're more readable and they don't add empty lines.
398 // Also prefer folding a super-long line.
399 if (!hasLineBreak && !hasFoldableLine) {
400 // Strings interpretable as another type have to be quoted;
401 // e.g. the string 'true' vs. the boolean true.
402 return plain && !testAmbiguousType(string)
403 ? STYLE_PLAIN : STYLE_SINGLE;
404 }
405 // Edge case: block indentation indicator can only have one digit.
406 if (string[0] === ' ' && indentPerLevel > 9) {
407 return STYLE_DOUBLE;
408 }
409 // At this point we know block styles are valid.
410 // Prefer literal style unless we want to fold.
411 return hasFoldableLine ? STYLE_FOLDED : STYLE_LITERAL;
412}
413
414// Note: line breaking/folding is implemented for only the folded style.
415// NB. We drop the last trailing newline (if any) of a returned block scalar
416// since the dumper adds its own newline. This always works:
417// • No ending newline => unaffected; already using strip "-" chomping.
418// • Ending newline => removed then restored.
419// Importantly, this keeps the "+" chomp indicator from gaining an extra line.
420function writeScalar(state, string, level, iskey) {
421 state.dump = (function () {
422 if (string.length === 0) {
423 return "''";
424 }
425 if (!state.noCompatMode &&
426 DEPRECATED_BOOLEANS_SYNTAX.indexOf(string) !== -1) {
427 return "'" + string + "'";
428 }
429
430 var indent = state.indent * Math.max(1, level); // no 0-indent scalars
431 // As indentation gets deeper, let the width decrease monotonically
432 // to the lower bound min(state.lineWidth, 40).
433 // Note that this implies
434 // state.lineWidth ≤ 40 + state.indent: width is fixed at the lower bound.
435 // state.lineWidth > 40 + state.indent: width decreases until the lower bound.
436 // This behaves better than a constant minimum width which disallows narrower options,
437 // or an indent threshold which causes the width to suddenly increase.
438 var lineWidth = state.lineWidth === -1
439 ? -1 : Math.max(Math.min(state.lineWidth, 40), state.lineWidth - indent);
440
441 // Without knowing if keys are implicit/explicit, assume implicit for safety.
442 var singleLineOnly = iskey
443 // No block styles in flow mode.
444 || (state.flowLevel > -1 && level >= state.flowLevel);
445 function testAmbiguity(string) {
446 return testImplicitResolving(state, string);
447 }
448
449 switch (chooseScalarStyle(string, singleLineOnly, state.indent, lineWidth, testAmbiguity)) {
450 case STYLE_PLAIN:
451 return string;
452 case STYLE_SINGLE:
453 return "'" + string.replace(/'/g, "''") + "'";
454 case STYLE_LITERAL:
455 return '|' + blockHeader(string, state.indent)
456 + dropEndingNewline(indentString(string, indent));
457 case STYLE_FOLDED:
458 return '>' + blockHeader(string, state.indent)
459 + dropEndingNewline(indentString(foldString(string, lineWidth), indent));
460 case STYLE_DOUBLE:
461 return '"' + escapeString(string, lineWidth) + '"';
462 default:
463 throw new YAMLException('impossible error: invalid scalar style');
464 }
465 }());
466}
467
468// Pre-conditions: string is valid for a block scalar, 1 <= indentPerLevel <= 9.
469function blockHeader(string, indentPerLevel) {
470 var indentIndicator = (string[0] === ' ') ? String(indentPerLevel) : '';
471
472 // note the special case: the string '\n' counts as a "trailing" empty line.
473 var clip = string[string.length - 1] === '\n';
474 var keep = clip && (string[string.length - 2] === '\n' || string === '\n');
475 var chomp = keep ? '+' : (clip ? '' : '-');
476
477 return indentIndicator + chomp + '\n';
478}
479
480// (See the note for writeScalar.)
481function dropEndingNewline(string) {
482 return string[string.length - 1] === '\n' ? string.slice(0, -1) : string;
483}
484
485// Note: a long line without a suitable break point will exceed the width limit.
486// Pre-conditions: every char in str isPrintable, str.length > 0, width > 0.
487function foldString(string, width) {
488 // In folded style, $k$ consecutive newlines output as $k+1$ newlines—
489 // unless they're before or after a more-indented line, or at the very
490 // beginning or end, in which case $k$ maps to $k$.
491 // Therefore, parse each chunk as newline(s) followed by a content line.
492 var lineRe = /(\n+)([^\n]*)/g;
493
494 // first line (possibly an empty line)
495 var result = (function () {
496 var nextLF = string.indexOf('\n');
497 nextLF = nextLF !== -1 ? nextLF : string.length;
498 lineRe.lastIndex = nextLF;
499 return foldLine(string.slice(0, nextLF), width);
500 }());
501 // If we haven't reached the first content line yet, don't add an extra \n.
502 var prevMoreIndented = string[0] === '\n' || string[0] === ' ';
503 var moreIndented;
504
505 // rest of the lines
506 var match;
507 while ((match = lineRe.exec(string))) {
508 var prefix = match[1], line = match[2];
509 moreIndented = (line[0] === ' ');
510 result += prefix
511 + (!prevMoreIndented && !moreIndented && line !== ''
512 ? '\n' : '')
513 + foldLine(line, width);
514 prevMoreIndented = moreIndented;
515 }
516
517 return result;
518}
519
520// Greedy line breaking.
521// Picks the longest line under the limit each time,
522// otherwise settles for the shortest line over the limit.
523// NB. More-indented lines *cannot* be folded, as that would add an extra \n.
524function foldLine(line, width) {
525 if (line === '' || line[0] === ' ') return line;
526
527 // Since a more-indented line adds a \n, breaks can't be followed by a space.
528 var breakRe = / [^ ]/g; // note: the match index will always be <= length-2.
529 var match;
530 // start is an inclusive index. end, curr, and next are exclusive.
531 var start = 0, end, curr = 0, next = 0;
532 var result = '';
533
534 // Invariants: 0 <= start <= length-1.
535 // 0 <= curr <= next <= max(0, length-2). curr - start <= width.
536 // Inside the loop:
537 // A match implies length >= 2, so curr and next are <= length-2.
538 while ((match = breakRe.exec(line))) {
539 next = match.index;
540 // maintain invariant: curr - start <= width
541 if (next - start > width) {
542 end = (curr > start) ? curr : next; // derive end <= length-2
543 result += '\n' + line.slice(start, end);
544 // skip the space that was output as \n
545 start = end + 1; // derive start <= length-1
546 }
547 curr = next;
548 }
549
550 // By the invariants, start <= length-1, so there is something left over.
551 // It is either the whole string or a part starting from non-whitespace.
552 result += '\n';
553 // Insert a break if the remainder is too long and there is a break available.
554 if (line.length - start > width && curr > start) {
555 result += line.slice(start, curr) + '\n' + line.slice(curr + 1);
556 } else {
557 result += line.slice(start);
558 }
559
560 return result.slice(1); // drop extra \n joiner
561}
562
563// Escapes a double-quoted string.
564function escapeString(string) {
565 var result = '';
566 var char;
567 var escapeSeq;
568
569 for (var i = 0; i < string.length; i++) {
570 char = string.charCodeAt(i);
571 escapeSeq = ESCAPE_SEQUENCES[char];
572 result += !escapeSeq && isPrintable(char)
573 ? string[i]
574 : escapeSeq || encodeHex(char);
575 }
576
577 return result;
578}
579
580function writeFlowSequence(state, level, object) {
581 var _result = '',
582 _tag = state.tag,
583 index,
584 length;
585
586 for (index = 0, length = object.length; index < length; index += 1) {
587 // Write only valid elements.
588 if (writeNode(state, level, object[index], false, false)) {
589 if (index !== 0) _result += ', ';
590 _result += state.dump;
591 }
592 }
593
594 state.tag = _tag;
595 state.dump = '[' + _result + ']';
596}
597
598function writeBlockSequence(state, level, object, compact) {
599 var _result = '',
600 _tag = state.tag,
601 index,
602 length;
603
604 for (index = 0, length = object.length; index < length; index += 1) {
605 // Write only valid elements.
606 if (writeNode(state, level + 1, object[index], true, true)) {
607 if (!compact || index !== 0) {
608 _result += generateNextLine(state, level);
609 }
610 _result += '- ' + state.dump;
611 }
612 }
613
614 state.tag = _tag;
615 state.dump = _result || '[]'; // Empty sequence if no valid values.
616}
617
618function writeFlowMapping(state, level, object) {
619 var _result = '',
620 _tag = state.tag,
621 objectKeyList = Object.keys(object),
622 index,
623 length,
624 objectKey,
625 objectValue,
626 pairBuffer;
627
628 for (index = 0, length = objectKeyList.length; index < length; index += 1) {
629 pairBuffer = '';
630
631 if (index !== 0) pairBuffer += ', ';
632
633 objectKey = objectKeyList[index];
634 objectValue = object[objectKey];
635
636 if (!writeNode(state, level, objectKey, false, false)) {
637 continue; // Skip this pair because of invalid key;
638 }
639
640 if (state.dump.length > 1024) pairBuffer += '? ';
641
642 pairBuffer += state.dump + ': ';
643
644 if (!writeNode(state, level, objectValue, false, false)) {
645 continue; // Skip this pair because of invalid value.
646 }
647
648 pairBuffer += state.dump;
649
650 // Both key and value are valid.
651 _result += pairBuffer;
652 }
653
654 state.tag = _tag;
655 state.dump = '{' + _result + '}';
656}
657
658function writeBlockMapping(state, level, object, compact) {
659 var _result = '',
660 _tag = state.tag,
661 objectKeyList = Object.keys(object),
662 index,
663 length,
664 objectKey,
665 objectValue,
666 explicitPair,
667 pairBuffer;
668
669 // Allow sorting keys so that the output file is deterministic
670 if (state.sortKeys === true) {
671 // Default sorting
672 objectKeyList.sort();
673 } else if (typeof state.sortKeys === 'function') {
674 // Custom sort function
675 objectKeyList.sort(state.sortKeys);
676 } else if (state.sortKeys) {
677 // Something is wrong
678 throw new YAMLException('sortKeys must be a boolean or a function');
679 }
680
681 for (index = 0, length = objectKeyList.length; index < length; index += 1) {
682 pairBuffer = '';
683
684 if (!compact || index !== 0) {
685 pairBuffer += generateNextLine(state, level);
686 }
687
688 objectKey = objectKeyList[index];
689 objectValue = object[objectKey];
690
691 if (!writeNode(state, level + 1, objectKey, true, true, true)) {
692 continue; // Skip this pair because of invalid key.
693 }
694
695 explicitPair = (state.tag !== null && state.tag !== '?') ||
696 (state.dump && state.dump.length > 1024);
697
698 if (explicitPair) {
699 if (state.dump && CHAR_LINE_FEED === state.dump.charCodeAt(0)) {
700 pairBuffer += '?';
701 } else {
702 pairBuffer += '? ';
703 }
704 }
705
706 pairBuffer += state.dump;
707
708 if (explicitPair) {
709 pairBuffer += generateNextLine(state, level);
710 }
711
712 if (!writeNode(state, level + 1, objectValue, true, explicitPair)) {
713 continue; // Skip this pair because of invalid value.
714 }
715
716 if (state.dump && CHAR_LINE_FEED === state.dump.charCodeAt(0)) {
717 pairBuffer += ':';
718 } else {
719 pairBuffer += ': ';
720 }
721
722 pairBuffer += state.dump;
723
724 // Both key and value are valid.
725 _result += pairBuffer;
726 }
727
728 state.tag = _tag;
729 state.dump = _result || '{}'; // Empty mapping if no valid pairs.
730}
731
732function detectType(state, object, explicit) {
733 var _result, typeList, index, length, type, style;
734
735 typeList = explicit ? state.explicitTypes : state.implicitTypes;
736
737 for (index = 0, length = typeList.length; index < length; index += 1) {
738 type = typeList[index];
739
740 if ((type.instanceOf || type.predicate) &&
741 (!type.instanceOf || ((typeof object === 'object') && (object instanceof type.instanceOf))) &&
742 (!type.predicate || type.predicate(object))) {
743
744 state.tag = explicit ? type.tag : '?';
745
746 if (type.represent) {
747 style = state.styleMap[type.tag] || type.defaultStyle;
748
749 if (_toString.call(type.represent) === '[object Function]') {
750 _result = type.represent(object, style);
751 } else if (_hasOwnProperty.call(type.represent, style)) {
752 _result = type.represent[style](object, style);
753 } else {
754 throw new YAMLException('!<' + type.tag + '> tag resolver accepts not "' + style + '" style');
755 }
756
757 state.dump = _result;
758 }
759
760 return true;
761 }
762 }
763
764 return false;
765}
766
767// Serializes `object` and writes it to global `result`.
768// Returns true on success, or false on invalid object.
769//
770function writeNode(state, level, object, block, compact, iskey) {
771 state.tag = null;
772 state.dump = object;
773
774 if (!detectType(state, object, false)) {
775 detectType(state, object, true);
776 }
777
778 var type = _toString.call(state.dump);
779
780 if (block) {
781 block = (state.flowLevel < 0 || state.flowLevel > level);
782 }
783
784 var objectOrArray = type === '[object Object]' || type === '[object Array]',
785 duplicateIndex,
786 duplicate;
787
788 if (objectOrArray) {
789 duplicateIndex = state.duplicates.indexOf(object);
790 duplicate = duplicateIndex !== -1;
791 }
792
793 if ((state.tag !== null && state.tag !== '?') || duplicate || (state.indent !== 2 && level > 0)) {
794 compact = false;
795 }
796
797 if (duplicate && state.usedDuplicates[duplicateIndex]) {
798 state.dump = '*ref_' + duplicateIndex;
799 } else {
800 if (objectOrArray && duplicate && !state.usedDuplicates[duplicateIndex]) {
801 state.usedDuplicates[duplicateIndex] = true;
802 }
803 if (type === '[object Object]') {
804 if (block && (Object.keys(state.dump).length !== 0)) {
805 writeBlockMapping(state, level, state.dump, compact);
806 if (duplicate) {
807 state.dump = '&ref_' + duplicateIndex + state.dump;
808 }
809 } else {
810 writeFlowMapping(state, level, state.dump);
811 if (duplicate) {
812 state.dump = '&ref_' + duplicateIndex + ' ' + state.dump;
813 }
814 }
815 } else if (type === '[object Array]') {
816 if (block && (state.dump.length !== 0)) {
817 writeBlockSequence(state, level, state.dump, compact);
818 if (duplicate) {
819 state.dump = '&ref_' + duplicateIndex + state.dump;
820 }
821 } else {
822 writeFlowSequence(state, level, state.dump);
823 if (duplicate) {
824 state.dump = '&ref_' + duplicateIndex + ' ' + state.dump;
825 }
826 }
827 } else if (type === '[object String]') {
828 if (state.tag !== '?') {
829 writeScalar(state, state.dump, level, iskey);
830 }
831 } else {
832 if (state.skipInvalid) return false;
833 throw new YAMLException('unacceptable kind of an object to dump ' + type);
834 }
835
836 if (state.tag !== null && state.tag !== '?') {
837 state.dump = '!<' + state.tag + '> ' + state.dump;
838 }
839 }
840
841 return true;
842}
843
844function getDuplicateReferences(object, state) {
845 var objects = [],
846 duplicatesIndexes = [],
847 index,
848 length;
849
850 inspectNode(object, objects, duplicatesIndexes);
851
852 for (index = 0, length = duplicatesIndexes.length; index < length; index += 1) {
853 state.duplicates.push(objects[duplicatesIndexes[index]]);
854 }
855 state.usedDuplicates = new Array(length);
856}
857
858function inspectNode(object, objects, duplicatesIndexes) {
859 var objectKeyList,
860 index,
861 length;
862
863 if (object !== null && typeof object === 'object') {
864 index = objects.indexOf(object);
865 if (index !== -1) {
866 if (duplicatesIndexes.indexOf(index) === -1) {
867 duplicatesIndexes.push(index);
868 }
869 } else {
870 objects.push(object);
871
872 if (Array.isArray(object)) {
873 for (index = 0, length = object.length; index < length; index += 1) {
874 inspectNode(object[index], objects, duplicatesIndexes);
875 }
876 } else {
877 objectKeyList = Object.keys(object);
878
879 for (index = 0, length = objectKeyList.length; index < length; index += 1) {
880 inspectNode(object[objectKeyList[index]], objects, duplicatesIndexes);
881 }
882 }
883 }
884 }
885}
886
887function dump(input, options) {
888 options = options || {};
889
890 var state = new State(options);
891
892 if (!state.noRefs) getDuplicateReferences(input, state);
893
894 if (writeNode(state, 0, input, true, true)) return state.dump + '\n';
895
896 return '';
897}
898
899function safeDump(input, options) {
900 return dump(input, common.extend({ schema: DEFAULT_SAFE_SCHEMA }, options));
901}
902
903module.exports.dump = dump;
904module.exports.safeDump = safeDump;
905
906},{"./common":2,"./exception":4,"./schema/default_full":9,"./schema/default_safe":10}],4:[function(require,module,exports){
907// YAML error class. http://stackoverflow.com/questions/8458984
908//
909'use strict';
910
911function YAMLException(reason, mark) {
912 // Super constructor
913 Error.call(this);
914
915 // Include stack trace in error object
916 if (Error.captureStackTrace) {
917 // Chrome and NodeJS
918 Error.captureStackTrace(this, this.constructor);
919 } else {
920 // FF, IE 10+ and Safari 6+. Fallback for others
921 this.stack = (new Error()).stack || '';
922 }
923
924 this.name = 'YAMLException';
925 this.reason = reason;
926 this.mark = mark;
927 this.message = (this.reason || '(unknown reason)') + (this.mark ? ' ' + this.mark.toString() : '');
928}
929
930
931// Inherit from Error
932YAMLException.prototype = Object.create(Error.prototype);
933YAMLException.prototype.constructor = YAMLException;
934
935
936YAMLException.prototype.toString = function toString(compact) {
937 var result = this.name + ': ';
938
939 result += this.reason || '(unknown reason)';
940
941 if (!compact && this.mark) {
942 result += ' ' + this.mark.toString();
943 }
944
945 return result;
946};
947
948
949module.exports = YAMLException;
950
951},{}],5:[function(require,module,exports){
952'use strict';
953
954/*eslint-disable max-len,no-use-before-define*/
955
956var common = require('./common');
957var YAMLException = require('./exception');
958var Mark = require('./mark');
959var DEFAULT_SAFE_SCHEMA = require('./schema/default_safe');
960var DEFAULT_FULL_SCHEMA = require('./schema/default_full');
961
962
963var _hasOwnProperty = Object.prototype.hasOwnProperty;
964
965
966var CONTEXT_FLOW_IN = 1;
967var CONTEXT_FLOW_OUT = 2;
968var CONTEXT_BLOCK_IN = 3;
969var CONTEXT_BLOCK_OUT = 4;
970
971
972var CHOMPING_CLIP = 1;
973var CHOMPING_STRIP = 2;
974var CHOMPING_KEEP = 3;
975
976
977var PATTERN_NON_PRINTABLE = /[\x00-\x08\x0B\x0C\x0E-\x1F\x7F-\x84\x86-\x9F\uFFFE\uFFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF]/;
978var PATTERN_NON_ASCII_LINE_BREAKS = /[\x85\u2028\u2029]/;
979var PATTERN_FLOW_INDICATORS = /[,\[\]\{\}]/;
980var PATTERN_TAG_HANDLE = /^(?:!|!!|![a-z\-]+!)$/i;
981var PATTERN_TAG_URI = /^(?:!|[^,\[\]\{\}])(?:%[0-9a-f]{2}|[0-9a-z\-#;\/\?:@&=\+\$,_\.!~\*'\(\)\[\]])*$/i;
982
983
984function is_EOL(c) {
985 return (c === 0x0A/* LF */) || (c === 0x0D/* CR */);
986}
987
988function is_WHITE_SPACE(c) {
989 return (c === 0x09/* Tab */) || (c === 0x20/* Space */);
990}
991
992function is_WS_OR_EOL(c) {
993 return (c === 0x09/* Tab */) ||
994 (c === 0x20/* Space */) ||
995 (c === 0x0A/* LF */) ||
996 (c === 0x0D/* CR */);
997}
998
999function is_FLOW_INDICATOR(c) {
1000 return c === 0x2C/* , */ ||
1001 c === 0x5B/* [ */ ||
1002 c === 0x5D/* ] */ ||
1003 c === 0x7B/* { */ ||
1004 c === 0x7D/* } */;
1005}
1006
1007function fromHexCode(c) {
1008 var lc;
1009
1010 if ((0x30/* 0 */ <= c) && (c <= 0x39/* 9 */)) {
1011 return c - 0x30;
1012 }
1013
1014 /*eslint-disable no-bitwise*/
1015 lc = c | 0x20;
1016
1017 if ((0x61/* a */ <= lc) && (lc <= 0x66/* f */)) {
1018 return lc - 0x61 + 10;
1019 }
1020
1021 return -1;
1022}
1023
1024function escapedHexLen(c) {
1025 if (c === 0x78/* x */) { return 2; }
1026 if (c === 0x75/* u */) { return 4; }
1027 if (c === 0x55/* U */) { return 8; }
1028 return 0;
1029}
1030
1031function fromDecimalCode(c) {
1032 if ((0x30/* 0 */ <= c) && (c <= 0x39/* 9 */)) {
1033 return c - 0x30;
1034 }
1035
1036 return -1;
1037}
1038
1039function simpleEscapeSequence(c) {
1040 return (c === 0x30/* 0 */) ? '\x00' :
1041 (c === 0x61/* a */) ? '\x07' :
1042 (c === 0x62/* b */) ? '\x08' :
1043 (c === 0x74/* t */) ? '\x09' :
1044 (c === 0x09/* Tab */) ? '\x09' :
1045 (c === 0x6E/* n */) ? '\x0A' :
1046 (c === 0x76/* v */) ? '\x0B' :
1047 (c === 0x66/* f */) ? '\x0C' :
1048 (c === 0x72/* r */) ? '\x0D' :
1049 (c === 0x65/* e */) ? '\x1B' :
1050 (c === 0x20/* Space */) ? ' ' :
1051 (c === 0x22/* " */) ? '\x22' :
1052 (c === 0x2F/* / */) ? '/' :
1053 (c === 0x5C/* \ */) ? '\x5C' :
1054 (c === 0x4E/* N */) ? '\x85' :
1055 (c === 0x5F/* _ */) ? '\xA0' :
1056 (c === 0x4C/* L */) ? '\u2028' :
1057 (c === 0x50/* P */) ? '\u2029' : '';
1058}
1059
1060function charFromCodepoint(c) {
1061 if (c <= 0xFFFF) {
1062 return String.fromCharCode(c);
1063 }
1064 // Encode UTF-16 surrogate pair
1065 // https://en.wikipedia.org/wiki/UTF-16#Code_points_U.2B010000_to_U.2B10FFFF
1066 return String.fromCharCode(((c - 0x010000) >> 10) + 0xD800,
1067 ((c - 0x010000) & 0x03FF) + 0xDC00);
1068}
1069
1070var simpleEscapeCheck = new Array(256); // integer, for fast access
1071var simpleEscapeMap = new Array(256);
1072for (var i = 0; i < 256; i++) {
1073 simpleEscapeCheck[i] = simpleEscapeSequence(i) ? 1 : 0;
1074 simpleEscapeMap[i] = simpleEscapeSequence(i);
1075}
1076
1077
1078function State(input, options) {
1079 this.input = input;
1080
1081 this.filename = options['filename'] || null;
1082 this.schema = options['schema'] || DEFAULT_FULL_SCHEMA;
1083 this.onWarning = options['onWarning'] || null;
1084 this.legacy = options['legacy'] || false;
1085 this.json = options['json'] || false;
1086 this.listener = options['listener'] || null;
1087
1088 this.implicitTypes = this.schema.compiledImplicit;
1089 this.typeMap = this.schema.compiledTypeMap;
1090
1091 this.length = input.length;
1092 this.position = 0;
1093 this.line = 0;
1094 this.lineStart = 0;
1095 this.lineIndent = 0;
1096
1097 this.documents = [];
1098
1099 /*
1100 this.version;
1101 this.checkLineBreaks;
1102 this.tagMap;
1103 this.anchorMap;
1104 this.tag;
1105 this.anchor;
1106 this.kind;
1107 this.result;*/
1108
1109}
1110
1111
1112function generateError(state, message) {
1113 return new YAMLException(
1114 message,
1115 new Mark(state.filename, state.input, state.position, state.line, (state.position - state.lineStart)));
1116}
1117
1118function throwError(state, message) {
1119 throw generateError(state, message);
1120}
1121
1122function throwWarning(state, message) {
1123 if (state.onWarning) {
1124 state.onWarning.call(null, generateError(state, message));
1125 }
1126}
1127
1128
1129var directiveHandlers = {
1130
1131 YAML: function handleYamlDirective(state, name, args) {
1132
1133 var match, major, minor;
1134
1135 if (state.version !== null) {
1136 throwError(state, 'duplication of %YAML directive');
1137 }
1138
1139 if (args.length !== 1) {
1140 throwError(state, 'YAML directive accepts exactly one argument');
1141 }
1142
1143 match = /^([0-9]+)\.([0-9]+)$/.exec(args[0]);
1144
1145 if (match === null) {
1146 throwError(state, 'ill-formed argument of the YAML directive');
1147 }
1148
1149 major = parseInt(match[1], 10);
1150 minor = parseInt(match[2], 10);
1151
1152 if (major !== 1) {
1153 throwError(state, 'unacceptable YAML version of the document');
1154 }
1155
1156 state.version = args[0];
1157 state.checkLineBreaks = (minor < 2);
1158
1159 if (minor !== 1 && minor !== 2) {
1160 throwWarning(state, 'unsupported YAML version of the document');
1161 }
1162 },
1163
1164 TAG: function handleTagDirective(state, name, args) {
1165
1166 var handle, prefix;
1167
1168 if (args.length !== 2) {
1169 throwError(state, 'TAG directive accepts exactly two arguments');
1170 }
1171
1172 handle = args[0];
1173 prefix = args[1];
1174
1175 if (!PATTERN_TAG_HANDLE.test(handle)) {
1176 throwError(state, 'ill-formed tag handle (first argument) of the TAG directive');
1177 }
1178
1179 if (_hasOwnProperty.call(state.tagMap, handle)) {
1180 throwError(state, 'there is a previously declared suffix for "' + handle + '" tag handle');
1181 }
1182
1183 if (!PATTERN_TAG_URI.test(prefix)) {
1184 throwError(state, 'ill-formed tag prefix (second argument) of the TAG directive');
1185 }
1186
1187 state.tagMap[handle] = prefix;
1188 }
1189};
1190
1191
1192function captureSegment(state, start, end, checkJson) {
1193 var _position, _length, _character, _result;
1194
1195 if (start < end) {
1196 _result = state.input.slice(start, end);
1197
1198 if (checkJson) {
1199 for (_position = 0, _length = _result.length;
1200 _position < _length;
1201 _position += 1) {
1202 _character = _result.charCodeAt(_position);
1203 if (!(_character === 0x09 ||
1204 (0x20 <= _character && _character <= 0x10FFFF))) {
1205 throwError(state, 'expected valid JSON character');
1206 }
1207 }
1208 } else if (PATTERN_NON_PRINTABLE.test(_result)) {
1209 throwError(state, 'the stream contains non-printable characters');
1210 }
1211
1212 state.result += _result;
1213 }
1214}
1215
1216function mergeMappings(state, destination, source, overridableKeys) {
1217 var sourceKeys, key, index, quantity;
1218
1219 if (!common.isObject(source)) {
1220 throwError(state, 'cannot merge mappings; the provided source object is unacceptable');
1221 }
1222
1223 sourceKeys = Object.keys(source);
1224
1225 for (index = 0, quantity = sourceKeys.length; index < quantity; index += 1) {
1226 key = sourceKeys[index];
1227
1228 if (!_hasOwnProperty.call(destination, key)) {
1229 destination[key] = source[key];
1230 overridableKeys[key] = true;
1231 }
1232 }
1233}
1234
1235function storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, valueNode, startLine, startPos) {
1236 var index, quantity;
1237
1238 keyNode = String(keyNode);
1239
1240 if (_result === null) {
1241 _result = {};
1242 }
1243
1244 if (keyTag === 'tag:yaml.org,2002:merge') {
1245 if (Array.isArray(valueNode)) {
1246 for (index = 0, quantity = valueNode.length; index < quantity; index += 1) {
1247 mergeMappings(state, _result, valueNode[index], overridableKeys);
1248 }
1249 } else {
1250 mergeMappings(state, _result, valueNode, overridableKeys);
1251 }
1252 } else {
1253 if (!state.json &&
1254 !_hasOwnProperty.call(overridableKeys, keyNode) &&
1255 _hasOwnProperty.call(_result, keyNode)) {
1256 state.line = startLine || state.line;
1257 state.position = startPos || state.position;
1258 throwError(state, 'duplicated mapping key');
1259 }
1260 _result[keyNode] = valueNode;
1261 delete overridableKeys[keyNode];
1262 }
1263
1264 return _result;
1265}
1266
1267function readLineBreak(state) {
1268 var ch;
1269
1270 ch = state.input.charCodeAt(state.position);
1271
1272 if (ch === 0x0A/* LF */) {
1273 state.position++;
1274 } else if (ch === 0x0D/* CR */) {
1275 state.position++;
1276 if (state.input.charCodeAt(state.position) === 0x0A/* LF */) {
1277 state.position++;
1278 }
1279 } else {
1280 throwError(state, 'a line break is expected');
1281 }
1282
1283 state.line += 1;
1284 state.lineStart = state.position;
1285}
1286
1287function skipSeparationSpace(state, allowComments, checkIndent) {
1288 var lineBreaks = 0,
1289 ch = state.input.charCodeAt(state.position);
1290
1291 while (ch !== 0) {
1292 while (is_WHITE_SPACE(ch)) {
1293 ch = state.input.charCodeAt(++state.position);
1294 }
1295
1296 if (allowComments && ch === 0x23/* # */) {
1297 do {
1298 ch = state.input.charCodeAt(++state.position);
1299 } while (ch !== 0x0A/* LF */ && ch !== 0x0D/* CR */ && ch !== 0);
1300 }
1301
1302 if (is_EOL(ch)) {
1303 readLineBreak(state);
1304
1305 ch = state.input.charCodeAt(state.position);
1306 lineBreaks++;
1307 state.lineIndent = 0;
1308
1309 while (ch === 0x20/* Space */) {
1310 state.lineIndent++;
1311 ch = state.input.charCodeAt(++state.position);
1312 }
1313 } else {
1314 break;
1315 }
1316 }
1317
1318 if (checkIndent !== -1 && lineBreaks !== 0 && state.lineIndent < checkIndent) {
1319 throwWarning(state, 'deficient indentation');
1320 }
1321
1322 return lineBreaks;
1323}
1324
1325function testDocumentSeparator(state) {
1326 var _position = state.position,
1327 ch;
1328
1329 ch = state.input.charCodeAt(_position);
1330
1331 // Condition state.position === state.lineStart is tested
1332 // in parent on each call, for efficiency. No needs to test here again.
1333 if ((ch === 0x2D/* - */ || ch === 0x2E/* . */) &&
1334 ch === state.input.charCodeAt(_position + 1) &&
1335 ch === state.input.charCodeAt(_position + 2)) {
1336
1337 _position += 3;
1338
1339 ch = state.input.charCodeAt(_position);
1340
1341 if (ch === 0 || is_WS_OR_EOL(ch)) {
1342 return true;
1343 }
1344 }
1345
1346 return false;
1347}
1348
1349function writeFoldedLines(state, count) {
1350 if (count === 1) {
1351 state.result += ' ';
1352 } else if (count > 1) {
1353 state.result += common.repeat('\n', count - 1);
1354 }
1355}
1356
1357
1358function readPlainScalar(state, nodeIndent, withinFlowCollection) {
1359 var preceding,
1360 following,
1361 captureStart,
1362 captureEnd,
1363 hasPendingContent,
1364 _line,
1365 _lineStart,
1366 _lineIndent,
1367 _kind = state.kind,
1368 _result = state.result,
1369 ch;
1370
1371 ch = state.input.charCodeAt(state.position);
1372
1373 if (is_WS_OR_EOL(ch) ||
1374 is_FLOW_INDICATOR(ch) ||
1375 ch === 0x23/* # */ ||
1376 ch === 0x26/* & */ ||
1377 ch === 0x2A/* * */ ||
1378 ch === 0x21/* ! */ ||
1379 ch === 0x7C/* | */ ||
1380 ch === 0x3E/* > */ ||
1381 ch === 0x27/* ' */ ||
1382 ch === 0x22/* " */ ||
1383 ch === 0x25/* % */ ||
1384 ch === 0x40/* @ */ ||
1385 ch === 0x60/* ` */) {
1386 return false;
1387 }
1388
1389 if (ch === 0x3F/* ? */ || ch === 0x2D/* - */) {
1390 following = state.input.charCodeAt(state.position + 1);
1391
1392 if (is_WS_OR_EOL(following) ||
1393 withinFlowCollection && is_FLOW_INDICATOR(following)) {
1394 return false;
1395 }
1396 }
1397
1398 state.kind = 'scalar';
1399 state.result = '';
1400 captureStart = captureEnd = state.position;
1401 hasPendingContent = false;
1402
1403 while (ch !== 0) {
1404 if (ch === 0x3A/* : */) {
1405 following = state.input.charCodeAt(state.position + 1);
1406
1407 if (is_WS_OR_EOL(following) ||
1408 withinFlowCollection && is_FLOW_INDICATOR(following)) {
1409 break;
1410 }
1411
1412 } else if (ch === 0x23/* # */) {
1413 preceding = state.input.charCodeAt(state.position - 1);
1414
1415 if (is_WS_OR_EOL(preceding)) {
1416 break;
1417 }
1418
1419 } else if ((state.position === state.lineStart && testDocumentSeparator(state)) ||
1420 withinFlowCollection && is_FLOW_INDICATOR(ch)) {
1421 break;
1422
1423 } else if (is_EOL(ch)) {
1424 _line = state.line;
1425 _lineStart = state.lineStart;
1426 _lineIndent = state.lineIndent;
1427 skipSeparationSpace(state, false, -1);
1428
1429 if (state.lineIndent >= nodeIndent) {
1430 hasPendingContent = true;
1431 ch = state.input.charCodeAt(state.position);
1432 continue;
1433 } else {
1434 state.position = captureEnd;
1435 state.line = _line;
1436 state.lineStart = _lineStart;
1437 state.lineIndent = _lineIndent;
1438 break;
1439 }
1440 }
1441
1442 if (hasPendingContent) {
1443 captureSegment(state, captureStart, captureEnd, false);
1444 writeFoldedLines(state, state.line - _line);
1445 captureStart = captureEnd = state.position;
1446 hasPendingContent = false;
1447 }
1448
1449 if (!is_WHITE_SPACE(ch)) {
1450 captureEnd = state.position + 1;
1451 }
1452
1453 ch = state.input.charCodeAt(++state.position);
1454 }
1455
1456 captureSegment(state, captureStart, captureEnd, false);
1457
1458 if (state.result) {
1459 return true;
1460 }
1461
1462 state.kind = _kind;
1463 state.result = _result;
1464 return false;
1465}
1466
1467function readSingleQuotedScalar(state, nodeIndent) {
1468 var ch,
1469 captureStart, captureEnd;
1470
1471 ch = state.input.charCodeAt(state.position);
1472
1473 if (ch !== 0x27/* ' */) {
1474 return false;
1475 }
1476
1477 state.kind = 'scalar';
1478 state.result = '';
1479 state.position++;
1480 captureStart = captureEnd = state.position;
1481
1482 while ((ch = state.input.charCodeAt(state.position)) !== 0) {
1483 if (ch === 0x27/* ' */) {
1484 captureSegment(state, captureStart, state.position, true);
1485 ch = state.input.charCodeAt(++state.position);
1486
1487 if (ch === 0x27/* ' */) {
1488 captureStart = state.position;
1489 state.position++;
1490 captureEnd = state.position;
1491 } else {
1492 return true;
1493 }
1494
1495 } else if (is_EOL(ch)) {
1496 captureSegment(state, captureStart, captureEnd, true);
1497 writeFoldedLines(state, skipSeparationSpace(state, false, nodeIndent));
1498 captureStart = captureEnd = state.position;
1499
1500 } else if (state.position === state.lineStart && testDocumentSeparator(state)) {
1501 throwError(state, 'unexpected end of the document within a single quoted scalar');
1502
1503 } else {
1504 state.position++;
1505 captureEnd = state.position;
1506 }
1507 }
1508
1509 throwError(state, 'unexpected end of the stream within a single quoted scalar');
1510}
1511
1512function readDoubleQuotedScalar(state, nodeIndent) {
1513 var captureStart,
1514 captureEnd,
1515 hexLength,
1516 hexResult,
1517 tmp,
1518 ch;
1519
1520 ch = state.input.charCodeAt(state.position);
1521
1522 if (ch !== 0x22/* " */) {
1523 return false;
1524 }
1525
1526 state.kind = 'scalar';
1527 state.result = '';
1528 state.position++;
1529 captureStart = captureEnd = state.position;
1530
1531 while ((ch = state.input.charCodeAt(state.position)) !== 0) {
1532 if (ch === 0x22/* " */) {
1533 captureSegment(state, captureStart, state.position, true);
1534 state.position++;
1535 return true;
1536
1537 } else if (ch === 0x5C/* \ */) {
1538 captureSegment(state, captureStart, state.position, true);
1539 ch = state.input.charCodeAt(++state.position);
1540
1541 if (is_EOL(ch)) {
1542 skipSeparationSpace(state, false, nodeIndent);
1543
1544 // TODO: rework to inline fn with no type cast?
1545 } else if (ch < 256 && simpleEscapeCheck[ch]) {
1546 state.result += simpleEscapeMap[ch];
1547 state.position++;
1548
1549 } else if ((tmp = escapedHexLen(ch)) > 0) {
1550 hexLength = tmp;
1551 hexResult = 0;
1552
1553 for (; hexLength > 0; hexLength--) {
1554 ch = state.input.charCodeAt(++state.position);
1555
1556 if ((tmp = fromHexCode(ch)) >= 0) {
1557 hexResult = (hexResult << 4) + tmp;
1558
1559 } else {
1560 throwError(state, 'expected hexadecimal character');
1561 }
1562 }
1563
1564 state.result += charFromCodepoint(hexResult);
1565
1566 state.position++;
1567
1568 } else {
1569 throwError(state, 'unknown escape sequence');
1570 }
1571
1572 captureStart = captureEnd = state.position;
1573
1574 } else if (is_EOL(ch)) {
1575 captureSegment(state, captureStart, captureEnd, true);
1576 writeFoldedLines(state, skipSeparationSpace(state, false, nodeIndent));
1577 captureStart = captureEnd = state.position;
1578
1579 } else if (state.position === state.lineStart && testDocumentSeparator(state)) {
1580 throwError(state, 'unexpected end of the document within a double quoted scalar');
1581
1582 } else {
1583 state.position++;
1584 captureEnd = state.position;
1585 }
1586 }
1587
1588 throwError(state, 'unexpected end of the stream within a double quoted scalar');
1589}
1590
1591function readFlowCollection(state, nodeIndent) {
1592 var readNext = true,
1593 _line,
1594 _tag = state.tag,
1595 _result,
1596 _anchor = state.anchor,
1597 following,
1598 terminator,
1599 isPair,
1600 isExplicitPair,
1601 isMapping,
1602 overridableKeys = {},
1603 keyNode,
1604 keyTag,
1605 valueNode,
1606 ch;
1607
1608 ch = state.input.charCodeAt(state.position);
1609
1610 if (ch === 0x5B/* [ */) {
1611 terminator = 0x5D;/* ] */
1612 isMapping = false;
1613 _result = [];
1614 } else if (ch === 0x7B/* { */) {
1615 terminator = 0x7D;/* } */
1616 isMapping = true;
1617 _result = {};
1618 } else {
1619 return false;
1620 }
1621
1622 if (state.anchor !== null) {
1623 state.anchorMap[state.anchor] = _result;
1624 }
1625
1626 ch = state.input.charCodeAt(++state.position);
1627
1628 while (ch !== 0) {
1629 skipSeparationSpace(state, true, nodeIndent);
1630
1631 ch = state.input.charCodeAt(state.position);
1632
1633 if (ch === terminator) {
1634 state.position++;
1635 state.tag = _tag;
1636 state.anchor = _anchor;
1637 state.kind = isMapping ? 'mapping' : 'sequence';
1638 state.result = _result;
1639 return true;
1640 } else if (!readNext) {
1641 throwError(state, 'missed comma between flow collection entries');
1642 }
1643
1644 keyTag = keyNode = valueNode = null;
1645 isPair = isExplicitPair = false;
1646
1647 if (ch === 0x3F/* ? */) {
1648 following = state.input.charCodeAt(state.position + 1);
1649
1650 if (is_WS_OR_EOL(following)) {
1651 isPair = isExplicitPair = true;
1652 state.position++;
1653 skipSeparationSpace(state, true, nodeIndent);
1654 }
1655 }
1656
1657 _line = state.line;
1658 composeNode(state, nodeIndent, CONTEXT_FLOW_IN, false, true);
1659 keyTag = state.tag;
1660 keyNode = state.result;
1661 skipSeparationSpace(state, true, nodeIndent);
1662
1663 ch = state.input.charCodeAt(state.position);
1664
1665 if ((isExplicitPair || state.line === _line) && ch === 0x3A/* : */) {
1666 isPair = true;
1667 ch = state.input.charCodeAt(++state.position);
1668 skipSeparationSpace(state, true, nodeIndent);
1669 composeNode(state, nodeIndent, CONTEXT_FLOW_IN, false, true);
1670 valueNode = state.result;
1671 }
1672
1673 if (isMapping) {
1674 storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, valueNode);
1675 } else if (isPair) {
1676 _result.push(storeMappingPair(state, null, overridableKeys, keyTag, keyNode, valueNode));
1677 } else {
1678 _result.push(keyNode);
1679 }
1680
1681 skipSeparationSpace(state, true, nodeIndent);
1682
1683 ch = state.input.charCodeAt(state.position);
1684
1685 if (ch === 0x2C/* , */) {
1686 readNext = true;
1687 ch = state.input.charCodeAt(++state.position);
1688 } else {
1689 readNext = false;
1690 }
1691 }
1692
1693 throwError(state, 'unexpected end of the stream within a flow collection');
1694}
1695
1696function readBlockScalar(state, nodeIndent) {
1697 var captureStart,
1698 folding,
1699 chomping = CHOMPING_CLIP,
1700 didReadContent = false,
1701 detectedIndent = false,
1702 textIndent = nodeIndent,
1703 emptyLines = 0,
1704 atMoreIndented = false,
1705 tmp,
1706 ch;
1707
1708 ch = state.input.charCodeAt(state.position);
1709
1710 if (ch === 0x7C/* | */) {
1711 folding = false;
1712 } else if (ch === 0x3E/* > */) {
1713 folding = true;
1714 } else {
1715 return false;
1716 }
1717
1718 state.kind = 'scalar';
1719 state.result = '';
1720
1721 while (ch !== 0) {
1722 ch = state.input.charCodeAt(++state.position);
1723
1724 if (ch === 0x2B/* + */ || ch === 0x2D/* - */) {
1725 if (CHOMPING_CLIP === chomping) {
1726 chomping = (ch === 0x2B/* + */) ? CHOMPING_KEEP : CHOMPING_STRIP;
1727 } else {
1728 throwError(state, 'repeat of a chomping mode identifier');
1729 }
1730
1731 } else if ((tmp = fromDecimalCode(ch)) >= 0) {
1732 if (tmp === 0) {
1733 throwError(state, 'bad explicit indentation width of a block scalar; it cannot be less than one');
1734 } else if (!detectedIndent) {
1735 textIndent = nodeIndent + tmp - 1;
1736 detectedIndent = true;
1737 } else {
1738 throwError(state, 'repeat of an indentation width identifier');
1739 }
1740
1741 } else {
1742 break;
1743 }
1744 }
1745
1746 if (is_WHITE_SPACE(ch)) {
1747 do { ch = state.input.charCodeAt(++state.position); }
1748 while (is_WHITE_SPACE(ch));
1749
1750 if (ch === 0x23/* # */) {
1751 do { ch = state.input.charCodeAt(++state.position); }
1752 while (!is_EOL(ch) && (ch !== 0));
1753 }
1754 }
1755
1756 while (ch !== 0) {
1757 readLineBreak(state);
1758 state.lineIndent = 0;
1759
1760 ch = state.input.charCodeAt(state.position);
1761
1762 while ((!detectedIndent || state.lineIndent < textIndent) &&
1763 (ch === 0x20/* Space */)) {
1764 state.lineIndent++;
1765 ch = state.input.charCodeAt(++state.position);
1766 }
1767
1768 if (!detectedIndent && state.lineIndent > textIndent) {
1769 textIndent = state.lineIndent;
1770 }
1771
1772 if (is_EOL(ch)) {
1773 emptyLines++;
1774 continue;
1775 }
1776
1777 // End of the scalar.
1778 if (state.lineIndent < textIndent) {
1779
1780 // Perform the chomping.
1781 if (chomping === CHOMPING_KEEP) {
1782 state.result += common.repeat('\n', didReadContent ? 1 + emptyLines : emptyLines);
1783 } else if (chomping === CHOMPING_CLIP) {
1784 if (didReadContent) { // i.e. only if the scalar is not empty.
1785 state.result += '\n';
1786 }
1787 }
1788
1789 // Break this `while` cycle and go to the funciton's epilogue.
1790 break;
1791 }
1792
1793 // Folded style: use fancy rules to handle line breaks.
1794 if (folding) {
1795
1796 // Lines starting with white space characters (more-indented lines) are not folded.
1797 if (is_WHITE_SPACE(ch)) {
1798 atMoreIndented = true;
1799 // except for the first content line (cf. Example 8.1)
1800 state.result += common.repeat('\n', didReadContent ? 1 + emptyLines : emptyLines);
1801
1802 // End of more-indented block.
1803 } else if (atMoreIndented) {
1804 atMoreIndented = false;
1805 state.result += common.repeat('\n', emptyLines + 1);
1806
1807 // Just one line break - perceive as the same line.
1808 } else if (emptyLines === 0) {
1809 if (didReadContent) { // i.e. only if we have already read some scalar content.
1810 state.result += ' ';
1811 }
1812
1813 // Several line breaks - perceive as different lines.
1814 } else {
1815 state.result += common.repeat('\n', emptyLines);
1816 }
1817
1818 // Literal style: just add exact number of line breaks between content lines.
1819 } else {
1820 // Keep all line breaks except the header line break.
1821 state.result += common.repeat('\n', didReadContent ? 1 + emptyLines : emptyLines);
1822 }
1823
1824 didReadContent = true;
1825 detectedIndent = true;
1826 emptyLines = 0;
1827 captureStart = state.position;
1828
1829 while (!is_EOL(ch) && (ch !== 0)) {
1830 ch = state.input.charCodeAt(++state.position);
1831 }
1832
1833 captureSegment(state, captureStart, state.position, false);
1834 }
1835
1836 return true;
1837}
1838
1839function readBlockSequence(state, nodeIndent) {
1840 var _line,
1841 _tag = state.tag,
1842 _anchor = state.anchor,
1843 _result = [],
1844 following,
1845 detected = false,
1846 ch;
1847
1848 if (state.anchor !== null) {
1849 state.anchorMap[state.anchor] = _result;
1850 }
1851
1852 ch = state.input.charCodeAt(state.position);
1853
1854 while (ch !== 0) {
1855
1856 if (ch !== 0x2D/* - */) {
1857 break;
1858 }
1859
1860 following = state.input.charCodeAt(state.position + 1);
1861
1862 if (!is_WS_OR_EOL(following)) {
1863 break;
1864 }
1865
1866 detected = true;
1867 state.position++;
1868
1869 if (skipSeparationSpace(state, true, -1)) {
1870 if (state.lineIndent <= nodeIndent) {
1871 _result.push(null);
1872 ch = state.input.charCodeAt(state.position);
1873 continue;
1874 }
1875 }
1876
1877 _line = state.line;
1878 composeNode(state, nodeIndent, CONTEXT_BLOCK_IN, false, true);
1879 _result.push(state.result);
1880 skipSeparationSpace(state, true, -1);
1881
1882 ch = state.input.charCodeAt(state.position);
1883
1884 if ((state.line === _line || state.lineIndent > nodeIndent) && (ch !== 0)) {
1885 throwError(state, 'bad indentation of a sequence entry');
1886 } else if (state.lineIndent < nodeIndent) {
1887 break;
1888 }
1889 }
1890
1891 if (detected) {
1892 state.tag = _tag;
1893 state.anchor = _anchor;
1894 state.kind = 'sequence';
1895 state.result = _result;
1896 return true;
1897 }
1898 return false;
1899}
1900
1901function readBlockMapping(state, nodeIndent, flowIndent) {
1902 var following,
1903 allowCompact,
1904 _line,
1905 _pos,
1906 _tag = state.tag,
1907 _anchor = state.anchor,
1908 _result = {},
1909 overridableKeys = {},
1910 keyTag = null,
1911 keyNode = null,
1912 valueNode = null,
1913 atExplicitKey = false,
1914 detected = false,
1915 ch;
1916
1917 if (state.anchor !== null) {
1918 state.anchorMap[state.anchor] = _result;
1919 }
1920
1921 ch = state.input.charCodeAt(state.position);
1922
1923 while (ch !== 0) {
1924 following = state.input.charCodeAt(state.position + 1);
1925 _line = state.line; // Save the current line.
1926 _pos = state.position;
1927
1928 //
1929 // Explicit notation case. There are two separate blocks:
1930 // first for the key (denoted by "?") and second for the value (denoted by ":")
1931 //
1932 if ((ch === 0x3F/* ? */ || ch === 0x3A/* : */) && is_WS_OR_EOL(following)) {
1933
1934 if (ch === 0x3F/* ? */) {
1935 if (atExplicitKey) {
1936 storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, null);
1937 keyTag = keyNode = valueNode = null;
1938 }
1939
1940 detected = true;
1941 atExplicitKey = true;
1942 allowCompact = true;
1943
1944 } else if (atExplicitKey) {
1945 // i.e. 0x3A/* : */ === character after the explicit key.
1946 atExplicitKey = false;
1947 allowCompact = true;
1948
1949 } else {
1950 throwError(state, 'incomplete explicit mapping pair; a key node is missed');
1951 }
1952
1953 state.position += 1;
1954 ch = following;
1955
1956 //
1957 // Implicit notation case. Flow-style node as the key first, then ":", and the value.
1958 //
1959 } else if (composeNode(state, flowIndent, CONTEXT_FLOW_OUT, false, true)) {
1960
1961 if (state.line === _line) {
1962 ch = state.input.charCodeAt(state.position);
1963
1964 while (is_WHITE_SPACE(ch)) {
1965 ch = state.input.charCodeAt(++state.position);
1966 }
1967
1968 if (ch === 0x3A/* : */) {
1969 ch = state.input.charCodeAt(++state.position);
1970
1971 if (!is_WS_OR_EOL(ch)) {
1972 throwError(state, 'a whitespace character is expected after the key-value separator within a block mapping');
1973 }
1974
1975 if (atExplicitKey) {
1976 storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, null);
1977 keyTag = keyNode = valueNode = null;
1978 }
1979
1980 detected = true;
1981 atExplicitKey = false;
1982 allowCompact = false;
1983 keyTag = state.tag;
1984 keyNode = state.result;
1985
1986 } else if (detected) {
1987 throwError(state, 'can not read an implicit mapping pair; a colon is missed');
1988
1989 } else {
1990 state.tag = _tag;
1991 state.anchor = _anchor;
1992 return true; // Keep the result of `composeNode`.
1993 }
1994
1995 } else if (detected) {
1996 throwError(state, 'can not read a block mapping entry; a multiline key may not be an implicit key');
1997
1998 } else {
1999 state.tag = _tag;
2000 state.anchor = _anchor;
2001 return true; // Keep the result of `composeNode`.
2002 }
2003
2004 } else {
2005 break; // Reading is done. Go to the epilogue.
2006 }
2007
2008 //
2009 // Common reading code for both explicit and implicit notations.
2010 //
2011 if (state.line === _line || state.lineIndent > nodeIndent) {
2012 if (composeNode(state, nodeIndent, CONTEXT_BLOCK_OUT, true, allowCompact)) {
2013 if (atExplicitKey) {
2014 keyNode = state.result;
2015 } else {
2016 valueNode = state.result;
2017 }
2018 }
2019
2020 if (!atExplicitKey) {
2021 storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, valueNode, _line, _pos);
2022 keyTag = keyNode = valueNode = null;
2023 }
2024
2025 skipSeparationSpace(state, true, -1);
2026 ch = state.input.charCodeAt(state.position);
2027 }
2028
2029 if (state.lineIndent > nodeIndent && (ch !== 0)) {
2030 throwError(state, 'bad indentation of a mapping entry');
2031 } else if (state.lineIndent < nodeIndent) {
2032 break;
2033 }
2034 }
2035
2036 //
2037 // Epilogue.
2038 //
2039
2040 // Special case: last mapping's node contains only the key in explicit notation.
2041 if (atExplicitKey) {
2042 storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, null);
2043 }
2044
2045 // Expose the resulting mapping.
2046 if (detected) {
2047 state.tag = _tag;
2048 state.anchor = _anchor;
2049 state.kind = 'mapping';
2050 state.result = _result;
2051 }
2052
2053 return detected;
2054}
2055
2056function readTagProperty(state) {
2057 var _position,
2058 isVerbatim = false,
2059 isNamed = false,
2060 tagHandle,
2061 tagName,
2062 ch;
2063
2064 ch = state.input.charCodeAt(state.position);
2065
2066 if (ch !== 0x21/* ! */) return false;
2067
2068 if (state.tag !== null) {
2069 throwError(state, 'duplication of a tag property');
2070 }
2071
2072 ch = state.input.charCodeAt(++state.position);
2073
2074 if (ch === 0x3C/* < */) {
2075 isVerbatim = true;
2076 ch = state.input.charCodeAt(++state.position);
2077
2078 } else if (ch === 0x21/* ! */) {
2079 isNamed = true;
2080 tagHandle = '!!';
2081 ch = state.input.charCodeAt(++state.position);
2082
2083 } else {
2084 tagHandle = '!';
2085 }
2086
2087 _position = state.position;
2088
2089 if (isVerbatim) {
2090 do { ch = state.input.charCodeAt(++state.position); }
2091 while (ch !== 0 && ch !== 0x3E/* > */);
2092
2093 if (state.position < state.length) {
2094 tagName = state.input.slice(_position, state.position);
2095 ch = state.input.charCodeAt(++state.position);
2096 } else {
2097 throwError(state, 'unexpected end of the stream within a verbatim tag');
2098 }
2099 } else {
2100 while (ch !== 0 && !is_WS_OR_EOL(ch)) {
2101
2102 if (ch === 0x21/* ! */) {
2103 if (!isNamed) {
2104 tagHandle = state.input.slice(_position - 1, state.position + 1);
2105
2106 if (!PATTERN_TAG_HANDLE.test(tagHandle)) {
2107 throwError(state, 'named tag handle cannot contain such characters');
2108 }
2109
2110 isNamed = true;
2111 _position = state.position + 1;
2112 } else {
2113 throwError(state, 'tag suffix cannot contain exclamation marks');
2114 }
2115 }
2116
2117 ch = state.input.charCodeAt(++state.position);
2118 }
2119
2120 tagName = state.input.slice(_position, state.position);
2121
2122 if (PATTERN_FLOW_INDICATORS.test(tagName)) {
2123 throwError(state, 'tag suffix cannot contain flow indicator characters');
2124 }
2125 }
2126
2127 if (tagName && !PATTERN_TAG_URI.test(tagName)) {
2128 throwError(state, 'tag name cannot contain such characters: ' + tagName);
2129 }
2130
2131 if (isVerbatim) {
2132 state.tag = tagName;
2133
2134 } else if (_hasOwnProperty.call(state.tagMap, tagHandle)) {
2135 state.tag = state.tagMap[tagHandle] + tagName;
2136
2137 } else if (tagHandle === '!') {
2138 state.tag = '!' + tagName;
2139
2140 } else if (tagHandle === '!!') {
2141 state.tag = 'tag:yaml.org,2002:' + tagName;
2142
2143 } else {
2144 throwError(state, 'undeclared tag handle "' + tagHandle + '"');
2145 }
2146
2147 return true;
2148}
2149
2150function readAnchorProperty(state) {
2151 var _position,
2152 ch;
2153
2154 ch = state.input.charCodeAt(state.position);
2155
2156 if (ch !== 0x26/* & */) return false;
2157
2158 if (state.anchor !== null) {
2159 throwError(state, 'duplication of an anchor property');
2160 }
2161
2162 ch = state.input.charCodeAt(++state.position);
2163 _position = state.position;
2164
2165 while (ch !== 0 && !is_WS_OR_EOL(ch) && !is_FLOW_INDICATOR(ch)) {
2166 ch = state.input.charCodeAt(++state.position);
2167 }
2168
2169 if (state.position === _position) {
2170 throwError(state, 'name of an anchor node must contain at least one character');
2171 }
2172
2173 state.anchor = state.input.slice(_position, state.position);
2174 return true;
2175}
2176
2177function readAlias(state) {
2178 var _position, alias,
2179 ch;
2180
2181 ch = state.input.charCodeAt(state.position);
2182
2183 if (ch !== 0x2A/* * */) return false;
2184
2185 ch = state.input.charCodeAt(++state.position);
2186 _position = state.position;
2187
2188 while (ch !== 0 && !is_WS_OR_EOL(ch) && !is_FLOW_INDICATOR(ch)) {
2189 ch = state.input.charCodeAt(++state.position);
2190 }
2191
2192 if (state.position === _position) {
2193 throwError(state, 'name of an alias node must contain at least one character');
2194 }
2195
2196 alias = state.input.slice(_position, state.position);
2197
2198 if (!state.anchorMap.hasOwnProperty(alias)) {
2199 throwError(state, 'unidentified alias "' + alias + '"');
2200 }
2201
2202 state.result = state.anchorMap[alias];
2203 skipSeparationSpace(state, true, -1);
2204 return true;
2205}
2206
2207function composeNode(state, parentIndent, nodeContext, allowToSeek, allowCompact) {
2208 var allowBlockStyles,
2209 allowBlockScalars,
2210 allowBlockCollections,
2211 indentStatus = 1, // 1: this>parent, 0: this=parent, -1: this<parent
2212 atNewLine = false,
2213 hasContent = false,
2214 typeIndex,