@breakside/jskit 2022.22.2 → 2022.24.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 (98) 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 +347 -25
  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/JSParagraphStyle.js +71 -0
  14. package/Frameworks/Foundation.jsframework/JS/JSTextAttachment.js +1 -1
  15. package/Frameworks/Foundation.jsframework/JS/JSTextContainer.js +56 -29
  16. package/Frameworks/Foundation.jsframework/JS/JSTextFrame.js +2 -32
  17. package/Frameworks/Foundation.jsframework/JS/JSTextFramesetter.js +125 -22
  18. package/Frameworks/Foundation.jsframework/JS/JSTextLayoutManager.js +11 -3
  19. package/Frameworks/Foundation.jsframework/JS/JSTextLine.js +4 -3
  20. package/Frameworks/Foundation.jsframework/JS/JSTextRun.js +5 -3
  21. package/Frameworks/Foundation.jsframework/JS/JSTextTypesetter.js +41 -25
  22. package/Frameworks/Foundation.jsframework/JS/String+JS.js +69 -0
  23. package/Frameworks/Foundation.jsframework/JS/UnicodeChar.js +8 -0
  24. package/Frameworks/Foundation.jsframework/io.breakside.JSKit.Foundation-bundle.js +2 -2
  25. package/Frameworks/Foundation.jsframework/sources.json +170 -8
  26. package/Frameworks/SecurityKit.jsframework/Info.json +2 -2
  27. package/Frameworks/SecurityKit.jsframework/io.breakside.JSKit.SecurityKit-bundle.js +2 -2
  28. package/Frameworks/SecurityKit.jsframework/sources.json +43 -2
  29. package/Info.json +2 -2
  30. package/Node/Builder.js +20 -9
  31. package/Node/FrameworkBuilder.js +22 -2
  32. package/Node/Project.js +22 -2
  33. package/Node/io.breakside.jskit-bundle.js +2 -2
  34. package/Node/jskit +8 -7
  35. package/Root/Frameworks/APIKit/Info.yaml +1 -1
  36. package/Root/Frameworks/APIKitTesting/Info.yaml +1 -1
  37. package/Root/Frameworks/AuthKit/Info.yaml +1 -1
  38. package/Root/Frameworks/CSSOM/Info.yaml +1 -1
  39. package/Root/Frameworks/ChartKit/CHAxis.js +5 -5
  40. package/Root/Frameworks/ChartKit/CHPieChart.js +1 -1
  41. package/Root/Frameworks/ChartKit/Info.yaml +1 -1
  42. package/Root/Frameworks/ConferenceKit/Info.yaml +1 -1
  43. package/Root/Frameworks/DBKit/Info.yaml +1 -1
  44. package/Root/Frameworks/DOM/Info.yaml +1 -1
  45. package/Root/Frameworks/DOM/XMLSerializer.js +9 -4
  46. package/Root/Frameworks/Dispatch/Info.yaml +1 -1
  47. package/Root/Frameworks/FontKit/Info.yaml +1 -1
  48. package/Root/Frameworks/Foundation/Info.yaml +1 -1
  49. package/Root/Frameworks/Foundation/JSAttributedString.js +347 -25
  50. package/Root/Frameworks/Foundation/JSFont.js +39 -15
  51. package/Root/Frameworks/Foundation/JSFontDescriptor+HTML.js +8 -0
  52. package/Root/Frameworks/Foundation/JSFontDescriptor.js +105 -27
  53. package/Root/Frameworks/Foundation/JSParagraphStyle.js +71 -0
  54. package/Root/Frameworks/Foundation/JSTextAttachment.js +1 -1
  55. package/Root/Frameworks/Foundation/JSTextContainer.js +56 -29
  56. package/Root/Frameworks/Foundation/JSTextFrame.js +2 -32
  57. package/Root/Frameworks/Foundation/JSTextFramesetter.js +125 -22
  58. package/Root/Frameworks/Foundation/JSTextLayoutManager.js +11 -3
  59. package/Root/Frameworks/Foundation/JSTextLine.js +4 -3
  60. package/Root/Frameworks/Foundation/JSTextRun.js +5 -3
  61. package/Root/Frameworks/Foundation/JSTextTypesetter.js +41 -25
  62. package/Root/Frameworks/Foundation/String+JS.js +69 -0
  63. package/Root/Frameworks/Foundation/UnicodeChar.js +8 -0
  64. package/Root/Frameworks/ImageKit/Info.yaml +1 -1
  65. package/Root/Frameworks/MediaKit/Info.yaml +1 -1
  66. package/Root/Frameworks/MediaKitUI/Info.yaml +1 -1
  67. package/Root/Frameworks/NotificationKit/Info.yaml +1 -1
  68. package/Root/Frameworks/PDFKit/Info.yaml +1 -1
  69. package/Root/Frameworks/QRKit/Info.yaml +1 -1
  70. package/Root/Frameworks/SearchKit/Info.yaml +1 -1
  71. package/Root/Frameworks/SecurityKit/Info.yaml +1 -1
  72. package/Root/Frameworks/ServerKit/Info.yaml +1 -1
  73. package/Root/Frameworks/ServerKitTesting/Info.yaml +1 -1
  74. package/Root/Frameworks/TestKit/Info.yaml +1 -1
  75. package/Root/Frameworks/UIKit/Info.yaml +1 -1
  76. package/Root/Frameworks/UIKit/UIHTMLContentEditableTextInputManager.js +36 -0
  77. package/Root/Frameworks/UIKit/UIHTMLDisplayServer.js +1 -1
  78. package/Root/Frameworks/UIKit/UIHTMLTextField.js +1 -1
  79. package/Root/Frameworks/UIKit/UIHTMLTextFrame.js +19 -91
  80. package/Root/Frameworks/UIKit/UIHTMLTextFramesetter.js +52 -9
  81. package/Root/Frameworks/UIKit/UIHTMLTextLine.js +95 -30
  82. package/Root/Frameworks/UIKit/UIHTMLTextRun.js +22 -9
  83. package/Root/Frameworks/UIKit/UIHTMLTextTypesetter.js +334 -459
  84. package/Root/Frameworks/UIKit/UIHTMLWindowServer.js +16 -0
  85. package/Root/Frameworks/UIKit/UILabel.js +43 -10
  86. package/Root/Frameworks/UIKit/UIScrollView.js +12 -0
  87. package/Root/Frameworks/UIKit/UISegmentedControl.js +6 -6
  88. package/Root/Frameworks/UIKit/UITextAttachmentView.js +1 -1
  89. package/Root/Frameworks/UIKit/UITextEditor.js +210 -25
  90. package/Root/Frameworks/UIKit/UITextField.js +58 -31
  91. package/Root/Frameworks/UIKit/UITextInput.js +3 -1
  92. package/Root/Frameworks/UIKit/UITextInputManager.js +2 -2
  93. package/Root/Frameworks/UIKit/UITextLayer.js +39 -26
  94. package/Root/Frameworks/UIKit/UITokenField.js +4 -4
  95. package/Root/Frameworks/UIKit/UIView.js +3 -1
  96. package/Root/Frameworks/UIKit/UIWindow.js +16 -3
  97. package/Root/Frameworks/UIKitTesting/Info.yaml +1 -1
  98. package/package.json +1 -1
