@breakside/jskit 2022.22.1 → 2022.23.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (63) hide show
  1. package/Frameworks/DOM.jsframework/Info.json +2 -2
  2. package/Frameworks/DOM.jsframework/JS/XMLSerializer.js +9 -4
  3. package/Frameworks/DOM.jsframework/io.breakside.JSKit.DOM-bundle.js +2 -2
  4. package/Frameworks/DOM.jsframework/sources.json +10 -3
  5. package/Frameworks/FontKit.jsframework/Info.json +2 -2
  6. package/Frameworks/FontKit.jsframework/io.breakside.JSKit.FontKit-bundle.js +2 -2
  7. package/Frameworks/FontKit.jsframework/sources.json +34 -2
  8. package/Frameworks/Foundation.jsframework/Info.json +2 -2
  9. package/Frameworks/Foundation.jsframework/JS/JSAttributedString.js +213 -20
  10. package/Frameworks/Foundation.jsframework/JS/JSFont.js +39 -15
  11. package/Frameworks/Foundation.jsframework/JS/JSFontDescriptor+HTML.js +8 -0
  12. package/Frameworks/Foundation.jsframework/JS/JSFontDescriptor.js +105 -27
  13. package/Frameworks/Foundation.jsframework/JS/JSTextAttachment.js +6 -1
  14. package/Frameworks/Foundation.jsframework/JS/JSTextRun.js +3 -0
  15. package/Frameworks/Foundation.jsframework/JS/String+JS.js +34 -0
  16. package/Frameworks/Foundation.jsframework/io.breakside.JSKit.Foundation-bundle.js +2 -2
  17. package/Frameworks/Foundation.jsframework/sources.json +167 -8
  18. package/Frameworks/SecurityKit.jsframework/Info.json +2 -2
  19. package/Frameworks/SecurityKit.jsframework/io.breakside.JSKit.SecurityKit-bundle.js +2 -2
  20. package/Frameworks/SecurityKit.jsframework/sources.json +43 -2
  21. package/Info.json +2 -2
  22. package/Node/Builder.js +20 -9
  23. package/Node/FrameworkBuilder.js +22 -2
  24. package/Node/Project.js +22 -2
  25. package/Node/io.breakside.jskit-bundle.js +2 -2
  26. package/Node/jskit +7 -7
  27. package/Root/Frameworks/APIKit/Info.yaml +1 -1
  28. package/Root/Frameworks/APIKitTesting/Info.yaml +1 -1
  29. package/Root/Frameworks/AuthKit/Info.yaml +1 -1
  30. package/Root/Frameworks/CSSOM/Info.yaml +1 -1
  31. package/Root/Frameworks/ChartKit/Info.yaml +1 -1
  32. package/Root/Frameworks/ConferenceKit/Info.yaml +1 -1
  33. package/Root/Frameworks/DBKit/Info.yaml +1 -1
  34. package/Root/Frameworks/DOM/Info.yaml +1 -1
  35. package/Root/Frameworks/DOM/XMLSerializer.js +9 -4
  36. package/Root/Frameworks/Dispatch/Info.yaml +1 -1
  37. package/Root/Frameworks/FontKit/Info.yaml +1 -1
  38. package/Root/Frameworks/Foundation/Info.yaml +1 -1
  39. package/Root/Frameworks/Foundation/JSAttributedString.js +213 -20
  40. package/Root/Frameworks/Foundation/JSFont.js +39 -15
  41. package/Root/Frameworks/Foundation/JSFontDescriptor+HTML.js +8 -0
  42. package/Root/Frameworks/Foundation/JSFontDescriptor.js +105 -27
  43. package/Root/Frameworks/Foundation/JSTextAttachment.js +6 -1
  44. package/Root/Frameworks/Foundation/JSTextRun.js +3 -0
  45. package/Root/Frameworks/Foundation/String+JS.js +34 -0
  46. package/Root/Frameworks/ImageKit/Info.yaml +1 -1
  47. package/Root/Frameworks/MediaKit/Info.yaml +1 -1
  48. package/Root/Frameworks/MediaKitUI/Info.yaml +1 -1
  49. package/Root/Frameworks/NotificationKit/Info.yaml +1 -1
  50. package/Root/Frameworks/PDFKit/Info.yaml +1 -1
  51. package/Root/Frameworks/QRKit/Info.yaml +1 -1
  52. package/Root/Frameworks/SearchKit/Info.yaml +1 -1
  53. package/Root/Frameworks/SecurityKit/Info.yaml +1 -1
  54. package/Root/Frameworks/ServerKit/Info.yaml +1 -1
  55. package/Root/Frameworks/ServerKitTesting/Info.yaml +1 -1
  56. package/Root/Frameworks/TestKit/Info.yaml +1 -1
  57. package/Root/Frameworks/UIKit/Info.yaml +1 -1
  58. package/Root/Frameworks/UIKit/UIHTMLTextFrame.js +3 -0
  59. package/Root/Frameworks/UIKit/UIHTMLTextRun.js +3 -1
  60. package/Root/Frameworks/UIKit/UIHTMLTextTypesetter.js +14 -0
  61. package/Root/Frameworks/UIKit/UILabel.js +43 -10
  62. package/Root/Frameworks/UIKitTesting/Info.yaml +1 -1
  63. package/package.json +1 -1
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "JSBundleType": "framework",
3
3
  "JSBundleIdentifier": "io.breakside.JSKit.DOM",
