From 94f49644be9053935faa74cffd65723468435f8f Mon Sep 17 00:00:00 2001 From: xianjimli Date: Mon, 6 Mar 2017 13:10:05 +0800 Subject: [PATCH] use global typescript compiler --- index.js | 92802 ++++++++-------- js/application.js | 25 +- js/assets.d.ts | 1 - js/assets.js | 36 +- js/behaviors/behavior.js | 3 +- js/behaviors/draggable.js | 20 +- js/behaviors/droppable.js | 20 +- js/behaviors/movable.js | 29 +- js/behaviors/resizable.d.ts | 2 +- js/behaviors/resizable.js | 31 +- js/canvas.js | 39 +- js/consts.js | 21 +- js/controls-ext/chart-view.js | 22 +- js/controls-ext/choosable-edit.js | 22 +- js/controls-ext/property-dialog.js | 22 +- js/controls-ext/property-page.js | 24 +- js/controls-ext/property-sheets.js | 28 +- js/controls-ext/props-desc.js | 111 +- js/controls-ext/range-edit.js | 22 +- js/controls-ext/ruler.js | 43 +- js/controls-ext/title-check-button.js | 22 +- js/controls-ext/title-choosable-edit.js | 22 +- js/controls-ext/title-combo-box.js | 30 +- js/controls-ext/title-edit.js | 22 +- js/controls-ext/title-label.js | 22 +- js/controls-ext/title-line.js | 22 +- js/controls-ext/title-link.js | 22 +- js/controls-ext/title-range.js | 22 +- js/controls-ext/title-slider.js | 22 +- js/controls-ext/title-text-area.js | 22 +- js/controls-ext/title-value.js | 22 +- js/controls-ext/title-vector.js | 22 +- js/controls-ext/vector-edit.js | 28 +- js/controls/accordion.js | 24 +- js/controls/button.js | 22 +- js/controls/check-button.js | 22 +- js/controls/collapsable-title.js | 22 +- js/controls/color-tile.js | 30 +- js/controls/combo-box.js | 42 +- js/controls/dialog.js | 25 +- js/controls/edit.js | 33 +- js/controls/grid-view.js | 24 +- js/controls/group.js | 22 +- js/controls/image.js | 22 +- js/controls/iwindow-manager.js | 1 + js/controls/label.js | 24 +- js/controls/list-item.js | 34 +- js/controls/list-view.js | 24 +- js/controls/menu-bar.js | 36 +- js/controls/menu.js | 34 +- js/controls/message-box.js | 31 +- js/controls/page.js | 22 +- js/controls/pages.js | 22 +- js/controls/progress-bar.js | 33 +- js/controls/radio-button.js | 22 +- js/controls/rich-text-edit.js | 53 +- js/controls/rich-text.js | 25 +- js/controls/scroll-view.js | 31 +- js/controls/slider.js | 24 +- js/controls/switch.js | 22 +- js/controls/tab-button-group.js | 24 +- js/controls/tab-button.js | 26 +- js/controls/tab-control.js | 24 +- js/controls/tab-page.js | 22 +- js/controls/title-content.js | 24 +- js/controls/tool-bar.js | 30 +- js/controls/tree-item-data.js | 30 +- js/controls/tree-item.js | 22 +- js/controls/tree-view.js | 25 +- js/controls/widget-factory.js | 3 +- js/controls/widget-recyclable-creator.js | 23 +- js/controls/widget.js | 103 +- js/controls/window-manager-desktop.js | 22 +- js/controls/window-manager-mobile.js | 22 +- js/controls/window-manager.js | 18 +- js/controls/window-normal.js | 25 +- js/controls/window.js | 25 +- js/device-info.js | 1 + js/dirty-rect-context.js | 23 +- js/emitter.js | 18 +- js/event-detail.js | 43 +- js/events.d.ts | 136 +- js/events.js | 61 +- js/factory.js | 1 + js/graphics.js | 7 +- js/html/html-edit.js | 23 +- js/html/html-element.js | 18 +- js/iapplication.js | 1 + js/image-tile.js | 45 +- js/imain-loop.js | 1 + js/index.js | 1 + js/input-event-adapter.js | 1 + js/interaction-request/choice-dialog.js | 1 + js/interaction-request/choice-info.js | 1 + js/interaction-request/confirmation-dialog.js | 1 + js/interaction-request/confirmation-info.js | 1 + .../iinteraction-service.js | 1 + js/interaction-request/input-dialog.js | 1 + js/interaction-request/input-info.js | 1 + js/interaction-request/interaction-request.js | 1 + js/interaction-request/interaction-service.js | 1 + js/interaction-request/interaction-types.js | 15 +- js/interaction-request/notification-dialog.js | 1 + js/interaction-request/notification-info.js | 1 + js/interaction-request/progress-dialog.js | 1 + js/interaction-request/progress-info.js | 1 + js/interaction-request/props-dialog.js | 1 + js/interaction-request/props-info.js | 1 + js/interaction-request/toast-dialog.js | 1 + js/interaction-request/toast-info.js | 1 + js/items-storage.js | 1 + js/itheme-manager.js | 1 + js/iview-port.js | 1 + js/json-serializer.js | 1 + js/key-event.js | 1 + js/layouters/dock-layouter.js | 29 +- js/layouters/grid-layouter.js | 36 +- js/layouters/layouter.js | 24 +- js/layouters/linear-layouter.d.ts | 2 +- js/layouters/linear-layouter.js | 45 +- js/layouters/list-layouter.js | 32 +- js/layouters/simple-layouter.js | 39 +- js/main-loop.js | 27 +- js/matrix-stack.js | 1 + js/matrix.js | 3 +- js/mvvm/binding-rule.js | 48 +- js/mvvm/collection-view-model.js | 40 +- js/mvvm/comparators.js | 1 + js/mvvm/delegate-command.js | 1 + js/mvvm/delegate-comparator.js | 1 + js/mvvm/delegate-filter.js | 1 + js/mvvm/delegate-validation-rule.js | 1 + js/mvvm/delegate-value-converter.js | 1 + js/mvvm/icommand.js | 1 + js/mvvm/icomparator.js | 1 + js/mvvm/ifilter.js | 1 + js/mvvm/ivalidation-rule.d.ts | 8 +- js/mvvm/ivalidation-rule.js | 17 +- js/mvvm/ivalue-converter.js | 1 + js/mvvm/iview-model.js | 9 +- js/mvvm/number-fixer.js | 1 + js/mvvm/range-fixer.js | 1 + js/mvvm/vector2-fixer.js | 1 + js/mvvm/vector3-fixer.js | 1 + js/mvvm/view-model-default.js | 33 +- js/mvvm/view-model.js | 18 +- js/point.js | 3 +- js/range.js | 3 +- js/rect.js | 3 +- js/recyclable-creator.js | 1 + js/service-locator.js | 1 + js/string-table.js | 3 +- js/style.js | 20 +- js/table/passive-scrollable-group.js | 18 +- js/table/table-client.js | 22 +- js/table/table-header-item.js | 29 +- js/table/table-header.js | 22 +- js/table/table-index-item.js | 22 +- js/table/table-index.js | 22 +- js/table/table-row.js | 22 +- js/table/table.js | 24 +- js/theme-manager.js | 1 + js/utils.js | 1 + js/view-port.js | 18 +- package.json | 1 - src/assets.ts | 1 - src/json-serializer.ts | 2 +- src/layouters/layouter.ts | 4 +- src/layouters/linear-layouter.ts | 8 +- src/mvvm/ivalidation-rule.ts | 13 +- typings/globals/whatwg-fetch/index.d.ts | 95 - typings/globals/whatwg-fetch/typings.json | 8 - typings/index.d.ts | 1 - 173 files changed, 49901 insertions(+), 46126 deletions(-) delete mode 100644 typings/globals/whatwg-fetch/index.d.ts delete mode 100644 typings/globals/whatwg-fetch/typings.json diff --git a/index.js b/index.js index 9d03fd1..2c626f4 100644 --- a/index.js +++ b/index.js @@ -45,1113 +45,1128 @@ var qtk = /* 0 */ /***/ function(module, exports, __webpack_require__) { - "use strict"; - var rect_1 = __webpack_require__(1); - exports.Rect = rect_1.Rect; - var point_1 = __webpack_require__(2); - exports.Point = point_1.Point; - var style_1 = __webpack_require__(3); - exports.Style = style_1.Style; - var matrix_1 = __webpack_require__(12); - exports.Matrix = matrix_1.Matrix; - var canvas_1 = __webpack_require__(13); - exports.Canvas = canvas_1.Canvas; - var edit_1 = __webpack_require__(17); - exports.Edit = edit_1.Edit; - var label_1 = __webpack_require__(18); - exports.Label = label_1.Label; - var emitter_1 = __webpack_require__(4); - exports.Emitter = emitter_1.Emitter; - var page_1 = __webpack_require__(88); - exports.Page = page_1.Page; - var key_event_1 = __webpack_require__(16); - exports.KeyEvent = key_event_1.KeyEvent; - var view_port_1 = __webpack_require__(89); - exports.ViewPort = view_port_1.ViewPort; - var pages_1 = __webpack_require__(90); - exports.Pages = pages_1.Pages; - var main_loop_1 = __webpack_require__(91); - exports.MainLoop = main_loop_1.MainLoop; - var string_table_1 = __webpack_require__(22); - exports.StringTable = string_table_1.StringTable; - var image_1 = __webpack_require__(92); - exports.Image = image_1.Image; - var group_1 = __webpack_require__(93); - exports.Group = group_1.Group; - var dialog_1 = __webpack_require__(94); - exports.Dialog = dialog_1.Dialog; - var button_1 = __webpack_require__(96); - exports.Button = button_1.Button; - var slider_1 = __webpack_require__(97); - exports.Slider = slider_1.Slider; - var switch_1 = __webpack_require__(99); - exports.Switch = switch_1.Switch; - var matrix_stack_1 = __webpack_require__(78); - exports.MatrixStack = matrix_stack_1.MatrixStack; - var tab_page_1 = __webpack_require__(100); - exports.TabPage = tab_page_1.TabPage; - var rich_text_1 = __webpack_require__(101); - exports.RichText = rich_text_1.RichText; - var tab_button_1 = __webpack_require__(106); - exports.TabButton = tab_button_1.TabButton; - var tab_control_1 = __webpack_require__(110); - exports.TabControl = tab_control_1.TabControl; - var image_tile_1 = __webpack_require__(7); - exports.ImageDrawType = image_tile_1.ImageDrawType; - exports.ImageTile = image_tile_1.ImageTile; - var rich_text_edit_1 = __webpack_require__(112); - exports.RichTextEdit = rich_text_edit_1.RichTextEdit; - var tab_button_group_1 = __webpack_require__(111); - exports.TabButtonGroup = tab_button_group_1.TabButtonGroup; - var combo_box_1 = __webpack_require__(113); - exports.ComboBox = combo_box_1.ComboBox; - exports.ComboBoxEditable = combo_box_1.ComboBoxEditable; - var grid_view_1 = __webpack_require__(118); - exports.GridView = grid_view_1.GridView; - var list_view_1 = __webpack_require__(114); - exports.ListView = list_view_1.ListView; - var tree_item_1 = __webpack_require__(120); - exports.TreeItem = tree_item_1.TreeItem; - var tree_view_1 = __webpack_require__(121); - exports.TreeView = tree_view_1.TreeView; - var application_1 = __webpack_require__(123); - exports.Application = application_1.Application; - var movable_1 = __webpack_require__(165); - exports.Movable = movable_1.Movable; - var theme_manager_1 = __webpack_require__(124); - exports.ThemeManager = theme_manager_1.ThemeManager; - var draggable_1 = __webpack_require__(166); - exports.Draggable = draggable_1.Draggable; - var droppable_1 = __webpack_require__(167); - exports.Droppable = droppable_1.Droppable; - var behavior_1 = __webpack_require__(79); - exports.Behavior = behavior_1.Behavior; - exports.BehaviorFactory = behavior_1.BehaviorFactory; - var resizable_1 = __webpack_require__(168); - exports.Resizable = resizable_1.Resizable; - exports.ResizableOptions = resizable_1.ResizableOptions; - var menu_1 = __webpack_require__(169); - exports.Menu = menu_1.Menu; - exports.MenuItem = menu_1.MenuItem; - var radio_button_1 = __webpack_require__(108); - exports.RadioButton = radio_button_1.RadioButton; - var tree_item_data_1 = __webpack_require__(122); - exports.TreeItemData = tree_item_data_1.TreeItemData; - var check_button_1 = __webpack_require__(109); - exports.CheckButton = check_button_1.CheckButton; - var window_normal_1 = __webpack_require__(170); - exports.WindowNormal = window_normal_1.WindowNormal; - var widget_factory_1 = __webpack_require__(24); - exports.WidgetFactory = widget_factory_1.WidgetFactory; - var menu_bar_1 = __webpack_require__(171); - exports.MenuBar = menu_bar_1.MenuBar; - exports.MenuBarItem = menu_bar_1.MenuBarItem; - var tool_bar_1 = __webpack_require__(172); - exports.ToolBar = tool_bar_1.ToolBar; - exports.ToolBarItem = tool_bar_1.ToolBarItem; - var color_tile_1 = __webpack_require__(142); - exports.ColorTile = color_tile_1.ColorTile; - exports.ColorLine = color_tile_1.ColorLine; - var list_item_1 = __webpack_require__(116); - exports.ListItem = list_item_1.ListItem; - exports.ListItemStyle = list_item_1.ListItemStyle; - var chart_view_1 = __webpack_require__(173); - exports.ChartView = chart_view_1.ChartView; - var graphics_1 = __webpack_require__(26); - exports.RoundType = graphics_1.RoundType; - exports.Graphics = graphics_1.Graphics; - var accordion_1 = __webpack_require__(326); - exports.Accordion = accordion_1.Accordion; - var ruler_1 = __webpack_require__(329); - exports.VRuler = ruler_1.VRuler; - exports.HRuler = ruler_1.HRuler; - var title_content_1 = __webpack_require__(327); - exports.TitleContent = title_content_1.TitleContent; - var title_label_1 = __webpack_require__(144); - exports.TitleLabel = title_label_1.TitleLabel; - var title_range_1 = __webpack_require__(145); - exports.TitleRange = title_range_1.TitleRange; - var title_vector_1 = __webpack_require__(147); - exports.TitleVector = title_vector_1.TitleVector; - var title_edit_1 = __webpack_require__(143); - exports.TitleEdit = title_edit_1.TitleEdit; - var title_slider_1 = __webpack_require__(149); - exports.TitleSlider = title_slider_1.TitleSlider; - var property_page_1 = __webpack_require__(138); - exports.PropertyPage = property_page_1.PropertyPage; - var property_dialog_1 = __webpack_require__(137); - exports.PropertyDialog = property_dialog_1.PropertyDialog; - var range_edit_1 = __webpack_require__(146); - exports.RangeEdit = range_edit_1.RangeEdit; - var vector_edit_1 = __webpack_require__(148); - exports.VectorEdit = vector_edit_1.VectorEdit; - var choosable_edit_1 = __webpack_require__(153); - exports.ChoosableEdit = choosable_edit_1.ChoosableEdit; - var title_text_area_1 = __webpack_require__(150); - exports.TitleTextArea = title_text_area_1.TitleTextArea; - var property_sheets_1 = __webpack_require__(330); - exports.PropertySheets = property_sheets_1.PropertySheets; - var progress_bar_1 = __webpack_require__(98); - exports.ProgressBarType = progress_bar_1.ProgressBarType; - exports.ProgressBar = progress_bar_1.ProgressBar; - var title_choosable_edit_1 = __webpack_require__(152); - exports.TitleChoosableEdit = title_choosable_edit_1.TitleChoosableEdit; - var dock_layouter_1 = __webpack_require__(133); - exports.DockLayouter = dock_layouter_1.DockLayouter; - exports.DockLayouterParam = dock_layouter_1.DockLayouterParam; - var grid_layouter_1 = __webpack_require__(119); - exports.GridLayouter = grid_layouter_1.GridLayouter; - exports.GridLayouterParam = grid_layouter_1.GridLayouterParam; - var list_layouter_1 = __webpack_require__(115); - exports.ListLayouter = list_layouter_1.ListLayouter; - exports.ListLayouterParam = list_layouter_1.ListLayouterParam; - var simple_layouter_1 = __webpack_require__(117); - exports.SimpleLayouter = simple_layouter_1.SimpleLayouter; - exports.SimpleLayouterParam = simple_layouter_1.SimpleLayouterParam; - var linear_layouter_1 = __webpack_require__(134); - exports.LinearLayouter = linear_layouter_1.LinearLayouter; - exports.LinearLayouterParam = linear_layouter_1.LinearLayouterParam; - var widget_1 = __webpack_require__(19); - exports.Widget = widget_1.Widget; - exports.WidgetState = widget_1.WidgetState; - exports.HitTestResult = widget_1.HitTestResult; - var consts_1 = __webpack_require__(107); - exports.Direction = consts_1.Direction; - exports.Align = consts_1.Align; - exports.AlignH = consts_1.AlignH; - exports.AlignV = consts_1.AlignV; - exports.Orientation = consts_1.Orientation; - var title_combo_box_1 = __webpack_require__(154); - exports.TitleComboBox = title_combo_box_1.TitleComboBox; - exports.TitleComboBoxEditable = title_combo_box_1.TitleComboBoxEditable; - var message_box_1 = __webpack_require__(132); - exports.ButtonOption = message_box_1.ButtonOption; - exports.ButtonsOptions = message_box_1.ButtonsOptions; - exports.TitleOptions = message_box_1.TitleOptions; - exports.MessageBox = message_box_1.MessageBox; - var scroll_view_1 = __webpack_require__(102); - exports.ScrollerBarVisibility = scroll_view_1.ScrollerBarVisibility; - exports.ScrollBarStyle = scroll_view_1.ScrollBarStyle; - exports.ScrollView = scroll_view_1.ScrollView; - var device_info_1 = __webpack_require__(23); - exports.DeviceInfo = device_info_1.DeviceInfo; - var view_model_1 = __webpack_require__(156); - exports.ViewModel = view_model_1.ViewModel; - var recyclable_creator_1 = __webpack_require__(85); - exports.RecyclableCreator = recyclable_creator_1.RecyclableCreator; - var delegate_command_1 = __webpack_require__(331); - exports.DelegateCommand = delegate_command_1.DelegateCommand; - var collection_view_model_1 = __webpack_require__(332); - exports.CollectionViewModel = collection_view_model_1.CollectionViewModel; - var delegate_value_converter_1 = __webpack_require__(333); - exports.DelegateValueConverter = delegate_value_converter_1.DelegateValueConverter; - var widget_recyclable_creator_1 = __webpack_require__(84); - exports.WidgetRecyclableCreator = widget_recyclable_creator_1.WidgetRecyclableCreator; - var ivalidation_rule_1 = __webpack_require__(160); - exports.ValidationResult = ivalidation_rule_1.ValidationResult; - var delegate_validation_rule_1 = __webpack_require__(334); - exports.DelegateValidationRule = delegate_validation_rule_1.DelegateValidationRule; - var binding_rule_1 = __webpack_require__(81); - exports.BindingRule = binding_rule_1.BindingRule; - exports.BindingDataSource = binding_rule_1.BindingDataSource; - exports.BindingCommandSource = binding_rule_1.BindingCommandSource; - exports.BindingRuleItem = binding_rule_1.BindingRuleItem; - var iview_model_1 = __webpack_require__(83); - exports.BindingMode = iview_model_1.BindingMode; - var props_desc_1 = __webpack_require__(155); - exports.PagePropsDesc = props_desc_1.PagePropsDesc; - exports.PropsDesc = props_desc_1.PropsDesc; - exports.PropDesc = props_desc_1.PropDesc; - exports.NumberPropDesc = props_desc_1.NumberPropDesc; - exports.SliderPropDesc = props_desc_1.SliderPropDesc; - var props_desc_2 = __webpack_require__(155); - exports.TextPropDesc = props_desc_2.TextPropDesc; - exports.ReadonlyTextPropDesc = props_desc_2.ReadonlyTextPropDesc; - exports.OptionsPropDesc = props_desc_2.OptionsPropDesc; - exports.RangePropDesc = props_desc_2.RangePropDesc; - var props_desc_3 = __webpack_require__(155); - exports.Vector2PropDesc = props_desc_3.Vector2PropDesc; - exports.Vector3PropDesc = props_desc_3.Vector3PropDesc; - exports.LinePropDesc = props_desc_3.LinePropDesc; - /// - var TWEEN = __webpack_require__(20); - exports.TWEEN = TWEEN; - var Events = __webpack_require__(6); - exports.Events = Events; - var inputEventAdapter = __webpack_require__(15); - exports.inputEventAdapter = inputEventAdapter; - var assets_1 = __webpack_require__(11); - exports.AssetManager = assets_1.AssetManager; - exports.AssetGroup = assets_1.AssetGroup; - exports.AssetItem = assets_1.AssetItem; - var toast_info_1 = __webpack_require__(335); - exports.ToastInfo = toast_info_1.ToastInfo; - var input_info_1 = __webpack_require__(336); - exports.InputInfo = input_info_1.InputInfo; - var props_info_1 = __webpack_require__(337); - exports.PropsInfo = props_info_1.PropsInfo; - var choice_info_1 = __webpack_require__(338); - exports.ChoiceInfo = choice_info_1.ChoiceInfo; - var progress_info_1 = __webpack_require__(339); - exports.ProgressInfo = progress_info_1.ProgressInfo; - var confirmation_info_1 = __webpack_require__(340); - exports.ConfirmationInfo = confirmation_info_1.ConfirmationInfo; - var notification_info_1 = __webpack_require__(341); - exports.NotificationInfo = notification_info_1.NotificationInfo; - var interaction_types_1 = __webpack_require__(129); - exports.InteractionTypes = interaction_types_1.InteractionTypes; - var interaction_request_1 = __webpack_require__(128); - exports.InteractionRequest = interaction_request_1.InteractionRequest; - var interaction_service_1 = __webpack_require__(130); - exports.InteractionService = interaction_service_1.InteractionService; - var items_storage_1 = __webpack_require__(342); - exports.ItemsStorage = items_storage_1.ItemsStorage; - var table_row_1 = __webpack_require__(343); - exports.TableRow = table_row_1.TableRow; - var table_client_1 = __webpack_require__(344); - exports.TableClient = table_client_1.TableClient; - var table_index_1 = __webpack_require__(346); - exports.TableIndex = table_index_1.TableIndex; - var table_header_1 = __webpack_require__(348); - exports.TableHeader = table_header_1.TableHeader; - var table_1 = __webpack_require__(349); - exports.Table = table_1.Table; - exports.TableColInfo = table_1.TableColInfo; - var table_index_item_1 = __webpack_require__(350); - exports.TableIndexItem = table_index_item_1.TableIndexItem; - var table_header_item_1 = __webpack_require__(351); - exports.TableHeaderItem = table_header_item_1.TableHeaderItem; - var delegate_filter_1 = __webpack_require__(352); - exports.DelegateFilter = delegate_filter_1.DelegateFilter; - var delegate_comparator_1 = __webpack_require__(353); - exports.DelegateComparator = delegate_comparator_1.DelegateComparator; - var comparators_1 = __webpack_require__(354); - exports.NumberComparator = comparators_1.NumberComparator; - exports.StringComparator = comparators_1.StringComparator; - exports.RevertComparator = comparators_1.RevertComparator; - exports.ObjectPropComparator = comparators_1.ObjectPropComparator; - var range_fixer_1 = __webpack_require__(355); - exports.RangeFixer = range_fixer_1.RangeFixer; - var number_fixer_1 = __webpack_require__(356); - exports.NumberFixer = number_fixer_1.NumberFixer; - var vector2_fixer_1 = __webpack_require__(357); - exports.Vector2Fixer = vector2_fixer_1.Vector2Fixer; - var vector3_fixer_1 = __webpack_require__(358); - exports.Vector3Fixer = vector3_fixer_1.Vector3Fixer; - var html_element_1 = __webpack_require__(87); - exports.HtmlElement = html_element_1.HtmlElement; - var html_edit_1 = __webpack_require__(86); - exports.HtmlEdit = html_edit_1.HtmlEdit; + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + var rect_1 = __webpack_require__(1); + exports.Rect = rect_1.Rect; + var point_1 = __webpack_require__(2); + exports.Point = point_1.Point; + var style_1 = __webpack_require__(3); + exports.Style = style_1.Style; + var matrix_1 = __webpack_require__(12); + exports.Matrix = matrix_1.Matrix; + var canvas_1 = __webpack_require__(13); + exports.Canvas = canvas_1.Canvas; + var edit_1 = __webpack_require__(17); + exports.Edit = edit_1.Edit; + var label_1 = __webpack_require__(18); + exports.Label = label_1.Label; + var emitter_1 = __webpack_require__(4); + exports.Emitter = emitter_1.Emitter; + var page_1 = __webpack_require__(94); + exports.Page = page_1.Page; + var key_event_1 = __webpack_require__(16); + exports.KeyEvent = key_event_1.KeyEvent; + var view_port_1 = __webpack_require__(95); + exports.ViewPort = view_port_1.ViewPort; + var pages_1 = __webpack_require__(96); + exports.Pages = pages_1.Pages; + var main_loop_1 = __webpack_require__(97); + exports.MainLoop = main_loop_1.MainLoop; + var string_table_1 = __webpack_require__(22); + exports.StringTable = string_table_1.StringTable; + var image_1 = __webpack_require__(98); + exports.Image = image_1.Image; + var group_1 = __webpack_require__(99); + exports.Group = group_1.Group; + var dialog_1 = __webpack_require__(100); + exports.Dialog = dialog_1.Dialog; + var button_1 = __webpack_require__(102); + exports.Button = button_1.Button; + var slider_1 = __webpack_require__(103); + exports.Slider = slider_1.Slider; + var switch_1 = __webpack_require__(105); + exports.Switch = switch_1.Switch; + var matrix_stack_1 = __webpack_require__(84); + exports.MatrixStack = matrix_stack_1.MatrixStack; + var tab_page_1 = __webpack_require__(106); + exports.TabPage = tab_page_1.TabPage; + var rich_text_1 = __webpack_require__(107); + exports.RichText = rich_text_1.RichText; + var tab_button_1 = __webpack_require__(112); + exports.TabButton = tab_button_1.TabButton; + var tab_control_1 = __webpack_require__(116); + exports.TabControl = tab_control_1.TabControl; + var image_tile_1 = __webpack_require__(7); + exports.ImageDrawType = image_tile_1.ImageDrawType; + exports.ImageTile = image_tile_1.ImageTile; + var rich_text_edit_1 = __webpack_require__(118); + exports.RichTextEdit = rich_text_edit_1.RichTextEdit; + var tab_button_group_1 = __webpack_require__(117); + exports.TabButtonGroup = tab_button_group_1.TabButtonGroup; + var combo_box_1 = __webpack_require__(119); + exports.ComboBox = combo_box_1.ComboBox; + exports.ComboBoxEditable = combo_box_1.ComboBoxEditable; + var grid_view_1 = __webpack_require__(124); + exports.GridView = grid_view_1.GridView; + var list_view_1 = __webpack_require__(120); + exports.ListView = list_view_1.ListView; + var tree_item_1 = __webpack_require__(126); + exports.TreeItem = tree_item_1.TreeItem; + var tree_view_1 = __webpack_require__(127); + exports.TreeView = tree_view_1.TreeView; + var application_1 = __webpack_require__(129); + exports.Application = application_1.Application; + var movable_1 = __webpack_require__(171); + exports.Movable = movable_1.Movable; + var theme_manager_1 = __webpack_require__(130); + exports.ThemeManager = theme_manager_1.ThemeManager; + var draggable_1 = __webpack_require__(172); + exports.Draggable = draggable_1.Draggable; + var droppable_1 = __webpack_require__(173); + exports.Droppable = droppable_1.Droppable; + var behavior_1 = __webpack_require__(85); + exports.Behavior = behavior_1.Behavior; + exports.BehaviorFactory = behavior_1.BehaviorFactory; + var resizable_1 = __webpack_require__(174); + exports.Resizable = resizable_1.Resizable; + exports.ResizableOptions = resizable_1.ResizableOptions; + var menu_1 = __webpack_require__(175); + exports.Menu = menu_1.Menu; + exports.MenuItem = menu_1.MenuItem; + var radio_button_1 = __webpack_require__(114); + exports.RadioButton = radio_button_1.RadioButton; + var tree_item_data_1 = __webpack_require__(128); + exports.TreeItemData = tree_item_data_1.TreeItemData; + var check_button_1 = __webpack_require__(115); + exports.CheckButton = check_button_1.CheckButton; + var window_normal_1 = __webpack_require__(176); + exports.WindowNormal = window_normal_1.WindowNormal; + var widget_factory_1 = __webpack_require__(24); + exports.WidgetFactory = widget_factory_1.WidgetFactory; + var menu_bar_1 = __webpack_require__(177); + exports.MenuBar = menu_bar_1.MenuBar; + exports.MenuBarItem = menu_bar_1.MenuBarItem; + var tool_bar_1 = __webpack_require__(178); + exports.ToolBar = tool_bar_1.ToolBar; + exports.ToolBarItem = tool_bar_1.ToolBarItem; + var color_tile_1 = __webpack_require__(148); + exports.ColorTile = color_tile_1.ColorTile; + exports.ColorLine = color_tile_1.ColorLine; + var list_item_1 = __webpack_require__(122); + exports.ListItem = list_item_1.ListItem; + exports.ListItemStyle = list_item_1.ListItemStyle; + var chart_view_1 = __webpack_require__(179); + exports.ChartView = chart_view_1.ChartView; + var graphics_1 = __webpack_require__(26); + exports.RoundType = graphics_1.RoundType; + exports.Graphics = graphics_1.Graphics; + var accordion_1 = __webpack_require__(338); + exports.Accordion = accordion_1.Accordion; + var ruler_1 = __webpack_require__(341); + exports.VRuler = ruler_1.VRuler; + exports.HRuler = ruler_1.HRuler; + var title_content_1 = __webpack_require__(339); + exports.TitleContent = title_content_1.TitleContent; + var title_label_1 = __webpack_require__(150); + exports.TitleLabel = title_label_1.TitleLabel; + var title_range_1 = __webpack_require__(151); + exports.TitleRange = title_range_1.TitleRange; + var title_vector_1 = __webpack_require__(153); + exports.TitleVector = title_vector_1.TitleVector; + var title_edit_1 = __webpack_require__(149); + exports.TitleEdit = title_edit_1.TitleEdit; + var title_slider_1 = __webpack_require__(155); + exports.TitleSlider = title_slider_1.TitleSlider; + var property_page_1 = __webpack_require__(144); + exports.PropertyPage = property_page_1.PropertyPage; + var property_dialog_1 = __webpack_require__(143); + exports.PropertyDialog = property_dialog_1.PropertyDialog; + var range_edit_1 = __webpack_require__(152); + exports.RangeEdit = range_edit_1.RangeEdit; + var vector_edit_1 = __webpack_require__(154); + exports.VectorEdit = vector_edit_1.VectorEdit; + var choosable_edit_1 = __webpack_require__(159); + exports.ChoosableEdit = choosable_edit_1.ChoosableEdit; + var title_text_area_1 = __webpack_require__(156); + exports.TitleTextArea = title_text_area_1.TitleTextArea; + var property_sheets_1 = __webpack_require__(342); + exports.PropertySheets = property_sheets_1.PropertySheets; + var progress_bar_1 = __webpack_require__(104); + exports.ProgressBarType = progress_bar_1.ProgressBarType; + exports.ProgressBar = progress_bar_1.ProgressBar; + var title_choosable_edit_1 = __webpack_require__(158); + exports.TitleChoosableEdit = title_choosable_edit_1.TitleChoosableEdit; + var dock_layouter_1 = __webpack_require__(139); + exports.DockLayouter = dock_layouter_1.DockLayouter; + exports.DockLayouterParam = dock_layouter_1.DockLayouterParam; + var grid_layouter_1 = __webpack_require__(125); + exports.GridLayouter = grid_layouter_1.GridLayouter; + exports.GridLayouterParam = grid_layouter_1.GridLayouterParam; + var list_layouter_1 = __webpack_require__(121); + exports.ListLayouter = list_layouter_1.ListLayouter; + exports.ListLayouterParam = list_layouter_1.ListLayouterParam; + var simple_layouter_1 = __webpack_require__(123); + exports.SimpleLayouter = simple_layouter_1.SimpleLayouter; + exports.SimpleLayouterParam = simple_layouter_1.SimpleLayouterParam; + var linear_layouter_1 = __webpack_require__(140); + exports.LinearLayouter = linear_layouter_1.LinearLayouter; + exports.LinearLayouterParam = linear_layouter_1.LinearLayouterParam; + var widget_1 = __webpack_require__(19); + exports.Widget = widget_1.Widget; + exports.WidgetState = widget_1.WidgetState; + exports.HitTestResult = widget_1.HitTestResult; + var consts_1 = __webpack_require__(113); + exports.Direction = consts_1.Direction; + exports.Align = consts_1.Align; + exports.AlignH = consts_1.AlignH; + exports.AlignV = consts_1.AlignV; + exports.Orientation = consts_1.Orientation; + var title_combo_box_1 = __webpack_require__(160); + exports.TitleComboBox = title_combo_box_1.TitleComboBox; + exports.TitleComboBoxEditable = title_combo_box_1.TitleComboBoxEditable; + var message_box_1 = __webpack_require__(138); + exports.ButtonOption = message_box_1.ButtonOption; + exports.ButtonsOptions = message_box_1.ButtonsOptions; + exports.TitleOptions = message_box_1.TitleOptions; + exports.MessageBox = message_box_1.MessageBox; + var scroll_view_1 = __webpack_require__(108); + exports.ScrollerBarVisibility = scroll_view_1.ScrollerBarVisibility; + exports.ScrollBarStyle = scroll_view_1.ScrollBarStyle; + exports.ScrollView = scroll_view_1.ScrollView; + var device_info_1 = __webpack_require__(23); + exports.DeviceInfo = device_info_1.DeviceInfo; + var view_model_1 = __webpack_require__(162); + exports.ViewModel = view_model_1.ViewModel; + var recyclable_creator_1 = __webpack_require__(91); + exports.RecyclableCreator = recyclable_creator_1.RecyclableCreator; + var delegate_command_1 = __webpack_require__(343); + exports.DelegateCommand = delegate_command_1.DelegateCommand; + var collection_view_model_1 = __webpack_require__(344); + exports.CollectionViewModel = collection_view_model_1.CollectionViewModel; + var delegate_value_converter_1 = __webpack_require__(345); + exports.DelegateValueConverter = delegate_value_converter_1.DelegateValueConverter; + var widget_recyclable_creator_1 = __webpack_require__(90); + exports.WidgetRecyclableCreator = widget_recyclable_creator_1.WidgetRecyclableCreator; + var ivalidation_rule_1 = __webpack_require__(166); + exports.ValidationResult = ivalidation_rule_1.ValidationResult; + var delegate_validation_rule_1 = __webpack_require__(346); + exports.DelegateValidationRule = delegate_validation_rule_1.DelegateValidationRule; + var binding_rule_1 = __webpack_require__(87); + exports.BindingRule = binding_rule_1.BindingRule; + exports.BindingDataSource = binding_rule_1.BindingDataSource; + exports.BindingCommandSource = binding_rule_1.BindingCommandSource; + exports.BindingRuleItem = binding_rule_1.BindingRuleItem; + var iview_model_1 = __webpack_require__(89); + exports.BindingMode = iview_model_1.BindingMode; + var props_desc_1 = __webpack_require__(161); + exports.PagePropsDesc = props_desc_1.PagePropsDesc; + exports.PropsDesc = props_desc_1.PropsDesc; + exports.PropDesc = props_desc_1.PropDesc; + exports.NumberPropDesc = props_desc_1.NumberPropDesc; + exports.SliderPropDesc = props_desc_1.SliderPropDesc; + var props_desc_2 = __webpack_require__(161); + exports.TextPropDesc = props_desc_2.TextPropDesc; + exports.ReadonlyTextPropDesc = props_desc_2.ReadonlyTextPropDesc; + exports.OptionsPropDesc = props_desc_2.OptionsPropDesc; + exports.RangePropDesc = props_desc_2.RangePropDesc; + var props_desc_3 = __webpack_require__(161); + exports.Vector2PropDesc = props_desc_3.Vector2PropDesc; + exports.Vector3PropDesc = props_desc_3.Vector3PropDesc; + exports.LinePropDesc = props_desc_3.LinePropDesc; + /// + var TWEEN = __webpack_require__(20); + exports.TWEEN = TWEEN; + var Events = __webpack_require__(6); + exports.Events = Events; + var inputEventAdapter = __webpack_require__(15); + exports.inputEventAdapter = inputEventAdapter; + var assets_1 = __webpack_require__(11); + exports.AssetManager = assets_1.AssetManager; + exports.AssetGroup = assets_1.AssetGroup; + exports.AssetItem = assets_1.AssetItem; + var toast_info_1 = __webpack_require__(347); + exports.ToastInfo = toast_info_1.ToastInfo; + var input_info_1 = __webpack_require__(348); + exports.InputInfo = input_info_1.InputInfo; + var props_info_1 = __webpack_require__(349); + exports.PropsInfo = props_info_1.PropsInfo; + var choice_info_1 = __webpack_require__(350); + exports.ChoiceInfo = choice_info_1.ChoiceInfo; + var progress_info_1 = __webpack_require__(351); + exports.ProgressInfo = progress_info_1.ProgressInfo; + var confirmation_info_1 = __webpack_require__(352); + exports.ConfirmationInfo = confirmation_info_1.ConfirmationInfo; + var notification_info_1 = __webpack_require__(353); + exports.NotificationInfo = notification_info_1.NotificationInfo; + var interaction_types_1 = __webpack_require__(135); + exports.InteractionTypes = interaction_types_1.InteractionTypes; + var interaction_request_1 = __webpack_require__(134); + exports.InteractionRequest = interaction_request_1.InteractionRequest; + var interaction_service_1 = __webpack_require__(136); + exports.InteractionService = interaction_service_1.InteractionService; + var items_storage_1 = __webpack_require__(354); + exports.ItemsStorage = items_storage_1.ItemsStorage; + var table_row_1 = __webpack_require__(355); + exports.TableRow = table_row_1.TableRow; + var table_client_1 = __webpack_require__(356); + exports.TableClient = table_client_1.TableClient; + var table_index_1 = __webpack_require__(358); + exports.TableIndex = table_index_1.TableIndex; + var table_header_1 = __webpack_require__(360); + exports.TableHeader = table_header_1.TableHeader; + var table_1 = __webpack_require__(361); + exports.Table = table_1.Table; + exports.TableColInfo = table_1.TableColInfo; + var table_index_item_1 = __webpack_require__(362); + exports.TableIndexItem = table_index_item_1.TableIndexItem; + var table_header_item_1 = __webpack_require__(363); + exports.TableHeaderItem = table_header_item_1.TableHeaderItem; + var delegate_filter_1 = __webpack_require__(364); + exports.DelegateFilter = delegate_filter_1.DelegateFilter; + var delegate_comparator_1 = __webpack_require__(365); + exports.DelegateComparator = delegate_comparator_1.DelegateComparator; + var comparators_1 = __webpack_require__(366); + exports.NumberComparator = comparators_1.NumberComparator; + exports.StringComparator = comparators_1.StringComparator; + exports.RevertComparator = comparators_1.RevertComparator; + exports.ObjectPropComparator = comparators_1.ObjectPropComparator; + var range_fixer_1 = __webpack_require__(367); + exports.RangeFixer = range_fixer_1.RangeFixer; + var number_fixer_1 = __webpack_require__(368); + exports.NumberFixer = number_fixer_1.NumberFixer; + var vector2_fixer_1 = __webpack_require__(369); + exports.Vector2Fixer = vector2_fixer_1.Vector2Fixer; + var vector3_fixer_1 = __webpack_require__(370); + exports.Vector3Fixer = vector3_fixer_1.Vector3Fixer; + var html_element_1 = __webpack_require__(93); + exports.HtmlElement = html_element_1.HtmlElement; + var html_edit_1 = __webpack_require__(92); + exports.HtmlEdit = html_edit_1.HtmlEdit; /***/ }, /* 1 */ /***/ function(module, exports) { - "use strict"; - /** - * @class Rect - * 用左上角坐标、宽度和高度来描述一个矩形区域。 - */ - var Rect = (function () { - function Rect(x, y, w, h) { - this.init(x, y, w, h); - } - /** - * @method init - * 初始化Rect。 - * @param {number} x 左上角X坐标。 - * @param {number} y 左上角Y坐标。 - * @param {number} w 宽度。 - * @param {number} h 高度。 - * - * return {Rect} Rect自己。 - */ - Rect.prototype.init = function (x, y, w, h) { - this.x = x; - this.y = y; - this.w = w; - this.h = h; - return this; - }; - Rect.prototype.dispose = function () { - }; - /** - * @method clone - * 克隆。 - */ - Rect.prototype.clone = function () { - return Rect.create(this.x, this.y, this.w, this.h); - }; - /** - * @method equal - * 判断两个Rect的区域是否相同。 - */ - Rect.prototype.equal = function (other) { - return this.x === other.x && this.y === other.y && this.w === other.w && this.h === other.h; - }; - /** - * @method copy - * 拷贝另外一个Rect的属性到当前的Rect。 - */ - Rect.prototype.copy = function (other) { - return this.init(other.x, other.y, other.w, other.h); - }; - /** - * @method merge - * 扩展当前的Rect去包含指定的Rect。 - * - * @return {Rect} Rect本身。 - */ - Rect.prototype.merge = function (other) { - var x = Math.min(this.x, other.x); - var y = Math.min(this.y, other.y); - this.w = Math.max(this.x + this.w, other.x + other.w) - x; - this.h = Math.max(this.y + this.h, other.y + other.h) - y; - this.x = x; - this.y = y; - return this; - }; - /** - * @method containsPoint - * 判断Rect是否包含指定的点。 - */ - Rect.prototype.containsPoint = function (x, y) { - return x >= this.x && x < (this.x + this.w) && y >= this.y && y < (this.y + this.h); - }; - /** - * @method normalize - * 规范化Rect,让w/h总是非负的,但表示的区域不变。 - * @param {Rect} out 保存规范化之后的Rect,如果为空,则直接修改Rect本身。 - * @return {Rect} 规范化之后的Rect。 - */ - Rect.prototype.normalize = function (out) { - var x = this.w > 0 ? this.x : (this.x + this.w); - var y = this.h > 0 ? this.y : (this.y + this.h); - var w = Math.abs(this.w); - var h = Math.abs(this.h); - if (!out) { - out = this; - } - out.init(x, y, w, h); - return out; - }; - Rect.create = function (x, y, w, h) { - var r = new Rect(x || 0, y || 0, w || 0, h || 0); - return r; - }; - Rect.rect = Rect.create(0, 0, 0, 0); - return Rect; - }()); - exports.Rect = Rect; - ; + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + /** + * @class Rect + * 用左上角坐标、宽度和高度来描述一个矩形区域。 + */ + var Rect = (function () { + function Rect(x, y, w, h) { + this.init(x, y, w, h); + } + /** + * @method init + * 初始化Rect。 + * @param {number} x 左上角X坐标。 + * @param {number} y 左上角Y坐标。 + * @param {number} w 宽度。 + * @param {number} h 高度。 + * + * return {Rect} Rect自己。 + */ + Rect.prototype.init = function (x, y, w, h) { + this.x = x; + this.y = y; + this.w = w; + this.h = h; + return this; + }; + Rect.prototype.dispose = function () { + }; + /** + * @method clone + * 克隆。 + */ + Rect.prototype.clone = function () { + return Rect.create(this.x, this.y, this.w, this.h); + }; + /** + * @method equal + * 判断两个Rect的区域是否相同。 + */ + Rect.prototype.equal = function (other) { + return this.x === other.x && this.y === other.y && this.w === other.w && this.h === other.h; + }; + /** + * @method copy + * 拷贝另外一个Rect的属性到当前的Rect。 + */ + Rect.prototype.copy = function (other) { + return this.init(other.x, other.y, other.w, other.h); + }; + /** + * @method merge + * 扩展当前的Rect去包含指定的Rect。 + * + * @return {Rect} Rect本身。 + */ + Rect.prototype.merge = function (other) { + var x = Math.min(this.x, other.x); + var y = Math.min(this.y, other.y); + this.w = Math.max(this.x + this.w, other.x + other.w) - x; + this.h = Math.max(this.y + this.h, other.y + other.h) - y; + this.x = x; + this.y = y; + return this; + }; + /** + * @method containsPoint + * 判断Rect是否包含指定的点。 + */ + Rect.prototype.containsPoint = function (x, y) { + return x >= this.x && x < (this.x + this.w) && y >= this.y && y < (this.y + this.h); + }; + /** + * @method normalize + * 规范化Rect,让w/h总是非负的,但表示的区域不变。 + * @param {Rect} out 保存规范化之后的Rect,如果为空,则直接修改Rect本身。 + * @return {Rect} 规范化之后的Rect。 + */ + Rect.prototype.normalize = function (out) { + var x = this.w > 0 ? this.x : (this.x + this.w); + var y = this.h > 0 ? this.y : (this.y + this.h); + var w = Math.abs(this.w); + var h = Math.abs(this.h); + if (!out) { + out = this; + } + out.init(x, y, w, h); + return out; + }; + Rect.create = function (x, y, w, h) { + var r = new Rect(x || 0, y || 0, w || 0, h || 0); + return r; + }; + return Rect; + }()); + Rect.rect = Rect.create(0, 0, 0, 0); + exports.Rect = Rect; + ; /***/ }, /* 2 */ /***/ function(module, exports) { - "use strict"; - var Point = (function () { - function Point(x, y) { - this.x = x; - this.y = y; - } - Point.prototype.dispose = function () { - }; - Point.prototype.init = function (x, y) { - this.x = x; - this.y = y; - return this; - }; - Point.prototype.copy = function (p) { - this.x = p.x; - this.y = p.y; - return this; - }; - Point.prototype.isInRect = function (r) { - return this.isIn(r.x, r.y, r.w, r.h); - }; - Point.prototype.isIn = function (x, y, w, h) { - var xx = this.x; - var yy = this.y; - return xx >= x && xx <= (x + w) && yy >= y && yy <= (y + h); - }; - Point.create = function (x, y) { - return new Point(x, y); - }; - Point.point = Point.create(0, 0); - return Point; - }()); - exports.Point = Point; - ; + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + var Point = (function () { + function Point(x, y) { + this.x = x; + this.y = y; + } + Point.prototype.dispose = function () { + }; + Point.prototype.init = function (x, y) { + this.x = x; + this.y = y; + return this; + }; + Point.prototype.copy = function (p) { + this.x = p.x; + this.y = p.y; + return this; + }; + Point.prototype.isInRect = function (r) { + return this.isIn(r.x, r.y, r.w, r.h); + }; + Point.prototype.isIn = function (x, y, w, h) { + var xx = this.x; + var yy = this.y; + return xx >= x && xx <= (x + w) && yy >= y && yy <= (y + h); + }; + Point.create = function (x, y) { + return new Point(x, y); + }; + return Point; + }()); + Point.point = Point.create(0, 0); + exports.Point = Point; + ; /***/ }, /* 3 */ /***/ function(module, exports, __webpack_require__) { - /// - "use strict"; - var __extends = (this && this.__extends) || function (d, b) { - for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; - var emitter_1 = __webpack_require__(4); - var Events = __webpack_require__(6); - var image_tile_1 = __webpack_require__(7); + /// + "use strict"; + var __extends = (this && this.__extends) || (function () { + var extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + return function (d, b) { + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; + })(); + Object.defineProperty(exports, "__esModule", { value: true }); + var emitter_1 = __webpack_require__(4); + var Events = __webpack_require__(6); + var image_tile_1 = __webpack_require__(7); + /** + * Style用来控制Widget的外观效果,如背景和字体等等。 + */ + var Style = (function (_super) { + __extends(Style, _super); + function Style() { + return _super.call(this) || this; + } + Style.prototype.notifyChanged = function () { + this.dispatchEvent({ type: Events.CHANGE }); + }; + Object.defineProperty(Style.prototype, "textLineHeight", { + get: function () { + return Math.round(this.fontSize * 1.2); + }, + enumerable: true, + configurable: true + }); + Style.prototype.clone = function () { + var other = new Style(); + if (this._backGroundColor) { + other._backGroundColor = this._backGroundColor; + } + if (this._foreGroundColor) { + other._foreGroundColor = this._foreGroundColor; + } + if (this._backGroundImage) { + other._backGroundImage = this._backGroundImage; + } + if (this._backGroundImageDrawType) { + other._backGroundImageDrawType = this._backGroundImageDrawType; + } + if (this._foreGroundImage) { + other._foreGroundImage = this._foreGroundImage; + } + if (this._foreGroundImageDrawType) { + other._foreGroundImageDrawType = this._foreGroundImageDrawType; + } + if (this._fontFamily) { + other._fontFamily = this._fontFamily; + } + if (this._fontSize) { + other._fontSize = this._fontSize; + } + if (this._textColor) { + other._textColor = this._textColor; + } + if (this._fontBold) { + other._fontBold = this._fontBold; + } + if (this._fontItalic) { + other._fontItalic = this._fontItalic; + } + if (this._fontUnderline) { + other._fontUnderline = this._fontUnderline; + } + if (this._lineColor) { + other._lineColor = this._lineColor; + } + if (this._lineWidth) { + other._lineWidth = this._lineWidth; + } + if (this._lineJoin) { + other._lineJoin = this._lineJoin; + } + if (this._lineCap) { + other._lineCap = this._lineCap; + } + if (this._dashLine) { + other._dashLine = this._dashLine; + } + if (this._roundRadius) { + other._roundRadius = this._roundRadius; + } + if (this._roundType) { + other._roundType = this._roundType; + } + return other; + }; + Style.prototype.toJson = function () { + var json = {}; + if (this._backGroundColor) { + json.backGroundColor = this._backGroundColor; + } + if (this._foreGroundColor) { + json.foreGroundColor = this._foreGroundColor; + } + if (this._backGroundImage) { + json.backGroundImage = this._backGroundImage.toJson(); + } + if (this._backGroundImageDrawType) { + json.backGroundImageDrawType = image_tile_1.ImageDrawType[this._backGroundImageDrawType]; + } + if (this._foreGroundImage) { + json.foreGroundImage = this._foreGroundImage.toJson(); + } + if (this._foreGroundImageDrawType) { + json.foreGroundImageDrawType = image_tile_1.ImageDrawType[this._foreGroundImageDrawType]; + } + if (this._fontFamily) { + json.fontFamily = this._fontFamily; + } + if (this._fontSize) { + json.fontSize = this._fontSize; + } + if (this._textColor) { + json.textColor = this._textColor; + } + if (this._fontBold) { + json.fontBold = this._fontBold; + } + if (this._fontItalic) { + json.fontItalic = this._fontItalic; + } + if (this._fontUnderline) { + json.fontUnderline = this._fontUnderline; + } + if (this._textBaseline) { + json.textBaseline = this._textBaseline; + } + if (this._textAlign) { + json.textAlign = this._textAlign; + } + if (this._lineWidth) { + json.lineWidth = this._lineWidth; + } + if (this._lineJoin) { + json.lineJoin = this._lineJoin; + } + if (this._lineCap) { + json.lineCap = this._lineCap; + } + if (this._dashLine) { + json.dashLine = this._dashLine; + } + if (this._lineColor) { + json.lineColor = this._lineColor; + } + if (this._roundRadius) { + json.roundRadius = this._roundRadius; + } + if (this._roundType) { + json.roundType = this._roundType; + } + return json; + }; + Style.prototype.fromJson = function (json, baseURL) { + var _this = this; + if (json.backGroundColor) { + this._backGroundColor = json.backGroundColor; + } + if (json.foreGroundColor) { + this._foreGroundColor = json.foreGroundColor; + } + if (json.backGroundImage) { + var url = baseURL ? baseURL + "/" + json.backGroundImage : json.backGroundImage; + this._backGroundImage = image_tile_1.ImageTile.create(url, function (evt) { + _this.notifyChanged(); + }); + } + if (json.foreGroundImage) { + var url = baseURL ? baseURL + "/" + json.foreGroundImage : json.foreGroundImage; + this._foreGroundImage = image_tile_1.ImageTile.create(url, function (evt) { + _this.notifyChanged(); + }); + } + if (json.backGroundImageDrawType) { + this._backGroundImageDrawType = parseInt(image_tile_1.ImageDrawType[json.backGroundImageDrawType]); + } + if (json.foreGroundImageDrawType) { + this._foreGroundImageDrawType = parseInt(image_tile_1.ImageDrawType[json.foreGroundImageDrawType]); + } + if (json.fontFamily) { + this._fontFamily = json.fontFamily; + } + if (json.fontSize) { + this._fontSize = json.fontSize; + } + if (json.textColor) { + this._textColor = json.textColor; + } + if (json.fontBold) { + this._fontBold = json.fontBold; + } + if (json.fontItalic) { + this._fontItalic = json.fontItalic; + } + if (json.fontUnderline) { + this._fontUnderline = json.fontUnderline; + } + if (json.textBaseline) { + this._textBaseline = json.textBaseline; + } + if (json.textAlign) { + this._textAlign = json.textAlign; + } + if (json.lineWidth) { + this._lineWidth = json.lineWidth; + } + if (json.lineJoin) { + this._lineJoin = json.lineJoin; + } + if (json.lineCap) { + this._lineCap = json.lineCap; + } + if (json.dashLine) { + this._dashLine = json.dashLine; + } + if (json.lineColor) { + this._lineColor = json.lineColor; + } + if (json.roundRadius) { + this._roundRadius = json.roundRadius; + } + if (json.roundType) { + this._roundType = json.roundType; + } + this.notifyChanged(); + }; + Object.defineProperty(Style.prototype, "backGroundColor", { + get: function () { + return this._backGroundColor; + }, + set: function (value) { + this._backGroundColor = value; + this.notifyChanged(); + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Style.prototype, "foreGroundColor", { + get: function () { + return this._foreGroundColor; + }, + set: function (value) { + this._foreGroundColor = value; + this.notifyChanged(); + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Style.prototype, "backGroundImage", { + get: function () { + return this._backGroundImage; + }, + set: function (value) { + this._backGroundImage = value; + this.notifyChanged(); + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Style.prototype, "backGroundImageDrawType", { + get: function () { + return this._backGroundImageDrawType; + }, + set: function (value) { + this._backGroundImageDrawType = value; + this.notifyChanged(); + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Style.prototype, "foreGroundImage", { + get: function () { + return this._foreGroundImage; + }, + set: function (value) { + this._foreGroundImage = value; + this.notifyChanged(); + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Style.prototype, "foreGroundImageDrawType", { + get: function () { + return this._foreGroundImageDrawType; + }, + set: function (value) { + this._foreGroundImageDrawType = value; + this.notifyChanged(); + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Style.prototype, "font", { + get: function () { + var font = ""; + if (this._fontBold) { + font += "bold "; + } + if (this._fontItalic) { + font += "italic "; + } + font += this._fontSize + "px " + (this._fontFamily || "Sans"); + return font; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Style.prototype, "fontFamily", { + get: function () { + return this._fontFamily || "Sans"; + }, + set: function (value) { + this._fontFamily = value; + this.notifyChanged(); + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Style.prototype, "fontSize", { + get: function () { + return this._fontSize; + }, + set: function (value) { + this._fontSize = value; + this.notifyChanged(); + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Style.prototype, "textColor", { + get: function () { + return this._textColor; + }, + set: function (value) { + this._textColor = value; + this.notifyChanged(); + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Style.prototype, "fontBold", { + get: function () { + return this._fontBold; + }, + set: function (value) { + this._fontBold = value; + this.notifyChanged(); + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Style.prototype, "fontItalic", { + get: function () { + return this._fontItalic; + }, + set: function (value) { + this._fontItalic = value; + this.notifyChanged(); + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Style.prototype, "fontUnderline", { + get: function () { + return this._fontUnderline; + }, + set: function (value) { + this._fontUnderline = value; + this.notifyChanged(); + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Style.prototype, "textAlign", { + get: function () { + return this._textAlign || "center"; + }, + set: function (value) { + this._textAlign = value; + this.notifyChanged(); + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Style.prototype, "textBaseline", { + get: function () { + return this._textBaseline || "middle"; + }, + set: function (value) { + this._textBaseline = value; + this.notifyChanged(); + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Style.prototype, "lineWidth", { + get: function () { + return this._lineWidth; + }, + set: function (value) { + this._lineWidth = value; + this.notifyChanged(); + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Style.prototype, "lineJoin", { + get: function () { + return this._lineJoin; + }, + set: function (value) { + this._lineJoin = value; + this.notifyChanged(); + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Style.prototype, "lineCap", { + get: function () { + return this._lineCap; + }, + set: function (value) { + this._lineCap = value; + this.notifyChanged(); + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Style.prototype, "dashLine", { + get: function () { + return this._dashLine; + }, + set: function (value) { + this._dashLine = value; + this.notifyChanged(); + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Style.prototype, "lineColor", { + get: function () { + return this._lineColor; + }, + set: function (value) { + this._lineColor = value; + this.notifyChanged(); + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Style.prototype, "roundRadius", { + get: function () { + return this._roundRadius; + }, + set: function (value) { + this._roundRadius = value; + this.notifyChanged(); + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Style.prototype, "roundType", { + get: function () { + return this._roundType; + }, + set: function (value) { + this._roundType = value; + this.notifyChanged(); + }, + enumerable: true, + configurable: true + }); + Style.create = function (json, baseURL) { + var style = new Style(); + if (json) { + style.fromJson(json, baseURL); + } + return style; + }; + Style.fill = function (ctx, fillStyle, h) { + if (!fillStyle || typeof fillStyle === "string") { + ctx.fillStyle = fillStyle; + } + else { + var key = fillStyle + "." + h; + var value = Style.fillStyles[key]; + if (!value) { + var data = fillStyle; + var n = data.length; + var delta = 1 / n; + var value = ctx.createLinearGradient(0, 0, 0, h); + for (var i = 0; i < n; i++) { + var color = data[i]; + value.addColorStop(i * delta, color); + } + Style.fillStyles[key] = value; + } + ctx.fillStyle = value; + } + ctx.fill(); + return; + }; + return Style; + }(emitter_1.Emitter)); + Style.fillStyles = {}; + exports.Style = Style; + ; + + +/***/ }, +/* 4 */ +/***/ function(module, exports, __webpack_require__) { + + /// + "use strict"; + var __extends = (this && this.__extends) || (function () { + var extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + return function (d, b) { + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; + })(); + Object.defineProperty(exports, "__esModule", { value: true }); + var EventEmitter = __webpack_require__(5); + var EmitterImpl = (function (_super) { + __extends(EmitterImpl, _super); + function EmitterImpl() { + return _super.call(this) || this; + } + return EmitterImpl; + }(EventEmitter)); + function toCaptureEventName(name) { + return name + ".capture"; + } + /** + * 事件分发器。 + */ + var Emitter = (function () { + function Emitter() { + this.emitter = new EmitterImpl(); + } + /*** + * 注册事件处理函数。 + * @param type 事件的名称。 + * @param callback 回调函数。 + * @param useCapture 是否注册为capture阶段的处理函数。 + */ + Emitter.prototype.on = function (type, callback, useCapture) { + this.addEventListener(type, callback, useCapture); + }; + /*** + * 注册事件处理函数(只执行一次)。 + * @param type 事件的名称。 + * @param callback 回调函数。 + * @param useCapture 是否注册为capture阶段的处理函数。 + */ + Emitter.prototype.once = function (type, callback) { + this.emitter.once(type, callback, this); + }; + /*** + * 注消事件处理函数。 + * @param type 事件的名称。 + * @param callback 回调函数。 + * @param useCapture 是否注消capture阶段的处理函数。 + */ + Emitter.prototype.off = function (type, callback, useCapture) { + this.removeEventListener(type, callback, useCapture); + }; + /*** + * 注册事件处理函数。 + * @param type 事件的名称。 + * @param callback 回调函数。 + * @param useCapture 是否注册为capture阶段的处理函数。 + */ + Emitter.prototype.addEventListener = function (type, callback, useCapture) { + if (!callback) { + return; + } + if (useCapture) { + this.emitter.addListener(toCaptureEventName(type), callback, this); + } + else { + this.emitter.addListener(type, callback, this); + } + }; + /*** + * 注消事件处理函数。 + * @param type 事件的名称。 + * @param callback 回调函数。 + * @param useCapture 是否注消capture阶段的处理函数。 + */ + Emitter.prototype.removeEventListener = function (type, callback, useCapture) { + if (useCapture) { + this.emitter.removeListener(toCaptureEventName(type), callback, this); + } + else { + this.emitter.removeListener(type, callback, this); + } + }; + /*** + * 分发异步事件。 + * @param evt 事件。 + * @param useCapture 是否触发capture阶段的处理函数。 + */ + Emitter.prototype.dispatchEventAsync = function (evt, useCapture) { + var _this = this; + setTimeout(function (e) { + _this.dispatchEvent(evt, useCapture); + }, 0); + }; + /*** + * 分发事件。 + * @param evt 事件。 + * @param useCapture 是否触发capture阶段的处理函数。 + */ + Emitter.prototype.dispatchEvent = function (evt, useCapture) { + if (evt.propagationStopped) { + console.log("evt.propagationStopped = true;"); + return; + } + var emitter = this.emitter; + if (useCapture) { + emitter.emit(toCaptureEventName(evt.type), evt); + } + else { + emitter.emit(evt.type, evt); + } + }; + Emitter.prototype.removeAllListeners = function (event) { + this.emitter.removeAllListeners(event); + }; + return Emitter; + }()); + exports.Emitter = Emitter; + + +/***/ }, +/* 5 */ +/***/ function(module, exports, __webpack_require__) { + + 'use strict'; + + var has = Object.prototype.hasOwnProperty; + + // + // We store our EE objects in a plain object whose properties are event names. + // If `Object.create(null)` is not supported we prefix the event names with a + // `~` to make sure that the built-in object properties are not overridden or + // used as an attack vector. + // We also assume that `Object.create(null)` is available when the event name + // is an ES6 Symbol. + // + var prefix = typeof Object.create !== 'function' ? '~' : false; + /** - * Style用来控制Widget的外观效果,如背景和字体等等。 - */ - var Style = (function (_super) { - __extends(Style, _super); - function Style() { - _super.call(this); - } - Style.prototype.notifyChanged = function () { - this.dispatchEvent({ type: Events.CHANGE }); - }; - Object.defineProperty(Style.prototype, "textLineHeight", { - get: function () { - return Math.round(this.fontSize * 1.2); - }, - enumerable: true, - configurable: true - }); - Style.prototype.clone = function () { - var other = new Style(); - if (this._backGroundColor) { - other._backGroundColor = this._backGroundColor; - } - if (this._foreGroundColor) { - other._foreGroundColor = this._foreGroundColor; - } - if (this._backGroundImage) { - other._backGroundImage = this._backGroundImage; - } - if (this._backGroundImageDrawType) { - other._backGroundImageDrawType = this._backGroundImageDrawType; - } - if (this._foreGroundImage) { - other._foreGroundImage = this._foreGroundImage; - } - if (this._foreGroundImageDrawType) { - other._foreGroundImageDrawType = this._foreGroundImageDrawType; - } - if (this._fontFamily) { - other._fontFamily = this._fontFamily; - } - if (this._fontSize) { - other._fontSize = this._fontSize; - } - if (this._textColor) { - other._textColor = this._textColor; - } - if (this._fontBold) { - other._fontBold = this._fontBold; - } - if (this._fontItalic) { - other._fontItalic = this._fontItalic; - } - if (this._fontUnderline) { - other._fontUnderline = this._fontUnderline; - } - if (this._lineColor) { - other._lineColor = this._lineColor; - } - if (this._lineWidth) { - other._lineWidth = this._lineWidth; - } - if (this._lineJoin) { - other._lineJoin = this._lineJoin; - } - if (this._lineCap) { - other._lineCap = this._lineCap; - } - if (this._dashLine) { - other._dashLine = this._dashLine; - } - if (this._roundRadius) { - other._roundRadius = this._roundRadius; - } - if (this._roundType) { - other._roundType = this._roundType; - } - return other; - }; - Style.prototype.toJson = function () { - var json = {}; - if (this._backGroundColor) { - json.backGroundColor = this._backGroundColor; - } - if (this._foreGroundColor) { - json.foreGroundColor = this._foreGroundColor; - } - if (this._backGroundImage) { - json.backGroundImage = this._backGroundImage.toJson(); - } - if (this._backGroundImageDrawType) { - json.backGroundImageDrawType = image_tile_1.ImageDrawType[this._backGroundImageDrawType]; - } - if (this._foreGroundImage) { - json.foreGroundImage = this._foreGroundImage.toJson(); - } - if (this._foreGroundImageDrawType) { - json.foreGroundImageDrawType = image_tile_1.ImageDrawType[this._foreGroundImageDrawType]; - } - if (this._fontFamily) { - json.fontFamily = this._fontFamily; - } - if (this._fontSize) { - json.fontSize = this._fontSize; - } - if (this._textColor) { - json.textColor = this._textColor; - } - if (this._fontBold) { - json.fontBold = this._fontBold; - } - if (this._fontItalic) { - json.fontItalic = this._fontItalic; - } - if (this._fontUnderline) { - json.fontUnderline = this._fontUnderline; - } - if (this._textBaseline) { - json.textBaseline = this._textBaseline; - } - if (this._textAlign) { - json.textAlign = this._textAlign; - } - if (this._lineWidth) { - json.lineWidth = this._lineWidth; - } - if (this._lineJoin) { - json.lineJoin = this._lineJoin; - } - if (this._lineCap) { - json.lineCap = this._lineCap; - } - if (this._dashLine) { - json.dashLine = this._dashLine; - } - if (this._lineColor) { - json.lineColor = this._lineColor; - } - if (this._roundRadius) { - json.roundRadius = this._roundRadius; - } - if (this._roundType) { - json.roundType = this._roundType; - } - return json; - }; - Style.prototype.fromJson = function (json, baseURL) { - var _this = this; - if (json.backGroundColor) { - this._backGroundColor = json.backGroundColor; - } - if (json.foreGroundColor) { - this._foreGroundColor = json.foreGroundColor; - } - if (json.backGroundImage) { - var url = baseURL ? baseURL + "/" + json.backGroundImage : json.backGroundImage; - this._backGroundImage = image_tile_1.ImageTile.create(url, function (evt) { - _this.notifyChanged(); - }); - } - if (json.foreGroundImage) { - var url = baseURL ? baseURL + "/" + json.foreGroundImage : json.foreGroundImage; - this._foreGroundImage = image_tile_1.ImageTile.create(url, function (evt) { - _this.notifyChanged(); - }); - } - if (json.backGroundImageDrawType) { - this._backGroundImageDrawType = parseInt(image_tile_1.ImageDrawType[json.backGroundImageDrawType]); - } - if (json.foreGroundImageDrawType) { - this._foreGroundImageDrawType = parseInt(image_tile_1.ImageDrawType[json.foreGroundImageDrawType]); - } - if (json.fontFamily) { - this._fontFamily = json.fontFamily; - } - if (json.fontSize) { - this._fontSize = json.fontSize; - } - if (json.textColor) { - this._textColor = json.textColor; - } - if (json.fontBold) { - this._fontBold = json.fontBold; - } - if (json.fontItalic) { - this._fontItalic = json.fontItalic; - } - if (json.fontUnderline) { - this._fontUnderline = json.fontUnderline; - } - if (json.textBaseline) { - this._textBaseline = json.textBaseline; - } - if (json.textAlign) { - this._textAlign = json.textAlign; - } - if (json.lineWidth) { - this._lineWidth = json.lineWidth; - } - if (json.lineJoin) { - this._lineJoin = json.lineJoin; - } - if (json.lineCap) { - this._lineCap = json.lineCap; - } - if (json.dashLine) { - this._dashLine = json.dashLine; - } - if (json.lineColor) { - this._lineColor = json.lineColor; - } - if (json.roundRadius) { - this._roundRadius = json.roundRadius; - } - if (json.roundType) { - this._roundType = json.roundType; - } - this.notifyChanged(); - }; - Object.defineProperty(Style.prototype, "backGroundColor", { - get: function () { - return this._backGroundColor; - }, - set: function (value) { - this._backGroundColor = value; - this.notifyChanged(); - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(Style.prototype, "foreGroundColor", { - get: function () { - return this._foreGroundColor; - }, - set: function (value) { - this._foreGroundColor = value; - this.notifyChanged(); - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(Style.prototype, "backGroundImage", { - get: function () { - return this._backGroundImage; - }, - set: function (value) { - this._backGroundImage = value; - this.notifyChanged(); - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(Style.prototype, "backGroundImageDrawType", { - get: function () { - return this._backGroundImageDrawType; - }, - set: function (value) { - this._backGroundImageDrawType = value; - this.notifyChanged(); - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(Style.prototype, "foreGroundImage", { - get: function () { - return this._foreGroundImage; - }, - set: function (value) { - this._foreGroundImage = value; - this.notifyChanged(); - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(Style.prototype, "foreGroundImageDrawType", { - get: function () { - return this._foreGroundImageDrawType; - }, - set: function (value) { - this._foreGroundImageDrawType = value; - this.notifyChanged(); - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(Style.prototype, "font", { - get: function () { - var font = ""; - if (this._fontBold) { - font += "bold "; - } - if (this._fontItalic) { - font += "italic "; - } - font += this._fontSize + "px " + (this._fontFamily || "Sans"); - return font; - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(Style.prototype, "fontFamily", { - get: function () { - return this._fontFamily || "Sans"; - }, - set: function (value) { - this._fontFamily = value; - this.notifyChanged(); - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(Style.prototype, "fontSize", { - get: function () { - return this._fontSize; - }, - set: function (value) { - this._fontSize = value; - this.notifyChanged(); - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(Style.prototype, "textColor", { - get: function () { - return this._textColor; - }, - set: function (value) { - this._textColor = value; - this.notifyChanged(); - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(Style.prototype, "fontBold", { - get: function () { - return this._fontBold; - }, - set: function (value) { - this._fontBold = value; - this.notifyChanged(); - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(Style.prototype, "fontItalic", { - get: function () { - return this._fontItalic; - }, - set: function (value) { - this._fontItalic = value; - this.notifyChanged(); - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(Style.prototype, "fontUnderline", { - get: function () { - return this._fontUnderline; - }, - set: function (value) { - this._fontUnderline = value; - this.notifyChanged(); - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(Style.prototype, "textAlign", { - get: function () { - return this._textAlign || "center"; - }, - set: function (value) { - this._textAlign = value; - this.notifyChanged(); - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(Style.prototype, "textBaseline", { - get: function () { - return this._textBaseline || "middle"; - }, - set: function (value) { - this._textBaseline = value; - this.notifyChanged(); - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(Style.prototype, "lineWidth", { - get: function () { - return this._lineWidth; - }, - set: function (value) { - this._lineWidth = value; - this.notifyChanged(); - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(Style.prototype, "lineJoin", { - get: function () { - return this._lineJoin; - }, - set: function (value) { - this._lineJoin = value; - this.notifyChanged(); - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(Style.prototype, "lineCap", { - get: function () { - return this._lineCap; - }, - set: function (value) { - this._lineCap = value; - this.notifyChanged(); - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(Style.prototype, "dashLine", { - get: function () { - return this._dashLine; - }, - set: function (value) { - this._dashLine = value; - this.notifyChanged(); - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(Style.prototype, "lineColor", { - get: function () { - return this._lineColor; - }, - set: function (value) { - this._lineColor = value; - this.notifyChanged(); - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(Style.prototype, "roundRadius", { - get: function () { - return this._roundRadius; - }, - set: function (value) { - this._roundRadius = value; - this.notifyChanged(); - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(Style.prototype, "roundType", { - get: function () { - return this._roundType; - }, - set: function (value) { - this._roundType = value; - this.notifyChanged(); - }, - enumerable: true, - configurable: true - }); - Style.create = function (json, baseURL) { - var style = new Style(); - if (json) { - style.fromJson(json, baseURL); - } - return style; - }; - Style.fill = function (ctx, fillStyle, h) { - if (!fillStyle || typeof fillStyle === "string") { - ctx.fillStyle = fillStyle; - } - else { - var key = fillStyle + "." + h; - var value = Style.fillStyles[key]; - if (!value) { - var data = fillStyle; - var n = data.length; - var delta = 1 / n; - var value = ctx.createLinearGradient(0, 0, 0, h); - for (var i = 0; i < n; i++) { - var color = data[i]; - value.addColorStop(i * delta, color); - } - Style.fillStyles[key] = value; - } - ctx.fillStyle = value; - } - ctx.fill(); - return; - }; - Style.fillStyles = {}; - return Style; - }(emitter_1.Emitter)); - exports.Style = Style; - ; - - -/***/ }, -/* 4 */ -/***/ function(module, exports, __webpack_require__) { - - /// - "use strict"; - var __extends = (this && this.__extends) || function (d, b) { - for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; - var EventEmitter = __webpack_require__(5); - var EmitterImpl = (function (_super) { - __extends(EmitterImpl, _super); - function EmitterImpl() { - _super.call(this); - } - return EmitterImpl; - }(EventEmitter)); - function toCaptureEventName(name) { - return name + ".capture"; - } - /** - * 事件分发器。 - */ - var Emitter = (function () { - function Emitter() { - this.emitter = new EmitterImpl(); - } - /*** - * 注册事件处理函数。 - * @param type 事件的名称。 - * @param callback 回调函数。 - * @param useCapture 是否注册为capture阶段的处理函数。 - */ - Emitter.prototype.on = function (type, callback, useCapture) { - this.addEventListener(type, callback, useCapture); - }; - /*** - * 注册事件处理函数(只执行一次)。 - * @param type 事件的名称。 - * @param callback 回调函数。 - * @param useCapture 是否注册为capture阶段的处理函数。 - */ - Emitter.prototype.once = function (type, callback) { - this.emitter.once(type, callback, this); - }; - /*** - * 注消事件处理函数。 - * @param type 事件的名称。 - * @param callback 回调函数。 - * @param useCapture 是否注消capture阶段的处理函数。 - */ - Emitter.prototype.off = function (type, callback, useCapture) { - this.removeEventListener(type, callback, useCapture); - }; - /*** - * 注册事件处理函数。 - * @param type 事件的名称。 - * @param callback 回调函数。 - * @param useCapture 是否注册为capture阶段的处理函数。 - */ - Emitter.prototype.addEventListener = function (type, callback, useCapture) { - if (!callback) { - return; - } - if (useCapture) { - this.emitter.addListener(toCaptureEventName(type), callback, this); - } - else { - this.emitter.addListener(type, callback, this); - } - }; - /*** - * 注消事件处理函数。 - * @param type 事件的名称。 - * @param callback 回调函数。 - * @param useCapture 是否注消capture阶段的处理函数。 - */ - Emitter.prototype.removeEventListener = function (type, callback, useCapture) { - if (useCapture) { - this.emitter.removeListener(toCaptureEventName(type), callback, this); - } - else { - this.emitter.removeListener(type, callback, this); - } - }; - /*** - * 分发异步事件。 - * @param evt 事件。 - * @param useCapture 是否触发capture阶段的处理函数。 - */ - Emitter.prototype.dispatchEventAsync = function (evt, useCapture) { - var _this = this; - setTimeout(function (e) { - _this.dispatchEvent(evt, useCapture); - }, 0); - }; - /*** - * 分发事件。 - * @param evt 事件。 - * @param useCapture 是否触发capture阶段的处理函数。 - */ - Emitter.prototype.dispatchEvent = function (evt, useCapture) { - if (evt.propagationStopped) { - console.log("evt.propagationStopped = true;"); - return; - } - var emitter = this.emitter; - if (useCapture) { - emitter.emit(toCaptureEventName(evt.type), evt); - } - else { - emitter.emit(evt.type, evt); - } - }; - Emitter.prototype.removeAllListeners = function (event) { - this.emitter.removeAllListeners(event); - }; - return Emitter; - }()); - exports.Emitter = Emitter; - - -/***/ }, -/* 5 */ -/***/ function(module, exports, __webpack_require__) { - - 'use strict'; - - var has = Object.prototype.hasOwnProperty; - - // - // We store our EE objects in a plain object whose properties are event names. - // If `Object.create(null)` is not supported we prefix the event names with a - // `~` to make sure that the built-in object properties are not overridden or - // used as an attack vector. - // We also assume that `Object.create(null)` is available when the event name - // is an ES6 Symbol. - // - var prefix = typeof Object.create !== 'function' ? '~' : false; - - /** - * Representation of a single EventEmitter function. - * - * @param {Function} fn Event handler to be called. - * @param {Mixed} context Context for function execution. - * @param {Boolean} [once=false] Only emit once - * @api private + * Representation of a single EventEmitter function. + * + * @param {Function} fn Event handler to be called. + * @param {Mixed} context Context for function execution. + * @param {Boolean} [once=false] Only emit once + * @api private */ function EE(fn, context, once) { this.fn = fn; @@ -1426,1002 +1441,1016 @@ var qtk = /* 6 */ /***/ function(module, exports) { - "use strict"; - var __extends = (this && this.__extends) || function (d, b) { - for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; - /** - * 常见事件名称的定义。 - */ - exports.WHEEL = "qtk-wheel"; - exports.KEYUP = "qtk-keyup"; - exports.KEYDOWN = "qtk-keydown"; - exports.CONFIRM = "confirm"; - exports.CONTEXT_MENU = "qtk-context-menu"; - exports.POINTER_DOWN = "qtk-pointer-down"; - exports.POINTER_MOVE = "qtk-pointer-move"; - exports.POINTER_UP = "qtk-pointer-up"; - exports.POINTER_OUT = "qtk-pointer-out"; - exports.POINTER_OVER = "qtk-pointer-over"; - exports.POINTER_ENTER = "qtk-pointer-enter"; - exports.POINTER_LEAVE = "qtk-pointer-leave"; - exports.CLICK = "qtk-click"; - exports.DBLCLICK = "qtk-dblclick"; - exports.CHANGE = "change"; - exports.PROGRESS = "progress"; - exports.CHANGING = "changing"; - exports.PROP_CHANGE = "prop-change"; - exports.PROP_DELETE = "prop-delete"; - exports.ITEMS_CHANGE = "items-change"; - exports.DISPOSE = "dispose"; - exports.RUN = "run"; - exports.QUIT = "quit"; - exports.SHOW = "show"; - exports.HIDE = "hide"; - exports.MOVE = "move-end"; - exports.MOVING = "moving"; - exports.MOVE_END = "move-end"; - exports.MOVE_BEGIN = "move-begin"; - exports.MOVE_CANCEL = "move-cancel"; - exports.CHOOSE = "choose"; - exports.WINDOW_OPEN = "window-open"; - exports.WINDOW_CLOSE = "window-close"; - exports.WINDOW_CREATE = "window-create"; - exports.WINDOW_CREATED = "window-created"; - exports.INIT = "init"; - exports.FOCUS = "focus"; - exports.BLUR = "blur"; - exports.DEINIT = "deinit"; - exports.RESIZE = "resize"; - exports.RESIZING = "resizing"; - exports.RESIZE_END = "resize-end"; - exports.RESIZE_BEGIN = "resize-begin"; - exports.RESIZE_CANCEL = "resize-cancel"; - exports.READY = "ready"; - exports.TICK = "tick"; - exports.PRETICK = "pretick"; - exports.POSTTICK = "posttick"; - exports.LOAD = "load"; - exports.EXPAND = "expand"; - exports.COLLAPSE = "collapse"; - exports.BEFORE_DRAW = "before-draw"; - exports.AFTER_DRAW = "after-draw"; - exports.BEFORE_APPLY_TRANSFORM = "before-apply-transform"; - exports.AFTER_APPLY_TRANSFORM = "after-apply-transform"; - exports.SORT = "sort"; - exports.SCROLL = "scroll"; - exports.SCROLL_DONE = "scroll-done"; - exports.DRAG = "drag"; - exports.DROP = "drop"; - exports.DRAGEND = "dragend"; - exports.DRAGENTER = "dragenter"; - exports.DRAGCANCEL = "dragcancel"; - exports.DRAGLEAVE = "dragleave"; - exports.DRAGOVER = "dragover"; - exports.DRAGSTART = "dragstart"; - exports.SHORTCUT = "shortcut"; - exports.INTERACTION_REQUEST = "interaction-request"; - var Event = (function () { - function Event() { - } - Event.prototype.init = function (type, detail) { - this._type = type; - this._target = null; - this._preventedDefault = false; - this._propagationStopped = false; - return this; - }; - Event.prototype.preventDefault = function () { - this._preventedDefault = true; - }; - Object.defineProperty(Event.prototype, "defaultPrevented", { - get: function () { - return this._preventedDefault; - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(Event.prototype, "propagationStopped", { - get: function () { - return this._propagationStopped; - }, - enumerable: true, - configurable: true - }); - Event.prototype.stopPropagation = function () { - this._propagationStopped = true; - }; - Object.defineProperty(Event.prototype, "type", { - get: function () { - return this._type; - }, - set: function (value) { - this._type = value; - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(Event.prototype, "target", { - get: function () { - return this._target; - }, - set: function (value) { - this._target = value; - }, - enumerable: true, - configurable: true - }); - Event.prototype.dispose = function () { - }; - return Event; - }()); - exports.Event = Event; - ; - var AnyEvent = (function (_super) { - __extends(AnyEvent, _super); - function AnyEvent() { - _super.apply(this, arguments); - } - AnyEvent.prototype.init = function (type, payload) { - _super.prototype.init.call(this, type); - this.payload = payload; - return this; - }; - AnyEvent.create = function (type, payload) { - var e = new AnyEvent(); - return e.init(type, payload); - }; - return AnyEvent; - }(Event)); - exports.AnyEvent = AnyEvent; - ; - /** - * View Model请求显示指定的视图或跳转到指定的视图。 - */ - var InteractionRequestEvent = (function (_super) { - __extends(InteractionRequestEvent, _super); - function InteractionRequestEvent() { - _super.apply(this, arguments); - } - ; - InteractionRequestEvent.prototype.returnResult = function () { - if (this._callback) { - this._callback(this.payload); - } - }; - InteractionRequestEvent.prototype.init = function (type, detail) { - _super.prototype.init.call(this, type); - this.name = detail.name; - this.payload = detail.payload; - this._callback = detail.callback; - return this; - }; - InteractionRequestEvent.create = function (type, detail) { - var e = new InteractionRequestEvent(); - return e.init(type, detail); - }; - return InteractionRequestEvent; - }(Event)); - exports.InteractionRequestEvent = InteractionRequestEvent; - ; - var InputEvent = (function (_super) { - __extends(InputEvent, _super); - function InputEvent() { - _super.apply(this, arguments); - } - InputEvent.prototype.init = function (type, detail) { - _super.prototype.init.call(this, type); - this.altKey = detail.altKey; - this.ctrlKey = detail.ctrlKey; - this.shiftKey = detail.shiftKey; - this.commandKey = detail.commandKey; - return this; - }; - return InputEvent; - }(Event)); - exports.InputEvent = InputEvent; - ; - var PointerEvent = (function (_super) { - __extends(PointerEvent, _super); - function PointerEvent() { - _super.apply(this, arguments); - } - PointerEvent.prototype.init = function (type, detail) { - _super.prototype.init.call(this, type, detail); - this.id = detail.id; - this.x = detail.x; - this.y = detail.y; - this.localX = detail.x; - this.localY = detail.y; - this.timeStamp = detail.timeStamp; - this.pointerDown = detail.pointerDown; - this.pointerDownX = detail.pointerDownX; - this.pointerDownY = detail.pointerDownY; - this.pointerDownTime = detail.pointerDownTime; - this.dx = detail.x - detail.pointerDownX; - this.dy = detail.y - detail.pointerDownY; - return this; - }; - PointerEvent.create = function (type, detail) { - var e = new PointerEvent(); - return e.init(type, detail); - }; - return PointerEvent; - }(InputEvent)); - exports.PointerEvent = PointerEvent; - var WheelEvent = (function (_super) { - __extends(WheelEvent, _super); - function WheelEvent() { - _super.apply(this, arguments); - } - WheelEvent.prototype.init = function (type, detail) { - _super.prototype.init.call(this, type, detail); - this.delta = detail.delta; - this.timeStamp = detail.timeStamp; - return this; - }; - WheelEvent.create = function (detail) { - var e = new WheelEvent(); - return e.init(exports.WHEEL, detail); - }; - return WheelEvent; - }(InputEvent)); - exports.WheelEvent = WheelEvent; - var KeyEvent = (function (_super) { - __extends(KeyEvent, _super); - function KeyEvent() { - _super.apply(this, arguments); - } - KeyEvent.prototype.init = function (type, detail) { - _super.prototype.init.call(this, type, detail); - this.keyCode = detail.keyCode; - this.timeStamp = detail.timeStamp; - return this; - }; - KeyEvent.create = function (type, detail) { - var e = new KeyEvent(); - return e.init(type, detail); - }; - return KeyEvent; - }(InputEvent)); - exports.KeyEvent = KeyEvent; - var ShortcutEvent = (function (_super) { - __extends(ShortcutEvent, _super); - function ShortcutEvent() { - _super.apply(this, arguments); - } - ShortcutEvent.prototype.init = function (type, keys) { - _super.prototype.init.call(this, type, {}); - this.keys = keys; - return this; - }; - ShortcutEvent.create = function (type, keys) { - var e = new ShortcutEvent(); - return e.init(type, keys); - }; - return ShortcutEvent; - }(Event)); - exports.ShortcutEvent = ShortcutEvent; - var TickEvent = (function (_super) { - __extends(TickEvent, _super); - function TickEvent() { - _super.apply(this, arguments); - } - TickEvent.prototype.init = function (type, detail) { - _super.prototype.init.call(this, type); - this.fps = detail.fps; - this.time = detail.time; - this.deltaTime = detail.deltaTime; - return this; - }; - TickEvent.create = function (type) { - var e = new TickEvent(); - return e.init(type, {}); - }; - return TickEvent; - }(Event)); - exports.TickEvent = TickEvent; - ; - var ChangeEvent = (function (_super) { - __extends(ChangeEvent, _super); - function ChangeEvent() { - _super.apply(this, arguments); - } - ChangeEvent.prototype.init = function (type, detail) { - _super.prototype.init.call(this, type); - var value = detail.newValue === undefined ? detail.value : detail.newValue; - this.value = value; - this.newValue = value; - this.oldValue = detail.oldValue; - return this; - }; - ChangeEvent.create = function () { - var e = new ChangeEvent(); - return e; - }; - return ChangeEvent; - }(Event)); - exports.ChangeEvent = ChangeEvent; - ; - var PropChangeEvent = (function (_super) { - __extends(PropChangeEvent, _super); - function PropChangeEvent() { - _super.apply(this, arguments); - } - PropChangeEvent.prototype.init = function (type, detail) { - _super.prototype.init.call(this, type, detail); - this.prop = detail.prop; - this.trigger = detail.trigger; - return this; - }; - PropChangeEvent.create = function () { - var e = new PropChangeEvent(); - return e; - }; - return PropChangeEvent; - }(ChangeEvent)); - exports.PropChangeEvent = PropChangeEvent; - ; - var DataTransfer = (function () { - function DataTransfer() { - this.data = {}; - this.dragImage = null; - this.dropEffect = "move"; - } - DataTransfer.prototype.clearData = function (format) { - if (format) { - delete this.data[format]; - } - else { - this.data = {}; - } - }; - DataTransfer.prototype.getData = function (format) { - return this.data[format]; - }; - DataTransfer.prototype.setData = function (format, data) { - this.data[format] = data; - }; - DataTransfer.prototype.setDragImage = function (dragImage) { - this.dragImage = dragImage; - }; - return DataTransfer; - }()); - exports.DataTransfer = DataTransfer; - ; - var DragEvent = (function (_super) { - __extends(DragEvent, _super); - function DragEvent() { - _super.call(this); - this.dataTransfer = new DataTransfer(); - } - DragEvent.prototype.init = function (type, detail) { - _super.prototype.init.call(this, type, detail); - this.x = detail.x; - this.y = detail.y; - return this; - }; - Object.defineProperty(DragEvent, "isDragging", { - get: function () { - return DragEvent._isDragging; - }, - set: function (isDragging) { - DragEvent._isDragging = isDragging; - }, - enumerable: true, - configurable: true - }); - DragEvent.get = function (type, x, y) { - var e = DragEvent.event; - return e.init(type, { x: x, y: y }); - }; - DragEvent._isDragging = false; - DragEvent.event = new DragEvent(); - return DragEvent; - }(Event)); - exports.DragEvent = DragEvent; - ; - var DrawEvent = (function (_super) { - __extends(DrawEvent, _super); - function DrawEvent() { - _super.apply(this, arguments); - } - DrawEvent.prototype.reset = function (type, ctx, widget) { - _super.prototype.init.call(this, type); - this.ctx = ctx; - this.widget = widget; - return this; - }; - DrawEvent.get = function () { - return DrawEvent.event; - }; - DrawEvent.event = new DrawEvent(); - return DrawEvent; - }(Event)); - exports.DrawEvent = DrawEvent; - ; - var ApplyTransformEvent = (function (_super) { - __extends(ApplyTransformEvent, _super); - function ApplyTransformEvent() { - _super.apply(this, arguments); - } - ApplyTransformEvent.prototype.reset = function (type, ctx, widget) { - _super.prototype.init.call(this, type); - this.ctx = ctx; - this.widget = widget; - return this; - }; - ApplyTransformEvent.get = function () { - return ApplyTransformEvent.event; - }; - ApplyTransformEvent.event = new ApplyTransformEvent(); - return ApplyTransformEvent; - }(Event)); - exports.ApplyTransformEvent = ApplyTransformEvent; - ; - var ScrollEvent = (function (_super) { - __extends(ScrollEvent, _super); - function ScrollEvent() { - _super.apply(this, arguments); - } - ScrollEvent.prototype.reset = function (type, widget, offsetX, offsetY) { - _super.prototype.init.call(this, type); - this.widget = widget; - this.offsetX = offsetX; - this.offsetY = offsetY; - return this; - }; - ScrollEvent.create = function () { - return new ScrollEvent(); - }; - return ScrollEvent; - }(Event)); - exports.ScrollEvent = ScrollEvent; - ; - var WindowEvent = (function (_super) { - __extends(WindowEvent, _super); - function WindowEvent() { - _super.apply(this, arguments); - } - WindowEvent.prototype.reset = function (type, widget) { - _super.prototype.init.call(this, type); - this.widget = widget; - return this; - }; - WindowEvent.create = function () { - return new WindowEvent(); - }; - return WindowEvent; - }(Event)); - exports.WindowEvent = WindowEvent; - ; - var ProgressEvent = (function (_super) { - __extends(ProgressEvent, _super); - function ProgressEvent() { - _super.apply(this, arguments); - } - ProgressEvent.prototype.reset = function (progress, total, done) { - _super.prototype.init.call(this, exports.PROGRESS); - this.done = done; - this.total = total; - this.progress = progress; - return this; - }; - ProgressEvent.create = function () { - return new ProgressEvent(); - }; - return ProgressEvent; - }(Event)); - exports.ProgressEvent = ProgressEvent; - ; - /** - * 排序事件 - */ - var SortEvent = (function (_super) { - __extends(SortEvent, _super); - function SortEvent() { - _super.apply(this, arguments); - } - SortEvent.prototype.init = function (key, isDec) { - _super.prototype.init.call(this, exports.SORT); - this.key = key; - this.isDec = isDec; - return this; - }; - SortEvent.create = function (key, isDec) { - var e = new SortEvent(); - return e.init(key, isDec); - }; - return SortEvent; - }(Event)); - exports.SortEvent = SortEvent; - ; - function createAnyEvent(type, payload) { - return AnyEvent.create(type, payload); - } - exports.createAnyEvent = createAnyEvent; - var eventsMapToType = { - click: exports.CLICK, - keydown: exports.KEYDOWN, - keyup: exports.KEYUP, - confirm: exports.CONFIRM, - change: exports.CHANGE, - chaning: exports.CHANGING, - dblclick: exports.DBLCLICK, - pointerup: exports.POINTER_UP, - pointermove: exports.POINTER_MOVE, - pointerdown: exports.POINTER_DOWN, - pointerenter: exports.POINTER_ENTER, - pointerleave: exports.POINTER_LEAVE - }; - function mapToEvent(name) { - return eventsMapToType[name]; - } - exports.mapToEvent = mapToEvent; + "use strict"; + var __extends = (this && this.__extends) || (function () { + var extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + return function (d, b) { + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; + })(); + Object.defineProperty(exports, "__esModule", { value: true }); + /** + * 常见事件名称的定义。 + */ + exports.WHEEL = "qtk-wheel"; + exports.KEYUP = "qtk-keyup"; + exports.KEYDOWN = "qtk-keydown"; + exports.CONFIRM = "confirm"; + exports.CONTEXT_MENU = "qtk-context-menu"; + exports.POINTER_DOWN = "qtk-pointer-down"; + exports.POINTER_MOVE = "qtk-pointer-move"; + exports.POINTER_UP = "qtk-pointer-up"; + exports.POINTER_OUT = "qtk-pointer-out"; + exports.POINTER_OVER = "qtk-pointer-over"; + exports.POINTER_ENTER = "qtk-pointer-enter"; + exports.POINTER_LEAVE = "qtk-pointer-leave"; + exports.CLICK = "qtk-click"; + exports.DBLCLICK = "qtk-dblclick"; + exports.CHANGE = "change"; + exports.PROGRESS = "progress"; + exports.CHANGING = "changing"; + exports.PROP_CHANGE = "prop-change"; + exports.PROP_DELETE = "prop-delete"; + exports.ITEMS_CHANGE = "items-change"; + exports.DISPOSE = "dispose"; + exports.RUN = "run"; + exports.QUIT = "quit"; + exports.SHOW = "show"; + exports.HIDE = "hide"; + exports.MOVE = "move-end"; + exports.MOVING = "moving"; + exports.MOVE_END = "move-end"; + exports.MOVE_BEGIN = "move-begin"; + exports.MOVE_CANCEL = "move-cancel"; + exports.CHOOSE = "choose"; + exports.WINDOW_OPEN = "window-open"; + exports.WINDOW_CLOSE = "window-close"; + exports.WINDOW_CREATE = "window-create"; + exports.WINDOW_CREATED = "window-created"; + exports.INIT = "init"; + exports.FOCUS = "focus"; + exports.BLUR = "blur"; + exports.DEINIT = "deinit"; + exports.RESIZE = "resize"; + exports.RESIZING = "resizing"; + exports.RESIZE_END = "resize-end"; + exports.RESIZE_BEGIN = "resize-begin"; + exports.RESIZE_CANCEL = "resize-cancel"; + exports.READY = "ready"; + exports.TICK = "tick"; + exports.PRETICK = "pretick"; + exports.POSTTICK = "posttick"; + exports.LOAD = "load"; + exports.EXPAND = "expand"; + exports.COLLAPSE = "collapse"; + exports.BEFORE_DRAW = "before-draw"; + exports.AFTER_DRAW = "after-draw"; + exports.BEFORE_APPLY_TRANSFORM = "before-apply-transform"; + exports.AFTER_APPLY_TRANSFORM = "after-apply-transform"; + exports.SORT = "sort"; + exports.SCROLL = "scroll"; + exports.SCROLL_DONE = "scroll-done"; + exports.DRAG = "drag"; + exports.DROP = "drop"; + exports.DRAGEND = "dragend"; + exports.DRAGENTER = "dragenter"; + exports.DRAGCANCEL = "dragcancel"; + exports.DRAGLEAVE = "dragleave"; + exports.DRAGOVER = "dragover"; + exports.DRAGSTART = "dragstart"; + exports.SHORTCUT = "shortcut"; + exports.INTERACTION_REQUEST = "interaction-request"; + var Event = (function () { + function Event() { + } + Event.prototype.init = function (type, detail) { + this._type = type; + this._target = null; + this._preventedDefault = false; + this._propagationStopped = false; + return this; + }; + Event.prototype.preventDefault = function () { + this._preventedDefault = true; + }; + Object.defineProperty(Event.prototype, "defaultPrevented", { + get: function () { + return this._preventedDefault; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Event.prototype, "propagationStopped", { + get: function () { + return this._propagationStopped; + }, + enumerable: true, + configurable: true + }); + Event.prototype.stopPropagation = function () { + this._propagationStopped = true; + }; + Object.defineProperty(Event.prototype, "type", { + get: function () { + return this._type; + }, + set: function (value) { + this._type = value; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Event.prototype, "target", { + get: function () { + return this._target; + }, + set: function (value) { + this._target = value; + }, + enumerable: true, + configurable: true + }); + Event.prototype.dispose = function () { + }; + return Event; + }()); + exports.Event = Event; + ; + var AnyEvent = (function (_super) { + __extends(AnyEvent, _super); + function AnyEvent() { + return _super !== null && _super.apply(this, arguments) || this; + } + AnyEvent.prototype.init = function (type, payload) { + _super.prototype.init.call(this, type); + this.payload = payload; + return this; + }; + AnyEvent.create = function (type, payload) { + var e = new AnyEvent(); + return e.init(type, payload); + }; + return AnyEvent; + }(Event)); + exports.AnyEvent = AnyEvent; + ; + /** + * View Model请求显示指定的视图或跳转到指定的视图。 + */ + var InteractionRequestEvent = (function (_super) { + __extends(InteractionRequestEvent, _super); + function InteractionRequestEvent() { + return _super !== null && _super.apply(this, arguments) || this; + } + ; + InteractionRequestEvent.prototype.returnResult = function () { + if (this._callback) { + this._callback(this.payload); + } + }; + InteractionRequestEvent.prototype.init = function (type, detail) { + _super.prototype.init.call(this, type); + this.name = detail.name; + this.payload = detail.payload; + this._callback = detail.callback; + return this; + }; + InteractionRequestEvent.create = function (type, detail) { + var e = new InteractionRequestEvent(); + return e.init(type, detail); + }; + return InteractionRequestEvent; + }(Event)); + exports.InteractionRequestEvent = InteractionRequestEvent; + ; + var InputEvent = (function (_super) { + __extends(InputEvent, _super); + function InputEvent() { + return _super !== null && _super.apply(this, arguments) || this; + } + InputEvent.prototype.init = function (type, detail) { + _super.prototype.init.call(this, type); + this.altKey = detail.altKey; + this.ctrlKey = detail.ctrlKey; + this.shiftKey = detail.shiftKey; + this.commandKey = detail.commandKey; + return this; + }; + return InputEvent; + }(Event)); + exports.InputEvent = InputEvent; + ; + var PointerEvent = (function (_super) { + __extends(PointerEvent, _super); + function PointerEvent() { + return _super !== null && _super.apply(this, arguments) || this; + } + PointerEvent.prototype.init = function (type, detail) { + _super.prototype.init.call(this, type, detail); + this.id = detail.id; + this.x = detail.x; + this.y = detail.y; + this.localX = detail.x; + this.localY = detail.y; + this.timeStamp = detail.timeStamp; + this.pointerDown = detail.pointerDown; + this.pointerDownX = detail.pointerDownX; + this.pointerDownY = detail.pointerDownY; + this.pointerDownTime = detail.pointerDownTime; + this.dx = detail.x - detail.pointerDownX; + this.dy = detail.y - detail.pointerDownY; + return this; + }; + PointerEvent.create = function (type, detail) { + var e = new PointerEvent(); + return e.init(type, detail); + }; + return PointerEvent; + }(InputEvent)); + exports.PointerEvent = PointerEvent; + var WheelEvent = (function (_super) { + __extends(WheelEvent, _super); + function WheelEvent() { + return _super !== null && _super.apply(this, arguments) || this; + } + WheelEvent.prototype.init = function (type, detail) { + _super.prototype.init.call(this, type, detail); + this.delta = detail.delta; + this.timeStamp = detail.timeStamp; + return this; + }; + WheelEvent.create = function (detail) { + var e = new WheelEvent(); + return e.init(exports.WHEEL, detail); + }; + return WheelEvent; + }(InputEvent)); + exports.WheelEvent = WheelEvent; + var KeyEvent = (function (_super) { + __extends(KeyEvent, _super); + function KeyEvent() { + return _super !== null && _super.apply(this, arguments) || this; + } + KeyEvent.prototype.init = function (type, detail) { + _super.prototype.init.call(this, type, detail); + this.keyCode = detail.keyCode; + this.timeStamp = detail.timeStamp; + return this; + }; + KeyEvent.create = function (type, detail) { + var e = new KeyEvent(); + return e.init(type, detail); + }; + return KeyEvent; + }(InputEvent)); + exports.KeyEvent = KeyEvent; + var ShortcutEvent = (function (_super) { + __extends(ShortcutEvent, _super); + function ShortcutEvent() { + return _super !== null && _super.apply(this, arguments) || this; + } + ShortcutEvent.prototype.init = function (type, keys) { + _super.prototype.init.call(this, type, {}); + this.keys = keys; + return this; + }; + ShortcutEvent.create = function (type, keys) { + var e = new ShortcutEvent(); + return e.init(type, keys); + }; + return ShortcutEvent; + }(Event)); + exports.ShortcutEvent = ShortcutEvent; + var TickEvent = (function (_super) { + __extends(TickEvent, _super); + function TickEvent() { + return _super !== null && _super.apply(this, arguments) || this; + } + TickEvent.prototype.init = function (type, detail) { + _super.prototype.init.call(this, type); + this.fps = detail.fps; + this.time = detail.time; + this.deltaTime = detail.deltaTime; + return this; + }; + TickEvent.create = function (type) { + var e = new TickEvent(); + return e.init(type, {}); + }; + return TickEvent; + }(Event)); + exports.TickEvent = TickEvent; + ; + var ChangeEvent = (function (_super) { + __extends(ChangeEvent, _super); + function ChangeEvent() { + return _super !== null && _super.apply(this, arguments) || this; + } + ChangeEvent.prototype.init = function (type, detail) { + _super.prototype.init.call(this, type); + var value = detail.newValue === undefined ? detail.value : detail.newValue; + this.value = value; + this.newValue = value; + this.oldValue = detail.oldValue; + return this; + }; + ChangeEvent.create = function () { + var e = new ChangeEvent(); + return e; + }; + return ChangeEvent; + }(Event)); + exports.ChangeEvent = ChangeEvent; + ; + var PropChangeEvent = (function (_super) { + __extends(PropChangeEvent, _super); + function PropChangeEvent() { + return _super !== null && _super.apply(this, arguments) || this; + } + PropChangeEvent.prototype.init = function (type, detail) { + _super.prototype.init.call(this, type, detail); + this.prop = detail.prop; + this.trigger = detail.trigger; + return this; + }; + PropChangeEvent.create = function () { + var e = new PropChangeEvent(); + return e; + }; + return PropChangeEvent; + }(ChangeEvent)); + exports.PropChangeEvent = PropChangeEvent; + ; + var DataTransfer = (function () { + function DataTransfer() { + this.data = {}; + this.dragImage = null; + this.dropEffect = "move"; + } + DataTransfer.prototype.clearData = function (format) { + if (format) { + delete this.data[format]; + } + else { + this.data = {}; + } + }; + DataTransfer.prototype.getData = function (format) { + return this.data[format]; + }; + DataTransfer.prototype.setData = function (format, data) { + this.data[format] = data; + }; + DataTransfer.prototype.setDragImage = function (dragImage) { + this.dragImage = dragImage; + }; + return DataTransfer; + }()); + exports.DataTransfer = DataTransfer; + ; + var DragEvent = (function (_super) { + __extends(DragEvent, _super); + function DragEvent() { + var _this = _super.call(this) || this; + _this.dataTransfer = new DataTransfer(); + return _this; + } + DragEvent.prototype.init = function (type, detail) { + _super.prototype.init.call(this, type, detail); + this.x = detail.x; + this.y = detail.y; + return this; + }; + Object.defineProperty(DragEvent, "isDragging", { + get: function () { + return DragEvent._isDragging; + }, + set: function (isDragging) { + DragEvent._isDragging = isDragging; + }, + enumerable: true, + configurable: true + }); + DragEvent.get = function (type, x, y) { + var e = DragEvent.event; + return e.init(type, { x: x, y: y }); + }; + return DragEvent; + }(Event)); + DragEvent._isDragging = false; + DragEvent.event = new DragEvent(); + exports.DragEvent = DragEvent; + ; + var DrawEvent = (function (_super) { + __extends(DrawEvent, _super); + function DrawEvent() { + return _super !== null && _super.apply(this, arguments) || this; + } + DrawEvent.prototype.reset = function (type, ctx, widget) { + _super.prototype.init.call(this, type); + this.ctx = ctx; + this.widget = widget; + return this; + }; + DrawEvent.get = function () { + return DrawEvent.event; + }; + return DrawEvent; + }(Event)); + DrawEvent.event = new DrawEvent(); + exports.DrawEvent = DrawEvent; + ; + var ApplyTransformEvent = (function (_super) { + __extends(ApplyTransformEvent, _super); + function ApplyTransformEvent() { + return _super !== null && _super.apply(this, arguments) || this; + } + ApplyTransformEvent.prototype.reset = function (type, ctx, widget) { + _super.prototype.init.call(this, type); + this.ctx = ctx; + this.widget = widget; + return this; + }; + ApplyTransformEvent.get = function () { + return ApplyTransformEvent.event; + }; + return ApplyTransformEvent; + }(Event)); + ApplyTransformEvent.event = new ApplyTransformEvent(); + exports.ApplyTransformEvent = ApplyTransformEvent; + ; + var ScrollEvent = (function (_super) { + __extends(ScrollEvent, _super); + function ScrollEvent() { + return _super !== null && _super.apply(this, arguments) || this; + } + ScrollEvent.prototype.reset = function (type, widget, offsetX, offsetY) { + _super.prototype.init.call(this, type); + this.widget = widget; + this.offsetX = offsetX; + this.offsetY = offsetY; + return this; + }; + ScrollEvent.create = function () { + return new ScrollEvent(); + }; + return ScrollEvent; + }(Event)); + exports.ScrollEvent = ScrollEvent; + ; + var WindowEvent = (function (_super) { + __extends(WindowEvent, _super); + function WindowEvent() { + return _super !== null && _super.apply(this, arguments) || this; + } + WindowEvent.prototype.reset = function (type, widget) { + _super.prototype.init.call(this, type); + this.widget = widget; + return this; + }; + WindowEvent.create = function () { + return new WindowEvent(); + }; + return WindowEvent; + }(Event)); + exports.WindowEvent = WindowEvent; + ; + var ProgressEvent = (function (_super) { + __extends(ProgressEvent, _super); + function ProgressEvent() { + return _super !== null && _super.apply(this, arguments) || this; + } + ProgressEvent.prototype.reset = function (progress, total, done) { + _super.prototype.init.call(this, exports.PROGRESS); + this.done = done; + this.total = total; + this.progress = progress; + return this; + }; + ProgressEvent.create = function () { + return new ProgressEvent(); + }; + return ProgressEvent; + }(Event)); + exports.ProgressEvent = ProgressEvent; + ; + /** + * 排序事件 + */ + var SortEvent = (function (_super) { + __extends(SortEvent, _super); + function SortEvent() { + return _super !== null && _super.apply(this, arguments) || this; + } + SortEvent.prototype.init = function (key, isDec) { + _super.prototype.init.call(this, exports.SORT); + this.key = key; + this.isDec = isDec; + return this; + }; + SortEvent.create = function (key, isDec) { + var e = new SortEvent(); + return e.init(key, isDec); + }; + return SortEvent; + }(Event)); + exports.SortEvent = SortEvent; + ; + function createAnyEvent(type, payload) { + return AnyEvent.create(type, payload); + } + exports.createAnyEvent = createAnyEvent; + var eventsMapToType = { + click: exports.CLICK, + keydown: exports.KEYDOWN, + keyup: exports.KEYUP, + confirm: exports.CONFIRM, + change: exports.CHANGE, + chaning: exports.CHANGING, + dblclick: exports.DBLCLICK, + pointerup: exports.POINTER_UP, + pointermove: exports.POINTER_MOVE, + pointerdown: exports.POINTER_DOWN, + pointerenter: exports.POINTER_ENTER, + pointerleave: exports.POINTER_LEAVE + }; + function mapToEvent(name) { + return eventsMapToType[name]; + } + exports.mapToEvent = mapToEvent; /***/ }, /* 7 */ /***/ function(module, exports, __webpack_require__) { - /// - /// - "use strict"; - var __extends = (this && this.__extends) || function (d, b) { - for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; - __webpack_require__(8); - var path = __webpack_require__(9); - var emitter_1 = __webpack_require__(4); - var assets_1 = __webpack_require__(11); - var Events = __webpack_require__(6); - (function (ImageDrawType) { - /** - * 画在填满指定的矩形区域。 - */ - ImageDrawType[ImageDrawType["DEFAULT"] = 1] = "DEFAULT"; - /** - * 按1比1大小画在指定的矩形区域的中间。 - */ - ImageDrawType[ImageDrawType["CENTER"] = 2] = "CENTER"; - /** - * 把图分成3行3列等大小的区域,按9宫格的方式填满指定的矩形区域。 - */ - ImageDrawType[ImageDrawType["PATCH9"] = 3] = "PATCH9"; - /** - * 把图分成3行1列等大小的区域,按3宫格的方式填满指定的矩形区域。 - */ - ImageDrawType[ImageDrawType["PATCH3_V"] = 4] = "PATCH3_V"; - /** - * 把图分成1行1列等大小的区域,按3宫格的方式填满指定的矩形区域。 - */ - ImageDrawType[ImageDrawType["PATCH3_H"] = 5] = "PATCH3_H"; - /** - * 按平铺的方式填满指定的矩形区域。 - */ - ImageDrawType[ImageDrawType["TILE"] = 6] = "TILE"; - /** - * 按垂直平铺的方式填满指定的矩形区域。 - */ - ImageDrawType[ImageDrawType["TILE_V"] = 7] = "TILE_V"; - /** - * 按水平平铺的方式填满指定的矩形区域。 - */ - ImageDrawType[ImageDrawType["TILE_H"] = 8] = "TILE_H"; - /** - * 保持比例缩放到指定的矩形区域。 - */ - ImageDrawType[ImageDrawType["AUTO"] = 9] = "AUTO"; - /** - * ICON - */ - ImageDrawType[ImageDrawType["ICON"] = 10] = "ICON"; - })(exports.ImageDrawType || (exports.ImageDrawType = {})); - var ImageDrawType = exports.ImageDrawType; - /** - * 把多个小的图片合并成一张大图,不但可以减少网路请求和GPU的调用次数,还可以提高内存的利用率。 - * ImageTile用来表示大图中的一张小图,QTK中支持下面几种方式: - * - * 0.普通图片。如果URL中没有#,则表示一张普通图片,它的位置为(0,0),大小为图片的整个大小。 - * - * 1.指定子图的位置和大小,#之前的部分是大图的URL,后面是子图的位置和大小信息。 - * 字母x后紧跟x坐标,字母y后紧跟y坐标,字母w后紧跟宽度,字母h后紧跟高度。 - * 下面的URL表示图片demo.png中位置为(100,200),大小为(300,400)的子图。 - * - * ``` - * https://qtoolkit.github.io/demo.png#x100y200w300h400 - * ``` - * - * 2.指定图片的行列数以及小图的序数,#之前的部分是大图的URL,后面是行数、列数和序数。 - * 字母r紧跟行数,字母c后紧跟列数,字母i后紧跟序数。 - * - * 下面的URL表示图片demo.png分成3行3列,序数为0的子图。 - * - * ``` - * https://qtoolkit.github.io/demo.png#r3c3i0 - * ``` - * - * 3.用TexturePacker打包的JSON Hash格式。#之前部分是JSON的URL,后面是子图的名称。如: - * - * ``` - * https://qtoolkit.github.io/demo.json#demo.png - * ``` - * - * - */ - var ImageTile = (function (_super) { - __extends(ImageTile, _super); - function ImageTile(src) { - _super.call(this); - this.x = 0; - this.y = 0; - this.w = 0; - this.h = 0; - this._id = 0; - this.img = null; - this.src = src; - if (src) { - this.create(src); - } - } - ImageTile.prototype.toJson = function () { - return this.src; - }; - ImageTile.prototype.create = function (src) { - var index = src.indexOf('#'); - if (index < 0) { - this.createNormal(src); - } - else { - var base = src.substr(0, index); - var ext = src.substr(index + 1); - if (ext[0] === 'x') { - this.createXYWH(base, ext); - } - else if (ext[0] === 'r') { - this.createRowColIndex(base, ext); - } - else { - this.createTexturePacker(base, ext); - } - } - }; - ImageTile.prototype.init = function (img, x, y, w, h) { - this.x = x; - this.y = y; - this.w = w; - this.h = h; - this.img = img; - if (ImageTile.onImageLoaded) { - ImageTile.onImageLoaded(this); - } - this.dispatchEventAsync({ type: Events.LOAD, detail: this }); - }; - Object.defineProperty(ImageTile.prototype, "complete", { - get: function () { - return this.img && this.img.width; - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(ImageTile.prototype, "id", { - get: function () { - return this._id; - }, - set: function (id) { - this._id = id; - if (this.img) { - this.img.imgID = id; - } - }, - enumerable: true, - configurable: true - }); - ImageTile.prototype.createNormal = function (src) { - var _this = this; - assets_1.AssetManager.loadImage(src).then(function (img) { - _this.init(img, 0, 0, img.width, img.height); - }).catch(function (err) { - _this.init(null, 0, 0, 0, 0); - }); - }; - ImageTile.prototype.createXYWH = function (base, meta) { - var _this = this; - var xywh = meta.match(/x([0-9]+)y([0-9]+)w([0-9]+)h([0-9]+)/i); - var x = parseInt(xywh[1]); - var y = parseInt(xywh[2]); - var w = parseInt(xywh[3]); - var h = parseInt(xywh[4]); - assets_1.AssetManager.loadImage(base).then(function (img) { - _this.init(img, x, y, w, h); - }).catch(function (err) { - _this.init(null, 0, 0, 0, 0); - }); - }; - ImageTile.prototype.createRowColIndex = function (base, meta) { - var _this = this; - var rowcolIndex = meta.match(/r([0-9]+)c([0-9]+)i([0-9]+)/i); - var rows = parseInt(rowcolIndex[1]); - var cols = parseInt(rowcolIndex[2]); - var index = parseInt(rowcolIndex[3]); - assets_1.AssetManager.loadImage(base).then(function (img) { - var w = img.width / cols; - var h = img.height / rows; - var r = (index / cols) >> 0; - var c = index % cols; - var x = c * w; - var y = r * h; - _this.init(img, x, y, w, h); - }).catch(function (err) { - _this.init(null, 0, 0, 0, 0); - }); - }; - ImageTile.prototype.createTexturePacker = function (jsonURL, name) { - var _this = this; - assets_1.AssetManager.loadJson(jsonURL).then(function (json) { - var info = json.frames[name]; - var imgSRC = path.dirname(jsonURL) + "/" + (json.file || json.meta.image); - assets_1.AssetManager.loadImage(imgSRC).then(function (img) { - var rect = info.frame || info; - var x = rect.x; - var y = rect.y; - var w = rect.w; - var h = rect.h; - if (!info.trimmed && !info.rotate) { - _this.init(img, x, y, w, h); - } - else { - console.log("Not support trimmed mode or rotated mode"); - _this.init(null, 0, 0, 0, 0); - } - }).catch(function (err) { - _this.init(null, 0, 0, 0, 0); - }); - }).catch(function (err) { - _this.init(null, 0, 0, 0, 0); - }); - }; - ImageTile.prototype.drawDefault = function (ctx, dx, dy, dw, dh) { - ctx.drawImage(this.img, this.x, this.y, this.w, this.h, dx, dy, dw, dh); - }; - ImageTile.prototype.drawIcon = function (ctx, dx, dy, dw, dh) { - var cx = dx + (dw >> 1); - var cy = dy + (dh >> 1); - var x = dx + ((dw - this.w) >> 1); - var y = dy + ((dh - this.h) >> 1); - ctx.save(); - ctx.translate(cx, cy); - ctx.scale(ImageTile.scale, ImageTile.scale); - ctx.translate(-cx, -cy); - ctx.drawImage(this.img, this.x, this.y, this.w, this.h, x, y, this.w, this.h); - ctx.restore(); - }; - ImageTile.prototype.drawCenter = function (ctx, dx, dy, dw, dh) { - var x = dx + ((dw - this.w) >> 1); - var y = dy + ((dh - this.h) >> 1); - ctx.drawImage(this.img, this.x, this.y, this.w, this.h, x, y, this.w, this.h); - }; - ImageTile.prototype.drawAuto = function (ctx, dx, dy, dw, dh) { - var x = dx; - var y = dy; - var w = 0; - var h = 0; - var scaleX = dw / this.w; - var scaleY = dh / this.h; - if (scaleX >= scaleY) { - h = dh; - w = scaleY * this.w; - x += ((dw - w) >> 1); - } - else { - w = dw; - h = scaleX * this.h; - y += ((dh - h) >> 1); - } - ctx.drawImage(this.img, this.x, this.y, this.w, this.h, x, y, w, h); - }; - ImageTile.prototype.draw3PatchH = function (ctx, dx, dy, dw, dh) { - var w = Math.min(dw >> 1, (this.w / 3) >> 0); - ctx.drawImage(this.img, this.x, this.y, w, this.h, dx, dy, w, dh); - ctx.drawImage(this.img, this.x + this.w - w, this.y, w, this.h, dx + dw - w, dy, w, dh); - var cw = dw - w - w; - if (cw > 0) { - ctx.drawImage(this.img, this.x + w, this.y, w, this.h, dx + w, dy, cw, dh); - } - }; - ImageTile.prototype.draw9Patch = function (ctx, dx, dy, dw, dh) { - var w = Math.min(dw >> 1, (this.w / 3) >> 0); - var h = Math.min(dh >> 1, (this.h / 3) >> 0); - var cw = dw - w - w; - var ch = dh - h - h; - var rightSX = this.x + this.w - w; - var rightDX = dx + dw - w; - var bottomSY = this.y + this.h - h; - var bottomDY = dy + dh - h; - ctx.drawImage(this.img, this.x, this.y, w, h, dx, dy, w, h); - ctx.drawImage(this.img, rightSX, this.y, w, h, rightDX, dy, w, h); - if (cw > 0) { - ctx.drawImage(this.img, this.x + w, this.y, w, h, dx + w, dy, cw, h); - } - ctx.drawImage(this.img, this.x, this.y + h, w, h, dx, dy + h, w, ch); - ctx.drawImage(this.img, rightSX, this.y + h, w, h, rightDX, dy + h, w, ch); - if (cw > 0 && ch > 0) { - ctx.drawImage(this.img, this.x + w, this.y + h, w, h, dx + w, dy + h, cw, ch); - } - ctx.drawImage(this.img, this.x, bottomSY, w, h, dx, bottomDY, w, h); - ctx.drawImage(this.img, rightSX, bottomSY, w, h, rightDX, bottomDY, w, h); - if (cw > 0) { - ctx.drawImage(this.img, this.x + w, bottomSY, w, h, dx + w, bottomDY, cw, h); - } - }; - ImageTile.prototype.draw3PatchV = function (ctx, dx, dy, dw, dh) { - var h = Math.min(dh >> 1, (this.h / 3) >> 0); - ctx.drawImage(this.img, this.x, this.y, this.w, h, dx, dy, dw, h); - ctx.drawImage(this.img, this.x, this.y + this.h - h, this.w, h, dx, dy + dh - h, dw, h); - var ch = dh - h - h; - if (ch > 0) { - ctx.drawImage(this.img, this.x, this.y + h, this.w, h, dx, dy + h, dw, ch); - } - }; - ImageTile.prototype.drawTileH = function (ctx, dx, dy, dw, dh) { - var x = dx; - var w = 0; - var remainW = dw; - while (remainW > 0) { - w = Math.min(this.w, remainW); - ctx.drawImage(this.img, this.x, this.y, w, this.h, x, dy, w, dh); - x += w; - remainW -= w; - } - }; - ImageTile.prototype.drawTileV = function (ctx, dx, dy, dw, dh) { - var y = dy; - var h = 0; - var remainH = dh; - while (remainH > 0) { - h = Math.min(this.h, remainH); - ctx.drawImage(this.img, this.x, this.y, this.w, h, dx, y, dw, h); - y += h; - remainH -= h; - } - }; - ImageTile.prototype.drawTile = function (ctx, dx, dy, dw, dh) { - var x = dx; - var y = dy; - var w = 0; - var h = 0; - var remainW = dw; - var remainH = dh; - while (remainH > 0) { - h = Math.min(this.h, remainH); - while (remainW > 0) { - w = Math.min(this.w, remainW); - ctx.drawImage(this.img, this.x, this.y, w, h, x, y, w, h); - x += w; - remainW -= w; - } - x = 0; - remainW = dw; - y += h; - remainH -= h; - } - }; - ImageTile.prototype.draw = function (ctx, type, dx, dy, dw, dh) { - if (ctx && this.complete) { - if (type === ImageDrawType.CENTER) { - this.drawCenter(ctx, dx, dy, dw, dh); - } - else if (type === ImageDrawType.AUTO) { - this.drawAuto(ctx, dx, dy, dw, dh); - } - else if (type === ImageDrawType.PATCH3_H) { - this.draw3PatchH(ctx, dx, dy, dw, dh); - } - else if (type === ImageDrawType.PATCH3_V) { - this.draw3PatchV(ctx, dx, dy, dw, dh); - } - else if (type === ImageDrawType.PATCH9) { - this.draw9Patch(ctx, dx, dy, dw, dh); - } - else if (type === ImageDrawType.TILE_H) { - this.drawTileH(ctx, dx, dy, dw, dh); - } - else if (type === ImageDrawType.TILE_V) { - this.drawTileV(ctx, dx, dy, dw, dh); - } - else if (type === ImageDrawType.TILE) { - this.drawTile(ctx, dx, dy, dw, dh); - } - else if (type === ImageDrawType.ICON) { - this.drawIcon(ctx, dx, dy, dw, dh); - } - else { - this.drawDefault(ctx, dx, dy, dw, dh); - } - } - }; - ImageTile.init = function (density, scale, onImageLoaded) { - ImageTile.scale = scale; - ImageTile.density = density; - ImageTile.onImageLoaded = onImageLoaded; - }; - ImageTile.fixURL = function (src) { - var ret = src.replace("@density", "x" + ImageTile.density); - return ret; - }; - ImageTile.create = function (_src, onDone) { - var src = ImageTile.fixURL(_src); - var it = ImageTile.cache[src]; - if (!it) { - it = new ImageTile(src); - ImageTile.cache[src] = it; - } - if (onDone) { - if (it.complete) { - setTimeout(onDone, 0); - } - else { - it.once(Events.LOAD, onDone); - } - } - return it; - }; - ImageTile.scale = 1; - ImageTile.density = 1; - ImageTile.cache = {}; - return ImageTile; - }(emitter_1.Emitter)); - exports.ImageTile = ImageTile; - ; - - -/***/ }, -/* 8 */ -/***/ function(module, exports) { - - (function(self) { - 'use strict'; - - if (self.fetch) { - return - } - - var support = { - searchParams: 'URLSearchParams' in self, - iterable: 'Symbol' in self && 'iterator' in Symbol, - blob: 'FileReader' in self && 'Blob' in self && (function() { - try { - new Blob() - return true - } catch(e) { - return false - } - })(), - formData: 'FormData' in self, - arrayBuffer: 'ArrayBuffer' in self - } - - if (support.arrayBuffer) { - var viewClasses = [ - '[object Int8Array]', - '[object Uint8Array]', - '[object Uint8ClampedArray]', - '[object Int16Array]', - '[object Uint16Array]', - '[object Int32Array]', - '[object Uint32Array]', - '[object Float32Array]', - '[object Float64Array]' - ] - - var isDataView = function(obj) { - return obj && DataView.prototype.isPrototypeOf(obj) - } - + /// + /// + "use strict"; + var __extends = (this && this.__extends) || (function () { + var extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + return function (d, b) { + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; + })(); + Object.defineProperty(exports, "__esModule", { value: true }); + __webpack_require__(8); + var path = __webpack_require__(9); + var emitter_1 = __webpack_require__(4); + var assets_1 = __webpack_require__(11); + var Events = __webpack_require__(6); + var ImageDrawType; + (function (ImageDrawType) { + /** + * 画在填满指定的矩形区域。 + */ + ImageDrawType[ImageDrawType["DEFAULT"] = 1] = "DEFAULT"; + /** + * 按1比1大小画在指定的矩形区域的中间。 + */ + ImageDrawType[ImageDrawType["CENTER"] = 2] = "CENTER"; + /** + * 把图分成3行3列等大小的区域,按9宫格的方式填满指定的矩形区域。 + */ + ImageDrawType[ImageDrawType["PATCH9"] = 3] = "PATCH9"; + /** + * 把图分成3行1列等大小的区域,按3宫格的方式填满指定的矩形区域。 + */ + ImageDrawType[ImageDrawType["PATCH3_V"] = 4] = "PATCH3_V"; + /** + * 把图分成1行1列等大小的区域,按3宫格的方式填满指定的矩形区域。 + */ + ImageDrawType[ImageDrawType["PATCH3_H"] = 5] = "PATCH3_H"; + /** + * 按平铺的方式填满指定的矩形区域。 + */ + ImageDrawType[ImageDrawType["TILE"] = 6] = "TILE"; + /** + * 按垂直平铺的方式填满指定的矩形区域。 + */ + ImageDrawType[ImageDrawType["TILE_V"] = 7] = "TILE_V"; + /** + * 按水平平铺的方式填满指定的矩形区域。 + */ + ImageDrawType[ImageDrawType["TILE_H"] = 8] = "TILE_H"; + /** + * 保持比例缩放到指定的矩形区域。 + */ + ImageDrawType[ImageDrawType["AUTO"] = 9] = "AUTO"; + /** + * ICON + */ + ImageDrawType[ImageDrawType["ICON"] = 10] = "ICON"; + })(ImageDrawType = exports.ImageDrawType || (exports.ImageDrawType = {})); + /** + * 把多个小的图片合并成一张大图,不但可以减少网路请求和GPU的调用次数,还可以提高内存的利用率。 + * ImageTile用来表示大图中的一张小图,QTK中支持下面几种方式: + * + * 0.普通图片。如果URL中没有#,则表示一张普通图片,它的位置为(0,0),大小为图片的整个大小。 + * + * 1.指定子图的位置和大小,#之前的部分是大图的URL,后面是子图的位置和大小信息。 + * 字母x后紧跟x坐标,字母y后紧跟y坐标,字母w后紧跟宽度,字母h后紧跟高度。 + * 下面的URL表示图片demo.png中位置为(100,200),大小为(300,400)的子图。 + * + * ``` + * https://qtoolkit.github.io/demo.png#x100y200w300h400 + * ``` + * + * 2.指定图片的行列数以及小图的序数,#之前的部分是大图的URL,后面是行数、列数和序数。 + * 字母r紧跟行数,字母c后紧跟列数,字母i后紧跟序数。 + * + * 下面的URL表示图片demo.png分成3行3列,序数为0的子图。 + * + * ``` + * https://qtoolkit.github.io/demo.png#r3c3i0 + * ``` + * + * 3.用TexturePacker打包的JSON Hash格式。#之前部分是JSON的URL,后面是子图的名称。如: + * + * ``` + * https://qtoolkit.github.io/demo.json#demo.png + * ``` + * + * + */ + var ImageTile = (function (_super) { + __extends(ImageTile, _super); + function ImageTile(src) { + var _this = _super.call(this) || this; + _this.x = 0; + _this.y = 0; + _this.w = 0; + _this.h = 0; + _this._id = 0; + _this.img = null; + _this.src = src; + if (src) { + _this.create(src); + } + return _this; + } + ImageTile.prototype.toJson = function () { + return this.src; + }; + ImageTile.prototype.create = function (src) { + var index = src.indexOf('#'); + if (index < 0) { + this.createNormal(src); + } + else { + var base = src.substr(0, index); + var ext = src.substr(index + 1); + if (ext[0] === 'x') { + this.createXYWH(base, ext); + } + else if (ext[0] === 'r') { + this.createRowColIndex(base, ext); + } + else { + this.createTexturePacker(base, ext); + } + } + }; + ImageTile.prototype.init = function (img, x, y, w, h) { + this.x = x; + this.y = y; + this.w = w; + this.h = h; + this.img = img; + if (ImageTile.onImageLoaded) { + ImageTile.onImageLoaded(this); + } + this.dispatchEventAsync({ type: Events.LOAD, detail: this }); + }; + Object.defineProperty(ImageTile.prototype, "complete", { + get: function () { + return this.img && this.img.width; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(ImageTile.prototype, "id", { + get: function () { + return this._id; + }, + set: function (id) { + this._id = id; + if (this.img) { + this.img.imgID = id; + } + }, + enumerable: true, + configurable: true + }); + ImageTile.prototype.createNormal = function (src) { + var _this = this; + assets_1.AssetManager.loadImage(src).then(function (img) { + _this.init(img, 0, 0, img.width, img.height); + }).catch(function (err) { + _this.init(null, 0, 0, 0, 0); + }); + }; + ImageTile.prototype.createXYWH = function (base, meta) { + var _this = this; + var xywh = meta.match(/x([0-9]+)y([0-9]+)w([0-9]+)h([0-9]+)/i); + var x = parseInt(xywh[1]); + var y = parseInt(xywh[2]); + var w = parseInt(xywh[3]); + var h = parseInt(xywh[4]); + assets_1.AssetManager.loadImage(base).then(function (img) { + _this.init(img, x, y, w, h); + }).catch(function (err) { + _this.init(null, 0, 0, 0, 0); + }); + }; + ImageTile.prototype.createRowColIndex = function (base, meta) { + var _this = this; + var rowcolIndex = meta.match(/r([0-9]+)c([0-9]+)i([0-9]+)/i); + var rows = parseInt(rowcolIndex[1]); + var cols = parseInt(rowcolIndex[2]); + var index = parseInt(rowcolIndex[3]); + assets_1.AssetManager.loadImage(base).then(function (img) { + var w = img.width / cols; + var h = img.height / rows; + var r = (index / cols) >> 0; + var c = index % cols; + var x = c * w; + var y = r * h; + _this.init(img, x, y, w, h); + }).catch(function (err) { + _this.init(null, 0, 0, 0, 0); + }); + }; + ImageTile.prototype.createTexturePacker = function (jsonURL, name) { + var _this = this; + assets_1.AssetManager.loadJson(jsonURL).then(function (json) { + var info = json.frames[name]; + var imgSRC = path.dirname(jsonURL) + "/" + (json.file || json.meta.image); + assets_1.AssetManager.loadImage(imgSRC).then(function (img) { + var rect = info.frame || info; + var x = rect.x; + var y = rect.y; + var w = rect.w; + var h = rect.h; + if (!info.trimmed && !info.rotate) { + _this.init(img, x, y, w, h); + } + else { + console.log("Not support trimmed mode or rotated mode"); + _this.init(null, 0, 0, 0, 0); + } + }).catch(function (err) { + _this.init(null, 0, 0, 0, 0); + }); + }).catch(function (err) { + _this.init(null, 0, 0, 0, 0); + }); + }; + ImageTile.prototype.drawDefault = function (ctx, dx, dy, dw, dh) { + ctx.drawImage(this.img, this.x, this.y, this.w, this.h, dx, dy, dw, dh); + }; + ImageTile.prototype.drawIcon = function (ctx, dx, dy, dw, dh) { + var cx = dx + (dw >> 1); + var cy = dy + (dh >> 1); + var x = dx + ((dw - this.w) >> 1); + var y = dy + ((dh - this.h) >> 1); + ctx.save(); + ctx.translate(cx, cy); + ctx.scale(ImageTile.scale, ImageTile.scale); + ctx.translate(-cx, -cy); + ctx.drawImage(this.img, this.x, this.y, this.w, this.h, x, y, this.w, this.h); + ctx.restore(); + }; + ImageTile.prototype.drawCenter = function (ctx, dx, dy, dw, dh) { + var x = dx + ((dw - this.w) >> 1); + var y = dy + ((dh - this.h) >> 1); + ctx.drawImage(this.img, this.x, this.y, this.w, this.h, x, y, this.w, this.h); + }; + ImageTile.prototype.drawAuto = function (ctx, dx, dy, dw, dh) { + var x = dx; + var y = dy; + var w = 0; + var h = 0; + var scaleX = dw / this.w; + var scaleY = dh / this.h; + if (scaleX >= scaleY) { + h = dh; + w = scaleY * this.w; + x += ((dw - w) >> 1); + } + else { + w = dw; + h = scaleX * this.h; + y += ((dh - h) >> 1); + } + ctx.drawImage(this.img, this.x, this.y, this.w, this.h, x, y, w, h); + }; + ImageTile.prototype.draw3PatchH = function (ctx, dx, dy, dw, dh) { + var w = Math.min(dw >> 1, (this.w / 3) >> 0); + ctx.drawImage(this.img, this.x, this.y, w, this.h, dx, dy, w, dh); + ctx.drawImage(this.img, this.x + this.w - w, this.y, w, this.h, dx + dw - w, dy, w, dh); + var cw = dw - w - w; + if (cw > 0) { + ctx.drawImage(this.img, this.x + w, this.y, w, this.h, dx + w, dy, cw, dh); + } + }; + ImageTile.prototype.draw9Patch = function (ctx, dx, dy, dw, dh) { + var w = Math.min(dw >> 1, (this.w / 3) >> 0); + var h = Math.min(dh >> 1, (this.h / 3) >> 0); + var cw = dw - w - w; + var ch = dh - h - h; + var rightSX = this.x + this.w - w; + var rightDX = dx + dw - w; + var bottomSY = this.y + this.h - h; + var bottomDY = dy + dh - h; + ctx.drawImage(this.img, this.x, this.y, w, h, dx, dy, w, h); + ctx.drawImage(this.img, rightSX, this.y, w, h, rightDX, dy, w, h); + if (cw > 0) { + ctx.drawImage(this.img, this.x + w, this.y, w, h, dx + w, dy, cw, h); + } + ctx.drawImage(this.img, this.x, this.y + h, w, h, dx, dy + h, w, ch); + ctx.drawImage(this.img, rightSX, this.y + h, w, h, rightDX, dy + h, w, ch); + if (cw > 0 && ch > 0) { + ctx.drawImage(this.img, this.x + w, this.y + h, w, h, dx + w, dy + h, cw, ch); + } + ctx.drawImage(this.img, this.x, bottomSY, w, h, dx, bottomDY, w, h); + ctx.drawImage(this.img, rightSX, bottomSY, w, h, rightDX, bottomDY, w, h); + if (cw > 0) { + ctx.drawImage(this.img, this.x + w, bottomSY, w, h, dx + w, bottomDY, cw, h); + } + }; + ImageTile.prototype.draw3PatchV = function (ctx, dx, dy, dw, dh) { + var h = Math.min(dh >> 1, (this.h / 3) >> 0); + ctx.drawImage(this.img, this.x, this.y, this.w, h, dx, dy, dw, h); + ctx.drawImage(this.img, this.x, this.y + this.h - h, this.w, h, dx, dy + dh - h, dw, h); + var ch = dh - h - h; + if (ch > 0) { + ctx.drawImage(this.img, this.x, this.y + h, this.w, h, dx, dy + h, dw, ch); + } + }; + ImageTile.prototype.drawTileH = function (ctx, dx, dy, dw, dh) { + var x = dx; + var w = 0; + var remainW = dw; + while (remainW > 0) { + w = Math.min(this.w, remainW); + ctx.drawImage(this.img, this.x, this.y, w, this.h, x, dy, w, dh); + x += w; + remainW -= w; + } + }; + ImageTile.prototype.drawTileV = function (ctx, dx, dy, dw, dh) { + var y = dy; + var h = 0; + var remainH = dh; + while (remainH > 0) { + h = Math.min(this.h, remainH); + ctx.drawImage(this.img, this.x, this.y, this.w, h, dx, y, dw, h); + y += h; + remainH -= h; + } + }; + ImageTile.prototype.drawTile = function (ctx, dx, dy, dw, dh) { + var x = dx; + var y = dy; + var w = 0; + var h = 0; + var remainW = dw; + var remainH = dh; + while (remainH > 0) { + h = Math.min(this.h, remainH); + while (remainW > 0) { + w = Math.min(this.w, remainW); + ctx.drawImage(this.img, this.x, this.y, w, h, x, y, w, h); + x += w; + remainW -= w; + } + x = 0; + remainW = dw; + y += h; + remainH -= h; + } + }; + ImageTile.prototype.draw = function (ctx, type, dx, dy, dw, dh) { + if (ctx && this.complete) { + if (type === ImageDrawType.CENTER) { + this.drawCenter(ctx, dx, dy, dw, dh); + } + else if (type === ImageDrawType.AUTO) { + this.drawAuto(ctx, dx, dy, dw, dh); + } + else if (type === ImageDrawType.PATCH3_H) { + this.draw3PatchH(ctx, dx, dy, dw, dh); + } + else if (type === ImageDrawType.PATCH3_V) { + this.draw3PatchV(ctx, dx, dy, dw, dh); + } + else if (type === ImageDrawType.PATCH9) { + this.draw9Patch(ctx, dx, dy, dw, dh); + } + else if (type === ImageDrawType.TILE_H) { + this.drawTileH(ctx, dx, dy, dw, dh); + } + else if (type === ImageDrawType.TILE_V) { + this.drawTileV(ctx, dx, dy, dw, dh); + } + else if (type === ImageDrawType.TILE) { + this.drawTile(ctx, dx, dy, dw, dh); + } + else if (type === ImageDrawType.ICON) { + this.drawIcon(ctx, dx, dy, dw, dh); + } + else { + this.drawDefault(ctx, dx, dy, dw, dh); + } + } + }; + ImageTile.init = function (density, scale, onImageLoaded) { + ImageTile.scale = scale; + ImageTile.density = density; + ImageTile.onImageLoaded = onImageLoaded; + }; + ImageTile.fixURL = function (src) { + var ret = src.replace("@density", "x" + ImageTile.density); + return ret; + }; + ImageTile.create = function (_src, onDone) { + var src = ImageTile.fixURL(_src); + var it = ImageTile.cache[src]; + if (!it) { + it = new ImageTile(src); + ImageTile.cache[src] = it; + } + if (onDone) { + if (it.complete) { + setTimeout(onDone, 0); + } + else { + it.once(Events.LOAD, onDone); + } + } + return it; + }; + return ImageTile; + }(emitter_1.Emitter)); + ImageTile.scale = 1; + ImageTile.density = 1; + ImageTile.cache = {}; + exports.ImageTile = ImageTile; + ; + + +/***/ }, +/* 8 */ +/***/ function(module, exports) { + + (function(self) { + 'use strict'; + + if (self.fetch) { + return + } + + var support = { + searchParams: 'URLSearchParams' in self, + iterable: 'Symbol' in self && 'iterator' in Symbol, + blob: 'FileReader' in self && 'Blob' in self && (function() { + try { + new Blob() + return true + } catch(e) { + return false + } + })(), + formData: 'FormData' in self, + arrayBuffer: 'ArrayBuffer' in self + } + + if (support.arrayBuffer) { + var viewClasses = [ + '[object Int8Array]', + '[object Uint8Array]', + '[object Uint8ClampedArray]', + '[object Int16Array]', + '[object Uint16Array]', + '[object Int32Array]', + '[object Uint32Array]', + '[object Float32Array]', + '[object Float64Array]' + ] + + var isDataView = function(obj) { + return obj && DataView.prototype.isPrototypeOf(obj) + } + var isArrayBufferView = ArrayBuffer.isView || function(obj) { return obj && viewClasses.indexOf(Object.prototype.toString.call(obj)) > -1 } @@ -3097,20 +3126,30 @@ var qtk = var cachedSetTimeout; var cachedClearTimeout; + function defaultSetTimout() { + throw new Error('setTimeout has not been defined'); + } + function defaultClearTimeout () { + throw new Error('clearTimeout has not been defined'); + } (function () { try { - cachedSetTimeout = setTimeout; - } catch (e) { - cachedSetTimeout = function () { - throw new Error('setTimeout is not defined'); + if (typeof setTimeout === 'function') { + cachedSetTimeout = setTimeout; + } else { + cachedSetTimeout = defaultSetTimout; } + } catch (e) { + cachedSetTimeout = defaultSetTimout; } try { - cachedClearTimeout = clearTimeout; - } catch (e) { - cachedClearTimeout = function () { - throw new Error('clearTimeout is not defined'); + if (typeof clearTimeout === 'function') { + cachedClearTimeout = clearTimeout; + } else { + cachedClearTimeout = defaultClearTimeout; } + } catch (e) { + cachedClearTimeout = defaultClearTimeout; } } ()) function runTimeout(fun) { @@ -3118,6 +3157,11 @@ var qtk = //normal enviroments in sane situations return setTimeout(fun, 0); } + // if setTimeout wasn't available but was latter defined + if ((cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && setTimeout) { + cachedSetTimeout = setTimeout; + return setTimeout(fun, 0); + } try { // when when somebody has screwed with setTimeout but no I.E. maddness return cachedSetTimeout(fun, 0); @@ -3138,6 +3182,11 @@ var qtk = //normal enviroments in sane situations return clearTimeout(marker); } + // if clearTimeout wasn't available but was latter defined + if ((cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && clearTimeout) { + cachedClearTimeout = clearTimeout; + return clearTimeout(marker); + } try { // when when somebody has screwed with setTimeout but no I.E. maddness return cachedClearTimeout(marker); @@ -3252,11844 +3301,10168 @@ var qtk = /* 11 */ /***/ function(module, exports, __webpack_require__) { - /// - /// - /// - "use strict"; - var __extends = (this && this.__extends) || function (d, b) { - for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; - __webpack_require__(8); - var path = __webpack_require__(9); - var Events = __webpack_require__(6); - var emitter_1 = __webpack_require__(4); - ; - var assetsCache = {}; - function load(url, type) { - var item = assetsCache[url]; - if (!item) { - item = fetch(url).then(function ok(response) { - if (response.status !== 200) { - return Promise.reject(null); - } - if (type === AssetType.JSON) { - return response.json(); - } - else if (type === AssetType.BLOB) { - return response.blob(); - } - else { - return response.text(); - } - }, function fail(err) { - return null; - }); - assetsCache[url] = item; - } - return item; - } - /** - * @enum AssetType - * 资源类型。 - */ - (function (AssetType) { - /** - * @property {number} [AUDIO=1] - * 音频资源。 - */ - AssetType[AssetType["AUDIO"] = 1] = "AUDIO"; - /** - * @property {number} [IMAGE] - * 图像资源。 - */ - AssetType[AssetType["IMAGE"] = 2] = "IMAGE"; - /** - * @property {number} [BLOB] - * 二进制资源。 - */ - AssetType[AssetType["BLOB"] = 3] = "BLOB"; - /** - * @property {number} [JSON] - * JSON资源。 - */ - AssetType[AssetType["JSON"] = 4] = "JSON"; - /** - * @property {number} [SCRIPT] - * SCRIPT资源。 - */ - AssetType[AssetType["SCRIPT"] = 5] = "SCRIPT"; - /** - * @property {number} [TEXT] - * 文本资源。 - */ - AssetType[AssetType["TEXT"] = 6] = "TEXT"; - })(exports.AssetType || (exports.AssetType = {})); - var AssetType = exports.AssetType; - ; - /** - * @class AssetManager - * 资源管理类,用于加载各种资源。 - */ - var AssetManager = (function () { - function AssetManager() { - } - /** - * @method loadJson - * 加载JSON资源。 - * @static - * @param {String} url 资源URL。 - * @return {Promise} - */ - AssetManager.loadJson = function (url) { - return load(url, AssetType.JSON); - }; - /** - * @method loadText - * 加载文本数据资源。 - * @static - * @param {String} url 资源URL。 - * @return {Promise} - */ - AssetManager.loadText = function (url) { - return load(url, AssetType.TEXT); - }; - /** - * @method loadBlob - * 加载二进制数据资源。 - * @static - * @param {String} url 资源URL。 - * @return {Promise} - */ - AssetManager.loadBlob = function (url) { - return load(url, AssetType.BLOB); - }; - /** - * @method loadImage - * 加载图片资源。 - * @static - * @param {String} url 资源URL。 - * @return {Promise} - */ - AssetManager.loadImage = function (url) { - var item = assetsCache[url]; - if (!item) { - item = new Promise(function (resolve, reject) { - var image = new Image(); - image.onload = function () { - resolve(image); - }; - image.onerror = function (err) { - reject(err); - }; - image.src = url; - }); - } - assetsCache[url] = item; - return item; - }; - /** - * @method loadScript - * 加载脚本资源。 - * @static - * @param {String} url 资源URL。 - * @return {Promise} - */ - AssetManager.loadScript = function (url) { - var item = new Promise(function (resolve, reject) { - var node = document.head ? document.head : document.body; - var script = document.createElement("script"); - script.onload = function () { - resolve(script); - }; - script.onerror = function (err) { - reject(err); - }; - script.src = url; - node.appendChild(script); - }); - return item; - }; - /** - * @method loadAudio - * 加载音频资源。 - * @static - * @param {String} url 资源URL。 - * @return {Promise} - */ - AssetManager.loadAudio = function (url) { - var item = assetsCache[url]; - if (!item) { - item = new Promise(function (resolve, reject) { - var audio = new Audio(); - audio.onload = function () { - resolve(audio); - }; - audio.onerror = function (err) { - reject(err); - }; - audio.src = url; - }); - } - assetsCache[url] = item; - return item; - }; - /** - * @method clear - * 清除指定URL资源的缓存。 - * @static - * @param {String} url 资源URL。 - */ - AssetManager.clear = function (url) { - delete assetsCache[url]; - }; - return AssetManager; - }()); - exports.AssetManager = AssetManager; - /** - * @class AssetItem - * 表示一个资源项, 用于预加载资源。 - * - */ - var AssetItem = (function () { - function AssetItem(src, type) { - if (!type) { - var name = path.extname(src).toLowerCase(); - if (name === ".json") { - type = AssetType.JSON; - } - else if (name === ".jpg" || name === ".png" || name === ".svg") { - type = AssetType.IMAGE; - } - else if (name === ".txt") { - type = AssetType.TEXT; - } - else if (name === ".js") { - type = AssetType.SCRIPT; - } - else { - type = AssetType.BLOB; - } - } - this.src = src; - this.type = type; - } - AssetItem.create = function (src, type) { - return new AssetItem(src, type); - }; - return AssetItem; - }()); - exports.AssetItem = AssetItem; - ; - /** - * @class AssetGroup - * - * 表示一个资源分组, 用于预加载资源。 - * - */ - var AssetGroup = (function (_super) { - __extends(AssetGroup, _super); - function AssetGroup(items, onProgress) { - _super.call(this); - this.event = { - total: 0, - loaded: 0, - type: Events.PROGRESS - }; - var i = 0; - var n = items.length; - this.loaded = 0; - this.total = items.length; - this.event.total = this.total; - if (onProgress) { - this.onProgress(onProgress); - } - items.forEach(this.loadOne.bind(this)); - } - /** - * 注册加载进度的回调函数。 - */ - AssetGroup.prototype.onProgress = function (callback) { - this.on(Events.PROGRESS, callback); - }; - AssetGroup.prototype.addLoaded = function () { - this.loaded++; - this.event.loaded = this.loaded; - this.dispatchEvent(this.event); - }; - AssetGroup.prototype.loadOne = function (item) { - var src = item.src; - var type = item.type; - var addLoaded = this.addLoaded.bind(this); - var name = path.extname(src).toLowerCase(); - if (type === AssetType.JSON || (!type && name === '.json')) { - AssetManager.loadJson(src).then(addLoaded, addLoaded); - } - else if (type === AssetType.IMAGE || (!type && (name === ".jpg" || name === ".png" || name === ".svg"))) { - AssetManager.loadImage(src).then(addLoaded, addLoaded); - } - else if (type === AssetType.BLOB) { - AssetManager.loadBlob(src).then(addLoaded, addLoaded); - } - else if (type === AssetType.SCRIPT) { - AssetManager.loadScript(src).then(addLoaded, addLoaded); - } - else { - AssetManager.loadText(src).then(addLoaded, addLoaded); - } - }; - AssetGroup.create = function (items, onProgress) { - return new AssetGroup(items, onProgress); - }; - /** - * @method preload - * 预加载指定的资源。 - * @static - * @param {Array} assetsURLS 资源URL列表。 - * @param {Function} onProgress 资源进度回调函数。 - * @return {AssetGroup} 资源分组对象。 - */ - AssetGroup.preload = function (assetsURLS, onProgress) { - var arr = assetsURLS.map(function (iter) { - return AssetItem.create(iter); - }); - return AssetGroup.create(arr, onProgress); - }; - return AssetGroup; - }(emitter_1.Emitter)); - exports.AssetGroup = AssetGroup; - - -/***/ }, -/* 12 */ -/***/ function(module, exports, __webpack_require__) { - - "use strict"; - var point_1 = __webpack_require__(2); - /** - * 2维矩阵变换 - */ - var Matrix = (function () { - function Matrix() { - this.data = new Float32Array(6); - this.identity(); - } - Matrix.prototype.identity = function () { - var data = this.data; - data[0] = 1; - data[1] = 0; - data[2] = 0; - data[3] = 1; - data[4] = 0; - data[5] = 0; - return this; - }; - Matrix.prototype.clone = function () { - var other = new Matrix(); - var data = other.data; - var src = this.data; - data[0] = src[0]; - data[1] = src[1]; - data[2] = src[2]; - data[3] = src[3]; - data[4] = src[4]; - data[5] = src[5]; - return other; - }; - Matrix.prototype.set = function (a, b, c, d, tx, ty) { - var data = this.data; - data[0] = a; - data[1] = b; - data[2] = c; - data[3] = d; - data[4] = tx; - data[5] = ty; - return this; - }; - Matrix.prototype.rotate = function (rad) { - var a = this.data; - var a0 = a[0], a1 = a[1], a2 = a[2], a3 = a[3], s = Math.sin(rad), c = Math.cos(rad); - a[0] = a0 * c + a2 * s; - a[1] = a1 * c + a3 * s; - a[2] = a0 * -s + a2 * c; - a[3] = a1 * -s + a3 * c; - return this; - }; - Matrix.prototype.scale = function (sx, sy) { - var a = this.data; - a[0] *= sx; - a[1] *= sx; - a[2] *= sy; - a[3] *= sy; - return this; - }; - Matrix.prototype.translate = function (dx, dy) { - var a = this.data; - var a0 = a[0], a1 = a[1], a2 = a[2], a3 = a[3], a4 = a[4], a5 = a[5]; - a[4] = a0 * dx + a2 * dy + a4; - a[5] = a1 * dx + a3 * dy + a5; - return this; - }; - ; - Matrix.prototype.transformPoint = function (x, y, out) { - var p = out || point_1.Point.create(); - var a = this.data; - p.x = a[0] * x + a[2] * y + a[4]; - p.y = a[1] * x + a[3] * y + a[5]; - return p; - }; - ; - Matrix.prototype.equal = function (other) { - var a = this.data; - var b = other.data; - return a[0] === b[0] - && a[1] === b[1] - && a[2] === b[2] - && a[3] === b[3] - && a[4] === b[4] - && a[5] === b[5]; - }; - Matrix.prototype.invert = function () { - var a = this.data; - var aa = a[0], ab = a[1], ac = a[2], ad = a[3], atx = a[4], aty = a[5]; - var det = aa * ad - ab * ac; - if (!det) { - return null; - } - det = 1.0 / det; - var newMatrix = Matrix.create(); - var out = newMatrix.data; - out[0] = ad * det; - out[1] = -ab * det; - out[2] = -ac * det; - out[3] = aa * det; - out[4] = (ac * aty - ad * atx) * det; - out[5] = (ab * atx - aa * aty) * det; - return newMatrix; - }; - ; - Matrix.prototype.toString = function () { - var ret = Array.prototype.map.call(this.data, function (iter) { - return iter.toFixed(2); - }); - return JSON.stringify(ret); - }; - Matrix.prototype.dispose = function () { - this.identity(); - Matrix.cache.push(this); - }; - Matrix.create = function () { - if (Matrix.cache.length) { - return Matrix.cache.pop(); - } - return new Matrix(); - }; - Matrix.cache = []; - return Matrix; - }()); - exports.Matrix = Matrix; - ; + /// + /// + "use strict"; + var __extends = (this && this.__extends) || (function () { + var extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + return function (d, b) { + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; + })(); + Object.defineProperty(exports, "__esModule", { value: true }); + __webpack_require__(8); + var path = __webpack_require__(9); + var Events = __webpack_require__(6); + var emitter_1 = __webpack_require__(4); + ; + var assetsCache = {}; + function load(url, type) { + var item = assetsCache[url]; + if (!item) { + item = fetch(url).then(function ok(response) { + if (response.status !== 200) { + return Promise.reject(null); + } + if (type === AssetType.JSON) { + return response.json(); + } + else if (type === AssetType.BLOB) { + return response.blob(); + } + else { + return response.text(); + } + }, function fail(err) { + return null; + }); + assetsCache[url] = item; + } + return item; + } + /** + * @enum AssetType + * 资源类型。 + */ + var AssetType; + (function (AssetType) { + /** + * @property {number} [AUDIO=1] + * 音频资源。 + */ + AssetType[AssetType["AUDIO"] = 1] = "AUDIO"; + /** + * @property {number} [IMAGE] + * 图像资源。 + */ + AssetType[AssetType["IMAGE"] = 2] = "IMAGE"; + /** + * @property {number} [BLOB] + * 二进制资源。 + */ + AssetType[AssetType["BLOB"] = 3] = "BLOB"; + /** + * @property {number} [JSON] + * JSON资源。 + */ + AssetType[AssetType["JSON"] = 4] = "JSON"; + /** + * @property {number} [SCRIPT] + * SCRIPT资源。 + */ + AssetType[AssetType["SCRIPT"] = 5] = "SCRIPT"; + /** + * @property {number} [TEXT] + * 文本资源。 + */ + AssetType[AssetType["TEXT"] = 6] = "TEXT"; + })(AssetType = exports.AssetType || (exports.AssetType = {})); + ; + /** + * @class AssetManager + * 资源管理类,用于加载各种资源。 + */ + var AssetManager = (function () { + function AssetManager() { + } + /** + * @method loadJson + * 加载JSON资源。 + * @static + * @param {String} url 资源URL。 + * @return {Promise} + */ + AssetManager.loadJson = function (url) { + return load(url, AssetType.JSON); + }; + /** + * @method loadText + * 加载文本数据资源。 + * @static + * @param {String} url 资源URL。 + * @return {Promise} + */ + AssetManager.loadText = function (url) { + return load(url, AssetType.TEXT); + }; + /** + * @method loadBlob + * 加载二进制数据资源。 + * @static + * @param {String} url 资源URL。 + * @return {Promise} + */ + AssetManager.loadBlob = function (url) { + return load(url, AssetType.BLOB); + }; + /** + * @method loadImage + * 加载图片资源。 + * @static + * @param {String} url 资源URL。 + * @return {Promise} + */ + AssetManager.loadImage = function (url) { + var item = assetsCache[url]; + if (!item) { + item = new Promise(function (resolve, reject) { + var image = new Image(); + image.onload = function () { + resolve(image); + }; + image.onerror = function (err) { + reject(err); + }; + image.src = url; + }); + } + assetsCache[url] = item; + return item; + }; + /** + * @method loadScript + * 加载脚本资源。 + * @static + * @param {String} url 资源URL。 + * @return {Promise} + */ + AssetManager.loadScript = function (url) { + var item = new Promise(function (resolve, reject) { + var node = document.head ? document.head : document.body; + var script = document.createElement("script"); + script.onload = function () { + resolve(script); + }; + script.onerror = function (err) { + reject(err); + }; + script.src = url; + node.appendChild(script); + }); + return item; + }; + /** + * @method loadAudio + * 加载音频资源。 + * @static + * @param {String} url 资源URL。 + * @return {Promise} + */ + AssetManager.loadAudio = function (url) { + var item = assetsCache[url]; + if (!item) { + item = new Promise(function (resolve, reject) { + var audio = new Audio(); + audio.onload = function () { + resolve(audio); + }; + audio.onerror = function (err) { + reject(err); + }; + audio.src = url; + }); + } + assetsCache[url] = item; + return item; + }; + /** + * @method clear + * 清除指定URL资源的缓存。 + * @static + * @param {String} url 资源URL。 + */ + AssetManager.clear = function (url) { + delete assetsCache[url]; + }; + return AssetManager; + }()); + exports.AssetManager = AssetManager; + /** + * @class AssetItem + * 表示一个资源项, 用于预加载资源。 + * + */ + var AssetItem = (function () { + function AssetItem(src, type) { + if (!type) { + var name = path.extname(src).toLowerCase(); + if (name === ".json") { + type = AssetType.JSON; + } + else if (name === ".jpg" || name === ".png" || name === ".svg") { + type = AssetType.IMAGE; + } + else if (name === ".txt") { + type = AssetType.TEXT; + } + else if (name === ".js") { + type = AssetType.SCRIPT; + } + else { + type = AssetType.BLOB; + } + } + this.src = src; + this.type = type; + } + AssetItem.create = function (src, type) { + return new AssetItem(src, type); + }; + return AssetItem; + }()); + exports.AssetItem = AssetItem; + ; + /** + * @class AssetGroup + * + * 表示一个资源分组, 用于预加载资源。 + * + */ + var AssetGroup = (function (_super) { + __extends(AssetGroup, _super); + function AssetGroup(items, onProgress) { + var _this = _super.call(this) || this; + _this.event = { + total: 0, + loaded: 0, + type: Events.PROGRESS + }; + var i = 0; + var n = items.length; + _this.loaded = 0; + _this.total = items.length; + _this.event.total = _this.total; + if (onProgress) { + _this.onProgress(onProgress); + } + items.forEach(_this.loadOne.bind(_this)); + return _this; + } + /** + * 注册加载进度的回调函数。 + */ + AssetGroup.prototype.onProgress = function (callback) { + this.on(Events.PROGRESS, callback); + }; + AssetGroup.prototype.addLoaded = function () { + this.loaded++; + this.event.loaded = this.loaded; + this.dispatchEvent(this.event); + }; + AssetGroup.prototype.loadOne = function (item) { + var src = item.src; + var type = item.type; + var addLoaded = this.addLoaded.bind(this); + var name = path.extname(src).toLowerCase(); + if (type === AssetType.JSON || (!type && name === '.json')) { + AssetManager.loadJson(src).then(addLoaded, addLoaded); + } + else if (type === AssetType.IMAGE || (!type && (name === ".jpg" || name === ".png" || name === ".svg"))) { + AssetManager.loadImage(src).then(addLoaded, addLoaded); + } + else if (type === AssetType.BLOB) { + AssetManager.loadBlob(src).then(addLoaded, addLoaded); + } + else if (type === AssetType.SCRIPT) { + AssetManager.loadScript(src).then(addLoaded, addLoaded); + } + else { + AssetManager.loadText(src).then(addLoaded, addLoaded); + } + }; + AssetGroup.create = function (items, onProgress) { + return new AssetGroup(items, onProgress); + }; + /** + * @method preload + * 预加载指定的资源。 + * @static + * @param {Array} assetsURLS 资源URL列表。 + * @param {Function} onProgress 资源进度回调函数。 + * @return {AssetGroup} 资源分组对象。 + */ + AssetGroup.preload = function (assetsURLS, onProgress) { + var arr = assetsURLS.map(function (iter) { + return AssetItem.create(iter); + }); + return AssetGroup.create(arr, onProgress); + }; + return AssetGroup; + }(emitter_1.Emitter)); + exports.AssetGroup = AssetGroup; + + +/***/ }, +/* 12 */ +/***/ function(module, exports, __webpack_require__) { + + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + var point_1 = __webpack_require__(2); + /** + * 2维矩阵变换 + */ + var Matrix = (function () { + function Matrix() { + this.data = new Float32Array(6); + this.identity(); + } + Matrix.prototype.identity = function () { + var data = this.data; + data[0] = 1; + data[1] = 0; + data[2] = 0; + data[3] = 1; + data[4] = 0; + data[5] = 0; + return this; + }; + Matrix.prototype.clone = function () { + var other = new Matrix(); + var data = other.data; + var src = this.data; + data[0] = src[0]; + data[1] = src[1]; + data[2] = src[2]; + data[3] = src[3]; + data[4] = src[4]; + data[5] = src[5]; + return other; + }; + Matrix.prototype.set = function (a, b, c, d, tx, ty) { + var data = this.data; + data[0] = a; + data[1] = b; + data[2] = c; + data[3] = d; + data[4] = tx; + data[5] = ty; + return this; + }; + Matrix.prototype.rotate = function (rad) { + var a = this.data; + var a0 = a[0], a1 = a[1], a2 = a[2], a3 = a[3], s = Math.sin(rad), c = Math.cos(rad); + a[0] = a0 * c + a2 * s; + a[1] = a1 * c + a3 * s; + a[2] = a0 * -s + a2 * c; + a[3] = a1 * -s + a3 * c; + return this; + }; + Matrix.prototype.scale = function (sx, sy) { + var a = this.data; + a[0] *= sx; + a[1] *= sx; + a[2] *= sy; + a[3] *= sy; + return this; + }; + Matrix.prototype.translate = function (dx, dy) { + var a = this.data; + var a0 = a[0], a1 = a[1], a2 = a[2], a3 = a[3], a4 = a[4], a5 = a[5]; + a[4] = a0 * dx + a2 * dy + a4; + a[5] = a1 * dx + a3 * dy + a5; + return this; + }; + ; + Matrix.prototype.transformPoint = function (x, y, out) { + var p = out || point_1.Point.create(); + var a = this.data; + p.x = a[0] * x + a[2] * y + a[4]; + p.y = a[1] * x + a[3] * y + a[5]; + return p; + }; + ; + Matrix.prototype.equal = function (other) { + var a = this.data; + var b = other.data; + return a[0] === b[0] + && a[1] === b[1] + && a[2] === b[2] + && a[3] === b[3] + && a[4] === b[4] + && a[5] === b[5]; + }; + Matrix.prototype.invert = function () { + var a = this.data; + var aa = a[0], ab = a[1], ac = a[2], ad = a[3], atx = a[4], aty = a[5]; + var det = aa * ad - ab * ac; + if (!det) { + return null; + } + det = 1.0 / det; + var newMatrix = Matrix.create(); + var out = newMatrix.data; + out[0] = ad * det; + out[1] = -ab * det; + out[2] = -ac * det; + out[3] = aa * det; + out[4] = (ac * aty - ad * atx) * det; + out[5] = (ab * atx - aa * aty) * det; + return newMatrix; + }; + ; + Matrix.prototype.toString = function () { + var ret = Array.prototype.map.call(this.data, function (iter) { + return iter.toFixed(2); + }); + return JSON.stringify(ret); + }; + Matrix.prototype.dispose = function () { + this.identity(); + Matrix.cache.push(this); + }; + Matrix.create = function () { + if (Matrix.cache.length) { + return Matrix.cache.pop(); + } + return new Matrix(); + }; + return Matrix; + }()); + Matrix.cache = []; + exports.Matrix = Matrix; + ; /***/ }, /* 13 */ /***/ function(module, exports, __webpack_require__) { - "use strict"; - var __extends = (this && this.__extends) || function (d, b) { - for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; - var emitter_1 = __webpack_require__(4); - var Events = __webpack_require__(6); - var event_detail_1 = __webpack_require__(14); - var inputEventAdapter = __webpack_require__(15); - /** - * - * @class Canvas - * Canvas是对HTMLCanvasElement的包装,主要解决两个问题: - * - * 1.对指针事件坐标的转换,让绝对坐标变成相对与Canvas左上角的坐标。 - * - * 2.支持高清屏。为了避免在高清屏上图片模糊,让Canvas的宽高乘以devicePixelRatio, Canvas的style.width/style.height仍然用实际的宽高,getContext时预先将矩阵乘以devicePixelRatio,从而让使用者无需关心当前屏幕的类型。 - * - */ - var Canvas = (function (_super) { - __extends(Canvas, _super); - function Canvas(x, y, w, h, devicePixelRatio, offline) { - _super.call(this); - this._x = x || 0; - this._y = y || 0; - this._w = w || 0; - this._h = h || 0; - this._offline = offline || false; - this._devicePixelRatio = devicePixelRatio || 1; - var me = this; - this.onPointerEvent = function (evt) { - me.transformXY(evt.detail); - var e = Events.PointerEvent.create(evt.type, evt.detail); - me.dispatchEvent(e); - e.dispose(); - }; - this.onKeyEvent = function (evt) { - var e = Events.KeyEvent.create(evt.type, evt.detail); - me.dispatchEvent(e); - e.dispose(); - }; - this.onWheelEvent = function (evt) { - var e = Events.WheelEvent.create(evt.detail); - me.dispatchEvent(e); - e.dispose(); - }; - } - Object.defineProperty(Canvas.prototype, "x", { - /** - * @property {number} x - * X 坐标 - */ - get: function () { - return this._x; - }, - set: function (value) { - this._x = value; - this.moveCanvas(this.canvas); - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(Canvas.prototype, "y", { - /** - * @property {number} y - * Y 坐标 - */ - get: function () { - return this._y; - }, - set: function (value) { - this._y = value; - this.moveCanvas(this.canvas); - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(Canvas.prototype, "z", { - /** - * @property {number} z - * Z 坐标 - */ - set: function (value) { - this._z = value; - this.canvas.style.zIndex = value; - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(Canvas.prototype, "w", { - get: function () { - return this._w; - }, - /** - * @property {number} w - * 宽度 - */ - set: function (value) { - this._w = value; - this.resizeCanvas(this.canvas); - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(Canvas.prototype, "width", { - get: function () { - return this._w; - }, - set: function (value) { - this.w = value; - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(Canvas.prototype, "h", { - /** - * @property {number} h - * 高度 - */ - get: function () { - return this._h; - }, - set: function (value) { - this._h = value; - this.resizeCanvas(this.canvas); - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(Canvas.prototype, "height", { - get: function () { - return this._h; - }, - set: function (value) { - this.h = value; - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(Canvas.prototype, "id", { - get: function () { - return this._id; - }, - /** - * @property {string} id - * ID - */ - set: function (value) { - this._id = value; - if (this.canvas) { - this.canvas.id = value; - } - }, - enumerable: true, - configurable: true - }); - /** - * @method grabKey - * Grab Key事件。 - */ - Canvas.prototype.grabKey = function () { - inputEventAdapter.grabKey(this.canvas); - }; - /** - * @method ungrabKey - * ungrabKey Key事件。 - */ - Canvas.prototype.ungrabKey = function () { - inputEventAdapter.ungrabKey(this.canvas); - }; - /** - * @method grab - * grab事件。 - */ - Canvas.prototype.grab = function () { - inputEventAdapter.grab(this.canvas); - }; - /** - * @method ungrab - * ungrab事件。 - */ - Canvas.prototype.ungrab = function () { - inputEventAdapter.ungrab(this.canvas); - }; - Canvas.prototype.transformXY = function (detail) { - detail.x -= this.x; - detail.y -= this.y; - detail.pointerDownX -= this.x; - detail.pointerDownY -= this.y; - }; - Canvas.prototype.moveCanvas = function (canvas) { - if (canvas) { - var x = this._x; - var y = this._y; - canvas.style.position = "absolute"; - canvas.style.left = x + "px"; - canvas.style.top = y + "px"; - } - }; - Canvas.prototype.resizeCanvas = function (canvas) { - if (canvas) { - var w = this._w; - var h = this._h; - canvas.width = w * this._devicePixelRatio; - canvas.style.width = w + "px"; - canvas.height = h * this._devicePixelRatio; - canvas.style.height = h + "px"; - } - }; - Canvas.prototype.dispose = function () { - var canvas = this.canvas; - if (!this._offline) { - document.body.removeChild(canvas); - } - canvas.removeEventListener(Events.POINTER_DOWN, this.onPointerEvent); - canvas.removeEventListener(Events.POINTER_MOVE, this.onPointerEvent); - canvas.removeEventListener(Events.POINTER_UP, this.onPointerEvent); - canvas.removeEventListener(Events.CLICK, this.onPointerEvent); - canvas.removeEventListener(Events.WHEEL, this.onWheelEvent); - canvas.removeEventListener(Events.KEYDOWN, this.onKeyEvent); - canvas.removeEventListener(Events.KEYUP, this.onKeyEvent); - }; - Canvas.prototype.createCanvas = function () { - var canvas = document.createElement("canvas"); - canvas.id = this._id; - this.moveCanvas(canvas); - this.resizeCanvas(canvas); - if (!this._offline) { - document.body.appendChild(canvas); - } - var me = this; - canvas.addEventListener(Events.POINTER_DOWN, this.onPointerEvent); - canvas.addEventListener(Events.POINTER_MOVE, this.onPointerEvent); - canvas.addEventListener(Events.POINTER_UP, this.onPointerEvent); - canvas.addEventListener(Events.CLICK, this.onPointerEvent); - canvas.addEventListener(Events.DBLCLICK, this.onPointerEvent); - canvas.addEventListener(Events.WHEEL, this.onWheelEvent); - canvas.addEventListener(Events.KEYDOWN, this.onKeyEvent); - canvas.addEventListener(Events.KEYUP, this.onKeyEvent); - canvas.oncontextmenu = function (evt) { - evt.preventDefault(); - var detail = event_detail_1.PointerEventDetail.create(evt.which, evt.pageX, evt.pageY, evt.altKey, evt.ctrlKey, evt.shiftKey, false); - me.onPointerEvent({ type: Events.CONTEXT_MENU, detail: detail }); - detail.dispose(); - }; - return canvas; - }; - Canvas.prototype.ensureCanvas = function () { - if (!this.canvas) { - this.canvas = this.createCanvas(); - } - }; - /** - * @method getContext - * 获取Canvas的绘图Context。 - */ - Canvas.prototype.getContext = function (type) { - if (!this.canvas) { - this.canvas = this.createCanvas(); - } - var ctx = this.canvas.getContext("2d"); - ctx.setTransform(1, 0, 0, 1, 0, 0); - ctx.scale(this._devicePixelRatio, this._devicePixelRatio); - return ctx; - }; - /** - * @method create - * @static - * 创建一个Canvas对象。 - * @param {number} x X坐标。 - * @param {number} y Y坐标。 - * @param {number} w 宽度。 - * @param {number} h 高度。 - * @param {number} devicePixelRatio 屏幕密度。 - * @param {boolean} offline 是否是离线Canvas。 - */ - Canvas.create = function (x, y, w, h, devicePixelRatio, offline) { - return new Canvas(x, y, w, h, devicePixelRatio, offline); - }; - return Canvas; - }(emitter_1.Emitter)); - exports.Canvas = Canvas; + "use strict"; + var __extends = (this && this.__extends) || (function () { + var extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + return function (d, b) { + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; + })(); + Object.defineProperty(exports, "__esModule", { value: true }); + var emitter_1 = __webpack_require__(4); + var Events = __webpack_require__(6); + var event_detail_1 = __webpack_require__(14); + var inputEventAdapter = __webpack_require__(15); + /** + * + * @class Canvas + * Canvas是对HTMLCanvasElement的包装,主要解决两个问题: + * + * 1.对指针事件坐标的转换,让绝对坐标变成相对与Canvas左上角的坐标。 + * + * 2.支持高清屏。为了避免在高清屏上图片模糊,让Canvas的宽高乘以devicePixelRatio, Canvas的style.width/style.height仍然用实际的宽高,getContext时预先将矩阵乘以devicePixelRatio,从而让使用者无需关心当前屏幕的类型。 + * + */ + var Canvas = (function (_super) { + __extends(Canvas, _super); + function Canvas(x, y, w, h, devicePixelRatio, offline) { + var _this = _super.call(this) || this; + _this._x = x || 0; + _this._y = y || 0; + _this._w = w || 0; + _this._h = h || 0; + _this._offline = offline || false; + _this._devicePixelRatio = devicePixelRatio || 1; + var me = _this; + _this.onPointerEvent = function (evt) { + me.transformXY(evt.detail); + var e = Events.PointerEvent.create(evt.type, evt.detail); + me.dispatchEvent(e); + e.dispose(); + }; + _this.onKeyEvent = function (evt) { + var e = Events.KeyEvent.create(evt.type, evt.detail); + me.dispatchEvent(e); + e.dispose(); + }; + _this.onWheelEvent = function (evt) { + var e = Events.WheelEvent.create(evt.detail); + me.dispatchEvent(e); + e.dispose(); + }; + return _this; + } + Object.defineProperty(Canvas.prototype, "x", { + /** + * @property {number} x + * X 坐标 + */ + get: function () { + return this._x; + }, + set: function (value) { + this._x = value; + this.moveCanvas(this.canvas); + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Canvas.prototype, "y", { + /** + * @property {number} y + * Y 坐标 + */ + get: function () { + return this._y; + }, + set: function (value) { + this._y = value; + this.moveCanvas(this.canvas); + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Canvas.prototype, "z", { + /** + * @property {number} z + * Z 坐标 + */ + set: function (value) { + this._z = value; + this.canvas.style.zIndex = value; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Canvas.prototype, "w", { + get: function () { + return this._w; + }, + /** + * @property {number} w + * 宽度 + */ + set: function (value) { + this._w = value; + this.resizeCanvas(this.canvas); + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Canvas.prototype, "width", { + get: function () { + return this._w; + }, + set: function (value) { + this.w = value; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Canvas.prototype, "h", { + /** + * @property {number} h + * 高度 + */ + get: function () { + return this._h; + }, + set: function (value) { + this._h = value; + this.resizeCanvas(this.canvas); + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Canvas.prototype, "height", { + get: function () { + return this._h; + }, + set: function (value) { + this.h = value; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Canvas.prototype, "id", { + get: function () { + return this._id; + }, + /** + * @property {string} id + * ID + */ + set: function (value) { + this._id = value; + if (this.canvas) { + this.canvas.id = value; + } + }, + enumerable: true, + configurable: true + }); + /** + * @method grabKey + * Grab Key事件。 + */ + Canvas.prototype.grabKey = function () { + inputEventAdapter.grabKey(this.canvas); + }; + /** + * @method ungrabKey + * ungrabKey Key事件。 + */ + Canvas.prototype.ungrabKey = function () { + inputEventAdapter.ungrabKey(this.canvas); + }; + /** + * @method grab + * grab事件。 + */ + Canvas.prototype.grab = function () { + inputEventAdapter.grab(this.canvas); + }; + /** + * @method ungrab + * ungrab事件。 + */ + Canvas.prototype.ungrab = function () { + inputEventAdapter.ungrab(this.canvas); + }; + Canvas.prototype.transformXY = function (detail) { + detail.x -= this.x; + detail.y -= this.y; + detail.pointerDownX -= this.x; + detail.pointerDownY -= this.y; + }; + Canvas.prototype.moveCanvas = function (canvas) { + if (canvas) { + var x = this._x; + var y = this._y; + canvas.style.position = "absolute"; + canvas.style.left = x + "px"; + canvas.style.top = y + "px"; + } + }; + Canvas.prototype.resizeCanvas = function (canvas) { + if (canvas) { + var w = this._w; + var h = this._h; + canvas.width = w * this._devicePixelRatio; + canvas.style.width = w + "px"; + canvas.height = h * this._devicePixelRatio; + canvas.style.height = h + "px"; + } + }; + Canvas.prototype.dispose = function () { + var canvas = this.canvas; + if (!this._offline) { + document.body.removeChild(canvas); + } + canvas.removeEventListener(Events.POINTER_DOWN, this.onPointerEvent); + canvas.removeEventListener(Events.POINTER_MOVE, this.onPointerEvent); + canvas.removeEventListener(Events.POINTER_UP, this.onPointerEvent); + canvas.removeEventListener(Events.CLICK, this.onPointerEvent); + canvas.removeEventListener(Events.WHEEL, this.onWheelEvent); + canvas.removeEventListener(Events.KEYDOWN, this.onKeyEvent); + canvas.removeEventListener(Events.KEYUP, this.onKeyEvent); + }; + Canvas.prototype.createCanvas = function () { + var canvas = document.createElement("canvas"); + canvas.id = this._id; + this.moveCanvas(canvas); + this.resizeCanvas(canvas); + if (!this._offline) { + document.body.appendChild(canvas); + } + var me = this; + canvas.addEventListener(Events.POINTER_DOWN, this.onPointerEvent); + canvas.addEventListener(Events.POINTER_MOVE, this.onPointerEvent); + canvas.addEventListener(Events.POINTER_UP, this.onPointerEvent); + canvas.addEventListener(Events.CLICK, this.onPointerEvent); + canvas.addEventListener(Events.DBLCLICK, this.onPointerEvent); + canvas.addEventListener(Events.WHEEL, this.onWheelEvent); + canvas.addEventListener(Events.KEYDOWN, this.onKeyEvent); + canvas.addEventListener(Events.KEYUP, this.onKeyEvent); + canvas.oncontextmenu = function (evt) { + evt.preventDefault(); + var detail = event_detail_1.PointerEventDetail.create(evt.which, evt.pageX, evt.pageY, evt.altKey, evt.ctrlKey, evt.shiftKey, false); + me.onPointerEvent({ type: Events.CONTEXT_MENU, detail: detail }); + detail.dispose(); + }; + return canvas; + }; + Canvas.prototype.ensureCanvas = function () { + if (!this.canvas) { + this.canvas = this.createCanvas(); + } + }; + /** + * @method getContext + * 获取Canvas的绘图Context。 + */ + Canvas.prototype.getContext = function (type) { + if (!this.canvas) { + this.canvas = this.createCanvas(); + } + var ctx = this.canvas.getContext("2d"); + ctx.setTransform(1, 0, 0, 1, 0, 0); + ctx.scale(this._devicePixelRatio, this._devicePixelRatio); + return ctx; + }; + /** + * @method create + * @static + * 创建一个Canvas对象。 + * @param {number} x X坐标。 + * @param {number} y Y坐标。 + * @param {number} w 宽度。 + * @param {number} h 高度。 + * @param {number} devicePixelRatio 屏幕密度。 + * @param {boolean} offline 是否是离线Canvas。 + */ + Canvas.create = function (x, y, w, h, devicePixelRatio, offline) { + return new Canvas(x, y, w, h, devicePixelRatio, offline); + }; + return Canvas; + }(emitter_1.Emitter)); + exports.Canvas = Canvas; /***/ }, /* 14 */ /***/ function(module, exports) { - "use strict"; - var __extends = (this && this.__extends) || function (d, b) { - for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; - /** - * 输入事件的详细信息。 - */ - var InputEventDetail = (function () { - function InputEventDetail(altKey, ctrlKey, shiftKey, commandKey) { - this.altKey = altKey; - this.ctrlKey = ctrlKey; - this.shiftKey = shiftKey; - this.commandKey = commandKey; - } - return InputEventDetail; - }()); - exports.InputEventDetail = InputEventDetail; - ; - /** - * 指针事件的详细信息。 - */ - var PointerEventDetail = (function (_super) { - __extends(PointerEventDetail, _super); - function PointerEventDetail(id, x, y, altKey, ctrlKey, shiftKey, commandKey) { - _super.call(this, altKey, ctrlKey, shiftKey, commandKey); - this.id = id; - this.x = x; - this.y = y; - this.pointerDown = false; - this.pointerDownX = 0; - this.pointerDownY = 0; - this.pointerDownTime = 0; - } - /** - * 设置指针按下的状态。 - */ - PointerEventDetail.prototype.setPointerDown = function (pointerDown, x, y, t) { - this.pointerDownX = x; - this.pointerDownY = y; - this.pointerDownTime = t; - this.pointerDown = pointerDown; - }; - PointerEventDetail.prototype.dispose = function () { - }; - PointerEventDetail.create = function (id, x, y, altKey, ctrlKey, shiftKey, commandKey) { - var detail = new PointerEventDetail(id, x, y, altKey, ctrlKey, shiftKey, commandKey); - return detail; - }; - return PointerEventDetail; - }(InputEventDetail)); - exports.PointerEventDetail = PointerEventDetail; - ; - /** - * 按键事件的详细信息。 - */ - var KeyEventDetail = (function (_super) { - __extends(KeyEventDetail, _super); - function KeyEventDetail(keyCode, altKey, ctrlKey, shiftKey, commandKey) { - _super.call(this, altKey, ctrlKey, shiftKey, commandKey); - this.keyCode = keyCode; - } - KeyEventDetail.prototype.dispose = function () { - }; - KeyEventDetail.create = function (keyCode, altKey, ctrlKey, shiftKey, commandKey) { - var detail = new KeyEventDetail(keyCode, altKey, ctrlKey, shiftKey, commandKey); - return detail; - }; - return KeyEventDetail; - }(InputEventDetail)); - exports.KeyEventDetail = KeyEventDetail; - ; - /** - * 滚轮事件的详细信息。 - */ - var WheelEventDetail = (function (_super) { - __extends(WheelEventDetail, _super); - function WheelEventDetail(delta, altKey, ctrlKey, shiftKey, commandKey) { - _super.call(this, altKey, ctrlKey, shiftKey, commandKey); - this.delta = delta; - } - WheelEventDetail.prototype.dispose = function () { - }; - WheelEventDetail.create = function (delta, altKey, ctrlKey, shiftKey, commandKey) { - var detail = new WheelEventDetail(delta, altKey, ctrlKey, shiftKey, commandKey); - return detail; - }; - return WheelEventDetail; - }(InputEventDetail)); - exports.WheelEventDetail = WheelEventDetail; - ; + "use strict"; + var __extends = (this && this.__extends) || (function () { + var extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + return function (d, b) { + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; + })(); + Object.defineProperty(exports, "__esModule", { value: true }); + /** + * 输入事件的详细信息。 + */ + var InputEventDetail = (function () { + function InputEventDetail(altKey, ctrlKey, shiftKey, commandKey) { + this.altKey = altKey; + this.ctrlKey = ctrlKey; + this.shiftKey = shiftKey; + this.commandKey = commandKey; + } + return InputEventDetail; + }()); + exports.InputEventDetail = InputEventDetail; + ; + /** + * 指针事件的详细信息。 + */ + var PointerEventDetail = (function (_super) { + __extends(PointerEventDetail, _super); + function PointerEventDetail(id, x, y, altKey, ctrlKey, shiftKey, commandKey) { + var _this = _super.call(this, altKey, ctrlKey, shiftKey, commandKey) || this; + _this.id = id; + _this.x = x; + _this.y = y; + _this.pointerDown = false; + _this.pointerDownX = 0; + _this.pointerDownY = 0; + _this.pointerDownTime = 0; + return _this; + } + /** + * 设置指针按下的状态。 + */ + PointerEventDetail.prototype.setPointerDown = function (pointerDown, x, y, t) { + this.pointerDownX = x; + this.pointerDownY = y; + this.pointerDownTime = t; + this.pointerDown = pointerDown; + }; + PointerEventDetail.prototype.dispose = function () { + }; + PointerEventDetail.create = function (id, x, y, altKey, ctrlKey, shiftKey, commandKey) { + var detail = new PointerEventDetail(id, x, y, altKey, ctrlKey, shiftKey, commandKey); + return detail; + }; + return PointerEventDetail; + }(InputEventDetail)); + exports.PointerEventDetail = PointerEventDetail; + ; + /** + * 按键事件的详细信息。 + */ + var KeyEventDetail = (function (_super) { + __extends(KeyEventDetail, _super); + function KeyEventDetail(keyCode, altKey, ctrlKey, shiftKey, commandKey) { + var _this = _super.call(this, altKey, ctrlKey, shiftKey, commandKey) || this; + _this.keyCode = keyCode; + return _this; + } + KeyEventDetail.prototype.dispose = function () { + }; + KeyEventDetail.create = function (keyCode, altKey, ctrlKey, shiftKey, commandKey) { + var detail = new KeyEventDetail(keyCode, altKey, ctrlKey, shiftKey, commandKey); + return detail; + }; + return KeyEventDetail; + }(InputEventDetail)); + exports.KeyEventDetail = KeyEventDetail; + ; + /** + * 滚轮事件的详细信息。 + */ + var WheelEventDetail = (function (_super) { + __extends(WheelEventDetail, _super); + function WheelEventDetail(delta, altKey, ctrlKey, shiftKey, commandKey) { + var _this = _super.call(this, altKey, ctrlKey, shiftKey, commandKey) || this; + _this.delta = delta; + return _this; + } + WheelEventDetail.prototype.dispose = function () { + }; + WheelEventDetail.create = function (delta, altKey, ctrlKey, shiftKey, commandKey) { + var detail = new WheelEventDetail(delta, altKey, ctrlKey, shiftKey, commandKey); + return detail; + }; + return WheelEventDetail; + }(InputEventDetail)); + exports.WheelEventDetail = WheelEventDetail; + ; /***/ }, /* 15 */ /***/ function(module, exports, __webpack_require__) { - "use strict"; - var Events = __webpack_require__(6); - var key_event_1 = __webpack_require__(16); - var emitter_1 = __webpack_require__(4); - var event_detail_1 = __webpack_require__(14); - var grabs = []; - var keyGrabs = []; - var lastDetail; - var ctrlKey = false; - var altKey = false; - var shiftKey = false; - var commandKey = false; - var pointerDeviceType; - var pointerDown = false; - var pointerDownX = 0; - var pointerDownY = 0; - var pointerDownTime = 0; - var pointerMoved = false; - var globalInputEmitter = new emitter_1.Emitter(); - var lastClickTime = 0; - function dispatchEvent(target, type, detail) { - var realTarget = target; - if (grabs.length) { - realTarget = grabs[grabs.length - 1]; - } - else if (keyGrabs.length) { - if ((type === Events.KEYDOWN || type === Events.KEYUP) && target.tagName === "BODY") { - realTarget = keyGrabs[keyGrabs.length - 1]; - } - } - var event = new CustomEvent(type, { detail: detail }); - globalInputEmitter.dispatchEvent(event); - realTarget.dispatchEvent(event); - } - function getPointerDetail(e, timeStamp) { - if (e) { - var id = e.identifier || 0; - var x = Math.max(e.pageX || 0, e.x || e.clientX); - var y = Math.max(e.pageY || 0, e.y || e.clientY); - lastDetail = event_detail_1.PointerEventDetail.create(id, x, y, altKey, ctrlKey, shiftKey, commandKey); - lastDetail.timeStamp = e.timeStamp || timeStamp; - } - return lastDetail; - } - function dispatchPointerEvent(type, target, detail) { - if (type === Events.POINTER_DOWN) { - pointerDown = true; - pointerDownX = detail.x; - pointerDownY = detail.y; - pointerDownTime = Date.now(); - pointerMoved = false; - } - else if (type === Events.POINTER_UP) { - var now = Date.now(); - detail.setPointerDown(pointerDown, pointerDownX, pointerDownY, pointerDownTime); - if ((now - lastClickTime) > 500) { - //双击只触发一次click事件。 - dispatchEvent(target, Events.CLICK, detail); - } - lastClickTime = now; - pointerDown = false; - pointerMoved = false; - } - else { - pointerMoved = true; - detail.setPointerDown(pointerDown, pointerDownX, pointerDownY, pointerDownTime); - } - dispatchEvent(target, type, detail); - detail.dispose(); - } - function onMouseDown(evt) { - dispatchPointerEvent(Events.POINTER_DOWN, evt.target, getPointerDetail(evt)); - } - function onMouseMove(evt) { - dispatchPointerEvent(Events.POINTER_MOVE, evt.target, getPointerDetail(evt)); - } - function onMouseUp(evt) { - dispatchPointerEvent(Events.POINTER_UP, evt.target, getPointerDetail(evt)); - } - function onDblClick(evt) { - dispatchPointerEvent(Events.DBLCLICK, evt.target, getPointerDetail(evt)); - } - function onMouseOut(evt) { - dispatchPointerEvent(Events.POINTER_OUT, evt.target, getPointerDetail(evt)); - } - function onMouseOver(evt) { - dispatchPointerEvent(Events.POINTER_OVER, evt.target, getPointerDetail(evt)); - } - function getTouchPoints(evt) { - var touches = evt.touches || evt.changedTouches || evt.touchList || evt.targetTouches; - var n = touches.length; - var ret = []; - for (var i = 0; i < n; i++) { - ret.push(getPointerDetail(touches[i])); - } - if (ret.length < 1) { - ret.push(getPointerDetail(null)); - } - return ret; - } - function onTouchStart(evt) { - var detail = getPointerDetail(getTouchPoints(evt)[0], evt.timeStamp); - dispatchPointerEvent(Events.POINTER_DOWN, evt.target, detail); - evt.preventDefault(); - } - function onTouchMove(evt) { - var detail = getPointerDetail(getTouchPoints(evt)[0], evt.timeStamp); - dispatchPointerEvent(Events.POINTER_MOVE, evt.target, detail); - evt.preventDefault(); - } - function onTouchEnd(evt) { - var detail = getPointerDetail(getTouchPoints(evt)[0], evt.timeStamp); - dispatchPointerEvent(Events.POINTER_UP, evt.target, detail); - evt.preventDefault(); - } - function onPointerDown(evt) { - dispatchPointerEvent(Events.POINTER_DOWN, evt.target, getPointerDetail(evt)); - } - function onPointerMove(evt) { - dispatchPointerEvent(Events.POINTER_MOVE, evt.target, getPointerDetail(evt)); - } - function onPointerUp(evt) { - dispatchPointerEvent(Events.POINTER_UP, evt.target, getPointerDetail(evt)); - } - function onWheel(evt) { - var delta = evt.wheelDelta || evt.detail * -8; - var detail = event_detail_1.WheelEventDetail.create(delta, altKey, ctrlKey, shiftKey, commandKey); - detail.timeStamp = evt.timeStamp; - dispatchEvent(evt.target, Events.WHEEL, detail); - detail.dispose(); - } - function updateKeysStatus(keyCode, value) { - switch (keyCode) { - case key_event_1.KeyEvent.VK_CONTROL: { - ctrlKey = value; - break; - } - case key_event_1.KeyEvent.VK_ALT: { - altKey = value; - break; - } - case key_event_1.KeyEvent.VK_SHIFT: { - shiftKey = value; - break; - } - case key_event_1.KeyEvent.VK_COMMAND: { - commandKey = value; - break; - } - } - } - function onKeyDown(evt) { - updateKeysStatus(evt.keyCode, true); - var detail = event_detail_1.KeyEventDetail.create(evt.keyCode, altKey, ctrlKey, shiftKey, commandKey); - detail.timeStamp = evt.timeStamp; - dispatchEvent(evt.target, Events.KEYDOWN, detail); - detail.dispose(); - var tagName = evt.target.tagName; - if (tagName !== "INPUT" && tagName !== "TEXTAREA") { - evt.preventDefault(); - } - } - function onKeyUp(evt) { - updateKeysStatus(evt.keyCode, false); - var detail = event_detail_1.KeyEventDetail.create(evt.keyCode, altKey, ctrlKey, shiftKey, commandKey); - detail.timeStamp = evt.timeStamp; - dispatchEvent(evt.target, Events.KEYUP, detail); - detail.dispose(); - var tagName = evt.target.tagName; - if (tagName !== "INPUT" && tagName !== "TEXTAREA") { - evt.preventDefault(); - } - } - function dispatchKeyEvent(target, keyCode) { - var detail = event_detail_1.KeyEventDetail.create(keyCode, altKey, ctrlKey, shiftKey, commandKey); - dispatchEvent(target, Events.KEYDOWN, detail); - dispatchEvent(target, Events.KEYUP, detail); - detail.dispose(); - } - /** - * 初始化。 - * - * InputEventAdapter如其名所示,是对输入事件的适配,为上层提供统一的接口。主要功能有: - * - * 1.把鼠标事件、触屏事件和指针事件统一成qtk-pointer事件。 - * - * 2.把DOMMouseScroll和mousewheel事件统一成qtk-wheel事件。 - * - * 3.把keydown/keyup事件转换成qtk-keydown/qtk-keyup事件。 - * - * 4.把tizen和phonegap的按键事件转换成标准的key事件。 - * - * 5.实现grab/ungrab功能。事件优先发给最后grab的target。 - * - * @param doc document对象。 - * @param win window对象。 - * @param pointerSupported 当前系统是否支持pointer事件。 - * @param msPointerSupported 当前系统是否支持ms pointer事件。 - * @param touchSupported 当前系统是否支持触屏事件。 - * - */ - function init(doc, win, pointerSupported, msPointerSupported, touchSupported) { - doc.addEventListener('tizenhwkey', function (evt) { - dispatchKeyEvent(evt.target, key_event_1.KeyEvent.VK_TIZEN_HW); - }); - doc.addEventListener("backbutton", function (evt) { - dispatchKeyEvent(evt.target, key_event_1.KeyEvent.VK_BACK); - }); - doc.addEventListener("menubutton", function (evt) { - dispatchKeyEvent(evt.target, key_event_1.KeyEvent.VK_MENU); - }); - doc.addEventListener("searchbutton", function (evt) { - dispatchKeyEvent(evt.target, key_event_1.KeyEvent.VK_SEARCH); - }); - if (pointerSupported) { - pointerDeviceType = "pointer"; - doc.addEventListener('pointerdown', onPointerDown); - doc.addEventListener('pointermove', onPointerMove); - doc.addEventListener('pointerup', onPointerUp); - doc.addEventListener('mousewheel', onWheel); - } - else if (msPointerSupported) { - pointerDeviceType = "pointer"; - doc.addEventListener('MSPointerDown', onPointerDown); - doc.addEventListener('MSPointerMove', onPointerMove); - doc.addEventListener('MSPointerUp', onPointerUp); - doc.addEventListener('mousewheel', onWheel); - } - else if (touchSupported) { - pointerDeviceType = "touch"; - doc.addEventListener('touchstart', onTouchStart); - doc.addEventListener('touchmove', onTouchMove); - doc.addEventListener('touchend', onTouchEnd); - } - else { - pointerDeviceType = "mouse"; - doc.addEventListener('mousedown', onMouseDown); - doc.addEventListener('mousemove', onMouseMove); - doc.addEventListener('mouseup', onMouseUp); - doc.addEventListener('mouseout', onMouseOut); - doc.addEventListener('mouseover', onMouseOver); - doc.addEventListener('dblclick', onDblClick); - } - doc.addEventListener('mousewheel', onWheel); - doc.addEventListener('DOMMouseScroll', onWheel); - doc.addEventListener('keyup', onKeyUp); - doc.addEventListener('keydown', onKeyDown); - } - exports.init = init; - /** - * grab输入事件。输入事件后发送给最后grab的target。 - */ - function grab(target) { - grabs.push(target); - } - exports.grab = grab; - /** - * ungrab移出最后grab的target。 - */ - function ungrab(target) { - return grabs.remove(target); - } - exports.ungrab = ungrab; - /** - * grab输入事件。输入事件后发送给最后grab的target。 - */ - function grabKey(target) { - keyGrabs.push(target); - } - exports.grabKey = grabKey; - /** - * ungrab移出最后grab的target。 - */ - function ungrabKey(target) { - return keyGrabs.pop(); - } - exports.ungrabKey = ungrabKey; - /** - * 注册全局的Input事件。 - */ - function on(type, callback) { - globalInputEmitter.on(type, callback); - } - exports.on = on; - /** - * 注销全局的Input事件。 - */ - function off(type, callback) { - globalInputEmitter.off(type, callback); - } - exports.off = off; + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + var Events = __webpack_require__(6); + var key_event_1 = __webpack_require__(16); + var emitter_1 = __webpack_require__(4); + var event_detail_1 = __webpack_require__(14); + var grabs = []; + var keyGrabs = []; + var lastDetail; + var ctrlKey = false; + var altKey = false; + var shiftKey = false; + var commandKey = false; + var pointerDeviceType; + var pointerDown = false; + var pointerDownX = 0; + var pointerDownY = 0; + var pointerDownTime = 0; + var pointerMoved = false; + var globalInputEmitter = new emitter_1.Emitter(); + var lastClickTime = 0; + function dispatchEvent(target, type, detail) { + var realTarget = target; + if (grabs.length) { + realTarget = grabs[grabs.length - 1]; + } + else if (keyGrabs.length) { + if ((type === Events.KEYDOWN || type === Events.KEYUP) && target.tagName === "BODY") { + realTarget = keyGrabs[keyGrabs.length - 1]; + } + } + var event = new CustomEvent(type, { detail: detail }); + globalInputEmitter.dispatchEvent(event); + realTarget.dispatchEvent(event); + } + function getPointerDetail(e, timeStamp) { + if (e) { + var id = e.identifier || 0; + var x = Math.max(e.pageX || 0, e.x || e.clientX); + var y = Math.max(e.pageY || 0, e.y || e.clientY); + lastDetail = event_detail_1.PointerEventDetail.create(id, x, y, altKey, ctrlKey, shiftKey, commandKey); + lastDetail.timeStamp = e.timeStamp || timeStamp; + } + return lastDetail; + } + function dispatchPointerEvent(type, target, detail) { + if (type === Events.POINTER_DOWN) { + pointerDown = true; + pointerDownX = detail.x; + pointerDownY = detail.y; + pointerDownTime = Date.now(); + pointerMoved = false; + } + else if (type === Events.POINTER_UP) { + var now = Date.now(); + detail.setPointerDown(pointerDown, pointerDownX, pointerDownY, pointerDownTime); + if ((now - lastClickTime) > 500) { + //双击只触发一次click事件。 + dispatchEvent(target, Events.CLICK, detail); + } + lastClickTime = now; + pointerDown = false; + pointerMoved = false; + } + else { + pointerMoved = true; + detail.setPointerDown(pointerDown, pointerDownX, pointerDownY, pointerDownTime); + } + dispatchEvent(target, type, detail); + detail.dispose(); + } + function onMouseDown(evt) { + dispatchPointerEvent(Events.POINTER_DOWN, evt.target, getPointerDetail(evt)); + } + function onMouseMove(evt) { + dispatchPointerEvent(Events.POINTER_MOVE, evt.target, getPointerDetail(evt)); + } + function onMouseUp(evt) { + dispatchPointerEvent(Events.POINTER_UP, evt.target, getPointerDetail(evt)); + } + function onDblClick(evt) { + dispatchPointerEvent(Events.DBLCLICK, evt.target, getPointerDetail(evt)); + } + function onMouseOut(evt) { + dispatchPointerEvent(Events.POINTER_OUT, evt.target, getPointerDetail(evt)); + } + function onMouseOver(evt) { + dispatchPointerEvent(Events.POINTER_OVER, evt.target, getPointerDetail(evt)); + } + function getTouchPoints(evt) { + var touches = evt.touches || evt.changedTouches || evt.touchList || evt.targetTouches; + var n = touches.length; + var ret = []; + for (var i = 0; i < n; i++) { + ret.push(getPointerDetail(touches[i])); + } + if (ret.length < 1) { + ret.push(getPointerDetail(null)); + } + return ret; + } + function onTouchStart(evt) { + var detail = getPointerDetail(getTouchPoints(evt)[0], evt.timeStamp); + dispatchPointerEvent(Events.POINTER_DOWN, evt.target, detail); + evt.preventDefault(); + } + function onTouchMove(evt) { + var detail = getPointerDetail(getTouchPoints(evt)[0], evt.timeStamp); + dispatchPointerEvent(Events.POINTER_MOVE, evt.target, detail); + evt.preventDefault(); + } + function onTouchEnd(evt) { + var detail = getPointerDetail(getTouchPoints(evt)[0], evt.timeStamp); + dispatchPointerEvent(Events.POINTER_UP, evt.target, detail); + evt.preventDefault(); + } + function onPointerDown(evt) { + dispatchPointerEvent(Events.POINTER_DOWN, evt.target, getPointerDetail(evt)); + } + function onPointerMove(evt) { + dispatchPointerEvent(Events.POINTER_MOVE, evt.target, getPointerDetail(evt)); + } + function onPointerUp(evt) { + dispatchPointerEvent(Events.POINTER_UP, evt.target, getPointerDetail(evt)); + } + function onWheel(evt) { + var delta = evt.wheelDelta || evt.detail * -8; + var detail = event_detail_1.WheelEventDetail.create(delta, altKey, ctrlKey, shiftKey, commandKey); + detail.timeStamp = evt.timeStamp; + dispatchEvent(evt.target, Events.WHEEL, detail); + detail.dispose(); + } + function updateKeysStatus(keyCode, value) { + switch (keyCode) { + case key_event_1.KeyEvent.VK_CONTROL: { + ctrlKey = value; + break; + } + case key_event_1.KeyEvent.VK_ALT: { + altKey = value; + break; + } + case key_event_1.KeyEvent.VK_SHIFT: { + shiftKey = value; + break; + } + case key_event_1.KeyEvent.VK_COMMAND: { + commandKey = value; + break; + } + } + } + function onKeyDown(evt) { + updateKeysStatus(evt.keyCode, true); + var detail = event_detail_1.KeyEventDetail.create(evt.keyCode, altKey, ctrlKey, shiftKey, commandKey); + detail.timeStamp = evt.timeStamp; + dispatchEvent(evt.target, Events.KEYDOWN, detail); + detail.dispose(); + var tagName = evt.target.tagName; + if (tagName !== "INPUT" && tagName !== "TEXTAREA") { + evt.preventDefault(); + } + } + function onKeyUp(evt) { + updateKeysStatus(evt.keyCode, false); + var detail = event_detail_1.KeyEventDetail.create(evt.keyCode, altKey, ctrlKey, shiftKey, commandKey); + detail.timeStamp = evt.timeStamp; + dispatchEvent(evt.target, Events.KEYUP, detail); + detail.dispose(); + var tagName = evt.target.tagName; + if (tagName !== "INPUT" && tagName !== "TEXTAREA") { + evt.preventDefault(); + } + } + function dispatchKeyEvent(target, keyCode) { + var detail = event_detail_1.KeyEventDetail.create(keyCode, altKey, ctrlKey, shiftKey, commandKey); + dispatchEvent(target, Events.KEYDOWN, detail); + dispatchEvent(target, Events.KEYUP, detail); + detail.dispose(); + } + /** + * 初始化。 + * + * InputEventAdapter如其名所示,是对输入事件的适配,为上层提供统一的接口。主要功能有: + * + * 1.把鼠标事件、触屏事件和指针事件统一成qtk-pointer事件。 + * + * 2.把DOMMouseScroll和mousewheel事件统一成qtk-wheel事件。 + * + * 3.把keydown/keyup事件转换成qtk-keydown/qtk-keyup事件。 + * + * 4.把tizen和phonegap的按键事件转换成标准的key事件。 + * + * 5.实现grab/ungrab功能。事件优先发给最后grab的target。 + * + * @param doc document对象。 + * @param win window对象。 + * @param pointerSupported 当前系统是否支持pointer事件。 + * @param msPointerSupported 当前系统是否支持ms pointer事件。 + * @param touchSupported 当前系统是否支持触屏事件。 + * + */ + function init(doc, win, pointerSupported, msPointerSupported, touchSupported) { + doc.addEventListener('tizenhwkey', function (evt) { + dispatchKeyEvent(evt.target, key_event_1.KeyEvent.VK_TIZEN_HW); + }); + doc.addEventListener("backbutton", function (evt) { + dispatchKeyEvent(evt.target, key_event_1.KeyEvent.VK_BACK); + }); + doc.addEventListener("menubutton", function (evt) { + dispatchKeyEvent(evt.target, key_event_1.KeyEvent.VK_MENU); + }); + doc.addEventListener("searchbutton", function (evt) { + dispatchKeyEvent(evt.target, key_event_1.KeyEvent.VK_SEARCH); + }); + if (pointerSupported) { + pointerDeviceType = "pointer"; + doc.addEventListener('pointerdown', onPointerDown); + doc.addEventListener('pointermove', onPointerMove); + doc.addEventListener('pointerup', onPointerUp); + doc.addEventListener('mousewheel', onWheel); + } + else if (msPointerSupported) { + pointerDeviceType = "pointer"; + doc.addEventListener('MSPointerDown', onPointerDown); + doc.addEventListener('MSPointerMove', onPointerMove); + doc.addEventListener('MSPointerUp', onPointerUp); + doc.addEventListener('mousewheel', onWheel); + } + else if (touchSupported) { + pointerDeviceType = "touch"; + doc.addEventListener('touchstart', onTouchStart); + doc.addEventListener('touchmove', onTouchMove); + doc.addEventListener('touchend', onTouchEnd); + } + else { + pointerDeviceType = "mouse"; + doc.addEventListener('mousedown', onMouseDown); + doc.addEventListener('mousemove', onMouseMove); + doc.addEventListener('mouseup', onMouseUp); + doc.addEventListener('mouseout', onMouseOut); + doc.addEventListener('mouseover', onMouseOver); + doc.addEventListener('dblclick', onDblClick); + } + doc.addEventListener('mousewheel', onWheel); + doc.addEventListener('DOMMouseScroll', onWheel); + doc.addEventListener('keyup', onKeyUp); + doc.addEventListener('keydown', onKeyDown); + } + exports.init = init; + /** + * grab输入事件。输入事件后发送给最后grab的target。 + */ + function grab(target) { + grabs.push(target); + } + exports.grab = grab; + /** + * ungrab移出最后grab的target。 + */ + function ungrab(target) { + return grabs.remove(target); + } + exports.ungrab = ungrab; + /** + * grab输入事件。输入事件后发送给最后grab的target。 + */ + function grabKey(target) { + keyGrabs.push(target); + } + exports.grabKey = grabKey; + /** + * ungrab移出最后grab的target。 + */ + function ungrabKey(target) { + return keyGrabs.pop(); + } + exports.ungrabKey = ungrabKey; + /** + * 注册全局的Input事件。 + */ + function on(type, callback) { + globalInputEmitter.on(type, callback); + } + exports.on = on; + /** + * 注销全局的Input事件。 + */ + function off(type, callback) { + globalInputEmitter.off(type, callback); + } + exports.off = off; /***/ }, /* 16 */ /***/ function(module, exports) { - "use strict"; - exports.KeyEvent = { - VK_CANCEL: 3, - VK_HELP: 6, - VK_BACK_SPACE: 8, - VK_TAB: 9, - VK_CLEAR: 12, - VK_RETURN: 13, - VK_ENTER: 14, - VK_SHIFT: 16, - VK_CONTROL: 17, - VK_ALT: 18, - VK_PAUSE: 19, - VK_CAPS_LOCK: 20, - VK_ESCAPE: 27, - VK_SPACE: 32, - VK_PAGE_UP: 33, - VK_PAGE_DOWN: 34, - VK_END: 35, - VK_HOME: 36, - VK_LEFT: 37, - VK_UP: 38, - VK_RIGHT: 39, - VK_DOWN: 40, - VK_PRINTSCREEN: 44, - VK_INSERT: 45, - VK_DELETE: 46, - VK_0: 48, - VK_1: 49, - VK_2: 50, - VK_3: 51, - VK_4: 52, - VK_5: 53, - VK_6: 54, - VK_7: 55, - VK_8: 56, - VK_9: 57, - VK_SEMICOLON: 59, - VK_EQUALS: 61, - VK_A: 65, - VK_B: 66, - VK_C: 67, - VK_D: 68, - VK_E: 69, - VK_F: 70, - VK_G: 71, - VK_H: 72, - VK_I: 73, - VK_J: 74, - VK_K: 75, - VK_L: 76, - VK_M: 77, - VK_N: 78, - VK_O: 79, - VK_P: 80, - VK_Q: 81, - VK_R: 82, - VK_S: 83, - VK_T: 84, - VK_U: 85, - VK_V: 86, - VK_W: 87, - VK_X: 88, - VK_Y: 89, - VK_Z: 90, - VK_COMMAND: 91, - VK_CONTEXT_MENU: 93, - VK_NUMPAD0: 96, - VK_NUMPAD1: 97, - VK_NUMPAD2: 98, - VK_NUMPAD3: 99, - VK_NUMPAD4: 100, - VK_NUMPAD5: 101, - VK_NUMPAD6: 102, - VK_NUMPAD7: 103, - VK_NUMPAD8: 104, - VK_NUMPAD9: 105, - VK_MULTIPLY: 106, - VK_ADD: 107, - VK_SEPARATOR: 108, - VK_SUBTRACT: 109, - VK_DECIMAL: 110, - VK_DIVIDE: 111, - VK_F1: 112, - VK_F2: 113, - VK_F3: 114, - VK_F4: 115, - VK_F5: 116, - VK_F6: 117, - VK_F7: 118, - VK_F8: 119, - VK_F9: 120, - VK_F10: 121, - VK_F11: 122, - VK_F12: 123, - VK_F13: 124, - VK_F14: 125, - VK_F15: 126, - VK_F16: 127, - VK_F17: 128, - VK_F18: 129, - VK_F19: 130, - VK_F20: 131, - VK_F21: 132, - VK_F22: 133, - VK_F23: 134, - VK_F24: 135, - VK_BACK: 136, - VK_MENU: 137, - VK_SEARCH: 138, - VK_TIZEN_HW: 139, - VK_NUM_LOCK: 144, - VK_SCROLL_LOCK: 145, - VK_COMMA: 188, - VK_PERIOD: 190, - VK_SLASH: 191, - VK_BACK_QUOTE: 192, - VK_OPEN_BRACKET: 219, - VK_BACK_SLASH: 220, - VK_CLOSE_BRACKET: 221, - VK_QUOTE: 222, - VK_META: 224 - }; + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + exports.KeyEvent = { + VK_CANCEL: 3, + VK_HELP: 6, + VK_BACK_SPACE: 8, + VK_TAB: 9, + VK_CLEAR: 12, + VK_RETURN: 13, + VK_ENTER: 14, + VK_SHIFT: 16, + VK_CONTROL: 17, + VK_ALT: 18, + VK_PAUSE: 19, + VK_CAPS_LOCK: 20, + VK_ESCAPE: 27, + VK_SPACE: 32, + VK_PAGE_UP: 33, + VK_PAGE_DOWN: 34, + VK_END: 35, + VK_HOME: 36, + VK_LEFT: 37, + VK_UP: 38, + VK_RIGHT: 39, + VK_DOWN: 40, + VK_PRINTSCREEN: 44, + VK_INSERT: 45, + VK_DELETE: 46, + VK_0: 48, + VK_1: 49, + VK_2: 50, + VK_3: 51, + VK_4: 52, + VK_5: 53, + VK_6: 54, + VK_7: 55, + VK_8: 56, + VK_9: 57, + VK_SEMICOLON: 59, + VK_EQUALS: 61, + VK_A: 65, + VK_B: 66, + VK_C: 67, + VK_D: 68, + VK_E: 69, + VK_F: 70, + VK_G: 71, + VK_H: 72, + VK_I: 73, + VK_J: 74, + VK_K: 75, + VK_L: 76, + VK_M: 77, + VK_N: 78, + VK_O: 79, + VK_P: 80, + VK_Q: 81, + VK_R: 82, + VK_S: 83, + VK_T: 84, + VK_U: 85, + VK_V: 86, + VK_W: 87, + VK_X: 88, + VK_Y: 89, + VK_Z: 90, + VK_COMMAND: 91, + VK_CONTEXT_MENU: 93, + VK_NUMPAD0: 96, + VK_NUMPAD1: 97, + VK_NUMPAD2: 98, + VK_NUMPAD3: 99, + VK_NUMPAD4: 100, + VK_NUMPAD5: 101, + VK_NUMPAD6: 102, + VK_NUMPAD7: 103, + VK_NUMPAD8: 104, + VK_NUMPAD9: 105, + VK_MULTIPLY: 106, + VK_ADD: 107, + VK_SEPARATOR: 108, + VK_SUBTRACT: 109, + VK_DECIMAL: 110, + VK_DIVIDE: 111, + VK_F1: 112, + VK_F2: 113, + VK_F3: 114, + VK_F4: 115, + VK_F5: 116, + VK_F6: 117, + VK_F7: 118, + VK_F8: 119, + VK_F9: 120, + VK_F10: 121, + VK_F11: 122, + VK_F12: 123, + VK_F13: 124, + VK_F14: 125, + VK_F15: 126, + VK_F16: 127, + VK_F17: 128, + VK_F18: 129, + VK_F19: 130, + VK_F20: 131, + VK_F21: 132, + VK_F22: 133, + VK_F23: 134, + VK_F24: 135, + VK_BACK: 136, + VK_MENU: 137, + VK_SEARCH: 138, + VK_TIZEN_HW: 139, + VK_NUM_LOCK: 144, + VK_SCROLL_LOCK: 145, + VK_COMMA: 188, + VK_PERIOD: 190, + VK_SLASH: 191, + VK_BACK_QUOTE: 192, + VK_OPEN_BRACKET: 219, + VK_BACK_SLASH: 220, + VK_CLOSE_BRACKET: 221, + VK_QUOTE: 222, + VK_META: 224 + }; /***/ }, /* 17 */ /***/ function(module, exports, __webpack_require__) { - "use strict"; - var __extends = (this && this.__extends) || function (d, b) { - for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; - var rect_1 = __webpack_require__(1); - var point_1 = __webpack_require__(2); - var label_1 = __webpack_require__(18); - var Events = __webpack_require__(6); - var key_event_1 = __webpack_require__(16); - var html_edit_1 = __webpack_require__(86); - var widget_1 = __webpack_require__(19); - var widget_factory_1 = __webpack_require__(24); - var graphics_1 = __webpack_require__(26); - var widget_recyclable_creator_1 = __webpack_require__(84); - /** - * 编辑器。multiLineMode决定是多行编辑器还是单行编辑器。 - */ - var Edit = (function (_super) { - __extends(Edit, _super); - function Edit() { - _super.call(this, Edit.TYPE); - this.onWheel = function () { - var input = this._input; - if (input) { - input.hide(); - this.hideEditor(); - } - }.bind(this); - this.drawInvalidInputTips = function (evt) { - var win = this.win; - var tm = this._themeManager; - var text = this._validationTips; - var style = tm.get("edit.invalid.tips", this.stateToString(widget_1.WidgetState.NORMAL)); - if (!this._isEditing || !text || !style) { - return; - } - var maxH = win.h; - var maxW = win.w; - var ctx = evt.ctx; - var p = this.toGlobalPoint(point_1.Point.point.init(0, 0)); - var width = graphics_1.Graphics.measureText(text, style.font) + 20; - var x = p.x - win.x; - var y = p.y - win.y + 5; - if ((x + width) >= maxW) { - x = maxW - width; - } - var r = null; - if ((y + this.h) < maxH) { - r = rect_1.Rect.rect.init(x, y + this.h, width, 30); - } - else { - r = rect_1.Rect.rect.init(x, y, width, 30); - } - graphics_1.Graphics.drawRoundRect(ctx, style.backGroundColor, style.lineColor, style.lineWidth, r.x, r.y, r.w, r.h, style.roundRadius); - graphics_1.Graphics.drawTextSL(ctx, text, style, r); - }.bind(this); - } - Object.defineProperty(Edit.prototype, "inputable", { - get: function () { - return true; - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(Edit.prototype, "inputFilter", { - /** - * 输入过滤器,对输入的文本进行转换。 - */ - set: function (value) { - this._inputFilter = value; - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(Edit.prototype, "inputTips", { - get: function () { - return this._it; - }, - /** - * 输入提示。 - */ - set: function (value) { - this._it = value; - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(Edit.prototype, "inputType", { - get: function () { - return this._itp; - }, - /** - * 输入类型。 - */ - set: function (value) { - this._itp = value; - }, - enumerable: true, - configurable: true - }); - Edit.prototype.draw = function (ctx) { - if (!this._isEditing) { - _super.prototype.draw.call(this, ctx); - } - else { - } - }; - Edit.prototype.relayoutText = function () { - if (!this._isEditing) { - _super.prototype.relayoutText.call(this); - } - return this; - }; - Edit.prototype.drawText = function (ctx, style) { - if (this._textLines && this._textLines.length) { - _super.prototype.drawText.call(this, ctx, style); - } - else if (this._it) { - this.drawTextSL(ctx, this._it, style); - } - return this; - }; - Edit.prototype.getStyleType = function () { - if (this._styleType) { - return this._styleType; - } - else { - if (this._text || this._isEditing) { - return this.multiLineMode ? "edit.ml" : "edit.sl"; - } - else { - return this.multiLineMode ? "edit.ml.tips" : "edit.sl.tips"; - } - } - }; - Edit.prototype.filterText = function (value) { - return this._inputFilter ? this._inputFilter(value) : value; - }; - Edit.prototype.hideEditor = function () { - if (this._isEditing) { - this._isEditing = false; - this.relayoutText(); - this._input = null; - this.dispatchEvent({ type: Events.BLUR }); - this.win.off(Events.WHEEL, this.onWheel); - } - this.requestRedraw(); - }; - Edit.prototype.notifyChangeEx = function (type, value, oldValue) { - var e = this.eChangeEvent; - e.init(type, { value: value, oldValue: oldValue }); - ; - this.dispatchEvent(e); - }; - Edit.prototype.showEditor = function () { - var _this = this; - var style = this.getStyle(); - this._input = this.multiLineMode ? html_edit_1.HtmlEdit.textArea : html_edit_1.HtmlEdit.input; - var input = this._input; - var vp = this.app.getViewPort(); - var p = this.toViewPoint(point_1.Point.point.init(0, 0)); - var borderWidth = input.borderWidth * 2; - var x = Math.max(0, p.x); - var y = Math.max(0, p.y); - var w = Math.min(this.w, vp.w - x - borderWidth); - var h = Math.min(this.h, vp.h - y - borderWidth); - input.move(x, y); - input.resize(w, h); - input.fontSize = style.fontSize; - input.inputType = this.inputType; - input.textColor = style.textColor; - input.fontFamily = style.fontFamily; - input.text = this.text || ""; - input.show(); - input.z = this.win.z + 1; - var oldValue = this.value; - this.dispatchEvent({ type: Events.FOCUS }); - this.win.on(Events.WHEEL, this.onWheel); - input.on(Events.HIDE, function (evt) { - _this.hideEditor(); - }); - input.on(Events.CHANGING, function (evt) { - _this.text = _this.filterText(evt.value); - var value = _this.inputType === "number" ? +_this.text : _this.text; - _this.notifyChangeEx(Events.CHANGING, value, null); - }); - input.on(Events.CHANGE, function (evt) { - _this.text = _this.filterText(evt.value); - var value = _this.inputType === "number" ? +_this.text : _this.text; - _this.notifyChangeEx(Events.CHANGE, value, oldValue); - }); - input.on(Events.KEYDOWN, function (evt) { - _this.dispatchEvent(evt); - }); - input.on(Events.KEYUP, function (evt) { - if (!_this.multiLineMode && evt.keyCode === key_event_1.KeyEvent.VK_RETURN) { - _this.dispatchEvent({ type: Events.CONFIRM }); - } - _this.dispatchEvent(evt); - }); - }; - Object.defineProperty(Edit.prototype, "validationTips", { - set: function (value) { - this._validationTips = value; - }, - enumerable: true, - configurable: true - }); - Edit.prototype.onInvalidInput = function (message) { - var win = this.win; - if (this._validationTips === message) { - return; - } - this._validationTips = message; - win.off(Events.AFTER_DRAW, this.drawInvalidInputTips); - if (message) { - win.on(Events.AFTER_DRAW, this.drawInvalidInputTips); - } - win.requestRedraw(); - }; - Edit.prototype.dispose = function () { - _super.prototype.dispose.call(this); - this._input = null; - this._inputFilter = null; - }; - Edit.prototype.dispatchClick = function (evt) { - _super.prototype.dispatchClick.call(this, evt); - if (!this._isEditing) { - this._isEditing = true; - this.showEditor(); - } - }; - Edit.prototype.getDefProps = function () { - return Edit.defProps; - }; - Edit.create = function (options) { - return Edit.r.create(options); - }; - Edit.defProps = Object.assign({}, label_1.Label.defProps, { _mlm: false, _it: null, _itp: null }); - Edit.TYPE = "edit"; - Edit.r = widget_recyclable_creator_1.WidgetRecyclableCreator.create(Edit); - return Edit; - }(label_1.Label)); - exports.Edit = Edit; - ; - widget_factory_1.WidgetFactory.register(Edit.TYPE, Edit.create); + "use strict"; + var __extends = (this && this.__extends) || (function () { + var extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + return function (d, b) { + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; + })(); + Object.defineProperty(exports, "__esModule", { value: true }); + var rect_1 = __webpack_require__(1); + var point_1 = __webpack_require__(2); + var label_1 = __webpack_require__(18); + var Events = __webpack_require__(6); + var key_event_1 = __webpack_require__(16); + var html_edit_1 = __webpack_require__(92); + var widget_1 = __webpack_require__(19); + var widget_factory_1 = __webpack_require__(24); + var graphics_1 = __webpack_require__(26); + var widget_recyclable_creator_1 = __webpack_require__(90); + /** + * 编辑器。multiLineMode决定是多行编辑器还是单行编辑器。 + */ + var Edit = (function (_super) { + __extends(Edit, _super); + function Edit() { + var _this = _super.call(this, Edit.TYPE) || this; + _this.onWheel = function () { + var input = this._input; + if (input) { + input.hide(); + this.hideEditor(); + } + }.bind(_this); + _this.drawInvalidInputTips = function (evt) { + var win = this.win; + var tm = this._themeManager; + var text = this._validationTips; + var style = tm.get("edit.invalid.tips", this.stateToString(widget_1.WidgetState.NORMAL)); + if (!this._isEditing || !text || !style) { + return; + } + var maxH = win.h; + var maxW = win.w; + var ctx = evt.ctx; + var p = this.toGlobalPoint(point_1.Point.point.init(0, 0)); + var width = graphics_1.Graphics.measureText(text, style.font) + 20; + var x = p.x - win.x; + var y = p.y - win.y + 5; + if ((x + width) >= maxW) { + x = maxW - width; + } + var r = null; + if ((y + this.h) < maxH) { + r = rect_1.Rect.rect.init(x, y + this.h, width, 30); + } + else { + r = rect_1.Rect.rect.init(x, y, width, 30); + } + graphics_1.Graphics.drawRoundRect(ctx, style.backGroundColor, style.lineColor, style.lineWidth, r.x, r.y, r.w, r.h, style.roundRadius); + graphics_1.Graphics.drawTextSL(ctx, text, style, r); + }.bind(_this); + return _this; + } + Object.defineProperty(Edit.prototype, "inputable", { + get: function () { + return true; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Edit.prototype, "inputFilter", { + /** + * 输入过滤器,对输入的文本进行转换。 + */ + set: function (value) { + this._inputFilter = value; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Edit.prototype, "inputTips", { + get: function () { + return this._it; + }, + /** + * 输入提示。 + */ + set: function (value) { + this._it = value; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Edit.prototype, "inputType", { + get: function () { + return this._itp; + }, + /** + * 输入类型。 + */ + set: function (value) { + this._itp = value; + }, + enumerable: true, + configurable: true + }); + Edit.prototype.draw = function (ctx) { + if (!this._isEditing) { + _super.prototype.draw.call(this, ctx); + } + else { + } + }; + Edit.prototype.relayoutText = function () { + if (!this._isEditing) { + _super.prototype.relayoutText.call(this); + } + return this; + }; + Edit.prototype.drawText = function (ctx, style) { + if (this._textLines && this._textLines.length) { + _super.prototype.drawText.call(this, ctx, style); + } + else if (this._it) { + this.drawTextSL(ctx, this._it, style); + } + return this; + }; + Edit.prototype.getStyleType = function () { + if (this._styleType) { + return this._styleType; + } + else { + if (this._text || this._isEditing) { + return this.multiLineMode ? "edit.ml" : "edit.sl"; + } + else { + return this.multiLineMode ? "edit.ml.tips" : "edit.sl.tips"; + } + } + }; + Edit.prototype.filterText = function (value) { + return this._inputFilter ? this._inputFilter(value) : value; + }; + Edit.prototype.hideEditor = function () { + if (this._isEditing) { + this._isEditing = false; + this.relayoutText(); + this._input = null; + this.dispatchEvent({ type: Events.BLUR }); + this.win.off(Events.WHEEL, this.onWheel); + } + this.requestRedraw(); + }; + Edit.prototype.notifyChangeEx = function (type, value, oldValue) { + var e = this.eChangeEvent; + e.init(type, { value: value, oldValue: oldValue }); + ; + this.dispatchEvent(e); + }; + Edit.prototype.showEditor = function () { + var _this = this; + var style = this.getStyle(); + this._input = this.multiLineMode ? html_edit_1.HtmlEdit.textArea : html_edit_1.HtmlEdit.input; + var input = this._input; + var vp = this.app.getViewPort(); + var p = this.toViewPoint(point_1.Point.point.init(0, 0)); + var borderWidth = input.borderWidth * 2; + var x = Math.max(0, p.x); + var y = Math.max(0, p.y); + var w = Math.min(this.w, vp.w - x - borderWidth); + var h = Math.min(this.h, vp.h - y - borderWidth); + input.move(x, y); + input.resize(w, h); + input.fontSize = style.fontSize; + input.inputType = this.inputType; + input.textColor = style.textColor; + input.fontFamily = style.fontFamily; + input.text = this.text || ""; + input.show(); + input.z = this.win.z + 1; + var oldValue = this.value; + this.dispatchEvent({ type: Events.FOCUS }); + this.win.on(Events.WHEEL, this.onWheel); + input.on(Events.HIDE, function (evt) { + _this.hideEditor(); + }); + input.on(Events.CHANGING, function (evt) { + _this.text = _this.filterText(evt.value); + var value = _this.inputType === "number" ? +_this.text : _this.text; + _this.notifyChangeEx(Events.CHANGING, value, null); + }); + input.on(Events.CHANGE, function (evt) { + _this.text = _this.filterText(evt.value); + var value = _this.inputType === "number" ? +_this.text : _this.text; + _this.notifyChangeEx(Events.CHANGE, value, oldValue); + }); + input.on(Events.KEYDOWN, function (evt) { + _this.dispatchEvent(evt); + }); + input.on(Events.KEYUP, function (evt) { + if (!_this.multiLineMode && evt.keyCode === key_event_1.KeyEvent.VK_RETURN) { + _this.dispatchEvent({ type: Events.CONFIRM }); + } + _this.dispatchEvent(evt); + }); + }; + Object.defineProperty(Edit.prototype, "validationTips", { + set: function (value) { + this._validationTips = value; + }, + enumerable: true, + configurable: true + }); + Edit.prototype.onInvalidInput = function (message) { + var win = this.win; + if (this._validationTips === message) { + return; + } + this._validationTips = message; + win.off(Events.AFTER_DRAW, this.drawInvalidInputTips); + if (message) { + win.on(Events.AFTER_DRAW, this.drawInvalidInputTips); + } + win.requestRedraw(); + }; + Edit.prototype.dispose = function () { + _super.prototype.dispose.call(this); + this._input = null; + this._inputFilter = null; + }; + Edit.prototype.dispatchClick = function (evt) { + _super.prototype.dispatchClick.call(this, evt); + if (!this._isEditing) { + this._isEditing = true; + this.showEditor(); + } + }; + Edit.prototype.getDefProps = function () { + return Edit.defProps; + }; + Edit.create = function (options) { + return Edit.r.create(options); + }; + return Edit; + }(label_1.Label)); + Edit.defProps = Object.assign({}, label_1.Label.defProps, { _mlm: false, _it: null, _itp: null }); + Edit.TYPE = "edit"; + Edit.r = widget_recyclable_creator_1.WidgetRecyclableCreator.create(Edit); + exports.Edit = Edit; + ; + widget_factory_1.WidgetFactory.register(Edit.TYPE, Edit.create); /***/ }, /* 18 */ /***/ function(module, exports, __webpack_require__) { - "use strict"; - var __extends = (this && this.__extends) || function (d, b) { - for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; - var widget_1 = __webpack_require__(19); - var graphics_1 = __webpack_require__(26); - var widget_factory_1 = __webpack_require__(24); - var widget_recyclable_creator_1 = __webpack_require__(84); - /** - * 文本控件。 - */ - var Label = (function (_super) { - __extends(Label, _super); - function Label(type) { - _super.call(this, type || Label.TYPE); - } - /** - * 对文本进行重新排版。 - */ - Label.prototype.relayoutText = function () { - if (this._inited) { - var style = this.getStyle(); - var text = this.getLocaleText(); - if (text && style) { - this._textLines = graphics_1.Graphics.layoutText(text, this.w, style.font); - } - else { - this._textLines = []; - } - } - return this; - }; - ; - Object.defineProperty(Label.prototype, "multiLineMode", { - /** - * 是否启用多行模式。 - */ - get: function () { - return this._mlm; - }, - set: function (value) { - this.setProp("mlm", value, true); - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(Label.prototype, "value", { - /** - * Label的值即它的文本。 - */ - get: function () { - return this.text; - }, - set: function (value) { - this.text = value; - }, - enumerable: true, - configurable: true - }); - Label.prototype.setStyle = function (state, style) { - _super.prototype.setStyle.call(this, state, style); - this.relayoutText(); - return this; - }; - Label.prototype.drawTextSL = function (ctx, text, style) { - if (text && style.textColor) { - graphics_1.Graphics.drawTextSL(ctx, text, style, this.getTextRect(style)); - } - return this; - }; - Label.prototype.drawTextML = function (ctx, style) { - if (style.textColor) { - graphics_1.Graphics.drawTextML(ctx, this._textLines, style, this.getTextRect(style)); - } - return this; - }; - Label.prototype.drawText = function (ctx, style) { - if (this._textLines && this._textLines.length) { - if (this._mlm) { - this.drawTextML(ctx, style); - } - else { - var text = this._textLines[0].text; - this.drawTextSL(ctx, text, style); - } - } - return this; - }; - Label.prototype.setProp = function (prop, newValue, notify) { - _super.prototype.setProp.call(this, prop, newValue, notify); - if (prop === "w" || prop === "h" || prop === "value" || prop === "text") { - this.relayoutText(); - } - return this; - }; - Label.prototype.onInit = function () { - _super.prototype.onInit.call(this); - this.relayoutText(); - }; - Label.prototype.getDefProps = function () { - return Label.defProps; - }; - Label.create = function (options) { - return Label.recycleBin.create(options); - }; - Label.defProps = Object.assign({}, widget_1.Widget.defProps, { _mlm: true, _lp: 5, _tp: 5, _rp: 5, _bp: 5 }); - Label.TYPE = "label"; - Label.recycleBin = widget_recyclable_creator_1.WidgetRecyclableCreator.create(Label); - return Label; - }(widget_1.Widget)); - exports.Label = Label; - ; - widget_factory_1.WidgetFactory.register(Label.TYPE, Label.create); - + "use strict"; + var __extends = (this && this.__extends) || (function () { + var extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + return function (d, b) { + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; + })(); + Object.defineProperty(exports, "__esModule", { value: true }); + var widget_1 = __webpack_require__(19); + var graphics_1 = __webpack_require__(26); + var widget_factory_1 = __webpack_require__(24); + var widget_recyclable_creator_1 = __webpack_require__(90); + /** + * 文本控件。 + */ + var Label = (function (_super) { + __extends(Label, _super); + function Label(type) { + return _super.call(this, type || Label.TYPE) || this; + } + /** + * 对文本进行重新排版。 + */ + Label.prototype.relayoutText = function () { + if (this._inited) { + var style = this.getStyle(); + var text = this.getLocaleText(); + if (text && style) { + this._textLines = graphics_1.Graphics.layoutText(text, this.w, style.font); + } + else { + this._textLines = []; + } + } + return this; + }; + ; + Object.defineProperty(Label.prototype, "multiLineMode", { + /** + * 是否启用多行模式。 + */ + get: function () { + return this._mlm; + }, + set: function (value) { + this.setProp("mlm", value, true); + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Label.prototype, "value", { + /** + * Label的值即它的文本。 + */ + get: function () { + return this.text; + }, + set: function (value) { + this.text = value; + }, + enumerable: true, + configurable: true + }); + Label.prototype.setStyle = function (state, style) { + _super.prototype.setStyle.call(this, state, style); + this.relayoutText(); + return this; + }; + Label.prototype.drawTextSL = function (ctx, text, style) { + if (text && style.textColor) { + graphics_1.Graphics.drawTextSL(ctx, text, style, this.getTextRect(style)); + } + return this; + }; + Label.prototype.drawTextML = function (ctx, style) { + if (style.textColor) { + graphics_1.Graphics.drawTextML(ctx, this._textLines, style, this.getTextRect(style)); + } + return this; + }; + Label.prototype.drawText = function (ctx, style) { + if (this._textLines && this._textLines.length) { + if (this._mlm) { + this.drawTextML(ctx, style); + } + else { + var text = this._textLines[0].text; + this.drawTextSL(ctx, text, style); + } + } + return this; + }; + Label.prototype.setProp = function (prop, newValue, notify) { + _super.prototype.setProp.call(this, prop, newValue, notify); + if (prop === "w" || prop === "h" || prop === "value" || prop === "text") { + this.relayoutText(); + } + return this; + }; + Label.prototype.onInit = function () { + _super.prototype.onInit.call(this); + this.relayoutText(); + }; + Label.prototype.getDefProps = function () { + return Label.defProps; + }; + Label.create = function (options) { + return Label.recycleBin.create(options); + }; + return Label; + }(widget_1.Widget)); + Label.defProps = Object.assign({}, widget_1.Widget.defProps, { _mlm: true, _lp: 5, _tp: 5, _rp: 5, _bp: 5 }); + Label.TYPE = "label"; + Label.recycleBin = widget_recyclable_creator_1.WidgetRecyclableCreator.create(Label); + exports.Label = Label; + ; + widget_factory_1.WidgetFactory.register(Label.TYPE, Label.create); + /***/ }, /* 19 */ /***/ function(module, exports, __webpack_require__) { - /// - /// - "use strict"; - var __extends = (this && this.__extends) || function (d, b) { - for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; - var rect_1 = __webpack_require__(1); - var style_1 = __webpack_require__(3); - var canvas_1 = __webpack_require__(13); - var TWEEN = __webpack_require__(20); - var emitter_1 = __webpack_require__(4); - var utils_1 = __webpack_require__(21); - var Events = __webpack_require__(6); - var string_table_1 = __webpack_require__(22); - var widget_factory_1 = __webpack_require__(24); - var graphics_1 = __webpack_require__(26); - var dirty_rect_context_1 = __webpack_require__(77); - var image_tile_1 = __webpack_require__(7); - var behavior_1 = __webpack_require__(79); - var layouter_1 = __webpack_require__(80); - var binding_rule_1 = __webpack_require__(81); - var binding_rule_2 = __webpack_require__(81); - var iview_model_1 = __webpack_require__(83); - /** - * @enum WidgetState - * 控件的状态 - */ - (function (WidgetState) { - /** - * @property {number} - * 正常状态。 - */ - WidgetState[WidgetState["NORMAL"] = 0] = "NORMAL"; - /** - * @property {number} - * Pointer在控件上。 - */ - WidgetState[WidgetState["OVER"] = 1] = "OVER"; - /** - * @property {number} - * Pointer按下的状态。 - */ - WidgetState[WidgetState["ACTIVE"] = 2] = "ACTIVE"; - /** - * @property {number} - * 禁用状态。 - */ - WidgetState[WidgetState["DISABLE"] = 3] = "DISABLE"; - /** - * @property {number} - * 选中状态。只对部分设备有效。 - */ - WidgetState[WidgetState["SELECTED"] = 4] = "SELECTED"; - })(exports.WidgetState || (exports.WidgetState = {})); - var WidgetState = exports.WidgetState; - ; - /** - * @enum HitTestResult - * 点击测试结果。 - */ - (function (HitTestResult) { - /** - * @property {number} - * 点击在控件之外。 - */ - HitTestResult[HitTestResult["NONE"] = 0] = "NONE"; - /** - * @property {number} - * 点击在控件左上角。 - */ - HitTestResult[HitTestResult["TL"] = 1] = "TL"; - /** - * @property {number} - * 点击在控件上面中间。 - */ - HitTestResult[HitTestResult["TM"] = 2] = "TM"; - /** - * @property {number} - * 点击在控件右上角。 - */ - HitTestResult[HitTestResult["TR"] = 3] = "TR"; - /** - * @property {number} - * 点击在控件左边中间。 - */ - HitTestResult[HitTestResult["ML"] = 4] = "ML"; - /** - * @property {number} - * 点击在控件中间区域。 - */ - HitTestResult[HitTestResult["MM"] = 5] = "MM"; - /** - * @property {number} - * 点击在控件右边中间。 - */ - HitTestResult[HitTestResult["MR"] = 6] = "MR"; - /** - * @property {number} - * 点击在控件左下角。 - */ - HitTestResult[HitTestResult["BL"] = 7] = "BL"; - /** - * @property {number} - * 点击在控件下面中间。 - */ - HitTestResult[HitTestResult["BM"] = 8] = "BM"; - /** - * @property {number} - * 点击在控件右下角。 - */ - HitTestResult[HitTestResult["BR"] = 9] = "BR"; - })(exports.HitTestResult || (exports.HitTestResult = {})); - var HitTestResult = exports.HitTestResult; - ; - /** - * @class Widget - * Widget是所有控件的基类。 - */ - var Widget = (function (_super) { - __extends(Widget, _super); - function Widget(type) { - _super.call(this); - /////////////////////////////////////////// - this.layoutRect = rect_1.Rect.create(0, 0, 0, 0); - this.eChangeEvent = Events.ChangeEvent.create(); - this.ePropChangeEvent = Events.PropChangeEvent.create(); - this.viewModelChangeFunc = function (evt) { - var viewModel = this._viewModel; - var dataBindingRule = this._dataBindingRule; - if (dataBindingRule && viewModel) { - this.onBindData(viewModel, dataBindingRule); - } - }.bind(this); - this.type = type; - } - /** - * @method set - * 同时设置多个属性。 - */ - Widget.prototype.set = function (props) { - if (props) { - for (var key in props) { - var value = props[key]; - if (value !== undefined) { - this[key] = value; - } - } - } - return this; - }; - /** - * @method get - * 同时获取多个属性。 - */ - Widget.prototype.get = function (props) { - if (props) { - for (var key in props) { - var value = this[key]; - if (value !== undefined) { - props[key] = value; - } - } - } - return this; - }; - /** - * 把全局的坐标转换成相对于当前控件左上角的坐标。 - * @param {Pointer} p 全局坐标。 - * @return {Pointer} 相对于当前控件左上角的坐标。 - */ - Widget.prototype.toLocalPoint = function (p) { - p.x -= this.x; - p.y -= this.y; - var iter = this.parent; - while (iter) { - p.x -= iter.x; - p.y -= iter.y; - iter = iter.parent; - } - return p; - }; - /** - * 把相对于当前控件左上角的坐标转换成全局坐标。 - * @param {Point} p 相对于当前控件左上角的坐标。 - * @return {Point} 全局坐标。 - */ - Widget.prototype.toGlobalPoint = function (p) { - p.x += this.x; - p.y += this.y; - var iter = this.parent; - while (iter) { - p.x += iter.x; - p.y += iter.y; - iter = iter.parent; - } - return p; - }; - /** - * 把相对于当前控件左上角的坐标转换成屏幕上的坐标。 - * @param {Point} p 相对于当前控件左上角的坐标。 - * @return {Point} 屏幕上的坐标。 - */ - Widget.prototype.toViewPoint = function (p) { - var iter = this; - while (iter) { - p.x += iter.x; - p.y += iter.y; - if (iter.offsetX) { - p.x -= iter.offsetX; - } - if (iter.offsetY) { - p.y -= iter.offsetY; - } - iter = iter.parent; - } - return p; - }; - Widget.prototype.onInit = function () { - this._inited = true; - if (!this.app && this.parent) { - this.app = this.parent.app; - } - }; - Widget.prototype.init = function () { - this.onInit(); - this.children.forEach(function (child) { - child.init(); - }); - return this; - }; - Widget.prototype.onDeinit = function () { - this._inited = false; - }; - Widget.prototype.deinit = function () { - this.children.forEach(function (child) { - child.deinit(); - }); - this.onDeinit(); - }; - Widget.prototype.translatePointerEvent = function (evt) { - evt.localX -= this.x; - evt.localY -= this.y; - }; - Widget.prototype.untranslatePointerEvent = function (evt) { - evt.localX += this.x; - evt.localY += this.y; - }; - Widget.prototype.dispatchPointerDown = function (evt) { - if (!this._enable || !this._sensitive) { - return; - } - this.translatePointerEvent(evt); - var x = evt.localX; - var y = evt.localY; - var hitTestResult = this.selfHitTest(x, y); - if (hitTestResult) { - this.dispatchEvent(evt, true); - this.target = this.findEventTargetChild(x, y); - if (this.target) { - this.target.dispatchPointerDown(evt); - } - if (this.onpointerdown) { - this.onpointerdown(evt); - } - this.dispatchEvent(evt, false); - this.state = WidgetState.ACTIVE; - } - else { - if (this.onpointerdown) { - this.onpointerdown(evt); - } - this.state = WidgetState.NORMAL; - } - this.untranslatePointerEvent(evt); - this.hitTestResult = hitTestResult; - }; - Widget.prototype.dispatchPointerMoveToTarget = function (evt) { - this.dispatchEvent(evt, true); - if (this.target) { - this.target.dispatchPointerMove(evt); - } - if (this.onpointermove) { - this.onpointermove(evt); - } - this.dispatchEvent(evt, false); - }; - Widget.prototype.dispatchPointerLeave = function (evt) { - if (this.state === WidgetState.OVER || this.state === WidgetState.ACTIVE) { - var e = Events.PointerEvent.create(Events.POINTER_LEAVE, evt); - this.dispatchEvent(e, false); - this.state = WidgetState.NORMAL; - e.dispose(); - } - if (this.target) { - this.target.dispatchPointerLeave(evt); - } - if (this._lastOverWidget) { - this._lastOverWidget.dispatchPointerLeave(evt); - this._lastOverWidget = null; - } - }; - Widget.prototype.dispatchPointerEnter = function (evt) { - var e = Events.PointerEvent.create(Events.POINTER_ENTER, evt); - this.dispatchEvent(e, false); - e.dispose(); - }; - Widget.prototype.dispatchPointerMoveToUnder = function (evt) { - var x = evt.localX; - var y = evt.localY; - var hitTestResult = this.selfHitTest(x, y); - if (hitTestResult) { - this.dispatchEvent(evt, true); - var _lastOverWidget = this._lastOverWidget; - var overWidget = this.findEventTargetChild(x, y); - if (_lastOverWidget !== overWidget) { - var e = null; - if (_lastOverWidget) { - _lastOverWidget.dispatchPointerMove(evt); - _lastOverWidget.dispatchPointerLeave(evt); - } - if (overWidget) { - overWidget.dispatchPointerEnter(evt); - } - this._lastOverWidget = overWidget; - } - if (overWidget) { - overWidget.dispatchPointerMove(evt); - } - if (this.onpointermove) { - this.onpointermove(evt); - } - this.dispatchEvent(evt, false); - if (evt.pointerDown) { - this.state = WidgetState.ACTIVE; - } - else { - this.state = WidgetState.OVER; - } - } - else { - this.dispatchEvent(evt, true); - if (this.onpointermove) { - this.onpointermove(evt); - } - this.dispatchEvent(evt, false); - this.state = WidgetState.NORMAL; - } - }; - Widget.prototype.dispatchPointerMove = function (evt) { - if (!this._enable || !this._sensitive) { - return; - } - this.translatePointerEvent(evt); - if (evt.pointerDown) { - this.dispatchPointerMoveToTarget(evt); - } - this.dispatchPointerMoveToUnder(evt); - this.untranslatePointerEvent(evt); - }; - Widget.prototype.dispatchPointerUp = function (evt) { - if (!this._enable || !this._sensitive) { - return; - } - this.translatePointerEvent(evt); - this.dispatchEvent(evt, true); - if (this._lastOverWidget && this.target !== this._lastOverWidget) { - this._lastOverWidget.dispatchPointerUp(evt); - } - if (this.target) { - this.target.dispatchPointerUp(evt); - } - if (this.onpointerup) { - this.onpointerup(evt); - } - this.dispatchEvent(evt, false); - this.state = WidgetState.NORMAL; - this.untranslatePointerEvent(evt); - }; - Widget.prototype.dispatchClick = function (evt) { - if (!this._enable || !this._sensitive) { - return; - } - this.translatePointerEvent(evt); - var x = evt.localX; - var y = evt.localY; - var hitTestResult = this.selfHitTest(x, y); - var isClick = Math.abs(evt.dx) < 5 && Math.abs(evt.dy) < 5; - if (isClick || hitTestResult) { - this.dispatchEvent(evt, true); - if (this.target) { - this.target.dispatchClick(evt); - } - if (this.onclick) { - this.onclick(evt); - } - this.dispatchEvent(evt, false); - } - this.untranslatePointerEvent(evt); - }; - Widget.prototype.dispatchContextMenu = function (evt) { - if (!this._enable || !this._sensitive) { - return; - } - this.dispatchEvent(evt, true); - if (this.target) { - this.target.dispatchContextMenu(evt); - } - if (this.oncontextmenu) { - this.oncontextmenu(evt); - } - this.dispatchEvent(evt, false); - }; - Widget.prototype.dispatchDblClick = function (evt) { - if (!this._enable || !this._sensitive) { - return; - } - this.dispatchEvent(evt, true); - if (this.target) { - this.target.dispatchDblClick(evt); - } - if (this.ondblclick) { - this.ondblclick(evt); - } - this.dispatchEvent(evt, false); - }; - Widget.prototype.dispatchKeyDown = function (evt) { - if (!this._enable || !this._sensitive) { - return; - } - this.dispatchEvent(evt, true); - if (this.target) { - this.target.dispatchKeyDown(evt); - } - if (this.onkeydown) { - this.onkeydown(evt); - } - this.dispatchEvent(evt, false); - }; - Widget.prototype.dispatchKeyUp = function (evt) { - if (!this._enable || !this._sensitive) { - return; - } - this.dispatchEvent(evt, true); - if (this.target) { - this.target.dispatchKeyUp(evt); - } - if (this.onkeyup) { - this.onkeyup(evt); - } - this.dispatchEvent(evt, false); - }; - Widget.prototype.dispatchWheel = function (evt) { - if (!this._enable || !this._sensitive) { - return; - } - this.dispatchEvent(evt, true); - if (this.target) { - this.target.dispatchWheel(evt); - } - if (this.onwheel) { - this.onwheel(evt); - } - this.dispatchEvent(evt, false); - }; - Widget.prototype.applyTransform = function (ctx) { - var e = Events.ApplyTransformEvent.get(); - this.dispatchEvent(e.reset(Events.BEFORE_APPLY_TRANSFORM, ctx, this)); - if (!this._canvas) { - ctx.translate(this._x, this._y); - } - var px = this._pivotX * this._w; - var py = this._pivotY * this._h; - if (this._rotation || this._scaleX !== 1 || this._scaleY !== 1) { - ctx.translate(px, py); - ctx.rotate(this._rotation); - ctx.scale(this._scaleX, this._scaleY); - ctx.translate(-px, -py); - } - this.dispatchEvent(e.reset(Events.AFTER_APPLY_TRANSFORM, ctx, this)); - return this; - }; - Widget.prototype.findEventTargetChild = function (x, y) { - var arr = this._children; - var n = arr.length; - for (var i = n - 1; i >= 0; i--) { - var iter = arr[i]; - if (iter._enable && iter._sensitive) { - if (rect_1.Rect.rect.init(iter.x, iter.y, iter.w, iter.h).containsPoint(x, y)) { - return iter; - } - } - } - return null; - }; - /////////////////////////////////////////// - Widget.prototype.animate = function () { - var tween = new TWEEN.Tween(this); - this.requestRedraw(); - return tween; - }; - /** - * @method scaleTo - * 设置控件的缩放比例到指定的值。如果duration > 0则启用动画,并返回TWEEN.Tween,否则返回null。 - * @param {number} sx 宽度缩放比例。 - * @param {number} sy 高度缩放比例。 - * @param {number} duration 动画时间。 - * @return {TWEEN.Tween} - */ - Widget.prototype.scaleTo = function (sx, sy, duration) { - this.requestRedraw(); - if (duration > 0) { - var tween = new TWEEN.Tween(this); - tween.to({ scaleX: sx, scaleY: sy }, duration).start(); - return tween; - } - else { - this.scaleX = sx; - this.scaleY = sy; - return null; - } - }; - /** - * @method opacityTo - * 设置控件的透明度到指定的值。如果duration > 0则启用动画,并返回TWEEN.Tween,否则返回null。 - * @param {number} opacity 不透明度[0-1] - * @param {number} duration 动画时间。 - * @return {TWEEN.Tween} - */ - Widget.prototype.opacityTo = function (opacity, duration) { - this.requestRedraw(); - if (duration > 0) { - var tween = new TWEEN.Tween(this); - tween.to({ opacity: opacity }, duration).start(); - return tween; - } - else { - this.opacity = opacity; - ; - return null; - } - }; - /** - * @method rotateTo - * 设置控件的旋转角度到指定的值。如果duration > 0则启用动画,并返回TWEEN.Tween,否则返回null。 - * @param {number} rotation 旋转角度,单位为弧度。 - * @param {number} duration 动画时间。 - * @return {TWEEN.Tween} - */ - Widget.prototype.rotateTo = function (rotation, duration) { - this.requestRedraw(); - if (duration > 0) { - var tween = new TWEEN.Tween(this); - tween.to({ rotation: rotation }, duration).start(); - return tween; - } - else { - this.rotation = rotation; - return null; - } - }; - /** - * @method moveTo - * 设置控件的位置到指定的值。如果duration > 0则启用动画,并返回TWEEN.Tween,否则返回null。 - * @param {number} x X 坐标。 - * @param {number} y Y 坐标。 - * @param {number} duration 动画时间。 - * @return {TWEEN.Tween} - */ - Widget.prototype.moveTo = function (x, y, duration) { - this.requestRedraw(); - if (duration > 0) { - var tween = new TWEEN.Tween(this); - tween.to({ x: x, y: y }, duration).start(); - return tween; - } - else { - this.x = x; - this.y = y; - return null; - } - }; - /** - * @method moveResizeTo - * 设置控件的位置和大小到指定的值。如果duration > 0则启用动画,并返回TWEEN.Tween,否则返回null。 - * @param {number} x X 坐标。 - * @param {number} y Y 坐标。 - * @param {number} w 宽度。 - * @param {number} h 高度。 - * @param {number} duration 动画时间。 - * @return {TWEEN.Tween} - */ - Widget.prototype.moveResizeTo = function (x, y, w, h, duration) { - if (duration > 0) { - var tween = new TWEEN.Tween(this); - tween.to({ x: x, y: y, w: w, h: h }, duration).start(); - return tween; - } - else { - this.x = x; - this.y = y; - this.w = w; - this.h = h; - return null; - } - }; - /** - * @method resizeTo - * 设置控件的大小到指定的值。如果duration > 0则启用动画,并返回TWEEN.Tween,否则返回null。 - * @param {number} w 宽度。 - * @param {number} h 高度。 - * @param {number} duration 动画时间。 - * @return {TWEEN.Tween} - */ - Widget.prototype.resizeTo = function (w, h, duration) { - if (duration > 0) { - var tween = new TWEEN.Tween(this); - tween.to({ w: w, h: h }, duration).start(); - return tween; - } - else { - this.w = w; - this.h = h; - return null; - } - }; - Widget.prototype.getLayoutRect = function () { - return this.layoutRect.init(this.leftPadding, this.topPadding, this.w - this.leftPadding - this.rightPadding, this.h - this.topPadding - this.bottomPadding); - }; - /** - * 根据当前的childrenLayouter重新布局子控件。 - */ - Widget.prototype.relayoutChildren = function () { - this.requestRedraw(); - if (this.children.length > 0 && this.childrenLayouter && ((this.w > 0 && this.h > 0) || this._inited)) { - var ret = this.childrenLayouter.layoutChildren(this, this.children, this.getLayoutRect()); - return this.layoutRect.copy(ret); - } - return this.getLayoutRect(); - }; - /** - * 请求重新布局当前控件。 - */ - Widget.prototype.requestRelayout = function () { - if (this.parent) { - this.parent.relayoutChildren(); - } - return this; - }; - /* - * 根据当前的childrenLayouter创建子控件的布局参数。 - */ - Widget.prototype.createChildLayoutParam = function (options) { - var layouter = this.childrenLayouter; - return layouter ? layouter.createParam(options) : null; - }; - /** - * 启用指定的childrenLayouter。 - */ - Widget.prototype.useChildrenLayouter = function (type, options) { - this.childrenLayouter = layouter_1.LayouterFactory.create(type, options); - return this; - }; - Object.defineProperty(Widget.prototype, "childrenLayouter", { - get: function () { - return this._childrenLayouter; - }, - /** - * @property {Layouter} childrenLayouter - * 用于子控件布局的Layouter。 - */ - set: function (layouter) { - if (typeof layouter === "string") { - this._childrenLayouter = layouter_1.LayouterFactory.create(layouter, null); - } - else { - this._childrenLayouter = layouter; - } - if (this.children.length) { - this.relayoutChildren(); - } - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(Widget.prototype, "layoutParam", { - get: function () { - return this._layoutParam; - }, - /** - * @property {Object} layoutParam - * 布局参数是父控件在布局当前控件时使用的参数。 - */ - set: function (param) { - this._layoutParam = param; - if (param) { - param.widget = this; - } - }, - enumerable: true, - configurable: true - }); - Widget.prototype.getParentByType = function (type) { - var iter = this.parent; - while (iter && iter.type !== type) { - iter = iter.parent; - } - return iter; - }; - /////////////////////////////////////////// - /** - * @method indexOfChild - * 获取指定子控件的位置序数。 - * @param {Widget} child 子控件 - * @return {number} 位置序数。 - */ - Widget.prototype.indexOfChild = function (child) { - return this.children.indexOf(child); - }; - /** - * @method findChild - * 查找满足指定条件的子控件。 - * @param {Function} func 比较函数。 - * @return {Widget} 如果找到,返回该子控件,否则返回null。 - */ - Widget.prototype.findChild = function (func) { - var i = 0; - var arr = this._children; - var n = arr.length; - for (var i = 0; i < n; i++) { - var iter = arr[i]; - if (func(iter)) { - return iter; - } - } - return null; - }; - /** - * @method findChildByName - * 按名称查找子控件。 - * @param {string} name 子控件的名称。 - * @return {Widget} 如果找到,返回该子控件,否则返回null。 - */ - Widget.prototype.findChildByName = function (name) { - var ret = this.findChild(function (child) { - return child.name === name; - }); - return ret; - }; - /** - * @method findChildByID - * 按ID查找子控件。 - * @param {string} id 子控件的ID。 - * @return {Widget} 如果找到,返回该子控件,否则返回null。 - */ - Widget.prototype.findChildByID = function (id) { - var ret = this.findChild(function (child) { - return child.id === id; - }); - return ret; - }; - Widget.prototype.drawColorBackground = function (ctx, style) { - var roundType = 0; - var roundTypeName = style.roundType; - if (roundTypeName) { - if (roundTypeName === "top") { - roundType = graphics_1.RoundType.TL | graphics_1.RoundType.TR; - } - else if (roundTypeName === "bottom") { - roundType = graphics_1.RoundType.BL | graphics_1.RoundType.BR; - } - else if (roundTypeName === "left") { - roundType = graphics_1.RoundType.BL | graphics_1.RoundType.TL; - } - else if (roundTypeName === "right") { - roundType = graphics_1.RoundType.TR | graphics_1.RoundType.BR; - } - } - graphics_1.Graphics.drawRoundRect(ctx, style.backGroundColor, style.lineColor, style.lineWidth, 0, 0, this.w, this.h, style.roundRadius, roundType); - return this; - }; - Widget.prototype.drawBackground = function (ctx, style) { - if (style.backGroundImage) { - style.backGroundImage.draw(ctx, style.backGroundImageDrawType, 0, 0, this.w, this.h); - } - else if (style.backGroundColor || (style.lineColor && style.lineWidth)) { - this.drawColorBackground(ctx, style); - } - return this; - }; - /** - * @method getLocaleText - * 获取本地化后的文本。 - */ - Widget.prototype.getLocaleText = function () { - return string_table_1.StringTable.tr(this.text); - }; - Widget.prototype.getFgImageRect = function (style) { - return rect_1.Rect.rect.init(this.leftPadding, this.topPadding, this.clientW, this.clientH); - }; - Widget.prototype.drawImage = function (ctx, style) { - if (style.foreGroundImage) { - var r = this.getFgImageRect(style); - style.foreGroundImage.draw(ctx, image_tile_1.ImageDrawType.ICON, r.x, r.y, r.w, r.h); - } - return this; - }; - Widget.prototype.getTextRect = function (style) { - return rect_1.Rect.rect.init(this.leftPadding, this.topPadding, this.clientW, this.clientH); - }; - Widget.prototype.drawText = function (ctx, style) { - var text = this.getLocaleText(); - if (text && style.textColor) { - graphics_1.Graphics.drawTextSL(ctx, text, style, this.getTextRect(style)); - } - return this; - }; - Widget.prototype.drawChildren = function (ctx) { - this._children.forEach(function (child) { - if (child.visible) { - child.draw(ctx); - } - }); - return this; - }; - Widget.prototype.drawTips = function (ctx, style) { - return this; - }; - Widget.prototype.computeDirtyRectSelf = function (ctx) { - if (this._dirty) { - ctx.addRect(-5, -5, this.w + 10, this.h + 10); - } - }; - Widget.prototype.computeDirtyRect = function (ctx) { - ctx.save(); - this.applyTransform(ctx); - this.computeDirtyRectSelf(ctx); - this.computeChildrenDirtyRect(ctx); - ctx.restore(); - }; - Widget.prototype.computeChildrenDirtyRect = function (ctx) { - this.children.forEach(function (child) { - child.computeDirtyRect(ctx); - }); - }; - Widget.prototype.doDraw = function (ctx, style) { - if (style) { - this.drawBackground(ctx, style) - .drawImage(ctx, style) - .drawChildren(ctx) - .drawText(ctx, style) - .drawTips(ctx, style); - } - else { - this.drawChildren(ctx); - } - }; - Widget.prototype.draw = function (ctx) { - this._dirty = false; - var style = this.getStyle(); - ctx.save(); - var opacity = this._opacity; - if (opacity !== 1) { - ctx.globalAlpha *= opacity; - } - this.applyTransform(ctx); - var drawEvent = Events.DrawEvent.get(); - this.dispatchEvent(drawEvent.reset(Events.BEFORE_DRAW, ctx, this)); - this.doDraw(ctx, style); - this.dispatchEvent(drawEvent.reset(Events.AFTER_DRAW, ctx, this)); - ctx.restore(); - return; - }; - Widget.prototype.stateToString = function (state) { - return WidgetState[state].toLowerCase(); - }; - Object.defineProperty(Widget.prototype, "styleType", { - get: function () { - return this._styleType; - }, - /** - * @property {string} styleType - * 用于从主题中获取style数据。 - */ - set: function (styleType) { - this._styleType = styleType; - }, - enumerable: true, - configurable: true - }); - /** - * @method setStyle - * 设置控件的Style。 - * @param {WidgetState} state 状态。 - * @param {Style} style 控件的Style。 - * return {Widget} 控件本身。 - */ - Widget.prototype.setStyle = function (state, style) { - if (!this._styles) { - this._styles = {}; - } - var stateName = this.stateToString(state); - this._styles[stateName] = style; - return this; - }; - Widget.prototype.getStyleType = function () { - return this._styleType || this.type; - }; - Widget.prototype.getStyleOfState = function (state) { - var style = null; - var tm = this._themeManager; - var stateName = this.stateToString(state); - if (this._styles) { - style = this._styles[stateName]; - } - else if (tm) { - var styleType = this.getStyleType(); - style = tm.get(styleType, stateName); - } - return style; - }; - Widget.prototype.getStateForStyle = function () { - return this.enable ? this._state : WidgetState.DISABLE; - }; - Widget.prototype.getStyle = function () { - var state = this.getStateForStyle(); - var style = this.getStyleOfState(state); - if (!style) { - style = this.getStyleOfState(WidgetState.NORMAL); - } - return style; - }; - Widget.prototype.sortChildren = function () { - var arr = this._children; - utils_1.stableSort(arr, function (a, b) { - return a.z - b.z; - }); - return this; - }; - /** - * @method removeAllChildren - * 移出并销毁所有的子控件。 - * return {Widget} 控件本身。 - */ - Widget.prototype.removeAllChildren = function () { - this.children.forEach(function (child) { - child.deinit(); - child.dispose(); - }); - this.target = null; - this.children.length = 0; - this._lastOverWidget = null; - return this; - }; - Widget.prototype.onRemoveChild = function (child) { - }; - /** - * @method removeChild - * 移出子控件。批量删除时,请使用快速模式,并在完成时调用relayoutChildren。 - * @param {Widget} child 子控件。 - * @param {boolean} fastMode 快速模式下,不重新布局子控件。 - * @param {boolean} destroy 是否销毁子控件。 - * return {Widget} 控件本身。 - */ - Widget.prototype.removeChild = function (child, fastMode, destroy) { - var arr = this._children; - var index = arr.indexOf(child); - if (index >= 0) { - arr.splice(index, 1); - if (!fastMode) { - this.relayoutChildren(); - } - } - this.onRemoveChild(child); - if (destroy) { - child.deinit(); - child.dispose(); - } - return this; - }; - Widget.prototype.onAddChild = function (child) { - }; - /** - * @method addChild - * 增加子控件。批量增加时,请使用快速模式,并在完成时调用relayoutChildren。 - * @param {Widget} child 子控件。 - * @param {boolean} fastMode 快速模式下,不重新布局子控件。 - * return {Widget} 控件本身。 - */ - Widget.prototype.addChild = function (child, fastMode) { - var arr = this._children; - arr.push(child); - child.parent = this; - child.app = this.app; - if (this._inited) { - child.init(); - } - if (!fastMode) { - this.sortChildren(); - this.relayoutChildren(); - } - this.onAddChild(child); - return this; - }; - /** - * @method dispose - * 销毁控件及其全部子控件。 - */ - Widget.prototype.dispose = function () { - this.dispatchEvent({ type: Events.DISPOSE }); - if (this._canvas) { - this._canvas.dispose(); - this._canvas = null; - } - this.removeAllListeners(); - this._children.forEach(function (child) { - child.dispose(); - }); - this._app = null; - this._parent = null; - this._children = []; - this._layoutParam = null; - this._childrenLayouter = null; - this._viewModel = null; - this._dataBindingRule = null; - this.removeBinding(); - if (this.recycle) { - this.recycle(); - } - }; - /** - * @method requestRedraw - * 请求重绘。 - */ - Widget.prototype.requestRedraw = function () { - var app = this._app; - this._dirty = true; - if (app) { - app.getMainLoop().requestRedraw(); - } - return this; - }; - ////////////////////////////////////////////////// - Widget.prototype.createCanvas = function () { - var _this = this; - var app = this.app; - var density = app.getViewPort().density; - var canvas = canvas_1.Canvas.create(this.x, this.y, this.w, this.h, density); - canvas.ensureCanvas(); - canvas.on(Events.POINTER_DOWN, function (evt) { - _this.dispatchPointerDown(evt); - }); - canvas.on(Events.POINTER_MOVE, function (evt) { - _this.dispatchPointerMove(evt); - }); - canvas.on(Events.POINTER_UP, function (evt) { - _this.dispatchPointerUp(evt); - }); - canvas.on(Events.CLICK, function (evt) { - _this.dispatchClick(evt); - }); - canvas.on(Events.DBLCLICK, function (evt) { - _this.dispatchDblClick(evt); - }); - canvas.on(Events.CONTEXT_MENU, function (evt) { - _this.dispatchContextMenu(evt); - }); - canvas.on(Events.WHEEL, function (evt) { - _this.dispatchWheel(evt); - }); - canvas.on(Events.KEYDOWN, function (evt) { - _this.dispatchKeyDown(evt); - }); - canvas.on(Events.KEYUP, function (evt) { - _this.dispatchKeyUp(evt); - }); - this._canvas = canvas; - var mainLoop = this.app.getMainLoop(); - var dirtyRectContext = dirty_rect_context_1.DirtyRectContext.create(); - var lastDirtyRect = rect_1.Rect.create(0, 0, this.w, this.h); - var debugDirtyRect = app.options.debugDirtyRect; - function drawWithDirtyRect(evt) { - var ctx = canvas.getContext("2d"); - dirtyRectContext.reset(); - this.computeDirtyRect(dirtyRectContext); - var dirtyRect = dirtyRectContext.getRect(); - var r = lastDirtyRect.merge(dirtyRect); - if (r.x < 0) - r.x = 0; - if (r.y < 0) - r.y = 0; - if ((r.x + r.w) > this.w) { - r.w = this.w - r.x; - } - if ((r.y + r.h) > this.h) { - r.h = this.h - r.y; - } - if (r.w > 0 && r.h > 0) { - r.x = r.x >> 0; - r.y = r.y >> 0; - r.w = (r.w + 1) >> 0; - r.h = (r.h + 2) >> 0; - ctx.save(); - ctx.beginPath(); - ctx.clearRect(r.x, r.y, r.w, r.h); - ctx.rect(r.x, r.y, r.w, r.h); - ctx.clip(); - ctx.globalAlpha = 1; - this.draw(ctx); - if (debugDirtyRect) { - ctx.lineWidth = 1; - ctx.strokeStyle = "gold"; - ctx.strokeRect(dirtyRect.x + 1, dirtyRect.y + 1, dirtyRect.w - 2, dirtyRect.h - 2); - } - ctx.restore(); - } - lastDirtyRect.copy(dirtyRect); - } - function drawWithoutDirtyRect(evt) { - var ctx = canvas.getContext("2d"); - ctx.globalAlpha = 1; - this.draw(ctx); - } - var withoutDirtyRect = app.options.withoutDirtyRect; - var draw = withoutDirtyRect ? drawWithoutDirtyRect.bind(this) : drawWithDirtyRect.bind(this); - mainLoop.on(Events.TICK, draw); - this.on(Events.DISPOSE, function (evt) { - mainLoop.off(Events.TICK, draw); - }); - this.on(Events.PROP_CHANGE, function (evt) { - var prop = evt.prop; - var value = evt.newValue; - switch (prop) { - case "x": { - canvas.x = value; - break; - } - case "y": { - canvas.y = value; - break; - } - case "w": { - canvas.w = value; - break; - } - case "h": { - canvas.h = value; - break; - } - case "z": { - canvas.z = value; - break; - } - } - }); - return this; - }; - Object.defineProperty(Widget.prototype, "dirty", { - ////////////////////////////////////////////////// - get: function () { - return this._dirty; - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(Widget.prototype, "x", { - /** - * @property {number} x - * 控件的X坐标。 - */ - get: function () { - return this._x; - }, - set: function (value) { - this.setProp("x", value, true); - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(Widget.prototype, "y", { - /** - * @property {number} y - * 控件的Y坐标。 - */ - get: function () { - return this._y; - }, - set: function (value) { - this.setProp("y", value, true); - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(Widget.prototype, "z", { - /** - * @property {number} z - * 控件的位置序数。 - */ - get: function () { - return this._z; - }, - set: function (value) { - this.setProp("z", value, true); - if (this._parent) { - this._parent.sortChildren(); - } - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(Widget.prototype, "desireWidth", { - /** - * @property {number} w - * 控件的宽度。 - */ - get: function () { - return this._w; - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(Widget.prototype, "w", { - get: function () { - return this._w; - }, - set: function (value) { - this.setProp("w", value, true); - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(Widget.prototype, "width", { - get: function () { - return this._w; - }, - set: function (value) { - this.setProp("w", value, true); - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(Widget.prototype, "clientW", { - get: function () { - return this._w - this.leftPadding - this.rightPadding; - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(Widget.prototype, "clientH", { - get: function () { - return this._h - this.topPadding - this.bottomPadding; - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(Widget.prototype, "height", { - /** - * @property {number} h - * 控件的高度。 - */ - get: function () { - return this._h; - }, - set: function (value) { - this.setProp("h", value, true); - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(Widget.prototype, "h", { - get: function () { - return this._h; - }, - set: function (value) { - this.setProp("h", value, true); - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(Widget.prototype, "state", { - /** - * @property {WidgetState} state - * 控件的状态。 - */ - get: function () { - return this._state; - }, - set: function (value) { - if (this._state !== value) { - this.setProp("state", value, true); - } - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(Widget.prototype, "value", { - /** - * @property {any} value - * 控件的值。不同的控件,值的定义不一样。 - */ - get: function () { - return this._value; - }, - set: function (value) { - this.setValue(value, false, false); - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(Widget.prototype, "selected", { - /** - * @property {boolean} selected - * 控件是否被选中。 - */ - get: function () { - return this._selected; - }, - set: function (value) { - this.setProp("selected", value, true); - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(Widget.prototype, "isEnableFunc", { - get: function () { - return this._isEnableFunc; - }, - set: function (value) { - this._isEnableFunc = value; - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(Widget.prototype, "enable", { - /** - * @property {boolean} enable - * 控件是否处于enable状态。 - */ - get: function () { - if (this.isEnableFunc) { - return this.isEnableFunc(); - } - return this._enable; - }, - set: function (value) { - this.setProp("enable", value, true); - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(Widget.prototype, "inputable", { - /** - * @property {boolean} inputable - * [只读] 控件是否可输入,也就是是否可以通过界面修改它的值。 - */ - get: function () { - return false; - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(Widget.prototype, "visible", { - /** - * @property {boolean} visible - * 控件是否可见。 - */ - get: function () { - return this._visible; - }, - set: function (value) { - var oldValue = this._visible; - if (this.value !== oldValue) { - this.setVisible(value); - } - }, - enumerable: true, - configurable: true - }); - Widget.prototype.setVisible = function (value) { - this.setProp("visible", value, true); - this.dispatchEvent({ type: value ? Events.SHOW : Events.HIDE }); - this.requestRedraw(); - }; - Object.defineProperty(Widget.prototype, "opacity", { - /** - * @property {number} opacity - * 控件的不透明度(0-1)。 - */ - get: function () { - return this._opacity; - }, - set: function (value) { - this.setProp("opacity", value, true); - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(Widget.prototype, "scaleX", { - /** - * @property {number} scaleX - * 控件的宽度缩放比例。 - */ - get: function () { - return this._scaleX; - }, - set: function (value) { - this.setProp("scaleX", value, true); - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(Widget.prototype, "scaleY", { - /** - * @property {number} scaleY - * 控件的高度缩放比例。 - */ - get: function () { - return this._scaleY; - }, - set: function (value) { - this.setProp("scaleY", value, true); - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(Widget.prototype, "rotation", { - /** - * @property {number} rotation - * 控件的旋转角度。 - */ - get: function () { - return this._rotation; - }, - set: function (value) { - this.setProp("rotation", value, true); - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(Widget.prototype, "sensitive", { - /** - * @property {number} sensitive - * 控件是否接受用户事件。 - */ - get: function () { - return this._sensitive; - }, - set: function (value) { - this.setProp("sensitive", value, true); - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(Widget.prototype, "pivotX", { - /** - * @property {number} pivotX - * 控件的X轴点,也就旋转点的X坐标。 - */ - get: function () { - return this._pivotX; - }, - set: function (value) { - this.setProp("pivotX", value, true); - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(Widget.prototype, "pivotY", { - /** - * @property {number} pivotY - * 控件的Y轴点,也就旋转点的Y坐标。 - */ - get: function () { - return this._pivotY; - }, - set: function (value) { - this.setProp("pivotY", value, true); - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(Widget.prototype, "tips", { - /** - * @property {string} tips - * 控件的提示文本。 - */ - get: function () { - return this._tips; - }, - set: function (value) { - this.setProp("tips", value, true); - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(Widget.prototype, "text", { - /** - * @property {string} text - * 控件的文本。 - */ - get: function () { - return this._text; - }, - set: function (value) { - this.setProp("text", (value || value === 0) ? value.toString() : "", true); - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(Widget.prototype, "name", { - /** - * @property {string} name - * 控件的名称。 - */ - get: function () { - return this._name; - }, - set: function (value) { - this.setProp("name", value, true); - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(Widget.prototype, "type", { - /** - * @property {string} type - * 控件的类型。 - */ - get: function () { - return this._type; - }, - set: function (value) { - this.setProp("type", value, true); - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(Widget.prototype, "id", { - /** - * @property {string} id - * 控件的ID。 - */ - get: function () { - return this._id; - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(Widget.prototype, "userData", { - /** - * @property {any} userData - * 控件的应用数据。 - */ - get: function () { - return this._userData; - }, - set: function (value) { - this._userData = value; - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(Widget.prototype, "target", { - get: function () { - return this._target; - }, - set: function (value) { - this._target = value; - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(Widget.prototype, "hitTestResult", { - get: function () { - return this._hitTestResult; - }, - set: function (value) { - this._hitTestResult = value; - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(Widget.prototype, "parent", { - /** - * @property {Widget} parent - * 控件的父控件。 - */ - get: function () { - return this._parent; - }, - set: function (value) { - this._parent = value; - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(Widget.prototype, "app", { - /** - * @property {IApplication} app - * 应用程序。 - */ - get: function () { - return this._app; - }, - set: function (app) { - this._app = app; - if (app) { - this._mainLoop = app.getMainLoop(); - this._themeManager = app.getThemeManager(); - } - this.children.forEach(function (child) { - child.app = app; - }); - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(Widget.prototype, "win", { - /** - * @property {Window} win - * 控件所在的窗口。 - */ - get: function () { - for (var iter = this; iter !== null; iter = iter._parent) { - if (iter._isWindow) { - return iter; - } - } - return null; - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(Widget.prototype, "children", { - /** - * @property {Array} children - * 控件的全部子控件。 - */ - get: function () { - return this._children; - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(Widget.prototype, "canvas", { - get: function () { - return this._canvas; - }, - enumerable: true, - configurable: true - }); - Widget.prototype.isWindow = function () { - return this._isWindow; - }; - Object.defineProperty(Widget.prototype, "leftPadding", { - /** - * @property {number} leftPadding - * 控件的左边界。 - */ - get: function () { - return this._lp; - }, - set: function (value) { - this.setProp("lp", value, true); - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(Widget.prototype, "rightPadding", { - /** - * @property {number} rightPadding - * 控件的右边界。 - */ - get: function () { - return this._rp; - }, - set: function (value) { - this.setProp("rp", value, true); - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(Widget.prototype, "topPadding", { - /** - * @property {number} topPadding - * 控件的上边界。 - */ - get: function () { - return this._tp; - }, - set: function (value) { - this.setProp("tp", value, true); - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(Widget.prototype, "bottomPadding", { - /** - * @property {number} bottomPadding - * 控件的下边界。 - */ - get: function () { - return this._bp; - }, - set: function (value) { - this.setProp("bp", value, true); - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(Widget.prototype, "padding", { - /** - * @property {number} padding - * 控件的边界。 - */ - get: function () { - return this._tp; - }, - set: function (value) { - this.setProp("lp", value, true); - this.setProp("tp", value, true); - this.setProp("rp", value, true); - this.setProp("bp", value, true); - }, - enumerable: true, - configurable: true - }); - Widget.prototype.setProp = function (prop, newValue, notify) { - var propName = "_" + prop; - var oldValue = this[propName]; - if (oldValue !== newValue) { - this[propName] = newValue; - this.requestRedraw(); - if (notify) { - var evt = this.ePropChangeEvent; - evt.init(Events.PROP_CHANGE, { prop: prop, oldValue: oldValue, newValue: newValue }); - this.dispatchEvent(evt); - } - } - return this; - }; - Widget.prototype.setText = function (text, notify) { - return this.setProp("text", text, notify); - }; - /** - * @method useBehavior - * 启用指定名称的Behavior - * @param {string} name Behavior的名称。 - * @param {any} options 选项。 - * @return {Behavior} - */ - Widget.prototype.useBehavior = function (name, options) { - var behavior; - if (!this._behaviors[name]) { - behavior = behavior_1.BehaviorFactory.create(name, this, options); - this._behaviors[name] = behavior; - } - else { - behavior = this._behaviors[name]; - behavior.setOptions(options); - } - return behavior; - }; - Widget.prototype.notifyChange = function (oldValue) { - this.dispatchEvent(this.eChangeEvent.init(Events.CHANGE, { newValue: this.value, oldValue: oldValue })); - }; - Widget.prototype.setValue = function (value, notify, exclude) { - var _this = this; - var oldValue = this.value; - if (exclude) { - var type = this.type; - if (this.parent && value) { - var arr = this.parent.children; - arr.forEach(function (child) { - if (child !== _this && child.type === type) { - if (child.value) { - child.setProp("value", false, true); - } - } - }); - } - this.setProp("value", true, notify); - } - else { - this.setProp("value", value, notify); - } - if (notify) { - this.notifyChange(oldValue); - } - }; - Widget.prototype.onReset = function () { - }; - Widget.prototype.onCreated = function () { - }; - Widget.prototype.getDefProps = function () { - return Widget.defProps; - }; - Widget.prototype.reset = function (type, options) { - var defProps = this.getDefProps(); - for (var key in defProps) { - this[key] = defProps[key]; - } - this._dirty = true; - this._type = type; - this._app = null; - this._children = []; - this._parent = null; - this._canvas = null; - this._styles = null; - this._target = null; - this._mainLoop = null; - this._userData = null; - this._themeManager = null; - this._lastOverWidget = null; - this._id = Date.now() + "." + Widget.ID++; - ; - this.onclick = null; - this.oncontextmenu = null; - this.onpointerdown = null; - this.onpointermove = null; - this.onpointerup = null; - this.onwheel = null; - this.onkeydown = null; - this.onkeyup = null; - this._behaviors = {}; - this._viewModel = null; - this._dataBindingRule = null; - this.onReset(); - this.set(options); - this.onCreated(); - return this; - }; - Widget.prototype.onFromJson = function (json) { - }; - /** - * @method fromJson - * 用JSON数据初始化当前控件。 - * @param {any} json 数据。 - */ - Widget.prototype.fromJson = function (json) { - var _this = this; - var defProps = this.getDefProps(); - for (var key in defProps) { - var value = json[key]; - if (value === undefined) { - value = defProps[key]; - } - this[key] = value; - } - var styles = json.styles; - if (styles) { - this._styles = {}; - for (var key in styles) { - var style = styles[key]; - json._styles[key] = style_1.Style.create(style); - } - } - var childrenLayouter = json.childrenLayouter; - if (childrenLayouter) { - this.childrenLayouter = layouter_1.LayouterFactory.create(childrenLayouter.type, childrenLayouter); - } - var layoutParam = json.layoutParam; - if (layoutParam) { - this.layoutParam = layouter_1.LayouterParamFactory.create(layoutParam.type, layoutParam); - } - this._children.length = 0; - if (json.children) { - json.children.forEach(function (childJson) { - var child = widget_factory_1.WidgetFactory.create(childJson.type, { parent: _this, app: _this.app }); - child.fromJson(childJson); - _this._children.push(child); - }); - } - if (json.dataBindingRule) { - this._dataBindingRule = binding_rule_2.BindingRule.createFromJson(json.dataBindingRule); - } - if (json.behaviors) { - this.behaviorsFromJson(json.behaviors); - } - this.onFromJson(json); - return this; - }; - /** - * @method clone - * CLONE当前控件。 - * @return {Widget} 新对象。 - */ - Widget.prototype.clone = function () { - var json = this.toJson(); - var widget = widget_factory_1.WidgetFactory.createWithJson(json); - return widget; - }; - Widget.prototype.onToJson = function (json) { - }; - Widget.prototype.behaviorsToJson = function () { - var json = {}; - var behaviors = this._behaviors; - if (behaviors) { - for (var key in behaviors) { - var value = behaviors[key]; - json[key] = value.toJson(); - } - } - return json; - }; - Widget.prototype.behaviorsFromJson = function (json) { - var behaviors = this._behaviors; - if (behaviors) { - for (var key in behaviors) { - var value = behaviors[key]; - value.dispose(); - } - } - if (json) { - for (var key in json) { - this.useBehavior(key, json.options); - } - } - return; - }; - /** - * @method toJson - * 序列化当前的控件到JSON数据。 - * @return {any} JSON数据。 - */ - Widget.prototype.toJson = function () { - var json = {}; - json.type = this._type; - var defProps = this.getDefProps(); - for (var key in defProps) { - var value = this[key]; - if (value !== defProps[key]) { - json[key] = value; - } - } - var styles = this._styles; - if (styles) { - json.styles = {}; - for (var key in styles) { - var style = styles[key]; - json.styles[key] = style.toJson(); - } - } - if (this.childrenLayouter) { - json.childrenLayouter = this.childrenLayouter.toJson(); - } - if (this.layoutParam) { - json.layoutParam = this.layoutParam.toJson(); - } - if (this.children.length) { - json.children = []; - this.children.forEach(function (child) { - json.children.push(child.toJson()); - }); - } - if (this._dataBindingRule) { - json.dataBindingRule = this._dataBindingRule.toJson(); - } - if (this._behaviors) { - json.behaviors = this.behaviorsToJson(); - } - this.onToJson(json); - return json; - }; - Object.defineProperty(Widget.prototype, "templateItem", { - get: function () { - return this._templateItem; - }, - /** - * @property {Widget} templateItem - * 模板项。用于在数据绑定时,自动生成子控件的模板。 - */ - set: function (value) { - this._templateItem = value; - this._templateItemJson = value ? value.toJson() : null; - }, - enumerable: true, - configurable: true - }); - Widget.prototype.addChildWithTemplate = function (fastMode) { - var child = null; - var json = this._templateItemJson; - if (json) { - child = widget_factory_1.WidgetFactory.createWithJson(json); - this.addChild(child, fastMode); - } - return child; - }; - //////////////////////////////////////////// - //绑定单个属性,子控件可以重载本函数去支持其它属性。 - Widget.prototype.onBindProp = function (prop, value) { - this[prop] = value; - }; - Object.defineProperty(Widget.prototype, "dataBindingRule", { - get: function () { - return this._dataBindingRule; - }, - /** - * @property {any} dataBindingRule - * 数据绑定规则。 - */ - set: function (dataBindingRule) { - this._dataBindingRule = binding_rule_2.BindingRule.create(dataBindingRule); - }, - enumerable: true, - configurable: true - }); - /** - * @method updateExplicit - * 显式的更新ViewModel。 - */ - Widget.prototype.updateExplicit = function () { - if (this._dataBindingRule) { - this.onUpdateToDataSource(); - } - this.children.forEach(function (child) { - child.updateExplicit(); - }); - return this; - }; - Widget.prototype.removeBinding = function () { - var viewModel = this._viewModel; - var dataBindingRule = this._dataBindingRule; - if (dataBindingRule && viewModel) { - viewModel.offChange(this.viewModelChangeFunc); - } - this._viewModel = null; - this._dataBindingRule = null; - }; - Widget.prototype.onBeforeBindData = function () { - }; - Widget.prototype.onAfterBindData = function () { - }; - /** - * @method bindData - * 绑定数据。 - * @param {IViewModel} viewModel View Model。 - * @return {Widget} 控件本身。 - */ - Widget.prototype.bindData = function (viewModel) { - var _this = this; - var dataBindingRule = this._dataBindingRule; - this._viewModel = viewModel; - this.onBeforeBindData(); - if (dataBindingRule && viewModel) { - var bindingMode = viewModel.bindingMode; - this.onBindCommand(viewModel, dataBindingRule); - if (bindingMode !== iview_model_1.BindingMode.ONE_WAY_TO_SOURCE) { - this.onBindData(viewModel, dataBindingRule); - } - if (bindingMode === iview_model_1.BindingMode.TWO_WAY || bindingMode === iview_model_1.BindingMode.ONE_WAY_TO_SOURCE) { - this.watchTargetChange(dataBindingRule); - } - if (bindingMode !== iview_model_1.BindingMode.ONE_TIME && bindingMode !== iview_model_1.BindingMode.ONE_WAY_TO_SOURCE) { - viewModel.onChange(this.viewModelChangeFunc); - } - this._isEnableFunc = function () { - var enable = true; - var vm = this._viewModel; - if (vm) { - dataBindingRule.forEach(function (prop, item) { - var source = item.source; - if (source.type === binding_rule_1.BindingCommandSource.TYPE) { - var commandSource = source; - enable = enable && vm.canExecute(commandSource.command); - } - }); - } - return enable; - }; - } - this.bindDataToChildren(viewModel); - if (viewModel.isCollection && this._templateItemJson) { - var collectionViewModel = viewModel; - collectionViewModel.onItemsChange(function (evt) { - _this.bindDataToChildren(viewModel); - }); - } - this.onAfterBindData(); - return this; - }; - Widget.prototype.bindDataToChildren = function (viewModel) { - if (viewModel.isCollection) { - if (this._templateItemJson) { - //对于集合viewModel,如果有模板项存在,则动态生成子控件。 - var json = this._templateItemJson; - var collectionViewModel = viewModel; - var n = collectionViewModel.total; - this.removeAllChildren(); - for (var i = 0; i < n; i++) { - var itemViewModel = collectionViewModel.getItemViewModel(i); - var child = this.addChildWithTemplate(true); - child.bindData(itemViewModel); - } - this.relayoutChildren(); - } - else { - //对于集合viewModel,如果没有模板项存在,则绑定集合viewModel当前项到子控件。 - this._children.forEach(function (child) { - child.bindData(viewModel); - }); - } - } - else { - //对于非集合viewModel,按正常绑定子控件。 - this._children.forEach(function (child) { - child.bindData(viewModel); - }); - } - }; - /* - * 绑定命令,注册相应的事件处理函数。 - */ - Widget.prototype.onBindCommand = function (viewModel, dataBindingRule) { - var _this = this; - dataBindingRule.forEach(function (prop, item) { - var source = item.source; - if (source.type === binding_rule_1.BindingCommandSource.TYPE) { - var commandSource = source; - var type = Events.mapToEvent(prop); - if (type) { - var command = commandSource.command; - if (typeof command == "object" && command.path) { - commandSource.command = viewModel.getProp(command.path); - } - var commandArgs = commandSource.commandArgs; - if (typeof commandArgs == "object" && commandArgs.path) { - commandSource.commandArgs = viewModel.getProp(commandArgs.path); - } - if (commandSource.eventHandler) { - _this.off(type, commandSource.eventHandler); - } - commandSource.eventHandler = function (evt) { - var args = commandSource.commandArgs || evt; - viewModel.execCommand(commandSource.command, args); - }; - _this.on(type, commandSource.eventHandler); - } - else { - console.log(prop + " is not supported yet."); - } - } - }); - }; - /* - * 把数据显示到界面上。 - */ - Widget.prototype.onBindData = function (viewModel, dataBindingRule) { - var _this = this; - dataBindingRule.forEach(function (prop, item) { - var source = item.source; - if (source.type === binding_rule_1.BindingDataSource.TYPE) { - var dataSource = source; - var value = dataSource.value; - var bindingMode = dataSource.mode || iview_model_1.BindingMode.TWO_WAY; - if (value === undefined && dataSource.path) { - value = viewModel.getProp(dataSource.path, dataSource.converter); - } - if (bindingMode !== iview_model_1.BindingMode.ONE_WAY_TO_SOURCE) { - _this.onBindProp(prop, value); - } - } - }); - }; - Widget.prototype.getPropDefaultBindMode = function (prop) { - return (prop === "value" && this.inputable) ? iview_model_1.BindingMode.TWO_WAY : iview_model_1.BindingMode.ONE_WAY; - }; - /* - * 子控件重载此函数向用户提示数据无效。 - */ - Widget.prototype.onInvalidInput = function (message) { - if (message) { - console.log("invalid value:" + message); - } - }; - Widget.prototype.onUpdateToDataSource = function () { - var _this = this; - var dataBindingRule = this._dataBindingRule; - dataBindingRule.forEach(function (prop, item) { - if (item.source.type === binding_rule_1.BindingDataSource.TYPE) { - var dataSource = item.source; - if (dataSource.updateTiming === iview_model_1.UpdateTiming.EXPLICIT) { - _this.updateValueToSource(_this.value, dataSource); - } - } - }); - }; - /* - * 把界面数据更新到模型。 - */ - Widget.prototype.updateValueToSource = function (value, dataSource, oldValue) { - var result = this._viewModel.setPropEx(dataSource, value, oldValue); - this.onInvalidInput(result.code ? result.message : null); - }; - /* - * 监控控件单个属性的变化。 - */ - Widget.prototype.watchTargetValueChange = function (dataSource) { - var _this = this; - var updateTiming = dataSource.updateTiming; - var bindingMode = dataSource.mode || iview_model_1.BindingMode.TWO_WAY; - if (updateTiming === iview_model_1.UpdateTiming.EXPLICIT) { - return; - } - if (bindingMode === iview_model_1.BindingMode.TWO_WAY || bindingMode === iview_model_1.BindingMode.ONE_WAY_TO_SOURCE) { - this.on(Events.CHANGE, function (evt) { - _this.updateValueToSource(evt.value, dataSource, evt.oldValue); - }); - if (updateTiming === iview_model_1.UpdateTiming.CHANGING) { - this.on(Events.CHANGING, function (evt) { - _this.updateValueToSource(evt.value, dataSource); - }); - } - } - }; - /* - * 监控控件属性的变化。 - */ - Widget.prototype.watchTargetChange = function (dataBindingRule) { - var _this = this; - dataBindingRule.forEach(function (prop, item) { - var source = item.source; - if (source.type === binding_rule_1.BindingDataSource.TYPE) { - var dataSource = source; - var bindingMode = _this.getPropDefaultBindMode(prop); - if (bindingMode === iview_model_1.BindingMode.TWO_WAY) { - _this.watchTargetValueChange(dataSource); - } - } - }); - }; - Widget.prototype.hitTest = function (x, y) { - return this.doHitTest(x, y, rect_1.Rect.rect.init(0, 0, this.w + 1, this.h + 1)); - }; - Widget.prototype.doHitTest = function (x, y, r) { - return r.containsPoint(x, y) ? HitTestResult.MM : HitTestResult.NONE; - }; - Widget.prototype.selfHitTest = function (x, y) { - return this.hitTest(x, y); - }; - Widget.defProps = { - _x: 0, - _y: 0, - _z: 0, - _w: 0, - _h: 0, - _state: 0, - _value: 0, - _enable: true, - _visible: true, - _selected: false, - _opacity: 1, - _scaleX: 1, - _scaleY: 1, - _pivotX: 0.5, - _pivotY: 0.5, - _rotation: 0, - _sensitive: true, - _tips: null, - _text: null, - _name: null, - _hitTestResult: 0, - _isWindow: false, - _mode: 0, - _styleType: null, - _lp: 0, - _tp: 0, - _rp: 0, - _bp: 0 - }; - Widget.ID = 10000; - return Widget; - }(emitter_1.Emitter)); - exports.Widget = Widget; - ; - - -/***/ }, -/* 20 */ -/***/ function(module, exports, __webpack_require__) { - - var __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__;/* WEBPACK VAR INJECTION */(function(process) {/** - * Tween.js - Licensed under the MIT license - * https://github.com/tweenjs/tween.js - * ---------------------------------------------- - * - * See https://github.com/tweenjs/tween.js/graphs/contributors for the full list of contributors. - * Thank you all, you're awesome! - */ - - var TWEEN = TWEEN || (function () { - - var _tweens = []; - - return { - - getAll: function () { - - return _tweens; - - }, - - removeAll: function () { - - _tweens = []; - - }, - - add: function (tween) { - - _tweens.push(tween); - - }, - - remove: function (tween) { - - var i = _tweens.indexOf(tween); - - if (i !== -1) { - _tweens.splice(i, 1); - } - - }, - - update: function (time, preserve) { - - if (_tweens.length === 0) { - return false; - } - - var i = 0; - - time = time !== undefined ? time : TWEEN.now(); - - while (i < _tweens.length) { - - if (_tweens[i].update(time) || preserve) { - i++; - } else { - _tweens.splice(i, 1); - } - - } - - return true; - - } - }; - - })(); - - - // Include a performance.now polyfill - (function () { - // In node.js, use process.hrtime. - if (this.window === undefined && this.process !== undefined) { - TWEEN.now = function () { - var time = process.hrtime(); - - // Convert [seconds, microseconds] to milliseconds. - return time[0] * 1000 + time[1] / 1000; - }; - } - // In a browser, use window.performance.now if it is available. - else if (this.window !== undefined && - window.performance !== undefined && - window.performance.now !== undefined) { - - // This must be bound, because directly assigning this function - // leads to an invocation exception in Chrome. - TWEEN.now = window.performance.now.bind(window.performance); - } - // Use Date.now if it is available. - else if (Date.now !== undefined) { - TWEEN.now = Date.now; - } - // Otherwise, use 'new Date().getTime()'. - else { - TWEEN.now = function () { - return new Date().getTime(); - }; - } - })(); - - - TWEEN.Tween = function (object) { - - var _object = object; - var _valuesStart = {}; - var _valuesEnd = {}; - var _valuesStartRepeat = {}; - var _duration = 1000; - var _repeat = 0; - var _yoyo = false; - var _isPlaying = false; - var _reversed = false; - var _delayTime = 0; - var _startTime = null; - var _easingFunction = TWEEN.Easing.Linear.None; - var _interpolationFunction = TWEEN.Interpolation.Linear; - var _chainedTweens = []; - var _onStartCallback = null; - var _onStartCallbackFired = false; - var _onUpdateCallback = null; - var _onCompleteCallback = null; - var _onStopCallback = null; - - // Set all starting values present on the target object - for (var field in object) { - _valuesStart[field] = parseFloat(object[field], 10); - } - - this.to = function (properties, duration) { - - if (duration !== undefined) { - _duration = duration; - } - - _valuesEnd = properties; - - return this; - - }; - - this.start = function (time) { - - TWEEN.add(this); - - _isPlaying = true; - - _onStartCallbackFired = false; - - _startTime = time !== undefined ? time : TWEEN.now(); - _startTime += _delayTime; - - for (var property in _valuesEnd) { - - // Check if an Array was provided as property value - if (_valuesEnd[property] instanceof Array) { - - if (_valuesEnd[property].length === 0) { - continue; - } - - // Create a local copy of the Array with the start value at the front - _valuesEnd[property] = [_object[property]].concat(_valuesEnd[property]); - - } - - // If `to()` specifies a property that doesn't exist in the source object, - // we should not set that property in the object - if (_valuesStart[property] === undefined) { - continue; - } - - _valuesStart[property] = _object[property]; - - if ((_valuesStart[property] instanceof Array) === false) { - _valuesStart[property] *= 1.0; // Ensures we're using numbers, not strings - } - - _valuesStartRepeat[property] = _valuesStart[property] || 0; - - } - - return this; - - }; - - this.stop = function () { - - if (!_isPlaying) { - return this; - } - - TWEEN.remove(this); - _isPlaying = false; - - if (_onStopCallback !== null) { - _onStopCallback.call(_object); - } - - this.stopChainedTweens(); - return this; - - }; - - this.stopChainedTweens = function () { - - for (var i = 0, numChainedTweens = _chainedTweens.length; i < numChainedTweens; i++) { - _chainedTweens[i].stop(); - } - - }; - - this.delay = function (amount) { - - _delayTime = amount; - return this; - - }; - - this.repeat = function (times) { - - _repeat = times; - return this; - - }; - - this.yoyo = function (yoyo) { - - _yoyo = yoyo; - return this; - - }; - - - this.easing = function (easing) { - - _easingFunction = easing; - return this; - - }; - - this.interpolation = function (interpolation) { - - _interpolationFunction = interpolation; - return this; - - }; - - this.chain = function () { - - _chainedTweens = arguments; - return this; - - }; - - this.onStart = function (callback) { - - _onStartCallback = callback; - return this; - - }; - - this.onUpdate = function (callback) { - - _onUpdateCallback = callback; - return this; - - }; - - this.onComplete = function (callback) { - - _onCompleteCallback = callback; - return this; - - }; - - this.onStop = function (callback) { - - _onStopCallback = callback; - return this; - - }; - - this.update = function (time) { - - var property; - var elapsed; - var value; - - if (time < _startTime) { - return true; - } - - if (_onStartCallbackFired === false) { - - if (_onStartCallback !== null) { - _onStartCallback.call(_object); - } - - _onStartCallbackFired = true; - - } - - elapsed = (time - _startTime) / _duration; - elapsed = elapsed > 1 ? 1 : elapsed; - - value = _easingFunction(elapsed); - - for (property in _valuesEnd) { - - // Don't update properties that do not exist in the source object - if (_valuesStart[property] === undefined) { - continue; - } - - var start = _valuesStart[property] || 0; - var end = _valuesEnd[property]; - - if (end instanceof Array) { - - _object[property] = _interpolationFunction(end, value); - - } else { - - // Parses relative end values with start as base (e.g.: +10, -3) - if (typeof (end) === 'string') { - - if (end.charAt(0) === '+' || end.charAt(0) === '-') { - end = start + parseFloat(end, 10); - } else { - end = parseFloat(end, 10); - } - } - - // Protect against non numeric properties. - if (typeof (end) === 'number') { - _object[property] = start + (end - start) * value; - } - - } - - } - - if (_onUpdateCallback !== null) { - _onUpdateCallback.call(_object, value); - } - - if (elapsed === 1) { - - if (_repeat > 0) { - - if (isFinite(_repeat)) { - _repeat--; - } - - // Reassign starting values, restart by making startTime = now - for (property in _valuesStartRepeat) { - - if (typeof (_valuesEnd[property]) === 'string') { - _valuesStartRepeat[property] = _valuesStartRepeat[property] + parseFloat(_valuesEnd[property], 10); - } - - if (_yoyo) { - var tmp = _valuesStartRepeat[property]; - - _valuesStartRepeat[property] = _valuesEnd[property]; - _valuesEnd[property] = tmp; - } - - _valuesStart[property] = _valuesStartRepeat[property]; - - } - - if (_yoyo) { - _reversed = !_reversed; - } - - _startTime = time + _delayTime; - - return true; - - } else { - - if (_onCompleteCallback !== null) { - _onCompleteCallback.call(_object); - } - - for (var i = 0, numChainedTweens = _chainedTweens.length; i < numChainedTweens; i++) { - // Make the chained tweens start exactly at the time they should, - // even if the `update()` method was called way past the duration of the tween - _chainedTweens[i].start(_startTime + _duration); - } - - return false; - - } - - } - - return true; - - }; - - }; - - - TWEEN.Easing = { - - Linear: { - - None: function (k) { - - return k; - - } - - }, - - Quadratic: { - - In: function (k) { - - return k * k; - - }, - - Out: function (k) { - - return k * (2 - k); - - }, - - InOut: function (k) { - - if ((k *= 2) < 1) { - return 0.5 * k * k; - } - - return - 0.5 * (--k * (k - 2) - 1); - - } - - }, - - Cubic: { - - In: function (k) { - - return k * k * k; - - }, - - Out: function (k) { - - return --k * k * k + 1; - - }, - - InOut: function (k) { - - if ((k *= 2) < 1) { - return 0.5 * k * k * k; - } - - return 0.5 * ((k -= 2) * k * k + 2); - - } - - }, - - Quartic: { - - In: function (k) { - - return k * k * k * k; - - }, - - Out: function (k) { - - return 1 - (--k * k * k * k); - - }, - - InOut: function (k) { - - if ((k *= 2) < 1) { - return 0.5 * k * k * k * k; - } - - return - 0.5 * ((k -= 2) * k * k * k - 2); - - } - - }, - - Quintic: { - - In: function (k) { - - return k * k * k * k * k; - - }, - - Out: function (k) { - - return --k * k * k * k * k + 1; - - }, - - InOut: function (k) { - - if ((k *= 2) < 1) { - return 0.5 * k * k * k * k * k; - } - - return 0.5 * ((k -= 2) * k * k * k * k + 2); - - } - - }, - - Sinusoidal: { - - In: function (k) { - - return 1 - Math.cos(k * Math.PI / 2); - - }, - - Out: function (k) { - - return Math.sin(k * Math.PI / 2); - - }, - - InOut: function (k) { - - return 0.5 * (1 - Math.cos(Math.PI * k)); - - } - - }, - - Exponential: { - - In: function (k) { - - return k === 0 ? 0 : Math.pow(1024, k - 1); - - }, - - Out: function (k) { - - return k === 1 ? 1 : 1 - Math.pow(2, - 10 * k); - - }, - - InOut: function (k) { - - if (k === 0) { - return 0; - } - - if (k === 1) { - return 1; - } - - if ((k *= 2) < 1) { - return 0.5 * Math.pow(1024, k - 1); - } - - return 0.5 * (- Math.pow(2, - 10 * (k - 1)) + 2); - - } - - }, - - Circular: { - - In: function (k) { - - return 1 - Math.sqrt(1 - k * k); - - }, - - Out: function (k) { - - return Math.sqrt(1 - (--k * k)); - - }, - - InOut: function (k) { - - if ((k *= 2) < 1) { - return - 0.5 * (Math.sqrt(1 - k * k) - 1); - } - - return 0.5 * (Math.sqrt(1 - (k -= 2) * k) + 1); - - } - - }, - - Elastic: { - - In: function (k) { - - if (k === 0) { - return 0; - } - - if (k === 1) { - return 1; - } - - return -Math.pow(2, 10 * (k - 1)) * Math.sin((k - 1.1) * 5 * Math.PI); - - }, - - Out: function (k) { - - if (k === 0) { - return 0; - } - - if (k === 1) { - return 1; - } - - return Math.pow(2, -10 * k) * Math.sin((k - 0.1) * 5 * Math.PI) + 1; - - }, - - InOut: function (k) { - - if (k === 0) { - return 0; - } - - if (k === 1) { - return 1; - } - - k *= 2; - - if (k < 1) { - return -0.5 * Math.pow(2, 10 * (k - 1)) * Math.sin((k - 1.1) * 5 * Math.PI); - } - - return 0.5 * Math.pow(2, -10 * (k - 1)) * Math.sin((k - 1.1) * 5 * Math.PI) + 1; - - } - - }, - - Back: { - - In: function (k) { - - var s = 1.70158; - - return k * k * ((s + 1) * k - s); - - }, - - Out: function (k) { - - var s = 1.70158; - - return --k * k * ((s + 1) * k + s) + 1; - - }, - - InOut: function (k) { - - var s = 1.70158 * 1.525; - - if ((k *= 2) < 1) { - return 0.5 * (k * k * ((s + 1) * k - s)); - } - - return 0.5 * ((k -= 2) * k * ((s + 1) * k + s) + 2); - - } - - }, - - Bounce: { - - In: function (k) { - - return 1 - TWEEN.Easing.Bounce.Out(1 - k); - - }, - - Out: function (k) { - - if (k < (1 / 2.75)) { - return 7.5625 * k * k; - } else if (k < (2 / 2.75)) { - return 7.5625 * (k -= (1.5 / 2.75)) * k + 0.75; - } else if (k < (2.5 / 2.75)) { - return 7.5625 * (k -= (2.25 / 2.75)) * k + 0.9375; - } else { - return 7.5625 * (k -= (2.625 / 2.75)) * k + 0.984375; - } - - }, - - InOut: function (k) { - - if (k < 0.5) { - return TWEEN.Easing.Bounce.In(k * 2) * 0.5; - } - - return TWEEN.Easing.Bounce.Out(k * 2 - 1) * 0.5 + 0.5; - - } - - } - - }; - - TWEEN.Interpolation = { - - Linear: function (v, k) { - - var m = v.length - 1; - var f = m * k; - var i = Math.floor(f); - var fn = TWEEN.Interpolation.Utils.Linear; - - if (k < 0) { - return fn(v[0], v[1], f); - } - - if (k > 1) { - return fn(v[m], v[m - 1], m - f); - } - - return fn(v[i], v[i + 1 > m ? m : i + 1], f - i); - - }, - - Bezier: function (v, k) { - - var b = 0; - var n = v.length - 1; - var pw = Math.pow; - var bn = TWEEN.Interpolation.Utils.Bernstein; - - for (var i = 0; i <= n; i++) { - b += pw(1 - k, n - i) * pw(k, i) * v[i] * bn(n, i); - } - - return b; - - }, - - CatmullRom: function (v, k) { - - var m = v.length - 1; - var f = m * k; - var i = Math.floor(f); - var fn = TWEEN.Interpolation.Utils.CatmullRom; - - if (v[0] === v[m]) { - - if (k < 0) { - i = Math.floor(f = m * (1 + k)); - } - - return fn(v[(i - 1 + m) % m], v[i], v[(i + 1) % m], v[(i + 2) % m], f - i); - - } else { - - if (k < 0) { - return v[0] - (fn(v[0], v[0], v[1], v[1], -f) - v[0]); - } - - if (k > 1) { - return v[m] - (fn(v[m], v[m], v[m - 1], v[m - 1], f - m) - v[m]); - } - - return fn(v[i ? i - 1 : 0], v[i], v[m < i + 1 ? m : i + 1], v[m < i + 2 ? m : i + 2], f - i); - - } - - }, - - Utils: { - - Linear: function (p0, p1, t) { - - return (p1 - p0) * t + p0; - - }, - - Bernstein: function (n, i) { - - var fc = TWEEN.Interpolation.Utils.Factorial; - - return fc(n) / fc(i) / fc(n - i); - - }, - - Factorial: (function () { - - var a = [1]; - - return function (n) { - - var s = 1; - - if (a[n]) { - return a[n]; - } - - for (var i = n; i > 1; i--) { - s *= i; - } - - a[n] = s; - return s; - - }; - - })(), - - CatmullRom: function (p0, p1, p2, p3, t) { - - var v0 = (p2 - p0) * 0.5; - var v1 = (p3 - p1) * 0.5; - var t2 = t * t; - var t3 = t * t2; - - return (2 * p1 - 2 * p2 + v0 + v1) * t3 + (- 3 * p1 + 3 * p2 - 2 * v0 - v1) * t2 + v0 * t + p1; - - } - - } - - }; - - // UMD (Universal Module Definition) - (function (root) { - - if (true) { - - // AMD - !(__WEBPACK_AMD_DEFINE_ARRAY__ = [], __WEBPACK_AMD_DEFINE_RESULT__ = function () { - return TWEEN; - }.apply(exports, __WEBPACK_AMD_DEFINE_ARRAY__), __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__)); - - } else if (typeof module !== 'undefined' && typeof exports === 'object') { - - // Node.js - module.exports = TWEEN; - - } else if (root !== undefined) { - - // Global variable - root.TWEEN = TWEEN; - - } - - })(this); - - /* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(10))) - -/***/ }, -/* 21 */ -/***/ function(module, exports) { - - //! stable.js 0.1.5, https://github.com/Two-Screen/stable - //! © 2014 Angry Bytes and contributors. MIT licensed. - "use strict"; - // A stable array sort, because `Array#sort()` is not guaranteed stable. - // This is an implementation of merge sort, without recursion. - function stableSort(arr, comp) { - var result = exec(arr, comp); - // This simply copies back if the result isn't in the original array, - // which happens on an odd number of passes. - if (result !== arr) { - pass(result, null, arr.length, arr); - } - return arr; - } - exports.stableSort = stableSort; - ; - // Execute the sort using the input array and a second buffer as work space. - // Returns one of those two, containing the final result. - function exec(arr, comp) { - if (typeof (comp) !== 'function') { - comp = function (a, b) { - return String(a).localeCompare(b); - }; - } - // Short-circuit when there's nothing to sort. - var len = arr.length; - if (len <= 1) { - return arr; - } - // Rather than dividing input, simply iterate chunks of 1, 2, 4, 8, etc. - // Chunks are the size of the left or right hand in merge sort. - // Stop when the left-hand covers all of the array. - var buffer = new Array(len); - for (var chk = 1; chk < len; chk *= 2) { - pass(arr, comp, chk, buffer); - var tmp = arr; - arr = buffer; - buffer = tmp; - } - return arr; - } - // Run a single pass with the given chunk size. - var pass = function (arr, comp, chk, result) { - var len = arr.length; - var i = 0; - // Step size / double chunk size. - var dbl = chk * 2; - // Bounds of the left and right chunks. - var l, r, e; - // Iterators over the left and right chunk. - var li, ri; - // Iterate over pairs of chunks. - for (l = 0; l < len; l += dbl) { - r = l + chk; - e = r + chk; - if (r > len) - r = len; - if (e > len) - e = len; - // Iterate both chunks in parallel. - li = l; - ri = r; - while (true) { - // Compare the chunks. - if (li < r && ri < e) { - // This works for a regular `sort()` compatible comparator, - // but also for a simple comparator like: `a > b` - if (comp(arr[li], arr[ri]) <= 0) { - result[i++] = arr[li++]; - } - else { - result[i++] = arr[ri++]; - } - } - else if (li < r) { - result[i++] = arr[li++]; - } - else if (ri < e) { - result[i++] = arr[ri++]; - } - else { - break; - } - } - } - }; - function assign(target, other) { - if (target === undefined || target === null) { - throw new TypeError('Cannot convert first argument to object'); - } - var to = Object(target); - for (var i = 1; i < arguments.length; i++) { - var nextSource = arguments[i]; - if (nextSource === undefined || nextSource === null) { - continue; - } - nextSource = Object(nextSource); - var keysArray = Object.keys(Object(nextSource)); - for (var nextIndex = 0, len = keysArray.length; nextIndex < len; nextIndex++) { - var nextKey = keysArray[nextIndex]; - var desc = Object.getOwnPropertyDescriptor(nextSource, nextKey); - if (desc !== undefined && desc.enumerable) { - to[nextKey] = nextSource[nextKey]; - } - } - } - return to; - } - exports.assign = assign; - function aRemove(arr, obj) { - var i = arr.indexOf(obj); - if (i >= 0) { - arr.splice(i, 1); - return true; - } - return false; - } - exports.aRemove = aRemove; - Array.prototype.forEachR = function (func) { - var n = this.length - 1; - for (var i = this.length - 1; i >= 0; i--) { - var iter = this[i]; - func(this[i], i); - } - }; - Array.prototype.stableSort = function (comp) { - stableSort(this, comp); - }; - Array.prototype.remove = function (obj) { - return aRemove(this, obj); - }; - - -/***/ }, -/* 22 */ -/***/ function(module, exports, __webpack_require__) { - - "use strict"; - var device_info_1 = __webpack_require__(23); - var StringTable = (function () { - function StringTable() { - } - StringTable.set = function (strTable, lang) { - if (!lang) { - lang = device_info_1.DeviceInfo.language; - } - StringTable.table[lang] = strTable; - }; - StringTable.add = function (strTable, lang) { - if (!lang) { - lang = device_info_1.DeviceInfo.language; - } - if (StringTable.table[lang]) { - var table = StringTable.table[lang]; - for (var key in strTable) { - table[key] = strTable[key]; - } - } - else { - StringTable.table[lang] = strTable; - } - }; - StringTable.get = function (lang) { - return StringTable.table[lang]; - }; - StringTable.tr = function (str) { - var lang = device_info_1.DeviceInfo.language; - var table = StringTable.table[lang]; - var tr = table ? table[str] : str; - return tr ? tr : str; - }; - StringTable.table = {}; - return StringTable; - }()); - exports.StringTable = StringTable; - ; - - -/***/ }, -/* 23 */ -/***/ function(module, exports) { - - "use strict"; - /** - * @class DeviceInfo - * 设备信息。可以获取语言,操作系统和浏览器等相关信息(单例对象,直接调用)。 - */ - var DeviceInfo = (function () { - function DeviceInfo() { - } - DeviceInfo.init = function (_locale, userAgent) { - DeviceInfo.locale = (_locale || navigator.language).toLowerCase(); - DeviceInfo.language = DeviceInfo.locale.split("-")[0]; - var ua = userAgent = userAgent || navigator.userAgent; - DeviceInfo.isWindowsPhone = ua.indexOf("Windows Phone") >= 0; - DeviceInfo.isAndroid = ua.indexOf("Android") >= 0; - DeviceInfo.isIPhone = ua.indexOf("iPhone;") >= 0; - DeviceInfo.isIPad = ua.indexOf("iPad;") >= 0; - DeviceInfo.isLinux = !DeviceInfo.isAndroid && ua.indexOf("Linux;") >= 0; - DeviceInfo.isMacOS = !DeviceInfo.isIPhone && !DeviceInfo.isIPad && ua.indexOf("Macintosh;") >= 0; - DeviceInfo.isWindows = !DeviceInfo.isWindowsPhone && ua.indexOf("Windows NT") >= 0; - DeviceInfo.isMobile = ua.indexOf("Mobile") >= 0; - DeviceInfo.isPointerSupported = window.navigator.pointerEnabled; - DeviceInfo.isMSPointerSupported = window.navigator.msPointerEnabled; - var msTouchEnabled = !!window.navigator.msMaxTouchPoints; - var generalTouchEnabled = "ontouchstart" in document.createElement("div"); - DeviceInfo.isTouchSupported = !!msTouchEnabled || generalTouchEnabled; - }; - return DeviceInfo; - }()); - exports.DeviceInfo = DeviceInfo; - - -/***/ }, -/* 24 */ -/***/ function(module, exports, __webpack_require__) { - - "use strict"; - var factory_1 = __webpack_require__(25); - /** - * Widget工厂,注册控件的创建函数和根据控件的类型创建控件。 - * 主要用于根据UI编辑器生成的UI数据创建UI,每个控件都要向WidgetFactory注册。 - * - * 示例: - * ``` - * WidgetFactory.register(Button.TYPE, Button.create); - * ``` - * - */ - var WidgetFactory = (function () { - function WidgetFactory() { - } - WidgetFactory.register = function (type, creator) { - return WidgetFactory.factory.register(type, creator); - }; - WidgetFactory.create = function (type, options) { - return WidgetFactory.factory.create(type, options); - }; - WidgetFactory.createWithJson = function (json) { - var widget = WidgetFactory.create(json.type); - widget.fromJson(json); - return widget; - }; - WidgetFactory.factory = new factory_1.Factory(); - return WidgetFactory; - }()); - exports.WidgetFactory = WidgetFactory; - - -/***/ }, -/* 25 */ -/***/ function(module, exports) { - - "use strict"; - /** - * 一个通用的工厂类。 - */ - var Factory = (function () { - function Factory() { - this.creators = {}; - } - Factory.prototype.register = function (type, creator) { - this.creators[type] = creator; - }; - Factory.prototype.create = function (type, options) { - var obj = null; - var creator = this.creators[type]; - if (creator) { - obj = creator(options); - } - return obj; - }; - return Factory; - }()); - exports.Factory = Factory; - - -/***/ }, -/* 26 */ -/***/ function(module, exports, __webpack_require__) { - - "use strict"; - var style_1 = __webpack_require__(3); - var carota = __webpack_require__(27); - var ut = __webpack_require__(48); - var tokenizer = ut.createTokenizerStream(); - var Token = ut.Token; - var Break = ut.Break; - (function (RoundType) { - RoundType[RoundType["TL"] = 1] = "TL"; - RoundType[RoundType["TR"] = 2] = "TR"; - RoundType[RoundType["BL"] = 4] = "BL"; - RoundType[RoundType["BR"] = 8] = "BR"; - })(exports.RoundType || (exports.RoundType = {})); - var RoundType = exports.RoundType; - ; - var TextLine = (function () { - function TextLine() { - this.text = ""; - this.width = 0; - } - return TextLine; - }()); - exports.TextLine = TextLine; - ; - var Graphics = (function () { - function Graphics() { - } - Graphics.measureText = function (text, font) { - var ctx = Graphics.canvas.getContext("2d"); - ctx.font = font; - var width = ctx.measureText(text).width; - return width; - }; - Graphics.layoutText = function (text, maxWidth, font, _ctx) { - var ret = []; - if (!text || maxWidth < 5) { - return ret; - } - var line = new TextLine(); - var tokenizer = ut.createTokenizerStream(); - var ctx = _ctx ? _ctx : Graphics.canvas.getContext("2d"); - ctx.font = font; - tokenizer.on('token', function (token, type, action) { - var width = ctx.measureText(token).width; - switch (type) { - case Token.LF: - case Token.CR: { - ret.push(line); - line = new TextLine(); - line.text = "\n"; - ret.push(line); - line = new TextLine(); - return; - } - case Token.CL: - case Token.EX: { - line.text += token; - line.width += width; - return; - } - default: break; - } - if (line.width >= maxWidth) { - ret.push(line); - line = new TextLine(); - } - var n = token.length; - if ((line.width + width) <= maxWidth || n < 2) { - line.text += token; - line.width += width; - } - else if (type === Token.AL && action === Break.PROHIBITED && width < maxWidth) { - ret.push(line); - line = new TextLine(); - line.text = token; - line.width = width; - } - else { - for (var i = 0; i < n; i++) { - var c = token[i]; - width = ctx.measureText(c).width; - if (line.width >= maxWidth) { - ret.push(line); - line = new TextLine(); - } - line.text += c; - line.width += width; - } - } - }); - tokenizer.write(text); - tokenizer.end(); - ret.push(line); - return ret; - }; - Graphics.drawTextML = function (ctx, lines, style, r) { - var x = 0; - var y = 0; - var n = lines.length; - var lineHeight = style.textLineHeight; - var height = n * lineHeight; - switch (style.textAlign) { - case "right": { - x = r.x + r.w; - break; - } - case "center": { - x = r.x + (r.w >> 1); - break; - } - default: { - x = r.x; - break; - } - } - switch (style.textBaseline) { - case "top": { - y = r.y; - break; - } - case "bottom": { - y = r.y + r.h - height; - break; - } - default: { - y = r.y + ((r.h - height) >> 1); - break; - } - } - y = Math.max(y, 0); - x = Math.max(x, 0); - var maxY = r.y + r.h; - ctx.font = style.font; - ctx.fillStyle = style.textColor; - ctx.textAlign = style.textAlign; - ctx.textBaseline = "top"; - for (var i = 0; i < n; i++) { - var text = lines[i].text; - ctx.fillText(text, x, y, r.w); - y += lineHeight; - if ((y + lineHeight) > maxY) { - break; - } - } - return; - }; - Graphics.drawTextSL = function (ctx, text, style, r) { - var x = 0; - var y = 0; - switch (style.textAlign) { - case "right": { - x = r.x + r.w; - break; - } - case "center": { - x = r.x + (r.w >> 1); - break; - } - default: { - x = r.x; - break; - } - } - switch (style.textBaseline) { - case "top": { - y = r.y; - break; - } - case "bottom": { - y = r.y + r.h; - break; - } - default: { - y = r.y + (r.h >> 1); - break; - } - } - if (text && style.textColor) { - ctx.font = style.font; - ctx.fillStyle = style.textColor; - ctx.textAlign = style.textAlign; - ctx.textBaseline = style.textBaseline; - ctx.fillText(text, x, y); - } - }; - Graphics.drawLine = function (ctx, strokeStyle, lineWidth, x1, y1, x2, y2) { - if (strokeStyle && lineWidth > 0) { - ctx.beginPath(); - ctx.lineWidth = lineWidth; - ctx.strokeStyle = strokeStyle; - ctx.moveTo(x1, y1); - ctx.lineTo(x2, y2); - ctx.stroke(); - } - }; - Graphics.drawCircle = function (ctx, fillStyle, strokeStyle, lineWidth, x, y, r) { - if (fillStyle || (strokeStyle && lineWidth > 0)) { - ctx.beginPath(); - ctx.arc(x, y, r, 0, Math.PI * 2); - if (fillStyle) { - ctx.fillStyle = fillStyle; - ctx.fill(); - } - if (strokeStyle && lineWidth > 0) { - ctx.strokeStyle = strokeStyle; - ctx.lineWidth = 1; - ctx.stroke(); - } - } - }; - Graphics.drawRect = function (ctx, fillStyle, strokeStyle, lineWidth, x, y, w, h) { - if (fillStyle || (strokeStyle && lineWidth > 0)) { - ctx.beginPath(); - ctx.rect(x, y, w, h); - if (fillStyle) { - style_1.Style.fill(ctx, fillStyle, h); - } - if (strokeStyle && lineWidth > 0) { - ctx.lineWidth = lineWidth; - ctx.strokeStyle = strokeStyle; - ctx.stroke(); - } - } - }; - Graphics.drawRoundRect = function (ctx, fillStyle, strokeStyle, lineWidth, x, y, w, h, r, type) { - if (fillStyle || (strokeStyle && lineWidth > 0)) { - Graphics.roundRect(ctx, x, y, w, h, r, type); - if (fillStyle) { - style_1.Style.fill(ctx, fillStyle, h); - } - if (strokeStyle && lineWidth > 0) { - ctx.lineWidth = lineWidth; - ctx.strokeStyle = strokeStyle; - ctx.stroke(); - } - } - }; - Graphics.roundRect = function (ctx, x, y, w, h, r, type) { - if (!type) { - type = RoundType.TL | RoundType.TR | RoundType.BL | RoundType.BR; - } - var d = r << 1; - ctx.beginPath(); - if (d > w || d > h) { - var cx = x + (w >> 1); - var cy = y + (h >> 1); - r = Math.min(w >> 1, h >> 1); - ctx.arc(cx, cy, r, 0, Math.PI * 2); - return; - } - if (!r) { - ctx.rect(x, y, w, h); - return; - } - ctx.translate(x, y); - if (type & RoundType.TL) { - ctx.moveTo(0, r); - ctx.quadraticCurveTo(0, 0, r, 0); - } - else { - ctx.moveTo(0, 0); - } - if (type & RoundType.TR) { - ctx.lineTo(w - r, 0); - ctx.quadraticCurveTo(w, 0, w, r); - } - else { - ctx.lineTo(w, 0); - } - if (type & RoundType.BR) { - ctx.lineTo(w, h - r); - ctx.quadraticCurveTo(w, h, w - r, h); - } - else { - ctx.lineTo(w, h); - } - if (type & RoundType.BL) { - ctx.lineTo(r, h); - ctx.quadraticCurveTo(0, h, 0, h - r); - } - else { - ctx.lineTo(0, h); - } - ctx.closePath(); - ctx.translate(-x, -y); - }; - Graphics.canvas = document.createElement("canvas"); - return Graphics; - }()); - exports.Graphics = Graphics; - ; - - -/***/ }, -/* 27 */ -/***/ function(module, exports, __webpack_require__) { - - var node = __webpack_require__(28); - var editor = __webpack_require__(33); - var doc = __webpack_require__(34); - var dom = __webpack_require__(46); - var runs = __webpack_require__(30); - var html = __webpack_require__(47); - var frame = __webpack_require__(41); - var text = __webpack_require__(39); - var rect = __webpack_require__(31); - - var bundle = { - node: node, - editor: editor, - document: doc, - dom: dom, - runs: runs, - html: html, - frame: frame, - text: text, - rect: rect - }; - - module.exports = bundle; - - if (typeof window !== 'undefined' && window.document) { - if (window.carota) { - throw new Error('Something else is called carota!'); - } - window.carota = bundle; - } - - -/***/ }, -/* 28 */ -/***/ function(module, exports, __webpack_require__) { - - var per = __webpack_require__(29); - var runs = __webpack_require__(30); - var rect = __webpack_require__(31); - var util = __webpack_require__(32); - - exports.prototype = { - children: function() { - return []; - }, - parent: function() { - return null; - }, - first: function() { - return this.children()[0]; - }, - last: function() { - return this.children()[this.children().length - 1]; - }, - next: function() { - var self = this; - for (;;) { - var parent = self.parent(); - if (!parent) { - return null; - } - var siblings = parent.children(); - var next = siblings[siblings.indexOf(self) + 1]; - if (next) { - for (;;) { - var first = next.first(); - if (!first) { - break; - } - next = first; - } - return next; - } - self = parent; - } - }, - previous: function() { - var parent = this.parent(); - if (!parent) { - return null; - } - var siblings = parent.children(); - var prev = siblings[siblings.indexOf(this) - 1]; - if (prev) { - return prev; - } - var prevParent = parent.previous(); - return !prevParent ? null : prevParent.last(); - }, - byOrdinal: function(index) { - var found = null; - if (this.children().some(function(child) { - if (index >= child.ordinal && index < child.ordinal + child.length) { - found = child.byOrdinal(index); - if (found) { - return true; - } - } - })) { - return found; - } - return this; - }, - byCoordinate: function(x, y) { - var found; - this.children().some(function(child) { - var b = child.bounds(); - if (b.contains(x, y)) { - found = child.byCoordinate(x, y); - if (found) { - return true; - } - } - }); - if (!found) { - found = this.last(); - while (found) { - var next = found.last(); - if (!next) { - break; - } - found = next; - } - var foundNext = found.next(); - if (foundNext && foundNext.block) { - found = foundNext; - } - } - return found; - }, - draw: function(ctx, viewPort) { - this.children().forEach(function(child) { - child.draw(ctx, viewPort); - }); - }, - parentOfType: function(type) { - var p = this.parent(); - return p && (p.type === type ? p : p.parentOfType(type)); - }, - bounds: function() { - var l = this._left, t = this._top, r = 0, b = 0; - this.children().forEach(function(child) { - var cb = child.bounds(); - l = Math.min(l, cb.l); - t = Math.min(t, cb.t); - r = Math.max(r, cb.l + cb.w); - b = Math.max(b, cb.t + cb.h); - }); - return rect(l, t, r - l, b - t); - } - }; - - exports.derive = function(methods) { - return util.derive(exports.prototype, methods); - }; - - var generic = exports.derive({ - children: function() { - return this._children; - }, - parent: function() { - return this._parent; - }, - finalize: function(startDecrement, lengthIncrement) { - var start = Number.MAX_VALUE, end = 0; - this._children.forEach(function(child) { - start = Math.min(start, child.ordinal); - end = Math.max(end, child.ordinal + child.length); - }); - Object.defineProperty(this, 'ordinal', { value: start - (startDecrement || 0) }); - Object.defineProperty(this, 'length', { value: (lengthIncrement || 0) + end - start }); - } - }); - - exports.generic = function(type, parent, left, top) { - return Object.create(generic, { - type: { value: type }, - _children: { value: [] }, - _parent: { value: parent }, - _left: { value: typeof left === 'number' ? left : Number.MAX_VALUE }, - _top: { value: typeof top === 'number' ? top : Number.MAX_VALUE } - }); - }; - - -/***/ }, -/* 29 */ -/***/ function(module, exports, __webpack_require__) { - - - (function(exportFunction) { - - function toFunc(valOrFunc, bindThis) { - if (typeof valOrFunc !== 'function') { - return Array.isArray(valOrFunc) - ? function(emit) { - return valOrFunc.some(emit); - } : function(emit) { - return emit(valOrFunc); - }; + /// + /// + "use strict"; + var __extends = (this && this.__extends) || (function () { + var extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + return function (d, b) { + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; + })(); + Object.defineProperty(exports, "__esModule", { value: true }); + var rect_1 = __webpack_require__(1); + var style_1 = __webpack_require__(3); + var canvas_1 = __webpack_require__(13); + var TWEEN = __webpack_require__(20); + var emitter_1 = __webpack_require__(4); + var utils_1 = __webpack_require__(21); + var Events = __webpack_require__(6); + var string_table_1 = __webpack_require__(22); + var widget_factory_1 = __webpack_require__(24); + var graphics_1 = __webpack_require__(26); + var dirty_rect_context_1 = __webpack_require__(83); + var image_tile_1 = __webpack_require__(7); + var behavior_1 = __webpack_require__(85); + var layouter_1 = __webpack_require__(86); + var binding_rule_1 = __webpack_require__(87); + var binding_rule_2 = __webpack_require__(87); + var iview_model_1 = __webpack_require__(89); + /** + * @enum WidgetState + * 控件的状态 + */ + var WidgetState; + (function (WidgetState) { + /** + * @property {number} + * 正常状态。 + */ + WidgetState[WidgetState["NORMAL"] = 0] = "NORMAL"; + /** + * @property {number} + * Pointer在控件上。 + */ + WidgetState[WidgetState["OVER"] = 1] = "OVER"; + /** + * @property {number} + * Pointer按下的状态。 + */ + WidgetState[WidgetState["ACTIVE"] = 2] = "ACTIVE"; + /** + * @property {number} + * 禁用状态。 + */ + WidgetState[WidgetState["DISABLE"] = 3] = "DISABLE"; + /** + * @property {number} + * 选中状态。只对部分设备有效。 + */ + WidgetState[WidgetState["SELECTED"] = 4] = "SELECTED"; + })(WidgetState = exports.WidgetState || (exports.WidgetState = {})); + ; + /** + * @enum HitTestResult + * 点击测试结果。 + */ + var HitTestResult; + (function (HitTestResult) { + /** + * @property {number} + * 点击在控件之外。 + */ + HitTestResult[HitTestResult["NONE"] = 0] = "NONE"; + /** + * @property {number} + * 点击在控件左上角。 + */ + HitTestResult[HitTestResult["TL"] = 1] = "TL"; + /** + * @property {number} + * 点击在控件上面中间。 + */ + HitTestResult[HitTestResult["TM"] = 2] = "TM"; + /** + * @property {number} + * 点击在控件右上角。 + */ + HitTestResult[HitTestResult["TR"] = 3] = "TR"; + /** + * @property {number} + * 点击在控件左边中间。 + */ + HitTestResult[HitTestResult["ML"] = 4] = "ML"; + /** + * @property {number} + * 点击在控件中间区域。 + */ + HitTestResult[HitTestResult["MM"] = 5] = "MM"; + /** + * @property {number} + * 点击在控件右边中间。 + */ + HitTestResult[HitTestResult["MR"] = 6] = "MR"; + /** + * @property {number} + * 点击在控件左下角。 + */ + HitTestResult[HitTestResult["BL"] = 7] = "BL"; + /** + * @property {number} + * 点击在控件下面中间。 + */ + HitTestResult[HitTestResult["BM"] = 8] = "BM"; + /** + * @property {number} + * 点击在控件右下角。 + */ + HitTestResult[HitTestResult["BR"] = 9] = "BR"; + })(HitTestResult = exports.HitTestResult || (exports.HitTestResult = {})); + ; + /** + * @class Widget + * Widget是所有控件的基类。 + */ + var Widget = (function (_super) { + __extends(Widget, _super); + function Widget(type) { + var _this = _super.call(this) || this; + /////////////////////////////////////////// + _this.layoutRect = rect_1.Rect.create(0, 0, 0, 0); + _this.eChangeEvent = Events.ChangeEvent.create(); + _this.ePropChangeEvent = Events.PropChangeEvent.create(); + _this.viewModelChangeFunc = function (evt) { + var viewModel = this._viewModel; + var dataBindingRule = this._dataBindingRule; + if (dataBindingRule && viewModel) { + this.onBindData(viewModel, dataBindingRule); + } + }.bind(_this); + _this.type = type; + return _this; + } + /** + * @method set + * 同时设置多个属性。 + */ + Widget.prototype.set = function (props) { + if (props) { + for (var key in props) { + var value = props[key]; + if (value !== undefined) { + this[key] = value; + } + } + } + return this; + }; + /** + * @method get + * 同时获取多个属性。 + */ + Widget.prototype.get = function (props) { + if (props) { + for (var key in props) { + var value = this[key]; + if (value !== undefined) { + props[key] = value; + } + } + } + return this; + }; + /** + * 把全局的坐标转换成相对于当前控件左上角的坐标。 + * @param {Pointer} p 全局坐标。 + * @return {Pointer} 相对于当前控件左上角的坐标。 + */ + Widget.prototype.toLocalPoint = function (p) { + p.x -= this.x; + p.y -= this.y; + var iter = this.parent; + while (iter) { + p.x -= iter.x; + p.y -= iter.y; + iter = iter.parent; + } + return p; + }; + /** + * 把相对于当前控件左上角的坐标转换成全局坐标。 + * @param {Point} p 相对于当前控件左上角的坐标。 + * @return {Point} 全局坐标。 + */ + Widget.prototype.toGlobalPoint = function (p) { + p.x += this.x; + p.y += this.y; + var iter = this.parent; + while (iter) { + p.x += iter.x; + p.y += iter.y; + iter = iter.parent; + } + return p; + }; + /** + * 把相对于当前控件左上角的坐标转换成屏幕上的坐标。 + * @param {Point} p 相对于当前控件左上角的坐标。 + * @return {Point} 屏幕上的坐标。 + */ + Widget.prototype.toViewPoint = function (p) { + var iter = this; + while (iter) { + p.x += iter.x; + p.y += iter.y; + if (iter.offsetX) { + p.x -= iter.offsetX; + } + if (iter.offsetY) { + p.y -= iter.offsetY; + } + iter = iter.parent; + } + return p; + }; + Widget.prototype.onInit = function () { + this._inited = true; + if (!this.app && this.parent) { + this.app = this.parent.app; + } + }; + Widget.prototype.init = function () { + this.onInit(); + this.children.forEach(function (child) { + child.init(); + }); + return this; + }; + Widget.prototype.onDeinit = function () { + this._inited = false; + }; + Widget.prototype.deinit = function () { + this.children.forEach(function (child) { + child.deinit(); + }); + this.onDeinit(); + }; + Widget.prototype.translatePointerEvent = function (evt) { + evt.localX -= this.x; + evt.localY -= this.y; + }; + Widget.prototype.untranslatePointerEvent = function (evt) { + evt.localX += this.x; + evt.localY += this.y; + }; + Widget.prototype.dispatchPointerDown = function (evt) { + if (!this._enable || !this._sensitive) { + return; + } + this.translatePointerEvent(evt); + var x = evt.localX; + var y = evt.localY; + var hitTestResult = this.selfHitTest(x, y); + if (hitTestResult) { + this.dispatchEvent(evt, true); + this.target = this.findEventTargetChild(x, y); + if (this.target) { + this.target.dispatchPointerDown(evt); + } + if (this.onpointerdown) { + this.onpointerdown(evt); + } + this.dispatchEvent(evt, false); + this.state = WidgetState.ACTIVE; + } + else { + if (this.onpointerdown) { + this.onpointerdown(evt); + } + this.state = WidgetState.NORMAL; + } + this.untranslatePointerEvent(evt); + this.hitTestResult = hitTestResult; + }; + Widget.prototype.dispatchPointerMoveToTarget = function (evt) { + this.dispatchEvent(evt, true); + if (this.target) { + this.target.dispatchPointerMove(evt); + } + if (this.onpointermove) { + this.onpointermove(evt); + } + this.dispatchEvent(evt, false); + }; + Widget.prototype.dispatchPointerLeave = function (evt) { + if (this.state === WidgetState.OVER || this.state === WidgetState.ACTIVE) { + var e = Events.PointerEvent.create(Events.POINTER_LEAVE, evt); + this.dispatchEvent(e, false); + this.state = WidgetState.NORMAL; + e.dispose(); + } + if (this.target) { + this.target.dispatchPointerLeave(evt); + } + if (this._lastOverWidget) { + this._lastOverWidget.dispatchPointerLeave(evt); + this._lastOverWidget = null; + } + }; + Widget.prototype.dispatchPointerEnter = function (evt) { + var e = Events.PointerEvent.create(Events.POINTER_ENTER, evt); + this.dispatchEvent(e, false); + e.dispose(); + }; + Widget.prototype.dispatchPointerMoveToUnder = function (evt) { + var x = evt.localX; + var y = evt.localY; + var hitTestResult = this.selfHitTest(x, y); + if (hitTestResult) { + this.dispatchEvent(evt, true); + var _lastOverWidget = this._lastOverWidget; + var overWidget = this.findEventTargetChild(x, y); + if (_lastOverWidget !== overWidget) { + var e = null; + if (_lastOverWidget) { + _lastOverWidget.dispatchPointerMove(evt); + _lastOverWidget.dispatchPointerLeave(evt); + } + if (overWidget) { + overWidget.dispatchPointerEnter(evt); + } + this._lastOverWidget = overWidget; + } + if (overWidget) { + overWidget.dispatchPointerMove(evt); + } + if (this.onpointermove) { + this.onpointermove(evt); + } + this.dispatchEvent(evt, false); + if (evt.pointerDown) { + this.state = WidgetState.ACTIVE; + } + else { + this.state = WidgetState.OVER; + } + } + else { + this.dispatchEvent(evt, true); + if (this.onpointermove) { + this.onpointermove(evt); + } + this.dispatchEvent(evt, false); + this.state = WidgetState.NORMAL; + } + }; + Widget.prototype.dispatchPointerMove = function (evt) { + if (!this._enable || !this._sensitive) { + return; + } + this.translatePointerEvent(evt); + if (evt.pointerDown) { + this.dispatchPointerMoveToTarget(evt); + } + this.dispatchPointerMoveToUnder(evt); + this.untranslatePointerEvent(evt); + }; + Widget.prototype.dispatchPointerUp = function (evt) { + if (!this._enable || !this._sensitive) { + return; + } + this.translatePointerEvent(evt); + this.dispatchEvent(evt, true); + if (this._lastOverWidget && this.target !== this._lastOverWidget) { + this._lastOverWidget.dispatchPointerUp(evt); + } + if (this.target) { + this.target.dispatchPointerUp(evt); + } + if (this.onpointerup) { + this.onpointerup(evt); + } + this.dispatchEvent(evt, false); + this.state = WidgetState.NORMAL; + this.untranslatePointerEvent(evt); + }; + Widget.prototype.dispatchClick = function (evt) { + if (!this._enable || !this._sensitive) { + return; + } + this.translatePointerEvent(evt); + var x = evt.localX; + var y = evt.localY; + var hitTestResult = this.selfHitTest(x, y); + var isClick = Math.abs(evt.dx) < 5 && Math.abs(evt.dy) < 5; + if (isClick || hitTestResult) { + this.dispatchEvent(evt, true); + if (this.target) { + this.target.dispatchClick(evt); + } + if (this.onclick) { + this.onclick(evt); + } + this.dispatchEvent(evt, false); + } + this.untranslatePointerEvent(evt); + }; + Widget.prototype.dispatchContextMenu = function (evt) { + if (!this._enable || !this._sensitive) { + return; + } + this.dispatchEvent(evt, true); + if (this.target) { + this.target.dispatchContextMenu(evt); + } + if (this.oncontextmenu) { + this.oncontextmenu(evt); + } + this.dispatchEvent(evt, false); + }; + Widget.prototype.dispatchDblClick = function (evt) { + if (!this._enable || !this._sensitive) { + return; + } + this.dispatchEvent(evt, true); + if (this.target) { + this.target.dispatchDblClick(evt); + } + if (this.ondblclick) { + this.ondblclick(evt); + } + this.dispatchEvent(evt, false); + }; + Widget.prototype.dispatchKeyDown = function (evt) { + if (!this._enable || !this._sensitive) { + return; + } + this.dispatchEvent(evt, true); + if (this.target) { + this.target.dispatchKeyDown(evt); + } + if (this.onkeydown) { + this.onkeydown(evt); + } + this.dispatchEvent(evt, false); + }; + Widget.prototype.dispatchKeyUp = function (evt) { + if (!this._enable || !this._sensitive) { + return; + } + this.dispatchEvent(evt, true); + if (this.target) { + this.target.dispatchKeyUp(evt); + } + if (this.onkeyup) { + this.onkeyup(evt); + } + this.dispatchEvent(evt, false); + }; + Widget.prototype.dispatchWheel = function (evt) { + if (!this._enable || !this._sensitive) { + return; + } + this.dispatchEvent(evt, true); + if (this.target) { + this.target.dispatchWheel(evt); + } + if (this.onwheel) { + this.onwheel(evt); + } + this.dispatchEvent(evt, false); + }; + Widget.prototype.applyTransform = function (ctx) { + var e = Events.ApplyTransformEvent.get(); + this.dispatchEvent(e.reset(Events.BEFORE_APPLY_TRANSFORM, ctx, this)); + if (!this._canvas) { + ctx.translate(this._x, this._y); + } + var px = this._pivotX * this._w; + var py = this._pivotY * this._h; + if (this._rotation || this._scaleX !== 1 || this._scaleY !== 1) { + ctx.translate(px, py); + ctx.rotate(this._rotation); + ctx.scale(this._scaleX, this._scaleY); + ctx.translate(-px, -py); + } + this.dispatchEvent(e.reset(Events.AFTER_APPLY_TRANSFORM, ctx, this)); + return this; + }; + Widget.prototype.findEventTargetChild = function (x, y) { + var arr = this._children; + var n = arr.length; + for (var i = n - 1; i >= 0; i--) { + var iter = arr[i]; + if (iter._enable && iter._sensitive) { + if (rect_1.Rect.rect.init(iter.x, iter.y, iter.w, iter.h).containsPoint(x, y)) { + return iter; + } + } + } + return null; + }; + /////////////////////////////////////////// + Widget.prototype.animate = function () { + var tween = new TWEEN.Tween(this); + this.requestRedraw(); + return tween; + }; + /** + * @method scaleTo + * 设置控件的缩放比例到指定的值。如果duration > 0则启用动画,并返回TWEEN.Tween,否则返回null。 + * @param {number} sx 宽度缩放比例。 + * @param {number} sy 高度缩放比例。 + * @param {number} duration 动画时间。 + * @return {TWEEN.Tween} + */ + Widget.prototype.scaleTo = function (sx, sy, duration) { + this.requestRedraw(); + if (duration > 0) { + var tween = new TWEEN.Tween(this); + tween.to({ scaleX: sx, scaleY: sy }, duration).start(); + return tween; + } + else { + this.scaleX = sx; + this.scaleY = sy; + return null; + } + }; + /** + * @method opacityTo + * 设置控件的透明度到指定的值。如果duration > 0则启用动画,并返回TWEEN.Tween,否则返回null。 + * @param {number} opacity 不透明度[0-1] + * @param {number} duration 动画时间。 + * @return {TWEEN.Tween} + */ + Widget.prototype.opacityTo = function (opacity, duration) { + this.requestRedraw(); + if (duration > 0) { + var tween = new TWEEN.Tween(this); + tween.to({ opacity: opacity }, duration).start(); + return tween; } - if (bindThis) { - return function(emit, value) { - valOrFunc.call(bindThis, emit, value); - } + else { + this.opacity = opacity; + ; + return null; } - return valOrFunc; - } - - function Per(valOrFunc, bindThis) { - this.forEach = toFunc(valOrFunc, bindThis); - } - - function blank(emit, value) { - emit(value); - } - - function create(valOrFunc, bindThis) { - if (arguments.length === 0) { - return new Per(blank); + }; + /** + * @method rotateTo + * 设置控件的旋转角度到指定的值。如果duration > 0则启用动画,并返回TWEEN.Tween,否则返回null。 + * @param {number} rotation 旋转角度,单位为弧度。 + * @param {number} duration 动画时间。 + * @return {TWEEN.Tween} + */ + Widget.prototype.rotateTo = function (rotation, duration) { + this.requestRedraw(); + if (duration > 0) { + var tween = new TWEEN.Tween(this); + tween.to({ rotation: rotation }, duration).start(); + return tween; } - if (valOrFunc && valOrFunc instanceof Per) { - return valOrFunc; + else { + this.rotation = rotation; + return null; } - return new Per(valOrFunc, bindThis) - } - - Per.prototype.per = function(valOrFunc, bindThis) { - var first = this.forEach; - var second = toFunc(valOrFunc && valOrFunc.forEach || valOrFunc, bindThis); - return create(function(emit, value) { - return first(function(firstVal) { - return second(emit, firstVal); - }, value); + }; + /** + * @method moveTo + * 设置控件的位置到指定的值。如果duration > 0则启用动画,并返回TWEEN.Tween,否则返回null。 + * @param {number} x X 坐标。 + * @param {number} y Y 坐标。 + * @param {number} duration 动画时间。 + * @return {TWEEN.Tween} + */ + Widget.prototype.moveTo = function (x, y, duration) { + this.requestRedraw(); + if (duration > 0) { + var tween = new TWEEN.Tween(this); + tween.to({ x: x, y: y }, duration).start(); + return tween; + } + else { + this.x = x; + this.y = y; + return null; + } + }; + /** + * @method moveResizeTo + * 设置控件的位置和大小到指定的值。如果duration > 0则启用动画,并返回TWEEN.Tween,否则返回null。 + * @param {number} x X 坐标。 + * @param {number} y Y 坐标。 + * @param {number} w 宽度。 + * @param {number} h 高度。 + * @param {number} duration 动画时间。 + * @return {TWEEN.Tween} + */ + Widget.prototype.moveResizeTo = function (x, y, w, h, duration) { + if (duration > 0) { + var tween = new TWEEN.Tween(this); + tween.to({ x: x, y: y, w: w, h: h }, duration).start(); + return tween; + } + else { + this.x = x; + this.y = y; + this.w = w; + this.h = h; + return null; + } + }; + /** + * @method resizeTo + * 设置控件的大小到指定的值。如果duration > 0则启用动画,并返回TWEEN.Tween,否则返回null。 + * @param {number} w 宽度。 + * @param {number} h 高度。 + * @param {number} duration 动画时间。 + * @return {TWEEN.Tween} + */ + Widget.prototype.resizeTo = function (w, h, duration) { + if (duration > 0) { + var tween = new TWEEN.Tween(this); + tween.to({ w: w, h: h }, duration).start(); + return tween; + } + else { + this.w = w; + this.h = h; + return null; + } + }; + Widget.prototype.getLayoutRect = function () { + return this.layoutRect.init(this.leftPadding, this.topPadding, this.w - this.leftPadding - this.rightPadding, this.h - this.topPadding - this.bottomPadding); + }; + /** + * 根据当前的childrenLayouter重新布局子控件。 + */ + Widget.prototype.relayoutChildren = function () { + this.requestRedraw(); + if (this.children.length > 0 && this.childrenLayouter && ((this.w > 0 && this.h > 0) || this._inited)) { + var ret = this.childrenLayouter.layoutChildren(this, this.children, this.getLayoutRect()); + return this.layoutRect.copy(ret); + } + return this.getLayoutRect(); + }; + /** + * 请求重新布局当前控件。 + */ + Widget.prototype.requestRelayout = function () { + if (this.parent) { + this.parent.relayoutChildren(); + } + return this; + }; + /* + * 根据当前的childrenLayouter创建子控件的布局参数。 + */ + Widget.prototype.createChildLayoutParam = function (options) { + var layouter = this.childrenLayouter; + return layouter ? layouter.createParam(options) : null; + }; + /** + * 启用指定的childrenLayouter。 + */ + Widget.prototype.useChildrenLayouter = function (type, options) { + this.childrenLayouter = layouter_1.LayouterFactory.create(type, options); + return this; + }; + Object.defineProperty(Widget.prototype, "childrenLayouter", { + get: function () { + return this._childrenLayouter; + }, + /** + * @property {Layouter} childrenLayouter + * 用于子控件布局的Layouter。 + */ + set: function (layouter) { + if (typeof layouter === "string") { + this._childrenLayouter = layouter_1.LayouterFactory.create(layouter, null); + } + else { + this._childrenLayouter = layouter; + } + if (this.children.length) { + this.relayoutChildren(); + } + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Widget.prototype, "layoutParam", { + get: function () { + return this._layoutParam; + }, + /** + * @property {Object} layoutParam + * 布局参数是父控件在布局当前控件时使用的参数。 + */ + set: function (param) { + this._layoutParam = param; + if (param) { + param.widget = this; + } + }, + enumerable: true, + configurable: true + }); + Widget.prototype.getParentByType = function (type) { + var iter = this.parent; + while (iter && iter.type !== type) { + iter = iter.parent; + } + return iter; + }; + /////////////////////////////////////////// + /** + * @method indexOfChild + * 获取指定子控件的位置序数。 + * @param {Widget} child 子控件 + * @return {number} 位置序数。 + */ + Widget.prototype.indexOfChild = function (child) { + return this.children.indexOf(child); + }; + /** + * @method findChild + * 查找满足指定条件的子控件。 + * @param {Function} func 比较函数。 + * @return {Widget} 如果找到,返回该子控件,否则返回null。 + */ + Widget.prototype.findChild = function (func) { + var i = 0; + var arr = this._children; + var n = arr.length; + for (var i = 0; i < n; i++) { + var iter = arr[i]; + if (func(iter)) { + return iter; + } + } + return null; + }; + /** + * @method findChildByName + * 按名称查找子控件。 + * @param {string} name 子控件的名称。 + * @return {Widget} 如果找到,返回该子控件,否则返回null。 + */ + Widget.prototype.findChildByName = function (name) { + var ret = this.findChild(function (child) { + return child.name === name; }); + return ret; }; - - function lambda(expression) { - return typeof expression === 'string' - ? new Function('x', 'return ' + expression) - : expression; - } - - Per.prototype.map = function(mapFunc) { - mapFunc = lambda(mapFunc); - return this.per(function(emit, value) { - return emit(mapFunc(value)); + /** + * @method findChildByID + * 按ID查找子控件。 + * @param {string} id 子控件的ID。 + * @return {Widget} 如果找到,返回该子控件,否则返回null。 + */ + Widget.prototype.findChildByID = function (id) { + var ret = this.findChild(function (child) { + return child.id === id; }); + return ret; }; - - Per.prototype.filter = function(predicate) { - predicate = lambda(predicate); - return this.per(function(emit, value) { - if (predicate(value)) { - return emit(value); + Widget.prototype.drawColorBackground = function (ctx, style) { + var roundType = 0; + var roundTypeName = style.roundType; + if (roundTypeName) { + if (roundTypeName === "top") { + roundType = graphics_1.RoundType.TL | graphics_1.RoundType.TR; + } + else if (roundTypeName === "bottom") { + roundType = graphics_1.RoundType.BL | graphics_1.RoundType.BR; + } + else if (roundTypeName === "left") { + roundType = graphics_1.RoundType.BL | graphics_1.RoundType.TL; + } + else if (roundTypeName === "right") { + roundType = graphics_1.RoundType.TR | graphics_1.RoundType.BR; + } + } + graphics_1.Graphics.drawRoundRect(ctx, style.backGroundColor, style.lineColor, style.lineWidth, 0, 0, this.w, this.h, style.roundRadius, roundType); + return this; + }; + Widget.prototype.drawBackground = function (ctx, style) { + if (style.backGroundImage) { + style.backGroundImage.draw(ctx, style.backGroundImageDrawType, 0, 0, this.w, this.h); + } + else if (style.backGroundColor || (style.lineColor && style.lineWidth)) { + this.drawColorBackground(ctx, style); + } + return this; + }; + /** + * @method getLocaleText + * 获取本地化后的文本。 + */ + Widget.prototype.getLocaleText = function () { + return string_table_1.StringTable.tr(this.text); + }; + Widget.prototype.getFgImageRect = function (style) { + return rect_1.Rect.rect.init(this.leftPadding, this.topPadding, this.clientW, this.clientH); + }; + Widget.prototype.drawImage = function (ctx, style) { + if (style.foreGroundImage) { + var r = this.getFgImageRect(style); + style.foreGroundImage.draw(ctx, image_tile_1.ImageDrawType.ICON, r.x, r.y, r.w, r.h); + } + return this; + }; + Widget.prototype.getTextRect = function (style) { + return rect_1.Rect.rect.init(this.leftPadding, this.topPadding, this.clientW, this.clientH); + }; + Widget.prototype.drawText = function (ctx, style) { + var text = this.getLocaleText(); + if (text && style.textColor) { + graphics_1.Graphics.drawTextSL(ctx, text, style, this.getTextRect(style)); + } + return this; + }; + Widget.prototype.drawChildren = function (ctx) { + this._children.forEach(function (child) { + if (child.visible) { + child.draw(ctx); } }); + return this; }; - - Per.prototype.concat = function(second, secondThis) { - if (second instanceof Per) { - second = second.forEach; - } else { - second = toFunc(second, secondThis); + Widget.prototype.drawTips = function (ctx, style) { + return this; + }; + Widget.prototype.computeDirtyRectSelf = function (ctx) { + if (this._dirty) { + ctx.addRect(-5, -5, this.w + 10, this.h + 10); } - var first = this.forEach; - return create(function(emit, value) { - first(emit, value); - second(emit, value); + }; + Widget.prototype.computeDirtyRect = function (ctx) { + ctx.save(); + this.applyTransform(ctx); + this.computeDirtyRectSelf(ctx); + this.computeChildrenDirtyRect(ctx); + ctx.restore(); + }; + Widget.prototype.computeChildrenDirtyRect = function (ctx) { + this.children.forEach(function (child) { + child.computeDirtyRect(ctx); }); }; - - Per.prototype.skip = function(count) { - return this.per(function(emit, value) { - if (count > 0) { - count--; - return false; + Widget.prototype.doDraw = function (ctx, style) { + if (style) { + this.drawBackground(ctx, style) + .drawImage(ctx, style) + .drawChildren(ctx) + .drawText(ctx, style) + .drawTips(ctx, style); + } + else { + this.drawChildren(ctx); + } + }; + Widget.prototype.draw = function (ctx) { + this._dirty = false; + var style = this.getStyle(); + ctx.save(); + var opacity = this._opacity; + if (opacity !== 1) { + ctx.globalAlpha *= opacity; + } + this.applyTransform(ctx); + var drawEvent = Events.DrawEvent.get(); + this.dispatchEvent(drawEvent.reset(Events.BEFORE_DRAW, ctx, this)); + this.doDraw(ctx, style); + this.dispatchEvent(drawEvent.reset(Events.AFTER_DRAW, ctx, this)); + ctx.restore(); + return; + }; + Widget.prototype.stateToString = function (state) { + return WidgetState[state].toLowerCase(); + }; + Object.defineProperty(Widget.prototype, "styleType", { + get: function () { + return this._styleType; + }, + /** + * @property {string} styleType + * 用于从主题中获取style数据。 + */ + set: function (styleType) { + this._styleType = styleType; + }, + enumerable: true, + configurable: true + }); + /** + * @method setStyle + * 设置控件的Style。 + * @param {WidgetState} state 状态。 + * @param {Style} style 控件的Style。 + * return {Widget} 控件本身。 + */ + Widget.prototype.setStyle = function (state, style) { + if (!this._styles) { + this._styles = {}; + } + var stateName = this.stateToString(state); + this._styles[stateName] = style; + return this; + }; + Widget.prototype.getStyleType = function () { + return this._styleType || this.type; + }; + Widget.prototype.getStyleOfState = function (state) { + var style = null; + var tm = this._themeManager; + var stateName = this.stateToString(state); + if (this._styles) { + style = this._styles[stateName]; + } + else if (tm) { + var styleType = this.getStyleType(); + style = tm.get(styleType, stateName); + } + return style; + }; + Widget.prototype.getStateForStyle = function () { + return this.enable ? this._state : WidgetState.DISABLE; + }; + Widget.prototype.getStyle = function () { + var state = this.getStateForStyle(); + var style = this.getStyleOfState(state); + if (!style) { + style = this.getStyleOfState(WidgetState.NORMAL); + } + return style; + }; + Widget.prototype.sortChildren = function () { + var arr = this._children; + utils_1.stableSort(arr, function (a, b) { + return a.z - b.z; + }); + return this; + }; + /** + * @method removeAllChildren + * 移出并销毁所有的子控件。 + * return {Widget} 控件本身。 + */ + Widget.prototype.removeAllChildren = function () { + this.children.forEach(function (child) { + child.deinit(); + child.dispose(); + }); + this.target = null; + this.children.length = 0; + this._lastOverWidget = null; + return this; + }; + Widget.prototype.onRemoveChild = function (child) { + }; + /** + * @method removeChild + * 移出子控件。批量删除时,请使用快速模式,并在完成时调用relayoutChildren。 + * @param {Widget} child 子控件。 + * @param {boolean} fastMode 快速模式下,不重新布局子控件。 + * @param {boolean} destroy 是否销毁子控件。 + * return {Widget} 控件本身。 + */ + Widget.prototype.removeChild = function (child, fastMode, destroy) { + var arr = this._children; + var index = arr.indexOf(child); + if (index >= 0) { + arr.splice(index, 1); + if (!fastMode) { + this.relayoutChildren(); + } + } + this.onRemoveChild(child); + if (destroy) { + child.deinit(); + child.dispose(); + } + return this; + }; + Widget.prototype.onAddChild = function (child) { + }; + /** + * @method addChild + * 增加子控件。批量增加时,请使用快速模式,并在完成时调用relayoutChildren。 + * @param {Widget} child 子控件。 + * @param {boolean} fastMode 快速模式下,不重新布局子控件。 + * return {Widget} 控件本身。 + */ + Widget.prototype.addChild = function (child, fastMode) { + var arr = this._children; + arr.push(child); + child.parent = this; + child.app = this.app; + if (this._inited) { + child.init(); + } + if (!fastMode) { + this.sortChildren(); + this.relayoutChildren(); + } + this.onAddChild(child); + return this; + }; + /** + * @method dispose + * 销毁控件及其全部子控件。 + */ + Widget.prototype.dispose = function () { + this.dispatchEvent({ type: Events.DISPOSE }); + if (this._canvas) { + this._canvas.dispose(); + this._canvas = null; + } + this.removeAllListeners(); + this._children.forEach(function (child) { + child.dispose(); + }); + this._app = null; + this._parent = null; + this._children = []; + this._layoutParam = null; + this._childrenLayouter = null; + this._viewModel = null; + this._dataBindingRule = null; + this.removeBinding(); + if (this.recycle) { + this.recycle(); + } + }; + /** + * @method requestRedraw + * 请求重绘。 + */ + Widget.prototype.requestRedraw = function () { + var app = this._app; + this._dirty = true; + if (app) { + app.getMainLoop().requestRedraw(); + } + return this; + }; + ////////////////////////////////////////////////// + Widget.prototype.createCanvas = function () { + var _this = this; + var app = this.app; + var density = app.getViewPort().density; + var canvas = canvas_1.Canvas.create(this.x, this.y, this.w, this.h, density); + canvas.ensureCanvas(); + canvas.on(Events.POINTER_DOWN, function (evt) { + _this.dispatchPointerDown(evt); + }); + canvas.on(Events.POINTER_MOVE, function (evt) { + _this.dispatchPointerMove(evt); + }); + canvas.on(Events.POINTER_UP, function (evt) { + _this.dispatchPointerUp(evt); + }); + canvas.on(Events.CLICK, function (evt) { + _this.dispatchClick(evt); + }); + canvas.on(Events.DBLCLICK, function (evt) { + _this.dispatchDblClick(evt); + }); + canvas.on(Events.CONTEXT_MENU, function (evt) { + _this.dispatchContextMenu(evt); + }); + canvas.on(Events.WHEEL, function (evt) { + _this.dispatchWheel(evt); + }); + canvas.on(Events.KEYDOWN, function (evt) { + _this.dispatchKeyDown(evt); + }); + canvas.on(Events.KEYUP, function (evt) { + _this.dispatchKeyUp(evt); + }); + this._canvas = canvas; + var mainLoop = this.app.getMainLoop(); + var dirtyRectContext = dirty_rect_context_1.DirtyRectContext.create(); + var lastDirtyRect = rect_1.Rect.create(0, 0, this.w, this.h); + var debugDirtyRect = app.options.debugDirtyRect; + function drawWithDirtyRect(evt) { + var ctx = canvas.getContext("2d"); + dirtyRectContext.reset(); + this.computeDirtyRect(dirtyRectContext); + var dirtyRect = dirtyRectContext.getRect(); + var r = lastDirtyRect.merge(dirtyRect); + if (r.x < 0) + r.x = 0; + if (r.y < 0) + r.y = 0; + if ((r.x + r.w) > this.w) { + r.w = this.w - r.x; + } + if ((r.y + r.h) > this.h) { + r.h = this.h - r.y; + } + if (r.w > 0 && r.h > 0) { + r.x = r.x >> 0; + r.y = r.y >> 0; + r.w = (r.w + 1) >> 0; + r.h = (r.h + 2) >> 0; + ctx.save(); + ctx.beginPath(); + ctx.clearRect(r.x, r.y, r.w, r.h); + ctx.rect(r.x, r.y, r.w, r.h); + ctx.clip(); + ctx.globalAlpha = 1; + this.draw(ctx); + if (debugDirtyRect) { + ctx.lineWidth = 1; + ctx.strokeStyle = "gold"; + ctx.strokeRect(dirtyRect.x + 1, dirtyRect.y + 1, dirtyRect.w - 2, dirtyRect.h - 2); + } + ctx.restore(); + } + lastDirtyRect.copy(dirtyRect); + } + function drawWithoutDirtyRect(evt) { + var ctx = canvas.getContext("2d"); + ctx.globalAlpha = 1; + this.draw(ctx); + } + var withoutDirtyRect = app.options.withoutDirtyRect; + var draw = withoutDirtyRect ? drawWithoutDirtyRect.bind(this) : drawWithDirtyRect.bind(this); + mainLoop.on(Events.TICK, draw); + this.on(Events.DISPOSE, function (evt) { + mainLoop.off(Events.TICK, draw); + }); + this.on(Events.PROP_CHANGE, function (evt) { + var prop = evt.prop; + var value = evt.newValue; + switch (prop) { + case "x": { + canvas.x = value; + break; + } + case "y": { + canvas.y = value; + break; + } + case "w": { + canvas.w = value; + break; + } + case "h": { + canvas.h = value; + break; + } + case "z": { + canvas.z = value; + break; + } } - return emit(value); }); + return this; + }; + Object.defineProperty(Widget.prototype, "dirty", { + ////////////////////////////////////////////////// + get: function () { + return this._dirty; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Widget.prototype, "x", { + /** + * @property {number} x + * 控件的X坐标。 + */ + get: function () { + return this._x; + }, + set: function (value) { + this.setProp("x", value, true); + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Widget.prototype, "y", { + /** + * @property {number} y + * 控件的Y坐标。 + */ + get: function () { + return this._y; + }, + set: function (value) { + this.setProp("y", value, true); + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Widget.prototype, "z", { + /** + * @property {number} z + * 控件的位置序数。 + */ + get: function () { + return this._z; + }, + set: function (value) { + this.setProp("z", value, true); + if (this._parent) { + this._parent.sortChildren(); + } + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Widget.prototype, "desireWidth", { + /** + * @property {number} w + * 控件的宽度。 + */ + get: function () { + return this._w; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Widget.prototype, "w", { + get: function () { + return this._w; + }, + set: function (value) { + this.setProp("w", value, true); + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Widget.prototype, "width", { + get: function () { + return this._w; + }, + set: function (value) { + this.setProp("w", value, true); + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Widget.prototype, "clientW", { + get: function () { + return this._w - this.leftPadding - this.rightPadding; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Widget.prototype, "clientH", { + get: function () { + return this._h - this.topPadding - this.bottomPadding; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Widget.prototype, "height", { + /** + * @property {number} h + * 控件的高度。 + */ + get: function () { + return this._h; + }, + set: function (value) { + this.setProp("h", value, true); + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Widget.prototype, "h", { + get: function () { + return this._h; + }, + set: function (value) { + this.setProp("h", value, true); + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Widget.prototype, "state", { + /** + * @property {WidgetState} state + * 控件的状态。 + */ + get: function () { + return this._state; + }, + set: function (value) { + if (this._state !== value) { + this.setProp("state", value, true); + } + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Widget.prototype, "value", { + /** + * @property {any} value + * 控件的值。不同的控件,值的定义不一样。 + */ + get: function () { + return this._value; + }, + set: function (value) { + this.setValue(value, false, false); + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Widget.prototype, "selected", { + /** + * @property {boolean} selected + * 控件是否被选中。 + */ + get: function () { + return this._selected; + }, + set: function (value) { + this.setProp("selected", value, true); + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Widget.prototype, "isEnableFunc", { + get: function () { + return this._isEnableFunc; + }, + set: function (value) { + this._isEnableFunc = value; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Widget.prototype, "enable", { + /** + * @property {boolean} enable + * 控件是否处于enable状态。 + */ + get: function () { + if (this.isEnableFunc) { + return this.isEnableFunc(); + } + return this._enable; + }, + set: function (value) { + this.setProp("enable", value, true); + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Widget.prototype, "inputable", { + /** + * @property {boolean} inputable + * [只读] 控件是否可输入,也就是是否可以通过界面修改它的值。 + */ + get: function () { + return false; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Widget.prototype, "visible", { + /** + * @property {boolean} visible + * 控件是否可见。 + */ + get: function () { + return this._visible; + }, + set: function (value) { + var oldValue = this._visible; + if (this.value !== oldValue) { + this.setVisible(value); + } + }, + enumerable: true, + configurable: true + }); + Widget.prototype.setVisible = function (value) { + this.setProp("visible", value, true); + this.dispatchEvent({ type: value ? Events.SHOW : Events.HIDE }); + this.requestRedraw(); + }; + Object.defineProperty(Widget.prototype, "opacity", { + /** + * @property {number} opacity + * 控件的不透明度(0-1)。 + */ + get: function () { + return this._opacity; + }, + set: function (value) { + this.setProp("opacity", value, true); + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Widget.prototype, "scaleX", { + /** + * @property {number} scaleX + * 控件的宽度缩放比例。 + */ + get: function () { + return this._scaleX; + }, + set: function (value) { + this.setProp("scaleX", value, true); + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Widget.prototype, "scaleY", { + /** + * @property {number} scaleY + * 控件的高度缩放比例。 + */ + get: function () { + return this._scaleY; + }, + set: function (value) { + this.setProp("scaleY", value, true); + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Widget.prototype, "rotation", { + /** + * @property {number} rotation + * 控件的旋转角度。 + */ + get: function () { + return this._rotation; + }, + set: function (value) { + this.setProp("rotation", value, true); + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Widget.prototype, "sensitive", { + /** + * @property {number} sensitive + * 控件是否接受用户事件。 + */ + get: function () { + return this._sensitive; + }, + set: function (value) { + this.setProp("sensitive", value, true); + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Widget.prototype, "pivotX", { + /** + * @property {number} pivotX + * 控件的X轴点,也就旋转点的X坐标。 + */ + get: function () { + return this._pivotX; + }, + set: function (value) { + this.setProp("pivotX", value, true); + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Widget.prototype, "pivotY", { + /** + * @property {number} pivotY + * 控件的Y轴点,也就旋转点的Y坐标。 + */ + get: function () { + return this._pivotY; + }, + set: function (value) { + this.setProp("pivotY", value, true); + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Widget.prototype, "tips", { + /** + * @property {string} tips + * 控件的提示文本。 + */ + get: function () { + return this._tips; + }, + set: function (value) { + this.setProp("tips", value, true); + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Widget.prototype, "text", { + /** + * @property {string} text + * 控件的文本。 + */ + get: function () { + return this._text; + }, + set: function (value) { + this.setProp("text", (value || value === 0) ? value.toString() : "", true); + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Widget.prototype, "name", { + /** + * @property {string} name + * 控件的名称。 + */ + get: function () { + return this._name; + }, + set: function (value) { + this.setProp("name", value, true); + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Widget.prototype, "type", { + /** + * @property {string} type + * 控件的类型。 + */ + get: function () { + return this._type; + }, + set: function (value) { + this.setProp("type", value, true); + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Widget.prototype, "id", { + /** + * @property {string} id + * 控件的ID。 + */ + get: function () { + return this._id; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Widget.prototype, "userData", { + /** + * @property {any} userData + * 控件的应用数据。 + */ + get: function () { + return this._userData; + }, + set: function (value) { + this._userData = value; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Widget.prototype, "target", { + get: function () { + return this._target; + }, + set: function (value) { + this._target = value; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Widget.prototype, "hitTestResult", { + get: function () { + return this._hitTestResult; + }, + set: function (value) { + this._hitTestResult = value; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Widget.prototype, "parent", { + /** + * @property {Widget} parent + * 控件的父控件。 + */ + get: function () { + return this._parent; + }, + set: function (value) { + this._parent = value; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Widget.prototype, "app", { + /** + * @property {IApplication} app + * 应用程序。 + */ + get: function () { + return this._app; + }, + set: function (app) { + this._app = app; + if (app) { + this._mainLoop = app.getMainLoop(); + this._themeManager = app.getThemeManager(); + } + this.children.forEach(function (child) { + child.app = app; + }); + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Widget.prototype, "win", { + /** + * @property {Window} win + * 控件所在的窗口。 + */ + get: function () { + for (var iter = this; iter !== null; iter = iter._parent) { + if (iter._isWindow) { + return iter; + } + } + return null; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Widget.prototype, "children", { + /** + * @property {Array} children + * 控件的全部子控件。 + */ + get: function () { + return this._children; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Widget.prototype, "canvas", { + get: function () { + return this._canvas; + }, + enumerable: true, + configurable: true + }); + Widget.prototype.isWindow = function () { + return this._isWindow; + }; + Object.defineProperty(Widget.prototype, "leftPadding", { + /** + * @property {number} leftPadding + * 控件的左边界。 + */ + get: function () { + return this._lp; + }, + set: function (value) { + this.setProp("lp", value, true); + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Widget.prototype, "rightPadding", { + /** + * @property {number} rightPadding + * 控件的右边界。 + */ + get: function () { + return this._rp; + }, + set: function (value) { + this.setProp("rp", value, true); + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Widget.prototype, "topPadding", { + /** + * @property {number} topPadding + * 控件的上边界。 + */ + get: function () { + return this._tp; + }, + set: function (value) { + this.setProp("tp", value, true); + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Widget.prototype, "bottomPadding", { + /** + * @property {number} bottomPadding + * 控件的下边界。 + */ + get: function () { + return this._bp; + }, + set: function (value) { + this.setProp("bp", value, true); + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Widget.prototype, "padding", { + /** + * @property {number} padding + * 控件的边界。 + */ + get: function () { + return this._tp; + }, + set: function (value) { + this.setProp("lp", value, true); + this.setProp("tp", value, true); + this.setProp("rp", value, true); + this.setProp("bp", value, true); + }, + enumerable: true, + configurable: true + }); + Widget.prototype.setProp = function (prop, newValue, notify) { + var propName = "_" + prop; + var oldValue = this[propName]; + if (oldValue !== newValue) { + this[propName] = newValue; + this.requestRedraw(); + if (notify) { + var evt = this.ePropChangeEvent; + evt.init(Events.PROP_CHANGE, { prop: prop, oldValue: oldValue, newValue: newValue }); + this.dispatchEvent(evt); + } + } + return this; + }; + Widget.prototype.setText = function (text, notify) { + return this.setProp("text", text, notify); + }; + /** + * @method useBehavior + * 启用指定名称的Behavior + * @param {string} name Behavior的名称。 + * @param {any} options 选项。 + * @return {Behavior} + */ + Widget.prototype.useBehavior = function (name, options) { + var behavior; + if (!this._behaviors[name]) { + behavior = behavior_1.BehaviorFactory.create(name, this, options); + this._behaviors[name] = behavior; + } + else { + behavior = this._behaviors[name]; + behavior.setOptions(options); + } + return behavior; + }; + Widget.prototype.notifyChange = function (oldValue) { + this.dispatchEvent(this.eChangeEvent.init(Events.CHANGE, { newValue: this.value, oldValue: oldValue })); + }; + Widget.prototype.setValue = function (value, notify, exclude) { + var _this = this; + var oldValue = this.value; + if (exclude) { + var type = this.type; + if (this.parent && value) { + var arr = this.parent.children; + arr.forEach(function (child) { + if (child !== _this && child.type === type) { + if (child.value) { + child.setProp("value", false, true); + } + } + }); + } + this.setProp("value", true, notify); + } + else { + this.setProp("value", value, notify); + } + if (notify) { + this.notifyChange(oldValue); + } + }; + Widget.prototype.onReset = function () { + }; + Widget.prototype.onCreated = function () { + }; + Widget.prototype.getDefProps = function () { + return Widget.defProps; + }; + Widget.prototype.reset = function (type, options) { + var defProps = this.getDefProps(); + for (var key in defProps) { + this[key] = defProps[key]; + } + this._dirty = true; + this._type = type; + this._app = null; + this._children = []; + this._parent = null; + this._canvas = null; + this._styles = null; + this._target = null; + this._mainLoop = null; + this._userData = null; + this._themeManager = null; + this._lastOverWidget = null; + this._id = Date.now() + "." + Widget.ID++; + ; + this.onclick = null; + this.oncontextmenu = null; + this.onpointerdown = null; + this.onpointermove = null; + this.onpointerup = null; + this.onwheel = null; + this.onkeydown = null; + this.onkeyup = null; + this._behaviors = {}; + this._viewModel = null; + this._dataBindingRule = null; + this.onReset(); + this.set(options); + this.onCreated(); + return this; + }; + Widget.prototype.onFromJson = function (json) { + }; + /** + * @method fromJson + * 用JSON数据初始化当前控件。 + * @param {any} json 数据。 + */ + Widget.prototype.fromJson = function (json) { + var _this = this; + var defProps = this.getDefProps(); + for (var key in defProps) { + var value = json[key]; + if (value === undefined) { + value = defProps[key]; + } + this[key] = value; + } + var styles = json.styles; + if (styles) { + this._styles = {}; + for (var key in styles) { + var style = styles[key]; + json._styles[key] = style_1.Style.create(style); + } + } + var childrenLayouter = json.childrenLayouter; + if (childrenLayouter) { + this.childrenLayouter = layouter_1.LayouterFactory.create(childrenLayouter.type, childrenLayouter); + } + var layoutParam = json.layoutParam; + if (layoutParam) { + this.layoutParam = layouter_1.LayouterParamFactory.create(layoutParam.type, layoutParam); + } + this._children.length = 0; + if (json.children) { + json.children.forEach(function (childJson) { + var child = widget_factory_1.WidgetFactory.create(childJson.type, { parent: _this, app: _this.app }); + child.fromJson(childJson); + _this._children.push(child); + }); + } + if (json.dataBindingRule) { + this._dataBindingRule = binding_rule_2.BindingRule.createFromJson(json.dataBindingRule); + } + if (json.behaviors) { + this.behaviorsFromJson(json.behaviors); + } + this.onFromJson(json); + return this; + }; + /** + * @method clone + * CLONE当前控件。 + * @return {Widget} 新对象。 + */ + Widget.prototype.clone = function () { + var json = this.toJson(); + var widget = widget_factory_1.WidgetFactory.createWithJson(json); + return widget; + }; + Widget.prototype.onToJson = function (json) { + }; + Widget.prototype.behaviorsToJson = function () { + var json = {}; + var behaviors = this._behaviors; + if (behaviors) { + for (var key in behaviors) { + var value = behaviors[key]; + json[key] = value.toJson(); + } + } + return json; + }; + Widget.prototype.behaviorsFromJson = function (json) { + var behaviors = this._behaviors; + if (behaviors) { + for (var key in behaviors) { + var value = behaviors[key]; + value.dispose(); + } + } + if (json) { + for (var key in json) { + this.useBehavior(key, json.options); + } + } + return; + }; + /** + * @method toJson + * 序列化当前的控件到JSON数据。 + * @return {any} JSON数据。 + */ + Widget.prototype.toJson = function () { + var json = {}; + json.type = this._type; + var defProps = this.getDefProps(); + for (var key in defProps) { + var value = this[key]; + if (value !== defProps[key]) { + json[key] = value; + } + } + var styles = this._styles; + if (styles) { + json.styles = {}; + for (var key in styles) { + var style = styles[key]; + json.styles[key] = style.toJson(); + } + } + if (this.childrenLayouter) { + json.childrenLayouter = this.childrenLayouter.toJson(); + } + if (this.layoutParam) { + json.layoutParam = this.layoutParam.toJson(); + } + if (this.children.length) { + json.children = []; + this.children.forEach(function (child) { + json.children.push(child.toJson()); + }); + } + if (this._dataBindingRule) { + json.dataBindingRule = this._dataBindingRule.toJson(); + } + if (this._behaviors) { + json.behaviors = this.behaviorsToJson(); + } + this.onToJson(json); + return json; + }; + Object.defineProperty(Widget.prototype, "templateItem", { + get: function () { + return this._templateItem; + }, + /** + * @property {Widget} templateItem + * 模板项。用于在数据绑定时,自动生成子控件的模板。 + */ + set: function (value) { + this._templateItem = value; + this._templateItemJson = value ? value.toJson() : null; + }, + enumerable: true, + configurable: true + }); + Widget.prototype.addChildWithTemplate = function (fastMode) { + var child = null; + var json = this._templateItemJson; + if (json) { + child = widget_factory_1.WidgetFactory.createWithJson(json); + this.addChild(child, fastMode); + } + return child; + }; + //////////////////////////////////////////// + //绑定单个属性,子控件可以重载本函数去支持其它属性。 + Widget.prototype.onBindProp = function (prop, value) { + this[prop] = value; }; - - Per.prototype.take = function(count) { - return this.per(function(emit, value) { - if (count <= 0) { - return true; - } - count--; - return emit(value); + Object.defineProperty(Widget.prototype, "dataBindingRule", { + get: function () { + return this._dataBindingRule; + }, + /** + * @property {any} dataBindingRule + * 数据绑定规则。 + */ + set: function (dataBindingRule) { + this._dataBindingRule = binding_rule_2.BindingRule.create(dataBindingRule); + }, + enumerable: true, + configurable: true + }); + /** + * @method updateExplicit + * 显式的更新ViewModel。 + */ + Widget.prototype.updateExplicit = function () { + if (this._dataBindingRule) { + this.onUpdateToDataSource(); + } + this.children.forEach(function (child) { + child.updateExplicit(); }); + return this; }; - - Per.prototype.listen = function(untilFunc) { - return this.per(function(emit, value) { - if (untilFunc(value)) { - return true; - } - return emit(value); - }); + Widget.prototype.removeBinding = function () { + var viewModel = this._viewModel; + var dataBindingRule = this._dataBindingRule; + if (dataBindingRule && viewModel) { + viewModel.offChange(this.viewModelChangeFunc); + } + this._viewModel = null; + this._dataBindingRule = null; }; - - Per.prototype.flatten = function() { - return this.per(function(emit, array) { - return !Array.isArray(array) - ? emit(array) - : array.some(function(value) { - return emit(value); - }); - }); + Widget.prototype.onBeforeBindData = function () { }; - - Per.prototype.reduce = function(reducer, seed) { - var result = seed, started = arguments.length == 2; - return this.per(function(emit, value) { - result = started ? reducer(result, value) : value; - emit(result); - started = true; - }); + Widget.prototype.onAfterBindData = function () { }; - - Per.prototype.multicast = function(destinations) { - if (arguments.length !== 1) { - destinations = Array.prototype.slice.call(arguments, 0); + /** + * @method bindData + * 绑定数据。 + * @param {IViewModel} viewModel View Model。 + * @return {Widget} 控件本身。 + */ + Widget.prototype.bindData = function (viewModel) { + var _this = this; + var dataBindingRule = this._dataBindingRule; + this._viewModel = viewModel; + this.onBeforeBindData(); + if (dataBindingRule && viewModel) { + var bindingMode = viewModel.bindingMode; + this.onBindCommand(viewModel, dataBindingRule); + if (bindingMode !== iview_model_1.BindingMode.ONE_WAY_TO_SOURCE) { + this.onBindData(viewModel, dataBindingRule); + } + if (bindingMode === iview_model_1.BindingMode.TWO_WAY || bindingMode === iview_model_1.BindingMode.ONE_WAY_TO_SOURCE) { + this.watchTargetChange(dataBindingRule); + } + if (bindingMode !== iview_model_1.BindingMode.ONE_TIME && bindingMode !== iview_model_1.BindingMode.ONE_WAY_TO_SOURCE) { + viewModel.onChange(this.viewModelChangeFunc); + } + this._isEnableFunc = function () { + var enable = true; + var vm = this._viewModel; + if (vm) { + dataBindingRule.forEach(function (prop, item) { + var source = item.source; + if (source.type === binding_rule_1.BindingCommandSource.TYPE) { + var commandSource = source; + enable = enable && vm.canExecute(commandSource.command); + } + }); + } + return enable; + }; } - destinations = destinations.map(function(destination) { - return typeof destination === 'function' ? destination : - destination instanceof Per ? destination.forEach : - ignore; - }); - return this.listen(function(value) { - var quit = true; - destinations.forEach(function(destination) { - if (!destination(ignore, value)) { - quit = false; + this.bindDataToChildren(viewModel); + if (viewModel.isCollection && this._templateItemJson) { + var collectionViewModel = viewModel; + collectionViewModel.onItemsChange(function (evt) { + _this.bindDataToChildren(viewModel); + }); + } + this.onAfterBindData(); + return this; + }; + Widget.prototype.bindDataToChildren = function (viewModel) { + if (viewModel.isCollection) { + if (this._templateItemJson) { + //对于集合viewModel,如果有模板项存在,则动态生成子控件。 + var json = this._templateItemJson; + var collectionViewModel = viewModel; + var n = collectionViewModel.total; + this.removeAllChildren(); + for (var i = 0; i < n; i++) { + var itemViewModel = collectionViewModel.getItemViewModel(i); + var child = this.addChildWithTemplate(true); + child.bindData(itemViewModel); } + this.relayoutChildren(); + } + else { + //对于集合viewModel,如果没有模板项存在,则绑定集合viewModel当前项到子控件。 + this._children.forEach(function (child) { + child.bindData(viewModel); + }); + } + } + else { + //对于非集合viewModel,按正常绑定子控件。 + this._children.forEach(function (child) { + child.bindData(viewModel); }); - return quit; - }); + } }; - - function optionalLimit(limit) { - return typeof limit != 'number' ? Number.MAX_VALUE : limit; - } - - /* A passive observer - gathers results into the specified array, but - otherwise has no effect on the stream of values + /* + * 绑定命令,注册相应的事件处理函数。 */ - Per.prototype.into = function(ar, limit) { - if (!Array.isArray(ar)) { - throw new Error("into expects an array"); - } - limit = optionalLimit(limit); - return this.listen(function(value) { - if (limit <= 0) { - return true; + Widget.prototype.onBindCommand = function (viewModel, dataBindingRule) { + var _this = this; + dataBindingRule.forEach(function (prop, item) { + var source = item.source; + if (source.type === binding_rule_1.BindingCommandSource.TYPE) { + var commandSource = source; + var type = Events.mapToEvent(prop); + if (type) { + var command = commandSource.command; + if (typeof command == "object" && command.path) { + commandSource.command = viewModel.getProp(command.path); + } + var commandArgs = commandSource.commandArgs; + if (typeof commandArgs == "object" && commandArgs.path) { + commandSource.commandArgs = viewModel.getProp(commandArgs.path); + } + if (commandSource.eventHandler) { + _this.off(type, commandSource.eventHandler); + } + commandSource.eventHandler = function (evt) { + var args = commandSource.commandArgs || evt; + viewModel.execCommand(commandSource.command, args); + }; + _this.on(type, commandSource.eventHandler); + } + else { + console.log(prop + " is not supported yet."); + } } - ar.push(value); - limit--; }); }; - - function setOrCall(obj, name) { - var prop = obj[name]; - if (typeof prop === 'function') { - return prop; - } - return function(val) { - obj[name] = val; - } - } - - /* Tracks first, last and count for the values as they go past, - up to an optional limit (see 'first' and 'last' methods). + /* + * 把数据显示到界面上。 */ - Per.prototype.monitor = function(data) { - var n = 0; - var count = setOrCall(data, 'count'), - first = setOrCall(data, 'first'), - last = setOrCall(data, 'last'), - limit = data.limit; - if (typeof limit != 'number') { - limit = Number.MAX_VALUE; - } - if (limit < 1) { - return this; - } - return this.listen(function(value) { - if (n === 0) { - first(value); - } - n++; - count(n); - last(value); - if (n >= limit) { - return true; + Widget.prototype.onBindData = function (viewModel, dataBindingRule) { + var _this = this; + dataBindingRule.forEach(function (prop, item) { + var source = item.source; + if (source.type === binding_rule_1.BindingDataSource.TYPE) { + var dataSource = source; + var value = dataSource.value; + var bindingMode = dataSource.mode || iview_model_1.BindingMode.TWO_WAY; + if (value === undefined && dataSource.path) { + value = viewModel.getProp(dataSource.path, dataSource.converter); + } + if (bindingMode !== iview_model_1.BindingMode.ONE_WAY_TO_SOURCE) { + _this.onBindProp(prop, value); + } } }); }; - - /* Send a value into the pipeline without caring what emerges - (only useful if you set up monitors and/or intos, or - similar stateful observers). + Widget.prototype.getPropDefaultBindMode = function (prop) { + return (prop === "value" && this.inputable) ? iview_model_1.BindingMode.TWO_WAY : iview_model_1.BindingMode.ONE_WAY; + }; + /* + * 子控件重载此函数向用户提示数据无效。 */ - function ignore() { } - Per.prototype.submit = function(value) { - return this.forEach(ignore, value); + Widget.prototype.onInvalidInput = function (message) { + if (message) { + console.log("invalid value:" + message); + } }; - - Per.prototype.all = function() { - var results = []; - this.into(results).submit(); - return results; + Widget.prototype.onUpdateToDataSource = function () { + var _this = this; + var dataBindingRule = this._dataBindingRule; + dataBindingRule.forEach(function (prop, item) { + if (item.source.type === binding_rule_1.BindingDataSource.TYPE) { + var dataSource = item.source; + if (dataSource.updateTiming === iview_model_1.UpdateTiming.EXPLICIT) { + _this.updateValueToSource(_this.value, dataSource); + } + } + }); }; - - Per.prototype.first = function() { - var results = { limit: 1 }; - this.monitor(results).submit(); - return results.count > 0 ? results.first : (void 0); + /* + * 把界面数据更新到模型。 + */ + Widget.prototype.updateValueToSource = function (value, dataSource, oldValue) { + var result = this._viewModel.setPropEx(dataSource, value, oldValue); + this.onInvalidInput(result.code ? result.message : null); }; - - Per.prototype.last = function() { - var results = {}; - this.monitor(results).submit(); - return results.count > 0 ? results.last : (void 0); + /* + * 监控控件单个属性的变化。 + */ + Widget.prototype.watchTargetValueChange = function (dataSource) { + var _this = this; + var updateTiming = dataSource.updateTiming; + var bindingMode = dataSource.mode || iview_model_1.BindingMode.TWO_WAY; + if (updateTiming === iview_model_1.UpdateTiming.EXPLICIT) { + return; + } + if (bindingMode === iview_model_1.BindingMode.TWO_WAY || bindingMode === iview_model_1.BindingMode.ONE_WAY_TO_SOURCE) { + this.on(Events.CHANGE, function (evt) { + _this.updateValueToSource(evt.value, dataSource, evt.oldValue); + }); + if (updateTiming === iview_model_1.UpdateTiming.CHANGING) { + this.on(Events.CHANGING, function (evt) { + _this.updateValueToSource(evt.value, dataSource); + }); + } + } }; - - function truthy(value) { return !!value; } - Per.prototype.truthy = function() { return this.filter(truthy); }; - - function min(l, r) { return Math.min(l, r); } - Per.prototype.min = function() { return this.reduce(min, Number.MAX_VALUE); }; - - function max(l, r) { return Math.max(l, r); } - Per.prototype.max = function() { return this.reduce(max, Number.MIN_VALUE); }; - - function sum(l, r) { return l + r } - Per.prototype.sum = function() { return this.reduce(sum, 0); }; - - function and(l, r) { return !!(l && r) } - Per.prototype.and = function() { return this.reduce(and, true); }; - - function or(l, r) { return !!(l || r) } - Per.prototype.or = function() { return this.reduce(or, false); }; - - function not(v) { return !v } - Per.prototype.not = function() { return this.map(not); }; - - create.pulse = function(ms) { - var counter = 0; - return create(function(emit) { - function step() { - if (emit(counter++) !== true) { - setTimeout(step, ms); + /* + * 监控控件属性的变化。 + */ + Widget.prototype.watchTargetChange = function (dataBindingRule) { + var _this = this; + dataBindingRule.forEach(function (prop, item) { + var source = item.source; + if (source.type === binding_rule_1.BindingDataSource.TYPE) { + var dataSource = source; + var bindingMode = _this.getPropDefaultBindMode(prop); + if (bindingMode === iview_model_1.BindingMode.TWO_WAY) { + _this.watchTargetValueChange(dataSource); } } - step(); }); }; - - exportFunction(create); - - })(function(per) { - if (false) { - this['per'] = per; - } else { - module.exports = per; - } - }); + Widget.prototype.hitTest = function (x, y) { + return this.doHitTest(x, y, rect_1.Rect.rect.init(0, 0, this.w + 1, this.h + 1)); + }; + Widget.prototype.doHitTest = function (x, y, r) { + return r.containsPoint(x, y) ? HitTestResult.MM : HitTestResult.NONE; + }; + Widget.prototype.selfHitTest = function (x, y) { + return this.hitTest(x, y); + }; + return Widget; + }(emitter_1.Emitter)); + Widget.defProps = { + _x: 0, + _y: 0, + _z: 0, + _w: 0, + _h: 0, + _state: 0, + _value: 0, + _enable: true, + _visible: true, + _selected: false, + _opacity: 1, + _scaleX: 1, + _scaleY: 1, + _pivotX: 0.5, + _pivotY: 0.5, + _rotation: 0, + _sensitive: true, + _tips: null, + _text: null, + _name: null, + _hitTestResult: 0, + _isWindow: false, + _mode: 0, + _styleType: null, + _lp: 0, + _tp: 0, + _rp: 0, + _bp: 0 + }; + Widget.ID = 10000; + exports.Widget = Widget; + ; /***/ }, -/* 30 */ -/***/ function(module, exports) { +/* 20 */ +/***/ function(module, exports, __webpack_require__) { - exports.formattingKeys = [ 'bold', 'italic', 'underline', 'strikeout', 'color', 'font', 'size', 'align', 'script' ]; + var __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__;/* WEBPACK VAR INJECTION */(function(process) {/** + * Tween.js - Licensed under the MIT license + * https://github.com/tweenjs/tween.js + * ---------------------------------------------- + * + * See https://github.com/tweenjs/tween.js/graphs/contributors for the full list of contributors. + * Thank you all, you're awesome! + */ - exports.defaultFormatting = { - size: 10, - font: 'sans-serif', - color: 'black', - bold: false, - italic: false, - underline: false, - strikeout: false, - align: 'left', - script: 'normal' - }; + var TWEEN = TWEEN || (function () { - exports.sameFormatting = function(run1, run2) { - return exports.formattingKeys.every(function(key) { - return run1[key] === run2[key]; - }) - }; + var _tweens = []; + + return { + + getAll: function () { + + return _tweens; + + }, + + removeAll: function () { + + _tweens = []; + + }, + + add: function (tween) { + + _tweens.push(tween); + + }, + + remove: function (tween) { + + var i = _tweens.indexOf(tween); + + if (i !== -1) { + _tweens.splice(i, 1); + } - exports.clone = function(run) { - var result = { text: run.text }; - exports.formattingKeys.forEach(function(key) { - var val = run[key]; - if (val && val != exports.defaultFormatting[key]) { - result[key] = val; - } - }); - return result; - }; + }, - exports.multipleValues = {}; + update: function (time, preserve) { - exports.merge = function(run1, run2) { - if (arguments.length === 1) { - return Array.isArray(run1) ? run1.reduce(exports.merge) : run1; - } - if (arguments.length > 2) { - return exports.merge(Array.prototype.slice.call(arguments, 0)); - } - var merged = {}; - exports.formattingKeys.forEach(function(key) { - if (key in run1 || key in run2) { - if (run1[key] === run2[key]) { - merged[key] = run1[key]; - } else { - merged[key] = exports.multipleValues; - } - } - }); - return merged; - }; + if (_tweens.length === 0) { + return false; + } - exports.format = function(run, template) { - if (Array.isArray(run)) { - run.forEach(function(r) { - exports.format(r, template); - }); - } else { - Object.keys(template).forEach(function(key) { - if (template[key] !== exports.multipleValues) { - run[key] = template[key]; - } - }); - } - }; + var i = 0; - exports.consolidate = function() { - var current; - return function (emit, run) { - if (!current || !exports.sameFormatting(current, run) || - (typeof current.text != 'string') || - (typeof run.text != 'string')) { - current = exports.clone(run); - emit(current); - } else { - current.text += run.text; - } - }; - }; + time = time !== undefined ? time : TWEEN.now(); - exports.getPlainText = function(run) { - if (typeof run.text === 'string') { - return run.text; - } - if (Array.isArray(run.text)) { - var str = []; - run.text.forEach(function(piece) { - str.push(exports.getPiecePlainText(piece)); - }); - return str.join(''); - } - return '_'; - }; + while (i < _tweens.length) { - /* The text property of a run can be an ordinary string, or a "character object", - or it can be an array containing strings and "character objects". + if (_tweens[i].update(time) || preserve) { + i++; + } else { + _tweens.splice(i, 1); + } - A character object is not a string, but is treated as a single character. + } - We abstract over this to provide the same string-like operations regardless. - */ - exports.getPieceLength = function(piece) { - return piece.length || 1; // either a string or something like a character - }; + return true; - exports.getPiecePlainText = function(piece) { - return piece.length ? piece : '_'; - }; + } + }; - exports.getTextLength = function(text) { - if (typeof text === 'string') { - return text.length; - } - if (Array.isArray(text)) { - var length = 0; - text.forEach(function(piece) { - length += exports.getPieceLength(piece); - }); - return length; - } - return 1; - }; + })(); - exports.getSubText = function(emit, text, start, count) { - if (count === 0) { - return; - } - if (typeof text === 'string') { - emit(text.substr(start, count)); - return; - } - if (Array.isArray(text)) { - var pos = 0; - text.some(function(piece) { - if (count <= 0) { - return true; - } - var pieceLength = exports.getPieceLength(piece); - if (pos + pieceLength > start) { - if (pieceLength === 1) { - emit(piece); - count -= 1; - } else { - var str = piece.substr(Math.max(0, start - pos), count); - emit(str); - count -= str.length; - } - } - pos += pieceLength; - }); - return; - } - emit(text); - }; - exports.getTextChar = function(text, offset) { - var result; - exports.getSubText(function(c) { result = c }, text, offset, 1); - return result; - }; + // Include a performance.now polyfill. + // In node.js, use process.hrtime. + if (typeof (window) === 'undefined' && typeof (process) !== 'undefined') { + TWEEN.now = function () { + var time = process.hrtime(); - exports.pieceCharacters = function(each, piece) { - if (typeof piece === 'string') { - for (var c = 0; c < piece.length; c++) { - each(piece[c]); - } - } else { - each(piece); - } - }; + // Convert [seconds, nanoseconds] to milliseconds. + return time[0] * 1000 + time[1] / 1000000; + }; + } + // In a browser, use window.performance.now if it is available. + else if (typeof (window) !== 'undefined' && + window.performance !== undefined && + window.performance.now !== undefined) { + // This must be bound, because directly assigning this function + // leads to an invocation exception in Chrome. + TWEEN.now = window.performance.now.bind(window.performance); + } + // Use Date.now if it is available. + else if (Date.now !== undefined) { + TWEEN.now = Date.now; + } + // Otherwise, use 'new Date().getTime()'. + else { + TWEEN.now = function () { + return new Date().getTime(); + }; + } -/***/ }, -/* 31 */ -/***/ function(module, exports) { + TWEEN.Tween = function (object) { - - var prototype = { - contains: function(x, y) { - return x >= this.l && x < (this.l + this.w) && - y >= this.t && y < (this.t + this.h); + var _object = object; + var _valuesStart = {}; + var _valuesEnd = {}; + var _valuesStartRepeat = {}; + var _duration = 1000; + var _repeat = 0; + var _repeatDelayTime; + var _yoyo = false; + var _isPlaying = false; + var _reversed = false; + var _delayTime = 0; + var _startTime = null; + var _easingFunction = TWEEN.Easing.Linear.None; + var _interpolationFunction = TWEEN.Interpolation.Linear; + var _chainedTweens = []; + var _onStartCallback = null; + var _onStartCallbackFired = false; + var _onUpdateCallback = null; + var _onCompleteCallback = null; + var _onStopCallback = null; - }, - stroke: function(ctx) { - ctx.strokeRect(this.l, this.t, this.w, this.h); - }, - fill: function(ctx) { - ctx.fillRect(this.l, this.t, this.w, this.h); - }, - offset: function(x, y) { - return rect(this.l + x, this.t + y, this.w, this.h); - }, - equals: function(other) { - return this.l === other.l && this.t === other.t && - this.w === other.w && this.h === other.h; - }, - center: function() { - return { x: this.l + this.w/2, y: this.t + this.h/2 }; - } - }; + this.to = function (properties, duration) { - var rect = module.exports = function(l, t, w, h) { - return Object.create(prototype, { - l: { value: l }, - t: { value: t }, - w: { value: w }, - h: { value: h }, - r: { value: l + w }, - b: { value: t + h } - }); - }; + _valuesEnd = properties; + if (duration !== undefined) { + _duration = duration; + } -/***/ }, -/* 32 */ -/***/ function(module, exports) { + return this; - exports.event = function() { - var handlers = []; + }; - var subscribe = function(handler) { - handlers.push(handler); - }; + this.start = function (time) { - subscribe.fire = function() { - var args = Array.prototype.slice.call(arguments, 0); - handlers.forEach(function(handler) { - handler.apply(null, args); - }); - }; + TWEEN.add(this); - return subscribe; - }; + _isPlaying = true; - exports.derive = function(prototype, methods) { - var properties = {}; - Object.keys(methods).forEach(function(name) { - properties[name] = { value: methods[name] }; - }); - return Object.create(prototype, properties); - }; + _onStartCallbackFired = false; -/***/ }, -/* 33 */ -/***/ function(module, exports, __webpack_require__) { + _startTime = time !== undefined ? time : TWEEN.now(); + _startTime += _delayTime; - var per = __webpack_require__(29); - var carotaDoc = __webpack_require__(34); - var dom = __webpack_require__(46); - var rect = __webpack_require__(31); + for (var property in _valuesEnd) { - setInterval(function() { - var editors = document.querySelectorAll('.carotaEditorCanvas'); + // Check if an Array was provided as property value + if (_valuesEnd[property] instanceof Array) { - var ev = document.createEvent('Event'); - ev.initEvent('carotaEditorSharedTimer', true, true); + if (_valuesEnd[property].length === 0) { + continue; + } - // not in IE, apparently: - // var ev = new CustomEvent('carotaEditorSharedTimer'); + // Create a local copy of the Array with the start value at the front + _valuesEnd[property] = [_object[property]].concat(_valuesEnd[property]); - for (var n = 0; n < editors.length; n++) { - editors[n].dispatchEvent(ev); - } - }, 200); + } - exports.create = function(element) { + // If `to()` specifies a property that doesn't exist in the source object, + // we should not set that property in the object + if (_object[property] === undefined) { + continue; + } - // We need the host element to be a container: - if (dom.effectiveStyle(element, 'position') !== 'absolute') { - element.style.position = 'relative'; - } + // Save the starting value. + _valuesStart[property] = _object[property]; - element.innerHTML = - '
' + - '' + - '
' + - '
' + - '' - '
'; + if ((_valuesStart[property] instanceof Array) === false) { + _valuesStart[property] *= 1.0; // Ensures we're using numbers, not strings + } - var canvas = element.querySelector('canvas'), - spacer = element.querySelector('.carotaSpacer'), - textAreaDiv = element.querySelector('.carotaTextArea'), - textArea = element.querySelector('textarea'), - doc = carotaDoc(), - keyboardSelect = 0, - keyboardX = null, nextKeyboardX = null, - selectDragStart = null, - focusChar = null, - textAreaContent = '', - richClipboard = null, - plainClipboard = null; - - var toggles = { - 66: 'bold', - 73: 'italic', - 85: 'underline', - 83: 'strikeout' - }; + _valuesStartRepeat[property] = _valuesStart[property] || 0; - var exhausted = function(ordinal, direction) { - return direction < 0 ? ordinal <= 0 : ordinal >= doc.frame.length - 1; - }; + } - var differentLine = function(caret1, caret2) { - return (caret1.b <= caret2.t) || - (caret2.b <= caret1.t); - }; + return this; - var changeLine = function(ordinal, direction) { + }; - var originalCaret = doc.getCaretCoords(ordinal), newCaret; - nextKeyboardX = (keyboardX !== null) ? keyboardX : originalCaret.l; + this.stop = function () { - while (!exhausted(ordinal, direction)) { - ordinal += direction; - newCaret = doc.getCaretCoords(ordinal); - if (differentLine(newCaret, originalCaret)) { - break; - } - } + if (!_isPlaying) { + return this; + } - originalCaret = newCaret; - while (!exhausted(ordinal, direction)) { - if ((direction > 0 && newCaret.l >= nextKeyboardX) || - (direction < 0 && newCaret.l <= nextKeyboardX)) { - break; - } + TWEEN.remove(this); + _isPlaying = false; - ordinal += direction; - newCaret = doc.getCaretCoords(ordinal); - if (differentLine(newCaret, originalCaret)) { - ordinal -= direction; - break; - } - } + if (_onStopCallback !== null) { + _onStopCallback.call(_object, _object); + } - return ordinal; - }; + this.stopChainedTweens(); + return this; - var endOfline = function(ordinal, direction) { - var originalCaret = doc.getCaretCoords(ordinal), newCaret; - while (!exhausted(ordinal, direction)) { - ordinal += direction; - newCaret = doc.getCaretCoords(ordinal); - if (differentLine(newCaret, originalCaret)) { - ordinal -= direction; - break; - } - } - return ordinal; - }; + }; - var handleKey = function(key, selecting, ctrlKey) { - var start = doc.selection.start, - end = doc.selection.end, - length = doc.frame.length - 1, - handled = false; + this.end = function () { - nextKeyboardX = null; + this.update(_startTime + _duration); + return this; - if (!selecting) { - keyboardSelect = 0; - } else if (!keyboardSelect) { - switch (key) { - case 37: // left arrow - case 38: // up - find character above - case 36: // start of line - case 33: // page up - keyboardSelect = -1; - break; - case 39: // right arrow - case 40: // down arrow - find character below - case 35: // end of line - case 34: // page down - keyboardSelect = 1; - break; - } - } + }; - var ordinal = keyboardSelect === 1 ? end : start; + this.stopChainedTweens = function () { - var changingCaret = false; - switch (key) { - case 37: // left arrow - if (!selecting && start != end) { - ordinal = start; - } else { - if (ordinal > 0) { - if (ctrlKey) { - var wordInfo = doc.wordContainingOrdinal(ordinal); - if (wordInfo.ordinal === ordinal) { - ordinal = wordInfo.index > 0 ? doc.wordOrdinal(wordInfo.index - 1) : 0; - } else { - ordinal = wordInfo.ordinal; - } - } else { - ordinal--; - } - } - } - changingCaret = true; - break; - case 39: // right arrow - if (!selecting && start != end) { - ordinal = end; - } else { - if (ordinal < length) { - if (ctrlKey) { - var wordInfo = doc.wordContainingOrdinal(ordinal); - ordinal = wordInfo.ordinal + wordInfo.word.length; - } else { - ordinal++; - } - } - } - changingCaret = true; - break; - case 40: // down arrow - find character below - ordinal = changeLine(ordinal, 1); - changingCaret = true; - break; - case 38: // up - find character above - ordinal = changeLine(ordinal, -1); - changingCaret = true; - break; - case 36: // start of line - ordinal = endOfline(ordinal, -1); - changingCaret = true; - break; - case 35: // end of line - ordinal = endOfline(ordinal, 1); - changingCaret = true; - break; - case 33: // page up - ordinal = 0; - changingCaret = true; - break; - case 34: // page down - ordinal = length; - changingCaret = true; - break; - case 8: // backspace - if (start === end && start > 0) { - doc.range(start - 1, start).clear(); - focusChar = start - 1; - doc.select(focusChar, focusChar); - handled = true; - } - break; - case 46: // del - if (start === end && start < length) { - doc.range(start, start + 1).clear(); - handled = true; - } - break; - case 90: // Z undo - if (ctrlKey) { - handled = true; - doc.performUndo(); - } - break; - case 89: // Y undo - if (ctrlKey) { - handled = true; - doc.performUndo(true); - } - break; - case 65: // A select all - if (ctrlKey) { - handled = true; - doc.select(0, length); - } - break; - case 67: // C - copy to clipboard - case 88: // X - cut to clipboard - if (ctrlKey) { - // Allow standard handling to take place as well - richClipboard = doc.selectedRange().save(); - plainClipboard = doc.selectedRange().plainText(); - } - break; - } + for (var i = 0, numChainedTweens = _chainedTweens.length; i < numChainedTweens; i++) { + _chainedTweens[i].stop(); + } - var toggle = toggles[key]; - if (ctrlKey && toggle) { - var selRange = doc.selectedRange(); - selRange.setFormatting(toggle, selRange.getFormatting()[toggle] !== true); - paint(); - handled = true; - } + }; - if (changingCaret) { - switch (keyboardSelect) { - case 0: - start = end = ordinal; - break; - case -1: - start = ordinal; - break; - case 1: - end = ordinal; - break; - } + this.delay = function (amount) { - if (start === end) { - keyboardSelect = 0; - } else { - if (start > end) { - keyboardSelect = -keyboardSelect; - var t = end; - end = start; - start = t; - } - } - focusChar = ordinal; - doc.select(start, end); - handled = true; - } + _delayTime = amount; + return this; - keyboardX = nextKeyboardX; - return handled; - }; + }; - dom.handleEvent(textArea, 'keydown', function(ev) { - if (handleKey(ev.keyCode, ev.shiftKey, ev.ctrlKey)) { - return false; - } - console.log(ev.which); - }); + this.repeat = function (times) { - var verticalAlignment = 'top'; - - doc.setVerticalAlignment = function(va) { - verticalAlignment = va; - paint(); - } + _repeat = times; + return this; - function getVerticalOffset() { - var docHeight = doc.frame.bounds().h; - if (docHeight < element.clientHeight) { - switch (verticalAlignment) { - case 'middle': - return (element.clientHeight - docHeight) / 2; - case 'bottom': - return element.clientHeight - docHeight; - } - } - return 0; - } + }; - var paint = function() { + this.repeatDelay = function (amount) { - var availableWidth = element.clientWidth * 1; // adjust to 0.5 to see if we draw in the wrong places! - if (doc.width() !== availableWidth) { - doc.width(availableWidth); - } + _repeatDelayTime = amount; + return this; - var docHeight = doc.frame.bounds().h; + }; - var dpr = Math.max(1, window.devicePixelRatio || 1); - - var logicalWidth = Math.max(doc.frame.actualWidth(), element.clientWidth), - logicalHeight = element.clientHeight; - - canvas.width = dpr * logicalWidth; - canvas.height = dpr * logicalHeight; - canvas.style.width = logicalWidth + 'px'; - canvas.style.height = logicalHeight + 'px'; - - canvas.style.top = element.scrollTop + 'px'; - spacer.style.width = logicalWidth + 'px'; - spacer.style.height = Math.max(docHeight, element.clientHeight) + 'px'; + this.yoyo = function (yoyo) { - if (docHeight < (element.clientHeight - 50) && - doc.frame.actualWidth() <= availableWidth) { - element.style.overflow = 'hidden'; - } else { - element.style.overflow = 'auto'; - } + _yoyo = yoyo; + return this; - var ctx = canvas.getContext('2d'); - ctx.scale(dpr, dpr); + }; - ctx.clearRect(0, 0, logicalWidth, logicalHeight); - ctx.translate(0, getVerticalOffset() - element.scrollTop); - - doc.draw(ctx, rect(0, element.scrollTop, logicalWidth, logicalHeight)); - doc.drawSelection(ctx, selectDragStart || (document.activeElement === textArea)); - }; - dom.handleEvent(element, 'scroll', paint); + this.easing = function (easing) { - dom.handleEvent(textArea, 'input', function() { - var newText = textArea.value; - if (textAreaContent != newText) { - textAreaContent = ''; - textArea.value = ''; - if (newText === plainClipboard) { - newText = richClipboard; - } - doc.insert(newText); - } - }); + _easingFunction = easing; + return this; - var updateTextArea = function() { - focusChar = focusChar === null ? doc.selection.end : focusChar; - var endChar = doc.byOrdinal(focusChar); - focusChar = null; - if (endChar) { - var bounds = endChar.bounds(); - textAreaDiv.style.left = bounds.l + 'px'; - textAreaDiv.style.top = bounds.t + 'px'; - textArea.focus(); - var scrollDownBy = Math.max(0, bounds.t + bounds.h - - (element.scrollTop + element.clientHeight)); - if (scrollDownBy) { - element.scrollTop += scrollDownBy; - } - var scrollUpBy = Math.max(0, element.scrollTop - bounds.t); - if (scrollUpBy) { - element.scrollTop -= scrollUpBy; - } - var scrollRightBy = Math.max(0, bounds.l - - (element.scrollLeft + element.clientWidth)); - if (scrollRightBy) { - element.scrollLeft += scrollRightBy; - } - var scrollLeftBy = Math.max(0, element.scrollLeft - bounds.l); - if (scrollLeftBy) { - element.scrollLeft -= scrollLeftBy; - } - } - textAreaContent = doc.selectedRange().plainText(); - textArea.value = textAreaContent; - textArea.select(); + }; - setTimeout(function() { - textArea.focus(); - }, 10); - }; + this.interpolation = function (interpolation) { - doc.selectionChanged(function(getformatting, takeFocus) { - paint(); - if (!selectDragStart) { - if (takeFocus !== false) { - updateTextArea(); - } - } - }); + _interpolationFunction = interpolation; + return this; - function registerMouseEvent(name, handler) { - dom.handleMouseEvent(spacer, name, function(ev, x, y) { - handler(doc.byCoordinate(x, y - getVerticalOffset())); - }); - } + }; - registerMouseEvent('mousedown', function(node) { - selectDragStart = node.ordinal; - doc.select(node.ordinal, node.ordinal); - keyboardX = null; - }); + this.chain = function () { - registerMouseEvent('dblclick', function(node) { - node = node.parent(); - if (node) { - doc.select(node.ordinal, node.ordinal + - (node.word ? node.word.text.length : node.length)); - } - }); + _chainedTweens = arguments; + return this; - registerMouseEvent('mousemove', function(node) { - if (selectDragStart !== null) { - if (node) { - focusChar = node.ordinal; - if (selectDragStart > node.ordinal) { - doc.select(node.ordinal, selectDragStart); - } else { - doc.select(selectDragStart, node.ordinal); - } - } - } - }); + }; - registerMouseEvent('mouseup', function(node) { - selectDragStart = null; - keyboardX = null; - updateTextArea(); - textArea.focus(); - }); + this.onStart = function (callback) { + + _onStartCallback = callback; + return this; + + }; + + this.onUpdate = function (callback) { + + _onUpdateCallback = callback; + return this; + + }; + + this.onComplete = function (callback) { + + _onCompleteCallback = callback; + return this; + + }; + + this.onStop = function (callback) { + + _onStopCallback = callback; + return this; + + }; + + this.update = function (time) { + + var property; + var elapsed; + var value; + + if (time < _startTime) { + return true; + } + + if (_onStartCallbackFired === false) { + + if (_onStartCallback !== null) { + _onStartCallback.call(_object, _object); + } + + _onStartCallbackFired = true; + } + + elapsed = (time - _startTime) / _duration; + elapsed = elapsed > 1 ? 1 : elapsed; - var nextCaretToggle = new Date().getTime(), - focused = false, - cachedWidth = element.clientWidth, - cachedHeight = element.clientHeight; + value = _easingFunction(elapsed); - var update = function() { - var requirePaint = false; - var newFocused = document.activeElement === textArea; - if (focused !== newFocused) { - focused = newFocused; - requirePaint = true; - } + for (property in _valuesEnd) { - var now = new Date().getTime(); - if (now > nextCaretToggle) { - nextCaretToggle = now + 500; - if (doc.toggleCaret()) { - requirePaint = true; - } - } + // Don't update properties that do not exist in the source object + if (_valuesStart[property] === undefined) { + continue; + } - if (element.clientWidth !== cachedWidth || - element.clientHeight !== cachedHeight) { - requirePaint = true; - cachedWidth =element.clientWidth; - cachedHeight = element.clientHeight; - } + var start = _valuesStart[property] || 0; + var end = _valuesEnd[property]; - if (requirePaint) { - paint(); - } - }; + if (end instanceof Array) { - dom.handleEvent(canvas, 'carotaEditorSharedTimer', update); - update(); + _object[property] = _interpolationFunction(end, value); - doc.sendKey = handleKey; - return doc; - }; + } else { + // Parses relative end values with start as base (e.g.: +10, -3) + if (typeof (end) === 'string') { -/***/ }, -/* 34 */ -/***/ function(module, exports, __webpack_require__) { + if (end.charAt(0) === '+' || end.charAt(0) === '-') { + end = start + parseFloat(end); + } else { + end = parseFloat(end); + } + } - var per = __webpack_require__(29); - var characters = __webpack_require__(35); - var split = __webpack_require__(36); - var word = __webpack_require__(37); - var node = __webpack_require__(28); - var runs = __webpack_require__(30); - var range = __webpack_require__(40); - var util = __webpack_require__(32); - var frame = __webpack_require__(41); - var codes = __webpack_require__(45); - var rect = __webpack_require__(31); + // Protect against non numeric properties. + if (typeof (end) === 'number') { + _object[property] = start + (end - start) * value; + } - var makeEditCommand = function(doc, start, count, words) { - var selStart = doc.selection.start, selEnd = doc.selection.end; - return function(log) { - doc._wordOrdinals = []; - var oldWords = Array.prototype.splice.apply(doc.words, [start, count].concat(words)); - log(makeEditCommand(doc, start, words.length, oldWords)); - doc._nextSelection = { start: selStart, end: selEnd }; - }; - }; + } - var makeTransaction = function(perform) { - var commands = []; - var log = function(command) { - commands.push(command); - log.length = commands.length; - }; - perform(log); + } - return function(outerLog) { - outerLog(makeTransaction(function(innerLog) { - while (commands.length) { - commands.pop()(innerLog); - } - })); - }; - }; + if (_onUpdateCallback !== null) { + _onUpdateCallback.call(_object, value); + } - var isBreaker = function(word) { - if (word.isNewLine()) { - return true; - } - var code = word.code(); - return !!(code && (code.block || code.eof)); - }; + if (elapsed === 1) { - var prototype = node.derive({ - load: function(runs, takeFocus) { - var self = this; - this.undo = []; - this.redo = []; - this._wordOrdinals = []; - this.words = per(characters(runs)).per(split(self.codes)).map(function(w) { - return word(w, self.codes); - }).all(); - this.layout(); - this.contentChanged.fire(); - this.select(0, 0, takeFocus); - }, - layout: function() { - this.frame = null; - try { - this.frame = per(this.words).per(frame(0, 0, this._width, 0, this)).first(); - } catch (x) { - console.error(x); - } - if (!this.frame) { - console.error('A bug somewhere has produced an invalid state - rolling back'); - this.performUndo(); - } else if (this._nextSelection) { - var next = this._nextSelection; - delete this._nextSelection; - this.select(next.start, next.end); - } - }, - range: function(start, end) { - return range(this, start, end); - }, - documentRange: function() { - return this.range(0, this.frame.length - 1); - }, - selectedRange: function() { - return this.range(this.selection.start, this.selection.end); - }, - save: function() { - return this.documentRange().save(); - }, - paragraphRange: function(start, end) { - var i; + if (_repeat > 0) { - // find the character after the nearest breaker before start - var startInfo = this.wordContainingOrdinal(start); - start = 0; - if (startInfo && !isBreaker(startInfo.word)) { - for (i = startInfo.index; i > 0; i--) { - if (isBreaker(this.words[i - 1])) { - start = this.wordOrdinal(i); - break; - } - } - } + if (isFinite(_repeat)) { + _repeat--; + } - // find the nearest breaker after end - var endInfo = this.wordContainingOrdinal(end); - end = this.frame.length - 1; - if (endInfo && !isBreaker(endInfo.word)) { - for (i = endInfo.index; i < this.words.length; i++) { - if (isBreaker(this.words[i])) { - end = this.wordOrdinal(i); - break; - } - } - } + // Reassign starting values, restart by making startTime = now + for (property in _valuesStartRepeat) { - return this.range(start, end); - }, - insert: function(text, takeFocus) { - this.select(this.selection.end + this.selectedRange().setText(text), null, takeFocus); - }, - modifyInsertFormatting: function(attribute, value) { - this.nextInsertFormatting[attribute] = value; - this.notifySelectionChanged(); - }, - applyInsertFormatting: function(text) { - var formatting = this.nextInsertFormatting; - var insertFormattingProperties = Object.keys(formatting); - if (insertFormattingProperties.length) { - text.forEach(function(run) { - insertFormattingProperties.forEach(function(property) { - run[property] = formatting[property]; - }); - }); - } - }, - wordOrdinal: function(index) { - if (index < this.words.length) { - var cached = this._wordOrdinals.length; - if (cached < (index + 1)) { - var o = cached > 0 ? this._wordOrdinals[cached - 1] : 0; - for (var n = cached; n <= index; n++) { - this._wordOrdinals[n] = o; - o += this.words[n].length; - } - } - return this._wordOrdinals[index]; - } - }, - wordContainingOrdinal: function(ordinal) { - // could rewrite to be faster using binary search over this.wordOrdinal - var result; - var pos = 0; - this.words.some(function(word, i) { - if (ordinal >= pos && ordinal < (pos + word.length)) { - result = { - word: word, - ordinal: pos, - index: i, - offset: ordinal - pos - }; - return true; - } - pos += word.length; - }); - return result; - }, - runs: function(emit, range) { - var startDetails = this.wordContainingOrdinal(Math.max(0, range.start)), - endDetails = this.wordContainingOrdinal(Math.min(range.end, this.frame.length - 1)); - if (startDetails.index === endDetails.index) { - startDetails.word.runs(emit, { - start: startDetails.offset, - end: endDetails.offset - }); - } else { - startDetails.word.runs(emit, { start: startDetails.offset }); - for (var n = startDetails.index + 1; n < endDetails.index; n++) { - this.words[n].runs(emit); - } - endDetails.word.runs(emit, { end: endDetails.offset }); - } - }, - spliceWordsWithRuns: function(wordIndex, count, runs) { - var self = this; + if (typeof (_valuesEnd[property]) === 'string') { + _valuesStartRepeat[property] = _valuesStartRepeat[property] + parseFloat(_valuesEnd[property]); + } + + if (_yoyo) { + var tmp = _valuesStartRepeat[property]; + + _valuesStartRepeat[property] = _valuesEnd[property]; + _valuesEnd[property] = tmp; + } - var newWords = per(characters(runs)) - .per(split(self.codes)) - .truthy() - .map(function(w) { - return word(w, self.codes); - }) - .all(); + _valuesStart[property] = _valuesStartRepeat[property]; - // Check if old or new content contains any fancy control codes: - var runFilters = false; + } - if ('_filtersRunning' in self) { - self._filtersRunning++; - } else { - for (var n = 0; n < count; n++) { - if (this.words[wordIndex + n].code()) { - runFilters = true; - } - } - if (!runFilters) { - runFilters = newWords.some(function(word) { - return !!word.code(); - }); - } - } + if (_yoyo) { + _reversed = !_reversed; + } - this.transaction(function(log) { - makeEditCommand(self, wordIndex, count, newWords)(log); - if (runFilters) { - self._filtersRunning = 0; - try { - for (;;) { - var spliceCount = self._filtersRunning; - if (!self.editFilters.some(function(filter) { - filter(self); - return spliceCount !== self._filtersRunning; - })) { - break; // No further changes were made - } - } - } finally { - delete self._filtersRunning; - } - } - }); - }, - splice: function(start, end, text) { - if (typeof text === 'string') { - var sample = Math.max(0, start - 1); - var sampleRun = per({ start: sample, end: sample + 1 }) - .per(this.runs, this) - .first(); - text = [ - sampleRun ? Object.create(sampleRun, { text: { value: text } }) : { text: text } - ]; - } else if (!Array.isArray(text)) { - text = [{ text: text }]; - } + if (_repeatDelayTime !== undefined) { + _startTime = time + _repeatDelayTime; + } else { + _startTime = time + _delayTime; + } - this.applyInsertFormatting(text); + return true; - var startWord = this.wordContainingOrdinal(start), - endWord = this.wordContainingOrdinal(end); + } else { - var prefix; - if (start === startWord.ordinal) { - if (startWord.index > 0 && !isBreaker(this.words[startWord.index - 1])) { - startWord.index--; - var previousWord = this.words[startWord.index]; - prefix = per({}).per(previousWord.runs, previousWord).all(); - } else { - prefix = []; - } - } else { - prefix = per({ end: startWord.offset }) - .per(startWord.word.runs, startWord.word) - .all(); - } + if (_onCompleteCallback !== null) { - var suffix; - if (end === endWord.ordinal) { - if ((end === this.frame.length - 1) || isBreaker(endWord.word)) { - suffix = []; - endWord.index--; - } else { - suffix = per({}).per(endWord.word.runs, endWord.word).all(); - } - } else { - suffix = per({ start: endWord.offset }) - .per(endWord.word.runs, endWord.word) - .all(); - } + _onCompleteCallback.call(_object, _object); + } - var oldLength = this.frame.length; + for (var i = 0, numChainedTweens = _chainedTweens.length; i < numChainedTweens; i++) { + // Make the chained tweens start exactly at the time they should, + // even if the `update()` method was called way past the duration of the tween + _chainedTweens[i].start(_startTime + _duration); + } - this.spliceWordsWithRuns(startWord.index, (endWord.index - startWord.index) + 1, - per(prefix).concat(text).concat(suffix).per(runs.consolidate()).all()); + return false; - return this.frame ? (this.frame.length - oldLength) : 0; - }, - registerEditFilter: function(filter) { - this.editFilters.push(filter); - }, - width: function(width) { - if (arguments.length === 0) { - return this._width; - } - this._width = width; - this.layout(); - }, - children: function() { - return [this.frame]; - }, - toggleCaret: function() { - var old = this.caretVisible; - if (this.selection.start === this.selection.end) { - if (this.selectionJustChanged) { - this.selectionJustChanged = false; - } else { - this.caretVisible = !this.caretVisible; - } - } - return this.caretVisible !== old; - }, - getCaretCoords: function(ordinal) { - var node = this.byOrdinal(ordinal), b; - if (node) { - if (node.block && ordinal > 0) { - var nodeBefore = this.byOrdinal(ordinal - 1); - if (nodeBefore.newLine) { - var newLineBounds = nodeBefore.bounds(); - var lineBounds = nodeBefore.parent().parent().bounds(); - b = rect(lineBounds.l, lineBounds.b, 1, newLineBounds.h); - } else { - b = nodeBefore.bounds(); - b = rect(b.r, b.t, 1, b.h); - } - } else { - b = node.bounds(); - if (b.h) { - b = rect(b.l, b.t, 1, b.h); - } else { - b = rect(b.l, b.t, b.w, 1); - } - } - return b; - } - }, - byCoordinate: function(x, y) { - var ordinal = this.frame.byCoordinate(x, y).ordinal; - var caret = this.getCaretCoords(ordinal); - while (caret.b <= y && ordinal < (this.frame.length - 1)) { - ordinal++; - caret = this.getCaretCoords(ordinal); - } - while (caret.t >= y && ordinal > 0) { - ordinal--; - caret = this.getCaretCoords(ordinal); - } - return this.byOrdinal(ordinal); - }, - drawSelection: function(ctx, hasFocus) { - if (this.selection.end === this.selection.start) { - if (this.selectionJustChanged || hasFocus && this.caretVisible) { - var caret = this.getCaretCoords(this.selection.start); - if (caret) { - ctx.save(); - ctx.fillStyle = 'black'; - caret.fill(ctx); - ctx.restore(); - } - } - } else { - ctx.save(); - ctx.fillStyle = hasFocus ? 'rgba(0, 100, 200, 0.3)' : 'rgba(160, 160, 160, 0.3)'; - this.selectedRange().parts(function(part) { - part.bounds(true).fill(ctx); - }); - ctx.restore(); - } - }, - notifySelectionChanged: function(takeFocus) { - // When firing selectionChanged, we pass a function can be used - // to obtain the formatting, as this highly likely to be needed - var cachedFormatting = null; - var self = this; - var getFormatting = function() { - if (!cachedFormatting) { - cachedFormatting = self.selectedRange().getFormatting(); - } - return cachedFormatting; - }; - this.selectionChanged.fire(getFormatting, takeFocus); - }, - select: function(ordinal, ordinalEnd, takeFocus) { - if (!this.frame) { - // Something has gone terribly wrong - doc.transaction will rollback soon - return; - } - this.selection.start = Math.max(0, ordinal); - this.selection.end = Math.min( - typeof ordinalEnd === 'number' ? ordinalEnd : this.selection.start, - this.frame.length - 1 - ); - this.selectionJustChanged = true; - this.caretVisible = true; - this.nextInsertFormatting = {}; + } + + } + + return true; + + }; + + }; + + + TWEEN.Easing = { + + Linear: { + + None: function (k) { + + return k; + + } + + }, + + Quadratic: { + + In: function (k) { + + return k * k; + + }, + + Out: function (k) { + + return k * (2 - k); + + }, + + InOut: function (k) { + + if ((k *= 2) < 1) { + return 0.5 * k * k; + } - /* NB. always fire this even if the positions stayed the same. The - event means that the formatting of the selection has changed - (which can happen either by moving the selection range or by - altering the formatting) - */ - this.notifySelectionChanged(takeFocus); - }, - performUndo: function(redo) { - var fromStack = redo ? this.redo : this.undo, - toStack = redo ? this.undo : this.redo, - oldCommand = fromStack.pop(); + return - 0.5 * (--k * (k - 2) - 1); - if (oldCommand) { - oldCommand(function(newCommand) { - toStack.push(newCommand); - }); - this.layout(); - this.contentChanged.fire(); - } - }, - canUndo: function(redo) { - return redo ? !!this.redo.length : !!this.undo.length; - }, - transaction: function(perform) { - if (this._currentTransaction) { - perform(this._currentTransaction); - } else { - var self = this; - while (this.undo.length > 50) { - self.undo.shift(); - } - this.redo.length = 0; - var changed = false; - this.undo.push(makeTransaction(function(log) { - self._currentTransaction = log; - try { - perform(log); - } finally { - changed = log.length > 0; - self._currentTransaction = null; - } - })); - if (changed) { - self.layout(); - self.contentChanged.fire(); - } - } - }, - type: 'document' - }); + } - exports = module.exports = function() { - var doc = Object.create(prototype); - doc._width = 0; - doc.selection = { start: 0, end: 0 }; - doc.caretVisible = true; - doc.customCodes = function(code, data, allCodes) {}; - doc.codes = function(code, data) { - var instance = codes(code, data, doc.codes); - return instance || doc.customCodes(code, data, doc.codes); - }; - doc.selectionChanged = util.event(); - doc.contentChanged = util.event(); - doc.editFilters = [codes.editFilter]; - doc.load([]); - return doc; - }; + }, + Cubic: { -/***/ }, -/* 35 */ -/***/ function(module, exports, __webpack_require__) { + In: function (k) { - var runs = __webpack_require__(30); + return k * k * k; - var compatible = function(a, b) { - if (a._runs !== b._runs) { - throw new Error('Characters for different documents'); - } - }; + }, - var prototype = { - equals: function(other) { - compatible(this, other); - return this._run === other._run && this._offset === other._offset; - }, - cut: function(upTo) { - compatible(this, upTo); - var self = this; - return function(eachRun) { - for (var runIndex = self._run; runIndex <= upTo._run; runIndex++) { - var run = self._runs[runIndex]; - if (run) { - var start = (runIndex === self._run) ? self._offset : 0; - var stop = (runIndex === upTo._run) ? upTo._offset : runs.getTextLength(run.text); - if (start < stop) { - runs.getSubText(function(piece) { - var pieceRun = Object.create(run); - pieceRun.text = piece; - eachRun(pieceRun); - }, run.text, start, stop - start); - } - } - } - }; - } - }; + Out: function (k) { - function character(runArray, run, offset) { - return Object.create(prototype, { - _runs: { value: runArray }, - _run: { value: run }, - _offset: { value: offset }, - char: { - value: run >= runArray.length ? null : - runs.getTextChar(runArray[run].text, offset) - } - }); - } + return --k * k * k + 1; - function firstNonEmpty(runArray, n) { - for (; n < runArray.length; n++) { - if (runs.getTextLength(runArray[n].text) != 0) { - return character(runArray, n, 0); - } - } - return character(runArray, runArray.length, 0); - } + }, - module.exports = function(runArray) { - return function(emit) { - var c = firstNonEmpty(runArray, 0); - while (!emit(c) && (c.char !== null)) { - c = (c._offset + 1 < runs.getTextLength(runArray[c._run].text)) - ? character(runArray, c._run, c._offset + 1) - : firstNonEmpty(runArray, c._run + 1); - } - }; - }; + InOut: function (k) { -/***/ }, -/* 36 */ -/***/ function(module, exports) { + if ((k *= 2) < 1) { + return 0.5 * k * k * k; + } - /* Creates a stateful transformer function that consumes Characters and produces "word coordinate" - objects, which are triplets of Characters representing the first characters of: + return 0.5 * ((k -= 2) * k * k + 2); - start - the word itself - end - any trailing whitespace - next - the subsequent word, or end of document. + } - Newline characters are NOT whitespace. They are always emitted as separate single-character - words. + }, - If start.equals(end) then the "word" only contains whitespace and so must represent spaces - at the start of a line. So even in this case, whitespace is always treated as "trailing - after" a word - even if that word happens to be zero characters long! - */ + Quartic: { - module.exports = function(codes) { + In: function (k) { - var word = null, trailingSpaces = null, newLine = true; + return k * k * k * k; - return function(emit, inputChar) { + }, - var endOfWord; - if (inputChar.char === null) { - endOfWord = true; - } else { - if (newLine) { - endOfWord = true; - newLine = false; - } - if (typeof inputChar.char === 'string') { - switch (inputChar.char) { - case ' ': - if (!trailingSpaces) { - trailingSpaces = inputChar; - } - break; - case '\n': - endOfWord = true; - newLine = true; - break; - default: - if (trailingSpaces) { - endOfWord = true; - } - } - } else { - var code = codes(inputChar.char); - if (code.block || code.eof) { - endOfWord = true; - newLine = true; - } - } - } - if (endOfWord) { - if (word && !word.equals(inputChar)) { - if (emit({ - text: word, - spaces: trailingSpaces || inputChar, - end: inputChar - }) === false) { - return false; - } - trailingSpaces = null; - } - if (inputChar.char === null) { - emit(null); // Indicate end of stream - } + Out: function (k) { + + return 1 - (--k * k * k * k); + + }, + + InOut: function (k) { + + if ((k *= 2) < 1) { + return 0.5 * k * k * k * k; + } + + return - 0.5 * ((k -= 2) * k * k * k - 2); + + } + + }, + + Quintic: { + + In: function (k) { + + return k * k * k * k * k; + + }, + + Out: function (k) { + + return --k * k * k * k * k + 1; + + }, + + InOut: function (k) { + + if ((k *= 2) < 1) { + return 0.5 * k * k * k * k * k; + } + + return 0.5 * ((k -= 2) * k * k * k * k + 2); + + } + + }, - word = inputChar; - } - }; - }; + Sinusoidal: { + In: function (k) { -/***/ }, -/* 37 */ -/***/ function(module, exports, __webpack_require__) { + return 1 - Math.cos(k * Math.PI / 2); - var per = __webpack_require__(29); - var part = __webpack_require__(38); - var runs = __webpack_require__(30); + }, - /* A Word has the following properties: + Out: function (k) { - text - Section (see below) for non-space portion of word. - space - Section for trailing space portion of word. - ascent - Ascent (distance from baseline to top) for whole word - descent - Descent (distance from baseline to bottom) for whole word - width - Width of the whole word (including trailing space) + return Math.sin(k * Math.PI / 2); - It has methods: + }, - isNewLine() - - Returns true if the Word represents a newline. Newlines are - always represented by separate words. + InOut: function (k) { - draw(ctx, x, y) - - Draws the Word at x, y on the canvas context ctx. + return 0.5 * (1 - Math.cos(Math.PI * k)); - Note: a section (i.e. text and space) is an object containing: + } - parts - array of Parts - ascent - Ascent (distance from baseline to top) for whole section - descent - Descent (distance from baseline to bottom) for whole section - width - Width of the whole section - */ + }, - var prototype = { - isNewLine: function() { - return this.text.parts.length == 1 && this.text.parts[0].isNewLine; - }, - code: function() { - return this.text.parts.length == 1 && this.text.parts[0].code; - }, - codeFormatting: function() { - return this.text.parts.length == 1 && this.text.parts[0].run; - }, - draw: function(ctx, x, y) { - per(this.text.parts).concat(this.space.parts).forEach(function(part) { - part.draw(ctx, x, y); - x += part.width; - }); - }, - plainText: function() { - return this.text.plainText + this.space.plainText; - }, - align: function() { - var first = this.text.parts[0]; - return first ? first.run.align : 'left'; - }, - runs: function(emit, range) { - var start = range && range.start || 0, - end = range && range.end; - if (typeof end !== 'number') { - end = Number.MAX_VALUE; - } - [this.text, this.space].forEach(function(section) { - section.parts.some(function(part) { - if (start >= end || end <= 0) { - return true; - } - var run = part.run, text = run.text; - if (typeof text === 'string') { - if (start <= 0 && end >= text.length) { - emit(run); - } else if (start < text.length) { - var pieceRun = Object.create(run); - var firstChar = Math.max(0, start); - pieceRun.text = text.substr( - firstChar, - Math.min(text.length, end - firstChar) - ); - emit(pieceRun); - } - start -= text.length; - end -= text.length; - } else { - if (start <= 0 && end >= 1) { - emit(run); - } - start--; - end--; - } - }); - }); - } - }; + Exponential: { - var section = function(runEmitter, codes) { - var s = { - parts: per(runEmitter).map(function(p) { - return part(p, codes); - }).all(), - ascent: 0, - descent: 0, - width: 0, - length: 0, - plainText: '' - }; - s.parts.forEach(function(p) { - s.ascent = Math.max(s.ascent, p.ascent); - s.descent = Math.max(s.descent, p.descent); - s.width += p.width; - s.length += runs.getPieceLength(p.run.text); - s.plainText += runs.getPiecePlainText(p.run.text); - }); - return s; - }; + In: function (k) { - module.exports = function(coords, codes) { - var text, space; - if (!coords) { - // special end-of-document marker, mostly like a newline with no formatting - text = [{ text: '\n' }]; - space = []; - } else { - text = coords.text.cut(coords.spaces); - space = coords.spaces.cut(coords.end); - } - text = section(text, codes); - space = section(space, codes); - var word = Object.create(prototype, { - text: { value: text }, - space: { value: space }, - ascent: { value: Math.max(text.ascent, space.ascent) }, - descent: { value: Math.max(text.descent, space.descent) }, - width: { value: text.width + space.width, configurable: true }, - length: { value: text.length + space.length } - }); - if (!coords) { - Object.defineProperty(word, 'eof', { value: true }); - } - return word; - }; + return k === 0 ? 0 : Math.pow(1024, k - 1); + }, -/***/ }, -/* 38 */ -/***/ function(module, exports, __webpack_require__) { + Out: function (k) { - var text = __webpack_require__(39); + return k === 1 ? 1 : 1 - Math.pow(2, - 10 * k); - var defaultInline = { - measure: function(formatting) { - var text = text.measure('?', formatting); - return { - width: text.width + 4, - ascent: text.width + 2, - descent: text.width + 2 - }; - }, - draw: function(ctx, x, y, width, ascent, descent) { - ctx.fillStyle = 'silver'; - ctx.fillRect(x, y - ascent, width, ascent + descent); - ctx.strokeRect(x, y - ascent, width, ascent + descent); - ctx.fillStyle = 'black'; - ctx.fillText('?', x + 2, y); - } - }; + }, - /* A Part is a section of a word with its own run, because a Word can span the - boundaries between runs, so it may have several parts in its text or space - arrays. + InOut: function (k) { - run - Run being measured. - isNewLine - True if this part only contain a newline (\n). This will be - the only Part in the Word, and this is the only way newlines - ever occur. - width - Width of the run - ascent - Distance from baseline to top - descent - Distance from baseline to bottom + if (k === 0) { + return 0; + } - And methods: + if (k === 1) { + return 1; + } - draw(ctx, x, y) - - Draws the Word at x, y on the canvas context ctx. The y - coordinate is assumed to be the baseline. The call - prepareContext(ctx) will set the canvas up appropriately. - */ - var prototype = { - draw: function(ctx, x, y) { - if (typeof this.run.text === 'string') { - text.draw(ctx, this.run.text, this.run, x, y, this.width, this.ascent, this.descent); - } else if (this.code && this.code.draw) { - ctx.save(); - this.code.draw(ctx, x, y, this.width, this.ascent, this.descent, this.run); - ctx.restore(); - } - } - }; + if ((k *= 2) < 1) { + return 0.5 * Math.pow(1024, k - 1); + } - module.exports = function(run, codes) { + return 0.5 * (- Math.pow(2, - 10 * (k - 1)) + 2); - var m, isNewLine, code; - if (typeof run.text === 'string') { - isNewLine = (run.text.length === 1) && (run.text[0] === '\n'); - m = text.measure(isNewLine ? text.nbsp : run.text, run); - } else { - code = codes(run.text) || defaultInline; - m = code.measure ? code.measure(run) : { - width: 0, ascent: 0, descent: 0 - }; - } + } + + }, + + Circular: { + + In: function (k) { + + return 1 - Math.sqrt(1 - k * k); + + }, + + Out: function (k) { + + return Math.sqrt(1 - (--k * k)); + + }, + + InOut: function (k) { + + if ((k *= 2) < 1) { + return - 0.5 * (Math.sqrt(1 - k * k) - 1); + } + + return 0.5 * (Math.sqrt(1 - (k -= 2) * k) + 1); + + } + + }, + + Elastic: { + + In: function (k) { + + if (k === 0) { + return 0; + } - var part = Object.create(prototype, { - run: { value: run }, - isNewLine: { value: isNewLine }, - width: { value: isNewLine ? 0 : m.width }, - ascent: { value: m.ascent }, - descent: { value: m.descent } - }); - if (code) { - Object.defineProperty(part, 'code', { value: code }); - } - return part; - }; + if (k === 1) { + return 1; + } + return -Math.pow(2, 10 * (k - 1)) * Math.sin((k - 1.1) * 5 * Math.PI); -/***/ }, -/* 39 */ -/***/ function(module, exports, __webpack_require__) { + }, - var runs = __webpack_require__(30); + Out: function (k) { - /* Returns a font CSS/Canvas string based on the settings in a run - */ - var getFontString = exports.getFontString = function(run) { + if (k === 0) { + return 0; + } - var size = (run && run.size) || runs.defaultFormatting.size; + if (k === 1) { + return 1; + } - if (run) { - switch (run.script) { - case 'super': - case 'sub': - size *= 0.8; - break; - } - } + return Math.pow(2, -10 * k) * Math.sin((k - 0.1) * 5 * Math.PI) + 1; - return (run && run.italic ? 'italic ' : '') + - (run && run.bold ? 'bold ' : '') + ' ' + - size + 'pt ' + - ((run && run.font) || runs.defaultFormatting.font); - }; + }, - /* Applies the style of a run to the canvas context - */ - exports.applyRunStyle = function(ctx, run) { - ctx.fillStyle = (run && run.color) || runs.defaultFormatting.color; - ctx.font = getFontString(run); - }; + InOut: function (k) { - exports.prepareContext = function(ctx) { - ctx.textAlign = 'left'; - ctx.textBaseline = 'alphabetic'; - }; + if (k === 0) { + return 0; + } - /* Generates the value for a CSS style attribute - */ - exports.getRunStyle = function(run) { - var parts = [ - 'font: ', getFontString(run), - '; color: ', ((run && run.color) || runs.defaultFormatting.color) - ]; + if (k === 1) { + return 1; + } - if (run) { - switch (run.script) { - case 'super': - parts.push('; vertical-align: super'); - break; - case 'sub': - parts.push('; vertical-align: sub'); - break; - } - } + k *= 2; - return parts.join(''); - }; + if (k < 1) { + return -0.5 * Math.pow(2, 10 * (k - 1)) * Math.sin((k - 1.1) * 5 * Math.PI); + } - var nbsp = exports.nbsp = String.fromCharCode(160); - var enter = exports.enter = nbsp; // String.fromCharCode(9166); + return 0.5 * Math.pow(2, -10 * (k - 1)) * Math.sin((k - 1.1) * 5 * Math.PI) + 1; - /* Returns width, height, ascent, descent in pixels for the specified text and font. - The ascent and descent are measured from the baseline. Note that we add/remove - all the DOM elements used for a measurement each time - this is not a significant - part of the cost, and if we left the hidden measuring node in the DOM then it - would affect the dimensions of the whole page. - */ - var measureText = exports.measureText = function(text, style) { - var span, block, div; + } - span = document.createElement('span'); - block = document.createElement('div'); - div = document.createElement('div'); + }, - block.style.display = 'inline-block'; - block.style.width = '1px'; - block.style.height = '0'; + Back: { - div.style.visibility = 'hidden'; - div.style.position = 'absolute'; - div.style.top = '0'; - div.style.left = '0'; - div.style.width = '500px'; - div.style.height = '200px'; + In: function (k) { - div.appendChild(span); - div.appendChild(block); - document.body.appendChild(div); - try { - span.setAttribute('style', style); + var s = 1.70158; - span.innerHTML = ''; - span.appendChild(document.createTextNode(text.replace(/\s/g, nbsp))); + return k * k * ((s + 1) * k - s); - var result = {}; - block.style.verticalAlign = 'baseline'; - result.ascent = (block.offsetTop - span.offsetTop); - block.style.verticalAlign = 'bottom'; - result.height = (block.offsetTop - span.offsetTop); - result.descent = result.height - result.ascent; - result.width = span.offsetWidth; - } finally { - div.parentNode.removeChild(div); - div = null; - } - return result; - }; + }, - /* Create a function that works like measureText except it caches every result for every - unique combination of (text, style) - that is, it memoizes measureText. + Out: function (k) { - So for example: + var s = 1.70158; - var measure = cachedMeasureText(); + return --k * k * ((s + 1) * k + s) + 1; - Then you can repeatedly do lots of separate calls to measure, e.g.: + }, - var m = measure('Hello, world', 'font: 12pt Arial'); - console.log(m.ascent, m.descent, m.width); + InOut: function (k) { - A cache may grow without limit if the text varies a lot. However, during normal interactive - editing the growth rate will be slow. If memory consumption becomes a problem, the cache - can be occasionally discarded, although of course this will cause a slow down as the cache - has to build up again (text measuring is by far the most costly operation we have to do). - */ - var createCachedMeasureText = exports.createCachedMeasureText = function() { - var cache = {}; - return function(text, style) { - var key = style + '<>!&%' + text; - var result = cache[key]; - if (!result) { - cache[key] = result = measureText(text, style); - } - return result; - }; - }; + var s = 1.70158 * 1.525; - exports.cachedMeasureText = createCachedMeasureText(); + if ((k *= 2) < 1) { + return 0.5 * (k * k * ((s + 1) * k - s)); + } - exports.measure = function(str, formatting) { - return exports.cachedMeasureText(str, exports.getRunStyle(formatting)); - }; + return 0.5 * ((k -= 2) * k * ((s + 1) * k + s) + 2); - exports.draw = function(ctx, str, formatting, left, baseline, width, ascent, descent) { - exports.prepareContext(ctx); - exports.applyRunStyle(ctx, formatting); - switch (formatting.script) { - case 'super': - baseline -= (ascent * (1/3)); - break; - case 'sub': - baseline += (descent / 2); - break; - } - ctx.fillText(str === '\n' ? exports.enter : str, left, baseline); - if (formatting.underline) { - ctx.fillRect(left, 1 + baseline, width, 1); - } - if (formatting.strikeout) { - ctx.fillRect(left, 1 + baseline - (ascent/2), width, 1); - } - }; + } -/***/ }, -/* 40 */ -/***/ function(module, exports, __webpack_require__) { + }, - var per = __webpack_require__(29); - var runs = __webpack_require__(30); + Bounce: { - function Range(doc, start, end) { - this.doc = doc; - this.start = start; - this.end = end; - if (start > end) { - this.start = end; - this.end = start; - } - } + In: function (k) { - Range.prototype.parts = function(emit, list) { - list = list || this.doc.children(); - var self = this; + return 1 - TWEEN.Easing.Bounce.Out(1 - k); - list.some(function(item) { - if (item.ordinal + item.length <= self.start) { - return false; - } - if (item.ordinal >= self.end) { - return true; - } - if (item.ordinal >= self.start && - item.ordinal + item.length <= self.end) { - emit(item); - } else { - self.parts(emit, item.children()); - } - }); - }; + }, - Range.prototype.clear = function() { - return this.setText([]); - }; + Out: function (k) { - Range.prototype.setText = function(text) { - return this.doc.splice(this.start, this.end, text); - }; + if (k < (1 / 2.75)) { + return 7.5625 * k * k; + } else if (k < (2 / 2.75)) { + return 7.5625 * (k -= (1.5 / 2.75)) * k + 0.75; + } else if (k < (2.5 / 2.75)) { + return 7.5625 * (k -= (2.25 / 2.75)) * k + 0.9375; + } else { + return 7.5625 * (k -= (2.625 / 2.75)) * k + 0.984375; + } + + }, + + InOut: function (k) { + + if (k < 0.5) { + return TWEEN.Easing.Bounce.In(k * 2) * 0.5; + } - Range.prototype.runs = function(emit) { - this.doc.runs(emit, this); - }; + return TWEEN.Easing.Bounce.Out(k * 2 - 1) * 0.5 + 0.5; - Range.prototype.plainText = function() { - return per(this.runs, this).map(runs.getPlainText).all().join(''); - }; + } - Range.prototype.save = function() { - return per(this.runs, this).per(runs.consolidate()).all(); - }; + } - Range.prototype.getFormatting = function() { - var range = this; - if (range.start === range.end) { - var pos = range.start; - // take formatting of character before, if any, because that's - // where plain text picks up formatting when inserted - if (pos > 0) { - pos--; - } - range.start = pos; - range.end = pos + 1; - } - return per(range.runs, range).reduce(runs.merge).last() || runs.defaultFormatting; }; - Range.prototype.setFormatting = function(attribute, value) { - var range = this; - if (attribute === 'align') { - // Special case: expand selection to surrounding paragraphs - range = range.doc.paragraphRange(range.start, range.end); - } - if (range.start === range.end) { - range.doc.modifyInsertFormatting(attribute, value); - } else { - var saved = range.save(); - var template = {}; - template[attribute] = value; - runs.format(saved, template); - range.setText(saved); - } - }; + TWEEN.Interpolation = { - module.exports = function(doc, start, end) { - return new Range(doc, start, end); - }; + Linear: function (v, k) { -/***/ }, -/* 41 */ -/***/ function(module, exports, __webpack_require__) { + var m = v.length - 1; + var f = m * k; + var i = Math.floor(f); + var fn = TWEEN.Interpolation.Utils.Linear; - var node = __webpack_require__(28); - var wrap = __webpack_require__(42); - var rect = __webpack_require__(31); + if (k < 0) { + return fn(v[0], v[1], f); + } - var prototype = node.derive({ - bounds: function() { - if (!this._bounds) { - var left = 0, top = 0, right = 0, bottom = 0; - if (this.lines.length) { - var first = this.lines[0].bounds(); - left = first.l; - top = first.t; - this.lines.forEach(function(line) { - var b = line.bounds(); - right = Math.max(right, b.l + b.w); - bottom = Math.max(bottom, b.t + b.h); - }); - } - this._bounds = rect(left, top, right - left, this.height || bottom - top); - } - return this._bounds; - }, - actualWidth: function() { - if (!this._actualWidth) { - var result = 0; - this.lines.forEach(function(line) { - if (typeof line.actualWidth === 'number') { - result = Math.max(result, line.actualWidth); - } - }); - this._actualWidth = result; - } - return this._actualWidth; - }, - children: function() { - return this.lines; - }, - parent: function() { - return this._parent; - }, - draw: function(ctx, viewPort) { - var top = viewPort ? viewPort.t : 0; - var bottom = viewPort ? (viewPort.t + viewPort.h) : Number.MAX_VALUE; - this.lines.some(function(line) { - var b = line.bounds(); - if (b.t + b.h < top) { - return false; - } - if (b.t > bottom) { - return true; - } - line.draw(ctx, viewPort); - }); - }, - type: 'frame' - }); + if (k > 1) { + return fn(v[m], v[m - 1], m - f); + } - exports = module.exports = function(left, top, width, ordinal, parent, - includeTerminator, initialAscent, initialDescent) { - var lines = []; - var frame = Object.create(prototype, { - lines: { value: lines }, - _parent: { value: parent }, - ordinal: { value: ordinal } - }); - var wrapper = wrap(left, top, width, ordinal, frame, includeTerminator, initialAscent, initialDescent); - var length = 0, height = 0; - return function(emit, word) { - if (wrapper(function(line) { - if (typeof line === 'number') { - height = line; - } else { - length = (line.ordinal + line.length) - ordinal; - lines.push(line); - } - }, word)) { - Object.defineProperty(frame, 'length', { value: length }); - Object.defineProperty(frame, 'height', { value: height }); - emit(frame); - return true; - } - }; - }; + return fn(v[i], v[i + 1 > m ? m : i + 1], f - i); + }, -/***/ }, -/* 42 */ -/***/ function(module, exports, __webpack_require__) { + Bezier: function (v, k) { - var line = __webpack_require__(43); + var b = 0; + var n = v.length - 1; + var pw = Math.pow; + var bn = TWEEN.Interpolation.Utils.Bernstein; - /* A stateful transformer function that accepts words and emits lines. If the first word - is too wide, it will overhang; if width is zero or negative, there will be one word on - each line. + for (var i = 0; i <= n; i++) { + b += pw(1 - k, n - i) * pw(k, i) * v[i] * bn(n, i); + } - The y-coordinate is the top of the first line, not the baseline. + return b; - Returns a stream of line objects, each containing an array of positionedWord objects. - */ + }, - module.exports = function(left, top, width, ordinal, parent, - includeTerminator, initialAscent, initialDescent) { + CatmullRom: function (v, k) { - var lineBuffer = [], - lineWidth = 0, - maxAscent = initialAscent || 0, - maxDescent = initialDescent || 0, - quit, - lastNewLineHeight = 0, - y = top; + var m = v.length - 1; + var f = m * k; + var i = Math.floor(f); + var fn = TWEEN.Interpolation.Utils.CatmullRom; - var store = function(word, emit) { - lineBuffer.push(word); - lineWidth += word.width; - maxAscent = Math.max(maxAscent, word.ascent); - maxDescent = Math.max(maxDescent, word.descent); - if (word.isNewLine()) { - send(emit); - lastNewLineHeight = word.ascent + word.descent; - } - }; + if (v[0] === v[m]) { - var send = function(emit) { - if (quit || lineBuffer.length === 0) { - return; - } - var l = line(parent, left, width, y + maxAscent, maxAscent, maxDescent, lineBuffer, ordinal); - ordinal += l.length; - quit = emit(l); - y += (maxAscent + maxDescent); - lineBuffer.length = 0; - lineWidth = maxAscent = maxDescent = 0; - }; + if (k < 0) { + i = Math.floor(f = m * (1 + k)); + } - var consumer = null; + return fn(v[(i - 1 + m) % m], v[i], v[(i + 1) % m], v[(i + 2) % m], f - i); - return function(emit, inputWord) { - if (consumer) { - lastNewLineHeight = 0; - var node = consumer(inputWord); - if (node) { - consumer = null; - ordinal += node.length; - y += node.bounds().h; - Object.defineProperty(node, 'block', { value: true }); - emit(node); - } - } else { - var code = inputWord.code(); - if (code && code.block) { - if (lineBuffer.length) { - send(emit); - } else { - y += lastNewLineHeight; - } - consumer = code.block(left, y, width, ordinal, parent, inputWord.codeFormatting()); - lastNewLineHeight = 0; - } - else if (code && code.eof || inputWord.eof) { - if (!code || (includeTerminator && includeTerminator(code))) { - store(inputWord, emit); - } - if (!lineBuffer.length) { - emit(y + lastNewLineHeight - top); - } else { - send(emit); - emit(y - top); - } - quit = true; - } else { - lastNewLineHeight = 0; - if (!lineBuffer.length) { - store(inputWord, emit); - } else { - if (lineWidth + inputWord.text.width > width) { - send(emit); - } - store(inputWord, emit); - } - } - } - return quit; - }; - }; + } else { + + if (k < 0) { + return v[0] - (fn(v[0], v[0], v[1], v[1], -f) - v[0]); + } + if (k > 1) { + return v[m] - (fn(v[m], v[m], v[m - 1], v[m - 1], f - m) - v[m]); + } -/***/ }, -/* 43 */ -/***/ function(module, exports, __webpack_require__) { + return fn(v[i ? i - 1 : 0], v[i], v[m < i + 1 ? m : i + 1], v[m < i + 2 ? m : i + 2], f - i); - var positionedWord = __webpack_require__(44); - var rect = __webpack_require__(31); - var node = __webpack_require__(28); - var runs = __webpack_require__(30); + } - /* A Line is returned by the wrap function. It contains an array of PositionedWord objects that are - all on the same physical line in the wrapped text. + }, - It has a width (which is actually the same for all lines returned by the same wrap). It also has - coordinates for baseline, ascent and descent. The ascent and descent have the maximum values of - the individual words' ascent and descent coordinates. + Utils: { - It has methods: + Linear: function (p0, p1, t) { - draw(ctx, x, y) - - Draw all the words in the line applying the specified (x, y) offset. - bounds() - - Returns a Rect for the bounding box. - */ + return (p1 - p0) * t + p0; - var prototype = node.derive({ - bounds: function(minimal) { - if (minimal) { - var firstWord = this.first().bounds(), - lastWord = this.last().bounds(); - return rect( - firstWord.l, - this.baseline - this.ascent, - (lastWord.l + lastWord.w) - firstWord.l, - this.ascent + this.descent); - } - return rect(this.left, this.baseline - this.ascent, - this.width, this.ascent + this.descent); - }, - parent: function() { - return this.doc; - }, - children: function() { - return this.positionedWords; - }, - type: 'line' - }); + }, - module.exports = function(doc, left, width, baseline, ascent, descent, words, ordinal) { + Bernstein: function (n, i) { - var align = words[0].align(); + var fc = TWEEN.Interpolation.Utils.Factorial; - var line = Object.create(prototype, { - doc: { value: doc }, // should be called frame, or else switch to using parent on all nodes - left: { value: left }, - width: { value: width }, - baseline: { value: baseline }, - ascent: { value: ascent }, - descent: { value: descent }, - ordinal: { value: ordinal }, - align: { value: align } - }); + return fc(n) / fc(i) / fc(n - i); - var actualWidth = 0; - words.forEach(function(word) { - actualWidth += word.width; - }); - actualWidth -= words[words.length - 1].space.width; + }, - var x = 0, spacing = 0; - if (actualWidth < width) { - switch (align) { - case 'right': - x = width - actualWidth; - break; - case 'center': - x = (width - actualWidth) / 2; - break; - case 'justify': - if (words.length > 1 && !words[words.length - 1].isNewLine()) { - spacing = (width - actualWidth) / (words.length - 1); - } - break; - } - } + Factorial: (function () { - Object.defineProperty(line, 'positionedWords', { - value: words.map(function(word) { - var wordLeft = x; - x += (word.width + spacing); - var wordOrdinal = ordinal; - ordinal += (word.text.length + word.space.length); - return positionedWord(word, line, wordLeft, wordOrdinal, word.width + spacing); - }) - }); + var a = [1]; - Object.defineProperty(line, 'actualWidth', { value: actualWidth }); - Object.defineProperty(line, 'length', { value: ordinal - line.ordinal }); - return line; - }; + return function (n) { + var s = 1; -/***/ }, -/* 44 */ -/***/ function(module, exports, __webpack_require__) { + if (a[n]) { + return a[n]; + } - var rect = __webpack_require__(31); - var part = __webpack_require__(38); - var text = __webpack_require__(39); - var node = __webpack_require__(28); - var word = __webpack_require__(37); - var runs = __webpack_require__(30); + for (var i = n; i > 1; i--) { + s *= i; + } + + a[n] = s; + return s; + + }; + + })(), + + CatmullRom: function (p0, p1, p2, p3, t) { + + var v0 = (p2 - p0) * 0.5; + var v1 = (p3 - p1) * 0.5; + var t2 = t * t; + var t3 = t * t2; + + return (2 * p1 - 2 * p2 + v0 + v1) * t3 + (- 3 * p1 + 3 * p2 - 2 * v0 - v1) * t2 + v0 * t + p1; + + } + + } - var newLineWidth = function(run) { - return text.measure(text.enter, run).width; }; - var positionedChar = node.derive({ - bounds: function() { - var wb = this.word.bounds(); - var width = this.word.word.isNewLine() - ? newLineWidth(this.word.word.run) - : this.width || this.part.width; - return rect(wb.l + this.left, wb.t, width, wb.h); - }, - parent: function() { - return this.word; - }, - byOrdinal: function() { - return this; - }, - byCoordinate: function(x, y) { - if (x <= this.bounds().center().x) { - return this; - } - return this.next(); - }, - type: 'character' - }); + // UMD (Universal Module Definition) + (function (root) { - /* A positionedWord is just a realised Word plus a reference back to the containing Line and - the left coordinate (x coordinate of the left edge of the word). + if (true) { - It has methods: + // AMD + !(__WEBPACK_AMD_DEFINE_ARRAY__ = [], __WEBPACK_AMD_DEFINE_RESULT__ = function () { + return TWEEN; + }.apply(exports, __WEBPACK_AMD_DEFINE_ARRAY__), __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__)); - draw(ctx, x, y) - - Draw the word within its containing line, applying the specified (x, y) - offset. - bounds() - - Returns a rect for the bounding box. - */ - var prototype = node.derive({ - draw: function(ctx) { - this.word.draw(ctx, this.line.left + this.left, this.line.baseline); + } else if (typeof module !== 'undefined' && typeof exports === 'object') { - // Handy for showing how word boundaries work - // var b = this.bounds(); - // ctx.strokeRect(b.l, b.t, b.w, b.h); - }, - bounds: function() { - return rect( - this.line.left + this.left, - this.line.baseline - this.line.ascent, - this.word.isNewLine() ? newLineWidth(this.word.run) : this.width, - this.line.ascent + this.line.descent); - }, - parts: function(eachPart) { - this.word.text.parts.some(eachPart) || - this.word.space.parts.some(eachPart); - }, - realiseCharacters: function() { - if (!this._characters) { - var cache = []; - var x = 0, self = this, ordinal = this.ordinal, - codes = this.parentOfType('document').codes; - this.parts(function(wordPart) { - runs.pieceCharacters(function(char) { - var charRun = Object.create(wordPart.run); - charRun.text = char; - var p = part(charRun, codes); - cache.push(Object.create(positionedChar, { - left: { value: x }, - part: { value: p }, - word: { value: self }, - ordinal: { value: ordinal }, - length: { value: 1 } - })); - x += p.width; - ordinal++; - }, wordPart.run.text); - }); - // Last character is artificially widened to match the length of the - // word taking into account (align === 'justify') - var lastChar = cache[cache.length - 1]; - if (lastChar) { - Object.defineProperty(lastChar, 'width', - { value: this.width - lastChar.left }); - if (this.word.isNewLine() || (this.word.code() && this.word.code().eof)) { - Object.defineProperty(lastChar, 'newLine', { value: true }); - } - } - this._characters = cache; - } - }, - children: function() { - this.realiseCharacters(); - return this._characters; - }, - parent: function() { - return this.line; - }, - type: 'word' - }); + // Node.js + module.exports = TWEEN; + + } else if (root !== undefined) { + + // Global variable + root.TWEEN = TWEEN; + + } + + })(this); + + /* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(10))) + +/***/ }, +/* 21 */ +/***/ function(module, exports) { - module.exports = function(word, line, left, ordinal, width) { - var pword = Object.create(prototype, { - word: { value: word }, - line: { value: line }, - left: { value: left }, - width: { value: width }, // can be different to word.width if (align == 'justify') - ordinal: { value: ordinal }, - length: { value: word.text.length + word.space.length } - }); - return pword; - }; + //! stable.js 0.1.5, https://github.com/Two-Screen/stable + //! © 2014 Angry Bytes and contributors. MIT licensed. + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + // A stable array sort, because `Array#sort()` is not guaranteed stable. + // This is an implementation of merge sort, without recursion. + function stableSort(arr, comp) { + var result = exec(arr, comp); + // This simply copies back if the result isn't in the original array, + // which happens on an odd number of passes. + if (result !== arr) { + pass(result, null, arr.length, arr); + } + return arr; + } + exports.stableSort = stableSort; + ; + // Execute the sort using the input array and a second buffer as work space. + // Returns one of those two, containing the final result. + function exec(arr, comp) { + if (typeof (comp) !== 'function') { + comp = function (a, b) { + return String(a).localeCompare(b); + }; + } + // Short-circuit when there's nothing to sort. + var len = arr.length; + if (len <= 1) { + return arr; + } + // Rather than dividing input, simply iterate chunks of 1, 2, 4, 8, etc. + // Chunks are the size of the left or right hand in merge sort. + // Stop when the left-hand covers all of the array. + var buffer = new Array(len); + for (var chk = 1; chk < len; chk *= 2) { + pass(arr, comp, chk, buffer); + var tmp = arr; + arr = buffer; + buffer = tmp; + } + return arr; + } + // Run a single pass with the given chunk size. + var pass = function (arr, comp, chk, result) { + var len = arr.length; + var i = 0; + // Step size / double chunk size. + var dbl = chk * 2; + // Bounds of the left and right chunks. + var l, r, e; + // Iterators over the left and right chunk. + var li, ri; + // Iterate over pairs of chunks. + for (l = 0; l < len; l += dbl) { + r = l + chk; + e = r + chk; + if (r > len) + r = len; + if (e > len) + e = len; + // Iterate both chunks in parallel. + li = l; + ri = r; + while (true) { + // Compare the chunks. + if (li < r && ri < e) { + // This works for a regular `sort()` compatible comparator, + // but also for a simple comparator like: `a > b` + if (comp(arr[li], arr[ri]) <= 0) { + result[i++] = arr[li++]; + } + else { + result[i++] = arr[ri++]; + } + } + else if (li < r) { + result[i++] = arr[li++]; + } + else if (ri < e) { + result[i++] = arr[ri++]; + } + else { + break; + } + } + } + }; + function assign(target, other) { + if (target === undefined || target === null) { + throw new TypeError('Cannot convert first argument to object'); + } + var to = Object(target); + for (var i = 1; i < arguments.length; i++) { + var nextSource = arguments[i]; + if (nextSource === undefined || nextSource === null) { + continue; + } + nextSource = Object(nextSource); + var keysArray = Object.keys(Object(nextSource)); + for (var nextIndex = 0, len = keysArray.length; nextIndex < len; nextIndex++) { + var nextKey = keysArray[nextIndex]; + var desc = Object.getOwnPropertyDescriptor(nextSource, nextKey); + if (desc !== undefined && desc.enumerable) { + to[nextKey] = nextSource[nextKey]; + } + } + } + return to; + } + exports.assign = assign; + function aRemove(arr, obj) { + var i = arr.indexOf(obj); + if (i >= 0) { + arr.splice(i, 1); + return true; + } + return false; + } + exports.aRemove = aRemove; + Array.prototype.forEachR = function (func) { + var n = this.length - 1; + for (var i = this.length - 1; i >= 0; i--) { + var iter = this[i]; + func(this[i], i); + } + }; + Array.prototype.stableSort = function (comp) { + stableSort(this, comp); + }; + Array.prototype.remove = function (obj) { + return aRemove(this, obj); + }; /***/ }, -/* 45 */ +/* 22 */ /***/ function(module, exports, __webpack_require__) { - var text = __webpack_require__(39); - var frame = __webpack_require__(41); - var node = __webpack_require__(28); - var rect = __webpack_require__(31); - var util = __webpack_require__(32); + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + var device_info_1 = __webpack_require__(23); + var StringTable = (function () { + function StringTable() { + } + StringTable.set = function (strTable, lang) { + if (!lang) { + lang = device_info_1.DeviceInfo.language; + } + StringTable.table[lang] = strTable; + }; + StringTable.add = function (strTable, lang) { + if (!lang) { + lang = device_info_1.DeviceInfo.language; + } + if (StringTable.table[lang]) { + var table = StringTable.table[lang]; + for (var key in strTable) { + table[key] = strTable[key]; + } + } + else { + StringTable.table[lang] = strTable; + } + }; + StringTable.get = function (lang) { + return StringTable.table[lang]; + }; + StringTable.tr = function (str) { + var lang = device_info_1.DeviceInfo.language; + var table = StringTable.table[lang]; + var tr = table ? table[str] : str; + return tr ? tr : str; + }; + return StringTable; + }()); + StringTable.table = {}; + exports.StringTable = StringTable; + ; - var inlineNodePrototype = node.derive({ - parent: function() { - return this._parent; - }, - draw: function(ctx) { - this.inline.draw(ctx, - this.left, - this.baseline, - this.measured.width, - this.measured.ascent, - this.measured.descent, - this.formatting); - }, - position: function(left, baseline, bounds) { - this.left = left; - this.baseline = baseline; - if (bounds) { - this._bounds = bounds; - } - }, - bounds: function() { - return this._bounds || rect(this.left, this.baseline - this.measured.ascent, - this.measured.width, this.measured.ascent + this.measured.descent); - }, - byCoordinate: function(x, y) { - if (x <= this.bounds().center().x) { - return this; - } - return this.next(); - } - }); - var inlineNode = function(inline, parent, ordinal, length, formatting) { - if (!inline.draw || !inline.measure) { - throw new Error(); - } - return Object.create(inlineNodePrototype, { - inline: { value: inline }, - _parent: { value: parent }, - ordinal: { value: ordinal }, - length: { value: length }, - formatting: { value: formatting }, - measured: { - value: inline.measure(formatting) - } - }); - }; +/***/ }, +/* 23 */ +/***/ function(module, exports) { - var codes = {}; + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + /** + * @class DeviceInfo + * 设备信息。可以获取语言,操作系统和浏览器等相关信息(单例对象,直接调用)。 + */ + var DeviceInfo = (function () { + function DeviceInfo() { + } + DeviceInfo.init = function (_locale, userAgent) { + DeviceInfo.locale = (_locale || navigator.language).toLowerCase(); + DeviceInfo.language = DeviceInfo.locale.split("-")[0]; + var ua = userAgent = userAgent || navigator.userAgent; + DeviceInfo.isWindowsPhone = ua.indexOf("Windows Phone") >= 0; + DeviceInfo.isAndroid = ua.indexOf("Android") >= 0; + DeviceInfo.isIPhone = ua.indexOf("iPhone;") >= 0; + DeviceInfo.isIPad = ua.indexOf("iPad;") >= 0; + DeviceInfo.isLinux = !DeviceInfo.isAndroid && ua.indexOf("Linux;") >= 0; + DeviceInfo.isMacOS = !DeviceInfo.isIPhone && !DeviceInfo.isIPad && ua.indexOf("Macintosh;") >= 0; + DeviceInfo.isWindows = !DeviceInfo.isWindowsPhone && ua.indexOf("Windows NT") >= 0; + DeviceInfo.isMobile = ua.indexOf("Mobile") >= 0; + DeviceInfo.isPointerSupported = window.navigator.pointerEnabled; + DeviceInfo.isMSPointerSupported = window.navigator.msPointerEnabled; + var msTouchEnabled = !!window.navigator.msMaxTouchPoints; + var generalTouchEnabled = "ontouchstart" in document.createElement("div"); + DeviceInfo.isTouchSupported = !!msTouchEnabled || generalTouchEnabled; + }; + return DeviceInfo; + }()); + exports.DeviceInfo = DeviceInfo; - codes.number = function(obj, number) { - var formattedNumber = (number + 1) + '.'; - return { - measure: function(formatting) { - return text.measure(formattedNumber, formatting); - }, - draw: function(ctx, x, y, width, ascent, descent, formatting) { - text.draw(ctx, formattedNumber, formatting, x, y, width, ascent, descent); - } - }; - }; - var listTerminator = function(obj) { - return util.derive(obj, { - eof: true, - measure: function(formatting) { - return { width: 18, ascent: 0, descent: 0 }; // text.measure(text.enter, formatting); - }, - draw: function(ctx, x, y) { - // ctx.fillText(text.enter, x, y); - } - }); - }; +/***/ }, +/* 24 */ +/***/ function(module, exports, __webpack_require__) { - codes.listNext = codes.listEnd = listTerminator; + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + var factory_1 = __webpack_require__(25); + /** + * Widget工厂,注册控件的创建函数和根据控件的类型创建控件。 + * 主要用于根据UI编辑器生成的UI数据创建UI,每个控件都要向WidgetFactory注册。 + * + * 示例: + * ``` + * WidgetFactory.register(Button.TYPE, Button.create); + * ``` + * + */ + var WidgetFactory = (function () { + function WidgetFactory() { + } + WidgetFactory.register = function (type, creator) { + return WidgetFactory.factory.register(type, creator); + }; + WidgetFactory.create = function (type, options) { + return WidgetFactory.factory.create(type, options); + }; + WidgetFactory.createWithJson = function (json) { + var widget = WidgetFactory.create(json.type); + widget.fromJson(json); + return widget; + }; + return WidgetFactory; + }()); + WidgetFactory.factory = new factory_1.Factory(); + exports.WidgetFactory = WidgetFactory; - codes.listStart = function(obj, data, allCodes) { - return util.derive(obj, { - block: function(left, top, width, ordinal, parent, formatting) { - var list = node.generic('list', parent, left, top), - itemNode, - itemFrame, - itemMarker; - var indent = 50, spacing = 10; +/***/ }, +/* 25 */ +/***/ function(module, exports) { - var startItem = function(code, formatting) { - itemNode = node.generic('item', list); - var marker = allCodes(code.marker || { $: 'number' }, list.children().length); - itemMarker = inlineNode(marker, itemNode, ordinal, 1, formatting); - itemMarker.block = true; - itemFrame = frame( - left + indent, top, width - indent, ordinal + 1, itemNode, - function(terminatorCode) { - return terminatorCode.$ === 'listEnd'; - }, - itemMarker.measured.ascent - ); - }; + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + /** + * 一个通用的工厂类。 + */ + var Factory = (function () { + function Factory() { + this.creators = {}; + } + Factory.prototype.register = function (type, creator) { + this.creators[type] = creator; + }; + Factory.prototype.create = function (type, options) { + var obj = null; + var creator = this.creators[type]; + if (creator) { + obj = creator(options); + } + return obj; + }; + return Factory; + }()); + exports.Factory = Factory; - startItem(obj, formatting); - return function(inputWord) { - if (itemFrame) { - itemFrame(function(finishedFrame) { - ordinal = finishedFrame.ordinal + finishedFrame.length; - var frameBounds = finishedFrame.bounds(); +/***/ }, +/* 26 */ +/***/ function(module, exports, __webpack_require__) { + + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + var style_1 = __webpack_require__(3); + var carota = __webpack_require__(27); + var ut = __webpack_require__(48); + var tokenizer = ut.createTokenizerStream(); + var Token = ut.Token; + var Break = ut.Break; + var RoundType; + (function (RoundType) { + RoundType[RoundType["TL"] = 1] = "TL"; + RoundType[RoundType["TR"] = 2] = "TR"; + RoundType[RoundType["BL"] = 4] = "BL"; + RoundType[RoundType["BR"] = 8] = "BR"; + })(RoundType = exports.RoundType || (exports.RoundType = {})); + ; + var TextLine = (function () { + function TextLine() { + this.text = ""; + this.width = 0; + } + return TextLine; + }()); + exports.TextLine = TextLine; + ; + var Graphics = (function () { + function Graphics() { + } + Graphics.measureText = function (text, font) { + var ctx = Graphics.canvas.getContext("2d"); + ctx.font = font; + var width = ctx.measureText(text).width; + return width; + }; + Graphics.layoutText = function (text, maxWidth, font, _ctx) { + var ret = []; + if (!text || maxWidth < 5) { + return ret; + } + var line = new TextLine(); + var tokenizer = ut.createTokenizerStream(); + var ctx = _ctx ? _ctx : Graphics.canvas.getContext("2d"); + ctx.font = font; + tokenizer.on('token', function (token, type, action) { + var width = ctx.measureText(token).width; + switch (type) { + case Token.LF: + case Token.CR: { + ret.push(line); + line = new TextLine(); + line.text = "\n"; + ret.push(line); + line = new TextLine(); + return; + } + case Token.CL: + case Token.EX: { + line.text += token; + line.width += width; + return; + } + default: break; + } + if (line.width >= maxWidth) { + ret.push(line); + line = new TextLine(); + } + var n = token.length; + if ((line.width + width) <= maxWidth || n < 2) { + line.text += token; + line.width += width; + } + else if (type === Token.AL && action === Break.PROHIBITED && width < maxWidth) { + ret.push(line); + line = new TextLine(); + line.text = token; + line.width = width; + } + else { + for (var i = 0; i < n; i++) { + var c = token[i]; + width = ctx.measureText(c).width; + if (line.width >= maxWidth) { + ret.push(line); + line = new TextLine(); + } + line.text += c; + line.width += width; + } + } + }); + tokenizer.write(text); + tokenizer.end(); + ret.push(line); + return ret; + }; + Graphics.drawTextML = function (ctx, lines, style, r) { + var x = 0; + var y = 0; + var n = lines.length; + var lineHeight = style.textLineHeight; + var height = n * lineHeight; + switch (style.textAlign) { + case "right": { + x = r.x + r.w; + break; + } + case "center": { + x = r.x + (r.w >> 1); + break; + } + default: { + x = r.x; + break; + } + } + switch (style.textBaseline) { + case "top": { + y = r.y; + break; + } + case "bottom": { + y = r.y + r.h - height; + break; + } + default: { + y = r.y + ((r.h - height) >> 1); + break; + } + } + y = Math.max(y, 0); + x = Math.max(x, 0); + var maxY = r.y + r.h; + ctx.font = style.font; + ctx.fillStyle = style.textColor; + ctx.textAlign = style.textAlign; + ctx.textBaseline = "top"; + for (var i = 0; i < n; i++) { + var text = lines[i].text; + ctx.fillText(text, x, y, r.w); + y += lineHeight; + if ((y + lineHeight) > maxY) { + break; + } + } + return; + }; + Graphics.drawTextSL = function (ctx, text, style, r) { + var x = 0; + var y = 0; + switch (style.textAlign) { + case "right": { + x = r.x + r.w; + break; + } + case "center": { + x = r.x + (r.w >> 1); + break; + } + default: { + x = r.x; + break; + } + } + switch (style.textBaseline) { + case "top": { + y = r.y; + break; + } + case "bottom": { + y = r.y + r.h; + break; + } + default: { + y = r.y + (r.h >> 1); + break; + } + } + if (text && style.textColor) { + ctx.font = style.font; + ctx.fillStyle = style.textColor; + ctx.textAlign = style.textAlign; + ctx.textBaseline = style.textBaseline; + ctx.fillText(text, x, y); + } + }; + Graphics.drawLine = function (ctx, strokeStyle, lineWidth, x1, y1, x2, y2) { + if (strokeStyle && lineWidth > 0) { + ctx.beginPath(); + ctx.lineWidth = lineWidth; + ctx.strokeStyle = strokeStyle; + ctx.moveTo(x1, y1); + ctx.lineTo(x2, y2); + ctx.stroke(); + } + }; + Graphics.drawCircle = function (ctx, fillStyle, strokeStyle, lineWidth, x, y, r) { + if (fillStyle || (strokeStyle && lineWidth > 0)) { + ctx.beginPath(); + ctx.arc(x, y, r, 0, Math.PI * 2); + if (fillStyle) { + ctx.fillStyle = fillStyle; + ctx.fill(); + } + if (strokeStyle && lineWidth > 0) { + ctx.strokeStyle = strokeStyle; + ctx.lineWidth = 1; + ctx.stroke(); + } + } + }; + Graphics.drawRect = function (ctx, fillStyle, strokeStyle, lineWidth, x, y, w, h) { + if (fillStyle || (strokeStyle && lineWidth > 0)) { + ctx.beginPath(); + ctx.rect(x, y, w, h); + if (fillStyle) { + style_1.Style.fill(ctx, fillStyle, h); + } + if (strokeStyle && lineWidth > 0) { + ctx.lineWidth = lineWidth; + ctx.strokeStyle = strokeStyle; + ctx.stroke(); + } + } + }; + Graphics.drawRoundRect = function (ctx, fillStyle, strokeStyle, lineWidth, x, y, w, h, r, type) { + if (fillStyle || (strokeStyle && lineWidth > 0)) { + Graphics.roundRect(ctx, x, y, w, h, r, type); + if (fillStyle) { + style_1.Style.fill(ctx, fillStyle, h); + } + if (strokeStyle && lineWidth > 0) { + ctx.lineWidth = lineWidth; + ctx.strokeStyle = strokeStyle; + ctx.stroke(); + } + } + }; + Graphics.roundRect = function (ctx, x, y, w, h, r, type) { + if (!type) { + type = RoundType.TL | RoundType.TR | RoundType.BL | RoundType.BR; + } + var d = r << 1; + ctx.beginPath(); + if (d > w || d > h) { + var cx = x + (w >> 1); + var cy = y + (h >> 1); + r = Math.min(w >> 1, h >> 1); + ctx.arc(cx, cy, r, 0, Math.PI * 2); + return; + } + if (!r) { + ctx.rect(x, y, w, h); + return; + } + ctx.translate(x, y); + if (type & RoundType.TL) { + ctx.moveTo(0, r); + ctx.quadraticCurveTo(0, 0, r, 0); + } + else { + ctx.moveTo(0, 0); + } + if (type & RoundType.TR) { + ctx.lineTo(w - r, 0); + ctx.quadraticCurveTo(w, 0, w, r); + } + else { + ctx.lineTo(w, 0); + } + if (type & RoundType.BR) { + ctx.lineTo(w, h - r); + ctx.quadraticCurveTo(w, h, w - r, h); + } + else { + ctx.lineTo(w, h); + } + if (type & RoundType.BL) { + ctx.lineTo(r, h); + ctx.quadraticCurveTo(0, h, 0, h - r); + } + else { + ctx.lineTo(0, h); + } + ctx.closePath(); + ctx.translate(-x, -y); + }; + return Graphics; + }()); + Graphics.canvas = document.createElement("canvas"); + exports.Graphics = Graphics; + ; + + +/***/ }, +/* 27 */ +/***/ function(module, exports, __webpack_require__) { + + var node = __webpack_require__(28); + var editor = __webpack_require__(33); + var doc = __webpack_require__(34); + var dom = __webpack_require__(46); + var runs = __webpack_require__(30); + var html = __webpack_require__(47); + var frame = __webpack_require__(41); + var text = __webpack_require__(39); + var rect = __webpack_require__(31); + + var bundle = { + node: node, + editor: editor, + document: doc, + dom: dom, + runs: runs, + html: html, + frame: frame, + text: text, + rect: rect + }; + + module.exports = bundle; - // get first line and position marker - var firstLine = finishedFrame.first(); - var markerLeft = left + indent - spacing - itemMarker.measured.width; - var markerBounds = rect(left, top, indent, frameBounds.h); - if ('baseline' in firstLine) { - itemMarker.position(markerLeft, firstLine.baseline, markerBounds); - } else { - itemMarker.position(markerLeft, top + itemMarker.measured.ascent, markerBounds); - } + if (typeof window !== 'undefined' && window.document) { + if (window.carota) { + throw new Error('Something else is called carota!'); + } + window.carota = bundle; + } - top = frameBounds.t + frameBounds.h; - itemNode.children().push(itemMarker); - itemNode.children().push(finishedFrame); - itemNode.finalize(); +/***/ }, +/* 28 */ +/***/ function(module, exports, __webpack_require__) { - list.children().push(itemNode); - itemNode = itemFrame = itemMarker = null; - }, inputWord); - } else { - ordinal++; - } + var per = __webpack_require__(29); + var runs = __webpack_require__(30); + var rect = __webpack_require__(31); + var util = __webpack_require__(32); - if (!itemFrame) { - var i = inputWord.code(); - if (i) { - if (i.$ == 'listEnd') { - list.finalize(); - return list; - } - if (i.$ == 'listNext') { - startItem(i, inputWord.codeFormatting()); - } + exports.prototype = { + children: function() { + return []; + }, + parent: function() { + return null; + }, + first: function() { + return this.children()[0]; + }, + last: function() { + return this.children()[this.children().length - 1]; + }, + next: function() { + var self = this; + for (;;) { + var parent = self.parent(); + if (!parent) { + return null; + } + var siblings = parent.children(); + var next = siblings[siblings.indexOf(self) + 1]; + if (next) { + for (;;) { + var first = next.first(); + if (!first) { + break; } + next = first; } - }; + return next; + } + self = parent; } - }); - }; - - module.exports = exports = function(obj, number, allCodes) { - var impl = codes[obj.$]; - return impl && impl(obj, number, allCodes); - }; - - exports.editFilter = function(doc) { - var balance = 0; - - if (!doc.words.some(function(word, i) { - var code = word.code(); - if (code) { - switch (code.$) { - case 'listStart': - balance++; - break; - case 'listNext': - if (balance === 0) { - doc.spliceWordsWithRuns(i, 1, [util.derive(word.codeFormatting(), { - text: { - $: 'listStart', - marker: code.marker - } - })]); - return true; - } - break; - case 'listEnd': - if (balance === 0) { - doc.spliceWordsWithRuns(i, 1, []); - } - balance--; - break; + }, + previous: function() { + var parent = this.parent(); + if (!parent) { + return null; + } + var siblings = parent.children(); + var prev = siblings[siblings.indexOf(this) - 1]; + if (prev) { + return prev; + } + var prevParent = parent.previous(); + return !prevParent ? null : prevParent.last(); + }, + byOrdinal: function(index) { + var found = null; + if (this.children().some(function(child) { + if (index >= child.ordinal && index < child.ordinal + child.length) { + found = child.byOrdinal(index); + if (found) { + return true; + } } + })) { + return found; } - })) { - if (balance > 0) { - var ending = []; - while (balance > 0) { - balance--; - ending.push({ - text: { $: 'listEnd' } - }); + return this; + }, + byCoordinate: function(x, y) { + var found; + this.children().some(function(child) { + var b = child.bounds(); + if (b.contains(x, y)) { + found = child.byCoordinate(x, y); + if (found) { + return true; + } + } + }); + if (!found) { + found = this.last(); + while (found) { + var next = found.last(); + if (!next) { + break; + } + found = next; + } + var foundNext = found.next(); + if (foundNext && foundNext.block) { + found = foundNext; } - doc.spliceWordsWithRuns(doc.words.length - 1, 0, ending); } + return found; + }, + draw: function(ctx, viewPort) { + this.children().forEach(function(child) { + child.draw(ctx, viewPort); + }); + }, + parentOfType: function(type) { + var p = this.parent(); + return p && (p.type === type ? p : p.parentOfType(type)); + }, + bounds: function() { + var l = this._left, t = this._top, r = 0, b = 0; + this.children().forEach(function(child) { + var cb = child.bounds(); + l = Math.min(l, cb.l); + t = Math.min(t, cb.t); + r = Math.max(r, cb.l + cb.w); + b = Math.max(b, cb.t + cb.h); + }); + return rect(l, t, r - l, b - t); + } + }; + + exports.derive = function(methods) { + return util.derive(exports.prototype, methods); + }; + + var generic = exports.derive({ + children: function() { + return this._children; + }, + parent: function() { + return this._parent; + }, + finalize: function(startDecrement, lengthIncrement) { + var start = Number.MAX_VALUE, end = 0; + this._children.forEach(function(child) { + start = Math.min(start, child.ordinal); + end = Math.max(end, child.ordinal + child.length); + }); + Object.defineProperty(this, 'ordinal', { value: start - (startDecrement || 0) }); + Object.defineProperty(this, 'length', { value: (lengthIncrement || 0) + end - start }); } + }); + + exports.generic = function(type, parent, left, top) { + return Object.create(generic, { + type: { value: type }, + _children: { value: [] }, + _parent: { value: parent }, + _left: { value: typeof left === 'number' ? left : Number.MAX_VALUE }, + _top: { value: typeof top === 'number' ? top : Number.MAX_VALUE } + }); }; /***/ }, -/* 46 */ +/* 29 */ +/***/ function(module, exports, __webpack_require__) { + + + (function(exportFunction) { + + function toFunc(valOrFunc, bindThis) { + if (typeof valOrFunc !== 'function') { + return Array.isArray(valOrFunc) + ? function(emit) { + return valOrFunc.some(emit); + } : function(emit) { + return emit(valOrFunc); + }; + } + if (bindThis) { + return function(emit, value) { + valOrFunc.call(bindThis, emit, value); + } + } + return valOrFunc; + } + + function Per(valOrFunc, bindThis) { + this.forEach = toFunc(valOrFunc, bindThis); + } + + function blank(emit, value) { + emit(value); + } + + function create(valOrFunc, bindThis) { + if (arguments.length === 0) { + return new Per(blank); + } + if (valOrFunc && valOrFunc instanceof Per) { + return valOrFunc; + } + return new Per(valOrFunc, bindThis) + } + + Per.prototype.per = function(valOrFunc, bindThis) { + var first = this.forEach; + var second = toFunc(valOrFunc && valOrFunc.forEach || valOrFunc, bindThis); + return create(function(emit, value) { + return first(function(firstVal) { + return second(emit, firstVal); + }, value); + }); + }; + + function lambda(expression) { + return typeof expression === 'string' + ? new Function('x', 'return ' + expression) + : expression; + } + + Per.prototype.map = function(mapFunc) { + mapFunc = lambda(mapFunc); + return this.per(function(emit, value) { + return emit(mapFunc(value)); + }); + }; + + Per.prototype.filter = function(predicate) { + predicate = lambda(predicate); + return this.per(function(emit, value) { + if (predicate(value)) { + return emit(value); + } + }); + }; + + Per.prototype.concat = function(second, secondThis) { + if (second instanceof Per) { + second = second.forEach; + } else { + second = toFunc(second, secondThis); + } + var first = this.forEach; + return create(function(emit, value) { + first(emit, value); + second(emit, value); + }); + }; + + Per.prototype.skip = function(count) { + return this.per(function(emit, value) { + if (count > 0) { + count--; + return false; + } + return emit(value); + }); + }; + + Per.prototype.take = function(count) { + return this.per(function(emit, value) { + if (count <= 0) { + return true; + } + count--; + return emit(value); + }); + }; + + Per.prototype.listen = function(untilFunc) { + return this.per(function(emit, value) { + if (untilFunc(value)) { + return true; + } + return emit(value); + }); + }; + + Per.prototype.flatten = function() { + return this.per(function(emit, array) { + return !Array.isArray(array) + ? emit(array) + : array.some(function(value) { + return emit(value); + }); + }); + }; + + Per.prototype.reduce = function(reducer, seed) { + var result = seed, started = arguments.length == 2; + return this.per(function(emit, value) { + result = started ? reducer(result, value) : value; + emit(result); + started = true; + }); + }; + + Per.prototype.multicast = function(destinations) { + if (arguments.length !== 1) { + destinations = Array.prototype.slice.call(arguments, 0); + } + destinations = destinations.map(function(destination) { + return typeof destination === 'function' ? destination : + destination instanceof Per ? destination.forEach : + ignore; + }); + return this.listen(function(value) { + var quit = true; + destinations.forEach(function(destination) { + if (!destination(ignore, value)) { + quit = false; + } + }); + return quit; + }); + }; + + function optionalLimit(limit) { + return typeof limit != 'number' ? Number.MAX_VALUE : limit; + } + + /* A passive observer - gathers results into the specified array, but + otherwise has no effect on the stream of values + */ + Per.prototype.into = function(ar, limit) { + if (!Array.isArray(ar)) { + throw new Error("into expects an array"); + } + limit = optionalLimit(limit); + return this.listen(function(value) { + if (limit <= 0) { + return true; + } + ar.push(value); + limit--; + }); + }; + + function setOrCall(obj, name) { + var prop = obj[name]; + if (typeof prop === 'function') { + return prop; + } + return function(val) { + obj[name] = val; + } + } + + /* Tracks first, last and count for the values as they go past, + up to an optional limit (see 'first' and 'last' methods). + */ + Per.prototype.monitor = function(data) { + var n = 0; + var count = setOrCall(data, 'count'), + first = setOrCall(data, 'first'), + last = setOrCall(data, 'last'), + limit = data.limit; + if (typeof limit != 'number') { + limit = Number.MAX_VALUE; + } + if (limit < 1) { + return this; + } + return this.listen(function(value) { + if (n === 0) { + first(value); + } + n++; + count(n); + last(value); + if (n >= limit) { + return true; + } + }); + }; + + /* Send a value into the pipeline without caring what emerges + (only useful if you set up monitors and/or intos, or + similar stateful observers). + */ + function ignore() { } + Per.prototype.submit = function(value) { + return this.forEach(ignore, value); + }; + + Per.prototype.all = function() { + var results = []; + this.into(results).submit(); + return results; + }; + + Per.prototype.first = function() { + var results = { limit: 1 }; + this.monitor(results).submit(); + return results.count > 0 ? results.first : (void 0); + }; + + Per.prototype.last = function() { + var results = {}; + this.monitor(results).submit(); + return results.count > 0 ? results.last : (void 0); + }; + + function truthy(value) { return !!value; } + Per.prototype.truthy = function() { return this.filter(truthy); }; + + function min(l, r) { return Math.min(l, r); } + Per.prototype.min = function() { return this.reduce(min, Number.MAX_VALUE); }; + + function max(l, r) { return Math.max(l, r); } + Per.prototype.max = function() { return this.reduce(max, Number.MIN_VALUE); }; + + function sum(l, r) { return l + r } + Per.prototype.sum = function() { return this.reduce(sum, 0); }; + + function and(l, r) { return !!(l && r) } + Per.prototype.and = function() { return this.reduce(and, true); }; + + function or(l, r) { return !!(l || r) } + Per.prototype.or = function() { return this.reduce(or, false); }; + + function not(v) { return !v } + Per.prototype.not = function() { return this.map(not); }; + + create.pulse = function(ms) { + var counter = 0; + return create(function(emit) { + function step() { + if (emit(counter++) !== true) { + setTimeout(step, ms); + } + } + step(); + }); + }; + + exportFunction(create); + + })(function(per) { + if (false) { + this['per'] = per; + } else { + module.exports = per; + } + }); + + +/***/ }, +/* 30 */ /***/ function(module, exports) { - - exports.isAttached = function(element) { - var ancestor = element; - while(ancestor.parentNode) { - ancestor = ancestor.parentNode; - } - return !!ancestor.body; - }; + exports.formattingKeys = [ 'bold', 'italic', 'underline', 'strikeout', 'color', 'font', 'size', 'align', 'script' ]; - exports.clear = function(element) { - while (element.firstChild) { - element.removeChild(element.firstChild); - } + exports.defaultFormatting = { + size: 10, + font: 'sans-serif', + color: 'black', + bold: false, + italic: false, + underline: false, + strikeout: false, + align: 'left', + script: 'normal' }; - exports.setText = function(element, text) { - exports.clear(element); - element.appendChild(document.createTextNode(text)); + exports.sameFormatting = function(run1, run2) { + return exports.formattingKeys.every(function(key) { + return run1[key] === run2[key]; + }) }; - exports.handleEvent = function(element, name, handler) { - element.addEventListener(name, function(ev) { - if (handler(ev) === false) { - ev.preventDefault(); + exports.clone = function(run) { + var result = { text: run.text }; + exports.formattingKeys.forEach(function(key) { + var val = run[key]; + if (val && val != exports.defaultFormatting[key]) { + result[key] = val; } }); + return result; }; - exports.handleMouseEvent = function(element, name, handler) { - exports.handleEvent(element, name, function(ev) { - var rect = element.getBoundingClientRect(); - return handler(ev, ev.clientX - rect.left, ev.clientY - rect.top); - }); - }; - - exports.effectiveStyle = function(element, name) { - return document.defaultView.getComputedStyle(element).getPropertyValue(name); - }; - -/***/ }, -/* 47 */ -/***/ function(module, exports, __webpack_require__) { - - var runs = __webpack_require__(30); - var per = __webpack_require__(29); - - var tag = function(name, formattingProperty) { - return function(node, formatting) { - if (node.nodeName === name) { - formatting[formattingProperty] = true; - } - }; - }; + exports.multipleValues = {}; - var value = function(type, styleProperty, formattingProperty, transformValue) { - return function(node, formatting) { - var val = node[type] && node[type][styleProperty]; - if (val) { - if (transformValue) { - val = transformValue(val); + exports.merge = function(run1, run2) { + if (arguments.length === 1) { + return Array.isArray(run1) ? run1.reduce(exports.merge) : run1; + } + if (arguments.length > 2) { + return exports.merge(Array.prototype.slice.call(arguments, 0)); + } + var merged = {}; + exports.formattingKeys.forEach(function(key) { + if (key in run1 || key in run2) { + if (run1[key] === run2[key]) { + merged[key] = run1[key]; + } else { + merged[key] = exports.multipleValues; } - formatting[formattingProperty] = val; } - }; - }; - - var attrValue = function(styleProperty, formattingProperty, transformValue) { - return value('attributes', styleProperty, formattingProperty, transformValue); + }); + return merged; }; - var styleValue = function(styleProperty, formattingProperty, transformValue) { - return value('style', styleProperty, formattingProperty, transformValue); + exports.format = function(run, template) { + if (Array.isArray(run)) { + run.forEach(function(r) { + exports.format(r, template); + }); + } else { + Object.keys(template).forEach(function(key) { + if (template[key] !== exports.multipleValues) { + run[key] = template[key]; + } + }); + } }; - var styleFlag = function(styleProperty, styleValue, formattingProperty) { - return function(node, formatting) { - if (node.style && node.style[styleProperty] === styleValue) { - formatting[formattingProperty] = true; + exports.consolidate = function() { + var current; + return function (emit, run) { + if (!current || !exports.sameFormatting(current, run) || + (typeof current.text != 'string') || + (typeof run.text != 'string')) { + current = exports.clone(run); + emit(current); + } else { + current.text += run.text; } }; }; - var obsoleteFontSizes = [ 6, 7, 9, 10, 12, 16, 20, 30 ]; - - var aligns = { left: true, center: true, right: true, justify: true }; - - var checkAlign = function(value) { - return aligns[value] ? value : 'left'; - }; - - var fontName = function(name) { - var s = name.split(/\s*,\s*/g); - if (s.length == 0) { - return name; - } - name = s[0] - var raw = name.match(/^"(.*)"$/); - if (raw) { - return raw[1].trim(); - } - raw = name.match(/^'(.*)'$/); - if (raw) { - return raw[1].trim(); + exports.getPlainText = function(run) { + if (typeof run.text === 'string') { + return run.text; } - return name; - }; - - var headings = { - H1: 30, - H2: 20, - H3: 16, - H4: 14, - H5: 12 - }; - - var handlers = [ - tag('B', 'bold'), - tag('STRONG', 'bold'), - tag('I', 'italic'), - tag('EM', 'italic'), - tag('U', 'underline'), - tag('S', 'strikeout'), - tag('STRIKE', 'strikeout'), - tag('DEL', 'strikeout'), - styleFlag('fontWeight', 'bold', 'bold'), - styleFlag('fontStyle', 'italic', 'italic'), - styleFlag('textDecoration', 'underline', 'underline'), - styleFlag('textDecoration', 'line-through', 'strikeout'), - styleValue('color', 'color'), - styleValue('fontFamily', 'font', fontName), - styleValue('fontSize', 'size', function(size) { - var m = size.match(/^([\d\.]+)pt$/); - return m ? parseFloat(m[1]) : 10 - }), - styleValue('textAlign', 'align', checkAlign), - function(node, formatting) { - if (node.nodeName === 'SUB') { - formatting.script = 'sub'; - } - }, - function(node, formatting) { - if (node.nodeName === 'SUPER') { - formatting.script = 'super'; - } - }, - function(node, formatting) { - if (node.nodeName === 'CODE') { - formatting.font = 'monospace'; - } - }, - function(node, formatting) { - var size = headings[node.nodeName]; - if (size) { - formatting.size = size; - } - }, - attrValue('color', 'color'), - attrValue('face', 'font', fontName), - attrValue('align', 'align', checkAlign), - attrValue('size', 'size', function(size) { - return obsoleteFontSizes[size] || 10; - }) - ]; - - var newLines = [ 'BR', 'P', 'H1', 'H2', 'H3', 'H4', 'H5' ]; - var isNewLine = {}; - newLines.forEach(function(name) { - isNewLine[name] = true; - }); - - exports.parse = function(html, classes) { - var root = html; - if (typeof root === 'string') { - root = document.createElement('div'); - root.innerHTML = html; + if (Array.isArray(run.text)) { + var str = []; + run.text.forEach(function(piece) { + str.push(exports.getPiecePlainText(piece)); + }); + return str.join(''); } + return '_'; + }; - var result = [], inSpace = true; - var cons = per(runs.consolidate()).into(result); - var emit = function(text, formatting) { - cons.submit(Object.create(formatting, { - text: { value: text } - })); - }; - var dealWithSpaces = function(text, formatting) { - text = text.replace(/\n+\s*/g, ' '); - var fullLength = text.length; - text = text.replace(/^\s+/, ''); - if (inSpace) { - inSpace = false; - } else if (fullLength !== text.length) { - text = ' ' + text; - } - fullLength = text.length; - text = text.replace(/\s+$/, ''); - if (fullLength !== text.length) { - inSpace = true; - text += ' '; - } - emit(text, formatting); - }; - - function recurse(node, formatting) { - if (node.nodeType == 3) { - dealWithSpaces(node.nodeValue, formatting); - } else { - formatting = Object.create(formatting); + /* The text property of a run can be an ordinary string, or a "character object", + or it can be an array containing strings and "character objects". - var classNames = node.attributes['class']; - if (classNames) { - classNames.value.split(' ').forEach(function(cls) { - cls = classes[cls]; - if (cls) { - Object.keys(cls).forEach(function(key) { - formatting[key] = cls[key]; - }); - } - }) - } + A character object is not a string, but is treated as a single character. - handlers.forEach(function(handler) { - handler(node, formatting); - }); - if (node.childNodes) { - for (var n = 0; n < node.childNodes.length; n++) { - recurse(node.childNodes[n], formatting); - } + We abstract over this to provide the same string-like operations regardless. + */ + exports.getPieceLength = function(piece) { + return piece.length || 1; // either a string or something like a character + }; + + exports.getPiecePlainText = function(piece) { + return piece.length ? piece : '_'; + }; + + exports.getTextLength = function(text) { + if (typeof text === 'string') { + return text.length; + } + if (Array.isArray(text)) { + var length = 0; + text.forEach(function(piece) { + length += exports.getPieceLength(piece); + }); + return length; + } + return 1; + }; + + exports.getSubText = function(emit, text, start, count) { + if (count === 0) { + return; + } + if (typeof text === 'string') { + emit(text.substr(start, count)); + return; + } + if (Array.isArray(text)) { + var pos = 0; + text.some(function(piece) { + if (count <= 0) { + return true; } - if (isNewLine[node.nodeName]) { - emit('\n', formatting); - inSpace = true; + var pieceLength = exports.getPieceLength(piece); + if (pos + pieceLength > start) { + if (pieceLength === 1) { + emit(piece); + count -= 1; + } else { + var str = piece.substr(Math.max(0, start - pos), count); + emit(str); + count -= str.length; + } } - } + pos += pieceLength; + }); + return; } - recurse(root, {}); + emit(text); + }; + + exports.getTextChar = function(text, offset) { + var result; + exports.getSubText(function(c) { result = c }, text, offset, 1); return result; }; + exports.pieceCharacters = function(each, piece) { + if (typeof piece === 'string') { + for (var c = 0; c < piece.length; c++) { + each(piece[c]); + } + } else { + each(piece); + } + }; /***/ }, -/* 48 */ -/***/ function(module, exports, __webpack_require__) { - - var Stream = __webpack_require__(49).Stream, - util = __webpack_require__(70), - TokenType = __webpack_require__(72), - BreakType = __webpack_require__(73), - tokenizer = __webpack_require__(74), - LineBreak = __webpack_require__(76); +/* 31 */ +/***/ function(module, exports) { - function TokenizerStream() { - Stream.call(this); + + var prototype = { + contains: function(x, y) { + return x >= this.l && x < (this.l + this.w) && + y >= this.t && y < (this.t + this.h); - var that = this; + }, + stroke: function(ctx) { + ctx.strokeRect(this.l, this.t, this.w, this.h); + }, + fill: function(ctx) { + ctx.fillRect(this.l, this.t, this.w, this.h); + }, + offset: function(x, y) { + return rect(this.l + x, this.t + y, this.w, this.h); + }, + equals: function(other) { + return this.l === other.l && this.t === other.t && + this.w === other.w && this.h === other.h; + }, + center: function() { + return { x: this.l + this.w/2, y: this.t + this.h/2 }; + } + }; - this.readable = true; - this.writable = true; + var rect = module.exports = function(l, t, w, h) { + return Object.create(prototype, { + l: { value: l }, + t: { value: t }, + w: { value: w }, + h: { value: h }, + r: { value: l + w }, + b: { value: t + h } + }); + }; - this.tokenizer = tokenizer.createTokenizer(); - this.linebreak = new LineBreak(); - this.tokenizer.on('token', function(token, type) { - that.linebreak.process(token, type); - }); +/***/ }, +/* 32 */ +/***/ function(module, exports) { - this.linebreak.on('action', function(token, type, action) { - that.emit('data', token); - that.emit('token', token, type, action); - }); + exports.event = function() { + var handlers = []; - this.tokenizer.on('end', function() { - that.linebreak.end(); - }); - } + var subscribe = function(handler) { + handlers.push(handler); + }; - util.inherits(TokenizerStream, Stream); + subscribe.fire = function() { + var args = Array.prototype.slice.call(arguments, 0); + handlers.forEach(function(handler) { + handler.apply(null, args); + }); + }; - TokenizerStream.prototype.write = function(chunk) { - this.tokenizer.write(chunk); + return subscribe; }; - TokenizerStream.prototype.end = function(data) { - if (data) { - this.write(data); - } - this.tokenizer.end(); - this.emit('end'); + exports.derive = function(prototype, methods) { + var properties = {}; + Object.keys(methods).forEach(function(name) { + properties[name] = { value: methods[name] }; + }); + return Object.create(prototype, properties); }; - module.exports = { - Break: BreakType, - Token: TokenType, +/***/ }, +/* 33 */ +/***/ function(module, exports, __webpack_require__) { - Tokenizer: tokenizer.Tokenizer, - tokenize: tokenizer.tokenize, - tokenizeSync: tokenizer.tokenizeSync, + var per = __webpack_require__(29); + var carotaDoc = __webpack_require__(34); + var dom = __webpack_require__(46); + var rect = __webpack_require__(31); - createTokenizerStream: function() { - return new TokenizerStream(); + setInterval(function() { + var editors = document.querySelectorAll('.carotaEditorCanvas'); + + var ev = document.createEvent('Event'); + ev.initEvent('carotaEditorSharedTimer', true, true); + + // not in IE, apparently: + // var ev = new CustomEvent('carotaEditorSharedTimer'); + + for (var n = 0; n < editors.length; n++) { + editors[n].dispatchEvent(ev); } - }; + }, 200); + exports.create = function(element) { -/***/ }, -/* 49 */ -/***/ function(module, exports, __webpack_require__) { + // We need the host element to be a container: + if (dom.effectiveStyle(element, 'position') !== 'absolute') { + element.style.position = 'relative'; + } - // Copyright Joyent, Inc. and other Node contributors. - // - // Permission is hereby granted, free of charge, to any person obtaining a - // copy of this software and associated documentation files (the - // "Software"), to deal in the Software without restriction, including - // without limitation the rights to use, copy, modify, merge, publish, - // distribute, sublicense, and/or sell copies of the Software, and to permit - // persons to whom the Software is furnished to do so, subject to the - // following conditions: - // - // The above copyright notice and this permission notice shall be included - // in all copies or substantial portions of the Software. - // - // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN - // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, - // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR - // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE - // USE OR OTHER DEALINGS IN THE SOFTWARE. + element.innerHTML = + '
' + + '' + + '
' + + '
' + + '' + '
'; + + var canvas = element.querySelector('canvas'), + spacer = element.querySelector('.carotaSpacer'), + textAreaDiv = element.querySelector('.carotaTextArea'), + textArea = element.querySelector('textarea'), + doc = carotaDoc(), + keyboardSelect = 0, + keyboardX = null, nextKeyboardX = null, + selectDragStart = null, + focusChar = null, + textAreaContent = '', + richClipboard = null, + plainClipboard = null; + + var toggles = { + 66: 'bold', + 73: 'italic', + 85: 'underline', + 83: 'strikeout' + }; - module.exports = Stream; + var exhausted = function(ordinal, direction) { + return direction < 0 ? ordinal <= 0 : ordinal >= doc.frame.length - 1; + }; - var EE = __webpack_require__(50).EventEmitter; - var inherits = __webpack_require__(51); + var differentLine = function(caret1, caret2) { + return (caret1.b <= caret2.t) || + (caret2.b <= caret1.t); + }; - inherits(Stream, EE); - Stream.Readable = __webpack_require__(52); - Stream.Writable = __webpack_require__(66); - Stream.Duplex = __webpack_require__(67); - Stream.Transform = __webpack_require__(68); - Stream.PassThrough = __webpack_require__(69); + var changeLine = function(ordinal, direction) { - // Backwards-compat with node 0.4.x - Stream.Stream = Stream; + var originalCaret = doc.getCaretCoords(ordinal), newCaret; + nextKeyboardX = (keyboardX !== null) ? keyboardX : originalCaret.l; + while (!exhausted(ordinal, direction)) { + ordinal += direction; + newCaret = doc.getCaretCoords(ordinal); + if (differentLine(newCaret, originalCaret)) { + break; + } + } + originalCaret = newCaret; + while (!exhausted(ordinal, direction)) { + if ((direction > 0 && newCaret.l >= nextKeyboardX) || + (direction < 0 && newCaret.l <= nextKeyboardX)) { + break; + } - // old-style streams. Note that the pipe method (the only relevant - // part of this class) is overridden in the Readable class. + ordinal += direction; + newCaret = doc.getCaretCoords(ordinal); + if (differentLine(newCaret, originalCaret)) { + ordinal -= direction; + break; + } + } - function Stream() { - EE.call(this); - } + return ordinal; + }; - Stream.prototype.pipe = function(dest, options) { - var source = this; + var endOfline = function(ordinal, direction) { + var originalCaret = doc.getCaretCoords(ordinal), newCaret; + while (!exhausted(ordinal, direction)) { + ordinal += direction; + newCaret = doc.getCaretCoords(ordinal); + if (differentLine(newCaret, originalCaret)) { + ordinal -= direction; + break; + } + } + return ordinal; + }; - function ondata(chunk) { - if (dest.writable) { - if (false === dest.write(chunk) && source.pause) { - source.pause(); - } - } - } + var handleKey = function(key, selecting, ctrlKey) { + var start = doc.selection.start, + end = doc.selection.end, + length = doc.frame.length - 1, + handled = false; - source.on('data', ondata); + nextKeyboardX = null; - function ondrain() { - if (source.readable && source.resume) { - source.resume(); - } - } + if (!selecting) { + keyboardSelect = 0; + } else if (!keyboardSelect) { + switch (key) { + case 37: // left arrow + case 38: // up - find character above + case 36: // start of line + case 33: // page up + keyboardSelect = -1; + break; + case 39: // right arrow + case 40: // down arrow - find character below + case 35: // end of line + case 34: // page down + keyboardSelect = 1; + break; + } + } - dest.on('drain', ondrain); + var ordinal = keyboardSelect === 1 ? end : start; - // If the 'end' option is not supplied, dest.end() will be called when - // source gets the 'end' or 'close' events. Only dest.end() once. - if (!dest._isStdio && (!options || options.end !== false)) { - source.on('end', onend); - source.on('close', onclose); - } + var changingCaret = false; + switch (key) { + case 37: // left arrow + if (!selecting && start != end) { + ordinal = start; + } else { + if (ordinal > 0) { + if (ctrlKey) { + var wordInfo = doc.wordContainingOrdinal(ordinal); + if (wordInfo.ordinal === ordinal) { + ordinal = wordInfo.index > 0 ? doc.wordOrdinal(wordInfo.index - 1) : 0; + } else { + ordinal = wordInfo.ordinal; + } + } else { + ordinal--; + } + } + } + changingCaret = true; + break; + case 39: // right arrow + if (!selecting && start != end) { + ordinal = end; + } else { + if (ordinal < length) { + if (ctrlKey) { + var wordInfo = doc.wordContainingOrdinal(ordinal); + ordinal = wordInfo.ordinal + wordInfo.word.length; + } else { + ordinal++; + } + } + } + changingCaret = true; + break; + case 40: // down arrow - find character below + ordinal = changeLine(ordinal, 1); + changingCaret = true; + break; + case 38: // up - find character above + ordinal = changeLine(ordinal, -1); + changingCaret = true; + break; + case 36: // start of line + ordinal = endOfline(ordinal, -1); + changingCaret = true; + break; + case 35: // end of line + ordinal = endOfline(ordinal, 1); + changingCaret = true; + break; + case 33: // page up + ordinal = 0; + changingCaret = true; + break; + case 34: // page down + ordinal = length; + changingCaret = true; + break; + case 8: // backspace + if (start === end && start > 0) { + doc.range(start - 1, start).clear(); + focusChar = start - 1; + doc.select(focusChar, focusChar); + handled = true; + } + break; + case 46: // del + if (start === end && start < length) { + doc.range(start, start + 1).clear(); + handled = true; + } + break; + case 90: // Z undo + if (ctrlKey) { + handled = true; + doc.performUndo(); + } + break; + case 89: // Y undo + if (ctrlKey) { + handled = true; + doc.performUndo(true); + } + break; + case 65: // A select all + if (ctrlKey) { + handled = true; + doc.select(0, length); + } + break; + case 67: // C - copy to clipboard + case 88: // X - cut to clipboard + if (ctrlKey) { + // Allow standard handling to take place as well + richClipboard = doc.selectedRange().save(); + plainClipboard = doc.selectedRange().plainText(); + } + break; + } - var didOnEnd = false; - function onend() { - if (didOnEnd) return; - didOnEnd = true; + var toggle = toggles[key]; + if (ctrlKey && toggle) { + var selRange = doc.selectedRange(); + selRange.setFormatting(toggle, selRange.getFormatting()[toggle] !== true); + paint(); + handled = true; + } - dest.end(); - } + if (changingCaret) { + switch (keyboardSelect) { + case 0: + start = end = ordinal; + break; + case -1: + start = ordinal; + break; + case 1: + end = ordinal; + break; + } + if (start === end) { + keyboardSelect = 0; + } else { + if (start > end) { + keyboardSelect = -keyboardSelect; + var t = end; + end = start; + start = t; + } + } + focusChar = ordinal; + doc.select(start, end); + handled = true; + } - function onclose() { - if (didOnEnd) return; - didOnEnd = true; + keyboardX = nextKeyboardX; + return handled; + }; - if (typeof dest.destroy === 'function') dest.destroy(); - } + dom.handleEvent(textArea, 'keydown', function(ev) { + if (handleKey(ev.keyCode, ev.shiftKey, ev.ctrlKey)) { + return false; + } + console.log(ev.which); + }); - // don't leave dangling pipes when there are errors. - function onerror(er) { - cleanup(); - if (EE.listenerCount(this, 'error') === 0) { - throw er; // Unhandled stream error in pipe. + var verticalAlignment = 'top'; + + doc.setVerticalAlignment = function(va) { + verticalAlignment = va; + paint(); } - } - source.on('error', onerror); - dest.on('error', onerror); + function getVerticalOffset() { + var docHeight = doc.frame.bounds().h; + if (docHeight < element.clientHeight) { + switch (verticalAlignment) { + case 'middle': + return (element.clientHeight - docHeight) / 2; + case 'bottom': + return element.clientHeight - docHeight; + } + } + return 0; + } - // remove all the event listeners that were added. - function cleanup() { - source.removeListener('data', ondata); - dest.removeListener('drain', ondrain); + var paint = function() { - source.removeListener('end', onend); - source.removeListener('close', onclose); + var availableWidth = element.clientWidth * 1; // adjust to 0.5 to see if we draw in the wrong places! + if (doc.width() !== availableWidth) { + doc.width(availableWidth); + } - source.removeListener('error', onerror); - dest.removeListener('error', onerror); + var docHeight = doc.frame.bounds().h; - source.removeListener('end', cleanup); - source.removeListener('close', cleanup); + var dpr = Math.max(1, window.devicePixelRatio || 1); + + var logicalWidth = Math.max(doc.frame.actualWidth(), element.clientWidth), + logicalHeight = element.clientHeight; + + canvas.width = dpr * logicalWidth; + canvas.height = dpr * logicalHeight; + canvas.style.width = logicalWidth + 'px'; + canvas.style.height = logicalHeight + 'px'; + + canvas.style.top = element.scrollTop + 'px'; + spacer.style.width = logicalWidth + 'px'; + spacer.style.height = Math.max(docHeight, element.clientHeight) + 'px'; - dest.removeListener('close', cleanup); - } + if (docHeight < (element.clientHeight - 50) && + doc.frame.actualWidth() <= availableWidth) { + element.style.overflow = 'hidden'; + } else { + element.style.overflow = 'auto'; + } - source.on('end', cleanup); - source.on('close', cleanup); + var ctx = canvas.getContext('2d'); + ctx.scale(dpr, dpr); - dest.on('close', cleanup); + ctx.clearRect(0, 0, logicalWidth, logicalHeight); + ctx.translate(0, getVerticalOffset() - element.scrollTop); + + doc.draw(ctx, rect(0, element.scrollTop, logicalWidth, logicalHeight)); + doc.drawSelection(ctx, selectDragStart || (document.activeElement === textArea)); + }; - dest.emit('pipe', source); + dom.handleEvent(element, 'scroll', paint); - // Allow for unix-like usage: A.pipe(B).pipe(C) - return dest; - }; + dom.handleEvent(textArea, 'input', function() { + var newText = textArea.value; + if (textAreaContent != newText) { + textAreaContent = ''; + textArea.value = ''; + if (newText === plainClipboard) { + newText = richClipboard; + } + doc.insert(newText); + } + }); + var updateTextArea = function() { + focusChar = focusChar === null ? doc.selection.end : focusChar; + var endChar = doc.byOrdinal(focusChar); + focusChar = null; + if (endChar) { + var bounds = endChar.bounds(); + textAreaDiv.style.left = bounds.l + 'px'; + textAreaDiv.style.top = bounds.t + 'px'; + textArea.focus(); + var scrollDownBy = Math.max(0, bounds.t + bounds.h - + (element.scrollTop + element.clientHeight)); + if (scrollDownBy) { + element.scrollTop += scrollDownBy; + } + var scrollUpBy = Math.max(0, element.scrollTop - bounds.t); + if (scrollUpBy) { + element.scrollTop -= scrollUpBy; + } + var scrollRightBy = Math.max(0, bounds.l - + (element.scrollLeft + element.clientWidth)); + if (scrollRightBy) { + element.scrollLeft += scrollRightBy; + } + var scrollLeftBy = Math.max(0, element.scrollLeft - bounds.l); + if (scrollLeftBy) { + element.scrollLeft -= scrollLeftBy; + } + } + textAreaContent = doc.selectedRange().plainText(); + textArea.value = textAreaContent; + textArea.select(); -/***/ }, -/* 50 */ -/***/ function(module, exports) { + setTimeout(function() { + textArea.focus(); + }, 10); + }; - // Copyright Joyent, Inc. and other Node contributors. - // - // Permission is hereby granted, free of charge, to any person obtaining a - // copy of this software and associated documentation files (the - // "Software"), to deal in the Software without restriction, including - // without limitation the rights to use, copy, modify, merge, publish, - // distribute, sublicense, and/or sell copies of the Software, and to permit - // persons to whom the Software is furnished to do so, subject to the - // following conditions: - // - // The above copyright notice and this permission notice shall be included - // in all copies or substantial portions of the Software. - // - // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN - // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, - // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR - // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE - // USE OR OTHER DEALINGS IN THE SOFTWARE. + doc.selectionChanged(function(getformatting, takeFocus) { + paint(); + if (!selectDragStart) { + if (takeFocus !== false) { + updateTextArea(); + } + } + }); - function EventEmitter() { - this._events = this._events || {}; - this._maxListeners = this._maxListeners || undefined; - } - module.exports = EventEmitter; + function registerMouseEvent(name, handler) { + dom.handleMouseEvent(spacer, name, function(ev, x, y) { + handler(doc.byCoordinate(x, y - getVerticalOffset())); + }); + } - // Backwards-compat with node 0.10.x - EventEmitter.EventEmitter = EventEmitter; + registerMouseEvent('mousedown', function(node) { + selectDragStart = node.ordinal; + doc.select(node.ordinal, node.ordinal); + keyboardX = null; + }); - EventEmitter.prototype._events = undefined; - EventEmitter.prototype._maxListeners = undefined; + registerMouseEvent('dblclick', function(node) { + node = node.parent(); + if (node) { + doc.select(node.ordinal, node.ordinal + + (node.word ? node.word.text.length : node.length)); + } + }); - // By default EventEmitters will print a warning if more than 10 listeners are - // added to it. This is a useful default which helps finding memory leaks. - EventEmitter.defaultMaxListeners = 10; + registerMouseEvent('mousemove', function(node) { + if (selectDragStart !== null) { + if (node) { + focusChar = node.ordinal; + if (selectDragStart > node.ordinal) { + doc.select(node.ordinal, selectDragStart); + } else { + doc.select(selectDragStart, node.ordinal); + } + } + } + }); - // Obviously not all Emitters should be limited to 10. This function allows - // that to be increased. Set to zero for unlimited. - EventEmitter.prototype.setMaxListeners = function(n) { - if (!isNumber(n) || n < 0 || isNaN(n)) - throw TypeError('n must be a positive number'); - this._maxListeners = n; - return this; - }; + registerMouseEvent('mouseup', function(node) { + selectDragStart = null; + keyboardX = null; + updateTextArea(); + textArea.focus(); + }); - EventEmitter.prototype.emit = function(type) { - var er, handler, len, args, i, listeners; + var nextCaretToggle = new Date().getTime(), + focused = false, + cachedWidth = element.clientWidth, + cachedHeight = element.clientHeight; - if (!this._events) - this._events = {}; + var update = function() { + var requirePaint = false; + var newFocused = document.activeElement === textArea; + if (focused !== newFocused) { + focused = newFocused; + requirePaint = true; + } - // If there is no 'error' event listener then throw. - if (type === 'error') { - if (!this._events.error || - (isObject(this._events.error) && !this._events.error.length)) { - er = arguments[1]; - if (er instanceof Error) { - throw er; // Unhandled 'error' event - } else { - // At least give some kind of context to the user - var err = new Error('Uncaught, unspecified "error" event. (' + er + ')'); - err.context = er; - throw err; - } - } - } + var now = new Date().getTime(); + if (now > nextCaretToggle) { + nextCaretToggle = now + 500; + if (doc.toggleCaret()) { + requirePaint = true; + } + } - handler = this._events[type]; + if (element.clientWidth !== cachedWidth || + element.clientHeight !== cachedHeight) { + requirePaint = true; + cachedWidth =element.clientWidth; + cachedHeight = element.clientHeight; + } - if (isUndefined(handler)) - return false; + if (requirePaint) { + paint(); + } + }; - if (isFunction(handler)) { - switch (arguments.length) { - // fast cases - case 1: - handler.call(this); - break; - case 2: - handler.call(this, arguments[1]); - break; - case 3: - handler.call(this, arguments[1], arguments[2]); - break; - // slower - default: - args = Array.prototype.slice.call(arguments, 1); - handler.apply(this, args); - } - } else if (isObject(handler)) { - args = Array.prototype.slice.call(arguments, 1); - listeners = handler.slice(); - len = listeners.length; - for (i = 0; i < len; i++) - listeners[i].apply(this, args); - } + dom.handleEvent(canvas, 'carotaEditorSharedTimer', update); + update(); - return true; + doc.sendKey = handleKey; + return doc; }; - EventEmitter.prototype.addListener = function(type, listener) { - var m; - if (!isFunction(listener)) - throw TypeError('listener must be a function'); +/***/ }, +/* 34 */ +/***/ function(module, exports, __webpack_require__) { - if (!this._events) - this._events = {}; + var per = __webpack_require__(29); + var characters = __webpack_require__(35); + var split = __webpack_require__(36); + var word = __webpack_require__(37); + var node = __webpack_require__(28); + var runs = __webpack_require__(30); + var range = __webpack_require__(40); + var util = __webpack_require__(32); + var frame = __webpack_require__(41); + var codes = __webpack_require__(45); + var rect = __webpack_require__(31); - // To avoid recursion in the case that type === "newListener"! Before - // adding it to the listeners, first emit "newListener". - if (this._events.newListener) - this.emit('newListener', type, - isFunction(listener.listener) ? - listener.listener : listener); + var makeEditCommand = function(doc, start, count, words) { + var selStart = doc.selection.start, selEnd = doc.selection.end; + return function(log) { + doc._wordOrdinals = []; + var oldWords = Array.prototype.splice.apply(doc.words, [start, count].concat(words)); + log(makeEditCommand(doc, start, words.length, oldWords)); + doc._nextSelection = { start: selStart, end: selEnd }; + }; + }; - if (!this._events[type]) - // Optimize the case of one listener. Don't need the extra array object. - this._events[type] = listener; - else if (isObject(this._events[type])) - // If we've already got an array, just append. - this._events[type].push(listener); - else - // Adding the second element, need to change to array. - this._events[type] = [this._events[type], listener]; + var makeTransaction = function(perform) { + var commands = []; + var log = function(command) { + commands.push(command); + log.length = commands.length; + }; + perform(log); - // Check for listener leak - if (isObject(this._events[type]) && !this._events[type].warned) { - if (!isUndefined(this._maxListeners)) { - m = this._maxListeners; - } else { - m = EventEmitter.defaultMaxListeners; - } + return function(outerLog) { + outerLog(makeTransaction(function(innerLog) { + while (commands.length) { + commands.pop()(innerLog); + } + })); + }; + }; - if (m && m > 0 && this._events[type].length > m) { - this._events[type].warned = true; - console.error('(node) warning: possible EventEmitter memory ' + - 'leak detected. %d listeners added. ' + - 'Use emitter.setMaxListeners() to increase limit.', - this._events[type].length); - if (typeof console.trace === 'function') { - // not supported in IE 10 - console.trace(); - } + var isBreaker = function(word) { + if (word.isNewLine()) { + return true; } - } - - return this; + var code = word.code(); + return !!(code && (code.block || code.eof)); }; - EventEmitter.prototype.on = EventEmitter.prototype.addListener; + var prototype = node.derive({ + load: function(runs, takeFocus) { + var self = this; + this.undo = []; + this.redo = []; + this._wordOrdinals = []; + this.words = per(characters(runs)).per(split(self.codes)).map(function(w) { + return word(w, self.codes); + }).all(); + this.layout(); + this.contentChanged.fire(); + this.select(0, 0, takeFocus); + }, + layout: function() { + this.frame = null; + try { + this.frame = per(this.words).per(frame(0, 0, this._width, 0, this)).first(); + } catch (x) { + console.error(x); + } + if (!this.frame) { + console.error('A bug somewhere has produced an invalid state - rolling back'); + this.performUndo(); + } else if (this._nextSelection) { + var next = this._nextSelection; + delete this._nextSelection; + this.select(next.start, next.end); + } + }, + range: function(start, end) { + return range(this, start, end); + }, + documentRange: function() { + return this.range(0, this.frame.length - 1); + }, + selectedRange: function() { + return this.range(this.selection.start, this.selection.end); + }, + save: function() { + return this.documentRange().save(); + }, + paragraphRange: function(start, end) { + var i; - EventEmitter.prototype.once = function(type, listener) { - if (!isFunction(listener)) - throw TypeError('listener must be a function'); + // find the character after the nearest breaker before start + var startInfo = this.wordContainingOrdinal(start); + start = 0; + if (startInfo && !isBreaker(startInfo.word)) { + for (i = startInfo.index; i > 0; i--) { + if (isBreaker(this.words[i - 1])) { + start = this.wordOrdinal(i); + break; + } + } + } - var fired = false; + // find the nearest breaker after end + var endInfo = this.wordContainingOrdinal(end); + end = this.frame.length - 1; + if (endInfo && !isBreaker(endInfo.word)) { + for (i = endInfo.index; i < this.words.length; i++) { + if (isBreaker(this.words[i])) { + end = this.wordOrdinal(i); + break; + } + } + } + + return this.range(start, end); + }, + insert: function(text, takeFocus) { + this.select(this.selection.end + this.selectedRange().setText(text), null, takeFocus); + }, + modifyInsertFormatting: function(attribute, value) { + this.nextInsertFormatting[attribute] = value; + this.notifySelectionChanged(); + }, + applyInsertFormatting: function(text) { + var formatting = this.nextInsertFormatting; + var insertFormattingProperties = Object.keys(formatting); + if (insertFormattingProperties.length) { + text.forEach(function(run) { + insertFormattingProperties.forEach(function(property) { + run[property] = formatting[property]; + }); + }); + } + }, + wordOrdinal: function(index) { + if (index < this.words.length) { + var cached = this._wordOrdinals.length; + if (cached < (index + 1)) { + var o = cached > 0 ? this._wordOrdinals[cached - 1] : 0; + for (var n = cached; n <= index; n++) { + this._wordOrdinals[n] = o; + o += this.words[n].length; + } + } + return this._wordOrdinals[index]; + } + }, + wordContainingOrdinal: function(ordinal) { + // could rewrite to be faster using binary search over this.wordOrdinal + var result; + var pos = 0; + this.words.some(function(word, i) { + if (ordinal >= pos && ordinal < (pos + word.length)) { + result = { + word: word, + ordinal: pos, + index: i, + offset: ordinal - pos + }; + return true; + } + pos += word.length; + }); + return result; + }, + runs: function(emit, range) { + var startDetails = this.wordContainingOrdinal(Math.max(0, range.start)), + endDetails = this.wordContainingOrdinal(Math.min(range.end, this.frame.length - 1)); + if (startDetails.index === endDetails.index) { + startDetails.word.runs(emit, { + start: startDetails.offset, + end: endDetails.offset + }); + } else { + startDetails.word.runs(emit, { start: startDetails.offset }); + for (var n = startDetails.index + 1; n < endDetails.index; n++) { + this.words[n].runs(emit); + } + endDetails.word.runs(emit, { end: endDetails.offset }); + } + }, + spliceWordsWithRuns: function(wordIndex, count, runs) { + var self = this; - function g() { - this.removeListener(type, g); + var newWords = per(characters(runs)) + .per(split(self.codes)) + .truthy() + .map(function(w) { + return word(w, self.codes); + }) + .all(); - if (!fired) { - fired = true; - listener.apply(this, arguments); - } - } + // Check if old or new content contains any fancy control codes: + var runFilters = false; - g.listener = listener; - this.on(type, g); + if ('_filtersRunning' in self) { + self._filtersRunning++; + } else { + for (var n = 0; n < count; n++) { + if (this.words[wordIndex + n].code()) { + runFilters = true; + } + } + if (!runFilters) { + runFilters = newWords.some(function(word) { + return !!word.code(); + }); + } + } - return this; - }; + this.transaction(function(log) { + makeEditCommand(self, wordIndex, count, newWords)(log); + if (runFilters) { + self._filtersRunning = 0; + try { + for (;;) { + var spliceCount = self._filtersRunning; + if (!self.editFilters.some(function(filter) { + filter(self); + return spliceCount !== self._filtersRunning; + })) { + break; // No further changes were made + } + } + } finally { + delete self._filtersRunning; + } + } + }); + }, + splice: function(start, end, text) { + if (typeof text === 'string') { + var sample = Math.max(0, start - 1); + var sampleRun = per({ start: sample, end: sample + 1 }) + .per(this.runs, this) + .first(); + text = [ + sampleRun ? Object.create(sampleRun, { text: { value: text } }) : { text: text } + ]; + } else if (!Array.isArray(text)) { + text = [{ text: text }]; + } - // emits a 'removeListener' event iff the listener was removed - EventEmitter.prototype.removeListener = function(type, listener) { - var list, position, length, i; + this.applyInsertFormatting(text); - if (!isFunction(listener)) - throw TypeError('listener must be a function'); + var startWord = this.wordContainingOrdinal(start), + endWord = this.wordContainingOrdinal(end); - if (!this._events || !this._events[type]) - return this; + var prefix; + if (start === startWord.ordinal) { + if (startWord.index > 0 && !isBreaker(this.words[startWord.index - 1])) { + startWord.index--; + var previousWord = this.words[startWord.index]; + prefix = per({}).per(previousWord.runs, previousWord).all(); + } else { + prefix = []; + } + } else { + prefix = per({ end: startWord.offset }) + .per(startWord.word.runs, startWord.word) + .all(); + } - list = this._events[type]; - length = list.length; - position = -1; + var suffix; + if (end === endWord.ordinal) { + if ((end === this.frame.length - 1) || isBreaker(endWord.word)) { + suffix = []; + endWord.index--; + } else { + suffix = per({}).per(endWord.word.runs, endWord.word).all(); + } + } else { + suffix = per({ start: endWord.offset }) + .per(endWord.word.runs, endWord.word) + .all(); + } - if (list === listener || - (isFunction(list.listener) && list.listener === listener)) { - delete this._events[type]; - if (this._events.removeListener) - this.emit('removeListener', type, listener); + var oldLength = this.frame.length; - } else if (isObject(list)) { - for (i = length; i-- > 0;) { - if (list[i] === listener || - (list[i].listener && list[i].listener === listener)) { - position = i; - break; - } - } + this.spliceWordsWithRuns(startWord.index, (endWord.index - startWord.index) + 1, + per(prefix).concat(text).concat(suffix).per(runs.consolidate()).all()); - if (position < 0) - return this; + return this.frame ? (this.frame.length - oldLength) : 0; + }, + registerEditFilter: function(filter) { + this.editFilters.push(filter); + }, + width: function(width) { + if (arguments.length === 0) { + return this._width; + } + this._width = width; + this.layout(); + }, + children: function() { + return [this.frame]; + }, + toggleCaret: function() { + var old = this.caretVisible; + if (this.selection.start === this.selection.end) { + if (this.selectionJustChanged) { + this.selectionJustChanged = false; + } else { + this.caretVisible = !this.caretVisible; + } + } + return this.caretVisible !== old; + }, + getCaretCoords: function(ordinal) { + var node = this.byOrdinal(ordinal), b; + if (node) { + if (node.block && ordinal > 0) { + var nodeBefore = this.byOrdinal(ordinal - 1); + if (nodeBefore.newLine) { + var newLineBounds = nodeBefore.bounds(); + var lineBounds = nodeBefore.parent().parent().bounds(); + b = rect(lineBounds.l, lineBounds.b, 1, newLineBounds.h); + } else { + b = nodeBefore.bounds(); + b = rect(b.r, b.t, 1, b.h); + } + } else { + b = node.bounds(); + if (b.h) { + b = rect(b.l, b.t, 1, b.h); + } else { + b = rect(b.l, b.t, b.w, 1); + } + } + return b; + } + }, + byCoordinate: function(x, y) { + var ordinal = this.frame.byCoordinate(x, y).ordinal; + var caret = this.getCaretCoords(ordinal); + while (caret.b <= y && ordinal < (this.frame.length - 1)) { + ordinal++; + caret = this.getCaretCoords(ordinal); + } + while (caret.t >= y && ordinal > 0) { + ordinal--; + caret = this.getCaretCoords(ordinal); + } + return this.byOrdinal(ordinal); + }, + drawSelection: function(ctx, hasFocus) { + if (this.selection.end === this.selection.start) { + if (this.selectionJustChanged || hasFocus && this.caretVisible) { + var caret = this.getCaretCoords(this.selection.start); + if (caret) { + ctx.save(); + ctx.fillStyle = 'black'; + caret.fill(ctx); + ctx.restore(); + } + } + } else { + ctx.save(); + ctx.fillStyle = hasFocus ? 'rgba(0, 100, 200, 0.3)' : 'rgba(160, 160, 160, 0.3)'; + this.selectedRange().parts(function(part) { + part.bounds(true).fill(ctx); + }); + ctx.restore(); + } + }, + notifySelectionChanged: function(takeFocus) { + // When firing selectionChanged, we pass a function can be used + // to obtain the formatting, as this highly likely to be needed + var cachedFormatting = null; + var self = this; + var getFormatting = function() { + if (!cachedFormatting) { + cachedFormatting = self.selectedRange().getFormatting(); + } + return cachedFormatting; + }; + this.selectionChanged.fire(getFormatting, takeFocus); + }, + select: function(ordinal, ordinalEnd, takeFocus) { + if (!this.frame) { + // Something has gone terribly wrong - doc.transaction will rollback soon + return; + } + this.selection.start = Math.max(0, ordinal); + this.selection.end = Math.min( + typeof ordinalEnd === 'number' ? ordinalEnd : this.selection.start, + this.frame.length - 1 + ); + this.selectionJustChanged = true; + this.caretVisible = true; + this.nextInsertFormatting = {}; - if (list.length === 1) { - list.length = 0; - delete this._events[type]; - } else { - list.splice(position, 1); - } + /* NB. always fire this even if the positions stayed the same. The + event means that the formatting of the selection has changed + (which can happen either by moving the selection range or by + altering the formatting) + */ + this.notifySelectionChanged(takeFocus); + }, + performUndo: function(redo) { + var fromStack = redo ? this.redo : this.undo, + toStack = redo ? this.undo : this.redo, + oldCommand = fromStack.pop(); - if (this._events.removeListener) - this.emit('removeListener', type, listener); - } + if (oldCommand) { + oldCommand(function(newCommand) { + toStack.push(newCommand); + }); + this.layout(); + this.contentChanged.fire(); + } + }, + canUndo: function(redo) { + return redo ? !!this.redo.length : !!this.undo.length; + }, + transaction: function(perform) { + if (this._currentTransaction) { + perform(this._currentTransaction); + } else { + var self = this; + while (this.undo.length > 50) { + self.undo.shift(); + } + this.redo.length = 0; + var changed = false; + this.undo.push(makeTransaction(function(log) { + self._currentTransaction = log; + try { + perform(log); + } finally { + changed = log.length > 0; + self._currentTransaction = null; + } + })); + if (changed) { + self.layout(); + self.contentChanged.fire(); + } + } + }, + type: 'document' + }); - return this; + exports = module.exports = function() { + var doc = Object.create(prototype); + doc._width = 0; + doc.selection = { start: 0, end: 0 }; + doc.caretVisible = true; + doc.customCodes = function(code, data, allCodes) {}; + doc.codes = function(code, data) { + var instance = codes(code, data, doc.codes); + return instance || doc.customCodes(code, data, doc.codes); + }; + doc.selectionChanged = util.event(); + doc.contentChanged = util.event(); + doc.editFilters = [codes.editFilter]; + doc.load([]); + return doc; }; - EventEmitter.prototype.removeAllListeners = function(type) { - var key, listeners; - if (!this._events) - return this; +/***/ }, +/* 35 */ +/***/ function(module, exports, __webpack_require__) { - // not listening for removeListener, no need to emit - if (!this._events.removeListener) { - if (arguments.length === 0) - this._events = {}; - else if (this._events[type]) - delete this._events[type]; - return this; - } + var runs = __webpack_require__(30); - // emit removeListener for all listeners on all events - if (arguments.length === 0) { - for (key in this._events) { - if (key === 'removeListener') continue; - this.removeAllListeners(key); + var compatible = function(a, b) { + if (a._runs !== b._runs) { + throw new Error('Characters for different documents'); } - this.removeAllListeners('removeListener'); - this._events = {}; - return this; - } - - listeners = this._events[type]; - - if (isFunction(listeners)) { - this.removeListener(type, listeners); - } else if (listeners) { - // LIFO order - while (listeners.length) - this.removeListener(type, listeners[listeners.length - 1]); - } - delete this._events[type]; - - return this; - }; - - EventEmitter.prototype.listeners = function(type) { - var ret; - if (!this._events || !this._events[type]) - ret = []; - else if (isFunction(this._events[type])) - ret = [this._events[type]]; - else - ret = this._events[type].slice(); - return ret; - }; - - EventEmitter.prototype.listenerCount = function(type) { - if (this._events) { - var evlistener = this._events[type]; - - if (isFunction(evlistener)) - return 1; - else if (evlistener) - return evlistener.length; - } - return 0; }; - EventEmitter.listenerCount = function(emitter, type) { - return emitter.listenerCount(type); + var prototype = { + equals: function(other) { + compatible(this, other); + return this._run === other._run && this._offset === other._offset; + }, + cut: function(upTo) { + compatible(this, upTo); + var self = this; + return function(eachRun) { + for (var runIndex = self._run; runIndex <= upTo._run; runIndex++) { + var run = self._runs[runIndex]; + if (run) { + var start = (runIndex === self._run) ? self._offset : 0; + var stop = (runIndex === upTo._run) ? upTo._offset : runs.getTextLength(run.text); + if (start < stop) { + runs.getSubText(function(piece) { + var pieceRun = Object.create(run); + pieceRun.text = piece; + eachRun(pieceRun); + }, run.text, start, stop - start); + } + } + } + }; + } }; - function isFunction(arg) { - return typeof arg === 'function'; - } - - function isNumber(arg) { - return typeof arg === 'number'; - } - - function isObject(arg) { - return typeof arg === 'object' && arg !== null; - } - - function isUndefined(arg) { - return arg === void 0; - } - - -/***/ }, -/* 51 */ -/***/ function(module, exports) { - - if (typeof Object.create === 'function') { - // implementation from standard node.js 'util' module - module.exports = function inherits(ctor, superCtor) { - ctor.super_ = superCtor - ctor.prototype = Object.create(superCtor.prototype, { - constructor: { - value: ctor, - enumerable: false, - writable: true, - configurable: true - } + function character(runArray, run, offset) { + return Object.create(prototype, { + _runs: { value: runArray }, + _run: { value: run }, + _offset: { value: offset }, + char: { + value: run >= runArray.length ? null : + runs.getTextChar(runArray[run].text, offset) + } }); - }; - } else { - // old school shim for old browsers - module.exports = function inherits(ctor, superCtor) { - ctor.super_ = superCtor - var TempCtor = function () {} - TempCtor.prototype = superCtor.prototype - ctor.prototype = new TempCtor() - ctor.prototype.constructor = ctor - } } - -/***/ }, -/* 52 */ -/***/ function(module, exports, __webpack_require__) { - - /* WEBPACK VAR INJECTION */(function(process) {exports = module.exports = __webpack_require__(53); - exports.Stream = __webpack_require__(49); - exports.Readable = exports; - exports.Writable = __webpack_require__(62); - exports.Duplex = __webpack_require__(61); - exports.Transform = __webpack_require__(64); - exports.PassThrough = __webpack_require__(65); - if (!process.browser && process.env.READABLE_STREAM === 'disable') { - module.exports = __webpack_require__(49); + function firstNonEmpty(runArray, n) { + for (; n < runArray.length; n++) { + if (runs.getTextLength(runArray[n].text) != 0) { + return character(runArray, n, 0); + } + } + return character(runArray, runArray.length, 0); } - /* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(10))) - -/***/ }, -/* 53 */ -/***/ function(module, exports, __webpack_require__) { - - /* WEBPACK VAR INJECTION */(function(process) {// Copyright Joyent, Inc. and other Node contributors. - // - // Permission is hereby granted, free of charge, to any person obtaining a - // copy of this software and associated documentation files (the - // "Software"), to deal in the Software without restriction, including - // without limitation the rights to use, copy, modify, merge, publish, - // distribute, sublicense, and/or sell copies of the Software, and to permit - // persons to whom the Software is furnished to do so, subject to the - // following conditions: - // - // The above copyright notice and this permission notice shall be included - // in all copies or substantial portions of the Software. - // - // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN - // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, - // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR - // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE - // USE OR OTHER DEALINGS IN THE SOFTWARE. + module.exports = function(runArray) { + return function(emit) { + var c = firstNonEmpty(runArray, 0); + while (!emit(c) && (c.char !== null)) { + c = (c._offset + 1 < runs.getTextLength(runArray[c._run].text)) + ? character(runArray, c._run, c._offset + 1) + : firstNonEmpty(runArray, c._run + 1); + } + }; + }; - module.exports = Readable; +/***/ }, +/* 36 */ +/***/ function(module, exports) { - /**/ - var isArray = __webpack_require__(54); - /**/ + /* Creates a stateful transformer function that consumes Characters and produces "word coordinate" + objects, which are triplets of Characters representing the first characters of: + start - the word itself + end - any trailing whitespace + next - the subsequent word, or end of document. - /**/ - var Buffer = __webpack_require__(55).Buffer; - /**/ + Newline characters are NOT whitespace. They are always emitted as separate single-character + words. - Readable.ReadableState = ReadableState; + If start.equals(end) then the "word" only contains whitespace and so must represent spaces + at the start of a line. So even in this case, whitespace is always treated as "trailing + after" a word - even if that word happens to be zero characters long! + */ - var EE = __webpack_require__(50).EventEmitter; + module.exports = function(codes) { - /**/ - if (!EE.listenerCount) EE.listenerCount = function(emitter, type) { - return emitter.listeners(type).length; + var word = null, trailingSpaces = null, newLine = true; + + return function(emit, inputChar) { + + var endOfWord; + if (inputChar.char === null) { + endOfWord = true; + } else { + if (newLine) { + endOfWord = true; + newLine = false; + } + if (typeof inputChar.char === 'string') { + switch (inputChar.char) { + case ' ': + if (!trailingSpaces) { + trailingSpaces = inputChar; + } + break; + case '\n': + endOfWord = true; + newLine = true; + break; + default: + if (trailingSpaces) { + endOfWord = true; + } + } + } else { + var code = codes(inputChar.char); + if (code.block || code.eof) { + endOfWord = true; + newLine = true; + } + } + } + if (endOfWord) { + if (word && !word.equals(inputChar)) { + if (emit({ + text: word, + spaces: trailingSpaces || inputChar, + end: inputChar + }) === false) { + return false; + } + trailingSpaces = null; + } + if (inputChar.char === null) { + emit(null); // Indicate end of stream + } + + word = inputChar; + } + }; }; - /**/ - var Stream = __webpack_require__(49); - /**/ - var util = __webpack_require__(59); - util.inherits = __webpack_require__(51); - /**/ +/***/ }, +/* 37 */ +/***/ function(module, exports, __webpack_require__) { - var StringDecoder; + var per = __webpack_require__(29); + var part = __webpack_require__(38); + var runs = __webpack_require__(30); + /* A Word has the following properties: - /**/ - var debug = __webpack_require__(60); - if (debug && debug.debuglog) { - debug = debug.debuglog('stream'); - } else { - debug = function () {}; - } - /**/ + text - Section (see below) for non-space portion of word. + space - Section for trailing space portion of word. + ascent - Ascent (distance from baseline to top) for whole word + descent - Descent (distance from baseline to bottom) for whole word + width - Width of the whole word (including trailing space) + It has methods: - util.inherits(Readable, Stream); + isNewLine() + - Returns true if the Word represents a newline. Newlines are + always represented by separate words. - function ReadableState(options, stream) { - var Duplex = __webpack_require__(61); + draw(ctx, x, y) + - Draws the Word at x, y on the canvas context ctx. - options = options || {}; + Note: a section (i.e. text and space) is an object containing: - // the point at which it stops calling _read() to fill the buffer - // Note: 0 is a valid value, means "don't call _read preemptively ever" - var hwm = options.highWaterMark; - var defaultHwm = options.objectMode ? 16 : 16 * 1024; - this.highWaterMark = (hwm || hwm === 0) ? hwm : defaultHwm; + parts - array of Parts + ascent - Ascent (distance from baseline to top) for whole section + descent - Descent (distance from baseline to bottom) for whole section + width - Width of the whole section + */ - // cast to ints. - this.highWaterMark = ~~this.highWaterMark; + var prototype = { + isNewLine: function() { + return this.text.parts.length == 1 && this.text.parts[0].isNewLine; + }, + code: function() { + return this.text.parts.length == 1 && this.text.parts[0].code; + }, + codeFormatting: function() { + return this.text.parts.length == 1 && this.text.parts[0].run; + }, + draw: function(ctx, x, y) { + per(this.text.parts).concat(this.space.parts).forEach(function(part) { + part.draw(ctx, x, y); + x += part.width; + }); + }, + plainText: function() { + return this.text.plainText + this.space.plainText; + }, + align: function() { + var first = this.text.parts[0]; + return first ? first.run.align : 'left'; + }, + runs: function(emit, range) { + var start = range && range.start || 0, + end = range && range.end; + if (typeof end !== 'number') { + end = Number.MAX_VALUE; + } + [this.text, this.space].forEach(function(section) { + section.parts.some(function(part) { + if (start >= end || end <= 0) { + return true; + } + var run = part.run, text = run.text; + if (typeof text === 'string') { + if (start <= 0 && end >= text.length) { + emit(run); + } else if (start < text.length) { + var pieceRun = Object.create(run); + var firstChar = Math.max(0, start); + pieceRun.text = text.substr( + firstChar, + Math.min(text.length, end - firstChar) + ); + emit(pieceRun); + } + start -= text.length; + end -= text.length; + } else { + if (start <= 0 && end >= 1) { + emit(run); + } + start--; + end--; + } + }); + }); + } + }; - this.buffer = []; - this.length = 0; - this.pipes = null; - this.pipesCount = 0; - this.flowing = null; - this.ended = false; - this.endEmitted = false; - this.reading = false; + var section = function(runEmitter, codes) { + var s = { + parts: per(runEmitter).map(function(p) { + return part(p, codes); + }).all(), + ascent: 0, + descent: 0, + width: 0, + length: 0, + plainText: '' + }; + s.parts.forEach(function(p) { + s.ascent = Math.max(s.ascent, p.ascent); + s.descent = Math.max(s.descent, p.descent); + s.width += p.width; + s.length += runs.getPieceLength(p.run.text); + s.plainText += runs.getPiecePlainText(p.run.text); + }); + return s; + }; - // a flag to be able to tell if the onwrite cb is called immediately, - // or on a later tick. We set this to true at first, because any - // actions that shouldn't happen until "later" should generally also - // not happen before the first write call. - this.sync = true; + module.exports = function(coords, codes) { + var text, space; + if (!coords) { + // special end-of-document marker, mostly like a newline with no formatting + text = [{ text: '\n' }]; + space = []; + } else { + text = coords.text.cut(coords.spaces); + space = coords.spaces.cut(coords.end); + } + text = section(text, codes); + space = section(space, codes); + var word = Object.create(prototype, { + text: { value: text }, + space: { value: space }, + ascent: { value: Math.max(text.ascent, space.ascent) }, + descent: { value: Math.max(text.descent, space.descent) }, + width: { value: text.width + space.width, configurable: true }, + length: { value: text.length + space.length } + }); + if (!coords) { + Object.defineProperty(word, 'eof', { value: true }); + } + return word; + }; - // whenever we return null, then we set a flag to say - // that we're awaiting a 'readable' event emission. - this.needReadable = false; - this.emittedReadable = false; - this.readableListening = false; +/***/ }, +/* 38 */ +/***/ function(module, exports, __webpack_require__) { - // object stream flag. Used to make read(n) ignore n and to - // make all the buffer merging and length checks go away - this.objectMode = !!options.objectMode; + var text = __webpack_require__(39); + + var defaultInline = { + measure: function(formatting) { + var text = text.measure('?', formatting); + return { + width: text.width + 4, + ascent: text.width + 2, + descent: text.width + 2 + }; + }, + draw: function(ctx, x, y, width, ascent, descent) { + ctx.fillStyle = 'silver'; + ctx.fillRect(x, y - ascent, width, ascent + descent); + ctx.strokeRect(x, y - ascent, width, ascent + descent); + ctx.fillStyle = 'black'; + ctx.fillText('?', x + 2, y); + } + }; - if (stream instanceof Duplex) - this.objectMode = this.objectMode || !!options.readableObjectMode; + /* A Part is a section of a word with its own run, because a Word can span the + boundaries between runs, so it may have several parts in its text or space + arrays. - // Crypto is kind of old and crusty. Historically, its default string - // encoding is 'binary' so we have to make this configurable. - // Everything else in the universe uses 'utf8', though. - this.defaultEncoding = options.defaultEncoding || 'utf8'; + run - Run being measured. + isNewLine - True if this part only contain a newline (\n). This will be + the only Part in the Word, and this is the only way newlines + ever occur. + width - Width of the run + ascent - Distance from baseline to top + descent - Distance from baseline to bottom - // when piping, we only care about 'readable' events that happen - // after read()ing all the bytes and not getting any pushback. - this.ranOut = false; + And methods: - // the number of writers that are awaiting a drain event in .pipe()s - this.awaitDrain = 0; + draw(ctx, x, y) + - Draws the Word at x, y on the canvas context ctx. The y + coordinate is assumed to be the baseline. The call + prepareContext(ctx) will set the canvas up appropriately. + */ + var prototype = { + draw: function(ctx, x, y) { + if (typeof this.run.text === 'string') { + text.draw(ctx, this.run.text, this.run, x, y, this.width, this.ascent, this.descent); + } else if (this.code && this.code.draw) { + ctx.save(); + this.code.draw(ctx, x, y, this.width, this.ascent, this.descent, this.run); + ctx.restore(); + } + } + }; - // if true, a maybeReadMore has been scheduled - this.readingMore = false; + module.exports = function(run, codes) { - this.decoder = null; - this.encoding = null; - if (options.encoding) { - if (!StringDecoder) - StringDecoder = __webpack_require__(63).StringDecoder; - this.decoder = new StringDecoder(options.encoding); - this.encoding = options.encoding; - } - } + var m, isNewLine, code; + if (typeof run.text === 'string') { + isNewLine = (run.text.length === 1) && (run.text[0] === '\n'); + m = text.measure(isNewLine ? text.nbsp : run.text, run); + } else { + code = codes(run.text) || defaultInline; + m = code.measure ? code.measure(run) : { + width: 0, ascent: 0, descent: 0 + }; + } - function Readable(options) { - var Duplex = __webpack_require__(61); + var part = Object.create(prototype, { + run: { value: run }, + isNewLine: { value: isNewLine }, + width: { value: isNewLine ? 0 : m.width }, + ascent: { value: m.ascent }, + descent: { value: m.descent } + }); + if (code) { + Object.defineProperty(part, 'code', { value: code }); + } + return part; + }; - if (!(this instanceof Readable)) - return new Readable(options); - this._readableState = new ReadableState(options, this); +/***/ }, +/* 39 */ +/***/ function(module, exports, __webpack_require__) { - // legacy - this.readable = true; + var runs = __webpack_require__(30); - Stream.call(this); - } + /* Returns a font CSS/Canvas string based on the settings in a run + */ + var getFontString = exports.getFontString = function(run) { - // Manually shove something into the read() buffer. - // This returns true if the highWaterMark has not been hit yet, - // similar to how Writable.write() returns true if you should - // write() some more. - Readable.prototype.push = function(chunk, encoding) { - var state = this._readableState; + var size = (run && run.size) || runs.defaultFormatting.size; - if (util.isString(chunk) && !state.objectMode) { - encoding = encoding || state.defaultEncoding; - if (encoding !== state.encoding) { - chunk = new Buffer(chunk, encoding); - encoding = ''; + if (run) { + switch (run.script) { + case 'super': + case 'sub': + size *= 0.8; + break; + } } - } - return readableAddChunk(this, state, chunk, encoding, false); + return (run && run.italic ? 'italic ' : '') + + (run && run.bold ? 'bold ' : '') + ' ' + + size + 'pt ' + + ((run && run.font) || runs.defaultFormatting.font); }; - // Unshift should *always* be something directly out of read() - Readable.prototype.unshift = function(chunk) { - var state = this._readableState; - return readableAddChunk(this, state, chunk, '', true); + /* Applies the style of a run to the canvas context + */ + exports.applyRunStyle = function(ctx, run) { + ctx.fillStyle = (run && run.color) || runs.defaultFormatting.color; + ctx.font = getFontString(run); }; - function readableAddChunk(stream, state, chunk, encoding, addToFront) { - var er = chunkInvalid(state, chunk); - if (er) { - stream.emit('error', er); - } else if (util.isNullOrUndefined(chunk)) { - state.reading = false; - if (!state.ended) - onEofChunk(stream, state); - } else if (state.objectMode || chunk && chunk.length > 0) { - if (state.ended && !addToFront) { - var e = new Error('stream.push() after EOF'); - stream.emit('error', e); - } else if (state.endEmitted && addToFront) { - var e = new Error('stream.unshift() after end event'); - stream.emit('error', e); - } else { - if (state.decoder && !addToFront && !encoding) - chunk = state.decoder.write(chunk); - - if (!addToFront) - state.reading = false; + exports.prepareContext = function(ctx) { + ctx.textAlign = 'left'; + ctx.textBaseline = 'alphabetic'; + }; - // if we want the data now, just emit it. - if (state.flowing && state.length === 0 && !state.sync) { - stream.emit('data', chunk); - stream.read(0); - } else { - // update the buffer info. - state.length += state.objectMode ? 1 : chunk.length; - if (addToFront) - state.buffer.unshift(chunk); - else - state.buffer.push(chunk); - - if (state.needReadable) - emitReadable(stream); - } + /* Generates the value for a CSS style attribute + */ + exports.getRunStyle = function(run) { + var parts = [ + 'font: ', getFontString(run), + '; color: ', ((run && run.color) || runs.defaultFormatting.color) + ]; - maybeReadMore(stream, state); + if (run) { + switch (run.script) { + case 'super': + parts.push('; vertical-align: super'); + break; + case 'sub': + parts.push('; vertical-align: sub'); + break; + } } - } else if (!addToFront) { - state.reading = false; - } - return needMoreData(state); - } + return parts.join(''); + }; + var nbsp = exports.nbsp = String.fromCharCode(160); + var enter = exports.enter = nbsp; // String.fromCharCode(9166); + /* Returns width, height, ascent, descent in pixels for the specified text and font. + The ascent and descent are measured from the baseline. Note that we add/remove + all the DOM elements used for a measurement each time - this is not a significant + part of the cost, and if we left the hidden measuring node in the DOM then it + would affect the dimensions of the whole page. + */ + var measureText = exports.measureText = function(text, style) { + var span, block, div; - // if it's past the high water mark, we can push in some more. - // Also, if we have no data yet, we can stand some - // more bytes. This is to work around cases where hwm=0, - // such as the repl. Also, if the push() triggered a - // readable event, and the user called read(largeNumber) such that - // needReadable was set, then we ought to push more, so that another - // 'readable' event will be triggered. - function needMoreData(state) { - return !state.ended && - (state.needReadable || - state.length < state.highWaterMark || - state.length === 0); - } + span = document.createElement('span'); + block = document.createElement('div'); + div = document.createElement('div'); - // backwards compatibility. - Readable.prototype.setEncoding = function(enc) { - if (!StringDecoder) - StringDecoder = __webpack_require__(63).StringDecoder; - this._readableState.decoder = new StringDecoder(enc); - this._readableState.encoding = enc; - return this; - }; + block.style.display = 'inline-block'; + block.style.width = '1px'; + block.style.height = '0'; - // Don't raise the hwm > 128MB - var MAX_HWM = 0x800000; - function roundUpToNextPowerOf2(n) { - if (n >= MAX_HWM) { - n = MAX_HWM; - } else { - // Get the next highest power of 2 - n--; - for (var p = 1; p < 32; p <<= 1) n |= n >> p; - n++; - } - return n; - } + div.style.visibility = 'hidden'; + div.style.position = 'absolute'; + div.style.top = '0'; + div.style.left = '0'; + div.style.width = '500px'; + div.style.height = '200px'; - function howMuchToRead(n, state) { - if (state.length === 0 && state.ended) - return 0; + div.appendChild(span); + div.appendChild(block); + document.body.appendChild(div); + try { + span.setAttribute('style', style); - if (state.objectMode) - return n === 0 ? 0 : 1; + span.innerHTML = ''; + span.appendChild(document.createTextNode(text.replace(/\s/g, nbsp))); - if (isNaN(n) || util.isNull(n)) { - // only flow one buffer at a time - if (state.flowing && state.buffer.length) - return state.buffer[0].length; - else - return state.length; - } + var result = {}; + block.style.verticalAlign = 'baseline'; + result.ascent = (block.offsetTop - span.offsetTop); + block.style.verticalAlign = 'bottom'; + result.height = (block.offsetTop - span.offsetTop); + result.descent = result.height - result.ascent; + result.width = span.offsetWidth; + } finally { + div.parentNode.removeChild(div); + div = null; + } + return result; + }; - if (n <= 0) - return 0; + /* Create a function that works like measureText except it caches every result for every + unique combination of (text, style) - that is, it memoizes measureText. - // If we're asking for more than the target buffer level, - // then raise the water mark. Bump up to the next highest - // power of 2, to prevent increasing it excessively in tiny - // amounts. - if (n > state.highWaterMark) - state.highWaterMark = roundUpToNextPowerOf2(n); + So for example: - // don't have that much. return null, unless we've ended. - if (n > state.length) { - if (!state.ended) { - state.needReadable = true; - return 0; - } else - return state.length; - } + var measure = cachedMeasureText(); - return n; - } + Then you can repeatedly do lots of separate calls to measure, e.g.: - // you can override either this method, or the async _read(n) below. - Readable.prototype.read = function(n) { - debug('read', n); - var state = this._readableState; - var nOrig = n; + var m = measure('Hello, world', 'font: 12pt Arial'); + console.log(m.ascent, m.descent, m.width); - if (!util.isNumber(n) || n > 0) - state.emittedReadable = false; + A cache may grow without limit if the text varies a lot. However, during normal interactive + editing the growth rate will be slow. If memory consumption becomes a problem, the cache + can be occasionally discarded, although of course this will cause a slow down as the cache + has to build up again (text measuring is by far the most costly operation we have to do). + */ + var createCachedMeasureText = exports.createCachedMeasureText = function() { + var cache = {}; + return function(text, style) { + var key = style + '<>!&%' + text; + var result = cache[key]; + if (!result) { + cache[key] = result = measureText(text, style); + } + return result; + }; + }; - // if we're doing read(0) to trigger a readable event, but we - // already have a bunch of data in the buffer, then just trigger - // the 'readable' event and move on. - if (n === 0 && - state.needReadable && - (state.length >= state.highWaterMark || state.ended)) { - debug('read: emitReadable', state.length, state.ended); - if (state.length === 0 && state.ended) - endReadable(this); - else - emitReadable(this); - return null; - } + exports.cachedMeasureText = createCachedMeasureText(); - n = howMuchToRead(n, state); + exports.measure = function(str, formatting) { + return exports.cachedMeasureText(str, exports.getRunStyle(formatting)); + }; - // if we've ended, and we're now clear, then finish it up. - if (n === 0 && state.ended) { - if (state.length === 0) - endReadable(this); - return null; - } + exports.draw = function(ctx, str, formatting, left, baseline, width, ascent, descent) { + exports.prepareContext(ctx); + exports.applyRunStyle(ctx, formatting); + switch (formatting.script) { + case 'super': + baseline -= (ascent * (1/3)); + break; + case 'sub': + baseline += (descent / 2); + break; + } + ctx.fillText(str === '\n' ? exports.enter : str, left, baseline); + if (formatting.underline) { + ctx.fillRect(left, 1 + baseline, width, 1); + } + if (formatting.strikeout) { + ctx.fillRect(left, 1 + baseline - (ascent/2), width, 1); + } + }; - // All the actual chunk generation logic needs to be - // *below* the call to _read. The reason is that in certain - // synthetic stream cases, such as passthrough streams, _read - // may be a completely synchronous operation which may change - // the state of the read buffer, providing enough data when - // before there was *not* enough. - // - // So, the steps are: - // 1. Figure out what the state of things will be after we do - // a read from the buffer. - // - // 2. If that resulting state will trigger a _read, then call _read. - // Note that this may be asynchronous, or synchronous. Yes, it is - // deeply ugly to write APIs this way, but that still doesn't mean - // that the Readable class should behave improperly, as streams are - // designed to be sync/async agnostic. - // Take note if the _read call is sync or async (ie, if the read call - // has returned yet), so that we know whether or not it's safe to emit - // 'readable' etc. - // - // 3. Actually pull the requested chunks out of the buffer and return. +/***/ }, +/* 40 */ +/***/ function(module, exports, __webpack_require__) { - // if we need a readable event, then we need to do some reading. - var doRead = state.needReadable; - debug('need readable', doRead); + var per = __webpack_require__(29); + var runs = __webpack_require__(30); - // if we currently have less than the highWaterMark, then also read some - if (state.length === 0 || state.length - n < state.highWaterMark) { - doRead = true; - debug('length less than watermark', doRead); - } + function Range(doc, start, end) { + this.doc = doc; + this.start = start; + this.end = end; + if (start > end) { + this.start = end; + this.end = start; + } + } - // however, if we've ended, then there's no point, and if we're already - // reading, then it's unnecessary. - if (state.ended || state.reading) { - doRead = false; - debug('reading or ended', doRead); - } + Range.prototype.parts = function(emit, list) { + list = list || this.doc.children(); + var self = this; - if (doRead) { - debug('do read'); - state.reading = true; - state.sync = true; - // if the length is currently zero, then we *need* a readable event. - if (state.length === 0) - state.needReadable = true; - // call internal read method - this._read(state.highWaterMark); - state.sync = false; - } + list.some(function(item) { + if (item.ordinal + item.length <= self.start) { + return false; + } + if (item.ordinal >= self.end) { + return true; + } + if (item.ordinal >= self.start && + item.ordinal + item.length <= self.end) { + emit(item); + } else { + self.parts(emit, item.children()); + } + }); + }; - // If _read pushed data synchronously, then `reading` will be false, - // and we need to re-evaluate how much data we can return to the user. - if (doRead && !state.reading) - n = howMuchToRead(nOrig, state); + Range.prototype.clear = function() { + return this.setText([]); + }; - var ret; - if (n > 0) - ret = fromList(n, state); - else - ret = null; + Range.prototype.setText = function(text) { + return this.doc.splice(this.start, this.end, text); + }; - if (util.isNull(ret)) { - state.needReadable = true; - n = 0; - } + Range.prototype.runs = function(emit) { + this.doc.runs(emit, this); + }; - state.length -= n; + Range.prototype.plainText = function() { + return per(this.runs, this).map(runs.getPlainText).all().join(''); + }; - // If we have nothing in the buffer, then we want to know - // as soon as we *do* get something into the buffer. - if (state.length === 0 && !state.ended) - state.needReadable = true; + Range.prototype.save = function() { + return per(this.runs, this).per(runs.consolidate()).all(); + }; - // If we tried to read() past the EOF, then emit end on the next tick. - if (nOrig !== n && state.ended && state.length === 0) - endReadable(this); + Range.prototype.getFormatting = function() { + var range = this; + if (range.start === range.end) { + var pos = range.start; + // take formatting of character before, if any, because that's + // where plain text picks up formatting when inserted + if (pos > 0) { + pos--; + } + range.start = pos; + range.end = pos + 1; + } + return per(range.runs, range).reduce(runs.merge).last() || runs.defaultFormatting; + }; - if (!util.isNull(ret)) - this.emit('data', ret); + Range.prototype.setFormatting = function(attribute, value) { + var range = this; + if (attribute === 'align') { + // Special case: expand selection to surrounding paragraphs + range = range.doc.paragraphRange(range.start, range.end); + } + if (range.start === range.end) { + range.doc.modifyInsertFormatting(attribute, value); + } else { + var saved = range.save(); + var template = {}; + template[attribute] = value; + runs.format(saved, template); + range.setText(saved); + } + }; - return ret; + module.exports = function(doc, start, end) { + return new Range(doc, start, end); }; - function chunkInvalid(state, chunk) { - var er = null; - if (!util.isBuffer(chunk) && - !util.isString(chunk) && - !util.isNullOrUndefined(chunk) && - !state.objectMode) { - er = new TypeError('Invalid non-string/buffer chunk'); - } - return er; - } +/***/ }, +/* 41 */ +/***/ function(module, exports, __webpack_require__) { + var node = __webpack_require__(28); + var wrap = __webpack_require__(42); + var rect = __webpack_require__(31); - function onEofChunk(stream, state) { - if (state.decoder && !state.ended) { - var chunk = state.decoder.end(); - if (chunk && chunk.length) { - state.buffer.push(chunk); - state.length += state.objectMode ? 1 : chunk.length; - } - } - state.ended = true; + var prototype = node.derive({ + bounds: function() { + if (!this._bounds) { + var left = 0, top = 0, right = 0, bottom = 0; + if (this.lines.length) { + var first = this.lines[0].bounds(); + left = first.l; + top = first.t; + this.lines.forEach(function(line) { + var b = line.bounds(); + right = Math.max(right, b.l + b.w); + bottom = Math.max(bottom, b.t + b.h); + }); + } + this._bounds = rect(left, top, right - left, this.height || bottom - top); + } + return this._bounds; + }, + actualWidth: function() { + if (!this._actualWidth) { + var result = 0; + this.lines.forEach(function(line) { + if (typeof line.actualWidth === 'number') { + result = Math.max(result, line.actualWidth); + } + }); + this._actualWidth = result; + } + return this._actualWidth; + }, + children: function() { + return this.lines; + }, + parent: function() { + return this._parent; + }, + draw: function(ctx, viewPort) { + var top = viewPort ? viewPort.t : 0; + var bottom = viewPort ? (viewPort.t + viewPort.h) : Number.MAX_VALUE; + this.lines.some(function(line) { + var b = line.bounds(); + if (b.t + b.h < top) { + return false; + } + if (b.t > bottom) { + return true; + } + line.draw(ctx, viewPort); + }); + }, + type: 'frame' + }); - // emit 'readable' now to make sure it gets picked up. - emitReadable(stream); - } + exports = module.exports = function(left, top, width, ordinal, parent, + includeTerminator, initialAscent, initialDescent) { + var lines = []; + var frame = Object.create(prototype, { + lines: { value: lines }, + _parent: { value: parent }, + ordinal: { value: ordinal } + }); + var wrapper = wrap(left, top, width, ordinal, frame, includeTerminator, initialAscent, initialDescent); + var length = 0, height = 0; + return function(emit, word) { + if (wrapper(function(line) { + if (typeof line === 'number') { + height = line; + } else { + length = (line.ordinal + line.length) - ordinal; + lines.push(line); + } + }, word)) { + Object.defineProperty(frame, 'length', { value: length }); + Object.defineProperty(frame, 'height', { value: height }); + emit(frame); + return true; + } + }; + }; - // Don't emit readable right away in sync mode, because this can trigger - // another read() call => stack overflow. This way, it might trigger - // a nextTick recursion warning, but that's not so bad. - function emitReadable(stream) { - var state = stream._readableState; - state.needReadable = false; - if (!state.emittedReadable) { - debug('emitReadable', state.flowing); - state.emittedReadable = true; - if (state.sync) - process.nextTick(function() { - emitReadable_(stream); - }); - else - emitReadable_(stream); - } - } - function emitReadable_(stream) { - debug('emit readable'); - stream.emit('readable'); - flow(stream); - } +/***/ }, +/* 42 */ +/***/ function(module, exports, __webpack_require__) { + var line = __webpack_require__(43); - // at this point, the user has presumably seen the 'readable' event, - // and called read() to consume some data. that may have triggered - // in turn another _read(n) call, in which case reading = true if - // it's in progress. - // However, if we're not ended, or reading, and the length < hwm, - // then go ahead and try to read some more preemptively. - function maybeReadMore(stream, state) { - if (!state.readingMore) { - state.readingMore = true; - process.nextTick(function() { - maybeReadMore_(stream, state); - }); - } - } + /* A stateful transformer function that accepts words and emits lines. If the first word + is too wide, it will overhang; if width is zero or negative, there will be one word on + each line. - function maybeReadMore_(stream, state) { - var len = state.length; - while (!state.reading && !state.flowing && !state.ended && - state.length < state.highWaterMark) { - debug('maybeReadMore read 0'); - stream.read(0); - if (len === state.length) - // didn't get any data, stop spinning. - break; - else - len = state.length; - } - state.readingMore = false; - } + The y-coordinate is the top of the first line, not the baseline. - // abstract method. to be overridden in specific implementation classes. - // call cb(er, data) where data is <= n in length. - // for virtual (non-string, non-buffer) streams, "length" is somewhat - // arbitrary, and perhaps not very meaningful. - Readable.prototype._read = function(n) { - this.emit('error', new Error('not implemented')); - }; + Returns a stream of line objects, each containing an array of positionedWord objects. + */ - Readable.prototype.pipe = function(dest, pipeOpts) { - var src = this; - var state = this._readableState; + module.exports = function(left, top, width, ordinal, parent, + includeTerminator, initialAscent, initialDescent) { - switch (state.pipesCount) { - case 0: - state.pipes = dest; - break; - case 1: - state.pipes = [state.pipes, dest]; - break; - default: - state.pipes.push(dest); - break; - } - state.pipesCount += 1; - debug('pipe count=%d opts=%j', state.pipesCount, pipeOpts); + var lineBuffer = [], + lineWidth = 0, + maxAscent = initialAscent || 0, + maxDescent = initialDescent || 0, + quit, + lastNewLineHeight = 0, + y = top; - var doEnd = (!pipeOpts || pipeOpts.end !== false) && - dest !== process.stdout && - dest !== process.stderr; + var store = function(word, emit) { + lineBuffer.push(word); + lineWidth += word.width; + maxAscent = Math.max(maxAscent, word.ascent); + maxDescent = Math.max(maxDescent, word.descent); + if (word.isNewLine()) { + send(emit); + lastNewLineHeight = word.ascent + word.descent; + } + }; - var endFn = doEnd ? onend : cleanup; - if (state.endEmitted) - process.nextTick(endFn); - else - src.once('end', endFn); + var send = function(emit) { + if (quit || lineBuffer.length === 0) { + return; + } + var l = line(parent, left, width, y + maxAscent, maxAscent, maxDescent, lineBuffer, ordinal); + ordinal += l.length; + quit = emit(l); + y += (maxAscent + maxDescent); + lineBuffer.length = 0; + lineWidth = maxAscent = maxDescent = 0; + }; - dest.on('unpipe', onunpipe); - function onunpipe(readable) { - debug('onunpipe'); - if (readable === src) { - cleanup(); - } - } + var consumer = null; - function onend() { - debug('onend'); - dest.end(); - } + return function(emit, inputWord) { + if (consumer) { + lastNewLineHeight = 0; + var node = consumer(inputWord); + if (node) { + consumer = null; + ordinal += node.length; + y += node.bounds().h; + Object.defineProperty(node, 'block', { value: true }); + emit(node); + } + } else { + var code = inputWord.code(); + if (code && code.block) { + if (lineBuffer.length) { + send(emit); + } else { + y += lastNewLineHeight; + } + consumer = code.block(left, y, width, ordinal, parent, inputWord.codeFormatting()); + lastNewLineHeight = 0; + } + else if (code && code.eof || inputWord.eof) { + if (!code || (includeTerminator && includeTerminator(code))) { + store(inputWord, emit); + } + if (!lineBuffer.length) { + emit(y + lastNewLineHeight - top); + } else { + send(emit); + emit(y - top); + } + quit = true; + } else { + lastNewLineHeight = 0; + if (!lineBuffer.length) { + store(inputWord, emit); + } else { + if (lineWidth + inputWord.text.width > width) { + send(emit); + } + store(inputWord, emit); + } + } + } + return quit; + }; + }; - // when the dest drains, it reduces the awaitDrain counter - // on the source. This would be more elegant with a .once() - // handler in flow(), but adding and removing repeatedly is - // too slow. - var ondrain = pipeOnDrain(src); - dest.on('drain', ondrain); - function cleanup() { - debug('cleanup'); - // cleanup event handlers once the pipe is broken - dest.removeListener('close', onclose); - dest.removeListener('finish', onfinish); - dest.removeListener('drain', ondrain); - dest.removeListener('error', onerror); - dest.removeListener('unpipe', onunpipe); - src.removeListener('end', onend); - src.removeListener('end', cleanup); - src.removeListener('data', ondata); +/***/ }, +/* 43 */ +/***/ function(module, exports, __webpack_require__) { - // if the reader is waiting for a drain event from this - // specific writer, then it would cause it to never start - // flowing again. - // So, if this is awaiting a drain, then we just call it now. - // If we don't know, then assume that we are waiting for one. - if (state.awaitDrain && - (!dest._writableState || dest._writableState.needDrain)) - ondrain(); - } + var positionedWord = __webpack_require__(44); + var rect = __webpack_require__(31); + var node = __webpack_require__(28); + var runs = __webpack_require__(30); - src.on('data', ondata); - function ondata(chunk) { - debug('ondata'); - var ret = dest.write(chunk); - if (false === ret) { - debug('false write response, pause', - src._readableState.awaitDrain); - src._readableState.awaitDrain++; - src.pause(); - } - } + /* A Line is returned by the wrap function. It contains an array of PositionedWord objects that are + all on the same physical line in the wrapped text. - // if the dest has an error, then stop piping into it. - // however, don't suppress the throwing behavior for this. - function onerror(er) { - debug('onerror', er); - unpipe(); - dest.removeListener('error', onerror); - if (EE.listenerCount(dest, 'error') === 0) - dest.emit('error', er); - } - // This is a brutally ugly hack to make sure that our error handler - // is attached before any userland ones. NEVER DO THIS. - if (!dest._events || !dest._events.error) - dest.on('error', onerror); - else if (isArray(dest._events.error)) - dest._events.error.unshift(onerror); - else - dest._events.error = [onerror, dest._events.error]; + It has a width (which is actually the same for all lines returned by the same wrap). It also has + coordinates for baseline, ascent and descent. The ascent and descent have the maximum values of + the individual words' ascent and descent coordinates. + It has methods: + draw(ctx, x, y) + - Draw all the words in the line applying the specified (x, y) offset. + bounds() + - Returns a Rect for the bounding box. + */ - // Both close and finish should trigger unpipe, but only once. - function onclose() { - dest.removeListener('finish', onfinish); - unpipe(); - } - dest.once('close', onclose); - function onfinish() { - debug('onfinish'); - dest.removeListener('close', onclose); - unpipe(); - } - dest.once('finish', onfinish); + var prototype = node.derive({ + bounds: function(minimal) { + if (minimal) { + var firstWord = this.first().bounds(), + lastWord = this.last().bounds(); + return rect( + firstWord.l, + this.baseline - this.ascent, + (lastWord.l + lastWord.w) - firstWord.l, + this.ascent + this.descent); + } + return rect(this.left, this.baseline - this.ascent, + this.width, this.ascent + this.descent); + }, + parent: function() { + return this.doc; + }, + children: function() { + return this.positionedWords; + }, + type: 'line' + }); - function unpipe() { - debug('unpipe'); - src.unpipe(dest); - } + module.exports = function(doc, left, width, baseline, ascent, descent, words, ordinal) { - // tell the dest that it's being piped to - dest.emit('pipe', src); + var align = words[0].align(); - // start the flow if it hasn't been started already. - if (!state.flowing) { - debug('pipe resume'); - src.resume(); - } + var line = Object.create(prototype, { + doc: { value: doc }, // should be called frame, or else switch to using parent on all nodes + left: { value: left }, + width: { value: width }, + baseline: { value: baseline }, + ascent: { value: ascent }, + descent: { value: descent }, + ordinal: { value: ordinal }, + align: { value: align } + }); - return dest; - }; + var actualWidth = 0; + words.forEach(function(word) { + actualWidth += word.width; + }); + actualWidth -= words[words.length - 1].space.width; - function pipeOnDrain(src) { - return function() { - var state = src._readableState; - debug('pipeOnDrain', state.awaitDrain); - if (state.awaitDrain) - state.awaitDrain--; - if (state.awaitDrain === 0 && EE.listenerCount(src, 'data')) { - state.flowing = true; - flow(src); + var x = 0, spacing = 0; + if (actualWidth < width) { + switch (align) { + case 'right': + x = width - actualWidth; + break; + case 'center': + x = (width - actualWidth) / 2; + break; + case 'justify': + if (words.length > 1 && !words[words.length - 1].isNewLine()) { + spacing = (width - actualWidth) / (words.length - 1); + } + break; + } } - }; - } - - Readable.prototype.unpipe = function(dest) { - var state = this._readableState; + Object.defineProperty(line, 'positionedWords', { + value: words.map(function(word) { + var wordLeft = x; + x += (word.width + spacing); + var wordOrdinal = ordinal; + ordinal += (word.text.length + word.space.length); + return positionedWord(word, line, wordLeft, wordOrdinal, word.width + spacing); + }) + }); - // if we're not piping anywhere, then do nothing. - if (state.pipesCount === 0) - return this; + Object.defineProperty(line, 'actualWidth', { value: actualWidth }); + Object.defineProperty(line, 'length', { value: ordinal - line.ordinal }); + return line; + }; - // just one destination. most common case. - if (state.pipesCount === 1) { - // passed in one, but it's not the right one. - if (dest && dest !== state.pipes) - return this; - if (!dest) - dest = state.pipes; +/***/ }, +/* 44 */ +/***/ function(module, exports, __webpack_require__) { - // got a match. - state.pipes = null; - state.pipesCount = 0; - state.flowing = false; - if (dest) - dest.emit('unpipe', this); - return this; - } + var rect = __webpack_require__(31); + var part = __webpack_require__(38); + var text = __webpack_require__(39); + var node = __webpack_require__(28); + var word = __webpack_require__(37); + var runs = __webpack_require__(30); - // slow case. multiple pipe destinations. + var newLineWidth = function(run) { + return text.measure(text.enter, run).width; + }; - if (!dest) { - // remove all. - var dests = state.pipes; - var len = state.pipesCount; - state.pipes = null; - state.pipesCount = 0; - state.flowing = false; + var positionedChar = node.derive({ + bounds: function() { + var wb = this.word.bounds(); + var width = this.word.word.isNewLine() + ? newLineWidth(this.word.word.run) + : this.width || this.part.width; + return rect(wb.l + this.left, wb.t, width, wb.h); + }, + parent: function() { + return this.word; + }, + byOrdinal: function() { + return this; + }, + byCoordinate: function(x, y) { + if (x <= this.bounds().center().x) { + return this; + } + return this.next(); + }, + type: 'character' + }); - for (var i = 0; i < len; i++) - dests[i].emit('unpipe', this); - return this; - } + /* A positionedWord is just a realised Word plus a reference back to the containing Line and + the left coordinate (x coordinate of the left edge of the word). - // try to find the right one. - var i = indexOf(state.pipes, dest); - if (i === -1) - return this; + It has methods: - state.pipes.splice(i, 1); - state.pipesCount -= 1; - if (state.pipesCount === 1) - state.pipes = state.pipes[0]; + draw(ctx, x, y) + - Draw the word within its containing line, applying the specified (x, y) + offset. + bounds() + - Returns a rect for the bounding box. + */ + var prototype = node.derive({ + draw: function(ctx) { + this.word.draw(ctx, this.line.left + this.left, this.line.baseline); - dest.emit('unpipe', this); + // Handy for showing how word boundaries work + // var b = this.bounds(); + // ctx.strokeRect(b.l, b.t, b.w, b.h); + }, + bounds: function() { + return rect( + this.line.left + this.left, + this.line.baseline - this.line.ascent, + this.word.isNewLine() ? newLineWidth(this.word.run) : this.width, + this.line.ascent + this.line.descent); + }, + parts: function(eachPart) { + this.word.text.parts.some(eachPart) || + this.word.space.parts.some(eachPart); + }, + realiseCharacters: function() { + if (!this._characters) { + var cache = []; + var x = 0, self = this, ordinal = this.ordinal, + codes = this.parentOfType('document').codes; + this.parts(function(wordPart) { + runs.pieceCharacters(function(char) { + var charRun = Object.create(wordPart.run); + charRun.text = char; + var p = part(charRun, codes); + cache.push(Object.create(positionedChar, { + left: { value: x }, + part: { value: p }, + word: { value: self }, + ordinal: { value: ordinal }, + length: { value: 1 } + })); + x += p.width; + ordinal++; + }, wordPart.run.text); + }); + // Last character is artificially widened to match the length of the + // word taking into account (align === 'justify') + var lastChar = cache[cache.length - 1]; + if (lastChar) { + Object.defineProperty(lastChar, 'width', + { value: this.width - lastChar.left }); + if (this.word.isNewLine() || (this.word.code() && this.word.code().eof)) { + Object.defineProperty(lastChar, 'newLine', { value: true }); + } + } + this._characters = cache; + } + }, + children: function() { + this.realiseCharacters(); + return this._characters; + }, + parent: function() { + return this.line; + }, + type: 'word' + }); - return this; + module.exports = function(word, line, left, ordinal, width) { + var pword = Object.create(prototype, { + word: { value: word }, + line: { value: line }, + left: { value: left }, + width: { value: width }, // can be different to word.width if (align == 'justify') + ordinal: { value: ordinal }, + length: { value: word.text.length + word.space.length } + }); + return pword; }; - // set up data events if they are asked for - // Ensure readable listeners eventually get something - Readable.prototype.on = function(ev, fn) { - var res = Stream.prototype.on.call(this, ev, fn); - // If listening to data, and it has not explicitly been paused, - // then call resume to start the flow of data on the next tick. - if (ev === 'data' && false !== this._readableState.flowing) { - this.resume(); - } +/***/ }, +/* 45 */ +/***/ function(module, exports, __webpack_require__) { - if (ev === 'readable' && this.readable) { - var state = this._readableState; - if (!state.readableListening) { - state.readableListening = true; - state.emittedReadable = false; - state.needReadable = true; - if (!state.reading) { - var self = this; - process.nextTick(function() { - debug('readable nexttick read 0'); - self.read(0); - }); - } else if (state.length) { - emitReadable(this, state); - } + var text = __webpack_require__(39); + var frame = __webpack_require__(41); + var node = __webpack_require__(28); + var rect = __webpack_require__(31); + var util = __webpack_require__(32); + + var inlineNodePrototype = node.derive({ + parent: function() { + return this._parent; + }, + draw: function(ctx) { + this.inline.draw(ctx, + this.left, + this.baseline, + this.measured.width, + this.measured.ascent, + this.measured.descent, + this.formatting); + }, + position: function(left, baseline, bounds) { + this.left = left; + this.baseline = baseline; + if (bounds) { + this._bounds = bounds; + } + }, + bounds: function() { + return this._bounds || rect(this.left, this.baseline - this.measured.ascent, + this.measured.width, this.measured.ascent + this.measured.descent); + }, + byCoordinate: function(x, y) { + if (x <= this.bounds().center().x) { + return this; + } + return this.next(); } - } - - return res; - }; - Readable.prototype.addListener = Readable.prototype.on; + }); - // pause() and resume() are remnants of the legacy readable stream API - // If the user uses them, then switch into old mode. - Readable.prototype.resume = function() { - var state = this._readableState; - if (!state.flowing) { - debug('resume'); - state.flowing = true; - if (!state.reading) { - debug('resume read 0'); - this.read(0); + var inlineNode = function(inline, parent, ordinal, length, formatting) { + if (!inline.draw || !inline.measure) { + throw new Error(); } - resume(this, state); - } - return this; + return Object.create(inlineNodePrototype, { + inline: { value: inline }, + _parent: { value: parent }, + ordinal: { value: ordinal }, + length: { value: length }, + formatting: { value: formatting }, + measured: { + value: inline.measure(formatting) + } + }); }; - function resume(stream, state) { - if (!state.resumeScheduled) { - state.resumeScheduled = true; - process.nextTick(function() { - resume_(stream, state); - }); - } - } + var codes = {}; - function resume_(stream, state) { - state.resumeScheduled = false; - stream.emit('resume'); - flow(stream); - if (state.flowing && !state.reading) - stream.read(0); - } + codes.number = function(obj, number) { + var formattedNumber = (number + 1) + '.'; + return { + measure: function(formatting) { + return text.measure(formattedNumber, formatting); + }, + draw: function(ctx, x, y, width, ascent, descent, formatting) { + text.draw(ctx, formattedNumber, formatting, x, y, width, ascent, descent); + } + }; + }; - Readable.prototype.pause = function() { - debug('call pause flowing=%j', this._readableState.flowing); - if (false !== this._readableState.flowing) { - debug('pause'); - this._readableState.flowing = false; - this.emit('pause'); - } - return this; + var listTerminator = function(obj) { + return util.derive(obj, { + eof: true, + measure: function(formatting) { + return { width: 18, ascent: 0, descent: 0 }; // text.measure(text.enter, formatting); + }, + draw: function(ctx, x, y) { + // ctx.fillText(text.enter, x, y); + } + }); }; - function flow(stream) { - var state = stream._readableState; - debug('flow', state.flowing); - if (state.flowing) { - do { - var chunk = stream.read(); - } while (null !== chunk && state.flowing); - } - } + codes.listNext = codes.listEnd = listTerminator; - // wrap an old-style stream as the async data source. - // This is *not* part of the readable stream interface. - // It is an ugly unfortunate mess of history. - Readable.prototype.wrap = function(stream) { - var state = this._readableState; - var paused = false; + codes.listStart = function(obj, data, allCodes) { + return util.derive(obj, { + block: function(left, top, width, ordinal, parent, formatting) { + var list = node.generic('list', parent, left, top), + itemNode, + itemFrame, + itemMarker; - var self = this; - stream.on('end', function() { - debug('wrapped end'); - if (state.decoder && !state.ended) { - var chunk = state.decoder.end(); - if (chunk && chunk.length) - self.push(chunk); - } + var indent = 50, spacing = 10; - self.push(null); - }); + var startItem = function(code, formatting) { + itemNode = node.generic('item', list); + var marker = allCodes(code.marker || { $: 'number' }, list.children().length); + itemMarker = inlineNode(marker, itemNode, ordinal, 1, formatting); + itemMarker.block = true; + itemFrame = frame( + left + indent, top, width - indent, ordinal + 1, itemNode, + function(terminatorCode) { + return terminatorCode.$ === 'listEnd'; + }, + itemMarker.measured.ascent + ); + }; - stream.on('data', function(chunk) { - debug('wrapped data'); - if (state.decoder) - chunk = state.decoder.write(chunk); - if (!chunk || !state.objectMode && !chunk.length) - return; + startItem(obj, formatting); - var ret = self.push(chunk); - if (!ret) { - paused = true; - stream.pause(); - } - }); + return function(inputWord) { + if (itemFrame) { + itemFrame(function(finishedFrame) { + ordinal = finishedFrame.ordinal + finishedFrame.length; + var frameBounds = finishedFrame.bounds(); - // proxy all the other methods. - // important when wrapping filters and duplexes. - for (var i in stream) { - if (util.isFunction(stream[i]) && util.isUndefined(this[i])) { - this[i] = function(method) { return function() { - return stream[method].apply(stream, arguments); - }}(i); - } - } + // get first line and position marker + var firstLine = finishedFrame.first(); + var markerLeft = left + indent - spacing - itemMarker.measured.width; + var markerBounds = rect(left, top, indent, frameBounds.h); + if ('baseline' in firstLine) { + itemMarker.position(markerLeft, firstLine.baseline, markerBounds); + } else { + itemMarker.position(markerLeft, top + itemMarker.measured.ascent, markerBounds); + } - // proxy certain important events. - var events = ['error', 'close', 'destroy', 'pause', 'resume']; - forEach(events, function(ev) { - stream.on(ev, self.emit.bind(self, ev)); - }); + top = frameBounds.t + frameBounds.h; - // when we try to consume some more bytes, simply unpause the - // underlying stream. - self._read = function(n) { - debug('wrapped _read', n); - if (paused) { - paused = false; - stream.resume(); - } - }; + itemNode.children().push(itemMarker); + itemNode.children().push(finishedFrame); + itemNode.finalize(); - return self; + list.children().push(itemNode); + itemNode = itemFrame = itemMarker = null; + }, inputWord); + } else { + ordinal++; + } + + if (!itemFrame) { + var i = inputWord.code(); + if (i) { + if (i.$ == 'listEnd') { + list.finalize(); + return list; + } + if (i.$ == 'listNext') { + startItem(i, inputWord.codeFormatting()); + } + } + } + }; + } + }); }; + module.exports = exports = function(obj, number, allCodes) { + var impl = codes[obj.$]; + return impl && impl(obj, number, allCodes); + }; + exports.editFilter = function(doc) { + var balance = 0; - // exposed for testing purposes only. - Readable._fromList = fromList; + if (!doc.words.some(function(word, i) { + var code = word.code(); + if (code) { + switch (code.$) { + case 'listStart': + balance++; + break; + case 'listNext': + if (balance === 0) { + doc.spliceWordsWithRuns(i, 1, [util.derive(word.codeFormatting(), { + text: { + $: 'listStart', + marker: code.marker + } + })]); + return true; + } + break; + case 'listEnd': + if (balance === 0) { + doc.spliceWordsWithRuns(i, 1, []); + } + balance--; + break; + } + } + })) { + if (balance > 0) { + var ending = []; + while (balance > 0) { + balance--; + ending.push({ + text: { $: 'listEnd' } + }); + } + doc.spliceWordsWithRuns(doc.words.length - 1, 0, ending); + } + } + }; - // Pluck off n bytes from an array of buffers. - // Length is the combined lengths of all the buffers in the list. - function fromList(n, state) { - var list = state.buffer; - var length = state.length; - var stringMode = !!state.decoder; - var objectMode = !!state.objectMode; - var ret; - // nothing in the list, definitely empty. - if (list.length === 0) - return null; +/***/ }, +/* 46 */ +/***/ function(module, exports) { - if (length === 0) - ret = null; - else if (objectMode) - ret = list.shift(); - else if (!n || n >= length) { - // read it all, truncate the array. - if (stringMode) - ret = list.join(''); - else - ret = Buffer.concat(list, length); - list.length = 0; - } else { - // read just some of it. - if (n < list[0].length) { - // just take a part of the first list item. - // slice is the same for buffers and strings. - var buf = list[0]; - ret = buf.slice(0, n); - list[0] = buf.slice(n); - } else if (n === list[0].length) { - // first list is a perfect match - ret = list.shift(); - } else { - // complex case. - // we have enough to cover it, but it spans past the first buffer. - if (stringMode) - ret = ''; - else - ret = new Buffer(n); - - var c = 0; - for (var i = 0, l = list.length; i < l && c < n; i++) { - var buf = list[0]; - var cpy = Math.min(n - c, buf.length); - - if (stringMode) - ret += buf.slice(0, cpy); - else - buf.copy(ret, c, 0, cpy); - - if (cpy < buf.length) - list[0] = buf.slice(cpy); - else - list.shift(); - - c += cpy; - } + + exports.isAttached = function(element) { + var ancestor = element; + while(ancestor.parentNode) { + ancestor = ancestor.parentNode; } - } - - return ret; - } + return !!ancestor.body; + }; - function endReadable(stream) { - var state = stream._readableState; + exports.clear = function(element) { + while (element.firstChild) { + element.removeChild(element.firstChild); + } + }; - // If we get here before consuming all the bytes, then that is a - // bug in node. Should never happen. - if (state.length > 0) - throw new Error('endReadable called on non-empty stream'); + exports.setText = function(element, text) { + exports.clear(element); + element.appendChild(document.createTextNode(text)); + }; - if (!state.endEmitted) { - state.ended = true; - process.nextTick(function() { - // Check that we didn't get one last unshift. - if (!state.endEmitted && state.length === 0) { - state.endEmitted = true; - stream.readable = false; - stream.emit('end'); - } + exports.handleEvent = function(element, name, handler) { + element.addEventListener(name, function(ev) { + if (handler(ev) === false) { + ev.preventDefault(); + } }); - } - } - - function forEach (xs, f) { - for (var i = 0, l = xs.length; i < l; i++) { - f(xs[i], i); - } - } + }; - function indexOf (xs, x) { - for (var i = 0, l = xs.length; i < l; i++) { - if (xs[i] === x) return i; - } - return -1; - } + exports.handleMouseEvent = function(element, name, handler) { + exports.handleEvent(element, name, function(ev) { + var rect = element.getBoundingClientRect(); + return handler(ev, ev.clientX - rect.left, ev.clientY - rect.top); + }); + }; - /* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(10))) + exports.effectiveStyle = function(element, name) { + return document.defaultView.getComputedStyle(element).getPropertyValue(name); + }; /***/ }, -/* 54 */ -/***/ function(module, exports) { +/* 47 */ +/***/ function(module, exports, __webpack_require__) { - module.exports = Array.isArray || function (arr) { - return Object.prototype.toString.call(arr) == '[object Array]'; - }; + var runs = __webpack_require__(30); + var per = __webpack_require__(29); + var tag = function(name, formattingProperty) { + return function(node, formatting) { + if (node.nodeName === name) { + formatting[formattingProperty] = true; + } + }; + }; -/***/ }, -/* 55 */ -/***/ function(module, exports, __webpack_require__) { + var value = function(type, styleProperty, formattingProperty, transformValue) { + return function(node, formatting) { + var val = node[type] && node[type][styleProperty]; + if (val) { + if (transformValue) { + val = transformValue(val); + } + formatting[formattingProperty] = val; + } + }; + }; - /* WEBPACK VAR INJECTION */(function(Buffer, global) {/*! - * The buffer module from node.js, for the browser. - * - * @author Feross Aboukhadijeh - * @license MIT - */ - /* eslint-disable no-proto */ + var attrValue = function(styleProperty, formattingProperty, transformValue) { + return value('attributes', styleProperty, formattingProperty, transformValue); + }; - 'use strict' + var styleValue = function(styleProperty, formattingProperty, transformValue) { + return value('style', styleProperty, formattingProperty, transformValue); + }; - var base64 = __webpack_require__(56) - var ieee754 = __webpack_require__(57) - var isArray = __webpack_require__(58) + var styleFlag = function(styleProperty, styleValue, formattingProperty) { + return function(node, formatting) { + if (node.style && node.style[styleProperty] === styleValue) { + formatting[formattingProperty] = true; + } + }; + }; - exports.Buffer = Buffer - exports.SlowBuffer = SlowBuffer - exports.INSPECT_MAX_BYTES = 50 - Buffer.poolSize = 8192 // not used by this implementation + var obsoleteFontSizes = [ 6, 7, 9, 10, 12, 16, 20, 30 ]; - var rootParent = {} + var aligns = { left: true, center: true, right: true, justify: true }; - /** - * If `Buffer.TYPED_ARRAY_SUPPORT`: - * === true Use Uint8Array implementation (fastest) - * === false Use Object implementation (most compatible, even IE6) - * - * Browsers that support typed arrays are IE 10+, Firefox 4+, Chrome 7+, Safari 5.1+, - * Opera 11.6+, iOS 4.2+. - * - * Due to various browser bugs, sometimes the Object implementation will be used even - * when the browser supports typed arrays. - * - * Note: - * - * - Firefox 4-29 lacks support for adding new properties to `Uint8Array` instances, - * See: https://bugzilla.mozilla.org/show_bug.cgi?id=695438. - * - * - Safari 5-7 lacks support for changing the `Object.prototype.constructor` property - * on objects. - * - * - Chrome 9-10 is missing the `TypedArray.prototype.subarray` function. - * - * - IE10 has a broken `TypedArray.prototype.subarray` function which returns arrays of - * incorrect length in some situations. + var checkAlign = function(value) { + return aligns[value] ? value : 'left'; + }; - * We detect these buggy browsers and set `Buffer.TYPED_ARRAY_SUPPORT` to `false` so they - * get the Object implementation, which is slower but behaves correctly. - */ - Buffer.TYPED_ARRAY_SUPPORT = global.TYPED_ARRAY_SUPPORT !== undefined - ? global.TYPED_ARRAY_SUPPORT - : typedArraySupport() + var fontName = function(name) { + var s = name.split(/\s*,\s*/g); + if (s.length == 0) { + return name; + } + name = s[0] + var raw = name.match(/^"(.*)"$/); + if (raw) { + return raw[1].trim(); + } + raw = name.match(/^'(.*)'$/); + if (raw) { + return raw[1].trim(); + } + return name; + }; - function typedArraySupport () { - function Bar () {} - try { - var arr = new Uint8Array(1) - arr.foo = function () { return 42 } - arr.constructor = Bar - return arr.foo() === 42 && // typed array instances can be augmented - arr.constructor === Bar && // constructor can be set - typeof arr.subarray === 'function' && // chrome 9-10 lack `subarray` - arr.subarray(1, 1).byteLength === 0 // ie10 has broken `subarray` - } catch (e) { - return false - } - } + var headings = { + H1: 30, + H2: 20, + H3: 16, + H4: 14, + H5: 12 + }; - function kMaxLength () { - return Buffer.TYPED_ARRAY_SUPPORT - ? 0x7fffffff - : 0x3fffffff - } + var handlers = [ + tag('B', 'bold'), + tag('STRONG', 'bold'), + tag('I', 'italic'), + tag('EM', 'italic'), + tag('U', 'underline'), + tag('S', 'strikeout'), + tag('STRIKE', 'strikeout'), + tag('DEL', 'strikeout'), + styleFlag('fontWeight', 'bold', 'bold'), + styleFlag('fontStyle', 'italic', 'italic'), + styleFlag('textDecoration', 'underline', 'underline'), + styleFlag('textDecoration', 'line-through', 'strikeout'), + styleValue('color', 'color'), + styleValue('fontFamily', 'font', fontName), + styleValue('fontSize', 'size', function(size) { + var m = size.match(/^([\d\.]+)pt$/); + return m ? parseFloat(m[1]) : 10 + }), + styleValue('textAlign', 'align', checkAlign), + function(node, formatting) { + if (node.nodeName === 'SUB') { + formatting.script = 'sub'; + } + }, + function(node, formatting) { + if (node.nodeName === 'SUPER') { + formatting.script = 'super'; + } + }, + function(node, formatting) { + if (node.nodeName === 'CODE') { + formatting.font = 'monospace'; + } + }, + function(node, formatting) { + var size = headings[node.nodeName]; + if (size) { + formatting.size = size; + } + }, + attrValue('color', 'color'), + attrValue('face', 'font', fontName), + attrValue('align', 'align', checkAlign), + attrValue('size', 'size', function(size) { + return obsoleteFontSizes[size] || 10; + }) + ]; - /** - * Class: Buffer - * ============= - * - * The Buffer constructor returns instances of `Uint8Array` that are augmented - * with function properties for all the node `Buffer` API functions. We use - * `Uint8Array` so that square bracket notation works as expected -- it returns - * a single octet. - * - * By augmenting the instances, we can avoid modifying the `Uint8Array` - * prototype. - */ - function Buffer (arg) { - if (!(this instanceof Buffer)) { - // Avoid going through an ArgumentsAdaptorTrampoline in the common case. - if (arguments.length > 1) return new Buffer(arg, arguments[1]) - return new Buffer(arg) - } + var newLines = [ 'BR', 'P', 'H1', 'H2', 'H3', 'H4', 'H5' ]; + var isNewLine = {}; + newLines.forEach(function(name) { + isNewLine[name] = true; + }); - if (!Buffer.TYPED_ARRAY_SUPPORT) { - this.length = 0 - this.parent = undefined - } + exports.parse = function(html, classes) { + var root = html; + if (typeof root === 'string') { + root = document.createElement('div'); + root.innerHTML = html; + } - // Common case. - if (typeof arg === 'number') { - return fromNumber(this, arg) - } + var result = [], inSpace = true; + var cons = per(runs.consolidate()).into(result); + var emit = function(text, formatting) { + cons.submit(Object.create(formatting, { + text: { value: text } + })); + }; + var dealWithSpaces = function(text, formatting) { + text = text.replace(/\n+\s*/g, ' '); + var fullLength = text.length; + text = text.replace(/^\s+/, ''); + if (inSpace) { + inSpace = false; + } else if (fullLength !== text.length) { + text = ' ' + text; + } + fullLength = text.length; + text = text.replace(/\s+$/, ''); + if (fullLength !== text.length) { + inSpace = true; + text += ' '; + } + emit(text, formatting); + }; - // Slightly less common case. - if (typeof arg === 'string') { - return fromString(this, arg, arguments.length > 1 ? arguments[1] : 'utf8') - } + function recurse(node, formatting) { + if (node.nodeType == 3) { + dealWithSpaces(node.nodeValue, formatting); + } else { + formatting = Object.create(formatting); - // Unusual. - return fromObject(this, arg) - } + var classNames = node.attributes['class']; + if (classNames) { + classNames.value.split(' ').forEach(function(cls) { + cls = classes[cls]; + if (cls) { + Object.keys(cls).forEach(function(key) { + formatting[key] = cls[key]; + }); + } + }) + } - function fromNumber (that, length) { - that = allocate(that, length < 0 ? 0 : checked(length) | 0) - if (!Buffer.TYPED_ARRAY_SUPPORT) { - for (var i = 0; i < length; i++) { - that[i] = 0 + handlers.forEach(function(handler) { + handler(node, formatting); + }); + if (node.childNodes) { + for (var n = 0; n < node.childNodes.length; n++) { + recurse(node.childNodes[n], formatting); + } + } + if (isNewLine[node.nodeName]) { + emit('\n', formatting); + inSpace = true; + } + } } - } - return that - } - - function fromString (that, string, encoding) { - if (typeof encoding !== 'string' || encoding === '') encoding = 'utf8' + recurse(root, {}); + return result; + }; - // Assumption: byteLength() return value is always < kMaxLength. - var length = byteLength(string, encoding) | 0 - that = allocate(that, length) - that.write(string, encoding) - return that - } - function fromObject (that, object) { - if (Buffer.isBuffer(object)) return fromBuffer(that, object) +/***/ }, +/* 48 */ +/***/ function(module, exports, __webpack_require__) { - if (isArray(object)) return fromArray(that, object) + var Stream = __webpack_require__(49).Stream, + util = __webpack_require__(75), + TokenType = __webpack_require__(78), + BreakType = __webpack_require__(79), + tokenizer = __webpack_require__(80), + LineBreak = __webpack_require__(82); - if (object == null) { - throw new TypeError('must start with number, buffer, array or string') - } + function TokenizerStream() { + Stream.call(this); - if (typeof ArrayBuffer !== 'undefined') { - if (object.buffer instanceof ArrayBuffer) { - return fromTypedArray(that, object) - } - if (object instanceof ArrayBuffer) { - return fromArrayBuffer(that, object) - } - } + var that = this; - if (object.length) return fromArrayLike(that, object) + this.readable = true; + this.writable = true; - return fromJsonObject(that, object) - } + this.tokenizer = tokenizer.createTokenizer(); + this.linebreak = new LineBreak(); - function fromBuffer (that, buffer) { - var length = checked(buffer.length) | 0 - that = allocate(that, length) - buffer.copy(that, 0, 0, length) - return that - } + this.tokenizer.on('token', function(token, type) { + that.linebreak.process(token, type); + }); - function fromArray (that, array) { - var length = checked(array.length) | 0 - that = allocate(that, length) - for (var i = 0; i < length; i += 1) { - that[i] = array[i] & 255 - } - return that - } + this.linebreak.on('action', function(token, type, action) { + that.emit('data', token); + that.emit('token', token, type, action); + }); - // Duplicate of fromArray() to keep fromArray() monomorphic. - function fromTypedArray (that, array) { - var length = checked(array.length) | 0 - that = allocate(that, length) - // Truncating the elements is probably not what people expect from typed - // arrays with BYTES_PER_ELEMENT > 1 but it's compatible with the behavior - // of the old Buffer constructor. - for (var i = 0; i < length; i += 1) { - that[i] = array[i] & 255 - } - return that + this.tokenizer.on('end', function() { + that.linebreak.end(); + }); } - function fromArrayBuffer (that, array) { - if (Buffer.TYPED_ARRAY_SUPPORT) { - // Return an augmented `Uint8Array` instance, for best performance - array.byteLength - that = Buffer._augment(new Uint8Array(array)) - } else { - // Fallback: Return an object instance of the Buffer class - that = fromTypedArray(that, new Uint8Array(array)) - } - return that - } + util.inherits(TokenizerStream, Stream); - function fromArrayLike (that, array) { - var length = checked(array.length) | 0 - that = allocate(that, length) - for (var i = 0; i < length; i += 1) { - that[i] = array[i] & 255 - } - return that - } + TokenizerStream.prototype.write = function(chunk) { + this.tokenizer.write(chunk); + }; - // Deserialize { type: 'Buffer', data: [1,2,3,...] } into a Buffer object. - // Returns a zero-length buffer for inputs that don't conform to the spec. - function fromJsonObject (that, object) { - var array - var length = 0 + TokenizerStream.prototype.end = function(data) { + if (data) { + this.write(data); + } + this.tokenizer.end(); + this.emit('end'); + }; - if (object.type === 'Buffer' && isArray(object.data)) { - array = object.data - length = checked(array.length) | 0 - } - that = allocate(that, length) + module.exports = { + Break: BreakType, + Token: TokenType, - for (var i = 0; i < length; i += 1) { - that[i] = array[i] & 255 - } - return that - } + Tokenizer: tokenizer.Tokenizer, + tokenize: tokenizer.tokenize, + tokenizeSync: tokenizer.tokenizeSync, - if (Buffer.TYPED_ARRAY_SUPPORT) { - Buffer.prototype.__proto__ = Uint8Array.prototype - Buffer.__proto__ = Uint8Array - } else { - // pre-set for values that may exist in the future - Buffer.prototype.length = undefined - Buffer.prototype.parent = undefined - } + createTokenizerStream: function() { + return new TokenizerStream(); + } + }; - function allocate (that, length) { - if (Buffer.TYPED_ARRAY_SUPPORT) { - // Return an augmented `Uint8Array` instance, for best performance - that = Buffer._augment(new Uint8Array(length)) - that.__proto__ = Buffer.prototype - } else { - // Fallback: Return an object instance of the Buffer class - that.length = length - that._isBuffer = true - } - var fromPool = length !== 0 && length <= Buffer.poolSize >>> 1 - if (fromPool) that.parent = rootParent +/***/ }, +/* 49 */ +/***/ function(module, exports, __webpack_require__) { - return that - } + // Copyright Joyent, Inc. and other Node contributors. + // + // Permission is hereby granted, free of charge, to any person obtaining a + // copy of this software and associated documentation files (the + // "Software"), to deal in the Software without restriction, including + // without limitation the rights to use, copy, modify, merge, publish, + // distribute, sublicense, and/or sell copies of the Software, and to permit + // persons to whom the Software is furnished to do so, subject to the + // following conditions: + // + // The above copyright notice and this permission notice shall be included + // in all copies or substantial portions of the Software. + // + // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN + // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, + // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR + // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE + // USE OR OTHER DEALINGS IN THE SOFTWARE. - function checked (length) { - // Note: cannot use `length < kMaxLength` here because that fails when - // length is NaN (which is otherwise coerced to zero.) - if (length >= kMaxLength()) { - throw new RangeError('Attempt to allocate Buffer larger than maximum ' + - 'size: 0x' + kMaxLength().toString(16) + ' bytes') - } - return length | 0 - } + module.exports = Stream; - function SlowBuffer (subject, encoding) { - if (!(this instanceof SlowBuffer)) return new SlowBuffer(subject, encoding) + var EE = __webpack_require__(50).EventEmitter; + var inherits = __webpack_require__(51); - var buf = new Buffer(subject, encoding) - delete buf.parent - return buf - } + inherits(Stream, EE); + Stream.Readable = __webpack_require__(52); + Stream.Writable = __webpack_require__(71); + Stream.Duplex = __webpack_require__(72); + Stream.Transform = __webpack_require__(73); + Stream.PassThrough = __webpack_require__(74); - Buffer.isBuffer = function isBuffer (b) { - return !!(b != null && b._isBuffer) - } + // Backwards-compat with node 0.4.x + Stream.Stream = Stream; - Buffer.compare = function compare (a, b) { - if (!Buffer.isBuffer(a) || !Buffer.isBuffer(b)) { - throw new TypeError('Arguments must be Buffers') - } - if (a === b) return 0 - var x = a.length - var y = b.length + // old-style streams. Note that the pipe method (the only relevant + // part of this class) is overridden in the Readable class. - var i = 0 - var len = Math.min(x, y) - while (i < len) { - if (a[i] !== b[i]) break + function Stream() { + EE.call(this); + } - ++i - } + Stream.prototype.pipe = function(dest, options) { + var source = this; - if (i !== len) { - x = a[i] - y = b[i] + function ondata(chunk) { + if (dest.writable) { + if (false === dest.write(chunk) && source.pause) { + source.pause(); + } + } } - if (x < y) return -1 - if (y < x) return 1 - return 0 - } + source.on('data', ondata); - Buffer.isEncoding = function isEncoding (encoding) { - switch (String(encoding).toLowerCase()) { - case 'hex': - case 'utf8': - case 'utf-8': - case 'ascii': - case 'binary': - case 'base64': - case 'raw': - case 'ucs2': - case 'ucs-2': - case 'utf16le': - case 'utf-16le': - return true - default: - return false + function ondrain() { + if (source.readable && source.resume) { + source.resume(); + } } - } - Buffer.concat = function concat (list, length) { - if (!isArray(list)) throw new TypeError('list argument must be an Array of Buffers.') + dest.on('drain', ondrain); - if (list.length === 0) { - return new Buffer(0) + // If the 'end' option is not supplied, dest.end() will be called when + // source gets the 'end' or 'close' events. Only dest.end() once. + if (!dest._isStdio && (!options || options.end !== false)) { + source.on('end', onend); + source.on('close', onclose); } - var i - if (length === undefined) { - length = 0 - for (i = 0; i < list.length; i++) { - length += list[i].length - } - } + var didOnEnd = false; + function onend() { + if (didOnEnd) return; + didOnEnd = true; - var buf = new Buffer(length) - var pos = 0 - for (i = 0; i < list.length; i++) { - var item = list[i] - item.copy(buf, pos) - pos += item.length + dest.end(); } - return buf - } - function byteLength (string, encoding) { - if (typeof string !== 'string') string = '' + string - var len = string.length - if (len === 0) return 0 + function onclose() { + if (didOnEnd) return; + didOnEnd = true; - // Use a for loop to avoid recursion - var loweredCase = false - for (;;) { - switch (encoding) { - case 'ascii': - case 'binary': - // Deprecated - case 'raw': - case 'raws': - return len - case 'utf8': - case 'utf-8': - return utf8ToBytes(string).length - case 'ucs2': - case 'ucs-2': - case 'utf16le': - case 'utf-16le': - return len * 2 - case 'hex': - return len >>> 1 - case 'base64': - return base64ToBytes(string).length - default: - if (loweredCase) return utf8ToBytes(string).length // assume utf8 - encoding = ('' + encoding).toLowerCase() - loweredCase = true + if (typeof dest.destroy === 'function') dest.destroy(); + } + + // don't leave dangling pipes when there are errors. + function onerror(er) { + cleanup(); + if (EE.listenerCount(this, 'error') === 0) { + throw er; // Unhandled stream error in pipe. } } - } - Buffer.byteLength = byteLength - function slowToString (encoding, start, end) { - var loweredCase = false + source.on('error', onerror); + dest.on('error', onerror); - start = start | 0 - end = end === undefined || end === Infinity ? this.length : end | 0 + // remove all the event listeners that were added. + function cleanup() { + source.removeListener('data', ondata); + dest.removeListener('drain', ondrain); - if (!encoding) encoding = 'utf8' - if (start < 0) start = 0 - if (end > this.length) end = this.length - if (end <= start) return '' + source.removeListener('end', onend); + source.removeListener('close', onclose); - while (true) { - switch (encoding) { - case 'hex': - return hexSlice(this, start, end) + source.removeListener('error', onerror); + dest.removeListener('error', onerror); - case 'utf8': - case 'utf-8': - return utf8Slice(this, start, end) + source.removeListener('end', cleanup); + source.removeListener('close', cleanup); - case 'ascii': - return asciiSlice(this, start, end) + dest.removeListener('close', cleanup); + } - case 'binary': - return binarySlice(this, start, end) + source.on('end', cleanup); + source.on('close', cleanup); - case 'base64': - return base64Slice(this, start, end) + dest.on('close', cleanup); - case 'ucs2': - case 'ucs-2': - case 'utf16le': - case 'utf-16le': - return utf16leSlice(this, start, end) + dest.emit('pipe', source); - default: - if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding) - encoding = (encoding + '').toLowerCase() - loweredCase = true - } - } - } + // Allow for unix-like usage: A.pipe(B).pipe(C) + return dest; + }; - Buffer.prototype.toString = function toString () { - var length = this.length | 0 - if (length === 0) return '' - if (arguments.length === 0) return utf8Slice(this, 0, length) - return slowToString.apply(this, arguments) - } - Buffer.prototype.equals = function equals (b) { - if (!Buffer.isBuffer(b)) throw new TypeError('Argument must be a Buffer') - if (this === b) return true - return Buffer.compare(this, b) === 0 - } +/***/ }, +/* 50 */ +/***/ function(module, exports) { - Buffer.prototype.inspect = function inspect () { - var str = '' - var max = exports.INSPECT_MAX_BYTES - if (this.length > 0) { - str = this.toString('hex', 0, max).match(/.{2}/g).join(' ') - if (this.length > max) str += ' ... ' - } - return '' - } + // Copyright Joyent, Inc. and other Node contributors. + // + // Permission is hereby granted, free of charge, to any person obtaining a + // copy of this software and associated documentation files (the + // "Software"), to deal in the Software without restriction, including + // without limitation the rights to use, copy, modify, merge, publish, + // distribute, sublicense, and/or sell copies of the Software, and to permit + // persons to whom the Software is furnished to do so, subject to the + // following conditions: + // + // The above copyright notice and this permission notice shall be included + // in all copies or substantial portions of the Software. + // + // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN + // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, + // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR + // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE + // USE OR OTHER DEALINGS IN THE SOFTWARE. - Buffer.prototype.compare = function compare (b) { - if (!Buffer.isBuffer(b)) throw new TypeError('Argument must be a Buffer') - if (this === b) return 0 - return Buffer.compare(this, b) + function EventEmitter() { + this._events = this._events || {}; + this._maxListeners = this._maxListeners || undefined; } + module.exports = EventEmitter; - Buffer.prototype.indexOf = function indexOf (val, byteOffset) { - if (byteOffset > 0x7fffffff) byteOffset = 0x7fffffff - else if (byteOffset < -0x80000000) byteOffset = -0x80000000 - byteOffset >>= 0 + // Backwards-compat with node 0.10.x + EventEmitter.EventEmitter = EventEmitter; - if (this.length === 0) return -1 - if (byteOffset >= this.length) return -1 + EventEmitter.prototype._events = undefined; + EventEmitter.prototype._maxListeners = undefined; - // Negative offsets start from the end of the buffer - if (byteOffset < 0) byteOffset = Math.max(this.length + byteOffset, 0) + // By default EventEmitters will print a warning if more than 10 listeners are + // added to it. This is a useful default which helps finding memory leaks. + EventEmitter.defaultMaxListeners = 10; - if (typeof val === 'string') { - if (val.length === 0) return -1 // special case: looking for empty string always fails - return String.prototype.indexOf.call(this, val, byteOffset) - } - if (Buffer.isBuffer(val)) { - return arrayIndexOf(this, val, byteOffset) - } - if (typeof val === 'number') { - if (Buffer.TYPED_ARRAY_SUPPORT && Uint8Array.prototype.indexOf === 'function') { - return Uint8Array.prototype.indexOf.call(this, val, byteOffset) - } - return arrayIndexOf(this, [ val ], byteOffset) - } + // Obviously not all Emitters should be limited to 10. This function allows + // that to be increased. Set to zero for unlimited. + EventEmitter.prototype.setMaxListeners = function(n) { + if (!isNumber(n) || n < 0 || isNaN(n)) + throw TypeError('n must be a positive number'); + this._maxListeners = n; + return this; + }; - function arrayIndexOf (arr, val, byteOffset) { - var foundIndex = -1 - for (var i = 0; byteOffset + i < arr.length; i++) { - if (arr[byteOffset + i] === val[foundIndex === -1 ? 0 : i - foundIndex]) { - if (foundIndex === -1) foundIndex = i - if (i - foundIndex + 1 === val.length) return byteOffset + foundIndex + EventEmitter.prototype.emit = function(type) { + var er, handler, len, args, i, listeners; + + if (!this._events) + this._events = {}; + + // If there is no 'error' event listener then throw. + if (type === 'error') { + if (!this._events.error || + (isObject(this._events.error) && !this._events.error.length)) { + er = arguments[1]; + if (er instanceof Error) { + throw er; // Unhandled 'error' event } else { - foundIndex = -1 + // At least give some kind of context to the user + var err = new Error('Uncaught, unspecified "error" event. (' + er + ')'); + err.context = er; + throw err; } } - return -1 } - throw new TypeError('val must be string, number or Buffer') - } - - // `get` is deprecated - Buffer.prototype.get = function get (offset) { - console.log('.get() is deprecated. Access using array indexes instead.') - return this.readUInt8(offset) - } + handler = this._events[type]; - // `set` is deprecated - Buffer.prototype.set = function set (v, offset) { - console.log('.set() is deprecated. Access using array indexes instead.') - return this.writeUInt8(v, offset) - } + if (isUndefined(handler)) + return false; - function hexWrite (buf, string, offset, length) { - offset = Number(offset) || 0 - var remaining = buf.length - offset - if (!length) { - length = remaining - } else { - length = Number(length) - if (length > remaining) { - length = remaining + if (isFunction(handler)) { + switch (arguments.length) { + // fast cases + case 1: + handler.call(this); + break; + case 2: + handler.call(this, arguments[1]); + break; + case 3: + handler.call(this, arguments[1], arguments[2]); + break; + // slower + default: + args = Array.prototype.slice.call(arguments, 1); + handler.apply(this, args); } + } else if (isObject(handler)) { + args = Array.prototype.slice.call(arguments, 1); + listeners = handler.slice(); + len = listeners.length; + for (i = 0; i < len; i++) + listeners[i].apply(this, args); } - // must be an even number of digits - var strLen = string.length - if (strLen % 2 !== 0) throw new Error('Invalid hex string') + return true; + }; + + EventEmitter.prototype.addListener = function(type, listener) { + var m; + + if (!isFunction(listener)) + throw TypeError('listener must be a function'); + + if (!this._events) + this._events = {}; + + // To avoid recursion in the case that type === "newListener"! Before + // adding it to the listeners, first emit "newListener". + if (this._events.newListener) + this.emit('newListener', type, + isFunction(listener.listener) ? + listener.listener : listener); + + if (!this._events[type]) + // Optimize the case of one listener. Don't need the extra array object. + this._events[type] = listener; + else if (isObject(this._events[type])) + // If we've already got an array, just append. + this._events[type].push(listener); + else + // Adding the second element, need to change to array. + this._events[type] = [this._events[type], listener]; + + // Check for listener leak + if (isObject(this._events[type]) && !this._events[type].warned) { + if (!isUndefined(this._maxListeners)) { + m = this._maxListeners; + } else { + m = EventEmitter.defaultMaxListeners; + } - if (length > strLen / 2) { - length = strLen / 2 - } - for (var i = 0; i < length; i++) { - var parsed = parseInt(string.substr(i * 2, 2), 16) - if (isNaN(parsed)) throw new Error('Invalid hex string') - buf[offset + i] = parsed + if (m && m > 0 && this._events[type].length > m) { + this._events[type].warned = true; + console.error('(node) warning: possible EventEmitter memory ' + + 'leak detected. %d listeners added. ' + + 'Use emitter.setMaxListeners() to increase limit.', + this._events[type].length); + if (typeof console.trace === 'function') { + // not supported in IE 10 + console.trace(); + } + } } - return i - } - function utf8Write (buf, string, offset, length) { - return blitBuffer(utf8ToBytes(string, buf.length - offset), buf, offset, length) - } + return this; + }; - function asciiWrite (buf, string, offset, length) { - return blitBuffer(asciiToBytes(string), buf, offset, length) - } + EventEmitter.prototype.on = EventEmitter.prototype.addListener; - function binaryWrite (buf, string, offset, length) { - return asciiWrite(buf, string, offset, length) - } + EventEmitter.prototype.once = function(type, listener) { + if (!isFunction(listener)) + throw TypeError('listener must be a function'); - function base64Write (buf, string, offset, length) { - return blitBuffer(base64ToBytes(string), buf, offset, length) - } + var fired = false; - function ucs2Write (buf, string, offset, length) { - return blitBuffer(utf16leToBytes(string, buf.length - offset), buf, offset, length) - } + function g() { + this.removeListener(type, g); - Buffer.prototype.write = function write (string, offset, length, encoding) { - // Buffer#write(string) - if (offset === undefined) { - encoding = 'utf8' - length = this.length - offset = 0 - // Buffer#write(string, encoding) - } else if (length === undefined && typeof offset === 'string') { - encoding = offset - length = this.length - offset = 0 - // Buffer#write(string, offset[, length][, encoding]) - } else if (isFinite(offset)) { - offset = offset | 0 - if (isFinite(length)) { - length = length | 0 - if (encoding === undefined) encoding = 'utf8' - } else { - encoding = length - length = undefined + if (!fired) { + fired = true; + listener.apply(this, arguments); } - // legacy write(string, encoding, offset, length) - remove in v0.13 - } else { - var swap = encoding - encoding = offset - offset = length | 0 - length = swap } - var remaining = this.length - offset - if (length === undefined || length > remaining) length = remaining + g.listener = listener; + this.on(type, g); - if ((string.length > 0 && (length < 0 || offset < 0)) || offset > this.length) { - throw new RangeError('attempt to write outside buffer bounds') - } + return this; + }; - if (!encoding) encoding = 'utf8' + // emits a 'removeListener' event iff the listener was removed + EventEmitter.prototype.removeListener = function(type, listener) { + var list, position, length, i; - var loweredCase = false - for (;;) { - switch (encoding) { - case 'hex': - return hexWrite(this, string, offset, length) + if (!isFunction(listener)) + throw TypeError('listener must be a function'); - case 'utf8': - case 'utf-8': - return utf8Write(this, string, offset, length) + if (!this._events || !this._events[type]) + return this; - case 'ascii': - return asciiWrite(this, string, offset, length) + list = this._events[type]; + length = list.length; + position = -1; - case 'binary': - return binaryWrite(this, string, offset, length) + if (list === listener || + (isFunction(list.listener) && list.listener === listener)) { + delete this._events[type]; + if (this._events.removeListener) + this.emit('removeListener', type, listener); - case 'base64': - // Warning: maxLength not taken into account in base64Write - return base64Write(this, string, offset, length) + } else if (isObject(list)) { + for (i = length; i-- > 0;) { + if (list[i] === listener || + (list[i].listener && list[i].listener === listener)) { + position = i; + break; + } + } - case 'ucs2': - case 'ucs-2': - case 'utf16le': - case 'utf-16le': - return ucs2Write(this, string, offset, length) + if (position < 0) + return this; - default: - if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding) - encoding = ('' + encoding).toLowerCase() - loweredCase = true + if (list.length === 1) { + list.length = 0; + delete this._events[type]; + } else { + list.splice(position, 1); } + + if (this._events.removeListener) + this.emit('removeListener', type, listener); } - } - Buffer.prototype.toJSON = function toJSON () { - return { - type: 'Buffer', - data: Array.prototype.slice.call(this._arr || this, 0) + return this; + }; + + EventEmitter.prototype.removeAllListeners = function(type) { + var key, listeners; + + if (!this._events) + return this; + + // not listening for removeListener, no need to emit + if (!this._events.removeListener) { + if (arguments.length === 0) + this._events = {}; + else if (this._events[type]) + delete this._events[type]; + return this; } - } - function base64Slice (buf, start, end) { - if (start === 0 && end === buf.length) { - return base64.fromByteArray(buf) - } else { - return base64.fromByteArray(buf.slice(start, end)) + // emit removeListener for all listeners on all events + if (arguments.length === 0) { + for (key in this._events) { + if (key === 'removeListener') continue; + this.removeAllListeners(key); + } + this.removeAllListeners('removeListener'); + this._events = {}; + return this; } - } - function utf8Slice (buf, start, end) { - end = Math.min(buf.length, end) - var res = [] + listeners = this._events[type]; - var i = start - while (i < end) { - var firstByte = buf[i] - var codePoint = null - var bytesPerSequence = (firstByte > 0xEF) ? 4 - : (firstByte > 0xDF) ? 3 - : (firstByte > 0xBF) ? 2 - : 1 + if (isFunction(listeners)) { + this.removeListener(type, listeners); + } else if (listeners) { + // LIFO order + while (listeners.length) + this.removeListener(type, listeners[listeners.length - 1]); + } + delete this._events[type]; - if (i + bytesPerSequence <= end) { - var secondByte, thirdByte, fourthByte, tempCodePoint + return this; + }; - switch (bytesPerSequence) { - case 1: - if (firstByte < 0x80) { - codePoint = firstByte - } - break - case 2: - secondByte = buf[i + 1] - if ((secondByte & 0xC0) === 0x80) { - tempCodePoint = (firstByte & 0x1F) << 0x6 | (secondByte & 0x3F) - if (tempCodePoint > 0x7F) { - codePoint = tempCodePoint - } - } - break - case 3: - secondByte = buf[i + 1] - thirdByte = buf[i + 2] - if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80) { - tempCodePoint = (firstByte & 0xF) << 0xC | (secondByte & 0x3F) << 0x6 | (thirdByte & 0x3F) - if (tempCodePoint > 0x7FF && (tempCodePoint < 0xD800 || tempCodePoint > 0xDFFF)) { - codePoint = tempCodePoint - } - } - break - case 4: - secondByte = buf[i + 1] - thirdByte = buf[i + 2] - fourthByte = buf[i + 3] - if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80 && (fourthByte & 0xC0) === 0x80) { - tempCodePoint = (firstByte & 0xF) << 0x12 | (secondByte & 0x3F) << 0xC | (thirdByte & 0x3F) << 0x6 | (fourthByte & 0x3F) - if (tempCodePoint > 0xFFFF && tempCodePoint < 0x110000) { - codePoint = tempCodePoint - } - } - } - } + EventEmitter.prototype.listeners = function(type) { + var ret; + if (!this._events || !this._events[type]) + ret = []; + else if (isFunction(this._events[type])) + ret = [this._events[type]]; + else + ret = this._events[type].slice(); + return ret; + }; - if (codePoint === null) { - // we did not generate a valid codePoint so insert a - // replacement char (U+FFFD) and advance only 1 byte - codePoint = 0xFFFD - bytesPerSequence = 1 - } else if (codePoint > 0xFFFF) { - // encode to utf16 (surrogate pair dance) - codePoint -= 0x10000 - res.push(codePoint >>> 10 & 0x3FF | 0xD800) - codePoint = 0xDC00 | codePoint & 0x3FF - } + EventEmitter.prototype.listenerCount = function(type) { + if (this._events) { + var evlistener = this._events[type]; - res.push(codePoint) - i += bytesPerSequence + if (isFunction(evlistener)) + return 1; + else if (evlistener) + return evlistener.length; } + return 0; + }; - return decodeCodePointsArray(res) - } - - // Based on http://stackoverflow.com/a/22747272/680742, the browser with - // the lowest limit is Chrome, with 0x10000 args. - // We go 1 magnitude less, for safety - var MAX_ARGUMENTS_LENGTH = 0x1000 + EventEmitter.listenerCount = function(emitter, type) { + return emitter.listenerCount(type); + }; - function decodeCodePointsArray (codePoints) { - var len = codePoints.length - if (len <= MAX_ARGUMENTS_LENGTH) { - return String.fromCharCode.apply(String, codePoints) // avoid extra slice() - } + function isFunction(arg) { + return typeof arg === 'function'; + } - // Decode in chunks to avoid "call stack size exceeded". - var res = '' - var i = 0 - while (i < len) { - res += String.fromCharCode.apply( - String, - codePoints.slice(i, i += MAX_ARGUMENTS_LENGTH) - ) - } - return res + function isNumber(arg) { + return typeof arg === 'number'; } - function asciiSlice (buf, start, end) { - var ret = '' - end = Math.min(buf.length, end) + function isObject(arg) { + return typeof arg === 'object' && arg !== null; + } - for (var i = start; i < end; i++) { - ret += String.fromCharCode(buf[i] & 0x7F) - } - return ret + function isUndefined(arg) { + return arg === void 0; } - function binarySlice (buf, start, end) { - var ret = '' - end = Math.min(buf.length, end) - for (var i = start; i < end; i++) { - ret += String.fromCharCode(buf[i]) +/***/ }, +/* 51 */ +/***/ function(module, exports) { + + if (typeof Object.create === 'function') { + // implementation from standard node.js 'util' module + module.exports = function inherits(ctor, superCtor) { + ctor.super_ = superCtor + ctor.prototype = Object.create(superCtor.prototype, { + constructor: { + value: ctor, + enumerable: false, + writable: true, + configurable: true + } + }); + }; + } else { + // old school shim for old browsers + module.exports = function inherits(ctor, superCtor) { + ctor.super_ = superCtor + var TempCtor = function () {} + TempCtor.prototype = superCtor.prototype + ctor.prototype = new TempCtor() + ctor.prototype.constructor = ctor } - return ret } - function hexSlice (buf, start, end) { - var len = buf.length - if (!start || start < 0) start = 0 - if (!end || end < 0 || end > len) end = len +/***/ }, +/* 52 */ +/***/ function(module, exports, __webpack_require__) { - var out = '' - for (var i = start; i < end; i++) { - out += toHex(buf[i]) - } - return out - } + /* WEBPACK VAR INJECTION */(function(process) {var Stream = (function (){ + try { + return __webpack_require__(49); // hack to fix a circular dependency issue when used with browserify + } catch(_){} + }()); + exports = module.exports = __webpack_require__(53); + exports.Stream = Stream || exports; + exports.Readable = exports; + exports.Writable = __webpack_require__(64); + exports.Duplex = __webpack_require__(63); + exports.Transform = __webpack_require__(69); + exports.PassThrough = __webpack_require__(70); - function utf16leSlice (buf, start, end) { - var bytes = buf.slice(start, end) - var res = '' - for (var i = 0; i < bytes.length; i += 2) { - res += String.fromCharCode(bytes[i] + bytes[i + 1] * 256) - } - return res + if (!process.browser && process.env.READABLE_STREAM === 'disable' && Stream) { + module.exports = Stream; } - Buffer.prototype.slice = function slice (start, end) { - var len = this.length - start = ~~start - end = end === undefined ? len : ~~end - - if (start < 0) { - start += len - if (start < 0) start = 0 - } else if (start > len) { - start = len - } + /* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(10))) - if (end < 0) { - end += len - if (end < 0) end = 0 - } else if (end > len) { - end = len - } +/***/ }, +/* 53 */ +/***/ function(module, exports, __webpack_require__) { - if (end < start) end = start + /* WEBPACK VAR INJECTION */(function(process) {'use strict'; - var newBuf - if (Buffer.TYPED_ARRAY_SUPPORT) { - newBuf = Buffer._augment(this.subarray(start, end)) - } else { - var sliceLen = end - start - newBuf = new Buffer(sliceLen, undefined) - for (var i = 0; i < sliceLen; i++) { - newBuf[i] = this[i + start] - } - } + module.exports = Readable; - if (newBuf.length) newBuf.parent = this.parent || this + /**/ + var processNextTick = __webpack_require__(54); + /**/ - return newBuf - } + /**/ + var isArray = __webpack_require__(55); + /**/ - /* - * Need to make sure that buffer isn't trying to write out of bounds. - */ - function checkOffset (offset, ext, length) { - if ((offset % 1) !== 0 || offset < 0) throw new RangeError('offset is not uint') - if (offset + ext > length) throw new RangeError('Trying to access beyond buffer length') - } + /**/ + var Duplex; + /**/ - Buffer.prototype.readUIntLE = function readUIntLE (offset, byteLength, noAssert) { - offset = offset | 0 - byteLength = byteLength | 0 - if (!noAssert) checkOffset(offset, byteLength, this.length) + Readable.ReadableState = ReadableState; - var val = this[offset] - var mul = 1 - var i = 0 - while (++i < byteLength && (mul *= 0x100)) { - val += this[offset + i] * mul - } + /**/ + var EE = __webpack_require__(50).EventEmitter; - return val - } + var EElistenerCount = function (emitter, type) { + return emitter.listeners(type).length; + }; + /**/ - Buffer.prototype.readUIntBE = function readUIntBE (offset, byteLength, noAssert) { - offset = offset | 0 - byteLength = byteLength | 0 - if (!noAssert) { - checkOffset(offset, byteLength, this.length) + /**/ + var Stream; + (function () { + try { + Stream = __webpack_require__(49); + } catch (_) {} finally { + if (!Stream) Stream = __webpack_require__(50).EventEmitter; } + })(); + /**/ - var val = this[offset + --byteLength] - var mul = 1 - while (byteLength > 0 && (mul *= 0x100)) { - val += this[offset + --byteLength] * mul - } + var Buffer = __webpack_require__(56).Buffer; + /**/ + var bufferShim = __webpack_require__(59); + /**/ - return val - } + /**/ + var util = __webpack_require__(60); + util.inherits = __webpack_require__(51); + /**/ - Buffer.prototype.readUInt8 = function readUInt8 (offset, noAssert) { - if (!noAssert) checkOffset(offset, 1, this.length) - return this[offset] + /**/ + var debugUtil = __webpack_require__(61); + var debug = void 0; + if (debugUtil && debugUtil.debuglog) { + debug = debugUtil.debuglog('stream'); + } else { + debug = function () {}; } + /**/ - Buffer.prototype.readUInt16LE = function readUInt16LE (offset, noAssert) { - if (!noAssert) checkOffset(offset, 2, this.length) - return this[offset] | (this[offset + 1] << 8) - } + var BufferList = __webpack_require__(62); + var StringDecoder; - Buffer.prototype.readUInt16BE = function readUInt16BE (offset, noAssert) { - if (!noAssert) checkOffset(offset, 2, this.length) - return (this[offset] << 8) | this[offset + 1] + util.inherits(Readable, Stream); + + function prependListener(emitter, event, fn) { + // Sadly this is not cacheable as some libraries bundle their own + // event emitter implementation with them. + if (typeof emitter.prependListener === 'function') { + return emitter.prependListener(event, fn); + } else { + // This is a hack to make sure that our error handler is attached before any + // userland ones. NEVER DO THIS. This is here only because this code needs + // to continue to work with older versions of Node.js that do not include + // the prependListener() method. The goal is to eventually remove this hack. + if (!emitter._events || !emitter._events[event]) emitter.on(event, fn);else if (isArray(emitter._events[event])) emitter._events[event].unshift(fn);else emitter._events[event] = [fn, emitter._events[event]]; + } } - Buffer.prototype.readUInt32LE = function readUInt32LE (offset, noAssert) { - if (!noAssert) checkOffset(offset, 4, this.length) + function ReadableState(options, stream) { + Duplex = Duplex || __webpack_require__(63); - return ((this[offset]) | - (this[offset + 1] << 8) | - (this[offset + 2] << 16)) + - (this[offset + 3] * 0x1000000) - } + options = options || {}; - Buffer.prototype.readUInt32BE = function readUInt32BE (offset, noAssert) { - if (!noAssert) checkOffset(offset, 4, this.length) + // object stream flag. Used to make read(n) ignore n and to + // make all the buffer merging and length checks go away + this.objectMode = !!options.objectMode; - return (this[offset] * 0x1000000) + - ((this[offset + 1] << 16) | - (this[offset + 2] << 8) | - this[offset + 3]) - } + if (stream instanceof Duplex) this.objectMode = this.objectMode || !!options.readableObjectMode; - Buffer.prototype.readIntLE = function readIntLE (offset, byteLength, noAssert) { - offset = offset | 0 - byteLength = byteLength | 0 - if (!noAssert) checkOffset(offset, byteLength, this.length) + // the point at which it stops calling _read() to fill the buffer + // Note: 0 is a valid value, means "don't call _read preemptively ever" + var hwm = options.highWaterMark; + var defaultHwm = this.objectMode ? 16 : 16 * 1024; + this.highWaterMark = hwm || hwm === 0 ? hwm : defaultHwm; - var val = this[offset] - var mul = 1 - var i = 0 - while (++i < byteLength && (mul *= 0x100)) { - val += this[offset + i] * mul - } - mul *= 0x80 + // cast to ints. + this.highWaterMark = ~ ~this.highWaterMark; - if (val >= mul) val -= Math.pow(2, 8 * byteLength) + // A linked list is used to store data chunks instead of an array because the + // linked list can remove elements from the beginning faster than + // array.shift() + this.buffer = new BufferList(); + this.length = 0; + this.pipes = null; + this.pipesCount = 0; + this.flowing = null; + this.ended = false; + this.endEmitted = false; + this.reading = false; - return val - } + // a flag to be able to tell if the onwrite cb is called immediately, + // or on a later tick. We set this to true at first, because any + // actions that shouldn't happen until "later" should generally also + // not happen before the first write call. + this.sync = true; - Buffer.prototype.readIntBE = function readIntBE (offset, byteLength, noAssert) { - offset = offset | 0 - byteLength = byteLength | 0 - if (!noAssert) checkOffset(offset, byteLength, this.length) + // whenever we return null, then we set a flag to say + // that we're awaiting a 'readable' event emission. + this.needReadable = false; + this.emittedReadable = false; + this.readableListening = false; + this.resumeScheduled = false; - var i = byteLength - var mul = 1 - var val = this[offset + --i] - while (i > 0 && (mul *= 0x100)) { - val += this[offset + --i] * mul - } - mul *= 0x80 + // Crypto is kind of old and crusty. Historically, its default string + // encoding is 'binary' so we have to make this configurable. + // Everything else in the universe uses 'utf8', though. + this.defaultEncoding = options.defaultEncoding || 'utf8'; - if (val >= mul) val -= Math.pow(2, 8 * byteLength) + // when piping, we only care about 'readable' events that happen + // after read()ing all the bytes and not getting any pushback. + this.ranOut = false; - return val - } + // the number of writers that are awaiting a drain event in .pipe()s + this.awaitDrain = 0; - Buffer.prototype.readInt8 = function readInt8 (offset, noAssert) { - if (!noAssert) checkOffset(offset, 1, this.length) - if (!(this[offset] & 0x80)) return (this[offset]) - return ((0xff - this[offset] + 1) * -1) - } + // if true, a maybeReadMore has been scheduled + this.readingMore = false; - Buffer.prototype.readInt16LE = function readInt16LE (offset, noAssert) { - if (!noAssert) checkOffset(offset, 2, this.length) - var val = this[offset] | (this[offset + 1] << 8) - return (val & 0x8000) ? val | 0xFFFF0000 : val + this.decoder = null; + this.encoding = null; + if (options.encoding) { + if (!StringDecoder) StringDecoder = __webpack_require__(68).StringDecoder; + this.decoder = new StringDecoder(options.encoding); + this.encoding = options.encoding; + } } - Buffer.prototype.readInt16BE = function readInt16BE (offset, noAssert) { - if (!noAssert) checkOffset(offset, 2, this.length) - var val = this[offset + 1] | (this[offset] << 8) - return (val & 0x8000) ? val | 0xFFFF0000 : val - } + function Readable(options) { + Duplex = Duplex || __webpack_require__(63); - Buffer.prototype.readInt32LE = function readInt32LE (offset, noAssert) { - if (!noAssert) checkOffset(offset, 4, this.length) + if (!(this instanceof Readable)) return new Readable(options); - return (this[offset]) | - (this[offset + 1] << 8) | - (this[offset + 2] << 16) | - (this[offset + 3] << 24) - } + this._readableState = new ReadableState(options, this); - Buffer.prototype.readInt32BE = function readInt32BE (offset, noAssert) { - if (!noAssert) checkOffset(offset, 4, this.length) + // legacy + this.readable = true; - return (this[offset] << 24) | - (this[offset + 1] << 16) | - (this[offset + 2] << 8) | - (this[offset + 3]) - } + if (options && typeof options.read === 'function') this._read = options.read; - Buffer.prototype.readFloatLE = function readFloatLE (offset, noAssert) { - if (!noAssert) checkOffset(offset, 4, this.length) - return ieee754.read(this, offset, true, 23, 4) + Stream.call(this); } - Buffer.prototype.readFloatBE = function readFloatBE (offset, noAssert) { - if (!noAssert) checkOffset(offset, 4, this.length) - return ieee754.read(this, offset, false, 23, 4) - } + // Manually shove something into the read() buffer. + // This returns true if the highWaterMark has not been hit yet, + // similar to how Writable.write() returns true if you should + // write() some more. + Readable.prototype.push = function (chunk, encoding) { + var state = this._readableState; - Buffer.prototype.readDoubleLE = function readDoubleLE (offset, noAssert) { - if (!noAssert) checkOffset(offset, 8, this.length) - return ieee754.read(this, offset, true, 52, 8) - } + if (!state.objectMode && typeof chunk === 'string') { + encoding = encoding || state.defaultEncoding; + if (encoding !== state.encoding) { + chunk = bufferShim.from(chunk, encoding); + encoding = ''; + } + } - Buffer.prototype.readDoubleBE = function readDoubleBE (offset, noAssert) { - if (!noAssert) checkOffset(offset, 8, this.length) - return ieee754.read(this, offset, false, 52, 8) - } + return readableAddChunk(this, state, chunk, encoding, false); + }; - function checkInt (buf, value, offset, ext, max, min) { - if (!Buffer.isBuffer(buf)) throw new TypeError('buffer must be a Buffer instance') - if (value > max || value < min) throw new RangeError('value is out of bounds') - if (offset + ext > buf.length) throw new RangeError('index out of range') - } + // Unshift should *always* be something directly out of read() + Readable.prototype.unshift = function (chunk) { + var state = this._readableState; + return readableAddChunk(this, state, chunk, '', true); + }; - Buffer.prototype.writeUIntLE = function writeUIntLE (value, offset, byteLength, noAssert) { - value = +value - offset = offset | 0 - byteLength = byteLength | 0 - if (!noAssert) checkInt(this, value, offset, byteLength, Math.pow(2, 8 * byteLength), 0) + Readable.prototype.isPaused = function () { + return this._readableState.flowing === false; + }; - var mul = 1 - var i = 0 - this[offset] = value & 0xFF - while (++i < byteLength && (mul *= 0x100)) { - this[offset + i] = (value / mul) & 0xFF - } + function readableAddChunk(stream, state, chunk, encoding, addToFront) { + var er = chunkInvalid(state, chunk); + if (er) { + stream.emit('error', er); + } else if (chunk === null) { + state.reading = false; + onEofChunk(stream, state); + } else if (state.objectMode || chunk && chunk.length > 0) { + if (state.ended && !addToFront) { + var e = new Error('stream.push() after EOF'); + stream.emit('error', e); + } else if (state.endEmitted && addToFront) { + var _e = new Error('stream.unshift() after end event'); + stream.emit('error', _e); + } else { + var skipAdd; + if (state.decoder && !addToFront && !encoding) { + chunk = state.decoder.write(chunk); + skipAdd = !state.objectMode && chunk.length === 0; + } - return offset + byteLength - } + if (!addToFront) state.reading = false; - Buffer.prototype.writeUIntBE = function writeUIntBE (value, offset, byteLength, noAssert) { - value = +value - offset = offset | 0 - byteLength = byteLength | 0 - if (!noAssert) checkInt(this, value, offset, byteLength, Math.pow(2, 8 * byteLength), 0) + // Don't add to the buffer if we've decoded to an empty string chunk and + // we're not in object mode + if (!skipAdd) { + // if we want the data now, just emit it. + if (state.flowing && state.length === 0 && !state.sync) { + stream.emit('data', chunk); + stream.read(0); + } else { + // update the buffer info. + state.length += state.objectMode ? 1 : chunk.length; + if (addToFront) state.buffer.unshift(chunk);else state.buffer.push(chunk); - var i = byteLength - 1 - var mul = 1 - this[offset + i] = value & 0xFF - while (--i >= 0 && (mul *= 0x100)) { - this[offset + i] = (value / mul) & 0xFF + if (state.needReadable) emitReadable(stream); + } + } + + maybeReadMore(stream, state); + } + } else if (!addToFront) { + state.reading = false; } - return offset + byteLength + return needMoreData(state); } - Buffer.prototype.writeUInt8 = function writeUInt8 (value, offset, noAssert) { - value = +value - offset = offset | 0 - if (!noAssert) checkInt(this, value, offset, 1, 0xff, 0) - if (!Buffer.TYPED_ARRAY_SUPPORT) value = Math.floor(value) - this[offset] = (value & 0xff) - return offset + 1 + // if it's past the high water mark, we can push in some more. + // Also, if we have no data yet, we can stand some + // more bytes. This is to work around cases where hwm=0, + // such as the repl. Also, if the push() triggered a + // readable event, and the user called read(largeNumber) such that + // needReadable was set, then we ought to push more, so that another + // 'readable' event will be triggered. + function needMoreData(state) { + return !state.ended && (state.needReadable || state.length < state.highWaterMark || state.length === 0); } - function objectWriteUInt16 (buf, value, offset, littleEndian) { - if (value < 0) value = 0xffff + value + 1 - for (var i = 0, j = Math.min(buf.length - offset, 2); i < j; i++) { - buf[offset + i] = (value & (0xff << (8 * (littleEndian ? i : 1 - i)))) >>> - (littleEndian ? i : 1 - i) * 8 - } - } + // backwards compatibility. + Readable.prototype.setEncoding = function (enc) { + if (!StringDecoder) StringDecoder = __webpack_require__(68).StringDecoder; + this._readableState.decoder = new StringDecoder(enc); + this._readableState.encoding = enc; + return this; + }; - Buffer.prototype.writeUInt16LE = function writeUInt16LE (value, offset, noAssert) { - value = +value - offset = offset | 0 - if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0) - if (Buffer.TYPED_ARRAY_SUPPORT) { - this[offset] = (value & 0xff) - this[offset + 1] = (value >>> 8) + // Don't raise the hwm > 8MB + var MAX_HWM = 0x800000; + function computeNewHighWaterMark(n) { + if (n >= MAX_HWM) { + n = MAX_HWM; } else { - objectWriteUInt16(this, value, offset, true) + // Get the next highest power of 2 to prevent increasing hwm excessively in + // tiny amounts + n--; + n |= n >>> 1; + n |= n >>> 2; + n |= n >>> 4; + n |= n >>> 8; + n |= n >>> 16; + n++; } - return offset + 2 + return n; } - Buffer.prototype.writeUInt16BE = function writeUInt16BE (value, offset, noAssert) { - value = +value - offset = offset | 0 - if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0) - if (Buffer.TYPED_ARRAY_SUPPORT) { - this[offset] = (value >>> 8) - this[offset + 1] = (value & 0xff) - } else { - objectWriteUInt16(this, value, offset, false) + // This function is designed to be inlinable, so please take care when making + // changes to the function body. + function howMuchToRead(n, state) { + if (n <= 0 || state.length === 0 && state.ended) return 0; + if (state.objectMode) return 1; + if (n !== n) { + // Only flow one buffer at a time + if (state.flowing && state.length) return state.buffer.head.data.length;else return state.length; + } + // If we're asking for more than the current hwm, then raise the hwm. + if (n > state.highWaterMark) state.highWaterMark = computeNewHighWaterMark(n); + if (n <= state.length) return n; + // Don't have enough + if (!state.ended) { + state.needReadable = true; + return 0; } - return offset + 2 + return state.length; } - function objectWriteUInt32 (buf, value, offset, littleEndian) { - if (value < 0) value = 0xffffffff + value + 1 - for (var i = 0, j = Math.min(buf.length - offset, 4); i < j; i++) { - buf[offset + i] = (value >>> (littleEndian ? i : 3 - i) * 8) & 0xff - } - } + // you can override either this method, or the async _read(n) below. + Readable.prototype.read = function (n) { + debug('read', n); + n = parseInt(n, 10); + var state = this._readableState; + var nOrig = n; - Buffer.prototype.writeUInt32LE = function writeUInt32LE (value, offset, noAssert) { - value = +value - offset = offset | 0 - if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0) - if (Buffer.TYPED_ARRAY_SUPPORT) { - this[offset + 3] = (value >>> 24) - this[offset + 2] = (value >>> 16) - this[offset + 1] = (value >>> 8) - this[offset] = (value & 0xff) - } else { - objectWriteUInt32(this, value, offset, true) - } - return offset + 4 - } + if (n !== 0) state.emittedReadable = false; - Buffer.prototype.writeUInt32BE = function writeUInt32BE (value, offset, noAssert) { - value = +value - offset = offset | 0 - if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0) - if (Buffer.TYPED_ARRAY_SUPPORT) { - this[offset] = (value >>> 24) - this[offset + 1] = (value >>> 16) - this[offset + 2] = (value >>> 8) - this[offset + 3] = (value & 0xff) - } else { - objectWriteUInt32(this, value, offset, false) + // if we're doing read(0) to trigger a readable event, but we + // already have a bunch of data in the buffer, then just trigger + // the 'readable' event and move on. + if (n === 0 && state.needReadable && (state.length >= state.highWaterMark || state.ended)) { + debug('read: emitReadable', state.length, state.ended); + if (state.length === 0 && state.ended) endReadable(this);else emitReadable(this); + return null; } - return offset + 4 - } - - Buffer.prototype.writeIntLE = function writeIntLE (value, offset, byteLength, noAssert) { - value = +value - offset = offset | 0 - if (!noAssert) { - var limit = Math.pow(2, 8 * byteLength - 1) - checkInt(this, value, offset, byteLength, limit - 1, -limit) - } + n = howMuchToRead(n, state); - var i = 0 - var mul = 1 - var sub = value < 0 ? 1 : 0 - this[offset] = value & 0xFF - while (++i < byteLength && (mul *= 0x100)) { - this[offset + i] = ((value / mul) >> 0) - sub & 0xFF + // if we've ended, and we're now clear, then finish it up. + if (n === 0 && state.ended) { + if (state.length === 0) endReadable(this); + return null; } - return offset + byteLength - } + // All the actual chunk generation logic needs to be + // *below* the call to _read. The reason is that in certain + // synthetic stream cases, such as passthrough streams, _read + // may be a completely synchronous operation which may change + // the state of the read buffer, providing enough data when + // before there was *not* enough. + // + // So, the steps are: + // 1. Figure out what the state of things will be after we do + // a read from the buffer. + // + // 2. If that resulting state will trigger a _read, then call _read. + // Note that this may be asynchronous, or synchronous. Yes, it is + // deeply ugly to write APIs this way, but that still doesn't mean + // that the Readable class should behave improperly, as streams are + // designed to be sync/async agnostic. + // Take note if the _read call is sync or async (ie, if the read call + // has returned yet), so that we know whether or not it's safe to emit + // 'readable' etc. + // + // 3. Actually pull the requested chunks out of the buffer and return. - Buffer.prototype.writeIntBE = function writeIntBE (value, offset, byteLength, noAssert) { - value = +value - offset = offset | 0 - if (!noAssert) { - var limit = Math.pow(2, 8 * byteLength - 1) + // if we need a readable event, then we need to do some reading. + var doRead = state.needReadable; + debug('need readable', doRead); - checkInt(this, value, offset, byteLength, limit - 1, -limit) + // if we currently have less than the highWaterMark, then also read some + if (state.length === 0 || state.length - n < state.highWaterMark) { + doRead = true; + debug('length less than watermark', doRead); } - var i = byteLength - 1 - var mul = 1 - var sub = value < 0 ? 1 : 0 - this[offset + i] = value & 0xFF - while (--i >= 0 && (mul *= 0x100)) { - this[offset + i] = ((value / mul) >> 0) - sub & 0xFF + // however, if we've ended, then there's no point, and if we're already + // reading, then it's unnecessary. + if (state.ended || state.reading) { + doRead = false; + debug('reading or ended', doRead); + } else if (doRead) { + debug('do read'); + state.reading = true; + state.sync = true; + // if the length is currently zero, then we *need* a readable event. + if (state.length === 0) state.needReadable = true; + // call internal read method + this._read(state.highWaterMark); + state.sync = false; + // If _read pushed data synchronously, then `reading` will be false, + // and we need to re-evaluate how much data we can return to the user. + if (!state.reading) n = howMuchToRead(nOrig, state); } - return offset + byteLength - } - - Buffer.prototype.writeInt8 = function writeInt8 (value, offset, noAssert) { - value = +value - offset = offset | 0 - if (!noAssert) checkInt(this, value, offset, 1, 0x7f, -0x80) - if (!Buffer.TYPED_ARRAY_SUPPORT) value = Math.floor(value) - if (value < 0) value = 0xff + value + 1 - this[offset] = (value & 0xff) - return offset + 1 - } + var ret; + if (n > 0) ret = fromList(n, state);else ret = null; - Buffer.prototype.writeInt16LE = function writeInt16LE (value, offset, noAssert) { - value = +value - offset = offset | 0 - if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000) - if (Buffer.TYPED_ARRAY_SUPPORT) { - this[offset] = (value & 0xff) - this[offset + 1] = (value >>> 8) + if (ret === null) { + state.needReadable = true; + n = 0; } else { - objectWriteUInt16(this, value, offset, true) + state.length -= n; } - return offset + 2 - } - Buffer.prototype.writeInt16BE = function writeInt16BE (value, offset, noAssert) { - value = +value - offset = offset | 0 - if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000) - if (Buffer.TYPED_ARRAY_SUPPORT) { - this[offset] = (value >>> 8) - this[offset + 1] = (value & 0xff) - } else { - objectWriteUInt16(this, value, offset, false) + if (state.length === 0) { + // If we have nothing in the buffer, then we want to know + // as soon as we *do* get something into the buffer. + if (!state.ended) state.needReadable = true; + + // If we tried to read() past the EOF, then emit end on the next tick. + if (nOrig !== n && state.ended) endReadable(this); } - return offset + 2 - } - Buffer.prototype.writeInt32LE = function writeInt32LE (value, offset, noAssert) { - value = +value - offset = offset | 0 - if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000) - if (Buffer.TYPED_ARRAY_SUPPORT) { - this[offset] = (value & 0xff) - this[offset + 1] = (value >>> 8) - this[offset + 2] = (value >>> 16) - this[offset + 3] = (value >>> 24) - } else { - objectWriteUInt32(this, value, offset, true) + if (ret !== null) this.emit('data', ret); + + return ret; + }; + + function chunkInvalid(state, chunk) { + var er = null; + if (!Buffer.isBuffer(chunk) && typeof chunk !== 'string' && chunk !== null && chunk !== undefined && !state.objectMode) { + er = new TypeError('Invalid non-string/buffer chunk'); } - return offset + 4 + return er; } - Buffer.prototype.writeInt32BE = function writeInt32BE (value, offset, noAssert) { - value = +value - offset = offset | 0 - if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000) - if (value < 0) value = 0xffffffff + value + 1 - if (Buffer.TYPED_ARRAY_SUPPORT) { - this[offset] = (value >>> 24) - this[offset + 1] = (value >>> 16) - this[offset + 2] = (value >>> 8) - this[offset + 3] = (value & 0xff) - } else { - objectWriteUInt32(this, value, offset, false) + function onEofChunk(stream, state) { + if (state.ended) return; + if (state.decoder) { + var chunk = state.decoder.end(); + if (chunk && chunk.length) { + state.buffer.push(chunk); + state.length += state.objectMode ? 1 : chunk.length; + } } - return offset + 4 - } + state.ended = true; - function checkIEEE754 (buf, value, offset, ext, max, min) { - if (value > max || value < min) throw new RangeError('value is out of bounds') - if (offset + ext > buf.length) throw new RangeError('index out of range') - if (offset < 0) throw new RangeError('index out of range') + // emit 'readable' now to make sure it gets picked up. + emitReadable(stream); } - function writeFloat (buf, value, offset, littleEndian, noAssert) { - if (!noAssert) { - checkIEEE754(buf, value, offset, 4, 3.4028234663852886e+38, -3.4028234663852886e+38) + // Don't emit readable right away in sync mode, because this can trigger + // another read() call => stack overflow. This way, it might trigger + // a nextTick recursion warning, but that's not so bad. + function emitReadable(stream) { + var state = stream._readableState; + state.needReadable = false; + if (!state.emittedReadable) { + debug('emitReadable', state.flowing); + state.emittedReadable = true; + if (state.sync) processNextTick(emitReadable_, stream);else emitReadable_(stream); } - ieee754.write(buf, value, offset, littleEndian, 23, 4) - return offset + 4 } - Buffer.prototype.writeFloatLE = function writeFloatLE (value, offset, noAssert) { - return writeFloat(this, value, offset, true, noAssert) + function emitReadable_(stream) { + debug('emit readable'); + stream.emit('readable'); + flow(stream); } - Buffer.prototype.writeFloatBE = function writeFloatBE (value, offset, noAssert) { - return writeFloat(this, value, offset, false, noAssert) + // at this point, the user has presumably seen the 'readable' event, + // and called read() to consume some data. that may have triggered + // in turn another _read(n) call, in which case reading = true if + // it's in progress. + // However, if we're not ended, or reading, and the length < hwm, + // then go ahead and try to read some more preemptively. + function maybeReadMore(stream, state) { + if (!state.readingMore) { + state.readingMore = true; + processNextTick(maybeReadMore_, stream, state); + } } - function writeDouble (buf, value, offset, littleEndian, noAssert) { - if (!noAssert) { - checkIEEE754(buf, value, offset, 8, 1.7976931348623157E+308, -1.7976931348623157E+308) + function maybeReadMore_(stream, state) { + var len = state.length; + while (!state.reading && !state.flowing && !state.ended && state.length < state.highWaterMark) { + debug('maybeReadMore read 0'); + stream.read(0); + if (len === state.length) + // didn't get any data, stop spinning. + break;else len = state.length; } - ieee754.write(buf, value, offset, littleEndian, 52, 8) - return offset + 8 + state.readingMore = false; } - Buffer.prototype.writeDoubleLE = function writeDoubleLE (value, offset, noAssert) { - return writeDouble(this, value, offset, true, noAssert) - } + // abstract method. to be overridden in specific implementation classes. + // call cb(er, data) where data is <= n in length. + // for virtual (non-string, non-buffer) streams, "length" is somewhat + // arbitrary, and perhaps not very meaningful. + Readable.prototype._read = function (n) { + this.emit('error', new Error('_read() is not implemented')); + }; - Buffer.prototype.writeDoubleBE = function writeDoubleBE (value, offset, noAssert) { - return writeDouble(this, value, offset, false, noAssert) - } + Readable.prototype.pipe = function (dest, pipeOpts) { + var src = this; + var state = this._readableState; - // copy(targetBuffer, targetStart=0, sourceStart=0, sourceEnd=buffer.length) - Buffer.prototype.copy = function copy (target, targetStart, start, end) { - if (!start) start = 0 - if (!end && end !== 0) end = this.length - if (targetStart >= target.length) targetStart = target.length - if (!targetStart) targetStart = 0 - if (end > 0 && end < start) end = start + switch (state.pipesCount) { + case 0: + state.pipes = dest; + break; + case 1: + state.pipes = [state.pipes, dest]; + break; + default: + state.pipes.push(dest); + break; + } + state.pipesCount += 1; + debug('pipe count=%d opts=%j', state.pipesCount, pipeOpts); - // Copy 0 bytes; we're done - if (end === start) return 0 - if (target.length === 0 || this.length === 0) return 0 + var doEnd = (!pipeOpts || pipeOpts.end !== false) && dest !== process.stdout && dest !== process.stderr; - // Fatal error conditions - if (targetStart < 0) { - throw new RangeError('targetStart out of bounds') + var endFn = doEnd ? onend : cleanup; + if (state.endEmitted) processNextTick(endFn);else src.once('end', endFn); + + dest.on('unpipe', onunpipe); + function onunpipe(readable) { + debug('onunpipe'); + if (readable === src) { + cleanup(); + } } - if (start < 0 || start >= this.length) throw new RangeError('sourceStart out of bounds') - if (end < 0) throw new RangeError('sourceEnd out of bounds') - // Are we oob? - if (end > this.length) end = this.length - if (target.length - targetStart < end - start) { - end = target.length - targetStart + start + function onend() { + debug('onend'); + dest.end(); } - var len = end - start - var i + // when the dest drains, it reduces the awaitDrain counter + // on the source. This would be more elegant with a .once() + // handler in flow(), but adding and removing repeatedly is + // too slow. + var ondrain = pipeOnDrain(src); + dest.on('drain', ondrain); + + var cleanedUp = false; + function cleanup() { + debug('cleanup'); + // cleanup event handlers once the pipe is broken + dest.removeListener('close', onclose); + dest.removeListener('finish', onfinish); + dest.removeListener('drain', ondrain); + dest.removeListener('error', onerror); + dest.removeListener('unpipe', onunpipe); + src.removeListener('end', onend); + src.removeListener('end', cleanup); + src.removeListener('data', ondata); + + cleanedUp = true; - if (this === target && start < targetStart && targetStart < end) { - // descending copy from end - for (i = len - 1; i >= 0; i--) { - target[i + targetStart] = this[i + start] - } - } else if (len < 1000 || !Buffer.TYPED_ARRAY_SUPPORT) { - // ascending copy from start - for (i = 0; i < len; i++) { - target[i + targetStart] = this[i + start] + // if the reader is waiting for a drain event from this + // specific writer, then it would cause it to never start + // flowing again. + // So, if this is awaiting a drain, then we just call it now. + // If we don't know, then assume that we are waiting for one. + if (state.awaitDrain && (!dest._writableState || dest._writableState.needDrain)) ondrain(); + } + + // If the user pushes more data while we're writing to dest then we'll end up + // in ondata again. However, we only want to increase awaitDrain once because + // dest will only emit one 'drain' event for the multiple writes. + // => Introduce a guard on increasing awaitDrain. + var increasedAwaitDrain = false; + src.on('data', ondata); + function ondata(chunk) { + debug('ondata'); + increasedAwaitDrain = false; + var ret = dest.write(chunk); + if (false === ret && !increasedAwaitDrain) { + // If the user unpiped during `dest.write()`, it is possible + // to get stuck in a permanently paused state if that write + // also returned false. + // => Check whether `dest` is still a piping destination. + if ((state.pipesCount === 1 && state.pipes === dest || state.pipesCount > 1 && indexOf(state.pipes, dest) !== -1) && !cleanedUp) { + debug('false write response, pause', src._readableState.awaitDrain); + src._readableState.awaitDrain++; + increasedAwaitDrain = true; + } + src.pause(); } - } else { - target._set(this.subarray(start, start + len), targetStart) } - return len - } + // if the dest has an error, then stop piping into it. + // however, don't suppress the throwing behavior for this. + function onerror(er) { + debug('onerror', er); + unpipe(); + dest.removeListener('error', onerror); + if (EElistenerCount(dest, 'error') === 0) dest.emit('error', er); + } - // fill(value, start=0, end=buffer.length) - Buffer.prototype.fill = function fill (value, start, end) { - if (!value) value = 0 - if (!start) start = 0 - if (!end) end = this.length + // Make sure our error handler is attached before userland ones. + prependListener(dest, 'error', onerror); - if (end < start) throw new RangeError('end < start') + // Both close and finish should trigger unpipe, but only once. + function onclose() { + dest.removeListener('finish', onfinish); + unpipe(); + } + dest.once('close', onclose); + function onfinish() { + debug('onfinish'); + dest.removeListener('close', onclose); + unpipe(); + } + dest.once('finish', onfinish); - // Fill 0 bytes; we're done - if (end === start) return - if (this.length === 0) return + function unpipe() { + debug('unpipe'); + src.unpipe(dest); + } - if (start < 0 || start >= this.length) throw new RangeError('start out of bounds') - if (end < 0 || end > this.length) throw new RangeError('end out of bounds') + // tell the dest that it's being piped to + dest.emit('pipe', src); - var i - if (typeof value === 'number') { - for (i = start; i < end; i++) { - this[i] = value - } - } else { - var bytes = utf8ToBytes(value.toString()) - var len = bytes.length - for (i = start; i < end; i++) { - this[i] = bytes[i % len] - } + // start the flow if it hasn't been started already. + if (!state.flowing) { + debug('pipe resume'); + src.resume(); } - return this - } + return dest; + }; - /** - * Creates a new `ArrayBuffer` with the *copied* memory of the buffer instance. - * Added in Node 0.12. Only available in browsers that support ArrayBuffer. - */ - Buffer.prototype.toArrayBuffer = function toArrayBuffer () { - if (typeof Uint8Array !== 'undefined') { - if (Buffer.TYPED_ARRAY_SUPPORT) { - return (new Buffer(this)).buffer - } else { - var buf = new Uint8Array(this.length) - for (var i = 0, len = buf.length; i < len; i += 1) { - buf[i] = this[i] - } - return buf.buffer + function pipeOnDrain(src) { + return function () { + var state = src._readableState; + debug('pipeOnDrain', state.awaitDrain); + if (state.awaitDrain) state.awaitDrain--; + if (state.awaitDrain === 0 && EElistenerCount(src, 'data')) { + state.flowing = true; + flow(src); } - } else { - throw new TypeError('Buffer.toArrayBuffer not supported in this browser') - } + }; } - // HELPER FUNCTIONS - // ================ - - var BP = Buffer.prototype + Readable.prototype.unpipe = function (dest) { + var state = this._readableState; - /** - * Augment a Uint8Array *instance* (not the Uint8Array class!) with Buffer methods - */ - Buffer._augment = function _augment (arr) { - arr.constructor = Buffer - arr._isBuffer = true - - // save reference to original Uint8Array set method before overwriting - arr._set = arr.set - - // deprecated - arr.get = BP.get - arr.set = BP.set - - arr.write = BP.write - arr.toString = BP.toString - arr.toLocaleString = BP.toString - arr.toJSON = BP.toJSON - arr.equals = BP.equals - arr.compare = BP.compare - arr.indexOf = BP.indexOf - arr.copy = BP.copy - arr.slice = BP.slice - arr.readUIntLE = BP.readUIntLE - arr.readUIntBE = BP.readUIntBE - arr.readUInt8 = BP.readUInt8 - arr.readUInt16LE = BP.readUInt16LE - arr.readUInt16BE = BP.readUInt16BE - arr.readUInt32LE = BP.readUInt32LE - arr.readUInt32BE = BP.readUInt32BE - arr.readIntLE = BP.readIntLE - arr.readIntBE = BP.readIntBE - arr.readInt8 = BP.readInt8 - arr.readInt16LE = BP.readInt16LE - arr.readInt16BE = BP.readInt16BE - arr.readInt32LE = BP.readInt32LE - arr.readInt32BE = BP.readInt32BE - arr.readFloatLE = BP.readFloatLE - arr.readFloatBE = BP.readFloatBE - arr.readDoubleLE = BP.readDoubleLE - arr.readDoubleBE = BP.readDoubleBE - arr.writeUInt8 = BP.writeUInt8 - arr.writeUIntLE = BP.writeUIntLE - arr.writeUIntBE = BP.writeUIntBE - arr.writeUInt16LE = BP.writeUInt16LE - arr.writeUInt16BE = BP.writeUInt16BE - arr.writeUInt32LE = BP.writeUInt32LE - arr.writeUInt32BE = BP.writeUInt32BE - arr.writeIntLE = BP.writeIntLE - arr.writeIntBE = BP.writeIntBE - arr.writeInt8 = BP.writeInt8 - arr.writeInt16LE = BP.writeInt16LE - arr.writeInt16BE = BP.writeInt16BE - arr.writeInt32LE = BP.writeInt32LE - arr.writeInt32BE = BP.writeInt32BE - arr.writeFloatLE = BP.writeFloatLE - arr.writeFloatBE = BP.writeFloatBE - arr.writeDoubleLE = BP.writeDoubleLE - arr.writeDoubleBE = BP.writeDoubleBE - arr.fill = BP.fill - arr.inspect = BP.inspect - arr.toArrayBuffer = BP.toArrayBuffer + // if we're not piping anywhere, then do nothing. + if (state.pipesCount === 0) return this; - return arr - } + // just one destination. most common case. + if (state.pipesCount === 1) { + // passed in one, but it's not the right one. + if (dest && dest !== state.pipes) return this; - var INVALID_BASE64_RE = /[^+\/0-9A-Za-z-_]/g + if (!dest) dest = state.pipes; - function base64clean (str) { - // Node strips out invalid characters like \n and \t from the string, base64-js does not - str = stringtrim(str).replace(INVALID_BASE64_RE, '') - // Node converts strings with length < 2 to '' - if (str.length < 2) return '' - // Node allows for non-padded base64 strings (missing trailing ===), base64-js does not - while (str.length % 4 !== 0) { - str = str + '=' + // got a match. + state.pipes = null; + state.pipesCount = 0; + state.flowing = false; + if (dest) dest.emit('unpipe', this); + return this; } - return str - } - - function stringtrim (str) { - if (str.trim) return str.trim() - return str.replace(/^\s+|\s+$/g, '') - } - - function toHex (n) { - if (n < 16) return '0' + n.toString(16) - return n.toString(16) - } - function utf8ToBytes (string, units) { - units = units || Infinity - var codePoint - var length = string.length - var leadSurrogate = null - var bytes = [] + // slow case. multiple pipe destinations. - for (var i = 0; i < length; i++) { - codePoint = string.charCodeAt(i) + if (!dest) { + // remove all. + var dests = state.pipes; + var len = state.pipesCount; + state.pipes = null; + state.pipesCount = 0; + state.flowing = false; - // is surrogate component - if (codePoint > 0xD7FF && codePoint < 0xE000) { - // last char was a lead - if (!leadSurrogate) { - // no lead yet - if (codePoint > 0xDBFF) { - // unexpected trail - if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD) - continue - } else if (i + 1 === length) { - // unpaired lead - if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD) - continue - } + for (var i = 0; i < len; i++) { + dests[i].emit('unpipe', this); + }return this; + } - // valid lead - leadSurrogate = codePoint + // try to find the right one. + var index = indexOf(state.pipes, dest); + if (index === -1) return this; - continue - } + state.pipes.splice(index, 1); + state.pipesCount -= 1; + if (state.pipesCount === 1) state.pipes = state.pipes[0]; - // 2 leads in a row - if (codePoint < 0xDC00) { - if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD) - leadSurrogate = codePoint - continue - } + dest.emit('unpipe', this); - // valid surrogate pair - codePoint = (leadSurrogate - 0xD800 << 10 | codePoint - 0xDC00) + 0x10000 - } else if (leadSurrogate) { - // valid bmp char, but last char was a lead - if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD) - } + return this; + }; - leadSurrogate = null + // set up data events if they are asked for + // Ensure readable listeners eventually get something + Readable.prototype.on = function (ev, fn) { + var res = Stream.prototype.on.call(this, ev, fn); - // encode utf8 - if (codePoint < 0x80) { - if ((units -= 1) < 0) break - bytes.push(codePoint) - } else if (codePoint < 0x800) { - if ((units -= 2) < 0) break - bytes.push( - codePoint >> 0x6 | 0xC0, - codePoint & 0x3F | 0x80 - ) - } else if (codePoint < 0x10000) { - if ((units -= 3) < 0) break - bytes.push( - codePoint >> 0xC | 0xE0, - codePoint >> 0x6 & 0x3F | 0x80, - codePoint & 0x3F | 0x80 - ) - } else if (codePoint < 0x110000) { - if ((units -= 4) < 0) break - bytes.push( - codePoint >> 0x12 | 0xF0, - codePoint >> 0xC & 0x3F | 0x80, - codePoint >> 0x6 & 0x3F | 0x80, - codePoint & 0x3F | 0x80 - ) - } else { - throw new Error('Invalid code point') + if (ev === 'data') { + // Start flowing on next tick if stream isn't explicitly paused + if (this._readableState.flowing !== false) this.resume(); + } else if (ev === 'readable') { + var state = this._readableState; + if (!state.endEmitted && !state.readableListening) { + state.readableListening = state.needReadable = true; + state.emittedReadable = false; + if (!state.reading) { + processNextTick(nReadingNextTick, this); + } else if (state.length) { + emitReadable(this, state); + } } } - return bytes - } + return res; + }; + Readable.prototype.addListener = Readable.prototype.on; - function asciiToBytes (str) { - var byteArray = [] - for (var i = 0; i < str.length; i++) { - // Node's code seems to be doing this and not & 0x7F.. - byteArray.push(str.charCodeAt(i) & 0xFF) - } - return byteArray + function nReadingNextTick(self) { + debug('readable nexttick read 0'); + self.read(0); } - function utf16leToBytes (str, units) { - var c, hi, lo - var byteArray = [] - for (var i = 0; i < str.length; i++) { - if ((units -= 2) < 0) break - - c = str.charCodeAt(i) - hi = c >> 8 - lo = c % 256 - byteArray.push(lo) - byteArray.push(hi) + // pause() and resume() are remnants of the legacy readable stream API + // If the user uses them, then switch into old mode. + Readable.prototype.resume = function () { + var state = this._readableState; + if (!state.flowing) { + debug('resume'); + state.flowing = true; + resume(this, state); } + return this; + }; - return byteArray - } - - function base64ToBytes (str) { - return base64.toByteArray(base64clean(str)) + function resume(stream, state) { + if (!state.resumeScheduled) { + state.resumeScheduled = true; + processNextTick(resume_, stream, state); + } } - function blitBuffer (src, dst, offset, length) { - for (var i = 0; i < length; i++) { - if ((i + offset >= dst.length) || (i >= src.length)) break - dst[i + offset] = src[i] + function resume_(stream, state) { + if (!state.reading) { + debug('resume read 0'); + stream.read(0); } - return i + + state.resumeScheduled = false; + state.awaitDrain = 0; + stream.emit('resume'); + flow(stream); + if (state.flowing && !state.reading) stream.read(0); } - /* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(55).Buffer, (function() { return this; }()))) - -/***/ }, -/* 56 */ -/***/ function(module, exports, __webpack_require__) { - - var lookup = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'; - - ;(function (exports) { - 'use strict'; - - var Arr = (typeof Uint8Array !== 'undefined') - ? Uint8Array - : Array - - var PLUS = '+'.charCodeAt(0) - var SLASH = '/'.charCodeAt(0) - var NUMBER = '0'.charCodeAt(0) - var LOWER = 'a'.charCodeAt(0) - var UPPER = 'A'.charCodeAt(0) - var PLUS_URL_SAFE = '-'.charCodeAt(0) - var SLASH_URL_SAFE = '_'.charCodeAt(0) - - function decode (elt) { - var code = elt.charCodeAt(0) - if (code === PLUS || - code === PLUS_URL_SAFE) - return 62 // '+' - if (code === SLASH || - code === SLASH_URL_SAFE) - return 63 // '/' - if (code < NUMBER) - return -1 //no match - if (code < NUMBER + 10) - return code - NUMBER + 26 + 26 - if (code < UPPER + 26) - return code - UPPER - if (code < LOWER + 26) - return code - LOWER + 26 - } + Readable.prototype.pause = function () { + debug('call pause flowing=%j', this._readableState.flowing); + if (false !== this._readableState.flowing) { + debug('pause'); + this._readableState.flowing = false; + this.emit('pause'); + } + return this; + }; - function b64ToByteArray (b64) { - var i, j, l, tmp, placeHolders, arr + function flow(stream) { + var state = stream._readableState; + debug('flow', state.flowing); + while (state.flowing && stream.read() !== null) {} + } - if (b64.length % 4 > 0) { - throw new Error('Invalid string. Length must be a multiple of 4') - } + // wrap an old-style stream as the async data source. + // This is *not* part of the readable stream interface. + // It is an ugly unfortunate mess of history. + Readable.prototype.wrap = function (stream) { + var state = this._readableState; + var paused = false; - // the number of equal signs (place holders) - // if there are two placeholders, than the two characters before it - // represent one byte - // if there is only one, then the three characters before it represent 2 bytes - // this is just a cheap hack to not do indexOf twice - var len = b64.length - placeHolders = '=' === b64.charAt(len - 2) ? 2 : '=' === b64.charAt(len - 1) ? 1 : 0 + var self = this; + stream.on('end', function () { + debug('wrapped end'); + if (state.decoder && !state.ended) { + var chunk = state.decoder.end(); + if (chunk && chunk.length) self.push(chunk); + } - // base64 is 4/3 + up to two characters of the original data - arr = new Arr(b64.length * 3 / 4 - placeHolders) + self.push(null); + }); - // if there are placeholders, only get up to the last complete 4 chars - l = placeHolders > 0 ? b64.length - 4 : b64.length + stream.on('data', function (chunk) { + debug('wrapped data'); + if (state.decoder) chunk = state.decoder.write(chunk); - var L = 0 + // don't skip over falsy values in objectMode + if (state.objectMode && (chunk === null || chunk === undefined)) return;else if (!state.objectMode && (!chunk || !chunk.length)) return; - function push (v) { - arr[L++] = v - } + var ret = self.push(chunk); + if (!ret) { + paused = true; + stream.pause(); + } + }); - for (i = 0, j = 0; i < l; i += 4, j += 3) { - tmp = (decode(b64.charAt(i)) << 18) | (decode(b64.charAt(i + 1)) << 12) | (decode(b64.charAt(i + 2)) << 6) | decode(b64.charAt(i + 3)) - push((tmp & 0xFF0000) >> 16) - push((tmp & 0xFF00) >> 8) - push(tmp & 0xFF) - } + // proxy all the other methods. + // important when wrapping filters and duplexes. + for (var i in stream) { + if (this[i] === undefined && typeof stream[i] === 'function') { + this[i] = function (method) { + return function () { + return stream[method].apply(stream, arguments); + }; + }(i); + } + } - if (placeHolders === 2) { - tmp = (decode(b64.charAt(i)) << 2) | (decode(b64.charAt(i + 1)) >> 4) - push(tmp & 0xFF) - } else if (placeHolders === 1) { - tmp = (decode(b64.charAt(i)) << 10) | (decode(b64.charAt(i + 1)) << 4) | (decode(b64.charAt(i + 2)) >> 2) - push((tmp >> 8) & 0xFF) - push(tmp & 0xFF) - } + // proxy certain important events. + var events = ['error', 'close', 'destroy', 'pause', 'resume']; + forEach(events, function (ev) { + stream.on(ev, self.emit.bind(self, ev)); + }); - return arr - } + // when we try to consume some more bytes, simply unpause the + // underlying stream. + self._read = function (n) { + debug('wrapped _read', n); + if (paused) { + paused = false; + stream.resume(); + } + }; - function uint8ToBase64 (uint8) { - var i, - extraBytes = uint8.length % 3, // if we have 1 byte left, pad 2 bytes - output = "", - temp, length + return self; + }; - function encode (num) { - return lookup.charAt(num) - } + // exposed for testing purposes only. + Readable._fromList = fromList; - function tripletToBase64 (num) { - return encode(num >> 18 & 0x3F) + encode(num >> 12 & 0x3F) + encode(num >> 6 & 0x3F) + encode(num & 0x3F) - } + // Pluck off n bytes from an array of buffers. + // Length is the combined lengths of all the buffers in the list. + // This function is designed to be inlinable, so please take care when making + // changes to the function body. + function fromList(n, state) { + // nothing buffered + if (state.length === 0) return null; - // go through the array every three bytes, we'll deal with trailing stuff later - for (i = 0, length = uint8.length - extraBytes; i < length; i += 3) { - temp = (uint8[i] << 16) + (uint8[i + 1] << 8) + (uint8[i + 2]) - output += tripletToBase64(temp) - } + var ret; + if (state.objectMode) ret = state.buffer.shift();else if (!n || n >= state.length) { + // read it all, truncate the list + if (state.decoder) ret = state.buffer.join('');else if (state.buffer.length === 1) ret = state.buffer.head.data;else ret = state.buffer.concat(state.length); + state.buffer.clear(); + } else { + // read part of list + ret = fromListPartial(n, state.buffer, state.decoder); + } - // pad the end with zeros, but make sure to not forget the extra bytes - switch (extraBytes) { - case 1: - temp = uint8[uint8.length - 1] - output += encode(temp >> 2) - output += encode((temp << 4) & 0x3F) - output += '==' - break - case 2: - temp = (uint8[uint8.length - 2] << 8) + (uint8[uint8.length - 1]) - output += encode(temp >> 10) - output += encode((temp >> 4) & 0x3F) - output += encode((temp << 2) & 0x3F) - output += '=' - break - } + return ret; + } - return output - } + // Extracts only enough buffered data to satisfy the amount requested. + // This function is designed to be inlinable, so please take care when making + // changes to the function body. + function fromListPartial(n, list, hasStrings) { + var ret; + if (n < list.head.data.length) { + // slice is the same for buffers and strings + ret = list.head.data.slice(0, n); + list.head.data = list.head.data.slice(n); + } else if (n === list.head.data.length) { + // first chunk is a perfect match + ret = list.shift(); + } else { + // result spans more than one buffer + ret = hasStrings ? copyFromBufferString(n, list) : copyFromBuffer(n, list); + } + return ret; + } - exports.toByteArray = b64ToByteArray - exports.fromByteArray = uint8ToBase64 - }( false ? (this.base64js = {}) : exports)) + // Copies a specified amount of characters from the list of buffered data + // chunks. + // This function is designed to be inlinable, so please take care when making + // changes to the function body. + function copyFromBufferString(n, list) { + var p = list.head; + var c = 1; + var ret = p.data; + n -= ret.length; + while (p = p.next) { + var str = p.data; + var nb = n > str.length ? str.length : n; + if (nb === str.length) ret += str;else ret += str.slice(0, n); + n -= nb; + if (n === 0) { + if (nb === str.length) { + ++c; + if (p.next) list.head = p.next;else list.head = list.tail = null; + } else { + list.head = p; + p.data = str.slice(nb); + } + break; + } + ++c; + } + list.length -= c; + return ret; + } + // Copies a specified amount of bytes from the list of buffered data chunks. + // This function is designed to be inlinable, so please take care when making + // changes to the function body. + function copyFromBuffer(n, list) { + var ret = bufferShim.allocUnsafe(n); + var p = list.head; + var c = 1; + p.data.copy(ret); + n -= p.data.length; + while (p = p.next) { + var buf = p.data; + var nb = n > buf.length ? buf.length : n; + buf.copy(ret, ret.length - n, 0, nb); + n -= nb; + if (n === 0) { + if (nb === buf.length) { + ++c; + if (p.next) list.head = p.next;else list.head = list.tail = null; + } else { + list.head = p; + p.data = buf.slice(nb); + } + break; + } + ++c; + } + list.length -= c; + return ret; + } -/***/ }, -/* 57 */ -/***/ function(module, exports) { + function endReadable(stream) { + var state = stream._readableState; - exports.read = function (buffer, offset, isLE, mLen, nBytes) { - var e, m - var eLen = nBytes * 8 - mLen - 1 - var eMax = (1 << eLen) - 1 - var eBias = eMax >> 1 - var nBits = -7 - var i = isLE ? (nBytes - 1) : 0 - var d = isLE ? -1 : 1 - var s = buffer[offset + i] + // If we get here before consuming all the bytes, then that is a + // bug in node. Should never happen. + if (state.length > 0) throw new Error('"endReadable()" called on non-empty stream'); - i += d + if (!state.endEmitted) { + state.ended = true; + processNextTick(endReadableNT, state, stream); + } + } - e = s & ((1 << (-nBits)) - 1) - s >>= (-nBits) - nBits += eLen - for (; nBits > 0; e = e * 256 + buffer[offset + i], i += d, nBits -= 8) {} + function endReadableNT(state, stream) { + // Check that we didn't get one last unshift. + if (!state.endEmitted && state.length === 0) { + state.endEmitted = true; + stream.readable = false; + stream.emit('end'); + } + } - m = e & ((1 << (-nBits)) - 1) - e >>= (-nBits) - nBits += mLen - for (; nBits > 0; m = m * 256 + buffer[offset + i], i += d, nBits -= 8) {} + function forEach(xs, f) { + for (var i = 0, l = xs.length; i < l; i++) { + f(xs[i], i); + } + } - if (e === 0) { - e = 1 - eBias - } else if (e === eMax) { - return m ? NaN : ((s ? -1 : 1) * Infinity) - } else { - m = m + Math.pow(2, mLen) - e = e - eBias + function indexOf(xs, x) { + for (var i = 0, l = xs.length; i < l; i++) { + if (xs[i] === x) return i; } - return (s ? -1 : 1) * m * Math.pow(2, e - mLen) + return -1; } + /* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(10))) - exports.write = function (buffer, value, offset, isLE, mLen, nBytes) { - var e, m, c - var eLen = nBytes * 8 - mLen - 1 - var eMax = (1 << eLen) - 1 - var eBias = eMax >> 1 - var rt = (mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0) - var i = isLE ? 0 : (nBytes - 1) - var d = isLE ? 1 : -1 - var s = value < 0 || (value === 0 && 1 / value < 0) ? 1 : 0 +/***/ }, +/* 54 */ +/***/ function(module, exports, __webpack_require__) { - value = Math.abs(value) + /* WEBPACK VAR INJECTION */(function(process) {'use strict'; - if (isNaN(value) || value === Infinity) { - m = isNaN(value) ? 1 : 0 - e = eMax - } else { - e = Math.floor(Math.log(value) / Math.LN2) - if (value * (c = Math.pow(2, -e)) < 1) { - e-- - c *= 2 - } - if (e + eBias >= 1) { - value += rt / c - } else { - value += rt * Math.pow(2, 1 - eBias) - } - if (value * c >= 2) { - e++ - c /= 2 - } + if (!process.version || + process.version.indexOf('v0.') === 0 || + process.version.indexOf('v1.') === 0 && process.version.indexOf('v1.8.') !== 0) { + module.exports = nextTick; + } else { + module.exports = process.nextTick; + } - if (e + eBias >= eMax) { - m = 0 - e = eMax - } else if (e + eBias >= 1) { - m = (value * c - 1) * Math.pow(2, mLen) - e = e + eBias - } else { - m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen) - e = 0 + function nextTick(fn, arg1, arg2, arg3) { + if (typeof fn !== 'function') { + throw new TypeError('"callback" argument must be a function'); + } + var len = arguments.length; + var args, i; + switch (len) { + case 0: + case 1: + return process.nextTick(fn); + case 2: + return process.nextTick(function afterTickOne() { + fn.call(null, arg1); + }); + case 3: + return process.nextTick(function afterTickTwo() { + fn.call(null, arg1, arg2); + }); + case 4: + return process.nextTick(function afterTickThree() { + fn.call(null, arg1, arg2, arg3); + }); + default: + args = new Array(len - 1); + i = 0; + while (i < args.length) { + args[i++] = arguments[i]; } + return process.nextTick(function afterTick() { + fn.apply(null, args); + }); } - - for (; mLen >= 8; buffer[offset + i] = m & 0xff, i += d, m /= 256, mLen -= 8) {} - - e = (e << mLen) | m - eLen += mLen - for (; eLen > 0; buffer[offset + i] = e & 0xff, i += d, e /= 256, eLen -= 8) {} - - buffer[offset + i - d] |= s * 128 } + /* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(10))) /***/ }, -/* 58 */ +/* 55 */ /***/ function(module, exports) { var toString = {}.toString; @@ -15100,1682 +13473,2159 @@ var qtk = /***/ }, -/* 59 */ +/* 56 */ /***/ function(module, exports, __webpack_require__) { - /* WEBPACK VAR INJECTION */(function(Buffer) {// Copyright Joyent, Inc. and other Node contributors. - // - // Permission is hereby granted, free of charge, to any person obtaining a - // copy of this software and associated documentation files (the - // "Software"), to deal in the Software without restriction, including - // without limitation the rights to use, copy, modify, merge, publish, - // distribute, sublicense, and/or sell copies of the Software, and to permit - // persons to whom the Software is furnished to do so, subject to the - // following conditions: - // - // The above copyright notice and this permission notice shall be included - // in all copies or substantial portions of the Software. - // - // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN - // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, - // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR - // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE - // USE OR OTHER DEALINGS IN THE SOFTWARE. + /* WEBPACK VAR INJECTION */(function(global) {/*! + * The buffer module from node.js, for the browser. + * + * @author Feross Aboukhadijeh + * @license MIT + */ + /* eslint-disable no-proto */ + + 'use strict' + + var base64 = __webpack_require__(57) + var ieee754 = __webpack_require__(58) + var isArray = __webpack_require__(55) + + exports.Buffer = Buffer + exports.SlowBuffer = SlowBuffer + exports.INSPECT_MAX_BYTES = 50 + + /** + * If `Buffer.TYPED_ARRAY_SUPPORT`: + * === true Use Uint8Array implementation (fastest) + * === false Use Object implementation (most compatible, even IE6) + * + * Browsers that support typed arrays are IE 10+, Firefox 4+, Chrome 7+, Safari 5.1+, + * Opera 11.6+, iOS 4.2+. + * + * Due to various browser bugs, sometimes the Object implementation will be used even + * when the browser supports typed arrays. + * + * Note: + * + * - Firefox 4-29 lacks support for adding new properties to `Uint8Array` instances, + * See: https://bugzilla.mozilla.org/show_bug.cgi?id=695438. + * + * - Chrome 9-10 is missing the `TypedArray.prototype.subarray` function. + * + * - IE10 has a broken `TypedArray.prototype.subarray` function which returns arrays of + * incorrect length in some situations. - // NOTE: These type checking functions intentionally don't use `instanceof` - // because it is fragile and can be easily faked with `Object.create()`. + * We detect these buggy browsers and set `Buffer.TYPED_ARRAY_SUPPORT` to `false` so they + * get the Object implementation, which is slower but behaves correctly. + */ + Buffer.TYPED_ARRAY_SUPPORT = global.TYPED_ARRAY_SUPPORT !== undefined + ? global.TYPED_ARRAY_SUPPORT + : typedArraySupport() - function isArray(arg) { - if (Array.isArray) { - return Array.isArray(arg); + /* + * Export kMaxLength after typed array support is determined. + */ + exports.kMaxLength = kMaxLength() + + function typedArraySupport () { + try { + var arr = new Uint8Array(1) + arr.__proto__ = {__proto__: Uint8Array.prototype, foo: function () { return 42 }} + return arr.foo() === 42 && // typed array instances can be augmented + typeof arr.subarray === 'function' && // chrome 9-10 lack `subarray` + arr.subarray(1, 1).byteLength === 0 // ie10 has broken `subarray` + } catch (e) { + return false } - return objectToString(arg) === '[object Array]'; } - exports.isArray = isArray; - function isBoolean(arg) { - return typeof arg === 'boolean'; + function kMaxLength () { + return Buffer.TYPED_ARRAY_SUPPORT + ? 0x7fffffff + : 0x3fffffff } - exports.isBoolean = isBoolean; - function isNull(arg) { - return arg === null; - } - exports.isNull = isNull; + function createBuffer (that, length) { + if (kMaxLength() < length) { + throw new RangeError('Invalid typed array length') + } + if (Buffer.TYPED_ARRAY_SUPPORT) { + // Return an augmented `Uint8Array` instance, for best performance + that = new Uint8Array(length) + that.__proto__ = Buffer.prototype + } else { + // Fallback: Return an object instance of the Buffer class + if (that === null) { + that = new Buffer(length) + } + that.length = length + } - function isNullOrUndefined(arg) { - return arg == null; + return that } - exports.isNullOrUndefined = isNullOrUndefined; - function isNumber(arg) { - return typeof arg === 'number'; - } - exports.isNumber = isNumber; + /** + * The Buffer constructor returns instances of `Uint8Array` that have their + * prototype changed to `Buffer.prototype`. Furthermore, `Buffer` is a subclass of + * `Uint8Array`, so the returned instances will have all the node `Buffer` methods + * and the `Uint8Array` methods. Square bracket notation works as expected -- it + * returns a single octet. + * + * The `Uint8Array` prototype remains unmodified. + */ - function isString(arg) { - return typeof arg === 'string'; - } - exports.isString = isString; + function Buffer (arg, encodingOrOffset, length) { + if (!Buffer.TYPED_ARRAY_SUPPORT && !(this instanceof Buffer)) { + return new Buffer(arg, encodingOrOffset, length) + } - function isSymbol(arg) { - return typeof arg === 'symbol'; + // Common case. + if (typeof arg === 'number') { + if (typeof encodingOrOffset === 'string') { + throw new Error( + 'If encoding is specified then the first argument must be a string' + ) + } + return allocUnsafe(this, arg) + } + return from(this, arg, encodingOrOffset, length) } - exports.isSymbol = isSymbol; - function isUndefined(arg) { - return arg === void 0; - } - exports.isUndefined = isUndefined; + Buffer.poolSize = 8192 // not used by this implementation - function isRegExp(re) { - return objectToString(re) === '[object RegExp]'; + // TODO: Legacy, not needed anymore. Remove in next major version. + Buffer._augment = function (arr) { + arr.__proto__ = Buffer.prototype + return arr } - exports.isRegExp = isRegExp; - function isObject(arg) { - return typeof arg === 'object' && arg !== null; - } - exports.isObject = isObject; + function from (that, value, encodingOrOffset, length) { + if (typeof value === 'number') { + throw new TypeError('"value" argument must not be a number') + } - function isDate(d) { - return objectToString(d) === '[object Date]'; + if (typeof ArrayBuffer !== 'undefined' && value instanceof ArrayBuffer) { + return fromArrayBuffer(that, value, encodingOrOffset, length) + } + + if (typeof value === 'string') { + return fromString(that, value, encodingOrOffset) + } + + return fromObject(that, value) } - exports.isDate = isDate; - function isError(e) { - return (objectToString(e) === '[object Error]' || e instanceof Error); + /** + * Functionally equivalent to Buffer(arg, encoding) but throws a TypeError + * if value is a number. + * Buffer.from(str[, encoding]) + * Buffer.from(array) + * Buffer.from(buffer) + * Buffer.from(arrayBuffer[, byteOffset[, length]]) + **/ + Buffer.from = function (value, encodingOrOffset, length) { + return from(null, value, encodingOrOffset, length) } - exports.isError = isError; - function isFunction(arg) { - return typeof arg === 'function'; + if (Buffer.TYPED_ARRAY_SUPPORT) { + Buffer.prototype.__proto__ = Uint8Array.prototype + Buffer.__proto__ = Uint8Array + if (typeof Symbol !== 'undefined' && Symbol.species && + Buffer[Symbol.species] === Buffer) { + // Fix subarray() in ES2016. See: https://github.com/feross/buffer/pull/97 + Object.defineProperty(Buffer, Symbol.species, { + value: null, + configurable: true + }) + } } - exports.isFunction = isFunction; - function isPrimitive(arg) { - return arg === null || - typeof arg === 'boolean' || - typeof arg === 'number' || - typeof arg === 'string' || - typeof arg === 'symbol' || // ES6 symbol - typeof arg === 'undefined'; + function assertSize (size) { + if (typeof size !== 'number') { + throw new TypeError('"size" argument must be a number') + } else if (size < 0) { + throw new RangeError('"size" argument must not be negative') + } } - exports.isPrimitive = isPrimitive; - exports.isBuffer = Buffer.isBuffer; + function alloc (that, size, fill, encoding) { + assertSize(size) + if (size <= 0) { + return createBuffer(that, size) + } + if (fill !== undefined) { + // Only pay attention to encoding if it's a string. This + // prevents accidentally sending in a number that would + // be interpretted as a start offset. + return typeof encoding === 'string' + ? createBuffer(that, size).fill(fill, encoding) + : createBuffer(that, size).fill(fill) + } + return createBuffer(that, size) + } - function objectToString(o) { - return Object.prototype.toString.call(o); + /** + * Creates a new filled Buffer instance. + * alloc(size[, fill[, encoding]]) + **/ + Buffer.alloc = function (size, fill, encoding) { + return alloc(null, size, fill, encoding) } - /* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(55).Buffer)) + function allocUnsafe (that, size) { + assertSize(size) + that = createBuffer(that, size < 0 ? 0 : checked(size) | 0) + if (!Buffer.TYPED_ARRAY_SUPPORT) { + for (var i = 0; i < size; ++i) { + that[i] = 0 + } + } + return that + } -/***/ }, -/* 60 */ -/***/ function(module, exports) { + /** + * Equivalent to Buffer(num), by default creates a non-zero-filled Buffer instance. + * */ + Buffer.allocUnsafe = function (size) { + return allocUnsafe(null, size) + } + /** + * Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance. + */ + Buffer.allocUnsafeSlow = function (size) { + return allocUnsafe(null, size) + } - /* (ignored) */ + function fromString (that, string, encoding) { + if (typeof encoding !== 'string' || encoding === '') { + encoding = 'utf8' + } -/***/ }, -/* 61 */ -/***/ function(module, exports, __webpack_require__) { + if (!Buffer.isEncoding(encoding)) { + throw new TypeError('"encoding" must be a valid string encoding') + } - /* WEBPACK VAR INJECTION */(function(process) {// Copyright Joyent, Inc. and other Node contributors. - // - // Permission is hereby granted, free of charge, to any person obtaining a - // copy of this software and associated documentation files (the - // "Software"), to deal in the Software without restriction, including - // without limitation the rights to use, copy, modify, merge, publish, - // distribute, sublicense, and/or sell copies of the Software, and to permit - // persons to whom the Software is furnished to do so, subject to the - // following conditions: - // - // The above copyright notice and this permission notice shall be included - // in all copies or substantial portions of the Software. - // - // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN - // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, - // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR - // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE - // USE OR OTHER DEALINGS IN THE SOFTWARE. + var length = byteLength(string, encoding) | 0 + that = createBuffer(that, length) - // a duplex stream is just a stream that is both readable and writable. - // Since JS doesn't have multiple prototypal inheritance, this class - // prototypally inherits from Readable, and then parasitically from - // Writable. + var actual = that.write(string, encoding) - module.exports = Duplex; + if (actual !== length) { + // Writing a hex string, for example, that contains invalid characters will + // cause everything after the first invalid character to be ignored. (e.g. + // 'abxxcd' will be treated as 'ab') + that = that.slice(0, actual) + } - /**/ - var objectKeys = Object.keys || function (obj) { - var keys = []; - for (var key in obj) keys.push(key); - return keys; + return that } - /**/ - - /**/ - var util = __webpack_require__(59); - util.inherits = __webpack_require__(51); - /**/ - - var Readable = __webpack_require__(53); - var Writable = __webpack_require__(62); - - util.inherits(Duplex, Readable); - - forEach(objectKeys(Writable.prototype), function(method) { - if (!Duplex.prototype[method]) - Duplex.prototype[method] = Writable.prototype[method]; - }); - - function Duplex(options) { - if (!(this instanceof Duplex)) - return new Duplex(options); + function fromArrayLike (that, array) { + var length = array.length < 0 ? 0 : checked(array.length) | 0 + that = createBuffer(that, length) + for (var i = 0; i < length; i += 1) { + that[i] = array[i] & 255 + } + return that + } - Readable.call(this, options); - Writable.call(this, options); + function fromArrayBuffer (that, array, byteOffset, length) { + array.byteLength // this throws if `array` is not a valid ArrayBuffer - if (options && options.readable === false) - this.readable = false; + if (byteOffset < 0 || array.byteLength < byteOffset) { + throw new RangeError('\'offset\' is out of bounds') + } - if (options && options.writable === false) - this.writable = false; + if (array.byteLength < byteOffset + (length || 0)) { + throw new RangeError('\'length\' is out of bounds') + } - this.allowHalfOpen = true; - if (options && options.allowHalfOpen === false) - this.allowHalfOpen = false; + if (byteOffset === undefined && length === undefined) { + array = new Uint8Array(array) + } else if (length === undefined) { + array = new Uint8Array(array, byteOffset) + } else { + array = new Uint8Array(array, byteOffset, length) + } - this.once('end', onend); + if (Buffer.TYPED_ARRAY_SUPPORT) { + // Return an augmented `Uint8Array` instance, for best performance + that = array + that.__proto__ = Buffer.prototype + } else { + // Fallback: Return an object instance of the Buffer class + that = fromArrayLike(that, array) + } + return that } - // the no-half-open enforcer - function onend() { - // if we allow half-open state, or if the writable side ended, - // then we're ok. - if (this.allowHalfOpen || this._writableState.ended) - return; + function fromObject (that, obj) { + if (Buffer.isBuffer(obj)) { + var len = checked(obj.length) | 0 + that = createBuffer(that, len) - // no more data can be written. - // But allow more writes to happen in this tick. - process.nextTick(this.end.bind(this)); - } + if (that.length === 0) { + return that + } - function forEach (xs, f) { - for (var i = 0, l = xs.length; i < l; i++) { - f(xs[i], i); + obj.copy(that, 0, 0, len) + return that } - } - /* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(10))) + if (obj) { + if ((typeof ArrayBuffer !== 'undefined' && + obj.buffer instanceof ArrayBuffer) || 'length' in obj) { + if (typeof obj.length !== 'number' || isnan(obj.length)) { + return createBuffer(that, 0) + } + return fromArrayLike(that, obj) + } -/***/ }, -/* 62 */ -/***/ function(module, exports, __webpack_require__) { + if (obj.type === 'Buffer' && isArray(obj.data)) { + return fromArrayLike(that, obj.data) + } + } - /* WEBPACK VAR INJECTION */(function(process) {// Copyright Joyent, Inc. and other Node contributors. - // - // Permission is hereby granted, free of charge, to any person obtaining a - // copy of this software and associated documentation files (the - // "Software"), to deal in the Software without restriction, including - // without limitation the rights to use, copy, modify, merge, publish, - // distribute, sublicense, and/or sell copies of the Software, and to permit - // persons to whom the Software is furnished to do so, subject to the - // following conditions: - // - // The above copyright notice and this permission notice shall be included - // in all copies or substantial portions of the Software. - // - // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN - // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, - // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR - // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE - // USE OR OTHER DEALINGS IN THE SOFTWARE. + throw new TypeError('First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object.') + } - // A bit simpler than readable streams. - // Implement an async ._write(chunk, cb), and it'll handle all - // the drain event emission and buffering. + function checked (length) { + // Note: cannot use `length < kMaxLength()` here because that fails when + // length is NaN (which is otherwise coerced to zero.) + if (length >= kMaxLength()) { + throw new RangeError('Attempt to allocate Buffer larger than maximum ' + + 'size: 0x' + kMaxLength().toString(16) + ' bytes') + } + return length | 0 + } - module.exports = Writable; + function SlowBuffer (length) { + if (+length != length) { // eslint-disable-line eqeqeq + length = 0 + } + return Buffer.alloc(+length) + } - /**/ - var Buffer = __webpack_require__(55).Buffer; - /**/ + Buffer.isBuffer = function isBuffer (b) { + return !!(b != null && b._isBuffer) + } - Writable.WritableState = WritableState; + Buffer.compare = function compare (a, b) { + if (!Buffer.isBuffer(a) || !Buffer.isBuffer(b)) { + throw new TypeError('Arguments must be Buffers') + } + if (a === b) return 0 - /**/ - var util = __webpack_require__(59); - util.inherits = __webpack_require__(51); - /**/ + var x = a.length + var y = b.length - var Stream = __webpack_require__(49); + for (var i = 0, len = Math.min(x, y); i < len; ++i) { + if (a[i] !== b[i]) { + x = a[i] + y = b[i] + break + } + } - util.inherits(Writable, Stream); + if (x < y) return -1 + if (y < x) return 1 + return 0 + } - function WriteReq(chunk, encoding, cb) { - this.chunk = chunk; - this.encoding = encoding; - this.callback = cb; + Buffer.isEncoding = function isEncoding (encoding) { + switch (String(encoding).toLowerCase()) { + case 'hex': + case 'utf8': + case 'utf-8': + case 'ascii': + case 'latin1': + case 'binary': + case 'base64': + case 'ucs2': + case 'ucs-2': + case 'utf16le': + case 'utf-16le': + return true + default: + return false + } } - function WritableState(options, stream) { - var Duplex = __webpack_require__(61); + Buffer.concat = function concat (list, length) { + if (!isArray(list)) { + throw new TypeError('"list" argument must be an Array of Buffers') + } - options = options || {}; + if (list.length === 0) { + return Buffer.alloc(0) + } - // the point at which write() starts returning false - // Note: 0 is a valid value, means that we always return false if - // the entire buffer is not flushed immediately on write() - var hwm = options.highWaterMark; - var defaultHwm = options.objectMode ? 16 : 16 * 1024; - this.highWaterMark = (hwm || hwm === 0) ? hwm : defaultHwm; + var i + if (length === undefined) { + length = 0 + for (i = 0; i < list.length; ++i) { + length += list[i].length + } + } - // object stream flag to indicate whether or not this stream - // contains buffers or objects. - this.objectMode = !!options.objectMode; + var buffer = Buffer.allocUnsafe(length) + var pos = 0 + for (i = 0; i < list.length; ++i) { + var buf = list[i] + if (!Buffer.isBuffer(buf)) { + throw new TypeError('"list" argument must be an Array of Buffers') + } + buf.copy(buffer, pos) + pos += buf.length + } + return buffer + } - if (stream instanceof Duplex) - this.objectMode = this.objectMode || !!options.writableObjectMode; + function byteLength (string, encoding) { + if (Buffer.isBuffer(string)) { + return string.length + } + if (typeof ArrayBuffer !== 'undefined' && typeof ArrayBuffer.isView === 'function' && + (ArrayBuffer.isView(string) || string instanceof ArrayBuffer)) { + return string.byteLength + } + if (typeof string !== 'string') { + string = '' + string + } - // cast to ints. - this.highWaterMark = ~~this.highWaterMark; + var len = string.length + if (len === 0) return 0 - this.needDrain = false; - // at the start of calling end() - this.ending = false; - // when end() has been called, and returned - this.ended = false; - // when 'finish' is emitted - this.finished = false; + // Use a for loop to avoid recursion + var loweredCase = false + for (;;) { + switch (encoding) { + case 'ascii': + case 'latin1': + case 'binary': + return len + case 'utf8': + case 'utf-8': + case undefined: + return utf8ToBytes(string).length + case 'ucs2': + case 'ucs-2': + case 'utf16le': + case 'utf-16le': + return len * 2 + case 'hex': + return len >>> 1 + case 'base64': + return base64ToBytes(string).length + default: + if (loweredCase) return utf8ToBytes(string).length // assume utf8 + encoding = ('' + encoding).toLowerCase() + loweredCase = true + } + } + } + Buffer.byteLength = byteLength - // should we decode strings into buffers before passing to _write? - // this is here so that some node-core streams can optimize string - // handling at a lower level. - var noDecode = options.decodeStrings === false; - this.decodeStrings = !noDecode; + function slowToString (encoding, start, end) { + var loweredCase = false - // Crypto is kind of old and crusty. Historically, its default string - // encoding is 'binary' so we have to make this configurable. - // Everything else in the universe uses 'utf8', though. - this.defaultEncoding = options.defaultEncoding || 'utf8'; + // No need to verify that "this.length <= MAX_UINT32" since it's a read-only + // property of a typed array. - // not an actual buffer we keep track of, but a measurement - // of how much we're waiting to get pushed to some underlying - // socket or file. - this.length = 0; + // This behaves neither like String nor Uint8Array in that we set start/end + // to their upper/lower bounds if the value passed is out of range. + // undefined is handled specially as per ECMA-262 6th Edition, + // Section 13.3.3.7 Runtime Semantics: KeyedBindingInitialization. + if (start === undefined || start < 0) { + start = 0 + } + // Return early if start > this.length. Done here to prevent potential uint32 + // coercion fail below. + if (start > this.length) { + return '' + } - // a flag to see when we're in the middle of a write. - this.writing = false; + if (end === undefined || end > this.length) { + end = this.length + } - // when true all writes will be buffered until .uncork() call - this.corked = 0; + if (end <= 0) { + return '' + } - // a flag to be able to tell if the onwrite cb is called immediately, - // or on a later tick. We set this to true at first, because any - // actions that shouldn't happen until "later" should generally also - // not happen before the first write call. - this.sync = true; + // Force coersion to uint32. This will also coerce falsey/NaN values to 0. + end >>>= 0 + start >>>= 0 - // a flag to know if we're processing previously buffered items, which - // may call the _write() callback in the same tick, so that we don't - // end up in an overlapped onwrite situation. - this.bufferProcessing = false; + if (end <= start) { + return '' + } - // the callback that's passed to _write(chunk,cb) - this.onwrite = function(er) { - onwrite(stream, er); - }; + if (!encoding) encoding = 'utf8' - // the callback that the user supplies to write(chunk,encoding,cb) - this.writecb = null; + while (true) { + switch (encoding) { + case 'hex': + return hexSlice(this, start, end) - // the amount that is being written when _write is called. - this.writelen = 0; + case 'utf8': + case 'utf-8': + return utf8Slice(this, start, end) - this.buffer = []; + case 'ascii': + return asciiSlice(this, start, end) - // number of pending user-supplied write callbacks - // this must be 0 before 'finish' can be emitted - this.pendingcb = 0; + case 'latin1': + case 'binary': + return latin1Slice(this, start, end) - // emit prefinish if the only thing we're waiting for is _write cbs - // This is relevant for synchronous Transform streams - this.prefinished = false; + case 'base64': + return base64Slice(this, start, end) - // True if the error was already emitted and should not be thrown again - this.errorEmitted = false; + case 'ucs2': + case 'ucs-2': + case 'utf16le': + case 'utf-16le': + return utf16leSlice(this, start, end) + + default: + if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding) + encoding = (encoding + '').toLowerCase() + loweredCase = true + } + } } - function Writable(options) { - var Duplex = __webpack_require__(61); + // The property is used by `Buffer.isBuffer` and `is-buffer` (in Safari 5-7) to detect + // Buffer instances. + Buffer.prototype._isBuffer = true - // Writable ctor is applied to Duplexes, though they're not - // instanceof Writable, they're instanceof Readable. - if (!(this instanceof Writable) && !(this instanceof Duplex)) - return new Writable(options); + function swap (b, n, m) { + var i = b[n] + b[n] = b[m] + b[m] = i + } - this._writableState = new WritableState(options, this); + Buffer.prototype.swap16 = function swap16 () { + var len = this.length + if (len % 2 !== 0) { + throw new RangeError('Buffer size must be a multiple of 16-bits') + } + for (var i = 0; i < len; i += 2) { + swap(this, i, i + 1) + } + return this + } - // legacy. - this.writable = true; + Buffer.prototype.swap32 = function swap32 () { + var len = this.length + if (len % 4 !== 0) { + throw new RangeError('Buffer size must be a multiple of 32-bits') + } + for (var i = 0; i < len; i += 4) { + swap(this, i, i + 3) + swap(this, i + 1, i + 2) + } + return this + } - Stream.call(this); + Buffer.prototype.swap64 = function swap64 () { + var len = this.length + if (len % 8 !== 0) { + throw new RangeError('Buffer size must be a multiple of 64-bits') + } + for (var i = 0; i < len; i += 8) { + swap(this, i, i + 7) + swap(this, i + 1, i + 6) + swap(this, i + 2, i + 5) + swap(this, i + 3, i + 4) + } + return this } - // Otherwise people can pipe Writable streams, which is just wrong. - Writable.prototype.pipe = function() { - this.emit('error', new Error('Cannot pipe. Not readable.')); - }; + Buffer.prototype.toString = function toString () { + var length = this.length | 0 + if (length === 0) return '' + if (arguments.length === 0) return utf8Slice(this, 0, length) + return slowToString.apply(this, arguments) + } + Buffer.prototype.equals = function equals (b) { + if (!Buffer.isBuffer(b)) throw new TypeError('Argument must be a Buffer') + if (this === b) return true + return Buffer.compare(this, b) === 0 + } - function writeAfterEnd(stream, state, cb) { - var er = new Error('write after end'); - // TODO: defer error events consistently everywhere, not just the cb - stream.emit('error', er); - process.nextTick(function() { - cb(er); - }); + Buffer.prototype.inspect = function inspect () { + var str = '' + var max = exports.INSPECT_MAX_BYTES + if (this.length > 0) { + str = this.toString('hex', 0, max).match(/.{2}/g).join(' ') + if (this.length > max) str += ' ... ' + } + return '' } - // If we get something that is not a buffer, string, null, or undefined, - // and we're not in objectMode, then that's an error. - // Otherwise stream chunks are all considered to be of length=1, and the - // watermarks determine how many objects to keep in the buffer, rather than - // how many bytes or characters. - function validChunk(stream, state, chunk, cb) { - var valid = true; - if (!util.isBuffer(chunk) && - !util.isString(chunk) && - !util.isNullOrUndefined(chunk) && - !state.objectMode) { - var er = new TypeError('Invalid non-string/buffer chunk'); - stream.emit('error', er); - process.nextTick(function() { - cb(er); - }); - valid = false; + Buffer.prototype.compare = function compare (target, start, end, thisStart, thisEnd) { + if (!Buffer.isBuffer(target)) { + throw new TypeError('Argument must be a Buffer') + } + + if (start === undefined) { + start = 0 + } + if (end === undefined) { + end = target ? target.length : 0 + } + if (thisStart === undefined) { + thisStart = 0 + } + if (thisEnd === undefined) { + thisEnd = this.length + } + + if (start < 0 || end > target.length || thisStart < 0 || thisEnd > this.length) { + throw new RangeError('out of range index') + } + + if (thisStart >= thisEnd && start >= end) { + return 0 + } + if (thisStart >= thisEnd) { + return -1 + } + if (start >= end) { + return 1 + } + + start >>>= 0 + end >>>= 0 + thisStart >>>= 0 + thisEnd >>>= 0 + + if (this === target) return 0 + + var x = thisEnd - thisStart + var y = end - start + var len = Math.min(x, y) + + var thisCopy = this.slice(thisStart, thisEnd) + var targetCopy = target.slice(start, end) + + for (var i = 0; i < len; ++i) { + if (thisCopy[i] !== targetCopy[i]) { + x = thisCopy[i] + y = targetCopy[i] + break + } } - return valid; + + if (x < y) return -1 + if (y < x) return 1 + return 0 } - Writable.prototype.write = function(chunk, encoding, cb) { - var state = this._writableState; - var ret = false; + // Finds either the first index of `val` in `buffer` at offset >= `byteOffset`, + // OR the last index of `val` in `buffer` at offset <= `byteOffset`. + // + // Arguments: + // - buffer - a Buffer to search + // - val - a string, Buffer, or number + // - byteOffset - an index into `buffer`; will be clamped to an int32 + // - encoding - an optional encoding, relevant is val is a string + // - dir - true for indexOf, false for lastIndexOf + function bidirectionalIndexOf (buffer, val, byteOffset, encoding, dir) { + // Empty buffer means no match + if (buffer.length === 0) return -1 + + // Normalize byteOffset + if (typeof byteOffset === 'string') { + encoding = byteOffset + byteOffset = 0 + } else if (byteOffset > 0x7fffffff) { + byteOffset = 0x7fffffff + } else if (byteOffset < -0x80000000) { + byteOffset = -0x80000000 + } + byteOffset = +byteOffset // Coerce to Number. + if (isNaN(byteOffset)) { + // byteOffset: it it's undefined, null, NaN, "foo", etc, search whole buffer + byteOffset = dir ? 0 : (buffer.length - 1) + } + + // Normalize byteOffset: negative offsets start from the end of the buffer + if (byteOffset < 0) byteOffset = buffer.length + byteOffset + if (byteOffset >= buffer.length) { + if (dir) return -1 + else byteOffset = buffer.length - 1 + } else if (byteOffset < 0) { + if (dir) byteOffset = 0 + else return -1 + } + + // Normalize val + if (typeof val === 'string') { + val = Buffer.from(val, encoding) + } - if (util.isFunction(encoding)) { - cb = encoding; - encoding = null; + // Finally, search either indexOf (if dir is true) or lastIndexOf + if (Buffer.isBuffer(val)) { + // Special case: looking for empty string/buffer always fails + if (val.length === 0) { + return -1 + } + return arrayIndexOf(buffer, val, byteOffset, encoding, dir) + } else if (typeof val === 'number') { + val = val & 0xFF // Search for a byte value [0-255] + if (Buffer.TYPED_ARRAY_SUPPORT && + typeof Uint8Array.prototype.indexOf === 'function') { + if (dir) { + return Uint8Array.prototype.indexOf.call(buffer, val, byteOffset) + } else { + return Uint8Array.prototype.lastIndexOf.call(buffer, val, byteOffset) + } + } + return arrayIndexOf(buffer, [ val ], byteOffset, encoding, dir) } - if (util.isBuffer(chunk)) - encoding = 'buffer'; - else if (!encoding) - encoding = state.defaultEncoding; + throw new TypeError('val must be string, number or Buffer') + } - if (!util.isFunction(cb)) - cb = function() {}; + function arrayIndexOf (arr, val, byteOffset, encoding, dir) { + var indexSize = 1 + var arrLength = arr.length + var valLength = val.length - if (state.ended) - writeAfterEnd(this, state, cb); - else if (validChunk(this, state, chunk, cb)) { - state.pendingcb++; - ret = writeOrBuffer(this, state, chunk, encoding, cb); + if (encoding !== undefined) { + encoding = String(encoding).toLowerCase() + if (encoding === 'ucs2' || encoding === 'ucs-2' || + encoding === 'utf16le' || encoding === 'utf-16le') { + if (arr.length < 2 || val.length < 2) { + return -1 + } + indexSize = 2 + arrLength /= 2 + valLength /= 2 + byteOffset /= 2 + } } - return ret; - }; + function read (buf, i) { + if (indexSize === 1) { + return buf[i] + } else { + return buf.readUInt16BE(i * indexSize) + } + } - Writable.prototype.cork = function() { - var state = this._writableState; + var i + if (dir) { + var foundIndex = -1 + for (i = byteOffset; i < arrLength; i++) { + if (read(arr, i) === read(val, foundIndex === -1 ? 0 : i - foundIndex)) { + if (foundIndex === -1) foundIndex = i + if (i - foundIndex + 1 === valLength) return foundIndex * indexSize + } else { + if (foundIndex !== -1) i -= i - foundIndex + foundIndex = -1 + } + } + } else { + if (byteOffset + valLength > arrLength) byteOffset = arrLength - valLength + for (i = byteOffset; i >= 0; i--) { + var found = true + for (var j = 0; j < valLength; j++) { + if (read(arr, i + j) !== read(val, j)) { + found = false + break + } + } + if (found) return i + } + } - state.corked++; - }; + return -1 + } - Writable.prototype.uncork = function() { - var state = this._writableState; + Buffer.prototype.includes = function includes (val, byteOffset, encoding) { + return this.indexOf(val, byteOffset, encoding) !== -1 + } - if (state.corked) { - state.corked--; + Buffer.prototype.indexOf = function indexOf (val, byteOffset, encoding) { + return bidirectionalIndexOf(this, val, byteOffset, encoding, true) + } + + Buffer.prototype.lastIndexOf = function lastIndexOf (val, byteOffset, encoding) { + return bidirectionalIndexOf(this, val, byteOffset, encoding, false) + } - if (!state.writing && - !state.corked && - !state.finished && - !state.bufferProcessing && - state.buffer.length) - clearBuffer(this, state); + function hexWrite (buf, string, offset, length) { + offset = Number(offset) || 0 + var remaining = buf.length - offset + if (!length) { + length = remaining + } else { + length = Number(length) + if (length > remaining) { + length = remaining + } } - }; - function decodeChunk(state, chunk, encoding) { - if (!state.objectMode && - state.decodeStrings !== false && - util.isString(chunk)) { - chunk = new Buffer(chunk, encoding); + // must be an even number of digits + var strLen = string.length + if (strLen % 2 !== 0) throw new TypeError('Invalid hex string') + + if (length > strLen / 2) { + length = strLen / 2 } - return chunk; + for (var i = 0; i < length; ++i) { + var parsed = parseInt(string.substr(i * 2, 2), 16) + if (isNaN(parsed)) return i + buf[offset + i] = parsed + } + return i } - // if we're already writing something, then just put this - // in the queue, and wait our turn. Otherwise, call _write - // If we return false, then we need a drain event, so set that flag. - function writeOrBuffer(stream, state, chunk, encoding, cb) { - chunk = decodeChunk(state, chunk, encoding); - if (util.isBuffer(chunk)) - encoding = 'buffer'; - var len = state.objectMode ? 1 : chunk.length; - - state.length += len; + function utf8Write (buf, string, offset, length) { + return blitBuffer(utf8ToBytes(string, buf.length - offset), buf, offset, length) + } - var ret = state.length < state.highWaterMark; - // we must ensure that previous needDrain will not be reset to false. - if (!ret) - state.needDrain = true; + function asciiWrite (buf, string, offset, length) { + return blitBuffer(asciiToBytes(string), buf, offset, length) + } - if (state.writing || state.corked) - state.buffer.push(new WriteReq(chunk, encoding, cb)); - else - doWrite(stream, state, false, len, chunk, encoding, cb); + function latin1Write (buf, string, offset, length) { + return asciiWrite(buf, string, offset, length) + } - return ret; + function base64Write (buf, string, offset, length) { + return blitBuffer(base64ToBytes(string), buf, offset, length) } - function doWrite(stream, state, writev, len, chunk, encoding, cb) { - state.writelen = len; - state.writecb = cb; - state.writing = true; - state.sync = true; - if (writev) - stream._writev(chunk, state.onwrite); - else - stream._write(chunk, encoding, state.onwrite); - state.sync = false; + function ucs2Write (buf, string, offset, length) { + return blitBuffer(utf16leToBytes(string, buf.length - offset), buf, offset, length) } - function onwriteError(stream, state, sync, er, cb) { - if (sync) - process.nextTick(function() { - state.pendingcb--; - cb(er); - }); - else { - state.pendingcb--; - cb(er); + Buffer.prototype.write = function write (string, offset, length, encoding) { + // Buffer#write(string) + if (offset === undefined) { + encoding = 'utf8' + length = this.length + offset = 0 + // Buffer#write(string, encoding) + } else if (length === undefined && typeof offset === 'string') { + encoding = offset + length = this.length + offset = 0 + // Buffer#write(string, offset[, length][, encoding]) + } else if (isFinite(offset)) { + offset = offset | 0 + if (isFinite(length)) { + length = length | 0 + if (encoding === undefined) encoding = 'utf8' + } else { + encoding = length + length = undefined + } + // legacy write(string, encoding, offset, length) - remove in v0.13 + } else { + throw new Error( + 'Buffer.write(string, encoding, offset[, length]) is no longer supported' + ) } - stream._writableState.errorEmitted = true; - stream.emit('error', er); - } + var remaining = this.length - offset + if (length === undefined || length > remaining) length = remaining - function onwriteStateUpdate(state) { - state.writing = false; - state.writecb = null; - state.length -= state.writelen; - state.writelen = 0; - } + if ((string.length > 0 && (length < 0 || offset < 0)) || offset > this.length) { + throw new RangeError('Attempt to write outside buffer bounds') + } - function onwrite(stream, er) { - var state = stream._writableState; - var sync = state.sync; - var cb = state.writecb; + if (!encoding) encoding = 'utf8' - onwriteStateUpdate(state); + var loweredCase = false + for (;;) { + switch (encoding) { + case 'hex': + return hexWrite(this, string, offset, length) - if (er) - onwriteError(stream, state, sync, er, cb); - else { - // Check if we're actually ready to finish, but don't emit yet - var finished = needFinish(stream, state); + case 'utf8': + case 'utf-8': + return utf8Write(this, string, offset, length) - if (!finished && - !state.corked && - !state.bufferProcessing && - state.buffer.length) { - clearBuffer(stream, state); - } + case 'ascii': + return asciiWrite(this, string, offset, length) - if (sync) { - process.nextTick(function() { - afterWrite(stream, state, finished, cb); - }); - } else { - afterWrite(stream, state, finished, cb); + case 'latin1': + case 'binary': + return latin1Write(this, string, offset, length) + + case 'base64': + // Warning: maxLength not taken into account in base64Write + return base64Write(this, string, offset, length) + + case 'ucs2': + case 'ucs-2': + case 'utf16le': + case 'utf-16le': + return ucs2Write(this, string, offset, length) + + default: + if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding) + encoding = ('' + encoding).toLowerCase() + loweredCase = true } } } - function afterWrite(stream, state, finished, cb) { - if (!finished) - onwriteDrain(stream, state); - state.pendingcb--; - cb(); - finishMaybe(stream, state); + Buffer.prototype.toJSON = function toJSON () { + return { + type: 'Buffer', + data: Array.prototype.slice.call(this._arr || this, 0) + } } - // Must force callback to be called on nextTick, so that we don't - // emit 'drain' before the write() consumer gets the 'false' return - // value, and has a chance to attach a 'drain' listener. - function onwriteDrain(stream, state) { - if (state.length === 0 && state.needDrain) { - state.needDrain = false; - stream.emit('drain'); + function base64Slice (buf, start, end) { + if (start === 0 && end === buf.length) { + return base64.fromByteArray(buf) + } else { + return base64.fromByteArray(buf.slice(start, end)) } } + function utf8Slice (buf, start, end) { + end = Math.min(buf.length, end) + var res = [] - // if there's something in the buffer waiting, then process it - function clearBuffer(stream, state) { - state.bufferProcessing = true; + var i = start + while (i < end) { + var firstByte = buf[i] + var codePoint = null + var bytesPerSequence = (firstByte > 0xEF) ? 4 + : (firstByte > 0xDF) ? 3 + : (firstByte > 0xBF) ? 2 + : 1 - if (stream._writev && state.buffer.length > 1) { - // Fast case, write everything using _writev() - var cbs = []; - for (var c = 0; c < state.buffer.length; c++) - cbs.push(state.buffer[c].callback); + if (i + bytesPerSequence <= end) { + var secondByte, thirdByte, fourthByte, tempCodePoint - // count the one we are adding, as well. - // TODO(isaacs) clean this up - state.pendingcb++; - doWrite(stream, state, true, state.length, state.buffer, '', function(err) { - for (var i = 0; i < cbs.length; i++) { - state.pendingcb--; - cbs[i](err); + switch (bytesPerSequence) { + case 1: + if (firstByte < 0x80) { + codePoint = firstByte + } + break + case 2: + secondByte = buf[i + 1] + if ((secondByte & 0xC0) === 0x80) { + tempCodePoint = (firstByte & 0x1F) << 0x6 | (secondByte & 0x3F) + if (tempCodePoint > 0x7F) { + codePoint = tempCodePoint + } + } + break + case 3: + secondByte = buf[i + 1] + thirdByte = buf[i + 2] + if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80) { + tempCodePoint = (firstByte & 0xF) << 0xC | (secondByte & 0x3F) << 0x6 | (thirdByte & 0x3F) + if (tempCodePoint > 0x7FF && (tempCodePoint < 0xD800 || tempCodePoint > 0xDFFF)) { + codePoint = tempCodePoint + } + } + break + case 4: + secondByte = buf[i + 1] + thirdByte = buf[i + 2] + fourthByte = buf[i + 3] + if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80 && (fourthByte & 0xC0) === 0x80) { + tempCodePoint = (firstByte & 0xF) << 0x12 | (secondByte & 0x3F) << 0xC | (thirdByte & 0x3F) << 0x6 | (fourthByte & 0x3F) + if (tempCodePoint > 0xFFFF && tempCodePoint < 0x110000) { + codePoint = tempCodePoint + } + } } - }); - - // Clear buffer - state.buffer = []; - } else { - // Slow case, write chunks one-by-one - for (var c = 0; c < state.buffer.length; c++) { - var entry = state.buffer[c]; - var chunk = entry.chunk; - var encoding = entry.encoding; - var cb = entry.callback; - var len = state.objectMode ? 1 : chunk.length; - - doWrite(stream, state, false, len, chunk, encoding, cb); + } - // if we didn't call the onwrite immediately, then - // it means that we need to wait until it does. - // also, that means that the chunk and cb are currently - // being processed, so move the buffer counter past them. - if (state.writing) { - c++; - break; - } + if (codePoint === null) { + // we did not generate a valid codePoint so insert a + // replacement char (U+FFFD) and advance only 1 byte + codePoint = 0xFFFD + bytesPerSequence = 1 + } else if (codePoint > 0xFFFF) { + // encode to utf16 (surrogate pair dance) + codePoint -= 0x10000 + res.push(codePoint >>> 10 & 0x3FF | 0xD800) + codePoint = 0xDC00 | codePoint & 0x3FF } - if (c < state.buffer.length) - state.buffer = state.buffer.slice(c); - else - state.buffer.length = 0; + res.push(codePoint) + i += bytesPerSequence } - state.bufferProcessing = false; + return decodeCodePointsArray(res) } - Writable.prototype._write = function(chunk, encoding, cb) { - cb(new Error('not implemented')); - - }; - - Writable.prototype._writev = null; - - Writable.prototype.end = function(chunk, encoding, cb) { - var state = this._writableState; + // Based on http://stackoverflow.com/a/22747272/680742, the browser with + // the lowest limit is Chrome, with 0x10000 args. + // We go 1 magnitude less, for safety + var MAX_ARGUMENTS_LENGTH = 0x1000 - if (util.isFunction(chunk)) { - cb = chunk; - chunk = null; - encoding = null; - } else if (util.isFunction(encoding)) { - cb = encoding; - encoding = null; + function decodeCodePointsArray (codePoints) { + var len = codePoints.length + if (len <= MAX_ARGUMENTS_LENGTH) { + return String.fromCharCode.apply(String, codePoints) // avoid extra slice() } - if (!util.isNullOrUndefined(chunk)) - this.write(chunk, encoding); - - // .end() fully uncorks - if (state.corked) { - state.corked = 1; - this.uncork(); + // Decode in chunks to avoid "call stack size exceeded". + var res = '' + var i = 0 + while (i < len) { + res += String.fromCharCode.apply( + String, + codePoints.slice(i, i += MAX_ARGUMENTS_LENGTH) + ) } - - // ignore unnecessary end() calls. - if (!state.ending && !state.finished) - endWritable(this, state, cb); - }; - - - function needFinish(stream, state) { - return (state.ending && - state.length === 0 && - !state.finished && - !state.writing); + return res } - function prefinish(stream, state) { - if (!state.prefinished) { - state.prefinished = true; - stream.emit('prefinish'); - } - } + function asciiSlice (buf, start, end) { + var ret = '' + end = Math.min(buf.length, end) - function finishMaybe(stream, state) { - var need = needFinish(stream, state); - if (need) { - if (state.pendingcb === 0) { - prefinish(stream, state); - state.finished = true; - stream.emit('finish'); - } else - prefinish(stream, state); + for (var i = start; i < end; ++i) { + ret += String.fromCharCode(buf[i] & 0x7F) } - return need; + return ret } - function endWritable(stream, state, cb) { - state.ending = true; - finishMaybe(stream, state); - if (cb) { - if (state.finished) - process.nextTick(cb); - else - stream.once('finish', cb); + function latin1Slice (buf, start, end) { + var ret = '' + end = Math.min(buf.length, end) + + for (var i = start; i < end; ++i) { + ret += String.fromCharCode(buf[i]) } - state.ended = true; + return ret } - /* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(10))) - -/***/ }, -/* 63 */ -/***/ function(module, exports, __webpack_require__) { - - // Copyright Joyent, Inc. and other Node contributors. - // - // Permission is hereby granted, free of charge, to any person obtaining a - // copy of this software and associated documentation files (the - // "Software"), to deal in the Software without restriction, including - // without limitation the rights to use, copy, modify, merge, publish, - // distribute, sublicense, and/or sell copies of the Software, and to permit - // persons to whom the Software is furnished to do so, subject to the - // following conditions: - // - // The above copyright notice and this permission notice shall be included - // in all copies or substantial portions of the Software. - // - // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN - // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, - // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR - // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE - // USE OR OTHER DEALINGS IN THE SOFTWARE. - - var Buffer = __webpack_require__(55).Buffer; - - var isBufferEncoding = Buffer.isEncoding - || function(encoding) { - switch (encoding && encoding.toLowerCase()) { - case 'hex': case 'utf8': case 'utf-8': case 'ascii': case 'binary': case 'base64': case 'ucs2': case 'ucs-2': case 'utf16le': case 'utf-16le': case 'raw': return true; - default: return false; - } - } + function hexSlice (buf, start, end) { + var len = buf.length + if (!start || start < 0) start = 0 + if (!end || end < 0 || end > len) end = len - function assertEncoding(encoding) { - if (encoding && !isBufferEncoding(encoding)) { - throw new Error('Unknown encoding: ' + encoding); + var out = '' + for (var i = start; i < end; ++i) { + out += toHex(buf[i]) } + return out } - // StringDecoder provides an interface for efficiently splitting a series of - // buffers into a series of JS strings without breaking apart multi-byte - // characters. CESU-8 is handled as part of the UTF-8 encoding. - // - // @TODO Handling all encodings inside a single object makes it very difficult - // to reason about this code, so it should be split up in the future. - // @TODO There should be a utf8-strict encoding that rejects invalid UTF-8 code - // points as used by CESU-8. - var StringDecoder = exports.StringDecoder = function(encoding) { - this.encoding = (encoding || 'utf8').toLowerCase().replace(/[-_]/, ''); - assertEncoding(encoding); - switch (this.encoding) { - case 'utf8': - // CESU-8 represents each of Surrogate Pair by 3-bytes - this.surrogateSize = 3; - break; - case 'ucs2': - case 'utf16le': - // UTF-16 represents each of Surrogate Pair by 2-bytes - this.surrogateSize = 2; - this.detectIncompleteChar = utf16DetectIncompleteChar; - break; - case 'base64': - // Base-64 stores 3 bytes in 4 chars, and pads the remainder. - this.surrogateSize = 3; - this.detectIncompleteChar = base64DetectIncompleteChar; - break; - default: - this.write = passThroughWrite; - return; + function utf16leSlice (buf, start, end) { + var bytes = buf.slice(start, end) + var res = '' + for (var i = 0; i < bytes.length; i += 2) { + res += String.fromCharCode(bytes[i] + bytes[i + 1] * 256) } + return res + } - // Enough space to store all bytes of a single character. UTF-8 needs 4 - // bytes, but CESU-8 may require up to 6 (3 bytes per surrogate). - this.charBuffer = new Buffer(6); - // Number of bytes received for the current incomplete multi-byte character. - this.charReceived = 0; - // Number of bytes expected for the current incomplete multi-byte character. - this.charLength = 0; - }; - - - // write decodes the given buffer and returns it as JS string that is - // guaranteed to not contain any partial multi-byte characters. Any partial - // character found at the end of the buffer is buffered up, and will be - // returned when calling write again with the remaining bytes. - // - // Note: Converting a Buffer containing an orphan surrogate to a String - // currently works, but converting a String to a Buffer (via `new Buffer`, or - // Buffer#write) will replace incomplete surrogates with the unicode - // replacement character. See https://codereview.chromium.org/121173009/ . - StringDecoder.prototype.write = function(buffer) { - var charStr = ''; - // if our last write ended with an incomplete multibyte character - while (this.charLength) { - // determine how many remaining bytes this buffer has to offer for this char - var available = (buffer.length >= this.charLength - this.charReceived) ? - this.charLength - this.charReceived : - buffer.length; - - // add the new bytes to the char buffer - buffer.copy(this.charBuffer, this.charReceived, 0, available); - this.charReceived += available; - - if (this.charReceived < this.charLength) { - // still not enough chars in this buffer? wait for more ... - return ''; - } - - // remove bytes belonging to the current character from the buffer - buffer = buffer.slice(available, buffer.length); + Buffer.prototype.slice = function slice (start, end) { + var len = this.length + start = ~~start + end = end === undefined ? len : ~~end - // get the character that was split - charStr = this.charBuffer.slice(0, this.charLength).toString(this.encoding); + if (start < 0) { + start += len + if (start < 0) start = 0 + } else if (start > len) { + start = len + } - // CESU-8: lead surrogate (D800-DBFF) is also the incomplete character - var charCode = charStr.charCodeAt(charStr.length - 1); - if (charCode >= 0xD800 && charCode <= 0xDBFF) { - this.charLength += this.surrogateSize; - charStr = ''; - continue; - } - this.charReceived = this.charLength = 0; + if (end < 0) { + end += len + if (end < 0) end = 0 + } else if (end > len) { + end = len + } - // if there are no more bytes in this buffer, just emit our char - if (buffer.length === 0) { - return charStr; + if (end < start) end = start + + var newBuf + if (Buffer.TYPED_ARRAY_SUPPORT) { + newBuf = this.subarray(start, end) + newBuf.__proto__ = Buffer.prototype + } else { + var sliceLen = end - start + newBuf = new Buffer(sliceLen, undefined) + for (var i = 0; i < sliceLen; ++i) { + newBuf[i] = this[i + start] } - break; } - // determine and set charLength / charReceived - this.detectIncompleteChar(buffer); + return newBuf + } - var end = buffer.length; - if (this.charLength) { - // buffer the incomplete character bytes we got - buffer.copy(this.charBuffer, 0, buffer.length - this.charReceived, end); - end -= this.charReceived; + /* + * Need to make sure that buffer isn't trying to write out of bounds. + */ + function checkOffset (offset, ext, length) { + if ((offset % 1) !== 0 || offset < 0) throw new RangeError('offset is not uint') + if (offset + ext > length) throw new RangeError('Trying to access beyond buffer length') + } + + Buffer.prototype.readUIntLE = function readUIntLE (offset, byteLength, noAssert) { + offset = offset | 0 + byteLength = byteLength | 0 + if (!noAssert) checkOffset(offset, byteLength, this.length) + + var val = this[offset] + var mul = 1 + var i = 0 + while (++i < byteLength && (mul *= 0x100)) { + val += this[offset + i] * mul } - charStr += buffer.toString(this.encoding, 0, end); + return val + } - var end = charStr.length - 1; - var charCode = charStr.charCodeAt(end); - // CESU-8: lead surrogate (D800-DBFF) is also the incomplete character - if (charCode >= 0xD800 && charCode <= 0xDBFF) { - var size = this.surrogateSize; - this.charLength += size; - this.charReceived += size; - this.charBuffer.copy(this.charBuffer, size, 0, size); - buffer.copy(this.charBuffer, 0, 0, size); - return charStr.substring(0, end); + Buffer.prototype.readUIntBE = function readUIntBE (offset, byteLength, noAssert) { + offset = offset | 0 + byteLength = byteLength | 0 + if (!noAssert) { + checkOffset(offset, byteLength, this.length) } - // or just emit the charStr - return charStr; - }; + var val = this[offset + --byteLength] + var mul = 1 + while (byteLength > 0 && (mul *= 0x100)) { + val += this[offset + --byteLength] * mul + } - // detectIncompleteChar determines if there is an incomplete UTF-8 character at - // the end of the given buffer. If so, it sets this.charLength to the byte - // length that character, and sets this.charReceived to the number of bytes - // that are available for this character. - StringDecoder.prototype.detectIncompleteChar = function(buffer) { - // determine how many bytes we have to check at the end of this buffer - var i = (buffer.length >= 3) ? 3 : buffer.length; + return val + } - // Figure out if one of the last i bytes of our buffer announces an - // incomplete char. - for (; i > 0; i--) { - var c = buffer[buffer.length - i]; + Buffer.prototype.readUInt8 = function readUInt8 (offset, noAssert) { + if (!noAssert) checkOffset(offset, 1, this.length) + return this[offset] + } - // See http://en.wikipedia.org/wiki/UTF-8#Description + Buffer.prototype.readUInt16LE = function readUInt16LE (offset, noAssert) { + if (!noAssert) checkOffset(offset, 2, this.length) + return this[offset] | (this[offset + 1] << 8) + } - // 110XXXXX - if (i == 1 && c >> 5 == 0x06) { - this.charLength = 2; - break; - } + Buffer.prototype.readUInt16BE = function readUInt16BE (offset, noAssert) { + if (!noAssert) checkOffset(offset, 2, this.length) + return (this[offset] << 8) | this[offset + 1] + } - // 1110XXXX - if (i <= 2 && c >> 4 == 0x0E) { - this.charLength = 3; - break; - } + Buffer.prototype.readUInt32LE = function readUInt32LE (offset, noAssert) { + if (!noAssert) checkOffset(offset, 4, this.length) - // 11110XXX - if (i <= 3 && c >> 3 == 0x1E) { - this.charLength = 4; - break; - } - } - this.charReceived = i; - }; + return ((this[offset]) | + (this[offset + 1] << 8) | + (this[offset + 2] << 16)) + + (this[offset + 3] * 0x1000000) + } - StringDecoder.prototype.end = function(buffer) { - var res = ''; - if (buffer && buffer.length) - res = this.write(buffer); + Buffer.prototype.readUInt32BE = function readUInt32BE (offset, noAssert) { + if (!noAssert) checkOffset(offset, 4, this.length) - if (this.charReceived) { - var cr = this.charReceived; - var buf = this.charBuffer; - var enc = this.encoding; - res += buf.slice(0, cr).toString(enc); + return (this[offset] * 0x1000000) + + ((this[offset + 1] << 16) | + (this[offset + 2] << 8) | + this[offset + 3]) + } + + Buffer.prototype.readIntLE = function readIntLE (offset, byteLength, noAssert) { + offset = offset | 0 + byteLength = byteLength | 0 + if (!noAssert) checkOffset(offset, byteLength, this.length) + + var val = this[offset] + var mul = 1 + var i = 0 + while (++i < byteLength && (mul *= 0x100)) { + val += this[offset + i] * mul } + mul *= 0x80 - return res; - }; + if (val >= mul) val -= Math.pow(2, 8 * byteLength) - function passThroughWrite(buffer) { - return buffer.toString(this.encoding); + return val } - function utf16DetectIncompleteChar(buffer) { - this.charReceived = buffer.length % 2; - this.charLength = this.charReceived ? 2 : 0; - } + Buffer.prototype.readIntBE = function readIntBE (offset, byteLength, noAssert) { + offset = offset | 0 + byteLength = byteLength | 0 + if (!noAssert) checkOffset(offset, byteLength, this.length) - function base64DetectIncompleteChar(buffer) { - this.charReceived = buffer.length % 3; - this.charLength = this.charReceived ? 3 : 0; + var i = byteLength + var mul = 1 + var val = this[offset + --i] + while (i > 0 && (mul *= 0x100)) { + val += this[offset + --i] * mul + } + mul *= 0x80 + + if (val >= mul) val -= Math.pow(2, 8 * byteLength) + + return val } + Buffer.prototype.readInt8 = function readInt8 (offset, noAssert) { + if (!noAssert) checkOffset(offset, 1, this.length) + if (!(this[offset] & 0x80)) return (this[offset]) + return ((0xff - this[offset] + 1) * -1) + } -/***/ }, -/* 64 */ -/***/ function(module, exports, __webpack_require__) { + Buffer.prototype.readInt16LE = function readInt16LE (offset, noAssert) { + if (!noAssert) checkOffset(offset, 2, this.length) + var val = this[offset] | (this[offset + 1] << 8) + return (val & 0x8000) ? val | 0xFFFF0000 : val + } - // Copyright Joyent, Inc. and other Node contributors. - // - // Permission is hereby granted, free of charge, to any person obtaining a - // copy of this software and associated documentation files (the - // "Software"), to deal in the Software without restriction, including - // without limitation the rights to use, copy, modify, merge, publish, - // distribute, sublicense, and/or sell copies of the Software, and to permit - // persons to whom the Software is furnished to do so, subject to the - // following conditions: - // - // The above copyright notice and this permission notice shall be included - // in all copies or substantial portions of the Software. - // - // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN - // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, - // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR - // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE - // USE OR OTHER DEALINGS IN THE SOFTWARE. + Buffer.prototype.readInt16BE = function readInt16BE (offset, noAssert) { + if (!noAssert) checkOffset(offset, 2, this.length) + var val = this[offset + 1] | (this[offset] << 8) + return (val & 0x8000) ? val | 0xFFFF0000 : val + } + Buffer.prototype.readInt32LE = function readInt32LE (offset, noAssert) { + if (!noAssert) checkOffset(offset, 4, this.length) - // a transform stream is a readable/writable stream where you do - // something with the data. Sometimes it's called a "filter", - // but that's not a great name for it, since that implies a thing where - // some bits pass through, and others are simply ignored. (That would - // be a valid example of a transform, of course.) - // - // While the output is causally related to the input, it's not a - // necessarily symmetric or synchronous transformation. For example, - // a zlib stream might take multiple plain-text writes(), and then - // emit a single compressed chunk some time in the future. - // - // Here's how this works: - // - // The Transform stream has all the aspects of the readable and writable - // stream classes. When you write(chunk), that calls _write(chunk,cb) - // internally, and returns false if there's a lot of pending writes - // buffered up. When you call read(), that calls _read(n) until - // there's enough pending readable data buffered up. - // - // In a transform stream, the written data is placed in a buffer. When - // _read(n) is called, it transforms the queued up data, calling the - // buffered _write cb's as it consumes chunks. If consuming a single - // written chunk would result in multiple output chunks, then the first - // outputted bit calls the readcb, and subsequent chunks just go into - // the read buffer, and will cause it to emit 'readable' if necessary. - // - // This way, back-pressure is actually determined by the reading side, - // since _read has to be called to start processing a new chunk. However, - // a pathological inflate type of transform can cause excessive buffering - // here. For example, imagine a stream where every byte of input is - // interpreted as an integer from 0-255, and then results in that many - // bytes of output. Writing the 4 bytes {ff,ff,ff,ff} would result in - // 1kb of data being output. In this case, you could write a very small - // amount of input, and end up with a very large amount of output. In - // such a pathological inflating mechanism, there'd be no way to tell - // the system to stop doing the transform. A single 4MB write could - // cause the system to run out of memory. - // - // However, even in such a pathological case, only a single written chunk - // would be consumed, and then the rest would wait (un-transformed) until - // the results of the previous transformed chunk were consumed. + return (this[offset]) | + (this[offset + 1] << 8) | + (this[offset + 2] << 16) | + (this[offset + 3] << 24) + } - module.exports = Transform; + Buffer.prototype.readInt32BE = function readInt32BE (offset, noAssert) { + if (!noAssert) checkOffset(offset, 4, this.length) - var Duplex = __webpack_require__(61); + return (this[offset] << 24) | + (this[offset + 1] << 16) | + (this[offset + 2] << 8) | + (this[offset + 3]) + } - /**/ - var util = __webpack_require__(59); - util.inherits = __webpack_require__(51); - /**/ + Buffer.prototype.readFloatLE = function readFloatLE (offset, noAssert) { + if (!noAssert) checkOffset(offset, 4, this.length) + return ieee754.read(this, offset, true, 23, 4) + } - util.inherits(Transform, Duplex); + Buffer.prototype.readFloatBE = function readFloatBE (offset, noAssert) { + if (!noAssert) checkOffset(offset, 4, this.length) + return ieee754.read(this, offset, false, 23, 4) + } + Buffer.prototype.readDoubleLE = function readDoubleLE (offset, noAssert) { + if (!noAssert) checkOffset(offset, 8, this.length) + return ieee754.read(this, offset, true, 52, 8) + } - function TransformState(options, stream) { - this.afterTransform = function(er, data) { - return afterTransform(stream, er, data); - }; + Buffer.prototype.readDoubleBE = function readDoubleBE (offset, noAssert) { + if (!noAssert) checkOffset(offset, 8, this.length) + return ieee754.read(this, offset, false, 52, 8) + } - this.needTransform = false; - this.transforming = false; - this.writecb = null; - this.writechunk = null; + function checkInt (buf, value, offset, ext, max, min) { + if (!Buffer.isBuffer(buf)) throw new TypeError('"buffer" argument must be a Buffer instance') + if (value > max || value < min) throw new RangeError('"value" argument is out of bounds') + if (offset + ext > buf.length) throw new RangeError('Index out of range') } - function afterTransform(stream, er, data) { - var ts = stream._transformState; - ts.transforming = false; + Buffer.prototype.writeUIntLE = function writeUIntLE (value, offset, byteLength, noAssert) { + value = +value + offset = offset | 0 + byteLength = byteLength | 0 + if (!noAssert) { + var maxBytes = Math.pow(2, 8 * byteLength) - 1 + checkInt(this, value, offset, byteLength, maxBytes, 0) + } - var cb = ts.writecb; + var mul = 1 + var i = 0 + this[offset] = value & 0xFF + while (++i < byteLength && (mul *= 0x100)) { + this[offset + i] = (value / mul) & 0xFF + } - if (!cb) - return stream.emit('error', new Error('no writecb in Transform class')); + return offset + byteLength + } - ts.writechunk = null; - ts.writecb = null; + Buffer.prototype.writeUIntBE = function writeUIntBE (value, offset, byteLength, noAssert) { + value = +value + offset = offset | 0 + byteLength = byteLength | 0 + if (!noAssert) { + var maxBytes = Math.pow(2, 8 * byteLength) - 1 + checkInt(this, value, offset, byteLength, maxBytes, 0) + } - if (!util.isNullOrUndefined(data)) - stream.push(data); + var i = byteLength - 1 + var mul = 1 + this[offset + i] = value & 0xFF + while (--i >= 0 && (mul *= 0x100)) { + this[offset + i] = (value / mul) & 0xFF + } - if (cb) - cb(er); + return offset + byteLength + } - var rs = stream._readableState; - rs.reading = false; - if (rs.needReadable || rs.length < rs.highWaterMark) { - stream._read(rs.highWaterMark); + Buffer.prototype.writeUInt8 = function writeUInt8 (value, offset, noAssert) { + value = +value + offset = offset | 0 + if (!noAssert) checkInt(this, value, offset, 1, 0xff, 0) + if (!Buffer.TYPED_ARRAY_SUPPORT) value = Math.floor(value) + this[offset] = (value & 0xff) + return offset + 1 + } + + function objectWriteUInt16 (buf, value, offset, littleEndian) { + if (value < 0) value = 0xffff + value + 1 + for (var i = 0, j = Math.min(buf.length - offset, 2); i < j; ++i) { + buf[offset + i] = (value & (0xff << (8 * (littleEndian ? i : 1 - i)))) >>> + (littleEndian ? i : 1 - i) * 8 + } + } + + Buffer.prototype.writeUInt16LE = function writeUInt16LE (value, offset, noAssert) { + value = +value + offset = offset | 0 + if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0) + if (Buffer.TYPED_ARRAY_SUPPORT) { + this[offset] = (value & 0xff) + this[offset + 1] = (value >>> 8) + } else { + objectWriteUInt16(this, value, offset, true) } + return offset + 2 } + Buffer.prototype.writeUInt16BE = function writeUInt16BE (value, offset, noAssert) { + value = +value + offset = offset | 0 + if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0) + if (Buffer.TYPED_ARRAY_SUPPORT) { + this[offset] = (value >>> 8) + this[offset + 1] = (value & 0xff) + } else { + objectWriteUInt16(this, value, offset, false) + } + return offset + 2 + } - function Transform(options) { - if (!(this instanceof Transform)) - return new Transform(options); + function objectWriteUInt32 (buf, value, offset, littleEndian) { + if (value < 0) value = 0xffffffff + value + 1 + for (var i = 0, j = Math.min(buf.length - offset, 4); i < j; ++i) { + buf[offset + i] = (value >>> (littleEndian ? i : 3 - i) * 8) & 0xff + } + } - Duplex.call(this, options); + Buffer.prototype.writeUInt32LE = function writeUInt32LE (value, offset, noAssert) { + value = +value + offset = offset | 0 + if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0) + if (Buffer.TYPED_ARRAY_SUPPORT) { + this[offset + 3] = (value >>> 24) + this[offset + 2] = (value >>> 16) + this[offset + 1] = (value >>> 8) + this[offset] = (value & 0xff) + } else { + objectWriteUInt32(this, value, offset, true) + } + return offset + 4 + } - this._transformState = new TransformState(options, this); + Buffer.prototype.writeUInt32BE = function writeUInt32BE (value, offset, noAssert) { + value = +value + offset = offset | 0 + if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0) + if (Buffer.TYPED_ARRAY_SUPPORT) { + this[offset] = (value >>> 24) + this[offset + 1] = (value >>> 16) + this[offset + 2] = (value >>> 8) + this[offset + 3] = (value & 0xff) + } else { + objectWriteUInt32(this, value, offset, false) + } + return offset + 4 + } - // when the writable side finishes, then flush out anything remaining. - var stream = this; + Buffer.prototype.writeIntLE = function writeIntLE (value, offset, byteLength, noAssert) { + value = +value + offset = offset | 0 + if (!noAssert) { + var limit = Math.pow(2, 8 * byteLength - 1) - // start out asking for a readable event once data is transformed. - this._readableState.needReadable = true; + checkInt(this, value, offset, byteLength, limit - 1, -limit) + } - // we have implemented the _read method, and done the other things - // that Readable wants before the first _read call, so unset the - // sync guard flag. - this._readableState.sync = false; + var i = 0 + var mul = 1 + var sub = 0 + this[offset] = value & 0xFF + while (++i < byteLength && (mul *= 0x100)) { + if (value < 0 && sub === 0 && this[offset + i - 1] !== 0) { + sub = 1 + } + this[offset + i] = ((value / mul) >> 0) - sub & 0xFF + } - this.once('prefinish', function() { - if (util.isFunction(this._flush)) - this._flush(function(er) { - done(stream, er); - }); - else - done(stream); - }); + return offset + byteLength } - Transform.prototype.push = function(chunk, encoding) { - this._transformState.needTransform = false; - return Duplex.prototype.push.call(this, chunk, encoding); - }; + Buffer.prototype.writeIntBE = function writeIntBE (value, offset, byteLength, noAssert) { + value = +value + offset = offset | 0 + if (!noAssert) { + var limit = Math.pow(2, 8 * byteLength - 1) - // This is the part where you do stuff! - // override this function in implementation classes. - // 'chunk' is an input chunk. - // - // Call `push(newChunk)` to pass along transformed output - // to the readable side. You may call 'push' zero or more times. - // - // Call `cb(err)` when you are done with this chunk. If you pass - // an error, then that'll put the hurt on the whole operation. If you - // never call cb(), then you'll never get another chunk. - Transform.prototype._transform = function(chunk, encoding, cb) { - throw new Error('not implemented'); - }; + checkInt(this, value, offset, byteLength, limit - 1, -limit) + } - Transform.prototype._write = function(chunk, encoding, cb) { - var ts = this._transformState; - ts.writecb = cb; - ts.writechunk = chunk; - ts.writeencoding = encoding; - if (!ts.transforming) { - var rs = this._readableState; - if (ts.needTransform || - rs.needReadable || - rs.length < rs.highWaterMark) - this._read(rs.highWaterMark); + var i = byteLength - 1 + var mul = 1 + var sub = 0 + this[offset + i] = value & 0xFF + while (--i >= 0 && (mul *= 0x100)) { + if (value < 0 && sub === 0 && this[offset + i + 1] !== 0) { + sub = 1 + } + this[offset + i] = ((value / mul) >> 0) - sub & 0xFF } - }; - // Doesn't matter what the args are here. - // _transform does all the work. - // That we got here means that the readable side wants more data. - Transform.prototype._read = function(n) { - var ts = this._transformState; + return offset + byteLength + } - if (!util.isNull(ts.writechunk) && ts.writecb && !ts.transforming) { - ts.transforming = true; - this._transform(ts.writechunk, ts.writeencoding, ts.afterTransform); + Buffer.prototype.writeInt8 = function writeInt8 (value, offset, noAssert) { + value = +value + offset = offset | 0 + if (!noAssert) checkInt(this, value, offset, 1, 0x7f, -0x80) + if (!Buffer.TYPED_ARRAY_SUPPORT) value = Math.floor(value) + if (value < 0) value = 0xff + value + 1 + this[offset] = (value & 0xff) + return offset + 1 + } + + Buffer.prototype.writeInt16LE = function writeInt16LE (value, offset, noAssert) { + value = +value + offset = offset | 0 + if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000) + if (Buffer.TYPED_ARRAY_SUPPORT) { + this[offset] = (value & 0xff) + this[offset + 1] = (value >>> 8) + } else { + objectWriteUInt16(this, value, offset, true) + } + return offset + 2 + } + + Buffer.prototype.writeInt16BE = function writeInt16BE (value, offset, noAssert) { + value = +value + offset = offset | 0 + if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000) + if (Buffer.TYPED_ARRAY_SUPPORT) { + this[offset] = (value >>> 8) + this[offset + 1] = (value & 0xff) + } else { + objectWriteUInt16(this, value, offset, false) + } + return offset + 2 + } + + Buffer.prototype.writeInt32LE = function writeInt32LE (value, offset, noAssert) { + value = +value + offset = offset | 0 + if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000) + if (Buffer.TYPED_ARRAY_SUPPORT) { + this[offset] = (value & 0xff) + this[offset + 1] = (value >>> 8) + this[offset + 2] = (value >>> 16) + this[offset + 3] = (value >>> 24) } else { - // mark that we need a transform, so that any data that comes in - // will get processed, now that we've asked for it. - ts.needTransform = true; + objectWriteUInt32(this, value, offset, true) } - }; - + return offset + 4 + } - function done(stream, er) { - if (er) - return stream.emit('error', er); + Buffer.prototype.writeInt32BE = function writeInt32BE (value, offset, noAssert) { + value = +value + offset = offset | 0 + if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000) + if (value < 0) value = 0xffffffff + value + 1 + if (Buffer.TYPED_ARRAY_SUPPORT) { + this[offset] = (value >>> 24) + this[offset + 1] = (value >>> 16) + this[offset + 2] = (value >>> 8) + this[offset + 3] = (value & 0xff) + } else { + objectWriteUInt32(this, value, offset, false) + } + return offset + 4 + } - // if there's nothing in the write buffer, then that means - // that nothing more will ever be provided - var ws = stream._writableState; - var ts = stream._transformState; + function checkIEEE754 (buf, value, offset, ext, max, min) { + if (offset + ext > buf.length) throw new RangeError('Index out of range') + if (offset < 0) throw new RangeError('Index out of range') + } - if (ws.length) - throw new Error('calling transform done when ws.length != 0'); + function writeFloat (buf, value, offset, littleEndian, noAssert) { + if (!noAssert) { + checkIEEE754(buf, value, offset, 4, 3.4028234663852886e+38, -3.4028234663852886e+38) + } + ieee754.write(buf, value, offset, littleEndian, 23, 4) + return offset + 4 + } - if (ts.transforming) - throw new Error('calling transform done when still transforming'); + Buffer.prototype.writeFloatLE = function writeFloatLE (value, offset, noAssert) { + return writeFloat(this, value, offset, true, noAssert) + } - return stream.push(null); + Buffer.prototype.writeFloatBE = function writeFloatBE (value, offset, noAssert) { + return writeFloat(this, value, offset, false, noAssert) } + function writeDouble (buf, value, offset, littleEndian, noAssert) { + if (!noAssert) { + checkIEEE754(buf, value, offset, 8, 1.7976931348623157E+308, -1.7976931348623157E+308) + } + ieee754.write(buf, value, offset, littleEndian, 52, 8) + return offset + 8 + } -/***/ }, -/* 65 */ -/***/ function(module, exports, __webpack_require__) { + Buffer.prototype.writeDoubleLE = function writeDoubleLE (value, offset, noAssert) { + return writeDouble(this, value, offset, true, noAssert) + } - // Copyright Joyent, Inc. and other Node contributors. - // - // Permission is hereby granted, free of charge, to any person obtaining a - // copy of this software and associated documentation files (the - // "Software"), to deal in the Software without restriction, including - // without limitation the rights to use, copy, modify, merge, publish, - // distribute, sublicense, and/or sell copies of the Software, and to permit - // persons to whom the Software is furnished to do so, subject to the - // following conditions: - // - // The above copyright notice and this permission notice shall be included - // in all copies or substantial portions of the Software. - // - // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN - // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, - // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR - // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE - // USE OR OTHER DEALINGS IN THE SOFTWARE. + Buffer.prototype.writeDoubleBE = function writeDoubleBE (value, offset, noAssert) { + return writeDouble(this, value, offset, false, noAssert) + } - // a passthrough stream. - // basically just the most minimal sort of Transform stream. - // Every written chunk gets output as-is. + // copy(targetBuffer, targetStart=0, sourceStart=0, sourceEnd=buffer.length) + Buffer.prototype.copy = function copy (target, targetStart, start, end) { + if (!start) start = 0 + if (!end && end !== 0) end = this.length + if (targetStart >= target.length) targetStart = target.length + if (!targetStart) targetStart = 0 + if (end > 0 && end < start) end = start - module.exports = PassThrough; + // Copy 0 bytes; we're done + if (end === start) return 0 + if (target.length === 0 || this.length === 0) return 0 - var Transform = __webpack_require__(64); + // Fatal error conditions + if (targetStart < 0) { + throw new RangeError('targetStart out of bounds') + } + if (start < 0 || start >= this.length) throw new RangeError('sourceStart out of bounds') + if (end < 0) throw new RangeError('sourceEnd out of bounds') - /**/ - var util = __webpack_require__(59); - util.inherits = __webpack_require__(51); - /**/ + // Are we oob? + if (end > this.length) end = this.length + if (target.length - targetStart < end - start) { + end = target.length - targetStart + start + } - util.inherits(PassThrough, Transform); + var len = end - start + var i - function PassThrough(options) { - if (!(this instanceof PassThrough)) - return new PassThrough(options); + if (this === target && start < targetStart && targetStart < end) { + // descending copy from end + for (i = len - 1; i >= 0; --i) { + target[i + targetStart] = this[i + start] + } + } else if (len < 1000 || !Buffer.TYPED_ARRAY_SUPPORT) { + // ascending copy from start + for (i = 0; i < len; ++i) { + target[i + targetStart] = this[i + start] + } + } else { + Uint8Array.prototype.set.call( + target, + this.subarray(start, start + len), + targetStart + ) + } - Transform.call(this, options); + return len } - PassThrough.prototype._transform = function(chunk, encoding, cb) { - cb(null, chunk); - }; - - -/***/ }, -/* 66 */ -/***/ function(module, exports, __webpack_require__) { - - module.exports = __webpack_require__(62) - + // Usage: + // buffer.fill(number[, offset[, end]]) + // buffer.fill(buffer[, offset[, end]]) + // buffer.fill(string[, offset[, end]][, encoding]) + Buffer.prototype.fill = function fill (val, start, end, encoding) { + // Handle string cases: + if (typeof val === 'string') { + if (typeof start === 'string') { + encoding = start + start = 0 + end = this.length + } else if (typeof end === 'string') { + encoding = end + end = this.length + } + if (val.length === 1) { + var code = val.charCodeAt(0) + if (code < 256) { + val = code + } + } + if (encoding !== undefined && typeof encoding !== 'string') { + throw new TypeError('encoding must be a string') + } + if (typeof encoding === 'string' && !Buffer.isEncoding(encoding)) { + throw new TypeError('Unknown encoding: ' + encoding) + } + } else if (typeof val === 'number') { + val = val & 255 + } -/***/ }, -/* 67 */ -/***/ function(module, exports, __webpack_require__) { + // Invalid ranges are not set to a default, so can range check early. + if (start < 0 || this.length < start || this.length < end) { + throw new RangeError('Out of range index') + } - module.exports = __webpack_require__(61) + if (end <= start) { + return this + } + start = start >>> 0 + end = end === undefined ? this.length : end >>> 0 -/***/ }, -/* 68 */ -/***/ function(module, exports, __webpack_require__) { + if (!val) val = 0 - module.exports = __webpack_require__(64) + var i + if (typeof val === 'number') { + for (i = start; i < end; ++i) { + this[i] = val + } + } else { + var bytes = Buffer.isBuffer(val) + ? val + : utf8ToBytes(new Buffer(val, encoding).toString()) + var len = bytes.length + for (i = 0; i < end - start; ++i) { + this[i + start] = bytes[i % len] + } + } + return this + } -/***/ }, -/* 69 */ -/***/ function(module, exports, __webpack_require__) { + // HELPER FUNCTIONS + // ================ - module.exports = __webpack_require__(65) + var INVALID_BASE64_RE = /[^+\/0-9A-Za-z-_]/g + function base64clean (str) { + // Node strips out invalid characters like \n and \t from the string, base64-js does not + str = stringtrim(str).replace(INVALID_BASE64_RE, '') + // Node converts strings with length < 2 to '' + if (str.length < 2) return '' + // Node allows for non-padded base64 strings (missing trailing ===), base64-js does not + while (str.length % 4 !== 0) { + str = str + '=' + } + return str + } -/***/ }, -/* 70 */ -/***/ function(module, exports, __webpack_require__) { + function stringtrim (str) { + if (str.trim) return str.trim() + return str.replace(/^\s+|\s+$/g, '') + } - /* WEBPACK VAR INJECTION */(function(global, process) {// Copyright Joyent, Inc. and other Node contributors. - // - // Permission is hereby granted, free of charge, to any person obtaining a - // copy of this software and associated documentation files (the - // "Software"), to deal in the Software without restriction, including - // without limitation the rights to use, copy, modify, merge, publish, - // distribute, sublicense, and/or sell copies of the Software, and to permit - // persons to whom the Software is furnished to do so, subject to the - // following conditions: - // - // The above copyright notice and this permission notice shall be included - // in all copies or substantial portions of the Software. - // - // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN - // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, - // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR - // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE - // USE OR OTHER DEALINGS IN THE SOFTWARE. + function toHex (n) { + if (n < 16) return '0' + n.toString(16) + return n.toString(16) + } - var formatRegExp = /%[sdj%]/g; - exports.format = function(f) { - if (!isString(f)) { - var objects = []; - for (var i = 0; i < arguments.length; i++) { - objects.push(inspect(arguments[i])); - } - return objects.join(' '); - } + function utf8ToBytes (string, units) { + units = units || Infinity + var codePoint + var length = string.length + var leadSurrogate = null + var bytes = [] - var i = 1; - var args = arguments; - var len = args.length; - var str = String(f).replace(formatRegExp, function(x) { - if (x === '%%') return '%'; - if (i >= len) return x; - switch (x) { - case '%s': return String(args[i++]); - case '%d': return Number(args[i++]); - case '%j': - try { - return JSON.stringify(args[i++]); - } catch (_) { - return '[Circular]'; - } - default: - return x; - } - }); - for (var x = args[i]; i < len; x = args[++i]) { - if (isNull(x) || !isObject(x)) { - str += ' ' + x; - } else { - str += ' ' + inspect(x); - } - } - return str; - }; + for (var i = 0; i < length; ++i) { + codePoint = string.charCodeAt(i) + // is surrogate component + if (codePoint > 0xD7FF && codePoint < 0xE000) { + // last char was a lead + if (!leadSurrogate) { + // no lead yet + if (codePoint > 0xDBFF) { + // unexpected trail + if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD) + continue + } else if (i + 1 === length) { + // unpaired lead + if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD) + continue + } - // Mark that a method should not be used. - // Returns a modified function which warns once by default. - // If --no-deprecation is set, then it is a no-op. - exports.deprecate = function(fn, msg) { - // Allow for deprecating things in the process of starting up. - if (isUndefined(global.process)) { - return function() { - return exports.deprecate(fn, msg).apply(this, arguments); - }; - } + // valid lead + leadSurrogate = codePoint - if (process.noDeprecation === true) { - return fn; - } + continue + } - var warned = false; - function deprecated() { - if (!warned) { - if (process.throwDeprecation) { - throw new Error(msg); - } else if (process.traceDeprecation) { - console.trace(msg); - } else { - console.error(msg); + // 2 leads in a row + if (codePoint < 0xDC00) { + if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD) + leadSurrogate = codePoint + continue } - warned = true; - } - return fn.apply(this, arguments); - } - return deprecated; - }; + // valid surrogate pair + codePoint = (leadSurrogate - 0xD800 << 10 | codePoint - 0xDC00) + 0x10000 + } else if (leadSurrogate) { + // valid bmp char, but last char was a lead + if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD) + } + leadSurrogate = null - var debugs = {}; - var debugEnviron; - exports.debuglog = function(set) { - if (isUndefined(debugEnviron)) - debugEnviron = process.env.NODE_DEBUG || ''; - set = set.toUpperCase(); - if (!debugs[set]) { - if (new RegExp('\\b' + set + '\\b', 'i').test(debugEnviron)) { - var pid = process.pid; - debugs[set] = function() { - var msg = exports.format.apply(exports, arguments); - console.error('%s %d: %s', set, pid, msg); - }; + // encode utf8 + if (codePoint < 0x80) { + if ((units -= 1) < 0) break + bytes.push(codePoint) + } else if (codePoint < 0x800) { + if ((units -= 2) < 0) break + bytes.push( + codePoint >> 0x6 | 0xC0, + codePoint & 0x3F | 0x80 + ) + } else if (codePoint < 0x10000) { + if ((units -= 3) < 0) break + bytes.push( + codePoint >> 0xC | 0xE0, + codePoint >> 0x6 & 0x3F | 0x80, + codePoint & 0x3F | 0x80 + ) + } else if (codePoint < 0x110000) { + if ((units -= 4) < 0) break + bytes.push( + codePoint >> 0x12 | 0xF0, + codePoint >> 0xC & 0x3F | 0x80, + codePoint >> 0x6 & 0x3F | 0x80, + codePoint & 0x3F | 0x80 + ) } else { - debugs[set] = function() {}; + throw new Error('Invalid code point') } } - return debugs[set]; - }; + return bytes + } - /** - * Echos the value of a value. Trys to print the value out - * in the best way possible given the different types. - * - * @param {Object} obj The object to print out. - * @param {Object} opts Optional options object that alters the output. - */ - /* legacy: obj, showHidden, depth, colors*/ - function inspect(obj, opts) { - // default options - var ctx = { - seen: [], - stylize: stylizeNoColor - }; - // legacy... - if (arguments.length >= 3) ctx.depth = arguments[2]; - if (arguments.length >= 4) ctx.colors = arguments[3]; - if (isBoolean(opts)) { - // legacy... - ctx.showHidden = opts; - } else if (opts) { - // got an "options" object - exports._extend(ctx, opts); + function asciiToBytes (str) { + var byteArray = [] + for (var i = 0; i < str.length; ++i) { + // Node's code seems to be doing this and not & 0x7F.. + byteArray.push(str.charCodeAt(i) & 0xFF) } - // set default options - if (isUndefined(ctx.showHidden)) ctx.showHidden = false; - if (isUndefined(ctx.depth)) ctx.depth = 2; - if (isUndefined(ctx.colors)) ctx.colors = false; - if (isUndefined(ctx.customInspect)) ctx.customInspect = true; - if (ctx.colors) ctx.stylize = stylizeWithColor; - return formatValue(ctx, obj, ctx.depth); + return byteArray } - exports.inspect = inspect; - - // http://en.wikipedia.org/wiki/ANSI_escape_code#graphics - inspect.colors = { - 'bold' : [1, 22], - 'italic' : [3, 23], - 'underline' : [4, 24], - 'inverse' : [7, 27], - 'white' : [37, 39], - 'grey' : [90, 39], - 'black' : [30, 39], - 'blue' : [34, 39], - 'cyan' : [36, 39], - 'green' : [32, 39], - 'magenta' : [35, 39], - 'red' : [31, 39], - 'yellow' : [33, 39] - }; + function utf16leToBytes (str, units) { + var c, hi, lo + var byteArray = [] + for (var i = 0; i < str.length; ++i) { + if ((units -= 2) < 0) break - // Don't use 'blue' not visible on cmd.exe - inspect.styles = { - 'special': 'cyan', - 'number': 'yellow', - 'boolean': 'yellow', - 'undefined': 'grey', - 'null': 'bold', - 'string': 'green', - 'date': 'magenta', - // "name": intentionally not styling - 'regexp': 'red' - }; + c = str.charCodeAt(i) + hi = c >> 8 + lo = c % 256 + byteArray.push(lo) + byteArray.push(hi) + } + return byteArray + } - function stylizeWithColor(str, styleType) { - var style = inspect.styles[styleType]; + function base64ToBytes (str) { + return base64.toByteArray(base64clean(str)) + } - if (style) { - return '\u001b[' + inspect.colors[style][0] + 'm' + str + - '\u001b[' + inspect.colors[style][1] + 'm'; - } else { - return str; + function blitBuffer (src, dst, offset, length) { + for (var i = 0; i < length; ++i) { + if ((i + offset >= dst.length) || (i >= src.length)) break + dst[i + offset] = src[i] } + return i } - - function stylizeNoColor(str, styleType) { - return str; + function isnan (val) { + return val !== val // eslint-disable-line no-self-compare } + /* WEBPACK VAR INJECTION */}.call(exports, (function() { return this; }()))) - function arrayToHash(array) { - var hash = {}; +/***/ }, +/* 57 */ +/***/ function(module, exports) { - array.forEach(function(val, idx) { - hash[val] = true; - }); + 'use strict' - return hash; + exports.byteLength = byteLength + exports.toByteArray = toByteArray + exports.fromByteArray = fromByteArray + + var lookup = [] + var revLookup = [] + var Arr = typeof Uint8Array !== 'undefined' ? Uint8Array : Array + + var code = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/' + for (var i = 0, len = code.length; i < len; ++i) { + lookup[i] = code[i] + revLookup[code.charCodeAt(i)] = i } + revLookup['-'.charCodeAt(0)] = 62 + revLookup['_'.charCodeAt(0)] = 63 - function formatValue(ctx, value, recurseTimes) { - // Provide a hook for user-specified inspect functions. - // Check that value is an object with an inspect function on it - if (ctx.customInspect && - value && - isFunction(value.inspect) && - // Filter out the util module, it's inspect function is special - value.inspect !== exports.inspect && - // Also filter out any prototype objects using the circular check. - !(value.constructor && value.constructor.prototype === value)) { - var ret = value.inspect(recurseTimes, ctx); - if (!isString(ret)) { - ret = formatValue(ctx, ret, recurseTimes); - } - return ret; + function placeHoldersCount (b64) { + var len = b64.length + if (len % 4 > 0) { + throw new Error('Invalid string. Length must be a multiple of 4') } - // Primitive types cannot have properties - var primitive = formatPrimitive(ctx, value); - if (primitive) { - return primitive; - } + // the number of equal signs (place holders) + // if there are two placeholders, than the two characters before it + // represent one byte + // if there is only one, then the three characters before it represent 2 bytes + // this is just a cheap hack to not do indexOf twice + return b64[len - 2] === '=' ? 2 : b64[len - 1] === '=' ? 1 : 0 + } - // Look up the keys of the object. - var keys = Object.keys(value); - var visibleKeys = arrayToHash(keys); + function byteLength (b64) { + // base64 is 4/3 + up to two characters of the original data + return b64.length * 3 / 4 - placeHoldersCount(b64) + } - if (ctx.showHidden) { - keys = Object.getOwnPropertyNames(value); - } + function toByteArray (b64) { + var i, j, l, tmp, placeHolders, arr + var len = b64.length + placeHolders = placeHoldersCount(b64) - // IE doesn't make error fields non-enumerable - // http://msdn.microsoft.com/en-us/library/ie/dww52sbt(v=vs.94).aspx - if (isError(value) - && (keys.indexOf('message') >= 0 || keys.indexOf('description') >= 0)) { - return formatError(value); - } + arr = new Arr(len * 3 / 4 - placeHolders) - // Some type of object without properties can be shortcutted. - if (keys.length === 0) { - if (isFunction(value)) { - var name = value.name ? ': ' + value.name : ''; - return ctx.stylize('[Function' + name + ']', 'special'); - } - if (isRegExp(value)) { - return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp'); - } - if (isDate(value)) { - return ctx.stylize(Date.prototype.toString.call(value), 'date'); - } - if (isError(value)) { - return formatError(value); - } - } + // if there are placeholders, only get up to the last complete 4 chars + l = placeHolders > 0 ? len - 4 : len - var base = '', array = false, braces = ['{', '}']; + var L = 0 - // Make Array say that they are Array - if (isArray(value)) { - array = true; - braces = ['[', ']']; + for (i = 0, j = 0; i < l; i += 4, j += 3) { + tmp = (revLookup[b64.charCodeAt(i)] << 18) | (revLookup[b64.charCodeAt(i + 1)] << 12) | (revLookup[b64.charCodeAt(i + 2)] << 6) | revLookup[b64.charCodeAt(i + 3)] + arr[L++] = (tmp >> 16) & 0xFF + arr[L++] = (tmp >> 8) & 0xFF + arr[L++] = tmp & 0xFF } - // Make functions say that they are functions - if (isFunction(value)) { - var n = value.name ? ': ' + value.name : ''; - base = ' [Function' + n + ']'; + if (placeHolders === 2) { + tmp = (revLookup[b64.charCodeAt(i)] << 2) | (revLookup[b64.charCodeAt(i + 1)] >> 4) + arr[L++] = tmp & 0xFF + } else if (placeHolders === 1) { + tmp = (revLookup[b64.charCodeAt(i)] << 10) | (revLookup[b64.charCodeAt(i + 1)] << 4) | (revLookup[b64.charCodeAt(i + 2)] >> 2) + arr[L++] = (tmp >> 8) & 0xFF + arr[L++] = tmp & 0xFF } - // Make RegExps say that they are RegExps - if (isRegExp(value)) { - base = ' ' + RegExp.prototype.toString.call(value); - } + return arr + } - // Make dates with properties first say the date - if (isDate(value)) { - base = ' ' + Date.prototype.toUTCString.call(value); - } + function tripletToBase64 (num) { + return lookup[num >> 18 & 0x3F] + lookup[num >> 12 & 0x3F] + lookup[num >> 6 & 0x3F] + lookup[num & 0x3F] + } - // Make error with message first say the error - if (isError(value)) { - base = ' ' + formatError(value); + function encodeChunk (uint8, start, end) { + var tmp + var output = [] + for (var i = start; i < end; i += 3) { + tmp = (uint8[i] << 16) + (uint8[i + 1] << 8) + (uint8[i + 2]) + output.push(tripletToBase64(tmp)) } + return output.join('') + } - if (keys.length === 0 && (!array || value.length == 0)) { - return braces[0] + base + braces[1]; - } + function fromByteArray (uint8) { + var tmp + var len = uint8.length + var extraBytes = len % 3 // if we have 1 byte left, pad 2 bytes + var output = '' + var parts = [] + var maxChunkLength = 16383 // must be multiple of 3 - if (recurseTimes < 0) { - if (isRegExp(value)) { - return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp'); - } else { - return ctx.stylize('[Object]', 'special'); - } + // go through the array every three bytes, we'll deal with trailing stuff later + for (var i = 0, len2 = len - extraBytes; i < len2; i += maxChunkLength) { + parts.push(encodeChunk(uint8, i, (i + maxChunkLength) > len2 ? len2 : (i + maxChunkLength))) } - ctx.seen.push(value); - - var output; - if (array) { - output = formatArray(ctx, value, recurseTimes, visibleKeys, keys); - } else { - output = keys.map(function(key) { - return formatProperty(ctx, value, recurseTimes, visibleKeys, key, array); - }); + // pad the end with zeros, but make sure to not forget the extra bytes + if (extraBytes === 1) { + tmp = uint8[len - 1] + output += lookup[tmp >> 2] + output += lookup[(tmp << 4) & 0x3F] + output += '==' + } else if (extraBytes === 2) { + tmp = (uint8[len - 2] << 8) + (uint8[len - 1]) + output += lookup[tmp >> 10] + output += lookup[(tmp >> 4) & 0x3F] + output += lookup[(tmp << 2) & 0x3F] + output += '=' } - ctx.seen.pop(); + parts.push(output) - return reduceToSingleString(output, base, braces); + return parts.join('') } - function formatPrimitive(ctx, value) { - if (isUndefined(value)) - return ctx.stylize('undefined', 'undefined'); - if (isString(value)) { - var simple = '\'' + JSON.stringify(value).replace(/^"|"$/g, '') - .replace(/'/g, "\\'") - .replace(/\\"/g, '"') + '\''; - return ctx.stylize(simple, 'string'); +/***/ }, +/* 58 */ +/***/ function(module, exports) { + + exports.read = function (buffer, offset, isLE, mLen, nBytes) { + var e, m + var eLen = nBytes * 8 - mLen - 1 + var eMax = (1 << eLen) - 1 + var eBias = eMax >> 1 + var nBits = -7 + var i = isLE ? (nBytes - 1) : 0 + var d = isLE ? -1 : 1 + var s = buffer[offset + i] + + i += d + + e = s & ((1 << (-nBits)) - 1) + s >>= (-nBits) + nBits += eLen + for (; nBits > 0; e = e * 256 + buffer[offset + i], i += d, nBits -= 8) {} + + m = e & ((1 << (-nBits)) - 1) + e >>= (-nBits) + nBits += mLen + for (; nBits > 0; m = m * 256 + buffer[offset + i], i += d, nBits -= 8) {} + + if (e === 0) { + e = 1 - eBias + } else if (e === eMax) { + return m ? NaN : ((s ? -1 : 1) * Infinity) + } else { + m = m + Math.pow(2, mLen) + e = e - eBias } - if (isNumber(value)) - return ctx.stylize('' + value, 'number'); - if (isBoolean(value)) - return ctx.stylize('' + value, 'boolean'); - // For some reason typeof null is "object", so special case here. - if (isNull(value)) - return ctx.stylize('null', 'null'); + return (s ? -1 : 1) * m * Math.pow(2, e - mLen) } + exports.write = function (buffer, value, offset, isLE, mLen, nBytes) { + var e, m, c + var eLen = nBytes * 8 - mLen - 1 + var eMax = (1 << eLen) - 1 + var eBias = eMax >> 1 + var rt = (mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0) + var i = isLE ? 0 : (nBytes - 1) + var d = isLE ? 1 : -1 + var s = value < 0 || (value === 0 && 1 / value < 0) ? 1 : 0 - function formatError(value) { - return '[' + Error.prototype.toString.call(value) + ']'; - } + value = Math.abs(value) + if (isNaN(value) || value === Infinity) { + m = isNaN(value) ? 1 : 0 + e = eMax + } else { + e = Math.floor(Math.log(value) / Math.LN2) + if (value * (c = Math.pow(2, -e)) < 1) { + e-- + c *= 2 + } + if (e + eBias >= 1) { + value += rt / c + } else { + value += rt * Math.pow(2, 1 - eBias) + } + if (value * c >= 2) { + e++ + c /= 2 + } - function formatArray(ctx, value, recurseTimes, visibleKeys, keys) { - var output = []; - for (var i = 0, l = value.length; i < l; ++i) { - if (hasOwnProperty(value, String(i))) { - output.push(formatProperty(ctx, value, recurseTimes, visibleKeys, - String(i), true)); + if (e + eBias >= eMax) { + m = 0 + e = eMax + } else if (e + eBias >= 1) { + m = (value * c - 1) * Math.pow(2, mLen) + e = e + eBias } else { - output.push(''); + m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen) + e = 0 } } - keys.forEach(function(key) { - if (!key.match(/^\d+$/)) { - output.push(formatProperty(ctx, value, recurseTimes, visibleKeys, - key, true)); - } - }); - return output; + + for (; mLen >= 8; buffer[offset + i] = m & 0xff, i += d, m /= 256, mLen -= 8) {} + + e = (e << mLen) | m + eLen += mLen + for (; eLen > 0; buffer[offset + i] = e & 0xff, i += d, e /= 256, eLen -= 8) {} + + buffer[offset + i - d] |= s * 128 } - function formatProperty(ctx, value, recurseTimes, visibleKeys, key, array) { - var name, str, desc; - desc = Object.getOwnPropertyDescriptor(value, key) || { value: value[key] }; - if (desc.get) { - if (desc.set) { - str = ctx.stylize('[Getter/Setter]', 'special'); - } else { - str = ctx.stylize('[Getter]', 'special'); +/***/ }, +/* 59 */ +/***/ function(module, exports, __webpack_require__) { + + /* WEBPACK VAR INJECTION */(function(global) {'use strict'; + + var buffer = __webpack_require__(56); + var Buffer = buffer.Buffer; + var SlowBuffer = buffer.SlowBuffer; + var MAX_LEN = buffer.kMaxLength || 2147483647; + exports.alloc = function alloc(size, fill, encoding) { + if (typeof Buffer.alloc === 'function') { + return Buffer.alloc(size, fill, encoding); + } + if (typeof encoding === 'number') { + throw new TypeError('encoding must not be number'); + } + if (typeof size !== 'number') { + throw new TypeError('size must be a number'); + } + if (size > MAX_LEN) { + throw new RangeError('size is too large'); + } + var enc = encoding; + var _fill = fill; + if (_fill === undefined) { + enc = undefined; + _fill = 0; + } + var buf = new Buffer(size); + if (typeof _fill === 'string') { + var fillBuf = new Buffer(_fill, enc); + var flen = fillBuf.length; + var i = -1; + while (++i < size) { + buf[i] = fillBuf[i % flen]; } } else { - if (desc.set) { - str = ctx.stylize('[Setter]', 'special'); - } + buf.fill(_fill); } - if (!hasOwnProperty(visibleKeys, key)) { - name = '[' + key + ']'; + return buf; + } + exports.allocUnsafe = function allocUnsafe(size) { + if (typeof Buffer.allocUnsafe === 'function') { + return Buffer.allocUnsafe(size); } - if (!str) { - if (ctx.seen.indexOf(desc.value) < 0) { - if (isNull(recurseTimes)) { - str = formatValue(ctx, desc.value, null); - } else { - str = formatValue(ctx, desc.value, recurseTimes - 1); - } - if (str.indexOf('\n') > -1) { - if (array) { - str = str.split('\n').map(function(line) { - return ' ' + line; - }).join('\n').substr(2); - } else { - str = '\n' + str.split('\n').map(function(line) { - return ' ' + line; - }).join('\n'); - } - } - } else { - str = ctx.stylize('[Circular]', 'special'); + if (typeof size !== 'number') { + throw new TypeError('size must be a number'); + } + if (size > MAX_LEN) { + throw new RangeError('size is too large'); + } + return new Buffer(size); + } + exports.from = function from(value, encodingOrOffset, length) { + if (typeof Buffer.from === 'function' && (!global.Uint8Array || Uint8Array.from !== Buffer.from)) { + return Buffer.from(value, encodingOrOffset, length); + } + if (typeof value === 'number') { + throw new TypeError('"value" argument must not be a number'); + } + if (typeof value === 'string') { + return new Buffer(value, encodingOrOffset); + } + if (typeof ArrayBuffer !== 'undefined' && value instanceof ArrayBuffer) { + var offset = encodingOrOffset; + if (arguments.length === 1) { + return new Buffer(value); + } + if (typeof offset === 'undefined') { + offset = 0; + } + var len = length; + if (typeof len === 'undefined') { + len = value.byteLength - offset; + } + if (offset >= value.byteLength) { + throw new RangeError('\'offset\' is out of bounds'); } + if (len > value.byteLength - offset) { + throw new RangeError('\'length\' is out of bounds'); + } + return new Buffer(value.slice(offset, offset + len)); } - if (isUndefined(name)) { - if (array && key.match(/^\d+$/)) { - return str; + if (Buffer.isBuffer(value)) { + var out = new Buffer(value.length); + value.copy(out, 0, 0, value.length); + return out; + } + if (value) { + if (Array.isArray(value) || (typeof ArrayBuffer !== 'undefined' && value.buffer instanceof ArrayBuffer) || 'length' in value) { + return new Buffer(value); } - name = JSON.stringify('' + key); - if (name.match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)) { - name = name.substr(1, name.length - 2); - name = ctx.stylize(name, 'name'); - } else { - name = name.replace(/'/g, "\\'") - .replace(/\\"/g, '"') - .replace(/(^"|"$)/g, "'"); - name = ctx.stylize(name, 'string'); + if (value.type === 'Buffer' && Array.isArray(value.data)) { + return new Buffer(value.data); } } - return name + ': ' + str; + throw new TypeError('First argument must be a string, Buffer, ' + 'ArrayBuffer, Array, or array-like object.'); } - - - function reduceToSingleString(output, base, braces) { - var numLinesEst = 0; - var length = output.reduce(function(prev, cur) { - numLinesEst++; - if (cur.indexOf('\n') >= 0) numLinesEst++; - return prev + cur.replace(/\u001b\[\d\d?m/g, '').length + 1; - }, 0); - - if (length > 60) { - return braces[0] + - (base === '' ? '' : base + '\n ') + - ' ' + - output.join(',\n ') + - ' ' + - braces[1]; + exports.allocUnsafeSlow = function allocUnsafeSlow(size) { + if (typeof Buffer.allocUnsafeSlow === 'function') { + return Buffer.allocUnsafeSlow(size); } - - return braces[0] + base + ' ' + output.join(', ') + ' ' + braces[1]; + if (typeof size !== 'number') { + throw new TypeError('size must be a number'); + } + if (size >= MAX_LEN) { + throw new RangeError('size is too large'); + } + return new SlowBuffer(size); } + /* WEBPACK VAR INJECTION */}.call(exports, (function() { return this; }()))) + +/***/ }, +/* 60 */ +/***/ function(module, exports, __webpack_require__) { + + /* WEBPACK VAR INJECTION */(function(Buffer) {// Copyright Joyent, Inc. and other Node contributors. + // + // Permission is hereby granted, free of charge, to any person obtaining a + // copy of this software and associated documentation files (the + // "Software"), to deal in the Software without restriction, including + // without limitation the rights to use, copy, modify, merge, publish, + // distribute, sublicense, and/or sell copies of the Software, and to permit + // persons to whom the Software is furnished to do so, subject to the + // following conditions: + // + // The above copyright notice and this permission notice shall be included + // in all copies or substantial portions of the Software. + // + // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN + // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, + // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR + // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE + // USE OR OTHER DEALINGS IN THE SOFTWARE. // NOTE: These type checking functions intentionally don't use `instanceof` // because it is fragile and can be easily faked with `Object.create()`. - function isArray(ar) { - return Array.isArray(ar); + + function isArray(arg) { + if (Array.isArray) { + return Array.isArray(arg); + } + return objectToString(arg) === '[object Array]'; } exports.isArray = isArray; @@ -16815,7 +15665,7 @@ var qtk = exports.isUndefined = isUndefined; function isRegExp(re) { - return isObject(re) && objectToString(re) === '[object RegExp]'; + return objectToString(re) === '[object RegExp]'; } exports.isRegExp = isRegExp; @@ -16825,13 +15675,12 @@ var qtk = exports.isObject = isObject; function isDate(d) { - return isObject(d) && objectToString(d) === '[object Date]'; + return objectToString(d) === '[object Date]'; } exports.isDate = isDate; function isError(e) { - return isObject(e) && - (objectToString(e) === '[object Error]' || e instanceof Error); + return (objectToString(e) === '[object Error]' || e instanceof Error); } exports.isError = isError; @@ -16850,12771 +15699,15286 @@ var qtk = } exports.isPrimitive = isPrimitive; - exports.isBuffer = __webpack_require__(71); + exports.isBuffer = Buffer.isBuffer; function objectToString(o) { return Object.prototype.toString.call(o); } + /* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(56).Buffer)) - function pad(n) { - return n < 10 ? '0' + n.toString(10) : n.toString(10); - } +/***/ }, +/* 61 */ +/***/ function(module, exports) { + /* (ignored) */ - var months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', - 'Oct', 'Nov', 'Dec']; +/***/ }, +/* 62 */ +/***/ function(module, exports, __webpack_require__) { - // 26 Feb 16:19:34 - function timestamp() { - var d = new Date(); - var time = [pad(d.getHours()), - pad(d.getMinutes()), - pad(d.getSeconds())].join(':'); - return [d.getDate(), months[d.getMonth()], time].join(' '); + 'use strict'; + + var Buffer = __webpack_require__(56).Buffer; + /**/ + var bufferShim = __webpack_require__(59); + /**/ + + module.exports = BufferList; + + function BufferList() { + this.head = null; + this.tail = null; + this.length = 0; } + BufferList.prototype.push = function (v) { + var entry = { data: v, next: null }; + if (this.length > 0) this.tail.next = entry;else this.head = entry; + this.tail = entry; + ++this.length; + }; - // log is just a thin wrapper to console.log that prepends a timestamp - exports.log = function() { - console.log('%s - %s', timestamp(), exports.format.apply(exports, arguments)); + BufferList.prototype.unshift = function (v) { + var entry = { data: v, next: this.head }; + if (this.length === 0) this.tail = entry; + this.head = entry; + ++this.length; }; + BufferList.prototype.shift = function () { + if (this.length === 0) return; + var ret = this.head.data; + if (this.length === 1) this.head = this.tail = null;else this.head = this.head.next; + --this.length; + return ret; + }; - /** - * Inherit the prototype methods from one constructor into another. - * - * The Function.prototype.inherits from lang.js rewritten as a standalone - * function (not on Function.prototype). NOTE: If this file is to be loaded - * during bootstrapping this function needs to be rewritten using some native - * functions as prototype setup using normal JavaScript does not work as - * expected during bootstrapping (see mirror.js in r114903). - * - * @param {function} ctor Constructor function which needs to inherit the - * prototype. - * @param {function} superCtor Constructor function to inherit prototype from. - */ - exports.inherits = __webpack_require__(51); + BufferList.prototype.clear = function () { + this.head = this.tail = null; + this.length = 0; + }; - exports._extend = function(origin, add) { - // Don't do anything if add isn't an object - if (!add || !isObject(add)) return origin; + BufferList.prototype.join = function (s) { + if (this.length === 0) return ''; + var p = this.head; + var ret = '' + p.data; + while (p = p.next) { + ret += s + p.data; + }return ret; + }; - var keys = Object.keys(add); - var i = keys.length; - while (i--) { - origin[keys[i]] = add[keys[i]]; + BufferList.prototype.concat = function (n) { + if (this.length === 0) return bufferShim.alloc(0); + if (this.length === 1) return this.head.data; + var ret = bufferShim.allocUnsafe(n >>> 0); + var p = this.head; + var i = 0; + while (p) { + p.data.copy(ret, i); + i += p.data.length; + p = p.next; } - return origin; + return ret; }; - function hasOwnProperty(obj, prop) { - return Object.prototype.hasOwnProperty.call(obj, prop); +/***/ }, +/* 63 */ +/***/ function(module, exports, __webpack_require__) { + + // a duplex stream is just a stream that is both readable and writable. + // Since JS doesn't have multiple prototypal inheritance, this class + // prototypally inherits from Readable, and then parasitically from + // Writable. + + 'use strict'; + + /**/ + + var objectKeys = Object.keys || function (obj) { + var keys = []; + for (var key in obj) { + keys.push(key); + }return keys; + }; + /**/ + + module.exports = Duplex; + + /**/ + var processNextTick = __webpack_require__(54); + /**/ + + /**/ + var util = __webpack_require__(60); + util.inherits = __webpack_require__(51); + /**/ + + var Readable = __webpack_require__(53); + var Writable = __webpack_require__(64); + + util.inherits(Duplex, Readable); + + var keys = objectKeys(Writable.prototype); + for (var v = 0; v < keys.length; v++) { + var method = keys[v]; + if (!Duplex.prototype[method]) Duplex.prototype[method] = Writable.prototype[method]; } - /* WEBPACK VAR INJECTION */}.call(exports, (function() { return this; }()), __webpack_require__(10))) + function Duplex(options) { + if (!(this instanceof Duplex)) return new Duplex(options); -/***/ }, -/* 71 */ -/***/ function(module, exports) { + Readable.call(this, options); + Writable.call(this, options); - module.exports = function isBuffer(arg) { - return arg && typeof arg === 'object' - && typeof arg.copy === 'function' - && typeof arg.fill === 'function' - && typeof arg.readUInt8 === 'function'; + if (options && options.readable === false) this.readable = false; + + if (options && options.writable === false) this.writable = false; + + this.allowHalfOpen = true; + if (options && options.allowHalfOpen === false) this.allowHalfOpen = false; + + this.once('end', onend); + } + + // the no-half-open enforcer + function onend() { + // if we allow half-open state, or if the writable side ended, + // then we're ok. + if (this.allowHalfOpen || this._writableState.ended) return; + + // no more data can be written. + // But allow more writes to happen in this tick. + processNextTick(onEndNT, this); + } + + function onEndNT(self) { + self.end(); + } + + function forEach(xs, f) { + for (var i = 0, l = xs.length; i < l; i++) { + f(xs[i], i); + } } /***/ }, -/* 72 */ -/***/ function(module, exports) { +/* 64 */ +/***/ function(module, exports, __webpack_require__) { - module.exports = { - OP: 0, - CL: 1, - CP: 2, - QU: 3, - GL: 4, - NS: 5, - EX: 6, - SY: 7, - IS: 8, - PR: 9, - PO: 10, - NU: 11, - AL: 12, - HL: 13, - ID: 14, - IN: 15, - HY: 16, - BA: 17, - BB: 18, - B2: 19, - ZW: 20, - CM: 21, - WJ: 22, - H2: 23, - H3: 24, - JL: 25, - JV: 26, - JT: 27, + /* WEBPACK VAR INJECTION */(function(process, setImmediate) {// A bit simpler than readable streams. + // Implement an async ._write(chunk, encoding, cb), and it'll handle all + // the drain event emission and buffering. + + 'use strict'; + + module.exports = Writable; + + /**/ + var processNextTick = __webpack_require__(54); + /**/ + + /**/ + var asyncWrite = !process.browser && ['v0.10', 'v0.9.'].indexOf(process.version.slice(0, 5)) > -1 ? setImmediate : processNextTick; + /**/ + + /**/ + var Duplex; + /**/ + + Writable.WritableState = WritableState; + + /**/ + var util = __webpack_require__(60); + util.inherits = __webpack_require__(51); + /**/ + + /**/ + var internalUtil = { + deprecate: __webpack_require__(67) + }; + /**/ + + /**/ + var Stream; + (function () { + try { + Stream = __webpack_require__(49); + } catch (_) {} finally { + if (!Stream) Stream = __webpack_require__(50).EventEmitter; + } + })(); + /**/ + + var Buffer = __webpack_require__(56).Buffer; + /**/ + var bufferShim = __webpack_require__(59); + /**/ + + util.inherits(Writable, Stream); + + function nop() {} + + function WriteReq(chunk, encoding, cb) { + this.chunk = chunk; + this.encoding = encoding; + this.callback = cb; + this.next = null; + } + + function WritableState(options, stream) { + Duplex = Duplex || __webpack_require__(63); + + options = options || {}; + + // object stream flag to indicate whether or not this stream + // contains buffers or objects. + this.objectMode = !!options.objectMode; + + if (stream instanceof Duplex) this.objectMode = this.objectMode || !!options.writableObjectMode; + + // the point at which write() starts returning false + // Note: 0 is a valid value, means that we always return false if + // the entire buffer is not flushed immediately on write() + var hwm = options.highWaterMark; + var defaultHwm = this.objectMode ? 16 : 16 * 1024; + this.highWaterMark = hwm || hwm === 0 ? hwm : defaultHwm; + + // cast to ints. + this.highWaterMark = ~ ~this.highWaterMark; + + // drain event flag. + this.needDrain = false; + // at the start of calling end() + this.ending = false; + // when end() has been called, and returned + this.ended = false; + // when 'finish' is emitted + this.finished = false; + + // should we decode strings into buffers before passing to _write? + // this is here so that some node-core streams can optimize string + // handling at a lower level. + var noDecode = options.decodeStrings === false; + this.decodeStrings = !noDecode; - // Non-standard - SP: 28, - LF: 29, - NL: 30, - BK: 31, - CR: 32, - XX: 33 - }; + // Crypto is kind of old and crusty. Historically, its default string + // encoding is 'binary' so we have to make this configurable. + // Everything else in the universe uses 'utf8', though. + this.defaultEncoding = options.defaultEncoding || 'utf8'; + // not an actual buffer we keep track of, but a measurement + // of how much we're waiting to get pushed to some underlying + // socket or file. + this.length = 0; + // a flag to see when we're in the middle of a write. + this.writing = false; -/***/ }, -/* 73 */ -/***/ function(module, exports) { + // when true all writes will be buffered until .uncork() call + this.corked = 0; - module.exports = { - // A line break opportunity exists between two adjacent - // characters of the given line breaking classes. - // Example: break before an em-dash - DIRECT: 0, + // a flag to be able to tell if the onwrite cb is called immediately, + // or on a later tick. We set this to true at first, because any + // actions that shouldn't happen until "later" should generally also + // not happen before the first write call. + this.sync = true; - // A line break opportunity exists between two characters - // of the given line breaking classes only if they are - // separated by one or more spaces. - // Example: two words separated by a space - INDIRECT: 1, + // a flag to know if we're processing previously buffered items, which + // may call the _write() callback in the same tick, so that we don't + // end up in an overlapped onwrite situation. + this.bufferProcessing = false; - COMBINING_INDIRECT: 2, + // the callback that's passed to _write(chunk,cb) + this.onwrite = function (er) { + onwrite(stream, er); + }; - COMBINING_PROHIBITED: 3, + // the callback that the user supplies to write(chunk,encoding,cb) + this.writecb = null; - // No line break opportunity exists between two characters - // of the given line breaking classes, even if they are - // separated by one or more space characters. - // Example: non-breaking space - PROHIBITED: 4, + // the amount that is being written when _write is called. + this.writelen = 0; - // A line must break following a character that has the - // mandatory break property. - EXPLICIT: 5 - }; + this.bufferedRequest = null; + this.lastBufferedRequest = null; + // number of pending user-supplied write callbacks + // this must be 0 before 'finish' can be emitted + this.pendingcb = 0; -/***/ }, -/* 74 */ -/***/ function(module, exports, __webpack_require__) { + // emit prefinish if the only thing we're waiting for is _write cbs + // This is relevant for synchronous Transform streams + this.prefinished = false; - var util = __webpack_require__(70), - Stream = __webpack_require__(49).Stream, - types = __webpack_require__(72), - tokens = __webpack_require__(75), - tokenClasses = Object.keys(tokens), - tokenRegExp = {}; + // True if the error was already emitted and should not be thrown again + this.errorEmitted = false; - tokenClasses.forEach(function(tokenClass) { - tokenRegExp[tokenClass] = new RegExp('^(' + tokens[tokenClass] + ')+'); - }); + // count buffered requests + this.bufferedRequestCount = 0; - function tokenizeSync(str) { - var result = []; + // allocate the first CorkedRequest, there is always + // one allocated and free to use, and we maintain at most two + this.corkedRequestsFree = new CorkedRequest(this); + } - while (str) { - var found = false; + WritableState.prototype.getBuffer = function getBuffer() { + var current = this.bufferedRequest; + var out = []; + while (current) { + out.push(current); + current = current.next; + } + return out; + }; - for (var i = 0; i < tokenClasses.length; i += 1) { - var type = tokenClasses[i], - m = tokenRegExp[type].exec(str); + (function () { + try { + Object.defineProperty(WritableState.prototype, 'buffer', { + get: internalUtil.deprecate(function () { + return this.getBuffer(); + }, '_writableState.buffer is deprecated. Use _writableState.getBuffer ' + 'instead.') + }); + } catch (_) {} + })(); - if (m) { - var token = m[0]; - result.push({ - token: token, - type: types[type] - }); - str = str.substring(token.length); - found = true; - } - } + // Test _writableState for inheritance to account for Duplex streams, + // whose prototype chain only points to Readable. + var realHasInstance; + if (typeof Symbol === 'function' && Symbol.hasInstance && typeof Function.prototype[Symbol.hasInstance] === 'function') { + realHasInstance = Function.prototype[Symbol.hasInstance]; + Object.defineProperty(Writable, Symbol.hasInstance, { + value: function (object) { + if (realHasInstance.call(this, object)) return true; - if (!found) { - result.push({ - token: str, - type: types.XX - }); - break; - } + return object && object._writableState instanceof WritableState; } - return result; - }; + }); + } else { + realHasInstance = function (object) { + return object instanceof this; + }; + } - function tokenize(str, callback) { - var result = []; + function Writable(options) { + Duplex = Duplex || __webpack_require__(63); - while (str) { - var found = false; + // Writable ctor is applied to Duplexes, too. + // `realHasInstance` is necessary because using plain `instanceof` + // would return false, as no `_writableState` property is attached. - for (var i = 0; i < tokenClasses.length; i += 1) { - var type = tokenClasses[i], - m = tokenRegExp[type].exec(str); + // Trying to use the custom `instanceof` for Writable here will also break the + // Node.js LazyTransform implementation, which has a non-trivial getter for + // `_writableState` that would lead to infinite recursion. + if (!realHasInstance.call(Writable, this) && !(this instanceof Duplex)) { + return new Writable(options); + } - if (m) { - var token = m[0]; - callback(token, types[type]); - str = str.substring(token.length); - found = true; - } - } + this._writableState = new WritableState(options, this); - if (!found) { - callback(str, types['XX']); - break; - } - } + // legacy. + this.writable = true; + + if (options) { + if (typeof options.write === 'function') this._write = options.write; + + if (typeof options.writev === 'function') this._writev = options.writev; + } + + Stream.call(this); } - function Tokenizer() { - Stream.call(this); - this.readable = true; - this.writable = true; + // Otherwise people can pipe Writable streams, which is just wrong. + Writable.prototype.pipe = function () { + this.emit('error', new Error('Cannot pipe, not readable')); + }; + + function writeAfterEnd(stream, cb) { + var er = new Error('write after end'); + // TODO: defer error events consistently everywhere, not just the cb + stream.emit('error', er); + processNextTick(cb, er); } - util.inherits(Tokenizer, Stream); + // If we get something that is not a buffer, string, null, or undefined, + // and we're not in objectMode, then that's an error. + // Otherwise stream chunks are all considered to be of length=1, and the + // watermarks determine how many objects to keep in the buffer, rather than + // how many bytes or characters. + function validChunk(stream, state, chunk, cb) { + var valid = true; + var er = false; + // Always throw error if a null is written + // if we are not in object mode then throw + // if it is not a buffer, string, or undefined. + if (chunk === null) { + er = new TypeError('May not write null values to stream'); + } else if (!Buffer.isBuffer(chunk) && typeof chunk !== 'string' && chunk !== undefined && !state.objectMode) { + er = new TypeError('Invalid non-string/buffer chunk'); + } + if (er) { + stream.emit('error', er); + processNextTick(cb, er); + valid = false; + } + return valid; + } - Tokenizer.prototype.write = function(chunk) { - var that = this; + Writable.prototype.write = function (chunk, encoding, cb) { + var state = this._writableState; + var ret = false; - tokenize(chunk.toString('utf8'), function(token, type) { - that.emit('data', token); - that.emit('token', token, type); - }); - }; + if (typeof encoding === 'function') { + cb = encoding; + encoding = null; + } - Tokenizer.prototype.end = function(data) { - if (data) { - this.write(data); - } - this.emit('end'); - }; + if (Buffer.isBuffer(chunk)) encoding = 'buffer';else if (!encoding) encoding = state.defaultEncoding; - module.exports = { - Tokenizer: Tokenizer, - createTokenizer: function() { - return new Tokenizer(); - }, - tokenize: tokenize, - tokenizeSync: tokenizeSync - }; + if (typeof cb !== 'function') cb = nop; + if (state.ended) writeAfterEnd(this, cb);else if (validChunk(this, state, chunk, cb)) { + state.pendingcb++; + ret = writeOrBuffer(this, state, chunk, encoding, cb); + } -/***/ }, -/* 75 */ -/***/ function(module, exports) { + return ret; + }; - // This file is auto-generated. Do not modify. - module.exports = { - "CM": "[\\u0000-\\u0008\\u000E-\\u001F\\u007F-\\u0084\\u0086-\\u009F\\u0300-\\u034E\\u0350-\\u035B\\u0363-\\u036F\\u0483-\\u0489\\u0591-\\u05BD\\u05BF\\u05C1\\u05C2\\u05C4\\u05C5\\u05C7\\u0610-\\u061A\\u064B-\\u065F\\u0670\\u06D6-\\u06DC\\u06DF-\\u06E4\\u06E7\\u06E8\\u06EA-\\u06ED\\u0711\\u0730-\\u074A\\u07A6-\\u07B0\\u07EB-\\u07F3\\u0816-\\u0819\\u081B-\\u0823\\u0825-\\u0827\\u0829-\\u082D\\u0859-\\u085B\\u08E4-\\u08FE\\u0900-\\u0903\\u093A-\\u093C\\u093E-\\u094F\\u0951-\\u0957\\u0962\\u0963\\u0981-\\u0983\\u09BC\\u09BE-\\u09C4\\u09C7\\u09C8\\u09CB-\\u09CD\\u09D7\\u09E2\\u09E3\\u0A01-\\u0A03\\u0A3C\\u0A3E-\\u0A42\\u0A47\\u0A48\\u0A4B-\\u0A4D\\u0A51\\u0A70\\u0A71\\u0A75\\u0A81-\\u0A83\\u0ABC\\u0ABE-\\u0AC5\\u0AC7-\\u0AC9\\u0ACB-\\u0ACD\\u0AE2\\u0AE3\\u0B01-\\u0B03\\u0B3C\\u0B3E-\\u0B44\\u0B47\\u0B48\\u0B4B-\\u0B4D\\u0B56\\u0B57\\u0B62\\u0B63\\u0B82\\u0BBE-\\u0BC2\\u0BC6-\\u0BC8\\u0BCA-\\u0BCD\\u0BD7\\u0C01-\\u0C03\\u0C3E-\\u0C44\\u0C46-\\u0C48\\u0C4A-\\u0C4D\\u0C55\\u0C56\\u0C62\\u0C63\\u0C82\\u0C83\\u0CBC\\u0CBE-\\u0CC4\\u0CC6-\\u0CC8\\u0CCA-\\u0CCD\\u0CD5\\u0CD6\\u0CE2\\u0CE3\\u0D02\\u0D03\\u0D3E-\\u0D44\\u0D46-\\u0D48\\u0D4A-\\u0D4D\\u0D57\\u0D62\\u0D63\\u0D82\\u0D83\\u0DCA\\u0DCF-\\u0DD4\\u0DD6\\u0DD8-\\u0DDF\\u0DF2\\u0DF3\\u0F18\\u0F19\\u0F35\\u0F37\\u0F39\\u0F3E\\u0F3F\\u0F71-\\u0F7E\\u0F80-\\u0F84\\u0F86\\u0F87\\u0F8D-\\u0F97\\u0F99-\\u0FBC\\u0FC6\\u135D-\\u135F\\u1712-\\u1714\\u1732-\\u1734\\u1752\\u1753\\u1772\\u1773\\u180B-\\u180D\\u18A9\\u1920-\\u192B\\u1930-\\u193B\\u1A17-\\u1A1B\\u1A7F\\u1B00-\\u1B04\\u1B34-\\u1B44\\u1B6B-\\u1B73\\u1B80-\\u1B82\\u1BA1-\\u1BAD\\u1BE6-\\u1BF3\\u1C24-\\u1C37\\u1CD0-\\u1CD2\\u1CD4-\\u1CE8\\u1CED\\u1CF2-\\u1CF4\\u1DC0-\\u1DE6\\u1DFC-\\u1DFF\\u200C-\\u200F\\u202A-\\u202E\\u206A-\\u206F\\u20D0-\\u20F0\\u2CEF-\\u2CF1\\u2D7F\\u2DE0-\\u2DFF\\u302A-\\u302F\\u3099\\u309A\\uA66F-\\uA672\\uA674-\\uA67D\\uA69F\\uA6F0\\uA6F1\\uA802\\uA806\\uA80B\\uA823-\\uA827\\uA880\\uA881\\uA8B4-\\uA8C4\\uA8E0-\\uA8F1\\uA926-\\uA92D\\uA947-\\uA953\\uA980-\\uA983\\uA9B3-\\uA9C0\\uAA29-\\uAA36\\uAA43\\uAA4C\\uAA4D\\uAAEB-\\uAAEF\\uAAF5\\uAAF6\\uABE3-\\uABEA\\uABEC\\uABED\\uFB1E\\uFE00-\\uFE0F\\uFE20-\\uFE26\\uFFF9-\\uFFFB]|[\\u5536][\\uDDFD]|[\\u5536][\\uDE01-\\uDE03\\uDE05\\uDE06\\uDE0C-\\uDE0F\\uDE38-\\uDE3A\\uDE3F]|[\\u5536][\\uDC00-\\uDC02\\uDC38-\\uDC46\\uDC80-\\uDC82\\uDCB0-\\uDCBA\\uDD00-\\uDD02\\uDD27-\\uDD34\\uDD80-\\uDD82\\uDDB3-\\uDDC0]|[\\u5536][\\uDEAB-\\uDEB7]|[\\u5536][\\uDF51-\\uDF7E\\uDF8F-\\uDF92]|[\\u5536][\\uDD65-\\uDD69\\uDD6D-\\uDD82\\uDD85-\\uDD8B\\uDDAA-\\uDDAD\\uDE42-\\uDE44]|[\\u5536][\\uDC01\\uDC20-\\uDC7F\\uDD00-\\uDDEF]", - "BA": "[\\u0009\\u007C\\u00AD\\u058A\\u05BE\\u0964\\u0965\\u0E5A\\u0E5B\\u0F0B\\u0F34\\u0F7F\\u0F85\\u0FBE\\u0FBF\\u0FD2\\u104A\\u104B\\u1361\\u1400\\u1680\\u16EB-\\u16ED\\u1735\\u1736\\u17D4\\u17D5\\u17D8\\u17DA\\u1804\\u1805\\u1B5A\\u1B5B\\u1B5D-\\u1B60\\u1C3B-\\u1C3F\\u1C7E\\u1C7F\\u2000-\\u2006\\u2008-\\u200A\\u2010\\u2012\\u2013\\u2027\\u2056\\u2058-\\u205B\\u205D-\\u205F\\u2CFA-\\u2CFC\\u2CFF\\u2D70\\u2E0E-\\u2E15\\u2E17\\u2E19\\u2E2A-\\u2E2D\\u2E30\\u2E31\\u2E33\\u2E34\\uA4FE\\uA4FF\\uA60D\\uA60F\\uA6F3-\\uA6F7\\uA8CE\\uA8CF\\uA92E\\uA92F\\uA9C7-\\uA9C9\\uAA5D-\\uAA5F\\uAAF0\\uAAF1\\uABEB]|[\\u5536][\\uDD00-\\uDD02\\uDF9F\\uDFD0]|[\\u5536][\\uDC57\\uDD1F\\uDE50-\\uDE57\\uDF39-\\uDF3F]|[\\u5536][\\uDC47\\uDC48\\uDCBE-\\uDCC1\\uDD40-\\uDD43\\uDDC5\\uDDC6\\uDDC8]|[\\u5536][\\uDC70-\\uDC73]", - "LF": "[\\u000A]", - "BK": "[\\u000B\\u000C\\u2028\\u2029]", - "CR": "[\\u000D]", - "SP": "[\\u0020]", - "EX": "[\\u0021\\u003F\\u05C6\\u061B\\u061E\\u061F\\u06D4\\u07F9\\u0F0D-\\u0F11\\u0F14\\u1802\\u1803\\u1808\\u1809\\u1944\\u1945\\u2762\\u2763\\u2CF9\\u2CFE\\u2E2E\\uA60E\\uA876\\uA877\\uFE15\\uFE16\\uFE56\\uFE57\\uFF01\\uFF1F]", - "QU": "[\\u0022\\u0027\\u00AB\\u00BB\\u2018\\u2019\\u201B-\\u201D\\u201F\\u2039\\u203A\\u275B-\\u275E\\u2E00-\\u2E0D\\u2E1C\\u2E1D\\u2E20\\u2E21]", - "AL": "[\\u0023\\u0026\\u002A\\u003C-\\u003E\\u0040-Z\\u005E-z\\u007E\\u00A6\\u00A9\\u00AC\\u00AE\\u00AF\\u00B5\\u00C0-\\u00D6\\u00D8-\\u00F6\\u00F8-\\u02C6\\u02CE\\u02CF\\u02D1-\\u02D7\\u02DC\\u02DE\\u02E0-\\u02FF\\u0370-\\u0377\\u037A-\\u037D\\u0384-\\u038A\\u038C\\u038E-\\u03A1\\u03A3-\\u0482\\u048A-\\u0527\\u0531-\\u0556\\u0559-\\u055F\\u0561-\\u0587\\u05C0\\u05C3\\u05F3\\u05F4\\u0600-\\u0604\\u0606-\\u0608\\u060E\\u060F\\u0620-\\u064A\\u066D-\\u066F\\u0671-\\u06D3\\u06D5\\u06DD\\u06DE\\u06E5\\u06E6\\u06E9\\u06EE\\u06EF\\u06FA-\\u070D\\u070F\\u0710\\u0712-\\u072F\\u074D-\\u07A5\\u07B1\\u07CA-\\u07EA\\u07F4-\\u07F7\\u07FA\\u0800-\\u0815\\u081A\\u0824\\u0828\\u0830-\\u083E\\u0840-\\u0858\\u085E\\u08A0\\u08A2-\\u08AC\\u0904-\\u0939\\u093D\\u0950\\u0958-\\u0961\\u0970-\\u0977\\u0979-\\u097F\\u0985-\\u098C\\u098F\\u0990\\u0993-\\u09A8\\u09AA-\\u09B0\\u09B2\\u09B6-\\u09B9\\u09BD\\u09CE\\u09DC\\u09DD\\u09DF-\\u09E1\\u09F0\\u09F1\\u09F4-\\u09F8\\u09FA\\u0A05-\\u0A0A\\u0A0F\\u0A10\\u0A13-\\u0A28\\u0A2A-\\u0A30\\u0A32\\u0A33\\u0A35\\u0A36\\u0A38\\u0A39\\u0A59-\\u0A5C\\u0A5E\\u0A72-\\u0A74\\u0A85-\\u0A8D\\u0A8F-\\u0A91\\u0A93-\\u0AA8\\u0AAA-\\u0AB0\\u0AB2\\u0AB3\\u0AB5-\\u0AB9\\u0ABD\\u0AD0\\u0AE0\\u0AE1\\u0AF0\\u0B05-\\u0B0C\\u0B0F\\u0B10\\u0B13-\\u0B28\\u0B2A-\\u0B30\\u0B32\\u0B33\\u0B35-\\u0B39\\u0B3D\\u0B5C\\u0B5D\\u0B5F-\\u0B61\\u0B70-\\u0B77\\u0B83\\u0B85-\\u0B8A\\u0B8E-\\u0B90\\u0B92-\\u0B95\\u0B99\\u0B9A\\u0B9C\\u0B9E\\u0B9F\\u0BA3\\u0BA4\\u0BA8-\\u0BAA\\u0BAE-\\u0BB9\\u0BD0\\u0BF0-\\u0BF8\\u0BFA\\u0C05-\\u0C0C\\u0C0E-\\u0C10\\u0C12-\\u0C28\\u0C2A-\\u0C33\\u0C35-\\u0C39\\u0C3D\\u0C58\\u0C59\\u0C60\\u0C61\\u0C78-\\u0C7F\\u0C85-\\u0C8C\\u0C8E-\\u0C90\\u0C92-\\u0CA8\\u0CAA-\\u0CB3\\u0CB5-\\u0CB9\\u0CBD\\u0CDE\\u0CE0\\u0CE1\\u0CF1\\u0CF2\\u0D05-\\u0D0C\\u0D0E-\\u0D10\\u0D12-\\u0D3A\\u0D3D\\u0D4E\\u0D60\\u0D61\\u0D70-\\u0D75\\u0D7A-\\u0D7F\\u0D85-\\u0D96\\u0D9A-\\u0DB1\\u0DB3-\\u0DBB\\u0DBD\\u0DC0-\\u0DC6\\u0DF4\\u0E4F\\u0F00\\u0F05\\u0F13\\u0F15-\\u0F17\\u0F1A-\\u0F1F\\u0F2A-\\u0F33\\u0F36\\u0F38\\u0F40-\\u0F47\\u0F49-\\u0F6C\\u0F88-\\u0F8C\\u0FC0-\\u0FC5\\u0FC7-\\u0FCC\\u0FCE\\u0FCF\\u0FD4-\\u0FD8\\u104C-\\u104F\\u10A0-\\u10C5\\u10C7\\u10CD\\u10D0-\\u10FF\\u1200-\\u1248\\u124A-\\u124D\\u1250-\\u1256\\u1258\\u125A-\\u125D\\u1260-\\u1288\\u128A-\\u128D\\u1290-\\u12B0\\u12B2-\\u12B5\\u12B8-\\u12BE\\u12C0\\u12C2-\\u12C5\\u12C8-\\u12D6\\u12D8-\\u1310\\u1312-\\u1315\\u1318-\\u135A\\u1360\\u1362-\\u137C\\u1380-\\u1399\\u13A0-\\u13F4\\u1401-\\u167F\\u1681-\\u169A\\u16A0-\\u16EA\\u16EE-\\u16F0\\u1700-\\u170C\\u170E-\\u1711\\u1720-\\u1731\\u1740-\\u1751\\u1760-\\u176C\\u176E-\\u1770\\u17D9\\u17F0-\\u17F9\\u1800\\u1801\\u1807\\u180A\\u1820-\\u1877\\u1880-\\u18A8\\u18AA\\u18B0-\\u18F5\\u1900-\\u191C\\u1940\\u19E0-\\u1A16\\u1A1E\\u1A1F\\u1B05-\\u1B33\\u1B45-\\u1B4B\\u1B5C\\u1B61-\\u1B6A\\u1B74-\\u1B7C\\u1B83-\\u1BA0\\u1BAE\\u1BAF\\u1BBA-\\u1BE5\\u1BFC-\\u1C23\\u1C4D-\\u1C4F\\u1C5A-\\u1C7D\\u1CC0-\\u1CC7\\u1CD3\\u1CE9-\\u1CEC\\u1CEE-\\u1CF1\\u1CF5\\u1CF6\\u1D00-\\u1DBF\\u1E00-\\u1F15\\u1F18-\\u1F1D\\u1F20-\\u1F45\\u1F48-\\u1F4D\\u1F50-\\u1F57\\u1F59\\u1F5B\\u1F5D\\u1F5F-\\u1F7D\\u1F80-\\u1FB4\\u1FB6-\\u1FC4\\u1FC6-\\u1FD3\\u1FD6-\\u1FDB\\u1FDD-\\u1FEF\\u1FF2-\\u1FF4\\u1FF6-\\u1FFC\\u1FFE\\u2017\\u2022\\u2023\\u2038\\u203E-\\u2043\\u204A-\\u2055\\u2057\\u205C\\u2061-\\u2064\\u2070\\u2071\\u2075-\\u207C\\u2080\\u2085-\\u208C\\u2090-\\u209C\\u2100-\\u2102\\u2104\\u2106-\\u2108\\u210A-\\u2112\\u2114\\u2115\\u2117-\\u2120\\u2123-\\u212A\\u212C-\\u2153\\u2156-\\u215A\\u215C\\u215D\\u215F\\u216C-\\u216F\\u217A-\\u2188\\u219A-\\u21D1\\u21D3\\u21D5-\\u21FF\\u2201\\u2204-\\u2206\\u2209\\u220A\\u220C-\\u220E\\u2210\\u2214\\u2216-\\u2219\\u221B\\u221C\\u2221\\u2222\\u2224\\u2226\\u222D\\u222F-\\u2233\\u2238-\\u223B\\u223E-\\u2247\\u2249-\\u224B\\u224D-\\u2251\\u2253-\\u225F\\u2262\\u2263\\u2268\\u2269\\u226C\\u226D\\u2270-\\u2281\\u2284\\u2285\\u2288-\\u2294\\u2296-\\u2298\\u229A-\\u22A4\\u22A6-\\u22BE\\u22C0-\\u2311\\u2313-\\u2328\\u232B-\\u23F3\\u2400-\\u2426\\u2440-\\u244A\\u24FF\\u254C-\\u254F\\u2575-\\u257F\\u2590\\u2591\\u2596-\\u259F\\u25A2\\u25AA-\\u25B1\\u25B4\\u25B5\\u25B8-\\u25BB\\u25BE\\u25BF\\u25C2-\\u25C5\\u25C9\\u25CA\\u25CC\\u25CD\\u25D2-\\u25E1\\u25E6-\\u25EE\\u25F0-\\u2604\\u2607\\u2608\\u260A-\\u260D\\u2610-\\u2613\\u2618-\\u261B\\u261D\\u261F-\\u263F\\u2641\\u2643-\\u265F\\u2662\\u2666\\u266B\\u266E\\u2670-\\u269D\\u26A0-\\u26BD\\u26C0-\\u26C3\\u26CE\\u26E2\\u26E4-\\u26E7\\u2701-\\u2756\\u2758-\\u275A\\u275F-\\u2761\\u2764-\\u2767\\u2794-\\u27C4\\u27C7-\\u27E5\\u27F0-\\u2982\\u2999-\\u29D7\\u29DC-\\u29FB\\u29FE-\\u2B4C\\u2B50-\\u2B54\\u2C00-\\u2C2E\\u2C30-\\u2C5E\\u2C60-\\u2CEE\\u2CF2\\u2CF3\\u2CFD\\u2D00-\\u2D25\\u2D27\\u2D2D\\u2D30-\\u2D67\\u2D6F\\u2D80-\\u2D96\\u2DA0-\\u2DA6\\u2DA8-\\u2DAE\\u2DB0-\\u2DB6\\u2DB8-\\u2DBE\\u2DC0-\\u2DC6\\u2DC8-\\u2DCE\\u2DD0-\\u2DD6\\u2DD8-\\u2DDE\\u2E16\\u2E1A\\u2E1B\\u2E1E\\u2E1F\\u2E2F\\u2E32\\u2E35-\\u2E39\\u4DC0-\\u4DFF\\uA4D0-\\uA4FD\\uA500-\\uA60C\\uA610-\\uA61F\\uA62A\\uA62B\\uA640-\\uA66E\\uA673\\uA67E-\\uA697\\uA6A0-\\uA6EF\\uA6F2\\uA700-\\uA78E\\uA790-\\uA793\\uA7A0-\\uA7AA\\uA7F8-\\uA801\\uA803-\\uA805\\uA807-\\uA80A\\uA80C-\\uA822\\uA828-\\uA82B\\uA830-\\uA837\\uA839\\uA840-\\uA873\\uA882-\\uA8B3\\uA8F2-\\uA8FB\\uA90A-\\uA925\\uA930-\\uA946\\uA95F\\uA984-\\uA9B2\\uA9C1-\\uA9C6\\uA9CA-\\uA9CD\\uA9CF\\uA9DE\\uA9DF\\uAA00-\\uAA28\\uAA40-\\uAA42\\uAA44-\\uAA4B\\uAA5C\\uAAE0-\\uAAEA\\uAAF2-\\uAAF4\\uAB01-\\uAB06\\uAB09-\\uAB0E\\uAB11-\\uAB16\\uAB20-\\uAB26\\uAB28-\\uAB2E\\uABC0-\\uABE2\\uFB00-\\uFB06\\uFB13-\\uFB17\\uFB29\\uFB50-\\uFBC1\\uFBD3-\\uFD3D\\uFD50-\\uFD8F\\uFD92-\\uFDC7\\uFDF0-\\uFDFB\\uFDFD\\uFE70-\\uFE74\\uFE76-\\uFEFC\\uFF66\\uFF71-\\uFF9D\\uFFA0-\\uFFBE\\uFFC2-\\uFFC7\\uFFCA-\\uFFCF\\uFFD2-\\uFFD7\\uFFDA-\\uFFDC\\uFFE8-\\uFFEE]|[\\u5536][\\uDC00-\\uDC0B\\uDC0D-\\uDC26\\uDC28-\\uDC3A\\uDC3C\\uDC3D\\uDC3F-\\uDC4D\\uDC50-\\uDC5D\\uDC80-\\uDCFA\\uDD07-\\uDD33\\uDD37-\\uDD8A\\uDD90-\\uDD9B\\uDDD0-\\uDDFC\\uDE80-\\uDE9C\\uDEA0-\\uDED0\\uDF00-\\uDF1E\\uDF20-\\uDF23\\uDF30-\\uDF4A\\uDF80-\\uDF9D\\uDFA0-\\uDFC3\\uDFC8-\\uDFCF\\uDFD1-\\uDFD5]|[\\u5536][\\uDC00-\\uDC9D]|[\\u5536][\\uDC00-\\uDC05\\uDC08\\uDC0A-\\uDC35\\uDC37\\uDC38\\uDC3C\\uDC3F-\\uDC55\\uDC58-\\uDC5F\\uDD00-\\uDD1B\\uDD20-\\uDD39\\uDD3F\\uDD80-\\uDDB7\\uDDBE\\uDDBF\\uDE00\\uDE10-\\uDE13\\uDE15-\\uDE17\\uDE19-\\uDE33\\uDE40-\\uDE47\\uDE58\\uDE60-\\uDE7F\\uDF00-\\uDF35\\uDF40-\\uDF55\\uDF58-\\uDF72\\uDF78-\\uDF7F]|[\\u5536][\\uDC00-\\uDC48\\uDE60-\\uDE7E]|[\\u5536][\\uDC03-\\uDC37\\uDC49-\\uDC4D\\uDC52-\\uDC65\\uDC83-\\uDCAF\\uDCBB-\\uDCBD\\uDCD0-\\uDCE8\\uDD03-\\uDD26\\uDD83-\\uDDB2\\uDDC1-\\uDDC4\\uDDC7]|[\\u5536][\\uDE80-\\uDEAA]|[\\u5536][\\uDC00-\\uDF6E]|[\\u5536][\\uDC00-\\uDC62]|[\\u5536][\\uDC00-\\uDE57\\uDE5E-\\uDE81\\uDE83-\\uDE85\\uDE8A-\\uDF78\\uDF7C-\\uDFFF]|[\\u5536][\\uDC00-\\uDC2E]|[\\u5536][\\uDC00-\\uDE38]|[\\u5536][\\uDF00-\\uDF44\\uDF50\\uDF93-\\uDF9F]|[\\u5536][\\uDC00-\\uDCF5\\uDD00-\\uDD26\\uDD29-\\uDD64\\uDD6A-\\uDD6C\\uDD83\\uDD84\\uDD8C-\\uDDA9\\uDDAE-\\uDDDD\\uDE00-\\uDE41\\uDE45\\uDF00-\\uDF56\\uDF60-\\uDF71]|[\\u5536][\\uDC00-\\uDC54\\uDC56-\\uDC9C\\uDC9E\\uDC9F\\uDCA2\\uDCA5\\uDCA6\\uDCA9-\\uDCAC\\uDCAE-\\uDCB9\\uDCBB\\uDCBD-\\uDCC3\\uDCC5-\\uDD05\\uDD07-\\uDD0A\\uDD0D-\\uDD14\\uDD16-\\uDD1C\\uDD1E-\\uDD39\\uDD3B-\\uDD3E\\uDD40-\\uDD44\\uDD46\\uDD4A-\\uDD50\\uDD52-\\uDEA5\\uDEA8-\\uDFCB]|[\\u5536][\\uDE00-\\uDE03\\uDE05-\\uDE1F\\uDE21\\uDE22\\uDE24\\uDE27\\uDE29-\\uDE32\\uDE34-\\uDE37\\uDE39\\uDE3B\\uDE42\\uDE47\\uDE49\\uDE4B\\uDE4D-\\uDE4F\\uDE51\\uDE52\\uDE54\\uDE57\\uDE59\\uDE5B\\uDE5D\\uDE5F\\uDE61\\uDE62\\uDE64\\uDE67-\\uDE6A\\uDE6C-\\uDE72\\uDE74-\\uDE77\\uDE79-\\uDE7C\\uDE7E\\uDE80-\\uDE89\\uDE8B-\\uDE9B\\uDEA1-\\uDEA3\\uDEA5-\\uDEA9\\uDEAB-\\uDEBB\\uDEF0\\uDEF1]|[\\u5536][\\uDC00-\\uDC2B\\uDC30-\\uDC93\\uDCA0-\\uDCAE\\uDCB1-\\uDCBE\\uDCC1-\\uDCCF\\uDCD1-\\uDCDF\\uDD2E\\uDD6A\\uDD6B\\uDDE6-\\uDDFF\\uDF00-\\uDF20\\uDF30-\\uDF35\\uDF37-\\uDF7C\\uDF80-\\uDF93\\uDFA0-\\uDFC4\\uDFC6-\\uDFCA\\uDFE0-\\uDFF0]|[\\u5536][\\uDC00-\\uDC3E\\uDC40\\uDC42-\\uDCF7\\uDCF9-\\uDCFC\\uDD00-\\uDD3D\\uDD40-\\uDD43\\uDD50-\\uDD67\\uDDFB-\\uDE40\\uDE45-\\uDE4F\\uDE80-\\uDEC5\\uDF00-\\uDF73]", - "PR": "[\\u0024\\u002B\\u005C\\u00A3-\\u00A5\\u00B1\\u058F\\u09FB\\u0AF1\\u0BF9\\u0E3F\\u17DB\\u20A0-\\u20A6\\u20A8-\\u20B5\\u20B7-\\u20B9\\u2116\\u2212\\u2213\\uFE69\\uFF04\\uFFE1\\uFFE5\\uFFE6]", - "PO": "[\\u0025\\u00A2\\u00B0\\u0609-\\u060B\\u066A\\u09F2\\u09F3\\u09F9\\u0D79\\u2030-\\u2037\\u20A7\\u20B6\\u2103\\u2109\\uA838\\uFDFC\\uFE6A\\uFF05\\uFFE0]", - "OP": "[\\u0028\\u005B\\u007B\\u00A1\\u00BF\\u0F3A\\u0F3C\\u169B\\u201A\\u201E\\u2045\\u207D\\u208D\\u2329\\u2768\\u276A\\u276C\\u276E\\u2770\\u2772\\u2774\\u27C5\\u27E6\\u27E8\\u27EA\\u27EC\\u27EE\\u2983\\u2985\\u2987\\u2989\\u298B\\u298D\\u298F\\u2991\\u2993\\u2995\\u2997\\u29D8\\u29DA\\u29FC\\u2E18\\u2E22\\u2E24\\u2E26\\u2E28\\u3008\\u300A\\u300C\\u300E\\u3010\\u3014\\u3016\\u3018\\u301A\\u301D\\uFD3E\\uFE17\\uFE35\\uFE37\\uFE39\\uFE3B\\uFE3D\\uFE3F\\uFE41\\uFE43\\uFE47\\uFE59\\uFE5B\\uFE5D\\uFF08\\uFF3B\\uFF5B\\uFF5F\\uFF62]|[\\u5536][\\uDE58-\\uDE5A\\uDE86\\uDE88\\uDF79]", - "CP": "[\\u0029\\u005D]", - "IS": "[\\u002C\\u002E\\u003A\\u003B\\u037E\\u0589\\u060C\\u060D\\u07F8\\u2044\\uFE10\\uFE13\\uFE14]", - "HY": "[\\u002D]", - "SY": "[\\u002F]", - "NU": "[0-9\\u0660-\\u0669\\u066B\\u066C\\u06F0-\\u06F9\\u07C0-\\u07C9\\u0966-\\u096F\\u09E6-\\u09EF\\u0A66-\\u0A6F\\u0AE6-\\u0AEF\\u0B66-\\u0B6F\\u0BE6-\\u0BEF\\u0C66-\\u0C6F\\u0CE6-\\u0CEF\\u0D66-\\u0D6F\\u0E50-\\u0E59\\u0ED0-\\u0ED9\\u0F20-\\u0F29\\u1040-\\u1049\\u1090-\\u1099\\u17E0-\\u17E9\\u1810-\\u1819\\u1946-\\u194F\\u19D0-\\u19D9\\u1A80-\\u1A89\\u1A90-\\u1A99\\u1B50-\\u1B59\\u1BB0-\\u1BB9\\u1C40-\\u1C49\\u1C50-\\u1C59\\uA620-\\uA629\\uA8D0-\\uA8D9\\uA900-\\uA909\\uA9D0-\\uA9D9\\uAA50-\\uAA59\\uABF0-\\uABF9]|[\\u5536][\\uDCA0-\\uDCA9]|[\\u5536][\\uDC66-\\uDC6F\\uDCF0-\\uDCF9\\uDD36-\\uDD3F\\uDDD0-\\uDDD9]|[\\u5536][\\uDEC0-\\uDEC9]|[\\u5536][\\uDFCE-\\uDFFF]", - "CL": "[\\u007D\\u0F3B\\u0F3D\\u169C\\u2046\\u207E\\u208E\\u232A\\u2769\\u276B\\u276D\\u276F\\u2771\\u2773\\u2775\\u27C6\\u27E7\\u27E9\\u27EB\\u27ED\\u27EF\\u2984\\u2986\\u2988\\u298A\\u298C\\u298E\\u2990\\u2992\\u2994\\u2996\\u2998\\u29D9\\u29DB\\u29FD\\u2E23\\u2E25\\u2E27\\u2E29\\u3001\\u3002\\u3009\\u300B\\u300D\\u300F\\u3011\\u3015\\u3017\\u3019\\u301B\\u301E\\u301F\\uFD3F\\uFE11\\uFE12\\uFE18\\uFE36\\uFE38\\uFE3A\\uFE3C\\uFE3E\\uFE40\\uFE42\\uFE44\\uFE48\\uFE50\\uFE52\\uFE5A\\uFE5C\\uFE5E\\uFF09\\uFF0C\\uFF0E\\uFF3D\\uFF5D\\uFF60\\uFF61\\uFF63\\uFF64]|[\\u5536][\\uDE5B-\\uDE5D\\uDE82\\uDE87\\uDE89\\uDF7A\\uDF7B]", - "NL": "[\\u0085]", - "GL": "[\\u00A0\\u034F\\u035C-\\u0362\\u0F08\\u0F0C\\u0F12\\u0FD9\\u0FDA\\u180E\\u2007\\u2011\\u202F]", - "AI": "[\\u00A7\\u00A8\\u00AA\\u00B2\\u00B3\\u00B6-\\u00BA\\u00BC-\\u00BE\\u00D7\\u00F7\\u02C7\\u02C9-\\u02CB\\u02CD\\u02D0\\u02D8-\\u02DB\\u02DD\\u2015\\u2016\\u2020\\u2021\\u203B\\u2074\\u207F\\u2081-\\u2084\\u2105\\u2113\\u2121\\u2122\\u212B\\u2154\\u2155\\u215B\\u215E\\u2160-\\u216B\\u2170-\\u2179\\u2189\\u2190-\\u2199\\u21D2\\u21D4\\u2200\\u2202\\u2203\\u2207\\u2208\\u220B\\u220F\\u2211\\u2215\\u221A\\u221D-\\u2220\\u2223\\u2225\\u2227-\\u222C\\u222E\\u2234-\\u2237\\u223C\\u223D\\u2248\\u224C\\u2252\\u2260\\u2261\\u2264-\\u2267\\u226A\\u226B\\u226E\\u226F\\u2282\\u2283\\u2286\\u2287\\u2295\\u2299\\u22A5\\u22BF\\u2312\\u2460-\\u24FE\\u2500-\\u254B\\u2550-\\u2574\\u2580-\\u258F\\u2592-\\u2595\\u25A0\\u25A1\\u25A3-\\u25A9\\u25B2\\u25B3\\u25B6\\u25B7\\u25BC\\u25BD\\u25C0\\u25C1\\u25C6-\\u25C8\\u25CB\\u25CE-\\u25D1\\u25E2-\\u25E5\\u25EF\\u2605\\u2606\\u2609\\u260E\\u260F\\u2614-\\u2617\\u261C\\u261E\\u2640\\u2642\\u2660\\u2661\\u2663-\\u2665\\u2667-\\u266A\\u266C\\u266D\\u266F\\u269E\\u269F\\u26BE\\u26BF\\u26C4-\\u26CD\\u26CF-\\u26E1\\u26E3\\u26E8-\\u26FF\\u2757\\u2776-\\u2793\\u2B55-\\u2B59\\u3248-\\u324F\\uFFFD]|[\\u5536][\\uDD00-\\uDD0A\\uDD10-\\uDD2D\\uDD30-\\uDD69\\uDD70-\\uDD9A]", - "BB": "[\\u00B4\\u02C8\\u02CC\\u02DF\\u0F01-\\u0F04\\u0F06\\u0F07\\u0F09\\u0F0A\\u0FD0\\u0FD1\\u0FD3\\u1806\\u1FFD\\uA874\\uA875]", - "HL": "[\\u05D0-\\u05EA\\u05F0-\\u05F2\\uFB1D\\uFB1F-\\uFB28\\uFB2A-\\uFB36\\uFB38-\\uFB3C\\uFB3E\\uFB40\\uFB41\\uFB43\\uFB44\\uFB46-\\uFB4F]", - "SA": "[\\u0E01-\\u0E3A\\u0E40-\\u0E4E\\u0E81\\u0E82\\u0E84\\u0E87\\u0E88\\u0E8A\\u0E8D\\u0E94-\\u0E97\\u0E99-\\u0E9F\\u0EA1-\\u0EA3\\u0EA5\\u0EA7\\u0EAA\\u0EAB\\u0EAD-\\u0EB9\\u0EBB-\\u0EBD\\u0EC0-\\u0EC4\\u0EC6\\u0EC8-\\u0ECD\\u0EDC-\\u0EDF\\u1000-\\u103F\\u1050-\\u108F\\u109A-\\u109F\\u1780-\\u17D3\\u17D7\\u17DC\\u17DD\\u1950-\\u196D\\u1970-\\u1974\\u1980-\\u19AB\\u19B0-\\u19C9\\u19DA\\u19DE\\u19DF\\u1A20-\\u1A5E\\u1A60-\\u1A7C\\u1AA0-\\u1AAD\\uAA60-\\uAA7B\\uAA80-\\uAAC2\\uAADB-\\uAADF]", - "JL": "[\\u1100-\\u115F\\uA960-\\uA97C]", - "JV": "[\\u1160-\\u11A7\\uD7B0-\\uD7C6]", - "JT": "[\\u11A8-\\u11FF\\uD7CB-\\uD7FB]", - "NS": "[\\u17D6\\u203C\\u203D\\u2047-\\u2049\\u3005\\u301C\\u303B\\u303C\\u309B-\\u309E\\u30A0\\u30FB\\u30FD\\u30FE\\uA015\\uFE54\\uFE55\\uFF1A\\uFF1B\\uFF65\\uFF9E\\uFF9F]", - "ZW": "[\\u200B]", - "B2": "[\\u2014\\u2E3A\\u2E3B]", - "IN": "[\\u2024-\\u2026\\uFE19]", - "WJ": "[\\u2060\\uFEFF]", - "ID": "[\\u2E80-\\u2E99\\u2E9B-\\u2EF3\\u2F00-\\u2FD5\\u2FF0-\\u2FFB\\u3000\\u3003\\u3004\\u3006\\u3007\\u3012\\u3013\\u3020-\\u3029\\u3030-\\u303A\\u303D-\\u303F\\u3042\\u3044\\u3046\\u3048\\u304A-\\u3062\\u3064-\\u3082\\u3084\\u3086\\u3088-\\u308D\\u308F-\\u3094\\u309F\\u30A2\\u30A4\\u30A6\\u30A8\\u30AA-\\u30C2\\u30C4-\\u30E2\\u30E4\\u30E6\\u30E8-\\u30ED\\u30EF-\\u30F4\\u30F7-\\u30FA\\u30FF\\u3105-\\u312D\\u3131-\\u318E\\u3190-\\u31BA\\u31C0-\\u31E3\\u3200-\\u321E\\u3220-\\u3247\\u3250-\\u32FE\\u3300-\\u4DBF\\u4E00-\\uA014\\uA016-\\uA48C\\uA490-\\uA4C6\\uF900-\\uFAFF\\uFE30-\\uFE34\\uFE45\\uFE46\\uFE49-\\uFE4F\\uFE51\\uFE58\\uFE5F-\\uFE66\\uFE68\\uFE6B\\uFF02\\uFF03\\uFF06\\uFF07\\uFF0A\\uFF0B\\uFF0D\\uFF0F-\\uFF19\\uFF1C-\\uFF1E\\uFF20-\\uFF3A\\uFF3C\\uFF3E-\\uFF5A\\uFF5C\\uFF5E\\uFFE2-\\uFFE4]|[\\u5536][\\uDC00\\uDC01]|[\\u5536][\\uDE00-\\uDE02\\uDE10-\\uDE3A\\uDE40-\\uDE48\\uDE50\\uDE51]|[\\u5536\\u5536\\u5536\\u5536\\u5536\\u5536\\u5536\\u5536\\u5536\\u5536\\u5536\\u5536\\u5536\\u5536\\u5536\\u5536\\u5536\\u5536\\u5536\\u5536\\u5536\\u5536\\u5536\\u5536\\u5536\\u5536\\u5536\\u5536\\u5536\\u5536\\u5536\\u5536\\u5536\\u5536\\u5536\\u5536\\u5536\\u5536\\u5536\\u5536\\u5536\\u5536\\u5536\\u5536\\u5536\\u5536\\u5536\\u5536\\u5536\\u5536\\u5536\\u5536\\u5536\\u5536\\u5536\\u5536\\u5536\\u5536\\u5536\\u5536\\u5536\\u5536\\u5536\\u5536\\u5536\\u5536\\u5536\\u5536\\u5536\\u5536\\u5536\\u5536\\u5536\\u5536\\u5536\\u5536\\u5536\\u5536\\u5536\\u5536\\u5536\\u5536\\u5536\\u5536\\u5536\\u5536\\u5536\\u5536\\u5536\\u5536\\u5536\\u5536\\u5536\\u5536\\u5536\\u5536\\u5536\\u5536\\u5536\\u5536\\u5536\\u5536\\u5536\\u5536\\u5536\\u5536\\u5536\\u5536\\u5536\\u5536\\u5536\\u5536\\u5536\\u5536\\u5536\\u5536\\u5536\\u5536\\u5536\\u5536\\u5536\\u5536\\u5536\\u5536\\u5536\\u5536][\\uDC00-\\uDFFF]|[\\u5536\\u5536][\\uDC00-\\uDFFD]", - "CJ": "[\\u3041\\u3043\\u3045\\u3047\\u3049\\u3063\\u3083\\u3085\\u3087\\u308E\\u3095\\u3096\\u30A1\\u30A3\\u30A5\\u30A7\\u30A9\\u30C3\\u30E3\\u30E5\\u30E7\\u30EE\\u30F5\\u30F6\\u30FC\\u31F0-\\u31FF\\uFF67-\\uFF70]", - "H2": "[\\uAC00\\uAC1C\\uAC38\\uAC54\\uAC70\\uAC8C\\uACA8\\uACC4\\uACE0\\uACFC\\uAD18\\uAD34\\uAD50\\uAD6C\\uAD88\\uADA4\\uADC0\\uADDC\\uADF8\\uAE14\\uAE30\\uAE4C\\uAE68\\uAE84\\uAEA0\\uAEBC\\uAED8\\uAEF4\\uAF10\\uAF2C\\uAF48\\uAF64\\uAF80\\uAF9C\\uAFB8\\uAFD4\\uAFF0\\uB00C\\uB028\\uB044\\uB060\\uB07C\\uB098\\uB0B4\\uB0D0\\uB0EC\\uB108\\uB124\\uB140\\uB15C\\uB178\\uB194\\uB1B0\\uB1CC\\uB1E8\\uB204\\uB220\\uB23C\\uB258\\uB274\\uB290\\uB2AC\\uB2C8\\uB2E4\\uB300\\uB31C\\uB338\\uB354\\uB370\\uB38C\\uB3A8\\uB3C4\\uB3E0\\uB3FC\\uB418\\uB434\\uB450\\uB46C\\uB488\\uB4A4\\uB4C0\\uB4DC\\uB4F8\\uB514\\uB530\\uB54C\\uB568\\uB584\\uB5A0\\uB5BC\\uB5D8\\uB5F4\\uB610\\uB62C\\uB648\\uB664\\uB680\\uB69C\\uB6B8\\uB6D4\\uB6F0\\uB70C\\uB728\\uB744\\uB760\\uB77C\\uB798\\uB7B4\\uB7D0\\uB7EC\\uB808\\uB824\\uB840\\uB85C\\uB878\\uB894\\uB8B0\\uB8CC\\uB8E8\\uB904\\uB920\\uB93C\\uB958\\uB974\\uB990\\uB9AC\\uB9C8\\uB9E4\\uBA00\\uBA1C\\uBA38\\uBA54\\uBA70\\uBA8C\\uBAA8\\uBAC4\\uBAE0\\uBAFC\\uBB18\\uBB34\\uBB50\\uBB6C\\uBB88\\uBBA4\\uBBC0\\uBBDC\\uBBF8\\uBC14\\uBC30\\uBC4C\\uBC68\\uBC84\\uBCA0\\uBCBC\\uBCD8\\uBCF4\\uBD10\\uBD2C\\uBD48\\uBD64\\uBD80\\uBD9C\\uBDB8\\uBDD4\\uBDF0\\uBE0C\\uBE28\\uBE44\\uBE60\\uBE7C\\uBE98\\uBEB4\\uBED0\\uBEEC\\uBF08\\uBF24\\uBF40\\uBF5C\\uBF78\\uBF94\\uBFB0\\uBFCC\\uBFE8\\uC004\\uC020\\uC03C\\uC058\\uC074\\uC090\\uC0AC\\uC0C8\\uC0E4\\uC100\\uC11C\\uC138\\uC154\\uC170\\uC18C\\uC1A8\\uC1C4\\uC1E0\\uC1FC\\uC218\\uC234\\uC250\\uC26C\\uC288\\uC2A4\\uC2C0\\uC2DC\\uC2F8\\uC314\\uC330\\uC34C\\uC368\\uC384\\uC3A0\\uC3BC\\uC3D8\\uC3F4\\uC410\\uC42C\\uC448\\uC464\\uC480\\uC49C\\uC4B8\\uC4D4\\uC4F0\\uC50C\\uC528\\uC544\\uC560\\uC57C\\uC598\\uC5B4\\uC5D0\\uC5EC\\uC608\\uC624\\uC640\\uC65C\\uC678\\uC694\\uC6B0\\uC6CC\\uC6E8\\uC704\\uC720\\uC73C\\uC758\\uC774\\uC790\\uC7AC\\uC7C8\\uC7E4\\uC800\\uC81C\\uC838\\uC854\\uC870\\uC88C\\uC8A8\\uC8C4\\uC8E0\\uC8FC\\uC918\\uC934\\uC950\\uC96C\\uC988\\uC9A4\\uC9C0\\uC9DC\\uC9F8\\uCA14\\uCA30\\uCA4C\\uCA68\\uCA84\\uCAA0\\uCABC\\uCAD8\\uCAF4\\uCB10\\uCB2C\\uCB48\\uCB64\\uCB80\\uCB9C\\uCBB8\\uCBD4\\uCBF0\\uCC0C\\uCC28\\uCC44\\uCC60\\uCC7C\\uCC98\\uCCB4\\uCCD0\\uCCEC\\uCD08\\uCD24\\uCD40\\uCD5C\\uCD78\\uCD94\\uCDB0\\uCDCC\\uCDE8\\uCE04\\uCE20\\uCE3C\\uCE58\\uCE74\\uCE90\\uCEAC\\uCEC8\\uCEE4\\uCF00\\uCF1C\\uCF38\\uCF54\\uCF70\\uCF8C\\uCFA8\\uCFC4\\uCFE0\\uCFFC\\uD018\\uD034\\uD050\\uD06C\\uD088\\uD0A4\\uD0C0\\uD0DC\\uD0F8\\uD114\\uD130\\uD14C\\uD168\\uD184\\uD1A0\\uD1BC\\uD1D8\\uD1F4\\uD210\\uD22C\\uD248\\uD264\\uD280\\uD29C\\uD2B8\\uD2D4\\uD2F0\\uD30C\\uD328\\uD344\\uD360\\uD37C\\uD398\\uD3B4\\uD3D0\\uD3EC\\uD408\\uD424\\uD440\\uD45C\\uD478\\uD494\\uD4B0\\uD4CC\\uD4E8\\uD504\\uD520\\uD53C\\uD558\\uD574\\uD590\\uD5AC\\uD5C8\\uD5E4\\uD600\\uD61C\\uD638\\uD654\\uD670\\uD68C\\uD6A8\\uD6C4\\uD6E0\\uD6FC\\uD718\\uD734\\uD750\\uD76C\\uD788]", - "H3": "[\\uAC01-\\uAC1B\\uAC1D-\\uAC37\\uAC39-\\uAC53\\uAC55-\\uAC6F\\uAC71-\\uAC8B\\uAC8D-\\uACA7\\uACA9-\\uACC3\\uACC5-\\uACDF\\uACE1-\\uACFB\\uACFD-\\uAD17\\uAD19-\\uAD33\\uAD35-\\uAD4F\\uAD51-\\uAD6B\\uAD6D-\\uAD87\\uAD89-\\uADA3\\uADA5-\\uADBF\\uADC1-\\uADDB\\uADDD-\\uADF7\\uADF9-\\uAE13\\uAE15-\\uAE2F\\uAE31-\\uAE4B\\uAE4D-\\uAE67\\uAE69-\\uAE83\\uAE85-\\uAE9F\\uAEA1-\\uAEBB\\uAEBD-\\uAED7\\uAED9-\\uAEF3\\uAEF5-\\uAF0F\\uAF11-\\uAF2B\\uAF2D-\\uAF47\\uAF49-\\uAF63\\uAF65-\\uAF7F\\uAF81-\\uAF9B\\uAF9D-\\uAFB7\\uAFB9-\\uAFD3\\uAFD5-\\uAFEF\\uAFF1-\\uB00B\\uB00D-\\uB027\\uB029-\\uB043\\uB045-\\uB05F\\uB061-\\uB07B\\uB07D-\\uB097\\uB099-\\uB0B3\\uB0B5-\\uB0CF\\uB0D1-\\uB0EB\\uB0ED-\\uB107\\uB109-\\uB123\\uB125-\\uB13F\\uB141-\\uB15B\\uB15D-\\uB177\\uB179-\\uB193\\uB195-\\uB1AF\\uB1B1-\\uB1CB\\uB1CD-\\uB1E7\\uB1E9-\\uB203\\uB205-\\uB21F\\uB221-\\uB23B\\uB23D-\\uB257\\uB259-\\uB273\\uB275-\\uB28F\\uB291-\\uB2AB\\uB2AD-\\uB2C7\\uB2C9-\\uB2E3\\uB2E5-\\uB2FF\\uB301-\\uB31B\\uB31D-\\uB337\\uB339-\\uB353\\uB355-\\uB36F\\uB371-\\uB38B\\uB38D-\\uB3A7\\uB3A9-\\uB3C3\\uB3C5-\\uB3DF\\uB3E1-\\uB3FB\\uB3FD-\\uB417\\uB419-\\uB433\\uB435-\\uB44F\\uB451-\\uB46B\\uB46D-\\uB487\\uB489-\\uB4A3\\uB4A5-\\uB4BF\\uB4C1-\\uB4DB\\uB4DD-\\uB4F7\\uB4F9-\\uB513\\uB515-\\uB52F\\uB531-\\uB54B\\uB54D-\\uB567\\uB569-\\uB583\\uB585-\\uB59F\\uB5A1-\\uB5BB\\uB5BD-\\uB5D7\\uB5D9-\\uB5F3\\uB5F5-\\uB60F\\uB611-\\uB62B\\uB62D-\\uB647\\uB649-\\uB663\\uB665-\\uB67F\\uB681-\\uB69B\\uB69D-\\uB6B7\\uB6B9-\\uB6D3\\uB6D5-\\uB6EF\\uB6F1-\\uB70B\\uB70D-\\uB727\\uB729-\\uB743\\uB745-\\uB75F\\uB761-\\uB77B\\uB77D-\\uB797\\uB799-\\uB7B3\\uB7B5-\\uB7CF\\uB7D1-\\uB7EB\\uB7ED-\\uB807\\uB809-\\uB823\\uB825-\\uB83F\\uB841-\\uB85B\\uB85D-\\uB877\\uB879-\\uB893\\uB895-\\uB8AF\\uB8B1-\\uB8CB\\uB8CD-\\uB8E7\\uB8E9-\\uB903\\uB905-\\uB91F\\uB921-\\uB93B\\uB93D-\\uB957\\uB959-\\uB973\\uB975-\\uB98F\\uB991-\\uB9AB\\uB9AD-\\uB9C7\\uB9C9-\\uB9E3\\uB9E5-\\uB9FF\\uBA01-\\uBA1B\\uBA1D-\\uBA37\\uBA39-\\uBA53\\uBA55-\\uBA6F\\uBA71-\\uBA8B\\uBA8D-\\uBAA7\\uBAA9-\\uBAC3\\uBAC5-\\uBADF\\uBAE1-\\uBAFB\\uBAFD-\\uBB17\\uBB19-\\uBB33\\uBB35-\\uBB4F\\uBB51-\\uBB6B\\uBB6D-\\uBB87\\uBB89-\\uBBA3\\uBBA5-\\uBBBF\\uBBC1-\\uBBDB\\uBBDD-\\uBBF7\\uBBF9-\\uBC13\\uBC15-\\uBC2F\\uBC31-\\uBC4B\\uBC4D-\\uBC67\\uBC69-\\uBC83\\uBC85-\\uBC9F\\uBCA1-\\uBCBB\\uBCBD-\\uBCD7\\uBCD9-\\uBCF3\\uBCF5-\\uBD0F\\uBD11-\\uBD2B\\uBD2D-\\uBD47\\uBD49-\\uBD63\\uBD65-\\uBD7F\\uBD81-\\uBD9B\\uBD9D-\\uBDB7\\uBDB9-\\uBDD3\\uBDD5-\\uBDEF\\uBDF1-\\uBE0B\\uBE0D-\\uBE27\\uBE29-\\uBE43\\uBE45-\\uBE5F\\uBE61-\\uBE7B\\uBE7D-\\uBE97\\uBE99-\\uBEB3\\uBEB5-\\uBECF\\uBED1-\\uBEEB\\uBEED-\\uBF07\\uBF09-\\uBF23\\uBF25-\\uBF3F\\uBF41-\\uBF5B\\uBF5D-\\uBF77\\uBF79-\\uBF93\\uBF95-\\uBFAF\\uBFB1-\\uBFCB\\uBFCD-\\uBFE7\\uBFE9-\\uC003\\uC005-\\uC01F\\uC021-\\uC03B\\uC03D-\\uC057\\uC059-\\uC073\\uC075-\\uC08F\\uC091-\\uC0AB\\uC0AD-\\uC0C7\\uC0C9-\\uC0E3\\uC0E5-\\uC0FF\\uC101-\\uC11B\\uC11D-\\uC137\\uC139-\\uC153\\uC155-\\uC16F\\uC171-\\uC18B\\uC18D-\\uC1A7\\uC1A9-\\uC1C3\\uC1C5-\\uC1DF\\uC1E1-\\uC1FB\\uC1FD-\\uC217\\uC219-\\uC233\\uC235-\\uC24F\\uC251-\\uC26B\\uC26D-\\uC287\\uC289-\\uC2A3\\uC2A5-\\uC2BF\\uC2C1-\\uC2DB\\uC2DD-\\uC2F7\\uC2F9-\\uC313\\uC315-\\uC32F\\uC331-\\uC34B\\uC34D-\\uC367\\uC369-\\uC383\\uC385-\\uC39F\\uC3A1-\\uC3BB\\uC3BD-\\uC3D7\\uC3D9-\\uC3F3\\uC3F5-\\uC40F\\uC411-\\uC42B\\uC42D-\\uC447\\uC449-\\uC463\\uC465-\\uC47F\\uC481-\\uC49B\\uC49D-\\uC4B7\\uC4B9-\\uC4D3\\uC4D5-\\uC4EF\\uC4F1-\\uC50B\\uC50D-\\uC527\\uC529-\\uC543\\uC545-\\uC55F\\uC561-\\uC57B\\uC57D-\\uC597\\uC599-\\uC5B3\\uC5B5-\\uC5CF\\uC5D1-\\uC5EB\\uC5ED-\\uC607\\uC609-\\uC623\\uC625-\\uC63F\\uC641-\\uC65B\\uC65D-\\uC677\\uC679-\\uC693\\uC695-\\uC6AF\\uC6B1-\\uC6CB\\uC6CD-\\uC6E7\\uC6E9-\\uC703\\uC705-\\uC71F\\uC721-\\uC73B\\uC73D-\\uC757\\uC759-\\uC773\\uC775-\\uC78F\\uC791-\\uC7AB\\uC7AD-\\uC7C7\\uC7C9-\\uC7E3\\uC7E5-\\uC7FF\\uC801-\\uC81B\\uC81D-\\uC837\\uC839-\\uC853\\uC855-\\uC86F\\uC871-\\uC88B\\uC88D-\\uC8A7\\uC8A9-\\uC8C3\\uC8C5-\\uC8DF\\uC8E1-\\uC8FB\\uC8FD-\\uC917\\uC919-\\uC933\\uC935-\\uC94F\\uC951-\\uC96B\\uC96D-\\uC987\\uC989-\\uC9A3\\uC9A5-\\uC9BF\\uC9C1-\\uC9DB\\uC9DD-\\uC9F7\\uC9F9-\\uCA13\\uCA15-\\uCA2F\\uCA31-\\uCA4B\\uCA4D-\\uCA67\\uCA69-\\uCA83\\uCA85-\\uCA9F\\uCAA1-\\uCABB\\uCABD-\\uCAD7\\uCAD9-\\uCAF3\\uCAF5-\\uCB0F\\uCB11-\\uCB2B\\uCB2D-\\uCB47\\uCB49-\\uCB63\\uCB65-\\uCB7F\\uCB81-\\uCB9B\\uCB9D-\\uCBB7\\uCBB9-\\uCBD3\\uCBD5-\\uCBEF\\uCBF1-\\uCC0B\\uCC0D-\\uCC27\\uCC29-\\uCC43\\uCC45-\\uCC5F\\uCC61-\\uCC7B\\uCC7D-\\uCC97\\uCC99-\\uCCB3\\uCCB5-\\uCCCF\\uCCD1-\\uCCEB\\uCCED-\\uCD07\\uCD09-\\uCD23\\uCD25-\\uCD3F\\uCD41-\\uCD5B\\uCD5D-\\uCD77\\uCD79-\\uCD93\\uCD95-\\uCDAF\\uCDB1-\\uCDCB\\uCDCD-\\uCDE7\\uCDE9-\\uCE03\\uCE05-\\uCE1F\\uCE21-\\uCE3B\\uCE3D-\\uCE57\\uCE59-\\uCE73\\uCE75-\\uCE8F\\uCE91-\\uCEAB\\uCEAD-\\uCEC7\\uCEC9-\\uCEE3\\uCEE5-\\uCEFF\\uCF01-\\uCF1B\\uCF1D-\\uCF37\\uCF39-\\uCF53\\uCF55-\\uCF6F\\uCF71-\\uCF8B\\uCF8D-\\uCFA7\\uCFA9-\\uCFC3\\uCFC5-\\uCFDF\\uCFE1-\\uCFFB\\uCFFD-\\uD017\\uD019-\\uD033\\uD035-\\uD04F\\uD051-\\uD06B\\uD06D-\\uD087\\uD089-\\uD0A3\\uD0A5-\\uD0BF\\uD0C1-\\uD0DB\\uD0DD-\\uD0F7\\uD0F9-\\uD113\\uD115-\\uD12F\\uD131-\\uD14B\\uD14D-\\uD167\\uD169-\\uD183\\uD185-\\uD19F\\uD1A1-\\uD1BB\\uD1BD-\\uD1D7\\uD1D9-\\uD1F3\\uD1F5-\\uD20F\\uD211-\\uD22B\\uD22D-\\uD247\\uD249-\\uD263\\uD265-\\uD27F\\uD281-\\uD29B\\uD29D-\\uD2B7\\uD2B9-\\uD2D3\\uD2D5-\\uD2EF\\uD2F1-\\uD30B\\uD30D-\\uD327\\uD329-\\uD343\\uD345-\\uD35F\\uD361-\\uD37B\\uD37D-\\uD397\\uD399-\\uD3B3\\uD3B5-\\uD3CF\\uD3D1-\\uD3EB\\uD3ED-\\uD407\\uD409-\\uD423\\uD425-\\uD43F\\uD441-\\uD45B\\uD45D-\\uD477\\uD479-\\uD493\\uD495-\\uD4AF\\uD4B1-\\uD4CB\\uD4CD-\\uD4E7\\uD4E9-\\uD503\\uD505-\\uD51F\\uD521-\\uD53B\\uD53D-\\uD557\\uD559-\\uD573\\uD575-\\uD58F\\uD591-\\uD5AB\\uD5AD-\\uD5C7\\uD5C9-\\uD5E3\\uD5E5-\\uD5FF\\uD601-\\uD61B\\uD61D-\\uD637\\uD639-\\uD653\\uD655-\\uD66F\\uD671-\\uD68B\\uD68D-\\uD6A7\\uD6A9-\\uD6C3\\uD6C5-\\uD6DF\\uD6E1-\\uD6FB\\uD6FD-\\uD717\\uD719-\\uD733\\uD735-\\uD74F\\uD751-\\uD76B\\uD76D-\\uD787\\uD789-\\uD7A3]", - "SG": "[\\uDC00-\\uDFFF]|[\\uD800-\\uDBFF]", - "CB": "[\\uFFFC]" + Writable.prototype.cork = function () { + var state = this._writableState; + + state.corked++; }; + Writable.prototype.uncork = function () { + var state = this._writableState; -/***/ }, -/* 76 */ -/***/ function(module, exports, __webpack_require__) { + if (state.corked) { + state.corked--; + + if (!state.writing && !state.corked && !state.finished && !state.bufferProcessing && state.bufferedRequest) clearBuffer(this, state); + } + }; - var EventEmitter = __webpack_require__(50).EventEmitter, - TokenType = __webpack_require__(72), - BreakType = __webpack_require__(73), - util = __webpack_require__(70); + Writable.prototype.setDefaultEncoding = function setDefaultEncoding(encoding) { + // node::ParseEncoding() requires lower case. + if (typeof encoding === 'string') encoding = encoding.toLowerCase(); + if (!(['hex', 'utf8', 'utf-8', 'ascii', 'binary', 'base64', 'ucs2', 'ucs-2', 'utf16le', 'utf-16le', 'raw'].indexOf((encoding + '').toLowerCase()) > -1)) throw new TypeError('Unknown encoding: ' + encoding); + this._writableState.defaultEncoding = encoding; + return this; + }; - function LineBreak() { - EventEmitter.call(this); - this.tokenClass = null; - this.previousToken = null; - this.previousTokenClass = null; + function decodeChunk(state, chunk, encoding) { + if (!state.objectMode && state.decodeStrings !== false && typeof chunk === 'string') { + chunk = bufferShim.from(chunk, encoding); + } + return chunk; } - util.inherits(LineBreak, EventEmitter); - - var DI = BreakType.DIRECT, - IN = BreakType.INDIRECT, - CI = BreakType.COMBINING_INDIRECT, - CP = BreakType.COMBINING_PROHIBITED, - PR = BreakType.PROHIBITED, - EX = BreakType.EXPLICIT, - pairTable = [ - [PR, PR, PR, PR, PR, PR, PR, PR, PR, PR, PR, PR, PR, PR, PR, PR, PR, PR, PR, PR, PR, CP, PR, PR, PR, PR, PR, PR], - [DI, PR, PR, IN, IN, PR, PR, PR, PR, IN, IN, DI, DI, DI, DI, DI, IN, IN, DI, DI, PR, CI, PR, DI, DI, DI, DI, DI], - [DI, PR, PR, IN, IN, PR, PR, PR, PR, IN, IN, IN, IN, IN, DI, DI, IN, IN, DI, DI, PR, CI, PR, DI, DI, DI, DI, DI], - [PR, PR, PR, IN, IN, IN, PR, PR, PR, IN, IN, IN, IN, IN, IN, IN, IN, IN, IN, IN, PR, CI, PR, IN, IN, IN, IN, IN], - [IN, PR, PR, IN, IN, IN, PR, PR, PR, IN, IN, IN, IN, IN, IN, IN, IN, IN, IN, IN, PR, CI, PR, IN, IN, IN, IN, IN], - [DI, PR, PR, IN, IN, IN, PR, PR, PR, DI, DI, DI, DI, DI, DI, DI, IN, IN, DI, DI, PR, CI, PR, DI, DI, DI, DI, DI], - [DI, PR, PR, IN, IN, IN, PR, PR, PR, DI, DI, DI, DI, DI, DI, DI, IN, IN, DI, DI, PR, CI, PR, DI, DI, DI, DI, DI], - [DI, PR, PR, IN, IN, IN, PR, PR, PR, DI, DI, IN, DI, DI, DI, DI, IN, IN, DI, DI, PR, CI, PR, DI, DI, DI, DI, DI], - [DI, PR, PR, IN, IN, IN, PR, PR, PR, DI, DI, IN, IN, IN, DI, DI, IN, IN, DI, DI, PR, CI, PR, DI, DI, DI, DI, DI], - [IN, PR, PR, IN, IN, IN, PR, PR, PR, DI, DI, IN, IN, IN, IN, DI, IN, IN, DI, DI, PR, CI, PR, IN, IN, IN, IN, IN], - [IN, PR, PR, IN, IN, IN, PR, PR, PR, DI, DI, IN, IN, IN, DI, DI, IN, IN, DI, DI, PR, CI, PR, DI, DI, DI, DI, DI], - [IN, PR, PR, IN, IN, IN, PR, PR, PR, IN, IN, IN, IN, IN, DI, IN, IN, IN, DI, DI, PR, CI, PR, DI, DI, DI, DI, DI], - [IN, PR, PR, IN, IN, IN, PR, PR, PR, DI, DI, IN, IN, IN, DI, IN, IN, IN, DI, DI, PR, CI, PR, DI, DI, DI, DI, DI], - [IN, PR, PR, IN, IN, IN, PR, PR, PR, DI, DI, IN, IN, IN, DI, IN, IN, IN, DI, DI, PR, CI, PR, DI, DI, DI, DI, DI], - [DI, PR, PR, IN, IN, IN, PR, PR, PR, DI, IN, DI, DI, DI, DI, IN, IN, IN, DI, DI, PR, CI, PR, DI, DI, DI, DI, DI], - [DI, PR, PR, IN, IN, IN, PR, PR, PR, DI, DI, DI, DI, DI, DI, IN, IN, IN, DI, DI, PR, CI, PR, DI, DI, DI, DI, DI], - [DI, PR, PR, IN, DI, IN, PR, PR, PR, DI, DI, IN, DI, DI, DI, DI, IN, IN, DI, DI, PR, CI, PR, DI, DI, DI, DI, DI], - [DI, PR, PR, IN, DI, IN, PR, PR, PR, DI, DI, DI, DI, DI, DI, DI, IN, IN, DI, DI, PR, CI, PR, DI, DI, DI, DI, DI], - [IN, PR, PR, IN, IN, IN, PR, PR, PR, IN, IN, IN, IN, IN, IN, IN, IN, IN, IN, IN, PR, CI, PR, IN, IN, IN, IN, IN], - [DI, PR, PR, IN, IN, IN, PR, PR, PR, DI, DI, DI, DI, DI, DI, DI, IN, IN, DI, PR, PR, CI, PR, DI, DI, DI, DI, DI], - [DI, DI, DI, DI, DI, DI, DI, DI, DI, DI, DI, DI, DI, DI, DI, DI, DI, DI, DI, DI, PR, DI, DI, DI, DI, DI, DI, DI], - [IN, PR, PR, IN, IN, IN, PR, PR, PR, DI, DI, IN, IN, IN, DI, IN, IN, IN, DI, DI, PR, CI, PR, DI, DI, DI, DI, DI], - [IN, PR, PR, IN, IN, IN, PR, PR, PR, IN, IN, IN, IN, IN, IN, IN, IN, IN, IN, IN, PR, CI, PR, IN, IN, IN, IN, IN], - [DI, PR, PR, IN, IN, IN, PR, PR, PR, DI, IN, DI, DI, DI, DI, IN, IN, IN, DI, DI, PR, CI, PR, DI, DI, DI, IN, IN], - [DI, PR, PR, IN, IN, IN, PR, PR, PR, DI, IN, DI, DI, DI, DI, IN, IN, IN, DI, DI, PR, CI, PR, DI, DI, DI, DI, IN], - [DI, PR, PR, IN, IN, IN, PR, PR, PR, DI, IN, DI, DI, DI, DI, IN, IN, IN, DI, DI, PR, CI, PR, IN, IN, IN, IN, DI], - [DI, PR, PR, IN, IN, IN, PR, PR, PR, DI, IN, DI, DI, DI, DI, IN, IN, IN, DI, DI, PR, CI, PR, DI, DI, DI, IN, IN], - [DI, PR, PR, IN, IN, IN, PR, PR, PR, DI, IN, DI, DI, DI, DI, IN, IN, IN, DI, DI, PR, CI, PR, DI, DI, DI, DI, IN] - ]; + // if we're already writing something, then just put this + // in the queue, and wait our turn. Otherwise, call _write + // If we return false, then we need a drain event, so set that flag. + function writeOrBuffer(stream, state, chunk, encoding, cb) { + chunk = decodeChunk(state, chunk, encoding); - LineBreak.prototype.end = function() { - if (this.previousToken) { - this.emit('action', this.previousToken, this.previousTokenClass, BreakType.EXPLICIT); - } - this.emit('end'); - }; + if (Buffer.isBuffer(chunk)) encoding = 'buffer'; + var len = state.objectMode ? 1 : chunk.length; - LineBreak.prototype.process = function(token, tokenClass) { - var breakAction = null; + state.length += len; - if (this.tokenClass !== null) { - if (this.tokenClass !== TokenType.BK && (this.tokenClass !== TokenType.CR || tokenClass === TokenType.LF)) { - if (tokenClass === TokenType.SP) { - breakAction = BreakType.PROHIBITED; - } else if (tokenClass === TokenType.BK || - tokenClass === TokenType.NL || - tokenClass === TokenType.LF) { - breakAction = BreakType.PROHIBITED; - this.tokenClass = TokenType.BK; - } else if (tokenClass === TokenType.CR) { - breakAction = BreakType.PROHIBITED; - this.tokenClass = TokenType.BK; - } else { - breakAction = pairTable[this.tokenClass][tokenClass]; + var ret = state.length < state.highWaterMark; + // we must ensure that previous needDrain will not be reset to false. + if (!ret) state.needDrain = true; - if (breakAction === BreakType.INDIRECT) { - if (this.previousTokenClass === TokenType.SP) { - breakAction = BreakType.INDIRECT; - } else { - breakAction = BreakType.PROHIBITED; - } - this.tokenClass = tokenClass; - } else if (breakAction === BreakType.COMBINING_PROHIBITED) { - breakAction = BreakType.COMBINING_PROHIBITED; - if (this.previousTokenClass === TokenType.SP) { - this.tokenClass = tokenClass; - } - } else if (breakAction === BreakType.COMBINING_INDIRECT) { - breakAction = BreakType.PROHIBITED; - if (this.previousTokenClass === TokenType.SP) { - breakAction = BreakType.COMBINING_INDIRECT; - this.tokenClass = tokenClass; - } - } else { - this.tokenClass = tokenClass; - } - } - this.emit('action', this.previousToken, this.previousTokenClass, breakAction); - } else { - this.emit('action', this.previousToken, this.previousTokenClass, BreakType.EXPLICIT); - if (tokenClass === TokenType.SP) { - this.tokenClass = TokenType.WJ; - } else if (tokenClass === TokenType.LF || tokenClass === TokenType.NL) { - this.tokenClass = TokenType.BK; - } else { - this.tokenClass = tokenClass; - } - } + if (state.writing || state.corked) { + var last = state.lastBufferedRequest; + state.lastBufferedRequest = new WriteReq(chunk, encoding, cb); + if (last) { + last.next = state.lastBufferedRequest; } else { - if (tokenClass === TokenType.SP) { - this.tokenClass = TokenType.WJ; - } else if (tokenClass === TokenType.LF || tokenClass === TokenType.NL) { - this.tokenClass = TokenType.BK; - } else { - this.tokenClass = tokenClass; - } + state.bufferedRequest = state.lastBufferedRequest; } - this.previousToken = token; - this.previousTokenClass = tokenClass; - }; - - module.exports = LineBreak; + state.bufferedRequestCount += 1; + } else { + doWrite(stream, state, false, len, chunk, encoding, cb); + } + return ret; + } -/***/ }, -/* 77 */ -/***/ function(module, exports, __webpack_require__) { + function doWrite(stream, state, writev, len, chunk, encoding, cb) { + state.writelen = len; + state.writecb = cb; + state.writing = true; + state.sync = true; + if (writev) stream._writev(chunk, state.onwrite);else stream._write(chunk, encoding, state.onwrite); + state.sync = false; + } - "use strict"; - var __extends = (this && this.__extends) || function (d, b) { - for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; - var rect_1 = __webpack_require__(1); - var point_1 = __webpack_require__(2); - var matrix_stack_1 = __webpack_require__(78); - var DirtyRectContext = (function (_super) { - __extends(DirtyRectContext, _super); - function DirtyRectContext() { - _super.call(this); - this._rect = rect_1.Rect.create(0, 0, 0, 0); - this.reset(); - } - DirtyRectContext.prototype.addRect = function (x, y, w, h) { - var p = point_1.Point.point; - this.addPoint(this.transformPoint(x, y, p)); - this.addPoint(this.transformPoint(x + w, y, p)); - this.addPoint(this.transformPoint(x + w, y + h, p)); - this.addPoint(this.transformPoint(x, y + h, p)); - }; - DirtyRectContext.prototype.addPoint = function (p) { - var x = p.x; - var y = p.y; - if (!this._pointsNr) { - this._minX = this._maxX = x; - this._minY = this._maxY = y; - } - else { - if (this._minX > x) { - this._minX = x; - } - if (this._maxX < x) { - this._maxX = x; - } - if (this._minY > y) { - this._minY = y; - } - if (this._maxY < y) { - this._maxY = y; - } - } - this._pointsNr++; - }; - DirtyRectContext.prototype.getRect = function () { - var r = this._rect; - r.x = this._minX; - r.y = this._minY; - r.w = this._maxX - this._minX; - r.h = this._maxY - this._minY; - return r; - }; - DirtyRectContext.prototype.reset = function () { - this._pointsNr = 0; - this.identity(); - this._minX = -1; - this._minY = -1; - this._maxX = -1; - this._maxY = -1; - }; - DirtyRectContext.create = function () { - return new DirtyRectContext(); - }; - return DirtyRectContext; - }(matrix_stack_1.MatrixStack)); - exports.DirtyRectContext = DirtyRectContext; - ; + function onwriteError(stream, state, sync, er, cb) { + --state.pendingcb; + if (sync) processNextTick(cb, er);else cb(er); + stream._writableState.errorEmitted = true; + stream.emit('error', er); + } -/***/ }, -/* 78 */ -/***/ function(module, exports, __webpack_require__) { + function onwriteStateUpdate(state) { + state.writing = false; + state.writecb = null; + state.length -= state.writelen; + state.writelen = 0; + } - "use strict"; - var matrix_1 = __webpack_require__(12); - var MatrixStack = (function () { - function MatrixStack() { - this.stack = []; - this.matrix = new matrix_1.Matrix(); - } - MatrixStack.prototype.save = function () { - this.stack.push(this.matrix.clone()); - return this; - }; - MatrixStack.prototype.restore = function () { - if (this.stack.length) { - this.matrix = this.stack.pop(); - } - return this; - }; - MatrixStack.prototype.identity = function () { - this.matrix.identity(); - return this; - }; - MatrixStack.prototype.set = function (a, b, c, d, tx, ty) { - this.matrix.set(a, b, c, d, tx, ty); - return this; - }; - MatrixStack.prototype.rotate = function (rad) { - this.matrix.rotate(rad); - return this; - }; - MatrixStack.prototype.scale = function (sx, sy) { - this.matrix.scale(sx, sy); - return this; - }; - MatrixStack.prototype.translate = function (dx, dy) { - this.matrix.translate(dx, dy); - }; - MatrixStack.prototype.transformPoint = function (x, y, out) { - return this.matrix.transformPoint(x, y, out); - }; - MatrixStack.prototype.invert = function () { - return this.matrix.invert(); - }; - MatrixStack.prototype.matrixToString = function () { - return this.matrix.toString(); - }; - MatrixStack.create = function () { - return new MatrixStack(); - }; - return MatrixStack; - }()); - exports.MatrixStack = MatrixStack; - ; + function onwrite(stream, er) { + var state = stream._writableState; + var sync = state.sync; + var cb = state.writecb; + onwriteStateUpdate(state); -/***/ }, -/* 79 */ -/***/ function(module, exports, __webpack_require__) { + if (er) onwriteError(stream, state, sync, er, cb);else { + // Check if we're actually ready to finish, but don't emit yet + var finished = needFinish(state); - "use strict"; - var Events = __webpack_require__(6); - var inputEventAdapter = __webpack_require__(15); - /** - * Behavior代表控件的一种行为特性,比如Resizable/Movable/Draggable/Droppable等。 - * 把这些行为特性抽象出来单独实现,一方面可以避免让Widget变得太复杂,另一方面可以最大限度的重用这些行为特性。 - * - * 任何一个Widget,都可以使用useBehavior来启用某种Behavior。比如下面的代码让image具有Resizable的特性: - * - * ``` - * image.useBehavior("resizable", {all:true}); - * ``` - */ - var Behavior = (function () { - /** - * 构造函数。主要是注册一些事件,把这些事件映射在成员函数上,子类只需要重载这些成员函数即可。 - * @param type 类型名。 - * @param widget Behavior作用的Widget。 - * @param options 初始化参数,与具体的Behavior有关。 - */ - function Behavior(type, widget, options) { - this.type = type; - this.widget = widget; - this.keyDownGlobalFunc = this.onKeyDownGlobal.bind(this); - this.keyUpGlobalFunc = this.onKeyUpGlobal.bind(this); - this.pointerEnterFunc = this.onPointerEnter.bind(this); - this.pointerLeaveFunc = this.onPointerLeave.bind(this); - this.pointerDownFunc = this.onPointerDown.bind(this); - this.pointerMoveFunc = this.onPointerMove.bind(this); - this.pointerUpFunc = this.onPointerUp.bind(this); - this.keyDownFunc = this.onKeyDown.bind(this); - this.keyUpFunc = this.onKeyUp.bind(this); - inputEventAdapter.on(Events.KEYDOWN, this.keyDownGlobalFunc); - inputEventAdapter.on(Events.KEYUP, this.keyUpGlobalFunc); - widget.on(Events.POINTER_ENTER, this.pointerEnterFunc); - widget.on(Events.POINTER_LEAVE, this.pointerLeaveFunc); - widget.on(Events.POINTER_DOWN, this.pointerDownFunc); - widget.on(Events.POINTER_MOVE, this.pointerMoveFunc); - widget.on(Events.DISPOSE, this.dispose.bind(this)); - widget.on(Events.POINTER_UP, this.pointerUpFunc); - widget.on(Events.KEYDOWN, this.keyDownFunc); - widget.on(Events.KEYUP, this.keyUpFunc); - this.init(options || {}); - this._json = { type: type, options: options }; - } - /** - * 初始化。在具体的Behavior的实现中,可以重载此函数做些初始化的工作。 - * @param options 初始化参数,与具体的Behavior有关。 - */ - Behavior.prototype.init = function (options) { - return this; - }; - Behavior.prototype.setOptions = function (options) { - this.init(options); - }; - /** - * 析构函数。 主要是注销事件的处理函数。 - */ - Behavior.prototype.dispose = function () { - var widget = this.widget; - inputEventAdapter.off(Events.KEYDOWN, this.keyDownGlobalFunc); - inputEventAdapter.off(Events.KEYUP, this.keyUpGlobalFunc); - widget.off(Events.POINTER_ENTER, this.pointerEnterFunc); - widget.off(Events.POINTER_LEAVE, this.pointerLeaveFunc); - widget.off(Events.POINTER_DOWN, this.pointerDownFunc); - widget.off(Events.POINTER_MOVE, this.pointerMoveFunc); - widget.off(Events.POINTER_UP, this.pointerUpFunc); - widget.off(Events.KEYDOWN, this.keyDownFunc); - widget.off(Events.KEYUP, this.keyUpFunc); - this.widget = null; - }; - Behavior.prototype.toJson = function () { - this._json; - }; - /** - * 子类重载此函数,可以处理Widget的按键按下事件。 - */ - Behavior.prototype.onKeyDown = function (evt) { - }; - /** - * 子类重载此函数,可以处理Widget的按键抬起事件。 - */ - Behavior.prototype.onKeyUp = function (evt) { - }; - /** - * 子类重载此函数,可以处理全局的按键按下事件。 - */ - Behavior.prototype.onKeyDownGlobal = function (evt) { - }; - /** - * 子类重载此函数,可以处理全局的按键抬起事件。 - */ - Behavior.prototype.onKeyUpGlobal = function (evt) { - }; - /** - * 子类重载此函数,可以处理Widget的PointerEnter事件。 - */ - Behavior.prototype.onPointerEnter = function (evt) { - }; - /** - * 子类重载此函数,可以处理Widget的PointerLeave事件。 - */ - Behavior.prototype.onPointerLeave = function (evt) { - }; - /** - * 子类重载此函数,可以处理Widget的PointerDown事件。 - */ - Behavior.prototype.onPointerDown = function (evt) { - }; - /** - * 子类重载此函数,可以处理Widget的PointerMove事件。 - */ - Behavior.prototype.onPointerMove = function (evt) { - }; - /** - * 子类重载此函数,可以处理Widget的PointerUp事件。 - */ - Behavior.prototype.onPointerUp = function (evt) { - }; - return Behavior; - }()); - exports.Behavior = Behavior; - /** - * Behavior工厂类。 - * - * 具体的Behavior需要调用BehaviorFactory.register注册自己,useBehavior才能找到对应的Behavior。 - */ - var BehaviorFactory = (function () { - function BehaviorFactory() { + if (!finished && !state.corked && !state.bufferProcessing && state.bufferedRequest) { + clearBuffer(stream, state); } - /** - * 注册Behavior - * @param type Behavior的类型名。 - * @param creator Behavior创建函数。 - */ - BehaviorFactory.register = function (type, creator) { - BehaviorFactory.creators[type] = creator; - }; - /** - * 创建Behavior。目前只在useBehavior中会用到。 - * @param type Behavior的类型名。 - * @param widget Behavior作用的Widget。 - * @param options Behavior的初始化参数。 - */ - BehaviorFactory.create = function (type, widget, options) { - var create = BehaviorFactory.creators[type]; - return create ? create(widget, options) : null; - }; - BehaviorFactory.creators = {}; - return BehaviorFactory; - }()); - exports.BehaviorFactory = BehaviorFactory; + if (sync) { + /**/ + asyncWrite(afterWrite, stream, state, finished, cb); + /**/ + } else { + afterWrite(stream, state, finished, cb); + } + } + } + + function afterWrite(stream, state, finished, cb) { + if (!finished) onwriteDrain(stream, state); + state.pendingcb--; + cb(); + finishMaybe(stream, state); + } -/***/ }, -/* 80 */ -/***/ function(module, exports, __webpack_require__) { + // Must force callback to be called on nextTick, so that we don't + // emit 'drain' before the write() consumer gets the 'false' return + // value, and has a chance to attach a 'drain' listener. + function onwriteDrain(stream, state) { + if (state.length === 0 && state.needDrain) { + state.needDrain = false; + stream.emit('drain'); + } + } - "use strict"; - var __extends = (this && this.__extends) || function (d, b) { - for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; - var factory_1 = __webpack_require__(25); - /** - * 子控件布局算法。 - */ - var Layouter = (function () { - function Layouter() { - } - Object.defineProperty(Layouter.prototype, "type", { - /** - * 布局算法的名称。 - */ - get: function () { - return "dummy"; - }, - enumerable: true, - configurable: true - }); - /** - * 设置参数。 - */ - Layouter.prototype.setOptions = function (options) { - return this; - }; - /** - * 对子控件进行布局。 - * @param widget 父控件 - * @param children 只控件 - * @returns 全部子控件需要的区域。 - */ - Layouter.prototype.layoutChildren = function (widget, children, rect) { - return null; - }; - Layouter.prototype.createParam = function (options) { - return null; - }; - /** - * 从JSON数据创建。 - */ - Layouter.prototype.fromJson = function (json) { - for (var key in json) { - var value = json[key]; - var type = typeof value; - if (type === "number" || type === "string") { - this[key] = value; - } - } - return this; - }; - /** - * 转换成JSON数据。 - */ - Layouter.prototype.toJson = function () { - var json = {}; - for (var key in this) { - var value = this[key]; - var type = typeof value; - if (type === "number" || type === "string") { - json[key] = value; - } - } - return json; - }; - Layouter.evalValue = function (value, total) { - var v = parseFloat(value); - if (typeof value === "number") { - return v; - } - if (value.indexOf("%") > 0) { - v = total * v / 100; - } - if (v < 0) { - v = total + v; - } - return v; - }; - return Layouter; - }()); - exports.Layouter = Layouter; - /** - * Layouter的工厂。 - */ - var LayouterFactory = (function (_super) { - __extends(LayouterFactory, _super); - function LayouterFactory() { - _super.apply(this, arguments); + // if there's something in the buffer waiting, then process it + function clearBuffer(stream, state) { + state.bufferProcessing = true; + var entry = state.bufferedRequest; + + if (stream._writev && entry && entry.next) { + // Fast case, write everything using _writev() + var l = state.bufferedRequestCount; + var buffer = new Array(l); + var holder = state.corkedRequestsFree; + holder.entry = entry; + + var count = 0; + while (entry) { + buffer[count] = entry; + entry = entry.next; + count += 1; } - LayouterFactory.register = function (type, creator) { - return LayouterFactory.factory.register(type, creator); - }; - LayouterFactory.create = function (type, options) { - return LayouterFactory.factory.create(type, options); - }; - LayouterFactory.createWithJson = function (json) { - var layouter = LayouterFactory.create(json.type, null); - layouter.fromJson(json); - return layouter; - }; - LayouterFactory.factory = new factory_1.Factory(); - return LayouterFactory; - }(factory_1.Factory)); - exports.LayouterFactory = LayouterFactory; - /** - * 布局参数。 - * 如果父控件有指定childrenLayouter,那么其中的子控件需要有与之对应的LayouterParam。 - */ - var LayouterParam = (function () { - function LayouterParam(type) { - this.type = type; + + doWrite(stream, state, true, state.length, buffer, '', holder.finish); + + // doWrite is almost always async, defer these to save a bit of time + // as the hot path ends with doWrite + state.pendingcb++; + state.lastBufferedRequest = null; + if (holder.next) { + state.corkedRequestsFree = holder.next; + holder.next = null; + } else { + state.corkedRequestsFree = new CorkedRequest(state); } - Object.defineProperty(LayouterParam.prototype, "widget", { - get: function () { - return this._widget; - }, - /** - * 与之关联的Widget。 - */ - set: function (value) { - this._widget = value; - }, - enumerable: true, - configurable: true - }); - /** - * 从JSON数据创建。 - */ - LayouterParam.prototype.fromJson = function (json) { - for (var key in json) { - var value = json[key]; - var type = typeof value; - if (type === "number" || type === "string") { - this[key] = value; - } - } - return this; - }; - /** - * 转换成JSON数据。 - */ - LayouterParam.prototype.toJson = function () { - var json = {}; - for (var key in this) { - var value = this[key]; - var type = typeof value; - if (type === "number" || type === "string") { - json[key] = value; - } - } - return json; - }; - return LayouterParam; - }()); - exports.LayouterParam = LayouterParam; - ; - /** - * LayouterParam的工厂。 - */ - var LayouterParamFactory = (function (_super) { - __extends(LayouterParamFactory, _super); - function LayouterParamFactory() { - _super.apply(this, arguments); + } else { + // Slow case, write chunks one-by-one + while (entry) { + var chunk = entry.chunk; + var encoding = entry.encoding; + var cb = entry.callback; + var len = state.objectMode ? 1 : chunk.length; + + doWrite(stream, state, false, len, chunk, encoding, cb); + entry = entry.next; + // if we didn't call the onwrite immediately, then + // it means that we need to wait until it does. + // also, that means that the chunk and cb are currently + // being processed, so move the buffer counter past them. + if (state.writing) { + break; + } } - LayouterParamFactory.register = function (type, creator) { - return LayouterParamFactory.factory.register(type, creator); - }; - LayouterParamFactory.create = function (type, options) { - return LayouterParamFactory.factory.create(type, options); - }; - LayouterParamFactory.createWithJson = function (json) { - var layouter = LayouterParamFactory.create(json.type, null); - layouter.fromJson(json); - return layouter; - }; - LayouterParamFactory.factory = new factory_1.Factory(); - return LayouterParamFactory; - }(factory_1.Factory)); - exports.LayouterParamFactory = LayouterParamFactory; + if (entry === null) state.lastBufferedRequest = null; + } -/***/ }, -/* 81 */ -/***/ function(module, exports, __webpack_require__) { + state.bufferedRequestCount = 0; + state.bufferedRequest = entry; + state.bufferProcessing = false; + } - "use strict"; - var __extends = (this && this.__extends) || function (d, b) { - for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + Writable.prototype._write = function (chunk, encoding, cb) { + cb(new Error('_write() is not implemented')); }; - var json_serializer_1 = __webpack_require__(82); - var iview_model_1 = __webpack_require__(83); - var iview_model_2 = __webpack_require__(83); - ; - /** - * 数据源。如果指定了value,直接从value获取数据。否则通过path从ViewModel中获取数据。 - */ - var BindingDataSource = (function (_super) { - __extends(BindingDataSource, _super); - function BindingDataSource(path, value, mode, updateTiming, validationRule, converter) { - _super.call(this); - this.converter = converter; - this.type = BindingDataSource.TYPE; - this.validationRule = validationRule; - this.mode = mode || iview_model_2.BindingMode.TWO_WAY; - this.updateTiming = updateTiming !== undefined ? updateTiming : iview_model_2.UpdateTiming.CHANGING; - if (path !== undefined) { - this.path = path; - } - if (value !== undefined) { - this.value = value; - } - } - BindingDataSource.create = function (path, value, mode, updateTiming, validationRule, converter) { - return new BindingDataSource(path, value, mode, updateTiming, validationRule, converter); - }; - BindingDataSource.TYPE = "data"; - return BindingDataSource; - }(json_serializer_1.JsonSerializer)); - exports.BindingDataSource = BindingDataSource; - ; - /** - * 命令源。 - */ - var BindingCommandSource = (function (_super) { - __extends(BindingCommandSource, _super); - function BindingCommandSource(command, commandArgs) { - _super.call(this); - this.command = command; - this.eventHandler = null; - this.commandArgs = commandArgs; - this.type = BindingCommandSource.TYPE; - } - BindingCommandSource.create = function (command, commandArgs) { - return new BindingCommandSource(command, commandArgs); - }; - BindingCommandSource.TYPE = "command"; - return BindingCommandSource; - }(json_serializer_1.JsonSerializer)); - exports.BindingCommandSource = BindingCommandSource; - /** - * 单项数据绑定规则。 - */ - var BindingRuleItem = (function () { - function BindingRuleItem(prop, source) { - this.prop = prop; - this.source = source; - } - BindingRuleItem.prototype.toJson = function () { - return { prop: this.prop, source: this.source.toJson() }; - }; - BindingRuleItem.prototype.fromJson = function (json) { - this.prop = json.prop; - var source = json.source; - if (source.command) { - this.source = BindingCommandSource.create(source.command, source.commandArgs); - } - else { - this.source = BindingDataSource.create(source.path, source.value, source.mode, source.updateTiming, source.validationRule, source.converter); - } - return this; - }; - BindingRuleItem.create = function (prop, source) { - return new BindingRuleItem(prop, source); - }; - return BindingRuleItem; - }()); - exports.BindingRuleItem = BindingRuleItem; - ; - /** - * 数据绑定规则。 - */ - var BindingRule = (function () { - function BindingRule() { - } - BindingRule.prototype.getSource = function (prop) { - return this._items[prop]; - }; - BindingRule.prototype.forEach = function (func) { - var items = this._items; - for (var prop in items) { - var item = items[prop]; - func(prop, item); - } - }; - BindingRule.prototype.fromData = function (json) { - this._items = {}; - for (var prop in json) { - var source = null; - var sJson = json[prop]; - if (sJson.command) { - source = BindingCommandSource.create(sJson.command, sJson.commandArgs); - } - else { - source = BindingDataSource.create(sJson.path, sJson.value, sJson.mode, sJson.updateTiming, sJson.validationRule, sJson.converter); - } - this._items[prop] = BindingRuleItem.create(prop, source); - } - return this; - }; - BindingRule.prototype.fromJson = function (json) { - this._items = {}; - for (var prop in json) { - var source = null; - var propJson = json[prop]; - var sourceJson = propJson.source; - if (sourceJson.command) { - source = BindingCommandSource.create(sourceJson.command, sourceJson.commandArgs); - } - else { - source = BindingDataSource.create(sourceJson.path, sourceJson.value, sourceJson.mode, sourceJson.updateTiming, sourceJson.validationRule, sourceJson.converter); - } - this._items[prop] = BindingRuleItem.create(prop, source); - } - return this; - }; - BindingRule.prototype.toJson = function () { - var json = {}; - var items = this._items; - for (var prop in items) { - var item = items[prop]; - json[prop] = item.toJson(); - } - return json; - }; - BindingRule.parse = function (rule) { - if (typeof rule === "string") { - rule = { value: { path: rule } }; - } - for (var key in rule) { - var dataSource = rule[key]; - if (typeof dataSource === "string") { - rule[key] = { path: dataSource }; - dataSource = rule[key]; - } - var path = dataSource.path; - if (path && path.charAt(0) !== '/') { - dataSource.path = '/' + dataSource.path; - } - var mode = dataSource.mode; - if (mode && typeof mode === "string") { - dataSource.mode = iview_model_1.toBindingMode(mode); - } - var updateTiming = dataSource.updateTiming; - if (updateTiming && typeof updateTiming === "string") { - dataSource.updateTiming = iview_model_1.toUpdateTiming(updateTiming); - } - } - return rule; - }; - BindingRule.create = function (data) { - var rule = new BindingRule(); - return rule.fromData(BindingRule.parse(data)); - }; - BindingRule.createFromJson = function (json) { - var rule = new BindingRule(); - return rule.fromJson(json); - }; - return BindingRule; - }()); - exports.BindingRule = BindingRule; + Writable.prototype._writev = null; -/***/ }, -/* 82 */ -/***/ function(module, exports) { + Writable.prototype.end = function (chunk, encoding, cb) { + var state = this._writableState; - "use strict"; - /** - * 把当前对象转换成JSON对象或从JSON对象来初始化当前对象。 - */ - var JsonSerializer = (function () { - function JsonSerializer() { - } - JsonSerializer.prototype.toJson = function () { - var json = {}; - for (var key in this) { - var value = this[key]; - if (this.hasOwnProperty(key) && typeof value !== "function") { - json[key] = value; - } - } - return json; - }; - JsonSerializer.prototype.fromJson = function (json) { - for (var key in json) { - this[key] = json[key]; - } - }; - return JsonSerializer; - }()); - exports.JsonSerializer = JsonSerializer; + if (typeof chunk === 'function') { + cb = chunk; + chunk = null; + encoding = null; + } else if (typeof encoding === 'function') { + cb = encoding; + encoding = null; + } + if (chunk !== null && chunk !== undefined) this.write(chunk, encoding); -/***/ }, -/* 83 */ -/***/ function(module, exports) { + // .end() fully uncorks + if (state.corked) { + state.corked = 1; + this.uncork(); + } - "use strict"; - ; - ; - /** - * 数据绑定模式。 - */ - (function (BindingMode) { - /** - * 双向数据绑定。 - * 界面数据变化时自动更新ViewModel,ViewModel数据有变化时自动更新界面。 - */ - BindingMode[BindingMode["TWO_WAY"] = 0] = "TWO_WAY"; - /** - * 单向数据绑定。 - * 界面数据变化时不更新ViewModel,ViewModel数据有变化时自动更新界面。 - */ - BindingMode[BindingMode["ONE_WAY"] = 1] = "ONE_WAY"; - /** - * 只在初始化时绑定。 - * 界面数据变化时不更新ViewModel,ViewModel数据有变化时不更新界面。 - */ - BindingMode[BindingMode["ONE_TIME"] = 2] = "ONE_TIME"; - /** - * 单向数据绑定。 - * 界面数据变化时自动更新ViewModel,ViewModel数据有变化时不更新界面。 - */ - BindingMode[BindingMode["ONE_WAY_TO_SOURCE"] = 3] = "ONE_WAY_TO_SOURCE"; - })(exports.BindingMode || (exports.BindingMode = {})); - var BindingMode = exports.BindingMode; - ; - var BindingModeNames = ["two-way", "one-way", "one-time", "one-way-to-source"]; - function toBindingMode(name) { - return Math.max(0, BindingModeNames.indexOf(name)); + // ignore unnecessary end() calls. + if (!state.ending && !state.finished) endWritable(this, state, cb); + }; + + function needFinish(state) { + return state.ending && state.length === 0 && state.bufferedRequest === null && !state.finished && !state.writing; } - exports.toBindingMode = toBindingMode; - /** - * 更新ViewModel的时机。 - */ - (function (UpdateTiming) { - /** - * 有变化时立即更新(如编辑器正在输入)。 - */ - UpdateTiming[UpdateTiming["CHANGING"] = 0] = "CHANGING"; - /** - * 变化完成时才更新(如编辑器失去焦点时)。 - */ - UpdateTiming[UpdateTiming["CHANGED"] = 1] = "CHANGED"; - /** - * 手动更新。 - */ - UpdateTiming[UpdateTiming["EXPLICIT"] = 2] = "EXPLICIT"; - })(exports.UpdateTiming || (exports.UpdateTiming = {})); - var UpdateTiming = exports.UpdateTiming; - ; - var UpdateTimingNames = ["changing", "changed", "explicit"]; - function toUpdateTiming(name) { - return Math.max(0, UpdateTimingNames.indexOf(name)); + + function prefinish(stream, state) { + if (!state.prefinished) { + state.prefinished = true; + stream.emit('prefinish'); + } + } + + function finishMaybe(stream, state) { + var need = needFinish(state); + if (need) { + if (state.pendingcb === 0) { + prefinish(stream, state); + state.finished = true; + stream.emit('finish'); + } else { + prefinish(stream, state); + } + } + return need; + } + + function endWritable(stream, state, cb) { + state.ending = true; + finishMaybe(stream, state); + if (cb) { + if (state.finished) processNextTick(cb);else stream.once('finish', cb); + } + state.ended = true; + stream.writable = false; + } + + // It seems a linked list but it is not + // there will be only 2 of these for each stream + function CorkedRequest(state) { + var _this = this; + + this.next = null; + this.entry = null; + + this.finish = function (err) { + var entry = _this.entry; + _this.entry = null; + while (entry) { + var cb = entry.callback; + state.pendingcb--; + cb(err); + entry = entry.next; + } + if (state.corkedRequestsFree) { + state.corkedRequestsFree.next = _this; + } else { + state.corkedRequestsFree = _this; + } + }; + } + /* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(10), __webpack_require__(65).setImmediate)) + +/***/ }, +/* 65 */ +/***/ function(module, exports, __webpack_require__) { + + var apply = Function.prototype.apply; + + // DOM APIs, for completeness + + exports.setTimeout = function() { + return new Timeout(apply.call(setTimeout, window, arguments), clearTimeout); + }; + exports.setInterval = function() { + return new Timeout(apply.call(setInterval, window, arguments), clearInterval); + }; + exports.clearTimeout = + exports.clearInterval = function(timeout) { + if (timeout) { + timeout.close(); + } + }; + + function Timeout(id, clearFn) { + this._id = id; + this._clearFn = clearFn; } - exports.toUpdateTiming = toUpdateTiming; + Timeout.prototype.unref = Timeout.prototype.ref = function() {}; + Timeout.prototype.close = function() { + this._clearFn.call(window, this._id); + }; + + // Does not start the time, just sets up the members needed. + exports.enroll = function(item, msecs) { + clearTimeout(item._idleTimeoutId); + item._idleTimeout = msecs; + }; + + exports.unenroll = function(item) { + clearTimeout(item._idleTimeoutId); + item._idleTimeout = -1; + }; + + exports._unrefActive = exports.active = function(item) { + clearTimeout(item._idleTimeoutId); + + var msecs = item._idleTimeout; + if (msecs >= 0) { + item._idleTimeoutId = setTimeout(function onTimeout() { + if (item._onTimeout) + item._onTimeout(); + }, msecs); + } + }; + + // setimmediate attaches itself to the global object + __webpack_require__(66); + exports.setImmediate = setImmediate; + exports.clearImmediate = clearImmediate; /***/ }, -/* 84 */ +/* 66 */ /***/ function(module, exports, __webpack_require__) { - "use strict"; - var __extends = (this && this.__extends) || function (d, b) { - for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; - var recyclable_creator_1 = __webpack_require__(85); - /** - * 可循环的创建器。 - */ - var WidgetRecyclableCreator = (function (_super) { - __extends(WidgetRecyclableCreator, _super); - function WidgetRecyclableCreator(ctor) { - _super.call(this, function () { - return new ctor; - }); - this._type = ctor.TYPE; + /* WEBPACK VAR INJECTION */(function(global, process) {(function (global, undefined) { + "use strict"; + + if (global.setImmediate) { + return; } - WidgetRecyclableCreator.prototype.create = function (options) { - var obj = _super.prototype.create.call(this); - obj.reset(this._type, options); - return obj; - }; - WidgetRecyclableCreator.create = function (ctor) { - return new WidgetRecyclableCreator(ctor); - }; - return WidgetRecyclableCreator; - }(recyclable_creator_1.RecyclableCreator)); - exports.WidgetRecyclableCreator = WidgetRecyclableCreator; - ; + var nextHandle = 1; // Spec says greater than zero + var tasksByHandle = {}; + var currentlyRunningATask = false; + var doc = global.document; + var registerImmediate; -/***/ }, -/* 85 */ -/***/ function(module, exports) { + function setImmediate(callback) { + // Callback can either be a function or a string + if (typeof callback !== "function") { + callback = new Function("" + callback); + } + // Copy function arguments + var args = new Array(arguments.length - 1); + for (var i = 0; i < args.length; i++) { + args[i] = arguments[i + 1]; + } + // Store and register the task + var task = { callback: callback, args: args }; + tasksByHandle[nextHandle] = task; + registerImmediate(nextHandle); + return nextHandle++; + } - "use strict"; - /** - * 可循环的创建器。 - */ - var RecyclableCreator = (function () { - function RecyclableCreator(ctor) { - this.cache = []; - this.ctor = ctor; + function clearImmediate(handle) { + delete tasksByHandle[handle]; } - /** - * 回收对象。 - */ - RecyclableCreator.prototype.recycle = function (obj) { - if (obj) { - this.cache.push(obj); + + function run(task) { + var callback = task.callback; + var args = task.args; + switch (args.length) { + case 0: + callback(); + break; + case 1: + callback(args[0]); + break; + case 2: + callback(args[0], args[1]); + break; + case 3: + callback(args[0], args[1], args[2]); + break; + default: + callback.apply(undefined, args); + break; } - }; - /** - * 创建对象。优先从缓存中取对象,如果缓存中没有对象,则创建新对象。 - */ - RecyclableCreator.prototype.create = function (options) { - var me = this; - if (this.cache.length) { - return this.cache.pop(); + } + + function runIfPresent(handle) { + // From the spec: "Wait until any invocations of this algorithm started before this one have completed." + // So if we're currently running a task, we'll need to delay this invocation. + if (currentlyRunningATask) { + // Delay by doing a setTimeout. setImmediate was tried instead, but in Firefox 7 it generated a + // "too much recursion" error. + setTimeout(runIfPresent, 0, handle); + } else { + var task = tasksByHandle[handle]; + if (task) { + currentlyRunningATask = true; + try { + run(task); + } finally { + clearImmediate(handle); + currentlyRunningATask = false; + } + } } - else { - var obj = (this.ctor()); - obj.recycle = function () { - me.recycle(this); + } + + function installNextTickImplementation() { + registerImmediate = function(handle) { + process.nextTick(function () { runIfPresent(handle); }); + }; + } + + function canUsePostMessage() { + // The test against `importScripts` prevents this implementation from being installed inside a web worker, + // where `global.postMessage` means something completely different and can't be used for this purpose. + if (global.postMessage && !global.importScripts) { + var postMessageIsAsynchronous = true; + var oldOnMessage = global.onmessage; + global.onmessage = function() { + postMessageIsAsynchronous = false; }; - return obj; + global.postMessage("", "*"); + global.onmessage = oldOnMessage; + return postMessageIsAsynchronous; } - }; - return RecyclableCreator; - }()); - exports.RecyclableCreator = RecyclableCreator; - ; - + } -/***/ }, -/* 86 */ -/***/ function(module, exports, __webpack_require__) { + function installPostMessageImplementation() { + // Installs an event handler on `global` for the `message` event: see + // * https://developer.mozilla.org/en/DOM/window.postMessage + // * http://www.whatwg.org/specs/web-apps/current-work/multipage/comms.html#crossDocumentMessages - "use strict"; - var __extends = (this && this.__extends) || function (d, b) { - for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; - var Events = __webpack_require__(6); - var html_element_1 = __webpack_require__(87); - var event_detail_1 = __webpack_require__(14); - var HtmlEdit = (function (_super) { - __extends(HtmlEdit, _super); - function HtmlEdit() { - _super.apply(this, arguments); - this.changeEvent = Events.ChangeEvent.create(); - this.keyEvent = Events.KeyEvent.create(null, event_detail_1.KeyEventDetail.create(0)); - } - Object.defineProperty(HtmlEdit.prototype, "inputType", { - set: function (value) { - if (this.tag === "input") { - this.element.type = value; - } - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(HtmlEdit.prototype, "text", { - get: function () { - return this.element.value; - }, - set: function (value) { - this.element.value = value; - }, - enumerable: true, - configurable: true - }); - HtmlEdit.prototype.show = function () { - _super.prototype.show.call(this); - this.element.focus(); - this._visible = true; - this.dispatchEvent({ type: Events.SHOW }); - return this; - }; - HtmlEdit.prototype.hide = function () { - if (this._visible) { - this._visible = false; - this.element.blur(); - this.dispatchEvent({ type: Events.HIDE }); - } - this.removeAllListeners(); - return _super.prototype.hide.call(this); - }; - HtmlEdit.prototype.create = function (tag) { - _super.prototype.create.call(this, tag); - var me = this; - var element = this.element; - element.onkeyup = function (e) { - var evt = me.changeEvent; - var detail = { oldValue: this.value, newValue: this.value }; - me.dispatchEvent(me.keyEvent.init(Events.KEYUP, event_detail_1.KeyEventDetail.create(e.keyCode))); - if (e.keyCode === 13 && tag === "input") { - me.dispatchEvent(evt.init(Events.CHANGE, detail)); - this.blur(); - } - else { - me.dispatchEvent(evt.init(Events.CHANGING, detail)); + var messagePrefix = "setImmediate$" + Math.random() + "$"; + var onGlobalMessage = function(event) { + if (event.source === global && + typeof event.data === "string" && + event.data.indexOf(messagePrefix) === 0) { + runIfPresent(+event.data.slice(messagePrefix.length)); } }; - element.onkeydown = function (e) { - me.dispatchEvent(me.keyEvent.init(Events.KEYDOWN, event_detail_1.KeyEventDetail.create(e.keyCode))); + + if (global.addEventListener) { + global.addEventListener("message", onGlobalMessage, false); + } else { + global.attachEvent("onmessage", onGlobalMessage); + } + + registerImmediate = function(handle) { + global.postMessage(messagePrefix + handle, "*"); }; - element.oninput = function (evt) { - var detail = { oldValue: this.value, newValue: this.value }; - me.dispatchEvent(me.changeEvent.init(Events.CHANGING, detail)); + } + + function installMessageChannelImplementation() { + var channel = new MessageChannel(); + channel.port1.onmessage = function(event) { + var handle = event.data; + runIfPresent(handle); }; - element.onchange = function (evt) { - var detail = { oldValue: this.value, newValue: this.value }; - me.changeEvent.init(Events.CHANGE, detail); - me.dispatchEvent(me.changeEvent); + + registerImmediate = function(handle) { + channel.port2.postMessage(handle); }; - element.onblur = function (evt) { - me.hide(); + } + + function installReadyStateChangeImplementation() { + var html = doc.documentElement; + registerImmediate = function(handle) { + // Create a