@@ -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
  }
@@ -1,6 +1,6 @@
1
1
  JSBundleType: framework
2
2
  JSBundleIdentifier: io.breakside.JSKit.Dispatch
3
- JSBundleVersion: 2022.22.2
3
+ JSBundleVersion: 2022.24.0
4
4
  JSCopyright: Copyright © 2020 Breakside Inc.
5
5
  JSBundleEnvironments:
6
6
  html: Dispatch+HTML.js
@@ -1,6 +1,6 @@
1
1
  JSBundleType: framework
2
2
  JSBundleIdentifier: io.breakside.JSKit.FontKit
3
- JSBundleVersion: 2022.22.2
3
+ JSBundleVersion: 2022.24.0
4
4
  JSDevelopmentLanguage: en
5
5
  JSCopyright: Copyright © 2020 Breakside Inc.
6
6
  JSBundleEnvironments:
@@ -1,6 +1,6 @@
1
1
  JSBundleType: framework
2
2
  JSBundleIdentifier: io.breakside.JSKit.Foundation
3
- JSBundleVersion: 2022.22.2
3
+ JSBundleVersion: 2022.24.0
4
4
  JSDevelopmentLanguage: en
5
5
  JSCopyright: Copyright © 2020 Breakside Inc.
6
6
  JSBundleEnvironments:
@@ -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,137 @@ 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
+ case JSAttributedString.Attribute.paragraphStyleName:
72
+ return JSAttributedString.AttributeDecoder.string(value);
73
+ case JSAttributedString.Attribute.bold:
74
+ case JSAttributedString.Attribute.italic:
75
+ case JSAttributedString.Attribute.underline:
76
+ case JSAttributedString.Attribute.strike:
77
+ return JSAttributedString.AttributeDecoder.boolean(value);
78
+ case JSAttributedString.Attribute.lineHeightMultiple:
79
+ case JSAttributedString.Attribute.lineSpacing:
80
+ case JSAttributedString.Attribute.paragraphSpacing:
81
+ case JSAttributedString.Attribute.beforeParagraphSpacing:
82
+ case JSAttributedString.Attribute.firstLineHeadIndent:
83
+ case JSAttributedString.Attribute.headIndent:
84
+ case JSAttributedString.Attribute.tailIndent:
85
+ case JSAttributedString.Attribute.minimumLineHeight:
86
+ return JSAttributedString.AttributeDecoder.number(value);
87
+ case JSAttributedString.Attribute.textAlignment:
88
+ return JSAttributedString.AttributeDecoder.enumValue(JSTextAlignment)(value);
89
+ case JSAttributedString.Attribute.lineBreakMode:
90
+ return JSAttributedString.AttributeDecoder.enumName(JSLineBreakMode)(value);
91
+ default:
92
+ return value;
93
+ }
94
+
95
+ };
96
+ if (dictionary.runs instanceof Array){
97
+ for (i = 0, l = dictionary.runs.length; i < l && maxLength > 0; ++i){
98
+ runDictionary = dictionary.runs[i];
99
+ attributes = {};
100
+ length = typeof(runDictionary.length) === "number" ? Math.min(maxLength, Math.floor(runDictionary.length)) : 0;
101
+ if (length > 0 && typeof(runDictionary.attributes) === "object"){
102
+ for (name in runDictionary.attributes){
103
+ attributes[name] = decodeAttribute(name, runDictionary.attributes[name]);
104
+ }
105
+ this._runs.push(JSAttributedStringRun(JSRange(location, length), attributes));
106
+ }
107
+ location += length;
108
+ maxLength -= length;
109
+ }
110
+ }
111
+ if (maxLength > 0){
112
+ this._runs.push(JSAttributedStringRun(JSRange(location, maxLength), {}));
113
+ }
114
+ if (this._runs.length === 0){
115
+ this._runs.push(JSAttributedStringRun(JSRange(0, 0), {}));
116
+ }
117
+ },
118
+
119
+ dictionaryRepresentation: function(){
120
+ var dictionary = {
121
+ string: this._string,
122
+ runs: []
123
+ };
124
+ var i, l;
125
+ var run;
126
+ var name;
127
+ var runDictionary;
128
+ var encodeAttribute = function(name, value){
129
+ switch (name){
130
+ case JSAttributedString.Attribute.font:
131
+ return JSAttributedString.AttributeEncoder.font(value);
132
+ case JSAttributedString.Attribute.textColor:
133
+ case JSAttributedString.Attribute.backgroundColor:
134
+ return JSAttributedString.AttributeEncoder.color(value);
135
+ case JSAttributedString.Attribute.link:
136
+ return JSAttributedString.AttributeEncoder.url(value);
137
+ case JSAttributedString.Attribute.cursor:
138
+ return JSAttributedString.Attribute.Encoder.skip(value);
139
+ case JSAttributedString.Attribute.attachment:
140
+ // TODO:
141
+ return JSAttributedString.Attribute.Encoder.skip(value);
142
+ case JSAttributedString.Attribute.bold:
143
+ case JSAttributedString.Attribute.italic:
144
+ case JSAttributedString.Attribute.underline:
145
+ case JSAttributedString.Attribute.strike:
146
+ case JSAttributedString.Attribute.lineHeightMultiple:
147
+ case JSAttributedString.Attribute.minimumLineHeight:
148
+ case JSAttributedString.Attribute.lineSpacing:
149
+ case JSAttributedString.Attribute.paragraphSpacing:
150
+ case JSAttributedString.Attribute.beforeParagraphSpacing:
151
+ case JSAttributedString.Attribute.firstLineHeadIndent:
152
+ case JSAttributedString.Attribute.headIndent:
153
+ case JSAttributedString.Attribute.tailIndent:
154
+ case JSAttributedString.Attribute.textAlignment:
155
+ case JSAttributedString.Attribute.lineBreakMode:
156
+ case JSAttributedString.Attribute.maskCharacter:
157
+ case JSAttributedString.Attribute.paragraphStyleName:
158
+ default:
159
+ return value;
160
+ }
161
+ };
162
+ for (i = 0, l = this._runs.length; i < l; ++i){
163
+ run = this._runs[i];
164
+ runDictionary = {
165
+ length: run.range.length,
166
+ attributes: {}
167
+ };
168
+ for (name in run.attributes){
169
+ runDictionary.attributes[name] = encodeAttribute(name, run.attributes[name]);
170
+ }
171
+ dictionary.runs.push(runDictionary);
172
+ }
173
+ return dictionary;
174
+ },
175
+
43
176
  initWithAttributedString: function(attributedString, defaultAttributes){
44
177
  this._string = attributedString.string;
45
178
  this._runs = [];
@@ -213,6 +346,8 @@ JSClass("JSAttributedString", JSObject, {
213
346
  }
214
347
  this._fixRunsAtIndex(runIndex);
215
348
  this._fixRunsAtIndex(runRange.location);
349
+ this._fixParagraphAttributesAtIndex(range.location);
350
+ this._fixParagraphAttributesAtIndex(range.location + attributedString.string.length);
216
351
  },
217
352
 
218
353
  // MARK: - Attribute mutations
@@ -294,6 +429,44 @@ JSClass("JSAttributedString", JSObject, {
294
429
  return new JSAttributedStringRunIterator(this, index);
295
430
  },
296
431
 
432
+ longestRangeOfAttributeAtIndex: function(attributeName, index){
433
+ return this.longestRangeOfAttributesAtIndex([attributeName], index);
434
+ },
435
+
436
+ longestRangeOfAttributesAtIndex: function(attributeNames, index){
437
+ var runIndex = this._runIndexForStringIndex(index);
438
+ var run = this._runs[runIndex];
439
+ var range = JSRange(run.range);
440
+ var attributes = {};
441
+ var i, l;
442
+ for (i = 0, l = attributeNames.length; i < l; ++i){
443
+ attributes[attributeNames[i]] = run.attributes[attributeNames[i]];
444
+ }
445
+ i = runIndex - 1;
446
+ while (i >= 0){
447
+ run = this._runs[i];
448
+ if (run.containsEqualAttributes(attributes)){
449
+ range.length = range.end - run.range.location;
450
+ range.location = run.range.location;
451
+ }else{
452
+ break;
453
+ }
454
+ --i;
455
+ }
456
+ i = runIndex + 1;
457
+ l = this._runs.length;
458
+ while (i < l){
459
+ run = this._runs[i];
460
+ if (run.containsEqualAttributes(attributes)){
461
+ range.length = run.range.end - range.location;
462
+ }else{
463
+ break;
464
+ }
465
+ ++i;
466
+ }
467
+ return range;
468
+ },
469
+
297
470
  // MARK: - Formatting
298
471
 
299
472
  replaceFormat: function(){
@@ -339,7 +512,7 @@ JSClass("JSAttributedString", JSObject, {
339
512
  var runA;
340
513
  for (var runIndex = lastRunIndex - 1; runIndex >= expandedRunRange.location; --runIndex){
341
514
  runA = this._runs[runIndex];
342
- if (runA.hasIdenticalAttributes(runB)){
515
+ if (runA.onlyContainsEqualAttributes(runB.attributes)){
343
516
  this._runs.splice(runIndex, 1);
344
517
  runB.range.location = runA.range.location;
345
518
  runB.range.length += runA.range.length;
@@ -358,12 +531,50 @@ JSClass("JSAttributedString", JSObject, {
358
531
  }
359
532
  var runA = this._runs[runIndex - 1];
360
533
  var runB = this._runs[runIndex];
361
- if (runA.hasIdenticalAttributes(runB)){
534
+ if (runA.onlyContainsEqualAttributes(runB.attributes)){
362
535
  this._runs.splice(runIndex, 1);
363
536
  runA.range.length += runB.range.length;
364
537
  }
365
538
  },
366
539
 
540
+ _fixParagraphAttributesAtIndex: function(index){
541
+ if (index >= this._string.length){
542
+ return;
543
+ }
544
+ var paragraphRange = this._string.rangeForParagraphAtIndex(index);
545
+ var runIndex = this._runIndexForStringIndex(paragraphRange.location);
546
+ var run = this._runs[runIndex];
547
+ var paragraphAttributes = run.attributes;
548
+ var copy;
549
+ var i, l;
550
+ var attribute;
551
+ var value;
552
+ while (run.range.end < paragraphRange.end && runIndex < this._runs.length){
553
+ run = this._runs[runIndex];
554
+ if (!run.containsEqualParagraphAttributes(paragraphAttributes)){
555
+ if (run.range.end > paragraphRange.end){
556
+ copy = JSAttributedStringRun(JSRange(paragraphRange.end, run.range.end - paragraphRange.end), run.attributes);
557
+ this._runs.splice(runIndex + 1, 0, copy);
558
+ run.range.length -= copy.range.length;
559
+ }
560
+ for (i = 0, l = JSAttributedString.paragraphAttributes.length; i < l; ++i){
561
+ attribute = JSAttributedString.paragraphAttributes[i];
562
+ if (attribute in paragraphAttributes){
563
+ run.attributes[attribute] = paragraphAttributes[attribute];
564
+ }else{
565
+ delete run.attributes[attribute];
566
+ }
567
+ }
568
+ if (this._runs[runIndex - 1].onlyContainsEqualAttributes(run.attributes)){
569
+ this._runs[runIndex - 1].range.length += run.range.length;
570
+ this._runs.splice(runIndex, 1);
571
+ --runIndex;
572
+ }
573
+ }
574
+ ++runIndex;
575
+ }
576
+ },
577
+
367
578
  _rangeOfRunsPreparedForChangeInStringRange: function(range){
368
579
  var firstRunIndex = this._splitRunAtIndex(range.location);
369
580
  if (range.length > 0){
@@ -434,13 +645,84 @@ JSAttributedString.Attribute = {
434
645
  underline: "underline",
435
646
  strike: "strike",
436
647
  attachment: "attachment",
437
- lineHeight: "lineHeight",
438
- lineSpacing: "lineSpacing",
439
- textAlignment: "textAlignment",
440
- lineBreakMode: "lineBreakMode",
441
648
  maskCharacter: "maskCharacter",
442
649
  cursor: "cursor",
443
- link: "link"
650
+ link: "link",
651
+
652
+ // Paragraph
653
+ paragraphStyleName: "paragraphStyleName",
654
+ textAlignment: "textAlignment",
655
+ lineBreakMode: "lineBreakMode",
656
+ minimumLineHeight: "minimumLineHeight",
657
+ lineHeightMultiple: "lineHeightMultiple",
658
+ lineSpacing: "lineSpacing",
659
+ paragraphSpacing: "paragraphSpacing",
660
+ beforeParagraphSpacing: "beforeParagraphSpacing",
661
+ firstLineHeadIndent: "firstLineHeadIndent",
662
+ headIndent: "headIndent",
663
+ tailIndent: "tailIndent",
664
+ };
665
+
666
+ JSAttributedString.paragraphAttributes = [
667
+ JSAttributedString.Attribute.paragraphStyleName,
668
+ JSAttributedString.Attribute.textAlignment,
669
+ JSAttributedString.Attribute.lineBreakMode,
670
+ JSAttributedString.Attribute.minimumLineHeight,
671
+ JSAttributedString.Attribute.lineHeightMultiple,
672
+ JSAttributedString.Attribute.lineSpacing,
673
+ JSAttributedString.Attribute.paragraphSpacing,
674
+ JSAttributedString.Attribute.beforeParagraphSpacing,
675
+ JSAttributedString.Attribute.firstLineHeadIndent,
676
+ JSAttributedString.Attribute.headIndent,
677
+ JSAttributedString.Attribute.tailIndent
678
+ ];
679
+
680
+ JSAttributedString.AttributeEncoder = {
681
+ skip: function(value){ return undefined; },
682
+ identity: function(value){ return value; },
683
+ dataBase64: function(value){ return value.base64StringRepresentation(); },
684
+ dataBase64URL: function(value){ return value.base64URLStringRepresentation(); },
685
+ dataHex: function(value){ return value.hexStringRepresentation(); },
686
+ url: function(value){ return value.encodedString; },
687
+ font: function(value){ return value.dictionaryRepresentation(); },
688
+ color: function(value){ return value.dictionaryRepresentation(); },
689
+ enumName: function(obj){
690
+ return function(value){
691
+ for (var name in obj){
692
+ if (obj[name] === value){
693
+ return name;
694
+ }
695
+ }
696
+ };
697
+ }
698
+ };
699
+
700
+ JSAttributedString.AttributeDecoder = {
701
+ skip: function(value){ return undefined; },
702
+ identity: function(value){ return value; },
703
+ dataBase64: function(value){ return value.dataByDecodingBase64(); },
704
+ dataBase64URL: function(value){ return value.dataByDecodingBase64URL(); },
705
+ dataHex: function(value){ return value.dataByDecodingHex(); },
706
+ url: function(value){ return JSURL.initWithString(value); },
707
+ font: function(value){ return JSFont.initFromDictionary(value); },
708
+ color: function(value){ return JSColor.initFromDictionary(value); },
709
+ boolean: function(value){ return typeof(value) === "boolean" ? value : undefined; },
710
+ number: function(value){ return typeof(value) === "number" ? value : undefined; },
711
+ string: function(value){ return typeof(value) === "string" ? value : undefined; },
712
+ enumName: function(obj){
713
+ return function(value){
714
+ return obj[value];
715
+ };
716
+ },
717
+ enumValue: function(obj){
718
+ return function(value){
719
+ for (var name in obj){
720
+ if (obj[name] === value){
721
+ return value;
722
+ }
723
+ }
724
+ };
725
+ }
444
726
  };
445
727
 
446
728
  JSAttributedString.SpecialCharacter = {
@@ -471,30 +753,70 @@ function JSAttributedStringRun(range, attributes){
471
753
 
472
754
  JSAttributedStringRun.prototype = {
473
755
 
474
- hasIdenticalAttributes: function(other){
756
+ containsEqualAttributes: function(attributes){
475
757
  var attribute;
476
758
  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){
759
+ for (attribute in attributes){
760
+ a = attributes[attribute];
761
+ b = this.attributes[attribute];
762
+ if (a === undefined){
763
+ if (!!b){
490
764
  return false;
491
765
  }
492
- }else{
766
+ }else if (a === null){
767
+ if (b !== null && b !== undefined){
768
+ return false;
769
+ }
770
+ }else if (a.isEqual){
771
+ if (b === null || b === undefined){
772
+ return false;
773
+ }
774
+ if (!a.isEqual(b)){
775
+ return false;
776
+ }
777
+ }else if (a != b){
493
778
  return false;
494
779
  }
495
780
  }
496
- for (attribute in other.attributes){
497
- if (!(attribute in this.attributes)){
781
+ return true;
782
+ },
783
+
784
+ onlyContainsEqualAttributes: function(attributes){
785
+ if (!this.containsEqualAttributes(attributes)){
786
+ return false;
787
+ }
788
+ var attribute;
789
+ for (attribute in this.attributes){
790
+ if (!(attribute in attributes)){
791
+ return false;
792
+ }
793
+ }
794
+ return true;
795
+ },
796
+
797
+ containsEqualParagraphAttributes: function(attributes){
798
+ var attribute;
799
+ var a, b;
800
+ for (var i = 0, l = JSAttributedString.paragraphAttributes.length; i < l; ++i){
801
+ attribute = JSAttributedString.paragraphAttributes[i];
802
+ a = attributes[attribute];
803
+ b = this.attributes[attribute];
804
+ if (a === undefined){
805
+ if (!!b){
806
+ return false;
807
+ }
808
+ }else if (a === null){
809
+ if (b !== null && b !== undefined){
810
+ return false;
811
+ }
812
+ }else if (a.isEqual){
813
+ if (b === null || b === undefined){
814
+ return false;
815
+ }
816
+ if (!a.isEqual(b)){
817
+ return false;
818
+ }
819
+ }else if (a != b){
498
820
  return false;
499
821
  }
500
822
  }
@@ -571,7 +893,7 @@ Object.defineProperties(JSAttributedStringRunIterator.prototype, {
571
893
  return null;
572
894
  }
573
895
  var run = this._attributedString._runs[this._runIndex];
574
- if (run.range.length === 1 && this._attributedString.charCodeAt(run.range.location) === JSAttributedString.SpecialCharacter.attachment){
896
+ if (run.range.length === 1 && this._attributedString.string.charCodeAt(run.range.location) === JSAttributedString.SpecialCharacter.attachment){
575
897
  return run.attributes[JSAttributedString.Attribute.attachment];
576
898
  }
577
899
  return null;
@@ -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
  })();