4
- "JSBundleVersion": "2022.22.1",
4
+ "JSBundleVersion": "2022.23.0",
5
5
  "JSDevelopmentLanguage": "en",
6
6
  "JSCopyright": "Copyright © 2020 Breakside Inc.",
7
7
  "JSBundleEnvironments": {
@@ -9,5 +9,5 @@
9
9
  "node": "DOM+Node.js"
10
10
  },
11
11
  "JSLicenseNotice": "Licensed under the Breakside Public License, Version 1.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nIf a copy of the License was not distributed with this file, you may\nobtain a copy at\n\n http://breakside.io/licenses/LICENSE-1.0.txt\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n",
12
- "GitRevision": "5fd19ed5f4d9bc2a74be2eef1e45ad5c0de02cc9"
12
+ "GitRevision": "e2a77335b26d1a321448e73eb7b733cdd0714cc8"
13
13
  }
@@ -113,10 +113,15 @@ XMLSerializer.prototype = {
113
113
  str += " " + node.name;
114
114
  }
115
115
  if (node.publicId.length > 0){
116
- str += " " + node.publicId;
117
- }
118
- if (node.systemId.length > 0){
119
- str += " " + node.systemId;
116
+ value = node.publicId.replace(/&/g, "&amp;").replace(/"/g, "&quot;").replace(/</g, "&lt;");
117
+ str += ' PUBLIC "%s"'.sprintf(value);
118
+ if (node.systemId.length > 0){
119
+ value = node.systemId.replace(/&/g, "&amp;").replace(/"/g, "&quot;").replace(/</g, "&lt;");
120
+ str += ' "%s"'.sprintf(value);
121
+ }
122
+ }else if (node.systemId.length > 0){
123
+ value = node.systemId.replace(/&/g, "&amp;").replace(/"/g, "&quot;").replace(/</g, "&lt;");
124
+ str += ' SYSTEM "%s"'.sprintf(value);
120
125
  }
121
126
  str += ">\n";
122
127
  }
@@ -3,7 +3,7 @@ JSBundle.bundles['io.breakside.JSKit.DOM'] = {
3
3
  "Info": {
4
4
  "JSBundleType": "framework",
5
5
  "JSBundleIdentifier": "io.breakside.JSKit.DOM",
6
- "JSBundleVersion": "2022.22.1",
6
+ "JSBundleVersion": "2022.23.0",
7
7
  "JSDevelopmentLanguage": "en",
8
8
  "JSCopyright": "Copyright © 2020 Breakside Inc.",
9
9
  "JSBundleEnvironments": {
@@ -11,7 +11,7 @@ JSBundle.bundles['io.breakside.JSKit.DOM'] = {
11
11
  "node": "DOM+Node.js"
12
12
  },
13
13
  "JSLicenseNotice": "Licensed under the Breakside Public License, Version 1.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nIf a copy of the License was not distributed with this file, you may\nobtain a copy at\n\n http://breakside.io/licenses/LICENSE-1.0.txt\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n",
14
- "GitRevision": "5fd19ed5f4d9bc2a74be2eef1e45ad5c0de02cc9"
14
+ "GitRevision": "e2a77335b26d1a321448e73eb7b733cdd0714cc8"
15
15
  },
16
16
  "Resources": [],
17
17
  "ResourceLookup": {
@@ -4,14 +4,16 @@
4
4
  "files": [
5
5
  "DOM.js"
6
6
  ],
7
- "features": []
7
+ "features": [],
8
+ "globals": []
8
9
  },
9
10
  "html": {
10
11
  "frameworks": [],
11
12
  "files": [
12
13
  "DOM+HTML.js"
13
14
  ],
14
- "features": []
15
+ "features": [],
16
+ "globals": []
15
17
  },
16
18
  "node": {
17
19
  "frameworks": [
@@ -33,6 +35,11 @@
33
35
  "XMLSerializer.js",
34
36
  "DOM+Node.js"
35
37
  ],
36
- "features": []
38
+ "features": [],
39
+ "globals": [
40
+ "DOM",
41
+ "DOMParser",
42
+ "XMLSerializer"
43
+ ]
37
44
  }
38
45
  }
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "JSBundleType": "framework",
3
3
  "JSBundleIdentifier": "io.breakside.JSKit.FontKit",
4
- "JSBundleVersion": "2022.22.1",
4
+ "JSBundleVersion": "2022.23.0",
5
5
  "JSDevelopmentLanguage": "en",
6
6
  "JSCopyright": "Copyright © 2020 Breakside Inc.",
7
7
  "JSBundleEnvironments": {
8
8
  "html": "FontKit+HTML.js"
9
9
  },
10
10
  "JSLicenseNotice": "Licensed under the Breakside Public License, Version 1.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nIf a copy of the License was not distributed with this file, you may\nobtain a copy at\n\n http://breakside.io/licenses/LICENSE-1.0.txt\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n",
11
- "GitRevision": "5fd19ed5f4d9bc2a74be2eef1e45ad5c0de02cc9"
11
+ "GitRevision": "e2a77335b26d1a321448e73eb7b733cdd0714cc8"
12
12
  }
@@ -3,14 +3,14 @@ JSBundle.bundles['io.breakside.JSKit.FontKit'] = {
3
3
  "Info": {
4
4
  "JSBundleType": "framework",
5
5
  "JSBundleIdentifier": "io.breakside.JSKit.FontKit",
6
- "JSBundleVersion": "2022.22.1",
6
+ "JSBundleVersion": "2022.23.0",
7
7
  "JSDevelopmentLanguage": "en",
8
8
  "JSCopyright": "Copyright © 2020 Breakside Inc.",
9
9
  "JSBundleEnvironments": {
10
10
  "html": "FontKit+HTML.js"
11
11
  },
12
12
  "JSLicenseNotice": "Licensed under the Breakside Public License, Version 1.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nIf a copy of the License was not distributed with this file, you may\nobtain a copy at\n\n http://breakside.io/licenses/LICENSE-1.0.txt\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n",
13
- "GitRevision": "5fd19ed5f4d9bc2a74be2eef1e45ad5c0de02cc9"
13
+ "GitRevision": "e2a77335b26d1a321448e73eb7b733cdd0714cc8"
14
14
  },
15
15
  "Resources": [],
16
16
  "ResourceLookup": {
@@ -12,7 +12,38 @@
12
12
  "FNTFontDescriptor.js",
13
13
  "FontKit.js"
14
14
  ],
15
- "features": []
15
+ "features": [],
16
+ "globals": [
17
+ "FNTOpenTypeFont",
18
+ "FNTOpenTypeFontTable",
19
+ "FNTOpenTypeFontTableHead",
20
+ "FNTOpenTypeFontTableName",
21
+ "FNTOpenTypeFontTableHhea",
22
+ "FNTOpenTypeFontTableHmtx",
23
+ "FNTOpenTypeFontTableCmap",
24
+ "FNTOpenTypeFontTableOS2",
25
+ "FNTOpenTypeFontTableMaxp",
26
+ "FNTOpenTypeFontTablePost",
27
+ "FNTOpenTypeFontTableCFF",
28
+ "FNTOpenTypeFontTableGlyf",
29
+ "FNTOpenTypeFontTableLoca",
30
+ "FNTOpenTypeFontCmap",
31
+ "FNTOpenTypeFontCmapNull",
32
+ "FNTOpenTypeFontCmap0",
33
+ "FNTOpenTypeFontCmap4",
34
+ "FNTOpenTypeFontCmap6",
35
+ "FNTOpenTypeFontCmap10",
36
+ "FNTOpenTypeFontCmap12",
37
+ "FNTOpenTypeFontCmap13",
38
+ "FNTOpenTypeGlyph",
39
+ "FNTOpenTypeSimpleGlyph",
40
+ "FNTOpenTypeCompoundGlyph",
41
+ "FNTOpenTypeConstructor",
42
+ "FNTType1Font",
43
+ "FNTAdobeNamesToUnicode",
44
+ "FNTCompactFontFormat",
45
+ "FNTFontDescriptor"
46
+ ]
16
47
  },
17
48
  "html": {
18
49
  "frameworks": [],
@@ -20,6 +51,7 @@
20
51
  "FNTFontDescriptor+HTML.js",
21
52
  "FontKit+HTML.js"
22
53
  ],
23
- "features": []
54
+ "features": [],
55
+ "globals": []
24
56
  }
25
57
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "JSBundleType": "framework",
3
3
  "JSBundleIdentifier": "io.breakside.JSKit.Foundation",
4
- "JSBundleVersion": "2022.22.1",
4
+ "JSBundleVersion": "2022.23.0",
5
5
  "JSDevelopmentLanguage": "en",
6
6
  "JSCopyright": "Copyright © 2020 Breakside Inc.",
7
7
  "JSBundleEnvironments": {
@@ -9,5 +9,5 @@
9
9
  "node": "Foundation+Node.js"
10
10
  },
11
11
  "JSLicenseNotice": "Licensed under the Breakside Public License, Version 1.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nIf a copy of the License was not distributed with this file, you may\nobtain a copy at\n\n http://breakside.io/licenses/LICENSE-1.0.txt\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n",
12
- "GitRevision": "5fd19ed5f4d9bc2a74be2eef1e45ad5c0de02cc9"
12
+ "GitRevision": "e2a77335b26d1a321448e73eb7b733cdd0714cc8"
13
13
  }
@@ -16,6 +16,8 @@
16
16
  // #import "Javascript.js"
17
17
  // #import "JSObject.js"
18
18
  // #import "JSTextAttachment.js"
19
+ // #import "JSFont.js"
20
+ // #import "JSColor.js"
19
21
  'use strict';
20
22
 
21
23
  (function(){
@@ -40,6 +42,123 @@ JSClass("JSAttributedString", JSObject, {
40
42
  this._runs = [run];
41
43
  },
42
44
 
45
+ initFromDictionary: function(dictionary){
46
+ this._string = typeof(dictionary.string) === "string" ? dictionary.string : "";
47
+ this._runs = [];
48
+ var i, l;
49
+ var runDictionary;
50
+ var run;
51
+ var attributes;
52
+ var name;
53
+ var location = 0;
54
+ var length;
55
+ var maxLength = this._string.length;
56
+ var decodeAttribute = function(name, value){
57
+ switch (name){
58
+ case JSAttributedString.Attribute.font:
59
+ return JSAttributedString.AttributeDecoder.font(value);
60
+ case JSAttributedString.Attribute.textColor:
61
+ case JSAttributedString.Attribute.backgroundColor:
62
+ return JSAttributedString.AttributeDecoder.color(value);
63
+ case JSAttributedString.Attribute.link:
64
+ return JSAttributedString.AttributeDecoder.url(value);
65
+ case JSAttributedString.Attribute.cursor:
66
+ return JSAttributedString.AttributeDecoder.skip(value);
67
+ case JSAttributedString.Attribute.attachment:
68
+ // TODO:
69
+ return JSAttributedString.AttributeDecoder.skip(value);
70
+ case JSAttributedString.Attribute.maskCharacter:
71
+ return JSAttributedString.AttributeDecoder.string(value);
72
+ case JSAttributedString.Attribute.bold:
73
+ case JSAttributedString.Attribute.italic:
74
+ case JSAttributedString.Attribute.underline:
75
+ case JSAttributedString.Attribute.strike:
76
+ return JSAttributedString.AttributeDecoder.boolean(value);
77
+ case JSAttributedString.Attribute.lineHeight:
78
+ case JSAttributedString.Attribute.lineSpacing:
79
+ return JSAttributedString.AttributeDecoder.number(value);
80
+ case JSAttributedString.Attribute.textAlignment:
81
+ // TODO: validate
82
+ case JSAttributedString.Attribute.lineBreakMode:
83
+ // TODO: validate
84
+ default:
85
+ return value;
86
+ }
87
+
88
+ };
89
+ if (dictionary.runs instanceof Array){
90
+ for (i = 0, l = dictionary.runs.length; i < l && maxLength > 0; ++i){
91
+ runDictionary = dictionary.runs[i];
92
+ attributes = {};
93
+ length = typeof(runDictionary.length) === "number" ? Math.min(maxLength, Math.floor(runDictionary.length)) : 0;
94
+ if (length > 0 && typeof(runDictionary.attributes) === "object"){
95
+ for (name in runDictionary.attributes){
96
+ attributes[name] = decodeAttribute(name, runDictionary.attributes[name]);
97
+ }
98
+ this._runs.push(JSAttributedStringRun(JSRange(location, length), attributes));
99
+ }
100
+ location += length;
101
+ maxLength -= length;
102
+ }
103
+ }
104
+ if (maxLength > 0){
105
+ this._runs.push(JSAttributedStringRun(JSRange(location, maxLength), {}));
106
+ }
107
+ if (this._runs.length === 0){
108
+ this._runs.push(JSAttributedStringRun(JSRange(0, 0), {}));
109
+ }
110
+ },
111
+
112
+ dictionaryRepresentation: function(){
113
+ var dictionary = {
114
+ string: this._string,
115
+ runs: []
116
+ };
117
+ var i, l;
118
+ var run;
119
+ var name;
120
+ var runDictionary;
121
+ var encodeAttribute = function(name, value){
122
+ switch (name){
123
+ case JSAttributedString.Attribute.font:
124
+ return JSAttributedString.AttributeEncoder.font(value);
125
+ case JSAttributedString.Attribute.textColor:
126
+ case JSAttributedString.Attribute.backgroundColor:
127
+ return JSAttributedString.AttributeEncoder.color(value);
128
+ case JSAttributedString.Attribute.link:
129
+ return JSAttributedString.AttributeEncoder.url(value);
130
+ case JSAttributedString.Attribute.cursor:
131
+ return JSAttributedString.Attribute.Encoder.skip(value);
132
+ case JSAttributedString.Attribute.attachment:
133
+ // TODO:
134
+ return JSAttributedString.Attribute.Encoder.skip(value);
135
+ case JSAttributedString.Attribute.bold:
136
+ case JSAttributedString.Attribute.italic:
137
+ case JSAttributedString.Attribute.underline:
138
+ case JSAttributedString.Attribute.strike:
139
+ case JSAttributedString.Attribute.lineHeight:
140
+ case JSAttributedString.Attribute.lineSpacing:
141
+ case JSAttributedString.Attribute.textAlignment:
142
+ case JSAttributedString.Attribute.lineBreakMode:
143
+ case JSAttributedString.Attribute.maskCharacter:
144
+ default:
145
+ return value;
146
+ }
147
+ };
148
+ for (i = 0, l = this._runs.length; i < l; ++i){
149
+ run = this._runs[i];
150
+ runDictionary = {
151
+ length: run.range.length,
152
+ attributes: {}
153
+ };
154
+ for (name in run.attributes){
155
+ runDictionary.attributes[name] = encodeAttribute(name, run.attributes[name]);
156
+ }
157
+ dictionary.runs.push(runDictionary);
158
+ }
159
+ return dictionary;
160
+ },
161
+
43
162
  initWithAttributedString: function(attributedString, defaultAttributes){
44
163
  this._string = attributedString.string;
45
164
  this._runs = [];
@@ -294,6 +413,44 @@ JSClass("JSAttributedString", JSObject, {
294
413
  return new JSAttributedStringRunIterator(this, index);
295
414
  },
296
415
 
416
+ longestRangeOfAttributeAtIndex: function(attributeName, index){
417
+ return this.longestRangeOfAttributesAtIndex([attributeName], index);
418
+ },
419
+
420
+ longestRangeOfAttributesAtIndex: function(attributeNames, index){
421
+ var runIndex = this._runIndexForStringIndex(index);
422
+ var run = this._runs[runIndex];
423
+ var range = JSRange(run.range);
424
+ var attributes = {};
425
+ var i, l;
426
+ for (i = 0, l = attributeNames.length; i < l; ++i){
427
+ attributes[attributeNames[i]] = run.attributes[attributeNames[i]];
428
+ }
429
+ i = runIndex - 1;
430
+ while (i >= 0){
431
+ run = this._runs[i];
432
+ if (run.containsEqualAttributes(attributes)){
433
+ range.length = range.end - run.range.location;
434
+ range.location = run.range.location;
435
+ }else{
436
+ break;
437
+ }
438
+ --i;
439
+ }
440
+ i = runIndex + 1;
441
+ l = this._runs.length;
442
+ while (i < l){
443
+ run = this._runs[i];
444
+ if (run.containsEqualAttributes(attributes)){
445
+ range.length = run.range.end - range.location;
446
+ }else{
447
+ break;
448
+ }
449
+ ++i;
450
+ }
451
+ return range;
452
+ },
453
+
297
454
  // MARK: - Formatting
298
455
 
299
456
  replaceFormat: function(){
@@ -339,7 +496,7 @@ JSClass("JSAttributedString", JSObject, {
339
496
  var runA;
340
497
  for (var runIndex = lastRunIndex - 1; runIndex >= expandedRunRange.location; --runIndex){
341
498
  runA = this._runs[runIndex];
342
- if (runA.hasIdenticalAttributes(runB)){
499
+ if (runA.onlyContainsEqualAttributes(runB.attributes)){
343
500
  this._runs.splice(runIndex, 1);
344
501
  runB.range.location = runA.range.location;
345
502
  runB.range.length += runA.range.length;
@@ -358,7 +515,7 @@ JSClass("JSAttributedString", JSObject, {
358
515
  }
359
516
  var runA = this._runs[runIndex - 1];
360
517
  var runB = this._runs[runIndex];
361
- if (runA.hasIdenticalAttributes(runB)){
518
+ if (runA.onlyContainsEqualAttributes(runB.attributes)){
362
519
  this._runs.splice(runIndex, 1);
363
520
  runA.range.length += runB.range.length;
364
521
  }
@@ -443,6 +600,31 @@ JSAttributedString.Attribute = {
443
600
  link: "link"
444
601
  };
445
602
 
603
+ JSAttributedString.AttributeEncoder = {
604
+ skip: function(value){ return undefined; },
605
+ identity: function(value){ return value; },
606
+ dataBase64: function(value){ return value.base64StringRepresentation(); },
607
+ dataBase64URL: function(value){ return value.base64URLStringRepresentation(); },
608
+ dataHex: function(value){ return value.hexStringRepresentation(); },
609
+ url: function(value){ return value.encodedString; },
610
+ font: function(value){ return value.dictionaryRepresentation(); },
611
+ color: function(value){ return value.dictionaryRepresentation(); },
612
+ };
613
+
614
+ JSAttributedString.AttributeDecoder = {
615
+ skip: function(value){ return undefined; },
616
+ identity: function(value){ return value; },
617
+ dataBase64: function(value){ return value.dataByDecodingBase64(); },
618
+ dataBase64URL: function(value){ return value.dataByDecodingBase64URL(); },
619
+ dataHex: function(value){ return value.dataByDecodingHex(); },
620
+ url: function(value){ return JSURL.initWithString(value); },
621
+ font: function(value){ return JSFont.initFromDictionary(value); },
622
+ color: function(value){ return JSColor.initFromDictionary(value); },
623
+ boolean: function(value){ return typeof(value) === "boolean" ? value : undefined; },
624
+ number: function(value){ return typeof(value) === "number" ? value : undefined; },
625
+ string: function(value){ return typeof(value) === "string" ? value : undefined; },
626
+ };
627
+
446
628
  JSAttributedString.SpecialCharacter = {
447
629
  attachment: 0xFFFC,
448
630
  attachmentUTF16: "\uFFFC"
@@ -471,35 +653,46 @@ function JSAttributedStringRun(range, attributes){
471
653
 
472
654
  JSAttributedStringRun.prototype = {
473
655
 
474
- hasIdenticalAttributes: function(other){
656
+ containsEqualAttributes: function(attributes){
475
657
  var attribute;
476
658
  var a, b;
477
- for (attribute in this.attributes){
478
- if (attribute in other.attributes){
479
- a = this.attributes[attribute];
480
- b = other.attributes[attribute];
481
- if (a.isEqual){
482
- if (!a.isEqual(b)){
483
- return false;
484
- }
485
- }else if (b.isEqual){
486
- if (!b.isEqual(a)){
487
- return false;
488
- }
489
- }else if (a != b){
659
+ for (attribute in attributes){
660
+ a = attributes[attribute];
661
+ b = this.attributes[attribute];
662
+ if (a === undefined){
663
+ if (!!b){
490
664
  return false;
491
665
  }
492
- }else{
666
+ }else if (a === null){
667
+ if (b !== null && b !== undefined){
668
+ return false;
669
+ }
670
+ }else if (a.isEqual){
671
+ if (b === null || b === undefined){
672
+ return false;
673
+ }
674
+ if (!a.isEqual(b)){
675
+ return false;
676
+ }
677
+ }else if (a != b){
493
678
  return false;
494
679
  }
495
680
  }
496
- for (attribute in other.attributes){
497
- if (!(attribute in this.attributes)){
681
+ return true;
682
+ },
683
+
684
+ onlyContainsEqualAttributes: function(attributes){
685
+ if (!this.containsEqualAttributes(attributes)){
686
+ return false;
687
+ }
688
+ var attribute;
689
+ for (attribute in this.attributes){
690
+ if (!(attribute in attributes)){
498
691
  return false;
499
692
  }
500
693
  }
501
694
  return true;
502
- }
695
+ },
503
696
 
504
697
  };
505
698
 
@@ -49,7 +49,7 @@ JSClass("JSFont", JSObject, {
49
49
  var weight;
50
50
  var style;
51
51
  var size;
52
- var defaults = JSFont._systemFontDescriptor;
52
+ var defaults = JSFontDescriptor.system;
53
53
  // if ('descriptor' in values){
54
54
  // values = values.descriptor;
55
55
  // }
@@ -78,7 +78,7 @@ JSClass("JSFont", JSObject, {
78
78
  size = JSFont.Size.normal;
79
79
  }
80
80
  if (family){
81
- var descriptor = JSResourceFontDescriptor.descriptorWithFamily(family, weight, style);
81
+ var descriptor = JSFontDescriptor.descriptorWithFamily(family, weight, style);
82
82
  if (descriptor !== null){
83
83
  return JSFont.initWithDescriptor(descriptor, size);
84
84
  }
@@ -86,6 +86,30 @@ JSClass("JSFont", JSObject, {
86
86
  return null;
87
87
  },
88
88
 
89
+ initFromDictionary: function(dictionary){
90
+ var descriptor = JSFontDescriptor.descriptorWithFamily(dictionary.family, dictionary.weight, dictionary.style);
91
+ if (descriptor === null){
92
+ if (dictionary.url){
93
+ descriptor = JSURLFontDescriptor.initWithURL(JSURL.initWithString(dictionary.url), dictionary.family, dictionary.weight, dictionary.style);
94
+ JSFontDescriptor.registerDescriptor(descriptor);
95
+ }
96
+ }
97
+ if (descriptor !== null){
98
+ return JSFont.initWithDescriptor(descriptor, dictionary.size);
99
+ }
100
+ return null;
101
+ },
102
+
103
+ dictionaryRepresentation: function(){
104
+ return {
105
+ url: this.descriptor instanceof JSURLFontDescriptor ? this._descriptor.url : undefined,
106
+ family: this._descriptor.family,
107
+ weight: this._descriptor.weight,
108
+ style: this._descriptor.style,
109
+ size: this.pointSize
110
+ };
111
+ },
112
+
89
113
  getFullName: function(){
90
114
  return this._descriptor.name;
91
115
  },
@@ -187,7 +211,7 @@ JSClass("JSFont", JSObject, {
187
211
  });
188
212
 
189
213
  JSFont.fontWithFamily = function(family, pointSize, weight, style){
190
- var descriptor = JSResourceFontDescriptor.descriptorWithFamily(family, weight || JSFont.Weight.regular, style || JSFont.Style.normal);
214
+ var descriptor = JSFontDescriptor.descriptorWithFamily(family, weight || JSFont.Weight.regular, style || JSFont.Style.normal);
191
215
  return JSFont.initWithDescriptor(descriptor, pointSize);
192
216
  };
193
217
 
@@ -204,12 +228,12 @@ JSFont.registerBundleFonts = function(bundle){
204
228
 
205
229
  JSFont._registerFontResource = function(bundle, metadata){
206
230
  var descriptor = JSResourceFontDescriptor.initWithMetadata(bundle, metadata);
231
+ JSFontDescriptor.registerDescriptor(descriptor);
207
232
  return descriptor;
208
233
  };
209
234
 
210
- JSFont._systemFontDescriptor = null;
211
-
212
- JSFont.registerSystemFontResource = function(name){
235
+ JSFont.registerSystemFontResource = function(name, bundle){
236
+ bundle = bundle || JSBundle.mainBundle;
213
237
  var ext;
214
238
  var extIndex = name.lastIndexOf('.');
215
239
  var i, l;
@@ -221,33 +245,33 @@ JSFont.registerSystemFontResource = function(name){
221
245
  extGuessed = true;
222
246
  ext = "ttf";
223
247
  }
224
- var metadata = JSBundle.mainBundle.metadataForResourceName(name, ext);
248
+ var metadata = bundle.metadataForResourceName(name, ext);
225
249
  if (extGuessed && metadata === null){
226
250
  ext = "otf";
227
- metadata = JSBundle.mainBundle.metadataForResourceName(name, ext);
251
+ metadata = bundle.metadataForResourceName(name, ext);
228
252
  }
229
- this._systemFontDescriptor = JSResourceFontDescriptor.descriptorsByName[metadata.font.unique_identifier];
253
+ JSFontDescriptor.system = JSResourceFontDescriptor.descriptorsByName[metadata.font.unique_identifier];
230
254
  };
231
255
 
232
256
  JSFont.registerSystemFont = function(familyName, weight, style){
233
- this._systemFontDescriptor = JSResourceFontDescriptor.descriptorWithFamily(familyName, weight || JSFont.Weight.regular, style || JSFont.Style.normal);
257
+ JSFontDescriptor.system = JSFontDescriptor.descriptorWithFamily(familyName, weight || JSFont.Weight.regular, style || JSFont.Style.normal);
234
258
  };
235
259
 
236
260
  JSFont.registerSystemFontDescriptor = function(descriptor){
237
- this._systemFontDescriptor = descriptor;
261
+ JSFontDescriptor.system = descriptor;
238
262
  };
239
263
 
240
264
  JSFont.unregisterAllFonts = function(){
241
- JSResourceFontDescriptor.descriptorsByFamily = {};
265
+ JSFontDescriptor.descriptorsByFamily = {};
242
266
  JSResourceFontDescriptor.descriptorsByName = {};
243
- this._systemFontDescriptor = null;
267
+ JSFontDescriptor.system = null;
244
268
  };
245
269
 
246
270
  JSFont.systemFontOfSize = function(pointSize){
247
- if (this._systemFontDescriptor === null){
271
+ if (JSFontDescriptor.system === null){
248
272
  return null;
249
273
  }
250
- return JSFont.initWithDescriptor(this._systemFontDescriptor, pointSize);
274
+ return JSFont.initWithDescriptor(JSFontDescriptor.system, pointSize);
251
275
  };
252
276
 
253
277
  JSFont.Size = {
@@ -94,4 +94,12 @@ JSDataFontDescriptor.definePropertiesFromExtensions({
94
94
 
95
95
  });
96
96
 
97
+ JSURLFontDescriptor.definePropertiesFromExtensions({
98
+
99
+ htmlURLString: function(){
100
+ return this.url.encodedString;
101
+ }
102
+
103
+ });
104
+
97
105
  })();